diff mbox series

discover/udev.c: Added warning in system status log

Message ID 20211007032624.25842-1-Lulu_Su@wistron.com
State New
Headers show
Series discover/udev.c: Added warning in system status log | expand

Commit Message

Lulu Su Oct. 7, 2021, 3:26 a.m. UTC
From: LuluTHSu <Lulu_Su@wistron.com>

When a new device is detected with the same UUID as an already mounted
device, a warning is issued in the status log, which is used to alert
the user that the new device will be ignored.

Signed-off-by: LuluTHSu <Lulu_Su@wistron.com>
---
 discover/device-handler.h |  2 ++
 discover/udev.c           | 21 ++++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

Comments

Jeremy Kerr Oct. 12, 2021, 12:43 a.m. UTC | #1
Hi Lulu,


> When a new device is detected with the same UUID as an already
> mounted device, a warning is issued in the status log, which is used
> to alert the user that the new device will be ignored.

Applied, with a couple of whitespace fixes.

Thanks for all the work on this!

Cheers,


Jeremy
diff mbox series

Patch

diff --git a/discover/device-handler.h b/discover/device-handler.h
index 6591120..216d17b 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -25,6 +25,7 @@  struct discover_device {
 
 	const char		*uuid;
 	const char		*label;
+	const char		*id_path;
 
 	char			*mount_path;
 	char			*root_path;
@@ -36,6 +37,7 @@  struct discover_device {
 	bool			crypt_device;
 
 	bool			notified;
+	bool			dup_warn;
 
 	struct list		boot_options;
 	struct list		params;
diff --git a/discover/udev.c b/discover/udev.c
index 0c3da66..04ed8f1 100644
--- a/discover/udev.c
+++ b/discover/udev.c
@@ -20,6 +20,7 @@ 
 #include <waiter/waiter.h>
 #include <system/system.h>
 #include <process/process.h>
+#include <i18n/i18n.h>
 
 #include "event.h"
 #include "udev.h"
@@ -101,6 +102,7 @@  static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
 	const char *prop;
 	const char *type;
 	const char *devname;
+	const char *idpath;
 	const char *ignored_types[] = {
 		"linux_raid_member",
 		"swap",
@@ -179,11 +181,19 @@  static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
 	/* We may see multipath devices; they'll have the same uuid as an
 	 * existing device, so only parse the first. */
 	uuid = udev_device_get_property_value(dev, "ID_FS_UUID");
+	idpath = udev_device_get_property_value(dev, "ID_PATH");
 	if (uuid) {
 		ddev = device_lookup_by_uuid(udev->handler, uuid);
 		if (ddev) {
 			pb_log("SKIP: %s UUID [%s] already present (as %s)\n",
 					name, uuid, ddev->device->id);
+			/* Only warn once in petitboot status log to remind users */
+			if (strcmp(idpath, ddev->id_path) && !ddev->dup_warn) {
+				device_handler_status_info(udev->handler, 
+				_("Duplicate filesystem as %s detected; skipping duplicates"), 
+				ddev->device->id);
+				ddev->dup_warn = true;
+			} 
 			return 0;
 		}
 	}
@@ -211,6 +221,7 @@  static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
 		}
 	}
 
+	ddev->id_path = talloc_strdup(ddev, idpath);
 	ddev->device_path = talloc_strdup(ddev, node);
 	talloc_free(devlinks);
 
@@ -355,6 +366,7 @@  static int udev_handle_dev_remove(struct pb_udev *udev, struct udev_device *dev)
 {
 	struct discover_device *ddev;
 	const char *name;
+	const char *uuid;
 
 	name = udev_device_get_sysname(dev);
 	if (!name) {
@@ -363,8 +375,15 @@  static int udev_handle_dev_remove(struct pb_udev *udev, struct udev_device *dev)
 	}
 
 	ddev = device_lookup_by_id(udev->handler, name);
-	if (!ddev)
+	if (!ddev) {
+		uuid = udev_device_get_property_value(dev, "ID_FS_UUID");
+		if (uuid) {
+			ddev = device_lookup_by_uuid(udev->handler, uuid);
+			if (ddev)
+				ddev->dup_warn = false;
+		}
 		return 0;
+	}
 
 	device_handler_remove(udev->handler, ddev);