tree 8a9e70c2ccecee681626589ac0ee1843dd657d13
parent c759b8b1a01729a044368527ec08d795ec2175fb
author Hannes Reinecke <hare@suse.de> 1174657150 +0100
committer Hannes Reinecke <hare@suse.de> 1174657150 +0100

[libcheckers] Add rdac path checkers

rdac machines are not supported by the existing path
checker properly. This patch adds a separate 'rdac' path
checker which will properly return the path state.

Signed-off-by: chandra.seetharaman@us.ibm.com
Signed-off-by: Hannes Reinecke <hare@suse.de>
05b598fe1a09531d60ae5f96dd066e1f47768e1f
 libcheckers/Makefile   |    2 +-
 libcheckers/checkers.c |   10 ++++
 libcheckers/checkers.h |    1 +
 libcheckers/rdac.c     |  109 ++++++++++++++++++++++++++++++++++++++++++++++++
 libmultipath/hwtable.c |   10 ++--
 5 files changed, 126 insertions(+), 6 deletions(-)

diff --git a/libcheckers/Makefile b/libcheckers/Makefile
index bcdc6de..6340a68 100644
--- a/libcheckers/Makefile
+++ b/libcheckers/Makefile
@@ -6,7 +6,7 @@ BUILD = glibc
 
 include ../Makefile.inc
 
-OBJS = libsg.o checkers.o readsector0.o tur.o directio.o emc_clariion.o hp_sw.o
+OBJS = libsg.o checkers.o readsector0.o tur.o directio.o emc_clariion.o hp_sw.o rdac.o
 
 all: $(BUILD)
 
diff --git a/libcheckers/checkers.c b/libcheckers/checkers.c
index 4f6928f..a49ad59 100644
--- a/libcheckers/checkers.c
+++ b/libcheckers/checkers.c
@@ -7,6 +7,7 @@
 #include "tur.h"
 #include "hp_sw.h"
 #include "emc_clariion.h"
