X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=43171eb7e1d7f0e2f6ec95392d364597dfa8c1cf;hp=a8df295df1b6e4763516b68de240c6fa907240a7;hb=3fb8fb6fb6259e7b0894cb3756ea02dbe2d361f3;hpb=5444648fe1ff9b79f3db5ee6feadd51341f59d71 diff --git a/discover/device-handler.c b/discover/device-handler.c index a8df295..43171eb 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -75,6 +75,7 @@ static void boot_option_finalise(struct discover_boot_option *opt) assert(!opt->option->boot_image_file); assert(!opt->option->initrd_file); assert(!opt->option->icon_file); + assert(!opt->option->device_id); if (opt->boot_image) opt->option->boot_image_file = opt->boot_image->url->full; @@ -82,6 +83,8 @@ static void boot_option_finalise(struct discover_boot_option *opt) opt->option->initrd_file = opt->initrd->url->full; if (opt->icon) opt->option->icon_file = opt->icon->url->full; + + opt->option->device_id = opt->device->device->id; } static void process_boot_option_queue(struct device_handler *handler) @@ -149,8 +152,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 +174,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 +403,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 +466,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 +531,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 +678,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 +692,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); }