]> git.ozlabs.org Git - petitboot/commitdiff
discover-client: Add discover_client_boot
authorJeremy Kerr <jk@ozlabs.org>
Wed, 27 Feb 2013 03:00:32 +0000 (11:00 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 15 Apr 2013 07:42:26 +0000 (15:42 +0800)
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 <jk@ozlabs.org>
lib/pb-protocol/pb-protocol.c
lib/pb-protocol/pb-protocol.h
ui/common/discover-client.c
ui/common/discover-client.h
ui/common/ui-system.h

index 1d1a84b8901a3069c6a957382b992b395dc7b7f4..4e0af873b710ad8d72707c9fa60190076197e865 100644 (file)
@@ -183,6 +183,14 @@ int pb_protocol_device_len(const struct device *dev)
        return len;
 }
 
        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;
 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;
 }
 
        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;
 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
 {
        int total_len, rc;
index beb18cc2e0f11f6e07fdc0f1456511e3b1ee6233..2ec264cce26a045ef68582ab5815449cca7a5f05 100644 (file)
@@ -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);
 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,
 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);
                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);
 
 
 int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
 
index cd9f63a9f68f584bcc5b3f26976fd6d73269ad11..9374dc538506fd788a4c246a547f6d0b0629d38f 100644 (file)
@@ -172,3 +172,42 @@ struct device *discover_client_get_device(struct discover_client *client,
 
        return client->devices[index];
 }
 
        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;
+}
index 4af936c57cf498644e51e75052f3a6278395463b..6e768d9f9c50b463a296d6fab9a1d235f0a3faf6 100644 (file)
@@ -5,6 +5,12 @@
 
 struct discover_client;
 
 
 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.
 /**
  * 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);
  */
 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
 #endif
index bf4f4e9e115a8de9efdcbf567306275f41cba776..b4372ee7fcab02ab8be7239b2d0dac017322d723 100644 (file)
 #include "system/system.h"
 #include "types/types.h"
 #include "ui/common/timer.h"
 #include "system/system.h"
 #include "types/types.h"
 #include "ui/common/timer.h"
+#include "ui/common/discover-client.h"
 
 #include <signal.h>
 
 
 #include <signal.h>
 
-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);
 
 int pb_boot(const struct pb_boot_data *bd, int dry_run);
 int pb_start_daemon(void);