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

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