2 * Copyright (C) 2003 Sistina Software.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * Module Author: Heinz Mauelshagen
7 * This file is released under the GPL.
9 * Round-robin path selector.
12 #include <linux/device-mapper.h>
14 #include "dm-path-selector.h"
16 #include <linux/slab.h>
17 #include <linux/module.h>
19 #define DM_MSG_PREFIX "multipath round-robin"
21 /*-----------------------------------------------------------------
22 * Path-handling code, paths are held in lists
23 *---------------------------------------------------------------*/
25 struct list_head list
;
27 unsigned repeat_count
;
30 static void free_paths(struct list_head
*paths
)
32 struct path_info
*pi
, *next
;
34 list_for_each_entry_safe(pi
, next
, paths
, list
) {
40 /*-----------------------------------------------------------------
41 * Round-robin selector
42 *---------------------------------------------------------------*/
44 #define RR_MIN_IO 1000
47 struct list_head valid_paths
;
48 struct list_head invalid_paths
;
51 static struct selector
*alloc_selector(void)
53 struct selector
*s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
56 INIT_LIST_HEAD(&s
->valid_paths
);
57 INIT_LIST_HEAD(&s
->invalid_paths
);
63 static int rr_create(struct path_selector
*ps
, unsigned argc
, char **argv
)
75 static void rr_destroy(struct path_selector
*ps
)
77 struct selector
*s
= (struct selector
*) ps
->context
;
79 free_paths(&s
->valid_paths
);
80 free_paths(&s
->invalid_paths
);
85 static int rr_status(struct path_selector
*ps
, struct dm_path
*path
,
86 status_type_t type
, char *result
, unsigned int maxlen
)
97 case STATUSTYPE_TABLE
:
99 DMEMIT("%u ", pi
->repeat_count
);
108 * Called during initialisation to register each path with an
109 * optional repeat_count.
111 static int rr_add_path(struct path_selector
*ps
, struct dm_path
*path
,
112 int argc
, char **argv
, char **error
)
114 struct selector
*s
= (struct selector
*) ps
->context
;
115 struct path_info
*pi
;
116 unsigned repeat_count
= RR_MIN_IO
;
120 *error
= "round-robin ps: incorrect number of arguments";
124 /* First path argument is number of I/Os before switching path */
125 if ((argc
== 1) && (sscanf(argv
[0], "%u%c", &repeat_count
, &dummy
) != 1)) {
126 *error
= "round-robin ps: invalid repeat count";
130 /* allocate the path */
131 pi
= kmalloc(sizeof(*pi
), GFP_KERNEL
);
133 *error
= "round-robin ps: Error allocating path context";
138 pi
->repeat_count
= repeat_count
;
140 path
->pscontext
= pi
;
142 list_add_tail(&pi
->list
, &s
->valid_paths
);
147 static void rr_fail_path(struct path_selector
*ps
, struct dm_path
*p
)
149 struct selector
*s
= (struct selector
*) ps
->context
;
150 struct path_info
*pi
= p
->pscontext
;
152 list_move(&pi
->list
, &s
->invalid_paths
);
155 static int rr_reinstate_path(struct path_selector
*ps
, struct dm_path
*p
)
157 struct selector
*s
= (struct selector
*) ps
->context
;
158 struct path_info
*pi
= p
->pscontext
;
160 list_move(&pi
->list
, &s
->valid_paths
);
165 static struct dm_path
*rr_select_path(struct path_selector
*ps
,
166 unsigned *repeat_count
, size_t nr_bytes
)
168 struct selector
*s
= (struct selector
*) ps
->context
;
169 struct path_info
*pi
= NULL
;
171 if (!list_empty(&s
->valid_paths
)) {
172 pi
= list_entry(s
->valid_paths
.next
, struct path_info
, list
);
173 list_move_tail(&pi
->list
, &s
->valid_paths
);
174 *repeat_count
= pi
->repeat_count
;
177 return pi
? pi
->path
: NULL
;
180 static struct path_selector_type rr_ps
= {
181 .name
= "round-robin",
182 .module
= THIS_MODULE
,
186 .destroy
= rr_destroy
,
188 .add_path
= rr_add_path
,
189 .fail_path
= rr_fail_path
,
190 .reinstate_path
= rr_reinstate_path
,
191 .select_path
= rr_select_path
,
194 static int __init
dm_rr_init(void)
196 int r
= dm_register_path_selector(&rr_ps
);
199 DMERR("register failed %d", r
);
201 DMINFO("version 1.0.0 loaded");
206 static void __exit
dm_rr_exit(void)
208 int r
= dm_unregister_path_selector(&rr_ps
);
211 DMERR("unregister failed %d", r
);
214 module_init(dm_rr_init
);
215 module_exit(dm_rr_exit
);
217 MODULE_DESCRIPTION(DM_NAME
" round-robin multipath path selector");
218 MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>");
219 MODULE_LICENSE("GPL");
This page took 0.034337 seconds and 5 git commands to generate.