Logoj0ke.net Open Build Service > Projects > GFS > multipath-tools > multipath-tools-retry-sg_read
Sign Up | Log In

File multipath-tools-retry-sg_read of Package multipath-tools

 
1
commit f0aa11f03cf7dfd9973a0f5df833283916639f0b
2
Author: Hannes Reinecke <hare@suse.de>
3
Date:   Mon Mar 17 14:29:36 2008 +0100
4
5
    Improve sense code scanning in sg_read() and tur
6
    
7
    sg_read and tur should be able to scan all sense data,
8
    as we might need to retry a UNIT ATTENTION.
9
    
10
    References: 343019,329922
11
    Signed-off-by: Hannes Reinecke <hare@suse.de>
12
13
diff --git a/libcheckers/libsg.c b/libcheckers/libsg.c
14
index 9171b10..4cb7ecc 100644
15
--- a/libcheckers/libsg.c
16
+++ b/libcheckers/libsg.c
17
@@ -72,10 +72,21 @@ retry:
18
        (0 == io_hdr.driver_status)) {
19
        return PATH_UP;
20
    } else {
21
+       int key = 0;
22
+
23
+       if (io_hdr.sb_len_wr > 3) {
24
+           if (sbb[0] == 0x72 || sbb[0] == 0x73)
25
+               key = sbb[1] & 0x0f;
26
+           else if (io_hdr.sb_len_wr > 13 &&
27
+                ((sbb[0] & 0x7f) == 0x70 ||
28
+                 (sbb[0] & 0x7f) == 0x71))
29
+               key = sbb[2] & 0x0f;
30
+       }
31
+
32
        /*
33
         * Retry if UNIT_ATTENTION check condition.
34
         */
35
-       if ((sbb[2]&0xf) == 6) {
36
+       if (key == 0x6) {
37
            if (--retry_count)
38
                goto retry;
39
        }
40
diff --git a/libcheckers/tur.c b/libcheckers/tur.c
41
index e79bc0a..6022590 100644
42
--- a/libcheckers/tur.c
43
+++ b/libcheckers/tur.c
44
@@ -41,26 +41,48 @@ extern int
45
 tur (struct checker * c)
46
 {
47
    struct sg_io_hdr io_hdr;
48
-        unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
49
-        unsigned char sense_buffer[32];
50
+   unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
51
+   unsigned char sense_buffer[32];
52
+   int retry_tur = 5;
53
 
54
-        memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
55
-        io_hdr.interface_id = 'S';
56
-        io_hdr.cmd_len = sizeof (turCmdBlk);
57
-        io_hdr.mx_sb_len = sizeof (sense_buffer);
58
-        io_hdr.dxfer_direction = SG_DXFER_NONE;
59
-        io_hdr.cmdp = turCmdBlk;
60
-        io_hdr.sbp = sense_buffer;
61
-        io_hdr.timeout = DEF_TIMEOUT;
62
-        io_hdr.pack_id = 0;
63
-        if (ioctl(c->fd, SG_IO, &io_hdr) < 0) {
64
+ retry:
65
+   memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
66
+   io_hdr.interface_id = 'S';
67
+   io_hdr.cmd_len = sizeof (turCmdBlk);
68
+   io_hdr.mx_sb_len = sizeof (sense_buffer);
69
+   io_hdr.dxfer_direction = SG_DXFER_NONE;
70
+   io_hdr.cmdp = turCmdBlk;
71
+   io_hdr.sbp = sense_buffer;
72
+   io_hdr.timeout = DEF_TIMEOUT;
73
+   io_hdr.pack_id = 0;
74
+   if (ioctl(c->fd, SG_IO, &io_hdr) < 0) {
75
        MSG(c, MSG_TUR_DOWN);
76
-                return PATH_DOWN;
77
-        }
78
-        if (io_hdr.info & SG_INFO_OK_MASK) {
79
+       return PATH_DOWN;
80
+   }
81
+   if (io_hdr.info & SG_INFO_OK_MASK) {
82
+       int key = 0, asc, ascq;
83
+
84
+       if (io_hdr.sb_len_wr > 3) {
85
+           if (io_hdr.sbp[0] == 0x72 || io_hdr.sbp[0] == 0x73) {
86
+               key = io_hdr.sbp[1] & 0x0f;
87
+               asc = io_hdr.sbp[2];
88
+               ascq = io_hdr.sbp[3];
89
+           } else if (io_hdr.sb_len_wr > 13 &&
90
+                  ((io_hdr.sbp[0] & 0x7f) == 0x70 ||
91
+                   (io_hdr.sbp[0] & 0x7f) == 0x71)) {
92
+               key = io_hdr.sbp[2] & 0x0f;
93
+               asc = io_hdr.sbp[12];
94
+               ascq = io_hdr.sbp[13];
95
+           }
96
+       }
97
+       if (key == 0x6) {
98
+           /* Unit Attention, retry */
99
+           if (--retry_tur)
100
+               goto retry;
101
+       }
102
        MSG(c, MSG_TUR_DOWN);
103
-                return PATH_DOWN;
104
-        }
105
+       return PATH_DOWN;
106
+   }
107
    MSG(c, MSG_TUR_UP);
108
-        return PATH_UP;
109
+   return PATH_UP;
110
 }
111