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