2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/epoll.h>
25 #include "sd-messages.h"
27 #include "alloc-util.h"
28 #include "dbus-mount.h"
30 #include "exit-status.h"
31 #include "formats-util.h"
32 #include "fstab-util.h"
36 #include "mount-setup.h"
37 #include "mount-util.h"
39 #include "parse-util.h"
40 #include "path-util.h"
41 #include "process-util.h"
43 #include "string-table.h"
44 #include "string-util.h"
46 #include "unit-name.h"
49 #define RETRY_UMOUNT_MAX 32
51 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table
*, mnt_free_table
);
52 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter
*, mnt_free_iter
);
54 static const UnitActiveState state_translation_table
[_MOUNT_STATE_MAX
] = {
55 [MOUNT_DEAD
] = UNIT_INACTIVE
,
56 [MOUNT_MOUNTING
] = UNIT_ACTIVATING
,
57 [MOUNT_MOUNTING_DONE
] = UNIT_ACTIVE
,
58 [MOUNT_MOUNTED
] = UNIT_ACTIVE
,
59 [MOUNT_REMOUNTING
] = UNIT_RELOADING
,
60 [MOUNT_UNMOUNTING
] = UNIT_DEACTIVATING
,
61 [MOUNT_MOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
62 [MOUNT_MOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
63 [MOUNT_REMOUNTING_SIGTERM
] = UNIT_RELOADING
,
64 [MOUNT_REMOUNTING_SIGKILL
] = UNIT_RELOADING
,
65 [MOUNT_UNMOUNTING_SIGTERM
] = UNIT_DEACTIVATING
,
66 [MOUNT_UNMOUNTING_SIGKILL
] = UNIT_DEACTIVATING
,
67 [MOUNT_FAILED
] = UNIT_FAILED
70 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
71 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
73 static bool mount_needs_network(const char *options
, const char *fstype
) {
74 if (fstab_test_option(options
, "_netdev\0"))
77 if (fstype
&& fstype_is_network(fstype
))
83 static bool mount_is_network(const MountParameters
*p
) {
86 return mount_needs_network(p
->options
, p
->fstype
);
89 static bool mount_is_loop(const MountParameters
*p
) {
92 if (fstab_test_option(p
->options
, "loop\0"))
98 static bool mount_is_bind(const MountParameters
*p
) {
101 if (fstab_test_option(p
->options
, "bind\0" "rbind\0"))
104 if (p
->fstype
&& STR_IN_SET(p
->fstype
, "bind", "rbind"))
110 static bool mount_is_auto(const MountParameters
*p
) {
113 return !fstab_test_option(p
->options
, "noauto\0");
116 static bool mount_is_automount(const MountParameters
*p
) {
119 return fstab_test_option(p
->options
,
120 "comment=systemd.automount\0"
121 "x-systemd.automount\0");
124 static bool mount_state_active(MountState state
) {
130 MOUNT_MOUNTING_SIGTERM
,
131 MOUNT_MOUNTING_SIGKILL
,
132 MOUNT_UNMOUNTING_SIGTERM
,
133 MOUNT_UNMOUNTING_SIGKILL
,
134 MOUNT_REMOUNTING_SIGTERM
,
135 MOUNT_REMOUNTING_SIGKILL
);
138 static bool needs_quota(const MountParameters
*p
) {
141 /* Quotas are not enabled on network filesystems,
142 * but we want them, for example, on storage connected via iscsi */
143 if (p
->fstype
&& fstype_is_network(p
->fstype
))
146 if (mount_is_bind(p
))
149 return fstab_test_option(p
->options
,
150 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
153 static void mount_init(Unit
*u
) {
157 assert(u
->load_state
== UNIT_STUB
);
159 m
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
160 m
->directory_mode
= 0755;
162 if (unit_has_name(u
, "-.mount")) {
163 /* Don't allow start/stop for root directory */
164 u
->refuse_manual_start
= true;
165 u
->refuse_manual_stop
= true;
167 /* The stdio/kmsg bridge socket is on /, in order to avoid a
168 * dep loop, don't use kmsg logging for -.mount */
169 m
->exec_context
.std_output
= u
->manager
->default_std_output
;
170 m
->exec_context
.std_error
= u
->manager
->default_std_error
;
173 /* We need to make sure that /usr/bin/mount is always called
174 * in the same process group as us, so that the autofs kernel
175 * side doesn't send us another mount request while we are
176 * already trying to comply its last one. */
177 m
->exec_context
.same_pgrp
= true;
179 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
181 u
->ignore_on_isolate
= true;
184 static int mount_arm_timer(Mount
*m
, usec_t usec
) {
189 if (m
->timer_event_source
) {
190 r
= sd_event_source_set_time(m
->timer_event_source
, usec
);
194 return sd_event_source_set_enabled(m
->timer_event_source
, SD_EVENT_ONESHOT
);
197 if (usec
== USEC_INFINITY
)
200 r
= sd_event_add_time(
201 UNIT(m
)->manager
->event
,
202 &m
->timer_event_source
,
205 mount_dispatch_timer
, m
);
209 (void) sd_event_source_set_description(m
->timer_event_source
, "mount-timer");
214 static void mount_unwatch_control_pid(Mount
*m
) {
217 if (m
->control_pid
<= 0)
220 unit_unwatch_pid(UNIT(m
), m
->control_pid
);
224 static void mount_parameters_done(MountParameters
*p
) {
231 p
->what
= p
->options
= p
->fstype
= NULL
;
234 static void mount_done(Unit
*u
) {
239 m
->where
= mfree(m
->where
);
241 mount_parameters_done(&m
->parameters_proc_self_mountinfo
);
242 mount_parameters_done(&m
->parameters_fragment
);
244 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
245 exec_command_done_array(m
->exec_command
, _MOUNT_EXEC_COMMAND_MAX
);
246 m
->control_command
= NULL
;
248 dynamic_creds_unref(&m
->dynamic_creds
);
250 mount_unwatch_control_pid(m
);
252 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
255 _pure_
static MountParameters
* get_mount_parameters_fragment(Mount
*m
) {
258 if (m
->from_fragment
)
259 return &m
->parameters_fragment
;
264 _pure_
static MountParameters
* get_mount_parameters(Mount
*m
) {
267 if (m
->from_proc_self_mountinfo
)
268 return &m
->parameters_proc_self_mountinfo
;
270 return get_mount_parameters_fragment(m
);
273 static int mount_add_mount_links(Mount
*m
) {
274 _cleanup_free_
char *parent
= NULL
;
283 if (!path_equal(m
->where
, "/")) {
284 /* Adds in links to other mount points that might lie further
285 * up in the hierarchy */
287 parent
= dirname_malloc(m
->where
);
291 r
= unit_require_mounts_for(UNIT(m
), parent
);
296 /* Adds in links to other mount points that might be needed
297 * for the source path (if this is a bind mount or a loop mount) to be
299 pm
= get_mount_parameters_fragment(m
);
300 if (pm
&& pm
->what
&&
301 path_is_absolute(pm
->what
) &&
302 (mount_is_bind(pm
) || mount_is_loop(pm
) || !mount_is_network(pm
))) {
304 r
= unit_require_mounts_for(UNIT(m
), pm
->what
);
309 /* Adds in links to other units that use this path or paths
310 * further down in the hierarchy */
311 s
= manager_get_units_requiring_mounts_for(UNIT(m
)->manager
, m
->where
);
312 SET_FOREACH(other
, s
, i
) {
314 if (other
->load_state
!= UNIT_LOADED
)
317 if (other
== UNIT(m
))
320 r
= unit_add_dependency(other
, UNIT_AFTER
, UNIT(m
), true);
324 if (UNIT(m
)->fragment_path
) {
325 /* If we have fragment configuration, then make this dependency required */
326 r
= unit_add_dependency(other
, UNIT_REQUIRES
, UNIT(m
), true);
335 static int mount_add_device_links(Mount
*m
) {
337 bool device_wants_mount
= false;
342 p
= get_mount_parameters(m
);
349 if (mount_is_bind(p
))
352 if (!is_device_path(p
->what
))
355 /* /dev/root is a really weird thing, it's not a real device,
356 * but just a path the kernel exports for the root file system
357 * specified on the kernel command line. Ignore it here. */
358 if (path_equal(p
->what
, "/dev/root"))
361 if (path_equal(m
->where
, "/"))
364 if (mount_is_auto(p
) && !mount_is_automount(p
) && MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
365 device_wants_mount
= true;
367 r
= unit_add_node_link(UNIT(m
), p
->what
, device_wants_mount
, m
->from_fragment
? UNIT_BINDS_TO
: UNIT_REQUIRES
);
374 static int mount_add_quota_links(Mount
*m
) {
380 if (!MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
383 p
= get_mount_parameters_fragment(m
);
390 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTACHECK_SERVICE
, NULL
, true);
394 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_WANTS
, SPECIAL_QUOTAON_SERVICE
, NULL
, true);
401 static bool should_umount(Mount
*m
) {
404 if (PATH_IN_SET(m
->where
, "/", "/usr") ||
405 path_startswith(m
->where
, "/run/initramfs"))
408 p
= get_mount_parameters(m
);
409 if (p
&& fstab_test_option(p
->options
, "x-initrd.mount\0") &&
416 static int mount_add_default_dependencies(Mount
*m
) {
423 if (!UNIT(m
)->default_dependencies
)
426 if (!MANAGER_IS_SYSTEM(UNIT(m
)->manager
))
429 /* We do not add any default dependencies to /, /usr or
430 * /run/initramfs/, since they are guaranteed to stay
431 * mounted the whole time, since our system is on it.
432 * Also, don't bother with anything mounted below virtual
433 * file systems, it's also going to be virtual, and hence
434 * not worth the effort. */
435 if (PATH_IN_SET(m
->where
, "/", "/usr") ||
436 path_startswith(m
->where
, "/run/initramfs") ||
437 path_startswith(m
->where
, "/proc") ||
438 path_startswith(m
->where
, "/sys") ||
439 path_startswith(m
->where
, "/dev"))
442 p
= get_mount_parameters(m
);
446 if (mount_is_network(p
)) {
447 /* We order ourselves after network.target. This is
448 * primarily useful at shutdown: services that take
449 * down the network should order themselves before
450 * network.target, so that they are shut down only
451 * after this mount unit is stopped. */
453 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, SPECIAL_NETWORK_TARGET
, NULL
, true);
457 /* We pull in network-online.target, and order
458 * ourselves after it. This is useful at start-up to
459 * actively pull in tools that want to be started
460 * before we start mounting network file systems, and
461 * whose purpose it is to delay this until the network
464 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_WANTS
, UNIT_AFTER
, SPECIAL_NETWORK_ONLINE_TARGET
, NULL
, true);
468 after
= SPECIAL_REMOTE_FS_PRE_TARGET
;
470 after
= SPECIAL_LOCAL_FS_PRE_TARGET
;
472 r
= unit_add_dependency_by_name(UNIT(m
), UNIT_AFTER
, after
, NULL
, true);
476 if (should_umount(m
)) {
477 r
= unit_add_two_dependencies_by_name(UNIT(m
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
485 static int mount_verify(Mount
*m
) {
486 _cleanup_free_
char *e
= NULL
;
492 if (UNIT(m
)->load_state
!= UNIT_LOADED
)
495 if (!m
->from_fragment
&& !m
->from_proc_self_mountinfo
)
498 r
= unit_name_from_path(m
->where
, ".mount", &e
);
500 return log_unit_error_errno(UNIT(m
), r
, "Failed to generate unit name from mount path: %m");
502 if (!unit_has_name(UNIT(m
), e
)) {
503 log_unit_error(UNIT(m
), "Where= setting doesn't match unit name. Refusing.");
507 if (mount_point_is_api(m
->where
) || mount_point_ignore(m
->where
)) {
508 log_unit_error(UNIT(m
), "Cannot create mount unit for API file system %s. Refusing.", m
->where
);
512 p
= get_mount_parameters_fragment(m
);
514 log_unit_error(UNIT(m
), "What= setting is missing. Refusing.");
518 if (m
->exec_context
.pam_name
&& m
->kill_context
.kill_mode
!= KILL_CONTROL_GROUP
) {
519 log_unit_error(UNIT(m
), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
526 static int mount_add_extras(Mount
*m
) {
532 if (u
->fragment_path
)
533 m
->from_fragment
= true;
536 r
= unit_name_to_path(u
->id
, &m
->where
);
541 path_kill_slashes(m
->where
);
543 if (!u
->description
) {
544 r
= unit_set_description(u
, m
->where
);
549 r
= mount_add_device_links(m
);
553 r
= mount_add_mount_links(m
);
557 r
= mount_add_quota_links(m
);
561 r
= unit_patch_contexts(u
);
565 r
= unit_add_exec_dependencies(u
, &m
->exec_context
);
569 r
= unit_set_default_slice(u
);
573 r
= mount_add_default_dependencies(m
);
580 static int mount_load(Unit
*u
) {
585 assert(u
->load_state
== UNIT_STUB
);
587 if (m
->from_proc_self_mountinfo
)
588 r
= unit_load_fragment_and_dropin_optional(u
);
590 r
= unit_load_fragment_and_dropin(u
);
595 /* This is a new unit? Then let's add in some extras */
596 if (u
->load_state
== UNIT_LOADED
) {
597 r
= mount_add_extras(m
);
602 return mount_verify(m
);
605 static void mount_set_state(Mount
*m
, MountState state
) {
606 MountState old_state
;
609 old_state
= m
->state
;
612 if (!mount_state_active(state
)) {
613 m
->timer_event_source
= sd_event_source_unref(m
->timer_event_source
);
614 mount_unwatch_control_pid(m
);
615 m
->control_command
= NULL
;
616 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
619 if (state
!= old_state
)
620 log_unit_debug(UNIT(m
), "Changed %s -> %s", mount_state_to_string(old_state
), mount_state_to_string(state
));
622 unit_notify(UNIT(m
), state_translation_table
[old_state
], state_translation_table
[state
], m
->reload_result
== MOUNT_SUCCESS
);
623 m
->reload_result
= MOUNT_SUCCESS
;
626 static int mount_coldplug(Unit
*u
) {
628 MountState new_state
= MOUNT_DEAD
;
632 assert(m
->state
== MOUNT_DEAD
);
634 if (m
->deserialized_state
!= m
->state
)
635 new_state
= m
->deserialized_state
;
636 else if (m
->from_proc_self_mountinfo
)
637 new_state
= MOUNT_MOUNTED
;
639 if (new_state
== m
->state
)
642 if (m
->control_pid
> 0 &&
643 pid_is_unwaited(m
->control_pid
) &&
644 mount_state_active(new_state
)) {
646 r
= unit_watch_pid(UNIT(m
), m
->control_pid
);
650 r
= mount_arm_timer(m
, usec_add(u
->state_change_timestamp
.monotonic
, m
->timeout_usec
));
655 if (!IN_SET(new_state
, MOUNT_DEAD
, MOUNT_FAILED
))
656 (void) unit_setup_dynamic_creds(u
);
658 mount_set_state(m
, new_state
);
662 static void mount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
669 p
= get_mount_parameters(m
);
672 "%sMount State: %s\n"
676 "%sFile System Type: %s\n"
678 "%sFrom /proc/self/mountinfo: %s\n"
679 "%sFrom fragment: %s\n"
680 "%sDirectoryMode: %04o\n"
681 "%sSloppyOptions: %s\n"
682 "%sLazyUnmount: %s\n"
683 "%sForceUnmount: %s\n",
684 prefix
, mount_state_to_string(m
->state
),
685 prefix
, mount_result_to_string(m
->result
),
687 prefix
, p
? strna(p
->what
) : "n/a",
688 prefix
, p
? strna(p
->fstype
) : "n/a",
689 prefix
, p
? strna(p
->options
) : "n/a",
690 prefix
, yes_no(m
->from_proc_self_mountinfo
),
691 prefix
, yes_no(m
->from_fragment
),
692 prefix
, m
->directory_mode
,
693 prefix
, yes_no(m
->sloppy_options
),
694 prefix
, yes_no(m
->lazy_unmount
),
695 prefix
, yes_no(m
->force_unmount
));
697 if (m
->control_pid
> 0)
699 "%sControl PID: "PID_FMT
"\n",
700 prefix
, m
->control_pid
);
702 exec_context_dump(&m
->exec_context
, f
, prefix
);
703 kill_context_dump(&m
->kill_context
, f
, prefix
);
706 static int mount_spawn(Mount
*m
, ExecCommand
*c
, pid_t
*_pid
) {
709 ExecParameters exec_params
= {
710 .flags
= EXEC_APPLY_PERMISSIONS
|EXEC_APPLY_CHROOT
|EXEC_APPLY_TTY_STDIN
,
720 (void) unit_realize_cgroup(UNIT(m
));
721 if (m
->reset_cpu_usage
) {
722 (void) unit_reset_cpu_usage(UNIT(m
));
723 m
->reset_cpu_usage
= false;
726 r
= unit_setup_exec_runtime(UNIT(m
));
730 r
= unit_setup_dynamic_creds(UNIT(m
));
734 r
= mount_arm_timer(m
, usec_add(now(CLOCK_MONOTONIC
), m
->timeout_usec
));
738 exec_params
.environment
= UNIT(m
)->manager
->environment
;
739 exec_params
.flags
|= UNIT(m
)->manager
->confirm_spawn
? EXEC_CONFIRM_SPAWN
: 0;
740 exec_params
.cgroup_supported
= UNIT(m
)->manager
->cgroup_supported
;
741 exec_params
.cgroup_path
= UNIT(m
)->cgroup_path
;
742 exec_params
.cgroup_delegate
= m
->cgroup_context
.delegate
;
743 exec_params
.runtime_prefix
= manager_get_runtime_prefix(UNIT(m
)->manager
);
745 r
= exec_spawn(UNIT(m
),
755 r
= unit_watch_pid(UNIT(m
), pid
);
757 /* FIXME: we need to do something here */
765 static void mount_enter_dead(Mount
*m
, MountResult f
) {
768 if (m
->result
== MOUNT_SUCCESS
)
771 mount_set_state(m
, m
->result
!= MOUNT_SUCCESS
? MOUNT_FAILED
: MOUNT_DEAD
);
773 exec_runtime_destroy(m
->exec_runtime
);
774 m
->exec_runtime
= exec_runtime_unref(m
->exec_runtime
);
776 exec_context_destroy_runtime_directory(&m
->exec_context
, manager_get_runtime_prefix(UNIT(m
)->manager
));
778 unit_unref_uid_gid(UNIT(m
), true);
780 dynamic_creds_destroy(&m
->dynamic_creds
);
783 static void mount_enter_mounted(Mount
*m
, MountResult f
) {
786 if (m
->result
== MOUNT_SUCCESS
)
789 mount_set_state(m
, MOUNT_MOUNTED
);
792 static void mount_enter_signal(Mount
*m
, MountState state
, MountResult f
) {
797 if (m
->result
== MOUNT_SUCCESS
)
800 r
= unit_kill_context(
803 (state
!= MOUNT_MOUNTING_SIGTERM
&& state
!= MOUNT_UNMOUNTING_SIGTERM
&& state
!= MOUNT_REMOUNTING_SIGTERM
) ?
804 KILL_KILL
: KILL_TERMINATE
,
812 r
= mount_arm_timer(m
, usec_add(now(CLOCK_MONOTONIC
), m
->timeout_usec
));
816 mount_set_state(m
, state
);
817 } else if (state
== MOUNT_REMOUNTING_SIGTERM
)
818 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
819 else if (state
== MOUNT_REMOUNTING_SIGKILL
)
820 mount_enter_mounted(m
, MOUNT_SUCCESS
);
821 else if (state
== MOUNT_MOUNTING_SIGTERM
)
822 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_SUCCESS
);
823 else if (state
== MOUNT_UNMOUNTING_SIGTERM
)
824 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_SUCCESS
);
826 mount_enter_dead(m
, MOUNT_SUCCESS
);
831 log_unit_warning_errno(UNIT(m
), r
, "Failed to kill processes: %m");
833 if (state
== MOUNT_REMOUNTING_SIGTERM
|| state
== MOUNT_REMOUNTING_SIGKILL
)
834 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
836 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
839 static void mount_enter_unmounting(Mount
*m
) {
844 /* Start counting our attempts */
845 if (!IN_SET(m
->state
,
847 MOUNT_UNMOUNTING_SIGTERM
,
848 MOUNT_UNMOUNTING_SIGKILL
))
849 m
->n_retry_umount
= 0;
851 m
->control_command_id
= MOUNT_EXEC_UNMOUNT
;
852 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_UNMOUNT
;
854 r
= exec_command_set(m
->control_command
, UMOUNT_PATH
, m
->where
, NULL
);
855 if (r
>= 0 && m
->lazy_unmount
)
856 r
= exec_command_append(m
->control_command
, "-l", NULL
);
857 if (r
>= 0 && m
->force_unmount
)
858 r
= exec_command_append(m
->control_command
, "-f", NULL
);
862 mount_unwatch_control_pid(m
);
864 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
868 mount_set_state(m
, MOUNT_UNMOUNTING
);
873 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'umount' task: %m");
874 mount_enter_mounted(m
, MOUNT_FAILURE_RESOURCES
);
877 static void mount_enter_mounting(Mount
*m
) {
883 m
->control_command_id
= MOUNT_EXEC_MOUNT
;
884 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_MOUNT
;
886 r
= unit_fail_if_symlink(UNIT(m
), m
->where
);
890 (void) mkdir_p_label(m
->where
, m
->directory_mode
);
892 unit_warn_if_dir_nonempty(UNIT(m
), m
->where
);
894 /* Create the source directory for bind-mounts if needed */
895 p
= get_mount_parameters_fragment(m
);
896 if (p
&& mount_is_bind(p
))
897 (void) mkdir_p_label(p
->what
, m
->directory_mode
);
900 _cleanup_free_
char *opts
= NULL
;
902 r
= fstab_filter_options(p
->options
, "nofail\0" "noauto\0" "auto\0", NULL
, NULL
, &opts
);
906 r
= exec_command_set(m
->control_command
, MOUNT_PATH
, p
->what
, m
->where
, NULL
);
907 if (r
>= 0 && m
->sloppy_options
)
908 r
= exec_command_append(m
->control_command
, "-s", NULL
);
909 if (r
>= 0 && p
->fstype
)
910 r
= exec_command_append(m
->control_command
, "-t", p
->fstype
, NULL
);
911 if (r
>= 0 && !isempty(opts
))
912 r
= exec_command_append(m
->control_command
, "-o", opts
, NULL
);
919 mount_unwatch_control_pid(m
);
921 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
925 mount_set_state(m
, MOUNT_MOUNTING
);
930 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'mount' task: %m");
931 mount_enter_dead(m
, MOUNT_FAILURE_RESOURCES
);
934 static void mount_enter_remounting(Mount
*m
) {
940 m
->control_command_id
= MOUNT_EXEC_REMOUNT
;
941 m
->control_command
= m
->exec_command
+ MOUNT_EXEC_REMOUNT
;
943 p
= get_mount_parameters_fragment(m
);
948 o
= strjoina("remount,", p
->options
);
952 r
= exec_command_set(m
->control_command
, MOUNT_PATH
,
955 if (r
>= 0 && m
->sloppy_options
)
956 r
= exec_command_append(m
->control_command
, "-s", NULL
);
957 if (r
>= 0 && p
->fstype
)
958 r
= exec_command_append(m
->control_command
, "-t", p
->fstype
, NULL
);
965 mount_unwatch_control_pid(m
);
967 r
= mount_spawn(m
, m
->control_command
, &m
->control_pid
);
971 mount_set_state(m
, MOUNT_REMOUNTING
);
976 log_unit_warning_errno(UNIT(m
), r
, "Failed to run 'remount' task: %m");
977 m
->reload_result
= MOUNT_FAILURE_RESOURCES
;
978 mount_enter_mounted(m
, MOUNT_SUCCESS
);
981 static int mount_start(Unit
*u
) {
987 /* We cannot fulfill this request right now, try again later
989 if (m
->state
== MOUNT_UNMOUNTING
||
990 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
991 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
992 m
->state
== MOUNT_MOUNTING_SIGTERM
||
993 m
->state
== MOUNT_MOUNTING_SIGKILL
)
997 if (m
->state
== MOUNT_MOUNTING
)
1000 assert(m
->state
== MOUNT_DEAD
|| m
->state
== MOUNT_FAILED
);
1002 r
= unit_start_limit_test(u
);
1004 mount_enter_dead(m
, MOUNT_FAILURE_START_LIMIT_HIT
);
1008 r
= unit_acquire_invocation_id(u
);
1012 m
->result
= MOUNT_SUCCESS
;
1013 m
->reload_result
= MOUNT_SUCCESS
;
1014 m
->reset_cpu_usage
= true;
1016 mount_enter_mounting(m
);
1020 static int mount_stop(Unit
*u
) {
1021 Mount
*m
= MOUNT(u
);
1026 if (m
->state
== MOUNT_UNMOUNTING
||
1027 m
->state
== MOUNT_UNMOUNTING_SIGKILL
||
1028 m
->state
== MOUNT_UNMOUNTING_SIGTERM
||
1029 m
->state
== MOUNT_MOUNTING_SIGTERM
||
1030 m
->state
== MOUNT_MOUNTING_SIGKILL
)
1033 assert(m
->state
== MOUNT_MOUNTING
||
1034 m
->state
== MOUNT_MOUNTING_DONE
||
1035 m
->state
== MOUNT_MOUNTED
||
1036 m
->state
== MOUNT_REMOUNTING
||
1037 m
->state
== MOUNT_REMOUNTING_SIGTERM
||
1038 m
->state
== MOUNT_REMOUNTING_SIGKILL
);
1040 mount_enter_unmounting(m
);
1044 static int mount_reload(Unit
*u
) {
1045 Mount
*m
= MOUNT(u
);
1049 if (m
->state
== MOUNT_MOUNTING_DONE
)
1052 assert(m
->state
== MOUNT_MOUNTED
);
1054 mount_enter_remounting(m
);
1058 static int mount_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1059 Mount
*m
= MOUNT(u
);
1065 unit_serialize_item(u
, f
, "state", mount_state_to_string(m
->state
));
1066 unit_serialize_item(u
, f
, "result", mount_result_to_string(m
->result
));
1067 unit_serialize_item(u
, f
, "reload-result", mount_result_to_string(m
->reload_result
));
1069 if (m
->control_pid
> 0)
1070 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, m
->control_pid
);
1072 if (m
->control_command_id
>= 0)
1073 unit_serialize_item(u
, f
, "control-command", mount_exec_command_to_string(m
->control_command_id
));
1078 static int mount_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
1079 Mount
*m
= MOUNT(u
);
1086 if (streq(key
, "state")) {
1089 if ((state
= mount_state_from_string(value
)) < 0)
1090 log_unit_debug(u
, "Failed to parse state value: %s", value
);
1092 m
->deserialized_state
= state
;
1093 } else if (streq(key
, "result")) {
1096 f
= mount_result_from_string(value
);
1098 log_unit_debug(u
, "Failed to parse result value: %s", value
);
1099 else if (f
!= MOUNT_SUCCESS
)
1102 } else if (streq(key
, "reload-result")) {
1105 f
= mount_result_from_string(value
);
1107 log_unit_debug(u
, "Failed to parse reload result value: %s", value
);
1108 else if (f
!= MOUNT_SUCCESS
)
1109 m
->reload_result
= f
;
1111 } else if (streq(key
, "control-pid")) {
1114 if (parse_pid(value
, &pid
) < 0)
1115 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
1117 m
->control_pid
= pid
;
1118 } else if (streq(key
, "control-command")) {
1119 MountExecCommand id
;
1121 id
= mount_exec_command_from_string(value
);
1123 log_unit_debug(u
, "Failed to parse exec-command value: %s", value
);
1125 m
->control_command_id
= id
;
1126 m
->control_command
= m
->exec_command
+ id
;
1129 log_unit_debug(u
, "Unknown serialization key: %s", key
);
1134 _pure_
static UnitActiveState
mount_active_state(Unit
*u
) {
1137 return state_translation_table
[MOUNT(u
)->state
];
1140 _pure_
static const char *mount_sub_state_to_string(Unit
*u
) {
1143 return mount_state_to_string(MOUNT(u
)->state
);
1146 _pure_
static bool mount_check_gc(Unit
*u
) {
1147 Mount
*m
= MOUNT(u
);
1151 return m
->from_proc_self_mountinfo
;
1154 static void mount_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
1155 Mount
*m
= MOUNT(u
);
1161 if (pid
!= m
->control_pid
)
1166 if (is_clean_exit(code
, status
, NULL
))
1168 else if (code
== CLD_EXITED
)
1169 f
= MOUNT_FAILURE_EXIT_CODE
;
1170 else if (code
== CLD_KILLED
)
1171 f
= MOUNT_FAILURE_SIGNAL
;
1172 else if (code
== CLD_DUMPED
)
1173 f
= MOUNT_FAILURE_CORE_DUMP
;
1175 assert_not_reached("Unknown code");
1177 if (m
->result
== MOUNT_SUCCESS
)
1180 if (m
->control_command
) {
1181 exec_status_exit(&m
->control_command
->exec_status
, &m
->exec_context
, pid
, code
, status
);
1183 m
->control_command
= NULL
;
1184 m
->control_command_id
= _MOUNT_EXEC_COMMAND_INVALID
;
1187 log_unit_full(u
, f
== MOUNT_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
1188 "Mount process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
1190 /* Note that mount(8) returning and the kernel sending us a
1191 * mount table change event might happen out-of-order. If an
1192 * operation succeed we assume the kernel will follow soon too
1193 * and already change into the resulting state. If it fails
1194 * we check if the kernel still knows about the mount. and
1195 * change state accordingly. */
1199 case MOUNT_MOUNTING
:
1200 case MOUNT_MOUNTING_DONE
:
1201 case MOUNT_MOUNTING_SIGKILL
:
1202 case MOUNT_MOUNTING_SIGTERM
:
1204 if (f
== MOUNT_SUCCESS
)
1205 mount_enter_mounted(m
, f
);
1206 else if (m
->from_proc_self_mountinfo
)
1207 mount_enter_mounted(m
, f
);
1209 mount_enter_dead(m
, f
);
1212 case MOUNT_REMOUNTING
:
1213 case MOUNT_REMOUNTING_SIGKILL
:
1214 case MOUNT_REMOUNTING_SIGTERM
:
1216 m
->reload_result
= f
;
1217 if (m
->from_proc_self_mountinfo
)
1218 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1220 mount_enter_dead(m
, MOUNT_SUCCESS
);
1224 case MOUNT_UNMOUNTING
:
1225 case MOUNT_UNMOUNTING_SIGKILL
:
1226 case MOUNT_UNMOUNTING_SIGTERM
:
1228 if (f
== MOUNT_SUCCESS
) {
1230 if (m
->from_proc_self_mountinfo
) {
1232 /* Still a mount point? If so, let's
1233 * try again. Most likely there were
1234 * multiple mount points stacked on
1235 * top of each other. Note that due to
1236 * the io event priority logic we can
1237 * be sure the new mountinfo is loaded
1238 * before we process the SIGCHLD for
1239 * the mount command. */
1241 if (m
->n_retry_umount
< RETRY_UMOUNT_MAX
) {
1242 log_unit_debug(u
, "Mount still present, trying again.");
1243 m
->n_retry_umount
++;
1244 mount_enter_unmounting(m
);
1246 log_unit_debug(u
, "Mount still present after %u attempts to unmount, giving up.", m
->n_retry_umount
);
1247 mount_enter_mounted(m
, f
);
1250 mount_enter_dead(m
, f
);
1252 } else if (m
->from_proc_self_mountinfo
)
1253 mount_enter_mounted(m
, f
);
1255 mount_enter_dead(m
, f
);
1259 assert_not_reached("Uh, control process died at wrong time.");
1262 /* Notify clients about changed exit status */
1263 unit_add_to_dbus_queue(u
);
1266 static int mount_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
1267 Mount
*m
= MOUNT(userdata
);
1270 assert(m
->timer_event_source
== source
);
1274 case MOUNT_MOUNTING
:
1275 case MOUNT_MOUNTING_DONE
:
1276 log_unit_warning(UNIT(m
), "Mounting timed out. Stopping.");
1277 mount_enter_signal(m
, MOUNT_MOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1280 case MOUNT_REMOUNTING
:
1281 log_unit_warning(UNIT(m
), "Remounting timed out. Stopping.");
1282 m
->reload_result
= MOUNT_FAILURE_TIMEOUT
;
1283 mount_enter_mounted(m
, MOUNT_SUCCESS
);
1286 case MOUNT_UNMOUNTING
:
1287 log_unit_warning(UNIT(m
), "Unmounting timed out. Stopping.");
1288 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGTERM
, MOUNT_FAILURE_TIMEOUT
);
1291 case MOUNT_MOUNTING_SIGTERM
:
1292 if (m
->kill_context
.send_sigkill
) {
1293 log_unit_warning(UNIT(m
), "Mounting timed out. Killing.");
1294 mount_enter_signal(m
, MOUNT_MOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1296 log_unit_warning(UNIT(m
), "Mounting timed out. Skipping SIGKILL. Ignoring.");
1298 if (m
->from_proc_self_mountinfo
)
1299 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1301 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1305 case MOUNT_REMOUNTING_SIGTERM
:
1306 if (m
->kill_context
.send_sigkill
) {
1307 log_unit_warning(UNIT(m
), "Remounting timed out. Killing.");
1308 mount_enter_signal(m
, MOUNT_REMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1310 log_unit_warning(UNIT(m
), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1312 if (m
->from_proc_self_mountinfo
)
1313 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1315 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1319 case MOUNT_UNMOUNTING_SIGTERM
:
1320 if (m
->kill_context
.send_sigkill
) {
1321 log_unit_warning(UNIT(m
), "Unmounting timed out. Killing.");
1322 mount_enter_signal(m
, MOUNT_UNMOUNTING_SIGKILL
, MOUNT_FAILURE_TIMEOUT
);
1324 log_unit_warning(UNIT(m
), "Unmounting timed out. Skipping SIGKILL. Ignoring.");
1326 if (m
->from_proc_self_mountinfo
)
1327 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1329 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1333 case MOUNT_MOUNTING_SIGKILL
:
1334 case MOUNT_REMOUNTING_SIGKILL
:
1335 case MOUNT_UNMOUNTING_SIGKILL
:
1336 log_unit_warning(UNIT(m
),"Mount process still around after SIGKILL. Ignoring.");
1338 if (m
->from_proc_self_mountinfo
)
1339 mount_enter_mounted(m
, MOUNT_FAILURE_TIMEOUT
);
1341 mount_enter_dead(m
, MOUNT_FAILURE_TIMEOUT
);
1345 assert_not_reached("Timeout at wrong time.");
1351 static int mount_setup_unit(
1355 const char *options
,
1359 _cleanup_free_
char *e
= NULL
, *w
= NULL
, *o
= NULL
, *f
= NULL
;
1360 bool load_extras
= false;
1362 bool delete, changed
= false;
1372 /* Ignore API mount points. They should never be referenced in
1373 * dependencies ever. */
1374 if (mount_point_is_api(where
) || mount_point_ignore(where
))
1377 if (streq(fstype
, "autofs"))
1380 /* probably some kind of swap, ignore */
1381 if (!is_path(where
))
1384 r
= unit_name_from_path(where
, ".mount", &e
);
1388 u
= manager_get_unit(m
, e
);
1392 u
= unit_new(m
, sizeof(Mount
));
1396 r
= unit_add_name(u
, e
);
1400 MOUNT(u
)->where
= strdup(where
);
1401 if (!MOUNT(u
)->where
) {
1406 u
->source_path
= strdup("/proc/self/mountinfo");
1407 if (!u
->source_path
) {
1412 if (MANAGER_IS_SYSTEM(m
)) {
1415 target
= mount_needs_network(options
, fstype
) ? SPECIAL_REMOTE_FS_TARGET
: SPECIAL_LOCAL_FS_TARGET
;
1416 r
= unit_add_dependency_by_name(u
, UNIT_BEFORE
, target
, NULL
, true);
1420 if (should_umount(MOUNT(u
))) {
1421 r
= unit_add_dependency_by_name(u
, UNIT_CONFLICTS
, SPECIAL_UMOUNT_TARGET
, NULL
, true);
1427 unit_add_to_load_queue(u
);
1432 if (!MOUNT(u
)->where
) {
1433 MOUNT(u
)->where
= strdup(where
);
1434 if (!MOUNT(u
)->where
) {
1440 if (MANAGER_IS_SYSTEM(m
) &&
1441 mount_needs_network(options
, fstype
)) {
1442 /* _netdev option may have shown up late, or on a
1443 * remount. Add remote-fs dependencies, even though
1444 * local-fs ones may already be there. */
1445 unit_add_dependency_by_name(u
, UNIT_BEFORE
, SPECIAL_REMOTE_FS_TARGET
, NULL
, true);
1449 if (u
->load_state
== UNIT_NOT_FOUND
) {
1450 u
->load_state
= UNIT_LOADED
;
1453 /* Load in the extras later on, after we
1454 * finished initialization of the unit */
1461 o
= strdup(options
);
1463 if (!w
|| !o
|| !f
) {
1468 p
= &MOUNT(u
)->parameters_proc_self_mountinfo
;
1470 changed
= changed
||
1471 !streq_ptr(p
->options
, options
) ||
1472 !streq_ptr(p
->what
, what
) ||
1473 !streq_ptr(p
->fstype
, fstype
);
1476 MOUNT(u
)->is_mounted
= true;
1477 MOUNT(u
)->just_mounted
= !MOUNT(u
)->from_proc_self_mountinfo
;
1478 MOUNT(u
)->just_changed
= changed
;
1481 MOUNT(u
)->from_proc_self_mountinfo
= true;
1496 r
= mount_add_extras(MOUNT(u
));
1502 unit_add_to_dbus_queue(u
);
1507 log_warning_errno(r
, "Failed to set up mount unit: %m");
1515 static int mount_load_proc_self_mountinfo(Manager
*m
, bool set_flags
) {
1516 _cleanup_(mnt_free_tablep
) struct libmnt_table
*t
= NULL
;
1517 _cleanup_(mnt_free_iterp
) struct libmnt_iter
*i
= NULL
;
1522 t
= mnt_new_table();
1526 i
= mnt_new_iter(MNT_ITER_FORWARD
);
1530 r
= mnt_table_parse_mtab(t
, NULL
);
1532 return log_error_errno(r
, "Failed to parse /proc/self/mountinfo: %m");
1536 const char *device
, *path
, *options
, *fstype
;
1537 _cleanup_free_
char *d
= NULL
, *p
= NULL
;
1538 struct libmnt_fs
*fs
;
1541 k
= mnt_table_next_fs(t
, i
, &fs
);
1545 return log_error_errno(k
, "Failed to get next entry from /proc/self/mountinfo: %m");
1547 device
= mnt_fs_get_source(fs
);
1548 path
= mnt_fs_get_target(fs
);
1549 options
= mnt_fs_get_options(fs
);
1550 fstype
= mnt_fs_get_fstype(fs
);
1552 if (!device
|| !path
)
1555 if (cunescape(device
, UNESCAPE_RELAX
, &d
) < 0)
1558 if (cunescape(path
, UNESCAPE_RELAX
, &p
) < 0)
1561 (void) device_found_node(m
, d
, true, DEVICE_FOUND_MOUNT
, set_flags
);
1563 k
= mount_setup_unit(m
, d
, p
, options
, fstype
, set_flags
);
1564 if (r
== 0 && k
< 0)
1571 static void mount_shutdown(Manager
*m
) {
1575 m
->mount_event_source
= sd_event_source_unref(m
->mount_event_source
);
1577 mnt_unref_monitor(m
->mount_monitor
);
1578 m
->mount_monitor
= NULL
;
1581 static int mount_get_timeout(Unit
*u
, usec_t
*timeout
) {
1582 Mount
*m
= MOUNT(u
);
1586 if (!m
->timer_event_source
)
1589 r
= sd_event_source_get_time(m
->timer_event_source
, &t
);
1592 if (t
== USEC_INFINITY
)
1599 static void mount_enumerate(Manager
*m
) {
1606 if (!m
->mount_monitor
) {
1609 m
->mount_monitor
= mnt_new_monitor();
1610 if (!m
->mount_monitor
) {
1615 r
= mnt_monitor_enable_kernel(m
->mount_monitor
, 1);
1617 log_error_errno(r
, "Failed to enable watching of kernel mount events: %m");
1621 r
= mnt_monitor_enable_userspace(m
->mount_monitor
, 1, NULL
);
1623 log_error_errno(r
, "Failed to enable watching of userspace mount events: %m");
1627 /* mnt_unref_monitor() will close the fd */
1628 fd
= r
= mnt_monitor_get_fd(m
->mount_monitor
);
1630 log_error_errno(r
, "Failed to acquire watch file descriptor: %m");
1634 r
= sd_event_add_io(m
->event
, &m
->mount_event_source
, fd
, EPOLLIN
, mount_dispatch_io
, m
);
1636 log_error_errno(r
, "Failed to watch mount file descriptor: %m");
1640 r
= sd_event_source_set_priority(m
->mount_event_source
, -10);
1642 log_error_errno(r
, "Failed to adjust mount watch priority: %m");
1646 (void) sd_event_source_set_description(m
->mount_event_source
, "mount-monitor-dispatch");
1649 r
= mount_load_proc_self_mountinfo(m
, false);
1659 static int mount_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
1660 _cleanup_set_free_ Set
*around
= NULL
, *gone
= NULL
;
1661 Manager
*m
= userdata
;
1668 assert(revents
& EPOLLIN
);
1670 if (fd
== mnt_monitor_get_fd(m
->mount_monitor
)) {
1671 bool rescan
= false;
1673 /* Drain all events and verify that the event is valid.
1675 * Note that libmount also monitors /run/mount mkdir if the
1676 * directory does not exist yet. The mkdir may generate event
1677 * which is irrelevant for us.
1679 * error: r < 0; valid: r == 0, false positive: rc == 1 */
1681 r
= mnt_monitor_next_change(m
->mount_monitor
, NULL
, NULL
);
1685 return log_error_errno(r
, "Failed to drain libmount events");
1688 log_debug("libmount event [rescan: %s]", yes_no(rescan
));
1693 r
= mount_load_proc_self_mountinfo(m
, true);
1695 /* Reset flags, just in case, for later calls */
1696 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1697 Mount
*mount
= MOUNT(u
);
1699 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1705 manager_dispatch_load_queue(m
);
1707 LIST_FOREACH(units_by_type
, u
, m
->units_by_type
[UNIT_MOUNT
]) {
1708 Mount
*mount
= MOUNT(u
);
1710 if (!mount
->is_mounted
) {
1712 /* A mount point is not around right now. It
1713 * might be gone, or might never have
1716 if (mount
->from_proc_self_mountinfo
&&
1717 mount
->parameters_proc_self_mountinfo
.what
) {
1719 /* Remember that this device might just have disappeared */
1720 if (set_ensure_allocated(&gone
, &string_hash_ops
) < 0 ||
1721 set_put(gone
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1722 log_oom(); /* we don't care too much about OOM here... */
1725 mount
->from_proc_self_mountinfo
= false;
1727 switch (mount
->state
) {
1730 /* This has just been unmounted by
1731 * somebody else, follow the state
1733 mount
->result
= MOUNT_SUCCESS
; /* make sure we forget any earlier umount failures */
1734 mount_enter_dead(mount
, MOUNT_SUCCESS
);
1741 } else if (mount
->just_mounted
|| mount
->just_changed
) {
1743 /* A mount point was added or changed */
1745 switch (mount
->state
) {
1750 /* This has just been mounted by somebody else, follow the state change, but let's
1751 * generate a new invocation ID for this implicitly and automatically. */
1752 (void) unit_acquire_invocation_id(UNIT(mount
));
1753 mount_enter_mounted(mount
, MOUNT_SUCCESS
);
1756 case MOUNT_MOUNTING
:
1757 mount_set_state(mount
, MOUNT_MOUNTING_DONE
);
1761 /* Nothing really changed, but let's
1762 * issue an notification call
1763 * nonetheless, in case somebody is
1764 * waiting for this. (e.g. file system
1765 * ro/rw remounts.) */
1766 mount_set_state(mount
, mount
->state
);
1771 if (mount
->is_mounted
&&
1772 mount
->from_proc_self_mountinfo
&&
1773 mount
->parameters_proc_self_mountinfo
.what
) {
1775 if (set_ensure_allocated(&around
, &string_hash_ops
) < 0 ||
1776 set_put(around
, mount
->parameters_proc_self_mountinfo
.what
) < 0)
1780 /* Reset the flags for later calls */
1781 mount
->is_mounted
= mount
->just_mounted
= mount
->just_changed
= false;
1784 SET_FOREACH(what
, gone
, i
) {
1785 if (set_contains(around
, what
))
1788 /* Let the device units know that the device is no longer mounted */
1789 (void) device_found_node(m
, what
, false, DEVICE_FOUND_MOUNT
, true);
1795 static void mount_reset_failed(Unit
*u
) {
1796 Mount
*m
= MOUNT(u
);
1800 if (m
->state
== MOUNT_FAILED
)
1801 mount_set_state(m
, MOUNT_DEAD
);
1803 m
->result
= MOUNT_SUCCESS
;
1804 m
->reload_result
= MOUNT_SUCCESS
;
1807 static int mount_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
1808 return unit_kill_common(u
, who
, signo
, -1, MOUNT(u
)->control_pid
, error
);
1811 static int mount_control_pid(Unit
*u
) {
1812 Mount
*m
= MOUNT(u
);
1816 return m
->control_pid
;
1819 static const char* const mount_exec_command_table
[_MOUNT_EXEC_COMMAND_MAX
] = {
1820 [MOUNT_EXEC_MOUNT
] = "ExecMount",
1821 [MOUNT_EXEC_UNMOUNT
] = "ExecUnmount",
1822 [MOUNT_EXEC_REMOUNT
] = "ExecRemount",
1825 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command
, MountExecCommand
);
1827 static const char* const mount_result_table
[_MOUNT_RESULT_MAX
] = {
1828 [MOUNT_SUCCESS
] = "success",
1829 [MOUNT_FAILURE_RESOURCES
] = "resources",
1830 [MOUNT_FAILURE_TIMEOUT
] = "timeout",
1831 [MOUNT_FAILURE_EXIT_CODE
] = "exit-code",
1832 [MOUNT_FAILURE_SIGNAL
] = "signal",
1833 [MOUNT_FAILURE_CORE_DUMP
] = "core-dump",
1834 [MOUNT_FAILURE_START_LIMIT_HIT
] = "start-limit-hit",
1837 DEFINE_STRING_TABLE_LOOKUP(mount_result
, MountResult
);
1839 const UnitVTable mount_vtable
= {
1840 .object_size
= sizeof(Mount
),
1841 .exec_context_offset
= offsetof(Mount
, exec_context
),
1842 .cgroup_context_offset
= offsetof(Mount
, cgroup_context
),
1843 .kill_context_offset
= offsetof(Mount
, kill_context
),
1844 .exec_runtime_offset
= offsetof(Mount
, exec_runtime
),
1845 .dynamic_creds_offset
= offsetof(Mount
, dynamic_creds
),
1851 .private_section
= "Mount",
1857 .coldplug
= mount_coldplug
,
1861 .start
= mount_start
,
1863 .reload
= mount_reload
,
1867 .serialize
= mount_serialize
,
1868 .deserialize_item
= mount_deserialize_item
,
1870 .active_state
= mount_active_state
,
1871 .sub_state_to_string
= mount_sub_state_to_string
,
1873 .check_gc
= mount_check_gc
,
1875 .sigchld_event
= mount_sigchld_event
,
1877 .reset_failed
= mount_reset_failed
,
1879 .control_pid
= mount_control_pid
,
1881 .bus_vtable
= bus_mount_vtable
,
1882 .bus_set_property
= bus_mount_set_property
,
1883 .bus_commit_properties
= bus_mount_commit_properties
,
1885 .get_timeout
= mount_get_timeout
,
1887 .can_transient
= true,
1889 .enumerate
= mount_enumerate
,
1890 .shutdown
= mount_shutdown
,
1892 .status_message_formats
= {
1893 .starting_stopping
= {
1894 [0] = "Mounting %s...",
1895 [1] = "Unmounting %s...",
1897 .finished_start_job
= {
1898 [JOB_DONE
] = "Mounted %s.",
1899 [JOB_FAILED
] = "Failed to mount %s.",
1900 [JOB_TIMEOUT
] = "Timed out mounting %s.",
1902 .finished_stop_job
= {
1903 [JOB_DONE
] = "Unmounted %s.",
1904 [JOB_FAILED
] = "Failed unmounting %s.",
1905 [JOB_TIMEOUT
] = "Timed out unmounting %s.",