diff options
-rw-r--r-- | discover/device-handler.c | 13 | ||||
-rw-r--r-- | discover/device-handler.h | 3 | ||||
-rw-r--r-- | discover/udev.c | 7 |
3 files changed, 23 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c index 95d2039..251c517 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -103,6 +103,12 @@ static int device_match_id(struct discover_device *dev, const char *id) return !strcmp(dev->device->id, id); } +static int device_match_serial(struct discover_device *dev, const char *serial) +{ + const char *val = discover_device_get_param(dev, "ID_SERIAL"); + return val && !strcmp(val, serial); +} + static struct discover_device *device_lookup( struct device_handler *device_handler, int (match_fn)(struct discover_device *, const char *), @@ -154,6 +160,13 @@ struct discover_device *device_lookup_by_id( return device_lookup(device_handler, device_match_id, id); } +struct discover_device *device_lookup_by_serial( + struct device_handler *device_handler, + const char *serial) +{ + return device_lookup(device_handler, device_match_serial, serial); +} + void device_handler_destroy(struct device_handler *handler) { talloc_free(handler); diff --git a/discover/device-handler.h b/discover/device-handler.h index 1d78a49..854be48 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -108,6 +108,9 @@ struct discover_device *device_lookup_by_label(struct device_handler *handler, const char *label); struct discover_device *device_lookup_by_id(struct device_handler *handler, const char *id); +struct discover_device *device_lookup_by_serial( + struct device_handler *device_handler, + const char *serial); void discover_device_set_param(struct discover_device *device, const char *name, const char *value); diff --git a/discover/udev.c b/discover/udev.c index 1c5cf71..e996e22 100644 --- a/discover/udev.c +++ b/discover/udev.c @@ -70,6 +70,7 @@ static int udev_handle_dev_add(struct pb_udev *udev, struct udev_device *dev) { struct discover_device *ddev; const char *typestr; + const char *serial; const char *path; const char *name; @@ -104,6 +105,12 @@ static int udev_handle_dev_add(struct pb_udev *udev, struct udev_device *dev) return -1; } + /* we may also see multipath devices; same dev nodes (hence id), but + * different serial numbers */ + serial = udev_device_get_property_value(dev, "ID_SERIAL"); + if (serial && device_lookup_by_serial(udev->handler, serial)) + return -1; + ddev = discover_device_create(udev->handler, name); ddev->device_path = udev_device_get_devnode(dev); |