From 5e7c90eddd7ac2e4a3b05a7a5f6e29166edfa161 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Tue, 19 Mar 2013 14:00:53 +0800 Subject: [PATCH] discover: Add configuration methods We'd like to be able to download petitboot configurations from other sources (not just local files), but we'll need some way to indicate to the parsers that a chunk of config data is from a specific source. This change adds "configuration methods". At present, we have only one: CONF_METHOD_LOCAL_FILE. For any incoming configuration data, we only run parsers that have registered themselves with that configuration method. Signed-off-by: Jeremy Kerr --- discover/device-handler.c | 2 +- discover/device-handler.h | 6 ++++++ discover/grub2-parser.c | 1 + discover/kboot-parser.c | 1 + discover/parser.c | 17 +++++++++++------ discover/parser.h | 5 ++++- discover/yaboot-parser.c | 1 + test/parser/parser-test.c | 2 +- 8 files changed, 26 insertions(+), 9 deletions(-) diff --git a/discover/device-handler.c b/discover/device-handler.c index a8df295..6ff70c1 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -388,7 +388,7 @@ static int handle_add_udev_event(struct device_handler *handler, } /* run the parsers. This will populate the ctx's boot_option list. */ - iterate_parsers(ctx); + iterate_parsers(ctx, CONF_METHOD_LOCAL_FILE); /* add discovered stuff to the handler */ context_commit(handler, ctx); diff --git a/discover/device-handler.h b/discover/device-handler.h index be55f73..ad9f50a 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -11,6 +11,11 @@ struct boot_command; struct event; struct device; +enum conf_method { + CONF_METHOD_LOCAL_FILE, /* discover by looking at local files on this + block device */ +}; + struct discover_device { struct device *device; @@ -43,6 +48,7 @@ struct discover_context { struct event *event; struct discover_device *device; struct list boot_options; + enum conf_method method; }; struct device_handler *device_handler_init(struct discover_server *server, diff --git a/discover/grub2-parser.c b/discover/grub2-parser.c index 4a1acf5..0589329 100644 --- a/discover/grub2-parser.c +++ b/discover/grub2-parser.c @@ -193,6 +193,7 @@ static int grub2_parse(struct discover_context *dc, char *buf, int len) static struct parser grub2_parser = { .name = "grub2", + .method = CONF_METHOD_LOCAL_FILE, .parse = grub2_parse, .filenames = grub2_conf_files, }; diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c index 884658e..f097674 100644 --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -159,6 +159,7 @@ static int kboot_parse(struct discover_context *dc, char *buf, int len) static struct parser kboot_parser = { .name = "kboot", + .method = CONF_METHOD_LOCAL_FILE, .parse = kboot_parse, .filenames = kboot_conf_files, .resolve_resource = resolve_devpath_resource, diff --git a/discover/parser.c b/discover/parser.c index 641e06b..c04a0af 100644 --- a/discover/parser.c +++ b/discover/parser.c @@ -98,18 +98,23 @@ static void iterate_parser_files(struct discover_context *ctx, } } -void iterate_parsers(struct discover_context *ctx) +void iterate_parsers(struct discover_context *ctx, enum conf_method method) { int i; pb_log("trying parsers for %s\n", ctx->device->device->id); - for (i = 0; i < n_parsers; i++) { - pb_log("\ttrying parser '%s'\n", parsers[i]->name); - ctx->parser = parsers[i]; - iterate_parser_files(ctx, parsers[i]); + if (method == CONF_METHOD_LOCAL_FILE) { + for (i = 0; i < n_parsers; i++) { + if (parsers[i]->method != CONF_METHOD_LOCAL_FILE) + continue; + + pb_log("\ttrying parser '%s'\n", parsers[i]->name); + ctx->parser = parsers[i]; + iterate_parser_files(ctx, ctx->parser); + } + ctx->parser = NULL; } - ctx->parser = NULL; } void __register_parser(struct parser *parser) diff --git a/discover/parser.h b/discover/parser.h index 03ba8d4..b738577 100644 --- a/discover/parser.h +++ b/discover/parser.h @@ -3,6 +3,8 @@ #include +#include "device-handler.h" + struct discover_context; struct device_handler; struct resource; @@ -25,6 +27,7 @@ struct resource; */ struct parser { char *name; + enum conf_method method; const char * const *filenames; int (*parse)(struct discover_context *ctx, char *buf, int len); @@ -45,7 +48,7 @@ enum generic_icon_type { void parser_init(void); -void iterate_parsers(struct discover_context *ctx); +void iterate_parsers(struct discover_context *ctx, enum conf_method method); int parse_user_event(struct discover_context *ctx, struct event *event); #endif /* _PARSER_H */ diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c index f51d2c6..816e0c4 100644 --- a/discover/yaboot-parser.c +++ b/discover/yaboot-parser.c @@ -315,6 +315,7 @@ static int yaboot_parse(struct discover_context *dc, char *buf, int len) static struct parser yaboot_parser = { .name = "yaboot", + .method = CONF_METHOD_LOCAL_FILE, .parse = yaboot_parse, .filenames = yaboot_conf_files, }; diff --git a/test/parser/parser-test.c b/test/parser/parser-test.c index 33b411b..bf4ac6c 100644 --- a/test/parser/parser-test.c +++ b/test/parser/parser-test.c @@ -110,7 +110,7 @@ int main(int argc, char **argv) argv[1], argv[2]); ctx->device->device->id = talloc_strdup(ctx->device->device, argv[2]); - iterate_parsers(ctx); + iterate_parsers(ctx, CONF_METHOD_LOCAL_FILE); pb_log("--- end ---\n"); -- 2.39.2