1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "sd-messages.h"
10 #include "alloc-util.h"
11 #include "dbus-mount.h"
12 #include "dbus-unit.h"
14 #include "exit-status.h"
15 #include "format-util.h"
17 #include "fstab-util.h"
18 #include "initrd-util.h"
19 #include "libmount-util.h"
22 #include "mkdir-label.h"
23 #include "mount-setup.h"
25 #include "mountpoint-util.h"
26 #include "parse-util.h"
27 #include "path-util.h"
28 #include "process-util.h"
29 #include "serialize.h"
31 #include "stat-util.h"
32 #include "string-table.h"
33 #include "string-util.h"
35 #include "unit-name.h"
38 #define RETRY_UMOUNT_MAX 32
40 static const UnitActiveState state_translation_table
[_MOUNT_STATE_MAX
] = {
41 [MOUNT_DEAD
] = UNIT_INACTIVE
,
42 [MOUNT_MOUNTING
] = UNIT_ACTIVATING
,
43 [MOUNT_MOUNTING_DONE
] = UNIT_ACTIVATING
,
44 [MOUNT_MOUNTED
] = UNIT_ACTIVE
,
45 [MOUNT_REMOUNTING
] = UNIT_RELOADING
,
46 [MOUNT_UNMOUNTING
] = UNIT_DEACTIVATING
,
47 [MOUNT_REMOUNTING_SIGTERM
] = UNIT_RELOADING
,
48 [MOUNT_REMOUNTING_SIGKILL
] = UNIT_RELOADING
,
49 [MOUNT_UNMOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
50 [MOUNT_UNMOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
51 [MOUNT_FAILED
] = UNIT_FAILED
,
52 [MOUNT_CLEANING
] = UNIT_MAINTENANCE
,
55 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
56 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
57 static void mount_enter_dead(Mount
*m
, MountResult f
);
58 static void mount_enter_mounted(Mount
*m
, MountResult f
);
59 static void mount_cycle_clear(Mount
*m
);
60 static int mount_process_proc_self_mountinfo(Manager
*m
);
62 static bool MOUNT_STATE_WITH_PROCESS(MountState state
) {
67 MOUNT_REMOUNTING_SIGTERM
,
68 MOUNT_REMOUNTING_SIGKILL
,
70 MOUNT_UNMOUNTING_SIGTERM
,
71 MOUNT_UNMOUNTING_SIGKILL
,
75 static MountParameters
* get_mount_parameters_fragment(Mount
*m
) {
79 return &m
->parameters_fragment
;
84 static MountParameters
* get_mount_parameters(Mount
*m
) {
87 if (m
->from_proc_self_mountinfo
)
88 return &m
->parameters_proc_self_mountinfo
;
90 return get_mount_parameters_fragment(m
);
93 static bool mount_is_network(const MountParameters
*p
) {
96 if (fstab_test_option(p
->options
, "_netdev\0"))
99 if (p
->fstype
&& fstype_is_network(p
->fstype
))
105 static bool mount_is_nofail(const Mount
*m
) {
108 if (!m
->from_fragment
)
111 return fstab_test_yes_no_option(m
->parameters_fragment
.options
, "nofail\0" "fail\0");
114 static bool mount_is_loop(const MountParameters
*p
) {
117 if (fstab_test_option(p
->options
, "loop\0"))
123 static bool mount_is_bind(const MountParameters
*p
) {
125 return fstab_is_bind(p
->options
, p
->fstype
);
128 static bool mount_is_bound_to_device(Mount
*m
) {
129 const MountParameters
*p
;
133 /* Determines whether to place a Requires= or BindsTo= dependency on the backing device unit. We do
134 * this by checking for the x-systemd.device-bound mount option. Iff it is set we use BindsTo=,
135 * otherwise Requires=. But note that we might combine the latter with StopPropagatedFrom=, see
138 p
= get_mount_parameters(m
);
142 return fstab_test_option(p
->options
, "x-systemd.device-bound\0");
145 static bool mount_propagate_stop(Mount
*m
) {
148 if (mount_is_bound_to_device(m
)) /* If we are using BindsTo= the stop propagation is implicit, no need to bother */
151 return m
->from_fragment
; /* let's propagate stop whenever this is an explicitly configured unit,
152 * otherwise let's not bother. */
155 static bool mount_needs_quota(const MountParameters
*p
) {
158 if (p
->fstype
&& !fstype_needs_quota(p
->fstype
))
161 if (mount_is_bind(p
))
164 return fstab_test_option(p
->options
,
165 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
168 static void mount_init(Unit
*u
) {
173 assert(u
->load_state
== UNIT_STUB
);
175 m
->timeout_usec
= u
->manager
->defaults
.timeout_start_usec
;
177 m
->exec_context
.std_output
= u
->manager
->defaults
.std_output
;
178 m
->exec_context
.std_error
= u
->manager
->defaults
.std_error
;
180 m
->directory_mode
= 0755;
182 /* We need to make sure that /usr/bin/mount is always called
183 * in the same process group as us, so that the autofs kernel
184 * side doesn't send us another mount request while we are
185 * already trying to comply its last one. */
186 m
->exec_context
.same_pgrp
= true;
188 m
->control_pid
= PIDREF_NULL
;
189 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
191 u
->ignore_on_isolate
= true;
194 static int mount_arm_timer(Mount
*m
, usec_t usec
) {
199 if (usec
== USEC_INFINITY
)
200 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_OFF
);
202 if (m
->timer_event_source
) {
203 r
= sd_event_source_set_time(m
->timer_event_source
, usec
);
207 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_ONESHOT
);
210 r
= sd_event_add_time(
211 UNIT(m
)->manager
->event
,
212 &m
->timer_event_source
,
215 mount_dispatch_timer
, m
);
219 (void) sd_event_source_set_description(m
->timer_event_source
, "mount-timer");
224 static void mount_unwatch_control_pid(Mount
*m
) {
227 if (!pidref_is_set(&m
->control_pid
))
230 unit_unwatch_pid(UNIT(m
), m
->control_pid
.pid
);
231 pidref_done(&m
->control_pid
);
234 static void mount_parameters_done(MountParameters
*p
) {
237 p
->what
= mfree(p
->what
);
238 p
->options
= mfree(p
->options
);
239 p
->fstype
= mfree(p
->fstype
);
242 static void mount_done(Unit
*u
) {
247 m
->where
= mfree(m
->where
);
249 mount_parameters_done(&m
->parameters_proc_self_mountinfo
);
250 mount_parameters_done(&m
->parameters_fragment
);
252 m
->exec_runtime
= exec_runtime_free(m
->exec_runtime
);
253 exec_command_done_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
254 m
->control_command
= NULL
;
256 mount_unwatch_control_pid(m
);
258 m
->timer_event_source
= sd_event_source_disable_unref(m
->timer_event_source
);
261 static int update_parameters_proc_self_mountinfo(
265 const char *fstype
) {
270 p
= &m
->parameters_proc_self_mountinfo
;
272 r
= free_and_strdup(&p
->what
, what
);
276 q
= free_and_strdup(&p
->options
, options
);
280 w
= free_and_strdup(&p
->fstype
, fstype
);
284 return r
> 0 || q
> 0 || w
> 0;
287 static int mount_add_mount_dependencies(Mount
*m
) {
295 if (!path_equal(m
->where
, "/")) {
296 _cleanup_free_
char *parent
= NULL
;
298 /* Adds in links to other mount points that might lie further up in the hierarchy */
300 r
= path_extract_directory(m
->where
, &parent
);
304 r
= unit_require_mounts_for(UNIT(m
), parent
, UNIT_DEPENDENCY_IMPLICIT
);
309 /* Adds in dependencies to other mount points that might be needed for the source path (if this is a bind mount
310 * or a loop mount) to be available. */
311 pm
= get_mount_parameters_fragment(m
);
312 if (pm
&& pm
->what
&&
313 path_is_absolute(pm
->what
) &&
314 (mount_is_bind(pm
) || mount_is_loop(pm
) || !mount_is_network(pm
))) {
316 r
= unit_require_mounts_for(UNIT(m
), pm
->what
, UNIT_DEPENDENCY_FILE
);
321 /* Adds in dependencies to other units that use this path or paths further down in the hierarchy */
322 s
= manager_get_units_requiring_mounts_for(UNIT(m
)->manager
, m
->where
);
323 SET_FOREACH(other
, s
) {
325 if (other
->load_state
!= UNIT_LOADED
)
328 if (other
== UNIT(m
))
331 r
= unit_add_dependency(other
, UNIT_AFTER
, UNIT(m
), true, UNIT_DEPENDENCY_PATH
);
335 if (UNIT(m
)->fragment_path
) {
336 /* If we have fragment configuration, then make this dependency required */
337 r
= unit_add_dependency(other
, UNIT_REQUIRES
, UNIT(m
), true, UNIT_DEPENDENCY_PATH
);
346 static int mount_add_device_dependencies(Mount
*m
) {
347 UnitDependencyMask mask
;
354 log_unit_trace(UNIT(m
), "Processing implicit device dependencies");
356 p
= get_mount_parameters(m
);
358 log_unit_trace(UNIT(m
), "Missing mount parameters, skipping implicit device dependencies");
363 log_unit_trace(UNIT(m
), "Missing mount source, skipping implicit device dependencies");
367 if (mount_is_bind(p
)) {
368 log_unit_trace(UNIT(m
), "Mount unit is a bind mount, skipping implicit device dependencies");
372 if (!is_device_path(p
->what
)) {
373 log_unit_trace(UNIT(m
), "Mount source is not a device path, skipping implicit device dependencies");
377 /* /dev/root is a really weird thing, it's not a real device, but just a path the kernel exports for
378 * the root file system specified on the kernel command line. Ignore it here. */
379 if (PATH_IN_SET(p
->what
, "/dev/root", "/dev/nfs")) {
380 log_unit_trace(UNIT(m
), "Mount source is in /dev/root or /dev/nfs, skipping implicit device dependencies");
384 if (path_equal(m
->where
, "/")) {
385 log_unit_trace(UNIT(m
), "Mount destination is '/', skipping implicit device dependencies");
389 /* Mount units from /proc/self/mountinfo are not bound to devices by default since they're subject to
390 * races when mounts are established by other tools with different backing devices than what we
391 * maintain. The user can still force this to be a BindsTo= dependency with an appropriate option (or
392 * udev property) so the mount units are automatically stopped when the device disappears
394 dep
= mount_is_bound_to_device(m
) ? UNIT_BINDS_TO
: UNIT_REQUIRES
;
396 /* We always use 'what' from /proc/self/mountinfo if mounted */
397 mask
= m
->from_proc_self_mountinfo
? UNIT_DEPENDENCY_MOUNTINFO
: UNIT_DEPENDENCY_MOUNT_FILE
;
399 r
= unit_add_node_dependency(UNIT(m
), p
->what
, dep
, mask
);
403 log_unit_trace(UNIT(m
), "Added %s dependency on %s", unit_dependency_to_string(dep
), p
->what
);
405 if (mount_propagate_stop(m
)) {
406 r
= unit_add_node_dependency(UNIT(m
), p
->what
, UNIT_STOP_PROPAGATED_FROM
, mask
);
410 log_unit_trace(UNIT(m
), "Added %s dependency on %s",
411 unit_dependency_to_string(UNIT_STOP_PROPAGATED_FROM
), p
->what
);
414 r
= unit_add_blockdev_dependency(UNIT(m
), p
->what
, mask
);
416 log_unit_trace(UNIT(m
), "Added %s dependency on %s", unit_dependency_to_string(UNIT_AFTER
), p
->what
);
421 static int mount_add_quota_dependencies(Mount
*m
) {
427 if (!MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
430 p
= get_mount_parameters_fragment(m
);
434 if (!mount_needs_quota(p
))
437 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
,
438 /* add_reference= */ true, UNIT_DEPENDENCY_FILE
);
442 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
,
443 /* add_reference= */true, UNIT_DEPENDENCY_FILE
);
450 static bool mount_is_extrinsic(Unit
*u
) {
455 /* Returns true for all units that are "magic" and should be excluded from the usual
456 * start-up and shutdown dependencies. We call them "extrinsic" here, as they are generally
457 * mounted outside of the systemd dependency logic. We shouldn't attempt to manage them
458 * ourselves but it's fine if the user operates on them with us. */
460 /* We only automatically manage mounts if we are in system mode */
461 if (MANAGER_IS_USER(u
->manager
))
464 p
= get_mount_parameters(m
);
465 if (p
&& fstab_is_extrinsic(m
->where
, p
->options
))
471 static bool mount_is_credentials(Mount
*m
) {
476 /* Returns true if this is a credentials mount. We don't want automatic dependencies on credential
477 * mounts, since they are managed by us for even the earliest services, and we never want anything to
478 * be ordered before them hence. */
480 e
= path_startswith(m
->where
, UNIT(m
)->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
484 return !isempty(path_startswith(e
, "credentials"));
487 static int mount_add_default_ordering_dependencies(Mount
*m
, MountParameters
*p
, UnitDependencyMask mask
) {
488 const char *after
, *before
, *e
;
493 e
= path_startswith(m
->where
, "/sysroot");
494 if (e
&& in_initrd()) {
495 /* All mounts under /sysroot need to happen later, at initrd-fs.target time. IOW,
496 * it's not technically part of the basic initrd filesystem itself, and so
497 * shouldn't inherit the default Before=local-fs.target dependency. However,
498 * these mounts still need to start after local-fs-pre.target, as a sync point
499 * for things like systemd-hibernate-resume.service that should start before
502 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
503 before
= isempty(e
) ? SPECIAL_INITRD_ROOT_FS_TARGET
: SPECIAL_INITRD_FS_TARGET
;
505 } else if (in_initrd() && path_startswith(m
->where
, "/sysusr/usr")) {
506 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
507 before
= SPECIAL_INITRD_USR_FS_TARGET
;
509 } else if (mount_is_credentials(m
))
510 after
= before
= NULL
;
512 else if (mount_is_network(p
)) {
513 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
514 before
= SPECIAL_REMOTE_FS_TARGET
;
517 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
518 before
= SPECIAL_LOCAL_FS_TARGET
;
521 if (before
&& !mount_is_nofail(m
)) {
522 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_BEFORE
, before
, /* add_reference= */ true, mask
);
528 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, /* add_reference= */ true, mask
);
533 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
,
534 /* add_reference= */ true, mask
);
538 /* If this is a tmpfs mount then we have to unmount it before we try to deactivate swaps */
539 if (streq_ptr(p
->fstype
, "tmpfs") && !mount_is_credentials(m
)) {
540 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, SPECIAL_SWAP_TARGET
,
541 /* add_reference= */ true, mask
);
549 static int mount_add_default_network_dependencies(Mount
*m
, MountParameters
*p
, UnitDependencyMask mask
) {
554 if (!mount_is_network(p
))
557 /* We order ourselves after network.target. This is primarily useful at shutdown: services that take
558 * down the network should order themselves before network.target, so that they are shut down only
559 * after this mount unit is stopped. */
561 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, SPECIAL_NETWORK_TARGET
,
562 /* add_reference= */ true, mask
);
566 /* We pull in network-online.target, and order ourselves after it. This is useful at start-up to
567 * actively pull in tools that want to be started before we start mounting network file systems, and
568 * whose purpose it is to delay this until the network is "up". */
570 return unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, SPECIAL_NETWORK_ONLINE_TARGET
,
571 /* add_reference= */ true, mask
);
574 static int mount_add_default_dependencies(Mount
*m
) {
575 UnitDependencyMask mask
;
581 if (!UNIT(m
)->default_dependencies
)
584 /* We do not add any default dependencies to /, /usr or /run/initramfs/, since they are
585 * guaranteed to stay mounted the whole time, since our system is on it. Also, don't
586 * bother with anything mounted below virtual file systems, it's also going to be virtual,
587 * and hence not worth the effort. */
588 if (mount_is_extrinsic(UNIT(m
)))
591 p
= get_mount_parameters(m
);
595 mask
= m
->from_proc_self_mountinfo
? UNIT_DEPENDENCY_MOUNTINFO
: UNIT_DEPENDENCY_MOUNT_FILE
;
597 r
= mount_add_default_ordering_dependencies(m
, p
, mask
);
601 r
= mount_add_default_network_dependencies(m
, p
, mask
);
608 static int mount_verify(Mount
*m
) {
609 _cleanup_free_
char *e
= NULL
;
614 assert(UNIT(m
)->load_state
== UNIT_LOADED
);
616 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
&& !UNIT(m
)->perpetual
)
619 r
= unit_name_from_path(m
->where
, ".mount", &e
);
621 return log_unit_error_errno(UNIT(m
), r
, "Failed to generate unit name from mount path: %m");
623 if (!unit_has_name(UNIT(m
), e
))
624 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
), "Where= setting doesn't match unit name. Refusing.");
626 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
))
627 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
), "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
629 p
= get_mount_parameters_fragment(m
);
630 if (p
&& !p
->what
&& !UNIT(m
)->perpetual
)
631 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
),
632 "What= setting is missing. Refusing.");
634 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
)
635 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
640 static int mount_add_non_exec_dependencies(Mount
*m
) {
645 /* We may be called due to this mount appearing in /proc/self/mountinfo, hence we clear all existing
646 * dependencies that were initialized from the unit file but whose final value really depends on the
647 * content of /proc/self/mountinfo. Some (such as m->where) might have become stale now. */
648 unit_remove_dependencies(UNIT(m
), UNIT_DEPENDENCY_MOUNTINFO
| UNIT_DEPENDENCY_MOUNT_FILE
);
653 /* Adds in all dependencies directly responsible for ordering the mount, as opposed to dependencies
654 * resulting from the ExecContext and such. */
656 r
= mount_add_device_dependencies(m
);
660 r
= mount_add_mount_dependencies(m
);
664 r
= mount_add_quota_dependencies(m
);
668 r
= mount_add_default_dependencies(m
);
675 static int mount_add_extras(Mount
*m
) {
681 /* Note: this call might be called after we already have been loaded once (and even when it has already been
682 * activated), in case data from /proc/self/mountinfo has changed. This means all code here needs to be ready
683 * to run with an already set up unit. */
685 if (u
->fragment_path
)
686 m
->from_fragment
= true;
689 r
= unit_name_to_path(u
->id
, &m
->where
);
690 if (r
== -ENAMETOOLONG
)
691 log_unit_error_errno(u
, r
, "Failed to derive mount point path from unit name, because unit name is hashed. "
692 "Set \"Where=\" in the unit file explicitly.");
697 path_simplify(m
->where
);
699 if (!u
->description
) {
700 r
= unit_set_description(u
, m
->where
);
705 r
= unit_patch_contexts(u
);
709 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
713 r
= unit_set_default_slice(u
);
717 r
= mount_add_non_exec_dependencies(m
);
724 static void mount_load_root_mount(Unit
*u
) {
727 if (!unit_has_name(u
, SPECIAL_ROOT_MOUNT
))
731 u
->default_dependencies
= false;
733 /* The stdio/kmsg bridge socket is on /, in order to avoid a dep loop, don't use kmsg logging for -.mount */
734 MOUNT(u
)->exec_context
.std_output
= EXEC_OUTPUT_NULL
;
735 MOUNT(u
)->exec_context
.std_input
= EXEC_INPUT_NULL
;
738 u
->description
= strdup("Root Mount");
741 static int mount_load(Unit
*u
) {
747 assert(u
->load_state
== UNIT_STUB
);
749 mount_load_root_mount(u
);
751 bool fragment_optional
= m
->from_proc_self_mountinfo
|| u
->perpetual
;
752 r
= unit_load_fragment_and_dropin(u
, !fragment_optional
);
754 /* Add in some extras. Note we do this in all cases (even if we failed to load the unit) when announced by the
755 * kernel, because we need some things to be set up no matter what when the kernel establishes a mount and thus
756 * we need to update the state in our unit to track it. After all, consider that we don't allow changing the
757 * 'slice' field for a unit once it is active. */
758 if (u
->load_state
== UNIT_LOADED
|| m
->from_proc_self_mountinfo
|| u
->perpetual
)
759 q
= mount_add_extras(m
);
765 if (u
->load_state
!= UNIT_LOADED
)
768 return mount_verify(m
);
771 static void mount_set_state(Mount
*m
, MountState state
) {
772 MountState old_state
;
775 if (m
->state
!= state
)
776 bus_unit_send_pending_change_signal(UNIT(m
), false);
778 old_state
= m
->state
;
781 if (!MOUNT_STATE_WITH_PROCESS(state
)) {
782 m
->timer_event_source
= sd_event_source_disable_unref(m
->timer_event_source
);
783 mount_unwatch_control_pid(m
);
784 m
->control_command
= NULL
;
785 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
788 if (state
!= old_state
)
789 log_unit_debug(UNIT(m
), "Changed %s -> %s", mount_state_to_string(old_state
), mount_state_to_string(state
));
791 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
794 static int mount_coldplug(Unit
*u
) {
799 assert(m
->state
== MOUNT_DEAD
);
801 if (m
->deserialized_state
== m
->state
)
804 if (pidref_is_set(&m
->control_pid
) &&
805 pid_is_unwaited(m
->control_pid
.pid
) &&
806 MOUNT_STATE_WITH_PROCESS(m
->deserialized_state
)) {
808 r
= unit_watch_pid(UNIT(m
), m
->control_pid
.pid
, /* exclusive= */ false);
812 r
= mount_arm_timer(m
, usec_add(u
->state_change_timestamp
.monotonic
, m
->timeout_usec
));
817 if (!IN_SET(m
->deserialized_state
, MOUNT_DEAD
, MOUNT_FAILED
))
818 (void) unit_setup_exec_runtime(u
);
820 mount_set_state(m
, m
->deserialized_state
);
824 static void mount_catchup(Unit
*u
) {
825 Mount
*m
= MOUNT(ASSERT_PTR(u
));
829 /* Adjust the deserialized state. See comments in mount_process_proc_self_mountinfo(). */
830 if (m
->from_proc_self_mountinfo
)
834 assert(!pidref_is_set(&m
->control_pid
));
835 (void) unit_acquire_invocation_id(u
);
836 mount_cycle_clear(m
);
837 mount_enter_mounted(m
, MOUNT_SUCCESS
);
840 assert(pidref_is_set(&m
->control_pid
));
841 mount_set_state(m
, MOUNT_MOUNTING_DONE
);
848 case MOUNT_MOUNTING_DONE
:
849 assert(pidref_is_set(&m
->control_pid
));
850 mount_set_state(m
, MOUNT_MOUNTING
);
853 assert(!pidref_is_set(&m
->control_pid
));
854 mount_enter_dead(m
, MOUNT_SUCCESS
);
861 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
868 p
= get_mount_parameters(m
);
871 "%sMount State: %s\n"
873 "%sClean Result: %s\n"
876 "%sFile System Type: %s\n"
878 "%sFrom /proc/self/mountinfo: %s\n"
879 "%sFrom fragment: %s\n"
881 "%sDirectoryMode: %04o\n"
882 "%sSloppyOptions: %s\n"
883 "%sLazyUnmount: %s\n"
884 "%sForceUnmount: %s\n"
885 "%sReadWriteOnly: %s\n"
886 "%sTimeoutSec: %s\n",
887 prefix
, mount_state_to_string(m
->state
),
888 prefix
, mount_result_to_string(m
->result
),
889 prefix
, mount_result_to_string(m
->clean_result
),
891 prefix
, p
? strna(p
->what
) : "n/a",
892 prefix
, p
? strna(p
->fstype
) : "n/a",
893 prefix
, p
? strna(p
->options
) : "n/a",
894 prefix
, yes_no(m
->from_proc_self_mountinfo
),
895 prefix
, yes_no(m
->from_fragment
),
896 prefix
, yes_no(mount_is_extrinsic(u
)),
897 prefix
, m
->directory_mode
,
898 prefix
, yes_no(m
->sloppy_options
),
899 prefix
, yes_no(m
->lazy_unmount
),
900 prefix
, yes_no(m
->force_unmount
),
901 prefix
, yes_no(m
->read_write_only
),
902 prefix
, FORMAT_TIMESPAN(m
->timeout_usec
, USEC_PER_SEC
));
904 if (pidref_is_set(&m
->control_pid
))
906 "%sControl PID: "PID_FMT
"\n",
907 prefix
, m
->control_pid
.pid
);
909 exec_context_dump(&m
->exec_context
, f
, prefix
);
910 kill_context_dump(&m
->kill_context
, f
, prefix
);
911 cgroup_context_dump(UNIT(m
), f
, prefix
);
914 static int mount_spawn(Mount
*m
, ExecCommand
*c
, PidRef
*ret_pid
) {
916 _cleanup_(exec_params_clear
) ExecParameters exec_params
= {
917 .flags
= EXEC_APPLY_SANDBOXING
|EXEC_APPLY_CHROOT
|EXEC_APPLY_TTY_STDIN
,
923 _cleanup_(pidref_done
) PidRef pidref
= PIDREF_NULL
;
931 r
= unit_prepare_exec(UNIT(m
));
935 r
= mount_arm_timer(m
, usec_add(now(CLOCK_MONOTONIC
), m
->timeout_usec
));
939 r
= unit_set_exec_params(UNIT(m
), &exec_params
);
943 r
= exec_spawn(UNIT(m
),
953 r
= pidref_set_pid(&pidref
, pid
);
957 r
= unit_watch_pid(UNIT(m
), pidref
.pid
, /* exclusive= */ true);
961 *ret_pid
= TAKE_PIDREF(pidref
);
965 static void mount_enter_dead(Mount
*m
, MountResult f
) {
968 if (m
->result
== MOUNT_SUCCESS
)
971 unit_log_result(UNIT(m
), m
->result
== MOUNT_SUCCESS
, mount_result_to_string(m
->result
));
972 unit_warn_leftover_processes(UNIT(m
), unit_log_leftover_process_stop
);
974 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
976 m
->exec_runtime
= exec_runtime_destroy(m
->exec_runtime
);
978 unit_destroy_runtime_data(UNIT(m
), &m
->exec_context
);
980 unit_unref_uid_gid(UNIT(m
), true);
982 /* Any dependencies based on /proc/self/mountinfo are now stale. Let's re-generate dependencies from
984 (void) mount_add_non_exec_dependencies(m
);
987 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
990 if (m
->result
== MOUNT_SUCCESS
)
993 mount_set_state(m
, MOUNT_MOUNTED
);
996 static void mount_enter_dead_or_mounted(Mount
*m
, MountResult f
) {
999 /* Enter DEAD or MOUNTED state, depending on what the kernel currently says about the mount point. We use this
1000 * whenever we executed an operation, so that our internal state reflects what the kernel says again, after all
1001 * ultimately we just mirror the kernel's internal state on this. */
1003 if (m
->from_proc_self_mountinfo
)
1004 mount_enter_mounted(m
, f
);
1006 mount_enter_dead(m
, f
);
1009 static int state_to_kill_operation(MountState state
) {
1012 case MOUNT_REMOUNTING_SIGTERM
:
1013 return KILL_RESTART
;
1015 case MOUNT_UNMOUNTING_SIGTERM
:
1016 return KILL_TERMINATE
;
1018 case MOUNT_REMOUNTING_SIGKILL
:
1019 case MOUNT_UNMOUNTING_SIGKILL
:
1023 return _KILL_OPERATION_INVALID
;
1027 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
1032 if (m
->result
== MOUNT_SUCCESS
)
1035 r
= unit_kill_context(
1038 state_to_kill_operation(state
),
1039 /* main_pid= */ NULL
,
1041 /* main_pid_alien= */ false);
1046 r
= mount_arm_timer(m
, usec_add(now(CLOCK_MONOTONIC
), m
->timeout_usec
));
1050 mount_set_state(m
, state
);
1051 } else if (state
== MOUNT_REMOUNTING_SIGTERM
&& m
->kill_context
.send_sigkill
)
1052 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1053 else if (IN_SET(state
, MOUNT_REMOUNTING_SIGTERM
, MOUNT_REMOUNTING_SIGKILL
))
1054 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1055 else if (state
== MOUNT_UNMOUNTING_SIGTERM
&& m
->kill_context
.send_sigkill
)
1056 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1058 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1063 log_unit_warning_errno(UNIT(m
), r
, "Failed to kill processes: %m");
1064 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_RESOURCES
);
1067 static void mount_enter_unmounting(Mount
*m
) {
1072 /* Start counting our attempts */
1073 if (!IN_SET(m
->state
,
1075 MOUNT_UNMOUNTING_SIGTERM
,
1076 MOUNT_UNMOUNTING_SIGKILL
))
1077 m
->n_retry_umount
= 0;
1079 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
1080 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
1082 r
= exec_command_set(m
->control_command
, UMOUNT_PATH
, m
->where
, "-c", NULL
);
1083 if (r
>= 0 && m
->lazy_unmount
)
1084 r
= exec_command_append(m
->control_command
, "-l", NULL
);
1085 if (r
>= 0 && m
->force_unmount
)
1086 r
= exec_command_append(m
->control_command
, "-f", NULL
);
1090 mount_unwatch_control_pid(m
);
1092 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
1096 mount_set_state(m
, MOUNT_UNMOUNTING
);
1101 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'umount' task: %m");
1102 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_RESOURCES
);
1105 static void mount_enter_mounting(Mount
*m
) {
1108 bool source_is_dir
= true;
1112 r
= unit_fail_if_noncanonical(UNIT(m
), m
->where
);
1116 p
= get_mount_parameters_fragment(m
);
1117 if (p
&& mount_is_bind(p
)) {
1118 r
= is_dir(p
->what
, /* follow = */ true);
1119 if (r
< 0 && r
!= -ENOENT
)
1120 log_unit_info_errno(UNIT(m
), r
, "Failed to determine type of bind mount source '%s', ignoring: %m", p
->what
);
1122 source_is_dir
= false;
1126 (void) mkdir_p_label(m
->where
, m
->directory_mode
);
1128 (void) touch_file(m
->where
, /* parents = */ true, USEC_INFINITY
, UID_INVALID
, GID_INVALID
, MODE_INVALID
);
1131 unit_warn_if_dir_nonempty(UNIT(m
), m
->where
);
1132 unit_warn_leftover_processes(UNIT(m
), unit_log_leftover_process_start
);
1134 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
1135 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
1137 /* Create the source directory for bind-mounts if needed */
1138 if (p
&& mount_is_bind(p
)) {
1139 r
= mkdir_p_label(p
->what
, m
->directory_mode
);
1140 /* mkdir_p_label() can return -EEXIST if the target path exists and is not a directory - which is
1141 * totally OK, in case the user wants us to overmount a non-directory inode. Also -EROFS can be
1142 * returned on read-only filesystem. Moreover, -EACCES (and also maybe -EPERM?) may be returned
1143 * when the path is on NFS. See issue #24120. All such errors will be logged in the debug level. */
1144 if (r
< 0 && r
!= -EEXIST
)
1145 log_unit_full_errno(UNIT(m
),
1146 (r
== -EROFS
|| ERRNO_IS_PRIVILEGE(r
)) ? LOG_DEBUG
: LOG_WARNING
,
1147 r
, "Failed to make bind mount source '%s', ignoring: %m", p
->what
);
1151 _cleanup_free_
char *opts
= NULL
;
1153 r
= fstab_filter_options(p
->options
, "nofail\0" "noauto\0" "auto\0", NULL
, NULL
, NULL
, &opts
);
1157 r
= exec_command_set(m
->control_command
, MOUNT_PATH
, p
->what
, m
->where
, NULL
);
1158 if (r
>= 0 && m
->sloppy_options
)
1159 r
= exec_command_append(m
->control_command
, "-s", NULL
);
1160 if (r
>= 0 && m
->read_write_only
)
1161 r
= exec_command_append(m
->control_command
, "-w", NULL
);
1162 if (r
>= 0 && p
->fstype
)
1163 r
= exec_command_append(m
->control_command
, "-t", p
->fstype
, NULL
);
1164 if (r
>= 0 && !isempty(opts
))
1165 r
= exec_command_append(m
->control_command
, "-o", opts
, NULL
);
1171 mount_unwatch_control_pid(m
);
1173 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
1177 mount_set_state(m
, MOUNT_MOUNTING
);
1182 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'mount' task: %m");
1183 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_RESOURCES
);
1186 static void mount_set_reload_result(Mount
*m
, MountResult result
) {
1189 /* Only store the first error we encounter */
1190 if (m
->reload_result
!= MOUNT_SUCCESS
)
1193 m
->reload_result
= result
;
1196 static void mount_enter_remounting(Mount
*m
) {
1202 /* Reset reload result when we are about to start a new remount operation */
1203 m
->reload_result
= MOUNT_SUCCESS
;
1205 m
->control_command_id
= MOUNT_EXEC_REMOUNT
;
1206 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_REMOUNT
;
1208 p
= get_mount_parameters_fragment(m
);
1213 o
= strjoina("remount,", p
->options
);
1217 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
1220 if (r
>= 0 && m
->sloppy_options
)
1221 r
= exec_command_append(m
->control_command
, "-s", NULL
);
1222 if (r
>= 0 && m
->read_write_only
)
1223 r
= exec_command_append(m
->control_command
, "-w", NULL
);
1224 if (r
>= 0 && p
->fstype
)
1225 r
= exec_command_append(m
->control_command
, "-t", p
->fstype
, NULL
);
1231 mount_unwatch_control_pid(m
);
1233 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
1237 mount_set_state(m
, MOUNT_REMOUNTING
);
1242 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'remount' task: %m");
1243 mount_set_reload_result(m
, MOUNT_FAILURE_RESOURCES
);
1244 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1247 static void mount_cycle_clear(Mount
*m
) {
1250 /* Clear all state we shall forget for this new cycle */
1252 m
->result
= MOUNT_SUCCESS
;
1253 m
->reload_result
= MOUNT_SUCCESS
;
1254 exec_command_reset_status_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
1255 UNIT(m
)->reset_accounting
= true;
1258 static int mount_start(Unit
*u
) {
1259 Mount
*m
= MOUNT(u
);
1264 /* We cannot fulfill this request right now, try again later
1266 if (IN_SET(m
->state
,
1268 MOUNT_UNMOUNTING_SIGTERM
,
1269 MOUNT_UNMOUNTING_SIGKILL
,
1273 /* Already on it! */
1274 if (IN_SET(m
->state
, MOUNT_MOUNTING
, MOUNT_MOUNTING_DONE
))
1277 assert(IN_SET(m
->state
, MOUNT_DEAD
, MOUNT_FAILED
));
1279 r
= unit_acquire_invocation_id(u
);
1283 mount_cycle_clear(m
);
1284 mount_enter_mounting(m
);
1289 static int mount_stop(Unit
*u
) {
1290 Mount
*m
= MOUNT(u
);
1294 /* When we directly call umount() for a path, then the state of the corresponding mount unit may be
1295 * outdated. Let's re-read mountinfo now and update the state. */
1296 if (m
->invalidated_state
)
1297 (void) mount_process_proc_self_mountinfo(u
->manager
);
1301 case MOUNT_UNMOUNTING
:
1302 case MOUNT_UNMOUNTING_SIGKILL
:
1303 case MOUNT_UNMOUNTING_SIGTERM
:
1307 case MOUNT_MOUNTING
:
1308 case MOUNT_MOUNTING_DONE
:
1309 case MOUNT_REMOUNTING
:
1310 /* If we are still waiting for /bin/mount, we go directly into kill mode. */
1311 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_SUCCESS
);
1314 case MOUNT_REMOUNTING_SIGTERM
:
1315 /* If we are already waiting for a hung remount, convert this to the matching unmounting state */
1316 mount_set_state(m
, MOUNT_UNMOUNTING_SIGTERM
);
1319 case MOUNT_REMOUNTING_SIGKILL
:
1321 mount_set_state(m
, MOUNT_UNMOUNTING_SIGKILL
);
1325 mount_enter_unmounting(m
);
1328 case MOUNT_CLEANING
:
1329 /* If we are currently cleaning, then abort it, brutally. */
1330 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1335 /* The mount has just been unmounted by somebody else. */
1339 assert_not_reached();
1343 static int mount_reload(Unit
*u
) {
1344 Mount
*m
= MOUNT(u
);
1347 assert(m
->state
== MOUNT_MOUNTED
);
1349 mount_enter_remounting(m
);
1354 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1355 Mount
*m
= MOUNT(u
);
1361 (void) serialize_item(f
, "state", mount_state_to_string(m
->state
));
1362 (void) serialize_item(f
, "result", mount_result_to_string(m
->result
));
1363 (void) serialize_item(f
, "reload-result", mount_result_to_string(m
->reload_result
));
1364 (void) serialize_item_format(f
, "n-retry-umount", "%u", m
->n_retry_umount
);
1366 if (pidref_is_set(&m
->control_pid
))
1367 (void) serialize_item_format(f
, "control-pid", PID_FMT
, m
->control_pid
.pid
);
1369 if (m
->control_command_id
>= 0)
1370 (void) serialize_item(f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1375 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1376 Mount
*m
= MOUNT(u
);
1385 if (streq(key
, "state")) {
1388 state
= mount_state_from_string(value
);
1390 log_unit_debug_errno(u
, state
, "Failed to parse state value: %s", value
);
1392 m
->deserialized_state
= state
;
1394 } else if (streq(key
, "result")) {
1397 f
= mount_result_from_string(value
);
1399 log_unit_debug_errno(u
, f
, "Failed to parse result value: %s", value
);
1400 else if (f
!= MOUNT_SUCCESS
)
1403 } else if (streq(key
, "reload-result")) {
1406 f
= mount_result_from_string(value
);
1408 log_unit_debug_errno(u
, f
, "Failed to parse reload result value: %s", value
);
1409 else if (f
!= MOUNT_SUCCESS
)
1410 m
->reload_result
= f
;
1412 } else if (streq(key
, "n-retry-umount")) {
1414 r
= safe_atou(value
, &m
->n_retry_umount
);
1416 log_unit_debug_errno(u
, r
, "Failed to parse n-retry-umount value: %s", value
);
1418 } else if (streq(key
, "control-pid")) {
1420 pidref_done(&m
->control_pid
);
1421 r
= pidref_set_pidstr(&m
->control_pid
, value
);
1423 log_debug_errno(r
, "Failed to set control PID to '%s': %m", value
);
1425 } else if (streq(key
, "control-command")) {
1426 MountExecCommand id
;
1428 id
= mount_exec_command_from_string(value
);
1430 log_unit_debug_errno(u
, id
, "Failed to parse exec-command value: %s", value
);
1432 m
->control_command_id
= id
;
1433 m
->control_command
= m
->exec_command
+ id
;
1436 log_unit_debug(u
, "Unknown serialization key: %s", key
);
1441 static UnitActiveState
mount_active_state(Unit
*u
) {
1444 return state_translation_table
[MOUNT(u
)->state
];
1447 static const char *mount_sub_state_to_string(Unit
*u
) {
1450 return mount_state_to_string(MOUNT(u
)->state
);
1453 static bool mount_may_gc(Unit
*u
) {
1454 Mount
*m
= MOUNT(u
);
1458 if (m
->from_proc_self_mountinfo
)
1464 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1465 Mount
*m
= MOUNT(u
);
1471 if (pid
!= m
->control_pid
.pid
)
1474 /* So here's the thing, we really want to know before /usr/bin/mount or /usr/bin/umount exit whether
1475 * they established/remove a mount. This is important when mounting, but even more so when unmounting
1476 * since we need to deal with nested mounts and otherwise cannot safely determine whether to repeat
1477 * the unmounts. In theory, the kernel fires /proc/self/mountinfo changes off before returning from
1478 * the mount() or umount() syscalls, and thus we should see the changes to the proc file before we
1479 * process the waitid() for the /usr/bin/(u)mount processes. However, this is unfortunately racy: we
1480 * have to waitid() for processes using P_ALL (since we need to reap unexpected children that got
1481 * reparented to PID 1), but when using P_ALL we might end up reaping processes that terminated just
1482 * instants ago, i.e. already after our last event loop iteration (i.e. after the last point we might
1483 * have noticed /proc/self/mountinfo events via epoll). This means event loop priorities for
1484 * processing SIGCHLD vs. /proc/self/mountinfo IO events are not as relevant as we want. To fix that
1485 * race, let's explicitly scan /proc/self/mountinfo before we start processing /usr/bin/(u)mount
1486 * dying. It's ugly, but it makes our ordering systematic again, and makes sure we always see
1487 * /proc/self/mountinfo changes before our mount/umount exits. */
1488 (void) mount_process_proc_self_mountinfo(u
->manager
);
1490 pidref_done(&m
->control_pid
);
1492 if (is_clean_exit(code
, status
, EXIT_CLEAN_COMMAND
, NULL
))
1494 else if (code
== CLD_EXITED
)
1495 f
= MOUNT_FAILURE_EXIT_CODE
;
1496 else if (code
== CLD_KILLED
)
1497 f
= MOUNT_FAILURE_SIGNAL
;
1498 else if (code
== CLD_DUMPED
)
1499 f
= MOUNT_FAILURE_CORE_DUMP
;
1501 assert_not_reached();
1503 if (IN_SET(m
->state
, MOUNT_REMOUNTING
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_REMOUNTING_SIGTERM
))
1504 mount_set_reload_result(m
, f
);
1505 else if (m
->result
== MOUNT_SUCCESS
)
1508 if (m
->control_command
) {
1509 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1511 m
->control_command
= NULL
;
1512 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1515 unit_log_process_exit(
1518 mount_exec_command_to_string(m
->control_command_id
),
1522 /* Note that due to the io event priority logic, we can be sure the new mountinfo is loaded
1523 * before we process the SIGCHLD for the mount command. */
1527 case MOUNT_MOUNTING
:
1528 /* Our mount point has not appeared in mountinfo. Something went wrong. */
1530 if (f
== MOUNT_SUCCESS
) {
1531 /* Either /bin/mount has an unexpected definition of success,
1532 * or someone raced us and we lost. */
1533 log_unit_warning(UNIT(m
), "Mount process finished, but there is no mount.");
1534 f
= MOUNT_FAILURE_PROTOCOL
;
1536 mount_enter_dead(m
, f
);
1539 case MOUNT_MOUNTING_DONE
:
1540 mount_enter_mounted(m
, f
);
1543 case MOUNT_REMOUNTING
:
1544 case MOUNT_REMOUNTING_SIGTERM
:
1545 case MOUNT_REMOUNTING_SIGKILL
:
1546 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1549 case MOUNT_UNMOUNTING
:
1551 if (f
== MOUNT_SUCCESS
&& m
->from_proc_self_mountinfo
) {
1553 /* Still a mount point? If so, let's try again. Most likely there were multiple mount points
1554 * stacked on top of each other. We might exceed the timeout specified by the user overall,
1555 * but we will stop as soon as any one umount times out. */
1557 if (m
->n_retry_umount
< RETRY_UMOUNT_MAX
) {
1558 log_unit_debug(u
, "Mount still present, trying again.");
1559 m
->n_retry_umount
++;
1560 mount_enter_unmounting(m
);
1562 log_unit_warning(u
, "Mount still present after %u attempts to unmount, giving up.", m
->n_retry_umount
);
1563 mount_enter_mounted(m
, f
);
1566 mount_enter_dead_or_mounted(m
, f
);
1570 case MOUNT_UNMOUNTING_SIGKILL
:
1571 case MOUNT_UNMOUNTING_SIGTERM
:
1572 mount_enter_dead_or_mounted(m
, f
);
1575 case MOUNT_CLEANING
:
1576 if (m
->clean_result
== MOUNT_SUCCESS
)
1577 m
->clean_result
= f
;
1579 mount_enter_dead(m
, MOUNT_SUCCESS
);
1583 assert_not_reached();
1586 /* Notify clients about changed exit status */
1587 unit_add_to_dbus_queue(u
);
1590 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1591 Mount
*m
= MOUNT(userdata
);
1594 assert(m
->timer_event_source
== source
);
1598 case MOUNT_MOUNTING
:
1599 case MOUNT_MOUNTING_DONE
:
1600 log_unit_warning(UNIT(m
), "Mounting timed out. Terminating.");
1601 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1604 case MOUNT_REMOUNTING
:
1605 log_unit_warning(UNIT(m
), "Remounting timed out. Terminating remount process.");
1606 mount_set_reload_result(m
, MOUNT_FAILURE_TIMEOUT
);
1607 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGTERM
, MOUNT_SUCCESS
);
1610 case MOUNT_REMOUNTING_SIGTERM
:
1611 mount_set_reload_result(m
, MOUNT_FAILURE_TIMEOUT
);
1613 if (m
->kill_context
.send_sigkill
) {
1614 log_unit_warning(UNIT(m
), "Remounting timed out. Killing.");
1615 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1617 log_unit_warning(UNIT(m
), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1618 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1622 case MOUNT_REMOUNTING_SIGKILL
:
1623 mount_set_reload_result(m
, MOUNT_FAILURE_TIMEOUT
);
1625 log_unit_warning(UNIT(m
), "Mount process still around after SIGKILL. Ignoring.");
1626 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1629 case MOUNT_UNMOUNTING
:
1630 log_unit_warning(UNIT(m
), "Unmounting timed out. Terminating.");
1631 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1634 case MOUNT_UNMOUNTING_SIGTERM
:
1635 if (m
->kill_context
.send_sigkill
) {
1636 log_unit_warning(UNIT(m
), "Mount process timed out. Killing.");
1637 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1639 log_unit_warning(UNIT(m
), "Mount process timed out. Skipping SIGKILL. Ignoring.");
1640 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1644 case MOUNT_UNMOUNTING_SIGKILL
:
1645 log_unit_warning(UNIT(m
), "Mount process still around after SIGKILL. Ignoring.");
1646 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1649 case MOUNT_CLEANING
:
1650 log_unit_warning(UNIT(m
), "Cleaning timed out. killing.");
1652 if (m
->clean_result
== MOUNT_SUCCESS
)
1653 m
->clean_result
= MOUNT_FAILURE_TIMEOUT
;
1655 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, 0);
1659 assert_not_reached();
1665 static int mount_setup_new_unit(
1670 const char *options
,
1672 MountProcFlags
*ret_flags
,
1675 _cleanup_(unit_freep
) Unit
*u
= NULL
;
1683 r
= unit_new_for_name(m
, sizeof(Mount
), name
, &u
);
1687 r
= free_and_strdup(&u
->source_path
, "/proc/self/mountinfo");
1691 r
= free_and_strdup(&MOUNT(u
)->where
, where
);
1695 r
= update_parameters_proc_self_mountinfo(MOUNT(u
), what
, options
, fstype
);
1699 /* This unit was generated because /proc/self/mountinfo reported it. Remember this, so that by the
1700 * time we load the unit file for it (and thus add in extra deps right after) we know what source to
1701 * attributes the deps to. */
1702 MOUNT(u
)->from_proc_self_mountinfo
= true;
1704 r
= mount_add_non_exec_dependencies(MOUNT(u
));
1708 /* We have only allocated the stub now, let's enqueue this unit for loading now, so that everything
1709 * else is loaded in now. */
1710 unit_add_to_load_queue(u
);
1712 *ret_flags
= MOUNT_PROC_IS_MOUNTED
| MOUNT_PROC_JUST_MOUNTED
| MOUNT_PROC_JUST_CHANGED
;
1717 static int mount_setup_existing_unit(
1721 const char *options
,
1723 MountProcFlags
*ret_flags
) {
1730 if (!MOUNT(u
)->where
) {
1731 MOUNT(u
)->where
= strdup(where
);
1732 if (!MOUNT(u
)->where
)
1736 /* In case we have multiple mounts established on the same mount point, let's merge flags set already
1737 * for the current unit. Note that the flags field is reset on each iteration of reading
1738 * /proc/self/mountinfo, hence we know for sure anything already set here is from the current
1739 * iteration and thus worthy of taking into account. */
1740 MountProcFlags flags
=
1741 MOUNT(u
)->proc_flags
| MOUNT_PROC_IS_MOUNTED
;
1743 r
= update_parameters_proc_self_mountinfo(MOUNT(u
), what
, options
, fstype
);
1747 flags
|= MOUNT_PROC_JUST_CHANGED
;
1749 /* There are two conditions when we consider a mount point just mounted: when we haven't seen it in
1750 * /proc/self/mountinfo before or when MOUNT_MOUNTING is our current state. Why bother with the
1751 * latter? Shouldn't that be covered by the former? No, during reload it is not because we might then
1752 * encounter a new /proc/self/mountinfo in combination with an old mount unit state (since it stems
1753 * from the serialized state), and need to catch up. Since we know that the MOUNT_MOUNTING state is
1754 * reached when we wait for the mount to appear we hence can assume that if we are in it, we are
1755 * actually seeing it established for the first time. */
1756 if (!MOUNT(u
)->from_proc_self_mountinfo
|| MOUNT(u
)->state
== MOUNT_MOUNTING
)
1757 flags
|= MOUNT_PROC_JUST_MOUNTED
;
1759 MOUNT(u
)->from_proc_self_mountinfo
= true;
1761 if (IN_SET(u
->load_state
, UNIT_NOT_FOUND
, UNIT_BAD_SETTING
, UNIT_ERROR
)) {
1762 /* The unit was previously not found or otherwise not loaded. Now that the unit shows up in
1763 * /proc/self/mountinfo we should reconsider it this, hence set it to UNIT_LOADED. */
1764 u
->load_state
= UNIT_LOADED
;
1767 flags
|= MOUNT_PROC_JUST_CHANGED
;
1770 if (FLAGS_SET(flags
, MOUNT_PROC_JUST_CHANGED
)) {
1771 /* If things changed, then make sure that all deps are regenerated. Let's
1772 * first remove all automatic deps, and then add in the new ones. */
1773 r
= mount_add_non_exec_dependencies(MOUNT(u
));
1782 static int mount_setup_unit(
1786 const char *options
,
1790 _cleanup_free_
char *e
= NULL
;
1791 MountProcFlags flags
;
1801 /* Ignore API mount points. They should never be referenced in
1802 * dependencies ever. */
1803 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1806 if (streq(fstype
, "autofs"))
1809 /* probably some kind of swap, ignore */
1810 if (!is_path(where
))
1813 r
= unit_name_from_path(where
, ".mount", &e
);
1815 return log_struct_errno(
1817 "MESSAGE_ID=" SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE_STR
,
1818 "MOUNT_POINT=%s", where
,
1819 LOG_MESSAGE("Failed to generate valid unit name from mount point path '%s', ignoring mount point: %m",
1822 u
= manager_get_unit(m
, e
);
1824 r
= mount_setup_existing_unit(u
, what
, where
, options
, fstype
, &flags
);
1826 /* First time we see this mount point meaning that it's not been initiated by a mount unit
1827 * but rather by the sysadmin having called mount(8) directly. */
1828 r
= mount_setup_new_unit(m
, e
, what
, where
, options
, fstype
, &flags
, &u
);
1830 return log_warning_errno(r
, "Failed to set up mount unit for '%s': %m", where
);
1832 /* If the mount changed properties or state, let's notify our clients */
1833 if (flags
& (MOUNT_PROC_JUST_CHANGED
|MOUNT_PROC_JUST_MOUNTED
))
1834 unit_add_to_dbus_queue(u
);
1837 MOUNT(u
)->proc_flags
= flags
;
1842 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1843 _cleanup_(mnt_free_tablep
) struct libmnt_table
*table
= NULL
;
1844 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*iter
= NULL
;
1849 r
= libmount_parse(NULL
, NULL
, &table
, &iter
);
1851 return log_error_errno(r
, "Failed to parse /proc/self/mountinfo: %m");
1854 struct libmnt_fs
*fs
;
1855 const char *device
, *path
, *options
, *fstype
;
1857 r
= mnt_table_next_fs(table
, iter
, &fs
);
1861 return log_error_errno(r
, "Failed to get next entry from /proc/self/mountinfo: %m");
1863 device
= mnt_fs_get_source(fs
);
1864 path
= mnt_fs_get_target(fs
);
1865 options
= mnt_fs_get_options(fs
);
1866 fstype
= mnt_fs_get_fstype(fs
);
1868 if (!device
|| !path
)
1871 device_found_node(m
, device
, DEVICE_FOUND_MOUNT
, DEVICE_FOUND_MOUNT
);
1873 (void) mount_setup_unit(m
, device
, path
, options
, fstype
, set_flags
);
1879 static void mount_shutdown(Manager
*m
) {
1882 m
->mount_event_source
= sd_event_source_disable_unref(m
->mount_event_source
);
1884 mnt_unref_monitor(m
->mount_monitor
);
1885 m
->mount_monitor
= NULL
;
1888 static int mount_get_timeout(Unit
*u
, usec_t
*timeout
) {
1889 Mount
*m
= MOUNT(u
);
1896 if (!m
->timer_event_source
)
1899 r
= sd_event_source_get_time(m
->timer_event_source
, &t
);
1902 if (t
== USEC_INFINITY
)
1909 static void mount_enumerate_perpetual(Manager
*m
) {
1915 /* Whatever happens, we know for sure that the root directory is around, and cannot go away. Let's
1916 * unconditionally synthesize it here and mark it as perpetual. */
1918 u
= manager_get_unit(m
, SPECIAL_ROOT_MOUNT
);
1920 r
= unit_new_for_name(m
, sizeof(Mount
), SPECIAL_ROOT_MOUNT
, &u
);
1922 log_error_errno(r
, "Failed to allocate the special " SPECIAL_ROOT_MOUNT
" unit: %m");
1927 u
->perpetual
= true;
1928 MOUNT(u
)->deserialized_state
= MOUNT_MOUNTED
;
1930 unit_add_to_load_queue(u
);
1931 unit_add_to_dbus_queue(u
);
1934 static bool mount_is_mounted(Mount
*m
) {
1937 return UNIT(m
)->perpetual
|| FLAGS_SET(m
->proc_flags
, MOUNT_PROC_IS_MOUNTED
);
1940 static int mount_on_ratelimit_expire(sd_event_source
*s
, void *userdata
) {
1941 Manager
*m
= ASSERT_PTR(userdata
);
1944 /* Let's enqueue all start jobs that were previously skipped because of active ratelimit. */
1945 HASHMAP_FOREACH(j
, m
->jobs
) {
1946 if (j
->unit
->type
!= UNIT_MOUNT
)
1949 job_add_to_run_queue(j
);
1952 /* By entering ratelimited state we made all mount start jobs not runnable, now rate limit is over so
1953 * let's make sure we dispatch them in the next iteration. */
1954 manager_trigger_run_queue(m
);
1959 static void mount_enumerate(Manager
*m
) {
1966 if (!m
->mount_monitor
) {
1967 unsigned mount_rate_limit_burst
= 5;
1970 m
->mount_monitor
= mnt_new_monitor();
1971 if (!m
->mount_monitor
) {
1976 r
= mnt_monitor_enable_kernel(m
->mount_monitor
, 1);
1978 log_error_errno(r
, "Failed to enable watching of kernel mount events: %m");
1982 r
= mnt_monitor_enable_userspace(m
->mount_monitor
, 1, NULL
);
1984 log_error_errno(r
, "Failed to enable watching of userspace mount events: %m");
1988 /* mnt_unref_monitor() will close the fd */
1989 fd
= r
= mnt_monitor_get_fd(m
->mount_monitor
);
1991 log_error_errno(r
, "Failed to acquire watch file descriptor: %m");
1995 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fd
, EPOLLIN
, mount_dispatch_io
, m
);
1997 log_error_errno(r
, "Failed to watch mount file descriptor: %m");
2001 r
= sd_event_source_set_priority(m
->mount_event_source
, SD_EVENT_PRIORITY_NORMAL
-10);
2003 log_error_errno(r
, "Failed to adjust mount watch priority: %m");
2007 /* Let users override the default (5 in 1s), as it stalls the boot sequence on busy systems. */
2008 const char *e
= secure_getenv("SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST");
2010 r
= safe_atou(e
, &mount_rate_limit_burst
);
2012 log_debug("Invalid value in $SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST, ignoring: %s", e
);
2015 r
= sd_event_source_set_ratelimit(m
->mount_event_source
, 1 * USEC_PER_SEC
, mount_rate_limit_burst
);
2017 log_error_errno(r
, "Failed to enable rate limit for mount events: %m");
2021 r
= sd_event_source_set_ratelimit_expire_callback(m
->mount_event_source
, mount_on_ratelimit_expire
);
2023 log_error_errno(r
, "Failed to enable rate limit for mount events: %m");
2027 (void) sd_event_source_set_description(m
->mount_event_source
, "mount-monitor-dispatch");
2030 r
= mount_load_proc_self_mountinfo(m
, false);
2040 static int drain_libmount(Manager
*m
) {
2041 bool rescan
= false;
2046 /* Drain all events and verify that the event is valid.
2048 * Note that libmount also monitors /run/mount mkdir if the directory does not exist yet. The mkdir
2049 * may generate event which is irrelevant for us.
2051 * error: r < 0; valid: r == 0, false positive: r == 1 */
2053 r
= mnt_monitor_next_change(m
->mount_monitor
, NULL
, NULL
);
2055 return log_error_errno(r
, "Failed to drain libmount events: %m");
2063 static int mount_process_proc_self_mountinfo(Manager
*m
) {
2064 _cleanup_set_free_ Set
*around
= NULL
, *gone
= NULL
;
2070 r
= drain_libmount(m
);
2074 r
= mount_load_proc_self_mountinfo(m
, true);
2076 /* Reset flags, just in case, for later calls */
2077 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
])
2078 MOUNT(u
)->proc_flags
= 0;
2083 manager_dispatch_load_queue(m
);
2085 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
2086 Mount
*mount
= MOUNT(u
);
2088 mount
->invalidated_state
= false;
2090 if (!mount_is_mounted(mount
)) {
2092 /* A mount point is not around right now. It might be gone, or might never have
2095 if (mount
->from_proc_self_mountinfo
&&
2096 mount
->parameters_proc_self_mountinfo
.what
)
2097 /* Remember that this device might just have disappeared */
2098 if (set_put_strdup_full(&gone
, &path_hash_ops_free
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
2099 log_oom(); /* we don't care too much about OOM here... */
2101 mount
->from_proc_self_mountinfo
= false;
2102 assert_se(update_parameters_proc_self_mountinfo(mount
, NULL
, NULL
, NULL
) >= 0);
2104 switch (mount
->state
) {
2107 /* This has just been unmounted by somebody else, follow the state change. */
2108 mount_enter_dead(mount
, MOUNT_SUCCESS
);
2111 case MOUNT_MOUNTING_DONE
:
2112 /* The mount command may add the corresponding proc mountinfo entry and
2113 * then remove it because of an internal error. E.g., fuse.sshfs seems
2114 * to do that when the connection fails. See #17617. To handle such the
2115 * case, let's once set the state back to mounting. Then, the unit can
2116 * correctly enter the failed state later in mount_sigchld(). */
2117 mount_set_state(mount
, MOUNT_MOUNTING
);
2124 } else if (mount
->proc_flags
& (MOUNT_PROC_JUST_MOUNTED
|MOUNT_PROC_JUST_CHANGED
)) {
2126 /* A mount point was added or changed */
2128 switch (mount
->state
) {
2133 /* This has just been mounted by somebody else, follow the state change, but let's
2134 * generate a new invocation ID for this implicitly and automatically. */
2135 (void) unit_acquire_invocation_id(u
);
2136 mount_cycle_clear(mount
);
2137 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
2140 case MOUNT_MOUNTING
:
2141 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
2145 /* Nothing really changed, but let's issue an notification call nonetheless,
2146 * in case somebody is waiting for this. (e.g. file system ro/rw
2148 mount_set_state(mount
, mount
->state
);
2153 if (mount_is_mounted(mount
) &&
2154 mount
->from_proc_self_mountinfo
&&
2155 mount
->parameters_proc_self_mountinfo
.what
)
2156 /* Track devices currently used */
2157 if (set_put_strdup_full(&around
, &path_hash_ops_free
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
2160 /* Reset the flags for later calls */
2161 mount
->proc_flags
= 0;
2164 SET_FOREACH(what
, gone
) {
2165 if (set_contains(around
, what
))
2168 /* Let the device units know that the device is no longer mounted */
2169 device_found_node(m
, what
, DEVICE_NOT_FOUND
, DEVICE_FOUND_MOUNT
);
2175 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
2176 Manager
*m
= ASSERT_PTR(userdata
);
2178 assert(revents
& EPOLLIN
);
2180 return mount_process_proc_self_mountinfo(m
);
2183 int mount_invalidate_state_by_path(Manager
*manager
, const char *path
) {
2184 _cleanup_free_
char *name
= NULL
;
2191 r
= unit_name_from_path(path
, ".mount", &name
);
2193 return log_debug_errno(r
, "Failed to generate unit name from path \"%s\", ignoring: %m", path
);
2195 u
= manager_get_unit(manager
, name
);
2199 MOUNT(u
)->invalidated_state
= true;
2203 static void mount_reset_failed(Unit
*u
) {
2204 Mount
*m
= MOUNT(u
);
2208 if (m
->state
== MOUNT_FAILED
)
2209 mount_set_state(m
, MOUNT_DEAD
);
2211 m
->result
= MOUNT_SUCCESS
;
2212 m
->reload_result
= MOUNT_SUCCESS
;
2213 m
->clean_result
= MOUNT_SUCCESS
;
2216 static PidRef
* mount_control_pid(Unit
*u
) {
2217 return &ASSERT_PTR(MOUNT(u
))->control_pid
;
2220 static int mount_clean(Unit
*u
, ExecCleanMask mask
) {
2221 _cleanup_strv_free_
char **l
= NULL
;
2222 Mount
*m
= MOUNT(u
);
2228 if (m
->state
!= MOUNT_DEAD
)
2231 r
= exec_context_get_clean_directories(&m
->exec_context
, u
->manager
->prefix
, mask
, &l
);
2235 if (strv_isempty(l
))
2238 mount_unwatch_control_pid(m
);
2239 m
->clean_result
= MOUNT_SUCCESS
;
2240 m
->control_command
= NULL
;
2241 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
2243 r
= mount_arm_timer(m
, usec_add(now(CLOCK_MONOTONIC
), m
->exec_context
.timeout_clean_usec
));
2247 r
= unit_fork_and_watch_rm_rf(u
, l
, &m
->control_pid
);
2251 mount_set_state(m
, MOUNT_CLEANING
);
2255 log_unit_warning_errno(u
, r
, "Failed to initiate cleaning: %m");
2256 m
->clean_result
= MOUNT_FAILURE_RESOURCES
;
2257 m
->timer_event_source
= sd_event_source_disable_unref(m
->timer_event_source
);
2261 static int mount_can_clean(Unit
*u
, ExecCleanMask
*ret
) {
2262 Mount
*m
= MOUNT(u
);
2266 return exec_context_get_clean_mask(&m
->exec_context
, ret
);
2269 static int mount_can_start(Unit
*u
) {
2270 Mount
*m
= MOUNT(u
);
2275 r
= unit_test_start_limit(u
);
2277 mount_enter_dead(m
, MOUNT_FAILURE_START_LIMIT_HIT
);
2284 static int mount_subsystem_ratelimited(Manager
*m
) {
2287 if (!m
->mount_event_source
)
2290 return sd_event_source_is_ratelimited(m
->mount_event_source
);
2293 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
2294 [MOUNT_EXEC_MOUNT
] = "ExecMount",
2295 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
2296 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
2299 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
2301 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
2302 [MOUNT_SUCCESS
] = "success",
2303 [MOUNT_FAILURE_RESOURCES
] = "resources",
2304 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
2305 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
2306 [MOUNT_FAILURE_SIGNAL
] = "signal",
2307 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump",
2308 [MOUNT_FAILURE_START_LIMIT_HIT
] = "start-limit-hit",
2309 [MOUNT_FAILURE_PROTOCOL
] = "protocol",
2312 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
2314 const UnitVTable mount_vtable
= {
2315 .object_size
= sizeof(Mount
),
2316 .exec_context_offset
= offsetof(Mount
, exec_context
),
2317 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
2318 .kill_context_offset
= offsetof(Mount
, kill_context
),
2319 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
2325 .private_section
= "Mount",
2327 .can_transient
= true,
2329 .exclude_from_switch_root_serialization
= true,
2335 .coldplug
= mount_coldplug
,
2336 .catchup
= mount_catchup
,
2340 .start
= mount_start
,
2342 .reload
= mount_reload
,
2344 .clean
= mount_clean
,
2345 .can_clean
= mount_can_clean
,
2347 .serialize
= mount_serialize
,
2348 .deserialize_item
= mount_deserialize_item
,
2350 .active_state
= mount_active_state
,
2351 .sub_state_to_string
= mount_sub_state_to_string
,
2353 .will_restart
= unit_will_restart_default
,
2355 .may_gc
= mount_may_gc
,
2356 .is_extrinsic
= mount_is_extrinsic
,
2358 .sigchld_event
= mount_sigchld_event
,
2360 .reset_failed
= mount_reset_failed
,
2362 .control_pid
= mount_control_pid
,
2364 .bus_set_property
= bus_mount_set_property
,
2365 .bus_commit_properties
= bus_mount_commit_properties
,
2367 .get_timeout
= mount_get_timeout
,
2369 .enumerate_perpetual
= mount_enumerate_perpetual
,
2370 .enumerate
= mount_enumerate
,
2371 .shutdown
= mount_shutdown
,
2372 .subsystem_ratelimited
= mount_subsystem_ratelimited
,
2374 .status_message_formats
= {
2375 .starting_stopping
= {
2376 [0] = "Mounting %s...",
2377 [1] = "Unmounting %s...",
2379 .finished_start_job
= {
2380 [JOB_DONE
] = "Mounted %s.",
2381 [JOB_FAILED
] = "Failed to mount %s.",
2382 [JOB_TIMEOUT
] = "Timed out mounting %s.",
2384 .finished_stop_job
= {
2385 [JOB_DONE
] = "Unmounted %s.",
2386 [JOB_FAILED
] = "Failed unmounting %s.",
2387 [JOB_TIMEOUT
] = "Timed out unmounting %s.",
2391 .can_start
= mount_can_start
,
2393 .notify_plymouth
= true,