X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=251c517f884aaa0c2212898b2e71dd3ad37a8e9e;hb=4844eaae93e9e32708f02f7e5a43edcc87435699;hp=cdfee483767e449c885d0ebf3db3671040a4c78f;hpb=f611bde3f182e9a4befb48a0160d1831708aca67;p=petitboot diff --git a/discover/device-handler.c b/discover/device-handler.c index cdfee48..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); @@ -327,6 +340,8 @@ static int default_timeout(void *arg) return 0; } + handler->timeout_waiter = NULL; + pb_log("Timeout expired, booting default option %s\n", opt->option->id); boot(handler, handler->default_boot_option, NULL, @@ -334,17 +349,56 @@ static int default_timeout(void *arg) return 0; } +static bool priority_match(struct boot_priority *prio, + struct discover_boot_option *opt) +{ + return prio->type == opt->device->device->type; +} + +static int default_option_priority(struct discover_boot_option *opt) +{ + const struct config *config; + struct boot_priority *prio; + int i; + + config = config_get(); + + for (i = 0; i < config->n_boot_priorities; i++) { + prio = &config->boot_priorities[i]; + if (priority_match(prio, opt)) + break; + } + + return i; +} + static void set_default(struct device_handler *handler, struct discover_boot_option *opt) { - if (handler->default_boot_option) + if (!handler->autoboot_enabled) return; - if (!handler->autoboot_enabled) + /* Resolve any conflicts: if we have a new default option, it only + * replaces the current if it has a higher priority. */ + if (handler->default_boot_option) { + int new_prio, cur_prio; + + new_prio = default_option_priority(opt); + cur_prio = default_option_priority( + handler->default_boot_option); + + if (new_prio < cur_prio) { + handler->default_boot_option = opt; + /* extend the timeout a little, so the user sees some + * indication of the change */ + handler->sec_to_boot += 2; + } + return; + } - handler->default_boot_option = opt; handler->sec_to_boot = config_get()->autoboot_timeout_sec; + handler->default_boot_option = opt; pb_log("Boot option %s set as default, timeout %u sec.\n", opt->option->id, handler->sec_to_boot);