2 * Copyright (C) 2003 Sistina Software Limited.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * This file is released under the GPL.
9 #include "dm-path-selector.h"
10 #include "dm-hw-handler.h"
11 #include "dm-bio-list.h"
12 #include "dm-bio-record.h"
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>
24 #define MESG_STR(x) x, sizeof(x)
28 struct list_head list;
30 struct priority_group *pg; /* Owning PG */
31 unsigned fail_count; /* Cumulative failure count */
36 #define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path)
39 * Paths are grouped into Priority Groups and numbered from 1 upwards.
40 * Each has a path selector which controls which path gets used.
42 struct priority_group {
43 struct list_head list;
45 struct multipath *m; /* Owning multipath instance */
46 struct path_selector ps;
48 unsigned pg_num; /* Reference number */
49 unsigned bypassed; /* Temporarily bypass this PG? */
51 unsigned nr_pgpaths; /* Number of paths in PG */
52 struct list_head pgpaths;
55 /* Multipath context */
57 struct list_head list;
62 struct hw_handler hw_handler;
63 unsigned nr_priority_groups;
64 struct list_head priority_groups;
65 unsigned pg_init_required; /* pg_init needs calling? */
67 unsigned nr_valid_paths; /* Total number of usable paths */
68 struct pgpath *current_pgpath;
69 struct priority_group *current_pg;
70 struct priority_group *next_pg; /* Switch to this PG if set */
71 unsigned repeat_count; /* I/Os left before calling PS again */
73 unsigned queue_io; /* Must we queue all I/O? */
74 unsigned queue_if_no_path; /* Queue I/O if last path fails? */
75 unsigned suspended; /* Has dm core suspended our I/O? */
77 struct work_struct process_queued_ios;
78 struct bio_list queued_ios;
81 struct work_struct trigger_event;
84 * We must use a mempool of mpath_io structs so that we
85 * can resubmit bios on error.
91 * Context information attached to each bio we process.
94 struct pgpath *pgpath;
95 struct dm_bio_details details;
98 typedef int (*action_fn) (struct pgpath *pgpath);
100 #define MIN_IOS 256 /* Mempool size */
102 static kmem_cache_t *_mpio_cache;
104 static void process_queued_ios(void *data);
105 static void trigger_event(void *data);
108 /*-----------------------------------------------
109 * Allocation routines
110 *-----------------------------------------------*/
112 static struct pgpath *alloc_pgpath(void)
114 struct pgpath *pgpath = kmalloc(sizeof(*pgpath), GFP_KERNEL);
117 memset(pgpath, 0, sizeof(*pgpath));
118 pgpath->path.is_active = 1;
124 static inline void free_pgpath(struct pgpath *pgpath)
129 static struct priority_group *alloc_priority_group(void)
131 struct priority_group *pg;
133 pg = kmalloc(sizeof(*pg), GFP_KERNEL);
137 memset(pg, 0, sizeof(*pg));
138 INIT_LIST_HEAD(&pg->pgpaths);
143 static void free_pgpaths(struct list_head *pgpaths, struct dm_target *ti)
145 struct pgpath *pgpath, *tmp;
147 list_for_each_entry_safe(pgpath, tmp, pgpaths, list) {
148 list_del(&pgpath->list);
149 dm_put_device(ti, pgpath->path.dev);
154 static void free_priority_group(struct priority_group *pg,
155 struct dm_target *ti)
157 struct path_selector *ps = &pg->ps;
160 ps->type->destroy(ps);
161 dm_put_path_selector(ps->type);
164 free_pgpaths(&pg->pgpaths, ti);
168 static struct multipath *alloc_multipath(void)
172 m = kmalloc(sizeof(*m), GFP_KERNEL);
174 memset(m, 0, sizeof(*m));
175 INIT_LIST_HEAD(&m->priority_groups);
176 spin_lock_init(&m->lock);
178 INIT_WORK(&m->process_queued_ios, process_queued_ios, m);
179 INIT_WORK(&m->trigger_event, trigger_event, m);
180 m->mpio_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
181 mempool_free_slab, _mpio_cache);
191 static void free_multipath(struct multipath *m)
193 struct priority_group *pg, *tmp;
194 struct hw_handler *hwh = &m->hw_handler;
196 list_for_each_entry_safe(pg, tmp, &m->priority_groups, list) {
198 free_priority_group(pg, m->ti);
202 hwh->type->destroy(hwh);
203 dm_put_hw_handler(hwh->type);
206 mempool_destroy(m->mpio_pool);
211 /*-----------------------------------------------
213 *-----------------------------------------------*/
215 static void __switch_pg(struct multipath *m, struct pgpath *pgpath)
217 struct hw_handler *hwh = &m->hw_handler;
219 m->current_pg = pgpath->pg;
221 /* Must we initialise the PG first, and queue I/O till it's ready? */
222 if (hwh->type && hwh->type->pg_init) {
223 m->pg_init_required = 1;
226 m->pg_init_required = 0;
231 static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg)
235 path = pg->ps.type->select_path(&pg->ps, &m->repeat_count);
239 m->current_pgpath = path_to_pgpath(path);
241 if (m->current_pg != pg)
242 __switch_pg(m, m->current_pgpath);
247 static void __choose_pgpath(struct multipath *m)
249 struct priority_group *pg;
250 unsigned bypassed = 1;
252 if (!m->nr_valid_paths)
255 /* Were we instructed to switch PG? */
259 if (!__choose_path_in_pg(m, pg))
263 /* Don't change PG until it has no remaining paths */
264 if (m->current_pg && !__choose_path_in_pg(m, m->current_pg))
268 * Loop through priority groups until we find a valid path.
269 * First time we skip PGs marked 'bypassed'.
270 * Second time we only try the ones we skipped.
273 list_for_each_entry(pg, &m->priority_groups, list) {
274 if (pg->bypassed == bypassed)
276 if (!__choose_path_in_pg(m, pg))
279 } while (bypassed--);
282 m->current_pgpath = NULL;
283 m->current_pg = NULL;
286 static int map_io(struct multipath *m, struct bio *bio, struct mpath_io *mpio,
291 struct pgpath *pgpath;
293 spin_lock_irqsave(&m->lock, flags);
295 /* Do we need to select a new pgpath? */
296 if (!m->current_pgpath ||
297 (!m->queue_io && (m->repeat_count && --m->repeat_count == 0)))
300 pgpath = m->current_pgpath;
305 if ((pgpath && m->queue_io) ||
306 (!pgpath && m->queue_if_no_path && !m->suspended)) {
307 /* Queue for the daemon to resubmit */
308 bio_list_add(&m->queued_ios, bio);
310 if (m->pg_init_required || !m->queue_io)
311 schedule_work(&m->process_queued_ios);
315 r = -EIO; /* Failed */
317 bio->bi_bdev = pgpath->path.dev->bdev;
319 mpio->pgpath = pgpath;
321 spin_unlock_irqrestore(&m->lock, flags);
327 * If we run out of usable paths, should we queue I/O or error it?
329 static int queue_if_no_path(struct multipath *m, unsigned queue_if_no_path)
333 spin_lock_irqsave(&m->lock, flags);
335 m->queue_if_no_path = queue_if_no_path;
336 if (!m->queue_if_no_path)
337 schedule_work(&m->process_queued_ios);
339 spin_unlock_irqrestore(&m->lock, flags);
344 /*-----------------------------------------------------------------
345 * The multipath daemon is responsible for resubmitting queued ios.
346 *---------------------------------------------------------------*/
348 static void dispatch_queued_ios(struct multipath *m)
352 struct bio *bio = NULL, *next;
353 struct mpath_io *mpio;
354 union map_info *info;
356 spin_lock_irqsave(&m->lock, flags);
357 bio = bio_list_get(&m->queued_ios);
358 spin_unlock_irqrestore(&m->lock, flags);
364 info = dm_get_mapinfo(bio);
367 r = map_io(m, bio, mpio, 1);
369 bio_endio(bio, bio->bi_size, r);
371 generic_make_request(bio);
377 static void process_queued_ios(void *data)
379 struct multipath *m = (struct multipath *) data;
380 struct hw_handler *hwh = &m->hw_handler;
381 struct pgpath *pgpath;
382 unsigned init_required, must_queue = 0;
385 spin_lock_irqsave(&m->lock, flags);
387 if (!m->current_pgpath)
390 pgpath = m->current_pgpath;
392 if ((pgpath && m->queue_io) ||
393 (!pgpath && m->queue_if_no_path && !m->suspended))
396 init_required = m->pg_init_required;
398 m->pg_init_required = 0;
400 spin_unlock_irqrestore(&m->lock, flags);
403 hwh->type->pg_init(hwh, pgpath->pg->bypassed, &pgpath->path);
406 dispatch_queued_ios(m);
410 * An event is triggered whenever a path is taken out of use.
411 * Includes path failure and PG bypass.
413 static void trigger_event(void *data)
415 struct multipath *m = (struct multipath *) data;
417 dm_table_event(m->ti->table);
420 /*-----------------------------------------------------------------
421 * Constructor/argument parsing:
422 * <#multipath feature args> [<arg>]*
423 * <#hw_handler args> [hw_handler [<arg>]*]
425 * <initial priority group>
426 * [<selector> <#selector args> [<arg>]*
427 * <#paths> <#per-path selector args>
428 * [<path> [<arg>]* ]+ ]+
429 *---------------------------------------------------------------*/
436 #define ESTR(s) ("dm-multipath: " s)
438 static int read_param(struct param *param, char *str, unsigned *v, char **error)
441 (sscanf(str, "%u", v) != 1) ||
444 *error = param->error;
456 static char *shift(struct arg_set *as)
470 static void consume(struct arg_set *as, unsigned n)
472 BUG_ON (as->argc < n);
477 static int parse_path_selector(struct arg_set *as, struct priority_group *pg,
478 struct dm_target *ti)
481 struct path_selector_type *pst;
484 static struct param _params[] = {
485 {0, 1024, ESTR("invalid number of path selector args")},
488 pst = dm_get_path_selector(shift(as));
490 ti->error = ESTR("unknown path selector type");
494 r = read_param(_params, shift(as), &ps_argc, &ti->error);
498 r = pst->create(&pg->ps, ps_argc, as->argv);
500 dm_put_path_selector(pst);
501 ti->error = ESTR("path selector constructor failed");
506 consume(as, ps_argc);
511 static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps,
512 struct dm_target *ti)
517 /* we need at least a path arg */
519 ti->error = ESTR("no device given");
527 r = dm_get_device(ti, shift(as), ti->begin, ti->len,
528 dm_table_get_mode(ti->table), &p->path.dev);
530 ti->error = ESTR("error getting device");
534 r = ps->type->add_path(ps, &p->path, as->argc, as->argv, &ti->error);
536 dm_put_device(ti, p->path.dev);
547 static struct priority_group *parse_priority_group(struct arg_set *as,
549 struct dm_target *ti)
551 static struct param _params[] = {
552 {1, 1024, ESTR("invalid number of paths")},
553 {0, 1024, ESTR("invalid number of selector args")}
557 unsigned i, nr_selector_args, nr_params;
558 struct priority_group *pg;
562 ti->error = ESTR("not enough priority group aruments");
566 pg = alloc_priority_group();
568 ti->error = ESTR("couldn't allocate priority group");
573 r = parse_path_selector(as, pg, ti);
580 r = read_param(_params, shift(as), &pg->nr_pgpaths, &ti->error);
584 r = read_param(_params + 1, shift(as), &nr_selector_args, &ti->error);
588 nr_params = 1 + nr_selector_args;
589 for (i = 0; i < pg->nr_pgpaths; i++) {
590 struct pgpath *pgpath;
591 struct arg_set path_args;
593 if (as->argc < nr_params)
596 path_args.argc = nr_params;
597 path_args.argv = as->argv;
599 pgpath = parse_path(&path_args, &pg->ps, ti);
604 list_add_tail(&pgpath->list, &pg->pgpaths);
605 consume(as, nr_params);
611 free_priority_group(pg, ti);
615 static int parse_hw_handler(struct arg_set *as, struct multipath *m,
616 struct dm_target *ti)
619 struct hw_handler_type *hwht;
622 static struct param _params[] = {
623 {0, 1024, ESTR("invalid number of hardware handler args")},
626 r = read_param(_params, shift(as), &hw_argc, &ti->error);
633 hwht = dm_get_hw_handler(shift(as));
635 ti->error = ESTR("unknown hardware handler type");
639 r = hwht->create(&m->hw_handler, hw_argc - 1, as->argv);
641 dm_put_hw_handler(hwht);
642 ti->error = ESTR("hardware handler constructor failed");
646 m->hw_handler.type = hwht;
647 consume(as, hw_argc - 1);
652 static int parse_features(struct arg_set *as, struct multipath *m,
653 struct dm_target *ti)
658 static struct param _params[] = {
659 {0, 1, ESTR("invalid number of feature args")},
662 r = read_param(_params, shift(as), &argc, &ti->error);
669 if (!strnicmp(shift(as), MESG_STR("queue_if_no_path")))
670 return queue_if_no_path(m, 1);
672 ti->error = "Unrecognised multipath feature request";
677 static int multipath_ctr(struct dm_target *ti, unsigned int argc,
680 /* target parameters */
681 static struct param _params[] = {
682 {1, 1024, ESTR("invalid number of priority groups")},
683 {1, 1024, ESTR("invalid initial priority group number")},
689 unsigned pg_count = 0;
690 unsigned next_pg_num;
695 m = alloc_multipath();
697 ti->error = ESTR("can't allocate multipath");
701 r = parse_features(&as, m, ti);
705 r = parse_hw_handler(&as, m, ti);
709 r = read_param(_params, shift(&as), &m->nr_priority_groups, &ti->error);
713 r = read_param(_params + 1, shift(&as), &next_pg_num, &ti->error);
717 /* parse the priority groups */
719 struct priority_group *pg;
721 pg = parse_priority_group(&as, m, ti);
727 m->nr_valid_paths += pg->nr_pgpaths;
728 list_add_tail(&pg->list, &m->priority_groups);
730 pg->pg_num = pg_count;
735 if (pg_count != m->nr_priority_groups) {
736 ti->error = ESTR("priority group count mismatch");
751 static void multipath_dtr(struct dm_target *ti)
753 struct multipath *m = (struct multipath *) ti->private;
758 * Map bios, recording original fields for later in case we have to resubmit
760 static int multipath_map(struct dm_target *ti, struct bio *bio,
761 union map_info *map_context)
764 struct mpath_io *mpio;
765 struct multipath *m = (struct multipath *) ti->private;
767 mpio = mempool_alloc(m->mpio_pool, GFP_NOIO);
768 dm_bio_record(&mpio->details, bio);
770 map_context->ptr = mpio;
771 bio->bi_rw |= (1 << BIO_RW_FAILFAST);
772 r = map_io(m, bio, mpio, 0);
774 mempool_free(mpio, m->mpio_pool);
780 * Take a path out of use.
782 static int fail_path(struct pgpath *pgpath)
785 struct multipath *m = pgpath->pg->m;
787 spin_lock_irqsave(&m->lock, flags);
789 if (!pgpath->path.is_active)
792 DMWARN("dm-multipath: Failing path %s.", pgpath->path.dev->name);
794 pgpath->pg->ps.type->fail_path(&pgpath->pg->ps, &pgpath->path);
795 pgpath->path.is_active = 0;
796 pgpath->fail_count++;
800 if (pgpath == m->current_pgpath)
801 m->current_pgpath = NULL;
803 schedule_work(&m->trigger_event);
806 spin_unlock_irqrestore(&m->lock, flags);
812 * Reinstate a previously-failed path
814 static int reinstate_path(struct pgpath *pgpath)
818 struct multipath *m = pgpath->pg->m;
820 spin_lock_irqsave(&m->lock, flags);
822 if (pgpath->path.is_active)
825 if (!pgpath->pg->ps.type) {
826 DMWARN("Reinstate path not supported by path selector %s",
827 pgpath->pg->ps.type->name);
832 r = pgpath->pg->ps.type->reinstate_path(&pgpath->pg->ps, &pgpath->path);
836 pgpath->path.is_active = 1;
838 m->current_pgpath = NULL;
839 if (!m->nr_valid_paths++)
840 schedule_work(&m->process_queued_ios);
842 schedule_work(&m->trigger_event);
845 spin_unlock_irqrestore(&m->lock, flags);
851 * Fail or reinstate all paths that match the provided struct dm_dev.
853 static int action_dev(struct multipath *m, struct dm_dev *dev,
857 struct pgpath *pgpath;
858 struct priority_group *pg;
860 list_for_each_entry(pg, &m->priority_groups, list) {
861 list_for_each_entry(pgpath, &pg->pgpaths, list) {
862 if (pgpath->path.dev == dev)
871 * Temporarily try to avoid having to use the specified PG
873 static void bypass_pg(struct multipath *m, struct priority_group *pg,
878 spin_lock_irqsave(&m->lock, flags);
880 pg->bypassed = bypassed;
881 m->current_pgpath = NULL;
882 m->current_pg = NULL;
884 spin_unlock_irqrestore(&m->lock, flags);
886 schedule_work(&m->trigger_event);
890 * Switch to using the specified PG from the next I/O that gets mapped
892 static int switch_pg_num(struct multipath *m, const char *pgstr)
894 struct priority_group *pg;
898 if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum ||
899 (pgnum > m->nr_priority_groups)) {
900 DMWARN("invalid PG number supplied to switch_pg_num");
904 spin_lock_irqsave(&m->lock, flags);
905 list_for_each_entry(pg, &m->priority_groups, list) {
910 m->current_pgpath = NULL;
911 m->current_pg = NULL;
914 spin_unlock_irqrestore(&m->lock, flags);
916 schedule_work(&m->trigger_event);
921 * Set/clear bypassed status of a PG.
922 * PGs are numbered upwards from 1 in the order they were declared.
924 static int bypass_pg_num(struct multipath *m, const char *pgstr, int bypassed)
926 struct priority_group *pg;
929 if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum ||
930 (pgnum > m->nr_priority_groups)) {
931 DMWARN("invalid PG number supplied to bypass_pg");
935 list_for_each_entry(pg, &m->priority_groups, list) {
940 bypass_pg(m, pg, bypassed);
945 * pg_init must call this when it has completed its initialisation
947 void dm_pg_init_complete(struct path *path, unsigned err_flags)
949 struct pgpath *pgpath = path_to_pgpath(path);
950 struct priority_group *pg = pgpath->pg;
951 struct multipath *m = pg->m;
954 /* We insist on failing the path if the PG is already bypassed. */
955 if (err_flags && pg->bypassed)
956 err_flags |= MP_FAIL_PATH;
958 if (err_flags & MP_FAIL_PATH)
961 if (err_flags & MP_BYPASS_PG)
964 spin_lock_irqsave(&m->lock, flags);
968 m->current_pgpath = NULL;
969 m->current_pg = NULL;
971 schedule_work(&m->process_queued_ios);
972 spin_unlock_irqrestore(&m->lock, flags);
978 static int do_end_io(struct multipath *m, struct bio *bio,
979 int error, struct mpath_io *mpio)
981 struct hw_handler *hwh = &m->hw_handler;
982 unsigned err_flags = MP_FAIL_PATH; /* Default behavior */
985 return 0; /* I/O complete */
988 if (!m->nr_valid_paths) {
989 if (!m->queue_if_no_path || m->suspended) {
990 spin_unlock(&m->lock);
993 spin_unlock(&m->lock);
997 spin_unlock(&m->lock);
999 if (hwh->type && hwh->type->error)
1000 err_flags = hwh->type->error(hwh, bio);
1003 if (err_flags & MP_FAIL_PATH)
1004 fail_path(mpio->pgpath);
1006 if (err_flags & MP_BYPASS_PG)
1007 bypass_pg(m, mpio->pgpath->pg, 1);
1010 if (err_flags & MP_ERROR_IO)
1014 dm_bio_restore(&mpio->details, bio);
1016 /* queue for the daemon to resubmit or fail */
1017 spin_lock(&m->lock);
1018 bio_list_add(&m->queued_ios, bio);
1021 schedule_work(&m->process_queued_ios);
1022 spin_unlock(&m->lock);
1024 return 1; /* io not complete */
1027 static int multipath_end_io(struct dm_target *ti, struct bio *bio,
1028 int error, union map_info *map_context)
1030 struct multipath *m = (struct multipath *) ti->private;
1031 struct mpath_io *mpio = (struct mpath_io *) map_context->ptr;
1032 struct pgpath *pgpath = mpio->pgpath;
1033 struct path_selector *ps;
1036 r = do_end_io(m, bio, error, mpio);
1038 ps = &pgpath->pg->ps;
1039 if (ps->type->end_io)
1040 ps->type->end_io(ps, &pgpath->path);
1043 mempool_free(mpio, m->mpio_pool);
1049 * Suspend can't complete until all the I/O is processed so if
1050 * the last path failed we will now error any queued I/O.
1052 static void multipath_presuspend(struct dm_target *ti)
1054 struct multipath *m = (struct multipath *) ti->private;
1055 unsigned long flags;
1057 spin_lock_irqsave(&m->lock, flags);
1059 if (m->queue_if_no_path)
1060 schedule_work(&m->process_queued_ios);
1061 spin_unlock_irqrestore(&m->lock, flags);
1064 static void multipath_resume(struct dm_target *ti)
1066 struct multipath *m = (struct multipath *) ti->private;
1067 unsigned long flags;
1069 spin_lock_irqsave(&m->lock, flags);
1071 spin_unlock_irqrestore(&m->lock, flags);
1075 * Info output has the following format:
1076 * num_multipath_feature_args [multipath_feature_args]*
1077 * num_handler_status_args [handler_status_args]*
1078 * num_groups init_group_number
1079 * [A|D|E num_ps_status_args [ps_status_args]*
1080 * num_paths num_selector_args
1081 * [path_dev A|F fail_count [selector_args]* ]+ ]+
1083 * Table output has the following format (identical to the constructor string):
1084 * num_feature_args [features_args]*
1085 * num_handler_args hw_handler [hw_handler_args]*
1086 * num_groups init_group_number
1087 * [priority selector-name num_ps_args [ps_args]*
1088 * num_paths num_selector_args [path_dev [selector_args]* ]+ ]+
1090 static int multipath_status(struct dm_target *ti, status_type_t type,
1091 char *result, unsigned int maxlen)
1094 unsigned long flags;
1095 struct multipath *m = (struct multipath *) ti->private;
1096 struct hw_handler *hwh = &m->hw_handler;
1097 struct priority_group *pg;
1102 spin_lock_irqsave(&m->lock, flags);
1105 if (type == STATUSTYPE_INFO)
1106 DMEMIT("1 %u ", m->queue_size);
1107 else if (m->queue_if_no_path)
1108 DMEMIT("1 queue_if_no_path ");
1112 if (hwh->type && hwh->type->status)
1113 sz += hwh->type->status(hwh, type, result + sz, maxlen - sz);
1114 else if (!hwh->type || type == STATUSTYPE_INFO)
1117 DMEMIT("1 %s ", hwh->type->name);
1119 DMEMIT("%u ", m->nr_priority_groups);
1122 pg_num = m->next_pg->pg_num;
1123 else if (m->current_pg)
1124 pg_num = m->current_pg->pg_num;
1128 DMEMIT("%u ", pg_num);
1131 case STATUSTYPE_INFO:
1132 list_for_each_entry(pg, &m->priority_groups, list) {
1134 state = 'D'; /* Disabled */
1135 else if (pg == m->current_pg)
1136 state = 'A'; /* Currently Active */
1138 state = 'E'; /* Enabled */
1140 DMEMIT("%c ", state);
1142 if (pg->ps.type->status)
1143 sz += pg->ps.type->status(&pg->ps, NULL, type,
1149 DMEMIT("%u %u ", pg->nr_pgpaths,
1150 pg->ps.type->info_args);
1152 list_for_each_entry(p, &pg->pgpaths, list) {
1153 DMEMIT("%s %s %u ", p->path.dev->name,
1154 p->path.is_active ? "A" : "F",
1156 if (pg->ps.type->status)
1157 sz += pg->ps.type->status(&pg->ps,
1158 &p->path, type, result + sz,
1164 case STATUSTYPE_TABLE:
1165 list_for_each_entry(pg, &m->priority_groups, list) {
1166 DMEMIT("%s ", pg->ps.type->name);
1168 if (pg->ps.type->status)
1169 sz += pg->ps.type->status(&pg->ps, NULL, type,
1175 DMEMIT("%u %u ", pg->nr_pgpaths,
1176 pg->ps.type->table_args);
1178 list_for_each_entry(p, &pg->pgpaths, list) {
1179 DMEMIT("%s ", p->path.dev->name);
1180 if (pg->ps.type->status)
1181 sz += pg->ps.type->status(&pg->ps,
1182 &p->path, type, result + sz,
1189 spin_unlock_irqrestore(&m->lock, flags);
1194 static int multipath_message(struct dm_target *ti, unsigned argc, char **argv)
1198 struct multipath *m = (struct multipath *) ti->private;
1202 if (!strnicmp(argv[0], MESG_STR("queue_if_no_path")))
1203 return queue_if_no_path(m, 1);
1204 else if (!strnicmp(argv[0], MESG_STR("fail_if_no_path")))
1205 return queue_if_no_path(m, 0);
1211 if (!strnicmp(argv[0], MESG_STR("disable_group")))
1212 return bypass_pg_num(m, argv[1], 1);
1213 else if (!strnicmp(argv[0], MESG_STR("enable_group")))
1214 return bypass_pg_num(m, argv[1], 0);
1215 else if (!strnicmp(argv[0], MESG_STR("switch_group")))
1216 return switch_pg_num(m, argv[1]);
1217 else if (!strnicmp(argv[0], MESG_STR("reinstate_path")))
1218 action = reinstate_path;
1219 else if (!strnicmp(argv[0], MESG_STR("fail_path")))
1224 r = dm_get_device(ti, argv[1], ti->begin, ti->len,
1225 dm_table_get_mode(ti->table), &dev);
1227 DMWARN("dm-multipath message: error getting device %s",
1232 r = action_dev(m, dev, action);
1234 dm_put_device(ti, dev);
1239 DMWARN("Unrecognised multipath message received.");
1243 /*-----------------------------------------------------------------
1245 *---------------------------------------------------------------*/
1246 static struct target_type multipath_target = {
1247 .name = "multipath",
1248 .version = {1, 0, 4},
1249 .module = THIS_MODULE,
1250 .ctr = multipath_ctr,
1251 .dtr = multipath_dtr,
1252 .map = multipath_map,
1253 .end_io = multipath_end_io,
1254 .presuspend = multipath_presuspend,
1255 .resume = multipath_resume,
1256 .status = multipath_status,
1257 .message = multipath_message,
1260 static int __init dm_multipath_init(void)
1264 /* allocate a slab for the dm_ios */
1265 _mpio_cache = kmem_cache_create("dm_mpath", sizeof(struct mpath_io),
1270 r = dm_register_target(&multipath_target);
1272 DMERR("%s: register failed %d", multipath_target.name, r);
1273 kmem_cache_destroy(_mpio_cache);
1277 DMINFO("dm-multipath version %u.%u.%u loaded",
1278 multipath_target.version[0], multipath_target.version[1],
1279 multipath_target.version[2]);
1284 static void __exit dm_multipath_exit(void)
1288 r = dm_unregister_target(&multipath_target);
1290 DMERR("%s: target unregister failed %d",
1291 multipath_target.name, r);
1292 kmem_cache_destroy(_mpio_cache);
1295 EXPORT_SYMBOL_GPL(dm_pg_init_complete);
1297 module_init(dm_multipath_init);
1298 module_exit(dm_multipath_exit);
1300 MODULE_DESCRIPTION(DM_NAME " multipath target");
1301 MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>");
1302 MODULE_LICENSE("GPL");