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>
27 #include "sd-messages.h"
29 #include "dbus-mount.h"
31 #include "exit-status.h"
32 #include "formats-util.h"
33 #include "fstab-util.h"
37 #include "mount-setup.h"
39 #include "path-util.h"
40 #include "smack-util.h"
42 #include "string-util.h"
44 #include "unit-name.h"
47 #define RETRY_UMOUNT_MAX 32
49 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table
*, mnt_free_table
);
50 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter
*, mnt_free_iter
);
52 static const UnitActiveState state_translation_table
[_MOUNT_STATE_MAX
] = {
53 [MOUNT_DEAD
] = UNIT_INACTIVE
,
54 [MOUNT_MOUNTING
] = UNIT_ACTIVATING
,
55 [MOUNT_MOUNTING_DONE
] = UNIT_ACTIVE
,
56 [MOUNT_MOUNTED
] = UNIT_ACTIVE
,
57 [MOUNT_REMOUNTING
] = UNIT_RELOADING
,
58 [MOUNT_UNMOUNTING
] = UNIT_DEACTIVATING
,
59 [MOUNT_MOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
60 [MOUNT_MOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
61 [MOUNT_REMOUNTING_SIGTERM
] = UNIT_RELOADING
,
62 [MOUNT_REMOUNTING_SIGKILL
] = UNIT_RELOADING
,
63 [MOUNT_UNMOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
64 [MOUNT_UNMOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
65 [MOUNT_FAILED
] = UNIT_FAILED
68 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
69 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
71 static bool mount_needs_network(const char *options
, const char *fstype
) {
72 if (fstab_test_option(options
, "_netdev\0"))
75 if (fstype
&& fstype_is_network(fstype
))
81 static bool mount_is_network(const MountParameters
*p
) {
84 return mount_needs_network(p
->options
, p
->fstype
);
87 static bool mount_is_bind(const MountParameters
*p
) {
90 if (fstab_test_option(p
->options
, "bind\0" "rbind\0"))
93 if (p
->fstype
&& STR_IN_SET(p
->fstype
, "bind", "rbind"))
99 static bool mount_is_auto(const MountParameters
*p
) {
102 return !fstab_test_option(p
->options
, "noauto\0");
105 static bool needs_quota(const MountParameters
*p
) {
108 /* Quotas are not enabled on network filesystems,
109 * but we want them, for example, on storage connected via iscsi */
110 if (p
->fstype
&& fstype_is_network(p
->fstype
))
113 if (mount_is_bind(p
))
116 return fstab_test_option(p
->options
,
117 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
120 static void mount_init(Unit
*u
) {
124 assert(u
->load_state
== UNIT_STUB
);
126 m
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
127 m
->directory_mode
= 0755;
129 if (unit_has_name(u
, "-.mount")) {
130 /* Don't allow start/stop for root directory */
131 u
->refuse_manual_start
= true;
132 u
->refuse_manual_stop
= true;
134 /* The stdio/kmsg bridge socket is on /, in order to avoid a
135 * dep loop, don't use kmsg logging for -.mount */
136 m
->exec_context
.std_output
= u
->manager
->default_std_output
;
137 m
->exec_context
.std_error
= u
->manager
->default_std_error
;
140 /* We need to make sure that /usr/bin/mount is always called
141 * in the same process group as us, so that the autofs kernel
142 * side doesn't send us another mount request while we are
143 * already trying to comply its last one. */
144 m
->exec_context
.same_pgrp
= true;
146 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
148 u
->ignore_on_isolate
= true;
151 static int mount_arm_timer(Mount
*m
) {
156 if (m
->timeout_usec
<= 0) {
157 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
161 if (m
->timer_event_source
) {
162 r
= sd_event_source_set_time(m
->timer_event_source
, now(CLOCK_MONOTONIC
) + m
->timeout_usec
);
166 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_ONESHOT
);
169 r
= sd_event_add_time(
170 UNIT(m
)->manager
->event
,
171 &m
->timer_event_source
,
173 now(CLOCK_MONOTONIC
) + m
->timeout_usec
, 0,
174 mount_dispatch_timer
, m
);
178 (void) sd_event_source_set_description(m
->timer_event_source
, "mount-timer");
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
) {
208 m
->where
= mfree(m
->where
);
209 m
->smack_fs_root
= mfree(m
->smack_fs_root
);
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(m
);
316 if (mount_is_bind(p
))
319 if (!is_device_path(p
->what
))
322 /* /dev/root is a really weird thing, it's not a real device,
323 * but just a path the kernel exports for the root file system
324 * specified on the kernel command line. Ignore it here. */
325 if (path_equal(p
->what
, "/dev/root"))
328 if (path_equal(m
->where
, "/"))
331 if (mount_is_auto(p
) && UNIT(m
)->manager
->running_as
== MANAGER_SYSTEM
)
332 device_wants_mount
= true;
334 r
= unit_add_node_link(UNIT(m
), p
->what
, device_wants_mount
);
341 static int mount_add_quota_links(Mount
*m
) {
347 if (UNIT(m
)->manager
->running_as
!= MANAGER_SYSTEM
)
350 p
= get_mount_parameters_fragment(m
);
357 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
, NULL
, true);
361 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
, NULL
, true);
368 static bool should_umount(Mount
*m
) {
371 if (path_equal(m
->where
, "/") ||
372 path_equal(m
->where
, "/usr"))
375 p
= get_mount_parameters(m
);
376 if (p
&& fstab_test_option(p
->options
, "x-initrd.mount\0") &&
383 static int mount_add_default_dependencies(Mount
*m
) {
384 const char *after
, *after2
, *online
;
390 if (UNIT(m
)->manager
->running_as
!= MANAGER_SYSTEM
)
393 /* We do not add any default dependencies to / and /usr, since
394 * they are guaranteed to stay mounted the whole time, since
395 * our system is on it. Also, don't bother with anything
396 * mounted below virtual file systems, it's also going to be
397 * virtual, and hence not worth the effort. */
398 if (path_equal(m
->where
, "/") ||
399 path_equal(m
->where
, "/usr") ||
400 path_startswith(m
->where
, "/proc") ||
401 path_startswith(m
->where
, "/sys") ||
402 path_startswith(m
->where
, "/dev"))
405 p
= get_mount_parameters(m
);
409 if (mount_is_network(p
)) {
410 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
411 after2
= SPECIAL_NETWORK_TARGET
;
412 online
= SPECIAL_NETWORK_ONLINE_TARGET
;
414 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
419 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, NULL
, true);
424 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after2
, NULL
, true);
430 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, online
, NULL
, true);
435 if (should_umount(m
)) {
436 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
444 static int mount_verify(Mount
*m
) {
445 _cleanup_free_
char *e
= NULL
;
450 if (UNIT(m
)->load_state
!= UNIT_LOADED
)
453 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
)
456 r
= unit_name_from_path(m
->where
, ".mount", &e
);
458 return log_unit_error_errno(UNIT(m
), r
, "Failed to generate unit name from mount path: %m");
460 if (!unit_has_name(UNIT(m
), e
)) {
461 log_unit_error(UNIT(m
), "Where= setting doesn't match unit name. Refusing.");
465 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
)) {
466 log_unit_error(UNIT(m
), "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
470 if (UNIT(m
)->fragment_path
&& !m
->parameters_fragment
.what
) {
471 log_unit_error(UNIT(m
), "What= setting is missing. Refusing.");
475 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
) {
476 log_unit_error(UNIT(m
), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
483 static int mount_add_extras(Mount
*m
) {
489 if (u
->fragment_path
)
490 m
->from_fragment
= true;
493 r
= unit_name_to_path(u
->id
, &m
->where
);
498 path_kill_slashes(m
->where
);
500 if (!u
->description
) {
501 r
= unit_set_description(u
, m
->where
);
506 r
= mount_add_device_links(m
);
510 r
= mount_add_mount_links(m
);
514 r
= mount_add_quota_links(m
);
518 r
= unit_patch_contexts(u
);
522 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
526 r
= unit_set_default_slice(u
);
530 if (u
->default_dependencies
) {
531 r
= mount_add_default_dependencies(m
);
539 static int mount_load(Unit
*u
) {
544 assert(u
->load_state
== UNIT_STUB
);
546 if (m
->from_proc_self_mountinfo
)
547 r
= unit_load_fragment_and_dropin_optional(u
);
549 r
= unit_load_fragment_and_dropin(u
);
554 /* This is a new unit? Then let's add in some extras */
555 if (u
->load_state
== UNIT_LOADED
) {
556 r
= mount_add_extras(m
);
561 return mount_verify(m
);
564 static int mount_notify_automount(Mount
*m
, MountState old_state
, MountState state
) {
571 SET_FOREACH(p
, UNIT(m
)->dependencies
[UNIT_TRIGGERED_BY
], i
)
572 if (p
->type
== UNIT_AUTOMOUNT
) {
573 r
= automount_update_mount(AUTOMOUNT(p
), old_state
, state
);
581 static void mount_set_state(Mount
*m
, MountState state
) {
582 MountState old_state
;
585 old_state
= m
->state
;
588 if (state
!= MOUNT_MOUNTING
&&
589 state
!= MOUNT_MOUNTING_DONE
&&
590 state
!= MOUNT_REMOUNTING
&&
591 state
!= MOUNT_UNMOUNTING
&&
592 state
!= MOUNT_MOUNTING_SIGTERM
&&
593 state
!= MOUNT_MOUNTING_SIGKILL
&&
594 state
!= MOUNT_UNMOUNTING_SIGTERM
&&
595 state
!= MOUNT_UNMOUNTING_SIGKILL
&&
596 state
!= MOUNT_REMOUNTING_SIGTERM
&&
597 state
!= MOUNT_REMOUNTING_SIGKILL
) {
598 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
599 mount_unwatch_control_pid(m
);
600 m
->control_command
= NULL
;
601 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
604 mount_notify_automount(m
, old_state
, state
);
606 if (state
!= old_state
)
607 log_unit_debug(UNIT(m
), "Changed %s -> %s", mount_state_to_string(old_state
), mount_state_to_string(state
));
609 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
610 m
->reload_result
= MOUNT_SUCCESS
;
613 static int mount_coldplug(Unit
*u
) {
615 MountState new_state
= MOUNT_DEAD
;
619 assert(m
->state
== MOUNT_DEAD
);
621 if (m
->deserialized_state
!= m
->state
)
622 new_state
= m
->deserialized_state
;
623 else if (m
->from_proc_self_mountinfo
)
624 new_state
= MOUNT_MOUNTED
;
626 if (new_state
== m
->state
)
629 if (new_state
== MOUNT_MOUNTING
||
630 new_state
== MOUNT_MOUNTING_DONE
||
631 new_state
== MOUNT_REMOUNTING
||
632 new_state
== MOUNT_UNMOUNTING
||
633 new_state
== MOUNT_MOUNTING_SIGTERM
||
634 new_state
== MOUNT_MOUNTING_SIGKILL
||
635 new_state
== MOUNT_UNMOUNTING_SIGTERM
||
636 new_state
== MOUNT_UNMOUNTING_SIGKILL
||
637 new_state
== MOUNT_REMOUNTING_SIGTERM
||
638 new_state
== MOUNT_REMOUNTING_SIGKILL
) {
640 if (m
->control_pid
<= 0)
643 r
= unit_watch_pid(UNIT(m
), m
->control_pid
);
647 r
= mount_arm_timer(m
);
652 mount_set_state(m
, new_state
);
656 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
663 p
= get_mount_parameters(m
);
666 "%sMount State: %s\n"
670 "%sFile System Type: %s\n"
672 "%sFrom /proc/self/mountinfo: %s\n"
673 "%sFrom fragment: %s\n"
674 "%sDirectoryMode: %04o\n"
675 "%sSmackFileSystemRoot: %s\n",
676 prefix
, mount_state_to_string(m
->state
),
677 prefix
, mount_result_to_string(m
->result
),
679 prefix
, p
? strna(p
->what
) : "n/a",
680 prefix
, p
? strna(p
->fstype
) : "n/a",
681 prefix
, p
? strna(p
->options
) : "n/a",
682 prefix
, yes_no(m
->from_proc_self_mountinfo
),
683 prefix
, yes_no(m
->from_fragment
),
684 prefix
, m
->directory_mode
,
685 prefix
, strna(m
->smack_fs_root
));
687 if (m
->control_pid
> 0)
689 "%sControl PID: "PID_FMT
"\n",
690 prefix
, m
->control_pid
);
692 exec_context_dump(&m
->exec_context
, f
, prefix
);
693 kill_context_dump(&m
->kill_context
, f
, prefix
);
696 static int mount_spawn(Mount
*m
, ExecCommand
*c
, pid_t
*_pid
) {
699 ExecParameters exec_params
= {
700 .apply_permissions
= true,
701 .apply_chroot
= true,
702 .apply_tty_stdin
= true,
703 .bus_endpoint_fd
= -1,
713 (void) unit_realize_cgroup(UNIT(m
));
714 if (m
->reset_cpu_usage
) {
715 (void) unit_reset_cpu_usage(UNIT(m
));
716 m
->reset_cpu_usage
= false;
719 r
= unit_setup_exec_runtime(UNIT(m
));
723 r
= mount_arm_timer(m
);
727 exec_params
.environment
= UNIT(m
)->manager
->environment
;
728 exec_params
.confirm_spawn
= UNIT(m
)->manager
->confirm_spawn
;
729 exec_params
.cgroup_supported
= UNIT(m
)->manager
->cgroup_supported
;
730 exec_params
.cgroup_path
= UNIT(m
)->cgroup_path
;
731 exec_params
.cgroup_delegate
= m
->cgroup_context
.delegate
;
732 exec_params
.runtime_prefix
= manager_get_runtime_prefix(UNIT(m
)->manager
);
734 r
= exec_spawn(UNIT(m
),
743 r
= unit_watch_pid(UNIT(m
), pid
);
745 /* FIXME: we need to do something here */
753 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
758 static void mount_enter_dead(Mount
*m
, MountResult f
) {
761 if (f
!= MOUNT_SUCCESS
)
764 exec_runtime_destroy(m
->exec_runtime
);
765 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
767 exec_context_destroy_runtime_directory(&m
->exec_context
, manager_get_runtime_prefix(UNIT(m
)->manager
));
769 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
772 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
775 if (f
!= MOUNT_SUCCESS
)
778 mount_set_state(m
, MOUNT_MOUNTED
);
781 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
786 if (f
!= MOUNT_SUCCESS
)
789 r
= unit_kill_context(
792 (state
!= MOUNT_MOUNTING_SIGTERM
&& state
!= MOUNT_UNMOUNTING_SIGTERM
&& state
!= MOUNT_REMOUNTING_SIGTERM
) ?
793 KILL_KILL
: KILL_TERMINATE
,
801 r
= mount_arm_timer(m
);
805 mount_set_state(m
, state
);
806 } else if (state
== MOUNT_REMOUNTING_SIGTERM
)
807 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
808 else if (state
== MOUNT_REMOUNTING_SIGKILL
)
809 mount_enter_mounted(m
, MOUNT_SUCCESS
);
810 else if (state
== MOUNT_MOUNTING_SIGTERM
)
811 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_SUCCESS
);
812 else if (state
== MOUNT_UNMOUNTING_SIGTERM
)
813 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
815 mount_enter_dead(m
, MOUNT_SUCCESS
);
820 log_unit_warning_errno(UNIT(m
), r
, "Failed to kill processes: %m");
822 if (state
== MOUNT_REMOUNTING_SIGTERM
|| state
== MOUNT_REMOUNTING_SIGKILL
)
823 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
825 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
828 static void mount_enter_unmounting(Mount
*m
) {
833 /* Start counting our attempts */
834 if (!IN_SET(m
->state
,
836 MOUNT_UNMOUNTING_SIGTERM
,
837 MOUNT_UNMOUNTING_SIGKILL
))
838 m
->n_retry_umount
= 0;
840 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
841 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
843 r
= exec_command_set(m
->control_command
, UMOUNT_PATH
, m
->where
, NULL
);
847 mount_unwatch_control_pid(m
);
849 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
853 mount_set_state(m
, MOUNT_UNMOUNTING
);
858 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'umount' task: %m");
859 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
862 static int mount_get_opts(Mount
*m
, char **_opts
) {
864 char *o
= NULL
, *opts
= NULL
;
866 r
= fstab_filter_options(m
->parameters_fragment
.options
,
867 "nofail\0" "noauto\0" "auto\0", NULL
, NULL
, &o
);
871 if (mac_smack_use() && m
->smack_fs_root
) {
873 opts
= strjoin(o
, ",", "smackfsroot=", m
->smack_fs_root
, NULL
);
876 opts
= strjoin("smackfsroot=", m
->smack_fs_root
, NULL
);
887 static void mount_enter_mounting(Mount
*m
) {
893 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
894 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
896 r
= unit_fail_if_symlink(UNIT(m
), m
->where
);
900 (void) mkdir_p_label(m
->where
, m
->directory_mode
);
902 unit_warn_if_dir_nonempty(UNIT(m
), m
->where
);
904 /* Create the source directory for bind-mounts if needed */
905 p
= get_mount_parameters_fragment(m
);
906 if (p
&& mount_is_bind(p
))
907 (void) mkdir_p_label(p
->what
, m
->directory_mode
);
909 if (m
->from_fragment
) {
910 _cleanup_free_
char *opts
= NULL
;
912 r
= mount_get_opts(m
, &opts
);
916 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
917 m
->parameters_fragment
.what
, m
->where
, NULL
);
918 if (r
>= 0 && m
->sloppy_options
)
919 r
= exec_command_append(m
->control_command
, "-s", NULL
);
920 if (r
>= 0 && m
->parameters_fragment
.fstype
)
921 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
922 if (r
>= 0 && !isempty(opts
))
923 r
= exec_command_append(m
->control_command
, "-o", opts
, NULL
);
930 mount_unwatch_control_pid(m
);
932 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
936 mount_set_state(m
, MOUNT_MOUNTING
);
941 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'mount' task: %m");
942 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
945 static void mount_enter_remounting(Mount
*m
) {
950 m
->control_command_id
= MOUNT_EXEC_REMOUNT
;
951 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_REMOUNT
;
953 if (m
->from_fragment
) {
956 if (m
->parameters_fragment
.options
)
957 o
= strjoina("remount,", m
->parameters_fragment
.options
);
961 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
962 m
->parameters_fragment
.what
, m
->where
,
964 if (r
>= 0 && m
->sloppy_options
)
965 r
= exec_command_append(m
->control_command
, "-s", NULL
);
966 if (r
>= 0 && m
->parameters_fragment
.fstype
)
967 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
974 mount_unwatch_control_pid(m
);
976 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
980 mount_set_state(m
, MOUNT_REMOUNTING
);
985 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'remount' task: %m");
986 m
->reload_result
= MOUNT_FAILURE_RESOURCES
;
987 mount_enter_mounted(m
, MOUNT_SUCCESS
);
990 static int mount_start(Unit
*u
) {
995 /* We cannot fulfill this request right now, try again later
997 if (m
->state
== MOUNT_UNMOUNTING
||
998 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
999 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1000 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1001 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1004 /* Already on it! */
1005 if (m
->state
== MOUNT_MOUNTING
)
1008 assert(m
->state
== MOUNT_DEAD
|| m
->state
== MOUNT_FAILED
);
1010 m
->result
= MOUNT_SUCCESS
;
1011 m
->reload_result
= MOUNT_SUCCESS
;
1012 m
->reset_cpu_usage
= true;
1014 mount_enter_mounting(m
);
1018 static int mount_stop(Unit
*u
) {
1019 Mount
*m
= MOUNT(u
);
1024 if (m
->state
== MOUNT_UNMOUNTING
||
1025 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1026 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
1027 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1028 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1031 assert(m
->state
== MOUNT_MOUNTING
||
1032 m
->state
== MOUNT_MOUNTING_DONE
||
1033 m
->state
== MOUNT_MOUNTED
||
1034 m
->state
== MOUNT_REMOUNTING
||
1035 m
->state
== MOUNT_REMOUNTING_SIGTERM
||
1036 m
->state
== MOUNT_REMOUNTING_SIGKILL
);
1038 mount_enter_unmounting(m
);
1042 static int mount_reload(Unit
*u
) {
1043 Mount
*m
= MOUNT(u
);
1047 if (m
->state
== MOUNT_MOUNTING_DONE
)
1050 assert(m
->state
== MOUNT_MOUNTED
);
1052 mount_enter_remounting(m
);
1056 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1057 Mount
*m
= MOUNT(u
);
1063 unit_serialize_item(u
, f
, "state", mount_state_to_string(m
->state
));
1064 unit_serialize_item(u
, f
, "result", mount_result_to_string(m
->result
));
1065 unit_serialize_item(u
, f
, "reload-result", mount_result_to_string(m
->reload_result
));
1067 if (m
->control_pid
> 0)
1068 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, m
->control_pid
);
1070 if (m
->control_command_id
>= 0)
1071 unit_serialize_item(u
, f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1076 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1077 Mount
*m
= MOUNT(u
);
1084 if (streq(key
, "state")) {
1087 if ((state
= mount_state_from_string(value
)) < 0)
1088 log_unit_debug(u
, "Failed to parse state value: %s", value
);
1090 m
->deserialized_state
= state
;
1091 } else if (streq(key
, "result")) {
1094 f
= mount_result_from_string(value
);
1096 log_unit_debug(u
, "Failed to parse result value: %s", value
);
1097 else if (f
!= MOUNT_SUCCESS
)
1100 } else if (streq(key
, "reload-result")) {
1103 f
= mount_result_from_string(value
);
1105 log_unit_debug(u
, "Failed to parse reload result value: %s", value
);
1106 else if (f
!= MOUNT_SUCCESS
)
1107 m
->reload_result
= f
;
1109 } else if (streq(key
, "control-pid")) {
1112 if (parse_pid(value
, &pid
) < 0)
1113 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
1115 m
->control_pid
= pid
;
1116 } else if (streq(key
, "control-command")) {
1117 MountExecCommand id
;
1119 id
= mount_exec_command_from_string(value
);
1121 log_unit_debug(u
, "Failed to parse exec-command value: %s", value
);
1123 m
->control_command_id
= id
;
1124 m
->control_command
= m
->exec_command
+ id
;
1127 log_unit_debug(u
, "Unknown serialization key: %s", key
);
1132 _pure_
static UnitActiveState
mount_active_state(Unit
*u
) {
1135 return state_translation_table
[MOUNT(u
)->state
];
1138 _pure_
static const char *mount_sub_state_to_string(Unit
*u
) {
1141 return mount_state_to_string(MOUNT(u
)->state
);
1144 _pure_
static bool mount_check_gc(Unit
*u
) {
1145 Mount
*m
= MOUNT(u
);
1149 return m
->from_proc_self_mountinfo
;
1152 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1153 Mount
*m
= MOUNT(u
);
1159 if (pid
!= m
->control_pid
)
1164 if (is_clean_exit(code
, status
, NULL
))
1166 else if (code
== CLD_EXITED
)
1167 f
= MOUNT_FAILURE_EXIT_CODE
;
1168 else if (code
== CLD_KILLED
)
1169 f
= MOUNT_FAILURE_SIGNAL
;
1170 else if (code
== CLD_DUMPED
)
1171 f
= MOUNT_FAILURE_CORE_DUMP
;
1173 assert_not_reached("Unknown code");
1175 if (f
!= MOUNT_SUCCESS
)
1178 if (m
->control_command
) {
1179 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1181 m
->control_command
= NULL
;
1182 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1185 log_unit_full(u
, f
== MOUNT_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
1186 "Mount process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
1188 /* Note that mount(8) returning and the kernel sending us a
1189 * mount table change event might happen out-of-order. If an
1190 * operation succeed we assume the kernel will follow soon too
1191 * and already change into the resulting state. If it fails
1192 * we check if the kernel still knows about the mount. and
1193 * change state accordingly. */
1197 case MOUNT_MOUNTING
:
1198 case MOUNT_MOUNTING_DONE
:
1199 case MOUNT_MOUNTING_SIGKILL
:
1200 case MOUNT_MOUNTING_SIGTERM
:
1202 if (f
== MOUNT_SUCCESS
)
1203 mount_enter_mounted(m
, f
);
1204 else if (m
->from_proc_self_mountinfo
)
1205 mount_enter_mounted(m
, f
);
1207 mount_enter_dead(m
, f
);
1210 case MOUNT_REMOUNTING
:
1211 case MOUNT_REMOUNTING_SIGKILL
:
1212 case MOUNT_REMOUNTING_SIGTERM
:
1214 m
->reload_result
= f
;
1215 if (m
->from_proc_self_mountinfo
)
1216 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1218 mount_enter_dead(m
, MOUNT_SUCCESS
);
1222 case MOUNT_UNMOUNTING
:
1223 case MOUNT_UNMOUNTING_SIGKILL
:
1224 case MOUNT_UNMOUNTING_SIGTERM
:
1226 if (f
== MOUNT_SUCCESS
) {
1228 if (m
->from_proc_self_mountinfo
) {
1230 /* Still a mount point? If so, let's
1231 * try again. Most likely there were
1232 * multiple mount points stacked on
1233 * top of each other. Note that due to
1234 * the io event priority logic we can
1235 * be sure the new mountinfo is loaded
1236 * before we process the SIGCHLD for
1237 * the mount command. */
1239 if (m
->n_retry_umount
< RETRY_UMOUNT_MAX
) {
1240 log_unit_debug(u
, "Mount still present, trying again.");
1241 m
->n_retry_umount
++;
1242 mount_enter_unmounting(m
);
1244 log_unit_debug(u
, "Mount still present after %u attempts to unmount, giving up.", m
->n_retry_umount
);
1245 mount_enter_mounted(m
, f
);
1248 mount_enter_dead(m
, f
);
1250 } else if (m
->from_proc_self_mountinfo
)
1251 mount_enter_mounted(m
, f
);
1253 mount_enter_dead(m
, f
);
1257 assert_not_reached("Uh, control process died at wrong time.");
1260 /* Notify clients about changed exit status */
1261 unit_add_to_dbus_queue(u
);
1264 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1265 Mount
*m
= MOUNT(userdata
);
1268 assert(m
->timer_event_source
== source
);
1272 case MOUNT_MOUNTING
:
1273 case MOUNT_MOUNTING_DONE
:
1274 log_unit_warning(UNIT(m
), "Mounting timed out. Stopping.");
1275 mount_enter_signal(m
, MOUNT_MOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1278 case MOUNT_REMOUNTING
:
1279 log_unit_warning(UNIT(m
), "Remounting timed out. Stopping.");
1280 m
->reload_result
= MOUNT_FAILURE_TIMEOUT
;
1281 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1284 case MOUNT_UNMOUNTING
:
1285 log_unit_warning(UNIT(m
), "Unmounting timed out. Stopping.");
1286 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1289 case MOUNT_MOUNTING_SIGTERM
:
1290 if (m
->kill_context
.send_sigkill
) {
1291 log_unit_warning(UNIT(m
), "Mounting timed out. Killing.");
1292 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1294 log_unit_warning(UNIT(m
), "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
), "Remounting timed out. Killing.");
1306 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1308 log_unit_warning(UNIT(m
), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1310 if (m
->from_proc_self_mountinfo
)
1311 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1313 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1317 case MOUNT_UNMOUNTING_SIGTERM
:
1318 if (m
->kill_context
.send_sigkill
) {
1319 log_unit_warning(UNIT(m
), "Unmounting timed out. Killing.");
1320 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1322 log_unit_warning(UNIT(m
), "Unmounting timed out. Skipping SIGKILL. Ignoring.");
1324 if (m
->from_proc_self_mountinfo
)
1325 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1327 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1331 case MOUNT_MOUNTING_SIGKILL
:
1332 case MOUNT_REMOUNTING_SIGKILL
:
1333 case MOUNT_UNMOUNTING_SIGKILL
:
1334 log_unit_warning(UNIT(m
),"Mount process still around after SIGKILL. Ignoring.");
1336 if (m
->from_proc_self_mountinfo
)
1337 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1339 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1343 assert_not_reached("Timeout at wrong time.");
1349 static int mount_setup_unit(
1353 const char *options
,
1357 _cleanup_free_
char *e
= NULL
, *w
= NULL
, *o
= NULL
, *f
= NULL
;
1358 bool load_extras
= false;
1360 bool delete, changed
= false;
1370 /* Ignore API mount points. They should never be referenced in
1371 * dependencies ever. */
1372 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1375 if (streq(fstype
, "autofs"))
1378 /* probably some kind of swap, ignore */
1379 if (!is_path(where
))
1382 r
= unit_name_from_path(where
, ".mount", &e
);
1386 u
= manager_get_unit(m
, e
);
1390 u
= unit_new(m
, sizeof(Mount
));
1394 r
= unit_add_name(u
, e
);
1398 MOUNT(u
)->where
= strdup(where
);
1399 if (!MOUNT(u
)->where
) {
1404 u
->source_path
= strdup("/proc/self/mountinfo");
1405 if (!u
->source_path
) {
1410 if (m
->running_as
== MANAGER_SYSTEM
) {
1413 target
= mount_needs_network(options
, fstype
) ? SPECIAL_REMOTE_FS_TARGET
: SPECIAL_LOCAL_FS_TARGET
;
1414 r
= unit_add_dependency_by_name(u
, UNIT_BEFORE
, target
, NULL
, true);
1418 if (should_umount(MOUNT(u
))) {
1419 r
= unit_add_dependency_by_name(u
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
1425 unit_add_to_load_queue(u
);
1430 if (!MOUNT(u
)->where
) {
1431 MOUNT(u
)->where
= strdup(where
);
1432 if (!MOUNT(u
)->where
) {
1438 if (m
->running_as
== MANAGER_SYSTEM
&&
1439 mount_needs_network(options
, fstype
)) {
1440 /* _netdev option may have shown up late, or on a
1441 * remount. Add remote-fs dependencies, even though
1442 * local-fs ones may already be there. */
1443 unit_add_dependency_by_name(u
, UNIT_BEFORE
, SPECIAL_REMOTE_FS_TARGET
, NULL
, true);
1447 if (u
->load_state
== UNIT_NOT_FOUND
) {
1448 u
->load_state
= UNIT_LOADED
;
1451 /* Load in the extras later on, after we
1452 * finished initialization of the unit */
1459 o
= strdup(options
);
1461 if (!w
|| !o
|| !f
) {
1466 p
= &MOUNT(u
)->parameters_proc_self_mountinfo
;
1468 changed
= changed
||
1469 !streq_ptr(p
->options
, options
) ||
1470 !streq_ptr(p
->what
, what
) ||
1471 !streq_ptr(p
->fstype
, fstype
);
1474 MOUNT(u
)->is_mounted
= true;
1475 MOUNT(u
)->just_mounted
= !MOUNT(u
)->from_proc_self_mountinfo
;
1476 MOUNT(u
)->just_changed
= changed
;
1479 MOUNT(u
)->from_proc_self_mountinfo
= true;
1494 r
= mount_add_extras(MOUNT(u
));
1500 unit_add_to_dbus_queue(u
);
1505 log_warning_errno(r
, "Failed to set up mount unit: %m");
1513 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1514 _cleanup_(mnt_free_tablep
) struct libmnt_table
*t
= NULL
;
1515 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*i
= NULL
;
1520 t
= mnt_new_table();
1524 i
= mnt_new_iter(MNT_ITER_FORWARD
);
1528 r
= mnt_table_parse_mtab(t
, NULL
);
1530 return log_error_errno(r
, "Failed to parse /proc/self/mountinfo: %m");
1534 const char *device
, *path
, *options
, *fstype
;
1535 _cleanup_free_
char *d
= NULL
, *p
= NULL
;
1536 struct libmnt_fs
*fs
;
1539 k
= mnt_table_next_fs(t
, i
, &fs
);
1543 return log_error_errno(k
, "Failed to get next entry from /proc/self/mountinfo: %m");
1545 device
= mnt_fs_get_source(fs
);
1546 path
= mnt_fs_get_target(fs
);
1547 options
= mnt_fs_get_options(fs
);
1548 fstype
= mnt_fs_get_fstype(fs
);
1550 if (!device
|| !path
)
1553 if (cunescape(device
, UNESCAPE_RELAX
, &d
) < 0)
1556 if (cunescape(path
, UNESCAPE_RELAX
, &p
) < 0)
1559 (void) device_found_node(m
, d
, true, DEVICE_FOUND_MOUNT
, set_flags
);
1561 k
= mount_setup_unit(m
, d
, p
, options
, fstype
, set_flags
);
1562 if (r
== 0 && k
< 0)
1569 static void mount_shutdown(Manager
*m
) {
1573 m
->mount_event_source
= sd_event_source_unref(m
->mount_event_source
);
1575 mnt_unref_monitor(m
->mount_monitor
);
1576 m
->mount_monitor
= NULL
;
1579 static int mount_get_timeout(Unit
*u
, uint64_t *timeout
) {
1580 Mount
*m
= MOUNT(u
);
1583 if (!m
->timer_event_source
)
1586 r
= sd_event_source_get_time(m
->timer_event_source
, timeout
);
1593 static int mount_enumerate(Manager
*m
) {
1600 if (!m
->mount_monitor
) {
1603 m
->mount_monitor
= mnt_new_monitor();
1604 if (!m
->mount_monitor
) {
1609 r
= mnt_monitor_enable_kernel(m
->mount_monitor
, 1);
1612 r
= mnt_monitor_enable_userspace(m
->mount_monitor
, 1, NULL
);
1616 /* mnt_unref_monitor() will close the fd */
1617 fd
= r
= mnt_monitor_get_fd(m
->mount_monitor
);
1621 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fd
, EPOLLIN
, mount_dispatch_io
, m
);
1625 r
= sd_event_source_set_priority(m
->mount_event_source
, -10);
1629 (void) sd_event_source_set_description(m
->mount_event_source
, "mount-monitor-dispatch");
1632 r
= mount_load_proc_self_mountinfo(m
, false);
1643 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
1644 _cleanup_set_free_ Set
*around
= NULL
, *gone
= NULL
;
1645 Manager
*m
= userdata
;
1652 assert(revents
& EPOLLIN
);
1654 if (fd
== mnt_monitor_get_fd(m
->mount_monitor
)) {
1655 bool rescan
= false;
1657 /* Drain all events and verify that the event is valid.
1659 * Note that libmount also monitors /run/mount mkdir if the
1660 * directory does not exist yet. The mkdir may generate event
1661 * which is irrelevant for us.
1663 * error: r < 0; valid: r == 0, false positive: rc == 1 */
1665 r
= mnt_monitor_next_change(m
->mount_monitor
, NULL
, NULL
);
1669 return log_error_errno(r
, "Failed to drain libmount events");
1672 log_debug("libmount event [rescan: %s]", yes_no(rescan
));
1677 r
= mount_load_proc_self_mountinfo(m
, true);
1679 /* Reset flags, just in case, for later calls */
1680 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1681 Mount
*mount
= MOUNT(u
);
1683 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1689 manager_dispatch_load_queue(m
);
1691 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1692 Mount
*mount
= MOUNT(u
);
1694 if (!mount
->is_mounted
) {
1696 /* A mount point is not around right now. It
1697 * might be gone, or might never have
1700 if (mount
->from_proc_self_mountinfo
&&
1701 mount
->parameters_proc_self_mountinfo
.what
) {
1703 /* Remember that this device might just have disappeared */
1704 if (set_ensure_allocated(&gone
, &string_hash_ops
) < 0 ||
1705 set_put(gone
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1706 log_oom(); /* we don't care too much about OOM here... */
1709 mount
->from_proc_self_mountinfo
= false;
1711 switch (mount
->state
) {
1714 /* This has just been unmounted by
1715 * somebody else, follow the state
1717 mount_enter_dead(mount
, MOUNT_SUCCESS
);
1724 } else if (mount
->just_mounted
|| mount
->just_changed
) {
1726 /* A mount point was added or changed */
1728 switch (mount
->state
) {
1732 /* This has just been mounted by
1733 * somebody else, follow the state
1735 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
1738 case MOUNT_MOUNTING
:
1739 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
1743 /* Nothing really changed, but let's
1744 * issue an notification call
1745 * nonetheless, in case somebody is
1746 * waiting for this. (e.g. file system
1747 * ro/rw remounts.) */
1748 mount_set_state(mount
, mount
->state
);
1753 if (mount
->is_mounted
&&
1754 mount
->from_proc_self_mountinfo
&&
1755 mount
->parameters_proc_self_mountinfo
.what
) {
1757 if (set_ensure_allocated(&around
, &string_hash_ops
) < 0 ||
1758 set_put(around
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1762 /* Reset the flags for later calls */
1763 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1766 SET_FOREACH(what
, gone
, i
) {
1767 if (set_contains(around
, what
))
1770 /* Let the device units know that the device is no longer mounted */
1771 (void) device_found_node(m
, what
, false, DEVICE_FOUND_MOUNT
, true);
1777 static void mount_reset_failed(Unit
*u
) {
1778 Mount
*m
= MOUNT(u
);
1782 if (m
->state
== MOUNT_FAILED
)
1783 mount_set_state(m
, MOUNT_DEAD
);
1785 m
->result
= MOUNT_SUCCESS
;
1786 m
->reload_result
= MOUNT_SUCCESS
;
1789 static int mount_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
1790 return unit_kill_common(u
, who
, signo
, -1, MOUNT(u
)->control_pid
, error
);
1793 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
1794 [MOUNT_EXEC_MOUNT
] = "ExecMount",
1795 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
1796 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
1799 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
1801 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
1802 [MOUNT_SUCCESS
] = "success",
1803 [MOUNT_FAILURE_RESOURCES
] = "resources",
1804 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
1805 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
1806 [MOUNT_FAILURE_SIGNAL
] = "signal",
1807 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump"
1810 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
1812 const UnitVTable mount_vtable
= {
1813 .object_size
= sizeof(Mount
),
1814 .exec_context_offset
= offsetof(Mount
, exec_context
),
1815 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
1816 .kill_context_offset
= offsetof(Mount
, kill_context
),
1817 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
1823 .private_section
= "Mount",
1826 .no_instances
= true,
1832 .coldplug
= mount_coldplug
,
1836 .start
= mount_start
,
1838 .reload
= mount_reload
,
1842 .serialize
= mount_serialize
,
1843 .deserialize_item
= mount_deserialize_item
,
1845 .active_state
= mount_active_state
,
1846 .sub_state_to_string
= mount_sub_state_to_string
,
1848 .check_gc
= mount_check_gc
,
1850 .sigchld_event
= mount_sigchld_event
,
1852 .reset_failed
= mount_reset_failed
,
1854 .bus_vtable
= bus_mount_vtable
,
1855 .bus_set_property
= bus_mount_set_property
,
1856 .bus_commit_properties
= bus_mount_commit_properties
,
1858 .get_timeout
= mount_get_timeout
,
1860 .can_transient
= true,
1862 .enumerate
= mount_enumerate
,
1863 .shutdown
= mount_shutdown
,
1865 .status_message_formats
= {
1866 .starting_stopping
= {
1867 [0] = "Mounting %s...",
1868 [1] = "Unmounting %s...",
1870 .finished_start_job
= {
1871 [JOB_DONE
] = "Mounted %s.",
1872 [JOB_FAILED
] = "Failed to mount %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.",