]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/mount.c
Merge pull request #11142 from ssahani/bond-dynamic-tlb
[thirdparty/systemd.git] / src / core / mount.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <signal.h>
5 #include <stdio.h>
6 #include <sys/epoll.h>
7
8 #include <libmount.h>
9
10 #include "sd-messages.h"
11
12 #include "alloc-util.h"
13 #include "dbus-mount.h"
14 #include "dbus-unit.h"
15 #include "device.h"
16 #include "escape.h"
17 #include "exit-status.h"
18 #include "format-util.h"
19 #include "fstab-util.h"
20 #include "log.h"
21 #include "manager.h"
22 #include "mkdir.h"
23 #include "mount-setup.h"
24 #include "mount.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"
30 #include "special.h"
31 #include "string-table.h"
32 #include "string-util.h"
33 #include "strv.h"
34 #include "unit-name.h"
35 #include "unit.h"
36
37 #define RETRY_UMOUNT_MAX 32
38
39 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table);
40 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter);
41
42 static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
43 [MOUNT_DEAD] = UNIT_INACTIVE,
44 [MOUNT_MOUNTING] = UNIT_ACTIVATING,
45 [MOUNT_MOUNTING_DONE] = UNIT_ACTIVATING,
46 [MOUNT_MOUNTED] = UNIT_ACTIVE,
47 [MOUNT_REMOUNTING] = UNIT_RELOADING,
48 [MOUNT_UNMOUNTING] = UNIT_DEACTIVATING,
49 [MOUNT_REMOUNTING_SIGTERM] = UNIT_RELOADING,
50 [MOUNT_REMOUNTING_SIGKILL] = UNIT_RELOADING,
51 [MOUNT_UNMOUNTING_SIGTERM] = UNIT_DEACTIVATING,
52 [MOUNT_UNMOUNTING_SIGKILL] = UNIT_DEACTIVATING,
53 [MOUNT_FAILED] = UNIT_FAILED
54 };
55
56 static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
57 static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
58 static int mount_dispatch_proc_self_mountinfo_timer(sd_event_source *source, usec_t usec, void *userdata);
59
60 static bool MOUNT_STATE_WITH_PROCESS(MountState state) {
61 return IN_SET(state,
62 MOUNT_MOUNTING,
63 MOUNT_MOUNTING_DONE,
64 MOUNT_REMOUNTING,
65 MOUNT_REMOUNTING_SIGTERM,
66 MOUNT_REMOUNTING_SIGKILL,
67 MOUNT_UNMOUNTING,
68 MOUNT_UNMOUNTING_SIGTERM,
69 MOUNT_UNMOUNTING_SIGKILL);
70 }
71
72 static bool mount_is_network(const MountParameters *p) {
73 assert(p);
74
75 if (fstab_test_option(p->options, "_netdev\0"))
76 return true;
77
78 if (p->fstype && fstype_is_network(p->fstype))
79 return true;
80
81 return false;
82 }
83
84 static bool mount_is_loop(const MountParameters *p) {
85 assert(p);
86
87 if (fstab_test_option(p->options, "loop\0"))
88 return true;
89
90 return false;
91 }
92
93 static bool mount_is_bind(const MountParameters *p) {
94 assert(p);
95
96 if (fstab_test_option(p->options, "bind\0" "rbind\0"))
97 return true;
98
99 if (p->fstype && STR_IN_SET(p->fstype, "bind", "rbind"))
100 return true;
101
102 return false;
103 }
104
105 static bool mount_is_auto(const MountParameters *p) {
106 assert(p);
107
108 return !fstab_test_option(p->options, "noauto\0");
109 }
110
111 static bool mount_is_automount(const MountParameters *p) {
112 assert(p);
113
114 return fstab_test_option(p->options,
115 "comment=systemd.automount\0"
116 "x-systemd.automount\0");
117 }
118
119 static bool mount_is_bound_to_device(const Mount *m) {
120 const MountParameters *p;
121
122 if (m->from_fragment)
123 return true;
124
125 p = &m->parameters_proc_self_mountinfo;
126 return fstab_test_option(p->options, "x-systemd.device-bound\0");
127 }
128
129 static bool mount_needs_quota(const MountParameters *p) {
130 assert(p);
131
132 /* Quotas are not enabled on network filesystems, but we want them, for example, on storage connected via
133 * iscsi. We hence don't use mount_is_network() here, as that would also return true for _netdev devices. */
134 if (p->fstype && fstype_is_network(p->fstype))
135 return false;
136
137 if (mount_is_bind(p))
138 return false;
139
140 return fstab_test_option(p->options,
141 "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
142 }
143
144 static void mount_init(Unit *u) {
145 Mount *m = MOUNT(u);
146
147 assert(u);
148 assert(u->load_state == UNIT_STUB);
149
150 m->timeout_usec = u->manager->default_timeout_start_usec;
151
152 m->exec_context.std_output = u->manager->default_std_output;
153 m->exec_context.std_error = u->manager->default_std_error;
154
155 m->directory_mode = 0755;
156
157 /* We need to make sure that /usr/bin/mount is always called
158 * in the same process group as us, so that the autofs kernel
159 * side doesn't send us another mount request while we are
160 * already trying to comply its last one. */
161 m->exec_context.same_pgrp = true;
162
163 m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
164
165 u->ignore_on_isolate = true;
166 }
167
168 static int mount_arm_timer(Mount *m, usec_t usec) {
169 int r;
170
171 assert(m);
172
173 if (m->timer_event_source) {
174 r = sd_event_source_set_time(m->timer_event_source, usec);
175 if (r < 0)
176 return r;
177
178 return sd_event_source_set_enabled(m->timer_event_source, SD_EVENT_ONESHOT);
179 }
180
181 if (usec == USEC_INFINITY)
182 return 0;
183
184 r = sd_event_add_time(
185 UNIT(m)->manager->event,
186 &m->timer_event_source,
187 CLOCK_MONOTONIC,
188 usec, 0,
189 mount_dispatch_timer, m);
190 if (r < 0)
191 return r;
192
193 (void) sd_event_source_set_description(m->timer_event_source, "mount-timer");
194
195 return 0;
196 }
197
198 static void mount_unwatch_control_pid(Mount *m) {
199 assert(m);
200
201 if (m->control_pid <= 0)
202 return;
203
204 unit_unwatch_pid(UNIT(m), m->control_pid);
205 m->control_pid = 0;
206 }
207
208 static void mount_parameters_done(MountParameters *p) {
209 assert(p);
210
211 p->what = mfree(p->what);
212 p->options = mfree(p->options);
213 p->fstype = mfree(p->fstype);
214 }
215
216 static void mount_done(Unit *u) {
217 Mount *m = MOUNT(u);
218
219 assert(m);
220
221 m->where = mfree(m->where);
222
223 mount_parameters_done(&m->parameters_proc_self_mountinfo);
224 mount_parameters_done(&m->parameters_fragment);
225
226 m->exec_runtime = exec_runtime_unref(m->exec_runtime, false);
227 exec_command_done_array(m->exec_command, _MOUNT_EXEC_COMMAND_MAX);
228 m->control_command = NULL;
229
230 dynamic_creds_unref(&m->dynamic_creds);
231
232 mount_unwatch_control_pid(m);
233
234 m->timer_event_source = sd_event_source_unref(m->timer_event_source);
235 }
236
237 _pure_ static MountParameters* get_mount_parameters_fragment(Mount *m) {
238 assert(m);
239
240 if (m->from_fragment)
241 return &m->parameters_fragment;
242
243 return NULL;
244 }
245
246 _pure_ static MountParameters* get_mount_parameters(Mount *m) {
247 assert(m);
248
249 if (m->from_proc_self_mountinfo)
250 return &m->parameters_proc_self_mountinfo;
251
252 return get_mount_parameters_fragment(m);
253 }
254
255 static int mount_add_mount_dependencies(Mount *m) {
256 MountParameters *pm;
257 Unit *other;
258 Iterator i;
259 Set *s;
260 int r;
261
262 assert(m);
263
264 if (!path_equal(m->where, "/")) {
265 _cleanup_free_ char *parent = NULL;
266
267 /* Adds in links to other mount points that might lie further up in the hierarchy */
268
269 parent = dirname_malloc(m->where);
270 if (!parent)
271 return -ENOMEM;
272
273 r = unit_require_mounts_for(UNIT(m), parent, UNIT_DEPENDENCY_IMPLICIT);
274 if (r < 0)
275 return r;
276 }
277
278 /* Adds in dependencies to other mount points that might be needed for the source path (if this is a bind mount
279 * or a loop mount) to be available. */
280 pm = get_mount_parameters_fragment(m);
281 if (pm && pm->what &&
282 path_is_absolute(pm->what) &&
283 (mount_is_bind(pm) || mount_is_loop(pm) || !mount_is_network(pm))) {
284
285 r = unit_require_mounts_for(UNIT(m), pm->what, UNIT_DEPENDENCY_FILE);
286 if (r < 0)
287 return r;
288 }
289
290 /* Adds in dependencies to other units that use this path or paths further down in the hierarchy */
291 s = manager_get_units_requiring_mounts_for(UNIT(m)->manager, m->where);
292 SET_FOREACH(other, s, i) {
293
294 if (other->load_state != UNIT_LOADED)
295 continue;
296
297 if (other == UNIT(m))
298 continue;
299
300 r = unit_add_dependency(other, UNIT_AFTER, UNIT(m), true, UNIT_DEPENDENCY_PATH);
301 if (r < 0)
302 return r;
303
304 if (UNIT(m)->fragment_path) {
305 /* If we have fragment configuration, then make this dependency required */
306 r = unit_add_dependency(other, UNIT_REQUIRES, UNIT(m), true, UNIT_DEPENDENCY_PATH);
307 if (r < 0)
308 return r;
309 }
310 }
311
312 return 0;
313 }
314
315 static int mount_add_device_dependencies(Mount *m) {
316 bool device_wants_mount;
317 UnitDependencyMask mask;
318 MountParameters *p;
319 UnitDependency dep;
320 int r;
321
322 assert(m);
323
324 p = get_mount_parameters(m);
325 if (!p)
326 return 0;
327
328 if (!p->what)
329 return 0;
330
331 if (mount_is_bind(p))
332 return 0;
333
334 if (!is_device_path(p->what))
335 return 0;
336
337 /* /dev/root is a really weird thing, it's not a real device,
338 * but just a path the kernel exports for the root file system
339 * specified on the kernel command line. Ignore it here. */
340 if (path_equal(p->what, "/dev/root"))
341 return 0;
342
343 if (path_equal(m->where, "/"))
344 return 0;
345
346 device_wants_mount =
347 mount_is_auto(p) && !mount_is_automount(p) && MANAGER_IS_SYSTEM(UNIT(m)->manager);
348
349 /* Mount units from /proc/self/mountinfo are not bound to devices
350 * by default since they're subject to races when devices are
351 * unplugged. But the user can still force this dep with an
352 * appropriate option (or udev property) so the mount units are
353 * automatically stopped when the device disappears suddenly. */
354 dep = mount_is_bound_to_device(m) ? UNIT_BINDS_TO : UNIT_REQUIRES;
355
356 mask = m->from_fragment ? UNIT_DEPENDENCY_FILE : UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT;
357
358 r = unit_add_node_dependency(UNIT(m), p->what, device_wants_mount, dep, mask);
359 if (r < 0)
360 return r;
361
362 return 0;
363 }
364
365 static int mount_add_quota_dependencies(Mount *m) {
366 UnitDependencyMask mask;
367 MountParameters *p;
368 int r;
369
370 assert(m);
371
372 if (!MANAGER_IS_SYSTEM(UNIT(m)->manager))
373 return 0;
374
375 p = get_mount_parameters_fragment(m);
376 if (!p)
377 return 0;
378
379 if (!mount_needs_quota(p))
380 return 0;
381
382 mask = m->from_fragment ? UNIT_DEPENDENCY_FILE : UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT;
383
384 r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_WANTS, SPECIAL_QUOTACHECK_SERVICE, true, mask);
385 if (r < 0)
386 return r;
387
388 r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_WANTS, SPECIAL_QUOTAON_SERVICE, true, mask);
389 if (r < 0)
390 return r;
391
392 return 0;
393 }
394
395 static bool mount_is_extrinsic(Mount *m) {
396 MountParameters *p;
397 assert(m);
398
399 /* Returns true for all units that are "magic" and should be excluded from the usual start-up and shutdown
400 * dependencies. We call them "extrinsic" here, as they are generally mounted outside of the systemd dependency
401 * logic. We shouldn't attempt to manage them ourselves but it's fine if the user operates on them with us. */
402
403 if (!MANAGER_IS_SYSTEM(UNIT(m)->manager)) /* We only automatically manage mounts if we are in system mode */
404 return true;
405
406 if (PATH_IN_SET(m->where, /* Don't bother with the OS data itself */
407 "/",
408 "/usr"))
409 return true;
410
411 if (PATH_STARTSWITH_SET(m->where,
412 "/run/initramfs", /* This should stay around from before we boot until after we shutdown */
413 "/proc", /* All of this is API VFS */
414 "/sys", /* … dito … */
415 "/dev")) /* … dito … */
416 return true;
417
418 /* If this is an initrd mount, and we are not in the initrd, then leave this around forever, too. */
419 p = get_mount_parameters(m);
420 if (p && fstab_test_option(p->options, "x-initrd.mount\0") && !in_initrd())
421 return true;
422
423 return false;
424 }
425
426 static int mount_add_default_dependencies(Mount *m) {
427 const char *after, *before;
428 UnitDependencyMask mask;
429 MountParameters *p;
430 int r;
431
432 assert(m);
433
434 if (!UNIT(m)->default_dependencies)
435 return 0;
436
437 /* We do not add any default dependencies to /, /usr or /run/initramfs/, since they are guaranteed to stay
438 * mounted the whole time, since our system is on it. Also, don't bother with anything mounted below virtual
439 * file systems, it's also going to be virtual, and hence not worth the effort. */
440 if (mount_is_extrinsic(m))
441 return 0;
442
443 p = get_mount_parameters(m);
444 if (!p)
445 return 0;
446
447 mask = m->from_fragment ? UNIT_DEPENDENCY_FILE : UNIT_DEPENDENCY_MOUNTINFO_DEFAULT;
448
449 if (mount_is_network(p)) {
450 /* We order ourselves after network.target. This is
451 * primarily useful at shutdown: services that take
452 * down the network should order themselves before
453 * network.target, so that they are shut down only
454 * after this mount unit is stopped. */
455
456 r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_NETWORK_TARGET, true, mask);
457 if (r < 0)
458 return r;
459
460 /* We pull in network-online.target, and order
461 * ourselves after it. This is useful at start-up to
462 * actively pull in tools that want to be started
463 * before we start mounting network file systems, and
464 * whose purpose it is to delay this until the network
465 * is "up". */
466
467 r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_WANTS, UNIT_AFTER, SPECIAL_NETWORK_ONLINE_TARGET, true, mask);
468 if (r < 0)
469 return r;
470
471 after = SPECIAL_REMOTE_FS_PRE_TARGET;
472 before = SPECIAL_REMOTE_FS_TARGET;
473 } else {
474 after = SPECIAL_LOCAL_FS_PRE_TARGET;
475 before = SPECIAL_LOCAL_FS_TARGET;
476 }
477
478 r = unit_add_dependency_by_name(UNIT(m), UNIT_BEFORE, before, true, mask);
479 if (r < 0)
480 return r;
481
482 r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, after, true, mask);
483 if (r < 0)
484 return r;
485
486 r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, true, mask);
487 if (r < 0)
488 return r;
489
490 /* If this is a tmpfs mount then we have to unmount it before we try to deactivate swaps */
491 if (streq_ptr(p->fstype, "tmpfs")) {
492 r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_SWAP_TARGET, true, mask);
493 if (r < 0)
494 return r;
495 }
496
497 return 0;
498 }
499
500 static int mount_verify(Mount *m) {
501 _cleanup_free_ char *e = NULL;
502 MountParameters *p;
503 int r;
504
505 assert(m);
506
507 if (UNIT(m)->load_state != UNIT_LOADED)
508 return 0;
509
510 if (!m->from_fragment && !m->from_proc_self_mountinfo && !UNIT(m)->perpetual)
511 return -ENOENT;
512
513 r = unit_name_from_path(m->where, ".mount", &e);
514 if (r < 0)
515 return log_unit_error_errno(UNIT(m), r, "Failed to generate unit name from mount path: %m");
516
517 if (!unit_has_name(UNIT(m), e)) {
518 log_unit_error(UNIT(m), "Where= setting doesn't match unit name. Refusing.");
519 return -ENOEXEC;
520 }
521
522 if (mount_point_is_api(m->where) || mount_point_ignore(m->where)) {
523 log_unit_error(UNIT(m), "Cannot create mount unit for API file system %s. Refusing.", m->where);
524 return -ENOEXEC;
525 }
526
527 p = get_mount_parameters_fragment(m);
528 if (p && !p->what) {
529 log_unit_error(UNIT(m), "What= setting is missing. Refusing.");
530 return -ENOEXEC;
531 }
532
533 if (m->exec_context.pam_name && m->kill_context.kill_mode != KILL_CONTROL_GROUP) {
534 log_unit_error(UNIT(m), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
535 return -ENOEXEC;
536 }
537
538 return 0;
539 }
540
541 static int mount_add_extras(Mount *m) {
542 Unit *u = UNIT(m);
543 int r;
544
545 assert(m);
546
547 /* Note: this call might be called after we already have been loaded once (and even when it has already been
548 * activated), in case data from /proc/self/mountinfo has changed. This means all code here needs to be ready
549 * to run with an already set up unit. */
550
551 if (u->fragment_path)
552 m->from_fragment = true;
553
554 if (!m->where) {
555 r = unit_name_to_path(u->id, &m->where);
556 if (r < 0)
557 return r;
558 }
559
560 path_simplify(m->where, false);
561
562 if (!u->description) {
563 r = unit_set_description(u, m->where);
564 if (r < 0)
565 return r;
566 }
567
568 r = mount_add_device_dependencies(m);
569 if (r < 0)
570 return r;
571
572 r = mount_add_mount_dependencies(m);
573 if (r < 0)
574 return r;
575
576 r = mount_add_quota_dependencies(m);
577 if (r < 0)
578 return r;
579
580 r = unit_patch_contexts(u);
581 if (r < 0)
582 return r;
583
584 r = unit_add_exec_dependencies(u, &m->exec_context);
585 if (r < 0)
586 return r;
587
588 r = unit_set_default_slice(u);
589 if (r < 0)
590 return r;
591
592 r = mount_add_default_dependencies(m);
593 if (r < 0)
594 return r;
595
596 return 0;
597 }
598
599 static int mount_load_root_mount(Unit *u) {
600 assert(u);
601
602 if (!unit_has_name(u, SPECIAL_ROOT_MOUNT))
603 return 0;
604
605 u->perpetual = true;
606 u->default_dependencies = false;
607
608 /* The stdio/kmsg bridge socket is on /, in order to avoid a dep loop, don't use kmsg logging for -.mount */
609 MOUNT(u)->exec_context.std_output = EXEC_OUTPUT_NULL;
610 MOUNT(u)->exec_context.std_input = EXEC_INPUT_NULL;
611
612 if (!u->description)
613 u->description = strdup("Root Mount");
614
615 return 1;
616 }
617
618 static int mount_load(Unit *u) {
619 Mount *m = MOUNT(u);
620 int r, q, w;
621
622 assert(u);
623 assert(u->load_state == UNIT_STUB);
624
625 r = mount_load_root_mount(u);
626
627 if (m->from_proc_self_mountinfo || u->perpetual)
628 q = unit_load_fragment_and_dropin_optional(u);
629 else
630 q = unit_load_fragment_and_dropin(u);
631
632 /* Add in some extras. Note we do this in all cases (even if we failed to load the unit) when announced by the
633 * kernel, because we need some things to be set up no matter what when the kernel establishes a mount and thus
634 * we need to update the state in our unit to track it. After all, consider that we don't allow changing the
635 * 'slice' field for a unit once it is active. */
636 if (u->load_state == UNIT_LOADED || m->from_proc_self_mountinfo || u->perpetual)
637 w = mount_add_extras(m);
638 else
639 w = 0;
640
641 if (r < 0)
642 return r;
643 if (q < 0)
644 return q;
645 if (w < 0)
646 return w;
647
648 return mount_verify(m);
649 }
650
651 static void mount_set_state(Mount *m, MountState state) {
652 MountState old_state;
653 assert(m);
654
655 if (m->state != state)
656 bus_unit_send_pending_change_signal(UNIT(m), false);
657
658 old_state = m->state;
659 m->state = state;
660
661 if (!MOUNT_STATE_WITH_PROCESS(state)) {
662 m->timer_event_source = sd_event_source_unref(m->timer_event_source);
663 mount_unwatch_control_pid(m);
664 m->control_command = NULL;
665 m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
666 }
667
668 if (state != old_state)
669 log_unit_debug(UNIT(m), "Changed %s -> %s", mount_state_to_string(old_state), mount_state_to_string(state));
670
671 unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state],
672 m->reload_result == MOUNT_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE);
673 }
674
675 static int mount_coldplug(Unit *u) {
676 Mount *m = MOUNT(u);
677 MountState new_state = MOUNT_DEAD;
678 int r;
679
680 assert(m);
681 assert(m->state == MOUNT_DEAD);
682
683 if (m->deserialized_state != m->state)
684 new_state = m->deserialized_state;
685 else if (m->from_proc_self_mountinfo)
686 new_state = MOUNT_MOUNTED;
687
688 if (new_state == m->state)
689 return 0;
690
691 if (m->control_pid > 0 &&
692 pid_is_unwaited(m->control_pid) &&
693 MOUNT_STATE_WITH_PROCESS(new_state)) {
694
695 r = unit_watch_pid(UNIT(m), m->control_pid);
696 if (r < 0)
697 return r;
698
699 r = mount_arm_timer(m, usec_add(u->state_change_timestamp.monotonic, m->timeout_usec));
700 if (r < 0)
701 return r;
702 }
703
704 if (!IN_SET(new_state, MOUNT_DEAD, MOUNT_FAILED)) {
705 (void) unit_setup_dynamic_creds(u);
706 (void) unit_setup_exec_runtime(u);
707 }
708
709 mount_set_state(m, new_state);
710 return 0;
711 }
712
713 static void mount_dump(Unit *u, FILE *f, const char *prefix) {
714 char buf[FORMAT_TIMESPAN_MAX];
715 Mount *m = MOUNT(u);
716 MountParameters *p;
717
718 assert(m);
719 assert(f);
720
721 p = get_mount_parameters(m);
722
723 fprintf(f,
724 "%sMount State: %s\n"
725 "%sResult: %s\n"
726 "%sWhere: %s\n"
727 "%sWhat: %s\n"
728 "%sFile System Type: %s\n"
729 "%sOptions: %s\n"
730 "%sFrom /proc/self/mountinfo: %s\n"
731 "%sFrom fragment: %s\n"
732 "%sExtrinsic: %s\n"
733 "%sDirectoryMode: %04o\n"
734 "%sSloppyOptions: %s\n"
735 "%sLazyUnmount: %s\n"
736 "%sForceUnmount: %s\n"
737 "%sTimoutSec: %s\n",
738 prefix, mount_state_to_string(m->state),
739 prefix, mount_result_to_string(m->result),
740 prefix, m->where,
741 prefix, p ? strna(p->what) : "n/a",
742 prefix, p ? strna(p->fstype) : "n/a",
743 prefix, p ? strna(p->options) : "n/a",
744 prefix, yes_no(m->from_proc_self_mountinfo),
745 prefix, yes_no(m->from_fragment),
746 prefix, yes_no(mount_is_extrinsic(m)),
747 prefix, m->directory_mode,
748 prefix, yes_no(m->sloppy_options),
749 prefix, yes_no(m->lazy_unmount),
750 prefix, yes_no(m->force_unmount),
751 prefix, format_timespan(buf, sizeof(buf), m->timeout_usec, USEC_PER_SEC));
752
753 if (m->control_pid > 0)
754 fprintf(f,
755 "%sControl PID: "PID_FMT"\n",
756 prefix, m->control_pid);
757
758 exec_context_dump(&m->exec_context, f, prefix);
759 kill_context_dump(&m->kill_context, f, prefix);
760 cgroup_context_dump(&m->cgroup_context, f, prefix);
761 }
762
763 static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
764
765 _cleanup_(exec_params_clear) ExecParameters exec_params = {
766 .flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
767 .stdin_fd = -1,
768 .stdout_fd = -1,
769 .stderr_fd = -1,
770 .exec_fd = -1,
771 };
772 pid_t pid;
773 int r;
774
775 assert(m);
776 assert(c);
777 assert(_pid);
778
779 r = unit_prepare_exec(UNIT(m));
780 if (r < 0)
781 return r;
782
783 r = mount_arm_timer(m, usec_add(now(CLOCK_MONOTONIC), m->timeout_usec));
784 if (r < 0)
785 return r;
786
787 r = unit_set_exec_params(UNIT(m), &exec_params);
788 if (r < 0)
789 return r;
790
791 r = exec_spawn(UNIT(m),
792 c,
793 &m->exec_context,
794 &exec_params,
795 m->exec_runtime,
796 &m->dynamic_creds,
797 &pid);
798 if (r < 0)
799 return r;
800
801 r = unit_watch_pid(UNIT(m), pid);
802 if (r < 0)
803 /* FIXME: we need to do something here */
804 return r;
805
806 *_pid = pid;
807
808 return 0;
809 }
810
811 static void mount_enter_dead(Mount *m, MountResult f) {
812 assert(m);
813
814 if (m->result == MOUNT_SUCCESS)
815 m->result = f;
816
817 unit_log_result(UNIT(m), m->result == MOUNT_SUCCESS, mount_result_to_string(m->result));
818 mount_set_state(m, m->result != MOUNT_SUCCESS ? MOUNT_FAILED : MOUNT_DEAD);
819
820 m->exec_runtime = exec_runtime_unref(m->exec_runtime, true);
821
822 exec_context_destroy_runtime_directory(&m->exec_context, UNIT(m)->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
823
824 unit_unref_uid_gid(UNIT(m), true);
825
826 dynamic_creds_destroy(&m->dynamic_creds);
827 }
828
829 static void mount_enter_mounted(Mount *m, MountResult f) {
830 assert(m);
831
832 if (m->result == MOUNT_SUCCESS)
833 m->result = f;
834
835 mount_set_state(m, MOUNT_MOUNTED);
836 }
837
838 static void mount_enter_dead_or_mounted(Mount *m, MountResult f) {
839 assert(m);
840
841 /* Enter DEAD or MOUNTED state, depending on what the kernel currently says about the mount point. We use this
842 * whenever we executed an operation, so that our internal state reflects what the kernel says again, after all
843 * ultimately we just mirror the kernel's internal state on this. */
844
845 if (m->from_proc_self_mountinfo)
846 mount_enter_mounted(m, f);
847 else
848 mount_enter_dead(m, f);
849 }
850
851 static int state_to_kill_operation(MountState state) {
852 switch (state) {
853
854 case MOUNT_REMOUNTING_SIGTERM:
855 case MOUNT_UNMOUNTING_SIGTERM:
856 return KILL_TERMINATE;
857
858 case MOUNT_REMOUNTING_SIGKILL:
859 case MOUNT_UNMOUNTING_SIGKILL:
860 return KILL_KILL;
861
862 default:
863 return _KILL_OPERATION_INVALID;
864 }
865 }
866
867 static void mount_enter_signal(Mount *m, MountState state, MountResult f) {
868 int r;
869
870 assert(m);
871
872 if (m->result == MOUNT_SUCCESS)
873 m->result = f;
874
875 r = unit_kill_context(
876 UNIT(m),
877 &m->kill_context,
878 state_to_kill_operation(state),
879 -1,
880 m->control_pid,
881 false);
882 if (r < 0)
883 goto fail;
884
885 if (r > 0) {
886 r = mount_arm_timer(m, usec_add(now(CLOCK_MONOTONIC), m->timeout_usec));
887 if (r < 0)
888 goto fail;
889
890 mount_set_state(m, state);
891 } else if (state == MOUNT_REMOUNTING_SIGTERM && m->kill_context.send_sigkill)
892 mount_enter_signal(m, MOUNT_REMOUNTING_SIGKILL, MOUNT_SUCCESS);
893 else if (IN_SET(state, MOUNT_REMOUNTING_SIGTERM, MOUNT_REMOUNTING_SIGKILL))
894 mount_enter_mounted(m, MOUNT_SUCCESS);
895 else if (state == MOUNT_UNMOUNTING_SIGTERM && m->kill_context.send_sigkill)
896 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, MOUNT_SUCCESS);
897 else
898 mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
899
900 return;
901
902 fail:
903 log_unit_warning_errno(UNIT(m), r, "Failed to kill processes: %m");
904 mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES);
905 }
906
907 static void mount_enter_unmounting(Mount *m) {
908 int r;
909
910 assert(m);
911
912 /* Start counting our attempts */
913 if (!IN_SET(m->state,
914 MOUNT_UNMOUNTING,
915 MOUNT_UNMOUNTING_SIGTERM,
916 MOUNT_UNMOUNTING_SIGKILL))
917 m->n_retry_umount = 0;
918
919 m->control_command_id = MOUNT_EXEC_UNMOUNT;
920 m->control_command = m->exec_command + MOUNT_EXEC_UNMOUNT;
921
922 r = exec_command_set(m->control_command, UMOUNT_PATH, m->where, "-c", NULL);
923 if (r >= 0 && m->lazy_unmount)
924 r = exec_command_append(m->control_command, "-l", NULL);
925 if (r >= 0 && m->force_unmount)
926 r = exec_command_append(m->control_command, "-f", NULL);
927 if (r < 0)
928 goto fail;
929
930 mount_unwatch_control_pid(m);
931
932 r = mount_spawn(m, m->control_command, &m->control_pid);
933 if (r < 0)
934 goto fail;
935
936 mount_set_state(m, MOUNT_UNMOUNTING);
937
938 return;
939
940 fail:
941 log_unit_warning_errno(UNIT(m), r, "Failed to run 'umount' task: %m");
942 mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES);
943 }
944
945 static void mount_enter_mounting(Mount *m) {
946 int r;
947 MountParameters *p;
948
949 assert(m);
950
951 r = unit_fail_if_noncanonical(UNIT(m), m->where);
952 if (r < 0)
953 goto fail;
954
955 (void) mkdir_p_label(m->where, m->directory_mode);
956
957 unit_warn_if_dir_nonempty(UNIT(m), m->where);
958 unit_warn_leftover_processes(UNIT(m));
959
960 m->control_command_id = MOUNT_EXEC_MOUNT;
961 m->control_command = m->exec_command + MOUNT_EXEC_MOUNT;
962
963 /* Create the source directory for bind-mounts if needed */
964 p = get_mount_parameters_fragment(m);
965 if (p && mount_is_bind(p))
966 (void) mkdir_p_label(p->what, m->directory_mode);
967
968 if (p) {
969 _cleanup_free_ char *opts = NULL;
970
971 r = fstab_filter_options(p->options, "nofail\0" "noauto\0" "auto\0", NULL, NULL, &opts);
972 if (r < 0)
973 goto fail;
974
975 r = exec_command_set(m->control_command, MOUNT_PATH, p->what, m->where, NULL);
976 if (r >= 0 && m->sloppy_options)
977 r = exec_command_append(m->control_command, "-s", NULL);
978 if (r >= 0 && p->fstype)
979 r = exec_command_append(m->control_command, "-t", p->fstype, NULL);
980 if (r >= 0 && !isempty(opts))
981 r = exec_command_append(m->control_command, "-o", opts, NULL);
982 } else
983 r = -ENOENT;
984 if (r < 0)
985 goto fail;
986
987 mount_unwatch_control_pid(m);
988
989 r = mount_spawn(m, m->control_command, &m->control_pid);
990 if (r < 0)
991 goto fail;
992
993 mount_set_state(m, MOUNT_MOUNTING);
994
995 return;
996
997 fail:
998 log_unit_warning_errno(UNIT(m), r, "Failed to run 'mount' task: %m");
999 mount_enter_dead_or_mounted(m, MOUNT_FAILURE_RESOURCES);
1000 }
1001
1002 static void mount_set_reload_result(Mount *m, MountResult result) {
1003 assert(m);
1004
1005 /* Only store the first error we encounter */
1006 if (m->reload_result != MOUNT_SUCCESS)
1007 return;
1008
1009 m->reload_result = result;
1010 }
1011
1012 static void mount_enter_remounting(Mount *m) {
1013 int r;
1014 MountParameters *p;
1015
1016 assert(m);
1017
1018 /* Reset reload result when we are about to start a new remount operation */
1019 m->reload_result = MOUNT_SUCCESS;
1020
1021 m->control_command_id = MOUNT_EXEC_REMOUNT;
1022 m->control_command = m->exec_command + MOUNT_EXEC_REMOUNT;
1023
1024 p = get_mount_parameters_fragment(m);
1025 if (p) {
1026 const char *o;
1027
1028 if (p->options)
1029 o = strjoina("remount,", p->options);
1030 else
1031 o = "remount";
1032
1033 r = exec_command_set(m->control_command, MOUNT_PATH,
1034 p->what, m->where,
1035 "-o", o, NULL);
1036 if (r >= 0 && m->sloppy_options)
1037 r = exec_command_append(m->control_command, "-s", NULL);
1038 if (r >= 0 && p->fstype)
1039 r = exec_command_append(m->control_command, "-t", p->fstype, NULL);
1040 } else
1041 r = -ENOENT;
1042 if (r < 0)
1043 goto fail;
1044
1045 mount_unwatch_control_pid(m);
1046
1047 r = mount_spawn(m, m->control_command, &m->control_pid);
1048 if (r < 0)
1049 goto fail;
1050
1051 mount_set_state(m, MOUNT_REMOUNTING);
1052
1053 return;
1054
1055 fail:
1056 log_unit_warning_errno(UNIT(m), r, "Failed to run 'remount' task: %m");
1057 mount_set_reload_result(m, MOUNT_FAILURE_RESOURCES);
1058 mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
1059 }
1060
1061 static void mount_cycle_clear(Mount *m) {
1062 assert(m);
1063
1064 /* Clear all state we shall forget for this new cycle */
1065
1066 m->result = MOUNT_SUCCESS;
1067 m->reload_result = MOUNT_SUCCESS;
1068 exec_command_reset_status_array(m->exec_command, _MOUNT_EXEC_COMMAND_MAX);
1069 UNIT(m)->reset_accounting = true;
1070 }
1071
1072 static int mount_start(Unit *u) {
1073 Mount *m = MOUNT(u);
1074 int r;
1075
1076 assert(m);
1077
1078 /* We cannot fulfill this request right now, try again later
1079 * please! */
1080 if (IN_SET(m->state,
1081 MOUNT_UNMOUNTING,
1082 MOUNT_UNMOUNTING_SIGTERM,
1083 MOUNT_UNMOUNTING_SIGKILL))
1084 return -EAGAIN;
1085
1086 /* Already on it! */
1087 if (m->state == MOUNT_MOUNTING)
1088 return 0;
1089
1090 assert(IN_SET(m->state, MOUNT_DEAD, MOUNT_FAILED));
1091
1092 r = unit_start_limit_test(u);
1093 if (r < 0) {
1094 mount_enter_dead(m, MOUNT_FAILURE_START_LIMIT_HIT);
1095 return r;
1096 }
1097
1098 r = unit_acquire_invocation_id(u);
1099 if (r < 0)
1100 return r;
1101
1102 mount_cycle_clear(m);
1103 mount_enter_mounting(m);
1104
1105 return 1;
1106 }
1107
1108 static int mount_stop(Unit *u) {
1109 Mount *m = MOUNT(u);
1110
1111 assert(m);
1112
1113 switch (m->state) {
1114
1115 case MOUNT_UNMOUNTING:
1116 case MOUNT_UNMOUNTING_SIGKILL:
1117 case MOUNT_UNMOUNTING_SIGTERM:
1118 /* Already on it */
1119 return 0;
1120
1121 case MOUNT_MOUNTING:
1122 case MOUNT_MOUNTING_DONE:
1123 case MOUNT_REMOUNTING:
1124 /* If we are still waiting for /bin/mount, we go directly into kill mode. */
1125 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGTERM, MOUNT_SUCCESS);
1126 return 0;
1127
1128 case MOUNT_REMOUNTING_SIGTERM:
1129 /* If we are already waiting for a hung remount, convert this to the matching unmounting state */
1130 mount_set_state(m, MOUNT_UNMOUNTING_SIGTERM);
1131 return 0;
1132
1133 case MOUNT_REMOUNTING_SIGKILL:
1134 /* as above */
1135 mount_set_state(m, MOUNT_UNMOUNTING_SIGKILL);
1136 return 0;
1137
1138 case MOUNT_MOUNTED:
1139 mount_enter_unmounting(m);
1140 return 1;
1141
1142 default:
1143 assert_not_reached("Unexpected state.");
1144 }
1145 }
1146
1147 static int mount_reload(Unit *u) {
1148 Mount *m = MOUNT(u);
1149
1150 assert(m);
1151 assert(m->state == MOUNT_MOUNTED);
1152
1153 mount_enter_remounting(m);
1154
1155 return 1;
1156 }
1157
1158 static int mount_serialize(Unit *u, FILE *f, FDSet *fds) {
1159 Mount *m = MOUNT(u);
1160
1161 assert(m);
1162 assert(f);
1163 assert(fds);
1164
1165 (void) serialize_item(f, "state", mount_state_to_string(m->state));
1166 (void) serialize_item(f, "result", mount_result_to_string(m->result));
1167 (void) serialize_item(f, "reload-result", mount_result_to_string(m->reload_result));
1168 (void) serialize_item_format(f, "n-retry-umount", "%u", m->n_retry_umount);
1169
1170 if (m->control_pid > 0)
1171 (void) serialize_item_format(f, "control-pid", PID_FMT, m->control_pid);
1172
1173 if (m->control_command_id >= 0)
1174 (void) serialize_item(f, "control-command", mount_exec_command_to_string(m->control_command_id));
1175
1176 return 0;
1177 }
1178
1179 static int mount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
1180 Mount *m = MOUNT(u);
1181 int r;
1182
1183 assert(u);
1184 assert(key);
1185 assert(value);
1186 assert(fds);
1187
1188 if (streq(key, "state")) {
1189 MountState state;
1190
1191 if ((state = mount_state_from_string(value)) < 0)
1192 log_unit_debug(u, "Failed to parse state value: %s", value);
1193 else
1194 m->deserialized_state = state;
1195
1196 } else if (streq(key, "result")) {
1197 MountResult f;
1198
1199 f = mount_result_from_string(value);
1200 if (f < 0)
1201 log_unit_debug(u, "Failed to parse result value: %s", value);
1202 else if (f != MOUNT_SUCCESS)
1203 m->result = f;
1204
1205 } else if (streq(key, "reload-result")) {
1206 MountResult f;
1207
1208 f = mount_result_from_string(value);
1209 if (f < 0)
1210 log_unit_debug(u, "Failed to parse reload result value: %s", value);
1211 else if (f != MOUNT_SUCCESS)
1212 m->reload_result = f;
1213
1214 } else if (streq(key, "n-retry-umount")) {
1215
1216 r = safe_atou(value, &m->n_retry_umount);
1217 if (r < 0)
1218 log_unit_debug(u, "Failed to parse n-retry-umount value: %s", value);
1219
1220 } else if (streq(key, "control-pid")) {
1221
1222 if (parse_pid(value, &m->control_pid) < 0)
1223 log_unit_debug(u, "Failed to parse control-pid value: %s", value);
1224
1225 } else if (streq(key, "control-command")) {
1226 MountExecCommand id;
1227
1228 id = mount_exec_command_from_string(value);
1229 if (id < 0)
1230 log_unit_debug(u, "Failed to parse exec-command value: %s", value);
1231 else {
1232 m->control_command_id = id;
1233 m->control_command = m->exec_command + id;
1234 }
1235 } else
1236 log_unit_debug(u, "Unknown serialization key: %s", key);
1237
1238 return 0;
1239 }
1240
1241 _pure_ static UnitActiveState mount_active_state(Unit *u) {
1242 assert(u);
1243
1244 return state_translation_table[MOUNT(u)->state];
1245 }
1246
1247 _pure_ static const char *mount_sub_state_to_string(Unit *u) {
1248 assert(u);
1249
1250 return mount_state_to_string(MOUNT(u)->state);
1251 }
1252
1253 _pure_ static bool mount_may_gc(Unit *u) {
1254 Mount *m = MOUNT(u);
1255
1256 assert(m);
1257
1258 if (m->from_proc_self_mountinfo)
1259 return false;
1260
1261 return true;
1262 }
1263
1264 static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
1265 Mount *m = MOUNT(u);
1266 MountResult f;
1267
1268 assert(m);
1269 assert(pid >= 0);
1270
1271 if (pid != m->control_pid)
1272 return;
1273
1274 m->control_pid = 0;
1275
1276 if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
1277 f = MOUNT_SUCCESS;
1278 else if (code == CLD_EXITED)
1279 f = MOUNT_FAILURE_EXIT_CODE;
1280 else if (code == CLD_KILLED)
1281 f = MOUNT_FAILURE_SIGNAL;
1282 else if (code == CLD_DUMPED)
1283 f = MOUNT_FAILURE_CORE_DUMP;
1284 else
1285 assert_not_reached("Unknown code");
1286
1287 if (IN_SET(m->state, MOUNT_REMOUNTING, MOUNT_REMOUNTING_SIGKILL, MOUNT_REMOUNTING_SIGTERM))
1288 mount_set_reload_result(m, f);
1289 else if (m->result == MOUNT_SUCCESS)
1290 m->result = f;
1291
1292 if (m->control_command) {
1293 exec_status_exit(&m->control_command->exec_status, &m->exec_context, pid, code, status);
1294
1295 m->control_command = NULL;
1296 m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
1297 }
1298
1299 unit_log_process_exit(
1300 u, f == MOUNT_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
1301 "Mount process",
1302 mount_exec_command_to_string(m->control_command_id),
1303 code, status);
1304
1305 /* Note that due to the io event priority logic, we can be sure the new mountinfo is loaded
1306 * before we process the SIGCHLD for the mount command. */
1307
1308 switch (m->state) {
1309
1310 case MOUNT_MOUNTING:
1311 /* Our mount point has not appeared in mountinfo. Something went wrong. */
1312
1313 if (f == MOUNT_SUCCESS) {
1314 /* Either /bin/mount has an unexpected definition of success,
1315 * or someone raced us and we lost. */
1316 log_unit_warning(UNIT(m), "Mount process finished, but there is no mount.");
1317 f = MOUNT_FAILURE_PROTOCOL;
1318 }
1319 mount_enter_dead(m, f);
1320 break;
1321
1322 case MOUNT_MOUNTING_DONE:
1323 mount_enter_mounted(m, f);
1324 break;
1325
1326 case MOUNT_REMOUNTING:
1327 case MOUNT_REMOUNTING_SIGTERM:
1328 case MOUNT_REMOUNTING_SIGKILL:
1329 mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
1330 break;
1331
1332 case MOUNT_UNMOUNTING:
1333
1334 if (f == MOUNT_SUCCESS && m->from_proc_self_mountinfo) {
1335
1336 /* Still a mount point? If so, let's try again. Most likely there were multiple mount points
1337 * stacked on top of each other. We might exceed the timeout specified by the user overall,
1338 * but we will stop as soon as any one umount times out. */
1339
1340 if (m->n_retry_umount < RETRY_UMOUNT_MAX) {
1341 log_unit_debug(u, "Mount still present, trying again.");
1342 m->n_retry_umount++;
1343 mount_enter_unmounting(m);
1344 } else {
1345 log_unit_warning(u, "Mount still present after %u attempts to unmount, giving up.", m->n_retry_umount);
1346 mount_enter_mounted(m, f);
1347 }
1348 } else
1349 mount_enter_dead_or_mounted(m, f);
1350
1351 break;
1352
1353 case MOUNT_UNMOUNTING_SIGKILL:
1354 case MOUNT_UNMOUNTING_SIGTERM:
1355 mount_enter_dead_or_mounted(m, f);
1356 break;
1357
1358 default:
1359 assert_not_reached("Uh, control process died at wrong time.");
1360 }
1361
1362 /* Notify clients about changed exit status */
1363 unit_add_to_dbus_queue(u);
1364 }
1365
1366 static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) {
1367 Mount *m = MOUNT(userdata);
1368
1369 assert(m);
1370 assert(m->timer_event_source == source);
1371
1372 switch (m->state) {
1373
1374 case MOUNT_MOUNTING:
1375 case MOUNT_MOUNTING_DONE:
1376 log_unit_warning(UNIT(m), "Mounting timed out. Terminating.");
1377 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGTERM, MOUNT_FAILURE_TIMEOUT);
1378 break;
1379
1380 case MOUNT_REMOUNTING:
1381 log_unit_warning(UNIT(m), "Remounting timed out. Terminating remount process.");
1382 mount_set_reload_result(m, MOUNT_FAILURE_TIMEOUT);
1383 mount_enter_signal(m, MOUNT_REMOUNTING_SIGTERM, MOUNT_SUCCESS);
1384 break;
1385
1386 case MOUNT_REMOUNTING_SIGTERM:
1387 mount_set_reload_result(m, MOUNT_FAILURE_TIMEOUT);
1388
1389 if (m->kill_context.send_sigkill) {
1390 log_unit_warning(UNIT(m), "Remounting timed out. Killing.");
1391 mount_enter_signal(m, MOUNT_REMOUNTING_SIGKILL, MOUNT_SUCCESS);
1392 } else {
1393 log_unit_warning(UNIT(m), "Remounting timed out. Skipping SIGKILL. Ignoring.");
1394 mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
1395 }
1396 break;
1397
1398 case MOUNT_REMOUNTING_SIGKILL:
1399 mount_set_reload_result(m, MOUNT_FAILURE_TIMEOUT);
1400
1401 log_unit_warning(UNIT(m), "Mount process still around after SIGKILL. Ignoring.");
1402 mount_enter_dead_or_mounted(m, MOUNT_SUCCESS);
1403 break;
1404
1405 case MOUNT_UNMOUNTING:
1406 log_unit_warning(UNIT(m), "Unmounting timed out. Terminating.");
1407 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGTERM, MOUNT_FAILURE_TIMEOUT);
1408 break;
1409
1410 case MOUNT_UNMOUNTING_SIGTERM:
1411 if (m->kill_context.send_sigkill) {
1412 log_unit_warning(UNIT(m), "Mount process timed out. Killing.");
1413 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, MOUNT_FAILURE_TIMEOUT);
1414 } else {
1415 log_unit_warning(UNIT(m), "Mount process timed out. Skipping SIGKILL. Ignoring.");
1416 mount_enter_dead_or_mounted(m, MOUNT_FAILURE_TIMEOUT);
1417 }
1418 break;
1419
1420 case MOUNT_UNMOUNTING_SIGKILL:
1421 log_unit_warning(UNIT(m), "Mount process still around after SIGKILL. Ignoring.");
1422 mount_enter_dead_or_mounted(m, MOUNT_FAILURE_TIMEOUT);
1423 break;
1424
1425 default:
1426 assert_not_reached("Timeout at wrong time.");
1427 }
1428
1429 return 0;
1430 }
1431
1432 static int update_parameters_proc_self_mount_info(
1433 Mount *m,
1434 const char *what,
1435 const char *options,
1436 const char *fstype) {
1437
1438 MountParameters *p;
1439 int r, q, w;
1440
1441 p = &m->parameters_proc_self_mountinfo;
1442
1443 r = free_and_strdup(&p->what, what);
1444 if (r < 0)
1445 return r;
1446
1447 q = free_and_strdup(&p->options, options);
1448 if (q < 0)
1449 return q;
1450
1451 w = free_and_strdup(&p->fstype, fstype);
1452 if (w < 0)
1453 return w;
1454
1455 return r > 0 || q > 0 || w > 0;
1456 }
1457
1458 static int mount_setup_new_unit(
1459 Manager *m,
1460 const char *name,
1461 const char *what,
1462 const char *where,
1463 const char *options,
1464 const char *fstype,
1465 MountProcFlags *ret_flags,
1466 Unit **ret) {
1467
1468 _cleanup_(unit_freep) Unit *u = NULL;
1469 int r;
1470
1471 assert(m);
1472 assert(name);
1473 assert(ret_flags);
1474 assert(ret);
1475
1476 r = unit_new_for_name(m, sizeof(Mount), name, &u);
1477 if (r < 0)
1478 return r;
1479
1480 r = free_and_strdup(&u->source_path, "/proc/self/mountinfo");
1481 if (r < 0)
1482 return r;
1483
1484 r = free_and_strdup(&MOUNT(u)->where, where);
1485 if (r < 0)
1486 return r;
1487
1488 r = update_parameters_proc_self_mount_info(MOUNT(u), what, options, fstype);
1489 if (r < 0)
1490 return r;
1491
1492 /* This unit was generated because /proc/self/mountinfo reported it. Remember this, so that by the time we load
1493 * the unit file for it (and thus add in extra deps right after) we know what source to attributes the deps
1494 * to.*/
1495 MOUNT(u)->from_proc_self_mountinfo = true;
1496
1497 /* We have only allocated the stub now, let's enqueue this unit for loading now, so that everything else is
1498 * loaded in now. */
1499 unit_add_to_load_queue(u);
1500
1501 *ret_flags = MOUNT_PROC_IS_MOUNTED | MOUNT_PROC_JUST_MOUNTED | MOUNT_PROC_JUST_CHANGED;
1502 *ret = TAKE_PTR(u);
1503 return 0;
1504 }
1505
1506 static int mount_setup_existing_unit(
1507 Unit *u,
1508 const char *what,
1509 const char *where,
1510 const char *options,
1511 const char *fstype,
1512 MountProcFlags *ret_flags) {
1513
1514 MountProcFlags flags = MOUNT_PROC_IS_MOUNTED;
1515 int r;
1516
1517 assert(u);
1518 assert(flags);
1519
1520 if (!MOUNT(u)->where) {
1521 MOUNT(u)->where = strdup(where);
1522 if (!MOUNT(u)->where)
1523 return -ENOMEM;
1524 }
1525
1526 r = update_parameters_proc_self_mount_info(MOUNT(u), what, options, fstype);
1527 if (r < 0)
1528 return r;
1529 if (r > 0)
1530 flags |= MOUNT_PROC_JUST_CHANGED;
1531
1532 if (!MOUNT(u)->from_proc_self_mountinfo) {
1533 flags |= MOUNT_PROC_JUST_MOUNTED;
1534 MOUNT(u)->from_proc_self_mountinfo = true;
1535 }
1536
1537 if (IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_BAD_SETTING, UNIT_ERROR)) {
1538 /* The unit was previously not found or otherwise not loaded. Now that the unit shows up in
1539 * /proc/self/mountinfo we should reconsider it this, hence set it to UNIT_LOADED. */
1540 u->load_state = UNIT_LOADED;
1541 u->load_error = 0;
1542
1543 flags |= MOUNT_PROC_JUST_CHANGED;
1544 }
1545
1546 if (FLAGS_SET(flags, MOUNT_PROC_JUST_CHANGED)) {
1547 /* If things changed, then make sure that all deps are regenerated. Let's
1548 * first remove all automatic deps, and then add in the new ones. */
1549
1550 unit_remove_dependencies(u, UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT);
1551
1552 r = mount_add_extras(MOUNT(u));
1553 if (r < 0)
1554 return r;
1555 }
1556
1557 *ret_flags = flags;
1558 return 0;
1559 }
1560
1561 static int mount_setup_unit(
1562 Manager *m,
1563 const char *what,
1564 const char *where,
1565 const char *options,
1566 const char *fstype,
1567 bool set_flags) {
1568
1569 _cleanup_free_ char *e = NULL;
1570 MountProcFlags flags;
1571 Unit *u;
1572 int r;
1573
1574 assert(m);
1575 assert(what);
1576 assert(where);
1577 assert(options);
1578 assert(fstype);
1579
1580 /* Ignore API mount points. They should never be referenced in
1581 * dependencies ever. */
1582 if (mount_point_is_api(where) || mount_point_ignore(where))
1583 return 0;
1584
1585 if (streq(fstype, "autofs"))
1586 return 0;
1587
1588 /* probably some kind of swap, ignore */
1589 if (!is_path(where))
1590 return 0;
1591
1592 r = unit_name_from_path(where, ".mount", &e);
1593 if (r < 0)
1594 return log_error_errno(r, "Failed to generate unit name from path '%s': %m", where);
1595
1596 u = manager_get_unit(m, e);
1597 if (u)
1598 r = mount_setup_existing_unit(u, what, where, options, fstype, &flags);
1599 else
1600 /* First time we see this mount point meaning that it's not been initiated by a mount unit but rather
1601 * by the sysadmin having called mount(8) directly. */
1602 r = mount_setup_new_unit(m, e, what, where, options, fstype, &flags, &u);
1603 if (r < 0)
1604 return log_warning_errno(r, "Failed to set up mount unit: %m");
1605
1606 /* If the mount changed properties or state, let's notify our clients */
1607 if (flags & (MOUNT_PROC_JUST_CHANGED|MOUNT_PROC_JUST_MOUNTED))
1608 unit_add_to_dbus_queue(u);
1609
1610 if (set_flags)
1611 MOUNT(u)->proc_flags = flags;
1612
1613 return 0;
1614 }
1615
1616 static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
1617 _cleanup_(mnt_free_tablep) struct libmnt_table *t = NULL;
1618 _cleanup_(mnt_free_iterp) struct libmnt_iter *i = NULL;
1619 int r;
1620
1621 assert(m);
1622
1623 t = mnt_new_table();
1624 i = mnt_new_iter(MNT_ITER_FORWARD);
1625 if (!t || !i)
1626 return log_oom();
1627
1628 r = mnt_table_parse_mtab(t, NULL);
1629 if (r < 0)
1630 return log_error_errno(r, "Failed to parse /proc/self/mountinfo: %m");
1631
1632 for (;;) {
1633 struct libmnt_fs *fs;
1634 const char *device, *path, *options, *fstype;
1635 _cleanup_free_ char *d = NULL, *p = NULL;
1636 int k;
1637
1638 k = mnt_table_next_fs(t, i, &fs);
1639 if (k == 1)
1640 break;
1641 if (k < 0)
1642 return log_error_errno(k, "Failed to get next entry from /proc/self/mountinfo: %m");
1643
1644 device = mnt_fs_get_source(fs);
1645 path = mnt_fs_get_target(fs);
1646 options = mnt_fs_get_options(fs);
1647 fstype = mnt_fs_get_fstype(fs);
1648
1649 if (!device || !path)
1650 continue;
1651
1652 if (cunescape(device, UNESCAPE_RELAX, &d) < 0)
1653 return log_oom();
1654
1655 if (cunescape(path, UNESCAPE_RELAX, &p) < 0)
1656 return log_oom();
1657
1658 device_found_node(m, d, DEVICE_FOUND_MOUNT, DEVICE_FOUND_MOUNT);
1659
1660 (void) mount_setup_unit(m, d, p, options, fstype, set_flags);
1661 }
1662
1663 return 0;
1664 }
1665
1666 static void mount_shutdown(Manager *m) {
1667 assert(m);
1668
1669 m->mount_timeout_source = sd_event_source_unref(m->mount_timeout_source);
1670 m->mount_event_source = sd_event_source_unref(m->mount_event_source);
1671
1672 mnt_unref_monitor(m->mount_monitor);
1673 m->mount_monitor = NULL;
1674 }
1675
1676 static int mount_get_timeout(Unit *u, usec_t *timeout) {
1677 Mount *m = MOUNT(u);
1678 usec_t t;
1679 int r;
1680
1681 if (!m->timer_event_source)
1682 return 0;
1683
1684 r = sd_event_source_get_time(m->timer_event_source, &t);
1685 if (r < 0)
1686 return r;
1687 if (t == USEC_INFINITY)
1688 return 0;
1689
1690 *timeout = t;
1691 return 1;
1692 }
1693
1694 static void mount_enumerate_perpetual(Manager *m) {
1695 Unit *u;
1696 int r;
1697
1698 assert(m);
1699
1700 /* Whatever happens, we know for sure that the root directory is around, and cannot go away. Let's
1701 * unconditionally synthesize it here and mark it as perpetual. */
1702
1703 u = manager_get_unit(m, SPECIAL_ROOT_MOUNT);
1704 if (!u) {
1705 r = unit_new_for_name(m, sizeof(Mount), SPECIAL_ROOT_MOUNT, &u);
1706 if (r < 0) {
1707 log_error_errno(r, "Failed to allocate the special " SPECIAL_ROOT_MOUNT " unit: %m");
1708 return;
1709 }
1710 }
1711
1712 u->perpetual = true;
1713 MOUNT(u)->deserialized_state = MOUNT_MOUNTED;
1714
1715 unit_add_to_load_queue(u);
1716 unit_add_to_dbus_queue(u);
1717 }
1718
1719 static bool mount_is_mounted(Mount *m) {
1720 assert(m);
1721
1722 return UNIT(m)->perpetual || FLAGS_SET(m->proc_flags, MOUNT_PROC_IS_MOUNTED);
1723 }
1724
1725 static void mount_enumerate(Manager *m) {
1726 int r;
1727
1728 assert(m);
1729
1730 mnt_init_debug(0);
1731
1732 if (!m->mount_monitor) {
1733 int fd;
1734
1735 m->mount_monitor = mnt_new_monitor();
1736 if (!m->mount_monitor) {
1737 log_oom();
1738 goto fail;
1739 }
1740
1741 r = mnt_monitor_enable_kernel(m->mount_monitor, 1);
1742 if (r < 0) {
1743 log_error_errno(r, "Failed to enable watching of kernel mount events: %m");
1744 goto fail;
1745 }
1746
1747 r = mnt_monitor_enable_userspace(m->mount_monitor, 1, NULL);
1748 if (r < 0) {
1749 log_error_errno(r, "Failed to enable watching of userspace mount events: %m");
1750 goto fail;
1751 }
1752
1753 /* mnt_unref_monitor() will close the fd */
1754 fd = r = mnt_monitor_get_fd(m->mount_monitor);
1755 if (r < 0) {
1756 log_error_errno(r, "Failed to acquire watch file descriptor: %m");
1757 goto fail;
1758 }
1759
1760 r = sd_event_add_io(m->event, &m->mount_event_source, fd, EPOLLIN, mount_dispatch_io, m);
1761 if (r < 0) {
1762 log_error_errno(r, "Failed to watch mount file descriptor: %m");
1763 goto fail;
1764 }
1765
1766 r = sd_event_source_set_priority(m->mount_event_source, SD_EVENT_PRIORITY_NORMAL-10);
1767 if (r < 0) {
1768 log_error_errno(r, "Failed to adjust mount watch priority: %m");
1769 goto fail;
1770 }
1771
1772 (void) sd_event_source_set_description(m->mount_event_source, "mount-monitor-dispatch");
1773 }
1774
1775 r = mount_load_proc_self_mountinfo(m, false);
1776 if (r < 0)
1777 goto fail;
1778
1779 return;
1780
1781 fail:
1782 mount_shutdown(m);
1783 }
1784
1785 static void mount_process_proc_self_mountinfo(Manager *m);
1786
1787 static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
1788 Manager *m = userdata;
1789 int r;
1790 usec_t next_read = usec_add(m->mount_last_read_usec,
1791 m->mount_last_duration_usec * 10);
1792
1793 if (now(CLOCK_MONOTONIC) < next_read) {
1794 /* The (current) API for getting mount events from the Linux kernel
1795 * involves getting a "something changed" notification, and then having
1796 * to re-read the entire /proc/self/mountinfo file. When there are lots
1797 * of mountpoints, this file is large and parsing it can take noticeable
1798 * time. As most of the file won't have changed, this can be seen as wasted time.
1799 * If there is a "mount storm" such as 1000 mount points being created
1800 * in quick succession, this will result in 1000 successive notification.
1801 * If we respond to every notification, we will do quadratically more work
1802 * than if we respond just once after all the notifications have arrived.
1803 * In this (pathological) case, a delay in scheduling would actually
1804 * improve throughput as we would combine notifications and parse
1805 * the file less often. We cannot expect the scheduler to notice
1806 * this pathology without help.
1807 * So when the rate of notifications means we are spending more than
1808 * 10% of real time handling them, we set a timer and stop listening
1809 * to notifications for a while.
1810 * If/when Linux provides an API which provides only details of what
1811 * has changed, this rate-limiting can be removed.
1812 */
1813
1814 r = sd_event_source_set_enabled(source, SD_EVENT_OFF);
1815 if (r < 0)
1816 log_warning_errno(r, "Failed to disable monitoring of /proc/self/mounting, ignoring: %m");
1817 if (!m->mount_timeout_source) {
1818 r = sd_event_add_time(m->event, &m->mount_timeout_source,
1819 CLOCK_MONOTONIC,
1820 next_read,
1821 0,
1822 mount_dispatch_proc_self_mountinfo_timer,
1823 m);
1824 if (r < 0)
1825 log_warning_errno(r, "Failed to set timeout to reread /proc/self/mounting, ignoring: %m");
1826 }
1827 return 0;
1828 }
1829
1830 assert(m);
1831 assert(revents & EPOLLIN);
1832
1833 if (fd == mnt_monitor_get_fd(m->mount_monitor)) {
1834 bool rescan = false;
1835
1836 /* Drain all events and verify that the event is valid.
1837 *
1838 * Note that libmount also monitors /run/mount mkdir if the
1839 * directory does not exist yet. The mkdir may generate event
1840 * which is irrelevant for us.
1841 *
1842 * error: r < 0; valid: r == 0, false positive: rc == 1 */
1843 do {
1844 r = mnt_monitor_next_change(m->mount_monitor, NULL, NULL);
1845 if (r == 0)
1846 rescan = true;
1847 else if (r < 0)
1848 return log_error_errno(r, "Failed to drain libmount events: %m");
1849 } while (r == 0);
1850
1851 log_debug("libmount event [rescan: %s]", yes_no(rescan));
1852 if (!rescan)
1853 return 0;
1854 }
1855
1856 mount_process_proc_self_mountinfo(m);
1857 return 0;
1858 }
1859
1860 static int mount_dispatch_proc_self_mountinfo_timer(sd_event_source *source, usec_t usec, void *userdata) {
1861 Manager *m = userdata;
1862 int r;
1863
1864 r = sd_event_source_set_enabled(m->mount_event_source, SD_EVENT_ON);
1865 if (r < 0)
1866 log_warning_errno(r, "Failed to reenable /proc/self/mountinfo monitor, ignoring: %m");
1867 m->mount_timeout_source = sd_event_source_unref(source);
1868 mount_process_proc_self_mountinfo(m);
1869 return 0;
1870 }
1871
1872 static void mount_process_proc_self_mountinfo(Manager *m) {
1873 _cleanup_set_free_free_ Set *around = NULL, *gone = NULL;
1874 const char *what;
1875 Iterator i;
1876 Unit *u;
1877 int r;
1878
1879 m->mount_last_read_usec = now(CLOCK_MONOTONIC);
1880 /* If an error occurs, assume 10ms */
1881 m->mount_last_duration_usec = 10 * USEC_PER_MSEC;
1882
1883 r = mount_load_proc_self_mountinfo(m, true);
1884 if (r < 0) {
1885 /* Reset flags, just in case, for later calls */
1886 LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_MOUNT])
1887 MOUNT(u)->proc_flags = 0;
1888
1889 return;
1890 }
1891
1892 manager_dispatch_load_queue(m);
1893
1894 LIST_FOREACH(units_by_type, u, m->units_by_type[UNIT_MOUNT]) {
1895 Mount *mount = MOUNT(u);
1896
1897 if (!mount_is_mounted(mount)) {
1898
1899 /* A mount point is not around right now. It
1900 * might be gone, or might never have
1901 * existed. */
1902
1903 if (mount->from_proc_self_mountinfo &&
1904 mount->parameters_proc_self_mountinfo.what) {
1905
1906 /* Remember that this device might just have disappeared */
1907 if (set_ensure_allocated(&gone, &path_hash_ops) < 0 ||
1908 set_put_strdup(gone, mount->parameters_proc_self_mountinfo.what) < 0)
1909 log_oom(); /* we don't care too much about OOM here... */
1910 }
1911
1912 mount->from_proc_self_mountinfo = false;
1913
1914 switch (mount->state) {
1915
1916 case MOUNT_MOUNTED:
1917 /* This has just been unmounted by somebody else, follow the state change. */
1918 mount_enter_dead(mount, MOUNT_SUCCESS);
1919 break;
1920
1921 default:
1922 break;
1923 }
1924
1925 } else if (mount->proc_flags & (MOUNT_PROC_JUST_MOUNTED|MOUNT_PROC_JUST_CHANGED)) {
1926
1927 /* A mount point was added or changed */
1928
1929 switch (mount->state) {
1930
1931 case MOUNT_DEAD:
1932 case MOUNT_FAILED:
1933
1934 /* This has just been mounted by somebody else, follow the state change, but let's
1935 * generate a new invocation ID for this implicitly and automatically. */
1936 (void) unit_acquire_invocation_id(u);
1937 mount_cycle_clear(mount);
1938 mount_enter_mounted(mount, MOUNT_SUCCESS);
1939 break;
1940
1941 case MOUNT_MOUNTING:
1942 mount_set_state(mount, MOUNT_MOUNTING_DONE);
1943 break;
1944
1945 default:
1946 /* Nothing really changed, but let's
1947 * issue an notification call
1948 * nonetheless, in case somebody is
1949 * waiting for this. (e.g. file system
1950 * ro/rw remounts.) */
1951 mount_set_state(mount, mount->state);
1952 break;
1953 }
1954 }
1955
1956 if (mount_is_mounted(mount) &&
1957 mount->from_proc_self_mountinfo &&
1958 mount->parameters_proc_self_mountinfo.what) {
1959 /* Track devices currently used */
1960
1961 if (set_ensure_allocated(&around, &path_hash_ops) < 0 ||
1962 set_put_strdup(around, mount->parameters_proc_self_mountinfo.what) < 0)
1963 log_oom();
1964 }
1965
1966 /* Reset the flags for later calls */
1967 mount->proc_flags = 0;
1968 }
1969
1970 SET_FOREACH(what, gone, i) {
1971 if (set_contains(around, what))
1972 continue;
1973
1974 /* Let the device units know that the device is no longer mounted */
1975 device_found_node(m, what, 0, DEVICE_FOUND_MOUNT);
1976 }
1977 m->mount_last_duration_usec = usec_sub_unsigned(now(CLOCK_MONOTONIC),
1978 m->mount_last_read_usec);
1979 }
1980
1981 static void mount_reset_failed(Unit *u) {
1982 Mount *m = MOUNT(u);
1983
1984 assert(m);
1985
1986 if (m->state == MOUNT_FAILED)
1987 mount_set_state(m, MOUNT_DEAD);
1988
1989 m->result = MOUNT_SUCCESS;
1990 m->reload_result = MOUNT_SUCCESS;
1991 }
1992
1993 static int mount_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
1994 Mount *m = MOUNT(u);
1995
1996 assert(m);
1997
1998 return unit_kill_common(u, who, signo, -1, MOUNT(u)->control_pid, error);
1999 }
2000
2001 static int mount_control_pid(Unit *u) {
2002 Mount *m = MOUNT(u);
2003
2004 assert(m);
2005
2006 return m->control_pid;
2007 }
2008
2009 static const char* const mount_exec_command_table[_MOUNT_EXEC_COMMAND_MAX] = {
2010 [MOUNT_EXEC_MOUNT] = "ExecMount",
2011 [MOUNT_EXEC_UNMOUNT] = "ExecUnmount",
2012 [MOUNT_EXEC_REMOUNT] = "ExecRemount",
2013 };
2014
2015 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command, MountExecCommand);
2016
2017 static const char* const mount_result_table[_MOUNT_RESULT_MAX] = {
2018 [MOUNT_SUCCESS] = "success",
2019 [MOUNT_FAILURE_RESOURCES] = "resources",
2020 [MOUNT_FAILURE_TIMEOUT] = "timeout",
2021 [MOUNT_FAILURE_EXIT_CODE] = "exit-code",
2022 [MOUNT_FAILURE_SIGNAL] = "signal",
2023 [MOUNT_FAILURE_CORE_DUMP] = "core-dump",
2024 [MOUNT_FAILURE_START_LIMIT_HIT] = "start-limit-hit",
2025 [MOUNT_FAILURE_PROTOCOL] = "protocol",
2026 };
2027
2028 DEFINE_STRING_TABLE_LOOKUP(mount_result, MountResult);
2029
2030 const UnitVTable mount_vtable = {
2031 .object_size = sizeof(Mount),
2032 .exec_context_offset = offsetof(Mount, exec_context),
2033 .cgroup_context_offset = offsetof(Mount, cgroup_context),
2034 .kill_context_offset = offsetof(Mount, kill_context),
2035 .exec_runtime_offset = offsetof(Mount, exec_runtime),
2036 .dynamic_creds_offset = offsetof(Mount, dynamic_creds),
2037
2038 .sections =
2039 "Unit\0"
2040 "Mount\0"
2041 "Install\0",
2042 .private_section = "Mount",
2043
2044 .init = mount_init,
2045 .load = mount_load,
2046 .done = mount_done,
2047
2048 .coldplug = mount_coldplug,
2049
2050 .dump = mount_dump,
2051
2052 .start = mount_start,
2053 .stop = mount_stop,
2054 .reload = mount_reload,
2055
2056 .kill = mount_kill,
2057
2058 .serialize = mount_serialize,
2059 .deserialize_item = mount_deserialize_item,
2060
2061 .active_state = mount_active_state,
2062 .sub_state_to_string = mount_sub_state_to_string,
2063
2064 .may_gc = mount_may_gc,
2065
2066 .sigchld_event = mount_sigchld_event,
2067
2068 .reset_failed = mount_reset_failed,
2069
2070 .control_pid = mount_control_pid,
2071
2072 .bus_vtable = bus_mount_vtable,
2073 .bus_set_property = bus_mount_set_property,
2074 .bus_commit_properties = bus_mount_commit_properties,
2075
2076 .get_timeout = mount_get_timeout,
2077
2078 .can_transient = true,
2079
2080 .enumerate_perpetual = mount_enumerate_perpetual,
2081 .enumerate = mount_enumerate,
2082 .shutdown = mount_shutdown,
2083
2084 .status_message_formats = {
2085 .starting_stopping = {
2086 [0] = "Mounting %s...",
2087 [1] = "Unmounting %s...",
2088 },
2089 .finished_start_job = {
2090 [JOB_DONE] = "Mounted %s.",
2091 [JOB_FAILED] = "Failed to mount %s.",
2092 [JOB_TIMEOUT] = "Timed out mounting %s.",
2093 },
2094 .finished_stop_job = {
2095 [JOB_DONE] = "Unmounted %s.",
2096 [JOB_FAILED] = "Failed unmounting %s.",
2097 [JOB_TIMEOUT] = "Timed out unmounting %s.",
2098 },
2099 },
2100 };