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