]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/automount.c
clang: fix numerous little issues found with clang-analyzer
[thirdparty/systemd.git] / src / automount.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23 #include <limits.h>
24 #include <sys/mount.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/epoll.h>
28 #include <sys/stat.h>
29 #include <linux/auto_fs4.h>
30 #include <linux/auto_dev-ioctl.h>
31
32 #include "unit.h"
33 #include "automount.h"
34 #include "load-fragment.h"
35 #include "load-dropin.h"
36 #include "unit-name.h"
37 #include "dbus-automount.h"
38 #include "bus-errors.h"
39 #include "special.h"
40
41 static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
42 [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
43 [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
44 [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
45 [AUTOMOUNT_MAINTENANCE] = UNIT_MAINTENANCE
46 };
47
48 static int open_dev_autofs(Manager *m);
49
50 static void automount_init(Unit *u) {
51 Automount *a = AUTOMOUNT(u);
52
53 assert(u);
54 assert(u->meta.load_state == UNIT_STUB);
55
56 a->pipe_watch.fd = a->pipe_fd = -1;
57 a->pipe_watch.type = WATCH_INVALID;
58
59 a->directory_mode = 0755;
60 }
61
62 static void repeat_unmout(const char *path) {
63 assert(path);
64
65 for (;;) {
66 /* If there are multiple mounts on a mount point, this
67 * removes them all */
68
69 if (umount2(path, MNT_DETACH) >= 0)
70 continue;
71
72 if (errno != EINVAL)
73 log_error("Failed to unmount: %m");
74
75 break;
76 }
77 }
78
79 static void unmount_autofs(Automount *a) {
80 assert(a);
81
82 if (a->pipe_fd < 0)
83 return;
84
85 automount_send_ready(a, -EHOSTDOWN);
86
87 unit_unwatch_fd(UNIT(a), &a->pipe_watch);
88 close_nointr_nofail(a->pipe_fd);
89 a->pipe_fd = -1;
90
91 /* If we reload/reexecute things we keep the mount point
92 * around */
93 if (a->where &&
94 (a->meta.manager->exit_code != MANAGER_RELOAD &&
95 a->meta.manager->exit_code != MANAGER_REEXECUTE))
96 repeat_unmout(a->where);
97 }
98
99 static void automount_done(Unit *u) {
100 Automount *a = AUTOMOUNT(u);
101
102 assert(a);
103
104 unmount_autofs(a);
105 a->mount = NULL;
106
107 free(a->where);
108 a->where = NULL;
109
110 set_free(a->tokens);
111 a->tokens = NULL;
112 }
113
114 int automount_add_one_mount_link(Automount *a, Mount *m) {
115 int r;
116
117 assert(a);
118 assert(m);
119
120 if (a->meta.load_state != UNIT_LOADED ||
121 m->meta.load_state != UNIT_LOADED)
122 return 0;
123
124 if (!path_startswith(a->where, m->where))
125 return 0;
126
127 if (path_equal(a->where, m->where))
128 return 0;
129
130 if ((r = unit_add_two_dependencies(UNIT(a), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0)
131 return r;
132
133 return 0;
134 }
135
136 static int automount_add_mount_links(Automount *a) {
137 Meta *other;
138 int r;
139
140 assert(a);
141
142 LIST_FOREACH(units_per_type, other, a->meta.manager->units_per_type[UNIT_MOUNT])
143 if ((r = automount_add_one_mount_link(a, (Mount*) other)) < 0)
144 return r;
145
146 return 0;
147 }
148
149 static int automount_add_default_dependencies(Automount *a) {
150 int r;
151
152 assert(a);
153
154 if (a->meta.manager->running_as == MANAGER_SYSTEM) {
155
156 if ((r = unit_add_dependency_by_name(UNIT(a), UNIT_AFTER, SPECIAL_FSCK_TARGET, NULL, true)) < 0)
157 return r;
158
159 if ((r = unit_add_two_dependencies_by_name(UNIT(a), UNIT_BEFORE, UNIT_CONFLICTED_BY, SPECIAL_UMOUNT_TARGET, NULL, true)) < 0)
160 return r;
161 }
162
163 return 0;
164 }
165
166 static int automount_verify(Automount *a) {
167 bool b;
168 char *e;
169 assert(a);
170
171 if (a->meta.load_state != UNIT_LOADED)
172 return 0;
173
174 if (path_equal(a->where, "/")) {
175 log_error("Cannot have an automount unit for the root directory. Refusing.");
176 return -EINVAL;
177 }
178
179 if (!(e = unit_name_from_path(a->where, ".automount")))
180 return -ENOMEM;
181
182 b = unit_has_name(UNIT(a), e);
183 free(e);
184
185 if (!b) {
186 log_error("%s's Where setting doesn't match unit name. Refusing.", a->meta.id);
187 return -EINVAL;
188 }
189
190 return 0;
191 }
192
193 static int automount_load(Unit *u) {
194 int r;
195 Automount *a = AUTOMOUNT(u);
196
197 assert(u);
198 assert(u->meta.load_state == UNIT_STUB);
199
200 /* Load a .automount file */
201 if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
202 return r;
203
204 if (u->meta.load_state == UNIT_LOADED) {
205
206 if (!a->where)
207 if (!(a->where = unit_name_to_path(u->meta.id)))
208 return -ENOMEM;
209
210 path_kill_slashes(a->where);
211
212 if ((r = automount_add_mount_links(a)) < 0)
213 return r;
214
215 if ((r = unit_load_related_unit(u, ".mount", (Unit**) &a->mount)) < 0)
216 return r;
217
218 if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount), true)) < 0)
219 return r;
220
221 if (a->meta.default_dependencies)
222 if ((r = automount_add_default_dependencies(a)) < 0)
223 return r;
224 }
225
226 return automount_verify(a);
227 }
228
229 static void automount_set_state(Automount *a, AutomountState state) {
230 AutomountState old_state;
231 assert(a);
232
233 old_state = a->state;
234 a->state = state;
235
236 if (state != AUTOMOUNT_WAITING &&
237 state != AUTOMOUNT_RUNNING)
238 unmount_autofs(a);
239
240 if (state != old_state)
241 log_debug("%s changed %s -> %s",
242 a->meta.id,
243 automount_state_to_string(old_state),
244 automount_state_to_string(state));
245
246 unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state]);
247 }
248
249 static int automount_coldplug(Unit *u) {
250 Automount *a = AUTOMOUNT(u);
251 int r;
252
253 assert(a);
254 assert(a->state == AUTOMOUNT_DEAD);
255
256 if (a->deserialized_state != a->state) {
257
258 if ((r = open_dev_autofs(u->meta.manager)) < 0)
259 return r;
260
261 if (a->deserialized_state == AUTOMOUNT_WAITING ||
262 a->deserialized_state == AUTOMOUNT_RUNNING) {
263
264 assert(a->pipe_fd >= 0);
265
266 if ((r = unit_watch_fd(UNIT(a), a->pipe_fd, EPOLLIN, &a->pipe_watch)) < 0)
267 return r;
268 }
269
270 automount_set_state(a, a->deserialized_state);
271 }
272
273 return 0;
274 }
275
276 static void automount_dump(Unit *u, FILE *f, const char *prefix) {
277 Automount *a = AUTOMOUNT(u);
278
279 assert(a);
280
281 fprintf(f,
282 "%sAutomount State: %s\n"
283 "%sWhere: %s\n"
284 "%sDirectoryMode: %04o\n",
285 prefix, automount_state_to_string(a->state),
286 prefix, a->where,
287 prefix, a->directory_mode);
288 }
289
290 static void automount_enter_dead(Automount *a, bool success) {
291 assert(a);
292
293 if (!success)
294 a->failure = true;
295
296 automount_set_state(a, a->failure ? AUTOMOUNT_MAINTENANCE : AUTOMOUNT_DEAD);
297 }
298
299 static int open_dev_autofs(Manager *m) {
300 struct autofs_dev_ioctl param;
301
302 assert(m);
303
304 if (m->dev_autofs_fd >= 0)
305 return m->dev_autofs_fd;
306
307 label_fix("/dev/autofs");
308
309 if ((m->dev_autofs_fd = open("/dev/autofs", O_CLOEXEC|O_RDONLY)) < 0) {
310 log_error("Failed to open /dev/autofs: %s", strerror(errno));
311 return -errno;
312 }
313
314 init_autofs_dev_ioctl(&param);
315 if (ioctl(m->dev_autofs_fd, AUTOFS_DEV_IOCTL_VERSION, &param) < 0) {
316 close_nointr_nofail(m->dev_autofs_fd);
317 m->dev_autofs_fd = -1;
318 return -errno;
319 }
320
321 log_debug("Autofs kernel version %i.%i", param.ver_major, param.ver_minor);
322
323 return m->dev_autofs_fd;
324 }
325
326 static int open_ioctl_fd(int dev_autofs_fd, const char *where, dev_t devid) {
327 struct autofs_dev_ioctl *param;
328 size_t l;
329 int r;
330
331 assert(dev_autofs_fd >= 0);
332 assert(where);
333
334 l = sizeof(struct autofs_dev_ioctl) + strlen(where) + 1;
335
336 if (!(param = malloc(l)))
337 return -ENOMEM;
338
339 init_autofs_dev_ioctl(param);
340 param->size = l;
341 param->ioctlfd = -1;
342 param->openmount.devid = devid;
343 strcpy(param->path, where);
344
345 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_OPENMOUNT, param) < 0) {
346 r = -errno;
347 goto finish;
348 }
349
350 if (param->ioctlfd < 0) {
351 r = -EIO;
352 goto finish;
353 }
354
355 fd_cloexec(param->ioctlfd, true);
356 r = param->ioctlfd;
357
358 finish:
359 free(param);
360 return r;
361 }
362
363 static int autofs_protocol(int dev_autofs_fd, int ioctl_fd) {
364 uint32_t major, minor;
365 struct autofs_dev_ioctl param;
366
367 assert(dev_autofs_fd >= 0);
368 assert(ioctl_fd >= 0);
369
370 init_autofs_dev_ioctl(&param);
371 param.ioctlfd = ioctl_fd;
372
373 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_PROTOVER, &param) < 0)
374 return -errno;
375
376 major = param.protover.version;
377
378 init_autofs_dev_ioctl(&param);
379 param.ioctlfd = ioctl_fd;
380
381 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_PROTOSUBVER, &param) < 0)
382 return -errno;
383
384 minor = param.protosubver.sub_version;
385
386 log_debug("Autofs protocol version %i.%i", major, minor);
387 return 0;
388 }
389
390 static int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, time_t sec) {
391 struct autofs_dev_ioctl param;
392
393 assert(dev_autofs_fd >= 0);
394 assert(ioctl_fd >= 0);
395
396 init_autofs_dev_ioctl(&param);
397 param.ioctlfd = ioctl_fd;
398 param.timeout.timeout = sec;
399
400 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param) < 0)
401 return -errno;
402
403 return 0;
404 }
405
406 static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, int status) {
407 struct autofs_dev_ioctl param;
408
409 assert(dev_autofs_fd >= 0);
410 assert(ioctl_fd >= 0);
411
412 init_autofs_dev_ioctl(&param);
413 param.ioctlfd = ioctl_fd;
414
415 if (status) {
416 param.fail.token = token;
417 param.fail.status = status;
418 } else
419 param.ready.token = token;
420
421 if (ioctl(dev_autofs_fd, status ? AUTOFS_DEV_IOCTL_FAIL : AUTOFS_DEV_IOCTL_READY, &param) < 0)
422 return -errno;
423
424 return 0;
425 }
426
427 int automount_send_ready(Automount *a, int status) {
428 int ioctl_fd, r;
429 unsigned token;
430
431 assert(a);
432 assert(status <= 0);
433
434 if (set_isempty(a->tokens))
435 return 0;
436
437 if ((ioctl_fd = open_ioctl_fd(a->meta.manager->dev_autofs_fd, a->where, a->dev_id)) < 0) {
438 r = ioctl_fd;
439 goto fail;
440 }
441
442 if (status)
443 log_debug("Sending failure: %s", strerror(-status));
444 else
445 log_debug("Sending success.");
446
447 r = 0;
448
449 /* Autofs thankfully does not hand out 0 as a token */
450 while ((token = PTR_TO_UINT(set_steal_first(a->tokens)))) {
451 int k;
452
453 /* Autofs fun fact II:
454 *
455 * if you pass a positive status code here, the kernel will
456 * freeze! Yay! */
457
458 if ((k = autofs_send_ready(a->meta.manager->dev_autofs_fd,
459 ioctl_fd,
460 token,
461 status)) < 0)
462 r = k;
463 }
464
465 fail:
466 if (ioctl_fd >= 0)
467 close_nointr_nofail(ioctl_fd);
468
469 return r;
470 }
471
472 static void automount_enter_waiting(Automount *a) {
473 int p[2] = { -1, -1 };
474 char name[32], options[128];
475 bool mounted = false;
476 int r, ioctl_fd = -1, dev_autofs_fd;
477 struct stat st;
478
479 assert(a);
480 assert(a->pipe_fd < 0);
481 assert(a->where);
482
483 if (a->tokens)
484 set_clear(a->tokens);
485
486 if ((dev_autofs_fd = open_dev_autofs(a->meta.manager)) < 0) {
487 r = dev_autofs_fd;
488 goto fail;
489 }
490
491 /* We knowingly ignore the results of this call */
492 mkdir_p(a->where, 0555);
493
494 if (pipe2(p, O_NONBLOCK|O_CLOEXEC) < 0) {
495 r = -errno;
496 goto fail;
497 }
498
499 snprintf(options, sizeof(options), "fd=%i,pgrp=%u,minproto=5,maxproto=5,direct", p[1], (unsigned) getpgrp());
500 char_array_0(options);
501
502 snprintf(name, sizeof(name), "systemd-%u", (unsigned) getpid());
503 char_array_0(name);
504
505 if (mount(name, a->where, "autofs", 0, options) < 0) {
506 r = -errno;
507 goto fail;
508 }
509
510 mounted = true;
511
512 close_nointr_nofail(p[1]);
513 p[1] = -1;
514
515 if (stat(a->where, &st) < 0) {
516 r = -errno;
517 goto fail;
518 }
519
520 if ((ioctl_fd = open_ioctl_fd(dev_autofs_fd, a->where, st.st_dev)) < 0) {
521 r = ioctl_fd;
522 goto fail;
523 }
524
525 if ((r = autofs_protocol(dev_autofs_fd, ioctl_fd)) < 0)
526 goto fail;
527
528 if ((r = autofs_set_timeout(dev_autofs_fd, ioctl_fd, 300)) < 0)
529 goto fail;
530
531 /* Autofs fun fact:
532 *
533 * Unless we close the ioctl fd here, for some weird reason
534 * the direct mount will not receive events from the
535 * kernel. */
536
537 close_nointr_nofail(ioctl_fd);
538 ioctl_fd = -1;
539
540 if ((r = unit_watch_fd(UNIT(a), p[0], EPOLLIN, &a->pipe_watch)) < 0)
541 goto fail;
542
543 a->pipe_fd = p[0];
544 a->dev_id = st.st_dev;
545
546 automount_set_state(a, AUTOMOUNT_WAITING);
547
548 return;
549
550 fail:
551 assert_se(close_pipe(p) == 0);
552
553 if (ioctl_fd >= 0)
554 close_nointr_nofail(ioctl_fd);
555
556 if (mounted)
557 repeat_unmout(a->where);
558
559 log_error("Failed to initialize automounter: %s", strerror(-r));
560 automount_enter_dead(a, false);
561 }
562
563 static void automount_enter_runnning(Automount *a) {
564 int r;
565 struct stat st;
566 DBusError error;
567
568 assert(a);
569 assert(a->mount);
570
571 dbus_error_init(&error);
572
573 /* We don't take mount requests anymore if we are supposed to
574 * shut down anyway */
575 if (a->meta.job && a->meta.job->type == JOB_STOP) {
576 automount_send_ready(a, -EHOSTDOWN);
577 return;
578 }
579
580 mkdir_p(a->where, a->directory_mode);
581
582 /* Before we do anything, let's see if somebody is playing games with us? */
583 if (lstat(a->where, &st) < 0) {
584 log_warning("%s failed stat automount point: %m", a->meta.id);
585 goto fail;
586 }
587
588 if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id)
589 log_info("%s's automount point already active?", a->meta.id);
590 else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, &error, NULL)) < 0) {
591 log_warning("%s failed to queue mount startup job: %s", a->meta.id, bus_error(&error, r));
592 goto fail;
593 }
594
595 automount_set_state(a, AUTOMOUNT_RUNNING);
596 return;
597
598 fail:
599 automount_enter_dead(a, false);
600 dbus_error_free(&error);
601 }
602
603 static int automount_start(Unit *u) {
604 Automount *a = AUTOMOUNT(u);
605
606 assert(a);
607
608 assert(a->state == AUTOMOUNT_DEAD || a->state == AUTOMOUNT_MAINTENANCE);
609
610 if (path_is_mount_point(a->where)) {
611 log_error("Path %s is already a mount point, refusing start for %s", a->where, u->meta.id);
612 return -EEXIST;
613 }
614
615 if (a->mount->meta.load_state != UNIT_LOADED)
616 return -ENOENT;
617
618 a->failure = false;
619 automount_enter_waiting(a);
620 return 0;
621 }
622
623 static int automount_stop(Unit *u) {
624 Automount *a = AUTOMOUNT(u);
625
626 assert(a);
627
628 assert(a->state == AUTOMOUNT_WAITING || a->state == AUTOMOUNT_RUNNING);
629
630 automount_enter_dead(a, true);
631 return 0;
632 }
633
634 static int automount_serialize(Unit *u, FILE *f, FDSet *fds) {
635 Automount *a = AUTOMOUNT(u);
636 void *p;
637 Iterator i;
638
639 assert(a);
640 assert(f);
641 assert(fds);
642
643 unit_serialize_item(u, f, "state", automount_state_to_string(a->state));
644 unit_serialize_item(u, f, "failure", yes_no(a->failure));
645 unit_serialize_item_format(u, f, "dev-id", "%u", (unsigned) a->dev_id);
646
647 SET_FOREACH(p, a->tokens, i)
648 unit_serialize_item_format(u, f, "token", "%u", PTR_TO_UINT(p));
649
650 if (a->pipe_fd >= 0) {
651 int copy;
652
653 if ((copy = fdset_put_dup(fds, a->pipe_fd)) < 0)
654 return copy;
655
656 unit_serialize_item_format(u, f, "pipe-fd", "%i", copy);
657 }
658
659 return 0;
660 }
661
662 static int automount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
663 Automount *a = AUTOMOUNT(u);
664 int r;
665
666 assert(a);
667 assert(fds);
668
669 if (streq(key, "state")) {
670 AutomountState state;
671
672 if ((state = automount_state_from_string(value)) < 0)
673 log_debug("Failed to parse state value %s", value);
674 else
675 a->deserialized_state = state;
676 } else if (streq(key, "failure")) {
677 int b;
678
679 if ((b = parse_boolean(value)) < 0)
680 log_debug("Failed to parse failure value %s", value);
681 else
682 a->failure = b || a->failure;
683 } else if (streq(key, "dev-id")) {
684 unsigned d;
685
686 if (safe_atou(value, &d) < 0)
687 log_debug("Failed to parse dev-id value %s", value);
688 else
689 a->dev_id = (unsigned) d;
690 } else if (streq(key, "token")) {
691 unsigned token;
692
693 if (safe_atou(value, &token) < 0)
694 log_debug("Failed to parse token value %s", value);
695 else {
696 if (!a->tokens)
697 if (!(a->tokens = set_new(trivial_hash_func, trivial_compare_func)))
698 return -ENOMEM;
699
700 if ((r = set_put(a->tokens, UINT_TO_PTR(token))) < 0)
701 return r;
702 }
703 } else if (streq(key, "pipe-fd")) {
704 int fd;
705
706 if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
707 log_debug("Failed to parse pipe-fd value %s", value);
708 else {
709 if (a->pipe_fd >= 0)
710 close_nointr_nofail(a->pipe_fd);
711
712 a->pipe_fd = fdset_remove(fds, fd);
713 }
714 } else
715 log_debug("Unknown serialization key '%s'", key);
716
717 return 0;
718 }
719
720 static UnitActiveState automount_active_state(Unit *u) {
721 assert(u);
722
723 return state_translation_table[AUTOMOUNT(u)->state];
724 }
725
726 static const char *automount_sub_state_to_string(Unit *u) {
727 assert(u);
728
729 return automount_state_to_string(AUTOMOUNT(u)->state);
730 }
731
732 static bool automount_check_gc(Unit *u) {
733 Automount *a = AUTOMOUNT(u);
734
735 assert(a);
736
737 return UNIT_VTABLE(UNIT(a->mount))->check_gc(UNIT(a->mount));
738 }
739
740 static void automount_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
741 Automount *a = AUTOMOUNT(u);
742 union autofs_v5_packet_union packet;
743 ssize_t l;
744 int r;
745
746 assert(a);
747 assert(fd == a->pipe_fd);
748
749 if (events != EPOLLIN) {
750 log_error("Got invalid poll event on pipe.");
751 goto fail;
752 }
753
754 if ((l = loop_read(a->pipe_fd, &packet, sizeof(packet), true)) != sizeof(packet)) {
755 log_error("Invalid read from pipe: %s", l < 0 ? strerror(-l) : "short read");
756 goto fail;
757 }
758
759 switch (packet.hdr.type) {
760
761 case autofs_ptype_missing_direct:
762 log_debug("Got direct mount request for %s", packet.v5_packet.name);
763
764 if (!a->tokens)
765 if (!(a->tokens = set_new(trivial_hash_func, trivial_compare_func))) {
766 log_error("Failed to allocate token set.");
767 goto fail;
768 }
769
770 if ((r = set_put(a->tokens, UINT_TO_PTR(packet.v5_packet.wait_queue_token))) < 0) {
771 log_error("Failed to remember token: %s", strerror(-r));
772 goto fail;
773 }
774
775 automount_enter_runnning(a);
776 break;
777
778 default:
779 log_error("Received unknown automount request %i", packet.hdr.type);
780 break;
781 }
782
783 return;
784
785 fail:
786 automount_enter_dead(a, false);
787 }
788
789 static void automount_shutdown(Manager *m) {
790 assert(m);
791
792 if (m->dev_autofs_fd >= 0)
793 close_nointr_nofail(m->dev_autofs_fd);
794 }
795
796 static void automount_reset_maintenance(Unit *u) {
797 Automount *a = AUTOMOUNT(u);
798
799 assert(a);
800
801 if (a->state == AUTOMOUNT_MAINTENANCE)
802 automount_set_state(a, AUTOMOUNT_DEAD);
803
804 a->failure = false;
805 }
806
807 static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
808 [AUTOMOUNT_DEAD] = "dead",
809 [AUTOMOUNT_WAITING] = "waiting",
810 [AUTOMOUNT_RUNNING] = "running",
811 [AUTOMOUNT_MAINTENANCE] = "maintenance"
812 };
813
814 DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
815
816 const UnitVTable automount_vtable = {
817 .suffix = ".automount",
818
819 .no_alias = true,
820 .no_instances = true,
821
822 .init = automount_init,
823 .load = automount_load,
824 .done = automount_done,
825
826 .coldplug = automount_coldplug,
827
828 .dump = automount_dump,
829
830 .start = automount_start,
831 .stop = automount_stop,
832
833 .serialize = automount_serialize,
834 .deserialize_item = automount_deserialize_item,
835
836 .active_state = automount_active_state,
837 .sub_state_to_string = automount_sub_state_to_string,
838
839 .check_gc = automount_check_gc,
840
841 .fd_event = automount_fd_event,
842
843 .reset_maintenance = automount_reset_maintenance,
844
845 .bus_message_handler = bus_automount_message_handler,
846
847 .shutdown = automount_shutdown
848 };