Skip to content

Commit

Permalink
discover/pxe-parser: Recognise plugin sources
Browse files Browse the repository at this point in the history
Extend the pxe-parser to recognise 'PLUGIN' as well as the usual 'LABEL'
when parsing a config file. 'PLUGIN' will be used to specify an option
that provides the location of an installable pb-plugin file, named by
the 'TARBALL' label.

Since plugin options are discovered via the same mechanism as boot
options treat them the same as boot options and at the 'type' field to
the boot_option struct to differentiate between them.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
  • Loading branch information
sammj committed Aug 15, 2017
1 parent 98b04aa commit 9f191cc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
19 changes: 15 additions & 4 deletions discover/pxe-parser.c
Expand Up @@ -148,7 +148,7 @@ static void pxe_process_pair(struct conf_context *ctx,
return;
}

if (streq(name, "LABEL")) {
if (streq(name, "LABEL") || streq(name, "PLUGIN")) {
if (opt)
pxe_finish(ctx);

Expand All @@ -158,8 +158,12 @@ static void pxe_process_pair(struct conf_context *ctx,
opt->option->id = talloc_asprintf(opt, "%s@%p",
ctx->dc->device->device->id, opt);

opt->option->is_default = parser_info->default_name &&
streq(parser_info->default_name, value);
if (streq(name, "LABEL")) {
opt->option->type = DISCOVER_BOOT_OPTION;
opt->option->is_default = parser_info->default_name &&
streq(parser_info->default_name, value);
} else
opt->option->type = DISCOVER_PLUGIN_OPTION;

parser_info->opt = opt;
return;
Expand All @@ -169,6 +173,14 @@ static void pxe_process_pair(struct conf_context *ctx,
if (!opt)
return;

if (streq(name, "TARBALL") &&
opt->option->type == DISCOVER_PLUGIN_OPTION) {
url = pxe_url_join(ctx->dc, ctx->dc->conf_url, value);
opt->boot_image = create_url_resource(opt, url);
/* All other options apply to boot options only */
return;
}

if (streq(name, "KERNEL")) {
url = pxe_url_join(ctx->dc, ctx->dc->conf_url, value);
opt->boot_image = create_url_resource(opt, url);
Expand Down Expand Up @@ -210,7 +222,6 @@ static void pxe_process_pair(struct conf_context *ctx,
url = pxe_url_join(ctx->dc, ctx->dc->conf_url, value);
opt->dtb = create_url_resource(opt, url);
}

}

static void pxe_load_next_filename(struct conf_context *conf)
Expand Down
13 changes: 12 additions & 1 deletion lib/pb-protocol/pb-protocol.c
Expand Up @@ -75,6 +75,8 @@ void pb_protocol_dump_device(const struct device *dev, const char *text,
fprintf(stream, "%s\t\tdtb: %s\n", text, opt->dtb_file);
fprintf(stream, "%s\t\targs: %s\n", text, opt->boot_args);
fprintf(stream, "%s\t\tasig: %s\n", text, opt->args_sig_file);
fprintf(stream, "%s\t\ttype: %s\n", text,
opt->type == DISCOVER_BOOT_OPTION ? "boot" : "plugin");
}
}

Expand Down Expand Up @@ -201,7 +203,8 @@ int pb_protocol_boot_option_len(const struct boot_option *opt)
4 + optional_strlen(opt->dtb_file) +
4 + optional_strlen(opt->boot_args) +
4 + optional_strlen(opt->args_sig_file) +
sizeof(opt->is_default);
sizeof(opt->is_default) +
sizeof(opt->type);
}

int pb_protocol_boot_len(const struct boot_command *boot)
Expand Down Expand Up @@ -397,6 +400,9 @@ int pb_protocol_serialise_boot_option(const struct boot_option *opt,
*(bool *)pos = opt->is_default;
pos += sizeof(bool);

*(uint32_t *)pos = __cpu_to_be32(opt->type);
pos += 4;

assert(pos <= buf + buf_len);
(void)buf_len;

Expand Down Expand Up @@ -825,6 +831,11 @@ int pb_protocol_deserialise_boot_option(struct boot_option *opt,
if (len < sizeof(bool))
goto out;
opt->is_default = *(bool *)(pos);
pos += sizeof(bool);
len -= sizeof(bool);

if (read_u32(&pos, &len, &opt->type))
return -1;

rc = 0;

Expand Down
5 changes: 5 additions & 0 deletions lib/types/types.h
Expand Up @@ -58,6 +58,11 @@ struct boot_option {
struct list_item list;

void *ui_info;

enum {
DISCOVER_BOOT_OPTION,
DISCOVER_PLUGIN_OPTION,
} type;
};

struct plugin_option {
Expand Down

0 comments on commit 9f191cc

Please sign in to comment.