oom: suppress extraneous stack and memory dump
[wrt350n-kernel.git] / drivers / md / dm-emc.c
blob342517261ece129dd115f34897b1ff762a1fd78b
1 /*
2 * Copyright (C) 2004 SUSE LINUX Products GmbH. All rights reserved.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
5 * This file is released under the GPL.
7 * Multipath support for EMC CLARiiON AX/CX-series hardware.
8 */
10 #include "dm.h"
11 #include "dm-hw-handler.h"
12 #include <scsi/scsi.h>
13 #include <scsi/scsi_cmnd.h>
15 #define DM_MSG_PREFIX "multipath emc"
17 struct emc_handler {
18 spinlock_t lock;
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;
27 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
30 #define TRESPASS_PAGE 0x22
31 #define EMC_FAILOVER_TIMEOUT (60 * HZ)
33 /* Code borrowed from dm-lsi-rdac by Mike Christie */
35 static inline void free_bio(struct bio *bio)
37 __free_page(bio->bi_io_vec[0].bv_page);
38 bio_put(bio);
41 static void emc_endio(struct bio *bio, int error)
43 struct dm_path *path = bio->bi_private;
45 /* We also need to look at the sense keys here whether or not to
46 * switch to the next PG etc.
48 * For now simple logic: either it works or it doesn't.
50 if (error)
51 dm_pg_init_complete(path, MP_FAIL_PATH);
52 else
53 dm_pg_init_complete(path, 0);
55 /* request is freed in block layer */
56 free_bio(bio);
59 static struct bio *get_failover_bio(struct dm_path *path, unsigned data_size)
61 struct bio *bio;
62 struct page *page;
64 bio = bio_alloc(GFP_ATOMIC, 1);
65 if (!bio) {
66 DMERR("get_failover_bio: bio_alloc() failed.");
67 return NULL;
70 bio->bi_rw |= (1 << BIO_RW);
71 bio->bi_bdev = path->dev->bdev;
72 bio->bi_sector = 0;
73 bio->bi_private = path;
74 bio->bi_end_io = emc_endio;
76 page = alloc_page(GFP_ATOMIC);
77 if (!page) {
78 DMERR("get_failover_bio: alloc_page() failed.");
79 bio_put(bio);
80 return NULL;
83 if (bio_add_page(bio, page, data_size, 0) != data_size) {
84 DMERR("get_failover_bio: alloc_page() failed.");
85 __free_page(page);
86 bio_put(bio);
87 return NULL;
90 return bio;
93 static struct request *get_failover_req(struct emc_handler *h,
94 struct bio *bio, struct dm_path *path)
96 struct request *rq;
97 struct block_device *bdev = bio->bi_bdev;
98 struct request_queue *q = bdev_get_queue(bdev);
100 /* FIXME: Figure out why it fails with GFP_ATOMIC. */
101 rq = blk_get_request(q, WRITE, __GFP_WAIT);
102 if (!rq) {
103 DMERR("get_failover_req: blk_get_request failed");
104 return NULL;
107 blk_rq_append_bio(q, rq, bio);
109 rq->sense = h->sense;
110 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
111 rq->sense_len = 0;
113 memset(&rq->cmd, 0, BLK_MAX_CDB);
115 rq->timeout = EMC_FAILOVER_TIMEOUT;
116 rq->cmd_type = REQ_TYPE_BLOCK_PC;
117 rq->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
119 return rq;
122 static struct request *emc_trespass_get(struct emc_handler *h,
123 struct dm_path *path)
125 struct bio *bio;
126 struct request *rq;
127 unsigned char *page22;
128 unsigned char long_trespass_pg[] = {
129 0, 0, 0, 0,
130 TRESPASS_PAGE, /* Page code */
131 0x09, /* Page length - 2 */
132 h->hr ? 0x01 : 0x81, /* Trespass code + Honor reservation bit */
133 0xff, 0xff, /* Trespass target */
134 0, 0, 0, 0, 0, 0 /* Reserved bytes / unknown */
136 unsigned char short_trespass_pg[] = {
137 0, 0, 0, 0,
138 TRESPASS_PAGE, /* Page code */
139 0x02, /* Page length - 2 */
140 h->hr ? 0x01 : 0x81, /* Trespass code + Honor reservation bit */
141 0xff, /* Trespass target */
143 unsigned data_size = h->short_trespass ? sizeof(short_trespass_pg) :
144 sizeof(long_trespass_pg);
146 /* get bio backing */
147 if (data_size > PAGE_SIZE)
148 /* this should never happen */
149 return NULL;
151 bio = get_failover_bio(path, data_size);
152 if (!bio) {
153 DMERR("emc_trespass_get: no bio");
154 return NULL;
157 page22 = (unsigned char *)bio_data(bio);
158 memset(page22, 0, data_size);
160 memcpy(page22, h->short_trespass ?
161 short_trespass_pg : long_trespass_pg, data_size);
163 /* get request for block layer packet command */
164 rq = get_failover_req(h, bio, path);
165 if (!rq) {
166 DMERR("emc_trespass_get: no rq");
167 free_bio(bio);
168 return NULL;
171 /* Prepare the command. */
172 rq->cmd[0] = MODE_SELECT;
173 rq->cmd[1] = 0x10;
174 rq->cmd[4] = data_size;
175 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
177 return rq;
180 static void emc_pg_init(struct hw_handler *hwh, unsigned bypassed,
181 struct dm_path *path)
183 struct request *rq;
184 struct request_queue *q = bdev_get_queue(path->dev->bdev);
187 * We can either blindly init the pg (then look at the sense),
188 * or we can send some commands to get the state here (then
189 * possibly send the fo cmnd), or we can also have the
190 * initial state passed into us and then get an update here.
192 if (!q) {
193 DMINFO("emc_pg_init: no queue");
194 goto fail_path;
197 /* FIXME: The request should be pre-allocated. */
198 rq = emc_trespass_get(hwh->context, path);
199 if (!rq) {
200 DMERR("emc_pg_init: no rq");
201 goto fail_path;
204 DMINFO("emc_pg_init: sending switch-over command");
205 elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
206 return;
208 fail_path:
209 dm_pg_init_complete(path, MP_FAIL_PATH);
212 static struct emc_handler *alloc_emc_handler(void)
214 struct emc_handler *h = kmalloc(sizeof(*h), GFP_KERNEL);
216 if (h) {
217 memset(h, 0, sizeof(*h));
218 spin_lock_init(&h->lock);
221 return h;
224 static int emc_create(struct hw_handler *hwh, unsigned argc, char **argv)
226 struct emc_handler *h;
227 unsigned hr, short_trespass;
229 if (argc == 0) {
230 /* No arguments: use defaults */
231 hr = 0;
232 short_trespass = 0;
233 } else if (argc != 2) {
234 DMWARN("incorrect number of arguments");
235 return -EINVAL;
236 } else {
237 if ((sscanf(argv[0], "%u", &short_trespass) != 1)
238 || (short_trespass > 1)) {
239 DMWARN("invalid trespass mode selected");
240 return -EINVAL;
243 if ((sscanf(argv[1], "%u", &hr) != 1)
244 || (hr > 1)) {
245 DMWARN("invalid honor reservation flag selected");
246 return -EINVAL;
250 h = alloc_emc_handler();
251 if (!h)
252 return -ENOMEM;
254 hwh->context = h;
256 if ((h->short_trespass = short_trespass))
257 DMWARN("short trespass command will be send");
258 else
259 DMWARN("long trespass command will be send");
261 if ((h->hr = hr))
262 DMWARN("honor reservation bit will be set");
263 else
264 DMWARN("honor reservation bit will not be set (default)");
266 return 0;
269 static void emc_destroy(struct hw_handler *hwh)
271 struct emc_handler *h = (struct emc_handler *) hwh->context;
273 kfree(h);
274 hwh->context = NULL;
277 static unsigned emc_error(struct hw_handler *hwh, struct bio *bio)
279 /* FIXME: Patch from axboe still missing */
280 #if 0
281 int sense;
283 if (bio->bi_error & BIO_SENSE) {
284 sense = bio->bi_error & 0xffffff; /* sense key / asc / ascq */
286 if (sense == 0x020403) {
287 /* LUN Not Ready - Manual Intervention Required
288 * indicates this is a passive path.
290 * FIXME: However, if this is seen and EVPD C0
291 * indicates that this is due to a NDU in
292 * progress, we should set FAIL_PATH too.
293 * This indicates we might have to do a SCSI
294 * inquiry in the end_io path. Ugh. */
295 return MP_BYPASS_PG | MP_RETRY_IO;
296 } else if (sense == 0x052501) {
297 /* An array based copy is in progress. Do not
298 * fail the path, do not bypass to another PG,
299 * do not retry. Fail the IO immediately.
300 * (Actually this is the same conclusion as in
301 * the default handler, but lets make sure.) */
302 return 0;
303 } else if (sense == 0x062900) {
304 /* Unit Attention Code. This is the first IO
305 * to the new path, so just retry. */
306 return MP_RETRY_IO;
309 #endif
311 /* Try default handler */
312 return dm_scsi_err_handler(hwh, bio);
315 static struct hw_handler_type emc_hwh = {
316 .name = "emc",
317 .module = THIS_MODULE,
318 .create = emc_create,
319 .destroy = emc_destroy,
320 .pg_init = emc_pg_init,
321 .error = emc_error,
324 static int __init dm_emc_init(void)
326 int r = dm_register_hw_handler(&emc_hwh);
328 if (r < 0)
329 DMERR("register failed %d", r);
331 DMINFO("version 0.0.3 loaded");
333 return r;
336 static void __exit dm_emc_exit(void)
338 int r = dm_unregister_hw_handler(&emc_hwh);
340 if (r < 0)
341 DMERR("unregister failed %d", r);
344 module_init(dm_emc_init);
345 module_exit(dm_emc_exit);
347 MODULE_DESCRIPTION(DM_NAME " EMC CX/AX/FC-family multipath");
348 MODULE_AUTHOR("Lars Marowsky-Bree <lmb@suse.de>");
349 MODULE_LICENSE("GPL");