]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/automount.c
systemctl: introduce reset-maintenance command
[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_SYSINIT_TARGET, NULL, true)) < 0)
157 return r;
158
159 if ((r = unit_add_two_dependencies_by_name(UNIT(a), UNIT_BEFORE, UNIT_CONFLICTS, 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 if ((m->dev_autofs_fd = open("/dev/autofs", O_CLOEXEC|O_RDONLY)) < 0) {
308 log_error("Failed to open /dev/autofs: %s", strerror(errno));
309 return -errno;
310 }
311
312 init_autofs_dev_ioctl(&param);
313 if (ioctl(m->dev_autofs_fd, AUTOFS_DEV_IOCTL_VERSION, &param) < 0) {
314 close_nointr_nofail(m->dev_autofs_fd);
315 m->dev_autofs_fd = -1;
316 return -errno;
317 }
318
319 log_debug("Autofs kernel version %i.%i", param.ver_major, param.ver_minor);
320
321 return m->dev_autofs_fd;
322 }
323
324 static int open_ioctl_fd(int dev_autofs_fd, const char *where, dev_t devid) {
325 struct autofs_dev_ioctl *param;
326 size_t l;
327 int r;
328
329 assert(dev_autofs_fd >= 0);
330 assert(where);
331
332 l = sizeof(struct autofs_dev_ioctl) + strlen(where) + 1;
333
334 if (!(param = malloc(l)))
335 return -ENOMEM;
336
337 init_autofs_dev_ioctl(param);
338 param->size = l;
339 param->ioctlfd = -1;
340 param->openmount.devid = devid;
341 strcpy(param->path, where);
342
343 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_OPENMOUNT, param) < 0) {
344 r = -errno;
345 goto finish;
346 }
347
348 if (param->ioctlfd < 0) {
349 r = -EIO;
350 goto finish;
351 }
352
353 fd_cloexec(param->ioctlfd, true);
354 r = param->ioctlfd;
355
356 finish:
357 free(param);
358 return r;
359 }
360
361 static int autofs_protocol(int dev_autofs_fd, int ioctl_fd) {
362 uint32_t major, minor;
363 struct autofs_dev_ioctl param;
364
365 assert(dev_autofs_fd >= 0);
366 assert(ioctl_fd >= 0);
367
368 init_autofs_dev_ioctl(&param);
369 param.ioctlfd = ioctl_fd;
370
371 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_PROTOVER, &param) < 0)
372 return -errno;
373
374 major = param.protover.version;
375
376 init_autofs_dev_ioctl(&param);
377 param.ioctlfd = ioctl_fd;
378
379 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_PROTOSUBVER, &param) < 0)
380 return -errno;
381
382 minor = param.protosubver.sub_version;
383
384 log_debug("Autofs protocol version %i.%i", major, minor);
385 return 0;
386 }
387
388 static int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, time_t sec) {
389 struct autofs_dev_ioctl param;
390
391 assert(dev_autofs_fd >= 0);
392 assert(ioctl_fd >= 0);
393
394 init_autofs_dev_ioctl(&param);
395 param.ioctlfd = ioctl_fd;
396 param.timeout.timeout = sec;
397
398 if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param) < 0)
399 return -errno;
400
401 return 0;
402 }
403
404 static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, int status) {
405 struct autofs_dev_ioctl param;
406
407 assert(dev_autofs_fd >= 0);
408 assert(ioctl_fd >= 0);
409
410 init_autofs_dev_ioctl(&param);
411 param.ioctlfd = ioctl_fd;
412
413 if (status) {
414 param.fail.token = token;
415 param.fail.status = status;
416 } else
417 param.ready.token = token;
418
419 if (ioctl(dev_autofs_fd, status ? AUTOFS_DEV_IOCTL_FAIL : AUTOFS_DEV_IOCTL_READY, &param) < 0)
420 return -errno;
421
422 return 0;
423 }
424
425 int automount_send_ready(Automount *a, int status) {
426 int ioctl_fd, r;
427 unsigned token;
428
429 assert(a);
430 assert(status <= 0);
431
432 if (set_isempty(a->tokens))
433 return 0;
434
435 if ((ioctl_fd = open_ioctl_fd(a->meta.manager->dev_autofs_fd, a->where, a->dev_id)) < 0) {
436 r = ioctl_fd;
437 goto fail;
438 }
439
440 if (status)
441 log_debug("Sending failure: %s", strerror(-status));
442 else
443 log_debug("Sending success.");
444
445 /* Autofs thankfully does not hand out 0 as a token */
446 while ((token = PTR_TO_UINT(set_steal_first(a->tokens)))) {
447 int k;
448
449 /* Autofs fun fact II:
450 *
451 * if you pass a positive status code here, the kernel will
452 * freeze! Yay! */
453
454 if ((k = autofs_send_ready(a->meta.manager->dev_autofs_fd,
455 ioctl_fd,
456 token,
457 status)) < 0)
458 r = k;
459 }
460
461 r = 0;
462
463 fail:
464 if (ioctl_fd >= 0)
465 close_nointr_nofail(ioctl_fd);
466
467 return r;
468 }
469
470 static void automount_enter_waiting(Automount *a) {
471 int p[2] = { -1, -1 };
472 char name[32], options[128];
473 bool mounted = false;
474 int r, ioctl_fd = -1, dev_autofs_fd;
475 struct stat st;
476
477 assert(a);
478 assert(a->pipe_fd < 0);
479 assert(a->where);
480
481 if (a->tokens)
482 set_clear(a->tokens);
483
484 if ((dev_autofs_fd = open_dev_autofs(a->meta.manager)) < 0) {
485 r = dev_autofs_fd;
486 goto fail;
487 }
488
489 /* We knowingly ignore the results of this call */
490 mkdir_p(a->where, 0555);
491
492 if (pipe2(p, O_NONBLOCK|O_CLOEXEC) < 0) {
493 r = -errno;
494 goto fail;
495 }
496
497 snprintf(options, sizeof(options), "fd=%i,pgrp=%u,minproto=5,maxproto=5,direct", p[1], (unsigned) getpgrp());
498 char_array_0(options);
499
500 snprintf(name, sizeof(name), "systemd-%u", (unsigned) getpid());
501 char_array_0(name);
502
503 if (mount(name, a->where, "autofs", 0, options) < 0) {
504 r = -errno;
505 goto fail;
506 }
507
508 mounted = true;
509
510 close_nointr_nofail(p[1]);
511 p[1] = -1;
512
513 if (stat(a->where, &st) < 0) {
514 r = -errno;
515 goto fail;
516 }
517
518 if ((ioctl_fd = open_ioctl_fd(dev_autofs_fd, a->where, st.st_dev)) < 0) {
519 r = ioctl_fd;
520 goto fail;
521 }
522
523 if ((r = autofs_protocol(dev_autofs_fd, ioctl_fd)) < 0)
524 goto fail;
525
526 if ((r = autofs_set_timeout(dev_autofs_fd, ioctl_fd, 300)) < 0)
527 goto fail;
528
529 /* Autofs fun fact:
530 *
531 * Unless we close the ioctl fd here, for some weird reason
532 * the direct mount will not receive events from the
533 * kernel. */
534
535 close_nointr_nofail(ioctl_fd);
536 ioctl_fd = -1;
537
538 if ((r = unit_watch_fd(UNIT(a), p[0], EPOLLIN, &a->pipe_watch)) < 0)
539 goto fail;
540
541 a->pipe_fd = p[0];
542 a->dev_id = st.st_dev;
543
544 automount_set_state(a, AUTOMOUNT_WAITING);
545
546 return;
547
548 fail:
549 assert_se(close_pipe(p) == 0);
550
551 if (ioctl_fd >= 0)
552 close_nointr_nofail(ioctl_fd);
553
554 if (mounted)
555 repeat_unmout(a->where);
556
557 log_error("Failed to initialize automounter: %s", strerror(-r));
558 automount_enter_dead(a, false);
559 }
560
561 static void automount_enter_runnning(Automount *a) {
562 int r;
563 struct stat st;
564 DBusError error;
565
566 assert(a);
567 assert(a->mount);
568
569 dbus_error_init(&error);
570
571 /* We don't take mount requests anymore if we are supposed to
572 * shut down anyway */
573 if (a->meta.job && a->meta.job->type == JOB_STOP) {
574 automount_send_ready(a, -EHOSTDOWN);
575 return;
576 }
577
578 mkdir_p(a->where, a->directory_mode);
579
580 /* Before we do anything, let's see if somebody is playing games with us? */
581 if (lstat(a->where, &st) < 0) {
582 log_warning("%s failed stat automount point: %m", a->meta.id);
583 goto fail;
584 }
585
586 if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id)
587 log_info("%s's automount point already active?", a->meta.id);
588 else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, &error, NULL)) < 0) {
589 log_warning("%s failed to queue mount startup job: %s", a->meta.id, bus_error(&error, r));
590 goto fail;
591 }
592
593 automount_set_state(a, AUTOMOUNT_RUNNING);
594 return;
595
596 fail:
597 automount_enter_dead(a, false);
598 dbus_error_free(&error);
599 }
600
601 static int automount_start(Unit *u) {
602 Automount *a = AUTOMOUNT(u);
603
604 assert(a);
605
606 assert(a->state == AUTOMOUNT_DEAD || a->state == AUTOMOUNT_MAINTENANCE);
607
608 if (path_is_mount_point(a->where)) {
609 log_error("Path %s is already a mount point, refusing start for %s", a->where, u->meta.id);
610 return -EEXIST;
611 }
612
613 if (a->mount->meta.load_state != UNIT_LOADED)
614 return -ENOENT;
615
616 a->failure = false;
617 automount_enter_waiting(a);
618 return 0;
619 }
620
621 static int automount_stop(Unit *u) {
622 Automount *a = AUTOMOUNT(u);
623
624 assert(a);
625
626 assert(a->state == AUTOMOUNT_WAITING || a->state == AUTOMOUNT_RUNNING);
627
628 automount_enter_dead(a, true);
629 return 0;
630 }
631
632 static int automount_serialize(Unit *u, FILE *f, FDSet *fds) {
633 Automount *a = AUTOMOUNT(u);
634 void *p;
635 Iterator i;
636
637 assert(a);
638 assert(f);
639 assert(fds);
640
641 unit_serialize_item(u, f, "state", automount_state_to_string(a->state));
642 unit_serialize_item(u, f, "failure", yes_no(a->failure));
643 unit_serialize_item_format(u, f, "dev-id", "%u", (unsigned) a->dev_id);
644
645 SET_FOREACH(p, a->tokens, i)
646 unit_serialize_item_format(u, f, "token", "%u", PTR_TO_UINT(p));
647
648 if (a->pipe_fd >= 0) {
649 int copy;
650
651 if ((copy = fdset_put_dup(fds, a->pipe_fd)) < 0)
652 return copy;
653
654 unit_serialize_item_format(u, f, "pipe-fd", "%i", copy);
655 }
656
657 return 0;
658 }
659
660 static int automount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
661 Automount *a = AUTOMOUNT(u);
662 int r;
663
664 assert(a);
665 assert(fds);
666
667 if (streq(key, "state")) {
668 AutomountState state;
669
670 if ((state = automount_state_from_string(value)) < 0)
671 log_debug("Failed to parse state value %s", value);
672 else
673 a->deserialized_state = state;
674 } else if (streq(key, "failure")) {
675 int b;
676
677 if ((b = parse_boolean(value)) < 0)
678 log_debug("Failed to parse failure value %s", value);
679 else
680 a->failure = b || a->failure;
681 } else if (streq(key, "dev-id")) {
682 unsigned d;
683
684 if (safe_atou(value, &d) < 0)
685 log_debug("Failed to parse dev-id value %s", value);
686 else
687 a->dev_id = (unsigned) d;
688 } else if (streq(key, "token")) {
689 unsigned token;
690
691 if (safe_atou(value, &token) < 0)
692 log_debug("Failed to parse token value %s", value);
693 else {
694 if (!a->tokens)
695 if (!(a->tokens = set_new(trivial_hash_func, trivial_compare_func)))
696 return -ENOMEM;
697
698 if ((r = set_put(a->tokens, UINT_TO_PTR(token))) < 0)
699 return r;
700 }
701 } else if (streq(key, "pipe-fd")) {
702 int fd;
703
704 if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
705 log_debug("Failed to parse pipe-fd value %s", value);
706 else {
707 if (a->pipe_fd >= 0)
708 close_nointr_nofail(a->pipe_fd);
709
710 a->pipe_fd = fdset_remove(fds, fd);
711 }
712 } else
713 log_debug("Unknown serialization key '%s'", key);
714
715 return 0;
716 }
717
718 static UnitActiveState automount_active_state(Unit *u) {
719 assert(u);
720
721 return state_translation_table[AUTOMOUNT(u)->state];
722 }
723
724 static const char *automount_sub_state_to_string(Unit *u) {
725 assert(u);
726
727 return automount_state_to_string(AUTOMOUNT(u)->state);
728 }
729
730 static bool automount_check_gc(Unit *u) {
731 Automount *a = AUTOMOUNT(u);
732
733 assert(a);
734
735 return UNIT_VTABLE(UNIT(a->mount))->check_gc(UNIT(a->mount));
736 }
737
738 static void automount_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
739 Automount *a = AUTOMOUNT(u);
740 union autofs_v5_packet_union packet;
741 ssize_t l;
742 int r;
743
744 assert(a);
745 assert(fd == a->pipe_fd);
746
747 if (events != EPOLLIN) {
748 log_error("Got invalid poll event on pipe.");
749 goto fail;
750 }
751
752 if ((l = loop_read(a->pipe_fd, &packet, sizeof(packet), true)) != sizeof(packet)) {
753 log_error("Invalid read from pipe: %s", l < 0 ? strerror(-l) : "short read");
754 goto fail;
755 }
756
757 switch (packet.hdr.type) {
758
759 case autofs_ptype_missing_direct:
760 log_debug("Got direct mount request for %s", packet.v5_packet.name);
761
762 if (!a->tokens)
763 if (!(a->tokens = set_new(trivial_hash_func, trivial_compare_func))) {
764 log_error("Failed to allocate token set.");
765 goto fail;
766 }
767
768 if ((r = set_put(a->tokens, UINT_TO_PTR(packet.v5_packet.wait_queue_token))) < 0) {
769 log_error("Failed to remember token: %s", strerror(-r));
770 goto fail;
771 }
772
773 automount_enter_runnning(a);
774 break;
775
776 default:
777 log_error("Received unknown automount request %i", packet.hdr.type);
778 break;
779 }
780
781 return;
782
783 fail:
784 automount_enter_dead(a, false);
785 }
786
787 static void automount_shutdown(Manager *m) {
788 assert(m);
789
790 if (m->dev_autofs_fd >= 0)
791 close_nointr_nofail(m->dev_autofs_fd);
792 }
793
794 static void automount_reset_maintenance(Unit *u) {
795 Automount *a = AUTOMOUNT(u);
796
797 assert(a);
798
799 if (a->state == AUTOMOUNT_MAINTENANCE)
800 automount_set_state(a, AUTOMOUNT_DEAD);
801
802 a->failure = false;
803 }
804
805 static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
806 [AUTOMOUNT_DEAD] = "dead",
807 [AUTOMOUNT_WAITING] = "waiting",
808 [AUTOMOUNT_RUNNING] = "running",
809 [AUTOMOUNT_MAINTENANCE] = "maintenance"
810 };
811
812 DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
813
814 const UnitVTable automount_vtable = {
815 .suffix = ".automount",
816
817 .no_alias = true,
818 .no_instances = true,
819
820 .init = automount_init,
821 .load = automount_load,
822 .done = automount_done,
823
824 .coldplug = automount_coldplug,
825
826 .dump = automount_dump,
827
828 .start = automount_start,
829 .stop = automount_stop,
830
831 .serialize = automount_serialize,
832 .deserialize_item = automount_deserialize_item,
833
834 .active_state = automount_active_state,
835 .sub_state_to_string = automount_sub_state_to_string,
836
837 .check_gc = automount_check_gc,
838
839 .fd_event = automount_fd_event,
840
841 .reset_maintenance = automount_reset_maintenance,
842
843 .bus_message_handler = bus_automount_message_handler,
844
845 .shutdown = automount_shutdown
846 };