Blob Blame Raw
From 6e979154c9c51dedd54c91e46106e495a65ced43 Mon Sep 17 00:00:00 2001
From: Chris Leech <cleech@redhat.com>
Date: Wed, 2 Jan 2013 14:45:05 -0800
Subject: [PATCH 58/58] iscsiuio IPC newroot command

---
 usr/mgmt_ipc.c     | 11 +++++++++++
 usr/transport.c    |  1 +
 usr/transport.h    |  1 +
 usr/uip_mgmt_ipc.c | 14 ++++++++++++++
 usr/uip_mgmt_ipc.h |  5 +++++
 5 files changed, 32 insertions(+)

diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
index 5cb7143..a8f8473 100644
--- a/usr/mgmt_ipc.c
+++ b/usr/mgmt_ipc.c
@@ -36,6 +36,7 @@
 #include "sysdeps.h"
 #include "iscsi_ipc.h"
 #include "iscsi_err.h"
+#include "iscsi_sysfs.h"
 
 #define PEERUSER_MAX	64
 #define EXTMSG_MAX	(64 * 1024)
@@ -229,8 +230,18 @@ static int
 mgmt_ipc_newroot(queue_task_t *qtask)
 {
 	char *newroot = qtask->req.u.newroot.path;
+	struct iscsi_transport *t;
+
 	if (chdir(newroot) || chroot(".") || chdir("/"))
 		return ISCSI_ERR;
+
+	/* if a registered transport has a separate userspace process,
+	 * notify it of the root change as well */
+	list_for_each_entry(t, &transports, list) {
+		if (t->template->newroot)
+			t->template->newroot(t, newroot);
+	}
+
 	mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
 	return ISCSI_SUCCESS;
 }
diff --git a/usr/transport.c b/usr/transport.c
index 4d030a8..e0488ad 100644
--- a/usr/transport.c
+++ b/usr/transport.c
@@ -83,6 +83,7 @@ struct iscsi_transport_template bnx2i = {
 	.ep_poll	= ktransport_ep_poll,
 	.ep_disconnect	= ktransport_ep_disconnect,
 	.set_net_config = uip_broadcast_params,
+	.newroot	= uip_broadcast_newroot,
 };
 
 struct iscsi_transport_template be2iscsi = {
diff --git a/usr/transport.h b/usr/transport.h
index 388e4b1..d4d9ec7 100644
--- a/usr/transport.h
+++ b/usr/transport.h
@@ -39,6 +39,7 @@ struct iscsi_transport_template {
 	int (*set_net_config) (struct iscsi_transport *t,
 			       struct iface_rec *iface,
 			       struct iscsi_session *session);
+	void (*newroot) (struct iscsi_transport *t, char *path);
 };
 
 /* represents data path provider */
diff --git a/usr/uip_mgmt_ipc.c b/usr/uip_mgmt_ipc.c
index f3074ee..d5d496a 100644
--- a/usr/uip_mgmt_ipc.c
+++ b/usr/uip_mgmt_ipc.c
@@ -39,3 +39,17 @@ int uip_broadcast_params(struct iscsi_transport *t,
 			     sizeof(iscsid_uip_broadcast_header_t) +
 			     sizeof(*iface));
 }
+
+int uip_broadcast_newroot(struct iscsi_transport *t, char *newroot)
+{
+	struct iscsid_uip_broadcast broadcast;
+
+	memset(&broadcast, 0, sizeof(broadcast));
+
+	broadcast.header.command = ISCSID_UIP_NEWROOT;
+	strncpy(broadcast.u.newroot.path, newroot, PATH_MAX);
+
+	return uip_broadcast(&broadcast,
+			     sizeof(iscsid_uip_broadcast_header_t) +
+			     PATH_MAX + 1);
+}
diff --git a/usr/uip_mgmt_ipc.h b/usr/uip_mgmt_ipc.h
index 29a4769..3ca4fb1 100644
--- a/usr/uip_mgmt_ipc.h
+++ b/usr/uip_mgmt_ipc.h
@@ -29,6 +29,7 @@
 typedef enum iscsid_uip_cmd {
 	ISCSID_UIP_IPC_UNKNOWN			= 0,
 	ISCSID_UIP_IPC_GET_IFACE		= 1,
+	ISCSID_UIP_NEWROOT			= 2,
 
 	__ISCSID_UIP_IPC_MAX_COMMAND
 } iscsid_uip_cmd_e;
@@ -47,6 +48,9 @@ typedef struct iscsid_uip_broadcast {
 		struct ipc_broadcast_iface_rec {
 			struct iface_rec rec;
 		} iface_rec;
+		struct ipc_broadcast_newroot {
+			char path[PATH_MAX + 1];
+		} newroot;
 	} u;
 } iscsid_uip_broadcast_t;
 
@@ -69,5 +73,6 @@ extern int uip_broadcast_params(struct iscsi_transport *t,
 				struct iface_rec *iface,
 				struct iscsi_session *session);
 
+extern int uip_broadcast_newroot(struct iscsi_transport *t, char *path);
 
 #endif /* UIP_MGMT_IPC_H */
-- 
1.8.1.4