struct discover_context *ctx)
{
struct discover_device *dev = ctx->device;
+ struct discover_boot_option *opt, *tmp;
unsigned int i, existing_device;
- struct boot_option *opt, *tmp;
/* do we already have this device? */
for (i = 0; i < handler->n_devices; i++) {
/* move boot options from the context to the device */
list_for_each_entry_safe(&ctx->boot_options, opt, tmp, list) {
list_remove(&opt->list);
- list_add(&dev->device->boot_options, &opt->list);
- dev->device->n_options++;
- discover_server_notify_boot_option_add(handler->server, opt);
+ list_add(&dev->boot_options, &opt->list);
+ talloc_steal(dev, opt);
+ discover_server_notify_boot_option_add(handler->server,
+ opt->option);
}
}
void discover_context_add_boot_option(struct discover_context *ctx,
- struct boot_option *boot_option)
+ struct discover_boot_option *boot_option)
{
list_add(&ctx->boot_options, &boot_option->list);
talloc_steal(ctx, boot_option);
* device_handler_get_device - Get a handler device by index.
*/
-const struct device *device_handler_get_device(
+const struct discover_device *device_handler_get_device(
const struct device_handler *handler, unsigned int index)
{
if (index >= handler->n_devices) {
return NULL;
}
- return handler->devices[index]->device;
+ return handler->devices[index];
}
static void setup_device_links(struct discover_device *dev)
dev = talloc_zero(ctx, struct discover_device);
dev->device = talloc_zero(dev, struct device);
- list_init(&dev->device->boot_options);
+ list_init(&dev->boot_options);
devname = event_get_param(ctx->event, "DEVNAME");
if (devname)
return dev;
}
+struct discover_boot_option *discover_boot_option_create(
+ struct discover_context *ctx,
+ struct discover_device *device)
+{
+ struct discover_boot_option *opt;
+
+ opt = talloc_zero(ctx, struct discover_boot_option);
+ opt->option = talloc_zero(opt, struct boot_option);
+ opt->device = device;
+
+ return opt;
+}
+
+
static int handle_add_udev_event(struct device_handler *handler,
struct event *event)
{
return device_lookup(device_handler, device_match_id, id);
}
-static struct boot_option *find_boot_option_by_id(
+static struct discover_boot_option *find_boot_option_by_id(
struct device_handler *handler, const char *id)
{
unsigned int i;
for (i = 0; i < handler->n_devices; i++) {
struct discover_device *dev = handler->devices[i];
- struct boot_option *opt;
+ struct discover_boot_option *opt;
- list_for_each_entry(&dev->device->boot_options, opt, list)
- if (!strcmp(opt->id, id))
+ list_for_each_entry(&dev->boot_options, opt, list)
+ if (!strcmp(opt->option->id, id))
return opt;
}
void device_handler_boot(struct device_handler *handler,
struct boot_command *cmd)
{
- struct boot_option *opt;
+ struct discover_boot_option *opt;
opt = find_boot_option_by_id(handler, cmd->option_id);
- boot(handler, opt, cmd, handler->dry_run);
+ boot(handler, opt->option, cmd, handler->dry_run);
}
char *mount_path;
char *device_path;
+
+ struct list boot_options;
+};
+
+struct discover_boot_option {
+ struct discover_device *device;
+ struct boot_option *option;
+ struct list_item list;
};
+
struct discover_context {
struct event *event;
struct discover_device *device;
void device_handler_destroy(struct device_handler *devices);
int device_handler_get_device_count(const struct device_handler *handler);
-const struct device *device_handler_get_device(
+const struct discover_device *device_handler_get_device(
const struct device_handler *handler, unsigned int index);
struct device *discover_context_device(struct discover_context *ctx);
+struct discover_boot_option *discover_boot_option_create(
+ struct discover_context *ctx,
+ struct discover_device *dev);
void discover_context_add_boot_option(struct discover_context *ctx,
- struct boot_option *opt);
+ struct discover_boot_option *opt);
int device_handler_event(struct device_handler *handler, struct event *event);
/* send existing devices to client */
n_devices = device_handler_get_device_count(server->device_handler);
for (i = 0; i < n_devices; i++) {
- const struct device *device;
- struct boot_option *opt;
+ const struct discover_boot_option *opt;
+ const struct discover_device *device;
device = device_handler_get_device(server->device_handler, i);
- write_device_add_message(server, client, device);
+ write_device_add_message(server, client, device->device);
list_for_each_entry(&device->boot_options, opt, list)
- discover_server_notify_boot_option_add(server, opt);
+ discover_server_notify_boot_option_add(server,
+ opt->option);
}
int parse_user_event(struct discover_context *ctx, struct event *event)
{
+ struct discover_boot_option *d_opt;
struct boot_option *opt;
struct device *dev;
const char *p;
dev = ctx->device->device;
- opt = talloc_zero(dev, struct boot_option);
+ d_opt = discover_boot_option_create(ctx, ctx->device);
+ opt = d_opt->option;
- if (!opt)
+ if (!d_opt)
goto fail;
p = event_get_param(event, "name");
opt->description = talloc_asprintf(opt, "%s %s", opt->boot_image_file,
opt->boot_args);
- discover_context_add_boot_option(ctx, opt);
+ discover_context_add_boot_option(ctx, d_opt);
return 0;
fail:
- talloc_free(opt);
+ talloc_free(d_opt);
return -1;
}
#include "paths.h"
struct grub2_state {
- struct boot_option *opt;
+ struct discover_boot_option *opt;
char *desc_image;
char *desc_initrd;
const char *const *known_names;
{
struct device *dev = conf->dc->device->device;
struct grub2_state *state = conf->parser_info;
+ struct boot_option *opt;
if (!state->desc_image) {
pb_log("%s: %s: no image found\n", __func__, dev->id);
}
assert(state->opt);
- assert(state->opt->name);
- assert(state->opt->boot_args);
+ opt = state->opt->option;
- state->opt->description = talloc_asprintf(state->opt, "%s %s %s",
+ assert(opt);
+ assert(opt->name);
+ assert(opt->boot_args);
+
+ opt->description = talloc_asprintf(opt, "%s %s %s",
state->desc_image,
(state->desc_initrd ? state->desc_initrd : ""),
- state->opt->boot_args);
+ opt->boot_args);
talloc_free(state->desc_initrd);
state->desc_initrd = NULL;
- conf_strip_str(state->opt->boot_args);
- conf_strip_str(state->opt->description);
+ conf_strip_str(opt->boot_args);
+ conf_strip_str(opt->description);
/* opt is persistent, so must be associated with device */
discover_context_add_boot_option(conf->dc, state->opt);
- state->opt = talloc_zero(conf->dc, struct boot_option);
- state->opt->boot_args = talloc_strdup(state->opt, "");
+ state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
+ opt = state->opt->option;
+ opt->boot_args = talloc_strdup(opt, "");
talloc_free(state->desc_image);
state->desc_image = NULL;
{
struct device *dev = conf->dc->device->device;
struct grub2_state *state = conf->parser_info;
+ struct boot_option *opt = state->opt->option;
if (!name || !conf_param_in_list(state->known_names, name))
return;
if (sep)
*sep = 0;
- state->opt->id = talloc_asprintf(state->opt, "%s#%s",
- dev->id, value);
- state->opt->name = talloc_strdup(state->opt, value);
+ opt->id = talloc_asprintf(opt, "%s#%s", dev->id, value);
+ opt->name = talloc_strdup(opt, value);
return;
}
if (sep)
*sep = 0;
- state->opt->boot_image_file = resolve_path(state->opt,
- value, conf->dc->device->device_path);
- state->desc_image = talloc_strdup(state->opt, value);
+ opt->boot_image_file = resolve_path(opt, value,
+ conf->dc->device->device_path);
+ state->desc_image = talloc_strdup(opt, value);
if (sep)
- state->opt->boot_args = talloc_strdup(state->opt,
+ opt->boot_args = talloc_strdup(opt,
sep + 1);
return;
}
if (streq(name, "initrd")) {
- state->opt->initrd_file = resolve_path(state->opt,
+ opt->initrd_file = resolve_path(opt,
value, conf->dc->device->device_path);
state->desc_initrd = talloc_asprintf(state, "initrd=%s",
value);
/* opt is persistent, so must be associated with device */
- state->opt = talloc_zero(conf->dc->device, struct boot_option);
- state->opt->boot_args = talloc_strdup(state->opt, "");
+ state->opt = discover_boot_option_create(dc, dc->device);
+ state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
conf_parse_buf(conf, buf, len);
char *value)
{
const char *const *ignored_names = conf->parser_info;
- struct device *dev;
+ struct discover_boot_option *d_opt;
+ struct boot_option *opt;
char *pos;
char *args;
const char *initrd;
const char *root;
- struct boot_option *opt;
/* ignore bare values */
/* opt must be associated with dc */
- dev = conf->dc->device->device;
- opt = talloc_zero(dev, struct boot_option);
+ d_opt = talloc_zero(conf->dc, struct discover_boot_option);
+ d_opt->device = conf->dc->device;
+ opt = talloc_zero(d_opt, struct boot_option);
if (!opt)
return;
- opt->id = talloc_asprintf(opt, "%s#%s", dev->id, name);
+ opt->id = talloc_asprintf(opt, "%s#%s", conf->dc->device->device->id,
+ name);
opt->name = talloc_strdup(opt, name);
args = talloc_strdup(opt, "");
conf_strip_str(opt->boot_args);
conf_strip_str(opt->description);
- discover_context_add_boot_option(conf->dc, opt);
+ discover_context_add_boot_option(conf->dc, d_opt);
}
static struct conf_global_option kboot_global_options[] = {
#include "paths.h"
struct yaboot_state {
- struct boot_option *opt;
+ struct discover_boot_option *opt;
const char *desc_image;
char *desc_initrd;
int globals_done;
{
struct yaboot_state *state = conf->parser_info;
struct device *dev = conf->dc->device->device;
+ struct boot_option *opt;
if (!state->desc_image) {
pb_log("%s: %s: no image found\n", __func__, dev->id);
}
assert(state->opt);
- assert(state->opt->name);
- assert(state->opt->boot_args);
- state->opt->description = talloc_asprintf(state->opt, "%s %s %s",
+ opt = state->opt->option;
+ assert(opt);
+ assert(opt->name);
+ assert(opt->boot_args);
+
+ opt->description = talloc_asprintf(opt, "%s %s %s",
state->desc_image,
(state->desc_initrd ? state->desc_initrd : ""),
- state->opt->boot_args);
+ opt->boot_args);
talloc_free(state->desc_initrd);
state->desc_initrd = NULL;
- conf_strip_str(state->opt->boot_args);
- conf_strip_str(state->opt->description);
+ conf_strip_str(opt->boot_args);
+ conf_strip_str(opt->description);
/* opt is persistent, so must be associated with device */
discover_context_add_boot_option(conf->dc, state->opt);
- state->opt = talloc_zero(conf->dc, struct boot_option);
- state->opt->boot_args = talloc_strdup(state->opt, "");
+ state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
+ state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
}
static void yaboot_process_pair(struct conf_context *conf, const char *name,
char *value)
{
struct yaboot_state *state = conf->parser_info;
+ struct boot_option *opt = state->opt->option;
struct fixed_pair {
const char *image;
const char *initrd;
/* First finish any previous image. */
- if (state->opt->boot_image_file)
+ if (opt->boot_image_file)
yaboot_finish(conf);
/* Then start the new image. */
char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
g_part);
- state->opt->boot_image_file = resolve_path(state->opt,
+ opt->boot_image_file = resolve_path(opt,
value, dev);
- state->desc_image = talloc_asprintf(state->opt,
+ state->desc_image = talloc_asprintf(opt,
"%s%s", dev, value);
talloc_free(dev);
} else if (g_boot) {
- state->opt->boot_image_file = resolve_path(state->opt,
+ opt->boot_image_file = resolve_path(opt,
value, g_boot);
- state->desc_image = talloc_asprintf(state->opt,
+ state->desc_image = talloc_asprintf(opt,
"%s%s", g_boot, value);
} else {
- state->opt->boot_image_file = resolve_path(state->opt,
+ opt->boot_image_file = resolve_path(opt,
value, conf->dc->device->device_path);
- state->desc_image = talloc_strdup(state->opt, value);
+ state->desc_image = talloc_strdup(opt, value);
}
return;
if (suse_fp) {
/* First finish any previous image. */
- if (state->opt->boot_image_file)
+ if (opt->boot_image_file)
yaboot_finish(conf);
/* Then start the new image. */
if (*value == '/') {
- state->opt->boot_image_file = resolve_path(state->opt,
+ opt->boot_image_file = resolve_path(opt,
value, conf->dc->device->device_path);
- state->desc_image = talloc_strdup(state->opt, value);
+ state->desc_image = talloc_strdup(opt, value);
} else {
- state->opt->boot_image_file = resolve_path(state->opt,
+ opt->boot_image_file = resolve_path(opt,
suse_fp->image, conf->dc->device->device_path);
- state->desc_image = talloc_strdup(state->opt,
+ state->desc_image = talloc_strdup(opt,
suse_fp->image);
- state->opt->initrd_file = resolve_path(state->opt,
+ opt->initrd_file = resolve_path(opt,
suse_fp->initrd, conf->dc->device->device_path);
state->desc_initrd = talloc_asprintf(state, "initrd=%s",
suse_fp->initrd);
return;
}
- if (!state->opt->boot_image_file) {
+ if (!opt->boot_image_file) {
pb_log("%s: unknown name: %s\n", __func__, name);
return;
}
char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
g_part);
- state->opt->initrd_file = resolve_path(state->opt,
+ opt->initrd_file = resolve_path(opt,
value, dev);
state->desc_initrd = talloc_asprintf(state,
"initrd=%s%s", dev, value);
talloc_free(dev);
} else if (g_boot) {
- state->opt->initrd_file = resolve_path(state->opt,
+ opt->initrd_file = resolve_path(opt,
value, g_boot);
state->desc_initrd = talloc_asprintf(state,
"initrd=%s%s", g_boot, value);
} else {
- state->opt->initrd_file = resolve_path(state->opt,
+ opt->initrd_file = resolve_path(opt,
value, conf->dc->device->device_path);
state->desc_initrd = talloc_asprintf(state, "initrd=%s",
value);
/* label */
if (streq(name, "label")) {
- state->opt->id = talloc_asprintf(state->opt, "%s#%s",
+ opt->id = talloc_asprintf(opt, "%s#%s",
conf->dc->device->device->id, value);
- state->opt->name = talloc_strdup(state->opt, value);
+ opt->name = talloc_strdup(opt, value);
return;
}
/* args */
if (streq(name, "append")) {
- state->opt->boot_args = talloc_asprintf_append(
- state->opt->boot_args, "%s ", value);
+ opt->boot_args = talloc_asprintf_append(
+ opt->boot_args, "%s ", value);
return;
}
if (streq(name, "initrd-size")) {
- state->opt->boot_args = talloc_asprintf_append(
- state->opt->boot_args, "ramdisk_size=%s ", value);
+ opt->boot_args = talloc_asprintf_append(
+ opt->boot_args, "ramdisk_size=%s ", value);
return;
}
if (streq(name, "literal")) {
- if (*state->opt->boot_args) {
+ if (*opt->boot_args) {
pb_log("%s: literal over writes '%s'\n", __func__,
- state->opt->boot_args);
- talloc_free(state->opt->boot_args);
+ opt->boot_args);
+ talloc_free(opt->boot_args);
}
- talloc_asprintf(state->opt, "%s ", value);
+ talloc_asprintf(opt, "%s ", value);
return;
}
if (streq(name, "ramdisk")) {
- state->opt->boot_args = talloc_asprintf_append(
- state->opt->boot_args, "ramdisk=%s ", value);
+ opt->boot_args = talloc_asprintf_append(
+ opt->boot_args, "ramdisk=%s ", value);
return;
}
if (streq(name, "read-only")) {
- state->opt->boot_args = talloc_asprintf_append(
- state->opt->boot_args, "ro ");
+ opt->boot_args = talloc_asprintf_append(
+ opt->boot_args, "ro ");
return;
}
if (streq(name, "read-write")) {
- state->opt->boot_args = talloc_asprintf_append(
- state->opt->boot_args, "rw ");
+ opt->boot_args = talloc_asprintf_append(
+ opt->boot_args, "rw ");
return;
}
if (streq(name, "root")) {
- state->opt->boot_args = talloc_asprintf_append(
- state->opt->boot_args, "root=%s ", value);
+ opt->boot_args = talloc_asprintf_append(
+ opt->boot_args, "root=%s ", value);
return;
}
/* opt is persistent, so must be associated with device */
- state->opt = talloc_zero(conf->dc->device, struct boot_option);
- state->opt->boot_args = talloc_strdup(state->opt, "");
+ state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
+ state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
conf_parse_buf(conf, buf, len);
return ctx->device->device;
}
+struct discover_boot_option *discover_boot_option_create(
+ struct discover_context *ctx,
+ struct discover_device *dev)
+{
+ struct discover_boot_option *opt;
+
+ opt = talloc_zero(ctx, struct discover_boot_option);
+ opt->option = talloc(opt, struct boot_option);
+ opt->device = dev;
+
+ return opt;
+}
+
void discover_context_add_boot_option(struct discover_context *ctx,
- struct boot_option *boot_option)
+ struct discover_boot_option *boot_option)
{
+ struct boot_option *opt = boot_option->option;
+
fprintf(testf, "%s: %s\n", __func__, ctx->device->device->id);
- fprintf(testf, " id '%s'\n", boot_option->id);
- fprintf(testf, " name '%s'\n", boot_option->name);
- fprintf(testf, " descr '%s'\n", boot_option->description);
- fprintf(testf, " icon '%s'\n", boot_option->icon_file);
- fprintf(testf, " image '%s'\n", boot_option->boot_image_file);
- fprintf(testf, " initrd '%s'\n", boot_option->initrd_file);
- fprintf(testf, " args '%s'\n", boot_option->boot_args);
+ fprintf(testf, " id '%s'\n", opt->id);
+ fprintf(testf, " name '%s'\n", opt->name);
+ fprintf(testf, " descr '%s'\n", opt->description);
+ fprintf(testf, " icon '%s'\n", opt->icon_file);
+ fprintf(testf, " image '%s'\n", opt->boot_image_file);
+ fprintf(testf, " initrd '%s'\n", opt->initrd_file);
+ fprintf(testf, " args '%s'\n", opt->boot_args);
fflush(testf);
}