summaryrefslogtreecommitdiffstats
path: root/discover
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-03-11 13:43:48 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-04-16 11:41:46 +0800
commitbd06734362bb727b09b943688d9b69aa0a84590d (patch)
tree476072cae1d0d28b286928c5fba589bde4a2d9aa /discover
parentb838cf777ed3d21b166f8daddd4b11fc75e07307 (diff)
downloadtalos-petitboot-bd06734362bb727b09b943688d9b69aa0a84590d.tar.gz
talos-petitboot-bd06734362bb727b09b943688d9b69aa0a84590d.zip
protocol: Separate device add from boot-option add messages
We want to cater for situations where boot options may be discovered some time after we get notificiation about devices. For instance, discovering boot options from DHCP configuration parameters. In this case, we'll need to notify UIs of boot options appear some time after the device (and/or other boot options on the same device) has appeared. This change adds a new protocol message type, PB_PROTOCOL_ACTION_BOOT_OPTION_ADD. We also rename PB_PROTOCOL_ACTION_ADD to make it clear that it is just for devices. The discover server is updated to send boot option add events at device discover time, but we are now able to decouple this later. We also update the clients to handle the boot option add events separately. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover')
-rw-r--r--discover/device-handler.c16
-rw-r--r--discover/discover-server.c50
-rw-r--r--discover/discover-server.h7
-rw-r--r--discover/event-parser.c1
4 files changed, 59 insertions, 15 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index 12bd5ae..ab27b51 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -275,6 +275,7 @@ static int handle_add_udev_event(struct device_handler *handler,
struct event *event)
{
struct discover_context *ctx;
+ struct boot_option *opt;
const char *devname;
int rc;
@@ -311,7 +312,10 @@ static int handle_add_udev_event(struct device_handler *handler,
/* add device to handler device array */
device_handler_add(handler, ctx->device);
- discover_server_notify_add(handler->server, ctx->device);
+ discover_server_notify_device_add(handler->server, ctx->device);
+
+ list_for_each_entry(&ctx->device->boot_options, opt, list)
+ discover_server_notify_boot_option_add(handler->server, opt);
return 0;
}
@@ -325,7 +329,7 @@ static int handle_remove_udev_event(struct device_handler *handler,
if (!ctx)
return 0;
- discover_server_notify_remove(handler->server, ctx->device);
+ discover_server_notify_device_remove(handler->server, ctx->device);
/* remove device from handler device array */
device_handler_remove(handler, ctx->device);
@@ -338,6 +342,7 @@ static int handle_remove_udev_event(struct device_handler *handler,
static int handle_add_user_event(struct device_handler *handler,
struct event *event)
{
+ struct boot_option *opt;
struct device *device;
assert(event->device);
@@ -352,7 +357,10 @@ static int handle_add_user_event(struct device_handler *handler,
parse_user_event(device, event);
- discover_server_notify_add(handler->server, device);
+ discover_server_notify_device_add(handler->server, device);
+
+ list_for_each_entry(&device->boot_options, opt, list)
+ discover_server_notify_boot_option_add(handler->server, opt);
/* add device to handler device array */
device_handler_add(handler, device);
@@ -372,7 +380,7 @@ static int handle_remove_user_event(struct device_handler *handler,
if (!device)
return 0;
- discover_server_notify_remove(handler->server, device);
+ discover_server_notify_device_remove(handler->server, device);
/* remove device from handler device array */
device_handler_remove(handler, device);
diff --git a/discover/discover-server.c b/discover/discover-server.c
index 9ec3382..9f6e7da 100644
--- a/discover/discover-server.c
+++ b/discover/discover-server.c
@@ -91,7 +91,7 @@ static int client_write_message(
return rc;
}
-static int write_add_message(struct discover_server *server,
+static int write_device_add_message(struct discover_server *server,
struct client *client, const struct device *dev)
{
struct pb_protocol_message *message;
@@ -100,7 +100,7 @@ static int write_add_message(struct discover_server *server,
len = pb_protocol_device_len(dev);
message = pb_protocol_create_message(client,
- PB_PROTOCOL_ACTION_ADD, len);
+ PB_PROTOCOL_ACTION_DEVICE_ADD, len);
if (!message)
return -1;
@@ -109,7 +109,25 @@ static int write_add_message(struct discover_server *server,
return client_write_message(server, client, message);
}
-static int write_remove_message(struct discover_server *server,
+static int write_boot_option_add_message(struct discover_server *server,
+ struct client *client, const struct boot_option *opt)
+{
+ struct pb_protocol_message *message;
+ int len;
+
+ len = pb_protocol_boot_option_len(opt);
+
+ message = pb_protocol_create_message(client,
+ PB_PROTOCOL_ACTION_BOOT_OPTION_ADD, len);
+ if (!message)
+ return -1;
+
+ pb_protocol_serialise_boot_option(opt, message->payload, len);
+
+ return client_write_message(server, client, message);
+}
+
+static int write_device_remove_message(struct discover_server *server,
struct client *client, char *dev_id)
{
struct pb_protocol_message *message;
@@ -118,7 +136,7 @@ static int write_remove_message(struct discover_server *server,
len = strlen(dev_id) + sizeof(uint32_t);
message = pb_protocol_create_message(client,
- PB_PROTOCOL_ACTION_REMOVE, len);
+ PB_PROTOCOL_ACTION_DEVICE_REMOVE, len);
if (!message)
return -1;
@@ -183,9 +201,14 @@ static int discover_server_process_connection(void *arg)
n_devices = device_handler_get_device_count(server->device_handler);
for (i = 0; i < n_devices; i++) {
const struct device *device;
+ struct boot_option *opt;
device = device_handler_get_device(server->device_handler, i);
- write_add_message(server, client, device);
+ write_device_add_message(server, client, device);
+
+ list_for_each_entry(&device->boot_options, opt, list)
+ discover_server_notify_boot_option_add(server, opt);
+
}
waiter_register(server->waitset, client->fd, WAIT_IN,
@@ -194,23 +217,32 @@ static int discover_server_process_connection(void *arg)
return 0;
}
-void discover_server_notify_add(struct discover_server *server,
+void discover_server_notify_device_add(struct discover_server *server,
struct device *device)
{
struct client *client;
list_for_each_entry(&server->clients, client, list)
- write_add_message(server, client, device);
+ write_device_add_message(server, client, device);
+
+}
+void discover_server_notify_boot_option_add(struct discover_server *server,
+ struct boot_option *boot_option)
+{
+ struct client *client;
+
+ list_for_each_entry(&server->clients, client, list)
+ write_boot_option_add_message(server, client, boot_option);
}
-void discover_server_notify_remove(struct discover_server *server,
+void discover_server_notify_device_remove(struct discover_server *server,
struct device *device)
{
struct client *client;
list_for_each_entry(&server->clients, client, list)
- write_remove_message(server, client, device->id);
+ write_device_remove_message(server, client, device->id);
}
diff --git a/discover/discover-server.h b/discover/discover-server.h
index 6650bba..e47cf5f 100644
--- a/discover/discover-server.h
+++ b/discover/discover-server.h
@@ -5,6 +5,7 @@
struct discover_server;
struct device_handler;
+struct boot_option;
struct device;
struct discover_server *discover_server_init(struct waitset *waitset);
@@ -14,8 +15,10 @@ void discover_server_destroy(struct discover_server *server);
void discover_server_set_device_source(struct discover_server *server,
struct device_handler *handler);
-void discover_server_notify_add(struct discover_server *server,
+void discover_server_notify_device_add(struct discover_server *server,
struct device *device);
-void discover_server_notify_remove(struct discover_server *server,
+void discover_server_notify_boot_option_add(struct discover_server *server,
+ struct boot_option *option);
+void discover_server_notify_device_remove(struct discover_server *server,
struct device *device);
#endif /* _DISCOVER_SERVER_H */
diff --git a/discover/event-parser.c b/discover/event-parser.c
index 0b96a09..1eec5c9 100644
--- a/discover/event-parser.c
+++ b/discover/event-parser.c
@@ -31,6 +31,7 @@ int parse_user_event(struct device *device, struct event *event)
}
opt->id = talloc_asprintf(opt, "%s#%s", device->id, p);
+ opt->device_id = talloc_strdup(opt, device->id);
opt->name = talloc_strdup(opt, p);
p = event_get_param(event, "image");
OpenPOWER on IntegriCloud