[Pkg-iscsi-maintainers] [SCM] Debian Open-iSCSI Packaging branch, upstream-mnc, updated. 2.0-872-101-g2616afb

Mike Christie michaelc at cs.wisc.edu
Mon May 2 18:56:33 UTC 2011


The following commit has been merged in the upstream-mnc branch:
commit 4d045cdeaf701f8abe6bee4f1e433f7bc9c50493
Author: Mike Christie <michaelc at cs.wisc.edu>
Date:   Tue Feb 1 02:04:30 2011 -0600

    iscsi tools: support hostnames in node mode
    
    You can now pass in hostnames as the portal argument.
    
    If you had:
    
    iscsiadm -m node -P 1
    Target: iqn.2008-09.com.meanminna:3
    	Portal: 20.15.0.12:3260,1
    		Iface Name: default
    
    Then you can do
    
    iscsiadm -m node -T iqn.2008-09.com.meanminna:3 -p somehostname -l
    
    and iscsiadm will match this.
    
    For discovery mode we already support hostnames, but we do not support
    mixing. So if you used a hostname for discovery:
    
    iscsiadm -m discoverdb -t st -p somehostname -D
    
    Then when you run other discovery commands you have to use the hostname.
    
    iscsiadm -m discoverydb -t st -p somehostname -o update -n someval -v
    val
    
    will work, but
    
    iscsiadm -m discoverydb -t st -p 20.15.0.12 -o update -n someval -v val
    
    would not.
    
    For node mode, you do not have any control what the target returns
    (and it probably returns a address) but for discovery you can pass
    in what you want, so I think this should be ok.

diff --git a/README b/README
index 9a44f3c..ee69002 100644
--- a/README
+++ b/README
@@ -651,6 +651,9 @@ To now log into targets it is the same as with sofware iscsi. See section
 	If a record does not exist, it will be created using the iscsid.conf
 	discovery settings.
 
+	The argument to -p may also be a hostname instead of an address.
+	    ./iscsiadm -m discoverydb -t st -p smoehost --discover
+
 	For the ifaces, iscsiadm will first search /etc/iscsi/ifaces for
 	interfaces using software iscsi. If any are found then nodes found
 	during discovery will be setup so that they can logged in through
@@ -775,6 +778,10 @@ To now log into targets it is the same as with sofware iscsi. See section
 	    ./iscsiadm -m node -T iqn.2005-03.com.max \
 				-p [2001:c90::211:9ff:feb8:a9e9]:3260 -l
 
+	To specify a hostname the following can be used:
+
+	    ./iscsiadm -m node -T iqn.2005-03.com.max -p somehost -l
+
     - iSCSI Login to a specific portal through the NIC setup as iface0:
 
 	    ./iscsiadm -m node -T iqn.2005-03.com.max -p 192.168.0.4:3260 \
diff --git a/doc/iscsiadm.8 b/doc/iscsiadm.8
index 177d3cd..53900a9 100644
--- a/doc/iscsiadm.8
+++ b/doc/iscsiadm.8
@@ -171,8 +171,14 @@ sid is passed in.
 
 .TP
 \fB\-p\fR, \fB\-\-portal=\fIip[:port]\fR
-Use target portal with ip-address \fIip\fR and \fIport\fR, the default
-\fIport\fR value is 3260.
+Use target portal with ip-address \fIip\fR and \fIport\fR. If port is not passed
+in the default \fIport\fR value is 3260.
+.IP
+IPv6 addresses can bs specified as [ddd.ddd.ddd.ddd]:port or
+ddd.ddd.ddd.ddd.
+.IP
+Hostnames can also be used for the ip argument.
+
 .IP
 This option is only valid for discovery, or for node operations with
 the \fInew\fR operator.
diff --git a/usr/iscsi_util.c b/usr/iscsi_util.c
index 63cef8f..978d3ed 100644
--- a/usr/iscsi_util.c
+++ b/usr/iscsi_util.c
@@ -217,6 +217,64 @@ char *cfg_get_string_param(char *pathname, const char *key)
 	return value;
 }
 
+/**
+ * iscsi_addr_match - check if the addrs are to the same ip
+ * @address1: pattern
+ * @address2: address to check
+ *
+ * If address1 is blank then it matches any string passed in.
+ */
+static int iscsi_addr_match(char *address1, char *address2)
+{
+	struct addrinfo hints1, hints2, *res1, *res2;
+	int rc;
+
+	if (!strlen(address1))
+		return 1;
+
+	if (!strcmp(address1, address2))
+		return 1;
+
+	memset(&hints1, 0, sizeof(struct addrinfo));
+	hints1.ai_family = AF_UNSPEC;
+	hints1.ai_socktype = SOCK_STREAM;
+
+	memset(&hints2, 0, sizeof(struct addrinfo));
+	hints2.ai_family = AF_UNSPEC;
+	hints2.ai_socktype = SOCK_STREAM;
+
+	/*
+	 * didn't match so we have to resolve to see if one is a dnsname
+	 * that matches a ip address.
+	 */
+	rc = getaddrinfo(address1, NULL, &hints1, &res1);
+	if (rc) {
+		log_debug(1, "Match error. Could not resolve %s: %s", address1,
+			  gai_strerror(rc));
+		return 0;
+
+	}
+
+	rc = getaddrinfo(address2, NULL, &hints2, &res2);
+	if (rc) {
+		log_debug(1, "Match error. Could not resolve %s: %s", address2,
+			  gai_strerror(rc));
+		rc = 0;
+		goto free_res1;
+	}
+
+	if ((res1->ai_addrlen != res2->ai_addrlen) ||
+	    memcmp(res1->ai_addr, res2->ai_addr, res2->ai_addrlen))
+		rc = 0;
+	else
+		rc = 1;
+
+	freeaddrinfo(res2);
+free_res1:
+	freeaddrinfo(res1);
+	return rc;
+}
+
 int __iscsi_match_session(node_rec_t *rec, char *targetname,
 			  char *address, int port, struct iface_rec *iface)
 {
@@ -240,8 +298,7 @@ int __iscsi_match_session(node_rec_t *rec, char *targetname,
 	if (strlen(rec->name) && strcmp(rec->name, targetname))
 		return 0;
 
-	if (strlen(rec->conn[0].address) &&
-	    strcmp(rec->conn[0].address, address))
+	if (!iscsi_addr_match(rec->conn[0].address, address))
 		return 0;
 
 	if (rec->conn[0].port != -1 && port != rec->conn[0].port)

-- 
Debian Open-iSCSI Packaging



More information about the Pkg-iscsi-maintainers mailing list