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

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