discover: Handle incoming configuration messages
authorJeremy Kerr <jk@ozlabs.org>
Thu, 24 Oct 2013 06:43:05 +0000 (14:43 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 13 Nov 2013 09:28:18 +0000 (17:28 +0800)
When the client sends us a PB_PROTOCOL_ACTION_CONFIG message, we want to
update the current config.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/device-handler.c
discover/device-handler.h
discover/discover-server.c
lib/pb-config/pb-config.c

index 6fa14f9dd07ffb8c82d9df94c3344a12ca3d9ff5..725e491d1f6f9c87d11f1918826b049e0ba76885 100644 (file)
@@ -1,4 +1,3 @@
-
 #include <assert.h>
 #include <stdlib.h>
 #include <stdbool.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <stdbool.h>
@@ -717,6 +716,13 @@ void device_handler_cancel_default(struct device_handler *handler)
        discover_server_notify_boot_status(handler->server, &status);
 }
 
        discover_server_notify_boot_status(handler->server, &status);
 }
 
+void device_handler_update_config(struct device_handler *handler,
+               struct config *config)
+{
+       config_set(config);
+       discover_server_notify_config(handler->server, config);
+}
+
 #ifndef PETITBOOT_TEST
 static bool check_existing_mount(struct discover_device *dev)
 {
 #ifndef PETITBOOT_TEST
 static bool check_existing_mount(struct discover_device *dev)
 {
index 56d585a8ba117f4e474c4ba1e134dab6c176ef45..bad7447cfbb2e9e71ee9a3bac3ff8861f800aa54 100644 (file)
@@ -13,6 +13,7 @@ struct boot_command;
 struct event;
 struct device;
 struct waitset;
 struct event;
 struct device;
 struct waitset;
+struct config;
 
 struct discover_device {
        struct device           *device;
 
 struct discover_device {
        struct device           *device;
@@ -114,6 +115,8 @@ const char *discover_device_get_param(struct discover_device *device,
 void device_handler_boot(struct device_handler *handler,
                struct boot_command *cmd);
 void device_handler_cancel_default(struct device_handler *handler);
 void device_handler_boot(struct device_handler *handler,
                struct boot_command *cmd);
 void device_handler_cancel_default(struct device_handler *handler);
+void device_handler_update_config(struct device_handler *handler,
+               struct config *config);
 
 int device_request_write(struct discover_device *dev, bool *release);
 void device_release_write(struct discover_device *dev, bool release);
 
 int device_request_write(struct discover_device *dev, bool *release);
 void device_release_write(struct discover_device *dev, bool release);
index bd631f61bf86eac57c76dbfb8dfcb43476ad741a..3cf9facc07ff700d6d4e4d30b42c0a9271591344 100644 (file)
@@ -214,6 +214,7 @@ static int discover_server_process_message(void *arg)
        struct pb_protocol_message *message;
        struct boot_command *boot_command;
        struct client *client = arg;
        struct pb_protocol_message *message;
        struct boot_command *boot_command;
        struct client *client = arg;
+       struct config *config;
        int rc;
 
        message = pb_protocol_read_message(client, client->fd);
        int rc;
 
        message = pb_protocol_read_message(client, client->fd);
@@ -243,6 +244,19 @@ static int discover_server_process_message(void *arg)
                device_handler_cancel_default(client->server->device_handler);
                break;
 
                device_handler_cancel_default(client->server->device_handler);
                break;
 
+       case PB_PROTOCOL_ACTION_CONFIG:
+               config = talloc_zero(client, struct config);
+
+               rc = pb_protocol_deserialise_config(config, message);
+               if (rc) {
+                       pb_log("%s: no config?", __func__);
+                       return 0;
+               }
+
+               device_handler_update_config(client->server->device_handler,
+                               config);
+               break;
+
        default:
                pb_log("%s: invalid action %d\n", __func__, message->action);
                return 0;
        default:
                pb_log("%s: invalid action %d\n", __func__, message->action);
                return 0;
index 40bc39fc516a36da4593899cbe762bd36d26162d..915a01d47abaaab8a7929eef6f2abddc7e90d1fb 100644 (file)
@@ -100,9 +100,9 @@ int config_set(struct config *newconfig)
                return 0;
 
        pb_log("new configuration data received\n");
                return 0;
 
        pb_log("new configuration data received\n");
-       dump_config(config);
+       dump_config(newconfig);
 
 
-       rc = storage->save(storage, config);
+       rc = storage->save(storage, newconfig);
 
        if (!rc)
                config = talloc_steal(config_ctx, newconfig);
 
        if (!rc)
                config = talloc_steal(config_ctx, newconfig);