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