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