]> git.ozlabs.org Git - petitboot/blobdiff - discover/device-handler.c
discover: Don't invert option discovery order
[petitboot] / discover / device-handler.c
index a8df295df1b6e4763516b68de240c6fa907240a7..0fc6d75b0e64db0ce0a01773a779fd269663acfc 100644 (file)
@@ -149,8 +149,20 @@ static void context_commit(struct device_handler *handler,
                        discover_server_notify_boot_option_add(handler->server,
                                                                opt->option);
                } else {
-                       list_add(&handler->unresolved_boot_options, &opt->list);
-                       talloc_steal(handler, opt);
+                       if (!opt->source->resolve_resource) {
+                               pb_log("parser %s gave us an unresolved "
+                                       "resource (%s), but no way to "
+                                       "resolve it\n",
+                                       opt->source->name, opt->option->id);
+                               talloc_free(opt);
+                       } else {
+                               pb_log("boot option %s is unresolved, "
+                                               "adding to queue\n",
+                                               opt->option->id);
+                               list_add(&handler->unresolved_boot_options,
+                                               &opt->list);
+                               talloc_steal(handler, opt);
+                       }
                }
        }
 }
@@ -159,7 +171,7 @@ void discover_context_add_boot_option(struct discover_context *ctx,
                struct discover_boot_option *boot_option)
 {
        boot_option->source = ctx->parser;
-       list_add(&ctx->boot_options, &boot_option->list);
+       list_add_tail(&ctx->boot_options, &boot_option->list);
        talloc_steal(ctx, boot_option);
 }
 
@@ -388,7 +400,7 @@ static int handle_add_udev_event(struct device_handler *handler,
        }
 
        /* run the parsers. This will populate the ctx's boot_option list. */
-       iterate_parsers(ctx);
+       iterate_parsers(ctx, CONF_METHOD_LOCAL_FILE);
 
        /* add discovered stuff to the handler */
        context_commit(handler, ctx);
@@ -451,6 +463,61 @@ static int handle_remove_user_event(struct device_handler *handler,
        return 0;
 }
 
+static enum conf_method parse_conf_method(const char *str)
+{
+
+       if (!strcasecmp(str, "dhcp")) {
+               return CONF_METHOD_DHCP;
+       }
+       return CONF_METHOD_UNKNOWN;
+}
+
+static int handle_conf_user_event(struct device_handler *handler,
+               struct event *event)
+{
+       struct discover_context *ctx;
+       struct discover_device *dev;
+       enum conf_method method;
+       const char *val;
+
+       ctx = talloc(handler, struct discover_context);
+       ctx->event = event;
+       list_init(&ctx->boot_options);
+
+       val = event_get_param(event, "url");
+       if (!val) {
+               talloc_free(ctx);
+               return 0;
+       }
+
+       ctx->conf_url = pb_url_parse(ctx, val);
+       if (!ctx->conf_url) {
+               talloc_free(ctx);
+               return 0;
+       }
+
+       val = event_get_param(event, "method");
+       if (!val) {
+               talloc_free(ctx);
+               return 0;
+       }
+
+       method = parse_conf_method(val);
+       if (method == CONF_METHOD_UNKNOWN) {
+               talloc_free(ctx);
+               return 0;
+       }
+
+       dev = discover_device_create(handler, ctx, event);
+       ctx->device = dev;
+
+       iterate_parsers(ctx, method);
+
+       context_commit(handler, ctx);
+
+       return 0;
+}
+
 typedef int (*event_handler)(struct device_handler *, struct event *);
 
 static event_handler handlers[EVENT_TYPE_MAX][EVENT_ACTION_MAX] = {
@@ -461,6 +528,7 @@ static event_handler handlers[EVENT_TYPE_MAX][EVENT_ACTION_MAX] = {
        [EVENT_TYPE_USER] = {
                [EVENT_ACTION_ADD]      = handle_add_user_event,
                [EVENT_ACTION_REMOVE]   = handle_remove_user_event,
+               [EVENT_ACTION_CONF]     = handle_conf_user_event,
        }
 };
 
@@ -607,6 +675,13 @@ static struct discover_boot_option *find_boot_option_by_id(
        return NULL;
 }
 
+static void boot_status(void *arg, struct boot_status *status)
+{
+       struct device_handler *handler = arg;
+
+       discover_server_notify_boot_status(handler->server, status);
+}
+
 void device_handler_boot(struct device_handler *handler,
                struct boot_command *cmd)
 {
@@ -614,5 +689,5 @@ void device_handler_boot(struct device_handler *handler,
 
        opt = find_boot_option_by_id(handler, cmd->option_id);
 
-       boot(handler, opt, cmd, handler->dry_run);
+       boot(handler, opt, cmd, handler->dry_run, boot_status, handler);
 }