1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/blkdev.h>
17#include <linux/list.h>
18#include <linux/types.h>
19#include <scsi/scsi.h>
20#include <scsi/scsi_cmnd.h>
21#include <scsi/scsi_dbg.h>
22
23#include "dm.h"
24#include "dm-hw-handler.h"
25
26#define DM_MSG_PREFIX "multipath hp-sw"
27#define DM_HP_HWH_NAME "hp-sw"
28#define DM_HP_HWH_VER "1.0.0"
29
30struct hp_sw_context {
31 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
32};
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51static int hp_sw_error_is_retryable(struct request *req)
52{
53
54
55
56
57 if (status_byte(req->errors) == CHECK_CONDITION)
58 __scsi_print_sense(DM_HP_HWH_NAME, req->sense, req->sense_len);
59
60
61
62
63
64
65 return 1;
66}
67
68
69
70
71
72
73
74
75
76
77
78
79static void hp_sw_end_io(struct request *req, int error)
80{
81 struct dm_path *path = req->end_io_data;
82 unsigned err_flags = 0;
83
84 if (!error) {
85 DMDEBUG("%s path activation command - success",
86 path->dev->name);
87 goto out;
88 }
89
90 if (hp_sw_error_is_retryable(req)) {
91 DMDEBUG("%s path activation command - retry",
92 path->dev->name);
93 err_flags = MP_RETRY;
94 goto out;
95 }
96
97 DMWARN("%s path activation fail - error=0x%x",
98 path->dev->name, error);
99 err_flags = MP_FAIL_PATH;
100
101out:
102 req->end_io_data = NULL;
103 __blk_put_request(req->q, req);
104 dm_pg_init_complete(path, err_flags);
105}
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120static struct request *hp_sw_get_request(struct dm_path *path)
121{
122 struct request *req;
123 struct block_device *bdev = path->dev->bdev;
124 struct request_queue *q = bdev_get_queue(bdev);
125 struct hp_sw_context *h = path->hwhcontext;
126
127 req = blk_get_request(q, WRITE, GFP_NOIO);
128 if (!req)
129 goto out;
130
131 req->timeout = 60 * HZ;
132
133 req->errors = 0;
134 req->cmd_type = REQ_TYPE_BLOCK_PC;
135 req->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
136 req->end_io_data = path;
137 req->sense = h->sense;
138 memset(req->sense, 0, SCSI_SENSE_BUFFERSIZE);
139
140 memset(&req->cmd, 0, BLK_MAX_CDB);
141 req->cmd[0] = START_STOP;
142 req->cmd[4] = 1;
143 req->cmd_len = COMMAND_SIZE(req->cmd[0]);
144
145out:
146 return req;
147}
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167static void hp_sw_pg_init(struct hw_handler *hwh, unsigned bypassed,
168 struct dm_path *path)
169{
170 struct request *req;
171 struct hp_sw_context *h;
172
173 path->hwhcontext = hwh->context;
174 h = hwh->context;
175
176 req = hp_sw_get_request(path);
177 if (!req) {
178 DMERR("%s path activation command - allocation fail",
179 path->dev->name);
180 goto retry;
181 }
182
183 DMDEBUG("%s path activation command - sent", path->dev->name);
184
185 blk_execute_rq_nowait(req->q, NULL, req, 1, hp_sw_end_io);
186 return;
187
188retry:
189 dm_pg_init_complete(path, MP_RETRY);
190}
191
192static int hp_sw_create(struct hw_handler *hwh, unsigned argc, char **argv)
193{
194 struct hp_sw_context *h;
195
196 h = kmalloc(sizeof(*h), GFP_KERNEL);
197 if (!h)
198 return -ENOMEM;
199
200 hwh->context = h;
201
202 return 0;
203}
204
205static void hp_sw_destroy(struct hw_handler *hwh)
206{
207 struct hp_sw_context *h = hwh->context;
208
209 kfree(h);
210}
211
212static struct hw_handler_type hp_sw_hwh = {
213 .name = DM_HP_HWH_NAME,
214 .module = THIS_MODULE,
215 .create = hp_sw_create,
216 .destroy = hp_sw_destroy,
217 .pg_init = hp_sw_pg_init,
218};
219
220static int __init hp_sw_init(void)
221{
222 int r;
223
224 r = dm_register_hw_handler(&hp_sw_hwh);
225 if (r < 0)
226 DMERR("register failed %d", r);
227 else
228 DMINFO("version " DM_HP_HWH_VER " loaded");
229
230 return r;
231}
232
233static void __exit hp_sw_exit(void)
234{
235 int r;
236
237 r = dm_unregister_hw_handler(&hp_sw_hwh);
238 if (r < 0)
239 DMERR("unregister failed %d", r);
240}
241
242module_init(hp_sw_init);
243module_exit(hp_sw_exit);
244
245MODULE_DESCRIPTION("DM Multipath HP StorageWorks / FSC FibreCat (A/P) support");
246MODULE_AUTHOR("Mike Christie, Dave Wysochanski <dm-devel@redhat.com>");
247MODULE_LICENSE("GPL");
248MODULE_VERSION(DM_HP_HWH_VER);
249