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

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