From 173a8d04fc3535b571fe4a0d4715c18be315a43a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 25 Aug 2010 20:37:04 +0200 Subject: [PATCH] mount: rework automatic mounting to follow the 'nofail' option in fstab --- fixme | 4 +--- src/dbus-manager.c | 6 ++---- src/main.c | 9 +++------ src/manager.h | 4 +--- src/mount.c | 32 +++++++++++++++++++++++++++----- src/swap.c | 33 ++++++++++++++++++++++++++++----- src/swap.h | 3 ++- src/system.conf | 3 +-- 8 files changed, 65 insertions(+), 29 deletions(-) diff --git a/fixme b/fixme index 4ee7815b..52b81106 100644 --- a/fixme +++ b/fixme @@ -76,7 +76,7 @@ * add RefuseManualIsolate= (default on?) -* nofail +* fstab nofail * add systemctl switch to dump transaction without executing it @@ -84,8 +84,6 @@ * system.conf/session.conf brauch ne man page -* sd-daemon ohne SCM_CREDENTIALS bitte - * exec /sbin/poweroff als PID 1 und shutdown External: diff --git a/src/dbus-manager.c b/src/dbus-manager.c index 55712471..9b0a6002 100644 --- a/src/dbus-manager.c +++ b/src/dbus-manager.c @@ -141,9 +141,8 @@ " \n" \ " \n" \ " \n" \ - " \n" \ - " \n" \ " \n" \ + " \n" \ " \n" #define INTROSPECTION_BEGIN \ @@ -255,9 +254,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, { "org.freedesktop.systemd1.Manager", "SysVRcndPath", bus_property_append_strv, "as", m->lookup_paths.sysvrcnd_path }, { "org.freedesktop.systemd1.Manager", "NotifySocket", bus_property_append_string, "s", m->notify_socket }, { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy }, - { "org.freedesktop.systemd1.Manager", "MountOnPlug", bus_property_append_bool, "b", &m->mount_on_plug }, - { "org.freedesktop.systemd1.Manager", "SwapOnPlug", bus_property_append_bool, "b", &m->swap_on_plug }, { "org.freedesktop.systemd1.Manager", "MountAuto", bus_property_append_bool, "b", &m->mount_auto }, + { "org.freedesktop.systemd1.Manager", "SwapAuto", bus_property_append_bool, "b", &m->swap_auto }, { NULL, NULL, NULL, NULL, NULL } }; diff --git a/src/main.c b/src/main.c index 54fc0540..f1fa5691 100644 --- a/src/main.c +++ b/src/main.c @@ -64,9 +64,8 @@ static int arg_crash_chvt = -1; static bool arg_confirm_spawn = false; static bool arg_show_status = true; static bool arg_sysv_console = true; -static bool arg_mount_on_plug = true; -static bool arg_swap_on_plug = true; static bool arg_mount_auto = true; +static bool arg_swap_auto = true; static FILE* serialization = NULL; @@ -485,9 +484,8 @@ static int parse_config_file(void) { { "SysVConsole", config_parse_bool, &arg_sysv_console, "Manager" }, { "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" }, { "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" }, - { "MountOnPlug", config_parse_bool, &arg_mount_on_plug, "Manager" }, - { "SwapOnPlug", config_parse_bool, &arg_swap_on_plug, "Manager" }, { "MountAuto", config_parse_bool, &arg_mount_auto, "Manager" }, + { "SwapAuto", config_parse_bool, &arg_swap_auto, "Manager" }, { NULL, NULL, NULL, NULL } }; @@ -992,9 +990,8 @@ int main(int argc, char *argv[]) { m->confirm_spawn = arg_confirm_spawn; m->show_status = arg_show_status; m->sysv_console = arg_sysv_console; - m->mount_on_plug = arg_mount_on_plug; - m->swap_on_plug = arg_swap_on_plug; m->mount_auto = arg_mount_auto; + m->swap_auto = arg_swap_auto; if ((r = manager_startup(m, serialization, fds)) < 0) log_error("Failed to fully start up daemon: %s", strerror(-r)); diff --git a/src/manager.h b/src/manager.h index dd48593d..e3c6db23 100644 --- a/src/manager.h +++ b/src/manager.h @@ -201,10 +201,8 @@ struct Manager { bool show_status; bool confirm_spawn; bool sysv_console; - - bool mount_on_plug; - bool swap_on_plug; bool mount_auto; + bool swap_auto; int n_deserializing; }; diff --git a/src/mount.c b/src/mount.c index b49443ce..08d5de28 100644 --- a/src/mount.c +++ b/src/mount.c @@ -275,6 +275,30 @@ static int mount_add_target_links(Mount *m) { } } +static int mount_add_device_links(Mount *m) { + MountParameters *p; + bool nofail, noauto; + + assert(m); + + if (m->from_fragment) + p = &m->parameters_fragment; + else if (m->from_etc_fstab) + p = &m->parameters_etc_fstab; + else + return 0; + + if (!p->what || path_equal(m->where, "/")) + return 0; + + noauto = !!mount_test_option(p->options, MNTOPT_NOAUTO); + nofail = !!mount_test_option(p->options, "nofail"); + + return unit_add_node_link(UNIT(m), p->what, + !noauto && nofail && + UNIT(m)->meta.manager->running_as == MANAGER_SYSTEM); +} + static int mount_add_default_dependencies(Mount *m) { int r; @@ -362,11 +386,8 @@ static int mount_load(Unit *u) { else if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what) what = m->parameters_proc_self_mountinfo.what; - if (what && !path_equal(m->where, "/")) - if ((r = unit_add_node_link(u, what, - u->meta.manager->running_as == MANAGER_SYSTEM && - u->meta.manager->mount_on_plug)) < 0) - return r; + if ((r = mount_add_device_links(m)) < 0) + return r; if ((r = mount_add_mount_links(m)) < 0) return r; @@ -1289,6 +1310,7 @@ static int mount_load_etc_fstab(Manager *m) { what, pri, !!mount_test_option(me->mnt_opts, MNTOPT_NOAUTO), + !!mount_test_option(me->mnt_opts, "nofail"), !!mount_test_option(me->mnt_opts, "comment=systemd.swapon"), false); } else diff --git a/src/swap.c b/src/swap.c index 4a672fbd..69ccd3db 100644 --- a/src/swap.c +++ b/src/swap.c @@ -113,13 +113,33 @@ static int swap_add_target_links(Swap *s) { if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, NULL, &tu)) < 0) return r; - if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM) + if (!p->noauto && (p->handle || s->meta.manager->swap_auto) && s->meta.manager->running_as == MANAGER_SYSTEM) if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(s), true)) < 0) return r; return unit_add_dependency(UNIT(s), UNIT_BEFORE, tu, true); } +static int swap_add_device_links(Swap *s) { + SwapParameters *p; + + assert(s); + + if (!s->what) + return 0; + + if (s->from_fragment) + p = &s->parameters_fragment; + else if (s->from_etc_fstab) + p = &s->parameters_etc_fstab; + else + return 0; + + return unit_add_node_link(UNIT(s), s->what, + !p->noauto && p->nofail && + s->meta.manager->running_as == MANAGER_SYSTEM); +} + static int swap_add_default_dependencies(Swap *s) { int r; @@ -195,9 +215,8 @@ static int swap_load(Unit *u) { if ((r = unit_set_description(u, s->what)) < 0) return r; - if ((r = unit_add_node_link(u, s->what, - u->meta.manager->running_as == MANAGER_SYSTEM && - u->meta.manager->swap_on_plug)) < 0) + + if ((r = swap_add_device_links(s)) < 0) return r; if ((r = swap_add_mount_links(s)) < 0) @@ -262,6 +281,7 @@ int swap_add_one( const char *what, int priority, bool noauto, + bool nofail, bool handle, bool from_proc_swaps) { Unit *u = NULL; @@ -311,6 +331,7 @@ int swap_add_one( p->priority = priority; p->noauto = noauto; + p->nofail = nofail; p->handle = handle; if (delete) @@ -385,6 +406,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) { "%sWhat: %s\n" "%sPriority: %i\n" "%sNoAuto: %s\n" + "%sNoFail: %s\n" "%sHandle: %s\n" "%sFrom /etc/fstab: %s\n" "%sFrom /proc/swaps: %s\n" @@ -393,6 +415,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) { prefix, s->what, prefix, p->priority, prefix, yes_no(p->noauto), + prefix, yes_no(p->nofail), prefix, yes_no(p->handle), prefix, yes_no(s->from_etc_fstab), prefix, yes_no(s->from_proc_swaps), @@ -525,7 +548,7 @@ static int swap_load_proc_swaps(Manager *m) { if (!d) return -ENOMEM; - k = swap_add_one(m, d, prio, false, false, true); + k = swap_add_one(m, d, prio, false, false, false, true); free(d); if (k < 0) diff --git a/src/swap.h b/src/swap.h index 3c53536a..a180708a 100644 --- a/src/swap.h +++ b/src/swap.h @@ -39,6 +39,7 @@ typedef struct SwapParameters { char *what; int priority; bool noauto:1; + bool nofail:1; bool handle:1; } SwapParameters; @@ -60,7 +61,7 @@ struct Swap { extern const UnitVTable swap_vtable; -int swap_add_one(Manager *m, const char *what, int prio, bool no_auto, bool handle, bool from_proc_swap); +int swap_add_one(Manager *m, const char *what, int prio, bool no_auto, bool no_fail, bool handle, bool from_proc_swap); int swap_add_one_mount_link(Swap *s, Mount *m); diff --git a/src/system.conf b/src/system.conf index 9d87c6df..c6a7bf3d 100644 --- a/src/system.conf +++ b/src/system.conf @@ -18,6 +18,5 @@ #SysVConsole=yes #CrashChVT=1 #CPUAffinity=1 2 -#MountOnPlug=yes -#SwapOnPlug=yes #MountAuto=yes +#SwapAuto=yes -- 2.39.5