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 "alloc-util.h"
30 #include "dbus-mount.h"
32 #include "exit-status.h"
33 #include "formats-util.h"
34 #include "fstab-util.h"
38 #include "mount-setup.h"
39 #include "mount-util.h"
41 #include "parse-util.h"
42 #include "path-util.h"
43 #include "process-util.h"
44 #include "smack-util.h"
46 #include "string-table.h"
47 #include "string-util.h"
49 #include "unit-name.h"
52 #define RETRY_UMOUNT_MAX 32
54 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table
*, mnt_free_table
);
55 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter
*, mnt_free_iter
);
57 static const UnitActiveState state_translation_table
[_MOUNT_STATE_MAX
] = {
58 [MOUNT_DEAD
] = UNIT_INACTIVE
,
59 [MOUNT_MOUNTING
] = UNIT_ACTIVATING
,
60 [MOUNT_MOUNTING_DONE
] = UNIT_ACTIVE
,
61 [MOUNT_MOUNTED
] = UNIT_ACTIVE
,
62 [MOUNT_REMOUNTING
] = UNIT_RELOADING
,
63 [MOUNT_UNMOUNTING
] = UNIT_DEACTIVATING
,
64 [MOUNT_MOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
65 [MOUNT_MOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
66 [MOUNT_REMOUNTING_SIGTERM
] = UNIT_RELOADING
,
67 [MOUNT_REMOUNTING_SIGKILL
] = UNIT_RELOADING
,
68 [MOUNT_UNMOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
69 [MOUNT_UNMOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
70 [MOUNT_FAILED
] = UNIT_FAILED
73 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
74 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
76 static bool mount_needs_network(const char *options
, const char *fstype
) {
77 if (fstab_test_option(options
, "_netdev\0"))
80 if (fstype
&& fstype_is_network(fstype
))
86 static bool mount_is_network(const MountParameters
*p
) {
89 return mount_needs_network(p
->options
, p
->fstype
);
92 static bool mount_is_bind(const MountParameters
*p
) {
95 if (fstab_test_option(p
->options
, "bind\0" "rbind\0"))
98 if (p
->fstype
&& STR_IN_SET(p
->fstype
, "bind", "rbind"))
104 static bool mount_is_auto(const MountParameters
*p
) {
107 return !fstab_test_option(p
->options
, "noauto\0");
110 static bool needs_quota(const MountParameters
*p
) {
113 /* Quotas are not enabled on network filesystems,
114 * but we want them, for example, on storage connected via iscsi */
115 if (p
->fstype
&& fstype_is_network(p
->fstype
))
118 if (mount_is_bind(p
))
121 return fstab_test_option(p
->options
,
122 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
125 static void mount_init(Unit
*u
) {
129 assert(u
->load_state
== UNIT_STUB
);
131 m
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
132 m
->directory_mode
= 0755;
134 if (unit_has_name(u
, "-.mount")) {
135 /* Don't allow start/stop for root directory */
136 u
->refuse_manual_start
= true;
137 u
->refuse_manual_stop
= true;
139 /* The stdio/kmsg bridge socket is on /, in order to avoid a
140 * dep loop, don't use kmsg logging for -.mount */
141 m
->exec_context
.std_output
= u
->manager
->default_std_output
;
142 m
->exec_context
.std_error
= u
->manager
->default_std_error
;
145 /* We need to make sure that /usr/bin/mount is always called
146 * in the same process group as us, so that the autofs kernel
147 * side doesn't send us another mount request while we are
148 * already trying to comply its last one. */
149 m
->exec_context
.same_pgrp
= true;
151 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
153 u
->ignore_on_isolate
= true;
156 static int mount_arm_timer(Mount
*m
) {
161 if (m
->timeout_usec
<= 0) {
162 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
166 if (m
->timer_event_source
) {
167 r
= sd_event_source_set_time(m
->timer_event_source
, now(CLOCK_MONOTONIC
) + m
->timeout_usec
);
171 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_ONESHOT
);
174 r
= sd_event_add_time(
175 UNIT(m
)->manager
->event
,
176 &m
->timer_event_source
,
178 now(CLOCK_MONOTONIC
) + m
->timeout_usec
, 0,
179 mount_dispatch_timer
, m
);
183 (void) sd_event_source_set_description(m
->timer_event_source
, "mount-timer");
188 static void mount_unwatch_control_pid(Mount
*m
) {
191 if (m
->control_pid
<= 0)
194 unit_unwatch_pid(UNIT(m
), m
->control_pid
);
198 static void mount_parameters_done(MountParameters
*p
) {
205 p
->what
= p
->options
= p
->fstype
= NULL
;
208 static void mount_done(Unit
*u
) {
213 m
->where
= mfree(m
->where
);
214 m
->smack_fs_root_label
= mfree(m
->smack_fs_root_label
);
216 mount_parameters_done(&m
->parameters_proc_self_mountinfo
);
217 mount_parameters_done(&m
->parameters_fragment
);
219 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
220 exec_command_done_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
221 m
->control_command
= NULL
;
223 mount_unwatch_control_pid(m
);
225 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
228 _pure_
static MountParameters
* get_mount_parameters_fragment(Mount
*m
) {
231 if (m
->from_fragment
)
232 return &m
->parameters_fragment
;
237 _pure_
static MountParameters
* get_mount_parameters(Mount
*m
) {
240 if (m
->from_proc_self_mountinfo
)
241 return &m
->parameters_proc_self_mountinfo
;
243 return get_mount_parameters_fragment(m
);
246 static int mount_add_mount_links(Mount
*m
) {
247 _cleanup_free_
char *parent
= NULL
;
256 if (!path_equal(m
->where
, "/")) {
257 /* Adds in links to other mount points that might lie further
258 * up in the hierarchy */
260 parent
= dirname_malloc(m
->where
);
264 r
= unit_require_mounts_for(UNIT(m
), parent
);
269 /* Adds in links to other mount points that might be needed
270 * for the source path (if this is a bind mount) to be
272 pm
= get_mount_parameters_fragment(m
);
273 if (pm
&& pm
->what
&&
274 path_is_absolute(pm
->what
) &&
275 !mount_is_network(pm
)) {
277 r
= unit_require_mounts_for(UNIT(m
), pm
->what
);
282 /* Adds in links to other units that use this path or paths
283 * further down in the hierarchy */
284 s
= manager_get_units_requiring_mounts_for(UNIT(m
)->manager
, m
->where
);
285 SET_FOREACH(other
, s
, i
) {
287 if (other
->load_state
!= UNIT_LOADED
)
290 if (other
== UNIT(m
))
293 r
= unit_add_dependency(other
, UNIT_AFTER
, UNIT(m
), true);
297 if (UNIT(m
)->fragment_path
) {
298 /* If we have fragment configuration, then make this dependency required */
299 r
= unit_add_dependency(other
, UNIT_REQUIRES
, UNIT(m
), true);
308 static int mount_add_device_links(Mount
*m
) {
310 bool device_wants_mount
= false;
315 p
= get_mount_parameters(m
);
322 if (mount_is_bind(p
))
325 if (!is_device_path(p
->what
))
328 /* /dev/root is a really weird thing, it's not a real device,
329 * but just a path the kernel exports for the root file system
330 * specified on the kernel command line. Ignore it here. */
331 if (path_equal(p
->what
, "/dev/root"))
334 if (path_equal(m
->where
, "/"))
337 if (mount_is_auto(p
) && UNIT(m
)->manager
->running_as
== MANAGER_SYSTEM
)
338 device_wants_mount
= true;
340 r
= unit_add_node_link(UNIT(m
), p
->what
, device_wants_mount
);
347 static int mount_add_quota_links(Mount
*m
) {
353 if (UNIT(m
)->manager
->running_as
!= MANAGER_SYSTEM
)
356 p
= get_mount_parameters_fragment(m
);
363 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
, NULL
, true);
367 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
, NULL
, true);
374 static bool should_umount(Mount
*m
) {
377 if (path_equal(m
->where
, "/") ||
378 path_equal(m
->where
, "/usr"))
381 p
= get_mount_parameters(m
);
382 if (p
&& fstab_test_option(p
->options
, "x-initrd.mount\0") &&
389 static int mount_add_default_dependencies(Mount
*m
) {
390 const char *after
, *after2
, *online
;
396 if (!UNIT(m
)->default_dependencies
)
399 if (UNIT(m
)->manager
->running_as
!= MANAGER_SYSTEM
)
402 /* We do not add any default dependencies to / and /usr, since
403 * they are guaranteed to stay mounted the whole time, since
404 * our system is on it. Also, don't bother with anything
405 * mounted below virtual file systems, it's also going to be
406 * virtual, and hence not worth the effort. */
407 if (path_equal(m
->where
, "/") ||
408 path_equal(m
->where
, "/usr") ||
409 path_startswith(m
->where
, "/proc") ||
410 path_startswith(m
->where
, "/sys") ||
411 path_startswith(m
->where
, "/dev"))
414 p
= get_mount_parameters(m
);
418 if (mount_is_network(p
)) {
419 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
420 after2
= SPECIAL_NETWORK_TARGET
;
421 online
= SPECIAL_NETWORK_ONLINE_TARGET
;
423 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
428 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, NULL
, true);
433 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after2
, NULL
, true);
439 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, online
, NULL
, true);
444 if (should_umount(m
)) {
445 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
453 static int mount_verify(Mount
*m
) {
454 _cleanup_free_
char *e
= NULL
;
459 if (UNIT(m
)->load_state
!= UNIT_LOADED
)
462 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
)
465 r
= unit_name_from_path(m
->where
, ".mount", &e
);
467 return log_unit_error_errno(UNIT(m
), r
, "Failed to generate unit name from mount path: %m");
469 if (!unit_has_name(UNIT(m
), e
)) {
470 log_unit_error(UNIT(m
), "Where= setting doesn't match unit name. Refusing.");
474 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
)) {
475 log_unit_error(UNIT(m
), "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
479 if (UNIT(m
)->fragment_path
&& !m
->parameters_fragment
.what
) {
480 log_unit_error(UNIT(m
), "What= setting is missing. Refusing.");
484 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
) {
485 log_unit_error(UNIT(m
), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
492 static int mount_add_extras(Mount
*m
) {
498 if (u
->fragment_path
)
499 m
->from_fragment
= true;
502 r
= unit_name_to_path(u
->id
, &m
->where
);
507 path_kill_slashes(m
->where
);
509 if (!u
->description
) {
510 r
= unit_set_description(u
, m
->where
);
515 r
= mount_add_device_links(m
);
519 r
= mount_add_mount_links(m
);
523 r
= mount_add_quota_links(m
);
527 r
= unit_patch_contexts(u
);
531 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
535 r
= unit_set_default_slice(u
);
539 r
= mount_add_default_dependencies(m
);
546 static int mount_load(Unit
*u
) {
551 assert(u
->load_state
== UNIT_STUB
);
553 if (m
->from_proc_self_mountinfo
)
554 r
= unit_load_fragment_and_dropin_optional(u
);
556 r
= unit_load_fragment_and_dropin(u
);
561 /* This is a new unit? Then let's add in some extras */
562 if (u
->load_state
== UNIT_LOADED
) {
563 r
= mount_add_extras(m
);
568 return mount_verify(m
);
571 static int mount_notify_automount(Mount
*m
, MountState old_state
, MountState state
) {
578 SET_FOREACH(p
, UNIT(m
)->dependencies
[UNIT_TRIGGERED_BY
], i
)
579 if (p
->type
== UNIT_AUTOMOUNT
) {
580 r
= automount_update_mount(AUTOMOUNT(p
), old_state
, state
);
588 static void mount_set_state(Mount
*m
, MountState state
) {
589 MountState old_state
;
592 old_state
= m
->state
;
595 if (state
!= MOUNT_MOUNTING
&&
596 state
!= MOUNT_MOUNTING_DONE
&&
597 state
!= MOUNT_REMOUNTING
&&
598 state
!= MOUNT_UNMOUNTING
&&
599 state
!= MOUNT_MOUNTING_SIGTERM
&&
600 state
!= MOUNT_MOUNTING_SIGKILL
&&
601 state
!= MOUNT_UNMOUNTING_SIGTERM
&&
602 state
!= MOUNT_UNMOUNTING_SIGKILL
&&
603 state
!= MOUNT_REMOUNTING_SIGTERM
&&
604 state
!= MOUNT_REMOUNTING_SIGKILL
) {
605 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
606 mount_unwatch_control_pid(m
);
607 m
->control_command
= NULL
;
608 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
611 mount_notify_automount(m
, old_state
, state
);
613 if (state
!= old_state
)
614 log_unit_debug(UNIT(m
), "Changed %s -> %s", mount_state_to_string(old_state
), mount_state_to_string(state
));
616 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
617 m
->reload_result
= MOUNT_SUCCESS
;
620 static int mount_coldplug(Unit
*u
) {
622 MountState new_state
= MOUNT_DEAD
;
626 assert(m
->state
== MOUNT_DEAD
);
628 if (m
->deserialized_state
!= m
->state
)
629 new_state
= m
->deserialized_state
;
630 else if (m
->from_proc_self_mountinfo
)
631 new_state
= MOUNT_MOUNTED
;
633 if (new_state
== m
->state
)
636 if (m
->control_pid
> 0 &&
637 pid_is_unwaited(m
->control_pid
) &&
643 MOUNT_MOUNTING_SIGTERM
,
644 MOUNT_MOUNTING_SIGKILL
,
645 MOUNT_UNMOUNTING_SIGTERM
,
646 MOUNT_UNMOUNTING_SIGKILL
,
647 MOUNT_REMOUNTING_SIGTERM
,
648 MOUNT_REMOUNTING_SIGKILL
)) {
650 r
= unit_watch_pid(UNIT(m
), m
->control_pid
);
654 r
= mount_arm_timer(m
);
659 mount_set_state(m
, new_state
);
663 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
670 p
= get_mount_parameters(m
);
673 "%sMount State: %s\n"
677 "%sFile System Type: %s\n"
679 "%sFrom /proc/self/mountinfo: %s\n"
680 "%sFrom fragment: %s\n"
681 "%sDirectoryMode: %04o\n"
682 "%sSmackFileSystemRootLabel: %s\n",
683 prefix
, mount_state_to_string(m
->state
),
684 prefix
, mount_result_to_string(m
->result
),
686 prefix
, p
? strna(p
->what
) : "n/a",
687 prefix
, p
? strna(p
->fstype
) : "n/a",
688 prefix
, p
? strna(p
->options
) : "n/a",
689 prefix
, yes_no(m
->from_proc_self_mountinfo
),
690 prefix
, yes_no(m
->from_fragment
),
691 prefix
, m
->directory_mode
,
692 prefix
, strna(m
->smack_fs_root_label
));
694 if (m
->control_pid
> 0)
696 "%sControl PID: "PID_FMT
"\n",
697 prefix
, m
->control_pid
);
699 exec_context_dump(&m
->exec_context
, f
, prefix
);
700 kill_context_dump(&m
->kill_context
, f
, prefix
);
703 static int mount_spawn(Mount
*m
, ExecCommand
*c
, pid_t
*_pid
) {
706 ExecParameters exec_params
= {
707 .apply_permissions
= true,
708 .apply_chroot
= true,
709 .apply_tty_stdin
= true,
710 .bus_endpoint_fd
= -1,
720 (void) unit_realize_cgroup(UNIT(m
));
721 if (m
->reset_cpu_usage
) {
722 (void) unit_reset_cpu_usage(UNIT(m
));
723 m
->reset_cpu_usage
= false;
726 r
= unit_setup_exec_runtime(UNIT(m
));
730 r
= mount_arm_timer(m
);
734 exec_params
.environment
= UNIT(m
)->manager
->environment
;
735 exec_params
.confirm_spawn
= UNIT(m
)->manager
->confirm_spawn
;
736 exec_params
.cgroup_supported
= UNIT(m
)->manager
->cgroup_supported
;
737 exec_params
.cgroup_path
= UNIT(m
)->cgroup_path
;
738 exec_params
.cgroup_delegate
= m
->cgroup_context
.delegate
;
739 exec_params
.runtime_prefix
= manager_get_runtime_prefix(UNIT(m
)->manager
);
741 r
= exec_spawn(UNIT(m
),
750 r
= unit_watch_pid(UNIT(m
), pid
);
752 /* FIXME: we need to do something here */
760 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
765 static void mount_enter_dead(Mount
*m
, MountResult f
) {
768 if (f
!= MOUNT_SUCCESS
)
771 exec_runtime_destroy(m
->exec_runtime
);
772 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
774 exec_context_destroy_runtime_directory(&m
->exec_context
, manager_get_runtime_prefix(UNIT(m
)->manager
));
776 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
779 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
782 if (f
!= MOUNT_SUCCESS
)
785 mount_set_state(m
, MOUNT_MOUNTED
);
788 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
793 if (f
!= MOUNT_SUCCESS
)
796 r
= unit_kill_context(
799 (state
!= MOUNT_MOUNTING_SIGTERM
&& state
!= MOUNT_UNMOUNTING_SIGTERM
&& state
!= MOUNT_REMOUNTING_SIGTERM
) ?
800 KILL_KILL
: KILL_TERMINATE
,
808 r
= mount_arm_timer(m
);
812 mount_set_state(m
, state
);
813 } else if (state
== MOUNT_REMOUNTING_SIGTERM
)
814 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
815 else if (state
== MOUNT_REMOUNTING_SIGKILL
)
816 mount_enter_mounted(m
, MOUNT_SUCCESS
);
817 else if (state
== MOUNT_MOUNTING_SIGTERM
)
818 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_SUCCESS
);
819 else if (state
== MOUNT_UNMOUNTING_SIGTERM
)
820 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
822 mount_enter_dead(m
, MOUNT_SUCCESS
);
827 log_unit_warning_errno(UNIT(m
), r
, "Failed to kill processes: %m");
829 if (state
== MOUNT_REMOUNTING_SIGTERM
|| state
== MOUNT_REMOUNTING_SIGKILL
)
830 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
832 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
835 static void mount_enter_unmounting(Mount
*m
) {
840 /* Start counting our attempts */
841 if (!IN_SET(m
->state
,
843 MOUNT_UNMOUNTING_SIGTERM
,
844 MOUNT_UNMOUNTING_SIGKILL
))
845 m
->n_retry_umount
= 0;
847 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
848 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
850 r
= exec_command_set(m
->control_command
, UMOUNT_PATH
, m
->where
, NULL
);
854 mount_unwatch_control_pid(m
);
856 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
860 mount_set_state(m
, MOUNT_UNMOUNTING
);
865 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'umount' task: %m");
866 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
869 static int mount_get_opts(Mount
*m
, char **_opts
) {
871 char *o
= NULL
, *opts
= NULL
;
873 r
= fstab_filter_options(m
->parameters_fragment
.options
,
874 "nofail\0" "noauto\0" "auto\0", NULL
, NULL
, &o
);
878 if (mac_smack_use() && m
->smack_fs_root_label
) {
880 opts
= strjoin(o
, ",", "smackfsroot=", m
->smack_fs_root_label
, NULL
);
883 opts
= strjoin("smackfsroot=", m
->smack_fs_root_label
, NULL
);
894 static void mount_enter_mounting(Mount
*m
) {
900 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
901 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
903 r
= unit_fail_if_symlink(UNIT(m
), m
->where
);
907 (void) mkdir_p_label(m
->where
, m
->directory_mode
);
909 unit_warn_if_dir_nonempty(UNIT(m
), m
->where
);
911 /* Create the source directory for bind-mounts if needed */
912 p
= get_mount_parameters_fragment(m
);
913 if (p
&& mount_is_bind(p
))
914 (void) mkdir_p_label(p
->what
, m
->directory_mode
);
916 if (m
->from_fragment
) {
917 _cleanup_free_
char *opts
= NULL
;
919 r
= mount_get_opts(m
, &opts
);
923 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
924 m
->parameters_fragment
.what
, m
->where
, NULL
);
925 if (r
>= 0 && m
->sloppy_options
)
926 r
= exec_command_append(m
->control_command
, "-s", NULL
);
927 if (r
>= 0 && m
->parameters_fragment
.fstype
)
928 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
929 if (r
>= 0 && !isempty(opts
))
930 r
= exec_command_append(m
->control_command
, "-o", opts
, NULL
);
937 mount_unwatch_control_pid(m
);
939 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
943 mount_set_state(m
, MOUNT_MOUNTING
);
948 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'mount' task: %m");
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
= strjoina("remount,", m
->parameters_fragment
.options
);
968 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
969 m
->parameters_fragment
.what
, m
->where
,
971 if (r
>= 0 && m
->sloppy_options
)
972 r
= exec_command_append(m
->control_command
, "-s", NULL
);
973 if (r
>= 0 && m
->parameters_fragment
.fstype
)
974 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
981 mount_unwatch_control_pid(m
);
983 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
987 mount_set_state(m
, MOUNT_REMOUNTING
);
992 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'remount' task: %m");
993 m
->reload_result
= MOUNT_FAILURE_RESOURCES
;
994 mount_enter_mounted(m
, MOUNT_SUCCESS
);
997 static int mount_start(Unit
*u
) {
1002 /* We cannot fulfill this request right now, try again later
1004 if (m
->state
== MOUNT_UNMOUNTING
||
1005 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
1006 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1007 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1008 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1011 /* Already on it! */
1012 if (m
->state
== MOUNT_MOUNTING
)
1015 assert(m
->state
== MOUNT_DEAD
|| m
->state
== MOUNT_FAILED
);
1017 m
->result
= MOUNT_SUCCESS
;
1018 m
->reload_result
= MOUNT_SUCCESS
;
1019 m
->reset_cpu_usage
= true;
1021 mount_enter_mounting(m
);
1025 static int mount_stop(Unit
*u
) {
1026 Mount
*m
= MOUNT(u
);
1031 if (m
->state
== MOUNT_UNMOUNTING
||
1032 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1033 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
1034 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1035 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1038 assert(m
->state
== MOUNT_MOUNTING
||
1039 m
->state
== MOUNT_MOUNTING_DONE
||
1040 m
->state
== MOUNT_MOUNTED
||
1041 m
->state
== MOUNT_REMOUNTING
||
1042 m
->state
== MOUNT_REMOUNTING_SIGTERM
||
1043 m
->state
== MOUNT_REMOUNTING_SIGKILL
);
1045 mount_enter_unmounting(m
);
1049 static int mount_reload(Unit
*u
) {
1050 Mount
*m
= MOUNT(u
);
1054 if (m
->state
== MOUNT_MOUNTING_DONE
)
1057 assert(m
->state
== MOUNT_MOUNTED
);
1059 mount_enter_remounting(m
);
1063 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1064 Mount
*m
= MOUNT(u
);
1070 unit_serialize_item(u
, f
, "state", mount_state_to_string(m
->state
));
1071 unit_serialize_item(u
, f
, "result", mount_result_to_string(m
->result
));
1072 unit_serialize_item(u
, f
, "reload-result", mount_result_to_string(m
->reload_result
));
1074 if (m
->control_pid
> 0)
1075 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, m
->control_pid
);
1077 if (m
->control_command_id
>= 0)
1078 unit_serialize_item(u
, f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1083 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1084 Mount
*m
= MOUNT(u
);
1091 if (streq(key
, "state")) {
1094 if ((state
= mount_state_from_string(value
)) < 0)
1095 log_unit_debug(u
, "Failed to parse state value: %s", value
);
1097 m
->deserialized_state
= state
;
1098 } else if (streq(key
, "result")) {
1101 f
= mount_result_from_string(value
);
1103 log_unit_debug(u
, "Failed to parse result value: %s", value
);
1104 else if (f
!= MOUNT_SUCCESS
)
1107 } else if (streq(key
, "reload-result")) {
1110 f
= mount_result_from_string(value
);
1112 log_unit_debug(u
, "Failed to parse reload result value: %s", value
);
1113 else if (f
!= MOUNT_SUCCESS
)
1114 m
->reload_result
= f
;
1116 } else if (streq(key
, "control-pid")) {
1119 if (parse_pid(value
, &pid
) < 0)
1120 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
1122 m
->control_pid
= pid
;
1123 } else if (streq(key
, "control-command")) {
1124 MountExecCommand id
;
1126 id
= mount_exec_command_from_string(value
);
1128 log_unit_debug(u
, "Failed to parse exec-command value: %s", value
);
1130 m
->control_command_id
= id
;
1131 m
->control_command
= m
->exec_command
+ id
;
1134 log_unit_debug(u
, "Unknown serialization key: %s", key
);
1139 _pure_
static UnitActiveState
mount_active_state(Unit
*u
) {
1142 return state_translation_table
[MOUNT(u
)->state
];
1145 _pure_
static const char *mount_sub_state_to_string(Unit
*u
) {
1148 return mount_state_to_string(MOUNT(u
)->state
);
1151 _pure_
static bool mount_check_gc(Unit
*u
) {
1152 Mount
*m
= MOUNT(u
);
1156 return m
->from_proc_self_mountinfo
;
1159 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1160 Mount
*m
= MOUNT(u
);
1166 if (pid
!= m
->control_pid
)
1171 if (is_clean_exit(code
, status
, NULL
))
1173 else if (code
== CLD_EXITED
)
1174 f
= MOUNT_FAILURE_EXIT_CODE
;
1175 else if (code
== CLD_KILLED
)
1176 f
= MOUNT_FAILURE_SIGNAL
;
1177 else if (code
== CLD_DUMPED
)
1178 f
= MOUNT_FAILURE_CORE_DUMP
;
1180 assert_not_reached("Unknown code");
1182 if (f
!= MOUNT_SUCCESS
)
1185 if (m
->control_command
) {
1186 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1188 m
->control_command
= NULL
;
1189 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1192 log_unit_full(u
, f
== MOUNT_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
1193 "Mount process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
1195 /* Note that mount(8) returning and the kernel sending us a
1196 * mount table change event might happen out-of-order. If an
1197 * operation succeed we assume the kernel will follow soon too
1198 * and already change into the resulting state. If it fails
1199 * we check if the kernel still knows about the mount. and
1200 * change state accordingly. */
1204 case MOUNT_MOUNTING
:
1205 case MOUNT_MOUNTING_DONE
:
1206 case MOUNT_MOUNTING_SIGKILL
:
1207 case MOUNT_MOUNTING_SIGTERM
:
1209 if (f
== MOUNT_SUCCESS
)
1210 mount_enter_mounted(m
, f
);
1211 else if (m
->from_proc_self_mountinfo
)
1212 mount_enter_mounted(m
, f
);
1214 mount_enter_dead(m
, f
);
1217 case MOUNT_REMOUNTING
:
1218 case MOUNT_REMOUNTING_SIGKILL
:
1219 case MOUNT_REMOUNTING_SIGTERM
:
1221 m
->reload_result
= f
;
1222 if (m
->from_proc_self_mountinfo
)
1223 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1225 mount_enter_dead(m
, MOUNT_SUCCESS
);
1229 case MOUNT_UNMOUNTING
:
1230 case MOUNT_UNMOUNTING_SIGKILL
:
1231 case MOUNT_UNMOUNTING_SIGTERM
:
1233 if (f
== MOUNT_SUCCESS
) {
1235 if (m
->from_proc_self_mountinfo
) {
1237 /* Still a mount point? If so, let's
1238 * try again. Most likely there were
1239 * multiple mount points stacked on
1240 * top of each other. Note that due to
1241 * the io event priority logic we can
1242 * be sure the new mountinfo is loaded
1243 * before we process the SIGCHLD for
1244 * the mount command. */
1246 if (m
->n_retry_umount
< RETRY_UMOUNT_MAX
) {
1247 log_unit_debug(u
, "Mount still present, trying again.");
1248 m
->n_retry_umount
++;
1249 mount_enter_unmounting(m
);
1251 log_unit_debug(u
, "Mount still present after %u attempts to unmount, giving up.", m
->n_retry_umount
);
1252 mount_enter_mounted(m
, f
);
1255 mount_enter_dead(m
, f
);
1257 } else if (m
->from_proc_self_mountinfo
)
1258 mount_enter_mounted(m
, f
);
1260 mount_enter_dead(m
, f
);
1264 assert_not_reached("Uh, control process died at wrong time.");
1267 /* Notify clients about changed exit status */
1268 unit_add_to_dbus_queue(u
);
1271 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1272 Mount
*m
= MOUNT(userdata
);
1275 assert(m
->timer_event_source
== source
);
1279 case MOUNT_MOUNTING
:
1280 case MOUNT_MOUNTING_DONE
:
1281 log_unit_warning(UNIT(m
), "Mounting timed out. Stopping.");
1282 mount_enter_signal(m
, MOUNT_MOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1285 case MOUNT_REMOUNTING
:
1286 log_unit_warning(UNIT(m
), "Remounting timed out. Stopping.");
1287 m
->reload_result
= MOUNT_FAILURE_TIMEOUT
;
1288 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1291 case MOUNT_UNMOUNTING
:
1292 log_unit_warning(UNIT(m
), "Unmounting timed out. Stopping.");
1293 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1296 case MOUNT_MOUNTING_SIGTERM
:
1297 if (m
->kill_context
.send_sigkill
) {
1298 log_unit_warning(UNIT(m
), "Mounting timed out. Killing.");
1299 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1301 log_unit_warning(UNIT(m
), "Mounting timed out. Skipping SIGKILL. Ignoring.");
1303 if (m
->from_proc_self_mountinfo
)
1304 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1306 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1310 case MOUNT_REMOUNTING_SIGTERM
:
1311 if (m
->kill_context
.send_sigkill
) {
1312 log_unit_warning(UNIT(m
), "Remounting timed out. Killing.");
1313 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1315 log_unit_warning(UNIT(m
), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1317 if (m
->from_proc_self_mountinfo
)
1318 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1320 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1324 case MOUNT_UNMOUNTING_SIGTERM
:
1325 if (m
->kill_context
.send_sigkill
) {
1326 log_unit_warning(UNIT(m
), "Unmounting timed out. Killing.");
1327 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1329 log_unit_warning(UNIT(m
), "Unmounting timed out. Skipping SIGKILL. Ignoring.");
1331 if (m
->from_proc_self_mountinfo
)
1332 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1334 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1338 case MOUNT_MOUNTING_SIGKILL
:
1339 case MOUNT_REMOUNTING_SIGKILL
:
1340 case MOUNT_UNMOUNTING_SIGKILL
:
1341 log_unit_warning(UNIT(m
),"Mount process still around after SIGKILL. Ignoring.");
1343 if (m
->from_proc_self_mountinfo
)
1344 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1346 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1350 assert_not_reached("Timeout at wrong time.");
1356 static int mount_setup_unit(
1360 const char *options
,
1364 _cleanup_free_
char *e
= NULL
, *w
= NULL
, *o
= NULL
, *f
= NULL
;
1365 bool load_extras
= false;
1367 bool delete, changed
= false;
1377 /* Ignore API mount points. They should never be referenced in
1378 * dependencies ever. */
1379 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1382 if (streq(fstype
, "autofs"))
1385 /* probably some kind of swap, ignore */
1386 if (!is_path(where
))
1389 r
= unit_name_from_path(where
, ".mount", &e
);
1393 u
= manager_get_unit(m
, e
);
1397 u
= unit_new(m
, sizeof(Mount
));
1401 r
= unit_add_name(u
, e
);
1405 MOUNT(u
)->where
= strdup(where
);
1406 if (!MOUNT(u
)->where
) {
1411 u
->source_path
= strdup("/proc/self/mountinfo");
1412 if (!u
->source_path
) {
1417 if (m
->running_as
== MANAGER_SYSTEM
) {
1420 target
= mount_needs_network(options
, fstype
) ? SPECIAL_REMOTE_FS_TARGET
: SPECIAL_LOCAL_FS_TARGET
;
1421 r
= unit_add_dependency_by_name(u
, UNIT_BEFORE
, target
, NULL
, true);
1425 if (should_umount(MOUNT(u
))) {
1426 r
= unit_add_dependency_by_name(u
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
1432 unit_add_to_load_queue(u
);
1437 if (!MOUNT(u
)->where
) {
1438 MOUNT(u
)->where
= strdup(where
);
1439 if (!MOUNT(u
)->where
) {
1445 if (m
->running_as
== MANAGER_SYSTEM
&&
1446 mount_needs_network(options
, fstype
)) {
1447 /* _netdev option may have shown up late, or on a
1448 * remount. Add remote-fs dependencies, even though
1449 * local-fs ones may already be there. */
1450 unit_add_dependency_by_name(u
, UNIT_BEFORE
, SPECIAL_REMOTE_FS_TARGET
, NULL
, true);
1454 if (u
->load_state
== UNIT_NOT_FOUND
) {
1455 u
->load_state
= UNIT_LOADED
;
1458 /* Load in the extras later on, after we
1459 * finished initialization of the unit */
1466 o
= strdup(options
);
1468 if (!w
|| !o
|| !f
) {
1473 p
= &MOUNT(u
)->parameters_proc_self_mountinfo
;
1475 changed
= changed
||
1476 !streq_ptr(p
->options
, options
) ||
1477 !streq_ptr(p
->what
, what
) ||
1478 !streq_ptr(p
->fstype
, fstype
);
1481 MOUNT(u
)->is_mounted
= true;
1482 MOUNT(u
)->just_mounted
= !MOUNT(u
)->from_proc_self_mountinfo
;
1483 MOUNT(u
)->just_changed
= changed
;
1486 MOUNT(u
)->from_proc_self_mountinfo
= true;
1501 r
= mount_add_extras(MOUNT(u
));
1507 unit_add_to_dbus_queue(u
);
1512 log_warning_errno(r
, "Failed to set up mount unit: %m");
1520 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1521 _cleanup_(mnt_free_tablep
) struct libmnt_table
*t
= NULL
;
1522 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*i
= NULL
;
1527 t
= mnt_new_table();
1531 i
= mnt_new_iter(MNT_ITER_FORWARD
);
1535 r
= mnt_table_parse_mtab(t
, NULL
);
1537 return log_error_errno(r
, "Failed to parse /proc/self/mountinfo: %m");
1541 const char *device
, *path
, *options
, *fstype
;
1542 _cleanup_free_
char *d
= NULL
, *p
= NULL
;
1543 struct libmnt_fs
*fs
;
1546 k
= mnt_table_next_fs(t
, i
, &fs
);
1550 return log_error_errno(k
, "Failed to get next entry from /proc/self/mountinfo: %m");
1552 device
= mnt_fs_get_source(fs
);
1553 path
= mnt_fs_get_target(fs
);
1554 options
= mnt_fs_get_options(fs
);
1555 fstype
= mnt_fs_get_fstype(fs
);
1557 if (!device
|| !path
)
1560 if (cunescape(device
, UNESCAPE_RELAX
, &d
) < 0)
1563 if (cunescape(path
, UNESCAPE_RELAX
, &p
) < 0)
1566 (void) device_found_node(m
, d
, true, DEVICE_FOUND_MOUNT
, set_flags
);
1568 k
= mount_setup_unit(m
, d
, p
, options
, fstype
, set_flags
);
1569 if (r
== 0 && k
< 0)
1576 static void mount_shutdown(Manager
*m
) {
1580 m
->mount_event_source
= sd_event_source_unref(m
->mount_event_source
);
1582 mnt_unref_monitor(m
->mount_monitor
);
1583 m
->mount_monitor
= NULL
;
1586 static int mount_get_timeout(Unit
*u
, uint64_t *timeout
) {
1587 Mount
*m
= MOUNT(u
);
1590 if (!m
->timer_event_source
)
1593 r
= sd_event_source_get_time(m
->timer_event_source
, timeout
);
1600 static void mount_enumerate(Manager
*m
) {
1607 if (!m
->mount_monitor
) {
1610 m
->mount_monitor
= mnt_new_monitor();
1611 if (!m
->mount_monitor
) {
1616 r
= mnt_monitor_enable_kernel(m
->mount_monitor
, 1);
1618 log_error_errno(r
, "Failed to enable watching of kernel mount events: %m");
1622 r
= mnt_monitor_enable_userspace(m
->mount_monitor
, 1, NULL
);
1624 log_error_errno(r
, "Failed to enable watching of userspace mount events: %m");
1628 /* mnt_unref_monitor() will close the fd */
1629 fd
= r
= mnt_monitor_get_fd(m
->mount_monitor
);
1631 log_error_errno(r
, "Failed to acquire watch file descriptor: %m");
1635 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fd
, EPOLLIN
, mount_dispatch_io
, m
);
1637 log_error_errno(r
, "Failed to watch mount file descriptor: %m");
1641 r
= sd_event_source_set_priority(m
->mount_event_source
, -10);
1643 log_error_errno(r
, "Failed to adjust mount watch priority: %m");
1647 (void) sd_event_source_set_description(m
->mount_event_source
, "mount-monitor-dispatch");
1650 r
= mount_load_proc_self_mountinfo(m
, false);
1660 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
1661 _cleanup_set_free_ Set
*around
= NULL
, *gone
= NULL
;
1662 Manager
*m
= userdata
;
1669 assert(revents
& EPOLLIN
);
1671 if (fd
== mnt_monitor_get_fd(m
->mount_monitor
)) {
1672 bool rescan
= false;
1674 /* Drain all events and verify that the event is valid.
1676 * Note that libmount also monitors /run/mount mkdir if the
1677 * directory does not exist yet. The mkdir may generate event
1678 * which is irrelevant for us.
1680 * error: r < 0; valid: r == 0, false positive: rc == 1 */
1682 r
= mnt_monitor_next_change(m
->mount_monitor
, NULL
, NULL
);
1686 return log_error_errno(r
, "Failed to drain libmount events");
1689 log_debug("libmount event [rescan: %s]", yes_no(rescan
));
1694 r
= mount_load_proc_self_mountinfo(m
, true);
1696 /* Reset flags, just in case, for later calls */
1697 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1698 Mount
*mount
= MOUNT(u
);
1700 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1706 manager_dispatch_load_queue(m
);
1708 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1709 Mount
*mount
= MOUNT(u
);
1711 if (!mount
->is_mounted
) {
1713 /* A mount point is not around right now. It
1714 * might be gone, or might never have
1717 if (mount
->from_proc_self_mountinfo
&&
1718 mount
->parameters_proc_self_mountinfo
.what
) {
1720 /* Remember that this device might just have disappeared */
1721 if (set_ensure_allocated(&gone
, &string_hash_ops
) < 0 ||
1722 set_put(gone
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1723 log_oom(); /* we don't care too much about OOM here... */
1726 mount
->from_proc_self_mountinfo
= false;
1728 switch (mount
->state
) {
1731 /* This has just been unmounted by
1732 * somebody else, follow the state
1734 mount_enter_dead(mount
, MOUNT_SUCCESS
);
1741 } else if (mount
->just_mounted
|| mount
->just_changed
) {
1743 /* A mount point was added or changed */
1745 switch (mount
->state
) {
1749 /* This has just been mounted by
1750 * somebody else, follow the state
1752 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
1755 case MOUNT_MOUNTING
:
1756 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
1760 /* Nothing really changed, but let's
1761 * issue an notification call
1762 * nonetheless, in case somebody is
1763 * waiting for this. (e.g. file system
1764 * ro/rw remounts.) */
1765 mount_set_state(mount
, mount
->state
);
1770 if (mount
->is_mounted
&&
1771 mount
->from_proc_self_mountinfo
&&
1772 mount
->parameters_proc_self_mountinfo
.what
) {
1774 if (set_ensure_allocated(&around
, &string_hash_ops
) < 0 ||
1775 set_put(around
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1779 /* Reset the flags for later calls */
1780 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1783 SET_FOREACH(what
, gone
, i
) {
1784 if (set_contains(around
, what
))
1787 /* Let the device units know that the device is no longer mounted */
1788 (void) device_found_node(m
, what
, false, DEVICE_FOUND_MOUNT
, true);
1794 static void mount_reset_failed(Unit
*u
) {
1795 Mount
*m
= MOUNT(u
);
1799 if (m
->state
== MOUNT_FAILED
)
1800 mount_set_state(m
, MOUNT_DEAD
);
1802 m
->result
= MOUNT_SUCCESS
;
1803 m
->reload_result
= MOUNT_SUCCESS
;
1806 static int mount_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
1807 return unit_kill_common(u
, who
, signo
, -1, MOUNT(u
)->control_pid
, error
);
1810 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
1811 [MOUNT_EXEC_MOUNT
] = "ExecMount",
1812 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
1813 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
1816 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
1818 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
1819 [MOUNT_SUCCESS
] = "success",
1820 [MOUNT_FAILURE_RESOURCES
] = "resources",
1821 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
1822 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
1823 [MOUNT_FAILURE_SIGNAL
] = "signal",
1824 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump"
1827 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
1829 const UnitVTable mount_vtable
= {
1830 .object_size
= sizeof(Mount
),
1831 .exec_context_offset
= offsetof(Mount
, exec_context
),
1832 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
1833 .kill_context_offset
= offsetof(Mount
, kill_context
),
1834 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
1840 .private_section
= "Mount",
1843 .no_instances
= true,
1849 .coldplug
= mount_coldplug
,
1853 .start
= mount_start
,
1855 .reload
= mount_reload
,
1859 .serialize
= mount_serialize
,
1860 .deserialize_item
= mount_deserialize_item
,
1862 .active_state
= mount_active_state
,
1863 .sub_state_to_string
= mount_sub_state_to_string
,
1865 .check_gc
= mount_check_gc
,
1867 .sigchld_event
= mount_sigchld_event
,
1869 .reset_failed
= mount_reset_failed
,
1871 .bus_vtable
= bus_mount_vtable
,
1872 .bus_set_property
= bus_mount_set_property
,
1873 .bus_commit_properties
= bus_mount_commit_properties
,
1875 .get_timeout
= mount_get_timeout
,
1877 .can_transient
= true,
1879 .enumerate
= mount_enumerate
,
1880 .shutdown
= mount_shutdown
,
1882 .status_message_formats
= {
1883 .starting_stopping
= {
1884 [0] = "Mounting %s...",
1885 [1] = "Unmounting %s...",
1887 .finished_start_job
= {
1888 [JOB_DONE
] = "Mounted %s.",
1889 [JOB_FAILED
] = "Failed to mount %s.",
1890 [JOB_TIMEOUT
] = "Timed out mounting %s.",
1892 .finished_stop_job
= {
1893 [JOB_DONE
] = "Unmounted %s.",
1894 [JOB_FAILED
] = "Failed unmounting %s.",
1895 [JOB_TIMEOUT
] = "Timed out unmounting %s.",