summaryrefslogtreecommitdiffstats
path: root/discover/device-handler.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-09-19 22:18:04 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-09-19 22:21:38 +0800
commitc12cebabba5c4647f558ef40f8cbc8c6a204593e (patch)
treeb187d7ae3b60f3be2d280ac97595a1068189a651 /discover/device-handler.c
parentb324b03e2b603dafddfaac607e5f98d9cd9c0f04 (diff)
downloadtalos-petitboot-c12cebabba5c4647f558ef40f8cbc8c6a204593e.tar.gz
talos-petitboot-c12cebabba5c4647f558ef40f8cbc8c6a204593e.zip
discover: Implement device priorities
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r--discover/device-handler.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index cdfee48..f9d2dbf 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -334,17 +334,50 @@ static int default_timeout(void *arg)
return 0;
}
-static void set_default(struct device_handler *handler,
+static bool priority_match(struct boot_priority *prio,
struct discover_boot_option *opt)
{
- if (handler->default_boot_option)
- return;
+ 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->autoboot_enabled)
return;
- handler->default_boot_option = opt;
+ /* 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)
+ return;
+ }
+
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);
OpenPOWER on IntegriCloud