svn commit: r272040 - head/sys/cam/ctl

Alexander Motin mav at FreeBSD.org
Tue Sep 23 20:35:50 UTC 2014


Author: mav
Date: Tue Sep 23 20:35:48 2014
New Revision: 272040
URL: http://svnweb.freebsd.org/changeset/base/272040

Log:
  When reporting some major UNIT ATTENTION condition, like POWER ON OCCURRED
  or I_T NEXUS LOSS, clear all minor UAs for the LUN, redundant in this case.
  
  All SAM specifications tell that target MAY do it, but libiscsi initiator
  seems require it to be done, terminating connection with error if some more
  UAs happen to be reported during iSCSI connection.
  
  MFC after:	3 days

Modified:
  head/sys/cam/ctl/ctl.c
  head/sys/cam/ctl/ctl.h
  head/sys/cam/ctl/ctl_error.c
  head/sys/cam/ctl/ctl_error.h

Modified: head/sys/cam/ctl/ctl.c
==============================================================================
--- head/sys/cam/ctl/ctl.c	Tue Sep 23 19:32:42 2014	(r272039)
+++ head/sys/cam/ctl/ctl.c	Tue Sep 23 20:35:48 2014	(r272040)
@@ -9689,13 +9689,10 @@ ctl_request_sense(struct ctl_scsiio *cts
 	if (lun->pending_ua[initidx] != CTL_UA_NONE) {
 		ctl_ua_type ua_type;
 
-		ua_type = ctl_build_ua(lun->pending_ua[initidx],
+		ua_type = ctl_build_ua(&lun->pending_ua[initidx],
 				       sense_ptr, sense_format);
-		if (ua_type != CTL_UA_NONE) {
+		if (ua_type != CTL_UA_NONE)
 			have_error = 1;
-			/* We're reporting this UA, so clear it */
-			lun->pending_ua[initidx] &= ~ua_type;
-		}
 	}
 	mtx_unlock(&lun->lun_lock);
 
@@ -11743,8 +11740,7 @@ ctl_scsiio_precheck(struct ctl_softc *ct
 	if ((entry->flags & CTL_CMD_FLAG_NO_SENSE) == 0) {
 		ctl_ua_type ua_type;
 
-		ua_type = lun->pending_ua[initidx];
-		if (ua_type != CTL_UA_NONE) {
+		if (lun->pending_ua[initidx] != CTL_UA_NONE) {
 			scsi_sense_data_type sense_format;
 
 			if (lun != NULL)
@@ -11754,14 +11750,13 @@ ctl_scsiio_precheck(struct ctl_softc *ct
 			else
 				sense_format = SSD_TYPE_FIXED;
 
-			ua_type = ctl_build_ua(ua_type, &ctsio->sense_data,
-					       sense_format);
+			ua_type = ctl_build_ua(&lun->pending_ua[initidx],
+			    &ctsio->sense_data, sense_format);
 			if (ua_type != CTL_UA_NONE) {
 				ctsio->scsi_status = SCSI_STATUS_CHECK_COND;
 				ctsio->io_hdr.status = CTL_SCSI_ERROR |
 						       CTL_AUTOSENSE;
 				ctsio->sense_len = SSD_FULL_SIZE;
-				lun->pending_ua[initidx] &= ~ua_type;
 				mtx_unlock(&lun->lun_lock);
 				ctl_done((union ctl_io *)ctsio);
 				return (retval);

Modified: head/sys/cam/ctl/ctl.h
==============================================================================
--- head/sys/cam/ctl/ctl.h	Tue Sep 23 19:32:42 2014	(r272039)
+++ head/sys/cam/ctl/ctl.h	Tue Sep 23 20:35:48 2014	(r272040)
@@ -119,7 +119,7 @@ typedef enum {
 	CTL_UA_I_T_NEXUS_LOSS	= 0x0008,
 	CTL_UA_LUN_RESET	= 0x0010,
 	CTL_UA_LUN_CHANGE	= 0x0020,
-	CTL_UA_MODE_CHANGE	= 0x0030,
+	CTL_UA_MODE_CHANGE	= 0x0040,
 	CTL_UA_LOG_CHANGE	= 0x0080,
 	CTL_UA_LVD		= 0x0100,
 	CTL_UA_SE		= 0x0200,

Modified: head/sys/cam/ctl/ctl_error.c
==============================================================================
--- head/sys/cam/ctl/ctl_error.c	Tue Sep 23 19:32:42 2014	(r272039)
+++ head/sys/cam/ctl/ctl_error.c	Tue Sep 23 20:35:48 2014	(r272040)
@@ -367,44 +367,42 @@ ctl_set_ua(struct ctl_scsiio *ctsio, int
 }
 
 ctl_ua_type
-ctl_build_ua(ctl_ua_type ua_type, struct scsi_sense_data *sense,
+ctl_build_ua(ctl_ua_type *ua_type, struct scsi_sense_data *sense,
 	     scsi_sense_data_type sense_format)
 {
-	ctl_ua_type ua_to_build;
-	int i, asc, ascq;
+	ctl_ua_type ua_to_build, ua_to_clear;
+	int asc, ascq;
 
-	if (ua_type == CTL_UA_NONE)
-		return (ua_type);
+	if (*ua_type == CTL_UA_NONE)
+		return (CTL_UA_NONE);
 
-	ua_to_build = CTL_UA_NONE;
-
-	for (i = 0; i < (sizeof(ua_type) * 8); i++) {
-		if (ua_type & (1 << i)) {
-			ua_to_build = 1 << i;
-			break;
-		}
-	}
+	ua_to_build = (1 << (ffs(*ua_type) - 1));
+	ua_to_clear = ua_to_build;
 
 	switch (ua_to_build) {
 	case CTL_UA_POWERON:
 		/* 29h/01h  POWER ON OCCURRED */
 		asc = 0x29;
 		ascq = 0x01;
+		ua_to_clear = ~0;
 		break;
 	case CTL_UA_BUS_RESET:
 		/* 29h/02h  SCSI BUS RESET OCCURRED */
 		asc = 0x29;
 		ascq = 0x02;
+		ua_to_clear = ~0;
 		break;
 	case CTL_UA_TARG_RESET:
 		/* 29h/03h  BUS DEVICE RESET FUNCTION OCCURRED*/
 		asc = 0x29;
 		ascq = 0x03;
+		ua_to_clear = ~0;
 		break;
 	case CTL_UA_I_T_NEXUS_LOSS:
 		/* 29h/07h  I_T NEXUS LOSS OCCURRED */
 		asc = 0x29;
 		ascq = 0x07;
+		ua_to_clear = ~0;
 		break;
 	case CTL_UA_LUN_RESET:
 		/* 29h/00h  POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */
@@ -466,9 +464,7 @@ ctl_build_ua(ctl_ua_type ua_type, struct
 		ascq = 0x09;
 		break;
 	default:
-		ua_to_build = CTL_UA_NONE;
-		return (ua_to_build);
-		break; /* NOTREACHED */
+		panic("ctl_build_ua: Unknown UA %x", ua_to_build);
 	}
 
 	ctl_set_sense_data(sense,
@@ -480,6 +476,9 @@ ctl_build_ua(ctl_ua_type ua_type, struct
 			   ascq,
 			   SSD_ELEM_NONE);
 
+	/* We're reporting this UA, so clear it */
+	*ua_type &= ~ua_to_clear;
+
 	return (ua_to_build);
 }
 

Modified: head/sys/cam/ctl/ctl_error.h
==============================================================================
--- head/sys/cam/ctl/ctl_error.h	Tue Sep 23 19:32:42 2014	(r272039)
+++ head/sys/cam/ctl/ctl_error.h	Tue Sep 23 20:35:48 2014	(r272040)
@@ -55,7 +55,7 @@ void ctl_sense_to_desc(struct scsi_sense
 void ctl_sense_to_fixed(struct scsi_sense_data_desc *sense_src,
 			struct scsi_sense_data_fixed *sense_dest);
 void ctl_set_ua(struct ctl_scsiio *ctsio, int asc, int ascq);
-ctl_ua_type ctl_build_ua(ctl_ua_type ua_type, struct scsi_sense_data *sense,
+ctl_ua_type ctl_build_ua(ctl_ua_type *ua_type, struct scsi_sense_data *sense,
 			 scsi_sense_data_type sense_format);
 void ctl_set_overlapped_cmd(struct ctl_scsiio *ctsio);
 void ctl_set_overlapped_tag(struct ctl_scsiio *ctsio, uint8_t tag);


More information about the svn-src-head mailing list