Hey all, Martin Pitt [2015-02-26 16:50 +0100]: > IMHO it would be prudent to skip adding the BindsTo= if at the time of > creating the .mount unit the backing .device unit doesn't actually > exist. In that case it's a mount which isn't managed by systemd, and > we shouldn't touch it. We mostly want this BindsTo= for mounts where > the .device units *do* exist, so that when they go away we can clean > up the mount (mostly for hotpluggable devices and removable media).
The attached patch does that. It's not really pretty, but it works for me: mounts in the initramfs are now left alone, and the automatic unmount of force-ejected media is still working. Colin, can you please double-check that it works for your CoreOS, too? If not, I'd appreciate a debug journal. Thanks, Martin -- Martin Pitt | http://www.piware.de Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org)
From 5946b898357d448c2c03ad7ebc67c63041cc7e95 Mon Sep 17 00:00:00 2001 From: Martin Pitt <martin.p...@ubuntu.com> Date: Thu, 26 Feb 2015 18:37:04 +0100 Subject: [PATCH] core/mount: only add dependencies to active units for dynamic mounts Commit 06e9788 added .device dependencies to all .mount units, but this is overzealous: If the initrd sets up mounts other than what's in fstab (i. e. not fragments), their .device units aren't yet active at early boot, or possibly never will be. Thus for non-fragment mounts, only add a dependency to active device units. https://bugzilla.redhat.com/show_bug.cgi?id=1195761 --- src/core/mount.c | 19 +++++++++++++++---- src/core/socket.c | 2 +- src/core/swap.c | 2 +- src/core/unit.c | 6 +++++- src/core/unit.h | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 40037e7..100771c 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -291,13 +291,19 @@ static int mount_add_mount_links(Mount *m) { static int mount_add_device_links(Mount *m) { MountParameters *p; bool device_wants_mount = false; + bool is_fragment = true; int r; assert(m); - p = get_mount_parameters(m); - if (!p) - return 0; + p = get_mount_parameters_fragment(m); + if (!p) { + p = get_mount_parameters(m); + if (p) + is_fragment = false; + else + return 0; + } if (!p->what) return 0; @@ -314,7 +320,12 @@ static int mount_add_device_links(Mount *m) { if (mount_is_auto(p) && UNIT(m)->manager->running_as == SYSTEMD_SYSTEM) device_wants_mount = true; - r = unit_add_node_link(UNIT(m), p->what, device_wants_mount); + /* Skip adding device dependency for dynamic mounts which have been set + * up by the initrd or other manual methods; their device units are not + * active at early boot, or may never be, so we would immediately + * umount them again; but do keep the dependency for fstab mounts + * (fragments). */ + r = unit_add_node_link(UNIT(m), p->what, device_wants_mount, !is_fragment); if (r < 0) return r; diff --git a/src/core/socket.c b/src/core/socket.c index 7d052f2..f88d60a 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -263,7 +263,7 @@ static int socket_add_device_link(Socket *s) { return 0; t = strjoina("/sys/subsystem/net/devices/", s->bind_to_device); - return unit_add_node_link(UNIT(s), t, false); + return unit_add_node_link(UNIT(s), t, false, false); } static int socket_add_default_dependencies(Socket *s) { diff --git a/src/core/swap.c b/src/core/swap.c index f73a8e6..13dc2c9 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -194,7 +194,7 @@ static int swap_add_device_links(Swap *s) { return 0; if (is_device_path(s->what)) - return unit_add_node_link(UNIT(s), s->what, UNIT(s)->manager->running_as == SYSTEMD_SYSTEM); + return unit_add_node_link(UNIT(s), s->what, UNIT(s)->manager->running_as == SYSTEMD_SYSTEM, false); else /* File based swap devices need to be ordered after * systemd-remount-fs.service, since they might need a diff --git a/src/core/unit.c b/src/core/unit.c index 63ccd67..34836a8 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2814,7 +2814,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { } } -int unit_add_node_link(Unit *u, const char *what, bool wants) { +int unit_add_node_link(Unit *u, const char *what, bool wants, bool active_only) { Unit *device; _cleanup_free_ char *e = NULL; int r; @@ -2837,6 +2837,10 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) { if (r < 0) return r; + if (active_only && !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(device))) { + log_debug("Device %s for %s is not active, skipping dependency", device->id, u->id); + return 0; + } r = unit_add_two_dependencies(u, UNIT_AFTER, u->manager->running_as == SYSTEMD_SYSTEM ? UNIT_BINDS_TO : UNIT_WANTS, device, true); if (r < 0) diff --git a/src/core/unit.h b/src/core/unit.h index b3775d4..20cd8dc 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -533,7 +533,7 @@ void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *v void unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value); int unit_deserialize(Unit *u, FILE *f, FDSet *fds); -int unit_add_node_link(Unit *u, const char *what, bool wants); +int unit_add_node_link(Unit *u, const char *what, bool wants, bool active_only); int unit_coldplug(Unit *u); -- 2.1.4
signature.asc
Description: Digital signature
_______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel