discover: Implement device handler boot path
authorJeremy Kerr <jk@ozlabs.org>
Wed, 6 Mar 2013 09:14:58 +0000 (17:14 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 15 Apr 2013 07:42:27 +0000 (15:42 +0800)
This change adds a funtion, device_handler_boot, which processes the
boot command message from the discover server.

We add a new file, discover/boot.c (and a corresponding header) with a
skeleton for the final kexec code.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/Makefile.am
discover/boot.c [new file with mode: 0644]
discover/boot.h [new file with mode: 0644]
discover/device-handler.c
discover/device-handler.h
discover/discover-server.c

index 5f634425f948dca00a2953040888cde779382eb2..0e208357cfc1de34a62b55f691b84e4488a35508 100644 (file)
@@ -41,6 +41,8 @@ libparser_la_LIBADD = $(top_builddir)/lib/libpbcore.la
 sbin_PROGRAMS = pb-discover
 
 pb_discover_SOURCES = \
+       boot.c \
+       boot.h \
        device-handler.c \
        device-handler.h \
        discover-server.c \
diff --git a/discover/boot.c b/discover/boot.c
new file mode 100644 (file)
index 0000000..ddb9e7d
--- /dev/null
@@ -0,0 +1,14 @@
+
+#include "boot.h"
+
+int boot(void *ctx, struct boot_option *opt, struct boot_command *cmd,
+               int dry_run)
+{
+       /* todo: run kexec with options from opt & cmd */
+       (void)ctx;
+       (void)opt;
+       (void)cmd;
+       (void)dry_run;
+
+       return 0;
+}
diff --git a/discover/boot.h b/discover/boot.h
new file mode 100644 (file)
index 0000000..be2ca57
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef _BOOT_H
+#define _BOOT_H
+
+struct boot_option;
+struct boot_command;
+
+int boot(void *ctx, struct boot_option *opt, struct boot_command *cmd,
+               int dry_run);
+
+#endif /* _BOOT_H */
index 0d4349671dfa6c375f223cde0f43877c41ddad71..6a27f15780a5a4ae290e2ddf6d1b95f789dadb02 100644 (file)
@@ -19,6 +19,7 @@
 #include "parser.h"
 #include "udev.h"
 #include "paths.h"
+#include "boot.h"
 
 struct device_handler {
        struct discover_server *server;
@@ -429,3 +430,30 @@ void device_handler_destroy(struct device_handler *handler)
 {
        talloc_free(handler);
 }
+
+static struct boot_option *find_boot_option_by_id(
+               struct device_handler *handler, const char *id)
+{
+       unsigned int i;
+
+       for (i = 0; i < handler->n_devices; i++) {
+               struct device *dev = handler->devices[i];
+               struct boot_option *opt;
+
+               list_for_each_entry(&dev->boot_options, opt, list)
+                       if (!strcmp(opt->id, id))
+                               return opt;
+       }
+
+       return NULL;
+}
+
+void device_handler_boot(struct device_handler *handler,
+               struct boot_command *cmd)
+{
+       struct boot_option *opt;
+
+       opt = find_boot_option_by_id(handler, cmd->option_id);
+
+       boot(handler, opt, cmd, 0);
+}
index 796b328649bdcfc515d0e8d338d0109a38f5ec5d..7207f8d94104e2b93b385cbef196ecf9320d539c 100644 (file)
@@ -5,6 +5,7 @@
 
 struct device_handler;
 struct discover_server;
+struct boot_command;
 struct event;
 struct device;
 
@@ -30,4 +31,7 @@ const struct device *device_handler_get_device(
 
 int device_handler_event(struct device_handler *handler, struct event *event);
 
+void device_handler_boot(struct device_handler *handler,
+               struct boot_command *cmd);
+
 #endif /* _DEVICE_HANDLER_H */
index 76d03d1c10159924a3a73cf096d57827dd9ca31b..6c803728511cb5ea523ee52f33668a7f6982c166 100644 (file)
@@ -149,7 +149,7 @@ static int discover_server_process_message(void *arg)
                return 0;
        }
 
-       /* todo: pass boot_command to client->server->device_handler */
+       device_handler_boot(client->server->device_handler, boot_command);
 
        return 0;
 }