Improve sense code scanning in sg_read() and tur checker
authorHannes Reinecke <hare@suse.de>
Wed, 30 Apr 2008 09:03:45 +0000 (11:03 +0200)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Wed, 30 Apr 2008 11:25:14 +0000 (13:25 +0200)
sg_read and tur should be able to correctly parse sense data,
as we might need to retry any UNIT ATTENTION sense codes.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/checkers/libsg.c
libmultipath/checkers/tur.c

index 9171b10..4cb7ecc 100644 (file)
@@ -72,10 +72,21 @@ retry:
            (0 == io_hdr.driver_status)) {
                return PATH_UP;
        } else {
+               int key = 0;
+
+               if (io_hdr.sb_len_wr > 3) {
+                       if (sbb[0] == 0x72 || sbb[0] == 0x73)
+                               key = sbb[1] & 0x0f;
+                       else if (io_hdr.sb_len_wr > 13 &&
+                                ((sbb[0] & 0x7f) == 0x70 ||
+                                 (sbb[0] & 0x7f) == 0x71))
+                               key = sbb[2] & 0x0f;
+               }
+
                /*
                 * Retry if UNIT_ATTENTION check condition.
                 */
-               if ((sbb[2]&0xf) == 6) {
+               if (key == 0x6) {
                        if (--retry_count)
                                goto retry;
                }
index e84435e..43b846d 100644 (file)
@@ -41,26 +41,48 @@ extern int
 libcheck_check (struct checker * c)
 {
        struct sg_io_hdr io_hdr;
-        unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
-        unsigned char sense_buffer[32];
+       unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
+       unsigned char sense_buffer[32];
+       int retry_tur = 5;
 
-        memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
-        io_hdr.interface_id = 'S';
-        io_hdr.cmd_len = sizeof (turCmdBlk);
-        io_hdr.mx_sb_len = sizeof (sense_buffer);
-        io_hdr.dxfer_direction = SG_DXFER_NONE;
-        io_hdr.cmdp = turCmdBlk;
-        io_hdr.sbp = sense_buffer;
-        io_hdr.timeout = DEF_TIMEOUT;
-        io_hdr.pack_id = 0;
-        if (ioctl(c->fd, SG_IO, &io_hdr) < 0) {
+ retry:
+       memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
+       io_hdr.interface_id = 'S';
+       io_hdr.cmd_len = sizeof (turCmdBlk);
+       io_hdr.mx_sb_len = sizeof (sense_buffer);
+       io_hdr.dxfer_direction = SG_DXFER_NONE;
+       io_hdr.cmdp = turCmdBlk;
+       io_hdr.sbp = sense_buffer;
+       io_hdr.timeout = DEF_TIMEOUT;
+       io_hdr.pack_id = 0;
+       if (ioctl(c->fd, SG_IO, &io_hdr) < 0) {
                MSG(c, MSG_TUR_DOWN);
-                return PATH_DOWN;
-        }
-        if (io_hdr.info & SG_INFO_OK_MASK) {
+               return PATH_DOWN;
+       }
+       if (io_hdr.info & SG_INFO_OK_MASK) {
+               int key = 0, asc, ascq;
+
+               if (io_hdr.sb_len_wr > 3) {
+                       if (io_hdr.sbp[0] == 0x72 || io_hdr.sbp[0] == 0x73) {
+                               key = io_hdr.sbp[1] & 0x0f;
+                               asc = io_hdr.sbp[2];
+                               ascq = io_hdr.sbp[3];
+                       } else if (io_hdr.sb_len_wr > 13 &&
+                                  ((io_hdr.sbp[0] & 0x7f) == 0x70 ||
+                                   (io_hdr.sbp[0] & 0x7f) == 0x71)) {
+                               key = io_hdr.sbp[2] & 0x0f;
+                               asc = io_hdr.sbp[12];
+                               ascq = io_hdr.sbp[13];
+                       }
+               }
+               if (key == 0x6) {
+                       /* Unit Attention, retry */
+                       if (--retry_tur)
+                               goto retry;
+               }
                MSG(c, MSG_TUR_DOWN);
-                return PATH_DOWN;
-        }
+               return PATH_DOWN;
+       }
        MSG(c, MSG_TUR_UP);
-        return PATH_UP;
+       return PATH_UP;
 }