2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/epoll.h>
25 #include "sd-messages.h"
27 #include "alloc-util.h"
28 #include "dbus-mount.h"
30 #include "exit-status.h"
31 #include "formats-util.h"
32 #include "fstab-util.h"
36 #include "mount-setup.h"
37 #include "mount-util.h"
39 #include "parse-util.h"
40 #include "path-util.h"
41 #include "process-util.h"
43 #include "string-table.h"
44 #include "string-util.h"
46 #include "unit-name.h"
49 #define RETRY_UMOUNT_MAX 32
51 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table
*, mnt_free_table
);
52 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter
*, mnt_free_iter
);
54 static const UnitActiveState state_translation_table
[_MOUNT_STATE_MAX
] = {
55 [MOUNT_DEAD
] = UNIT_INACTIVE
,
56 [MOUNT_MOUNTING
] = UNIT_ACTIVATING
,
57 [MOUNT_MOUNTING_DONE
] = UNIT_ACTIVE
,
58 [MOUNT_MOUNTED
] = UNIT_ACTIVE
,
59 [MOUNT_REMOUNTING
] = UNIT_RELOADING
,
60 [MOUNT_UNMOUNTING
] = UNIT_DEACTIVATING
,
61 [MOUNT_MOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
62 [MOUNT_MOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
63 [MOUNT_REMOUNTING_SIGTERM
] = UNIT_RELOADING
,
64 [MOUNT_REMOUNTING_SIGKILL
] = UNIT_RELOADING
,
65 [MOUNT_UNMOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
66 [MOUNT_UNMOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
67 [MOUNT_FAILED
] = UNIT_FAILED
70 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
71 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
73 static bool mount_needs_network(const char *options
, const char *fstype
) {
74 if (fstab_test_option(options
, "_netdev\0"))
77 if (fstype
&& fstype_is_network(fstype
))
83 static bool mount_is_network(const MountParameters
*p
) {
86 return mount_needs_network(p
->options
, p
->fstype
);
89 static bool mount_is_loop(const MountParameters
*p
) {
92 if (fstab_test_option(p
->options
, "loop\0"))
98 static bool mount_is_bind(const MountParameters
*p
) {
101 if (fstab_test_option(p
->options
, "bind\0" "rbind\0"))
104 if (p
->fstype
&& STR_IN_SET(p
->fstype
, "bind", "rbind"))
110 static bool mount_is_auto(const MountParameters
*p
) {
113 return !fstab_test_option(p
->options
, "noauto\0");
116 static bool mount_is_automount(const MountParameters
*p
) {
119 return fstab_test_option(p
->options
,
120 "comment=systemd.automount\0"
121 "x-systemd.automount\0");
124 static bool mount_state_active(MountState state
) {
130 MOUNT_MOUNTING_SIGTERM
,
131 MOUNT_MOUNTING_SIGKILL
,
132 MOUNT_UNMOUNTING_SIGTERM
,
133 MOUNT_UNMOUNTING_SIGKILL
,
134 MOUNT_REMOUNTING_SIGTERM
,
135 MOUNT_REMOUNTING_SIGKILL
);
138 static bool needs_quota(const MountParameters
*p
) {
141 /* Quotas are not enabled on network filesystems,
142 * but we want them, for example, on storage connected via iscsi */
143 if (p
->fstype
&& fstype_is_network(p
->fstype
))
146 if (mount_is_bind(p
))
149 return fstab_test_option(p
->options
,
150 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
153 static void mount_init(Unit
*u
) {
157 assert(u
->load_state
== UNIT_STUB
);
159 m
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
160 m
->directory_mode
= 0755;
162 if (unit_has_name(u
, "-.mount")) {
163 /* Don't allow start/stop for root directory */
164 u
->refuse_manual_start
= true;
165 u
->refuse_manual_stop
= true;
167 /* The stdio/kmsg bridge socket is on /, in order to avoid a
168 * dep loop, don't use kmsg logging for -.mount */
169 m
->exec_context
.std_output
= u
->manager
->default_std_output
;
170 m
->exec_context
.std_error
= u
->manager
->default_std_error
;
173 /* We need to make sure that /usr/bin/mount is always called
174 * in the same process group as us, so that the autofs kernel
175 * side doesn't send us another mount request while we are
176 * already trying to comply its last one. */
177 m
->exec_context
.same_pgrp
= true;
179 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
181 u
->ignore_on_isolate
= true;
184 static int mount_arm_timer(Mount
*m
, usec_t usec
) {
189 if (m
->timer_event_source
) {
190 r
= sd_event_source_set_time(m
->timer_event_source
, usec
);
194 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_ONESHOT
);
197 if (usec
== USEC_INFINITY
)
200 r
= sd_event_add_time(
201 UNIT(m
)->manager
->event
,
202 &m
->timer_event_source
,
205 mount_dispatch_timer
, m
);
209 (void) sd_event_source_set_description(m
->timer_event_source
, "mount-timer");
214 static void mount_unwatch_control_pid(Mount
*m
) {
217 if (m
->control_pid
<= 0)
220 unit_unwatch_pid(UNIT(m
), m
->control_pid
);
224 static void mount_parameters_done(MountParameters
*p
) {
231 p
->what
= p
->options
= p
->fstype
= NULL
;
234 static void mount_done(Unit
*u
) {
239 m
->where
= mfree(m
->where
);
241 mount_parameters_done(&m
->parameters_proc_self_mountinfo
);
242 mount_parameters_done(&m
->parameters_fragment
);
244 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
245 exec_command_done_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
246 m
->control_command
= NULL
;
248 mount_unwatch_control_pid(m
);
250 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
253 _pure_
static MountParameters
* get_mount_parameters_fragment(Mount
*m
) {
256 if (m
->from_fragment
)
257 return &m
->parameters_fragment
;
262 _pure_
static MountParameters
* get_mount_parameters(Mount
*m
) {
265 if (m
->from_proc_self_mountinfo
)
266 return &m
->parameters_proc_self_mountinfo
;
268 return get_mount_parameters_fragment(m
);
271 static int mount_add_mount_links(Mount
*m
) {
272 _cleanup_free_
char *parent
= NULL
;
281 if (!path_equal(m
->where
, "/")) {
282 /* Adds in links to other mount points that might lie further
283 * up in the hierarchy */
285 parent
= dirname_malloc(m
->where
);
289 r
= unit_require_mounts_for(UNIT(m
), parent
);
294 /* Adds in links to other mount points that might be needed
295 * for the source path (if this is a bind mount or a loop mount) to be
297 pm
= get_mount_parameters_fragment(m
);
298 if (pm
&& pm
->what
&&
299 path_is_absolute(pm
->what
) &&
300 (mount_is_bind(pm
) || mount_is_loop(pm
) || !mount_is_network(pm
))) {
302 r
= unit_require_mounts_for(UNIT(m
), pm
->what
);
307 /* Adds in links to other units that use this path or paths
308 * further down in the hierarchy */
309 s
= manager_get_units_requiring_mounts_for(UNIT(m
)->manager
, m
->where
);
310 SET_FOREACH(other
, s
, i
) {
312 if (other
->load_state
!= UNIT_LOADED
)
315 if (other
== UNIT(m
))
318 r
= unit_add_dependency(other
, UNIT_AFTER
, UNIT(m
), true);
322 if (UNIT(m
)->fragment_path
) {
323 /* If we have fragment configuration, then make this dependency required */
324 r
= unit_add_dependency(other
, UNIT_REQUIRES
, UNIT(m
), true);
333 static int mount_add_device_links(Mount
*m
) {
335 bool device_wants_mount
= false;
340 p
= get_mount_parameters(m
);
347 if (mount_is_bind(p
))
350 if (!is_device_path(p
->what
))
353 /* /dev/root is a really weird thing, it's not a real device,
354 * but just a path the kernel exports for the root file system
355 * specified on the kernel command line. Ignore it here. */
356 if (path_equal(p
->what
, "/dev/root"))
359 if (path_equal(m
->where
, "/"))
362 if (mount_is_auto(p
) && !mount_is_automount(p
) && MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
363 device_wants_mount
= true;
365 r
= unit_add_node_link(UNIT(m
), p
->what
, device_wants_mount
, m
->from_fragment
? UNIT_BINDS_TO
: UNIT_REQUIRES
);
372 static int mount_add_quota_links(Mount
*m
) {
378 if (!MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
381 p
= get_mount_parameters_fragment(m
);
388 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
, NULL
, true);
392 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
, NULL
, true);
399 static bool should_umount(Mount
*m
) {
402 if (PATH_IN_SET(m
->where
, "/", "/usr") ||
403 path_startswith(m
->where
, "/run/initramfs"))
406 p
= get_mount_parameters(m
);
407 if (p
&& fstab_test_option(p
->options
, "x-initrd.mount\0") &&
414 static int mount_add_default_dependencies(Mount
*m
) {
421 if (!UNIT(m
)->default_dependencies
)
424 if (!MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
427 /* We do not add any default dependencies to /, /usr or
428 * /run/initramfs/, since they are guaranteed to stay
429 * mounted the whole time, since our system is on it.
430 * Also, don't bother with anything mounted below virtual
431 * file systems, it's also going to be virtual, and hence
432 * not worth the effort. */
433 if (PATH_IN_SET(m
->where
, "/", "/usr") ||
434 path_startswith(m
->where
, "/run/initramfs") ||
435 path_startswith(m
->where
, "/proc") ||
436 path_startswith(m
->where
, "/sys") ||
437 path_startswith(m
->where
, "/dev"))
440 p
= get_mount_parameters(m
);
444 if (mount_is_network(p
)) {
445 /* We order ourselves after network.target. This is
446 * primarily useful at shutdown: services that take
447 * down the network should order themselves before
448 * network.target, so that they are shut down only
449 * after this mount unit is stopped. */
451 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, SPECIAL_NETWORK_TARGET
, NULL
, true);
455 /* We pull in network-online.target, and order
456 * ourselves after it. This is useful at start-up to
457 * actively pull in tools that want to be started
458 * before we start mounting network file systems, and
459 * whose purpose it is to delay this until the network
462 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, SPECIAL_NETWORK_ONLINE_TARGET
, NULL
, true);
466 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
468 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
470 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, NULL
, true);
474 if (should_umount(m
)) {
475 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
483 static int mount_verify(Mount
*m
) {
484 _cleanup_free_
char *e
= NULL
;
489 if (UNIT(m
)->load_state
!= UNIT_LOADED
)
492 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
)
495 r
= unit_name_from_path(m
->where
, ".mount", &e
);
497 return log_unit_error_errno(UNIT(m
), r
, "Failed to generate unit name from mount path: %m");
499 if (!unit_has_name(UNIT(m
), e
)) {
500 log_unit_error(UNIT(m
), "Where= setting doesn't match unit name. Refusing.");
504 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
)) {
505 log_unit_error(UNIT(m
), "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
509 if (UNIT(m
)->fragment_path
&& !m
->parameters_fragment
.what
) {
510 log_unit_error(UNIT(m
), "What= setting is missing. Refusing.");
514 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
) {
515 log_unit_error(UNIT(m
), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
522 static int mount_add_extras(Mount
*m
) {
528 if (u
->fragment_path
)
529 m
->from_fragment
= true;
532 r
= unit_name_to_path(u
->id
, &m
->where
);
537 path_kill_slashes(m
->where
);
539 if (!u
->description
) {
540 r
= unit_set_description(u
, m
->where
);
545 r
= mount_add_device_links(m
);
549 r
= mount_add_mount_links(m
);
553 r
= mount_add_quota_links(m
);
557 r
= unit_patch_contexts(u
);
561 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
565 r
= unit_set_default_slice(u
);
569 r
= mount_add_default_dependencies(m
);
576 static int mount_load(Unit
*u
) {
581 assert(u
->load_state
== UNIT_STUB
);
583 if (m
->from_proc_self_mountinfo
)
584 r
= unit_load_fragment_and_dropin_optional(u
);
586 r
= unit_load_fragment_and_dropin(u
);
591 /* This is a new unit? Then let's add in some extras */
592 if (u
->load_state
== UNIT_LOADED
) {
593 r
= mount_add_extras(m
);
598 return mount_verify(m
);
601 static void mount_set_state(Mount
*m
, MountState state
) {
602 MountState old_state
;
605 old_state
= m
->state
;
608 if (!mount_state_active(state
)) {
609 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
610 mount_unwatch_control_pid(m
);
611 m
->control_command
= NULL
;
612 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
615 if (state
!= old_state
)
616 log_unit_debug(UNIT(m
), "Changed %s -> %s", mount_state_to_string(old_state
), mount_state_to_string(state
));
618 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
619 m
->reload_result
= MOUNT_SUCCESS
;
622 static int mount_coldplug(Unit
*u
) {
624 MountState new_state
= MOUNT_DEAD
;
628 assert(m
->state
== MOUNT_DEAD
);
630 if (m
->deserialized_state
!= m
->state
)
631 new_state
= m
->deserialized_state
;
632 else if (m
->from_proc_self_mountinfo
)
633 new_state
= MOUNT_MOUNTED
;
635 if (new_state
== m
->state
)
638 if (m
->control_pid
> 0 &&
639 pid_is_unwaited(m
->control_pid
) &&
640 mount_state_active(new_state
)) {
642 r
= unit_watch_pid(UNIT(m
), m
->control_pid
);
646 r
= mount_arm_timer(m
, usec_add(u
->state_change_timestamp
.monotonic
, m
->timeout_usec
));
651 mount_set_state(m
, new_state
);
655 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
662 p
= get_mount_parameters(m
);
665 "%sMount State: %s\n"
669 "%sFile System Type: %s\n"
671 "%sFrom /proc/self/mountinfo: %s\n"
672 "%sFrom fragment: %s\n"
673 "%sDirectoryMode: %04o\n",
674 prefix
, mount_state_to_string(m
->state
),
675 prefix
, mount_result_to_string(m
->result
),
677 prefix
, p
? strna(p
->what
) : "n/a",
678 prefix
, p
? strna(p
->fstype
) : "n/a",
679 prefix
, p
? strna(p
->options
) : "n/a",
680 prefix
, yes_no(m
->from_proc_self_mountinfo
),
681 prefix
, yes_no(m
->from_fragment
),
682 prefix
, m
->directory_mode
);
684 if (m
->control_pid
> 0)
686 "%sControl PID: "PID_FMT
"\n",
687 prefix
, m
->control_pid
);
689 exec_context_dump(&m
->exec_context
, f
, prefix
);
690 kill_context_dump(&m
->kill_context
, f
, prefix
);
693 static int mount_spawn(Mount
*m
, ExecCommand
*c
, pid_t
*_pid
) {
696 ExecParameters exec_params
= {
697 .apply_permissions
= true,
698 .apply_chroot
= true,
699 .apply_tty_stdin
= true,
709 (void) unit_realize_cgroup(UNIT(m
));
710 if (m
->reset_cpu_usage
) {
711 (void) unit_reset_cpu_usage(UNIT(m
));
712 m
->reset_cpu_usage
= false;
715 r
= unit_setup_exec_runtime(UNIT(m
));
719 r
= mount_arm_timer(m
, usec_add(now(CLOCK_MONOTONIC
), m
->timeout_usec
));
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
);
730 r
= exec_spawn(UNIT(m
),
739 r
= unit_watch_pid(UNIT(m
), pid
);
741 /* FIXME: we need to do something here */
749 static void mount_enter_dead(Mount
*m
, MountResult f
) {
752 if (f
!= MOUNT_SUCCESS
)
755 exec_runtime_destroy(m
->exec_runtime
);
756 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
758 exec_context_destroy_runtime_directory(&m
->exec_context
, manager_get_runtime_prefix(UNIT(m
)->manager
));
760 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
763 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
766 if (f
!= MOUNT_SUCCESS
)
769 mount_set_state(m
, MOUNT_MOUNTED
);
772 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
777 if (f
!= MOUNT_SUCCESS
)
780 r
= unit_kill_context(
783 (state
!= MOUNT_MOUNTING_SIGTERM
&& state
!= MOUNT_UNMOUNTING_SIGTERM
&& state
!= MOUNT_REMOUNTING_SIGTERM
) ?
784 KILL_KILL
: KILL_TERMINATE
,
792 r
= mount_arm_timer(m
, usec_add(now(CLOCK_MONOTONIC
), m
->timeout_usec
));
796 mount_set_state(m
, state
);
797 } else if (state
== MOUNT_REMOUNTING_SIGTERM
)
798 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
799 else if (state
== MOUNT_REMOUNTING_SIGKILL
)
800 mount_enter_mounted(m
, MOUNT_SUCCESS
);
801 else if (state
== MOUNT_MOUNTING_SIGTERM
)
802 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_SUCCESS
);
803 else if (state
== MOUNT_UNMOUNTING_SIGTERM
)
804 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
806 mount_enter_dead(m
, MOUNT_SUCCESS
);
811 log_unit_warning_errno(UNIT(m
), r
, "Failed to kill processes: %m");
813 if (state
== MOUNT_REMOUNTING_SIGTERM
|| state
== MOUNT_REMOUNTING_SIGKILL
)
814 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
816 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
819 static void mount_enter_unmounting(Mount
*m
) {
824 /* Start counting our attempts */
825 if (!IN_SET(m
->state
,
827 MOUNT_UNMOUNTING_SIGTERM
,
828 MOUNT_UNMOUNTING_SIGKILL
))
829 m
->n_retry_umount
= 0;
831 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
832 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
834 r
= exec_command_set(m
->control_command
, UMOUNT_PATH
, m
->where
, NULL
);
838 mount_unwatch_control_pid(m
);
840 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
844 mount_set_state(m
, MOUNT_UNMOUNTING
);
849 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'umount' task: %m");
850 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
853 static int mount_get_opts(Mount
*m
, char **ret
) {
854 return fstab_filter_options(m
->parameters_fragment
.options
,
855 "nofail\0" "noauto\0" "auto\0", NULL
, NULL
, ret
);
858 static void mount_enter_mounting(Mount
*m
) {
864 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
865 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
867 r
= unit_fail_if_symlink(UNIT(m
), m
->where
);
871 (void) mkdir_p_label(m
->where
, m
->directory_mode
);
873 unit_warn_if_dir_nonempty(UNIT(m
), m
->where
);
875 /* Create the source directory for bind-mounts if needed */
876 p
= get_mount_parameters_fragment(m
);
877 if (p
&& mount_is_bind(p
))
878 (void) mkdir_p_label(p
->what
, m
->directory_mode
);
880 if (m
->from_fragment
) {
881 _cleanup_free_
char *opts
= NULL
;
883 r
= mount_get_opts(m
, &opts
);
887 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
888 m
->parameters_fragment
.what
, m
->where
, NULL
);
889 if (r
>= 0 && m
->sloppy_options
)
890 r
= exec_command_append(m
->control_command
, "-s", NULL
);
891 if (r
>= 0 && m
->parameters_fragment
.fstype
)
892 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
893 if (r
>= 0 && !isempty(opts
))
894 r
= exec_command_append(m
->control_command
, "-o", opts
, NULL
);
901 mount_unwatch_control_pid(m
);
903 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
907 mount_set_state(m
, MOUNT_MOUNTING
);
912 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'mount' task: %m");
913 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
916 static void mount_enter_remounting(Mount
*m
) {
921 m
->control_command_id
= MOUNT_EXEC_REMOUNT
;
922 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_REMOUNT
;
924 if (m
->from_fragment
) {
927 if (m
->parameters_fragment
.options
)
928 o
= strjoina("remount,", m
->parameters_fragment
.options
);
932 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
933 m
->parameters_fragment
.what
, m
->where
,
935 if (r
>= 0 && m
->sloppy_options
)
936 r
= exec_command_append(m
->control_command
, "-s", NULL
);
937 if (r
>= 0 && m
->parameters_fragment
.fstype
)
938 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
945 mount_unwatch_control_pid(m
);
947 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
951 mount_set_state(m
, MOUNT_REMOUNTING
);
956 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'remount' task: %m");
957 m
->reload_result
= MOUNT_FAILURE_RESOURCES
;
958 mount_enter_mounted(m
, MOUNT_SUCCESS
);
961 static int mount_start(Unit
*u
) {
967 /* We cannot fulfill this request right now, try again later
969 if (m
->state
== MOUNT_UNMOUNTING
||
970 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
971 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
972 m
->state
== MOUNT_MOUNTING_SIGTERM
||
973 m
->state
== MOUNT_MOUNTING_SIGKILL
)
977 if (m
->state
== MOUNT_MOUNTING
)
980 assert(m
->state
== MOUNT_DEAD
|| m
->state
== MOUNT_FAILED
);
982 r
= unit_start_limit_test(u
);
984 mount_enter_dead(m
, MOUNT_FAILURE_START_LIMIT_HIT
);
988 m
->result
= MOUNT_SUCCESS
;
989 m
->reload_result
= MOUNT_SUCCESS
;
990 m
->reset_cpu_usage
= true;
992 mount_enter_mounting(m
);
996 static int mount_stop(Unit
*u
) {
1002 if (m
->state
== MOUNT_UNMOUNTING
||
1003 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1004 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
1005 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1006 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1009 assert(m
->state
== MOUNT_MOUNTING
||
1010 m
->state
== MOUNT_MOUNTING_DONE
||
1011 m
->state
== MOUNT_MOUNTED
||
1012 m
->state
== MOUNT_REMOUNTING
||
1013 m
->state
== MOUNT_REMOUNTING_SIGTERM
||
1014 m
->state
== MOUNT_REMOUNTING_SIGKILL
);
1016 mount_enter_unmounting(m
);
1020 static int mount_reload(Unit
*u
) {
1021 Mount
*m
= MOUNT(u
);
1025 if (m
->state
== MOUNT_MOUNTING_DONE
)
1028 assert(m
->state
== MOUNT_MOUNTED
);
1030 mount_enter_remounting(m
);
1034 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1035 Mount
*m
= MOUNT(u
);
1041 unit_serialize_item(u
, f
, "state", mount_state_to_string(m
->state
));
1042 unit_serialize_item(u
, f
, "result", mount_result_to_string(m
->result
));
1043 unit_serialize_item(u
, f
, "reload-result", mount_result_to_string(m
->reload_result
));
1045 if (m
->control_pid
> 0)
1046 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, m
->control_pid
);
1048 if (m
->control_command_id
>= 0)
1049 unit_serialize_item(u
, f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1054 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1055 Mount
*m
= MOUNT(u
);
1062 if (streq(key
, "state")) {
1065 if ((state
= mount_state_from_string(value
)) < 0)
1066 log_unit_debug(u
, "Failed to parse state value: %s", value
);
1068 m
->deserialized_state
= state
;
1069 } else if (streq(key
, "result")) {
1072 f
= mount_result_from_string(value
);
1074 log_unit_debug(u
, "Failed to parse result value: %s", value
);
1075 else if (f
!= MOUNT_SUCCESS
)
1078 } else if (streq(key
, "reload-result")) {
1081 f
= mount_result_from_string(value
);
1083 log_unit_debug(u
, "Failed to parse reload result value: %s", value
);
1084 else if (f
!= MOUNT_SUCCESS
)
1085 m
->reload_result
= f
;
1087 } else if (streq(key
, "control-pid")) {
1090 if (parse_pid(value
, &pid
) < 0)
1091 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
1093 m
->control_pid
= pid
;
1094 } else if (streq(key
, "control-command")) {
1095 MountExecCommand id
;
1097 id
= mount_exec_command_from_string(value
);
1099 log_unit_debug(u
, "Failed to parse exec-command value: %s", value
);
1101 m
->control_command_id
= id
;
1102 m
->control_command
= m
->exec_command
+ id
;
1105 log_unit_debug(u
, "Unknown serialization key: %s", key
);
1110 _pure_
static UnitActiveState
mount_active_state(Unit
*u
) {
1113 return state_translation_table
[MOUNT(u
)->state
];
1116 _pure_
static const char *mount_sub_state_to_string(Unit
*u
) {
1119 return mount_state_to_string(MOUNT(u
)->state
);
1122 _pure_
static bool mount_check_gc(Unit
*u
) {
1123 Mount
*m
= MOUNT(u
);
1127 return m
->from_proc_self_mountinfo
;
1130 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1131 Mount
*m
= MOUNT(u
);
1137 if (pid
!= m
->control_pid
)
1142 if (is_clean_exit(code
, status
, NULL
))
1144 else if (code
== CLD_EXITED
)
1145 f
= MOUNT_FAILURE_EXIT_CODE
;
1146 else if (code
== CLD_KILLED
)
1147 f
= MOUNT_FAILURE_SIGNAL
;
1148 else if (code
== CLD_DUMPED
)
1149 f
= MOUNT_FAILURE_CORE_DUMP
;
1151 assert_not_reached("Unknown code");
1153 if (f
!= MOUNT_SUCCESS
)
1156 if (m
->control_command
) {
1157 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1159 m
->control_command
= NULL
;
1160 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1163 log_unit_full(u
, f
== MOUNT_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
1164 "Mount process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
1166 /* Note that mount(8) returning and the kernel sending us a
1167 * mount table change event might happen out-of-order. If an
1168 * operation succeed we assume the kernel will follow soon too
1169 * and already change into the resulting state. If it fails
1170 * we check if the kernel still knows about the mount. and
1171 * change state accordingly. */
1175 case MOUNT_MOUNTING
:
1176 case MOUNT_MOUNTING_DONE
:
1177 case MOUNT_MOUNTING_SIGKILL
:
1178 case MOUNT_MOUNTING_SIGTERM
:
1180 if (f
== MOUNT_SUCCESS
)
1181 mount_enter_mounted(m
, f
);
1182 else if (m
->from_proc_self_mountinfo
)
1183 mount_enter_mounted(m
, f
);
1185 mount_enter_dead(m
, f
);
1188 case MOUNT_REMOUNTING
:
1189 case MOUNT_REMOUNTING_SIGKILL
:
1190 case MOUNT_REMOUNTING_SIGTERM
:
1192 m
->reload_result
= f
;
1193 if (m
->from_proc_self_mountinfo
)
1194 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1196 mount_enter_dead(m
, MOUNT_SUCCESS
);
1200 case MOUNT_UNMOUNTING
:
1201 case MOUNT_UNMOUNTING_SIGKILL
:
1202 case MOUNT_UNMOUNTING_SIGTERM
:
1204 if (f
== MOUNT_SUCCESS
) {
1206 if (m
->from_proc_self_mountinfo
) {
1208 /* Still a mount point? If so, let's
1209 * try again. Most likely there were
1210 * multiple mount points stacked on
1211 * top of each other. Note that due to
1212 * the io event priority logic we can
1213 * be sure the new mountinfo is loaded
1214 * before we process the SIGCHLD for
1215 * the mount command. */
1217 if (m
->n_retry_umount
< RETRY_UMOUNT_MAX
) {
1218 log_unit_debug(u
, "Mount still present, trying again.");
1219 m
->n_retry_umount
++;
1220 mount_enter_unmounting(m
);
1222 log_unit_debug(u
, "Mount still present after %u attempts to unmount, giving up.", m
->n_retry_umount
);
1223 mount_enter_mounted(m
, f
);
1226 mount_enter_dead(m
, f
);
1228 } else if (m
->from_proc_self_mountinfo
)
1229 mount_enter_mounted(m
, f
);
1231 mount_enter_dead(m
, f
);
1235 assert_not_reached("Uh, control process died at wrong time.");
1238 /* Notify clients about changed exit status */
1239 unit_add_to_dbus_queue(u
);
1242 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1243 Mount
*m
= MOUNT(userdata
);
1246 assert(m
->timer_event_source
== source
);
1250 case MOUNT_MOUNTING
:
1251 case MOUNT_MOUNTING_DONE
:
1252 log_unit_warning(UNIT(m
), "Mounting timed out. Stopping.");
1253 mount_enter_signal(m
, MOUNT_MOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1256 case MOUNT_REMOUNTING
:
1257 log_unit_warning(UNIT(m
), "Remounting timed out. Stopping.");
1258 m
->reload_result
= MOUNT_FAILURE_TIMEOUT
;
1259 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1262 case MOUNT_UNMOUNTING
:
1263 log_unit_warning(UNIT(m
), "Unmounting timed out. Stopping.");
1264 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1267 case MOUNT_MOUNTING_SIGTERM
:
1268 if (m
->kill_context
.send_sigkill
) {
1269 log_unit_warning(UNIT(m
), "Mounting timed out. Killing.");
1270 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1272 log_unit_warning(UNIT(m
), "Mounting timed out. Skipping SIGKILL. Ignoring.");
1274 if (m
->from_proc_self_mountinfo
)
1275 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1277 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1281 case MOUNT_REMOUNTING_SIGTERM
:
1282 if (m
->kill_context
.send_sigkill
) {
1283 log_unit_warning(UNIT(m
), "Remounting timed out. Killing.");
1284 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1286 log_unit_warning(UNIT(m
), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1288 if (m
->from_proc_self_mountinfo
)
1289 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1291 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1295 case MOUNT_UNMOUNTING_SIGTERM
:
1296 if (m
->kill_context
.send_sigkill
) {
1297 log_unit_warning(UNIT(m
), "Unmounting timed out. Killing.");
1298 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1300 log_unit_warning(UNIT(m
), "Unmounting timed out. Skipping SIGKILL. Ignoring.");
1302 if (m
->from_proc_self_mountinfo
)
1303 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1305 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1309 case MOUNT_MOUNTING_SIGKILL
:
1310 case MOUNT_REMOUNTING_SIGKILL
:
1311 case MOUNT_UNMOUNTING_SIGKILL
:
1312 log_unit_warning(UNIT(m
),"Mount process still around after SIGKILL. Ignoring.");
1314 if (m
->from_proc_self_mountinfo
)
1315 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1317 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1321 assert_not_reached("Timeout at wrong time.");
1327 static int mount_setup_unit(
1331 const char *options
,
1335 _cleanup_free_
char *e
= NULL
, *w
= NULL
, *o
= NULL
, *f
= NULL
;
1336 bool load_extras
= false;
1338 bool delete, changed
= false;
1348 /* Ignore API mount points. They should never be referenced in
1349 * dependencies ever. */
1350 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1353 if (streq(fstype
, "autofs"))
1356 /* probably some kind of swap, ignore */
1357 if (!is_path(where
))
1360 r
= unit_name_from_path(where
, ".mount", &e
);
1364 u
= manager_get_unit(m
, e
);
1368 u
= unit_new(m
, sizeof(Mount
));
1372 r
= unit_add_name(u
, e
);
1376 MOUNT(u
)->where
= strdup(where
);
1377 if (!MOUNT(u
)->where
) {
1382 u
->source_path
= strdup("/proc/self/mountinfo");
1383 if (!u
->source_path
) {
1388 if (MANAGER_IS_SYSTEM(m
)) {
1391 target
= mount_needs_network(options
, fstype
) ? SPECIAL_REMOTE_FS_TARGET
: SPECIAL_LOCAL_FS_TARGET
;
1392 r
= unit_add_dependency_by_name(u
, UNIT_BEFORE
, target
, NULL
, true);
1396 if (should_umount(MOUNT(u
))) {
1397 r
= unit_add_dependency_by_name(u
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
1403 unit_add_to_load_queue(u
);
1408 if (!MOUNT(u
)->where
) {
1409 MOUNT(u
)->where
= strdup(where
);
1410 if (!MOUNT(u
)->where
) {
1416 if (MANAGER_IS_SYSTEM(m
) &&
1417 mount_needs_network(options
, fstype
)) {
1418 /* _netdev option may have shown up late, or on a
1419 * remount. Add remote-fs dependencies, even though
1420 * local-fs ones may already be there. */
1421 unit_add_dependency_by_name(u
, UNIT_BEFORE
, SPECIAL_REMOTE_FS_TARGET
, NULL
, true);
1425 if (u
->load_state
== UNIT_NOT_FOUND
) {
1426 u
->load_state
= UNIT_LOADED
;
1429 /* Load in the extras later on, after we
1430 * finished initialization of the unit */
1437 o
= strdup(options
);
1439 if (!w
|| !o
|| !f
) {
1444 p
= &MOUNT(u
)->parameters_proc_self_mountinfo
;
1446 changed
= changed
||
1447 !streq_ptr(p
->options
, options
) ||
1448 !streq_ptr(p
->what
, what
) ||
1449 !streq_ptr(p
->fstype
, fstype
);
1452 MOUNT(u
)->is_mounted
= true;
1453 MOUNT(u
)->just_mounted
= !MOUNT(u
)->from_proc_self_mountinfo
;
1454 MOUNT(u
)->just_changed
= changed
;
1457 MOUNT(u
)->from_proc_self_mountinfo
= true;
1472 r
= mount_add_extras(MOUNT(u
));
1478 unit_add_to_dbus_queue(u
);
1483 log_warning_errno(r
, "Failed to set up mount unit: %m");
1491 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1492 _cleanup_(mnt_free_tablep
) struct libmnt_table
*t
= NULL
;
1493 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*i
= NULL
;
1498 t
= mnt_new_table();
1502 i
= mnt_new_iter(MNT_ITER_FORWARD
);
1506 r
= mnt_table_parse_mtab(t
, NULL
);
1508 return log_error_errno(r
, "Failed to parse /proc/self/mountinfo: %m");
1512 const char *device
, *path
, *options
, *fstype
;
1513 _cleanup_free_
char *d
= NULL
, *p
= NULL
;
1514 struct libmnt_fs
*fs
;
1517 k
= mnt_table_next_fs(t
, i
, &fs
);
1521 return log_error_errno(k
, "Failed to get next entry from /proc/self/mountinfo: %m");
1523 device
= mnt_fs_get_source(fs
);
1524 path
= mnt_fs_get_target(fs
);
1525 options
= mnt_fs_get_options(fs
);
1526 fstype
= mnt_fs_get_fstype(fs
);
1528 if (!device
|| !path
)
1531 if (cunescape(device
, UNESCAPE_RELAX
, &d
) < 0)
1534 if (cunescape(path
, UNESCAPE_RELAX
, &p
) < 0)
1537 (void) device_found_node(m
, d
, true, DEVICE_FOUND_MOUNT
, set_flags
);
1539 k
= mount_setup_unit(m
, d
, p
, options
, fstype
, set_flags
);
1540 if (r
== 0 && k
< 0)
1547 static void mount_shutdown(Manager
*m
) {
1551 m
->mount_event_source
= sd_event_source_unref(m
->mount_event_source
);
1553 mnt_unref_monitor(m
->mount_monitor
);
1554 m
->mount_monitor
= NULL
;
1557 static int mount_get_timeout(Unit
*u
, usec_t
*timeout
) {
1558 Mount
*m
= MOUNT(u
);
1562 if (!m
->timer_event_source
)
1565 r
= sd_event_source_get_time(m
->timer_event_source
, &t
);
1568 if (t
== USEC_INFINITY
)
1575 static void mount_enumerate(Manager
*m
) {
1582 if (!m
->mount_monitor
) {
1585 m
->mount_monitor
= mnt_new_monitor();
1586 if (!m
->mount_monitor
) {
1591 r
= mnt_monitor_enable_kernel(m
->mount_monitor
, 1);
1593 log_error_errno(r
, "Failed to enable watching of kernel mount events: %m");
1597 r
= mnt_monitor_enable_userspace(m
->mount_monitor
, 1, NULL
);
1599 log_error_errno(r
, "Failed to enable watching of userspace mount events: %m");
1603 /* mnt_unref_monitor() will close the fd */
1604 fd
= r
= mnt_monitor_get_fd(m
->mount_monitor
);
1606 log_error_errno(r
, "Failed to acquire watch file descriptor: %m");
1610 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fd
, EPOLLIN
, mount_dispatch_io
, m
);
1612 log_error_errno(r
, "Failed to watch mount file descriptor: %m");
1616 r
= sd_event_source_set_priority(m
->mount_event_source
, -10);
1618 log_error_errno(r
, "Failed to adjust mount watch priority: %m");
1622 (void) sd_event_source_set_description(m
->mount_event_source
, "mount-monitor-dispatch");
1625 r
= mount_load_proc_self_mountinfo(m
, false);
1635 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
1636 _cleanup_set_free_ Set
*around
= NULL
, *gone
= NULL
;
1637 Manager
*m
= userdata
;
1644 assert(revents
& EPOLLIN
);
1646 if (fd
== mnt_monitor_get_fd(m
->mount_monitor
)) {
1647 bool rescan
= false;
1649 /* Drain all events and verify that the event is valid.
1651 * Note that libmount also monitors /run/mount mkdir if the
1652 * directory does not exist yet. The mkdir may generate event
1653 * which is irrelevant for us.
1655 * error: r < 0; valid: r == 0, false positive: rc == 1 */
1657 r
= mnt_monitor_next_change(m
->mount_monitor
, NULL
, NULL
);
1661 return log_error_errno(r
, "Failed to drain libmount events");
1664 log_debug("libmount event [rescan: %s]", yes_no(rescan
));
1669 r
= mount_load_proc_self_mountinfo(m
, true);
1671 /* Reset flags, just in case, for later calls */
1672 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1673 Mount
*mount
= MOUNT(u
);
1675 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1681 manager_dispatch_load_queue(m
);
1683 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1684 Mount
*mount
= MOUNT(u
);
1686 if (!mount
->is_mounted
) {
1688 /* A mount point is not around right now. It
1689 * might be gone, or might never have
1692 if (mount
->from_proc_self_mountinfo
&&
1693 mount
->parameters_proc_self_mountinfo
.what
) {
1695 /* Remember that this device might just have disappeared */
1696 if (set_ensure_allocated(&gone
, &string_hash_ops
) < 0 ||
1697 set_put(gone
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1698 log_oom(); /* we don't care too much about OOM here... */
1701 mount
->from_proc_self_mountinfo
= false;
1703 switch (mount
->state
) {
1706 /* This has just been unmounted by
1707 * somebody else, follow the state
1709 mount
->result
= MOUNT_SUCCESS
; /* make sure we forget any earlier umount failures */
1710 mount_enter_dead(mount
, MOUNT_SUCCESS
);
1717 } else if (mount
->just_mounted
|| mount
->just_changed
) {
1719 /* A mount point was added or changed */
1721 switch (mount
->state
) {
1725 /* This has just been mounted by
1726 * somebody else, follow the state
1728 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
1731 case MOUNT_MOUNTING
:
1732 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
1736 /* Nothing really changed, but let's
1737 * issue an notification call
1738 * nonetheless, in case somebody is
1739 * waiting for this. (e.g. file system
1740 * ro/rw remounts.) */
1741 mount_set_state(mount
, mount
->state
);
1746 if (mount
->is_mounted
&&
1747 mount
->from_proc_self_mountinfo
&&
1748 mount
->parameters_proc_self_mountinfo
.what
) {
1750 if (set_ensure_allocated(&around
, &string_hash_ops
) < 0 ||
1751 set_put(around
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1755 /* Reset the flags for later calls */
1756 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1759 SET_FOREACH(what
, gone
, i
) {
1760 if (set_contains(around
, what
))
1763 /* Let the device units know that the device is no longer mounted */
1764 (void) device_found_node(m
, what
, false, DEVICE_FOUND_MOUNT
, true);
1770 static void mount_reset_failed(Unit
*u
) {
1771 Mount
*m
= MOUNT(u
);
1775 if (m
->state
== MOUNT_FAILED
)
1776 mount_set_state(m
, MOUNT_DEAD
);
1778 m
->result
= MOUNT_SUCCESS
;
1779 m
->reload_result
= MOUNT_SUCCESS
;
1782 static int mount_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
1783 return unit_kill_common(u
, who
, signo
, -1, MOUNT(u
)->control_pid
, error
);
1786 static int mount_control_pid(Unit
*u
) {
1787 Mount
*m
= MOUNT(u
);
1791 return m
->control_pid
;
1794 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
1795 [MOUNT_EXEC_MOUNT
] = "ExecMount",
1796 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
1797 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
1800 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
1802 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
1803 [MOUNT_SUCCESS
] = "success",
1804 [MOUNT_FAILURE_RESOURCES
] = "resources",
1805 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
1806 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
1807 [MOUNT_FAILURE_SIGNAL
] = "signal",
1808 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump",
1809 [MOUNT_FAILURE_START_LIMIT_HIT
] = "start-limit-hit",
1812 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
1814 const UnitVTable mount_vtable
= {
1815 .object_size
= sizeof(Mount
),
1816 .exec_context_offset
= offsetof(Mount
, exec_context
),
1817 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
1818 .kill_context_offset
= offsetof(Mount
, kill_context
),
1819 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
1825 .private_section
= "Mount",
1831 .coldplug
= mount_coldplug
,
1835 .start
= mount_start
,
1837 .reload
= mount_reload
,
1841 .serialize
= mount_serialize
,
1842 .deserialize_item
= mount_deserialize_item
,
1844 .active_state
= mount_active_state
,
1845 .sub_state_to_string
= mount_sub_state_to_string
,
1847 .check_gc
= mount_check_gc
,
1849 .sigchld_event
= mount_sigchld_event
,
1851 .reset_failed
= mount_reset_failed
,
1853 .control_pid
= mount_control_pid
,
1855 .bus_vtable
= bus_mount_vtable
,
1856 .bus_set_property
= bus_mount_set_property
,
1857 .bus_commit_properties
= bus_mount_commit_properties
,
1859 .get_timeout
= mount_get_timeout
,
1861 .can_transient
= true,
1863 .enumerate
= mount_enumerate
,
1864 .shutdown
= mount_shutdown
,
1866 .status_message_formats
= {
1867 .starting_stopping
= {
1868 [0] = "Mounting %s...",
1869 [1] = "Unmounting %s...",
1871 .finished_start_job
= {
1872 [JOB_DONE
] = "Mounted %s.",
1873 [JOB_FAILED
] = "Failed to mount %s.",
1874 [JOB_TIMEOUT
] = "Timed out mounting %s.",
1876 .finished_stop_job
= {
1877 [JOB_DONE
] = "Unmounted %s.",
1878 [JOB_FAILED
] = "Failed unmounting %s.",
1879 [JOB_TIMEOUT
] = "Timed out unmounting %s.",