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 int mount_is_bound_to_device(Mount
*m
) {
129 _cleanup_free_
char *value
= NULL
;
130 const MountParameters
*p
;
135 /* Determines whether to place a Requires= or BindsTo= dependency on the backing device unit. We do
136 * this by checking for the x-systemd.device-bound= mount option. If it is enabled we use BindsTo=,
137 * otherwise Requires=. But note that we might combine the latter with StopPropagatedFrom=, see
140 p
= get_mount_parameters(m
);
144 r
= fstab_filter_options(p
->options
, "x-systemd.device-bound\0", NULL
, &value
, NULL
, NULL
);
148 return -EIDRM
; /* If unspecified at all, return recognizable error */
153 return parse_boolean(value
);
156 static bool mount_propagate_stop(Mount
*m
) {
161 r
= mount_is_bound_to_device(m
);
163 /* If x-systemd.device-bound=no is explicitly requested by user, don't try to set StopPropagatedFrom=.
164 * Also don't bother if true, since with BindsTo= the stop propagation is implicit. */
167 log_debug_errno(r
, "Failed to get x-systemd.device-bound= option, ignoring: %m");
169 return m
->from_fragment
; /* let's propagate stop whenever this is an explicitly configured unit,
170 * otherwise let's not bother. */
173 static bool mount_needs_quota(const MountParameters
*p
) {
176 if (p
->fstype
&& !fstype_needs_quota(p
->fstype
))
179 if (mount_is_bind(p
))
182 return fstab_test_option(p
->options
,
183 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
186 static void mount_init(Unit
*u
) {
191 assert(u
->load_state
== UNIT_STUB
);
193 m
->timeout_usec
= u
->manager
->defaults
.timeout_start_usec
;
195 m
->exec_context
.std_output
= u
->manager
->defaults
.std_output
;
196 m
->exec_context
.std_error
= u
->manager
->defaults
.std_error
;
198 m
->directory_mode
= 0755;
200 /* We need to make sure that /usr/bin/mount is always called
201 * in the same process group as us, so that the autofs kernel
202 * side doesn't send us another mount request while we are
203 * already trying to comply its last one. */
204 m
->exec_context
.same_pgrp
= true;
206 m
->control_pid
= PIDREF_NULL
;
207 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
209 u
->ignore_on_isolate
= true;
212 static int mount_arm_timer(Mount
*m
, bool relative
, usec_t usec
) {
215 return unit_arm_timer(UNIT(m
), &m
->timer_event_source
, relative
, usec
, mount_dispatch_timer
);
218 static void mount_unwatch_control_pid(Mount
*m
) {
221 if (!pidref_is_set(&m
->control_pid
))
224 unit_unwatch_pidref(UNIT(m
), &m
->control_pid
);
225 pidref_done(&m
->control_pid
);
228 static void mount_parameters_done(MountParameters
*p
) {
231 p
->what
= mfree(p
->what
);
232 p
->options
= mfree(p
->options
);
233 p
->fstype
= mfree(p
->fstype
);
236 static void mount_done(Unit
*u
) {
241 m
->where
= mfree(m
->where
);
243 mount_parameters_done(&m
->parameters_proc_self_mountinfo
);
244 mount_parameters_done(&m
->parameters_fragment
);
246 m
->exec_runtime
= exec_runtime_free(m
->exec_runtime
);
247 exec_command_done_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
248 m
->control_command
= NULL
;
250 mount_unwatch_control_pid(m
);
252 m
->timer_event_source
= sd_event_source_disable_unref(m
->timer_event_source
);
255 static int update_parameters_proc_self_mountinfo(
259 const char *fstype
) {
264 p
= &m
->parameters_proc_self_mountinfo
;
266 r
= free_and_strdup(&p
->what
, what
);
270 q
= free_and_strdup(&p
->options
, options
);
274 w
= free_and_strdup(&p
->fstype
, fstype
);
278 return r
> 0 || q
> 0 || w
> 0;
281 static int mount_add_mount_dependencies(Mount
*m
) {
289 if (!path_equal(m
->where
, "/")) {
290 _cleanup_free_
char *parent
= NULL
;
292 /* Adds in links to other mount points that might lie further up in the hierarchy */
294 r
= path_extract_directory(m
->where
, &parent
);
298 r
= unit_require_mounts_for(UNIT(m
), parent
, UNIT_DEPENDENCY_IMPLICIT
);
303 /* Adds in dependencies to other mount points that might be needed for the source path (if this is a bind mount
304 * or a loop mount) to be available. */
305 pm
= get_mount_parameters_fragment(m
);
306 if (pm
&& pm
->what
&&
307 path_is_absolute(pm
->what
) &&
308 (mount_is_bind(pm
) || mount_is_loop(pm
) || !mount_is_network(pm
))) {
310 r
= unit_require_mounts_for(UNIT(m
), pm
->what
, UNIT_DEPENDENCY_FILE
);
315 /* Adds in dependencies to other units that use this path or paths further down in the hierarchy */
316 s
= manager_get_units_requiring_mounts_for(UNIT(m
)->manager
, m
->where
);
317 SET_FOREACH(other
, s
) {
319 if (other
->load_state
!= UNIT_LOADED
)
322 if (other
== UNIT(m
))
325 r
= unit_add_dependency(other
, UNIT_AFTER
, UNIT(m
), true, UNIT_DEPENDENCY_PATH
);
329 if (UNIT(m
)->fragment_path
) {
330 /* If we have fragment configuration, then make this dependency required */
331 r
= unit_add_dependency(other
, UNIT_REQUIRES
, UNIT(m
), true, UNIT_DEPENDENCY_PATH
);
340 static int mount_add_device_dependencies(Mount
*m
) {
341 UnitDependencyMask mask
;
348 log_unit_trace(UNIT(m
), "Processing implicit device dependencies");
350 p
= get_mount_parameters(m
);
352 log_unit_trace(UNIT(m
), "Missing mount parameters, skipping implicit device dependencies");
357 log_unit_trace(UNIT(m
), "Missing mount source, skipping implicit device dependencies");
361 if (mount_is_bind(p
)) {
362 log_unit_trace(UNIT(m
), "Mount unit is a bind mount, skipping implicit device dependencies");
366 if (!is_device_path(p
->what
)) {
367 log_unit_trace(UNIT(m
), "Mount source is not a device path, skipping implicit device dependencies");
371 /* /dev/root is a really weird thing, it's not a real device, but just a path the kernel exports for
372 * the root file system specified on the kernel command line. Ignore it here. */
373 if (PATH_IN_SET(p
->what
, "/dev/root", "/dev/nfs")) {
374 log_unit_trace(UNIT(m
), "Mount source is in /dev/root or /dev/nfs, skipping implicit device dependencies");
378 if (path_equal(m
->where
, "/")) {
379 log_unit_trace(UNIT(m
), "Mount destination is '/', skipping implicit device dependencies");
383 /* Mount units from /proc/self/mountinfo are not bound to devices by default since they're subject to
384 * races when mounts are established by other tools with different backing devices than what we
385 * maintain. The user can still force this to be a BindsTo= dependency with an appropriate option (or
386 * udev property) so the mount units are automatically stopped when the device disappears
388 dep
= mount_is_bound_to_device(m
) > 0 ? UNIT_BINDS_TO
: UNIT_REQUIRES
;
390 /* We always use 'what' from /proc/self/mountinfo if mounted */
391 mask
= m
->from_proc_self_mountinfo
? UNIT_DEPENDENCY_MOUNTINFO
: UNIT_DEPENDENCY_MOUNT_FILE
;
393 r
= unit_add_node_dependency(UNIT(m
), p
->what
, dep
, mask
);
397 log_unit_trace(UNIT(m
), "Added %s dependency on %s", unit_dependency_to_string(dep
), p
->what
);
399 if (mount_propagate_stop(m
)) {
400 r
= unit_add_node_dependency(UNIT(m
), p
->what
, UNIT_STOP_PROPAGATED_FROM
, mask
);
404 log_unit_trace(UNIT(m
), "Added %s dependency on %s",
405 unit_dependency_to_string(UNIT_STOP_PROPAGATED_FROM
), p
->what
);
408 r
= unit_add_blockdev_dependency(UNIT(m
), p
->what
, mask
);
410 log_unit_trace(UNIT(m
), "Added %s dependency on %s", unit_dependency_to_string(UNIT_AFTER
), p
->what
);
415 static int mount_add_quota_dependencies(Mount
*m
) {
421 if (!MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
424 p
= get_mount_parameters_fragment(m
);
428 if (!mount_needs_quota(p
))
431 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
,
432 /* add_reference= */ true, UNIT_DEPENDENCY_FILE
);
436 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
,
437 /* add_reference= */true, UNIT_DEPENDENCY_FILE
);
444 static bool mount_is_extrinsic(Unit
*u
) {
449 /* Returns true for all units that are "magic" and should be excluded from the usual
450 * start-up and shutdown dependencies. We call them "extrinsic" here, as they are generally
451 * mounted outside of the systemd dependency logic. We shouldn't attempt to manage them
452 * ourselves but it's fine if the user operates on them with us. */
454 /* We only automatically manage mounts if we are in system mode */
455 if (MANAGER_IS_USER(u
->manager
))
458 p
= get_mount_parameters(m
);
459 if (p
&& fstab_is_extrinsic(m
->where
, p
->options
))
465 static bool mount_is_credentials(Mount
*m
) {
470 /* Returns true if this is a credentials mount. We don't want automatic dependencies on credential
471 * mounts, since they are managed by us for even the earliest services, and we never want anything to
472 * be ordered before them hence. */
474 e
= path_startswith(m
->where
, UNIT(m
)->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
478 return !isempty(path_startswith(e
, "credentials"));
481 static int mount_add_default_ordering_dependencies(Mount
*m
, MountParameters
*p
, UnitDependencyMask mask
) {
482 const char *after
, *before
, *e
;
487 e
= path_startswith(m
->where
, "/sysroot");
488 if (e
&& in_initrd()) {
489 /* All mounts under /sysroot need to happen later, at initrd-fs.target time. IOW,
490 * it's not technically part of the basic initrd filesystem itself, and so
491 * shouldn't inherit the default Before=local-fs.target dependency. However,
492 * these mounts still need to start after local-fs-pre.target, as a sync point
493 * for things like systemd-hibernate-resume.service that should start before
496 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
497 before
= isempty(e
) ? SPECIAL_INITRD_ROOT_FS_TARGET
: SPECIAL_INITRD_FS_TARGET
;
499 } else if (in_initrd() && path_startswith(m
->where
, "/sysusr/usr")) {
500 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
501 before
= SPECIAL_INITRD_USR_FS_TARGET
;
503 } else if (mount_is_credentials(m
))
504 after
= before
= NULL
;
506 else if (mount_is_network(p
)) {
507 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
508 before
= SPECIAL_REMOTE_FS_TARGET
;
511 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
512 before
= SPECIAL_LOCAL_FS_TARGET
;
515 if (before
&& !mount_is_nofail(m
)) {
516 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_BEFORE
, before
, /* add_reference= */ true, mask
);
522 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, /* add_reference= */ true, mask
);
527 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
,
528 /* add_reference= */ true, mask
);
532 /* If this is a tmpfs mount then we have to unmount it before we try to deactivate swaps */
533 if (streq_ptr(p
->fstype
, "tmpfs") && !mount_is_credentials(m
)) {
534 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, SPECIAL_SWAP_TARGET
,
535 /* add_reference= */ true, mask
);
543 static int mount_add_default_network_dependencies(Mount
*m
, MountParameters
*p
, UnitDependencyMask mask
) {
548 if (!mount_is_network(p
))
551 /* We order ourselves after network.target. This is primarily useful at shutdown: services that take
552 * down the network should order themselves before network.target, so that they are shut down only
553 * after this mount unit is stopped. */
555 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, SPECIAL_NETWORK_TARGET
,
556 /* add_reference= */ true, mask
);
560 /* We pull in network-online.target, and order ourselves after it. This is useful at start-up to
561 * actively pull in tools that want to be started before we start mounting network file systems, and
562 * whose purpose it is to delay this until the network is "up". */
564 return unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, SPECIAL_NETWORK_ONLINE_TARGET
,
565 /* add_reference= */ true, mask
);
568 static int mount_add_default_dependencies(Mount
*m
) {
569 UnitDependencyMask mask
;
575 if (!UNIT(m
)->default_dependencies
)
578 /* We do not add any default dependencies to /, /usr or /run/initramfs/, since they are
579 * guaranteed to stay mounted the whole time, since our system is on it. Also, don't
580 * bother with anything mounted below virtual file systems, it's also going to be virtual,
581 * and hence not worth the effort. */
582 if (mount_is_extrinsic(UNIT(m
)))
585 p
= get_mount_parameters(m
);
589 mask
= m
->from_proc_self_mountinfo
? UNIT_DEPENDENCY_MOUNTINFO
: UNIT_DEPENDENCY_MOUNT_FILE
;
591 r
= mount_add_default_ordering_dependencies(m
, p
, mask
);
595 r
= mount_add_default_network_dependencies(m
, p
, mask
);
602 static int mount_verify(Mount
*m
) {
603 _cleanup_free_
char *e
= NULL
;
608 assert(UNIT(m
)->load_state
== UNIT_LOADED
);
610 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
&& !UNIT(m
)->perpetual
)
613 r
= unit_name_from_path(m
->where
, ".mount", &e
);
615 return log_unit_error_errno(UNIT(m
), r
, "Failed to generate unit name from mount path: %m");
617 if (!unit_has_name(UNIT(m
), e
))
618 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
), "Where= setting doesn't match unit name. Refusing.");
620 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
))
621 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
), "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
623 p
= get_mount_parameters_fragment(m
);
624 if (p
&& !p
->what
&& !UNIT(m
)->perpetual
)
625 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
),
626 "What= setting is missing. Refusing.");
628 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
)
629 return log_unit_error_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOEXEC
), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
634 static int mount_add_non_exec_dependencies(Mount
*m
) {
639 /* We may be called due to this mount appearing in /proc/self/mountinfo, hence we clear all existing
640 * dependencies that were initialized from the unit file but whose final value really depends on the
641 * content of /proc/self/mountinfo. Some (such as m->where) might have become stale now. */
642 unit_remove_dependencies(UNIT(m
), UNIT_DEPENDENCY_MOUNTINFO
| UNIT_DEPENDENCY_MOUNT_FILE
);
647 /* Adds in all dependencies directly responsible for ordering the mount, as opposed to dependencies
648 * resulting from the ExecContext and such. */
650 r
= mount_add_device_dependencies(m
);
654 r
= mount_add_mount_dependencies(m
);
658 r
= mount_add_quota_dependencies(m
);
662 r
= mount_add_default_dependencies(m
);
669 static int mount_add_extras(Mount
*m
) {
675 /* Note: this call might be called after we already have been loaded once (and even when it has already been
676 * activated), in case data from /proc/self/mountinfo has changed. This means all code here needs to be ready
677 * to run with an already set up unit. */
679 if (u
->fragment_path
)
680 m
->from_fragment
= true;
683 r
= unit_name_to_path(u
->id
, &m
->where
);
684 if (r
== -ENAMETOOLONG
)
685 log_unit_error_errno(u
, r
, "Failed to derive mount point path from unit name, because unit name is hashed. "
686 "Set \"Where=\" in the unit file explicitly.");
691 path_simplify(m
->where
);
693 if (!u
->description
) {
694 r
= unit_set_description(u
, m
->where
);
699 r
= unit_patch_contexts(u
);
703 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
707 r
= unit_set_default_slice(u
);
711 r
= mount_add_non_exec_dependencies(m
);
718 static void mount_load_root_mount(Unit
*u
) {
721 if (!unit_has_name(u
, SPECIAL_ROOT_MOUNT
))
725 u
->default_dependencies
= false;
727 /* The stdio/kmsg bridge socket is on /, in order to avoid a dep loop, don't use kmsg logging for -.mount */
728 MOUNT(u
)->exec_context
.std_output
= EXEC_OUTPUT_NULL
;
729 MOUNT(u
)->exec_context
.std_input
= EXEC_INPUT_NULL
;
732 u
->description
= strdup("Root Mount");
735 static int mount_load(Unit
*u
) {
741 assert(u
->load_state
== UNIT_STUB
);
743 mount_load_root_mount(u
);
745 bool fragment_optional
= m
->from_proc_self_mountinfo
|| u
->perpetual
;
746 r
= unit_load_fragment_and_dropin(u
, !fragment_optional
);
748 /* Add in some extras. Note we do this in all cases (even if we failed to load the unit) when announced by the
749 * kernel, because we need some things to be set up no matter what when the kernel establishes a mount and thus
750 * we need to update the state in our unit to track it. After all, consider that we don't allow changing the
751 * 'slice' field for a unit once it is active. */
752 if (u
->load_state
== UNIT_LOADED
|| m
->from_proc_self_mountinfo
|| u
->perpetual
)
753 q
= mount_add_extras(m
);
759 if (u
->load_state
!= UNIT_LOADED
)
762 return mount_verify(m
);
765 static void mount_set_state(Mount
*m
, MountState state
) {
766 MountState old_state
;
769 if (m
->state
!= state
)
770 bus_unit_send_pending_change_signal(UNIT(m
), false);
772 old_state
= m
->state
;
775 if (!MOUNT_STATE_WITH_PROCESS(state
)) {
776 m
->timer_event_source
= sd_event_source_disable_unref(m
->timer_event_source
);
777 mount_unwatch_control_pid(m
);
778 m
->control_command
= NULL
;
779 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
782 if (state
!= old_state
)
783 log_unit_debug(UNIT(m
), "Changed %s -> %s", mount_state_to_string(old_state
), mount_state_to_string(state
));
785 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
788 static int mount_coldplug(Unit
*u
) {
793 assert(m
->state
== MOUNT_DEAD
);
795 if (m
->deserialized_state
== m
->state
)
798 if (pidref_is_set(&m
->control_pid
) &&
799 pidref_is_unwaited(&m
->control_pid
) > 0 &&
800 MOUNT_STATE_WITH_PROCESS(m
->deserialized_state
)) {
802 r
= unit_watch_pidref(UNIT(m
), &m
->control_pid
, /* exclusive= */ false);
806 r
= mount_arm_timer(m
, /* relative= */ false, usec_add(u
->state_change_timestamp
.monotonic
, m
->timeout_usec
));
811 if (!IN_SET(m
->deserialized_state
, MOUNT_DEAD
, MOUNT_FAILED
))
812 (void) unit_setup_exec_runtime(u
);
814 mount_set_state(m
, m
->deserialized_state
);
818 static void mount_catchup(Unit
*u
) {
819 Mount
*m
= MOUNT(ASSERT_PTR(u
));
823 /* Adjust the deserialized state. See comments in mount_process_proc_self_mountinfo(). */
824 if (m
->from_proc_self_mountinfo
)
828 assert(!pidref_is_set(&m
->control_pid
));
829 (void) unit_acquire_invocation_id(u
);
830 mount_cycle_clear(m
);
831 mount_enter_mounted(m
, MOUNT_SUCCESS
);
834 assert(pidref_is_set(&m
->control_pid
));
835 mount_set_state(m
, MOUNT_MOUNTING_DONE
);
842 case MOUNT_MOUNTING_DONE
:
843 assert(pidref_is_set(&m
->control_pid
));
844 mount_set_state(m
, MOUNT_MOUNTING
);
847 assert(!pidref_is_set(&m
->control_pid
));
848 mount_enter_dead(m
, MOUNT_SUCCESS
);
855 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
862 p
= get_mount_parameters(m
);
865 "%sMount State: %s\n"
867 "%sClean Result: %s\n"
870 "%sFile System Type: %s\n"
872 "%sFrom /proc/self/mountinfo: %s\n"
873 "%sFrom fragment: %s\n"
875 "%sDirectoryMode: %04o\n"
876 "%sSloppyOptions: %s\n"
877 "%sLazyUnmount: %s\n"
878 "%sForceUnmount: %s\n"
879 "%sReadWriteOnly: %s\n"
880 "%sTimeoutSec: %s\n",
881 prefix
, mount_state_to_string(m
->state
),
882 prefix
, mount_result_to_string(m
->result
),
883 prefix
, mount_result_to_string(m
->clean_result
),
885 prefix
, p
? strna(p
->what
) : "n/a",
886 prefix
, p
? strna(p
->fstype
) : "n/a",
887 prefix
, p
? strna(p
->options
) : "n/a",
888 prefix
, yes_no(m
->from_proc_self_mountinfo
),
889 prefix
, yes_no(m
->from_fragment
),
890 prefix
, yes_no(mount_is_extrinsic(u
)),
891 prefix
, m
->directory_mode
,
892 prefix
, yes_no(m
->sloppy_options
),
893 prefix
, yes_no(m
->lazy_unmount
),
894 prefix
, yes_no(m
->force_unmount
),
895 prefix
, yes_no(m
->read_write_only
),
896 prefix
, FORMAT_TIMESPAN(m
->timeout_usec
, USEC_PER_SEC
));
898 if (pidref_is_set(&m
->control_pid
))
900 "%sControl PID: "PID_FMT
"\n",
901 prefix
, m
->control_pid
.pid
);
903 exec_context_dump(&m
->exec_context
, f
, prefix
);
904 kill_context_dump(&m
->kill_context
, f
, prefix
);
905 cgroup_context_dump(UNIT(m
), f
, prefix
);
908 static int mount_spawn(Mount
*m
, ExecCommand
*c
, PidRef
*ret_pid
) {
910 _cleanup_(exec_params_clear
) ExecParameters exec_params
= EXEC_PARAMETERS_INIT(
911 EXEC_APPLY_SANDBOXING
|EXEC_APPLY_CHROOT
|EXEC_APPLY_TTY_STDIN
);
912 _cleanup_(pidref_done
) PidRef pidref
= PIDREF_NULL
;
920 r
= unit_prepare_exec(UNIT(m
));
924 r
= mount_arm_timer(m
, /* relative= */ true, m
->timeout_usec
);
928 r
= unit_set_exec_params(UNIT(m
), &exec_params
);
932 r
= exec_spawn(UNIT(m
),
942 r
= pidref_set_pid(&pidref
, pid
);
946 r
= unit_watch_pidref(UNIT(m
), &pidref
, /* exclusive= */ true);
950 *ret_pid
= TAKE_PIDREF(pidref
);
954 static void mount_enter_dead(Mount
*m
, MountResult f
) {
957 if (m
->result
== MOUNT_SUCCESS
)
960 unit_log_result(UNIT(m
), m
->result
== MOUNT_SUCCESS
, mount_result_to_string(m
->result
));
961 unit_warn_leftover_processes(UNIT(m
), unit_log_leftover_process_stop
);
963 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
965 m
->exec_runtime
= exec_runtime_destroy(m
->exec_runtime
);
967 unit_destroy_runtime_data(UNIT(m
), &m
->exec_context
);
969 unit_unref_uid_gid(UNIT(m
), true);
971 /* Any dependencies based on /proc/self/mountinfo are now stale. Let's re-generate dependencies from
973 (void) mount_add_non_exec_dependencies(m
);
976 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
979 if (m
->result
== MOUNT_SUCCESS
)
982 mount_set_state(m
, MOUNT_MOUNTED
);
985 static void mount_enter_dead_or_mounted(Mount
*m
, MountResult f
) {
988 /* Enter DEAD or MOUNTED state, depending on what the kernel currently says about the mount point. We use this
989 * whenever we executed an operation, so that our internal state reflects what the kernel says again, after all
990 * ultimately we just mirror the kernel's internal state on this. */
992 if (m
->from_proc_self_mountinfo
)
993 mount_enter_mounted(m
, f
);
995 mount_enter_dead(m
, f
);
998 static int state_to_kill_operation(MountState state
) {
1001 case MOUNT_REMOUNTING_SIGTERM
:
1002 return KILL_RESTART
;
1004 case MOUNT_UNMOUNTING_SIGTERM
:
1005 return KILL_TERMINATE
;
1007 case MOUNT_REMOUNTING_SIGKILL
:
1008 case MOUNT_UNMOUNTING_SIGKILL
:
1012 return _KILL_OPERATION_INVALID
;
1016 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
1021 if (m
->result
== MOUNT_SUCCESS
)
1024 r
= unit_kill_context(
1027 state_to_kill_operation(state
),
1028 /* main_pid= */ NULL
,
1030 /* main_pid_alien= */ false);
1032 log_unit_warning_errno(UNIT(m
), r
, "Failed to kill processes: %m");
1037 r
= mount_arm_timer(m
, /* relative= */ true, m
->timeout_usec
);
1039 log_unit_warning_errno(UNIT(m
), r
, "Failed to install timer: %m");
1043 mount_set_state(m
, state
);
1044 } else if (state
== MOUNT_REMOUNTING_SIGTERM
&& m
->kill_context
.send_sigkill
)
1045 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1046 else if (IN_SET(state
, MOUNT_REMOUNTING_SIGTERM
, MOUNT_REMOUNTING_SIGKILL
))
1047 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1048 else if (state
== MOUNT_UNMOUNTING_SIGTERM
&& m
->kill_context
.send_sigkill
)
1049 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1051 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1056 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_RESOURCES
);
1059 static int mount_set_umount_command(Mount
*m
, ExecCommand
*c
) {
1065 r
= exec_command_set(c
, UMOUNT_PATH
, m
->where
, "-c", NULL
);
1069 if (m
->lazy_unmount
) {
1070 r
= exec_command_append(c
, "-l", NULL
);
1075 if (m
->force_unmount
) {
1076 r
= exec_command_append(c
, "-f", NULL
);
1084 static void mount_enter_unmounting(Mount
*m
) {
1089 /* Start counting our attempts */
1090 if (!IN_SET(m
->state
,
1092 MOUNT_UNMOUNTING_SIGTERM
,
1093 MOUNT_UNMOUNTING_SIGKILL
))
1094 m
->n_retry_umount
= 0;
1096 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
1097 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
1099 r
= mount_set_umount_command(m
, m
->control_command
);
1101 log_unit_warning_errno(UNIT(m
), r
, "Failed to prepare umount command line: %m");
1105 mount_unwatch_control_pid(m
);
1107 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
1109 log_unit_warning_errno(UNIT(m
), r
, "Failed to spawn 'umount' task: %m");
1113 mount_set_state(m
, MOUNT_UNMOUNTING
);
1118 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_RESOURCES
);
1121 static int mount_set_mount_command(Mount
*m
, ExecCommand
*c
, const MountParameters
*p
) {
1128 r
= exec_command_set(c
, MOUNT_PATH
, p
->what
, m
->where
, NULL
);
1132 if (m
->sloppy_options
) {
1133 r
= exec_command_append(c
, "-s", NULL
);
1138 if (m
->read_write_only
) {
1139 r
= exec_command_append(c
, "-w", NULL
);
1145 r
= exec_command_append(c
, "-t", p
->fstype
, NULL
);
1150 _cleanup_free_
char *opts
= NULL
;
1151 r
= fstab_filter_options(p
->options
, "nofail\0" "noauto\0" "auto\0", NULL
, NULL
, NULL
, &opts
);
1155 if (!isempty(opts
)) {
1156 r
= exec_command_append(c
, "-o", opts
, NULL
);
1164 static void mount_enter_mounting(Mount
*m
) {
1167 bool source_is_dir
= true;
1171 r
= unit_fail_if_noncanonical(UNIT(m
), m
->where
);
1175 p
= get_mount_parameters_fragment(m
);
1176 if (p
&& mount_is_bind(p
)) {
1177 r
= is_dir(p
->what
, /* follow = */ true);
1178 if (r
< 0 && r
!= -ENOENT
)
1179 log_unit_info_errno(UNIT(m
), r
, "Failed to determine type of bind mount source '%s', ignoring: %m", p
->what
);
1181 source_is_dir
= false;
1185 r
= mkdir_p_label(m
->where
, m
->directory_mode
);
1187 r
= touch_file(m
->where
, /* parents = */ true, USEC_INFINITY
, UID_INVALID
, GID_INVALID
, MODE_INVALID
);
1188 if (r
< 0 && r
!= -EEXIST
)
1189 log_unit_warning_errno(UNIT(m
), r
, "Failed to create mount point '%s', ignoring: %m", m
->where
);
1192 unit_warn_if_dir_nonempty(UNIT(m
), m
->where
);
1193 unit_warn_leftover_processes(UNIT(m
), unit_log_leftover_process_start
);
1195 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
1196 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
1198 /* Create the source directory for bind-mounts if needed */
1199 if (p
&& mount_is_bind(p
)) {
1200 r
= mkdir_p_label(p
->what
, m
->directory_mode
);
1201 /* mkdir_p_label() can return -EEXIST if the target path exists and is not a directory - which is
1202 * totally OK, in case the user wants us to overmount a non-directory inode. Also -EROFS can be
1203 * returned on read-only filesystem. Moreover, -EACCES (and also maybe -EPERM?) may be returned
1204 * when the path is on NFS. See issue #24120. All such errors will be logged in the debug level. */
1205 if (r
< 0 && r
!= -EEXIST
)
1206 log_unit_full_errno(UNIT(m
),
1207 (r
== -EROFS
|| ERRNO_IS_PRIVILEGE(r
)) ? LOG_DEBUG
: LOG_WARNING
,
1208 r
, "Failed to make bind mount source '%s', ignoring: %m", p
->what
);
1212 r
= mount_set_mount_command(m
, m
->control_command
, p
);
1214 log_unit_warning_errno(UNIT(m
), r
, "Failed to prepare mount command line: %m");
1218 r
= log_unit_warning_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOENT
), "No mount parameters to operate on.");
1222 mount_unwatch_control_pid(m
);
1224 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
1226 log_unit_warning_errno(UNIT(m
), r
, "Failed to spawn 'mount' task: %m");
1230 mount_set_state(m
, MOUNT_MOUNTING
);
1234 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_RESOURCES
);
1237 static void mount_set_reload_result(Mount
*m
, MountResult result
) {
1240 /* Only store the first error we encounter */
1241 if (m
->reload_result
!= MOUNT_SUCCESS
)
1244 m
->reload_result
= result
;
1247 static void mount_enter_remounting(Mount
*m
) {
1253 /* Reset reload result when we are about to start a new remount operation */
1254 m
->reload_result
= MOUNT_SUCCESS
;
1256 m
->control_command_id
= MOUNT_EXEC_REMOUNT
;
1257 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_REMOUNT
;
1259 p
= get_mount_parameters_fragment(m
);
1264 o
= strjoina("remount,", p
->options
);
1268 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
1271 if (r
>= 0 && m
->sloppy_options
)
1272 r
= exec_command_append(m
->control_command
, "-s", NULL
);
1273 if (r
>= 0 && m
->read_write_only
)
1274 r
= exec_command_append(m
->control_command
, "-w", NULL
);
1275 if (r
>= 0 && p
->fstype
)
1276 r
= exec_command_append(m
->control_command
, "-t", p
->fstype
, NULL
);
1278 log_unit_warning_errno(UNIT(m
), r
, "Failed to prepare remount command line: %m");
1283 r
= log_unit_warning_errno(UNIT(m
), SYNTHETIC_ERRNO(ENOENT
), "No mount parameters to operate on.");
1287 mount_unwatch_control_pid(m
);
1289 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
1291 log_unit_warning_errno(UNIT(m
), r
, "Failed to spawn 'remount' task: %m");
1295 mount_set_state(m
, MOUNT_REMOUNTING
);
1299 mount_set_reload_result(m
, MOUNT_FAILURE_RESOURCES
);
1300 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1303 static void mount_cycle_clear(Mount
*m
) {
1306 /* Clear all state we shall forget for this new cycle */
1308 m
->result
= MOUNT_SUCCESS
;
1309 m
->reload_result
= MOUNT_SUCCESS
;
1310 exec_command_reset_status_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
1311 UNIT(m
)->reset_accounting
= true;
1314 static int mount_start(Unit
*u
) {
1315 Mount
*m
= MOUNT(u
);
1320 /* We cannot fulfill this request right now, try again later
1322 if (IN_SET(m
->state
,
1324 MOUNT_UNMOUNTING_SIGTERM
,
1325 MOUNT_UNMOUNTING_SIGKILL
,
1329 /* Already on it! */
1330 if (IN_SET(m
->state
, MOUNT_MOUNTING
, MOUNT_MOUNTING_DONE
))
1333 assert(IN_SET(m
->state
, MOUNT_DEAD
, MOUNT_FAILED
));
1335 r
= unit_acquire_invocation_id(u
);
1339 mount_cycle_clear(m
);
1340 mount_enter_mounting(m
);
1345 static int mount_stop(Unit
*u
) {
1346 Mount
*m
= MOUNT(u
);
1350 /* When we directly call umount() for a path, then the state of the corresponding mount unit may be
1351 * outdated. Let's re-read mountinfo now and update the state. */
1352 if (m
->invalidated_state
)
1353 (void) mount_process_proc_self_mountinfo(u
->manager
);
1357 case MOUNT_UNMOUNTING
:
1358 case MOUNT_UNMOUNTING_SIGKILL
:
1359 case MOUNT_UNMOUNTING_SIGTERM
:
1363 case MOUNT_MOUNTING
:
1364 case MOUNT_MOUNTING_DONE
:
1365 case MOUNT_REMOUNTING
:
1366 /* If we are still waiting for /bin/mount, we go directly into kill mode. */
1367 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_SUCCESS
);
1370 case MOUNT_REMOUNTING_SIGTERM
:
1371 /* If we are already waiting for a hung remount, convert this to the matching unmounting state */
1372 mount_set_state(m
, MOUNT_UNMOUNTING_SIGTERM
);
1375 case MOUNT_REMOUNTING_SIGKILL
:
1377 mount_set_state(m
, MOUNT_UNMOUNTING_SIGKILL
);
1381 mount_enter_unmounting(m
);
1384 case MOUNT_CLEANING
:
1385 /* If we are currently cleaning, then abort it, brutally. */
1386 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1391 /* The mount has just been unmounted by somebody else. */
1395 assert_not_reached();
1399 static int mount_reload(Unit
*u
) {
1400 Mount
*m
= MOUNT(u
);
1403 assert(m
->state
== MOUNT_MOUNTED
);
1405 mount_enter_remounting(m
);
1410 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1411 Mount
*m
= MOUNT(u
);
1417 (void) serialize_item(f
, "state", mount_state_to_string(m
->state
));
1418 (void) serialize_item(f
, "result", mount_result_to_string(m
->result
));
1419 (void) serialize_item(f
, "reload-result", mount_result_to_string(m
->reload_result
));
1420 (void) serialize_item_format(f
, "n-retry-umount", "%u", m
->n_retry_umount
);
1421 (void) serialize_pidref(f
, fds
, "control-pid", &m
->control_pid
);
1423 if (m
->control_command_id
>= 0)
1424 (void) serialize_item(f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1429 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1430 Mount
*m
= MOUNT(u
);
1439 if (streq(key
, "state")) {
1442 state
= mount_state_from_string(value
);
1444 log_unit_debug_errno(u
, state
, "Failed to parse state value: %s", value
);
1446 m
->deserialized_state
= state
;
1448 } else if (streq(key
, "result")) {
1451 f
= mount_result_from_string(value
);
1453 log_unit_debug_errno(u
, f
, "Failed to parse result value: %s", value
);
1454 else if (f
!= MOUNT_SUCCESS
)
1457 } else if (streq(key
, "reload-result")) {
1460 f
= mount_result_from_string(value
);
1462 log_unit_debug_errno(u
, f
, "Failed to parse reload result value: %s", value
);
1463 else if (f
!= MOUNT_SUCCESS
)
1464 m
->reload_result
= f
;
1466 } else if (streq(key
, "n-retry-umount")) {
1468 r
= safe_atou(value
, &m
->n_retry_umount
);
1470 log_unit_debug_errno(u
, r
, "Failed to parse n-retry-umount value: %s", value
);
1472 } else if (streq(key
, "control-pid")) {
1474 pidref_done(&m
->control_pid
);
1475 (void) deserialize_pidref(fds
, value
, &m
->control_pid
);
1477 } else if (streq(key
, "control-command")) {
1478 MountExecCommand id
;
1480 id
= mount_exec_command_from_string(value
);
1482 log_unit_debug_errno(u
, id
, "Failed to parse exec-command value: %s", value
);
1484 m
->control_command_id
= id
;
1485 m
->control_command
= m
->exec_command
+ id
;
1488 log_unit_debug(u
, "Unknown serialization key: %s", key
);
1493 static UnitActiveState
mount_active_state(Unit
*u
) {
1496 return state_translation_table
[MOUNT(u
)->state
];
1499 static const char *mount_sub_state_to_string(Unit
*u
) {
1502 return mount_state_to_string(MOUNT(u
)->state
);
1505 static bool mount_may_gc(Unit
*u
) {
1506 Mount
*m
= MOUNT(u
);
1510 if (m
->from_proc_self_mountinfo
)
1516 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1517 Mount
*m
= MOUNT(u
);
1523 if (pid
!= m
->control_pid
.pid
)
1526 /* So here's the thing, we really want to know before /usr/bin/mount or /usr/bin/umount exit whether
1527 * they established/remove a mount. This is important when mounting, but even more so when unmounting
1528 * since we need to deal with nested mounts and otherwise cannot safely determine whether to repeat
1529 * the unmounts. In theory, the kernel fires /proc/self/mountinfo changes off before returning from
1530 * the mount() or umount() syscalls, and thus we should see the changes to the proc file before we
1531 * process the waitid() for the /usr/bin/(u)mount processes. However, this is unfortunately racy: we
1532 * have to waitid() for processes using P_ALL (since we need to reap unexpected children that got
1533 * reparented to PID 1), but when using P_ALL we might end up reaping processes that terminated just
1534 * instants ago, i.e. already after our last event loop iteration (i.e. after the last point we might
1535 * have noticed /proc/self/mountinfo events via epoll). This means event loop priorities for
1536 * processing SIGCHLD vs. /proc/self/mountinfo IO events are not as relevant as we want. To fix that
1537 * race, let's explicitly scan /proc/self/mountinfo before we start processing /usr/bin/(u)mount
1538 * dying. It's ugly, but it makes our ordering systematic again, and makes sure we always see
1539 * /proc/self/mountinfo changes before our mount/umount exits. */
1540 (void) mount_process_proc_self_mountinfo(u
->manager
);
1542 pidref_done(&m
->control_pid
);
1544 if (is_clean_exit(code
, status
, EXIT_CLEAN_COMMAND
, NULL
))
1546 else if (code
== CLD_EXITED
)
1547 f
= MOUNT_FAILURE_EXIT_CODE
;
1548 else if (code
== CLD_KILLED
)
1549 f
= MOUNT_FAILURE_SIGNAL
;
1550 else if (code
== CLD_DUMPED
)
1551 f
= MOUNT_FAILURE_CORE_DUMP
;
1553 assert_not_reached();
1555 if (IN_SET(m
->state
, MOUNT_REMOUNTING
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_REMOUNTING_SIGTERM
))
1556 mount_set_reload_result(m
, f
);
1557 else if (m
->result
== MOUNT_SUCCESS
)
1560 if (m
->control_command
) {
1561 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1563 m
->control_command
= NULL
;
1564 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1567 unit_log_process_exit(
1570 mount_exec_command_to_string(m
->control_command_id
),
1574 /* Note that due to the io event priority logic, we can be sure the new mountinfo is loaded
1575 * before we process the SIGCHLD for the mount command. */
1579 case MOUNT_MOUNTING
:
1580 /* Our mount point has not appeared in mountinfo. Something went wrong. */
1582 if (f
== MOUNT_SUCCESS
) {
1583 /* Either /bin/mount has an unexpected definition of success,
1584 * or someone raced us and we lost. */
1585 log_unit_warning(UNIT(m
), "Mount process finished, but there is no mount.");
1586 f
= MOUNT_FAILURE_PROTOCOL
;
1588 mount_enter_dead(m
, f
);
1591 case MOUNT_MOUNTING_DONE
:
1592 mount_enter_mounted(m
, f
);
1595 case MOUNT_REMOUNTING
:
1596 case MOUNT_REMOUNTING_SIGTERM
:
1597 case MOUNT_REMOUNTING_SIGKILL
:
1598 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1601 case MOUNT_UNMOUNTING
:
1603 if (f
== MOUNT_SUCCESS
&& m
->from_proc_self_mountinfo
) {
1605 /* Still a mount point? If so, let's try again. Most likely there were multiple mount points
1606 * stacked on top of each other. We might exceed the timeout specified by the user overall,
1607 * but we will stop as soon as any one umount times out. */
1609 if (m
->n_retry_umount
< RETRY_UMOUNT_MAX
) {
1610 log_unit_debug(u
, "Mount still present, trying again.");
1611 m
->n_retry_umount
++;
1612 mount_enter_unmounting(m
);
1614 log_unit_warning(u
, "Mount still present after %u attempts to unmount, giving up.", m
->n_retry_umount
);
1615 mount_enter_mounted(m
, f
);
1618 mount_enter_dead_or_mounted(m
, f
);
1622 case MOUNT_UNMOUNTING_SIGKILL
:
1623 case MOUNT_UNMOUNTING_SIGTERM
:
1624 mount_enter_dead_or_mounted(m
, f
);
1627 case MOUNT_CLEANING
:
1628 if (m
->clean_result
== MOUNT_SUCCESS
)
1629 m
->clean_result
= f
;
1631 mount_enter_dead(m
, MOUNT_SUCCESS
);
1635 assert_not_reached();
1638 /* Notify clients about changed exit status */
1639 unit_add_to_dbus_queue(u
);
1642 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1643 Mount
*m
= MOUNT(userdata
);
1646 assert(m
->timer_event_source
== source
);
1650 case MOUNT_MOUNTING
:
1651 case MOUNT_MOUNTING_DONE
:
1652 log_unit_warning(UNIT(m
), "Mounting timed out. Terminating.");
1653 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1656 case MOUNT_REMOUNTING
:
1657 log_unit_warning(UNIT(m
), "Remounting timed out. Terminating remount process.");
1658 mount_set_reload_result(m
, MOUNT_FAILURE_TIMEOUT
);
1659 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGTERM
, MOUNT_SUCCESS
);
1662 case MOUNT_REMOUNTING_SIGTERM
:
1663 mount_set_reload_result(m
, MOUNT_FAILURE_TIMEOUT
);
1665 if (m
->kill_context
.send_sigkill
) {
1666 log_unit_warning(UNIT(m
), "Remounting timed out. Killing.");
1667 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
1669 log_unit_warning(UNIT(m
), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1670 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1674 case MOUNT_REMOUNTING_SIGKILL
:
1675 mount_set_reload_result(m
, MOUNT_FAILURE_TIMEOUT
);
1677 log_unit_warning(UNIT(m
), "Mount process still around after SIGKILL. Ignoring.");
1678 mount_enter_dead_or_mounted(m
, MOUNT_SUCCESS
);
1681 case MOUNT_UNMOUNTING
:
1682 log_unit_warning(UNIT(m
), "Unmounting timed out. Terminating.");
1683 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1686 case MOUNT_UNMOUNTING_SIGTERM
:
1687 if (m
->kill_context
.send_sigkill
) {
1688 log_unit_warning(UNIT(m
), "Mount process timed out. Killing.");
1689 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1691 log_unit_warning(UNIT(m
), "Mount process timed out. Skipping SIGKILL. Ignoring.");
1692 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1696 case MOUNT_UNMOUNTING_SIGKILL
:
1697 log_unit_warning(UNIT(m
), "Mount process still around after SIGKILL. Ignoring.");
1698 mount_enter_dead_or_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1701 case MOUNT_CLEANING
:
1702 log_unit_warning(UNIT(m
), "Cleaning timed out. killing.");
1704 if (m
->clean_result
== MOUNT_SUCCESS
)
1705 m
->clean_result
= MOUNT_FAILURE_TIMEOUT
;
1707 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, 0);
1711 assert_not_reached();
1717 static int mount_setup_new_unit(
1722 const char *options
,
1724 MountProcFlags
*ret_flags
,
1727 _cleanup_(unit_freep
) Unit
*u
= NULL
;
1735 r
= unit_new_for_name(m
, sizeof(Mount
), name
, &u
);
1739 r
= free_and_strdup(&u
->source_path
, "/proc/self/mountinfo");
1743 r
= free_and_strdup(&MOUNT(u
)->where
, where
);
1747 r
= update_parameters_proc_self_mountinfo(MOUNT(u
), what
, options
, fstype
);
1751 /* This unit was generated because /proc/self/mountinfo reported it. Remember this, so that by the
1752 * time we load the unit file for it (and thus add in extra deps right after) we know what source to
1753 * attributes the deps to. */
1754 MOUNT(u
)->from_proc_self_mountinfo
= true;
1756 r
= mount_add_non_exec_dependencies(MOUNT(u
));
1760 /* We have only allocated the stub now, let's enqueue this unit for loading now, so that everything
1761 * else is loaded in now. */
1762 unit_add_to_load_queue(u
);
1764 *ret_flags
= MOUNT_PROC_IS_MOUNTED
| MOUNT_PROC_JUST_MOUNTED
| MOUNT_PROC_JUST_CHANGED
;
1769 static int mount_setup_existing_unit(
1773 const char *options
,
1775 MountProcFlags
*ret_flags
) {
1782 if (!MOUNT(u
)->where
) {
1783 MOUNT(u
)->where
= strdup(where
);
1784 if (!MOUNT(u
)->where
)
1788 /* In case we have multiple mounts established on the same mount point, let's merge flags set already
1789 * for the current unit. Note that the flags field is reset on each iteration of reading
1790 * /proc/self/mountinfo, hence we know for sure anything already set here is from the current
1791 * iteration and thus worthy of taking into account. */
1792 MountProcFlags flags
=
1793 MOUNT(u
)->proc_flags
| MOUNT_PROC_IS_MOUNTED
;
1795 r
= update_parameters_proc_self_mountinfo(MOUNT(u
), what
, options
, fstype
);
1799 flags
|= MOUNT_PROC_JUST_CHANGED
;
1801 /* There are two conditions when we consider a mount point just mounted: when we haven't seen it in
1802 * /proc/self/mountinfo before or when MOUNT_MOUNTING is our current state. Why bother with the
1803 * latter? Shouldn't that be covered by the former? No, during reload it is not because we might then
1804 * encounter a new /proc/self/mountinfo in combination with an old mount unit state (since it stems
1805 * from the serialized state), and need to catch up. Since we know that the MOUNT_MOUNTING state is
1806 * reached when we wait for the mount to appear we hence can assume that if we are in it, we are
1807 * actually seeing it established for the first time. */
1808 if (!MOUNT(u
)->from_proc_self_mountinfo
|| MOUNT(u
)->state
== MOUNT_MOUNTING
)
1809 flags
|= MOUNT_PROC_JUST_MOUNTED
;
1811 MOUNT(u
)->from_proc_self_mountinfo
= true;
1813 if (IN_SET(u
->load_state
, UNIT_NOT_FOUND
, UNIT_BAD_SETTING
, UNIT_ERROR
)) {
1814 /* The unit was previously not found or otherwise not loaded. Now that the unit shows up in
1815 * /proc/self/mountinfo we should reconsider it this, hence set it to UNIT_LOADED. */
1816 u
->load_state
= UNIT_LOADED
;
1819 flags
|= MOUNT_PROC_JUST_CHANGED
;
1822 if (FLAGS_SET(flags
, MOUNT_PROC_JUST_CHANGED
)) {
1823 /* If things changed, then make sure that all deps are regenerated. Let's
1824 * first remove all automatic deps, and then add in the new ones. */
1825 r
= mount_add_non_exec_dependencies(MOUNT(u
));
1834 static int mount_setup_unit(
1838 const char *options
,
1842 _cleanup_free_
char *e
= NULL
;
1843 MountProcFlags flags
;
1853 /* Ignore API mount points. They should never be referenced in
1854 * dependencies ever. */
1855 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1858 if (streq(fstype
, "autofs"))
1861 /* probably some kind of swap, ignore */
1862 if (!is_path(where
))
1865 r
= unit_name_from_path(where
, ".mount", &e
);
1867 return log_struct_errno(
1869 "MESSAGE_ID=" SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE_STR
,
1870 "MOUNT_POINT=%s", where
,
1871 LOG_MESSAGE("Failed to generate valid unit name from mount point path '%s', ignoring mount point: %m",
1874 u
= manager_get_unit(m
, e
);
1876 r
= mount_setup_existing_unit(u
, what
, where
, options
, fstype
, &flags
);
1878 /* First time we see this mount point meaning that it's not been initiated by a mount unit
1879 * but rather by the sysadmin having called mount(8) directly. */
1880 r
= mount_setup_new_unit(m
, e
, what
, where
, options
, fstype
, &flags
, &u
);
1882 return log_warning_errno(r
, "Failed to set up mount unit for '%s': %m", where
);
1884 /* If the mount changed properties or state, let's notify our clients */
1885 if (flags
& (MOUNT_PROC_JUST_CHANGED
|MOUNT_PROC_JUST_MOUNTED
))
1886 unit_add_to_dbus_queue(u
);
1889 MOUNT(u
)->proc_flags
= flags
;
1894 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1895 _cleanup_(mnt_free_tablep
) struct libmnt_table
*table
= NULL
;
1896 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*iter
= NULL
;
1901 r
= libmount_parse(NULL
, NULL
, &table
, &iter
);
1903 return log_error_errno(r
, "Failed to parse /proc/self/mountinfo: %m");
1906 struct libmnt_fs
*fs
;
1907 const char *device
, *path
, *options
, *fstype
;
1909 r
= mnt_table_next_fs(table
, iter
, &fs
);
1913 return log_error_errno(r
, "Failed to get next entry from /proc/self/mountinfo: %m");
1915 device
= mnt_fs_get_source(fs
);
1916 path
= mnt_fs_get_target(fs
);
1917 options
= mnt_fs_get_options(fs
);
1918 fstype
= mnt_fs_get_fstype(fs
);
1920 if (!device
|| !path
)
1923 device_found_node(m
, device
, DEVICE_FOUND_MOUNT
, DEVICE_FOUND_MOUNT
);
1925 (void) mount_setup_unit(m
, device
, path
, options
, fstype
, set_flags
);
1931 static void mount_shutdown(Manager
*m
) {
1934 m
->mount_event_source
= sd_event_source_disable_unref(m
->mount_event_source
);
1936 mnt_unref_monitor(m
->mount_monitor
);
1937 m
->mount_monitor
= NULL
;
1940 static int mount_get_timeout(Unit
*u
, usec_t
*timeout
) {
1941 Mount
*m
= MOUNT(u
);
1948 if (!m
->timer_event_source
)
1951 r
= sd_event_source_get_time(m
->timer_event_source
, &t
);
1954 if (t
== USEC_INFINITY
)
1961 static void mount_enumerate_perpetual(Manager
*m
) {
1967 /* Whatever happens, we know for sure that the root directory is around, and cannot go away. Let's
1968 * unconditionally synthesize it here and mark it as perpetual. */
1970 u
= manager_get_unit(m
, SPECIAL_ROOT_MOUNT
);
1972 r
= unit_new_for_name(m
, sizeof(Mount
), SPECIAL_ROOT_MOUNT
, &u
);
1974 log_error_errno(r
, "Failed to allocate the special " SPECIAL_ROOT_MOUNT
" unit: %m");
1979 u
->perpetual
= true;
1980 MOUNT(u
)->deserialized_state
= MOUNT_MOUNTED
;
1982 unit_add_to_load_queue(u
);
1983 unit_add_to_dbus_queue(u
);
1986 static bool mount_is_mounted(Mount
*m
) {
1989 return UNIT(m
)->perpetual
|| FLAGS_SET(m
->proc_flags
, MOUNT_PROC_IS_MOUNTED
);
1992 static int mount_on_ratelimit_expire(sd_event_source
*s
, void *userdata
) {
1993 Manager
*m
= ASSERT_PTR(userdata
);
1996 /* Let's enqueue all start jobs that were previously skipped because of active ratelimit. */
1997 HASHMAP_FOREACH(j
, m
->jobs
) {
1998 if (j
->unit
->type
!= UNIT_MOUNT
)
2001 job_add_to_run_queue(j
);
2004 /* By entering ratelimited state we made all mount start jobs not runnable, now rate limit is over so
2005 * let's make sure we dispatch them in the next iteration. */
2006 manager_trigger_run_queue(m
);
2011 static void mount_enumerate(Manager
*m
) {
2018 if (!m
->mount_monitor
) {
2019 unsigned mount_rate_limit_burst
= 5;
2022 m
->mount_monitor
= mnt_new_monitor();
2023 if (!m
->mount_monitor
) {
2028 r
= mnt_monitor_enable_kernel(m
->mount_monitor
, 1);
2030 log_error_errno(r
, "Failed to enable watching of kernel mount events: %m");
2034 r
= mnt_monitor_enable_userspace(m
->mount_monitor
, 1, NULL
);
2036 log_error_errno(r
, "Failed to enable watching of userspace mount events: %m");
2040 /* mnt_unref_monitor() will close the fd */
2041 fd
= r
= mnt_monitor_get_fd(m
->mount_monitor
);
2043 log_error_errno(r
, "Failed to acquire watch file descriptor: %m");
2047 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fd
, EPOLLIN
, mount_dispatch_io
, m
);
2049 log_error_errno(r
, "Failed to watch mount file descriptor: %m");
2053 r
= sd_event_source_set_priority(m
->mount_event_source
, SD_EVENT_PRIORITY_NORMAL
-10);
2055 log_error_errno(r
, "Failed to adjust mount watch priority: %m");
2059 /* Let users override the default (5 in 1s), as it stalls the boot sequence on busy systems. */
2060 const char *e
= secure_getenv("SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST");
2062 r
= safe_atou(e
, &mount_rate_limit_burst
);
2064 log_debug("Invalid value in $SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST, ignoring: %s", e
);
2067 r
= sd_event_source_set_ratelimit(m
->mount_event_source
, 1 * USEC_PER_SEC
, mount_rate_limit_burst
);
2069 log_error_errno(r
, "Failed to enable rate limit for mount events: %m");
2073 r
= sd_event_source_set_ratelimit_expire_callback(m
->mount_event_source
, mount_on_ratelimit_expire
);
2075 log_error_errno(r
, "Failed to enable rate limit for mount events: %m");
2079 (void) sd_event_source_set_description(m
->mount_event_source
, "mount-monitor-dispatch");
2082 r
= mount_load_proc_self_mountinfo(m
, false);
2092 static int drain_libmount(Manager
*m
) {
2093 bool rescan
= false;
2098 /* Drain all events and verify that the event is valid.
2100 * Note that libmount also monitors /run/mount mkdir if the directory does not exist yet. The mkdir
2101 * may generate event which is irrelevant for us.
2103 * error: r < 0; valid: r == 0, false positive: r == 1 */
2105 r
= mnt_monitor_next_change(m
->mount_monitor
, NULL
, NULL
);
2107 return log_error_errno(r
, "Failed to drain libmount events: %m");
2115 static int mount_process_proc_self_mountinfo(Manager
*m
) {
2116 _cleanup_set_free_ Set
*around
= NULL
, *gone
= NULL
;
2122 r
= drain_libmount(m
);
2126 r
= mount_load_proc_self_mountinfo(m
, true);
2128 /* Reset flags, just in case, for later calls */
2129 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
])
2130 MOUNT(u
)->proc_flags
= 0;
2135 manager_dispatch_load_queue(m
);
2137 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
2138 Mount
*mount
= MOUNT(u
);
2140 mount
->invalidated_state
= false;
2142 if (!mount_is_mounted(mount
)) {
2144 /* A mount point is not around right now. It might be gone, or might never have
2147 if (mount
->from_proc_self_mountinfo
&&
2148 mount
->parameters_proc_self_mountinfo
.what
)
2149 /* Remember that this device might just have disappeared */
2150 if (set_put_strdup_full(&gone
, &path_hash_ops_free
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
2151 log_oom(); /* we don't care too much about OOM here... */
2153 mount
->from_proc_self_mountinfo
= false;
2154 assert_se(update_parameters_proc_self_mountinfo(mount
, NULL
, NULL
, NULL
) >= 0);
2156 switch (mount
->state
) {
2159 /* This has just been unmounted by somebody else, follow the state change. */
2160 mount_enter_dead(mount
, MOUNT_SUCCESS
);
2163 case MOUNT_MOUNTING_DONE
:
2164 /* The mount command may add the corresponding proc mountinfo entry and
2165 * then remove it because of an internal error. E.g., fuse.sshfs seems
2166 * to do that when the connection fails. See #17617. To handle such the
2167 * case, let's once set the state back to mounting. Then, the unit can
2168 * correctly enter the failed state later in mount_sigchld(). */
2169 mount_set_state(mount
, MOUNT_MOUNTING
);
2176 } else if (mount
->proc_flags
& (MOUNT_PROC_JUST_MOUNTED
|MOUNT_PROC_JUST_CHANGED
)) {
2178 /* A mount point was added or changed */
2180 switch (mount
->state
) {
2185 /* This has just been mounted by somebody else, follow the state change, but let's
2186 * generate a new invocation ID for this implicitly and automatically. */
2187 (void) unit_acquire_invocation_id(u
);
2188 mount_cycle_clear(mount
);
2189 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
2192 case MOUNT_MOUNTING
:
2193 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
2197 /* Nothing really changed, but let's issue an notification call nonetheless,
2198 * in case somebody is waiting for this. (e.g. file system ro/rw
2200 mount_set_state(mount
, mount
->state
);
2205 if (mount_is_mounted(mount
) &&
2206 mount
->from_proc_self_mountinfo
&&
2207 mount
->parameters_proc_self_mountinfo
.what
)
2208 /* Track devices currently used */
2209 if (set_put_strdup_full(&around
, &path_hash_ops_free
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
2212 /* Reset the flags for later calls */
2213 mount
->proc_flags
= 0;
2216 SET_FOREACH(what
, gone
) {
2217 if (set_contains(around
, what
))
2220 /* Let the device units know that the device is no longer mounted */
2221 device_found_node(m
, what
, DEVICE_NOT_FOUND
, DEVICE_FOUND_MOUNT
);
2227 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
2228 Manager
*m
= ASSERT_PTR(userdata
);
2230 assert(revents
& EPOLLIN
);
2232 return mount_process_proc_self_mountinfo(m
);
2235 int mount_invalidate_state_by_path(Manager
*manager
, const char *path
) {
2236 _cleanup_free_
char *name
= NULL
;
2243 r
= unit_name_from_path(path
, ".mount", &name
);
2245 return log_debug_errno(r
, "Failed to generate unit name from path \"%s\", ignoring: %m", path
);
2247 u
= manager_get_unit(manager
, name
);
2251 MOUNT(u
)->invalidated_state
= true;
2255 static void mount_reset_failed(Unit
*u
) {
2256 Mount
*m
= MOUNT(u
);
2260 if (m
->state
== MOUNT_FAILED
)
2261 mount_set_state(m
, MOUNT_DEAD
);
2263 m
->result
= MOUNT_SUCCESS
;
2264 m
->reload_result
= MOUNT_SUCCESS
;
2265 m
->clean_result
= MOUNT_SUCCESS
;
2268 static PidRef
* mount_control_pid(Unit
*u
) {
2269 return &ASSERT_PTR(MOUNT(u
))->control_pid
;
2272 static int mount_clean(Unit
*u
, ExecCleanMask mask
) {
2273 _cleanup_strv_free_
char **l
= NULL
;
2274 Mount
*m
= MOUNT(u
);
2280 if (m
->state
!= MOUNT_DEAD
)
2283 r
= exec_context_get_clean_directories(&m
->exec_context
, u
->manager
->prefix
, mask
, &l
);
2287 if (strv_isempty(l
))
2290 mount_unwatch_control_pid(m
);
2291 m
->clean_result
= MOUNT_SUCCESS
;
2292 m
->control_command
= NULL
;
2293 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
2295 r
= mount_arm_timer(m
, /* relative= */ true, m
->exec_context
.timeout_clean_usec
);
2297 log_unit_warning_errno(u
, r
, "Failed to install timer: %m");
2301 r
= unit_fork_and_watch_rm_rf(u
, l
, &m
->control_pid
);
2303 log_unit_warning_errno(u
, r
, "Failed to spawn cleaning task: %m");
2307 mount_set_state(m
, MOUNT_CLEANING
);
2311 m
->clean_result
= MOUNT_FAILURE_RESOURCES
;
2312 m
->timer_event_source
= sd_event_source_disable_unref(m
->timer_event_source
);
2316 static int mount_can_clean(Unit
*u
, ExecCleanMask
*ret
) {
2317 Mount
*m
= MOUNT(u
);
2321 return exec_context_get_clean_mask(&m
->exec_context
, ret
);
2324 static int mount_can_start(Unit
*u
) {
2325 Mount
*m
= MOUNT(u
);
2330 r
= unit_test_start_limit(u
);
2332 mount_enter_dead(m
, MOUNT_FAILURE_START_LIMIT_HIT
);
2339 static int mount_subsystem_ratelimited(Manager
*m
) {
2342 if (!m
->mount_event_source
)
2345 return sd_event_source_is_ratelimited(m
->mount_event_source
);
2348 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
2349 [MOUNT_EXEC_MOUNT
] = "ExecMount",
2350 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
2351 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
2354 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
2356 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
2357 [MOUNT_SUCCESS
] = "success",
2358 [MOUNT_FAILURE_RESOURCES
] = "resources",
2359 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
2360 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
2361 [MOUNT_FAILURE_SIGNAL
] = "signal",
2362 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump",
2363 [MOUNT_FAILURE_START_LIMIT_HIT
] = "start-limit-hit",
2364 [MOUNT_FAILURE_PROTOCOL
] = "protocol",
2367 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
2369 const UnitVTable mount_vtable
= {
2370 .object_size
= sizeof(Mount
),
2371 .exec_context_offset
= offsetof(Mount
, exec_context
),
2372 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
2373 .kill_context_offset
= offsetof(Mount
, kill_context
),
2374 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
2380 .private_section
= "Mount",
2382 .can_transient
= true,
2384 .exclude_from_switch_root_serialization
= true,
2390 .coldplug
= mount_coldplug
,
2391 .catchup
= mount_catchup
,
2395 .start
= mount_start
,
2397 .reload
= mount_reload
,
2399 .clean
= mount_clean
,
2400 .can_clean
= mount_can_clean
,
2402 .serialize
= mount_serialize
,
2403 .deserialize_item
= mount_deserialize_item
,
2405 .active_state
= mount_active_state
,
2406 .sub_state_to_string
= mount_sub_state_to_string
,
2408 .will_restart
= unit_will_restart_default
,
2410 .may_gc
= mount_may_gc
,
2411 .is_extrinsic
= mount_is_extrinsic
,
2413 .sigchld_event
= mount_sigchld_event
,
2415 .reset_failed
= mount_reset_failed
,
2417 .control_pid
= mount_control_pid
,
2419 .bus_set_property
= bus_mount_set_property
,
2420 .bus_commit_properties
= bus_mount_commit_properties
,
2422 .get_timeout
= mount_get_timeout
,
2424 .enumerate_perpetual
= mount_enumerate_perpetual
,
2425 .enumerate
= mount_enumerate
,
2426 .shutdown
= mount_shutdown
,
2427 .subsystem_ratelimited
= mount_subsystem_ratelimited
,
2429 .status_message_formats
= {
2430 .starting_stopping
= {
2431 [0] = "Mounting %s...",
2432 [1] = "Unmounting %s...",
2434 .finished_start_job
= {
2435 [JOB_DONE
] = "Mounted %s.",
2436 [JOB_FAILED
] = "Failed to mount %s.",
2437 [JOB_TIMEOUT
] = "Timed out mounting %s.",
2439 .finished_stop_job
= {
2440 [JOB_DONE
] = "Unmounted %s.",
2441 [JOB_FAILED
] = "Failed unmounting %s.",
2442 [JOB_TIMEOUT
] = "Timed out unmounting %s.",
2446 .can_start
= mount_can_start
,
2448 .notify_plymouth
= true,