From: Jeremy Kerr Date: Wed, 27 Feb 2013 03:00:32 +0000 (+0800) Subject: discover-client: Add discover_client_boot X-Git-Tag: v1.0.0~725 X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=commitdiff_plain;h=69c459db80abece18b5557d9b8a8098a88329c28 discover-client: Add discover_client_boot This change implements the client side of the server-based boot interface. We add a funcion, discover_client_boot, which serialises a boot message, then sends it to the server. Signed-off-by: Jeremy Kerr --- diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index 1d1a84b..4e0af87 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -183,6 +183,14 @@ int pb_protocol_device_len(const struct device *dev) return len; } +int pb_protocol_boot_len(const struct boot_command *boot) +{ + return 4 + optional_strlen(boot->option_id) + + 4 + optional_strlen(boot->boot_image_file) + + 4 + optional_strlen(boot->initrd_file) + + 4 + optional_strlen(boot->boot_args); +} + int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_len) { struct boot_option *opt; @@ -223,6 +231,22 @@ int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_le return 0; } +int pb_protocol_serialise_boot_command(const struct boot_command *boot, + char *buf, int buf_len) +{ + char *pos = buf; + + pos += pb_protocol_serialise_string(pos, boot->option_id); + pos += pb_protocol_serialise_string(pos, boot->boot_image_file); + pos += pb_protocol_serialise_string(pos, boot->initrd_file); + pos += pb_protocol_serialise_string(pos, boot->boot_args); + + assert(pos <= buf + buf_len); + (void)buf_len; + + return 0; +} + int pb_protocol_write_message(int fd, struct pb_protocol_message *message) { int total_len, rc; diff --git a/lib/pb-protocol/pb-protocol.h b/lib/pb-protocol/pb-protocol.h index beb18cc..2ec264c 100644 --- a/lib/pb-protocol/pb-protocol.h +++ b/lib/pb-protocol/pb-protocol.h @@ -26,6 +26,7 @@ struct pb_protocol_message { void pb_protocol_dump_device(const struct device *dev, const char *text, FILE *stream); int pb_protocol_device_len(const struct device *dev); +int pb_protocol_boot_len(const struct boot_command *boot); int pb_protocol_device_cmp(const struct device *a, const struct device *b); int pb_protocol_boot_option_cmp(const struct boot_option *a, @@ -36,6 +37,8 @@ char *pb_protocol_deserialise_string(void *ctx, const struct pb_protocol_message *message); int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_len); +int pb_protocol_serialise_boot_command(const struct boot_command *boot, + char *buf, int buf_len); int pb_protocol_write_message(int fd, struct pb_protocol_message *message); diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c index cd9f63a..9374dc5 100644 --- a/ui/common/discover-client.c +++ b/ui/common/discover-client.c @@ -172,3 +172,42 @@ struct device *discover_client_get_device(struct discover_client *client, return client->devices[index]; } + +static void create_boot_command(struct boot_command *command, + const struct device *device __attribute__((unused)), + const struct boot_option *boot_option, + const struct pb_boot_data *data) +{ + + command->option_id = boot_option->id; + command->boot_image_file = data->image; + command->initrd_file = data->initrd; + command->boot_args = data->args; +} + +int discover_client_boot(struct discover_client *client, + const struct device *device, + const struct boot_option *boot_option, + const struct pb_boot_data *data) +{ + struct pb_protocol_message *message; + struct boot_command boot_command; + int len, rc; + + create_boot_command(&boot_command, device, boot_option, data); + + len = pb_protocol_boot_len(&boot_command); + + message = pb_protocol_create_message(client, + PB_PROTOCOL_ACTION_BOOT, len); + + if (!message) + return -1; + + pb_protocol_serialise_boot_command(&boot_command, + message->payload, len); + + rc = pb_protocol_write_message(client->fd, message); + + return rc; +} diff --git a/ui/common/discover-client.h b/ui/common/discover-client.h index 4af936c..6e768d9 100644 --- a/ui/common/discover-client.h +++ b/ui/common/discover-client.h @@ -5,6 +5,12 @@ struct discover_client; +struct pb_boot_data { + char *image; + char *initrd; + char *args; +}; + /** * struct discover_client_ops - Application supplied client info. * @device_add: PB_PROTOCOL_ACTION_ADD event callback. @@ -51,4 +57,13 @@ int discover_client_device_count(struct discover_client *client); */ struct device *discover_client_get_device(struct discover_client *client, int index); + +/* Tell the discover server to boot an image + * @param client A pointer to the discover client + * @param boot_command The command to boot + */ +int discover_client_boot(struct discover_client *client, + const struct device *device, + const struct boot_option *boot_option, + const struct pb_boot_data *data); #endif diff --git a/ui/common/ui-system.h b/ui/common/ui-system.h index bf4f4e9..b4372ee 100644 --- a/ui/common/ui-system.h +++ b/ui/common/ui-system.h @@ -24,15 +24,10 @@ #include "system/system.h" #include "types/types.h" #include "ui/common/timer.h" +#include "ui/common/discover-client.h" #include -struct pb_boot_data { - char *image; - char *initrd; - char *args; -}; - int pb_boot(const struct pb_boot_data *bd, int dry_run); int pb_start_daemon(void);