chiark / gitweb /
db8551e854b2902e6a28ccb2d1310ebdadc5f41f
[elogind.git] / src / mount.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 <stdio.h>
24 #include <mntent.h>
25 #include <sys/epoll.h>
26 #include <signal.h>
27
28 #include "unit.h"
29 #include "mount.h"
30 #include "load-fragment.h"
31 #include "load-dropin.h"
32 #include "log.h"
33 #include "strv.h"
34 #include "mount-setup.h"
35 #include "unit-name.h"
36 #include "mount.h"
37 #include "dbus-mount.h"
38 #include "special.h"
39
40 static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
41         [MOUNT_DEAD] = UNIT_INACTIVE,
42         [MOUNT_MOUNTING] = UNIT_ACTIVATING,
43         [MOUNT_MOUNTING_DONE] = UNIT_ACTIVE,
44         [MOUNT_MOUNTED] = UNIT_ACTIVE,
45         [MOUNT_REMOUNTING] = UNIT_RELOADING,
46         [MOUNT_UNMOUNTING] = UNIT_DEACTIVATING,
47         [MOUNT_MOUNTING_SIGTERM] = UNIT_DEACTIVATING,
48         [MOUNT_MOUNTING_SIGKILL] = UNIT_DEACTIVATING,
49         [MOUNT_REMOUNTING_SIGTERM] = UNIT_RELOADING,
50         [MOUNT_REMOUNTING_SIGKILL] = UNIT_RELOADING,
51         [MOUNT_UNMOUNTING_SIGTERM] = UNIT_DEACTIVATING,
52         [MOUNT_UNMOUNTING_SIGKILL] = UNIT_DEACTIVATING,
53         [MOUNT_MAINTENANCE] = UNIT_MAINTENANCE
54 };
55
56 static void mount_init(Unit *u) {
57         Mount *m = MOUNT(u);
58
59         assert(u);
60         assert(u->meta.load_state == UNIT_STUB);
61
62         m->timeout_usec = DEFAULT_TIMEOUT_USEC;
63         exec_context_init(&m->exec_context);
64
65         m->directory_mode = 0755;
66
67         /* We need to make sure that /bin/mount is always called in
68          * the same process group as us, so that the autofs kernel
69          * side doesn't send us another mount request while we are
70          * already trying to comply its last one. */
71         m->exec_context.no_setsid = true;
72
73         m->timer_watch.type = WATCH_INVALID;
74
75         m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
76 }
77
78 static void mount_unwatch_control_pid(Mount *m) {
79         assert(m);
80
81         if (m->control_pid <= 0)
82                 return;
83
84         unit_unwatch_pid(UNIT(m), m->control_pid);
85         m->control_pid = 0;
86 }
87
88 static void mount_parameters_done(MountParameters *p) {
89         assert(p);
90
91         free(p->what);
92         free(p->options);
93         free(p->fstype);
94
95         p->what = p->options = p->fstype = NULL;
96 }
97
98 static void mount_done(Unit *u) {
99         Mount *m = MOUNT(u);
100
101         assert(m);
102
103         free(m->where);
104         m->where = NULL;
105
106         mount_parameters_done(&m->parameters_etc_fstab);
107         mount_parameters_done(&m->parameters_proc_self_mountinfo);
108         mount_parameters_done(&m->parameters_fragment);
109
110         exec_context_done(&m->exec_context);
111         exec_command_done_array(m->exec_command, _MOUNT_EXEC_COMMAND_MAX);
112         m->control_command = NULL;
113
114         mount_unwatch_control_pid(m);
115
116         unit_unwatch_timer(u, &m->timer_watch);
117 }
118
119 static int mount_add_mount_links(Mount *m) {
120         Meta *other;
121         int r;
122
123         assert(m);
124
125         /* Adds in links to other mount points that might lie below or
126          * above us in the hierarchy */
127
128         LIST_FOREACH(units_per_type, other, m->meta.manager->units_per_type[UNIT_MOUNT]) {
129                 Mount *n = (Mount*) other;
130
131                 if (n == m)
132                         continue;
133
134                 if (n->meta.load_state != UNIT_LOADED)
135                         continue;
136
137                 if (path_startswith(m->where, n->where)) {
138
139                         if ((r = unit_add_dependency(UNIT(m), UNIT_AFTER, UNIT(n), true)) < 0)
140                                 return r;
141
142                         if (n->from_etc_fstab || n->from_fragment)
143                                 if ((r = unit_add_dependency(UNIT(m), UNIT_REQUIRES, UNIT(n), true)) < 0)
144                                         return r;
145
146                 } else if (path_startswith(n->where, m->where)) {
147
148                         if ((r = unit_add_dependency(UNIT(m), UNIT_BEFORE, UNIT(n), true)) < 0)
149                                 return r;
150
151                         if (m->from_etc_fstab || m->from_fragment)
152                                 if ((r = unit_add_dependency(UNIT(n), UNIT_REQUIRES, UNIT(m), true)) < 0)
153                                         return r;
154                 }
155         }
156
157         return 0;
158 }
159
160 static int mount_add_swap_links(Mount *m) {
161         Meta *other;
162         int r;
163
164         assert(m);
165
166         LIST_FOREACH(units_per_type, other, m->meta.manager->units_per_type[UNIT_SWAP])
167                 if ((r = swap_add_one_mount_link((Swap*) other, m)) < 0)
168                         return r;
169
170         return 0;
171 }
172
173 static int mount_add_path_links(Mount *m) {
174         Meta *other;
175         int r;
176
177         assert(m);
178
179         LIST_FOREACH(units_per_type, other, m->meta.manager->units_per_type[UNIT_PATH])
180                 if ((r = path_add_one_mount_link((Path*) other, m)) < 0)
181                         return r;
182
183         return 0;
184 }
185
186 static int mount_add_automount_links(Mount *m) {
187         Meta *other;
188         int r;
189
190         assert(m);
191
192         LIST_FOREACH(units_per_type, other, m->meta.manager->units_per_type[UNIT_AUTOMOUNT])
193                 if ((r = automount_add_one_mount_link((Automount*) other, m)) < 0)
194                         return r;
195
196         return 0;
197 }
198
199 static int mount_add_socket_links(Mount *m) {
200         Meta *other;
201         int r;
202
203         assert(m);
204
205         LIST_FOREACH(units_per_type, other, m->meta.manager->units_per_type[UNIT_SOCKET])
206                 if ((r = socket_add_one_mount_link((Socket*) other, m)) < 0)
207                         return r;
208
209         return 0;
210 }
211
212 static char* mount_test_option(const char *haystack, const char *needle) {
213         struct mntent me;
214
215         assert(needle);
216
217         /* Like glibc's hasmntopt(), but works on a string, not a
218          * struct mntent */
219
220         if (!haystack)
221                 return false;
222
223         zero(me);
224         me.mnt_opts = (char*) haystack;
225
226         return hasmntopt(&me, needle);
227 }
228
229 static int mount_add_target_links(Mount *m) {
230         const char *target;
231         MountParameters *p;
232         Unit *tu;
233         int r;
234         bool noauto, handle, automount, user;
235
236         assert(m);
237
238         if (m->from_fragment)
239                 p = &m->parameters_fragment;
240         else if (m->from_etc_fstab)
241                 p = &m->parameters_etc_fstab;
242         else
243                 return 0;
244
245         noauto = !!mount_test_option(p->options, MNTOPT_NOAUTO);
246         user = mount_test_option(p->options, "user") || mount_test_option(p->options, "users");
247         handle = !!mount_test_option(p->options, "comment=systemd.mount");
248         automount = !!mount_test_option(p->options, "comment=systemd.automount");
249
250         if (mount_test_option(p->options, "_netdev") ||
251             fstype_is_network(p->fstype))
252                 target = SPECIAL_REMOTE_FS_TARGET;
253         else
254                 target = SPECIAL_LOCAL_FS_TARGET;
255
256         if ((r = manager_load_unit(m->meta.manager, target, NULL, &tu)) < 0)
257                 return r;
258
259         if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
260                 Unit *am;
261
262                 if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0)
263                         return r;
264
265                 if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(am), true)) < 0)
266                         return r;
267
268                 return unit_add_dependency(UNIT(am), UNIT_BEFORE, tu, true);
269
270         } else {
271
272                 if (!noauto && handle)
273                         if (user || m->meta.manager->running_as == MANAGER_SYSTEM)
274                                 if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0)
275                                         return r;
276
277                 return unit_add_dependency(UNIT(m), UNIT_BEFORE, tu, true);
278         }
279 }
280
281 static int mount_verify(Mount *m) {
282         bool b;
283         char *e;
284         assert(m);
285
286         if (m->meta.load_state != UNIT_LOADED)
287                 return 0;
288
289         if (!m->from_etc_fstab && !m->from_fragment && !m->from_proc_self_mountinfo)
290                 return -ENOENT;
291
292         if (!(e = unit_name_from_path(m->where, ".mount")))
293                 return -ENOMEM;
294
295         b = unit_has_name(UNIT(m), e);
296         free(e);
297
298         if (!b) {
299                 log_error("%s's Where setting doesn't match unit name. Refusing.", m->meta.id);
300                 return -EINVAL;
301         }
302
303         if (m->meta.fragment_path && !m->parameters_fragment.what) {
304                 log_error("%s's What setting is missing. Refusing.", m->meta.id);
305                 return -EBADMSG;
306         }
307
308         if (m->exec_context.pam_name && m->kill_mode != KILL_CONTROL_GROUP) {
309                 log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", m->meta.id);
310                 return -EINVAL;
311         }
312
313         return 0;
314 }
315
316 static int mount_load(Unit *u) {
317         Mount *m = MOUNT(u);
318         int r;
319
320         assert(u);
321         assert(u->meta.load_state == UNIT_STUB);
322
323         if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
324                 return r;
325
326         /* This is a new unit? Then let's add in some extras */
327         if (u->meta.load_state == UNIT_LOADED) {
328                 const char *what = NULL;
329
330                 if (m->meta.fragment_path)
331                         m->from_fragment = true;
332
333                 if (!m->where)
334                         if (!(m->where = unit_name_to_path(u->meta.id)))
335                                 return -ENOMEM;
336
337                 path_kill_slashes(m->where);
338
339                 if (!m->meta.description)
340                         if ((r = unit_set_description(u, m->where)) < 0)
341                                 return r;
342
343                 if (m->from_fragment && m->parameters_fragment.what)
344                         what = m->parameters_fragment.what;
345                 else if (m->from_etc_fstab && m->parameters_etc_fstab.what)
346                         what = m->parameters_etc_fstab.what;
347                 else if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
348                         what = m->parameters_proc_self_mountinfo.what;
349
350                 if (what)
351                         if ((r = unit_add_node_link(u, what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
352                                 return r;
353
354                 if ((r = mount_add_mount_links(m)) < 0)
355                         return r;
356
357                 if ((r = mount_add_socket_links(m)) < 0)
358                         return r;
359
360                 if ((r = mount_add_swap_links(m)) < 0)
361                         return r;
362
363                 if ((r = mount_add_path_links(m)) < 0)
364                         return r;
365
366                 if ((r = mount_add_automount_links(m)) < 0)
367                         return r;
368
369                 if ((r = mount_add_target_links(m)) < 0)
370                         return r;
371
372                 if ((r = unit_add_default_cgroup(u)) < 0)
373                         return r;
374         }
375
376         return mount_verify(m);
377 }
378
379 static int mount_notify_automount(Mount *m, int status) {
380         Unit *p;
381         int r;
382
383         assert(m);
384
385         if ((r = unit_get_related_unit(UNIT(m), ".automount", &p)) < 0)
386                 return r == -ENOENT ? 0 : r;
387
388         return automount_send_ready(AUTOMOUNT(p), status);
389 }
390
391 static void mount_set_state(Mount *m, MountState state) {
392         MountState old_state;
393         assert(m);
394
395         old_state = m->state;
396         m->state = state;
397
398         if (state != MOUNT_MOUNTING &&
399             state != MOUNT_MOUNTING_DONE &&
400             state != MOUNT_REMOUNTING &&
401             state != MOUNT_UNMOUNTING &&
402             state != MOUNT_MOUNTING_SIGTERM &&
403             state != MOUNT_MOUNTING_SIGKILL &&
404             state != MOUNT_UNMOUNTING_SIGTERM &&
405             state != MOUNT_UNMOUNTING_SIGKILL &&
406             state != MOUNT_REMOUNTING_SIGTERM &&
407             state != MOUNT_REMOUNTING_SIGKILL) {
408                 unit_unwatch_timer(UNIT(m), &m->timer_watch);
409                 mount_unwatch_control_pid(m);
410                 m->control_command = NULL;
411                 m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
412         }
413
414         if (state == MOUNT_MOUNTED ||
415             state == MOUNT_REMOUNTING)
416                 mount_notify_automount(m, 0);
417         else if (state == MOUNT_DEAD ||
418                  state == MOUNT_UNMOUNTING ||
419                  state == MOUNT_MOUNTING_SIGTERM ||
420                  state == MOUNT_MOUNTING_SIGKILL ||
421                  state == MOUNT_REMOUNTING_SIGTERM ||
422                  state == MOUNT_REMOUNTING_SIGKILL ||
423                  state == MOUNT_UNMOUNTING_SIGTERM ||
424                  state == MOUNT_UNMOUNTING_SIGKILL ||
425                  state == MOUNT_MAINTENANCE)
426                 mount_notify_automount(m, -ENODEV);
427
428         if (state != old_state)
429                 log_debug("%s changed %s -> %s",
430                           m->meta.id,
431                           mount_state_to_string(old_state),
432                           mount_state_to_string(state));
433
434         unit_notify(UNIT(m), state_translation_table[old_state], state_translation_table[state]);
435 }
436
437 static int mount_coldplug(Unit *u) {
438         Mount *m = MOUNT(u);
439         MountState new_state = MOUNT_DEAD;
440         int r;
441
442         assert(m);
443         assert(m->state == MOUNT_DEAD);
444
445         if (m->deserialized_state != m->state)
446                 new_state = m->deserialized_state;
447         else if (m->from_proc_self_mountinfo)
448                 new_state = MOUNT_MOUNTED;
449
450         if (new_state != m->state) {
451
452                 if (new_state == MOUNT_MOUNTING ||
453                     new_state == MOUNT_MOUNTING_DONE ||
454                     new_state == MOUNT_REMOUNTING ||
455                     new_state == MOUNT_UNMOUNTING ||
456                     new_state == MOUNT_MOUNTING_SIGTERM ||
457                     new_state == MOUNT_MOUNTING_SIGKILL ||
458                     new_state == MOUNT_UNMOUNTING_SIGTERM ||
459                     new_state == MOUNT_UNMOUNTING_SIGKILL ||
460                     new_state == MOUNT_REMOUNTING_SIGTERM ||
461                     new_state == MOUNT_REMOUNTING_SIGKILL) {
462
463                         if (m->control_pid <= 0)
464                                 return -EBADMSG;
465
466                         if ((r = unit_watch_pid(UNIT(m), m->control_pid)) < 0)
467                                 return r;
468
469                         if ((r = unit_watch_timer(UNIT(m), m->timeout_usec, &m->timer_watch)) < 0)
470                                 return r;
471                 }
472
473                 mount_set_state(m, new_state);
474         }
475
476         return 0;
477 }
478
479 static void mount_dump(Unit *u, FILE *f, const char *prefix) {
480         Mount *m = MOUNT(u);
481         MountParameters *p;
482
483         assert(m);
484         assert(f);
485
486         if (m->from_proc_self_mountinfo)
487                 p = &m->parameters_proc_self_mountinfo;
488         else if (m->from_fragment)
489                 p = &m->parameters_fragment;
490         else
491                 p = &m->parameters_etc_fstab;
492
493         fprintf(f,
494                 "%sMount State: %s\n"
495                 "%sWhere: %s\n"
496                 "%sWhat: %s\n"
497                 "%sFile System Type: %s\n"
498                 "%sOptions: %s\n"
499                 "%sFrom /etc/fstab: %s\n"
500                 "%sFrom /proc/self/mountinfo: %s\n"
501                 "%sFrom fragment: %s\n"
502                 "%sKillMode: %s\n"
503                 "%sDirectoryMode: %04o\n",
504                 prefix, mount_state_to_string(m->state),
505                 prefix, m->where,
506                 prefix, strna(p->what),
507                 prefix, strna(p->fstype),
508                 prefix, strna(p->options),
509                 prefix, yes_no(m->from_etc_fstab),
510                 prefix, yes_no(m->from_proc_self_mountinfo),
511                 prefix, yes_no(m->from_fragment),
512                 prefix, kill_mode_to_string(m->kill_mode),
513                 prefix, m->directory_mode);
514
515         if (m->control_pid > 0)
516                 fprintf(f,
517                         "%sControl PID: %lu\n",
518                         prefix, (unsigned long) m->control_pid);
519
520         exec_context_dump(&m->exec_context, f, prefix);
521 }
522
523 static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
524         pid_t pid;
525         int r;
526
527         assert(m);
528         assert(c);
529         assert(_pid);
530
531         if ((r = unit_watch_timer(UNIT(m), m->timeout_usec, &m->timer_watch)) < 0)
532                 goto fail;
533
534         if ((r = exec_spawn(c,
535                             NULL,
536                             &m->exec_context,
537                             NULL, 0,
538                             m->meta.manager->environment,
539                             true,
540                             true,
541                             m->meta.manager->confirm_spawn,
542                             m->meta.cgroup_bondings,
543                             &pid)) < 0)
544                 goto fail;
545
546         if ((r = unit_watch_pid(UNIT(m), pid)) < 0)
547                 /* FIXME: we need to do something here */
548                 goto fail;
549
550         *_pid = pid;
551
552         return 0;
553
554 fail:
555         unit_unwatch_timer(UNIT(m), &m->timer_watch);
556
557         return r;
558 }
559
560 static void mount_enter_dead(Mount *m, bool success) {
561         assert(m);
562
563         if (!success)
564                 m->failure = true;
565
566         mount_set_state(m, m->failure ? MOUNT_MAINTENANCE : MOUNT_DEAD);
567 }
568
569 static void mount_enter_mounted(Mount *m, bool success) {
570         assert(m);
571
572         if (!success)
573                 m->failure = true;
574
575         mount_set_state(m, MOUNT_MOUNTED);
576 }
577
578 static void mount_enter_signal(Mount *m, MountState state, bool success) {
579         int r;
580         bool sent = false;
581
582         assert(m);
583
584         if (!success)
585                 m->failure = true;
586
587         if (m->kill_mode != KILL_NONE) {
588                 int sig = (state == MOUNT_MOUNTING_SIGTERM ||
589                            state == MOUNT_UNMOUNTING_SIGTERM ||
590                            state == MOUNT_REMOUNTING_SIGTERM) ? SIGTERM : SIGKILL;
591
592                 if (m->kill_mode == KILL_CONTROL_GROUP) {
593
594                         if ((r = cgroup_bonding_kill_list(m->meta.cgroup_bondings, sig)) < 0) {
595                                 if (r != -EAGAIN && r != -ESRCH)
596                                         goto fail;
597                         } else
598                                 sent = true;
599                 }
600
601                 if (!sent && m->control_pid > 0)
602                         if (kill(m->kill_mode == KILL_PROCESS ? m->control_pid : -m->control_pid, sig) < 0 && errno != ESRCH) {
603                                 r = -errno;
604                                 goto fail;
605                         }
606         }
607
608         if (sent) {
609                 if ((r = unit_watch_timer(UNIT(m), m->timeout_usec, &m->timer_watch)) < 0)
610                         goto fail;
611
612                 mount_set_state(m, state);
613         } else if (state == MOUNT_REMOUNTING_SIGTERM || state == MOUNT_REMOUNTING_SIGKILL)
614                 mount_enter_mounted(m, true);
615         else
616                 mount_enter_dead(m, true);
617
618         return;
619
620 fail:
621         log_warning("%s failed to kill processes: %s", m->meta.id, strerror(-r));
622
623         if (state == MOUNT_REMOUNTING_SIGTERM || state == MOUNT_REMOUNTING_SIGKILL)
624                 mount_enter_mounted(m, false);
625         else
626                 mount_enter_dead(m, false);
627 }
628
629 static void mount_enter_unmounting(Mount *m, bool success) {
630         int r;
631
632         assert(m);
633
634         if (!success)
635                 m->failure = true;
636
637         m->control_command_id = MOUNT_EXEC_UNMOUNT;
638         m->control_command = m->exec_command + MOUNT_EXEC_UNMOUNT;
639
640         if ((r = exec_command_set(
641                              m->control_command,
642                              "/bin/umount",
643                              m->where,
644                              NULL)) < 0)
645                 goto fail;
646
647         mount_unwatch_control_pid(m);
648
649         if ((r = mount_spawn(m, m->control_command, &m->control_pid)) < 0)
650                 goto fail;
651
652         mount_set_state(m, MOUNT_UNMOUNTING);
653
654         return;
655
656 fail:
657         log_warning("%s failed to run 'umount' task: %s", m->meta.id, strerror(-r));
658         mount_enter_mounted(m, false);
659 }
660
661 static void mount_enter_mounting(Mount *m) {
662         int r;
663
664         assert(m);
665
666         m->control_command_id = MOUNT_EXEC_MOUNT;
667         m->control_command = m->exec_command + MOUNT_EXEC_MOUNT;
668
669         mkdir_p(m->where, m->directory_mode);
670
671         if (m->from_fragment)
672                 r = exec_command_set(
673                                 m->control_command,
674                                 "/bin/mount",
675                                 m->parameters_fragment.what,
676                                 m->where,
677                                 "-t", m->parameters_fragment.fstype,
678                                 m->parameters_fragment.options ? "-o" : NULL, m->parameters_fragment.options,
679                                 NULL);
680         else if (m->from_etc_fstab)
681                 r = exec_command_set(
682                                 m->control_command,
683                                 "/bin/mount",
684                                 m->where,
685                                 NULL);
686         else
687                 r = -ENOENT;
688
689         if (r < 0)
690                 goto fail;
691
692         mount_unwatch_control_pid(m);
693
694         if ((r = mount_spawn(m, m->control_command, &m->control_pid)) < 0)
695                 goto fail;
696
697         mount_set_state(m, MOUNT_MOUNTING);
698
699         return;
700
701 fail:
702         log_warning("%s failed to run 'mount' task: %s", m->meta.id, strerror(-r));
703         mount_enter_dead(m, false);
704 }
705
706 static void mount_enter_mounting_done(Mount *m) {
707         assert(m);
708
709         mount_set_state(m, MOUNT_MOUNTING_DONE);
710 }
711
712 static void mount_enter_remounting(Mount *m, bool success) {
713         int r;
714
715         assert(m);
716
717         if (!success)
718                 m->failure = true;
719
720         m->control_command_id = MOUNT_EXEC_REMOUNT;
721         m->control_command = m->exec_command + MOUNT_EXEC_REMOUNT;
722
723         if (m->from_fragment) {
724                 char *buf = NULL;
725                 const char *o;
726
727                 if (m->parameters_fragment.options) {
728                         if (!(buf = strappend("remount,", m->parameters_fragment.options))) {
729                                 r = -ENOMEM;
730                                 goto fail;
731                         }
732
733                         o = buf;
734                 } else
735                         o = "remount";
736
737                 r = exec_command_set(
738                                 m->control_command,
739                                 "/bin/mount",
740                                 m->parameters_fragment.what,
741                                 m->where,
742                                 "-t", m->parameters_fragment.fstype,
743                                 "-o", o,
744                                 NULL);
745
746                 free(buf);
747         } else if (m->from_etc_fstab)
748                 r = exec_command_set(
749                                 m->control_command,
750                                 "/bin/mount",
751                                 m->where,
752                                 "-o", "remount",
753                                 NULL);
754         else
755                 r = -ENOENT;
756
757         if (r < 0) {
758                 r = -ENOMEM;
759                 goto fail;
760         }
761
762         mount_unwatch_control_pid(m);
763
764         if ((r = mount_spawn(m, m->control_command, &m->control_pid)) < 0)
765                 goto fail;
766
767         mount_set_state(m, MOUNT_REMOUNTING);
768
769         return;
770
771 fail:
772         mount_enter_mounted(m, false);
773 }
774
775 static int mount_start(Unit *u) {
776         Mount *m = MOUNT(u);
777
778         assert(m);
779
780         /* We cannot fulfill this request right now, try again later
781          * please! */
782         if (m->state == MOUNT_UNMOUNTING ||
783             m->state == MOUNT_UNMOUNTING_SIGTERM ||
784             m->state == MOUNT_UNMOUNTING_SIGKILL)
785                 return -EAGAIN;
786
787         /* Already on it! */
788         if (m->state == MOUNT_MOUNTING ||
789             m->state == MOUNT_MOUNTING_SIGTERM ||
790             m->state == MOUNT_MOUNTING_SIGKILL)
791                 return 0;
792
793         assert(m->state == MOUNT_DEAD || m->state == MOUNT_MAINTENANCE);
794
795         m->failure = false;
796         mount_enter_mounting(m);
797         return 0;
798 }
799
800 static int mount_stop(Unit *u) {
801         Mount *m = MOUNT(u);
802
803         assert(m);
804
805         /* Cann't do this right now. */
806         if (m->state == MOUNT_MOUNTING ||
807             m->state == MOUNT_MOUNTING_DONE ||
808             m->state == MOUNT_MOUNTING_SIGTERM ||
809             m->state == MOUNT_MOUNTING_SIGKILL ||
810             m->state == MOUNT_REMOUNTING ||
811             m->state == MOUNT_REMOUNTING_SIGTERM ||
812             m->state == MOUNT_REMOUNTING_SIGKILL)
813                 return -EAGAIN;
814
815         /* Already on it */
816         if (m->state == MOUNT_UNMOUNTING ||
817             m->state == MOUNT_UNMOUNTING_SIGKILL ||
818             m->state == MOUNT_UNMOUNTING_SIGTERM)
819                 return 0;
820
821         assert(m->state == MOUNT_MOUNTED);
822
823         mount_enter_unmounting(m, true);
824         return 0;
825 }
826
827 static int mount_reload(Unit *u) {
828         Mount *m = MOUNT(u);
829
830         assert(m);
831
832         if (m->state == MOUNT_MOUNTING_DONE)
833                 return -EAGAIN;
834
835         assert(m->state == MOUNT_MOUNTED);
836
837         mount_enter_remounting(m, true);
838         return 0;
839 }
840
841 static int mount_serialize(Unit *u, FILE *f, FDSet *fds) {
842         Mount *m = MOUNT(u);
843
844         assert(m);
845         assert(f);
846         assert(fds);
847
848         unit_serialize_item(u, f, "state", mount_state_to_string(m->state));
849         unit_serialize_item(u, f, "failure", yes_no(m->failure));
850
851         if (m->control_pid > 0)
852                 unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) m->control_pid);
853
854         if (m->control_command_id >= 0)
855                 unit_serialize_item(u, f, "control-command", mount_exec_command_to_string(m->control_command_id));
856
857         return 0;
858 }
859
860 static int mount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
861         Mount *m = MOUNT(u);
862         int r;
863
864         assert(u);
865         assert(key);
866         assert(value);
867         assert(fds);
868
869         if (streq(key, "state")) {
870                 MountState state;
871
872                 if ((state = mount_state_from_string(value)) < 0)
873                         log_debug("Failed to parse state value %s", value);
874                 else
875                         m->deserialized_state = state;
876         } else if (streq(key, "failure")) {
877                 int b;
878
879                 if ((b = parse_boolean(value)) < 0)
880                         log_debug("Failed to parse failure value %s", value);
881                 else
882                         m->failure = b || m->failure;
883
884         } else if (streq(key, "control-pid")) {
885                 pid_t pid;
886
887                 if ((r = parse_pid(value, &pid)) < 0)
888                         log_debug("Failed to parse control-pid value %s", value);
889                 else
890                         m->control_pid = pid;
891         } else if (streq(key, "control-command")) {
892                 MountExecCommand id;
893
894                 if ((id = mount_exec_command_from_string(value)) < 0)
895                         log_debug("Failed to parse exec-command value %s", value);
896                 else {
897                         m->control_command_id = id;
898                         m->control_command = m->exec_command + id;
899                 }
900
901         } else
902                 log_debug("Unknown serialization key '%s'", key);
903
904         return 0;
905 }
906
907 static UnitActiveState mount_active_state(Unit *u) {
908         assert(u);
909
910         return state_translation_table[MOUNT(u)->state];
911 }
912
913 static const char *mount_sub_state_to_string(Unit *u) {
914         assert(u);
915
916         return mount_state_to_string(MOUNT(u)->state);
917 }
918
919 static bool mount_check_gc(Unit *u) {
920         Mount *m = MOUNT(u);
921
922         assert(m);
923
924         return m->from_etc_fstab || m->from_proc_self_mountinfo;
925 }
926
927 static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
928         Mount *m = MOUNT(u);
929         bool success;
930
931         assert(m);
932         assert(pid >= 0);
933
934         if (pid != m->control_pid)
935                 return;
936
937         m->control_pid = 0;
938
939         success = is_clean_exit(code, status);
940         m->failure = m->failure || !success;
941
942         if (m->control_command) {
943                 exec_status_fill(&m->control_command->exec_status, pid, code, status);
944                 m->control_command = NULL;
945                 m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
946         }
947
948         log_debug("%s control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
949
950         /* Note that mount(8) returning and the kernel sending us a
951          * mount table change event might happen out-of-order. If an
952          * operation succeed we assume the kernel will follow soon too
953          * and already change into the resulting state.  If it fails
954          * we check if the kernel still knows about the mount. and
955          * change state accordingly. */
956
957         switch (m->state) {
958
959         case MOUNT_MOUNTING:
960         case MOUNT_MOUNTING_DONE:
961         case MOUNT_MOUNTING_SIGKILL:
962         case MOUNT_MOUNTING_SIGTERM:
963         case MOUNT_REMOUNTING:
964         case MOUNT_REMOUNTING_SIGKILL:
965         case MOUNT_REMOUNTING_SIGTERM:
966
967                 if (success)
968                         mount_enter_mounted(m, true);
969                 else if (m->from_proc_self_mountinfo)
970                         mount_enter_mounted(m, false);
971                 else
972                         mount_enter_dead(m, false);
973                 break;
974
975         case MOUNT_UNMOUNTING:
976         case MOUNT_UNMOUNTING_SIGKILL:
977         case MOUNT_UNMOUNTING_SIGTERM:
978
979                 if (success)
980                         mount_enter_dead(m, true);
981                 else if (m->from_proc_self_mountinfo)
982                         mount_enter_mounted(m, false);
983                 else
984                         mount_enter_dead(m, false);
985                 break;
986
987         default:
988                 assert_not_reached("Uh, control process died at wrong time.");
989         }
990 }
991
992 static void mount_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
993         Mount *m = MOUNT(u);
994
995         assert(m);
996         assert(elapsed == 1);
997         assert(w == &m->timer_watch);
998
999         switch (m->state) {
1000
1001         case MOUNT_MOUNTING:
1002         case MOUNT_MOUNTING_DONE:
1003                 log_warning("%s mounting timed out. Stopping.", u->meta.id);
1004                 mount_enter_signal(m, MOUNT_MOUNTING_SIGTERM, false);
1005                 break;
1006
1007         case MOUNT_REMOUNTING:
1008                 log_warning("%s remounting timed out. Stopping.", u->meta.id);
1009                 mount_enter_signal(m, MOUNT_REMOUNTING_SIGTERM, false);
1010                 break;
1011
1012         case MOUNT_UNMOUNTING:
1013                 log_warning("%s unmounting timed out. Stopping.", u->meta.id);
1014                 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGTERM, false);
1015                 break;
1016
1017         case MOUNT_MOUNTING_SIGTERM:
1018                 log_warning("%s mounting timed out. Killing.", u->meta.id);
1019                 mount_enter_signal(m, MOUNT_MOUNTING_SIGKILL, false);
1020                 break;
1021
1022         case MOUNT_REMOUNTING_SIGTERM:
1023                 log_warning("%s remounting timed out. Killing.", u->meta.id);
1024                 mount_enter_signal(m, MOUNT_REMOUNTING_SIGKILL, false);
1025                 break;
1026
1027         case MOUNT_UNMOUNTING_SIGTERM:
1028                 log_warning("%s unmounting timed out. Killing.", u->meta.id);
1029                 mount_enter_signal(m, MOUNT_UNMOUNTING_SIGKILL, false);
1030                 break;
1031
1032         case MOUNT_MOUNTING_SIGKILL:
1033         case MOUNT_REMOUNTING_SIGKILL:
1034         case MOUNT_UNMOUNTING_SIGKILL:
1035                 log_warning("%s mount process still around after SIGKILL. Ignoring.", u->meta.id);
1036
1037                 if (m->from_proc_self_mountinfo)
1038                         mount_enter_mounted(m, false);
1039                 else
1040                         mount_enter_dead(m, false);
1041                 break;
1042
1043         default:
1044                 assert_not_reached("Timeout at wrong time.");
1045         }
1046 }
1047
1048 static int mount_add_one(
1049                 Manager *m,
1050                 const char *what,
1051                 const char *where,
1052                 const char *options,
1053                 const char *fstype,
1054                 bool from_proc_self_mountinfo,
1055                 bool set_flags) {
1056         int r;
1057         Unit *u;
1058         bool delete;
1059         char *e, *w = NULL, *o = NULL, *f = NULL;
1060         MountParameters *p;
1061
1062         assert(m);
1063         assert(what);
1064         assert(where);
1065         assert(options);
1066         assert(fstype);
1067
1068         assert(!set_flags || from_proc_self_mountinfo);
1069
1070         /* Ignore API mount points. They should never be referenced in
1071          * dependencies ever. */
1072         if (mount_point_is_api(where))
1073                 return 0;
1074
1075         if (streq(fstype, "autofs"))
1076                 return 0;
1077
1078         /* probably some kind of swap, ignore */
1079         if (!is_path(where))
1080                 return 0;
1081
1082         if (!(e = unit_name_from_path(where, ".mount")))
1083                 return -ENOMEM;
1084
1085         if (!(u = manager_get_unit(m, e))) {
1086                 delete = true;
1087
1088                 if (!(u = unit_new(m))) {
1089                         free(e);
1090                         return -ENOMEM;
1091                 }
1092
1093                 r = unit_add_name(u, e);
1094                 free(e);
1095
1096                 if (r < 0)
1097                         goto fail;
1098
1099                 if (!(MOUNT(u)->where = strdup(where))) {
1100                         r = -ENOMEM;
1101                         goto fail;
1102                 }
1103
1104                 unit_add_to_load_queue(u);
1105         } else {
1106                 delete = false;
1107                 free(e);
1108         }
1109
1110         if (!(w = strdup(what)) ||
1111             !(o = strdup(options)) ||
1112             !(f = strdup(fstype))) {
1113                 r = -ENOMEM;
1114                 goto fail;
1115         }
1116
1117         if (from_proc_self_mountinfo) {
1118                 p = &MOUNT(u)->parameters_proc_self_mountinfo;
1119
1120                 if (set_flags) {
1121                         MOUNT(u)->is_mounted = true;
1122                         MOUNT(u)->just_mounted = !MOUNT(u)->from_proc_self_mountinfo;
1123                         MOUNT(u)->just_changed = !streq_ptr(p->options, o);
1124                 }
1125
1126                 MOUNT(u)->from_proc_self_mountinfo = true;
1127         } else {
1128                 p = &MOUNT(u)->parameters_etc_fstab;
1129                 MOUNT(u)->from_etc_fstab = true;
1130         }
1131
1132         free(p->what);
1133         p->what = w;
1134
1135         free(p->options);
1136         p->options = o;
1137
1138         free(p->fstype);
1139         p->fstype = f;
1140
1141         unit_add_to_dbus_queue(u);
1142
1143         return 0;
1144
1145 fail:
1146         free(w);
1147         free(o);
1148         free(f);
1149
1150         if (delete && u)
1151                 unit_free(u);
1152
1153         return r;
1154 }
1155
1156 static char *fstab_node_to_udev_node(char *p) {
1157         char *dn, *t;
1158         int r;
1159
1160         /* FIXME: to follow udev's logic 100% we need to leave valid
1161          * UTF8 chars unescaped */
1162
1163         if (startswith(p, "LABEL=")) {
1164
1165                 if (!(t = xescape(p+6, "/ ")))
1166                         return NULL;
1167
1168                 r = asprintf(&dn, "/dev/disk/by-label/%s", t);
1169                 free(t);
1170
1171                 if (r < 0)
1172                         return NULL;
1173
1174                 return dn;
1175         }
1176
1177         if (startswith(p, "UUID=")) {
1178
1179                 if (!(t = xescape(p+5, "/ ")))
1180                         return NULL;
1181
1182                 r = asprintf(&dn, "/dev/disk/by-uuid/%s", ascii_strlower(t));
1183                 free(t);
1184
1185                 if (r < 0)
1186                         return NULL;
1187
1188                 return dn;
1189         }
1190
1191         return strdup(p);
1192 }
1193
1194 static int mount_find_pri(char *options) {
1195         char *end, *pri;
1196         unsigned long r;
1197
1198         if (!(pri = mount_test_option(options, "pri=")))
1199                 return 0;
1200
1201         pri += 4;
1202
1203         errno = 0;
1204         r = strtoul(pri, &end, 10);
1205
1206         if (errno != 0)
1207                 return -errno;
1208
1209         if (end == pri || (*end != ',' && *end != 0))
1210                 return -EINVAL;
1211
1212         return (int) r;
1213 }
1214
1215 static int mount_load_etc_fstab(Manager *m) {
1216         FILE *f;
1217         int r;
1218         struct mntent* me;
1219
1220         assert(m);
1221
1222         errno = 0;
1223         if (!(f = setmntent("/etc/fstab", "r")))
1224                 return -errno;
1225
1226         while ((me = getmntent(f))) {
1227                 char *where, *what;
1228
1229                 if (!(what = fstab_node_to_udev_node(me->mnt_fsname))) {
1230                         r = -ENOMEM;
1231                         goto finish;
1232                 }
1233
1234                 if (!(where = strdup(me->mnt_dir))) {
1235                         free(what);
1236                         r = -ENOMEM;
1237                         goto finish;
1238                 }
1239
1240                 if (what[0] == '/')
1241                         path_kill_slashes(what);
1242
1243                 if (where[0] == '/')
1244                         path_kill_slashes(where);
1245
1246                 if (streq(me->mnt_type, "swap")) {
1247                         int pri;
1248
1249                         if ((pri = mount_find_pri(me->mnt_opts)) < 0)
1250                                 r = pri;
1251                         else
1252                                 r = swap_add_one(m,
1253                                                  what,
1254                                                  pri,
1255                                                  !!mount_test_option(me->mnt_opts, MNTOPT_NOAUTO),
1256                                                  !!mount_test_option(me->mnt_opts, "comment=systemd.swapon"),
1257                                                  false);
1258                 } else
1259                         r = mount_add_one(m, what, where, me->mnt_opts, me->mnt_type, false, false);
1260
1261                 free(what);
1262                 free(where);
1263
1264                 if (r < 0)
1265                         goto finish;
1266         }
1267
1268         r = 0;
1269 finish:
1270
1271         endmntent(f);
1272         return r;
1273 }
1274
1275 static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
1276         int r;
1277         char *device, *path, *options, *options2, *fstype, *d, *p, *o;
1278
1279         assert(m);
1280
1281         rewind(m->proc_self_mountinfo);
1282
1283         for (;;) {
1284                 int k;
1285
1286                 device = path = options = options2 = fstype = d = p = o = NULL;
1287
1288                 if ((k = fscanf(m->proc_self_mountinfo,
1289                                 "%*s "       /* (1) mount id */
1290                                 "%*s "       /* (2) parent id */
1291                                 "%*s "       /* (3) major:minor */
1292                                 "%*s "       /* (4) root */
1293                                 "%ms "       /* (5) mount point */
1294                                 "%ms"        /* (6) mount options */
1295                                 "%*[^-]"     /* (7) optional fields */
1296                                 "- "         /* (8) seperator */
1297                                 "%ms "       /* (9) file system type */
1298                                 "%ms"        /* (10) mount source */
1299                                 "%ms"        /* (11) mount options 2 */
1300                                 "%*[^\n]",   /* some rubbish at the end */
1301                                 &path,
1302                                 &options,
1303                                 &fstype,
1304                                 &device,
1305                                 &options2)) != 5) {
1306
1307                         if (k == EOF)
1308                                 break;
1309
1310                         r = -EBADMSG;
1311                         goto finish;
1312                 }
1313
1314                 if (asprintf(&o, "%s,%s", options, options2) < 0) {
1315                         r = -ENOMEM;
1316                         goto finish;
1317                 }
1318
1319                 if (!(d = cunescape(device)) ||
1320                     !(p = cunescape(path))) {
1321                         r = -ENOMEM;
1322                         goto finish;
1323                 }
1324
1325                 if ((r = mount_add_one(m, d, p, o, fstype, true, set_flags)) < 0)
1326                         goto finish;
1327
1328                 free(device);
1329                 free(path);
1330                 free(options);
1331                 free(options2);
1332                 free(fstype);
1333                 free(d);
1334                 free(p);
1335                 free(o);
1336         }
1337
1338         r = 0;
1339
1340 finish:
1341         free(device);
1342         free(path);
1343         free(options);
1344         free(options2);
1345         free(fstype);
1346         free(d);
1347         free(p);
1348         free(o);
1349
1350         return r;
1351 }
1352
1353 static void mount_shutdown(Manager *m) {
1354         assert(m);
1355
1356         if (m->proc_self_mountinfo) {
1357                 fclose(m->proc_self_mountinfo);
1358                 m->proc_self_mountinfo = NULL;
1359         }
1360 }
1361
1362 static int mount_enumerate(Manager *m) {
1363         int r;
1364         struct epoll_event ev;
1365         assert(m);
1366
1367         if (!m->proc_self_mountinfo) {
1368                 if (!(m->proc_self_mountinfo = fopen("/proc/self/mountinfo", "re")))
1369                         return -errno;
1370
1371                 m->mount_watch.type = WATCH_MOUNT;
1372                 m->mount_watch.fd = fileno(m->proc_self_mountinfo);
1373
1374                 zero(ev);
1375                 ev.events = EPOLLERR;
1376                 ev.data.ptr = &m->mount_watch;
1377
1378                 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->mount_watch.fd, &ev) < 0)
1379                         return -errno;
1380         }
1381
1382         if ((r = mount_load_etc_fstab(m)) < 0)
1383                 goto fail;
1384
1385         if ((r = mount_load_proc_self_mountinfo(m, false)) < 0)
1386                 goto fail;
1387
1388         return 0;
1389
1390 fail:
1391         mount_shutdown(m);
1392         return r;
1393 }
1394
1395 void mount_fd_event(Manager *m, int events) {
1396         Meta *meta;
1397         int r;
1398
1399         assert(m);
1400         assert(events == EPOLLERR);
1401
1402         /* The manager calls this for every fd event happening on the
1403          * /proc/self/mountinfo file, which informs us about mounting
1404          * table changes */
1405
1406         if ((r = mount_load_proc_self_mountinfo(m, true)) < 0) {
1407                 log_error("Failed to reread /proc/self/mountinfo: %s", strerror(errno));
1408
1409                 /* Reset flags, just in case, for later calls */
1410                 LIST_FOREACH(units_per_type, meta, m->units_per_type[UNIT_MOUNT]) {
1411                         Mount *mount = (Mount*) meta;
1412
1413                         mount->is_mounted = mount->just_mounted = mount->just_changed = false;
1414                 }
1415
1416                 return;
1417         }
1418
1419         manager_dispatch_load_queue(m);
1420
1421         LIST_FOREACH(units_per_type, meta, m->units_per_type[UNIT_MOUNT]) {
1422                 Mount *mount = (Mount*) meta;
1423
1424                 if (!mount->is_mounted) {
1425                         /* This has just been unmounted. */
1426
1427                         mount->from_proc_self_mountinfo = false;
1428
1429                         switch (mount->state) {
1430
1431                         case MOUNT_MOUNTED:
1432                                 mount_enter_dead(mount, true);
1433                                 break;
1434
1435                         default:
1436                                 mount_set_state(mount, mount->state);
1437                                 break;
1438
1439                         }
1440
1441                 } else if (mount->just_mounted || mount->just_changed) {
1442
1443                         /* New or changed entrymount */
1444
1445                         switch (mount->state) {
1446
1447                         case MOUNT_DEAD:
1448                         case MOUNT_MAINTENANCE:
1449                                 mount_enter_mounted(mount, true);
1450                                 break;
1451
1452                         case MOUNT_MOUNTING:
1453                                 mount_enter_mounting_done(mount);
1454                                 break;
1455
1456                         default:
1457                                 /* Nothing really changed, but let's
1458                                  * issue an notification call
1459                                  * nonetheless, in case somebody is
1460                                  * waiting for this. (e.g. file system
1461                                  * ro/rw remounts.) */
1462                                 mount_set_state(mount, mount->state);
1463                                 break;
1464                         }
1465                 }
1466
1467                 /* Reset the flags for later calls */
1468                 mount->is_mounted = mount->just_mounted = mount->just_changed = false;
1469         }
1470 }
1471
1472 int mount_path_is_mounted(Manager *m, const char* path) {
1473         char *t;
1474         int r;
1475
1476         assert(m);
1477         assert(path);
1478
1479         if (path[0] != '/')
1480                 return 1;
1481
1482         if (!(t = strdup(path)))
1483                 return -ENOMEM;
1484
1485         path_kill_slashes(t);
1486
1487         for (;;) {
1488                 char *e, *slash;
1489                 Unit *u;
1490
1491                 if (!(e = unit_name_from_path(t, ".mount"))) {
1492                         r = -ENOMEM;
1493                         goto finish;
1494                 }
1495
1496                 u = manager_get_unit(m, e);
1497                 free(e);
1498
1499                 if (u &&
1500                     (MOUNT(u)->from_etc_fstab || MOUNT(u)->from_fragment) &&
1501                     MOUNT(u)->state != MOUNT_MOUNTED) {
1502                         r = 0;
1503                         goto finish;
1504                 }
1505
1506                 assert_se(slash = strrchr(t, '/'));
1507
1508                 if (slash == t) {
1509                         r = 1;
1510                         goto finish;
1511                 }
1512
1513                 *slash = 0;
1514         }
1515
1516         r = 1;
1517
1518 finish:
1519         free(t);
1520         return r;
1521 }
1522
1523 static const char* const mount_state_table[_MOUNT_STATE_MAX] = {
1524         [MOUNT_DEAD] = "dead",
1525         [MOUNT_MOUNTING] = "mounting",
1526         [MOUNT_MOUNTING_DONE] = "mounting-done",
1527         [MOUNT_MOUNTED] = "mounted",
1528         [MOUNT_REMOUNTING] = "remounting",
1529         [MOUNT_UNMOUNTING] = "unmounting",
1530         [MOUNT_MOUNTING_SIGTERM] = "mounting-sigterm",
1531         [MOUNT_MOUNTING_SIGKILL] = "mounting-sigkill",
1532         [MOUNT_REMOUNTING_SIGTERM] = "remounting-sigterm",
1533         [MOUNT_REMOUNTING_SIGKILL] = "remounting-sigkill",
1534         [MOUNT_UNMOUNTING_SIGTERM] = "unmounting-sigterm",
1535         [MOUNT_UNMOUNTING_SIGKILL] = "unmounting-sigkill",
1536         [MOUNT_MAINTENANCE] = "maintenance"
1537 };
1538
1539 DEFINE_STRING_TABLE_LOOKUP(mount_state, MountState);
1540
1541 static const char* const mount_exec_command_table[_MOUNT_EXEC_COMMAND_MAX] = {
1542         [MOUNT_EXEC_MOUNT] = "ExecMount",
1543         [MOUNT_EXEC_UNMOUNT] = "ExecUnmount",
1544         [MOUNT_EXEC_REMOUNT] = "ExecRemount",
1545 };
1546
1547 DEFINE_STRING_TABLE_LOOKUP(mount_exec_command, MountExecCommand);
1548
1549 const UnitVTable mount_vtable = {
1550         .suffix = ".mount",
1551
1552         .no_alias = true,
1553         .no_instances = true,
1554         .no_isolate = true,
1555
1556         .init = mount_init,
1557         .load = mount_load,
1558         .done = mount_done,
1559
1560         .coldplug = mount_coldplug,
1561
1562         .dump = mount_dump,
1563
1564         .start = mount_start,
1565         .stop = mount_stop,
1566         .reload = mount_reload,
1567
1568         .serialize = mount_serialize,
1569         .deserialize_item = mount_deserialize_item,
1570
1571         .active_state = mount_active_state,
1572         .sub_state_to_string = mount_sub_state_to_string,
1573
1574         .check_gc = mount_check_gc,
1575
1576         .sigchld_event = mount_sigchld_event,
1577         .timer_event = mount_timer_event,
1578
1579         .bus_message_handler = bus_mount_message_handler,
1580
1581         .enumerate = mount_enumerate,
1582         .shutdown = mount_shutdown
1583 };