changeset 10765:7ae75584baf6

6861519 stmfCreateLu() should allow caller to specify host id
author John Forte <John.Forte@Sun.COM>
date Mon, 12 Oct 2009 20:05:55 -0700
parents 255b174a4d2a
children 84a888430fd9
files usr/src/cmd/stmfadm/stmfadm.c usr/src/lib/libstmf/common/libstmf.h usr/src/lib/libstmf/common/libstmf_impl.h usr/src/lib/libstmf/common/stmf.c usr/src/uts/common/io/comstar/lu/stmf_sbd/sbd.c usr/src/uts/common/io/comstar/stmf/stmf.c usr/src/uts/common/sys/stmf.h usr/src/uts/common/sys/stmf_sbd_ioctl.h
diffstat 8 files changed, 62 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/stmfadm/stmfadm.c	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/cmd/stmfadm/stmfadm.c	Mon Oct 12 20:05:55 2009 -0700
@@ -127,6 +127,7 @@
 #define	BLOCK_SIZE		    "BLK"
 #define	SERIAL_NUMBER		    "SERIAL"
 #define	MGMT_URL		    "MGMT-URL"
+#define	HOST_ID			    "HOST-ID"
 
 #define	MODIFY_HELP "\n"\
 "Description: Modify properties of a logical unit. \n" \
@@ -145,6 +146,8 @@
 "     alias    - alias for logical unit (up to 255 chars)\n" \
 "     blk      - block size in bytes in 2^n\n" \
 "     guid     - 32 ascii hex characters in NAA format \n" \
+"     host-id  - host identifier to be used for GUID generation \n" \
+"                8 ascii hex characters\n" \
 "     meta     - separate meta data file name\n" \
 "     mgmt-url - Management URL address\n" \
 "     oui      - organizational unique identifier\n" \
@@ -1287,6 +1290,8 @@
 		*propId = STMF_LU_PROP_META_FILENAME;
 	} else if (strcasecmp(prop, MGMT_URL) == 0) {
 		*propId = STMF_LU_PROP_MGMT_URL;
+	} else if (strcasecmp(prop, HOST_ID) == 0) {
+		*propId = STMF_LU_PROP_HOST_ID;
 	} else {
 		return (1);
 	}
--- a/usr/src/lib/libstmf/common/libstmf.h	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/lib/libstmf/common/libstmf.h	Mon Oct 12 20:05:55 2009 -0700
@@ -147,7 +147,8 @@
 	STMF_LU_PROP_VID,
 	STMF_LU_PROP_PID,
 	STMF_LU_PROP_SERIAL_NUM,
-	STMF_LU_PROP_ACCESS_STATE
+	STMF_LU_PROP_ACCESS_STATE,
+	STMF_LU_PROP_HOST_ID
 };
 
 
--- a/usr/src/lib/libstmf/common/libstmf_impl.h	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/lib/libstmf/common/libstmf_impl.h	Mon Oct 12 20:05:55 2009 -0700
@@ -68,6 +68,8 @@
 	boolean_t   writebackCacheDisableValid;
 	boolean_t   writebackCacheDisable;
 	uint16_t    accessState;
+	uint32_t    hostId;
+	boolean_t   hostIdValid;
 } diskResource;
 
 
--- a/usr/src/lib/libstmf/common/stmf.c	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/lib/libstmf/common/stmf.c	Mon Oct 12 20:05:55 2009 -0700
@@ -59,7 +59,9 @@
 #define	LU_ASCII_GUID_SIZE 32
 #define	LU_GUID_SIZE 16
 #define	OUI_ASCII_SIZE 6
+#define	HOST_ID_ASCII_SIZE 8
 #define	OUI_SIZE 3
+#define	HOST_ID_SIZE 4
 #define	IDENT_LENGTH_BYTE 3
 
 /* various initial allocation values */
@@ -1241,6 +1243,11 @@
 		sbdLu->slu_company_id = disk->companyId;
 	}
 
