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

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