+#include "rdac.h"
 #include "readsector0.h"
 
 static struct checker checkers[] = {
@@ -48,6 +49,15 @@ static struct checker checkers[] = {
 	},
 	{
 		.fd         = 0,
+		.name       = RDAC,
+		.message    = "",
+		.context    = NULL,
+		.check      = rdac,
+		.init       = rdac_init,
+		.free       = rdac_free
+	},
+	{
+		.fd         = 0,
 		.name       = READSECTOR0,
 		.message    = "",
 		.context    = NULL,
diff --git a/libcheckers/checkers.h b/libcheckers/checkers.h
index 5589fc7..d4dad9c 100644
--- a/libcheckers/checkers.h
+++ b/libcheckers/checkers.h
@@ -51,6 +51,7 @@
 #define DIRECTIO     "directio"
 #define TUR          "tur"
 #define HP_SW        "hp_sw"
+#define RDAC         "rdac"
 #define EMC_CLARIION "emc_clariion"
 #define READSECTOR0  "readsector0"
 
diff --git a/libcheckers/rdac.c b/libcheckers/rdac.c
new file mode 100644
index 0000000..76a2498
--- /dev/null
+++ b/libcheckers/rdac.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2005 Christophe Varoqui
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#include "checkers.h"
+
+#include "../libmultipath/sg_include.h"
+
+#define INQUIRY_CMDLEN		6
+#define INQUIRY_CMD		0x12
+#define SENSE_BUFF_LEN		32
+#define DEF_TIMEOUT		60000
+#define SCSI_CHECK_CONDITION	0x2
+#define SCSI_COMMAND_TERMINATED	0x22
+#define SG_ERR_DRIVER_SENSE	0x08
+#define RECOVERED_ERROR		0x01
+
+#define MSG_RDAC_UP	"rdac checker reports path is up"
+#define MSG_RDAC_DOWN	"rdac checker reports path is down"
+#define MSG_RDAC_GHOST	"rdac checker reports path is ghost"
+
+struct rdac_checker_context {
+	void * dummy;
+};
+
+int rdac_init (struct checker * c)
+{
+	return 0;
+}
+
+void rdac_free (struct checker * c)
+{
+	return;
+}
+
+static int
+do_inq(int sg_fd, unsigned int pg_op, void *resp, int mx_resp_len)
+{
+	unsigned char inqCmdBlk[INQUIRY_CMDLEN] = { INQUIRY_CMD, 1, 0, 0, 0, 0 };
+	unsigned char sense_b[SENSE_BUFF_LEN];
+	struct sg_io_hdr io_hdr;
+
+	inqCmdBlk[2] = (unsigned char) pg_op;
+	inqCmdBlk[4] = (unsigned char) (mx_resp_len & 0xff);
+	memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
+
+	io_hdr.interface_id = 'S';
+	io_hdr.cmd_len = sizeof (inqCmdBlk);
+	io_hdr.mx_sb_len = sizeof (sense_b);
+	io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
+	io_hdr.dxfer_len = mx_resp_len;
+	io_hdr.dxferp = resp;
+	io_hdr.cmdp = inqCmdBlk;
+	io_hdr.sbp = sense_b;
+	io_hdr.timeout = DEF_TIMEOUT;
+
+	if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
+		return 1;
+
+	/* treat SG_ERR here to get rid of sg_err.[ch] */
+	io_hdr.status &= 0x7e;
+	if ((0 == io_hdr.status) && (0 == io_hdr.host_status) &&
+			(0 == io_hdr.driver_status))
+		return 0;
+	if ((SCSI_CHECK_CONDITION == io_hdr.status) ||
+		(SCSI_COMMAND_TERMINATED == io_hdr.status) ||
+		(SG_ERR_DRIVER_SENSE == (0xf & io_hdr.driver_status))) {
+		if (io_hdr.sbp && (io_hdr.sb_len_wr > 2)) {
+			int sense_key;
+			unsigned char * sense_buffer = io_hdr.sbp;
+			if (sense_buffer[0] & 0x2)
+				sense_key = sense_buffer[1] & 0xf;
+			else
+				sense_key = sense_buffer[2] & 0xf;
+			if (RECOVERED_ERROR == sense_key)
+				return 0;
+		}
+	}
+	return 1;
+}
+
+struct volume_access_inq
+{
+	char dontcare0[8];
+	char avtcvp;
+	char dontcare1[39];
+};
+
+extern int
+rdac(struct checker * c)
+{
+	struct volume_access_inq inq;
+
+	if (0 != do_inq(c->fd, 0xC9, &inq, sizeof(struct volume_access_inq))) {
+		MSG(c, MSG_RDAC_DOWN);
+		return PATH_DOWN;
+	}
+
+	return ((inq.avtcvp & 0x1) ? PATH_UP : PATH_GHOST);
+}
diff --git a/libmultipath/hwtable.c b/libmultipath/hwtable.c
index 4c8520f..62a3bc1 100644
--- a/libmultipath/hwtable.c
+++ b/libmultipath/hwtable.c
@@ -303,7 +303,7 @@ static struct hwentry default_hw[] = {
 		.rr_weight     = RR_WEIGHT_NONE,
 		.no_path_retry = NO_PATH_RETRY_QUEUE,
 		.minio         = DEFAULT_MINIO,
-		.checker_name  = TUR,
+		.checker_name  = RDAC,
 	},
 	{
 		/* IBM Netfinity Fibre Channel RAID Controller Unit */
@@ -319,7 +319,7 @@ static struct hwentry default_hw[] = {
 		.rr_weight     = RR_WEIGHT_NONE,
 		.no_path_retry = NO_PATH_RETRY_QUEUE,
 		.minio         = DEFAULT_MINIO,
-		.checker_name  = TUR,
+		.checker_name  = RDAC,
 	},
 	{
 		/* IBM DS4200 / FAStT200 */
@@ -515,7 +515,7 @@ static struct hwentry default_hw[] = {
 		.rr_weight     = RR_WEIGHT_NONE,
 		.no_path_retry = NO_PATH_RETRY_QUEUE,
 		.minio         = DEFAULT_MINIO,
-		.checker_name  = TUR,
+		.checker_name  = RDAC,
 	},
 	{
 		.vendor        = "SGI",
@@ -530,7 +530,7 @@ static struct hwentry default_hw[] = {
 		.rr_weight     = RR_WEIGHT_NONE,
 		.no_path_retry = NO_PATH_RETRY_QUEUE,
 		.minio         = DEFAULT_MINIO,
-		.checker_name  = TUR,
+		.checker_name  = RDAC,
 	},
 	/*
 	 * STK arrays
@@ -551,7 +551,7 @@ static struct hwentry default_hw[] = {
 		.rr_weight     = RR_WEIGHT_NONE,
 		.no_path_retry = NO_PATH_RETRY_UNDEF,
 		.minio         = DEFAULT_MINIO,
-		.checker_name  = TUR,
+		.checker_name  = RDAC,
 	},
 	/*
 	 * SUN arrays
