summaryrefslogtreecommitdiffstats
path: root/discover
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-03-15 15:33:39 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-04-29 14:41:04 +1000
commitf7818748090c534b8d835b970373936463bff84a (patch)
tree03d4142e7470085a7ce39519cec8338b48d918f9 /discover
parent75b1278f2ab0dad22f393e4a002f797dcb8c8a3b (diff)
downloadtalos-petitboot-f7818748090c534b8d835b970373936463bff84a.tar.gz
talos-petitboot-f7818748090c534b8d835b970373936463bff84a.zip
discover: Finalise boot options during commit
Once the discover context is committed, we need to turn the resources in struct discover_boot_option into strings in struct boot_option, so that the parser can display & edit the boot option. This may cause assertions if any of the boot options contain unresolved resources, we'll fix this in the next patch. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover')
-rw-r--r--discover/device-handler.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index c661fbe..c0f6066 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -12,11 +12,13 @@
#include <log/log.h>
#include <types/types.h>
#include <system/system.h>
+#include <url/url.h>
#include "device-handler.h"
#include "discover-server.h"
#include "event.h"
#include "parser.h"
+#include "resource.h"
#include "udev.h"
#include "paths.h"
#include "boot.h"
@@ -29,6 +31,38 @@ struct device_handler {
unsigned int n_devices;
};
+static bool resource_is_resolved(struct resource *res)
+{
+ return !res || res->resolved;
+}
+
+/* We only use this in an assert, which will disappear if we're compiling
+ * with NDEBUG, so we need the 'used' attribute for these builds */
+static bool __attribute__((used)) boot_option_is_resolved(
+ struct discover_boot_option *opt)
+{
+ return resource_is_resolved(opt->boot_image) &&
+ resource_is_resolved(opt->initrd) &&
+ resource_is_resolved(opt->icon);
+}
+
+static void boot_option_finalise(struct discover_boot_option *opt)
+{
+ assert(boot_option_is_resolved(opt));
+
+ /* check that the parsers haven't set any of the final data */
+ assert(!opt->option->boot_image_file);
+ assert(!opt->option->initrd_file);
+ assert(!opt->option->icon_file);
+
+ if (opt->boot_image)
+ opt->option->boot_image_file = opt->boot_image->url->full;
+ if (opt->initrd)
+ opt->option->initrd_file = opt->initrd->url->full;
+ if (opt->icon)
+ opt->option->icon_file = opt->icon->url->full;
+}
+
/**
* context_commit - Commit a temporary discovery context to the handler,
* and notify the clients about any new options / devices
@@ -65,6 +99,7 @@ static void context_commit(struct device_handler *handler,
list_remove(&opt->list);
list_add(&dev->boot_options, &opt->list);
talloc_steal(dev, opt);
+ boot_option_finalise(opt);
discover_server_notify_boot_option_add(handler->server,
opt->option);
}
OpenPOWER on IntegriCloud