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>
}
/* run the parsers. This will populate the ctx's boot_option list. */
}
/* run the parsers. This will populate the ctx's boot_option list. */
+ iterate_parsers(ctx, CONF_METHOD_LOCAL_FILE);
/* add discovered stuff to the handler */
context_commit(handler, ctx);
/* add discovered stuff to the handler */
context_commit(handler, ctx);
struct event;
struct device;
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;
struct discover_device {
struct device *device;
struct event *event;
struct discover_device *device;
struct list boot_options;
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,
};
struct device_handler *device_handler_init(struct discover_server *server,
static struct parser grub2_parser = {
.name = "grub2",
static struct parser grub2_parser = {
.name = "grub2",
+ .method = CONF_METHOD_LOCAL_FILE,
.parse = grub2_parse,
.filenames = grub2_conf_files,
};
.parse = grub2_parse,
.filenames = grub2_conf_files,
};
static struct parser kboot_parser = {
.name = "kboot",
static struct parser kboot_parser = {
.name = "kboot",
+ .method = CONF_METHOD_LOCAL_FILE,
.parse = kboot_parse,
.filenames = kboot_conf_files,
.resolve_resource = resolve_devpath_resource,
.parse = kboot_parse,
.filenames = kboot_conf_files,
.resolve_resource = resolve_devpath_resource,
-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);
{
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;
}
void __register_parser(struct parser *parser)
}
void __register_parser(struct parser *parser)
+#include "device-handler.h"
+
struct discover_context;
struct device_handler;
struct resource;
struct discover_context;
struct device_handler;
struct resource;
*/
struct parser {
char *name;
*/
struct parser {
char *name;
+ enum conf_method method;
const char * const *filenames;
int (*parse)(struct discover_context *ctx,
char *buf, int len);
const char * const *filenames;
int (*parse)(struct discover_context *ctx,
char *buf, int len);
-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 */
int parse_user_event(struct discover_context *ctx, struct event *event);
#endif /* _PARSER_H */
static struct parser yaboot_parser = {
.name = "yaboot",
static struct parser yaboot_parser = {
.name = "yaboot",
+ .method = CONF_METHOD_LOCAL_FILE,
.parse = yaboot_parse,
.filenames = yaboot_conf_files,
};
.parse = yaboot_parse,
.filenames = yaboot_conf_files,
};
argv[1], argv[2]);
ctx->device->device->id = talloc_strdup(ctx->device->device, argv[2]);
argv[1], argv[2]);
ctx->device->device->id = talloc_strdup(ctx->device->device, argv[2]);
+ iterate_parsers(ctx, CONF_METHOD_LOCAL_FILE);