blob: fb9582ae6b2d19ddfd769cab126e55bc1be2e84c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2003 Sistina Software Limited.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm.h"
9#include "dm-path-selector.h"
10#include "dm-hw-handler.h"
11#include "dm-bio-list.h"
12#include "dm-bio-record.h"
13
14#include <linux/ctype.h>
15#include <linux/init.h>
16#include <linux/mempool.h>
17#include <linux/module.h>
18#include <linux/pagemap.h>
19#include <linux/slab.h>
20#include <linux/time.h>
21#include <linux/workqueue.h>
22#include <asm/atomic.h>
23
Alasdair G Kergon72d94862006-06-26 00:27:35 -070024#define DM_MSG_PREFIX "multipath"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#define MESG_STR(x) x, sizeof(x)
26
27/* Path properties */
28struct pgpath {
29 struct list_head list;
30
31 struct priority_group *pg; /* Owning PG */
32 unsigned fail_count; /* Cumulative failure count */
33
34 struct path path;
35};
36
37#define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path)
38
39/*
40 * Paths are grouped into Priority Groups and numbered from 1 upwards.
41 * Each has a path selector which controls which path gets used.
42 */
43struct priority_group {
44 struct list_head list;
45
46 struct multipath *m; /* Owning multipath instance */
47 struct path_selector ps;
48
49 unsigned pg_num; /* Reference number */
50 unsigned bypassed; /* Temporarily bypass this PG? */
51
52 unsigned nr_pgpaths; /* Number of paths in PG */
53 struct list_head pgpaths;
54};
55
56/* Multipath context */
57struct multipath {
58 struct list_head list;
59 struct dm_target *ti;
60
61 spinlock_t lock;
62
63 struct hw_handler hw_handler;
64 unsigned nr_priority_groups;
65 struct list_head priority_groups;
66 unsigned pg_init_required; /* pg_init needs calling? */
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -070067 unsigned pg_init_in_progress; /* Only one pg_init allowed at once */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 unsigned nr_valid_paths; /* Total number of usable paths */
70 struct pgpath *current_pgpath;
71 struct priority_group *current_pg;
72 struct priority_group *next_pg; /* Switch to this PG if set */
73 unsigned repeat_count; /* I/Os left before calling PS again */
74
75 unsigned queue_io; /* Must we queue all I/O? */
76 unsigned queue_if_no_path; /* Queue I/O if last path fails? */
Alasdair G Kergon436d4102005-07-12 15:53:03 -070077 unsigned saved_queue_if_no_path;/* Saved state during suspension */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 struct work_struct process_queued_ios;
80 struct bio_list queued_ios;
81 unsigned queue_size;
82
83 struct work_struct trigger_event;
84
85 /*
86 * We must use a mempool of mpath_io structs so that we
87 * can resubmit bios on error.
88 */
89 mempool_t *mpio_pool;
90};
91
92/*
93 * Context information attached to each bio we process.
94 */
95struct mpath_io {
96 struct pgpath *pgpath;
97 struct dm_bio_details details;
98};
99
100typedef int (*action_fn) (struct pgpath *pgpath);
101
102#define MIN_IOS 256 /* Mempool size */
103
104static kmem_cache_t *_mpio_cache;
105
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700106struct workqueue_struct *kmultipathd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static void process_queued_ios(void *data);
108static void trigger_event(void *data);
109
110
111/*-----------------------------------------------
112 * Allocation routines
113 *-----------------------------------------------*/
114
115static struct pgpath *alloc_pgpath(void)
116{
117 struct pgpath *pgpath = kmalloc(sizeof(*pgpath), GFP_KERNEL);
118
119 if (pgpath) {
120 memset(pgpath, 0, sizeof(*pgpath));
121 pgpath->path.is_active = 1;
122 }
123
124 return pgpath;
125}
126
127static inline void free_pgpath(struct pgpath *pgpath)
128{
129 kfree(pgpath);
130}
131
132static struct priority_group *alloc_priority_group(void)
133{
134 struct priority_group *pg;
135
136 pg = kmalloc(sizeof(*pg), GFP_KERNEL);
137 if (!pg)
138 return NULL;
139
140 memset(pg, 0, sizeof(*pg));
141 INIT_LIST_HEAD(&pg->pgpaths);
142
143 return pg;
144}
145
146static void free_pgpaths(struct list_head *pgpaths, struct dm_target *ti)
147{
148 struct pgpath *pgpath, *tmp;
149
150 list_for_each_entry_safe(pgpath, tmp, pgpaths, list) {
151 list_del(&pgpath->list);
152 dm_put_device(ti, pgpath->path.dev);
153 free_pgpath(pgpath);
154 }
155}
156
157static void free_priority_group(struct priority_group *pg,
158 struct dm_target *ti)
159{
160 struct path_selector *ps = &pg->ps;
161
162 if (ps->type) {
163 ps->type->destroy(ps);
164 dm_put_path_selector(ps->type);
165 }
166
167 free_pgpaths(&pg->pgpaths, ti);
168 kfree(pg);
169}
170
171static struct multipath *alloc_multipath(void)
172{
173 struct multipath *m;
174
175 m = kmalloc(sizeof(*m), GFP_KERNEL);
176 if (m) {
177 memset(m, 0, sizeof(*m));
178 INIT_LIST_HEAD(&m->priority_groups);
179 spin_lock_init(&m->lock);
180 m->queue_io = 1;
181 INIT_WORK(&m->process_queued_ios, process_queued_ios, m);
182 INIT_WORK(&m->trigger_event, trigger_event, m);
Matthew Dobson93d23412006-03-26 01:37:50 -0800183 m->mpio_pool = mempool_create_slab_pool(MIN_IOS, _mpio_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 if (!m->mpio_pool) {
185 kfree(m);
186 return NULL;
187 }
188 }
189
190 return m;
191}
192
193static void free_multipath(struct multipath *m)
194{
195 struct priority_group *pg, *tmp;
196 struct hw_handler *hwh = &m->hw_handler;
197
198 list_for_each_entry_safe(pg, tmp, &m->priority_groups, list) {
199 list_del(&pg->list);
200 free_priority_group(pg, m->ti);
201 }
202
203 if (hwh->type) {
204 hwh->type->destroy(hwh);
205 dm_put_hw_handler(hwh->type);
206 }
207
208 mempool_destroy(m->mpio_pool);
209 kfree(m);
210}
211
212
213/*-----------------------------------------------
214 * Path selection
215 *-----------------------------------------------*/
216
217static void __switch_pg(struct multipath *m, struct pgpath *pgpath)
218{
219 struct hw_handler *hwh = &m->hw_handler;
220
221 m->current_pg = pgpath->pg;
222
223 /* Must we initialise the PG first, and queue I/O till it's ready? */
224 if (hwh->type && hwh->type->pg_init) {
225 m->pg_init_required = 1;
226 m->queue_io = 1;
227 } else {
228 m->pg_init_required = 0;
229 m->queue_io = 0;
230 }
231}
232
233static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg)
234{
235 struct path *path;
236
237 path = pg->ps.type->select_path(&pg->ps, &m->repeat_count);
238 if (!path)
239 return -ENXIO;
240
241 m->current_pgpath = path_to_pgpath(path);
242
243 if (m->current_pg != pg)
244 __switch_pg(m, m->current_pgpath);
245
246 return 0;
247}
248
249static void __choose_pgpath(struct multipath *m)
250{
251 struct priority_group *pg;
252 unsigned bypassed = 1;
253
254 if (!m->nr_valid_paths)
255 goto failed;
256
257 /* Were we instructed to switch PG? */
258 if (m->next_pg) {
259 pg = m->next_pg;
260 m->next_pg = NULL;
261 if (!__choose_path_in_pg(m, pg))
262 return;
263 }
264
265 /* Don't change PG until it has no remaining paths */
266 if (m->current_pg && !__choose_path_in_pg(m, m->current_pg))
267 return;
268
269 /*
270 * Loop through priority groups until we find a valid path.
271 * First time we skip PGs marked 'bypassed'.
272 * Second time we only try the ones we skipped.
273 */
274 do {
275 list_for_each_entry(pg, &m->priority_groups, list) {
276 if (pg->bypassed == bypassed)
277 continue;
278 if (!__choose_path_in_pg(m, pg))
279 return;
280 }
281 } while (bypassed--);
282
283failed:
284 m->current_pgpath = NULL;
285 m->current_pg = NULL;
286}
287
288static int map_io(struct multipath *m, struct bio *bio, struct mpath_io *mpio,
289 unsigned was_queued)
290{
291 int r = 1;
292 unsigned long flags;
293 struct pgpath *pgpath;
294
295 spin_lock_irqsave(&m->lock, flags);
296
297 /* Do we need to select a new pgpath? */
298 if (!m->current_pgpath ||
299 (!m->queue_io && (m->repeat_count && --m->repeat_count == 0)))
300 __choose_pgpath(m);
301
302 pgpath = m->current_pgpath;
303
304 if (was_queued)
305 m->queue_size--;
306
307 if ((pgpath && m->queue_io) ||
Alasdair G Kergon436d4102005-07-12 15:53:03 -0700308 (!pgpath && m->queue_if_no_path)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 /* Queue for the daemon to resubmit */
310 bio_list_add(&m->queued_ios, bio);
311 m->queue_size++;
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700312 if ((m->pg_init_required && !m->pg_init_in_progress) ||
313 !m->queue_io)
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700314 queue_work(kmultipathd, &m->process_queued_ios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 pgpath = NULL;
316 r = 0;
317 } else if (!pgpath)
318 r = -EIO; /* Failed */
319 else
320 bio->bi_bdev = pgpath->path.dev->bdev;
321
322 mpio->pgpath = pgpath;
323
324 spin_unlock_irqrestore(&m->lock, flags);
325
326 return r;
327}
328
329/*
330 * If we run out of usable paths, should we queue I/O or error it?
331 */
Alasdair G Kergon485ef692005-09-27 21:45:45 -0700332static int queue_if_no_path(struct multipath *m, unsigned queue_if_no_path,
333 unsigned save_old_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 unsigned long flags;
336
337 spin_lock_irqsave(&m->lock, flags);
338
Alasdair G Kergon485ef692005-09-27 21:45:45 -0700339 if (save_old_value)
340 m->saved_queue_if_no_path = m->queue_if_no_path;
341 else
342 m->saved_queue_if_no_path = queue_if_no_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 m->queue_if_no_path = queue_if_no_path;
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700344 if (!m->queue_if_no_path && m->queue_size)
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700345 queue_work(kmultipathd, &m->process_queued_ios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 spin_unlock_irqrestore(&m->lock, flags);
348
349 return 0;
350}
351
352/*-----------------------------------------------------------------
353 * The multipath daemon is responsible for resubmitting queued ios.
354 *---------------------------------------------------------------*/
355
356static void dispatch_queued_ios(struct multipath *m)
357{
358 int r;
359 unsigned long flags;
360 struct bio *bio = NULL, *next;
361 struct mpath_io *mpio;
362 union map_info *info;
363
364 spin_lock_irqsave(&m->lock, flags);
365 bio = bio_list_get(&m->queued_ios);
366 spin_unlock_irqrestore(&m->lock, flags);
367
368 while (bio) {
369 next = bio->bi_next;
370 bio->bi_next = NULL;
371
372 info = dm_get_mapinfo(bio);
373 mpio = info->ptr;
374
375 r = map_io(m, bio, mpio, 1);
376 if (r < 0)
377 bio_endio(bio, bio->bi_size, r);
378 else if (r == 1)
379 generic_make_request(bio);
380
381 bio = next;
382 }
383}
384
385static void process_queued_ios(void *data)
386{
387 struct multipath *m = (struct multipath *) data;
388 struct hw_handler *hwh = &m->hw_handler;
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700389 struct pgpath *pgpath = NULL;
390 unsigned init_required = 0, must_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 unsigned long flags;
392
393 spin_lock_irqsave(&m->lock, flags);
394
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700395 if (!m->queue_size)
396 goto out;
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (!m->current_pgpath)
399 __choose_pgpath(m);
400
401 pgpath = m->current_pgpath;
402
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700403 if ((pgpath && !m->queue_io) ||
404 (!pgpath && !m->queue_if_no_path))
405 must_queue = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700407 if (m->pg_init_required && !m->pg_init_in_progress) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 m->pg_init_required = 0;
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700409 m->pg_init_in_progress = 1;
410 init_required = 1;
411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700413out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 spin_unlock_irqrestore(&m->lock, flags);
415
416 if (init_required)
417 hwh->type->pg_init(hwh, pgpath->pg->bypassed, &pgpath->path);
418
419 if (!must_queue)
420 dispatch_queued_ios(m);
421}
422
423/*
424 * An event is triggered whenever a path is taken out of use.
425 * Includes path failure and PG bypass.
426 */
427static void trigger_event(void *data)
428{
429 struct multipath *m = (struct multipath *) data;
430
431 dm_table_event(m->ti->table);
432}
433
434/*-----------------------------------------------------------------
435 * Constructor/argument parsing:
436 * <#multipath feature args> [<arg>]*
437 * <#hw_handler args> [hw_handler [<arg>]*]
438 * <#priority groups>
439 * <initial priority group>
440 * [<selector> <#selector args> [<arg>]*
441 * <#paths> <#per-path selector args>
442 * [<path> [<arg>]* ]+ ]+
443 *---------------------------------------------------------------*/
444struct param {
445 unsigned min;
446 unsigned max;
447 char *error;
448};
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450static int read_param(struct param *param, char *str, unsigned *v, char **error)
451{
452 if (!str ||
453 (sscanf(str, "%u", v) != 1) ||
454 (*v < param->min) ||
455 (*v > param->max)) {
456 *error = param->error;
457 return -EINVAL;
458 }
459
460 return 0;
461}
462
463struct arg_set {
464 unsigned argc;
465 char **argv;
466};
467
468static char *shift(struct arg_set *as)
469{
470 char *r;
471
472 if (as->argc) {
473 as->argc--;
474 r = *as->argv;
475 as->argv++;
476 return r;
477 }
478
479 return NULL;
480}
481
482static void consume(struct arg_set *as, unsigned n)
483{
484 BUG_ON (as->argc < n);
485 as->argc -= n;
486 as->argv += n;
487}
488
489static int parse_path_selector(struct arg_set *as, struct priority_group *pg,
490 struct dm_target *ti)
491{
492 int r;
493 struct path_selector_type *pst;
494 unsigned ps_argc;
495
496 static struct param _params[] = {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700497 {0, 1024, "invalid number of path selector args"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 };
499
500 pst = dm_get_path_selector(shift(as));
501 if (!pst) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700502 ti->error = "unknown path selector type";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 return -EINVAL;
504 }
505
506 r = read_param(_params, shift(as), &ps_argc, &ti->error);
507 if (r)
508 return -EINVAL;
509
510 r = pst->create(&pg->ps, ps_argc, as->argv);
511 if (r) {
512 dm_put_path_selector(pst);
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700513 ti->error = "path selector constructor failed";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return r;
515 }
516
517 pg->ps.type = pst;
518 consume(as, ps_argc);
519
520 return 0;
521}
522
523static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps,
524 struct dm_target *ti)
525{
526 int r;
527 struct pgpath *p;
528
529 /* we need at least a path arg */
530 if (as->argc < 1) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700531 ti->error = "no device given";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 return NULL;
533 }
534
535 p = alloc_pgpath();
536 if (!p)
537 return NULL;
538
539 r = dm_get_device(ti, shift(as), ti->begin, ti->len,
540 dm_table_get_mode(ti->table), &p->path.dev);
541 if (r) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700542 ti->error = "error getting device";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 goto bad;
544 }
545
546 r = ps->type->add_path(ps, &p->path, as->argc, as->argv, &ti->error);
547 if (r) {
548 dm_put_device(ti, p->path.dev);
549 goto bad;
550 }
551
552 return p;
553
554 bad:
555 free_pgpath(p);
556 return NULL;
557}
558
559static struct priority_group *parse_priority_group(struct arg_set *as,
560 struct multipath *m,
561 struct dm_target *ti)
562{
563 static struct param _params[] = {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700564 {1, 1024, "invalid number of paths"},
565 {0, 1024, "invalid number of selector args"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 };
567
568 int r;
569 unsigned i, nr_selector_args, nr_params;
570 struct priority_group *pg;
571
572 if (as->argc < 2) {
573 as->argc = 0;
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700574 ti->error = "not enough priority group aruments";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 return NULL;
576 }
577
578 pg = alloc_priority_group();
579 if (!pg) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700580 ti->error = "couldn't allocate priority group";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return NULL;
582 }
583 pg->m = m;
584
585 r = parse_path_selector(as, pg, ti);
586 if (r)
587 goto bad;
588
589 /*
590 * read the paths
591 */
592 r = read_param(_params, shift(as), &pg->nr_pgpaths, &ti->error);
593 if (r)
594 goto bad;
595
596 r = read_param(_params + 1, shift(as), &nr_selector_args, &ti->error);
597 if (r)
598 goto bad;
599
600 nr_params = 1 + nr_selector_args;
601 for (i = 0; i < pg->nr_pgpaths; i++) {
602 struct pgpath *pgpath;
603 struct arg_set path_args;
604
605 if (as->argc < nr_params)
606 goto bad;
607
608 path_args.argc = nr_params;
609 path_args.argv = as->argv;
610
611 pgpath = parse_path(&path_args, &pg->ps, ti);
612 if (!pgpath)
613 goto bad;
614
615 pgpath->pg = pg;
616 list_add_tail(&pgpath->list, &pg->pgpaths);
617 consume(as, nr_params);
618 }
619
620 return pg;
621
622 bad:
623 free_priority_group(pg, ti);
624 return NULL;
625}
626
627static int parse_hw_handler(struct arg_set *as, struct multipath *m,
628 struct dm_target *ti)
629{
630 int r;
631 struct hw_handler_type *hwht;
632 unsigned hw_argc;
633
634 static struct param _params[] = {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700635 {0, 1024, "invalid number of hardware handler args"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 };
637
638 r = read_param(_params, shift(as), &hw_argc, &ti->error);
639 if (r)
640 return -EINVAL;
641
642 if (!hw_argc)
643 return 0;
644
645 hwht = dm_get_hw_handler(shift(as));
646 if (!hwht) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700647 ti->error = "unknown hardware handler type";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return -EINVAL;
649 }
650
651 r = hwht->create(&m->hw_handler, hw_argc - 1, as->argv);
652 if (r) {
653 dm_put_hw_handler(hwht);
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700654 ti->error = "hardware handler constructor failed";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return r;
656 }
657
658 m->hw_handler.type = hwht;
659 consume(as, hw_argc - 1);
660
661 return 0;
662}
663
664static int parse_features(struct arg_set *as, struct multipath *m,
665 struct dm_target *ti)
666{
667 int r;
668 unsigned argc;
669
670 static struct param _params[] = {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700671 {0, 1, "invalid number of feature args"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 };
673
674 r = read_param(_params, shift(as), &argc, &ti->error);
675 if (r)
676 return -EINVAL;
677
678 if (!argc)
679 return 0;
680
681 if (!strnicmp(shift(as), MESG_STR("queue_if_no_path")))
Alasdair G Kergon485ef692005-09-27 21:45:45 -0700682 return queue_if_no_path(m, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 else {
684 ti->error = "Unrecognised multipath feature request";
685 return -EINVAL;
686 }
687}
688
689static int multipath_ctr(struct dm_target *ti, unsigned int argc,
690 char **argv)
691{
692 /* target parameters */
693 static struct param _params[] = {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700694 {1, 1024, "invalid number of priority groups"},
695 {1, 1024, "invalid initial priority group number"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 };
697
698 int r;
699 struct multipath *m;
700 struct arg_set as;
701 unsigned pg_count = 0;
702 unsigned next_pg_num;
703
704 as.argc = argc;
705 as.argv = argv;
706
707 m = alloc_multipath();
708 if (!m) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700709 ti->error = "can't allocate multipath";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return -EINVAL;
711 }
712
Michal Miroslaw485311a2006-08-13 23:24:20 -0700713 m->ti = ti;
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 r = parse_features(&as, m, ti);
716 if (r)
717 goto bad;
718
719 r = parse_hw_handler(&as, m, ti);
720 if (r)
721 goto bad;
722
723 r = read_param(_params, shift(&as), &m->nr_priority_groups, &ti->error);
724 if (r)
725 goto bad;
726
727 r = read_param(_params + 1, shift(&as), &next_pg_num, &ti->error);
728 if (r)
729 goto bad;
730
731 /* parse the priority groups */
732 while (as.argc) {
733 struct priority_group *pg;
734
735 pg = parse_priority_group(&as, m, ti);
736 if (!pg) {
737 r = -EINVAL;
738 goto bad;
739 }
740
741 m->nr_valid_paths += pg->nr_pgpaths;
742 list_add_tail(&pg->list, &m->priority_groups);
743 pg_count++;
744 pg->pg_num = pg_count;
745 if (!--next_pg_num)
746 m->next_pg = pg;
747 }
748
749 if (pg_count != m->nr_priority_groups) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700750 ti->error = "priority group count mismatch";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 r = -EINVAL;
752 goto bad;
753 }
754
755 ti->private = m;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 return 0;
758
759 bad:
760 free_multipath(m);
761 return r;
762}
763
764static void multipath_dtr(struct dm_target *ti)
765{
766 struct multipath *m = (struct multipath *) ti->private;
Alasdair G Kergona044d012005-07-12 15:53:02 -0700767
768 flush_workqueue(kmultipathd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 free_multipath(m);
770}
771
772/*
773 * Map bios, recording original fields for later in case we have to resubmit
774 */
775static int multipath_map(struct dm_target *ti, struct bio *bio,
776 union map_info *map_context)
777{
778 int r;
779 struct mpath_io *mpio;
780 struct multipath *m = (struct multipath *) ti->private;
781
Alasdair G Kergonf6a80ea2005-07-12 15:53:01 -0700782 if (bio_barrier(bio))
783 return -EOPNOTSUPP;
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 mpio = mempool_alloc(m->mpio_pool, GFP_NOIO);
786 dm_bio_record(&mpio->details, bio);
787
788 map_context->ptr = mpio;
789 bio->bi_rw |= (1 << BIO_RW_FAILFAST);
790 r = map_io(m, bio, mpio, 0);
791 if (r < 0)
792 mempool_free(mpio, m->mpio_pool);
793
794 return r;
795}
796
797/*
798 * Take a path out of use.
799 */
800static int fail_path(struct pgpath *pgpath)
801{
802 unsigned long flags;
803 struct multipath *m = pgpath->pg->m;
804
805 spin_lock_irqsave(&m->lock, flags);
806
807 if (!pgpath->path.is_active)
808 goto out;
809
Alasdair G Kergon72d94862006-06-26 00:27:35 -0700810 DMWARN("Failing path %s.", pgpath->path.dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 pgpath->pg->ps.type->fail_path(&pgpath->pg->ps, &pgpath->path);
813 pgpath->path.is_active = 0;
814 pgpath->fail_count++;
815
816 m->nr_valid_paths--;
817
818 if (pgpath == m->current_pgpath)
819 m->current_pgpath = NULL;
820
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700821 queue_work(kmultipathd, &m->trigger_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823out:
824 spin_unlock_irqrestore(&m->lock, flags);
825
826 return 0;
827}
828
829/*
830 * Reinstate a previously-failed path
831 */
832static int reinstate_path(struct pgpath *pgpath)
833{
834 int r = 0;
835 unsigned long flags;
836 struct multipath *m = pgpath->pg->m;
837
838 spin_lock_irqsave(&m->lock, flags);
839
840 if (pgpath->path.is_active)
841 goto out;
842
843 if (!pgpath->pg->ps.type) {
844 DMWARN("Reinstate path not supported by path selector %s",
845 pgpath->pg->ps.type->name);
846 r = -EINVAL;
847 goto out;
848 }
849
850 r = pgpath->pg->ps.type->reinstate_path(&pgpath->pg->ps, &pgpath->path);
851 if (r)
852 goto out;
853
854 pgpath->path.is_active = 1;
855
856 m->current_pgpath = NULL;
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700857 if (!m->nr_valid_paths++ && m->queue_size)
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700858 queue_work(kmultipathd, &m->process_queued_ios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700860 queue_work(kmultipathd, &m->trigger_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862out:
863 spin_unlock_irqrestore(&m->lock, flags);
864
865 return r;
866}
867
868/*
869 * Fail or reinstate all paths that match the provided struct dm_dev.
870 */
871static int action_dev(struct multipath *m, struct dm_dev *dev,
872 action_fn action)
873{
874 int r = 0;
875 struct pgpath *pgpath;
876 struct priority_group *pg;
877
878 list_for_each_entry(pg, &m->priority_groups, list) {
879 list_for_each_entry(pgpath, &pg->pgpaths, list) {
880 if (pgpath->path.dev == dev)
881 r = action(pgpath);
882 }
883 }
884
885 return r;
886}
887
888/*
889 * Temporarily try to avoid having to use the specified PG
890 */
891static void bypass_pg(struct multipath *m, struct priority_group *pg,
892 int bypassed)
893{
894 unsigned long flags;
895
896 spin_lock_irqsave(&m->lock, flags);
897
898 pg->bypassed = bypassed;
899 m->current_pgpath = NULL;
900 m->current_pg = NULL;
901
902 spin_unlock_irqrestore(&m->lock, flags);
903
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700904 queue_work(kmultipathd, &m->trigger_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
906
907/*
908 * Switch to using the specified PG from the next I/O that gets mapped
909 */
910static int switch_pg_num(struct multipath *m, const char *pgstr)
911{
912 struct priority_group *pg;
913 unsigned pgnum;
914 unsigned long flags;
915
916 if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum ||
917 (pgnum > m->nr_priority_groups)) {
918 DMWARN("invalid PG number supplied to switch_pg_num");
919 return -EINVAL;
920 }
921
922 spin_lock_irqsave(&m->lock, flags);
923 list_for_each_entry(pg, &m->priority_groups, list) {
924 pg->bypassed = 0;
925 if (--pgnum)
926 continue;
927
928 m->current_pgpath = NULL;
929 m->current_pg = NULL;
930 m->next_pg = pg;
931 }
932 spin_unlock_irqrestore(&m->lock, flags);
933
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700934 queue_work(kmultipathd, &m->trigger_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return 0;
936}
937
938/*
939 * Set/clear bypassed status of a PG.
940 * PGs are numbered upwards from 1 in the order they were declared.
941 */
942static int bypass_pg_num(struct multipath *m, const char *pgstr, int bypassed)
943{
944 struct priority_group *pg;
945 unsigned pgnum;
946
947 if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum ||
948 (pgnum > m->nr_priority_groups)) {
949 DMWARN("invalid PG number supplied to bypass_pg");
950 return -EINVAL;
951 }
952
953 list_for_each_entry(pg, &m->priority_groups, list) {
954 if (!--pgnum)
955 break;
956 }
957
958 bypass_pg(m, pg, bypassed);
959 return 0;
960}
961
962/*
963 * pg_init must call this when it has completed its initialisation
964 */
965void dm_pg_init_complete(struct path *path, unsigned err_flags)
966{
967 struct pgpath *pgpath = path_to_pgpath(path);
968 struct priority_group *pg = pgpath->pg;
969 struct multipath *m = pg->m;
970 unsigned long flags;
971
972 /* We insist on failing the path if the PG is already bypassed. */
973 if (err_flags && pg->bypassed)
974 err_flags |= MP_FAIL_PATH;
975
976 if (err_flags & MP_FAIL_PATH)
977 fail_path(pgpath);
978
979 if (err_flags & MP_BYPASS_PG)
980 bypass_pg(m, pg, 1);
981
982 spin_lock_irqsave(&m->lock, flags);
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700983 if (err_flags) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 m->current_pgpath = NULL;
985 m->current_pg = NULL;
Alasdair G Kergonc3cd4f62005-07-12 15:53:04 -0700986 } else if (!m->pg_init_required)
987 m->queue_io = 0;
988
989 m->pg_init_in_progress = 0;
Alasdair G Kergonc5573082005-05-05 16:16:07 -0700990 queue_work(kmultipathd, &m->process_queued_ios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 spin_unlock_irqrestore(&m->lock, flags);
992}
993
994/*
995 * end_io handling
996 */
997static int do_end_io(struct multipath *m, struct bio *bio,
998 int error, struct mpath_io *mpio)
999{
1000 struct hw_handler *hwh = &m->hw_handler;
1001 unsigned err_flags = MP_FAIL_PATH; /* Default behavior */
Stefan Bader640eb3b2005-11-21 21:32:35 -08001002 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 if (!error)
1005 return 0; /* I/O complete */
1006
Lars Marowsky-Bree4f588022005-06-08 15:50:31 -07001007 if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio))
1008 return error;
1009
Alasdair G Kergonf6a80ea2005-07-12 15:53:01 -07001010 if (error == -EOPNOTSUPP)
1011 return error;
1012
Stefan Bader640eb3b2005-11-21 21:32:35 -08001013 spin_lock_irqsave(&m->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 if (!m->nr_valid_paths) {
Alasdair G Kergon436d4102005-07-12 15:53:03 -07001015 if (!m->queue_if_no_path) {
Stefan Bader640eb3b2005-11-21 21:32:35 -08001016 spin_unlock_irqrestore(&m->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 return -EIO;
1018 } else {
Stefan Bader640eb3b2005-11-21 21:32:35 -08001019 spin_unlock_irqrestore(&m->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 goto requeue;
1021 }
1022 }
Stefan Bader640eb3b2005-11-21 21:32:35 -08001023 spin_unlock_irqrestore(&m->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 if (hwh->type && hwh->type->error)
1026 err_flags = hwh->type->error(hwh, bio);
1027
1028 if (mpio->pgpath) {
1029 if (err_flags & MP_FAIL_PATH)
1030 fail_path(mpio->pgpath);
1031
1032 if (err_flags & MP_BYPASS_PG)
1033 bypass_pg(m, mpio->pgpath->pg, 1);
1034 }
1035
1036 if (err_flags & MP_ERROR_IO)
1037 return -EIO;
1038
1039 requeue:
1040 dm_bio_restore(&mpio->details, bio);
1041
1042 /* queue for the daemon to resubmit or fail */
Stefan Bader640eb3b2005-11-21 21:32:35 -08001043 spin_lock_irqsave(&m->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 bio_list_add(&m->queued_ios, bio);
1045 m->queue_size++;
1046 if (!m->queue_io)
Alasdair G Kergonc5573082005-05-05 16:16:07 -07001047 queue_work(kmultipathd, &m->process_queued_ios);
Stefan Bader640eb3b2005-11-21 21:32:35 -08001048 spin_unlock_irqrestore(&m->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 return 1; /* io not complete */
1051}
1052
1053static int multipath_end_io(struct dm_target *ti, struct bio *bio,
1054 int error, union map_info *map_context)
1055{
1056 struct multipath *m = (struct multipath *) ti->private;
1057 struct mpath_io *mpio = (struct mpath_io *) map_context->ptr;
1058 struct pgpath *pgpath = mpio->pgpath;
1059 struct path_selector *ps;
1060 int r;
1061
1062 r = do_end_io(m, bio, error, mpio);
1063 if (pgpath) {
1064 ps = &pgpath->pg->ps;
1065 if (ps->type->end_io)
1066 ps->type->end_io(ps, &pgpath->path);
1067 }
1068 if (r <= 0)
1069 mempool_free(mpio, m->mpio_pool);
1070
1071 return r;
1072}
1073
1074/*
1075 * Suspend can't complete until all the I/O is processed so if
Alasdair G Kergon436d4102005-07-12 15:53:03 -07001076 * the last path fails we must error any remaining I/O.
1077 * Note that if the freeze_bdev fails while suspending, the
1078 * queue_if_no_path state is lost - userspace should reset it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 */
1080static void multipath_presuspend(struct dm_target *ti)
1081{
1082 struct multipath *m = (struct multipath *) ti->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Alasdair G Kergon485ef692005-09-27 21:45:45 -07001084 queue_if_no_path(m, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
Alasdair G Kergon436d4102005-07-12 15:53:03 -07001087/*
1088 * Restore the queue_if_no_path setting.
1089 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090static void multipath_resume(struct dm_target *ti)
1091{
1092 struct multipath *m = (struct multipath *) ti->private;
1093 unsigned long flags;
1094
1095 spin_lock_irqsave(&m->lock, flags);
Alasdair G Kergon436d4102005-07-12 15:53:03 -07001096 m->queue_if_no_path = m->saved_queue_if_no_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 spin_unlock_irqrestore(&m->lock, flags);
1098}
1099
1100/*
1101 * Info output has the following format:
1102 * num_multipath_feature_args [multipath_feature_args]*
1103 * num_handler_status_args [handler_status_args]*
1104 * num_groups init_group_number
1105 * [A|D|E num_ps_status_args [ps_status_args]*
1106 * num_paths num_selector_args
1107 * [path_dev A|F fail_count [selector_args]* ]+ ]+
1108 *
1109 * Table output has the following format (identical to the constructor string):
1110 * num_feature_args [features_args]*
1111 * num_handler_args hw_handler [hw_handler_args]*
1112 * num_groups init_group_number
1113 * [priority selector-name num_ps_args [ps_args]*
1114 * num_paths num_selector_args [path_dev [selector_args]* ]+ ]+
1115 */
1116static int multipath_status(struct dm_target *ti, status_type_t type,
1117 char *result, unsigned int maxlen)
1118{
1119 int sz = 0;
1120 unsigned long flags;
1121 struct multipath *m = (struct multipath *) ti->private;
1122 struct hw_handler *hwh = &m->hw_handler;
1123 struct priority_group *pg;
1124 struct pgpath *p;
1125 unsigned pg_num;
1126 char state;
1127
1128 spin_lock_irqsave(&m->lock, flags);
1129
1130 /* Features */
1131 if (type == STATUSTYPE_INFO)
1132 DMEMIT("1 %u ", m->queue_size);
1133 else if (m->queue_if_no_path)
1134 DMEMIT("1 queue_if_no_path ");
1135 else
1136 DMEMIT("0 ");
1137
1138 if (hwh->type && hwh->type->status)
1139 sz += hwh->type->status(hwh, type, result + sz, maxlen - sz);
1140 else if (!hwh->type || type == STATUSTYPE_INFO)
1141 DMEMIT("0 ");
1142 else
1143 DMEMIT("1 %s ", hwh->type->name);
1144
1145 DMEMIT("%u ", m->nr_priority_groups);
1146
1147 if (m->next_pg)
1148 pg_num = m->next_pg->pg_num;
1149 else if (m->current_pg)
1150 pg_num = m->current_pg->pg_num;
1151 else
1152 pg_num = 1;
1153
1154 DMEMIT("%u ", pg_num);
1155
1156 switch (type) {
1157 case STATUSTYPE_INFO:
1158 list_for_each_entry(pg, &m->priority_groups, list) {
1159 if (pg->bypassed)
1160 state = 'D'; /* Disabled */
1161 else if (pg == m->current_pg)
1162 state = 'A'; /* Currently Active */
1163 else
1164 state = 'E'; /* Enabled */
1165
1166 DMEMIT("%c ", state);
1167
1168 if (pg->ps.type->status)
1169 sz += pg->ps.type->status(&pg->ps, NULL, type,
1170 result + sz,
1171 maxlen - sz);
1172 else
1173 DMEMIT("0 ");
1174
1175 DMEMIT("%u %u ", pg->nr_pgpaths,
1176 pg->ps.type->info_args);
1177
1178 list_for_each_entry(p, &pg->pgpaths, list) {
1179 DMEMIT("%s %s %u ", p->path.dev->name,
1180 p->path.is_active ? "A" : "F",
1181 p->fail_count);
1182 if (pg->ps.type->status)
1183 sz += pg->ps.type->status(&pg->ps,
1184 &p->path, type, result + sz,
1185 maxlen - sz);
1186 }
1187 }
1188 break;
1189
1190 case STATUSTYPE_TABLE:
1191 list_for_each_entry(pg, &m->priority_groups, list) {
1192 DMEMIT("%s ", pg->ps.type->name);
1193
1194 if (pg->ps.type->status)
1195 sz += pg->ps.type->status(&pg->ps, NULL, type,
1196 result + sz,
1197 maxlen - sz);
1198 else
1199 DMEMIT("0 ");
1200
1201 DMEMIT("%u %u ", pg->nr_pgpaths,
1202 pg->ps.type->table_args);
1203
1204 list_for_each_entry(p, &pg->pgpaths, list) {
1205 DMEMIT("%s ", p->path.dev->name);
1206 if (pg->ps.type->status)
1207 sz += pg->ps.type->status(&pg->ps,
1208 &p->path, type, result + sz,
1209 maxlen - sz);
1210 }
1211 }
1212 break;
1213 }
1214
1215 spin_unlock_irqrestore(&m->lock, flags);
1216
1217 return 0;
1218}
1219
1220static int multipath_message(struct dm_target *ti, unsigned argc, char **argv)
1221{
1222 int r;
1223 struct dm_dev *dev;
1224 struct multipath *m = (struct multipath *) ti->private;
1225 action_fn action;
1226
1227 if (argc == 1) {
1228 if (!strnicmp(argv[0], MESG_STR("queue_if_no_path")))
Alasdair G Kergon485ef692005-09-27 21:45:45 -07001229 return queue_if_no_path(m, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 else if (!strnicmp(argv[0], MESG_STR("fail_if_no_path")))
Alasdair G Kergon485ef692005-09-27 21:45:45 -07001231 return queue_if_no_path(m, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 }
1233
1234 if (argc != 2)
1235 goto error;
1236
1237 if (!strnicmp(argv[0], MESG_STR("disable_group")))
1238 return bypass_pg_num(m, argv[1], 1);
1239 else if (!strnicmp(argv[0], MESG_STR("enable_group")))
1240 return bypass_pg_num(m, argv[1], 0);
1241 else if (!strnicmp(argv[0], MESG_STR("switch_group")))
1242 return switch_pg_num(m, argv[1]);
1243 else if (!strnicmp(argv[0], MESG_STR("reinstate_path")))
1244 action = reinstate_path;
1245 else if (!strnicmp(argv[0], MESG_STR("fail_path")))
1246 action = fail_path;
1247 else
1248 goto error;
1249
1250 r = dm_get_device(ti, argv[1], ti->begin, ti->len,
1251 dm_table_get_mode(ti->table), &dev);
1252 if (r) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -07001253 DMWARN("message: error getting device %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 argv[1]);
1255 return -EINVAL;
1256 }
1257
1258 r = action_dev(m, dev, action);
1259
1260 dm_put_device(ti, dev);
1261
1262 return r;
1263
1264error:
1265 DMWARN("Unrecognised multipath message received.");
1266 return -EINVAL;
1267}
1268
Milan Broz9af4aa32006-10-03 01:15:20 -07001269static int multipath_ioctl(struct dm_target *ti, struct inode *inode,
1270 struct file *filp, unsigned int cmd,
1271 unsigned long arg)
1272{
1273 struct multipath *m = (struct multipath *) ti->private;
1274 struct block_device *bdev = NULL;
1275 unsigned long flags;
Milan Broze90dae12006-10-03 01:15:22 -07001276 struct file fake_file = {};
1277 struct dentry fake_dentry = {};
Milan Broz9af4aa32006-10-03 01:15:20 -07001278 int r = 0;
1279
Milan Broze90dae12006-10-03 01:15:22 -07001280 fake_file.f_dentry = &fake_dentry;
1281
Milan Broz9af4aa32006-10-03 01:15:20 -07001282 spin_lock_irqsave(&m->lock, flags);
1283
1284 if (!m->current_pgpath)
1285 __choose_pgpath(m);
1286
Milan Broze90dae12006-10-03 01:15:22 -07001287 if (m->current_pgpath) {
Milan Broz9af4aa32006-10-03 01:15:20 -07001288 bdev = m->current_pgpath->path.dev->bdev;
Milan Broze90dae12006-10-03 01:15:22 -07001289 fake_dentry.d_inode = bdev->bd_inode;
1290 fake_file.f_mode = m->current_pgpath->path.dev->mode;
1291 }
Milan Broz9af4aa32006-10-03 01:15:20 -07001292
1293 if (m->queue_io)
1294 r = -EAGAIN;
1295 else if (!bdev)
1296 r = -EIO;
1297
1298 spin_unlock_irqrestore(&m->lock, flags);
1299
Milan Broze90dae12006-10-03 01:15:22 -07001300 return r ? : blkdev_driver_ioctl(bdev->bd_inode, &fake_file,
1301 bdev->bd_disk, cmd, arg);
Milan Broz9af4aa32006-10-03 01:15:20 -07001302}
1303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304/*-----------------------------------------------------------------
1305 * Module setup
1306 *---------------------------------------------------------------*/
1307static struct target_type multipath_target = {
1308 .name = "multipath",
Milan Broz9af4aa32006-10-03 01:15:20 -07001309 .version = {1, 0, 5},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 .module = THIS_MODULE,
1311 .ctr = multipath_ctr,
1312 .dtr = multipath_dtr,
1313 .map = multipath_map,
1314 .end_io = multipath_end_io,
1315 .presuspend = multipath_presuspend,
1316 .resume = multipath_resume,
1317 .status = multipath_status,
1318 .message = multipath_message,
Milan Broz9af4aa32006-10-03 01:15:20 -07001319 .ioctl = multipath_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320};
1321
1322static int __init dm_multipath_init(void)
1323{
1324 int r;
1325
1326 /* allocate a slab for the dm_ios */
1327 _mpio_cache = kmem_cache_create("dm_mpath", sizeof(struct mpath_io),
1328 0, 0, NULL, NULL);
1329 if (!_mpio_cache)
1330 return -ENOMEM;
1331
1332 r = dm_register_target(&multipath_target);
1333 if (r < 0) {
1334 DMERR("%s: register failed %d", multipath_target.name, r);
1335 kmem_cache_destroy(_mpio_cache);
1336 return -EINVAL;
1337 }
1338
Alasdair G Kergonc5573082005-05-05 16:16:07 -07001339 kmultipathd = create_workqueue("kmpathd");
1340 if (!kmultipathd) {
1341 DMERR("%s: failed to create workqueue kmpathd",
1342 multipath_target.name);
1343 dm_unregister_target(&multipath_target);
1344 kmem_cache_destroy(_mpio_cache);
1345 return -ENOMEM;
1346 }
1347
Alasdair G Kergon72d94862006-06-26 00:27:35 -07001348 DMINFO("version %u.%u.%u loaded",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 multipath_target.version[0], multipath_target.version[1],
1350 multipath_target.version[2]);
1351
1352 return r;
1353}
1354
1355static void __exit dm_multipath_exit(void)
1356{
1357 int r;
1358
Alasdair G Kergonc5573082005-05-05 16:16:07 -07001359 destroy_workqueue(kmultipathd);
1360
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 r = dm_unregister_target(&multipath_target);
1362 if (r < 0)
1363 DMERR("%s: target unregister failed %d",
1364 multipath_target.name, r);
1365 kmem_cache_destroy(_mpio_cache);
1366}
1367
1368EXPORT_SYMBOL_GPL(dm_pg_init_complete);
1369
1370module_init(dm_multipath_init);
1371module_exit(dm_multipath_exit);
1372
1373MODULE_DESCRIPTION(DM_NAME " multipath target");
1374MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>");
1375MODULE_LICENSE("GPL");