Drop 'size' argument from bio_endio and bi_end_io
[deliverable/linux.git] / drivers / md / dm-emc.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2004 SUSE LINUX Products GmbH. All rights reserved.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 *
7 * Multipath support for EMC CLARiiON AX/CX-series hardware.
8 */
9
10#include "dm.h"
11#include "dm-hw-handler.h"
12#include <scsi/scsi.h>
13#include <scsi/scsi_cmnd.h>
14
72d94861
AK
15#define DM_MSG_PREFIX "multipath emc"
16
1da177e4
LT
17struct emc_handler {
18 spinlock_t lock;
19
20 /* Whether we should send the short trespass command (FC-series)
21 * or the long version (default for AX/CX CLARiiON arrays). */
22 unsigned short_trespass;
23 /* Whether or not to honor SCSI reservations when initiating a
24 * switch-over. Default: Don't. */
25 unsigned hr;
26
27 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
28};
29
30#define TRESPASS_PAGE 0x22
31#define EMC_FAILOVER_TIMEOUT (60 * HZ)
32
33/* Code borrowed from dm-lsi-rdac by Mike Christie */
34
35static inline void free_bio(struct bio *bio)
36{
37 __free_page(bio->bi_io_vec[0].bv_page);
38 bio_put(bio);
39}
40
6712ecf8 41static void emc_endio(struct bio *bio, int error)
1da177e4 42{
c922d5f7 43 struct dm_path *path = bio->bi_private;
1da177e4 44
1da177e4
LT
45 /* We also need to look at the sense keys here whether or not to
46 * switch to the next PG etc.
47 *
48 * For now simple logic: either it works or it doesn't.
49 */
50 if (error)
51 dm_pg_init_complete(path, MP_FAIL_PATH);
52 else
53 dm_pg_init_complete(path, 0);
54
55 /* request is freed in block layer */
56 free_bio(bio);
57
58 return 0;
59}
60
c922d5f7 61static struct bio *get_failover_bio(struct dm_path *path, unsigned data_size)
1da177e4
LT
62{
63 struct bio *bio;
64 struct page *page;
65
66 bio = bio_alloc(GFP_ATOMIC, 1);
67 if (!bio) {
72d94861 68 DMERR("get_failover_bio: bio_alloc() failed.");
1da177e4
LT
69 return NULL;
70 }
71
72 bio->bi_rw |= (1 << BIO_RW);
73 bio->bi_bdev = path->dev->bdev;
74 bio->bi_sector = 0;
75 bio->bi_private = path;
76 bio->bi_end_io = emc_endio;
77
78 page = alloc_page(GFP_ATOMIC);
79 if (!page) {
72d94861 80 DMERR("get_failover_bio: alloc_page() failed.");
1da177e4
LT
81 bio_put(bio);
82 return NULL;
83 }
84
85 if (bio_add_page(bio, page, data_size, 0) != data_size) {
72d94861 86 DMERR("get_failover_bio: alloc_page() failed.");
1da177e4
LT
87 __free_page(page);
88 bio_put(bio);
89 return NULL;
90 }
91
92 return bio;
93}
94
95static struct request *get_failover_req(struct emc_handler *h,
c922d5f7 96 struct bio *bio, struct dm_path *path)
1da177e4
LT
97{
98 struct request *rq;
99 struct block_device *bdev = bio->bi_bdev;
100 struct request_queue *q = bdev_get_queue(bdev);
101
102 /* FIXME: Figure out why it fails with GFP_ATOMIC. */
103 rq = blk_get_request(q, WRITE, __GFP_WAIT);
104 if (!rq) {
72d94861 105 DMERR("get_failover_req: blk_get_request failed");
1da177e4
LT
106 return NULL;
107 }
108
66846572 109 blk_rq_append_bio(q, rq, bio);
1da177e4
LT
110
111 rq->sense = h->sense;
112 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
113 rq->sense_len = 0;
114
115 memset(&rq->cmd, 0, BLK_MAX_CDB);
116
117 rq->timeout = EMC_FAILOVER_TIMEOUT;
4aff5e23
JA
118 rq->cmd_type = REQ_TYPE_BLOCK_PC;
119 rq->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
1da177e4
LT
120
121 return rq;
122}
123
124static struct request *emc_trespass_get(struct emc_handler *h,
c922d5f7 125 struct dm_path *path)
1da177e4
LT
126{
127 struct bio *bio;
128 struct request *rq;
129 unsigned char *page22;
130 unsigned char long_trespass_pg[] = {
131 0, 0, 0, 0,
132 TRESPASS_PAGE, /* Page code */
133 0x09, /* Page length - 2 */
134 h->hr ? 0x01 : 0x81, /* Trespass code + Honor reservation bit */
135 0xff, 0xff, /* Trespass target */
136 0, 0, 0, 0, 0, 0 /* Reserved bytes / unknown */
137 };
138 unsigned char short_trespass_pg[] = {
139 0, 0, 0, 0,
140 TRESPASS_PAGE, /* Page code */
141 0x02, /* Page length - 2 */
142 h->hr ? 0x01 : 0x81, /* Trespass code + Honor reservation bit */
143 0xff, /* Trespass target */
144 };
145 unsigned data_size = h->short_trespass ? sizeof(short_trespass_pg) :
146 sizeof(long_trespass_pg);
147
148 /* get bio backing */
149 if (data_size > PAGE_SIZE)
150 /* this should never happen */
151 return NULL;
152
153 bio = get_failover_bio(path, data_size);
154 if (!bio) {
72d94861 155 DMERR("emc_trespass_get: no bio");
1da177e4
LT
156 return NULL;
157 }
158
159 page22 = (unsigned char *)bio_data(bio);
160 memset(page22, 0, data_size);
161
162 memcpy(page22, h->short_trespass ?
163 short_trespass_pg : long_trespass_pg, data_size);
164
165 /* get request for block layer packet command */
166 rq = get_failover_req(h, bio, path);
167 if (!rq) {
72d94861 168 DMERR("emc_trespass_get: no rq");
1da177e4
LT
169 free_bio(bio);
170 return NULL;
171 }
172
173 /* Prepare the command. */
174 rq->cmd[0] = MODE_SELECT;
175 rq->cmd[1] = 0x10;
176 rq->cmd[4] = data_size;
177 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
178
179 return rq;
180}
181
182static void emc_pg_init(struct hw_handler *hwh, unsigned bypassed,
c922d5f7 183 struct dm_path *path)
1da177e4
LT
184{
185 struct request *rq;
186 struct request_queue *q = bdev_get_queue(path->dev->bdev);
187
188 /*
189 * We can either blindly init the pg (then look at the sense),
190 * or we can send some commands to get the state here (then
191 * possibly send the fo cmnd), or we can also have the
192 * initial state passed into us and then get an update here.
193 */
194 if (!q) {
72d94861 195 DMINFO("emc_pg_init: no queue");
1da177e4
LT
196 goto fail_path;
197 }
198
199 /* FIXME: The request should be pre-allocated. */
200 rq = emc_trespass_get(hwh->context, path);
201 if (!rq) {
72d94861 202 DMERR("emc_pg_init: no rq");
1da177e4
LT
203 goto fail_path;
204 }
205
72d94861 206 DMINFO("emc_pg_init: sending switch-over command");
1da177e4
LT
207 elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
208 return;
209
210fail_path:
211 dm_pg_init_complete(path, MP_FAIL_PATH);
212}
213
214static struct emc_handler *alloc_emc_handler(void)
215{
216 struct emc_handler *h = kmalloc(sizeof(*h), GFP_KERNEL);
217
f1daa40b
AK
218 if (h) {
219 memset(h, 0, sizeof(*h));
1da177e4 220 spin_lock_init(&h->lock);
f1daa40b 221 }
1da177e4
LT
222
223 return h;
224}
225
226static int emc_create(struct hw_handler *hwh, unsigned argc, char **argv)
227{
228 struct emc_handler *h;
229 unsigned hr, short_trespass;
230
231 if (argc == 0) {
232 /* No arguments: use defaults */
233 hr = 0;
234 short_trespass = 0;
235 } else if (argc != 2) {
72d94861 236 DMWARN("incorrect number of arguments");
1da177e4
LT
237 return -EINVAL;
238 } else {
239 if ((sscanf(argv[0], "%u", &short_trespass) != 1)
240 || (short_trespass > 1)) {
72d94861 241 DMWARN("invalid trespass mode selected");
1da177e4
LT
242 return -EINVAL;
243 }
244
245 if ((sscanf(argv[1], "%u", &hr) != 1)
246 || (hr > 1)) {
72d94861 247 DMWARN("invalid honor reservation flag selected");
1da177e4
LT
248 return -EINVAL;
249 }
250 }
251
252 h = alloc_emc_handler();
253 if (!h)
254 return -ENOMEM;
255
1da177e4
LT
256 hwh->context = h;
257
258 if ((h->short_trespass = short_trespass))
72d94861 259 DMWARN("short trespass command will be send");
1da177e4 260 else
72d94861 261 DMWARN("long trespass command will be send");
1da177e4
LT
262
263 if ((h->hr = hr))
72d94861 264 DMWARN("honor reservation bit will be set");
1da177e4 265 else
72d94861 266 DMWARN("honor reservation bit will not be set (default)");
1da177e4
LT
267
268 return 0;
269}
270
271static void emc_destroy(struct hw_handler *hwh)
272{
273 struct emc_handler *h = (struct emc_handler *) hwh->context;
274
275 kfree(h);
276 hwh->context = NULL;
277}
278
279static unsigned emc_error(struct hw_handler *hwh, struct bio *bio)
280{
281 /* FIXME: Patch from axboe still missing */
282#if 0
283 int sense;
284
285 if (bio->bi_error & BIO_SENSE) {
286 sense = bio->bi_error & 0xffffff; /* sense key / asc / ascq */
287
288 if (sense == 0x020403) {
289 /* LUN Not Ready - Manual Intervention Required
290 * indicates this is a passive path.
291 *
292 * FIXME: However, if this is seen and EVPD C0
293 * indicates that this is due to a NDU in
294 * progress, we should set FAIL_PATH too.
295 * This indicates we might have to do a SCSI
296 * inquiry in the end_io path. Ugh. */
297 return MP_BYPASS_PG | MP_RETRY_IO;
298 } else if (sense == 0x052501) {
299 /* An array based copy is in progress. Do not
300 * fail the path, do not bypass to another PG,
301 * do not retry. Fail the IO immediately.
302 * (Actually this is the same conclusion as in
303 * the default handler, but lets make sure.) */
304 return 0;
305 } else if (sense == 0x062900) {
306 /* Unit Attention Code. This is the first IO
307 * to the new path, so just retry. */
308 return MP_RETRY_IO;
309 }
310 }
311#endif
312
313 /* Try default handler */
314 return dm_scsi_err_handler(hwh, bio);
315}
316
317static struct hw_handler_type emc_hwh = {
318 .name = "emc",
319 .module = THIS_MODULE,
320 .create = emc_create,
321 .destroy = emc_destroy,
322 .pg_init = emc_pg_init,
323 .error = emc_error,
324};
325
326static int __init dm_emc_init(void)
327{
328 int r = dm_register_hw_handler(&emc_hwh);
329
330 if (r < 0)
72d94861 331 DMERR("register failed %d", r);
1da177e4 332
72d94861 333 DMINFO("version 0.0.3 loaded");
1da177e4
LT
334
335 return r;
336}
337
338static void __exit dm_emc_exit(void)
339{
340 int r = dm_unregister_hw_handler(&emc_hwh);
341
342 if (r < 0)
72d94861 343 DMERR("unregister failed %d", r);
1da177e4
LT
344}
345
346module_init(dm_emc_init);
347module_exit(dm_emc_exit);
348
349MODULE_DESCRIPTION(DM_NAME " EMC CX/AX/FC-family multipath");
350MODULE_AUTHOR("Lars Marowsky-Bree <lmb@suse.de>");
351MODULE_LICENSE("GPL");
This page took 0.297575 seconds and 5 git commands to generate.