summaryrefslogtreecommitdiffstats
path: root/discover
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-03-19 14:00:53 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-04-29 14:43:04 +1000
commit5e7c90eddd7ac2e4a3b05a7a5f6e29166edfa161 (patch)
tree2ad50697e3380c2c14f72522fa719d3d571e7f8b /discover
parent45e92aa32a80fdbbf5ad3ad64e34b1ac872018ef (diff)
downloadtalos-petitboot-5e7c90eddd7ac2e4a3b05a7a5f6e29166edfa161.tar.gz
talos-petitboot-5e7c90eddd7ac2e4a3b05a7a5f6e29166edfa161.zip
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 <jk@ozlabs.org>
Diffstat (limited to 'discover')
-rw-r--r--discover/device-handler.c2
-rw-r--r--discover/device-handler.h6
-rw-r--r--discover/grub2-parser.c1
-rw-r--r--discover/kboot-parser.c1
-rw-r--r--discover/parser.c17
-rw-r--r--discover/parser.h5
-rw-r--r--discover/yaboot-parser.c1
7 files changed, 25 insertions, 8 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 <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 */
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,
};
OpenPOWER on IntegriCloud