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/>.
24 #include <sys/epoll.h>
31 #include "sd-messages.h"
34 #include "path-util.h"
35 #include "mount-setup.h"
36 #include "unit-name.h"
37 #include "dbus-mount.h"
39 #include "exit-status.h"
40 #include "fstab-util.h"
41 #include "formats-util.h"
43 #define RETRY_UMOUNT_MAX 32
45 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table
*, mnt_free_table
);
46 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter
*, mnt_free_iter
);
48 static const UnitActiveState state_translation_table
[_MOUNT_STATE_MAX
] = {
49 [MOUNT_DEAD
] = UNIT_INACTIVE
,
50 [MOUNT_MOUNTING
] = UNIT_ACTIVATING
,
51 [MOUNT_MOUNTING_DONE
] = UNIT_ACTIVE
,
52 [MOUNT_MOUNTED
] = UNIT_ACTIVE
,
53 [MOUNT_REMOUNTING
] = UNIT_RELOADING
,
54 [MOUNT_UNMOUNTING
] = UNIT_DEACTIVATING
,
55 [MOUNT_MOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
56 [MOUNT_MOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
57 [MOUNT_REMOUNTING_SIGTERM
] = UNIT_RELOADING
,
58 [MOUNT_REMOUNTING_SIGKILL
] = UNIT_RELOADING
,
59 [MOUNT_UNMOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
60 [MOUNT_UNMOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
61 [MOUNT_FAILED
] = UNIT_FAILED
64 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
65 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
67 static bool mount_needs_network(const char *options
, const char *fstype
) {
68 if (fstab_test_option(options
, "_netdev\0"))
71 if (fstype
&& fstype_is_network(fstype
))
77 static bool mount_is_network(const MountParameters
*p
) {
80 return mount_needs_network(p
->options
, p
->fstype
);
83 static bool mount_is_bind(const MountParameters
*p
) {
86 if (fstab_test_option(p
->options
, "bind\0" "rbind\0"))
89 if (p
->fstype
&& STR_IN_SET(p
->fstype
, "bind", "rbind"))
95 static bool mount_is_auto(const MountParameters
*p
) {
98 return !fstab_test_option(p
->options
, "noauto\0");
101 static bool needs_quota(const MountParameters
*p
) {
104 /* Quotas are not enabled on network filesystems,
105 * but we want them, for example, on storage connected via iscsi */
106 if (p
->fstype
&& fstype_is_network(p
->fstype
))
109 if (mount_is_bind(p
))
112 return fstab_test_option(p
->options
,
113 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
116 static void mount_init(Unit
*u
) {
120 assert(u
->load_state
== UNIT_STUB
);
122 m
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
123 m
->directory_mode
= 0755;
125 if (unit_has_name(u
, "-.mount")) {
126 /* Don't allow start/stop for root directory */
127 u
->refuse_manual_start
= true;
128 u
->refuse_manual_stop
= true;
130 /* The stdio/kmsg bridge socket is on /, in order to avoid a
131 * dep loop, don't use kmsg logging for -.mount */
132 m
->exec_context
.std_output
= u
->manager
->default_std_output
;
133 m
->exec_context
.std_error
= u
->manager
->default_std_error
;
136 /* We need to make sure that /usr/bin/mount is always called
137 * in the same process group as us, so that the autofs kernel
138 * side doesn't send us another mount request while we are
139 * already trying to comply its last one. */
140 m
->exec_context
.same_pgrp
= true;
142 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
144 u
->ignore_on_isolate
= true;
147 static int mount_arm_timer(Mount
*m
) {
152 if (m
->timeout_usec
<= 0) {
153 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
157 if (m
->timer_event_source
) {
158 r
= sd_event_source_set_time(m
->timer_event_source
, now(CLOCK_MONOTONIC
) + m
->timeout_usec
);
162 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_ONESHOT
);
165 r
= sd_event_add_time(
166 UNIT(m
)->manager
->event
,
167 &m
->timer_event_source
,
169 now(CLOCK_MONOTONIC
) + m
->timeout_usec
, 0,
170 mount_dispatch_timer
, m
);
174 (void) sd_event_source_set_description(m
->timer_event_source
, "mount-timer");
179 static void mount_unwatch_control_pid(Mount
*m
) {
182 if (m
->control_pid
<= 0)
185 unit_unwatch_pid(UNIT(m
), m
->control_pid
);
189 static void mount_parameters_done(MountParameters
*p
) {
196 p
->what
= p
->options
= p
->fstype
= NULL
;
199 static void mount_done(Unit
*u
) {
204 m
->where
= mfree(m
->where
);
206 mount_parameters_done(&m
->parameters_proc_self_mountinfo
);
207 mount_parameters_done(&m
->parameters_fragment
);
209 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
210 exec_command_done_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
211 m
->control_command
= NULL
;
213 mount_unwatch_control_pid(m
);
215 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
218 _pure_
static MountParameters
* get_mount_parameters_fragment(Mount
*m
) {
221 if (m
->from_fragment
)
222 return &m
->parameters_fragment
;
227 _pure_
static MountParameters
* get_mount_parameters(Mount
*m
) {
230 if (m
->from_proc_self_mountinfo
)
231 return &m
->parameters_proc_self_mountinfo
;
233 return get_mount_parameters_fragment(m
);
236 static int mount_add_mount_links(Mount
*m
) {
237 _cleanup_free_
char *parent
= NULL
;
246 if (!path_equal(m
->where
, "/")) {
247 /* Adds in links to other mount points that might lie further
248 * up in the hierarchy */
249 r
= path_get_parent(m
->where
, &parent
);
253 r
= unit_require_mounts_for(UNIT(m
), parent
);
258 /* Adds in links to other mount points that might be needed
259 * for the source path (if this is a bind mount) to be
261 pm
= get_mount_parameters_fragment(m
);
262 if (pm
&& pm
->what
&&
263 path_is_absolute(pm
->what
) &&
264 !mount_is_network(pm
)) {
266 r
= unit_require_mounts_for(UNIT(m
), pm
->what
);
271 /* Adds in links to other units that use this path or paths
272 * further down in the hierarchy */
273 s
= manager_get_units_requiring_mounts_for(UNIT(m
)->manager
, m
->where
);
274 SET_FOREACH(other
, s
, i
) {
276 if (other
->load_state
!= UNIT_LOADED
)
279 if (other
== UNIT(m
))
282 r
= unit_add_dependency(other
, UNIT_AFTER
, UNIT(m
), true);
286 if (UNIT(m
)->fragment_path
) {
287 /* If we have fragment configuration, then make this dependency required */
288 r
= unit_add_dependency(other
, UNIT_REQUIRES
, UNIT(m
), true);
297 static int mount_add_device_links(Mount
*m
) {
299 bool device_wants_mount
= false;
304 p
= get_mount_parameters(m
);
311 if (mount_is_bind(p
))
314 if (!is_device_path(p
->what
))
317 /* /dev/root is a really weird thing, it's not a real device,
318 * but just a path the kernel exports for the root file system
319 * specified on the kernel command line. Ignore it here. */
320 if (path_equal(p
->what
, "/dev/root"))
323 if (path_equal(m
->where
, "/"))
326 if (mount_is_auto(p
) && UNIT(m
)->manager
->running_as
== MANAGER_SYSTEM
)
327 device_wants_mount
= true;
329 r
= unit_add_node_link(UNIT(m
), p
->what
, device_wants_mount
);
336 static int mount_add_quota_links(Mount
*m
) {
342 if (UNIT(m
)->manager
->running_as
!= MANAGER_SYSTEM
)
345 p
= get_mount_parameters_fragment(m
);
352 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
, NULL
, true);
356 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
, NULL
, true);
363 static bool should_umount(Mount
*m
) {
366 if (path_equal(m
->where
, "/") ||
367 path_equal(m
->where
, "/usr"))
370 p
= get_mount_parameters(m
);
371 if (p
&& fstab_test_option(p
->options
, "x-initrd.mount\0") &&
378 static int mount_add_default_dependencies(Mount
*m
) {
379 const char *after
, *after2
, *online
;
385 if (UNIT(m
)->manager
->running_as
!= MANAGER_SYSTEM
)
388 /* We do not add any default dependencies to / and /usr, since
389 * they are guaranteed to stay mounted the whole time, since
390 * our system is on it. Also, don't bother with anything
391 * mounted below virtual file systems, it's also going to be
392 * virtual, and hence not worth the effort. */
393 if (path_equal(m
->where
, "/") ||
394 path_equal(m
->where
, "/usr") ||
395 path_startswith(m
->where
, "/proc") ||
396 path_startswith(m
->where
, "/sys") ||
397 path_startswith(m
->where
, "/dev"))
400 p
= get_mount_parameters(m
);
404 if (mount_is_network(p
)) {
405 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
406 after2
= SPECIAL_NETWORK_TARGET
;
407 online
= SPECIAL_NETWORK_ONLINE_TARGET
;
409 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
414 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, NULL
, true);
419 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after2
, NULL
, true);
425 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, online
, NULL
, true);
430 if (should_umount(m
)) {
431 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
439 static int mount_verify(Mount
*m
) {
440 _cleanup_free_
char *e
= NULL
;
445 if (UNIT(m
)->load_state
!= UNIT_LOADED
)
448 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
)
451 r
= unit_name_from_path(m
->where
, ".mount", &e
);
453 return log_unit_error_errno(UNIT(m
), r
, "Failed to generate unit name from mount path: %m");
455 if (!unit_has_name(UNIT(m
), e
)) {
456 log_unit_error(UNIT(m
), "Where= setting doesn't match unit name. Refusing.");
460 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
)) {
461 log_unit_error(UNIT(m
), "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
465 if (UNIT(m
)->fragment_path
&& !m
->parameters_fragment
.what
) {
466 log_unit_error(UNIT(m
), "What= setting is missing. Refusing.");
470 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
) {
471 log_unit_error(UNIT(m
), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
478 static int mount_add_extras(Mount
*m
) {
484 if (u
->fragment_path
)
485 m
->from_fragment
= true;
488 r
= unit_name_to_path(u
->id
, &m
->where
);
493 path_kill_slashes(m
->where
);
495 if (!u
->description
) {
496 r
= unit_set_description(u
, m
->where
);
501 r
= mount_add_device_links(m
);
505 r
= mount_add_mount_links(m
);
509 r
= mount_add_quota_links(m
);
513 r
= unit_patch_contexts(u
);
517 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
521 r
= unit_set_default_slice(u
);
525 if (u
->default_dependencies
) {
526 r
= mount_add_default_dependencies(m
);
534 static int mount_load(Unit
*u
) {
539 assert(u
->load_state
== UNIT_STUB
);
541 if (m
->from_proc_self_mountinfo
)
542 r
= unit_load_fragment_and_dropin_optional(u
);
544 r
= unit_load_fragment_and_dropin(u
);
549 /* This is a new unit? Then let's add in some extras */
550 if (u
->load_state
== UNIT_LOADED
) {
551 r
= mount_add_extras(m
);
556 return mount_verify(m
);
559 static int mount_notify_automount(Mount
*m
, MountState old_state
, MountState state
) {
566 SET_FOREACH(p
, UNIT(m
)->dependencies
[UNIT_TRIGGERED_BY
], i
)
567 if (p
->type
== UNIT_AUTOMOUNT
) {
568 r
= automount_update_mount(AUTOMOUNT(p
), old_state
, state
);
576 static void mount_set_state(Mount
*m
, MountState state
) {
577 MountState old_state
;
580 old_state
= m
->state
;
583 if (state
!= MOUNT_MOUNTING
&&
584 state
!= MOUNT_MOUNTING_DONE
&&
585 state
!= MOUNT_REMOUNTING
&&
586 state
!= MOUNT_UNMOUNTING
&&
587 state
!= MOUNT_MOUNTING_SIGTERM
&&
588 state
!= MOUNT_MOUNTING_SIGKILL
&&
589 state
!= MOUNT_UNMOUNTING_SIGTERM
&&
590 state
!= MOUNT_UNMOUNTING_SIGKILL
&&
591 state
!= MOUNT_REMOUNTING_SIGTERM
&&
592 state
!= MOUNT_REMOUNTING_SIGKILL
) {
593 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
594 mount_unwatch_control_pid(m
);
595 m
->control_command
= NULL
;
596 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
599 mount_notify_automount(m
, old_state
, state
);
601 if (state
!= old_state
)
602 log_unit_debug(UNIT(m
), "Changed %s -> %s", mount_state_to_string(old_state
), mount_state_to_string(state
));
604 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
605 m
->reload_result
= MOUNT_SUCCESS
;
608 static int mount_coldplug(Unit
*u
) {
610 MountState new_state
= MOUNT_DEAD
;
614 assert(m
->state
== MOUNT_DEAD
);
616 if (m
->deserialized_state
!= m
->state
)
617 new_state
= m
->deserialized_state
;
618 else if (m
->from_proc_self_mountinfo
)
619 new_state
= MOUNT_MOUNTED
;
621 if (new_state
== m
->state
)
624 if (new_state
== MOUNT_MOUNTING
||
625 new_state
== MOUNT_MOUNTING_DONE
||
626 new_state
== MOUNT_REMOUNTING
||
627 new_state
== MOUNT_UNMOUNTING
||
628 new_state
== MOUNT_MOUNTING_SIGTERM
||
629 new_state
== MOUNT_MOUNTING_SIGKILL
||
630 new_state
== MOUNT_UNMOUNTING_SIGTERM
||
631 new_state
== MOUNT_UNMOUNTING_SIGKILL
||
632 new_state
== MOUNT_REMOUNTING_SIGTERM
||
633 new_state
== MOUNT_REMOUNTING_SIGKILL
) {
635 if (m
->control_pid
<= 0)
638 r
= unit_watch_pid(UNIT(m
), m
->control_pid
);
642 r
= mount_arm_timer(m
);
647 mount_set_state(m
, new_state
);
651 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
658 p
= get_mount_parameters(m
);
661 "%sMount State: %s\n"
665 "%sFile System Type: %s\n"
667 "%sFrom /proc/self/mountinfo: %s\n"
668 "%sFrom fragment: %s\n"
669 "%sDirectoryMode: %04o\n",
670 prefix
, mount_state_to_string(m
->state
),
671 prefix
, mount_result_to_string(m
->result
),
673 prefix
, p
? strna(p
->what
) : "n/a",
674 prefix
, p
? strna(p
->fstype
) : "n/a",
675 prefix
, p
? strna(p
->options
) : "n/a",
676 prefix
, yes_no(m
->from_proc_self_mountinfo
),
677 prefix
, yes_no(m
->from_fragment
),
678 prefix
, m
->directory_mode
);
680 if (m
->control_pid
> 0)
682 "%sControl PID: "PID_FMT
"\n",
683 prefix
, m
->control_pid
);
685 exec_context_dump(&m
->exec_context
, f
, prefix
);
686 kill_context_dump(&m
->kill_context
, f
, prefix
);
689 static int mount_spawn(Mount
*m
, ExecCommand
*c
, pid_t
*_pid
) {
692 ExecParameters exec_params
= {
693 .apply_permissions
= true,
694 .apply_chroot
= true,
695 .apply_tty_stdin
= true,
696 .bus_endpoint_fd
= -1,
703 (void) unit_realize_cgroup(UNIT(m
));
704 if (m
->reset_cpu_usage
) {
705 (void) unit_reset_cpu_usage(UNIT(m
));
706 m
->reset_cpu_usage
= false;
709 r
= unit_setup_exec_runtime(UNIT(m
));
713 r
= mount_arm_timer(m
);
717 exec_params
.environment
= UNIT(m
)->manager
->environment
;
718 exec_params
.confirm_spawn
= UNIT(m
)->manager
->confirm_spawn
;
719 exec_params
.cgroup_supported
= UNIT(m
)->manager
->cgroup_supported
;
720 exec_params
.cgroup_path
= UNIT(m
)->cgroup_path
;
721 exec_params
.cgroup_delegate
= m
->cgroup_context
.delegate
;
722 exec_params
.runtime_prefix
= manager_get_runtime_prefix(UNIT(m
)->manager
);
724 r
= exec_spawn(UNIT(m
),
733 r
= unit_watch_pid(UNIT(m
), pid
);
735 /* FIXME: we need to do something here */
743 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
748 static void mount_enter_dead(Mount
*m
, MountResult f
) {
751 if (f
!= MOUNT_SUCCESS
)
754 exec_runtime_destroy(m
->exec_runtime
);
755 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
757 exec_context_destroy_runtime_directory(&m
->exec_context
, manager_get_runtime_prefix(UNIT(m
)->manager
));
759 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
762 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
765 if (f
!= MOUNT_SUCCESS
)
768 mount_set_state(m
, MOUNT_MOUNTED
);
771 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
776 if (f
!= MOUNT_SUCCESS
)
779 r
= unit_kill_context(
782 (state
!= MOUNT_MOUNTING_SIGTERM
&& state
!= MOUNT_UNMOUNTING_SIGTERM
&& state
!= MOUNT_REMOUNTING_SIGTERM
) ?
783 KILL_KILL
: KILL_TERMINATE
,
791 r
= mount_arm_timer(m
);
795 mount_set_state(m
, state
);
796 } else if (state
== MOUNT_REMOUNTING_SIGTERM
)
797 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
798 else if (state
== MOUNT_REMOUNTING_SIGKILL
)
799 mount_enter_mounted(m
, MOUNT_SUCCESS
);
800 else if (state
== MOUNT_MOUNTING_SIGTERM
)
801 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_SUCCESS
);
802 else if (state
== MOUNT_UNMOUNTING_SIGTERM
)
803 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
805 mount_enter_dead(m
, MOUNT_SUCCESS
);
810 log_unit_warning_errno(UNIT(m
), r
, "Failed to kill processes: %m");
812 if (state
== MOUNT_REMOUNTING_SIGTERM
|| state
== MOUNT_REMOUNTING_SIGKILL
)
813 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
815 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
818 static void mount_enter_unmounting(Mount
*m
) {
823 /* Start counting our attempts */
824 if (!IN_SET(m
->state
,
826 MOUNT_UNMOUNTING_SIGTERM
,
827 MOUNT_UNMOUNTING_SIGKILL
))
828 m
->n_retry_umount
= 0;
830 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
831 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
833 r
= exec_command_set(m
->control_command
, UMOUNT_PATH
, m
->where
, NULL
);
837 mount_unwatch_control_pid(m
);
839 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
843 mount_set_state(m
, MOUNT_UNMOUNTING
);
848 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'umount' task: %m");
849 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
852 static void mount_enter_mounting(Mount
*m
) {
858 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
859 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
861 r
= unit_fail_if_symlink(UNIT(m
), m
->where
);
865 (void) mkdir_p_label(m
->where
, m
->directory_mode
);
867 unit_warn_if_dir_nonempty(UNIT(m
), m
->where
);
869 /* Create the source directory for bind-mounts if needed */
870 p
= get_mount_parameters_fragment(m
);
871 if (p
&& mount_is_bind(p
))
872 (void) mkdir_p_label(p
->what
, m
->directory_mode
);
874 if (m
->from_fragment
) {
875 _cleanup_free_
char *opts
= NULL
;
877 r
= fstab_filter_options(m
->parameters_fragment
.options
,
878 "nofail\0" "noauto\0" "auto\0", NULL
, NULL
, &opts
);
882 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
883 m
->parameters_fragment
.what
, m
->where
, NULL
);
884 if (r
>= 0 && m
->sloppy_options
)
885 r
= exec_command_append(m
->control_command
, "-s", NULL
);
886 if (r
>= 0 && m
->parameters_fragment
.fstype
)
887 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
888 if (r
>= 0 && !isempty(opts
))
889 r
= exec_command_append(m
->control_command
, "-o", opts
, NULL
);
896 mount_unwatch_control_pid(m
);
898 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
902 mount_set_state(m
, MOUNT_MOUNTING
);
907 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'mount' task: %m");
908 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
911 static void mount_enter_remounting(Mount
*m
) {
916 m
->control_command_id
= MOUNT_EXEC_REMOUNT
;
917 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_REMOUNT
;
919 if (m
->from_fragment
) {
922 if (m
->parameters_fragment
.options
)
923 o
= strjoina("remount,", m
->parameters_fragment
.options
);
927 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
928 m
->parameters_fragment
.what
, m
->where
,
930 if (r
>= 0 && m
->sloppy_options
)
931 r
= exec_command_append(m
->control_command
, "-s", NULL
);
932 if (r
>= 0 && m
->parameters_fragment
.fstype
)
933 r
= exec_command_append(m
->control_command
, "-t", m
->parameters_fragment
.fstype
, NULL
);
940 mount_unwatch_control_pid(m
);
942 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
946 mount_set_state(m
, MOUNT_REMOUNTING
);
951 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'remount' task: %m");
952 m
->reload_result
= MOUNT_FAILURE_RESOURCES
;
953 mount_enter_mounted(m
, MOUNT_SUCCESS
);
956 static int mount_start(Unit
*u
) {
961 /* We cannot fulfill this request right now, try again later
963 if (m
->state
== MOUNT_UNMOUNTING
||
964 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
965 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
966 m
->state
== MOUNT_MOUNTING_SIGTERM
||
967 m
->state
== MOUNT_MOUNTING_SIGKILL
)
971 if (m
->state
== MOUNT_MOUNTING
)
974 assert(m
->state
== MOUNT_DEAD
|| m
->state
== MOUNT_FAILED
);
976 m
->result
= MOUNT_SUCCESS
;
977 m
->reload_result
= MOUNT_SUCCESS
;
978 m
->reset_cpu_usage
= true;
980 mount_enter_mounting(m
);
984 static int mount_stop(Unit
*u
) {
990 if (m
->state
== MOUNT_UNMOUNTING
||
991 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
992 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
993 m
->state
== MOUNT_MOUNTING_SIGTERM
||
994 m
->state
== MOUNT_MOUNTING_SIGKILL
)
997 assert(m
->state
== MOUNT_MOUNTING
||
998 m
->state
== MOUNT_MOUNTING_DONE
||
999 m
->state
== MOUNT_MOUNTED
||
1000 m
->state
== MOUNT_REMOUNTING
||
1001 m
->state
== MOUNT_REMOUNTING_SIGTERM
||
1002 m
->state
== MOUNT_REMOUNTING_SIGKILL
);
1004 mount_enter_unmounting(m
);
1008 static int mount_reload(Unit
*u
) {
1009 Mount
*m
= MOUNT(u
);
1013 if (m
->state
== MOUNT_MOUNTING_DONE
)
1016 assert(m
->state
== MOUNT_MOUNTED
);
1018 mount_enter_remounting(m
);
1022 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1023 Mount
*m
= MOUNT(u
);
1029 unit_serialize_item(u
, f
, "state", mount_state_to_string(m
->state
));
1030 unit_serialize_item(u
, f
, "result", mount_result_to_string(m
->result
));
1031 unit_serialize_item(u
, f
, "reload-result", mount_result_to_string(m
->reload_result
));
1033 if (m
->control_pid
> 0)
1034 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, m
->control_pid
);
1036 if (m
->control_command_id
>= 0)
1037 unit_serialize_item(u
, f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1042 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1043 Mount
*m
= MOUNT(u
);
1050 if (streq(key
, "state")) {
1053 if ((state
= mount_state_from_string(value
)) < 0)
1054 log_unit_debug(u
, "Failed to parse state value: %s", value
);
1056 m
->deserialized_state
= state
;
1057 } else if (streq(key
, "result")) {
1060 f
= mount_result_from_string(value
);
1062 log_unit_debug(u
, "Failed to parse result value: %s", value
);
1063 else if (f
!= MOUNT_SUCCESS
)
1066 } else if (streq(key
, "reload-result")) {
1069 f
= mount_result_from_string(value
);
1071 log_unit_debug(u
, "Failed to parse reload result value: %s", value
);
1072 else if (f
!= MOUNT_SUCCESS
)
1073 m
->reload_result
= f
;
1075 } else if (streq(key
, "control-pid")) {
1078 if (parse_pid(value
, &pid
) < 0)
1079 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
1081 m
->control_pid
= pid
;
1082 } else if (streq(key
, "control-command")) {
1083 MountExecCommand id
;
1085 id
= mount_exec_command_from_string(value
);
1087 log_unit_debug(u
, "Failed to parse exec-command value: %s", value
);
1089 m
->control_command_id
= id
;
1090 m
->control_command
= m
->exec_command
+ id
;
1093 log_unit_debug(u
, "Unknown serialization key: %s", key
);
1098 _pure_
static UnitActiveState
mount_active_state(Unit
*u
) {
1101 return state_translation_table
[MOUNT(u
)->state
];
1104 _pure_
static const char *mount_sub_state_to_string(Unit
*u
) {
1107 return mount_state_to_string(MOUNT(u
)->state
);
1110 _pure_
static bool mount_check_gc(Unit
*u
) {
1111 Mount
*m
= MOUNT(u
);
1115 return m
->from_proc_self_mountinfo
;
1118 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1119 Mount
*m
= MOUNT(u
);
1125 if (pid
!= m
->control_pid
)
1130 if (is_clean_exit(code
, status
, NULL
))
1132 else if (code
== CLD_EXITED
)
1133 f
= MOUNT_FAILURE_EXIT_CODE
;
1134 else if (code
== CLD_KILLED
)
1135 f
= MOUNT_FAILURE_SIGNAL
;
1136 else if (code
== CLD_DUMPED
)
1137 f
= MOUNT_FAILURE_CORE_DUMP
;
1139 assert_not_reached("Unknown code");
1141 if (f
!= MOUNT_SUCCESS
)
1144 if (m
->control_command
) {
1145 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1147 m
->control_command
= NULL
;
1148 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1151 log_unit_full(u
, f
== MOUNT_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
1152 "Mount process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
1154 /* Note that mount(8) returning and the kernel sending us a
1155 * mount table change event might happen out-of-order. If an
1156 * operation succeed we assume the kernel will follow soon too
1157 * and already change into the resulting state. If it fails
1158 * we check if the kernel still knows about the mount. and
1159 * change state accordingly. */
1163 case MOUNT_MOUNTING
:
1164 case MOUNT_MOUNTING_DONE
:
1165 case MOUNT_MOUNTING_SIGKILL
:
1166 case MOUNT_MOUNTING_SIGTERM
:
1168 if (f
== MOUNT_SUCCESS
)
1169 mount_enter_mounted(m
, f
);
1170 else if (m
->from_proc_self_mountinfo
)
1171 mount_enter_mounted(m
, f
);
1173 mount_enter_dead(m
, f
);
1176 case MOUNT_REMOUNTING
:
1177 case MOUNT_REMOUNTING_SIGKILL
:
1178 case MOUNT_REMOUNTING_SIGTERM
:
1180 m
->reload_result
= f
;
1181 if (m
->from_proc_self_mountinfo
)
1182 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1184 mount_enter_dead(m
, MOUNT_SUCCESS
);
1188 case MOUNT_UNMOUNTING
:
1189 case MOUNT_UNMOUNTING_SIGKILL
:
1190 case MOUNT_UNMOUNTING_SIGTERM
:
1192 if (f
== MOUNT_SUCCESS
) {
1194 if (m
->from_proc_self_mountinfo
) {
1196 /* Still a mount point? If so, let's
1197 * try again. Most likely there were
1198 * multiple mount points stacked on
1199 * top of each other. Note that due to
1200 * the io event priority logic we can
1201 * be sure the new mountinfo is loaded
1202 * before we process the SIGCHLD for
1203 * the mount command. */
1205 if (m
->n_retry_umount
< RETRY_UMOUNT_MAX
) {
1206 log_unit_debug(u
, "Mount still present, trying again.");
1207 m
->n_retry_umount
++;
1208 mount_enter_unmounting(m
);
1210 log_unit_debug(u
, "Mount still present after %u attempts to unmount, giving up.", m
->n_retry_umount
);
1211 mount_enter_mounted(m
, f
);
1214 mount_enter_dead(m
, f
);
1216 } else if (m
->from_proc_self_mountinfo
)
1217 mount_enter_mounted(m
, f
);
1219 mount_enter_dead(m
, f
);
1223 assert_not_reached("Uh, control process died at wrong time.");
1226 /* Notify clients about changed exit status */
1227 unit_add_to_dbus_queue(u
);
1230 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1231 Mount
*m
= MOUNT(userdata
);
1234 assert(m
->timer_event_source
== source
);
1238 case MOUNT_MOUNTING
:
1239 case MOUNT_MOUNTING_DONE
:
1240 log_unit_warning(UNIT(m
), "Mounting timed out. Stopping.");
1241 mount_enter_signal(m
, MOUNT_MOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1244 case MOUNT_REMOUNTING
:
1245 log_unit_warning(UNIT(m
), "Remounting timed out. Stopping.");
1246 m
->reload_result
= MOUNT_FAILURE_TIMEOUT
;
1247 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1250 case MOUNT_UNMOUNTING
:
1251 log_unit_warning(UNIT(m
), "Unmounting timed out. Stopping.");
1252 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1255 case MOUNT_MOUNTING_SIGTERM
:
1256 if (m
->kill_context
.send_sigkill
) {
1257 log_unit_warning(UNIT(m
), "Mounting timed out. Killing.");
1258 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1260 log_unit_warning(UNIT(m
), "Mounting timed out. Skipping SIGKILL. Ignoring.");
1262 if (m
->from_proc_self_mountinfo
)
1263 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1265 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1269 case MOUNT_REMOUNTING_SIGTERM
:
1270 if (m
->kill_context
.send_sigkill
) {
1271 log_unit_warning(UNIT(m
), "Remounting timed out. Killing.");
1272 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1274 log_unit_warning(UNIT(m
), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1276 if (m
->from_proc_self_mountinfo
)
1277 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1279 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1283 case MOUNT_UNMOUNTING_SIGTERM
:
1284 if (m
->kill_context
.send_sigkill
) {
1285 log_unit_warning(UNIT(m
), "Unmounting timed out. Killing.");
1286 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1288 log_unit_warning(UNIT(m
), "Unmounting timed out. Skipping SIGKILL. Ignoring.");
1290 if (m
->from_proc_self_mountinfo
)
1291 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1293 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1297 case MOUNT_MOUNTING_SIGKILL
:
1298 case MOUNT_REMOUNTING_SIGKILL
:
1299 case MOUNT_UNMOUNTING_SIGKILL
:
1300 log_unit_warning(UNIT(m
),"Mount process still around after 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 assert_not_reached("Timeout at wrong time.");
1315 static int mount_setup_unit(
1319 const char *options
,
1323 _cleanup_free_
char *e
= NULL
, *w
= NULL
, *o
= NULL
, *f
= NULL
;
1324 bool load_extras
= false;
1326 bool delete, changed
= false;
1336 /* Ignore API mount points. They should never be referenced in
1337 * dependencies ever. */
1338 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1341 if (streq(fstype
, "autofs"))
1344 /* probably some kind of swap, ignore */
1345 if (!is_path(where
))
1348 r
= unit_name_from_path(where
, ".mount", &e
);
1352 u
= manager_get_unit(m
, e
);
1356 u
= unit_new(m
, sizeof(Mount
));
1360 r
= unit_add_name(u
, e
);
1364 MOUNT(u
)->where
= strdup(where
);
1365 if (!MOUNT(u
)->where
) {
1370 u
->source_path
= strdup("/proc/self/mountinfo");
1371 if (!u
->source_path
) {
1376 if (m
->running_as
== MANAGER_SYSTEM
) {
1379 target
= mount_needs_network(options
, fstype
) ? SPECIAL_REMOTE_FS_TARGET
: SPECIAL_LOCAL_FS_TARGET
;
1380 r
= unit_add_dependency_by_name(u
, UNIT_BEFORE
, target
, NULL
, true);
1384 if (should_umount(MOUNT(u
))) {
1385 r
= unit_add_dependency_by_name(u
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
1391 unit_add_to_load_queue(u
);
1396 if (!MOUNT(u
)->where
) {
1397 MOUNT(u
)->where
= strdup(where
);
1398 if (!MOUNT(u
)->where
) {
1404 if (m
->running_as
== MANAGER_SYSTEM
&&
1405 mount_needs_network(options
, fstype
)) {
1406 /* _netdev option may have shown up late, or on a
1407 * remount. Add remote-fs dependencies, even though
1408 * local-fs ones may already be there. */
1409 unit_add_dependency_by_name(u
, UNIT_BEFORE
, SPECIAL_REMOTE_FS_TARGET
, NULL
, true);
1413 if (u
->load_state
== UNIT_NOT_FOUND
) {
1414 u
->load_state
= UNIT_LOADED
;
1417 /* Load in the extras later on, after we
1418 * finished initialization of the unit */
1425 o
= strdup(options
);
1427 if (!w
|| !o
|| !f
) {
1432 p
= &MOUNT(u
)->parameters_proc_self_mountinfo
;
1434 changed
= changed
||
1435 !streq_ptr(p
->options
, options
) ||
1436 !streq_ptr(p
->what
, what
) ||
1437 !streq_ptr(p
->fstype
, fstype
);
1440 MOUNT(u
)->is_mounted
= true;
1441 MOUNT(u
)->just_mounted
= !MOUNT(u
)->from_proc_self_mountinfo
;
1442 MOUNT(u
)->just_changed
= changed
;
1445 MOUNT(u
)->from_proc_self_mountinfo
= true;
1460 r
= mount_add_extras(MOUNT(u
));
1466 unit_add_to_dbus_queue(u
);
1471 log_warning_errno(r
, "Failed to set up mount unit: %m");
1479 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1480 _cleanup_(mnt_free_tablep
) struct libmnt_table
*t
= NULL
;
1481 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*i
= NULL
;
1486 t
= mnt_new_table();
1490 i
= mnt_new_iter(MNT_ITER_FORWARD
);
1494 r
= mnt_table_parse_mtab(t
, NULL
);
1496 return log_error_errno(r
, "Failed to parse /proc/self/mountinfo: %m");
1500 const char *device
, *path
, *options
, *fstype
;
1501 _cleanup_free_
char *d
= NULL
, *p
= NULL
;
1502 struct libmnt_fs
*fs
;
1505 k
= mnt_table_next_fs(t
, i
, &fs
);
1509 return log_error_errno(k
, "Failed to get next entry from /proc/self/mountinfo: %m");
1511 device
= mnt_fs_get_source(fs
);
1512 path
= mnt_fs_get_target(fs
);
1513 options
= mnt_fs_get_options(fs
);
1514 fstype
= mnt_fs_get_fstype(fs
);
1516 if (!device
|| !path
)
1519 if (cunescape(device
, UNESCAPE_RELAX
, &d
) < 0)
1522 if (cunescape(path
, UNESCAPE_RELAX
, &p
) < 0)
1525 (void) device_found_node(m
, d
, true, DEVICE_FOUND_MOUNT
, set_flags
);
1527 k
= mount_setup_unit(m
, d
, p
, options
, fstype
, set_flags
);
1528 if (r
== 0 && k
< 0)
1535 static void mount_shutdown(Manager
*m
) {
1539 m
->mount_event_source
= sd_event_source_unref(m
->mount_event_source
);
1541 mnt_unref_monitor(m
->mount_monitor
);
1542 m
->mount_monitor
= NULL
;
1545 static int mount_get_timeout(Unit
*u
, uint64_t *timeout
) {
1546 Mount
*m
= MOUNT(u
);
1549 if (!m
->timer_event_source
)
1552 r
= sd_event_source_get_time(m
->timer_event_source
, timeout
);
1559 static int mount_enumerate(Manager
*m
) {
1566 if (!m
->mount_monitor
) {
1569 m
->mount_monitor
= mnt_new_monitor();
1570 if (!m
->mount_monitor
) {
1575 r
= mnt_monitor_enable_kernel(m
->mount_monitor
, 1);
1578 r
= mnt_monitor_enable_userspace(m
->mount_monitor
, 1, NULL
);
1582 /* mnt_unref_monitor() will close the fd */
1583 fd
= r
= mnt_monitor_get_fd(m
->mount_monitor
);
1587 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fd
, EPOLLIN
, mount_dispatch_io
, m
);
1591 r
= sd_event_source_set_priority(m
->mount_event_source
, -10);
1595 (void) sd_event_source_set_description(m
->mount_event_source
, "mount-monitor-dispatch");
1598 r
= mount_load_proc_self_mountinfo(m
, false);
1609 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
1610 _cleanup_set_free_ Set
*around
= NULL
, *gone
= NULL
;
1611 Manager
*m
= userdata
;
1618 assert(revents
& EPOLLIN
);
1620 if (fd
== mnt_monitor_get_fd(m
->mount_monitor
)) {
1621 bool rescan
= false;
1623 /* Drain all events and verify that the event is valid.
1625 * Note that libmount also monitors /run/mount mkdir if the
1626 * directory does not exist yet. The mkdir may generate event
1627 * which is irrelevant for us.
1629 * error: r < 0; valid: r == 0, false positive: rc == 1 */
1631 r
= mnt_monitor_next_change(m
->mount_monitor
, NULL
, NULL
);
1635 return log_error_errno(r
, "Failed to drain libmount events");
1638 log_debug("libmount event [rescan: %s]", yes_no(rescan
));
1643 r
= mount_load_proc_self_mountinfo(m
, true);
1645 /* Reset flags, just in case, for later calls */
1646 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1647 Mount
*mount
= MOUNT(u
);
1649 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1655 manager_dispatch_load_queue(m
);
1657 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1658 Mount
*mount
= MOUNT(u
);
1660 if (!mount
->is_mounted
) {
1662 /* A mount point is not around right now. It
1663 * might be gone, or might never have
1666 if (mount
->from_proc_self_mountinfo
&&
1667 mount
->parameters_proc_self_mountinfo
.what
) {
1669 /* Remember that this device might just have disappeared */
1670 if (set_ensure_allocated(&gone
, &string_hash_ops
) < 0 ||
1671 set_put(gone
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1672 log_oom(); /* we don't care too much about OOM here... */
1675 mount
->from_proc_self_mountinfo
= false;
1677 switch (mount
->state
) {
1680 /* This has just been unmounted by
1681 * somebody else, follow the state
1683 mount_enter_dead(mount
, MOUNT_SUCCESS
);
1690 } else if (mount
->just_mounted
|| mount
->just_changed
) {
1692 /* A mount point was added or changed */
1694 switch (mount
->state
) {
1698 /* This has just been mounted by
1699 * somebody else, follow the state
1701 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
1704 case MOUNT_MOUNTING
:
1705 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
1709 /* Nothing really changed, but let's
1710 * issue an notification call
1711 * nonetheless, in case somebody is
1712 * waiting for this. (e.g. file system
1713 * ro/rw remounts.) */
1714 mount_set_state(mount
, mount
->state
);
1719 if (mount
->is_mounted
&&
1720 mount
->from_proc_self_mountinfo
&&
1721 mount
->parameters_proc_self_mountinfo
.what
) {
1723 if (set_ensure_allocated(&around
, &string_hash_ops
) < 0 ||
1724 set_put(around
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1728 /* Reset the flags for later calls */
1729 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1732 SET_FOREACH(what
, gone
, i
) {
1733 if (set_contains(around
, what
))
1736 /* Let the device units know that the device is no longer mounted */
1737 (void) device_found_node(m
, what
, false, DEVICE_FOUND_MOUNT
, true);
1743 static void mount_reset_failed(Unit
*u
) {
1744 Mount
*m
= MOUNT(u
);
1748 if (m
->state
== MOUNT_FAILED
)
1749 mount_set_state(m
, MOUNT_DEAD
);
1751 m
->result
= MOUNT_SUCCESS
;
1752 m
->reload_result
= MOUNT_SUCCESS
;
1755 static int mount_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
1756 return unit_kill_common(u
, who
, signo
, -1, MOUNT(u
)->control_pid
, error
);
1759 static const char* const mount_state_table
[_MOUNT_STATE_MAX
] = {
1760 [MOUNT_DEAD
] = "dead",
1761 [MOUNT_MOUNTING
] = "mounting",
1762 [MOUNT_MOUNTING_DONE
] = "mounting-done",
1763 [MOUNT_MOUNTED
] = "mounted",
1764 [MOUNT_REMOUNTING
] = "remounting",
1765 [MOUNT_UNMOUNTING
] = "unmounting",
1766 [MOUNT_MOUNTING_SIGTERM
] = "mounting-sigterm",
1767 [MOUNT_MOUNTING_SIGKILL
] = "mounting-sigkill",
1768 [MOUNT_REMOUNTING_SIGTERM
] = "remounting-sigterm",
1769 [MOUNT_REMOUNTING_SIGKILL
] = "remounting-sigkill",
1770 [MOUNT_UNMOUNTING_SIGTERM
] = "unmounting-sigterm",
1771 [MOUNT_UNMOUNTING_SIGKILL
] = "unmounting-sigkill",
1772 [MOUNT_FAILED
] = "failed"
1775 DEFINE_STRING_TABLE_LOOKUP(mount_state
, MountState
);
1777 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
1778 [MOUNT_EXEC_MOUNT
] = "ExecMount",
1779 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
1780 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
1783 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
1785 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
1786 [MOUNT_SUCCESS
] = "success",
1787 [MOUNT_FAILURE_RESOURCES
] = "resources",
1788 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
1789 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
1790 [MOUNT_FAILURE_SIGNAL
] = "signal",
1791 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump"
1794 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
1796 const UnitVTable mount_vtable
= {
1797 .object_size
= sizeof(Mount
),
1798 .exec_context_offset
= offsetof(Mount
, exec_context
),
1799 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
1800 .kill_context_offset
= offsetof(Mount
, kill_context
),
1801 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
1807 .private_section
= "Mount",
1810 .no_instances
= true,
1816 .coldplug
= mount_coldplug
,
1820 .start
= mount_start
,
1822 .reload
= mount_reload
,
1826 .serialize
= mount_serialize
,
1827 .deserialize_item
= mount_deserialize_item
,
1829 .active_state
= mount_active_state
,
1830 .sub_state_to_string
= mount_sub_state_to_string
,
1832 .check_gc
= mount_check_gc
,
1834 .sigchld_event
= mount_sigchld_event
,
1836 .reset_failed
= mount_reset_failed
,
1838 .bus_vtable
= bus_mount_vtable
,
1839 .bus_set_property
= bus_mount_set_property
,
1840 .bus_commit_properties
= bus_mount_commit_properties
,
1842 .get_timeout
= mount_get_timeout
,
1844 .can_transient
= true,
1846 .enumerate
= mount_enumerate
,
1847 .shutdown
= mount_shutdown
,
1849 .status_message_formats
= {
1850 .starting_stopping
= {
1851 [0] = "Mounting %s...",
1852 [1] = "Unmounting %s...",
1854 .finished_start_job
= {
1855 [JOB_DONE
] = "Mounted %s.",
1856 [JOB_FAILED
] = "Failed to mount %s.",
1857 [JOB_TIMEOUT
] = "Timed out mounting %s.",
1859 .finished_stop_job
= {
1860 [JOB_DONE
] = "Unmounted %s.",
1861 [JOB_FAILED
] = "Failed unmounting %s.",
1862 [JOB_TIMEOUT
] = "Timed out unmounting %s.",