[stgt] [PATCH RFC] support multiple target instances

Or Gerlitz ogerlitz at voltaire.com
Thu Sep 24 15:50:27 CEST 2009


enable multi target instances to run on the same system by enhancing
tgt to listen on non default network and on non default management socket.

Both back (admin) and front (network) ends are identified by a
--port NNNN directive (parameter) provided to tgtd/tgtadm through
thier command line.

Signed-off-by: Or Gerlitz <ogerlitz at voltaire.com>

This work is in RFC-on-the-concept now, I believe there's a
clever to pass the port param to at least some of the components
that needs it.


Index: tgt-upstream/usr/iscsi/iscsi_rdma.c
===================================================================
--- tgt-upstream.orig/usr/iscsi/iscsi_rdma.c
+++ tgt-upstream/usr/iscsi/iscsi_rdma.c
@@ -224,8 +224,6 @@ static int waiting_rdma_slot;
 #define uint64_from_ptr(p) (uint64_t)(uintptr_t)(p)
 #define ptr_from_int64(p) (void *)(unsigned long)(p)

-#define ISCSI_LISTEN_PORT 3260
-
 /*
  * Crazy hard-coded linux iser settings need 128 * 8 slots + slop, plus
  * room for our rdmas and send requests.
@@ -1144,9 +1142,10 @@ static void iser_sched_tx(struct event_d
  */
 static int iscsi_rdma_init(void)
 {
+	extern short int tgt_port;
 	int ret;
 	struct sockaddr_in sock_addr;
-	short int port = ISCSI_LISTEN_PORT;
+	short int port = tgt_port;

 	rdma_evt_channel = rdma_create_event_channel();

Index: tgt-upstream/usr/iscsi/iscsi_tcp.c
===================================================================
--- tgt-upstream.orig/usr/iscsi/iscsi_tcp.c
+++ tgt-upstream/usr/iscsi/iscsi_tcp.c
@@ -171,12 +171,13 @@ static void iscsi_tcp_event_handler(int

 static int iscsi_tcp_init(void)
 {
+	extern short int tgt_port;
 	struct addrinfo hints, *res, *res0;
 	char servname[64];
 	int ret, fd, opt, nr_sock = 0;

 	memset(servname, 0, sizeof(servname));
-	snprintf(servname, sizeof(servname), "%d", ISCSI_LISTEN_PORT);
+	snprintf(servname, sizeof(servname), "%d", tgt_port);

 	memset(&hints, 0, sizeof(hints));
 	hints.ai_socktype = SOCK_STREAM;
Index: tgt-upstream/usr/mgmt.c
===================================================================
--- tgt-upstream.orig/usr/mgmt.c
+++ tgt-upstream/usr/mgmt.c
@@ -552,10 +552,13 @@ out:
 	return;
 }

+
 int ipc_init(void)
 {
+	extern short int tgt_port;
 	int fd, err;
 	struct sockaddr_un addr;
+	char path[256];

 	fd = socket(AF_LOCAL, SOCK_STREAM, 0);
 	if (fd < 0) {
@@ -563,10 +566,11 @@ int ipc_init(void)
 		return -1;
 	}

-	unlink(TGT_IPC_NAMESPACE);
+	sprintf(path,"%s.%d",TGT_IPC_NAMESPACE,tgt_port);
+	unlink(path);
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
-	strncpy(addr.sun_path, TGT_IPC_NAMESPACE, sizeof(addr.sun_path));
+	strncpy(addr.sun_path, path, sizeof(addr.sun_path));

 	err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
 	if (err) {
Index: tgt-upstream/usr/tgtadm.c
===================================================================
--- tgt-upstream.orig/usr/tgtadm.c
+++ tgt-upstream/usr/tgtadm.c
@@ -122,10 +122,11 @@ struct option const long_options[] = {
 	{"bus", required_argument, NULL, 'B'},
 	{"device-type", required_argument, NULL, 'Y'},
 	{"outgoing", no_argument, NULL, 'O'},
+	{"port", required_argument, NULL, 'R'},
 	{NULL, 0, NULL, 0},
 };

-static char *short_options = "dhL:o:m:t:s:c:l:n:v:b:E:T:I:u:p:H:P:B:Y:O";
+static char *short_options = "dhL:o:m:t:s:c:l:n:v:b:E:T:I:u:p:H:P:B:Y:O:R:";

 static void usage(int status)
 {
@@ -174,6 +175,7 @@ Linux SCSI Target Framework Administrati
   --lld [driver] --mode account --op unbind --tid=[id] --user=[name]\n\
                         delete the specific account having [name] from specific\n\
                         target.\n\
+  --port NNNN		admin directive sent to tgt instance that uses port NNNN (default 3260)\n\
   --help                display this help and exit\n\
 \n\
 Report bugs to <stgt at vger.kernel.org>.\n", TGT_VERSION);
@@ -181,10 +183,16 @@ Report bugs to <stgt at vger.kernel.org>.\n
 	exit(status == 0 ? 0 : EINVAL);
 }

+/* default TGT listen endpoint for admin communication and
+   iSCSI listen port for incoming connections */
+#define ISCSI_LISTEN_PORT 3260
+short int tgt_port = ISCSI_LISTEN_PORT;
+
 static int ipc_mgmt_connect(int *fd)
 {
 	int err;
 	struct sockaddr_un addr;
+	char path[256];

 	*fd = socket(AF_LOCAL, SOCK_STREAM, 0);
 	if (*fd < 0) {
@@ -194,7 +202,8 @@ static int ipc_mgmt_connect(int *fd)

 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
-	strncpy(addr.sun_path, TGT_IPC_NAMESPACE, sizeof(addr.sun_path));
+	sprintf(path,"%s.%d", TGT_IPC_NAMESPACE, tgt_port);
+	strncpy(addr.sun_path, path, sizeof(addr.sun_path));

 	err = connect(*fd, (struct sockaddr *) &addr, sizeof(addr));
 	if (err < 0)
@@ -518,6 +527,9 @@ int main(int argc, char **argv)
 		case 'O':
 			ac_dir = ACCOUNT_TYPE_OUTGOING;
 			break;
+		case 'R':
+			tgt_port = strtol(optarg, NULL, 10);
+			break;
 		case 'd':
 			debug = 1;
 			break;
@@ -551,7 +563,7 @@ int main(int argc, char **argv)
 		}
 		switch (op) {
 		case OP_NEW:
-			rc = verify_mode_params(argc, argv, "LmotT");
+			rc = verify_mode_params(argc, argv, "LmotTR");
 			if (rc) {
 				eprintf("target mode: option '-%c' is not "
 					  "allowed/supported\n", rc);
@@ -564,7 +576,7 @@ int main(int argc, char **argv)
 			break;
 		case OP_DELETE:
 		case OP_SHOW:
-			rc = verify_mode_params(argc, argv, "Lmot");
+			rc = verify_mode_params(argc, argv, "LmotR");
 			if (rc) {
 				eprintf("target mode: option '-%c' is not "
 					  "allowed/supported\n", rc);
@@ -573,7 +585,7 @@ int main(int argc, char **argv)
 			break;
 		case OP_BIND:
 		case OP_UNBIND:
-			rc = verify_mode_params(argc, argv, "LmotIB");
+			rc = verify_mode_params(argc, argv, "LmotIBR");
 			if (rc) {
 				eprintf("target mode: option '-%c' is not "
 					  "allowed/supported\n", rc);
@@ -587,7 +599,7 @@ int main(int argc, char **argv)
 			}
 			break;
 		case OP_UPDATE:
-			rc = verify_mode_params(argc, argv, "Lmotnv");
+			rc = verify_mode_params(argc, argv, "LmotnvR");
 			if (rc) {
 				eprintf("target mode: option '-%c' is not "
 					  "allowed/supported\n", rc);
@@ -686,7 +698,7 @@ int main(int argc, char **argv)
 		}
 		switch (op) {
 		case OP_NEW:
-			rc = verify_mode_params(argc, argv, "LmotlbEY");
+			rc = verify_mode_params(argc, argv, "LmotlbEYR");
 			if (rc) {
 				eprintf("target mode: option '-%c' is not "
 					  "allowed/supported\n", rc);
@@ -699,7 +711,7 @@ int main(int argc, char **argv)
 			}
 			break;
 		case OP_DELETE:
-			rc = verify_mode_params(argc, argv, "Lmotl");
+			rc = verify_mode_params(argc, argv, "LmotlR");
 			if (rc) {
 				eprintf("target mode: option '-%c' is not "
 					  "allowed/supported\n", rc);
@@ -707,7 +719,7 @@ int main(int argc, char **argv)
 			}
 			break;
 		case OP_UPDATE:
-			rc = verify_mode_params(argc, argv, "LmotlP");
+			rc = verify_mode_params(argc, argv, "LmotlPR");
 			if (rc) {
 				eprintf("option '-%c' not supported in "
 					"logicalunit mode\n", rc);
Index: tgt-upstream/usr/tgtd.c
===================================================================
--- tgt-upstream.orig/usr/tgtd.c
+++ tgt-upstream/usr/tgtd.c
@@ -50,12 +50,13 @@ static LIST_HEAD(tgt_sched_events_list);
 static struct option const long_options[] =
 {
 	{"foreground", no_argument, 0, 'f'},
+	{"port", required_argument, 0, 'p'},
 	{"debug", required_argument, 0, 'd'},
 	{"help", no_argument, 0, 'h'},
 	{0, 0, 0, 0},
 };

-static char *short_options = "fd:h";
+static char *short_options = "fd:hp:";

 static void usage(int status)
 {
@@ -66,6 +67,7 @@ static void usage(int status)
 		printf("\
 Target framework daemon, version %s\n\
   -f, --foreground        make the program run in the foreground\n\
+  -p, --port  NNNN 	  use port NNNN for backend (admin) and frontend (network) communication\n\
   -d, --debug debuglevel  print debugging information\n\
   -h, --help              display this help and exit\n\
 ", TGT_VERSION);
@@ -73,6 +75,11 @@ Target framework daemon, version %s\n\
 	exit(status);
 }

+/* default TGT listen endpoint for admin communication and
+   iSCSI listen port for incoming connections */
+#define ISCSI_LISTEN_PORT 3260
+short int tgt_port = ISCSI_LISTEN_PORT;
+
 static void signal_catch(int signo) {
 }

@@ -334,6 +341,9 @@ int main(int argc, char **argv)
 		case 'f':
 			is_daemon = 0;
 			break;
+		case 'p':
+			tgt_port = atoi(optarg);
+			break;
 		case 'd':
 			is_debug = atoi(optarg);
 			break;
Index: tgt-upstream/usr/iscsi/iscsid.c
===================================================================
--- tgt-upstream.orig/usr/iscsi/iscsid.c
+++ tgt-upstream/usr/iscsi/iscsid.c
@@ -759,6 +759,7 @@ auth_err:

 static void text_scan_text(struct iscsi_connection *conn)
 {
+	extern short int tgt_port;
 	char *key, *value, *data;
 	int datasize;

@@ -793,7 +794,7 @@ static void text_scan_text(struct iscsi_
 			if (ss.ss_family == AF_INET6)
 				 *p++ = ']';

-			sprintf(p, ":%d,1", ISCSI_LISTEN_PORT);
+			sprintf(p, ":%d,1", tgt_port);
 			target_list_build(conn, buf,
 					  strcmp(value, "All") ? value : NULL);
 		} else
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list