1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/epoll.h>
28 #include <sys/inotify.h>
33 #include "load-fragment.h"
34 #include "load-dropin.h"
36 #include "sd-messages.h"
39 #include "path-util.h"
40 #include "mount-setup.h"
41 #include "unit-name.h"
42 #include "dbus-mount.h"
44 #include "bus-errors.h"
45 #include "exit-status.h"
48 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table
*, mnt_free_table
);
49 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter
*, mnt_free_iter
);
51 static const UnitActiveState state_translation_table
[_MOUNT_STATE_MAX
] = {
52 [MOUNT_DEAD
] = UNIT_INACTIVE
,
53 [MOUNT_MOUNTING
] = UNIT_ACTIVATING
,
54 [MOUNT_MOUNTING_DONE
] = UNIT_ACTIVE
,
55 [MOUNT_MOUNTED
] = UNIT_ACTIVE
,
56 [MOUNT_REMOUNTING
] = UNIT_RELOADING
,
57 [MOUNT_UNMOUNTING
] = UNIT_DEACTIVATING
,
58 [MOUNT_MOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
59 [MOUNT_MOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
60 [MOUNT_REMOUNTING_SIGTERM
] = UNIT_RELOADING
,
61 [MOUNT_REMOUNTING_SIGKILL
] = UNIT_RELOADING
,
62 [MOUNT_UNMOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
63 [MOUNT_UNMOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
64 [MOUNT_FAILED
] = UNIT_FAILED
67 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
68 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
70 static bool mount_needs_network(const char *options
, const char *fstype
) {
71 if (mount_test_option(options
, "_netdev"))
74 if (fstype
&& fstype_is_network(fstype
))
80 static bool mount_is_network(const MountParameters
*p
) {
83 return mount_needs_network(p
->options
, p
->fstype
);
86 static bool mount_is_bind(const MountParameters
*p
) {
89 if (mount_test_option(p
->options
, "bind"))
92 if (p
->fstype
&& streq(p
->fstype
, "bind"))
95 if (mount_test_option(p
->options
, "rbind"))
98 if (p
->fstype
&& streq(p
->fstype
, "rbind"))
104 static bool mount_is_auto(const MountParameters
*p
) {
107 return !mount_test_option(p
->options
, "noauto");
110 static bool needs_quota(const MountParameters
*p
) {
113 if (mount_is_network(p
))
116 if (mount_is_bind(p
))
119 return mount_test_option(p
->options
, "usrquota") ||
120 mount_test_option(p
->options
, "grpquota") ||
121 mount_test_option(p
->options
, "quota") ||
122 mount_test_option(p
->options
, "usrjquota") ||
123 mount_test_option(p
->options
, "grpjquota");
126 static void mount_init(Unit
*u
) {
130 assert(u
->load_state
== UNIT_STUB
);
132 m
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
133 m
->directory_mode
= 0755;
135 if (unit_has_name(u
, "-.mount")) {
136 /* Don't allow start/stop for root directory */
137 u
->refuse_manual_start
= true;
138 u
->refuse_manual_stop
= true;
140 /* The stdio/kmsg bridge socket is on /, in order to avoid a
141 * dep loop, don't use kmsg logging for -.mount */
142 m
->exec_context
.std_output
= u
->manager
->default_std_output
;
143 m
->exec_context
.std_error
= u
->manager
->default_std_error
;
146 /* We need to make sure that /bin/mount is always called in
147 * the same process group as us, so that the autofs kernel
148 * side doesn't send us another mount request while we are
149 * already trying to comply its last one. */
150 m
->exec_context
.same_pgrp
= true;
152 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
154 u
->ignore_on_isolate
= true;
157 static int mount_arm_timer(Mount
*m
) {
162 if (m
->timeout_usec
<= 0) {
163 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
167 if (m
->timer_event_source
) {
168 r
= sd_event_source_set_time(m
->timer_event_source
, now(CLOCK_MONOTONIC
) + m
->timeout_usec
);
172 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_ONESHOT
);
175 return sd_event_add_time(
176 UNIT(m
)->manager
->event
,
177 &m
->timer_event_source
,
179 now(CLOCK_MONOTONIC
) + m
->timeout_usec
, 0,
180 mount_dispatch_timer
, m
);
183 static void mount_unwatch_control_pid(Mount
*m
) {
186 if (m
->control_pid
<= 0)
189 unit_unwatch_pid(UNIT(m
), m
->control_pid
);
193 static void mount_parameters_done(MountParameters
*p
) {
200 p
->what
= p
->options
= p
->fstype
= NULL
;
203 static void mount_done(Unit
*u
) {
211 mount_parameters_done(&m
->parameters_proc_self_mountinfo
);
212 mount_parameters_done(&m
->parameters_fragment
);
214 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
215 exec_command_done_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
216 m
->control_command
= NULL
;
218 mount_unwatch_control_pid(m
);
220 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
223 _pure_
static MountParameters
* get_mount_parameters_fragment(Mount
*m
) {
226 if (m
->from_fragment
)
227 return &m
->parameters_fragment
;
232 _pure_
static MountParameters
* get_mount_parameters(Mount
*m
) {
235 if (m
->from_proc_self_mountinfo
)
236 return &m
->parameters_proc_self_mountinfo
;
238 return get_mount_parameters_fragment(m
);
241 static int mount_add_mount_links(Mount
*m
) {
242 _cleanup_free_
char *parent
= NULL
;
251 if (!path_equal(m
->where
, "/")) {
252 /* Adds in links to other mount points that might lie further
253 * up in the hierarchy */
254 r
= path_get_parent(m
->where
, &parent
);
258 r
= unit_require_mounts_for(UNIT(m
), parent
);
263 /* Adds in links to other mount points that might be needed
264 * for the source path (if this is a bind mount) to be
266 pm
= get_mount_parameters_fragment(m
);
267 if (pm
&& pm
->what
&&
268 path_is_absolute(pm
->what
) &&
269 !mount_is_network(pm
)) {
271 r
= unit_require_mounts_for(UNIT(m
), pm
->what
);
276 /* Adds in links to other units that use this path or paths
277 * further down in the hierarchy */
278 s
= manager_get_units_requiring_mounts_for(UNIT(m
)->manager
, m
->where
);
279 SET_FOREACH(other
, s
, i
) {
281 if (other
->load_state
!= UNIT_LOADED
)
284 if (other
== UNIT(m
))
287 r
= unit_add_dependency(other
, UNIT_AFTER
, UNIT(m
), true);
291 if (UNIT(m
)->fragment_path
) {
292 /* If we have fragment configuration, then make this dependency required */
293 r
= unit_add_dependency(other
, UNIT_REQUIRES
, UNIT(m
), true);
302 static int mount_add_device_links(Mount
*m
) {
304 bool device_wants_mount
= false;
309 p
= get_mount_parameters_fragment(m
);
316 if (mount_is_bind(p
))
319 if (!is_device_path(p
->what
))
322 if (path_equal(m
->where
, "/"))
325 if (mount_is_auto(p
) && UNIT(m
)->manager
->running_as
== SYSTEMD_SYSTEM
)
326 device_wants_mount
= true;
328 r
= unit_add_node_link(UNIT(m
), p
->what
, device_wants_mount
);
335 static int mount_add_quota_links(Mount
*m
) {
341 if (UNIT(m
)->manager
->running_as
!= SYSTEMD_SYSTEM
)
344 p
= get_mount_parameters_fragment(m
);
351 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
, NULL
, true);
355 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
, NULL
, true);
362 static bool should_umount(Mount
*m
) {
365 if (path_equal(m
->where
, "/") ||
366 path_equal(m
->where
, "/usr"))
369 p
= get_mount_parameters(m
);
370 if (p
&& mount_test_option(p
->options
, "x-initrd.mount") &&
377 static int mount_add_default_dependencies(Mount
*m
) {
378 const char *after
, *after2
, *online
;
384 if (UNIT(m
)->manager
->running_as
!= SYSTEMD_SYSTEM
)
387 p
= get_mount_parameters(m
);
392 if (path_equal(m
->where
, "/") ||
393 path_equal(m
->where
, "/usr"))
396 if (mount_is_network(p
)) {
397 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
398 after2
= SPECIAL_NETWORK_TARGET
;
399 online
= SPECIAL_NETWORK_ONLINE_TARGET
;
401 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
406 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, NULL
, true);
411 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after2
, NULL
, true);
417 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, online
, NULL
, true);
422 if (should_umount(m
)) {
423 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
431 static int mount_verify(Mount
*m
) {
432 _cleanup_free_
char *e
= NULL
;
437 if (UNIT(m
)->load_state
!= UNIT_LOADED
)
440 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
)
443 e
= unit_name_from_path(m
->where
, ".mount");
447 b
= unit_has_name(UNIT(m
), e
);
449 log_unit_error(UNIT(m
)->id
, "%s's Where= setting doesn't match unit name. Refusing.", UNIT(m
)->id
);
453 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
)) {
454 log_unit_error(UNIT(m
)->id
, "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
458 if (UNIT(m
)->fragment_path
&& !m
->parameters_fragment
.what
) {
459 log_unit_error(UNIT(m
)->id
, "%s's What setting is missing. Refusing.", UNIT(m
)->id
);
463 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
) {
464 log_unit_error(UNIT(m
)->id
, "%s has PAM enabled. Kill mode must be set to control-group'. Refusing.",UNIT(m
)->id
);
471 static int mount_add_extras(Mount
*m
) {
477 if (u
->fragment_path
)
478 m
->from_fragment
= true;
481 m
->where
= unit_name_to_path(u
->id
);
486 path_kill_slashes(m
->where
);
488 if (!u
->description
) {
489 r
= unit_set_description(u
, m
->where
);
494 r
= mount_add_device_links(m
);
498 r
= mount_add_mount_links(m
);
502 r
= mount_add_quota_links(m
);
506 r
= unit_patch_contexts(u
);
510 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
514 r
= unit_add_default_slice(u
, &m
->cgroup_context
);
518 if (u
->default_dependencies
) {
519 r
= mount_add_default_dependencies(m
);
527 static int mount_load(Unit
*u
) {
532 assert(u
->load_state
== UNIT_STUB
);
534 if (m
->from_proc_self_mountinfo
)
535 r
= unit_load_fragment_and_dropin_optional(u
);
537 r
= unit_load_fragment_and_dropin(u
);
542 /* This is a new unit? Then let's add in some extras */
543 if (u
->load_state
== UNIT_LOADED
) {
544 r
= mount_add_extras(m
);
549 return mount_verify(m
);
552 static int mount_notify_automount(Mount
*m
, int status
) {
559 SET_FOREACH(p
, UNIT(m
)->dependencies
[UNIT_TRIGGERED_BY
], i
)
560 if (p
->type
== UNIT_AUTOMOUNT
) {
561 r
= automount_send_ready(AUTOMOUNT(p
), status
);
569 static void mount_set_state(Mount
*m
, MountState state
) {
570 MountState old_state
;
573 old_state
= m
->state
;
576 if (state
!= MOUNT_MOUNTING
&&
577 state
!= MOUNT_MOUNTING_DONE
&&
578 state
!= MOUNT_REMOUNTING
&&
579 state
!= MOUNT_UNMOUNTING
&&
580 state
!= MOUNT_MOUNTING_SIGTERM
&&
581 state
!= MOUNT_MOUNTING_SIGKILL
&&
582 state
!= MOUNT_UNMOUNTING_SIGTERM
&&
583 state
!= MOUNT_UNMOUNTING_SIGKILL
&&
584 state
!= MOUNT_REMOUNTING_SIGTERM
&&
585 state
!= MOUNT_REMOUNTING_SIGKILL
) {
586 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
587 mount_unwatch_control_pid(m
);
588 m
->control_command
= NULL
;
589 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
592 if (state
== MOUNT_MOUNTED
||
593 state
== MOUNT_REMOUNTING
)
594 mount_notify_automount(m
, 0);
595 else if (state
== MOUNT_DEAD
||
596 state
== MOUNT_UNMOUNTING
||
597 state
== MOUNT_MOUNTING_SIGTERM
||
598 state
== MOUNT_MOUNTING_SIGKILL
||
599 state
== MOUNT_REMOUNTING_SIGTERM
||
600 state
== MOUNT_REMOUNTING_SIGKILL
||
601 state
== MOUNT_UNMOUNTING_SIGTERM
||
602 state
== MOUNT_UNMOUNTING_SIGKILL
||
603 state
== MOUNT_FAILED
) {
604 if (state
!= old_state
)
605 mount_notify_automount(m
, -ENODEV
);
608 if (state
!= old_state
)
609 log_unit_debug(UNIT(m
)->id
,
610 "%s changed %s -> %s",
612 mount_state_to_string(old_state
),
613 mount_state_to_string(state
));
615 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
616 m
->reload_result
= MOUNT_SUCCESS
;
619 static int mount_coldplug(Unit
*u
) {
621 MountState new_state
= MOUNT_DEAD
;
625 assert(m
->state
== MOUNT_DEAD
);
627 if (m
->deserialized_state
!= m
->state
)
628 new_state
= m
->deserialized_state
;
629 else if (m
->from_proc_self_mountinfo
)
630 new_state
= MOUNT_MOUNTED
;
632 if (new_state
== m
->state
)
635 if (new_state
== MOUNT_MOUNTING
||
636 new_state
== MOUNT_MOUNTING_DONE
||
637 new_state
== MOUNT_REMOUNTING
||
638 new_state
== MOUNT_UNMOUNTING
||
639 new_state
== MOUNT_MOUNTING_SIGTERM
||
640 new_state
== MOUNT_MOUNTING_SIGKILL
||
641 new_state
== MOUNT_UNMOUNTING_SIGTERM
||
642 new_state
== MOUNT_UNMOUNTING_SIGKILL
||
643 new_state
== MOUNT_REMOUNTING_SIGTERM
||
644 new_state
== MOUNT_REMOUNTING_SIGKILL
) {
646 if (m
->control_pid
<= 0)
649 r
= unit_watch_pid(UNIT(m
), m
->control_pid
);
653 r
= mount_arm_timer(m
);
658 mount_set_state(m
, new_state
);
662 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
669 p
= get_mount_parameters(m
);
672 "%sMount State: %s\n"
676 "%sFile System Type: %s\n"
678 "%sFrom /proc/self/mountinfo: %s\n"
679 "%sFrom fragment: %s\n"
680 "%sDirectoryMode: %04o\n",
681 prefix
, mount_state_to_string(m
->state
),
682 prefix
, mount_result_to_string(m
->result
),
684 prefix
, p
? strna(p
->what
) : "n/a",
685 prefix
, p
? strna(p
->fstype
) : "n/a",
686 prefix
, p
? strna(p
->options
) : "n/a",
687 prefix
, yes_no(m
->from_proc_self_mountinfo
),
688 prefix
, yes_no(m
->from_fragment
),
689 prefix
, m
->directory_mode
);
691 if (m
->control_pid
> 0)
693 "%sControl PID: "PID_FMT
"\n",
694 prefix
, m
->control_pid
);
696 exec_context_dump(&m
->exec_context
, f
, prefix
);
697 kill_context_dump(&m
->kill_context
, f
, prefix
);
700 static int mount_spawn(Mount
*m
, ExecCommand
*c
, pid_t
*_pid
) {
703 ExecParameters exec_params
= {
704 .apply_permissions
= true,
705 .apply_chroot
= true,
706 .apply_tty_stdin
= true,
713 unit_realize_cgroup(UNIT(m
));
715 r
= unit_setup_exec_runtime(UNIT(m
));
719 r
= mount_arm_timer(m
);
723 exec_params
.environment
= UNIT(m
)->manager
->environment
;
724 exec_params
.confirm_spawn
= UNIT(m
)->manager
->confirm_spawn
;
725 exec_params
.cgroup_supported
= UNIT(m
)->manager
->cgroup_supported
;
726 exec_params
.cgroup_path
= UNIT(m
)->cgroup_path
;
727 exec_params
.cgroup_delegate
= m
->cgroup_context
.delegate
;
728 exec_params
.runtime_prefix
= manager_get_runtime_prefix(UNIT(m
)->manager
);
729 exec_params
.unit_id
= UNIT(m
)->id
;
739 r
= unit_watch_pid(UNIT(m
), pid
);
741 /* FIXME: we need to do something here */
749 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
754 static void mount_enter_dead(Mount
*m
, MountResult f
) {
757 if (f
!= MOUNT_SUCCESS
)
760 exec_runtime_destroy(m
->exec_runtime
);
761 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
763 exec_context_destroy_runtime_directory(&m
->exec_context
, manager_get_runtime_prefix(UNIT(m
)->manager
));
765 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
768 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
771 if (f
!= MOUNT_SUCCESS
)
774 mount_set_state(m
, MOUNT_MOUNTED
);
777 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
782 if (f
!= MOUNT_SUCCESS
)
785 r
= unit_kill_context(
788 (state
!= MOUNT_MOUNTING_SIGTERM
&& state
!= MOUNT_UNMOUNTING_SIGTERM
&& state
!= MOUNT_REMOUNTING_SIGTERM
) ?
789 KILL_KILL
: KILL_TERMINATE
,
797 r
= mount_arm_timer(m
);
801 mount_set_state(m
, state
);
802 } else if (state
== MOUNT_REMOUNTING_SIGTERM
)
803 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
804 else if (state
== MOUNT_REMOUNTING_SIGKILL
)
805 mount_enter_mounted(m
, MOUNT_SUCCESS
);
806 else if (state
== MOUNT_MOUNTING_SIGTERM
)
807 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_SUCCESS
);
808 else if (state
== MOUNT_UNMOUNTING_SIGTERM
)
809 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
811 mount_enter_dead(m
, MOUNT_SUCCESS
);
816 log_unit_warning(UNIT(m
)->id
,
817 "%s failed to kill processes: %s", UNIT(m
)->id
, strerror(-r
));
819 if (state
== MOUNT_REMOUNTING_SIGTERM
|| state
== MOUNT_REMOUNTING_SIGKILL
)
820 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
822 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
825 void warn_if_dir_nonempty(const char *unit
, const char* where
) {
831 r
= dir_is_empty(where
);
835 log_unit_struct(unit
,
837 LOG_MESSAGE_ID(SD_MESSAGE_OVERMOUNTING
),
838 LOG_MESSAGE("%s: Directory %s to mount over is not empty, mounting anyway.",
843 log_unit_warning(unit
,
844 "MESSAGE=Failed to check directory %s: %s",
845 where
, strerror(-r
));
848 static int fail_if_symlink(const char *unit
, const char* where
) {
851 if (is_symlink(where
) > 0) {
852 log_unit_struct(unit
,
854 LOG_MESSAGE_ID(SD_MESSAGE_OVERMOUNTING
),
855 LOG_MESSAGE("%s: Mount on symlink %s not allowed.",
865 static void mount_enter_unmounting(Mount
*m
) {
870 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
871 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
873 if ((r
= exec_command_set(
881 mount_unwatch_control_pid(m
);
883 if ((r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
)) < 0)
886 mount_set_state(m
, MOUNT_UNMOUNTING
);
891 log_unit_warning(UNIT(m
)->id
,
892 "%s failed to run 'umount' task: %s",
893 UNIT(m
)->id
, strerror(-r
));
894 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
897 static void mount_enter_mounting(Mount
*m
) {
903 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
904 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
906 mkdir_p_label(m
->where
, m
->directory_mode
);
908 warn_if_dir_nonempty(m
->meta
.id
, m
->where
);
910 /* Create the source directory for bind-mounts if needed */
911 p
= get_mount_parameters_fragment(m
);
912 if (p
&& mount_is_bind(p
))
913 mkdir_p_label(p
->what
, m
->directory_mode
);
915 r
= fail_if_symlink(m
->meta
.id
, m
->where
);
919 if (m
->from_fragment
)
920 r
= exec_command_set(
923 m
->sloppy_options
? "-ns" : "-n",
924 m
->parameters_fragment
.what
,
926 "-t", m
->parameters_fragment
.fstype
? m
->parameters_fragment
.fstype
: "auto",
927 m
->parameters_fragment
.options
? "-o" : NULL
, m
->parameters_fragment
.options
,
935 mount_unwatch_control_pid(m
);
937 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
941 mount_set_state(m
, MOUNT_MOUNTING
);
946 log_unit_warning(UNIT(m
)->id
,
947 "%s failed to run 'mount' task: %s",
948 UNIT(m
)->id
, strerror(-r
));
949 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
952 static void mount_enter_remounting(Mount
*m
) {
957 m
->control_command_id
= MOUNT_EXEC_REMOUNT
;
958 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_REMOUNT
;
960 if (m
->from_fragment
) {
963 if (m
->parameters_fragment
.options
)
964 o
= strappenda("remount,", m
->parameters_fragment
.options
);
968 r
= exec_command_set(
971 m
->sloppy_options
? "-ns" : "-n",
972 m
->parameters_fragment
.what
,
974 "-t", m
->parameters_fragment
.fstype
? m
->parameters_fragment
.fstype
: "auto",
983 mount_unwatch_control_pid(m
);
985 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
989 mount_set_state(m
, MOUNT_REMOUNTING
);
994 log_unit_warning(UNIT(m
)->id
,
995 "%s failed to run 'remount' task: %s",
996 UNIT(m
)->id
, strerror(-r
));
997 m
->reload_result
= MOUNT_FAILURE_RESOURCES
;
998 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1001 static int mount_start(Unit
*u
) {
1002 Mount
*m
= MOUNT(u
);
1006 /* We cannot fulfill this request right now, try again later
1008 if (m
->state
== MOUNT_UNMOUNTING
||
1009 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
1010 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1011 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1012 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1015 /* Already on it! */
1016 if (m
->state
== MOUNT_MOUNTING
)
1019 assert(m
->state
== MOUNT_DEAD
|| m
->state
== MOUNT_FAILED
);
1021 m
->result
= MOUNT_SUCCESS
;
1022 m
->reload_result
= MOUNT_SUCCESS
;
1024 mount_enter_mounting(m
);
1028 static int mount_stop(Unit
*u
) {
1029 Mount
*m
= MOUNT(u
);
1034 if (m
->state
== MOUNT_UNMOUNTING
||
1035 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1036 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
1037 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1038 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1041 assert(m
->state
== MOUNT_MOUNTING
||
1042 m
->state
== MOUNT_MOUNTING_DONE
||
1043 m
->state
== MOUNT_MOUNTED
||
1044 m
->state
== MOUNT_REMOUNTING
||
1045 m
->state
== MOUNT_REMOUNTING_SIGTERM
||
1046 m
->state
== MOUNT_REMOUNTING_SIGKILL
);
1048 mount_enter_unmounting(m
);
1052 static int mount_reload(Unit
*u
) {
1053 Mount
*m
= MOUNT(u
);
1057 if (m
->state
== MOUNT_MOUNTING_DONE
)
1060 assert(m
->state
== MOUNT_MOUNTED
);
1062 mount_enter_remounting(m
);
1066 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1067 Mount
*m
= MOUNT(u
);
1073 unit_serialize_item(u
, f
, "state", mount_state_to_string(m
->state
));
1074 unit_serialize_item(u
, f
, "result", mount_result_to_string(m
->result
));
1075 unit_serialize_item(u
, f
, "reload-result", mount_result_to_string(m
->reload_result
));
1077 if (m
->control_pid
> 0)
1078 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, m
->control_pid
);
1080 if (m
->control_command_id
>= 0)
1081 unit_serialize_item(u
, f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1086 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1087 Mount
*m
= MOUNT(u
);
1094 if (streq(key
, "state")) {
1097 if ((state
= mount_state_from_string(value
)) < 0)
1098 log_unit_debug(u
->id
, "Failed to parse state value %s", value
);
1100 m
->deserialized_state
= state
;
1101 } else if (streq(key
, "result")) {
1104 f
= mount_result_from_string(value
);
1106 log_unit_debug(UNIT(m
)->id
,
1107 "Failed to parse result value %s", value
);
1108 else if (f
!= MOUNT_SUCCESS
)
1111 } else if (streq(key
, "reload-result")) {
1114 f
= mount_result_from_string(value
);
1116 log_unit_debug(UNIT(m
)->id
,
1117 "Failed to parse reload result value %s", value
);
1118 else if (f
!= MOUNT_SUCCESS
)
1119 m
->reload_result
= f
;
1121 } else if (streq(key
, "control-pid")) {
1124 if (parse_pid(value
, &pid
) < 0)
1125 log_unit_debug(UNIT(m
)->id
,
1126 "Failed to parse control-pid value %s", value
);
1128 m
->control_pid
= pid
;
1129 } else if (streq(key
, "control-command")) {
1130 MountExecCommand id
;
1132 if ((id
= mount_exec_command_from_string(value
)) < 0)
1133 log_unit_debug(UNIT(m
)->id
,
1134 "Failed to parse exec-command value %s", value
);
1136 m
->control_command_id
= id
;
1137 m
->control_command
= m
->exec_command
+ id
;
1140 log_unit_debug(UNIT(m
)->id
,
1141 "Unknown serialization key '%s'", key
);
1146 _pure_
static UnitActiveState
mount_active_state(Unit
*u
) {
1149 return state_translation_table
[MOUNT(u
)->state
];
1152 _pure_
static const char *mount_sub_state_to_string(Unit
*u
) {
1155 return mount_state_to_string(MOUNT(u
)->state
);
1158 _pure_
static bool mount_check_gc(Unit
*u
) {
1159 Mount
*m
= MOUNT(u
);
1163 return m
->from_proc_self_mountinfo
;
1166 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1167 Mount
*m
= MOUNT(u
);
1173 if (pid
!= m
->control_pid
)
1178 if (is_clean_exit(code
, status
, NULL
))
1180 else if (code
== CLD_EXITED
)
1181 f
= MOUNT_FAILURE_EXIT_CODE
;
1182 else if (code
== CLD_KILLED
)
1183 f
= MOUNT_FAILURE_SIGNAL
;
1184 else if (code
== CLD_DUMPED
)
1185 f
= MOUNT_FAILURE_CORE_DUMP
;
1187 assert_not_reached("Unknown code");
1189 if (f
!= MOUNT_SUCCESS
)
1192 if (m
->control_command
) {
1193 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1195 m
->control_command
= NULL
;
1196 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1199 log_unit_full(u
->id
,
1200 f
== MOUNT_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
,
1201 "%s mount process exited, code=%s status=%i",
1202 u
->id
, sigchld_code_to_string(code
), status
);
1204 /* Note that mount(8) returning and the kernel sending us a
1205 * mount table change event might happen out-of-order. If an
1206 * operation succeed we assume the kernel will follow soon too
1207 * and already change into the resulting state. If it fails
1208 * we check if the kernel still knows about the mount. and
1209 * change state accordingly. */
1213 case MOUNT_MOUNTING
:
1214 case MOUNT_MOUNTING_DONE
:
1215 case MOUNT_MOUNTING_SIGKILL
:
1216 case MOUNT_MOUNTING_SIGTERM
:
1218 if (f
== MOUNT_SUCCESS
)
1219 mount_enter_mounted(m
, f
);
1220 else if (m
->from_proc_self_mountinfo
)
1221 mount_enter_mounted(m
, f
);
1223 mount_enter_dead(m
, f
);
1226 case MOUNT_REMOUNTING
:
1227 case MOUNT_REMOUNTING_SIGKILL
:
1228 case MOUNT_REMOUNTING_SIGTERM
:
1230 m
->reload_result
= f
;
1231 if (m
->from_proc_self_mountinfo
)
1232 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1234 mount_enter_dead(m
, MOUNT_SUCCESS
);
1238 case MOUNT_UNMOUNTING
:
1239 case MOUNT_UNMOUNTING_SIGKILL
:
1240 case MOUNT_UNMOUNTING_SIGTERM
:
1242 if (f
== MOUNT_SUCCESS
)
1243 mount_enter_dead(m
, f
);
1244 else if (m
->from_proc_self_mountinfo
)
1245 mount_enter_mounted(m
, f
);
1247 mount_enter_dead(m
, f
);
1251 assert_not_reached("Uh, control process died at wrong time.");
1254 /* Notify clients about changed exit status */
1255 unit_add_to_dbus_queue(u
);
1258 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1259 Mount
*m
= MOUNT(userdata
);
1262 assert(m
->timer_event_source
== source
);
1266 case MOUNT_MOUNTING
:
1267 case MOUNT_MOUNTING_DONE
:
1268 log_unit_warning(UNIT(m
)->id
,
1269 "%s mounting timed out. Stopping.", UNIT(m
)->id
);
1270 mount_enter_signal(m
, MOUNT_MOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1273 case MOUNT_REMOUNTING
:
1274 log_unit_warning(UNIT(m
)->id
,
1275 "%s remounting timed out. Stopping.", UNIT(m
)->id
);
1276 m
->reload_result
= MOUNT_FAILURE_TIMEOUT
;
1277 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1280 case MOUNT_UNMOUNTING
:
1281 log_unit_warning(UNIT(m
)->id
,
1282 "%s unmounting timed out. Stopping.", UNIT(m
)->id
);
1283 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1286 case MOUNT_MOUNTING_SIGTERM
:
1287 if (m
->kill_context
.send_sigkill
) {
1288 log_unit_warning(UNIT(m
)->id
,
1289 "%s mounting timed out. Killing.", UNIT(m
)->id
);
1290 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1292 log_unit_warning(UNIT(m
)->id
,
1293 "%s mounting timed out. Skipping SIGKILL. Ignoring.",
1296 if (m
->from_proc_self_mountinfo
)
1297 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1299 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1303 case MOUNT_REMOUNTING_SIGTERM
:
1304 if (m
->kill_context
.send_sigkill
) {
1305 log_unit_warning(UNIT(m
)->id
,
1306 "%s remounting timed out. Killing.", UNIT(m
)->id
);
1307 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1309 log_unit_warning(UNIT(m
)->id
,
1310 "%s remounting timed out. Skipping SIGKILL. Ignoring.",
1313 if (m
->from_proc_self_mountinfo
)
1314 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1316 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1320 case MOUNT_UNMOUNTING_SIGTERM
:
1321 if (m
->kill_context
.send_sigkill
) {
1322 log_unit_warning(UNIT(m
)->id
,
1323 "%s unmounting timed out. Killing.", UNIT(m
)->id
);
1324 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1326 log_unit_warning(UNIT(m
)->id
,
1327 "%s unmounting timed out. Skipping SIGKILL. Ignoring.",
1330 if (m
->from_proc_self_mountinfo
)
1331 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1333 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1337 case MOUNT_MOUNTING_SIGKILL
:
1338 case MOUNT_REMOUNTING_SIGKILL
:
1339 case MOUNT_UNMOUNTING_SIGKILL
:
1340 log_unit_warning(UNIT(m
)->id
,
1341 "%s mount process still around after SIGKILL. Ignoring.",
1344 if (m
->from_proc_self_mountinfo
)
1345 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1347 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1351 assert_not_reached("Timeout at wrong time.");
1357 static int mount_add_one(
1361 const char *options
,
1365 _cleanup_free_
char *e
= NULL
, *w
= NULL
, *o
= NULL
, *f
= NULL
;
1366 bool load_extras
= false;
1368 bool delete, changed
= false;
1378 /* Ignore API mount points. They should never be referenced in
1379 * dependencies ever. */
1380 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1383 if (streq(fstype
, "autofs"))
1386 /* probably some kind of swap, ignore */
1387 if (!is_path(where
))
1390 e
= unit_name_from_path(where
, ".mount");
1394 u
= manager_get_unit(m
, e
);
1398 u
= unit_new(m
, sizeof(Mount
));
1402 r
= unit_add_name(u
, e
);
1406 MOUNT(u
)->where
= strdup(where
);
1407 if (!MOUNT(u
)->where
) {
1412 u
->source_path
= strdup("/proc/self/mountinfo");
1413 if (!u
->source_path
) {
1419 if (m
->running_as
== SYSTEMD_SYSTEM
) {
1422 target
= mount_needs_network(options
, fstype
) ? SPECIAL_REMOTE_FS_TARGET
: SPECIAL_LOCAL_FS_TARGET
;
1423 r
= unit_add_dependency_by_name(u
, UNIT_BEFORE
, target
, NULL
, true);
1427 if (should_umount(MOUNT(u
))) {
1428 r
= unit_add_dependency_by_name(u
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
1434 unit_add_to_load_queue(u
);
1439 if (!MOUNT(u
)->where
) {
1440 MOUNT(u
)->where
= strdup(where
);
1441 if (!MOUNT(u
)->where
) {
1447 if (m
->running_as
== SYSTEMD_SYSTEM
&&
1448 mount_needs_network(options
, fstype
)) {
1449 /* _netdev option may have shown up late, or on a
1450 * remount. Add remote-fs dependencies, even though
1451 * local-fs ones may already be there. */
1452 unit_add_dependency_by_name(u
, UNIT_BEFORE
, SPECIAL_REMOTE_FS_TARGET
, NULL
, true);
1456 if (u
->load_state
== UNIT_NOT_FOUND
) {
1457 u
->load_state
= UNIT_LOADED
;
1460 /* Load in the extras later on, after we
1461 * finished initialization of the unit */
1468 o
= strdup(options
);
1470 if (!w
|| !o
|| !f
) {
1475 p
= &MOUNT(u
)->parameters_proc_self_mountinfo
;
1477 changed
= changed
||
1478 !streq_ptr(p
->options
, options
) ||
1479 !streq_ptr(p
->what
, what
) ||
1480 !streq_ptr(p
->fstype
, fstype
);
1483 MOUNT(u
)->is_mounted
= true;
1484 MOUNT(u
)->just_mounted
= !MOUNT(u
)->from_proc_self_mountinfo
;
1485 MOUNT(u
)->just_changed
= changed
;
1488 MOUNT(u
)->from_proc_self_mountinfo
= true;
1503 r
= mount_add_extras(MOUNT(u
));
1509 unit_add_to_dbus_queue(u
);
1520 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1521 _cleanup_(mnt_free_tablep
) struct libmnt_table
*tb
= NULL
;
1522 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*itr
= NULL
;
1523 struct libmnt_fs
*fs
;
1528 tb
= mnt_new_table();
1529 itr
= mnt_new_iter(MNT_ITER_FORWARD
);
1533 r
= mnt_table_parse_mtab(tb
, NULL
);
1539 const char *device
, *path
, *options
, *fstype
;
1540 _cleanup_free_
const char *d
= NULL
, *p
= NULL
;
1543 k
= mnt_table_next_fs(tb
, itr
, &fs
);
1547 return log_error_errno(k
, "Failed to get next entry from /etc/fstab: %m");
1549 device
= mnt_fs_get_source(fs
);
1550 path
= mnt_fs_get_target(fs
);
1551 options
= mnt_fs_get_options(fs
);
1552 fstype
= mnt_fs_get_fstype(fs
);
1554 d
= cunescape(device
);
1555 p
= cunescape(path
);
1559 k
= mount_add_one(m
, d
, p
, options
, fstype
, set_flags
);
1560 if (r
== 0 && k
< 0)
1567 static void mount_shutdown(Manager
*m
) {
1570 m
->mount_event_source
= sd_event_source_unref(m
->mount_event_source
);
1571 m
->mount_utab_event_source
= sd_event_source_unref(m
->mount_utab_event_source
);
1573 if (m
->proc_self_mountinfo
) {
1574 fclose(m
->proc_self_mountinfo
);
1575 m
->proc_self_mountinfo
= NULL
;
1577 m
->utab_inotify_fd
= safe_close(m
->utab_inotify_fd
);
1580 static int mount_get_timeout(Unit
*u
, uint64_t *timeout
) {
1581 Mount
*m
= MOUNT(u
);
1584 if (!m
->timer_event_source
)
1587 r
= sd_event_source_get_time(m
->timer_event_source
, timeout
);
1594 static int mount_enumerate(Manager
*m
) {
1600 if (!m
->proc_self_mountinfo
) {
1601 m
->proc_self_mountinfo
= fopen("/proc/self/mountinfo", "re");
1602 if (!m
->proc_self_mountinfo
)
1605 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fileno(m
->proc_self_mountinfo
), EPOLLPRI
, mount_dispatch_io
, m
);
1609 /* Dispatch this before we dispatch SIGCHLD, so that
1610 * we always get the events from /proc/self/mountinfo
1611 * before the SIGCHLD of /bin/mount. */
1612 r
= sd_event_source_set_priority(m
->mount_event_source
, -10);
1617 if (m
->utab_inotify_fd
< 0) {
1618 m
->utab_inotify_fd
= inotify_init1(IN_NONBLOCK
|IN_CLOEXEC
);
1619 if (m
->utab_inotify_fd
< 0)
1620 goto fail_with_errno
;
1622 (void) mkdir_p_label("/run/mount", 0755);
1624 r
= inotify_add_watch(m
->utab_inotify_fd
, "/run/mount", IN_MOVED_TO
);
1626 goto fail_with_errno
;
1628 r
= sd_event_add_io(m
->event
, &m
->mount_utab_event_source
, m
->utab_inotify_fd
, EPOLLIN
, mount_dispatch_io
, m
);
1632 r
= sd_event_source_set_priority(m
->mount_utab_event_source
, -10);
1637 r
= mount_load_proc_self_mountinfo(m
, false);
1650 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
1651 Manager
*m
= userdata
;
1656 assert(revents
& (EPOLLPRI
| EPOLLIN
));
1658 /* The manager calls this for every fd event happening on the
1659 * /proc/self/mountinfo file, which informs us about mounting
1660 * table changes, and for /run/mount events which we watch
1661 * for mount options. */
1663 if (fd
== m
->utab_inotify_fd
) {
1664 char inotify_buffer
[sizeof(struct inotify_event
) + NAME_MAX
+ 1];
1665 struct inotify_event
*event
;
1669 while ((r
= read(fd
, inotify_buffer
, sizeof(inotify_buffer
))) > 0)
1670 for (p
= inotify_buffer
; p
< inotify_buffer
+ r
; ) {
1671 event
= (struct inotify_event
*) p
;
1672 /* only care about changes to utab, but we have
1673 * to monitor the directory to reliably get
1674 * notifications about when utab is replaced
1675 * using rename(2) */
1676 if ((event
->mask
& IN_Q_OVERFLOW
) || streq(event
->name
, "utab"))
1678 p
+= sizeof(struct inotify_event
) + event
->len
;
1685 r
= mount_load_proc_self_mountinfo(m
, true);
1687 log_error_errno(r
, "Failed to reread /proc/self/mountinfo: %m");
1689 /* Reset flags, just in case, for later calls */
1690 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1691 Mount
*mount
= MOUNT(u
);
1693 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1699 manager_dispatch_load_queue(m
);
1701 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1702 Mount
*mount
= MOUNT(u
);
1704 if (!mount
->is_mounted
) {
1706 mount
->from_proc_self_mountinfo
= false;
1708 switch (mount
->state
) {
1711 /* This has just been unmounted by
1712 * somebody else, follow the state
1714 mount_enter_dead(mount
, MOUNT_SUCCESS
);
1721 } else if (mount
->just_mounted
|| mount
->just_changed
) {
1723 /* New or changed mount entry */
1725 switch (mount
->state
) {
1729 /* This has just been mounted by
1730 * somebody else, follow the state
1732 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
1735 case MOUNT_MOUNTING
:
1736 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
1740 /* Nothing really changed, but let's
1741 * issue an notification call
1742 * nonetheless, in case somebody is
1743 * waiting for this. (e.g. file system
1744 * ro/rw remounts.) */
1745 mount_set_state(mount
, mount
->state
);
1750 /* Reset the flags for later calls */
1751 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1757 static void mount_reset_failed(Unit
*u
) {
1758 Mount
*m
= MOUNT(u
);
1762 if (m
->state
== MOUNT_FAILED
)
1763 mount_set_state(m
, MOUNT_DEAD
);
1765 m
->result
= MOUNT_SUCCESS
;
1766 m
->reload_result
= MOUNT_SUCCESS
;
1769 static int mount_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
1770 return unit_kill_common(u
, who
, signo
, -1, MOUNT(u
)->control_pid
, error
);
1773 static const char* const mount_state_table
[_MOUNT_STATE_MAX
] = {
1774 [MOUNT_DEAD
] = "dead",
1775 [MOUNT_MOUNTING
] = "mounting",
1776 [MOUNT_MOUNTING_DONE
] = "mounting-done",
1777 [MOUNT_MOUNTED
] = "mounted",
1778 [MOUNT_REMOUNTING
] = "remounting",
1779 [MOUNT_UNMOUNTING
] = "unmounting",
1780 [MOUNT_MOUNTING_SIGTERM
] = "mounting-sigterm",
1781 [MOUNT_MOUNTING_SIGKILL
] = "mounting-sigkill",
1782 [MOUNT_REMOUNTING_SIGTERM
] = "remounting-sigterm",
1783 [MOUNT_REMOUNTING_SIGKILL
] = "remounting-sigkill",
1784 [MOUNT_UNMOUNTING_SIGTERM
] = "unmounting-sigterm",
1785 [MOUNT_UNMOUNTING_SIGKILL
] = "unmounting-sigkill",
1786 [MOUNT_FAILED
] = "failed"
1789 DEFINE_STRING_TABLE_LOOKUP(mount_state
, MountState
);
1791 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
1792 [MOUNT_EXEC_MOUNT
] = "ExecMount",
1793 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
1794 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
1797 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
1799 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
1800 [MOUNT_SUCCESS
] = "success",
1801 [MOUNT_FAILURE_RESOURCES
] = "resources",
1802 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
1803 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
1804 [MOUNT_FAILURE_SIGNAL
] = "signal",
1805 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump"
1808 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
1810 const UnitVTable mount_vtable
= {
1811 .object_size
= sizeof(Mount
),
1812 .exec_context_offset
= offsetof(Mount
, exec_context
),
1813 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
1814 .kill_context_offset
= offsetof(Mount
, kill_context
),
1815 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
1821 .private_section
= "Mount",
1824 .no_instances
= true,
1830 .coldplug
= mount_coldplug
,
1834 .start
= mount_start
,
1836 .reload
= mount_reload
,
1840 .serialize
= mount_serialize
,
1841 .deserialize_item
= mount_deserialize_item
,
1843 .active_state
= mount_active_state
,
1844 .sub_state_to_string
= mount_sub_state_to_string
,
1846 .check_gc
= mount_check_gc
,
1848 .sigchld_event
= mount_sigchld_event
,
1850 .reset_failed
= mount_reset_failed
,
1852 .bus_interface
= "org.freedesktop.systemd1.Mount",
1853 .bus_vtable
= bus_mount_vtable
,
1854 .bus_set_property
= bus_mount_set_property
,
1855 .bus_commit_properties
= bus_mount_commit_properties
,
1857 .get_timeout
= mount_get_timeout
,
1859 .can_transient
= true,
1861 .enumerate
= mount_enumerate
,
1862 .shutdown
= mount_shutdown
,
1864 .status_message_formats
= {
1865 .starting_stopping
= {
1866 [0] = "Mounting %s...",
1867 [1] = "Unmounting %s...",
1869 .finished_start_job
= {
1870 [JOB_DONE
] = "Mounted %s.",
1871 [JOB_FAILED
] = "Failed to mount %s.",
1872 [JOB_DEPENDENCY
] = "Dependency failed for %s.",
1873 [JOB_TIMEOUT
] = "Timed out mounting %s.",
1875 .finished_stop_job
= {
1876 [JOB_DONE
] = "Unmounted %s.",
1877 [JOB_FAILED
] = "Failed unmounting %s.",
1878 [JOB_TIMEOUT
] = "Timed out unmounting %s.",