Skip to content

Commit dd9e426

Browse files
LuluTHSujk-ozlabs
authored andcommittedOct 12, 2021
discover/udev.c: Added warning for duplicate FS UUIDs in system status log
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> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
1 parent f7f9822 commit dd9e426

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
 

‎discover/device-handler.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct discover_device {
2525

2626
const char *uuid;
2727
const char *label;
28+
const char *id_path;
2829

2930
char *mount_path;
3031
char *root_path;
@@ -36,6 +37,7 @@ struct discover_device {
3637
bool crypt_device;
3738

3839
bool notified;
40+
bool dup_warn;
3941

4042
struct list boot_options;
4143
struct list params;

‎discover/udev.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <waiter/waiter.h>
2121
#include <system/system.h>
2222
#include <process/process.h>
23+
#include <i18n/i18n.h>
2324

2425
#include "event.h"
2526
#include "udev.h"
@@ -101,6 +102,7 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
101102
const char *prop;
102103
const char *type;
103104
const char *devname;
105+
const char *idpath;
104106
const char *ignored_types[] = {
105107
"linux_raid_member",
106108
"swap",
@@ -179,11 +181,19 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
179181
/* We may see multipath devices; they'll have the same uuid as an
180182
* existing device, so only parse the first. */
181183
uuid = udev_device_get_property_value(dev, "ID_FS_UUID");
184+
idpath = udev_device_get_property_value(dev, "ID_PATH");
182185
if (uuid) {
183186
ddev = device_lookup_by_uuid(udev->handler, uuid);
184187
if (ddev) {
185188
pb_log("SKIP: %s UUID [%s] already present (as %s)\n",
186189
name, uuid, ddev->device->id);
190+
/* Only warn once in petitboot status log to remind users */
191+
if (strcmp(idpath, ddev->id_path) && !ddev->dup_warn) {
192+
device_handler_status_info(udev->handler,
193+
_("Duplicate filesystem as %s detected; skipping duplicates"),
194+
ddev->device->id);
195+
ddev->dup_warn = true;
196+
}
187197
return 0;
188198
}
189199
}
@@ -211,6 +221,7 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
211221
}
212222
}
213223

224+
ddev->id_path = talloc_strdup(ddev, idpath);
214225
ddev->device_path = talloc_strdup(ddev, node);
215226
talloc_free(devlinks);
216227

@@ -355,6 +366,7 @@ static int udev_handle_dev_remove(struct pb_udev *udev, struct udev_device *dev)
355366
{
356367
struct discover_device *ddev;
357368
const char *name;
369+
const char *uuid;
358370

359371
name = udev_device_get_sysname(dev);
360372
if (!name) {
@@ -363,8 +375,15 @@ static int udev_handle_dev_remove(struct pb_udev *udev, struct udev_device *dev)
363375
}
364376

365377
ddev = device_lookup_by_id(udev->handler, name);
366-
if (!ddev)
378+
if (!ddev) {
379+
uuid = udev_device_get_property_value(dev, "ID_FS_UUID");
380+
if (uuid) {
381+
ddev = device_lookup_by_uuid(udev->handler, uuid);
382+
if (ddev)
383+
ddev->dup_warn = false;
384+
}
367385
return 0;
386+
}
368387

369388
device_handler_remove(udev->handler, ddev);
370389

0 commit comments

Comments
 (0)
Please sign in to comment.