From b7bbf89025d40cd73beccbb68fa1719d53aa8ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 17 Jan 2019 21:17:51 +0100 Subject: [PATCH 1/2] core/mount: move static function earlier in file No functional change. --- src/core/mount.c | 52 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 4c5a02948c..d7ecfd008a 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -251,6 +251,32 @@ _pure_ static MountParameters* get_mount_parameters(Mount *m) { return get_mount_parameters_fragment(m); } +static int update_parameters_proc_self_mount_info( + Mount *m, + const char *what, + const char *options, + const char *fstype) { + + MountParameters *p; + int r, q, w; + + p = &m->parameters_proc_self_mountinfo; + + r = free_and_strdup(&p->what, what); + if (r < 0) + return r; + + q = free_and_strdup(&p->options, options); + if (q < 0) + return q; + + w = free_and_strdup(&p->fstype, fstype); + if (w < 0) + return w; + + return r > 0 || q > 0 || w > 0; +} + static int mount_add_mount_dependencies(Mount *m) { MountParameters *pm; Unit *other; @@ -1428,32 +1454,6 @@ static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *user return 0; } -static int update_parameters_proc_self_mount_info( - Mount *m, - const char *what, - const char *options, - const char *fstype) { - - MountParameters *p; - int r, q, w; - - p = &m->parameters_proc_self_mountinfo; - - r = free_and_strdup(&p->what, what); - if (r < 0) - return r; - - q = free_and_strdup(&p->options, options); - if (q < 0) - return q; - - w = free_and_strdup(&p->fstype, fstype); - if (w < 0) - return w; - - return r > 0 || q > 0 || w > 0; -} - static int mount_setup_new_unit( Manager *m, const char *name, From c52c2dc64f2443dd2e1f0cc82f577b68520ceb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 17 Jan 2019 16:09:13 +0100 Subject: [PATCH 2/2] pid1: fix cleanup of stale implicit deps based on /proc/self/mountinfo The problem was introduced in a37422045fbb68ad68f734e5dc00e0a5b1759773: we have a unit which has a fragment, and when we'd update it based on /proc/self/mountinfo, we'd say that e.g. What=/dev/loop8 has origin-fragment. This commit changes two things: - origin-fragment is changed to origin-mountinfo-implicit - when we stop a unit, mountinfo information is flushed and all deps based on it are dropped. The second step is important, because when we restart the unit, we want to notice that we have "fresh" mountinfo information. We could keep the old info around and solve this in a different way, but keeping stale information seems inelegant. Fixes #11342. --- src/core/mount.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/mount.c b/src/core/mount.c index d7ecfd008a..6df5d60ee1 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -378,7 +378,8 @@ static int mount_add_device_dependencies(Mount *m) { * automatically stopped when the device disappears suddenly. */ dep = mount_is_bound_to_device(m) ? UNIT_BINDS_TO : UNIT_REQUIRES; - mask = m->from_fragment ? UNIT_DEPENDENCY_FILE : UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT; + /* We always use 'what' from /proc/self/mountinfo if mounted */ + mask = m->from_proc_self_mountinfo ? UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT : UNIT_DEPENDENCY_FILE; r = unit_add_node_dependency(UNIT(m), p->what, device_wants_mount, dep, mask); if (r < 0) @@ -849,6 +850,9 @@ static void mount_enter_dead(Mount *m, MountResult f) { unit_unref_uid_gid(UNIT(m), true); dynamic_creds_destroy(&m->dynamic_creds); + + /* Any dependencies based on /proc/self/mountinfo are now stale */ + unit_remove_dependencies(UNIT(m), UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT); } static void mount_enter_mounted(Mount *m, MountResult f) { @@ -1844,6 +1848,7 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, } mount->from_proc_self_mountinfo = false; + assert_se(update_parameters_proc_self_mount_info(mount, NULL, NULL, NULL) >= 0); switch (mount->state) {