[PATCH] discover/udev.c: Added warning in system status log
Lulu Su
Lulu_Su at wistron.com
Thu Oct 7 14:26:24 AEDT 2021
From: LuluTHSu <Lulu_Su at 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 at wistron.com>
---
discover/device-handler.h | 2 ++
discover/udev.c | 21 ++++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
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);
--
2.7.4
---------------------------------------------------------------------------------------------------------------------------------------------------------------
This email contains confidential or legally privileged information and is for the sole use of its intended recipient.
Any unauthorized review, use, copying or distribution of this email or the content of this email is strictly prohibited.
If you are not the intended recipient, you may reply to the sender and should delete this e-mail immediately.
---------------------------------------------------------------------------------------------------------------------------------------------------------------
More information about the Petitboot
mailing list