[10/29] discover: add handler reference to struct discover_context
diff mbox

Message ID 20161219041915.30497-11-sam@mendozajonas.com
State Accepted
Headers show

Commit Message

Samuel Mendoza-Jonas Dec. 19, 2016, 4:18 a.m. UTC
From: Jeremy Kerr <jk@ozlabs.org>

Since the device handler provides the status message functions, we need
a pointer to it for device discovery (which we use a struct
discover_context for).

This change adds a 'handler' member to struct discover_context, to allow
status reporting. Since we now have a handler, there's no need for the
network pointer, so provide an accessor function instead.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/device-handler.c | 8 +++++++-
 discover/device-handler.h | 4 +++-
 discover/pxe-parser.c     | 6 ++++--
 test/parser/utils.c       | 1 +
 4 files changed, 15 insertions(+), 4 deletions(-)

Patch
diff mbox

diff --git a/discover/device-handler.c b/discover/device-handler.c
index a9a24ae..fd9b155 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -114,6 +114,12 @@  const struct discover_device *device_handler_get_device(
 	return handler->devices[index];
 }
 
+struct network *device_handler_get_network(
+		const struct device_handler *handler)
+{
+	return handler->network;
+}
+
 struct discover_boot_option *discover_boot_option_create(
 		struct discover_context *ctx,
 		struct discover_device *device)
@@ -787,8 +793,8 @@  struct discover_context *device_handler_discover_context_create(
 	struct discover_context *ctx;
 
 	ctx = talloc_zero(handler, struct discover_context);
+	ctx->handler = handler;
 	ctx->device = device;
-	ctx->network = handler->network;
 	list_init(&ctx->boot_options);
 
 	return ctx;
diff --git a/discover/device-handler.h b/discover/device-handler.h
index fe8a3b0..874133d 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -54,12 +54,12 @@  struct discover_boot_option {
 
 
 struct discover_context {
+	struct device_handler	*handler;
 	struct parser		*parser;
 	struct event		*event;
 	struct discover_device	*device;
 	struct list		boot_options;
 	struct pb_url		*conf_url;
-	struct network		*network;
 	void			*test_data;
 };
 
@@ -79,6 +79,8 @@  void device_handler_destroy(struct device_handler *devices);
 int device_handler_get_device_count(const struct device_handler *handler);
 const struct discover_device *device_handler_get_device(
 	const struct device_handler *handler, unsigned int index);
+struct network *device_handler_get_network(
+		const struct device_handler *handler);
 
 struct discover_device *discover_device_create(struct device_handler *handler,
 		const char *uuid, const char *id);
diff --git a/discover/pxe-parser.c b/discover/pxe-parser.c
index 8237c4b..cd5f149 100644
--- a/discover/pxe-parser.c
+++ b/discover/pxe-parser.c
@@ -11,6 +11,7 @@ 
 #include <file/file.h>
 #include <i18n/i18n.h>
 
+#include "device-handler.h"
 #include "parser.h"
 #include "parser-conf.h"
 #include "parser-utils.h"
@@ -108,8 +109,9 @@  static void pxe_process_sysappend(struct discover_context *ctx,
 		return;
 
 	if (val & 0x2) {
-		uint8_t *mac = find_mac_by_name(ctx, ctx->network,
-					event->device);
+		uint8_t *mac = find_mac_by_name(ctx,
+				device_handler_get_network(ctx->handler),
+				event->device);
 		str = pxe_sysappend_mac(ctx, mac);
 		if (str) {
 			pxe_append_string(opt, str);
diff --git a/test/parser/utils.c b/test/parser/utils.c
index f0796fd..6bc7cc5 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -93,6 +93,7 @@  static struct discover_context *test_create_context(struct parser_test *test)
 	list_init(&ctx->boot_options);
 	ctx->device = test_create_device_simple(test);
 	ctx->test_data = test;
+	ctx->handler = test->handler;
 	device_handler_add_device(test->handler, ctx->device);
 
 	return ctx;