diff mbox

[1/4] discover/sysinfo: Add system_info_reinit()

Message ID 20170623055115.23963-1-sam@mendozajonas.com
State Accepted
Headers show

Commit Message

Sam Mendoza-Jonas June 23, 2017, 5:51 a.m. UTC
Currently over reinit events the system info is not affected. However
network and block device information can change over reinit, so clear
this information.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/device-handler.c |  2 ++
 discover/sysinfo.c        | 18 ++++++++++++++++++
 discover/sysinfo.h        |  1 +
 3 files changed, 21 insertions(+)
diff mbox

Patch

diff --git a/discover/device-handler.c b/discover/device-handler.c
index ec1eee3..a0c21b7 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -1407,6 +1407,8 @@  static void device_handler_reinit_sources(struct device_handler *handler)
 		return;
 	}
 
+	system_info_reinit();
+
 	udev_reinit(handler->udev);
 
 	network_shutdown(handler->network);
diff --git a/discover/sysinfo.c b/discover/sysinfo.c
index 0ac29c1..e8e6d52 100644
--- a/discover/sysinfo.c
+++ b/discover/sysinfo.c
@@ -139,3 +139,21 @@  void system_info_init(struct discover_server *s)
 	sysinfo = talloc_zero(server, struct system_info);
 	platform_get_sysinfo(sysinfo);
 }
+
+/* Only reset device information. Platform information is static */
+void system_info_reinit(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < sysinfo->n_blockdevs; i++)
+		talloc_free(sysinfo->blockdevs[i]);
+	talloc_free(sysinfo->blockdevs);
+	sysinfo->blockdevs = NULL;
+	sysinfo->n_blockdevs = 0;
+
+	for (i = 0; i < sysinfo->n_interfaces; i++)
+		talloc_free(sysinfo->interfaces[i]);
+	talloc_free(sysinfo->interfaces);
+	sysinfo->interfaces = NULL;
+	sysinfo->n_interfaces = 0;
+}
diff --git a/discover/sysinfo.h b/discover/sysinfo.h
index 19ed950..c570951 100644
--- a/discover/sysinfo.h
+++ b/discover/sysinfo.h
@@ -15,6 +15,7 @@  void system_info_register_blockdev(const char *name, const char *uuid,
 		const char *mountpoint);
 
 void system_info_init(struct discover_server *server);
+void system_info_reinit(void);
 
 #endif /* SYSINFO_H */