It's a bit hacky but it should work. = From: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx> Date: Sun, 18 Oct 2009 17:27:10 +0900 Subject: [PATCH] iscsi: add 'portal' boot option This patch enables you to specify the portal address and port: tgtd --iscsi portal=192.168.18.3:3261 If you want to specify only the address: tgtd --iscsi portal=192.168.18.3 Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx> --- usr/iscsi/iscsi_rdma.c | 2 +- usr/iscsi/iscsi_tcp.c | 4 ++-- usr/iscsi/iscsid.c | 39 ++++++++++++++++++++++++++++++++++++++- usr/iscsi/iscsid.h | 3 +++ usr/iscsi/isns.c | 2 +- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/usr/iscsi/iscsi_rdma.c b/usr/iscsi/iscsi_rdma.c index b25abf7..6cf5677 100644 --- a/usr/iscsi/iscsi_rdma.c +++ b/usr/iscsi/iscsi_rdma.c @@ -1146,7 +1146,7 @@ static int iscsi_rdma_init(void) { int ret; struct sockaddr_in sock_addr; - short int port = ISCSI_LISTEN_PORT; + short int port = iscsi_listen_port; rdma_evt_channel = rdma_create_event_channel(); diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c index edc4e86..8fc145f 100644 --- a/usr/iscsi/iscsi_tcp.c +++ b/usr/iscsi/iscsi_tcp.c @@ -176,13 +176,13 @@ static int iscsi_tcp_init(void) 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", iscsi_listen_port); memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; - ret = getaddrinfo(NULL, servname, &hints, &res0); + ret = getaddrinfo(iscsi_portal_addr, servname, &hints, &res0); if (ret) { eprintf("unable to get address info, %m\n"); return -errno; diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c index 634e0d1..0199978 100644 --- a/usr/iscsi/iscsid.c +++ b/usr/iscsi/iscsid.c @@ -42,6 +42,9 @@ #define MAX_QUEUE_CMD 128 +int iscsi_listen_port = ISCSI_LISTEN_PORT; +char *iscsi_portal_addr; + enum { IOSTATE_FREE, @@ -828,7 +831,7 @@ static void text_scan_text(struct iscsi_connection *conn) if (ss.ss_family == AF_INET6) *p++ = ']'; - sprintf(p, ":%d,1", ISCSI_LISTEN_PORT); + sprintf(p, ":%d,1", iscsi_listen_port); target_list_build(conn, buf, strcmp(value, "All") ? value : NULL); } else @@ -2253,7 +2256,41 @@ static struct tgt_driver iscsi = { .default_bst = "rdwr", }; +static int iscsi_param_parser(char *p) +{ + while (*p) { + if (!strncmp(p, "portal", 6)) { + char *addr, *q; + int len; + + addr = p + 7; + + q = strchr(addr, ':'); + if (q) + iscsi_listen_port = atoi(q + 1); + else + q = strchr(addr, ','); + + if (q) + len = q - addr; + else + len = strlen(addr); + + iscsi_portal_addr = zalloc(len + 1); + memcpy(iscsi_portal_addr, addr, len); + } + + p += strcspn(p, ","); + if (*p == ',') + ++p; + } + + return 0; +} + __attribute__((constructor)) static void iscsi_driver_constructor(void) { register_driver(&iscsi); + + setup_param("iscsi", iscsi_param_parser); } diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h index 02caad2..9eecfa2 100644 --- a/usr/iscsi/iscsid.h +++ b/usr/iscsi/iscsid.h @@ -251,6 +251,9 @@ enum task_flags { TASK_in_scsi, }; +extern int iscsi_listen_port; +extern char *iscsi_portal_addr; + #define set_task_pending(t) ((t)->flags |= (1 << TASK_pending)) #define clear_task_pending(t) ((t)->flags &= ~(1 << TASK_pending)) #define task_pending(t) ((t)->flags & (1 << TASK_pending)) diff --git a/usr/iscsi/isns.c b/usr/iscsi/isns.c index 88e5211..3bfc1fc 100644 --- a/usr/iscsi/isns.c +++ b/usr/iscsi/isns.c @@ -392,7 +392,7 @@ int isns_target_register(char *name) uint16_t flags = 0, length = 0; struct isns_hdr *hdr = (struct isns_hdr *) buf; struct isns_tlv *tlv; - uint32_t port = htonl(ISCSI_LISTEN_PORT); + uint32_t port = htonl(iscsi_listen_port); uint32_t node = htonl(ISNS_NODE_TARGET); uint32_t type = htonl(2); struct iscsi_target *target; -- 1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html