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 struct workqueue_struct
*kmultipathd
;
105 static void process_queued_ios(void *data
);
106 static void trigger_event(void *data
);
109 /*-----------------------------------------------
110 * Allocation routines
111 *-----------------------------------------------*/
113 static struct pgpath
*alloc_pgpath(void)
115 struct pgpath
*pgpath
= kmalloc(sizeof(*pgpath
), GFP_KERNEL
);
118 memset(pgpath
, 0, sizeof(*pgpath
));
119 pgpath
->path
.is_active
= 1;
125 static inline void free_pgpath(struct pgpath
*pgpath
)
130 static struct priority_group
*alloc_priority_group(void)
132 struct priority_group
*pg
;
134 pg
= kmalloc(sizeof(*pg
), GFP_KERNEL
);
138 memset(pg
, 0, sizeof(*pg
));
139 INIT_LIST_HEAD(&pg
->pgpaths
);
144 static void free_pgpaths(struct list_head
*pgpaths
, struct dm_target
*ti
)
146 struct pgpath
*pgpath
, *tmp
;
148 list_for_each_entry_safe(pgpath
, tmp
, pgpaths
, list
) {
149 list_del(&pgpath
->list
);
150 dm_put_device(ti
, pgpath
->path
.dev
);
155 static void free_priority_group(struct priority_group
*pg
,
156 struct dm_target
*ti
)
158 struct path_selector
*ps
= &pg
->ps
;
161 ps
->type
->destroy(ps
);
162 dm_put_path_selector(ps
->type
);
165 free_pgpaths(&pg
->pgpaths
, ti
);
169 static struct multipath
*alloc_multipath(void)
173 m
= kmalloc(sizeof(*m
), GFP_KERNEL
);
175 memset(m
, 0, sizeof(*m
));
176 INIT_LIST_HEAD(&m
->priority_groups
);
177 spin_lock_init(&m
->lock
);
179 INIT_WORK(&m
->process_queued_ios
, process_queued_ios
, m
);
180 INIT_WORK(&m
->trigger_event
, trigger_event
, m
);
181 m
->mpio_pool
= mempool_create(MIN_IOS
, mempool_alloc_slab
,
182 mempool_free_slab
, _mpio_cache
);
192 static void free_multipath(struct multipath
*m
)
194 struct priority_group
*pg
, *tmp
;
195 struct hw_handler
*hwh
= &m
->hw_handler
;
197 list_for_each_entry_safe(pg
, tmp
, &m
->priority_groups
, list
) {
199 free_priority_group(pg
, m
->ti
);
203 hwh
->type
->destroy(hwh
);
204 dm_put_hw_handler(hwh
->type
);
207 mempool_destroy(m
->mpio_pool
);
212 /*-----------------------------------------------
214 *-----------------------------------------------*/
216 static void __switch_pg(struct multipath
*m
, struct pgpath
*pgpath
)
218 struct hw_handler
*hwh
= &m
->hw_handler
;
220 m
->current_pg
= pgpath
->pg
;
222 /* Must we initialise the PG first, and queue I/O till it's ready? */
223 if (hwh
->type
&& hwh
->type
->pg_init
) {
224 m
->pg_init_required
= 1;
227 m
->pg_init_required
= 0;
232 static int __choose_path_in_pg(struct multipath
*m
, struct priority_group
*pg
)
236 path
= pg
->ps
.type
->select_path(&pg
->ps
, &m
->repeat_count
);
240 m
->current_pgpath
= path_to_pgpath(path
);
242 if (m
->current_pg
!= pg
)
243 __switch_pg(m
, m
->current_pgpath
);
248 static void __choose_pgpath(struct multipath
*m
)
250 struct priority_group
*pg
;
251 unsigned bypassed
= 1;
253 if (!m
->nr_valid_paths
)
256 /* Were we instructed to switch PG? */
260 if (!__choose_path_in_pg(m
, pg
))
264 /* Don't change PG until it has no remaining paths */
265 if (m
->current_pg
&& !__choose_path_in_pg(m
, m
->current_pg
))
269 * Loop through priority groups until we find a valid path.
270 * First time we skip PGs marked 'bypassed'.
271 * Second time we only try the ones we skipped.
274 list_for_each_entry(pg
, &m
->priority_groups
, list
) {
275 if (pg
->bypassed
== bypassed
)
277 if (!__choose_path_in_pg(m
, pg
))
280 } while (bypassed
--);
283 m
->current_pgpath
= NULL
;
284 m
->current_pg
= NULL
;
287 static int map_io(struct multipath
*m
, struct bio
*bio
, struct mpath_io
*mpio
,
292 struct pgpath
*pgpath
;
294 spin_lock_irqsave(&m
->lock
, flags
);
296 /* Do we need to select a new pgpath? */
297 if (!m
->current_pgpath
||
298 (!m
->queue_io
&& (m
->repeat_count
&& --m
->repeat_count
== 0)))
301 pgpath
= m
->current_pgpath
;
306 if ((pgpath
&& m
->queue_io
) ||
307 (!pgpath
&& m
->queue_if_no_path
&& !m
->suspended
)) {
308 /* Queue for the daemon to resubmit */
309 bio_list_add(&m
->queued_ios
, bio
);
311 if (m
->pg_init_required
|| !m
->queue_io
)
312 queue_work(kmultipathd
, &m
->process_queued_ios
);
316 r
= -EIO
; /* Failed */
318 bio
->bi_bdev
= pgpath
->path
.dev
->bdev
;
320 mpio
->pgpath
= pgpath
;
322 spin_unlock_irqrestore(&m
->lock
, flags
);
328 * If we run out of usable paths, should we queue I/O or error it?
330 static int queue_if_no_path(struct multipath
*m
, unsigned queue_if_no_path
)
334 spin_lock_irqsave(&m
->lock
, flags
);
336 m
->queue_if_no_path
= queue_if_no_path
;
337 if (!m
->queue_if_no_path
)
338 queue_work(kmultipathd
, &m
->process_queued_ios
);
340 spin_unlock_irqrestore(&m
->lock
, flags
);
345 /*-----------------------------------------------------------------
346 * The multipath daemon is responsible for resubmitting queued ios.
347 *---------------------------------------------------------------*/
349 static void dispatch_queued_ios(struct multipath
*m
)
353 struct bio
*bio
= NULL
, *next
;
354 struct mpath_io
*mpio
;
355 union map_info
*info
;
357 spin_lock_irqsave(&m
->lock
, flags
);
358 bio
= bio_list_get(&m
->queued_ios
);
359 spin_unlock_irqrestore(&m
->lock
, flags
);
365 info
= dm_get_mapinfo(bio
);
368 r
= map_io(m
, bio
, mpio
, 1);
370 bio_endio(bio
, bio
->bi_size
, r
);
372 generic_make_request(bio
);
378 static void process_queued_ios(void *data
)
380 struct multipath
*m
= (struct multipath
*) data
;
381 struct hw_handler
*hwh
= &m
->hw_handler
;
382 struct pgpath
*pgpath
;
383 unsigned init_required
, must_queue
= 0;
386 spin_lock_irqsave(&m
->lock
, flags
);
388 if (!m
->current_pgpath
)
391 pgpath
= m
->current_pgpath
;
393 if ((pgpath
&& m
->queue_io
) ||
394 (!pgpath
&& m
->queue_if_no_path
&& !m
->suspended
))
397 init_required
= m
->pg_init_required
;
399 m
->pg_init_required
= 0;
401 spin_unlock_irqrestore(&m
->lock
, flags
);
404 hwh
->type
->pg_init(hwh
, pgpath
->pg
->bypassed
, &pgpath
->path
);
407 dispatch_queued_ios(m
);
411 * An event is triggered whenever a path is taken out of use.
412 * Includes path failure and PG bypass.
414 static void trigger_event(void *data
)
416 struct multipath
*m
= (struct multipath
*) data
;
418 dm_table_event(m
->ti
->table
);
421 /*-----------------------------------------------------------------
422 * Constructor/argument parsing:
423 * <#multipath feature args> [<arg>]*
424 * <#hw_handler args> [hw_handler [<arg>]*]
426 * <initial priority group>
427 * [<selector> <#selector args> [<arg>]*
428 * <#paths> <#per-path selector args>
429 * [<path> [<arg>]* ]+ ]+
430 *---------------------------------------------------------------*/
437 #define ESTR(s) ("dm-multipath: " s)
439 static int read_param(struct param
*param
, char *str
, unsigned *v
, char **error
)
442 (sscanf(str
, "%u", v
) != 1) ||
445 *error
= param
->error
;
457 static char *shift(struct arg_set
*as
)
471 static void consume(struct arg_set
*as
, unsigned n
)
473 BUG_ON (as
->argc
< n
);
478 static int parse_path_selector(struct arg_set
*as
, struct priority_group
*pg
,
479 struct dm_target
*ti
)
482 struct path_selector_type
*pst
;
485 static struct param _params
[] = {
486 {0, 1024, ESTR("invalid number of path selector args")},
489 pst
= dm_get_path_selector(shift(as
));
491 ti
->error
= ESTR("unknown path selector type");
495 r
= read_param(_params
, shift(as
), &ps_argc
, &ti
->error
);
499 r
= pst
->create(&pg
->ps
, ps_argc
, as
->argv
);
501 dm_put_path_selector(pst
);
502 ti
->error
= ESTR("path selector constructor failed");
507 consume(as
, ps_argc
);
512 static struct pgpath
*parse_path(struct arg_set
*as
, struct path_selector
*ps
,
513 struct dm_target
*ti
)
518 /* we need at least a path arg */
520 ti
->error
= ESTR("no device given");
528 r
= dm_get_device(ti
, shift(as
), ti
->begin
, ti
->len
,
529 dm_table_get_mode(ti
->table
), &p
->path
.dev
);
531 ti
->error
= ESTR("error getting device");
535 r
= ps
->type
->add_path(ps
, &p
->path
, as
->argc
, as
->argv
, &ti
->error
);
537 dm_put_device(ti
, p
->path
.dev
);
548 static struct priority_group
*parse_priority_group(struct arg_set
*as
,
550 struct dm_target
*ti
)
552 static struct param _params
[] = {
553 {1, 1024, ESTR("invalid number of paths")},
554 {0, 1024, ESTR("invalid number of selector args")}
558 unsigned i
, nr_selector_args
, nr_params
;
559 struct priority_group
*pg
;
563 ti
->error
= ESTR("not enough priority group aruments");
567 pg
= alloc_priority_group();
569 ti
->error
= ESTR("couldn't allocate priority group");
574 r
= parse_path_selector(as
, pg
, ti
);
581 r
= read_param(_params
, shift(as
), &pg
->nr_pgpaths
, &ti
->error
);
585 r
= read_param(_params
+ 1, shift(as
), &nr_selector_args
, &ti
->error
);
589 nr_params
= 1 + nr_selector_args
;
590 for (i
= 0; i
< pg
->nr_pgpaths
; i
++) {
591 struct pgpath
*pgpath
;
592 struct arg_set path_args
;
594 if (as
->argc
< nr_params
)
597 path_args
.argc
= nr_params
;
598 path_args
.argv
= as
->argv
;
600 pgpath
= parse_path(&path_args
, &pg
->ps
, ti
);
605 list_add_tail(&pgpath
->list
, &pg
->pgpaths
);
606 consume(as
, nr_params
);
612 free_priority_group(pg
, ti
);
616 static int parse_hw_handler(struct arg_set
*as
, struct multipath
*m
,
617 struct dm_target
*ti
)
620 struct hw_handler_type
*hwht
;
623 static struct param _params
[] = {
624 {0, 1024, ESTR("invalid number of hardware handler args")},
627 r
= read_param(_params
, shift(as
), &hw_argc
, &ti
->error
);
634 hwht
= dm_get_hw_handler(shift(as
));
636 ti
->error
= ESTR("unknown hardware handler type");
640 r
= hwht
->create(&m
->hw_handler
, hw_argc
- 1, as
->argv
);
642 dm_put_hw_handler(hwht
);
643 ti
->error
= ESTR("hardware handler constructor failed");
647 m
->hw_handler
.type
= hwht
;
648 consume(as
, hw_argc
- 1);
653 static int parse_features(struct arg_set
*as
, struct multipath
*m
,
654 struct dm_target
*ti
)
659 static struct param _params
[] = {
660 {0, 1, ESTR("invalid number of feature args")},
663 r
= read_param(_params
, shift(as
), &argc
, &ti
->error
);
670 if (!strnicmp(shift(as
), MESG_STR("queue_if_no_path")))
671 return queue_if_no_path(m
, 1);
673 ti
->error
= "Unrecognised multipath feature request";
678 static int multipath_ctr(struct dm_target
*ti
, unsigned int argc
,
681 /* target parameters */
682 static struct param _params
[] = {
683 {1, 1024, ESTR("invalid number of priority groups")},
684 {1, 1024, ESTR("invalid initial priority group number")},
690 unsigned pg_count
= 0;
691 unsigned next_pg_num
;
696 m
= alloc_multipath();
698 ti
->error
= ESTR("can't allocate multipath");
702 r
= parse_features(&as
, m
, ti
);
706 r
= parse_hw_handler(&as
, m
, ti
);
710 r
= read_param(_params
, shift(&as
), &m
->nr_priority_groups
, &ti
->error
);
714 r
= read_param(_params
+ 1, shift(&as
), &next_pg_num
, &ti
->error
);
718 /* parse the priority groups */
720 struct priority_group
*pg
;
722 pg
= parse_priority_group(&as
, m
, ti
);
728 m
->nr_valid_paths
+= pg
->nr_pgpaths
;
729 list_add_tail(&pg
->list
, &m
->priority_groups
);
731 pg
->pg_num
= pg_count
;
736 if (pg_count
!= m
->nr_priority_groups
) {
737 ti
->error
= ESTR("priority group count mismatch");
752 static void multipath_dtr(struct dm_target
*ti
)
754 struct multipath
*m
= (struct multipath
*) ti
->private;
759 * Map bios, recording original fields for later in case we have to resubmit
761 static int multipath_map(struct dm_target
*ti
, struct bio
*bio
,
762 union map_info
*map_context
)
765 struct mpath_io
*mpio
;
766 struct multipath
*m
= (struct multipath
*) ti
->private;
768 if (bio_barrier(bio
))
771 mpio
= mempool_alloc(m
->mpio_pool
, GFP_NOIO
);
772 dm_bio_record(&mpio
->details
, bio
);
774 map_context
->ptr
= mpio
;
775 bio
->bi_rw
|= (1 << BIO_RW_FAILFAST
);
776 r
= map_io(m
, bio
, mpio
, 0);
778 mempool_free(mpio
, m
->mpio_pool
);
784 * Take a path out of use.
786 static int fail_path(struct pgpath
*pgpath
)
789 struct multipath
*m
= pgpath
->pg
->m
;
791 spin_lock_irqsave(&m
->lock
, flags
);
793 if (!pgpath
->path
.is_active
)
796 DMWARN("dm-multipath: Failing path %s.", pgpath
->path
.dev
->name
);
798 pgpath
->pg
->ps
.type
->fail_path(&pgpath
->pg
->ps
, &pgpath
->path
);
799 pgpath
->path
.is_active
= 0;
800 pgpath
->fail_count
++;
804 if (pgpath
== m
->current_pgpath
)
805 m
->current_pgpath
= NULL
;
807 queue_work(kmultipathd
, &m
->trigger_event
);
810 spin_unlock_irqrestore(&m
->lock
, flags
);
816 * Reinstate a previously-failed path
818 static int reinstate_path(struct pgpath
*pgpath
)
822 struct multipath
*m
= pgpath
->pg
->m
;
824 spin_lock_irqsave(&m
->lock
, flags
);
826 if (pgpath
->path
.is_active
)
829 if (!pgpath
->pg
->ps
.type
) {
830 DMWARN("Reinstate path not supported by path selector %s",
831 pgpath
->pg
->ps
.type
->name
);
836 r
= pgpath
->pg
->ps
.type
->reinstate_path(&pgpath
->pg
->ps
, &pgpath
->path
);
840 pgpath
->path
.is_active
= 1;
842 m
->current_pgpath
= NULL
;
843 if (!m
->nr_valid_paths
++)
844 queue_work(kmultipathd
, &m
->process_queued_ios
);
846 queue_work(kmultipathd
, &m
->trigger_event
);
849 spin_unlock_irqrestore(&m
->lock
, flags
);
855 * Fail or reinstate all paths that match the provided struct dm_dev.
857 static int action_dev(struct multipath
*m
, struct dm_dev
*dev
,
861 struct pgpath
*pgpath
;
862 struct priority_group
*pg
;
864 list_for_each_entry(pg
, &m
->priority_groups
, list
) {
865 list_for_each_entry(pgpath
, &pg
->pgpaths
, list
) {
866 if (pgpath
->path
.dev
== dev
)
875 * Temporarily try to avoid having to use the specified PG
877 static void bypass_pg(struct multipath
*m
, struct priority_group
*pg
,
882 spin_lock_irqsave(&m
->lock
, flags
);
884 pg
->bypassed
= bypassed
;
885 m
->current_pgpath
= NULL
;
886 m
->current_pg
= NULL
;
888 spin_unlock_irqrestore(&m
->lock
, flags
);
890 queue_work(kmultipathd
, &m
->trigger_event
);
894 * Switch to using the specified PG from the next I/O that gets mapped
896 static int switch_pg_num(struct multipath
*m
, const char *pgstr
)
898 struct priority_group
*pg
;
902 if (!pgstr
|| (sscanf(pgstr
, "%u", &pgnum
) != 1) || !pgnum
||
903 (pgnum
> m
->nr_priority_groups
)) {
904 DMWARN("invalid PG number supplied to switch_pg_num");
908 spin_lock_irqsave(&m
->lock
, flags
);
909 list_for_each_entry(pg
, &m
->priority_groups
, list
) {
914 m
->current_pgpath
= NULL
;
915 m
->current_pg
= NULL
;
918 spin_unlock_irqrestore(&m
->lock
, flags
);
920 queue_work(kmultipathd
, &m
->trigger_event
);
925 * Set/clear bypassed status of a PG.
926 * PGs are numbered upwards from 1 in the order they were declared.
928 static int bypass_pg_num(struct multipath
*m
, const char *pgstr
, int bypassed
)
930 struct priority_group
*pg
;
933 if (!pgstr
|| (sscanf(pgstr
, "%u", &pgnum
) != 1) || !pgnum
||
934 (pgnum
> m
->nr_priority_groups
)) {
935 DMWARN("invalid PG number supplied to bypass_pg");
939 list_for_each_entry(pg
, &m
->priority_groups
, list
) {
944 bypass_pg(m
, pg
, bypassed
);
949 * pg_init must call this when it has completed its initialisation
951 void dm_pg_init_complete(struct path
*path
, unsigned err_flags
)
953 struct pgpath
*pgpath
= path_to_pgpath(path
);
954 struct priority_group
*pg
= pgpath
->pg
;
955 struct multipath
*m
= pg
->m
;
958 /* We insist on failing the path if the PG is already bypassed. */
959 if (err_flags
&& pg
->bypassed
)
960 err_flags
|= MP_FAIL_PATH
;
962 if (err_flags
& MP_FAIL_PATH
)
965 if (err_flags
& MP_BYPASS_PG
)
968 spin_lock_irqsave(&m
->lock
, flags
);
972 m
->current_pgpath
= NULL
;
973 m
->current_pg
= NULL
;
975 queue_work(kmultipathd
, &m
->process_queued_ios
);
976 spin_unlock_irqrestore(&m
->lock
, flags
);
982 static int do_end_io(struct multipath
*m
, struct bio
*bio
,
983 int error
, struct mpath_io
*mpio
)
985 struct hw_handler
*hwh
= &m
->hw_handler
;
986 unsigned err_flags
= MP_FAIL_PATH
; /* Default behavior */
989 return 0; /* I/O complete */
991 if ((error
== -EWOULDBLOCK
) && bio_rw_ahead(bio
))
994 if (error
== -EOPNOTSUPP
)
998 if (!m
->nr_valid_paths
) {
999 if (!m
->queue_if_no_path
|| m
->suspended
) {
1000 spin_unlock(&m
->lock
);
1003 spin_unlock(&m
->lock
);
1007 spin_unlock(&m
->lock
);
1009 if (hwh
->type
&& hwh
->type
->error
)
1010 err_flags
= hwh
->type
->error(hwh
, bio
);
1013 if (err_flags
& MP_FAIL_PATH
)
1014 fail_path(mpio
->pgpath
);
1016 if (err_flags
& MP_BYPASS_PG
)
1017 bypass_pg(m
, mpio
->pgpath
->pg
, 1);
1020 if (err_flags
& MP_ERROR_IO
)
1024 dm_bio_restore(&mpio
->details
, bio
);
1026 /* queue for the daemon to resubmit or fail */
1027 spin_lock(&m
->lock
);
1028 bio_list_add(&m
->queued_ios
, bio
);
1031 queue_work(kmultipathd
, &m
->process_queued_ios
);
1032 spin_unlock(&m
->lock
);
1034 return 1; /* io not complete */
1037 static int multipath_end_io(struct dm_target
*ti
, struct bio
*bio
,
1038 int error
, union map_info
*map_context
)
1040 struct multipath
*m
= (struct multipath
*) ti
->private;
1041 struct mpath_io
*mpio
= (struct mpath_io
*) map_context
->ptr
;
1042 struct pgpath
*pgpath
= mpio
->pgpath
;
1043 struct path_selector
*ps
;
1046 r
= do_end_io(m
, bio
, error
, mpio
);
1048 ps
= &pgpath
->pg
->ps
;
1049 if (ps
->type
->end_io
)
1050 ps
->type
->end_io(ps
, &pgpath
->path
);
1053 mempool_free(mpio
, m
->mpio_pool
);
1059 * Suspend can't complete until all the I/O is processed so if
1060 * the last path failed we will now error any queued I/O.
1062 static void multipath_presuspend(struct dm_target
*ti
)
1064 struct multipath
*m
= (struct multipath
*) ti
->private;
1065 unsigned long flags
;
1067 spin_lock_irqsave(&m
->lock
, flags
);
1069 if (m
->queue_if_no_path
)
1070 queue_work(kmultipathd
, &m
->process_queued_ios
);
1071 spin_unlock_irqrestore(&m
->lock
, flags
);
1074 static void multipath_resume(struct dm_target
*ti
)
1076 struct multipath
*m
= (struct multipath
*) ti
->private;
1077 unsigned long flags
;
1079 spin_lock_irqsave(&m
->lock
, flags
);
1081 spin_unlock_irqrestore(&m
->lock
, flags
);
1085 * Info output has the following format:
1086 * num_multipath_feature_args [multipath_feature_args]*
1087 * num_handler_status_args [handler_status_args]*
1088 * num_groups init_group_number
1089 * [A|D|E num_ps_status_args [ps_status_args]*
1090 * num_paths num_selector_args
1091 * [path_dev A|F fail_count [selector_args]* ]+ ]+
1093 * Table output has the following format (identical to the constructor string):
1094 * num_feature_args [features_args]*
1095 * num_handler_args hw_handler [hw_handler_args]*
1096 * num_groups init_group_number
1097 * [priority selector-name num_ps_args [ps_args]*
1098 * num_paths num_selector_args [path_dev [selector_args]* ]+ ]+
1100 static int multipath_status(struct dm_target
*ti
, status_type_t type
,
1101 char *result
, unsigned int maxlen
)
1104 unsigned long flags
;
1105 struct multipath
*m
= (struct multipath
*) ti
->private;
1106 struct hw_handler
*hwh
= &m
->hw_handler
;
1107 struct priority_group
*pg
;
1112 spin_lock_irqsave(&m
->lock
, flags
);
1115 if (type
== STATUSTYPE_INFO
)
1116 DMEMIT("1 %u ", m
->queue_size
);
1117 else if (m
->queue_if_no_path
)
1118 DMEMIT("1 queue_if_no_path ");
1122 if (hwh
->type
&& hwh
->type
->status
)
1123 sz
+= hwh
->type
->status(hwh
, type
, result
+ sz
, maxlen
- sz
);
1124 else if (!hwh
->type
|| type
== STATUSTYPE_INFO
)
1127 DMEMIT("1 %s ", hwh
->type
->name
);
1129 DMEMIT("%u ", m
->nr_priority_groups
);
1132 pg_num
= m
->next_pg
->pg_num
;
1133 else if (m
->current_pg
)
1134 pg_num
= m
->current_pg
->pg_num
;
1138 DMEMIT("%u ", pg_num
);
1141 case STATUSTYPE_INFO
:
1142 list_for_each_entry(pg
, &m
->priority_groups
, list
) {
1144 state
= 'D'; /* Disabled */
1145 else if (pg
== m
->current_pg
)
1146 state
= 'A'; /* Currently Active */
1148 state
= 'E'; /* Enabled */
1150 DMEMIT("%c ", state
);
1152 if (pg
->ps
.type
->status
)
1153 sz
+= pg
->ps
.type
->status(&pg
->ps
, NULL
, type
,
1159 DMEMIT("%u %u ", pg
->nr_pgpaths
,
1160 pg
->ps
.type
->info_args
);
1162 list_for_each_entry(p
, &pg
->pgpaths
, list
) {
1163 DMEMIT("%s %s %u ", p
->path
.dev
->name
,
1164 p
->path
.is_active
? "A" : "F",
1166 if (pg
->ps
.type
->status
)
1167 sz
+= pg
->ps
.type
->status(&pg
->ps
,
1168 &p
->path
, type
, result
+ sz
,
1174 case STATUSTYPE_TABLE
:
1175 list_for_each_entry(pg
, &m
->priority_groups
, list
) {
1176 DMEMIT("%s ", pg
->ps
.type
->name
);
1178 if (pg
->ps
.type
->status
)
1179 sz
+= pg
->ps
.type
->status(&pg
->ps
, NULL
, type
,
1185 DMEMIT("%u %u ", pg
->nr_pgpaths
,
1186 pg
->ps
.type
->table_args
);
1188 list_for_each_entry(p
, &pg
->pgpaths
, list
) {
1189 DMEMIT("%s ", p
->path
.dev
->name
);
1190 if (pg
->ps
.type
->status
)
1191 sz
+= pg
->ps
.type
->status(&pg
->ps
,
1192 &p
->path
, type
, result
+ sz
,
1199 spin_unlock_irqrestore(&m
->lock
, flags
);
1204 static int multipath_message(struct dm_target
*ti
, unsigned argc
, char **argv
)
1208 struct multipath
*m
= (struct multipath
*) ti
->private;
1212 if (!strnicmp(argv
[0], MESG_STR("queue_if_no_path")))
1213 return queue_if_no_path(m
, 1);
1214 else if (!strnicmp(argv
[0], MESG_STR("fail_if_no_path")))
1215 return queue_if_no_path(m
, 0);
1221 if (!strnicmp(argv
[0], MESG_STR("disable_group")))
1222 return bypass_pg_num(m
, argv
[1], 1);
1223 else if (!strnicmp(argv
[0], MESG_STR("enable_group")))
1224 return bypass_pg_num(m
, argv
[1], 0);
1225 else if (!strnicmp(argv
[0], MESG_STR("switch_group")))
1226 return switch_pg_num(m
, argv
[1]);
1227 else if (!strnicmp(argv
[0], MESG_STR("reinstate_path")))
1228 action
= reinstate_path
;
1229 else if (!strnicmp(argv
[0], MESG_STR("fail_path")))
1234 r
= dm_get_device(ti
, argv
[1], ti
->begin
, ti
->len
,
1235 dm_table_get_mode(ti
->table
), &dev
);
1237 DMWARN("dm-multipath message: error getting device %s",
1242 r
= action_dev(m
, dev
, action
);
1244 dm_put_device(ti
, dev
);
1249 DMWARN("Unrecognised multipath message received.");
1253 /*-----------------------------------------------------------------
1255 *---------------------------------------------------------------*/
1256 static struct target_type multipath_target
= {
1257 .name
= "multipath",
1258 .version
= {1, 0, 4},
1259 .module
= THIS_MODULE
,
1260 .ctr
= multipath_ctr
,
1261 .dtr
= multipath_dtr
,
1262 .map
= multipath_map
,
1263 .end_io
= multipath_end_io
,
1264 .presuspend
= multipath_presuspend
,
1265 .resume
= multipath_resume
,
1266 .status
= multipath_status
,
1267 .message
= multipath_message
,
1270 static int __init
dm_multipath_init(void)
1274 /* allocate a slab for the dm_ios */
1275 _mpio_cache
= kmem_cache_create("dm_mpath", sizeof(struct mpath_io
),
1280 r
= dm_register_target(&multipath_target
);
1282 DMERR("%s: register failed %d", multipath_target
.name
, r
);
1283 kmem_cache_destroy(_mpio_cache
);
1287 kmultipathd
= create_workqueue("kmpathd");
1289 DMERR("%s: failed to create workqueue kmpathd",
1290 multipath_target
.name
);
1291 dm_unregister_target(&multipath_target
);
1292 kmem_cache_destroy(_mpio_cache
);
1296 DMINFO("dm-multipath version %u.%u.%u loaded",
1297 multipath_target
.version
[0], multipath_target
.version
[1],
1298 multipath_target
.version
[2]);
1303 static void __exit
dm_multipath_exit(void)
1307 destroy_workqueue(kmultipathd
);
1309 r
= dm_unregister_target(&multipath_target
);
1311 DMERR("%s: target unregister failed %d",
1312 multipath_target
.name
, r
);
1313 kmem_cache_destroy(_mpio_cache
);
1316 EXPORT_SYMBOL_GPL(dm_pg_init_complete
);
1318 module_init(dm_multipath_init
);
1319 module_exit(dm_multipath_exit
);
1321 MODULE_DESCRIPTION(DM_NAME
" multipath target");
1322 MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>");
1323 MODULE_LICENSE("GPL");