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

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