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>
18 #define DM_MSG_PREFIX "multipath round-robin"
20 /*-----------------------------------------------------------------
21 * Path-handling code, paths are held in lists
22 *---------------------------------------------------------------*/
24 struct list_head list
;
26 unsigned repeat_count
;
29 static void free_paths(struct list_head
*paths
)
31 struct path_info
*pi
, *next
;
33 list_for_each_entry_safe(pi
, next
, paths
, list
) {
39 /*-----------------------------------------------------------------
40 * Round-robin selector
41 *---------------------------------------------------------------*/
43 #define RR_MIN_IO 1000
46 struct list_head valid_paths
;
47 struct list_head invalid_paths
;
50 static struct selector
*alloc_selector(void)
52 struct selector
*s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
55 INIT_LIST_HEAD(&s
->valid_paths
);
56 INIT_LIST_HEAD(&s
->invalid_paths
);
62 static int rr_create(struct path_selector
*ps
, unsigned argc
, char **argv
)
74 static void rr_destroy(struct path_selector
*ps
)
76 struct selector
*s
= (struct selector
*) ps
->context
;
78 free_paths(&s
->valid_paths
);
79 free_paths(&s
->invalid_paths
);
84 static int rr_status(struct path_selector
*ps
, struct dm_path
*path
,
85 status_type_t type
, char *result
, unsigned int maxlen
)
96 case STATUSTYPE_TABLE
:
98 DMEMIT("%u ", pi
->repeat_count
);
107 * Called during initialisation to register each path with an
108 * optional repeat_count.
110 static int rr_add_path(struct path_selector
*ps
, struct dm_path
*path
,
111 int argc
, char **argv
, char **error
)
113 struct selector
*s
= (struct selector
*) ps
->context
;
114 struct path_info
*pi
;
115 unsigned repeat_count
= RR_MIN_IO
;
118 *error
= "round-robin ps: incorrect number of arguments";
122 /* First path argument is number of I/Os before switching path */
123 if ((argc
== 1) && (sscanf(argv
[0], "%u", &repeat_count
) != 1)) {
124 *error
= "round-robin ps: invalid repeat count";
128 /* allocate the path */
129 pi
= kmalloc(sizeof(*pi
), GFP_KERNEL
);
131 *error
= "round-robin ps: Error allocating path context";
136 pi
->repeat_count
= repeat_count
;
138 path
->pscontext
= pi
;
140 list_add_tail(&pi
->list
, &s
->valid_paths
);
145 static void rr_fail_path(struct path_selector
*ps
, struct dm_path
*p
)
147 struct selector
*s
= (struct selector
*) ps
->context
;
148 struct path_info
*pi
= p
->pscontext
;
150 list_move(&pi
->list
, &s
->invalid_paths
);
153 static int rr_reinstate_path(struct path_selector
*ps
, struct dm_path
*p
)
155 struct selector
*s
= (struct selector
*) ps
->context
;
156 struct path_info
*pi
= p
->pscontext
;
158 list_move(&pi
->list
, &s
->valid_paths
);
163 static struct dm_path
*rr_select_path(struct path_selector
*ps
,
164 unsigned *repeat_count
, size_t nr_bytes
)
166 struct selector
*s
= (struct selector
*) ps
->context
;
167 struct path_info
*pi
= NULL
;
169 if (!list_empty(&s
->valid_paths
)) {
170 pi
= list_entry(s
->valid_paths
.next
, struct path_info
, list
);
171 list_move_tail(&pi
->list
, &s
->valid_paths
);
172 *repeat_count
= pi
->repeat_count
;
175 return pi
? pi
->path
: NULL
;
178 static struct path_selector_type rr_ps
= {
179 .name
= "round-robin",
180 .module
= THIS_MODULE
,
184 .destroy
= rr_destroy
,
186 .add_path
= rr_add_path
,
187 .fail_path
= rr_fail_path
,
188 .reinstate_path
= rr_reinstate_path
,
189 .select_path
= rr_select_path
,
192 static int __init
dm_rr_init(void)
194 int r
= dm_register_path_selector(&rr_ps
);
197 DMERR("register failed %d", r
);
199 DMINFO("version 1.0.0 loaded");
204 static void __exit
dm_rr_exit(void)
206 int r
= dm_unregister_path_selector(&rr_ps
);
209 DMERR("unregister failed %d", r
);
212 module_init(dm_rr_init
);
213 module_exit(dm_rr_exit
);
215 MODULE_DESCRIPTION(DM_NAME
" round-robin multipath path selector");
216 MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>");
217 MODULE_LICENSE("GPL");
This page took 0.036213 seconds and 6 git commands to generate.