-
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <sys/wait.h>
-#include <pb-config/pb-config.h>
#include <talloc/talloc.h>
#include <list/list.h>
#include <log/log.h>
#include "device-handler.h"
#include "discover-server.h"
+#include "platform.h"
#include "event.h"
#include "parser.h"
#include "resource.h"
#include "paths.h"
+#include "sysinfo.h"
#include "boot.h"
struct device_handler {
void device_handler_remove(struct device_handler *handler,
struct discover_device *device)
{
+ struct discover_boot_option *opt, *tmp;
unsigned int i;
for (i = 0; i < handler->n_devices; i++)
return;
}
+ /* Free any unresolved options, as they're currently allocated
+ * against the handler */
+ list_for_each_entry_safe(&handler->unresolved_boot_options,
+ opt, tmp, list) {
+ if (opt->device != device)
+ continue;
+ list_remove(&opt->list);
+ talloc_free(opt);
+ }
+
handler->n_devices--;
memmove(&handler->devices[i], &handler->devices[i + 1],
(handler->n_devices - i) * sizeof(handler->devices[0]));
static bool priority_match(struct boot_priority *prio,
struct discover_boot_option *opt)
{
- return prio->type == opt->device->device->type;
+ return prio->type == opt->device->device->type ||
+ prio->type == DEVICE_TYPE_ANY;
}
static int default_option_priority(struct discover_boot_option *opt)
for (i = 0; i < config->n_boot_priorities; i++) {
prio = &config->boot_priorities[i];
if (priority_match(prio, opt))
- break;
+ return prio->priority;
}
- return i;
+ return 0;
}
static void set_default(struct device_handler *handler,
struct discover_boot_option *opt)
{
+ int new_prio;
+
if (!handler->autoboot_enabled)
return;
+ new_prio = default_option_priority(opt);
+
+ /* A negative priority indicates that we don't want to boot this device
+ * by default */
+ if (new_prio < 0)
+ return;
+
/* 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;
+ int cur_prio;
- new_prio = default_option_priority(opt);
cur_prio = default_option_priority(
handler->default_boot_option);
- if (new_prio < cur_prio) {
+ if (new_prio > cur_prio) {
handler->default_boot_option = opt;
/* extend the timeout a little, so the user sees some
* indication of the change */
if (rc)
goto out;
+ /* add this device to our system info */
+ system_info_register_blockdev(dev->device->id, dev->uuid,
+ dev->mount_path);
+
/* run the parsers. This will populate the ctx's boot_option list. */
iterate_parsers(ctx);
discover_server_notify_boot_status(handler->server, &status);
}
+void device_handler_update_config(struct device_handler *handler,
+ struct config *config)
+{
+ config_set(config);
+ discover_server_notify_config(handler->server, config);
+}
+
#ifndef PETITBOOT_TEST
static bool check_existing_mount(struct discover_device *dev)
{