summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2016-01-22 07:18:19 +0100
committerFranck Bui <fbui@suse.com>2016-01-22 13:53:00 +0100
commitac9d396b2abbae4e7ab84f7b556f70681b66236b (patch)
tree40f5de3c22988d4ef3d097e45570dc5ed5af2cca
parentca9ec350f39096f19d6672e38ca2419877627a4b (diff)
device: make sure to not ignore re-plugged device
systemd automatically mounts device unless 'noauto' is part of the mount options. This can happen during boot if the device is plugged at that time or later when the system is already running (the latter case is not documented AFAICS). After the systemd booted, I plugged my USB device which had an entry in /etc/fstab with the default options and systemd automatically mounted it. However I noticed that if I unplugged and re-plugged the device the automatic mounting of the device didn't work anymore: systemd didn't notice that the device was re-plugged. This was due to the device unit which was not recycled by the GC during the unplug event because in the case of automounting, the mount unit still referenced it. When the device was re-plugged, the old device unit was reused but it still had the old sysfs path (amongst other useful information). Systemd was confused by the stalled sysfs path and decided to ignore the plug event. This patch fixes this issue by simply not doing the sanity checking on the sysfs path if the device is in unplugged state.
-rw-r--r--src/core/device.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/core/device.c b/src/core/device.c
index bcd4d1146b..a3a80b1408 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -315,12 +315,19 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa
u = manager_get_unit(m, e);
- if (u &&
- sysfs &&
- DEVICE(u)->sysfs &&
- !path_equal(DEVICE(u)->sysfs, sysfs)) {
- log_unit_debug(u, "Device %s appeared twice with different sysfs paths %s and %s", e, DEVICE(u)->sysfs, sysfs);
- return -EEXIST;
+ /* The device unit can still be present even if the device was
+ * unplugged: a mount unit can reference it hence preventing
+ * the GC to have garbaged it. That's desired since the device
+ * unit may have a dependency on the mount unit which was
+ * added during the loading of the later. */
+ if (u && DEVICE(u)->state == DEVICE_PLUGGED) {
+ /* This unit is in plugged state: we're sure it's
+ * attached to a device. */
+ if (!path_equal(DEVICE(u)->sysfs, sysfs)) {
+ log_unit_error(u, "Dev %s appeared twice with different sysfs paths %s and %s",
+ e, DEVICE(u)->sysfs, sysfs);
+ return -EEXIST;
+ }
}
if (!u) {