Skip to content

Commit

Permalink
discover/udev.c: Added warning for duplicate FS UUIDs in system statu…
Browse files Browse the repository at this point in the history
…s 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 <[email protected]>
Signed-off-by: Jeremy Kerr <[email protected]>
  • Loading branch information
LuluTHSu authored and jk-ozlabs committed Oct 12, 2021
1 parent f7f9822 commit dd9e426
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions discover/device-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct discover_device {

const char *uuid;
const char *label;
const char *id_path;

char *mount_path;
char *root_path;
Expand All @@ -36,6 +37,7 @@ struct discover_device {
bool crypt_device;

bool notified;
bool dup_warn;

struct list boot_options;
struct list params;
Expand Down
21 changes: 20 additions & 1 deletion discover/udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down

0 comments on commit dd9e426

Please sign in to comment.