summaryrefslogtreecommitdiffstats
path: root/discover/device-handler.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-04-02 14:08:26 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-04-02 14:08:26 +0800
commitedcfca78ac49793e295ac97328942321f39e3996 (patch)
tree3f92527eba90f27af3fd9fe533a0c490e7ad73ea /discover/device-handler.c
parent70fb2ec0af31c1d78c8655ef13f682d597921390 (diff)
downloadtalos-petitboot-edcfca78ac49793e295ac97328942321f39e3996.tar.gz
talos-petitboot-edcfca78ac49793e295ac97328942321f39e3996.zip
discover: move device sources to the device handler
Currently, the pb-discover main() function initialises the device handler and the device sources. We want to eventually be able to re-init the device sources, which will be initiated by the handler. In this case, the handler will need references to the sources. This change moves the creation of the device sources to be internal to the handler. This way, the device handler gets a reference to everything, without having to pass pointers around in main(). We also remove the _destroy functions, as we handle everything through talloc destructors, as all sources are parented to the handler. We also change user_event_init and udev_init to take the handler as the first ('context') argument, to make them consistent with network_init. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r--discover/device-handler.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index 8bac866..352a477 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -19,6 +19,7 @@
#include "device-handler.h"
#include "discover-server.h"
+#include "user-event.h"
#include "platform.h"
#include "event.h"
#include "parser.h"
@@ -26,11 +27,17 @@
#include "paths.h"
#include "sysinfo.h"
#include "boot.h"
+#include "udev.h"
+#include "network.h"
struct device_handler {
struct discover_server *server;
int dry_run;
+ struct pb_udev *udev;
+ struct network *network;
+ struct user_event *user_event;
+
struct discover_device **devices;
unsigned int n_devices;
@@ -49,6 +56,8 @@ struct device_handler {
static int mount_device(struct discover_device *dev);
static int umount_device(struct discover_device *dev);
+static int device_handler_init_sources(struct device_handler *handler);
+
void discover_context_add_boot_option(struct discover_context *ctx,
struct discover_boot_option *boot_option)
{
@@ -260,6 +269,7 @@ struct device_handler *device_handler_init(struct discover_server *server,
struct waitset *waitset, int dry_run)
{
struct device_handler *handler;
+ int rc;
handler = talloc_zero(NULL, struct device_handler);
handler->server = server;
@@ -274,6 +284,12 @@ struct device_handler *device_handler_init(struct discover_server *server,
parser_init();
+ rc = device_handler_init_sources(handler);
+ if (rc) {
+ talloc_free(handler);
+ return NULL;
+ }
+
return handler;
}
@@ -750,6 +766,26 @@ void device_handler_update_config(struct device_handler *handler,
}
#ifndef PETITBOOT_TEST
+
+static int device_handler_init_sources(struct device_handler *handler)
+{
+ /* init our device sources: udev, network and user events */
+ handler->udev = udev_init(handler, handler->waitset);
+ if (!handler->udev)
+ return -1;
+
+ handler->network = network_init(handler, handler->waitset,
+ handler->dry_run);
+ if (!handler->network)
+ return -1;
+
+ handler->user_event = user_event_init(handler, handler->waitset);
+ if (!handler->user_event)
+ return -1;
+
+ return 0;
+}
+
static bool check_existing_mount(struct discover_device *dev)
{
struct stat devstat, mntstat;
@@ -911,6 +947,12 @@ void device_release_write(struct discover_device *dev, bool release)
#else
+static int device_handler_init_sources(
+ struct device_handler *handler __attribute__((unused)))
+{
+ return 0;
+}
+
static int umount_device(struct discover_device *dev __attribute__((unused)))
{
return 0;
OpenPOWER on IntegriCloud