923a60
From d5ab3fdc9bf9353478e7c0987b3830f14bbdefae Mon Sep 17 00:00:00 2001
923a60
From: Michal Sekletar <msekleta@redhat.com>
923a60
Date: Thu, 22 Jun 2017 14:26:39 +0200
923a60
Subject: [PATCH] core: unset sysfs path after transition to dead state
923a60
923a60
Device is gone and most likely it will get garbage collected. However in
923a60
cases when it doesn't get gc'ed (because it is referenced by some
923a60
other unit, e.g. mount from fstab) we need to unset sysfs. This is
923a60
because when device appears next time, possibly, with different sysfs
923a60
path we need to update the sysfs path. Current code could end up caching
923a60
stale sysfs path forever.
923a60
923a60
In reality this is not a problem for normal disks (unless you swap them
923a60
during system runtime). However this issue causes failures to mount
923a60
filesystems on LVM where sysfs path depends on activation
923a60
order (i.e. logical volumes from volume group that is activated first
923a60
get assigned lower dm-X numbers and corresponding syspaths).
923a60
923a60
Fixes #6126
923a60
923a60
(cherry picked from commit 0e139cac0318de09e6f4c1a4fc61388f7e541ebd)
923a60
923a60
Resolves: #1408916
923a60
---
923a60
 src/core/device.c | 6 +++++-
923a60
 1 file changed, 5 insertions(+), 1 deletion(-)
923a60
923a60
diff --git a/src/core/device.c b/src/core/device.c
923a60
index befbae83fd..63a04bdd3c 100644
923a60
--- a/src/core/device.c
923a60
+++ b/src/core/device.c
923a60
@@ -474,12 +474,16 @@ static void device_update_found_one(Device *d, bool add, DeviceFound found, bool
923a60
                  * now referenced by the kernel, then we assume the
923a60
                  * kernel knows it now, and udev might soon too. */
923a60
                 device_set_state(d, DEVICE_TENTATIVE);
923a60
-        else
923a60
+        else {
923a60
                 /* If nobody sees the device, or if the device was
923a60
                  * previously seen by udev and now is only referenced
923a60
                  * from the kernel, then we consider the device is
923a60
                  * gone, the kernel just hasn't noticed it yet. */
923a60
+
923a60
                 device_set_state(d, DEVICE_DEAD);
923a60
+                device_unset_sysfs(d);
923a60
+        }
923a60
+
923a60
 }
923a60
 
923a60
 static int device_update_found_by_sysfs(Manager *m, const char *sysfs, bool add, DeviceFound found, bool now) {