summaryrefslogtreecommitdiffstats
path: root/ui/common
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 /ui/common
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 'ui/common')
-rw-r--r--ui/common/discover-client.c54
-rw-r--r--ui/common/discover-client.h2
2 files changed, 52 insertions, 4 deletions
diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c
index c0cfea0..42aa9de 100644
--- a/ui/common/discover-client.c
+++ b/ui/common/discover-client.c
@@ -1,4 +1,5 @@
+#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@@ -37,6 +38,20 @@ void discover_client_destroy(struct discover_client *client)
talloc_free(client);
}
+static struct device *find_device(struct discover_client *client,
+ const char *id)
+{
+ int i;
+
+ for (i = 0; i < client->n_devices; i++) {
+ struct device *dev = client->devices[i];
+ if (!strcmp(dev->id, id))
+ return dev;
+ }
+
+ return NULL;
+}
+
static void device_add(struct discover_client *client, struct device *device)
{
client->n_devices++;
@@ -46,7 +61,25 @@ static void device_add(struct discover_client *client, struct device *device)
client->devices[client->n_devices - 1] = device;
talloc_steal(client, device);
- client->ops.device_add(device, client->ops.cb_arg);
+ if (client->ops.device_add)
+ client->ops.device_add(device, client->ops.cb_arg);
+}
+
+static void boot_option_add(struct discover_client *client,
+ struct boot_option *opt)
+{
+ struct device *dev;
+
+ dev = find_device(client, opt->device_id);
+
+ /* we require that devices are already present before any boot options
+ * are added */
+ assert(dev);
+
+ talloc_steal(dev, opt);
+
+ if (client->ops.boot_option_add)
+ client->ops.boot_option_add(dev, opt, client->ops.cb_arg);
}
static void device_remove(struct discover_client *client, const char *id)
@@ -81,6 +114,7 @@ static int discover_client_process(void *arg)
{
struct discover_client *client = arg;
struct pb_protocol_message *message;
+ struct boot_option *opt;
struct device *dev;
char *dev_id;
int rc;
@@ -91,8 +125,9 @@ static int discover_client_process(void *arg)
return -1;
switch (message->action) {
- case PB_PROTOCOL_ACTION_ADD:
- dev = talloc(client, struct device);
+ case PB_PROTOCOL_ACTION_DEVICE_ADD:
+ dev = talloc_zero(client, struct device);
+ list_init(&dev->boot_options);
rc = pb_protocol_deserialise_device(dev, message);
if (rc) {
@@ -102,7 +137,18 @@ static int discover_client_process(void *arg)
device_add(client, dev);
break;
- case PB_PROTOCOL_ACTION_REMOVE:
+ case PB_PROTOCOL_ACTION_BOOT_OPTION_ADD:
+ opt = talloc_zero(client, struct boot_option);
+
+ rc = pb_protocol_deserialise_boot_option(opt, message);
+ if (rc) {
+ pb_log("%s: no boot_option?\n", __func__);
+ return 0;
+ }
+
+ boot_option_add(client, opt);
+ break;
+ case PB_PROTOCOL_ACTION_DEVICE_REMOVE:
dev_id = pb_protocol_deserialise_string(client, message);
if (!dev_id) {
pb_log("%s: no device id?\n", __func__);
diff --git a/ui/common/discover-client.h b/ui/common/discover-client.h
index 6d5d1c4..5317b44 100644
--- a/ui/common/discover-client.h
+++ b/ui/common/discover-client.h
@@ -21,6 +21,8 @@ struct pb_boot_data {
struct discover_client_ops {
int (*device_add)(struct device *device, void *arg);
+ int (*boot_option_add)(struct device *dev, struct boot_option *option,
+ void *arg);
void (*device_remove)(struct device *device, void *arg);
void *cb_arg;
};
OpenPOWER on IntegriCloud