]> git.ozlabs.org Git - petitboot/commitdiff
discover: Add configuration methods
authorJeremy Kerr <jk@ozlabs.org>
Tue, 19 Mar 2013 06:00:53 +0000 (14:00 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 29 Apr 2013 04:43:04 +0000 (14:43 +1000)
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 <jk@ozlabs.org>
discover/device-handler.c
discover/device-handler.h
discover/grub2-parser.c
discover/kboot-parser.c
discover/parser.c
discover/parser.h
discover/yaboot-parser.c
test/parser/parser-test.c

index a8df295df1b6e4763516b68de240c6fa907240a7..6ff70c14b6e2faf0265667ce2749245deb3b8c74 100644 (file)
@@ -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);
index be55f738293748725ac87d311f57163555913f9b..ad9f50a43b041003048753591e22c176527b1594 100644 (file)
@@ -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,
index 4a1acf5da371113562005a07fa763a2033138240..05893292ea2b4cf93caa30f0a2d34e4bcb9bc605 100644 (file)
@@ -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,
 };
index 884658e8d07bcd6da655fb536bf13d56f27aad85..f0976746ee80241e679124ee443e3b4a1193b983 100644 (file)
@@ -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,
index 641e06b1cb54e9bdf34d1547e8a3de465a2097f2..c04a0afca610b31bfb07468824770445cfc94d92 100644 (file)
@@ -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)
index 03ba8d4d704134b3a9a239c9da9f6657ff449505..b738577ff3d9d4a17a41bdecb3a5247774d51ad9 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <stdbool.h>
 
+#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 */
index f51d2c61d886b07c0992ba776fb430fce52a63d4..816e0c4a91f941b542791bd31f74184dcdca5288 100644 (file)
@@ -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,
 };
index 33b411b2e4dbe1e29f055526e66d3ad9ee8f8a15..bf4ac6c80ac786403528c403fd951bbcb7712851 100644 (file)
@@ -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");