--- old/usr/src/cmd/stmfadm/stmfadm.c	Fri Dec  2 14:28:51 2011
+++ new/usr/src/cmd/stmfadm/stmfadm.c	Fri Dec  2 14:28:51 2011
@@ -80,7 +80,7 @@
 static void printGuid(stmfGuid *guid, FILE *printWhere);
 static void printTargetProps(stmfTargetProperties *);
 static void printSessionProps(stmfSessionList *);
-static int setLuPropFromInput(luResource, char *);
+static int setLuPropFromInput(luResource, char *, uint32_t *);
 static int convertCharToPropId(char *, uint32_t *);
 
 
@@ -130,6 +130,7 @@
 #define	SERIAL_NUMBER		    "SERIAL"
 #define	MGMT_URL		    "MGMT-URL"
 #define	HOST_ID			    "HOST-ID"
+#define	UNMAP			    "UNMAP"
 
 #define	STMFADM_SUCCESS		    0
 #define	STMFADM_FAILURE		    1
@@ -139,6 +140,7 @@
 "Valid properties for -p, --lu-prop are: \n" \
 "     alias    - alias for logical unit (up to 255 chars)\n" \
 "     mgmt-url - Management URL address\n" \
+"     unmap    - iSCSI UNMAP enabled (true, false)\n" \
 "     wcd      - write cache disabled (true, false)\n" \
 "     wp       - write protect (true, false)\n\n" \
 "-f alters the meaning of the operand to be a file name\n" \
@@ -159,6 +161,7 @@
 "                6 ascii hex characters of valid format\n" \
 "     pid      - product identifier (up to 16 chars)\n" \
 "     serial   - serial number (up to 252 chars)\n" \
+"     unmap    - iSCSI UNMAP enabled (true, false)\n" \
 "     vid      - vendor identifier (up to 8 chars)\n" \
 "     wcd      - write cache disabled (true, false)\n" \
 "     wp       - write protect (true, false)\n"
@@ -814,6 +817,8 @@
 	int stmfRet = 0;
 	char guidAsciiBuf[33];
 	stmfGuid createdGuid;
+	uint32_t propid;
+	boolean_t unmap_not_set = B_TRUE;
 
 	stmfRet = stmfCreateLuResource(STMF_DISK, &hdl);
 
@@ -826,7 +831,10 @@
 	for (; options->optval; options++) {
 		switch (options->optval) {
 			case 'p':
-				ret = setLuPropFromInput(hdl, options->optarg);
+				ret = setLuPropFromInput(hdl, options->optarg,
+				    &propid);
+				if (propid == STMF_LU_PROP_UNMAP)
+					unmap_not_set = B_FALSE;
 				if (ret != 0) {
 					(void) stmfFreeLuResource(hdl);
 					return (1);
@@ -851,6 +859,19 @@
 		}
 	}
 
+	if (unmap_not_set) {
+		/*
+		 * We "enable" unmap by default, but STMF is hostile toward
+		 * enable-by-default, so we enable it here if it hasn't
+		 * already been set.
+		 */
+		if (stmfSetLuProp(hdl, STMF_LU_PROP_UNMAP, "true") !=
+		    STMF_STATUS_SUCCESS) {
+			fprintf(stderr, "%s: %s\n", cmdName,
+			    gettext("Problems setting UNMAP default"));
+		}
+	}
+
 	stmfRet = stmfSetLuProp(hdl, STMF_LU_PROP_FILENAME, operands[0]);
 
 	if (stmfRet != STMF_STATUS_SUCCESS) {
@@ -1233,12 +1254,11 @@
 }
 
 static int
-setLuPropFromInput(luResource hdl, char *optarg)
+setLuPropFromInput(luResource hdl, char *optarg, uint32_t *propId)
 {
 	char *prop = NULL;
 	char *propVal = NULL;
 	char *lasts = NULL;
-	uint32_t propId;
 	int ret = 0;
 
 	prop = strtok_r(optarg, "=", &lasts);
@@ -1249,7 +1269,7 @@
 		return (1);
 	}
 
-	ret = convertCharToPropId(prop, &propId);
+	ret = convertCharToPropId(prop, propId);
 	if (ret != 0) {
 		(void) fprintf(stderr, "%s: %s: %s\n",
 		    cmdName, gettext("invalid property specified"), prop);
@@ -1256,7 +1276,7 @@
 		return (1);
 	}
 
-	ret = stmfSetLuProp(hdl, propId, propVal);
+	ret = stmfSetLuProp(hdl, *propId, propVal);
 	if (ret != STMF_STATUS_SUCCESS) {
 		(void) fprintf(stderr, "%s: %s %s: ",
 		    cmdName, gettext("unable to set"), prop);
@@ -1304,6 +1324,8 @@
 		*propId = STMF_LU_PROP_MGMT_URL;
 	} else if (strcasecmp(prop, HOST_ID) == 0) {
 		*propId = STMF_LU_PROP_HOST_ID;
+	} else if (strcasecmp(prop, UNMAP) == 0) {
+		*propId = STMF_LU_PROP_UNMAP;
 	} else {
 		return (1);
 	}
@@ -2218,6 +2240,21 @@
 		    strcasecmp(propVal, "true") ? "Enabled" : "Disabled");
 	} else if (stmfRet == STMF_ERROR_NO_PROP) {
 		(void) printf("not set\n");
+	} else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
+		(void) printf("prop unavailable in standby\n");
+	} else {
+		(void) printf("<error retrieving property>\n");
+		ret++;
+	}
+
+	stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_UNMAP, propVal,
+	    &propValSize);
+	(void) printf(PROPS_FORMAT, "UNMAP support");
+	if (stmfRet == STMF_STATUS_SUCCESS) {
+		(void) printf("%s\n", (strcasecmp(propVal, "true") == 0) ?
+		    "Enabled" : "Disabled");
+	} else if (stmfRet == STMF_ERROR_NO_PROP) {
+		(void) printf("not set\n");
 	} else if (stmfRet == STMF_ERROR_NO_PROP_STANDBY) {
 		(void) printf("prop unavailable in standby\n");
 	} else {