+	if (disk->hostIdValid) {
+		sbdLu->slu_host_id_valid = 1;
+		sbdLu->slu_host_id = disk->hostId;
+	}
+
 	if (disk->blkSizeValid) {
 		sbdLu->slu_blksize_valid = 1;
 		sbdLu->slu_blksize = disk->blkSize;
@@ -2589,7 +2596,9 @@
 	unsigned long long numericProp = 0;
 	char guidProp[LU_ASCII_GUID_SIZE + 1];
 	char ouiProp[OUI_ASCII_SIZE + 1];
+	char hostIdProp[HOST_ID_ASCII_SIZE + 1];
 	unsigned int oui[OUI_SIZE];
+	unsigned int hostId[HOST_ID_SIZE];
 	unsigned int guid[LU_GUID_SIZE];
 	int propSize;
 
@@ -2630,8 +2639,32 @@
 			diskLu->companyId += oui[0] << 16;
 			diskLu->companyId += oui[1] << 8;
 			diskLu->companyId += oui[2];
+			if (diskLu->companyId == 0) {
+				return (STMF_ERROR_INVALID_ARG);
+			}
 			diskLu->companyIdValid = B_TRUE;
 			break;
+		case STMF_LU_PROP_HOST_ID:
+			if ((strlcpy(hostIdProp, propVal,
+			    sizeof (hostIdProp))) >= sizeof (hostIdProp)) {
+				return (STMF_ERROR_INVALID_ARG);
+			}
+			if (checkHexUpper(hostIdProp) != 0) {
+				return (STMF_ERROR_INVALID_ARG);
+			}
+			(void) sscanf(hostIdProp, "%2X%2X%2X%2X",
+			    &hostId[0], &hostId[1], &hostId[2], &hostId[3]);
+
+			diskLu->hostId = 0;
+			diskLu->hostId += hostId[0] << 24;
+			diskLu->hostId += hostId[1] << 16;
+			diskLu->hostId += hostId[2] << 8;
+			diskLu->hostId += hostId[3];
+			if (diskLu->hostId == 0) {
+				return (STMF_ERROR_INVALID_ARG);
+			}
+			diskLu->hostIdValid = B_TRUE;
+			break;
 		case STMF_LU_PROP_GUID:
 			if (strlen(propVal) != LU_ASCII_GUID_SIZE) {
 				return (STMF_ERROR_INVALID_PROPSIZE);
--- a/usr/src/uts/common/io/comstar/lu/stmf_sbd/sbd.c	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/uts/common/io/comstar/lu/stmf_sbd/sbd.c	Mon Oct 12 20:05:55 2009 -0700
@@ -1635,6 +1635,7 @@
 	int ret = EIO;
 	int flag;
 	int wcd = 0;
+	uint32_t hid = 0;
 	enum vtype vt;
 
 	sz = struct_sz - sizeof (sbd_create_and_reg_lu_t) + 8 + 1;
@@ -1864,9 +1865,11 @@
 		sl->sl_device_id[2] = 0;
 		bcopy(slu->slu_guid, sl->sl_device_id + 4, 16);
 	} else {
+		if (slu->slu_host_id_valid)
+			hid = slu->slu_host_id;
 		if (!slu->slu_company_id_valid)
 			slu->slu_company_id = COMPANY_ID_SUN;
-		if (stmf_scsilib_uniq_lu_id(slu->slu_company_id,
+		if (stmf_scsilib_uniq_lu_id2(slu->slu_company_id, hid,
 		    (scsi_devid_desc_t *)&sl->sl_device_id[0]) !=
 		    STMF_SUCCESS) {
 			*err_ret = SBD_RET_META_CREATION_FAILED;
--- a/usr/src/uts/common/io/comstar/stmf/stmf.c	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/uts/common/io/comstar/stmf/stmf.c	Mon Oct 12 20:05:55 2009 -0700
@@ -5223,11 +5223,19 @@
 stmf_status_t
 stmf_scsilib_uniq_lu_id(uint32_t company_id, scsi_devid_desc_t *lu_id)
 {
+	return (stmf_scsilib_uniq_lu_id2(company_id, 0, lu_id));
+}
+
+stmf_status_t
+stmf_scsilib_uniq_lu_id2(uint32_t company_id, uint32_t host_id,
+    scsi_devid_desc_t *lu_id)
+{
 	uint8_t *p;
 	struct timeval32 timestamp32;
 	uint32_t *t = (uint32_t *)&timestamp32;
 	struct ether_addr mac;
 	uint8_t *e = (uint8_t *)&mac;
+	int hid = (int)host_id;
 
 	if (company_id == COMPANY_ID_NONE)
 		company_id = COMPANY_ID_SUN;
@@ -5244,8 +5252,10 @@
 	p[5] = (company_id >> 12) & 0xff;
 	p[6] = (company_id >> 4) & 0xff;
 	p[7] = (company_id << 4) & 0xf0;
-	if (!localetheraddr((struct ether_addr *)NULL, &mac)) {
-		int hid = BE_32((int)zone_get_hostid(NULL));
+	if (hid == 0 && !localetheraddr((struct ether_addr *)NULL, &mac)) {
+		hid = BE_32((int)zone_get_hostid(NULL));
+	}
+	if (hid != 0) {
 		e[0] = (hid >> 24) & 0xff;
 		e[1] = (hid >> 16) & 0xff;
 		e[2] = (hid >> 8) & 0xff;
--- a/usr/src/uts/common/sys/stmf.h	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/uts/common/sys/stmf.h	Mon Oct 12 20:05:55 2009 -0700
@@ -371,6 +371,8 @@
     uint8_t protocol_id);
 stmf_status_t stmf_scsilib_uniq_lu_id(uint32_t company_id,
     struct scsi_devid_desc *lu_id);
+stmf_status_t stmf_scsilib_uniq_lu_id2(uint32_t company_id, uint32_t host_id,
+    struct scsi_devid_desc *lu_id);
 void stmf_scsilib_send_status(scsi_task_t *task, uint8_t st, uint32_t saa);
 uint32_t stmf_scsilib_prepare_vpd_page83(scsi_task_t *task, uint8_t *page,
 		uint32_t page_len, uint8_t byte0, uint32_t vpd_mask);
--- a/usr/src/uts/common/sys/stmf_sbd_ioctl.h	Mon Oct 12 15:52:05 2009 -0400
+++ b/usr/src/uts/common/sys/stmf_sbd_ioctl.h	Mon Oct 12 20:05:55 2009 -0700
@@ -88,6 +88,7 @@
 			slu_mgmt_url_valid:1,
 			slu_guid_valid:1,
 			slu_company_id_valid:1,
+			slu_host_id_valid:1,
 			slu_writeback_cache_disable_valid:1,
 			slu_writeback_cache_disable:1,
 			slu_write_protected:1;
@@ -101,7 +102,7 @@
 	uint32_t	slu_company_id;
 	uint16_t	slu_alias_off;
 	uint16_t	slu_mgmt_url_off;
-	uint32_t	slu_rsvd1;
+	uint32_t	slu_host_id;
 	char		slu_rev[4];
 	char		slu_vid[8];
 	char		slu_pid[16];