summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-03-11 14:07:36 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-04-16 11:41:46 +0800
commit12a5c9153ce95ddde7fb14eaba9d779933a3637c (patch)
tree0919a8d387e617c01b4a462d7cd9fe0cedbc709c
parentbd06734362bb727b09b943688d9b69aa0a84590d (diff)
downloadtalos-petitboot-12a5c9153ce95ddde7fb14eaba9d779933a3637c.tar.gz
talos-petitboot-12a5c9153ce95ddde7fb14eaba9d779933a3637c.zip
discover: Consolidate user events by device ID
Currently, we assume all user events are for a new device. This means that we can never add boot options to an existing device. This change tries to find an existing (matching by ID) device before creating a new one in the user event add path. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--discover/device-handler.c24
-rw-r--r--discover/event-parser.c6
-rw-r--r--discover/parser.h3
-rw-r--r--ui/test/discover-test.c18
4 files changed, 36 insertions, 15 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index ab27b51..4ba7405 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -347,23 +347,25 @@ static int handle_add_user_event(struct device_handler *handler,
assert(event->device);
- device = talloc_zero(handler, struct device);
+ device = device_handler_find(handler, event->device);
- if (!device)
- goto fail;
+ if (!device) {
+ device = talloc_zero(handler, struct device);
- device->id = talloc_strdup(device, event->device);
- list_init(&device->boot_options);
+ if (!device)
+ goto fail;
- parse_user_event(device, event);
+ device->id = talloc_strdup(device, event->device);
+ list_init(&device->boot_options);
- discover_server_notify_device_add(handler->server, device);
+ /* add device to handler device array */
+ device_handler_add(handler, device);
- list_for_each_entry(&device->boot_options, opt, list)
- discover_server_notify_boot_option_add(handler->server, opt);
+ discover_server_notify_device_add(handler->server, device);
+ }
- /* add device to handler device array */
- device_handler_add(handler, device);
+ opt = parse_user_event(device, event);
+ discover_server_notify_boot_option_add(handler->server, opt);
return 0;
diff --git a/discover/event-parser.c b/discover/event-parser.c
index 1eec5c9..c09c5ba 100644
--- a/discover/event-parser.c
+++ b/discover/event-parser.c
@@ -13,7 +13,7 @@
* Understands params: name, image, args.
*/
-int parse_user_event(struct device *device, struct event *event)
+struct boot_option *parse_user_event(struct device *device, struct event *event)
{
struct boot_option *opt;
const char *p;
@@ -54,9 +54,9 @@ int parse_user_event(struct device *device, struct event *event)
device_add_boot_option(device, opt);
- return 0;
+ return opt;
fail:
talloc_free(opt);
- return -1;
+ return NULL;
}
diff --git a/discover/parser.h b/discover/parser.h
index 589c6ff..a80d1b5 100644
--- a/discover/parser.h
+++ b/discover/parser.h
@@ -21,6 +21,7 @@ enum generic_icon_type {
void parser_init(void);
void iterate_parsers(struct discover_context *ctx);
-int parse_user_event(struct device *device, struct event *event);
+struct boot_option *parse_user_event(struct device *device,
+ struct event *event);
#endif /* _PARSER_H */
diff --git a/ui/test/discover-test.c b/ui/test/discover-test.c
index ae43b1e..8f7c2c2 100644
--- a/ui/test/discover-test.c
+++ b/ui/test/discover-test.c
@@ -28,6 +28,23 @@ static int print_device_add(struct device *device,
return 0;
}
+static int print_boot_option_add(struct device *dev,
+ struct boot_option *opt,
+ void __attribute__((unused)) *arg)
+{
+ printf("new boot option (dev: %s):\n", dev->id);
+ printf("\tdev id: %s\n", opt->device_id);
+ printf("\tid: %s\n", opt->id);
+ printf("\tname: %s\n", opt->name);
+ printf("\tdesc: %s\n", opt->description);
+ printf("\ticon: %s\n", opt->icon_file);
+ printf("\tboot: %s\n", opt->boot_image_file);
+ printf("\tinit: %s\n", opt->initrd_file);
+ printf("\targs: %s\n", opt->boot_args);
+
+ return 0;
+}
+
static void print_device_remove(struct device *device,
void __attribute__((unused)) *arg)
{
@@ -38,6 +55,7 @@ static void print_device_remove(struct device *device,
static struct discover_client_ops client_ops = {
.device_add = print_device_add,
+ .boot_option_add = print_boot_option_add,
.device_remove = print_device_remove,
};
OpenPOWER on IntegriCloud