Blame SOURCES/0007-RH-add-hp_tur-checker.patch

671555
---
671555
 libmultipath/checkers.h        |    3 +
671555
 libmultipath/checkers/Makefile |    4 +
671555
 libmultipath/checkers/tur.c    |  123 +++++++++++++++++++++++++++++++++++++++--
671555
 multipath.conf.annotated       |    5 +
671555
 4 files changed, 128 insertions(+), 7 deletions(-)
671555
671555
Index: multipath-tools-120613/libmultipath/checkers.h
671555
===================================================================
671555
--- multipath-tools-120613.orig/libmultipath/checkers.h
671555
+++ multipath-tools-120613/libmultipath/checkers.h
671555
@@ -60,6 +60,7 @@ enum path_check_state {
671555
 
671555
 #define DIRECTIO     "directio"
671555
 #define TUR          "tur"
671555
+#define HP_TUR       "hp_tur"
671555
 #define HP_SW        "hp_sw"
671555
 #define RDAC         "rdac"
671555
 #define EMC_CLARIION "emc_clariion"
671555
@@ -77,6 +78,7 @@ enum path_check_state {
671555
 #define CHECKER_MSG_LEN 256
671555
 #define CHECKER_DEV_LEN 256
671555
 #define LIB_CHECKER_NAMELEN 256
671555
+#define WWID_SIZE 128
671555
 
671555
 struct checker {
671555
 	struct list_head node;
671555
@@ -88,6 +90,7 @@ struct checker {
671555
 	int disable;
671555
 	char name[CHECKER_NAME_LEN];
671555
 	char message[CHECKER_MSG_LEN];       /* comm with callers */
671555
+	char wwid[WWID_SIZE];                /* LUN wwid */
671555
 	void * context;                      /* store for persistent data */
671555
 	void ** mpcontext;                   /* store for persistent data shared
671555
 						multipath-wide. Use MALLOC if
671555
Index: multipath-tools-120613/libmultipath/checkers/Makefile
671555
===================================================================
671555
--- multipath-tools-120613.orig/libmultipath/checkers/Makefile
671555
+++ multipath-tools-120613/libmultipath/checkers/Makefile
671555
@@ -8,6 +8,7 @@ LIBS= \
671555
 	libcheckcciss_tur.so \
671555
 	libcheckreadsector0.so \
671555
 	libchecktur.so \
671555
+	libcheckhp_tur.so \
671555
 	libcheckdirectio.so \
671555
 	libcheckemc_clariion.so \
671555
 	libcheckhp_sw.so \
671555
@@ -23,6 +24,9 @@ libcheckdirectio.so: libsg.o directio.o
671555
 libcheck%.so: libsg.o %.o
671555
 	$(CC) $(LDFLAGS) $(SHARED_FLAGS) -o $@ $^
671555
 
671555
+hp_tur.o: tur.c
671555
+	$(CC) $(CFLAGS) -DCHECK_WWID -c -o $@ $<
671555
+
671555
 install:
671555
 	$(INSTALL_PROGRAM) -m 755 $(LIBS) $(DESTDIR)$(libdir)
671555
 
671555
Index: multipath-tools-120613/libmultipath/checkers/tur.c
671555
===================================================================
671555
--- multipath-tools-120613.orig/libmultipath/checkers/tur.c
671555
+++ multipath-tools-120613/libmultipath/checkers/tur.c
671555
@@ -24,12 +24,101 @@
671555
 #define TUR_CMD_LEN 6
671555
 #define HEAVY_CHECK_COUNT       10
671555
 
671555
+#ifdef CHECK_WWID
671555
+#define MSG_TUR_UP	"HP tur checker reports path is up"
671555
+#define MSG_TUR_DOWN	"HP tur checker reports path is down"
671555
+#define MSG_TUR_GHOST	"HP tur checker reports path is in standby state"
671555
+#define MSG_TUR_RUNNING "HP tur checker still running"
671555
+#define MSG_TUR_TIMEOUT "HP tur checker timed out"
671555
+#define MSG_TUR_FAILED  "HP tur checker failed to initialize"
671555
+#define EVPD            0x01
671555
+#define PAGE_83         0x83
671555
+#define INQUIRY_CMD     0x12
671555
+#define INQUIRY_CMDLEN  6
671555
+#define SCSI_INQ_BUFF_LEN 96
671555
+#else
671555
 #define MSG_TUR_UP	"tur checker reports path is up"
671555
 #define MSG_TUR_DOWN	"tur checker reports path is down"
671555
 #define MSG_TUR_GHOST	"tur checker reports path is in standby state"
671555
 #define MSG_TUR_RUNNING	"tur checker still running"
671555
 #define MSG_TUR_TIMEOUT	"tur checker timed out"
671555
 #define MSG_TUR_FAILED	"tur checker failed to initialize"
671555
+#endif
671555
+
671555
+#ifdef CHECK_WWID
671555
+static int
671555
+do_inq(int fd, unsigned int timeout, char * wwid)
671555
+{
671555
+	int ret = -1;
671555
+	unsigned char inq_cmd[INQUIRY_CMDLEN] =
671555
+	{INQUIRY_CMD, EVPD, PAGE_83, 0, SCSI_INQ_BUFF_LEN, 0 };
671555
+	unsigned char sense_buffer[32];
671555
+	unsigned char resp_buffer[SCSI_INQ_BUFF_LEN];
671555
+	char *pbuff;
671555
+
671555
+	int m,k;
671555
+	int retry_tur = 5;
671555
+	struct sg_io_hdr io_hdr;
671555
+
671555
+retry:
671555
+	memset(resp_buffer, 0, sizeof(resp_buffer));
671555
+	memset(&io_hdr, 0, sizeof(struct sg_io_hdr));
671555
+
671555
+	io_hdr.interface_id = 'S';
671555
+	io_hdr.cmd_len = sizeof(inq_cmd);
671555
+	io_hdr.mx_sb_len = sizeof(sense_buffer);
671555
+	io_hdr.dxfer_direction = -3; // Data transfer from the device.
671555
+	io_hdr.dxfer_len = sizeof(resp_buffer);
671555
+	io_hdr.dxferp = (unsigned char *)resp_buffer;
671555
+	io_hdr.cmdp = inq_cmd;
671555
+	io_hdr.sbp = sense_buffer;
671555
+	io_hdr.timeout = timeout; // IOCTL timeout value.
671555
+
671555
+	if (ioctl(fd, SG_IO, &io_hdr) < 0) {
671555
+		condlog(0, "SG_IO ioctl failed: %s", strerror(errno));
671555
+		return ret;
671555
+	}
671555
+	if (io_hdr.info & SG_INFO_OK_MASK){
671555
+		int key = 0, asc, ascq;
671555
+
671555
+		if (io_hdr.host_status == DID_BUS_BUSY ||
671555
+				io_hdr.host_status == DID_ERROR ||
671555
+				io_hdr.host_status == DID_TRANSPORT_DISRUPTED) {
671555
+			if (--retry_tur)
671555
+				goto retry;
671555
+		}
671555
+		if (io_hdr.sb_len_wr > 3) {
671555
+			if (io_hdr.sbp[0] == 0x72 || io_hdr.sbp[0] == 0x73) {
671555
+				key = io_hdr.sbp[1] & 0x0f;
671555
+				asc = io_hdr.sbp[2];
671555
+				ascq = io_hdr.sbp[3];
671555
+			} else if (io_hdr.sb_len_wr > 13 &&
671555
+					((io_hdr.sbp[0] & 0x7f) == 0x70 ||
671555
+					 (io_hdr.sbp[0] & 0x7f) == 0x71)) {
671555
+				key = io_hdr.sbp[2] & 0x0f;
671555
+				asc = io_hdr.sbp[12];
671555
+				ascq = io_hdr.sbp[13];
671555
+			}
671555
+		}
671555
+		if (key == 0x6) {
671555
+			/* Unit Attention, retry */
671555
+			if (--retry_tur)
671555
+				goto retry;
671555
+		}
671555
+		return ret;
671555
+	}
671555
+
671555
+	pbuff = (char *) resp_buffer;
671555
+
671555
+	wwid[0] = '3';
671555
+	for (m = 8, k = 1; m < 11; ++m, k+=2)
671555
+		sprintf(&wwid[k], "%02x", (unsigned int)pbuff[m] & 0xff);
671555
+	for (m = 11; m < 24; ++m, k+=2)
671555
+		sprintf(&wwid[k], "%02x", (unsigned int)pbuff[m] & 0xff);
671555
+
671555
+	return (ret = 0);
671555
+}
671555
+#endif
671555
 
671555
 struct tur_checker_context {
671555
 	dev_t devt;
671555
@@ -43,6 +132,7 @@ struct tur_checker_context {
671555
 	pthread_cond_t active;
671555
 	pthread_spinlock_t hldr_lock;
671555
 	int holders;
671555
+	char wwid[WWID_SIZE];
671555
 	char message[CHECKER_MSG_LEN];
671555
 };
671555
 
671555
@@ -100,12 +190,15 @@ void libcheck_free (struct checker * c)
671555
 #define TUR_MSG(msg, fmt, args...) snprintf(msg, CHECKER_MSG_LEN, fmt, ##args);
671555
 
671555
 int
671555
-tur_check(int fd, unsigned int timeout, char *msg)
671555
+tur_check (int fd, unsigned int timeout, char *msg, char *wwid)
671555
 {
671555
 	struct sg_io_hdr io_hdr;
671555
 	unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
671555
 	unsigned char sense_buffer[32];
671555
 	int retry_tur = 5;
671555
+#ifdef CHECK_WWID
671555
+	char new_wwid[WWID_SIZE];
671555
+#endif
671555
 
671555
  retry:
671555
 	memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
671555
@@ -179,6 +272,24 @@ tur_check(int fd, unsigned int timeout,
671555
 		TUR_MSG(msg, MSG_TUR_DOWN);
671555
 		return PATH_DOWN;
671555
 	}
671555
+#ifdef CHECK_WWID
671555
+	if (!do_inq(fd, timeout, new_wwid)) {
671555
+
671555
+		if(!strcmp(wwid, "\0")) {
671555
+			strcpy(wwid, new_wwid);
671555
+			goto up;
671555
+		}
671555
+
671555
+		if (strcmp(wwid , new_wwid)) {
671555
+			condlog(0,
671555
+				"hp_tur: Lun collided. new_wwid %s old_wwid %s",
671555
+				new_wwid, wwid);
671555
+			TUR_MSG(msg, MSG_TUR_DOWN);
671555
+			return PATH_DOWN;
671555
+		}
671555
+	}
671555
+up:
671555
+#endif
671555
 	TUR_MSG(msg, MSG_TUR_UP);
671555
 	return PATH_UP;
671555
 }
671555
@@ -215,7 +326,7 @@ void *tur_thread(void *ctx)
671555
 	ct->state = PATH_PENDING;
671555
 	pthread_mutex_unlock(&ct->lock);
671555
 
671555
-	state = tur_check(ct->fd, ct->timeout, ct->message);
671555
+	state = tur_check(ct->fd, ct->timeout, ct->message, ct->wwid);
671555
 
671555
 	/* TUR checker done */
671555
 	pthread_mutex_lock(&ct->lock);
671555
@@ -275,7 +386,7 @@ libcheck_check (struct checker * c)
671555
 		ct->devt = sb.st_rdev;
671555
 
671555
 	if (c->sync)
671555
-		return tur_check(c->fd, c->timeout, c->message);
671555
+		return tur_check(c->fd, c->timeout, c->message, ct->wwid);
671555
 
671555
 	/*
671555
 	 * Async mode
671555
@@ -319,7 +430,8 @@ libcheck_check (struct checker * c)
671555
 			pthread_mutex_unlock(&ct->lock);
671555
 			condlog(3, "%d:%d: tur thread not responding, "
671555
 				"using sync mode", TUR_DEVT(ct));
671555
-			return tur_check(c->fd, c->timeout, c->message);
671555
+			return tur_check(c->fd, c->timeout, c->message,
671555
+					 ct->wwid);
671555
 		}
671555
 		/* Start new TUR checker */
671555
 		ct->state = PATH_UNCHECKED;
671555
@@ -337,7 +449,8 @@ libcheck_check (struct checker * c)
671555
 			ct->holders--;
671555
 			condlog(3, "%d:%d: failed to start tur thread, using"
671555
 				" sync mode", TUR_DEVT(ct));
671555
-			return tur_check(c->fd, c->timeout, c->message);
671555
+			return tur_check(c->fd, c->timeout, c->message,
671555
+					 ct->wwid);
671555
 		}
671555
 		pthread_attr_destroy(&attr);
671555
 		tur_timeout(&tsp;;
671555
Index: multipath-tools-120613/multipath.conf.annotated
671555
===================================================================
671555
--- multipath-tools-120613.orig/multipath.conf.annotated
671555
+++ multipath-tools-120613/multipath.conf.annotated
671555
@@ -96,7 +96,8 @@
671555
 #	# name    : path_checker, checker
671555
 #	# scope   : multipath & multipathd
671555
 #	# desc    : the default method used to determine the paths' state
671555
-#	# values  : readsector0|tur|emc_clariion|hp_sw|directio|rdac|cciss_tur
671555
+#	# values  : readsector0|tur|emc_clariion|hp_sw|directio|rdac|
671555
+#	            cciss_tur|hp_tur
671555
 #	# default : directio
671555
 #	#
671555
 #	path_checker	directio
671555
@@ -493,7 +494,7 @@
671555
 #		# scope   : multipathd & multipathd
671555
 #		# desc    : path checking algorithm to use to check path state
671555
 #		# values  : readsector0|tur|emc_clariion|hp_sw|directio|rdac|
671555
-#		#           cciss_tur
671555
+#		#           cciss_tur|hp_tur
671555
 #		#
671555
 #		path_checker		directio
671555
 #