diff options
Diffstat (limited to 'discover')
-rw-r--r-- | discover/device-handler.c | 13 | ||||
-rw-r--r-- | discover/device-handler.h | 2 | ||||
-rw-r--r-- | discover/network.c | 10 | ||||
-rw-r--r-- | discover/udev.c | 2 | ||||
-rw-r--r-- | discover/user-event.c | 15 |
5 files changed, 29 insertions, 13 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c index 54a1986..70e4506 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -221,17 +221,22 @@ static int destroy_device(void *arg) } struct discover_device *discover_device_create(struct device_handler *handler, - const char *id) + const char *uuid, const char *id) { struct discover_device *dev; - dev = device_lookup_by_id(handler, id); + if (uuid) + dev = device_lookup_by_uuid(handler, uuid); + else + dev = device_lookup_by_id(handler, id); + if (dev) return dev; dev = talloc_zero(handler, struct discover_device); dev->device = talloc_zero(dev, struct device); dev->device->id = talloc_strdup(dev->device, id); + dev->uuid = talloc_strdup(dev, uuid); list_init(&dev->params); list_init(&dev->boot_options); @@ -1138,7 +1143,7 @@ void device_handler_process_url(struct device_handler *handler, goto msg; } - dev = discover_device_create(handler, event->device); + dev = discover_device_create(handler, mac, event->device); if (pb_url->scheme == pb_url_file) dev->device->type = DEVICE_TYPE_ANY; ctx = device_handler_discover_context_create(handler, dev); @@ -1171,7 +1176,7 @@ void device_handler_discover_context_commit(struct device_handler *handler, struct discover_device *dev = ctx->device; struct discover_boot_option *opt, *tmp; - if (!device_lookup_by_id(handler, dev->device->id)) + if (!device_lookup_by_uuid(handler, dev->uuid)) device_handler_add_device(handler, dev); /* move boot options from the context to the device */ diff --git a/discover/device-handler.h b/discover/device-handler.h index 6ffa4e1..d2e3baf 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -81,7 +81,7 @@ const struct discover_device *device_handler_get_device( const struct device_handler *handler, unsigned int index); struct discover_device *discover_device_create(struct device_handler *handler, - const char *id); + const char *uuid, const char *id); void device_handler_add_device(struct device_handler *handler, struct discover_device *device); void device_handler_add_ramdisk(struct device_handler *handler, diff --git a/discover/network.c b/discover/network.c index 2de96ec..0161c69 100644 --- a/discover/network.c +++ b/discover/network.c @@ -197,13 +197,15 @@ static char *mac_bytes_to_string(void *ctx, uint8_t *addr, int len) static void add_interface(struct network *network, struct interface *interface) { + char *uuid = mac_bytes_to_string(interface, interface->hwaddr, + sizeof(interface->hwaddr)); + list_add(&network->interfaces, &interface->list); - interface->dev = discover_device_create(network->handler, - interface->name); + interface->dev = discover_device_create(network->handler, uuid, + interface->name); interface->dev->device->type = DEVICE_TYPE_NETWORK; - interface->dev->uuid = mac_bytes_to_string(interface->dev, - interface->hwaddr, sizeof(interface->hwaddr)); device_handler_add_device(network->handler, interface->dev); + talloc_free(uuid); } static void remove_interface(struct network *network, diff --git a/discover/udev.c b/discover/udev.c index f4cefab..1e04313 100644 --- a/discover/udev.c +++ b/discover/udev.c @@ -158,7 +158,7 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, } } - ddev = discover_device_create(udev->handler, name); + ddev = discover_device_create(udev->handler, uuid, name); ddev->device_path = talloc_strdup(ddev, node); diff --git a/discover/user-event.c b/discover/user-event.c index 7ceddb1..20b2bea 100644 --- a/discover/user-event.c +++ b/discover/user-event.c @@ -385,7 +385,8 @@ static int user_event_dhcp(struct user_event *uev, struct event *event) struct device_handler *handler = uev->handler; struct discover_device *dev; - dev = discover_device_create(handler, event->device); + dev = discover_device_create(handler, event_get_param(event, "mac"), + event->device); device_handler_dhcp(handler, dev, event); @@ -398,7 +399,10 @@ static int user_event_add(struct user_event *uev, struct event *event) struct discover_context *ctx; struct discover_device *dev; - dev = discover_device_create(handler, event->device); + /* In case this is a network interface, try to refer to it by UUID */ + dev = discover_device_create(handler, event_get_param(event, "mac"), + event->device); + dev->device->id = talloc_strdup(dev, event->device); ctx = device_handler_discover_context_create(handler, dev); parse_user_event(ctx, event); @@ -414,8 +418,13 @@ static int user_event_remove(struct user_event *uev, struct event *event) { struct device_handler *handler = uev->handler; struct discover_device *dev; + const char *mac = event_get_param(event, "mac"); + + if (mac) + dev = device_lookup_by_uuid(handler, event_get_param(event, "mac")); + else + dev = device_lookup_by_id(handler, event->device); - dev = device_lookup_by_id(handler, event->device); if (!dev) return 0; |