Blame SOURCES/open-iscsi-2.0.874-30-isolate-iscsistart-socket-use.patch

e88930
From 2a463c04a75726e811161f435e2f6736d70a66bd Mon Sep 17 00:00:00 2001
e88930
From: Chris Leech <cleech@redhat.com>
e88930
Date: Tue, 20 Jun 2017 09:35:23 -0700
e88930
Subject: isolate iscsistart socket use
e88930
e88930
---
e88930
 usr/iscsid_req.c | 12 +++++++++++-
e88930
 usr/iscsid_req.h |  3 +++
e88930
 usr/iscsistart.c |  6 ++++++
e88930
 usr/mgmt_ipc.c   |  3 ++-
e88930
 usr/mgmt_ipc.h   |  1 -
e88930
 5 files changed, 22 insertions(+), 3 deletions(-)
e88930
e88930
diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c
e88930
index 2950d748c644..69351c6c61ea 100644
e88930
--- a/usr/iscsid_req.c
e88930
+++ b/usr/iscsid_req.c
e88930
@@ -96,9 +96,19 @@ static int ipc_connect(int *fd, char *unix_sock_name, int start_iscsid)
e88930
 	return ISCSI_ERR_ISCSID_NOTCONN;
e88930
 }
e88930
 
e88930
+char iscsid_namespace[64] = ISCSIADM_NAMESPACE;
e88930
+
e88930
+void iscsid_set_namespace(pid_t pid) {
e88930
+	if (pid) {
e88930
+		snprintf(iscsid_namespace, 64, ISCSIADM_NAMESPACE "-%d", pid);
e88930
+	} else {
e88930
+		snprintf(iscsid_namespace, 64, ISCSIADM_NAMESPACE);
e88930
+	}
e88930
+}
e88930
+
e88930
 static int iscsid_connect(int *fd, int start_iscsid)
e88930
 {
e88930
-	return ipc_connect(fd, ISCSIADM_NAMESPACE, start_iscsid);
e88930
+	return ipc_connect(fd, iscsid_namespace, start_iscsid);
e88930
 }
e88930
 
e88930
 int iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid)
e88930
diff --git a/usr/iscsid_req.h b/usr/iscsid_req.h
e88930
index 8cb4a922f46d..ba7b2357c729 100644
e88930
--- a/usr/iscsid_req.h
e88930
+++ b/usr/iscsid_req.h
e88930
@@ -25,6 +25,9 @@ struct iscsiadm_req;
e88930
 struct iscsiadm_rsp;
e88930
 struct node_rec;
e88930
 
e88930
+extern char iscsid_namespace[64];
e88930
+extern void iscsid_set_namespace(pid_t);
e88930
+
e88930
 extern int iscsid_exec_req(struct iscsiadm_req *req, struct iscsiadm_rsp *rsp,
e88930
 			   int iscsid_start);
e88930
 extern int iscsid_req_wait(int cmd, int fd);
e88930
diff --git a/usr/iscsistart.c b/usr/iscsistart.c
e88930
index ecb256b3c2f6..538dd2f9d780 100644
e88930
--- a/usr/iscsistart.c
e88930
+++ b/usr/iscsistart.c
e88930
@@ -458,6 +458,10 @@ int main(int argc, char *argv[])
e88930
 	} else if (pid) {
e88930
 		int status, rc, rc2;
e88930
 
e88930
+		/* make a special socket path for only this iscsistart instance */
e88930
+		iscsid_set_namespace(pid);
e88930
+		sleep(1);
e88930
+
e88930
 		rc = setup_session();
e88930
 		rc2 = stop_event_loop();
e88930
 		/*
e88930
@@ -475,6 +478,9 @@ int main(int argc, char *argv[])
e88930
 		exit(0);
e88930
 	}
e88930
 
e88930
+	pid = getpid();
e88930
+	iscsid_set_namespace(pid);
e88930
+
e88930
 	mgmt_ipc_fd = mgmt_ipc_listen();
e88930
 	if (mgmt_ipc_fd  < 0) {
e88930
 		log_error("Could not setup mgmt ipc");
e88930
diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
e88930
index c16bce962232..140d358ec5da 100644
e88930
--- a/usr/mgmt_ipc.c
e88930
+++ b/usr/mgmt_ipc.c
e88930
@@ -37,6 +37,7 @@
e88930
 #include "iscsi_ipc.h"
e88930
 #include "iscsi_err.h"
e88930
 #include "iscsi_util.h"
e88930
+#include "iscsid_req.h"
e88930
 
e88930
 #define PEERUSER_MAX	64
e88930
 #define EXTMSG_MAX	(64 * 1024)
e88930
@@ -60,7 +61,7 @@ mgmt_ipc_listen(void)
e88930
 		return fd;
e88930
 	}
e88930
 
e88930
-	addr_len = setup_abstract_addr(&addr, ISCSIADM_NAMESPACE);
e88930
+	addr_len = setup_abstract_addr(&addr, iscsid_namespace);
e88930
 
e88930
 	if ((err = bind(fd, (struct sockaddr *) &addr, addr_len)) < 0 ) {
e88930
 		log_error("Can not bind IPC socket");
e88930
diff --git a/usr/mgmt_ipc.h b/usr/mgmt_ipc.h
e88930
index 55972ed793a1..b6b836fc07c1 100644
e88930
--- a/usr/mgmt_ipc.h
e88930
+++ b/usr/mgmt_ipc.h
e88930
@@ -115,5 +115,4 @@ int mgmt_ipc_listen(void);
e88930
 int mgmt_ipc_systemd(void);
e88930
 void mgmt_ipc_close(int fd);
e88930
 void mgmt_ipc_handle(int accept_fd);
e88930
-
e88930
 #endif /* MGMT_IPC_H */
e88930
-- 
e88930
2.9.4
e88930