X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=22866e6600e29cb869c6196055447fa74b1619f8;hp=352a477d16230c49b4a14c6201bf3d7ab03de649;hb=24a530d0b58f57f151ee6d3df9f747ae98ef759f;hpb=edcfca78ac49793e295ac97328942321f39e3996 diff --git a/discover/device-handler.c b/discover/device-handler.c index 352a477..22866e6 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -57,6 +57,7 @@ static int mount_device(struct discover_device *dev); static int umount_device(struct discover_device *dev); static int device_handler_init_sources(struct device_handler *handler); +static void device_handler_reinit_sources(struct device_handler *handler); void discover_context_add_boot_option(struct discover_context *ctx, struct discover_boot_option *boot_option) @@ -284,6 +285,9 @@ struct device_handler *device_handler_init(struct discover_server *server, parser_init(); + if (config_get()->safe_mode) + return handler; + rc = device_handler_init_sources(handler); if (rc) { talloc_free(handler); @@ -293,6 +297,31 @@ struct device_handler *device_handler_init(struct discover_server *server, return handler; } +void device_handler_reinit(struct device_handler *handler) +{ + struct discover_boot_option *opt, *tmp; + unsigned int i; + + device_handler_cancel_default(handler); + + /* free unresolved boot options */ + list_for_each_entry_safe(&handler->unresolved_boot_options, + opt, tmp, list) + talloc_free(opt); + list_init(&handler->unresolved_boot_options); + + /* drop all devices */ + for (i = 0; i < handler->n_devices; i++) + discover_server_notify_device_remove(handler->server, + handler->devices[i]->device); + + talloc_free(handler->devices); + handler->devices = NULL; + handler->n_devices = 0; + + device_handler_reinit_sources(handler); +} + void device_handler_remove(struct device_handler *handler, struct discover_device *device) { @@ -318,6 +347,11 @@ void device_handler_remove(struct device_handler *handler, talloc_free(opt); } + /* if this is a network device, we have to unregister it from the + * network code */ + if (device->device->type == DEVICE_TYPE_NETWORK) + network_unregister_device(handler->network, device); + handler->n_devices--; memmove(&handler->devices[i], &handler->devices[i + 1], (handler->n_devices - i) * sizeof(handler->devices[0])); @@ -347,7 +381,7 @@ static void countdown_status(struct device_handler *handler, status.progress = -1; status.detail = NULL; status.message = talloc_asprintf(handler, - "Booting %s in %u sec", opt->option->name, sec); + "Booting in %d sec: %s", sec, opt->option->name); discover_server_notify_boot_status(handler->server, &status); @@ -410,6 +444,22 @@ static int default_option_priority(struct discover_boot_option *opt) return 0; } +static bool device_allows_default(struct discover_device *dev) +{ + const char *dev_str; + + dev_str = config_get()->boot_device; + + if (!dev_str || !strlen(dev_str)) + return true; + + /* default devices are specified by UUIDs at present */ + if (strcmp(dev->uuid, dev_str)) + return false; + + return true; +} + static void set_default(struct device_handler *handler, struct discover_boot_option *opt) { @@ -418,6 +468,10 @@ static void set_default(struct device_handler *handler, if (!handler->autoboot_enabled) return; + /* do we allow default-booting from this device? */ + if (!device_allows_default(opt->device)) + return; + new_prio = default_option_priority(opt); /* A negative priority indicates that we don't want to boot this device @@ -620,6 +674,8 @@ void device_handler_add_device(struct device_handler *handler, struct discover_device *, handler->n_devices); handler->devices[handler->n_devices - 1] = device; + if (device->device->type == DEVICE_TYPE_NETWORK) + network_register_device(handler->network, device); } /* Start discovery on a hotplugged device. The device will be in our devices @@ -761,8 +817,14 @@ void device_handler_cancel_default(struct device_handler *handler) void device_handler_update_config(struct device_handler *handler, struct config *config) { - config_set(config); + int rc; + + rc = config_set(config); + if (rc) + return; + discover_server_notify_config(handler->server, config); + device_handler_reinit(handler); } #ifndef PETITBOOT_TEST @@ -786,6 +848,22 @@ static int device_handler_init_sources(struct device_handler *handler) return 0; } +static void device_handler_reinit_sources(struct device_handler *handler) +{ + /* if we haven't initialised sources previously (becuase we started in + * safe mode), then init once here. */ + if (!(handler->udev || handler->network || handler->user_event)) { + device_handler_init_sources(handler); + return; + } + + udev_reinit(handler->udev); + + network_shutdown(handler->network); + handler->network = network_init(handler, handler->waitset, + handler->dry_run); +} + static bool check_existing_mount(struct discover_device *dev) { struct stat devstat, mntstat; @@ -953,6 +1031,11 @@ static int device_handler_init_sources( return 0; } +static void device_handler_reinit_sources( + struct device_handler *handler __attribute__((unused))) +{ +} + static int umount_device(struct discover_device *dev __attribute__((unused))) { return 0;