anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone
923a60
From 45ff3d79f079c73c73209940cf6eaa0ea0a95708 Mon Sep 17 00:00:00 2001
923a60
From: Franck Bui <fbui@suse.com>
923a60
Date: Fri, 22 Jan 2016 07:18:19 +0100
923a60
Subject: [PATCH] device: make sure to not ignore re-plugged device
923a60
923a60
systemd automatically mounts device unless 'noauto' is part of the
923a60
mount options. This can happen during boot if the device is plugged at
923a60
that time or later when the system is already running (the latter case
923a60
is not documented AFAICS).
923a60
923a60
After the systemd booted, I plugged my USB device which had an entry
923a60
in /etc/fstab with the default options and systemd automatically
923a60
mounted it.
923a60
923a60
However I noticed that if I unplugged and re-plugged the device the
923a60
automatic mounting of the device didn't work anymore: systemd didn't
923a60
notice that the device was re-plugged.
923a60
923a60
This was due to the device unit which was not recycled by the GC
923a60
during the unplug event because in the case of automounting, the mount
923a60
unit still referenced it. When the device was re-plugged, the old
923a60
device unit was reused but it still had the old sysfs path (amongst
923a60
other useful information).
923a60
923a60
Systemd was confused by the stalled sysfs path and decided to ignore
923a60
the plug event.
923a60
923a60
This patch fixes this issue by simply not doing the sanity checking on
923a60
the sysfs path if the device is in unplugged state.
923a60
923a60
Cherry-picked from: ac9d396b2abbae4e7ab84f7b556f70681b66236b
923a60
Resolves: #1332606
923a60
---
923a60
 src/core/device.c | 18 +++++++++++++-----
923a60
 1 file changed, 13 insertions(+), 5 deletions(-)
923a60
923a60
diff --git a/src/core/device.c b/src/core/device.c
923a60
index 1995e3c0b4..fc73e263ab 100644
923a60
--- a/src/core/device.c
923a60
+++ b/src/core/device.c
923a60
@@ -314,11 +314,19 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa
923a60
 
923a60
         u = manager_get_unit(m, e);
923a60
 
923a60
-        if (u &&
923a60
-            DEVICE(u)->sysfs &&
923a60
-            !path_equal(DEVICE(u)->sysfs, sysfs)) {
923a60
-                log_unit_debug(u->id, "Device %s appeared twice with different sysfs paths %s and %s", e, DEVICE(u)->sysfs, sysfs);
923a60
-                return -EEXIST;
923a60
+        /* The device unit can still be present even if the device was
923a60
+         * unplugged: a mount unit can reference it hence preventing
923a60
+         * the GC to have garbaged it. That's desired since the device
923a60
+         * unit may have a dependency on the mount unit which was
923a60
+         * added during the loading of the later. */
923a60
+        if (u && DEVICE(u)->state == DEVICE_PLUGGED) {
923a60
+                /* This unit is in plugged state: we're sure it's
923a60
+                 * attached to a device. */
923a60
+                if (!path_equal(DEVICE(u)->sysfs, sysfs)) {
923a60
+                        log_unit_debug(u->id, "Dev %s appeared twice with different sysfs paths %s and %s",
923a60
+                                       e, DEVICE(u)->sysfs, sysfs);
923a60
+                        return -EEXIST;
923a60
+                }
923a60
         }
923a60
 
923a60
         if (!u) {