]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | ||
586e80e6 MP |
8 | #include <linux/device-mapper.h> |
9 | ||
1da177e4 | 10 | #include "dm-path-selector.h" |
b15546f9 | 11 | #include "dm-uevent.h" |
1da177e4 LT |
12 | |
13 | #include <linux/ctype.h> | |
14 | #include <linux/init.h> | |
15 | #include <linux/mempool.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/pagemap.h> | |
18 | #include <linux/slab.h> | |
19 | #include <linux/time.h> | |
20 | #include <linux/workqueue.h> | |
cfae5c9b | 21 | #include <scsi/scsi_dh.h> |
1da177e4 LT |
22 | #include <asm/atomic.h> |
23 | ||
72d94861 | 24 | #define DM_MSG_PREFIX "multipath" |
1da177e4 LT |
25 | #define MESG_STR(x) x, sizeof(x) |
26 | ||
27 | /* Path properties */ | |
28 | struct pgpath { | |
29 | struct list_head list; | |
30 | ||
31 | struct priority_group *pg; /* Owning PG */ | |
6680073d | 32 | unsigned is_active; /* Path status */ |
1da177e4 LT |
33 | unsigned fail_count; /* Cumulative failure count */ |
34 | ||
c922d5f7 | 35 | struct dm_path path; |
224cb3e9 | 36 | struct work_struct deactivate_path; |
e54f77dd | 37 | struct work_struct activate_path; |
1da177e4 LT |
38 | }; |
39 | ||
40 | #define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path) | |
41 | ||
42 | /* | |
43 | * Paths are grouped into Priority Groups and numbered from 1 upwards. | |
44 | * Each has a path selector which controls which path gets used. | |
45 | */ | |
46 | struct priority_group { | |
47 | struct list_head list; | |
48 | ||
49 | struct multipath *m; /* Owning multipath instance */ | |
50 | struct path_selector ps; | |
51 | ||
52 | unsigned pg_num; /* Reference number */ | |
53 | unsigned bypassed; /* Temporarily bypass this PG? */ | |
54 | ||
55 | unsigned nr_pgpaths; /* Number of paths in PG */ | |
56 | struct list_head pgpaths; | |
57 | }; | |
58 | ||
59 | /* Multipath context */ | |
60 | struct multipath { | |
61 | struct list_head list; | |
62 | struct dm_target *ti; | |
63 | ||
64 | spinlock_t lock; | |
65 | ||
cfae5c9b | 66 | const char *hw_handler_name; |
2bfd2e13 | 67 | char *hw_handler_params; |
1da177e4 LT |
68 | unsigned nr_priority_groups; |
69 | struct list_head priority_groups; | |
70 | unsigned pg_init_required; /* pg_init needs calling? */ | |
c3cd4f6b | 71 | unsigned pg_init_in_progress; /* Only one pg_init allowed at once */ |
1da177e4 LT |
72 | |
73 | unsigned nr_valid_paths; /* Total number of usable paths */ | |
74 | struct pgpath *current_pgpath; | |
75 | struct priority_group *current_pg; | |
76 | struct priority_group *next_pg; /* Switch to this PG if set */ | |
77 | unsigned repeat_count; /* I/Os left before calling PS again */ | |
78 | ||
79 | unsigned queue_io; /* Must we queue all I/O? */ | |
80 | unsigned queue_if_no_path; /* Queue I/O if last path fails? */ | |
436d4108 | 81 | unsigned saved_queue_if_no_path;/* Saved state during suspension */ |
c9e45581 DW |
82 | unsigned pg_init_retries; /* Number of times to retry pg_init */ |
83 | unsigned pg_init_count; /* Number of times pg_init called */ | |
1da177e4 LT |
84 | |
85 | struct work_struct process_queued_ios; | |
f40c67f0 | 86 | struct list_head queued_ios; |
1da177e4 LT |
87 | unsigned queue_size; |
88 | ||
89 | struct work_struct trigger_event; | |
90 | ||
91 | /* | |
028867ac | 92 | * We must use a mempool of dm_mpath_io structs so that we |
1da177e4 LT |
93 | * can resubmit bios on error. |
94 | */ | |
95 | mempool_t *mpio_pool; | |
6380f26f MA |
96 | |
97 | struct mutex work_mutex; | |
67a46dad MA |
98 | |
99 | unsigned suspended; /* Don't create new I/O internally when set. */ | |
1da177e4 LT |
100 | }; |
101 | ||
102 | /* | |
103 | * Context information attached to each bio we process. | |
104 | */ | |
028867ac | 105 | struct dm_mpath_io { |
1da177e4 | 106 | struct pgpath *pgpath; |
02ab823f | 107 | size_t nr_bytes; |
1da177e4 LT |
108 | }; |
109 | ||
110 | typedef int (*action_fn) (struct pgpath *pgpath); | |
111 | ||
112 | #define MIN_IOS 256 /* Mempool size */ | |
113 | ||
e18b890b | 114 | static struct kmem_cache *_mpio_cache; |
1da177e4 | 115 | |
bab7cfc7 | 116 | static struct workqueue_struct *kmultipathd, *kmpath_handlerd; |
c4028958 DH |
117 | static void process_queued_ios(struct work_struct *work); |
118 | static void trigger_event(struct work_struct *work); | |
bab7cfc7 | 119 | static void activate_path(struct work_struct *work); |
224cb3e9 | 120 | static void deactivate_path(struct work_struct *work); |
1da177e4 LT |
121 | |
122 | ||
123 | /*----------------------------------------------- | |
124 | * Allocation routines | |
125 | *-----------------------------------------------*/ | |
126 | ||
127 | static struct pgpath *alloc_pgpath(void) | |
128 | { | |
e69fae56 | 129 | struct pgpath *pgpath = kzalloc(sizeof(*pgpath), GFP_KERNEL); |
1da177e4 | 130 | |
224cb3e9 | 131 | if (pgpath) { |
6680073d | 132 | pgpath->is_active = 1; |
224cb3e9 | 133 | INIT_WORK(&pgpath->deactivate_path, deactivate_path); |
e54f77dd | 134 | INIT_WORK(&pgpath->activate_path, activate_path); |
224cb3e9 | 135 | } |
1da177e4 LT |
136 | |
137 | return pgpath; | |
138 | } | |
139 | ||
028867ac | 140 | static void free_pgpath(struct pgpath *pgpath) |
1da177e4 LT |
141 | { |
142 | kfree(pgpath); | |
143 | } | |
144 | ||
224cb3e9 MA |
145 | static void deactivate_path(struct work_struct *work) |
146 | { | |
147 | struct pgpath *pgpath = | |
148 | container_of(work, struct pgpath, deactivate_path); | |
149 | ||
150 | blk_abort_queue(pgpath->path.dev->bdev->bd_disk->queue); | |
151 | } | |
152 | ||
1da177e4 LT |
153 | static struct priority_group *alloc_priority_group(void) |
154 | { | |
155 | struct priority_group *pg; | |
156 | ||
e69fae56 | 157 | pg = kzalloc(sizeof(*pg), GFP_KERNEL); |
1da177e4 | 158 | |
e69fae56 MM |
159 | if (pg) |
160 | INIT_LIST_HEAD(&pg->pgpaths); | |
1da177e4 LT |
161 | |
162 | return pg; | |
163 | } | |
164 | ||
165 | static void free_pgpaths(struct list_head *pgpaths, struct dm_target *ti) | |
166 | { | |
167 | struct pgpath *pgpath, *tmp; | |
ae11b1b3 | 168 | struct multipath *m = ti->private; |
1da177e4 LT |
169 | |
170 | list_for_each_entry_safe(pgpath, tmp, pgpaths, list) { | |
171 | list_del(&pgpath->list); | |
ae11b1b3 HR |
172 | if (m->hw_handler_name) |
173 | scsi_dh_detach(bdev_get_queue(pgpath->path.dev->bdev)); | |
1da177e4 LT |
174 | dm_put_device(ti, pgpath->path.dev); |
175 | free_pgpath(pgpath); | |
176 | } | |
177 | } | |
178 | ||
179 | static void free_priority_group(struct priority_group *pg, | |
180 | struct dm_target *ti) | |
181 | { | |
182 | struct path_selector *ps = &pg->ps; | |
183 | ||
184 | if (ps->type) { | |
185 | ps->type->destroy(ps); | |
186 | dm_put_path_selector(ps->type); | |
187 | } | |
188 | ||
189 | free_pgpaths(&pg->pgpaths, ti); | |
190 | kfree(pg); | |
191 | } | |
192 | ||
28f16c20 | 193 | static struct multipath *alloc_multipath(struct dm_target *ti) |
1da177e4 LT |
194 | { |
195 | struct multipath *m; | |
196 | ||
e69fae56 | 197 | m = kzalloc(sizeof(*m), GFP_KERNEL); |
1da177e4 | 198 | if (m) { |
1da177e4 | 199 | INIT_LIST_HEAD(&m->priority_groups); |
f40c67f0 | 200 | INIT_LIST_HEAD(&m->queued_ios); |
1da177e4 LT |
201 | spin_lock_init(&m->lock); |
202 | m->queue_io = 1; | |
c4028958 DH |
203 | INIT_WORK(&m->process_queued_ios, process_queued_ios); |
204 | INIT_WORK(&m->trigger_event, trigger_event); | |
6380f26f | 205 | mutex_init(&m->work_mutex); |
93d2341c | 206 | m->mpio_pool = mempool_create_slab_pool(MIN_IOS, _mpio_cache); |
1da177e4 LT |
207 | if (!m->mpio_pool) { |
208 | kfree(m); | |
209 | return NULL; | |
210 | } | |
28f16c20 MM |
211 | m->ti = ti; |
212 | ti->private = m; | |
1da177e4 LT |
213 | } |
214 | ||
215 | return m; | |
216 | } | |
217 | ||
218 | static void free_multipath(struct multipath *m) | |
219 | { | |
220 | struct priority_group *pg, *tmp; | |
1da177e4 LT |
221 | |
222 | list_for_each_entry_safe(pg, tmp, &m->priority_groups, list) { | |
223 | list_del(&pg->list); | |
224 | free_priority_group(pg, m->ti); | |
225 | } | |
226 | ||
cfae5c9b | 227 | kfree(m->hw_handler_name); |
2bfd2e13 | 228 | kfree(m->hw_handler_params); |
1da177e4 LT |
229 | mempool_destroy(m->mpio_pool); |
230 | kfree(m); | |
231 | } | |
232 | ||
233 | ||
234 | /*----------------------------------------------- | |
235 | * Path selection | |
236 | *-----------------------------------------------*/ | |
237 | ||
238 | static void __switch_pg(struct multipath *m, struct pgpath *pgpath) | |
239 | { | |
1da177e4 LT |
240 | m->current_pg = pgpath->pg; |
241 | ||
242 | /* Must we initialise the PG first, and queue I/O till it's ready? */ | |
cfae5c9b | 243 | if (m->hw_handler_name) { |
1da177e4 LT |
244 | m->pg_init_required = 1; |
245 | m->queue_io = 1; | |
246 | } else { | |
247 | m->pg_init_required = 0; | |
248 | m->queue_io = 0; | |
249 | } | |
c9e45581 DW |
250 | |
251 | m->pg_init_count = 0; | |
1da177e4 LT |
252 | } |
253 | ||
02ab823f KU |
254 | static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg, |
255 | size_t nr_bytes) | |
1da177e4 | 256 | { |
c922d5f7 | 257 | struct dm_path *path; |
1da177e4 | 258 | |
02ab823f | 259 | path = pg->ps.type->select_path(&pg->ps, &m->repeat_count, nr_bytes); |
1da177e4 LT |
260 | if (!path) |
261 | return -ENXIO; | |
262 | ||
263 | m->current_pgpath = path_to_pgpath(path); | |
264 | ||
265 | if (m->current_pg != pg) | |
266 | __switch_pg(m, m->current_pgpath); | |
267 | ||
268 | return 0; | |
269 | } | |
270 | ||
02ab823f | 271 | static void __choose_pgpath(struct multipath *m, size_t nr_bytes) |
1da177e4 LT |
272 | { |
273 | struct priority_group *pg; | |
274 | unsigned bypassed = 1; | |
275 | ||
276 | if (!m->nr_valid_paths) | |
277 | goto failed; | |
278 | ||
279 | /* Were we instructed to switch PG? */ | |
280 | if (m->next_pg) { | |
281 | pg = m->next_pg; | |
282 | m->next_pg = NULL; | |
02ab823f | 283 | if (!__choose_path_in_pg(m, pg, nr_bytes)) |
1da177e4 LT |
284 | return; |
285 | } | |
286 | ||
287 | /* Don't change PG until it has no remaining paths */ | |
02ab823f | 288 | if (m->current_pg && !__choose_path_in_pg(m, m->current_pg, nr_bytes)) |
1da177e4 LT |
289 | return; |
290 | ||
291 | /* | |
292 | * Loop through priority groups until we find a valid path. | |
293 | * First time we skip PGs marked 'bypassed'. | |
294 | * Second time we only try the ones we skipped. | |
295 | */ | |
296 | do { | |
297 | list_for_each_entry(pg, &m->priority_groups, list) { | |
298 | if (pg->bypassed == bypassed) | |
299 | continue; | |
02ab823f | 300 | if (!__choose_path_in_pg(m, pg, nr_bytes)) |
1da177e4 LT |
301 | return; |
302 | } | |
303 | } while (bypassed--); | |
304 | ||
305 | failed: | |
306 | m->current_pgpath = NULL; | |
307 | m->current_pg = NULL; | |
308 | } | |
309 | ||
45e15720 KU |
310 | /* |
311 | * Check whether bios must be queued in the device-mapper core rather | |
312 | * than here in the target. | |
313 | * | |
314 | * m->lock must be held on entry. | |
315 | * | |
316 | * If m->queue_if_no_path and m->saved_queue_if_no_path hold the | |
317 | * same value then we are not between multipath_presuspend() | |
318 | * and multipath_resume() calls and we have no need to check | |
319 | * for the DMF_NOFLUSH_SUSPENDING flag. | |
320 | */ | |
321 | static int __must_push_back(struct multipath *m) | |
322 | { | |
323 | return (m->queue_if_no_path != m->saved_queue_if_no_path && | |
324 | dm_noflush_suspending(m->ti)); | |
325 | } | |
326 | ||
f40c67f0 | 327 | static int map_io(struct multipath *m, struct request *clone, |
028867ac | 328 | struct dm_mpath_io *mpio, unsigned was_queued) |
1da177e4 | 329 | { |
d2a7ad29 | 330 | int r = DM_MAPIO_REMAPPED; |
f40c67f0 | 331 | size_t nr_bytes = blk_rq_bytes(clone); |
1da177e4 LT |
332 | unsigned long flags; |
333 | struct pgpath *pgpath; | |
f40c67f0 | 334 | struct block_device *bdev; |
1da177e4 LT |
335 | |
336 | spin_lock_irqsave(&m->lock, flags); | |
337 | ||
338 | /* Do we need to select a new pgpath? */ | |
339 | if (!m->current_pgpath || | |
340 | (!m->queue_io && (m->repeat_count && --m->repeat_count == 0))) | |
02ab823f | 341 | __choose_pgpath(m, nr_bytes); |
1da177e4 LT |
342 | |
343 | pgpath = m->current_pgpath; | |
344 | ||
345 | if (was_queued) | |
346 | m->queue_size--; | |
347 | ||
348 | if ((pgpath && m->queue_io) || | |
436d4108 | 349 | (!pgpath && m->queue_if_no_path)) { |
1da177e4 | 350 | /* Queue for the daemon to resubmit */ |
f40c67f0 | 351 | list_add_tail(&clone->queuelist, &m->queued_ios); |
1da177e4 | 352 | m->queue_size++; |
c3cd4f6b AK |
353 | if ((m->pg_init_required && !m->pg_init_in_progress) || |
354 | !m->queue_io) | |
c557308e | 355 | queue_work(kmultipathd, &m->process_queued_ios); |
1da177e4 | 356 | pgpath = NULL; |
d2a7ad29 | 357 | r = DM_MAPIO_SUBMITTED; |
f40c67f0 KU |
358 | } else if (pgpath) { |
359 | bdev = pgpath->path.dev->bdev; | |
360 | clone->q = bdev_get_queue(bdev); | |
361 | clone->rq_disk = bdev->bd_disk; | |
362 | } else if (__must_push_back(m)) | |
45e15720 KU |
363 | r = DM_MAPIO_REQUEUE; |
364 | else | |
365 | r = -EIO; /* Failed */ | |
1da177e4 LT |
366 | |
367 | mpio->pgpath = pgpath; | |
02ab823f KU |
368 | mpio->nr_bytes = nr_bytes; |
369 | ||
370 | if (r == DM_MAPIO_REMAPPED && pgpath->pg->ps.type->start_io) | |
371 | pgpath->pg->ps.type->start_io(&pgpath->pg->ps, &pgpath->path, | |
372 | nr_bytes); | |
1da177e4 LT |
373 | |
374 | spin_unlock_irqrestore(&m->lock, flags); | |
375 | ||
376 | return r; | |
377 | } | |
378 | ||
379 | /* | |
380 | * If we run out of usable paths, should we queue I/O or error it? | |
381 | */ | |
485ef69e AK |
382 | static int queue_if_no_path(struct multipath *m, unsigned queue_if_no_path, |
383 | unsigned save_old_value) | |
1da177e4 LT |
384 | { |
385 | unsigned long flags; | |
386 | ||
387 | spin_lock_irqsave(&m->lock, flags); | |
388 | ||
485ef69e AK |
389 | if (save_old_value) |
390 | m->saved_queue_if_no_path = m->queue_if_no_path; | |
391 | else | |
392 | m->saved_queue_if_no_path = queue_if_no_path; | |
1da177e4 | 393 | m->queue_if_no_path = queue_if_no_path; |
c3cd4f6b | 394 | if (!m->queue_if_no_path && m->queue_size) |
c557308e | 395 | queue_work(kmultipathd, &m->process_queued_ios); |
1da177e4 LT |
396 | |
397 | spin_unlock_irqrestore(&m->lock, flags); | |
398 | ||
399 | return 0; | |
400 | } | |
401 | ||
402 | /*----------------------------------------------------------------- | |
403 | * The multipath daemon is responsible for resubmitting queued ios. | |
404 | *---------------------------------------------------------------*/ | |
405 | ||
406 | static void dispatch_queued_ios(struct multipath *m) | |
407 | { | |
408 | int r; | |
409 | unsigned long flags; | |
028867ac | 410 | struct dm_mpath_io *mpio; |
1da177e4 | 411 | union map_info *info; |
f40c67f0 KU |
412 | struct request *clone, *n; |
413 | LIST_HEAD(cl); | |
1da177e4 LT |
414 | |
415 | spin_lock_irqsave(&m->lock, flags); | |
f40c67f0 | 416 | list_splice_init(&m->queued_ios, &cl); |
1da177e4 LT |
417 | spin_unlock_irqrestore(&m->lock, flags); |
418 | ||
f40c67f0 KU |
419 | list_for_each_entry_safe(clone, n, &cl, queuelist) { |
420 | list_del_init(&clone->queuelist); | |
1da177e4 | 421 | |
f40c67f0 | 422 | info = dm_get_rq_mapinfo(clone); |
1da177e4 LT |
423 | mpio = info->ptr; |
424 | ||
f40c67f0 KU |
425 | r = map_io(m, clone, mpio, 1); |
426 | if (r < 0) { | |
427 | mempool_free(mpio, m->mpio_pool); | |
428 | dm_kill_unmapped_request(clone, r); | |
429 | } else if (r == DM_MAPIO_REMAPPED) | |
430 | dm_dispatch_request(clone); | |
431 | else if (r == DM_MAPIO_REQUEUE) { | |
432 | mempool_free(mpio, m->mpio_pool); | |
433 | dm_requeue_unmapped_request(clone); | |
434 | } | |
1da177e4 LT |
435 | } |
436 | } | |
437 | ||
c4028958 | 438 | static void process_queued_ios(struct work_struct *work) |
1da177e4 | 439 | { |
c4028958 DH |
440 | struct multipath *m = |
441 | container_of(work, struct multipath, process_queued_ios); | |
e54f77dd CS |
442 | struct pgpath *pgpath = NULL, *tmp; |
443 | unsigned must_queue = 1; | |
1da177e4 LT |
444 | unsigned long flags; |
445 | ||
446 | spin_lock_irqsave(&m->lock, flags); | |
447 | ||
c3cd4f6b AK |
448 | if (!m->queue_size) |
449 | goto out; | |
450 | ||
1da177e4 | 451 | if (!m->current_pgpath) |
02ab823f | 452 | __choose_pgpath(m, 0); |
1da177e4 LT |
453 | |
454 | pgpath = m->current_pgpath; | |
455 | ||
c3cd4f6b AK |
456 | if ((pgpath && !m->queue_io) || |
457 | (!pgpath && !m->queue_if_no_path)) | |
458 | must_queue = 0; | |
1da177e4 | 459 | |
b81aa1c7 | 460 | if (m->pg_init_required && !m->pg_init_in_progress && pgpath) { |
c9e45581 | 461 | m->pg_init_count++; |
1da177e4 | 462 | m->pg_init_required = 0; |
e54f77dd CS |
463 | list_for_each_entry(tmp, &pgpath->pg->pgpaths, list) { |
464 | if (queue_work(kmpath_handlerd, &tmp->activate_path)) | |
465 | m->pg_init_in_progress++; | |
466 | } | |
c3cd4f6b | 467 | } |
c3cd4f6b | 468 | out: |
1da177e4 | 469 | spin_unlock_irqrestore(&m->lock, flags); |
1da177e4 LT |
470 | if (!must_queue) |
471 | dispatch_queued_ios(m); | |
472 | } | |
473 | ||
474 | /* | |
475 | * An event is triggered whenever a path is taken out of use. | |
476 | * Includes path failure and PG bypass. | |
477 | */ | |
c4028958 | 478 | static void trigger_event(struct work_struct *work) |
1da177e4 | 479 | { |
c4028958 DH |
480 | struct multipath *m = |
481 | container_of(work, struct multipath, trigger_event); | |
1da177e4 LT |
482 | |
483 | dm_table_event(m->ti->table); | |
484 | } | |
485 | ||
486 | /*----------------------------------------------------------------- | |
487 | * Constructor/argument parsing: | |
488 | * <#multipath feature args> [<arg>]* | |
489 | * <#hw_handler args> [hw_handler [<arg>]*] | |
490 | * <#priority groups> | |
491 | * <initial priority group> | |
492 | * [<selector> <#selector args> [<arg>]* | |
493 | * <#paths> <#per-path selector args> | |
494 | * [<path> [<arg>]* ]+ ]+ | |
495 | *---------------------------------------------------------------*/ | |
496 | struct param { | |
497 | unsigned min; | |
498 | unsigned max; | |
499 | char *error; | |
500 | }; | |
501 | ||
1da177e4 LT |
502 | static int read_param(struct param *param, char *str, unsigned *v, char **error) |
503 | { | |
504 | if (!str || | |
505 | (sscanf(str, "%u", v) != 1) || | |
506 | (*v < param->min) || | |
507 | (*v > param->max)) { | |
508 | *error = param->error; | |
509 | return -EINVAL; | |
510 | } | |
511 | ||
512 | return 0; | |
513 | } | |
514 | ||
515 | struct arg_set { | |
516 | unsigned argc; | |
517 | char **argv; | |
518 | }; | |
519 | ||
520 | static char *shift(struct arg_set *as) | |
521 | { | |
522 | char *r; | |
523 | ||
524 | if (as->argc) { | |
525 | as->argc--; | |
526 | r = *as->argv; | |
527 | as->argv++; | |
528 | return r; | |
529 | } | |
530 | ||
531 | return NULL; | |
532 | } | |
533 | ||
534 | static void consume(struct arg_set *as, unsigned n) | |
535 | { | |
536 | BUG_ON (as->argc < n); | |
537 | as->argc -= n; | |
538 | as->argv += n; | |
539 | } | |
540 | ||
541 | static int parse_path_selector(struct arg_set *as, struct priority_group *pg, | |
542 | struct dm_target *ti) | |
543 | { | |
544 | int r; | |
545 | struct path_selector_type *pst; | |
546 | unsigned ps_argc; | |
547 | ||
548 | static struct param _params[] = { | |
72d94861 | 549 | {0, 1024, "invalid number of path selector args"}, |
1da177e4 LT |
550 | }; |
551 | ||
552 | pst = dm_get_path_selector(shift(as)); | |
553 | if (!pst) { | |
72d94861 | 554 | ti->error = "unknown path selector type"; |
1da177e4 LT |
555 | return -EINVAL; |
556 | } | |
557 | ||
558 | r = read_param(_params, shift(as), &ps_argc, &ti->error); | |
371b2e34 MP |
559 | if (r) { |
560 | dm_put_path_selector(pst); | |
1da177e4 | 561 | return -EINVAL; |
371b2e34 | 562 | } |
1da177e4 | 563 | |
0e0497c0 MP |
564 | if (ps_argc > as->argc) { |
565 | dm_put_path_selector(pst); | |
566 | ti->error = "not enough arguments for path selector"; | |
567 | return -EINVAL; | |
568 | } | |
569 | ||
1da177e4 LT |
570 | r = pst->create(&pg->ps, ps_argc, as->argv); |
571 | if (r) { | |
572 | dm_put_path_selector(pst); | |
72d94861 | 573 | ti->error = "path selector constructor failed"; |
1da177e4 LT |
574 | return r; |
575 | } | |
576 | ||
577 | pg->ps.type = pst; | |
578 | consume(as, ps_argc); | |
579 | ||
580 | return 0; | |
581 | } | |
582 | ||
583 | static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps, | |
584 | struct dm_target *ti) | |
585 | { | |
586 | int r; | |
587 | struct pgpath *p; | |
ae11b1b3 | 588 | struct multipath *m = ti->private; |
1da177e4 LT |
589 | |
590 | /* we need at least a path arg */ | |
591 | if (as->argc < 1) { | |
72d94861 | 592 | ti->error = "no device given"; |
01460f35 | 593 | return ERR_PTR(-EINVAL); |
1da177e4 LT |
594 | } |
595 | ||
596 | p = alloc_pgpath(); | |
597 | if (!p) | |
01460f35 | 598 | return ERR_PTR(-ENOMEM); |
1da177e4 LT |
599 | |
600 | r = dm_get_device(ti, shift(as), ti->begin, ti->len, | |
601 | dm_table_get_mode(ti->table), &p->path.dev); | |
602 | if (r) { | |
72d94861 | 603 | ti->error = "error getting device"; |
1da177e4 LT |
604 | goto bad; |
605 | } | |
606 | ||
ae11b1b3 | 607 | if (m->hw_handler_name) { |
a0cf7ea9 HR |
608 | struct request_queue *q = bdev_get_queue(p->path.dev->bdev); |
609 | ||
610 | r = scsi_dh_attach(q, m->hw_handler_name); | |
611 | if (r == -EBUSY) { | |
612 | /* | |
613 | * Already attached to different hw_handler, | |
614 | * try to reattach with correct one. | |
615 | */ | |
616 | scsi_dh_detach(q); | |
617 | r = scsi_dh_attach(q, m->hw_handler_name); | |
618 | } | |
619 | ||
ae11b1b3 | 620 | if (r < 0) { |
a0cf7ea9 | 621 | ti->error = "error attaching hardware handler"; |
ae11b1b3 HR |
622 | dm_put_device(ti, p->path.dev); |
623 | goto bad; | |
624 | } | |
2bfd2e13 CS |
625 | |
626 | if (m->hw_handler_params) { | |
627 | r = scsi_dh_set_params(q, m->hw_handler_params); | |
628 | if (r < 0) { | |
629 | ti->error = "unable to set hardware " | |
630 | "handler parameters"; | |
631 | scsi_dh_detach(q); | |
632 | dm_put_device(ti, p->path.dev); | |
633 | goto bad; | |
634 | } | |
635 | } | |
ae11b1b3 HR |
636 | } |
637 | ||
1da177e4 LT |
638 | r = ps->type->add_path(ps, &p->path, as->argc, as->argv, &ti->error); |
639 | if (r) { | |
640 | dm_put_device(ti, p->path.dev); | |
641 | goto bad; | |
642 | } | |
643 | ||
644 | return p; | |
645 | ||
646 | bad: | |
647 | free_pgpath(p); | |
01460f35 | 648 | return ERR_PTR(r); |
1da177e4 LT |
649 | } |
650 | ||
651 | static struct priority_group *parse_priority_group(struct arg_set *as, | |
28f16c20 | 652 | struct multipath *m) |
1da177e4 LT |
653 | { |
654 | static struct param _params[] = { | |
72d94861 AK |
655 | {1, 1024, "invalid number of paths"}, |
656 | {0, 1024, "invalid number of selector args"} | |
1da177e4 LT |
657 | }; |
658 | ||
659 | int r; | |
660 | unsigned i, nr_selector_args, nr_params; | |
661 | struct priority_group *pg; | |
28f16c20 | 662 | struct dm_target *ti = m->ti; |
1da177e4 LT |
663 | |
664 | if (as->argc < 2) { | |
665 | as->argc = 0; | |
01460f35 BM |
666 | ti->error = "not enough priority group arguments"; |
667 | return ERR_PTR(-EINVAL); | |
1da177e4 LT |
668 | } |
669 | ||
670 | pg = alloc_priority_group(); | |
671 | if (!pg) { | |
72d94861 | 672 | ti->error = "couldn't allocate priority group"; |
01460f35 | 673 | return ERR_PTR(-ENOMEM); |
1da177e4 LT |
674 | } |
675 | pg->m = m; | |
676 | ||
677 | r = parse_path_selector(as, pg, ti); | |
678 | if (r) | |
679 | goto bad; | |
680 | ||
681 | /* | |
682 | * read the paths | |
683 | */ | |
684 | r = read_param(_params, shift(as), &pg->nr_pgpaths, &ti->error); | |
685 | if (r) | |
686 | goto bad; | |
687 | ||
688 | r = read_param(_params + 1, shift(as), &nr_selector_args, &ti->error); | |
689 | if (r) | |
690 | goto bad; | |
691 | ||
692 | nr_params = 1 + nr_selector_args; | |
693 | for (i = 0; i < pg->nr_pgpaths; i++) { | |
694 | struct pgpath *pgpath; | |
695 | struct arg_set path_args; | |
696 | ||
148acff6 MP |
697 | if (as->argc < nr_params) { |
698 | ti->error = "not enough path parameters"; | |
1da177e4 | 699 | goto bad; |
148acff6 | 700 | } |
1da177e4 LT |
701 | |
702 | path_args.argc = nr_params; | |
703 | path_args.argv = as->argv; | |
704 | ||
705 | pgpath = parse_path(&path_args, &pg->ps, ti); | |
01460f35 BM |
706 | if (IS_ERR(pgpath)) { |
707 | r = PTR_ERR(pgpath); | |
1da177e4 | 708 | goto bad; |
01460f35 | 709 | } |
1da177e4 LT |
710 | |
711 | pgpath->pg = pg; | |
712 | list_add_tail(&pgpath->list, &pg->pgpaths); | |
713 | consume(as, nr_params); | |
714 | } | |
715 | ||
716 | return pg; | |
717 | ||
718 | bad: | |
719 | free_priority_group(pg, ti); | |
01460f35 | 720 | return ERR_PTR(r); |
1da177e4 LT |
721 | } |
722 | ||
28f16c20 | 723 | static int parse_hw_handler(struct arg_set *as, struct multipath *m) |
1da177e4 | 724 | { |
1da177e4 | 725 | unsigned hw_argc; |
2bfd2e13 | 726 | int ret; |
28f16c20 | 727 | struct dm_target *ti = m->ti; |
1da177e4 LT |
728 | |
729 | static struct param _params[] = { | |
72d94861 | 730 | {0, 1024, "invalid number of hardware handler args"}, |
1da177e4 LT |
731 | }; |
732 | ||
cfae5c9b | 733 | if (read_param(_params, shift(as), &hw_argc, &ti->error)) |
1da177e4 LT |
734 | return -EINVAL; |
735 | ||
736 | if (!hw_argc) | |
737 | return 0; | |
738 | ||
e094f4f1 MP |
739 | if (hw_argc > as->argc) { |
740 | ti->error = "not enough arguments for hardware handler"; | |
741 | return -EINVAL; | |
742 | } | |
743 | ||
cfae5c9b CS |
744 | m->hw_handler_name = kstrdup(shift(as), GFP_KERNEL); |
745 | request_module("scsi_dh_%s", m->hw_handler_name); | |
746 | if (scsi_dh_handler_exist(m->hw_handler_name) == 0) { | |
72d94861 | 747 | ti->error = "unknown hardware handler type"; |
2bfd2e13 CS |
748 | ret = -EINVAL; |
749 | goto fail; | |
1da177e4 | 750 | } |
14e98c5c | 751 | |
2bfd2e13 CS |
752 | if (hw_argc > 1) { |
753 | char *p; | |
754 | int i, j, len = 4; | |
755 | ||
756 | for (i = 0; i <= hw_argc - 2; i++) | |
757 | len += strlen(as->argv[i]) + 1; | |
758 | p = m->hw_handler_params = kzalloc(len, GFP_KERNEL); | |
759 | if (!p) { | |
760 | ti->error = "memory allocation failed"; | |
761 | ret = -ENOMEM; | |
762 | goto fail; | |
763 | } | |
764 | j = sprintf(p, "%d", hw_argc - 1); | |
765 | for (i = 0, p+=j+1; i <= hw_argc - 2; i++, p+=j+1) | |
766 | j = sprintf(p, "%s", as->argv[i]); | |
767 | } | |
1da177e4 LT |
768 | consume(as, hw_argc - 1); |
769 | ||
770 | return 0; | |
2bfd2e13 CS |
771 | fail: |
772 | kfree(m->hw_handler_name); | |
773 | m->hw_handler_name = NULL; | |
774 | return ret; | |
1da177e4 LT |
775 | } |
776 | ||
28f16c20 | 777 | static int parse_features(struct arg_set *as, struct multipath *m) |
1da177e4 LT |
778 | { |
779 | int r; | |
780 | unsigned argc; | |
28f16c20 | 781 | struct dm_target *ti = m->ti; |
c9e45581 | 782 | const char *param_name; |
1da177e4 LT |
783 | |
784 | static struct param _params[] = { | |
c9e45581 DW |
785 | {0, 3, "invalid number of feature args"}, |
786 | {1, 50, "pg_init_retries must be between 1 and 50"}, | |
1da177e4 LT |
787 | }; |
788 | ||
789 | r = read_param(_params, shift(as), &argc, &ti->error); | |
790 | if (r) | |
791 | return -EINVAL; | |
792 | ||
793 | if (!argc) | |
794 | return 0; | |
795 | ||
c9e45581 DW |
796 | do { |
797 | param_name = shift(as); | |
798 | argc--; | |
799 | ||
800 | if (!strnicmp(param_name, MESG_STR("queue_if_no_path"))) { | |
801 | r = queue_if_no_path(m, 1, 0); | |
802 | continue; | |
803 | } | |
804 | ||
805 | if (!strnicmp(param_name, MESG_STR("pg_init_retries")) && | |
806 | (argc >= 1)) { | |
807 | r = read_param(_params + 1, shift(as), | |
808 | &m->pg_init_retries, &ti->error); | |
809 | argc--; | |
810 | continue; | |
811 | } | |
812 | ||
1da177e4 | 813 | ti->error = "Unrecognised multipath feature request"; |
c9e45581 DW |
814 | r = -EINVAL; |
815 | } while (argc && !r); | |
816 | ||
817 | return r; | |
1da177e4 LT |
818 | } |
819 | ||
820 | static int multipath_ctr(struct dm_target *ti, unsigned int argc, | |
821 | char **argv) | |
822 | { | |
823 | /* target parameters */ | |
824 | static struct param _params[] = { | |
72d94861 AK |
825 | {1, 1024, "invalid number of priority groups"}, |
826 | {1, 1024, "invalid initial priority group number"}, | |
1da177e4 LT |
827 | }; |
828 | ||
829 | int r; | |
830 | struct multipath *m; | |
831 | struct arg_set as; | |
832 | unsigned pg_count = 0; | |
833 | unsigned next_pg_num; | |
834 | ||
835 | as.argc = argc; | |
836 | as.argv = argv; | |
837 | ||
28f16c20 | 838 | m = alloc_multipath(ti); |
1da177e4 | 839 | if (!m) { |
72d94861 | 840 | ti->error = "can't allocate multipath"; |
1da177e4 LT |
841 | return -EINVAL; |
842 | } | |
843 | ||
28f16c20 | 844 | r = parse_features(&as, m); |
1da177e4 LT |
845 | if (r) |
846 | goto bad; | |
847 | ||
28f16c20 | 848 | r = parse_hw_handler(&as, m); |
1da177e4 LT |
849 | if (r) |
850 | goto bad; | |
851 | ||
852 | r = read_param(_params, shift(&as), &m->nr_priority_groups, &ti->error); | |
853 | if (r) | |
854 | goto bad; | |
855 | ||
856 | r = read_param(_params + 1, shift(&as), &next_pg_num, &ti->error); | |
857 | if (r) | |
858 | goto bad; | |
859 | ||
860 | /* parse the priority groups */ | |
861 | while (as.argc) { | |
862 | struct priority_group *pg; | |
863 | ||
28f16c20 | 864 | pg = parse_priority_group(&as, m); |
01460f35 BM |
865 | if (IS_ERR(pg)) { |
866 | r = PTR_ERR(pg); | |
1da177e4 LT |
867 | goto bad; |
868 | } | |
869 | ||
870 | m->nr_valid_paths += pg->nr_pgpaths; | |
871 | list_add_tail(&pg->list, &m->priority_groups); | |
872 | pg_count++; | |
873 | pg->pg_num = pg_count; | |
874 | if (!--next_pg_num) | |
875 | m->next_pg = pg; | |
876 | } | |
877 | ||
878 | if (pg_count != m->nr_priority_groups) { | |
72d94861 | 879 | ti->error = "priority group count mismatch"; |
1da177e4 LT |
880 | r = -EINVAL; |
881 | goto bad; | |
882 | } | |
883 | ||
8627921f MP |
884 | ti->num_flush_requests = 1; |
885 | ||
1da177e4 LT |
886 | return 0; |
887 | ||
888 | bad: | |
889 | free_multipath(m); | |
890 | return r; | |
891 | } | |
892 | ||
6df400ab | 893 | static void flush_multipath_work(void) |
1da177e4 | 894 | { |
bab7cfc7 | 895 | flush_workqueue(kmpath_handlerd); |
a044d016 | 896 | flush_workqueue(kmultipathd); |
53b351f9 | 897 | flush_scheduled_work(); |
6df400ab KU |
898 | } |
899 | ||
900 | static void multipath_dtr(struct dm_target *ti) | |
901 | { | |
902 | struct multipath *m = ti->private; | |
903 | ||
904 | flush_multipath_work(); | |
1da177e4 LT |
905 | free_multipath(m); |
906 | } | |
907 | ||
908 | /* | |
f40c67f0 | 909 | * Map cloned requests |
1da177e4 | 910 | */ |
f40c67f0 | 911 | static int multipath_map(struct dm_target *ti, struct request *clone, |
1da177e4 LT |
912 | union map_info *map_context) |
913 | { | |
914 | int r; | |
028867ac | 915 | struct dm_mpath_io *mpio; |
1da177e4 LT |
916 | struct multipath *m = (struct multipath *) ti->private; |
917 | ||
f40c67f0 KU |
918 | mpio = mempool_alloc(m->mpio_pool, GFP_ATOMIC); |
919 | if (!mpio) | |
920 | /* ENOMEM, requeue */ | |
921 | return DM_MAPIO_REQUEUE; | |
922 | memset(mpio, 0, sizeof(*mpio)); | |
1da177e4 LT |
923 | |
924 | map_context->ptr = mpio; | |
f40c67f0 KU |
925 | clone->cmd_flags |= REQ_FAILFAST_TRANSPORT; |
926 | r = map_io(m, clone, mpio, 0); | |
45e15720 | 927 | if (r < 0 || r == DM_MAPIO_REQUEUE) |
1da177e4 LT |
928 | mempool_free(mpio, m->mpio_pool); |
929 | ||
930 | return r; | |
931 | } | |
932 | ||
933 | /* | |
934 | * Take a path out of use. | |
935 | */ | |
936 | static int fail_path(struct pgpath *pgpath) | |
937 | { | |
938 | unsigned long flags; | |
939 | struct multipath *m = pgpath->pg->m; | |
940 | ||
941 | spin_lock_irqsave(&m->lock, flags); | |
942 | ||
6680073d | 943 | if (!pgpath->is_active) |
1da177e4 LT |
944 | goto out; |
945 | ||
72d94861 | 946 | DMWARN("Failing path %s.", pgpath->path.dev->name); |
1da177e4 LT |
947 | |
948 | pgpath->pg->ps.type->fail_path(&pgpath->pg->ps, &pgpath->path); | |
6680073d | 949 | pgpath->is_active = 0; |
1da177e4 LT |
950 | pgpath->fail_count++; |
951 | ||
952 | m->nr_valid_paths--; | |
953 | ||
954 | if (pgpath == m->current_pgpath) | |
955 | m->current_pgpath = NULL; | |
956 | ||
b15546f9 MA |
957 | dm_path_uevent(DM_UEVENT_PATH_FAILED, m->ti, |
958 | pgpath->path.dev->name, m->nr_valid_paths); | |
959 | ||
fe9cf30e | 960 | schedule_work(&m->trigger_event); |
224cb3e9 | 961 | queue_work(kmultipathd, &pgpath->deactivate_path); |
1da177e4 LT |
962 | |
963 | out: | |
964 | spin_unlock_irqrestore(&m->lock, flags); | |
965 | ||
966 | return 0; | |
967 | } | |
968 | ||
969 | /* | |
970 | * Reinstate a previously-failed path | |
971 | */ | |
972 | static int reinstate_path(struct pgpath *pgpath) | |
973 | { | |
974 | int r = 0; | |
975 | unsigned long flags; | |
976 | struct multipath *m = pgpath->pg->m; | |
977 | ||
978 | spin_lock_irqsave(&m->lock, flags); | |
979 | ||
6680073d | 980 | if (pgpath->is_active) |
1da177e4 LT |
981 | goto out; |
982 | ||
def052d2 | 983 | if (!pgpath->pg->ps.type->reinstate_path) { |
1da177e4 LT |
984 | DMWARN("Reinstate path not supported by path selector %s", |
985 | pgpath->pg->ps.type->name); | |
986 | r = -EINVAL; | |
987 | goto out; | |
988 | } | |
989 | ||
990 | r = pgpath->pg->ps.type->reinstate_path(&pgpath->pg->ps, &pgpath->path); | |
991 | if (r) | |
992 | goto out; | |
993 | ||
6680073d | 994 | pgpath->is_active = 1; |
1da177e4 | 995 | |
e54f77dd CS |
996 | if (!m->nr_valid_paths++ && m->queue_size) { |
997 | m->current_pgpath = NULL; | |
c557308e | 998 | queue_work(kmultipathd, &m->process_queued_ios); |
e54f77dd CS |
999 | } else if (m->hw_handler_name && (m->current_pg == pgpath->pg)) { |
1000 | if (queue_work(kmpath_handlerd, &pgpath->activate_path)) | |
1001 | m->pg_init_in_progress++; | |
1002 | } | |
1da177e4 | 1003 | |
b15546f9 MA |
1004 | dm_path_uevent(DM_UEVENT_PATH_REINSTATED, m->ti, |
1005 | pgpath->path.dev->name, m->nr_valid_paths); | |
1006 | ||
fe9cf30e | 1007 | schedule_work(&m->trigger_event); |
1da177e4 LT |
1008 | |
1009 | out: | |
1010 | spin_unlock_irqrestore(&m->lock, flags); | |
1011 | ||
1012 | return r; | |
1013 | } | |
1014 | ||
1015 | /* | |
1016 | * Fail or reinstate all paths that match the provided struct dm_dev. | |
1017 | */ | |
1018 | static int action_dev(struct multipath *m, struct dm_dev *dev, | |
1019 | action_fn action) | |
1020 | { | |
1021 | int r = 0; | |
1022 | struct pgpath *pgpath; | |
1023 | struct priority_group *pg; | |
1024 | ||
1025 | list_for_each_entry(pg, &m->priority_groups, list) { | |
1026 | list_for_each_entry(pgpath, &pg->pgpaths, list) { | |
1027 | if (pgpath->path.dev == dev) | |
1028 | r = action(pgpath); | |
1029 | } | |
1030 | } | |
1031 | ||
1032 | return r; | |
1033 | } | |
1034 | ||
1035 | /* | |
1036 | * Temporarily try to avoid having to use the specified PG | |
1037 | */ | |
1038 | static void bypass_pg(struct multipath *m, struct priority_group *pg, | |
1039 | int bypassed) | |
1040 | { | |
1041 | unsigned long flags; | |
1042 | ||
1043 | spin_lock_irqsave(&m->lock, flags); | |
1044 | ||
1045 | pg->bypassed = bypassed; | |
1046 | m->current_pgpath = NULL; | |
1047 | m->current_pg = NULL; | |
1048 | ||
1049 | spin_unlock_irqrestore(&m->lock, flags); | |
1050 | ||
fe9cf30e | 1051 | schedule_work(&m->trigger_event); |
1da177e4 LT |
1052 | } |
1053 | ||
1054 | /* | |
1055 | * Switch to using the specified PG from the next I/O that gets mapped | |
1056 | */ | |
1057 | static int switch_pg_num(struct multipath *m, const char *pgstr) | |
1058 | { | |
1059 | struct priority_group *pg; | |
1060 | unsigned pgnum; | |
1061 | unsigned long flags; | |
1062 | ||
1063 | if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum || | |
1064 | (pgnum > m->nr_priority_groups)) { | |
1065 | DMWARN("invalid PG number supplied to switch_pg_num"); | |
1066 | return -EINVAL; | |
1067 | } | |
1068 | ||
1069 | spin_lock_irqsave(&m->lock, flags); | |
1070 | list_for_each_entry(pg, &m->priority_groups, list) { | |
1071 | pg->bypassed = 0; | |
1072 | if (--pgnum) | |
1073 | continue; | |
1074 | ||
1075 | m->current_pgpath = NULL; | |
1076 | m->current_pg = NULL; | |
1077 | m->next_pg = pg; | |
1078 | } | |
1079 | spin_unlock_irqrestore(&m->lock, flags); | |
1080 | ||
fe9cf30e | 1081 | schedule_work(&m->trigger_event); |
1da177e4 LT |
1082 | return 0; |
1083 | } | |
1084 | ||
1085 | /* | |
1086 | * Set/clear bypassed status of a PG. | |
1087 | * PGs are numbered upwards from 1 in the order they were declared. | |
1088 | */ | |
1089 | static int bypass_pg_num(struct multipath *m, const char *pgstr, int bypassed) | |
1090 | { | |
1091 | struct priority_group *pg; | |
1092 | unsigned pgnum; | |
1093 | ||
1094 | if (!pgstr || (sscanf(pgstr, "%u", &pgnum) != 1) || !pgnum || | |
1095 | (pgnum > m->nr_priority_groups)) { | |
1096 | DMWARN("invalid PG number supplied to bypass_pg"); | |
1097 | return -EINVAL; | |
1098 | } | |
1099 | ||
1100 | list_for_each_entry(pg, &m->priority_groups, list) { | |
1101 | if (!--pgnum) | |
1102 | break; | |
1103 | } | |
1104 | ||
1105 | bypass_pg(m, pg, bypassed); | |
1106 | return 0; | |
1107 | } | |
1108 | ||
c9e45581 DW |
1109 | /* |
1110 | * Should we retry pg_init immediately? | |
1111 | */ | |
1112 | static int pg_init_limit_reached(struct multipath *m, struct pgpath *pgpath) | |
1113 | { | |
1114 | unsigned long flags; | |
1115 | int limit_reached = 0; | |
1116 | ||
1117 | spin_lock_irqsave(&m->lock, flags); | |
1118 | ||
1119 | if (m->pg_init_count <= m->pg_init_retries) | |
1120 | m->pg_init_required = 1; | |
1121 | else | |
1122 | limit_reached = 1; | |
1123 | ||
1124 | spin_unlock_irqrestore(&m->lock, flags); | |
1125 | ||
1126 | return limit_reached; | |
1127 | } | |
1128 | ||
3ae31f6a | 1129 | static void pg_init_done(void *data, int errors) |
cfae5c9b | 1130 | { |
83c0d5d5 | 1131 | struct pgpath *pgpath = data; |
cfae5c9b CS |
1132 | struct priority_group *pg = pgpath->pg; |
1133 | struct multipath *m = pg->m; | |
1134 | unsigned long flags; | |
1135 | ||
1136 | /* device or driver problems */ | |
1137 | switch (errors) { | |
1138 | case SCSI_DH_OK: | |
1139 | break; | |
1140 | case SCSI_DH_NOSYS: | |
1141 | if (!m->hw_handler_name) { | |
1142 | errors = 0; | |
1143 | break; | |
1144 | } | |
1145 | DMERR("Cannot failover device because scsi_dh_%s was not " | |
1146 | "loaded.", m->hw_handler_name); | |
1147 | /* | |
1148 | * Fail path for now, so we do not ping pong | |
1149 | */ | |
1150 | fail_path(pgpath); | |
1151 | break; | |
1152 | case SCSI_DH_DEV_TEMP_BUSY: | |
1153 | /* | |
1154 | * Probably doing something like FW upgrade on the | |
1155 | * controller so try the other pg. | |
1156 | */ | |
1157 | bypass_pg(m, pg, 1); | |
1158 | break; | |
1159 | /* TODO: For SCSI_DH_RETRY we should wait a couple seconds */ | |
1160 | case SCSI_DH_RETRY: | |
1161 | case SCSI_DH_IMM_RETRY: | |
1162 | case SCSI_DH_RES_TEMP_UNAVAIL: | |
1163 | if (pg_init_limit_reached(m, pgpath)) | |
1164 | fail_path(pgpath); | |
1165 | errors = 0; | |
1166 | break; | |
1167 | default: | |
1168 | /* | |
1169 | * We probably do not want to fail the path for a device | |
1170 | * error, but this is what the old dm did. In future | |
1171 | * patches we can do more advanced handling. | |
1172 | */ | |
1173 | fail_path(pgpath); | |
1174 | } | |
1175 | ||
1176 | spin_lock_irqsave(&m->lock, flags); | |
1177 | if (errors) { | |
e54f77dd CS |
1178 | if (pgpath == m->current_pgpath) { |
1179 | DMERR("Could not failover device. Error %d.", errors); | |
1180 | m->current_pgpath = NULL; | |
1181 | m->current_pg = NULL; | |
1182 | } | |
cfae5c9b CS |
1183 | } else if (!m->pg_init_required) { |
1184 | m->queue_io = 0; | |
1185 | pg->bypassed = 0; | |
1186 | } | |
1187 | ||
e54f77dd CS |
1188 | m->pg_init_in_progress--; |
1189 | if (!m->pg_init_in_progress) | |
1190 | queue_work(kmultipathd, &m->process_queued_ios); | |
cfae5c9b CS |
1191 | spin_unlock_irqrestore(&m->lock, flags); |
1192 | } | |
1193 | ||
bab7cfc7 CS |
1194 | static void activate_path(struct work_struct *work) |
1195 | { | |
e54f77dd CS |
1196 | struct pgpath *pgpath = |
1197 | container_of(work, struct pgpath, activate_path); | |
bab7cfc7 | 1198 | |
3ae31f6a | 1199 | scsi_dh_activate(bdev_get_queue(pgpath->path.dev->bdev), |
83c0d5d5 | 1200 | pg_init_done, pgpath); |
bab7cfc7 CS |
1201 | } |
1202 | ||
1da177e4 LT |
1203 | /* |
1204 | * end_io handling | |
1205 | */ | |
f40c67f0 | 1206 | static int do_end_io(struct multipath *m, struct request *clone, |
028867ac | 1207 | int error, struct dm_mpath_io *mpio) |
1da177e4 | 1208 | { |
f40c67f0 KU |
1209 | /* |
1210 | * We don't queue any clone request inside the multipath target | |
1211 | * during end I/O handling, since those clone requests don't have | |
1212 | * bio clones. If we queue them inside the multipath target, | |
1213 | * we need to make bio clones, that requires memory allocation. | |
1214 | * (See drivers/md/dm.c:end_clone_bio() about why the clone requests | |
1215 | * don't have bio clones.) | |
1216 | * Instead of queueing the clone request here, we queue the original | |
1217 | * request into dm core, which will remake a clone request and | |
1218 | * clone bios for it and resubmit it later. | |
1219 | */ | |
1220 | int r = DM_ENDIO_REQUEUE; | |
640eb3b0 | 1221 | unsigned long flags; |
1da177e4 | 1222 | |
f40c67f0 | 1223 | if (!error && !clone->errors) |
1da177e4 LT |
1224 | return 0; /* I/O complete */ |
1225 | ||
f6a80ea8 AK |
1226 | if (error == -EOPNOTSUPP) |
1227 | return error; | |
1228 | ||
cfae5c9b CS |
1229 | if (mpio->pgpath) |
1230 | fail_path(mpio->pgpath); | |
1da177e4 | 1231 | |
640eb3b0 | 1232 | spin_lock_irqsave(&m->lock, flags); |
f40c67f0 KU |
1233 | if (!m->nr_valid_paths && !m->queue_if_no_path && !__must_push_back(m)) |
1234 | r = -EIO; | |
640eb3b0 | 1235 | spin_unlock_irqrestore(&m->lock, flags); |
1da177e4 | 1236 | |
f40c67f0 | 1237 | return r; |
1da177e4 LT |
1238 | } |
1239 | ||
f40c67f0 | 1240 | static int multipath_end_io(struct dm_target *ti, struct request *clone, |
1da177e4 LT |
1241 | int error, union map_info *map_context) |
1242 | { | |
028867ac AK |
1243 | struct multipath *m = ti->private; |
1244 | struct dm_mpath_io *mpio = map_context->ptr; | |
1da177e4 LT |
1245 | struct pgpath *pgpath = mpio->pgpath; |
1246 | struct path_selector *ps; | |
1247 | int r; | |
1248 | ||
f40c67f0 | 1249 | r = do_end_io(m, clone, error, mpio); |
1da177e4 LT |
1250 | if (pgpath) { |
1251 | ps = &pgpath->pg->ps; | |
1252 | if (ps->type->end_io) | |
02ab823f | 1253 | ps->type->end_io(ps, &pgpath->path, mpio->nr_bytes); |
1da177e4 | 1254 | } |
f40c67f0 | 1255 | mempool_free(mpio, m->mpio_pool); |
1da177e4 LT |
1256 | |
1257 | return r; | |
1258 | } | |
1259 | ||
1260 | /* | |
1261 | * Suspend can't complete until all the I/O is processed so if | |
436d4108 AK |
1262 | * the last path fails we must error any remaining I/O. |
1263 | * Note that if the freeze_bdev fails while suspending, the | |
1264 | * queue_if_no_path state is lost - userspace should reset it. | |
1da177e4 LT |
1265 | */ |
1266 | static void multipath_presuspend(struct dm_target *ti) | |
1267 | { | |
1268 | struct multipath *m = (struct multipath *) ti->private; | |
1da177e4 | 1269 | |
485ef69e | 1270 | queue_if_no_path(m, 0, 1); |
1da177e4 LT |
1271 | } |
1272 | ||
6df400ab KU |
1273 | static void multipath_postsuspend(struct dm_target *ti) |
1274 | { | |
6380f26f MA |
1275 | struct multipath *m = ti->private; |
1276 | ||
1277 | mutex_lock(&m->work_mutex); | |
67a46dad | 1278 | m->suspended = 1; |
6df400ab | 1279 | flush_multipath_work(); |
6380f26f | 1280 | mutex_unlock(&m->work_mutex); |
6df400ab KU |
1281 | } |
1282 | ||
436d4108 AK |
1283 | /* |
1284 | * Restore the queue_if_no_path setting. | |
1285 | */ | |
1da177e4 LT |
1286 | static void multipath_resume(struct dm_target *ti) |
1287 | { | |
1288 | struct multipath *m = (struct multipath *) ti->private; | |
1289 | unsigned long flags; | |
1290 | ||
67a46dad MA |
1291 | mutex_lock(&m->work_mutex); |
1292 | m->suspended = 0; | |
1293 | mutex_unlock(&m->work_mutex); | |
1294 | ||
1da177e4 | 1295 | spin_lock_irqsave(&m->lock, flags); |
436d4108 | 1296 | m->queue_if_no_path = m->saved_queue_if_no_path; |
1da177e4 LT |
1297 | spin_unlock_irqrestore(&m->lock, flags); |
1298 | } | |
1299 | ||
1300 | /* | |
1301 | * Info output has the following format: | |
1302 | * num_multipath_feature_args [multipath_feature_args]* | |
1303 | * num_handler_status_args [handler_status_args]* | |
1304 | * num_groups init_group_number | |
1305 | * [A|D|E num_ps_status_args [ps_status_args]* | |
1306 | * num_paths num_selector_args | |
1307 | * [path_dev A|F fail_count [selector_args]* ]+ ]+ | |
1308 | * | |
1309 | * Table output has the following format (identical to the constructor string): | |
1310 | * num_feature_args [features_args]* | |
1311 | * num_handler_args hw_handler [hw_handler_args]* | |
1312 | * num_groups init_group_number | |
1313 | * [priority selector-name num_ps_args [ps_args]* | |
1314 | * num_paths num_selector_args [path_dev [selector_args]* ]+ ]+ | |
1315 | */ | |
1316 | static int multipath_status(struct dm_target *ti, status_type_t type, | |
1317 | char *result, unsigned int maxlen) | |
1318 | { | |
1319 | int sz = 0; | |
1320 | unsigned long flags; | |
1321 | struct multipath *m = (struct multipath *) ti->private; | |
1da177e4 LT |
1322 | struct priority_group *pg; |
1323 | struct pgpath *p; | |
1324 | unsigned pg_num; | |
1325 | char state; | |
1326 | ||
1327 | spin_lock_irqsave(&m->lock, flags); | |
1328 | ||
1329 | /* Features */ | |
1330 | if (type == STATUSTYPE_INFO) | |
c9e45581 DW |
1331 | DMEMIT("2 %u %u ", m->queue_size, m->pg_init_count); |
1332 | else { | |
1333 | DMEMIT("%u ", m->queue_if_no_path + | |
1334 | (m->pg_init_retries > 0) * 2); | |
1335 | if (m->queue_if_no_path) | |
1336 | DMEMIT("queue_if_no_path "); | |
1337 | if (m->pg_init_retries) | |
1338 | DMEMIT("pg_init_retries %u ", m->pg_init_retries); | |
1339 | } | |
1da177e4 | 1340 | |
cfae5c9b | 1341 | if (!m->hw_handler_name || type == STATUSTYPE_INFO) |
1da177e4 LT |
1342 | DMEMIT("0 "); |
1343 | else | |
cfae5c9b | 1344 | DMEMIT("1 %s ", m->hw_handler_name); |
1da177e4 LT |
1345 | |
1346 | DMEMIT("%u ", m->nr_priority_groups); | |
1347 | ||
1348 | if (m->next_pg) | |
1349 | pg_num = m->next_pg->pg_num; | |
1350 | else if (m->current_pg) | |
1351 | pg_num = m->current_pg->pg_num; | |
1352 | else | |
1353 | pg_num = 1; | |
1354 | ||
1355 | DMEMIT("%u ", pg_num); | |
1356 | ||
1357 | switch (type) { | |
1358 | case STATUSTYPE_INFO: | |
1359 | list_for_each_entry(pg, &m->priority_groups, list) { | |
1360 | if (pg->bypassed) | |
1361 | state = 'D'; /* Disabled */ | |
1362 | else if (pg == m->current_pg) | |
1363 | state = 'A'; /* Currently Active */ | |
1364 | else | |
1365 | state = 'E'; /* Enabled */ | |
1366 | ||
1367 | DMEMIT("%c ", state); | |
1368 | ||
1369 | if (pg->ps.type->status) | |
1370 | sz += pg->ps.type->status(&pg->ps, NULL, type, | |
1371 | result + sz, | |
1372 | maxlen - sz); | |
1373 | else | |
1374 | DMEMIT("0 "); | |
1375 | ||
1376 | DMEMIT("%u %u ", pg->nr_pgpaths, | |
1377 | pg->ps.type->info_args); | |
1378 | ||
1379 | list_for_each_entry(p, &pg->pgpaths, list) { | |
1380 | DMEMIT("%s %s %u ", p->path.dev->name, | |
6680073d | 1381 | p->is_active ? "A" : "F", |
1da177e4 LT |
1382 | p->fail_count); |
1383 | if (pg->ps.type->status) | |
1384 | sz += pg->ps.type->status(&pg->ps, | |
1385 | &p->path, type, result + sz, | |
1386 | maxlen - sz); | |
1387 | } | |
1388 | } | |
1389 | break; | |
1390 | ||
1391 | case STATUSTYPE_TABLE: | |
1392 | list_for_each_entry(pg, &m->priority_groups, list) { | |
1393 | DMEMIT("%s ", pg->ps.type->name); | |
1394 | ||
1395 | if (pg->ps.type->status) | |
1396 | sz += pg->ps.type->status(&pg->ps, NULL, type, | |
1397 | result + sz, | |
1398 | maxlen - sz); | |
1399 | else | |
1400 | DMEMIT("0 "); | |
1401 | ||
1402 | DMEMIT("%u %u ", pg->nr_pgpaths, | |
1403 | pg->ps.type->table_args); | |
1404 | ||
1405 | list_for_each_entry(p, &pg->pgpaths, list) { | |
1406 | DMEMIT("%s ", p->path.dev->name); | |
1407 | if (pg->ps.type->status) | |
1408 | sz += pg->ps.type->status(&pg->ps, | |
1409 | &p->path, type, result + sz, | |
1410 | maxlen - sz); | |
1411 | } | |
1412 | } | |
1413 | break; | |
1414 | } | |
1415 | ||
1416 | spin_unlock_irqrestore(&m->lock, flags); | |
1417 | ||
1418 | return 0; | |
1419 | } | |
1420 | ||
1421 | static int multipath_message(struct dm_target *ti, unsigned argc, char **argv) | |
1422 | { | |
6380f26f | 1423 | int r = -EINVAL; |
1da177e4 LT |
1424 | struct dm_dev *dev; |
1425 | struct multipath *m = (struct multipath *) ti->private; | |
1426 | action_fn action; | |
1427 | ||
6380f26f MA |
1428 | mutex_lock(&m->work_mutex); |
1429 | ||
67a46dad MA |
1430 | if (m->suspended) { |
1431 | r = -EBUSY; | |
1432 | goto out; | |
1433 | } | |
1434 | ||
c2f3d24b KU |
1435 | if (dm_suspended(ti)) { |
1436 | r = -EBUSY; | |
1437 | goto out; | |
1438 | } | |
1439 | ||
1da177e4 | 1440 | if (argc == 1) { |
6380f26f MA |
1441 | if (!strnicmp(argv[0], MESG_STR("queue_if_no_path"))) { |
1442 | r = queue_if_no_path(m, 1, 0); | |
1443 | goto out; | |
1444 | } else if (!strnicmp(argv[0], MESG_STR("fail_if_no_path"))) { | |
1445 | r = queue_if_no_path(m, 0, 0); | |
1446 | goto out; | |
1447 | } | |
1da177e4 LT |
1448 | } |
1449 | ||
6380f26f MA |
1450 | if (argc != 2) { |
1451 | DMWARN("Unrecognised multipath message received."); | |
1452 | goto out; | |
1453 | } | |
1da177e4 | 1454 | |
6380f26f MA |
1455 | if (!strnicmp(argv[0], MESG_STR("disable_group"))) { |
1456 | r = bypass_pg_num(m, argv[1], 1); | |
1457 | goto out; | |
1458 | } else if (!strnicmp(argv[0], MESG_STR("enable_group"))) { | |
1459 | r = bypass_pg_num(m, argv[1], 0); | |
1460 | goto out; | |
1461 | } else if (!strnicmp(argv[0], MESG_STR("switch_group"))) { | |
1462 | r = switch_pg_num(m, argv[1]); | |
1463 | goto out; | |
1464 | } else if (!strnicmp(argv[0], MESG_STR("reinstate_path"))) | |
1da177e4 LT |
1465 | action = reinstate_path; |
1466 | else if (!strnicmp(argv[0], MESG_STR("fail_path"))) | |
1467 | action = fail_path; | |
6380f26f MA |
1468 | else { |
1469 | DMWARN("Unrecognised multipath message received."); | |
1470 | goto out; | |
1471 | } | |
1da177e4 LT |
1472 | |
1473 | r = dm_get_device(ti, argv[1], ti->begin, ti->len, | |
1474 | dm_table_get_mode(ti->table), &dev); | |
1475 | if (r) { | |
72d94861 | 1476 | DMWARN("message: error getting device %s", |
1da177e4 | 1477 | argv[1]); |
6380f26f | 1478 | goto out; |
1da177e4 LT |
1479 | } |
1480 | ||
1481 | r = action_dev(m, dev, action); | |
1482 | ||
1483 | dm_put_device(ti, dev); | |
1484 | ||
6380f26f MA |
1485 | out: |
1486 | mutex_unlock(&m->work_mutex); | |
1da177e4 | 1487 | return r; |
1da177e4 LT |
1488 | } |
1489 | ||
647b3d00 | 1490 | static int multipath_ioctl(struct dm_target *ti, unsigned int cmd, |
9af4aa30 MB |
1491 | unsigned long arg) |
1492 | { | |
1493 | struct multipath *m = (struct multipath *) ti->private; | |
1494 | struct block_device *bdev = NULL; | |
633a08b8 | 1495 | fmode_t mode = 0; |
9af4aa30 MB |
1496 | unsigned long flags; |
1497 | int r = 0; | |
1498 | ||
1499 | spin_lock_irqsave(&m->lock, flags); | |
1500 | ||
1501 | if (!m->current_pgpath) | |
02ab823f | 1502 | __choose_pgpath(m, 0); |
9af4aa30 | 1503 | |
e90dae1f | 1504 | if (m->current_pgpath) { |
9af4aa30 | 1505 | bdev = m->current_pgpath->path.dev->bdev; |
633a08b8 | 1506 | mode = m->current_pgpath->path.dev->mode; |
e90dae1f | 1507 | } |
9af4aa30 MB |
1508 | |
1509 | if (m->queue_io) | |
1510 | r = -EAGAIN; | |
1511 | else if (!bdev) | |
1512 | r = -EIO; | |
1513 | ||
1514 | spin_unlock_irqrestore(&m->lock, flags); | |
1515 | ||
633a08b8 | 1516 | return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg); |
9af4aa30 MB |
1517 | } |
1518 | ||
af4874e0 MS |
1519 | static int multipath_iterate_devices(struct dm_target *ti, |
1520 | iterate_devices_callout_fn fn, void *data) | |
1521 | { | |
1522 | struct multipath *m = ti->private; | |
1523 | struct priority_group *pg; | |
1524 | struct pgpath *p; | |
1525 | int ret = 0; | |
1526 | ||
1527 | list_for_each_entry(pg, &m->priority_groups, list) { | |
1528 | list_for_each_entry(p, &pg->pgpaths, list) { | |
5dea271b | 1529 | ret = fn(ti, p->path.dev, ti->begin, ti->len, data); |
af4874e0 MS |
1530 | if (ret) |
1531 | goto out; | |
1532 | } | |
1533 | } | |
1534 | ||
1535 | out: | |
1536 | return ret; | |
1537 | } | |
1538 | ||
f40c67f0 KU |
1539 | static int __pgpath_busy(struct pgpath *pgpath) |
1540 | { | |
1541 | struct request_queue *q = bdev_get_queue(pgpath->path.dev->bdev); | |
1542 | ||
1543 | return dm_underlying_device_busy(q); | |
1544 | } | |
1545 | ||
1546 | /* | |
1547 | * We return "busy", only when we can map I/Os but underlying devices | |
1548 | * are busy (so even if we map I/Os now, the I/Os will wait on | |
1549 | * the underlying queue). | |
1550 | * In other words, if we want to kill I/Os or queue them inside us | |
1551 | * due to map unavailability, we don't return "busy". Otherwise, | |
1552 | * dm core won't give us the I/Os and we can't do what we want. | |
1553 | */ | |
1554 | static int multipath_busy(struct dm_target *ti) | |
1555 | { | |
1556 | int busy = 0, has_active = 0; | |
1557 | struct multipath *m = ti->private; | |
1558 | struct priority_group *pg; | |
1559 | struct pgpath *pgpath; | |
1560 | unsigned long flags; | |
1561 | ||
1562 | spin_lock_irqsave(&m->lock, flags); | |
1563 | ||
1564 | /* Guess which priority_group will be used at next mapping time */ | |
1565 | if (unlikely(!m->current_pgpath && m->next_pg)) | |
1566 | pg = m->next_pg; | |
1567 | else if (likely(m->current_pg)) | |
1568 | pg = m->current_pg; | |
1569 | else | |
1570 | /* | |
1571 | * We don't know which pg will be used at next mapping time. | |
1572 | * We don't call __choose_pgpath() here to avoid to trigger | |
1573 | * pg_init just by busy checking. | |
1574 | * So we don't know whether underlying devices we will be using | |
1575 | * at next mapping time are busy or not. Just try mapping. | |
1576 | */ | |
1577 | goto out; | |
1578 | ||
1579 | /* | |
1580 | * If there is one non-busy active path at least, the path selector | |
1581 | * will be able to select it. So we consider such a pg as not busy. | |
1582 | */ | |
1583 | busy = 1; | |
1584 | list_for_each_entry(pgpath, &pg->pgpaths, list) | |
1585 | if (pgpath->is_active) { | |
1586 | has_active = 1; | |
1587 | ||
1588 | if (!__pgpath_busy(pgpath)) { | |
1589 | busy = 0; | |
1590 | break; | |
1591 | } | |
1592 | } | |
1593 | ||
1594 | if (!has_active) | |
1595 | /* | |
1596 | * No active path in this pg, so this pg won't be used and | |
1597 | * the current_pg will be changed at next mapping time. | |
1598 | * We need to try mapping to determine it. | |
1599 | */ | |
1600 | busy = 0; | |
1601 | ||
1602 | out: | |
1603 | spin_unlock_irqrestore(&m->lock, flags); | |
1604 | ||
1605 | return busy; | |
1606 | } | |
1607 | ||
1da177e4 LT |
1608 | /*----------------------------------------------------------------- |
1609 | * Module setup | |
1610 | *---------------------------------------------------------------*/ | |
1611 | static struct target_type multipath_target = { | |
1612 | .name = "multipath", | |
6df400ab | 1613 | .version = {1, 1, 1}, |
1da177e4 LT |
1614 | .module = THIS_MODULE, |
1615 | .ctr = multipath_ctr, | |
1616 | .dtr = multipath_dtr, | |
f40c67f0 KU |
1617 | .map_rq = multipath_map, |
1618 | .rq_end_io = multipath_end_io, | |
1da177e4 | 1619 | .presuspend = multipath_presuspend, |
6df400ab | 1620 | .postsuspend = multipath_postsuspend, |
1da177e4 LT |
1621 | .resume = multipath_resume, |
1622 | .status = multipath_status, | |
1623 | .message = multipath_message, | |
9af4aa30 | 1624 | .ioctl = multipath_ioctl, |
af4874e0 | 1625 | .iterate_devices = multipath_iterate_devices, |
f40c67f0 | 1626 | .busy = multipath_busy, |
1da177e4 LT |
1627 | }; |
1628 | ||
1629 | static int __init dm_multipath_init(void) | |
1630 | { | |
1631 | int r; | |
1632 | ||
1633 | /* allocate a slab for the dm_ios */ | |
028867ac | 1634 | _mpio_cache = KMEM_CACHE(dm_mpath_io, 0); |
1da177e4 LT |
1635 | if (!_mpio_cache) |
1636 | return -ENOMEM; | |
1637 | ||
1638 | r = dm_register_target(&multipath_target); | |
1639 | if (r < 0) { | |
0cd33124 | 1640 | DMERR("register failed %d", r); |
1da177e4 LT |
1641 | kmem_cache_destroy(_mpio_cache); |
1642 | return -EINVAL; | |
1643 | } | |
1644 | ||
c557308e AK |
1645 | kmultipathd = create_workqueue("kmpathd"); |
1646 | if (!kmultipathd) { | |
0cd33124 | 1647 | DMERR("failed to create workqueue kmpathd"); |
c557308e AK |
1648 | dm_unregister_target(&multipath_target); |
1649 | kmem_cache_destroy(_mpio_cache); | |
1650 | return -ENOMEM; | |
1651 | } | |
1652 | ||
bab7cfc7 CS |
1653 | /* |
1654 | * A separate workqueue is used to handle the device handlers | |
1655 | * to avoid overloading existing workqueue. Overloading the | |
1656 | * old workqueue would also create a bottleneck in the | |
1657 | * path of the storage hardware device activation. | |
1658 | */ | |
1659 | kmpath_handlerd = create_singlethread_workqueue("kmpath_handlerd"); | |
1660 | if (!kmpath_handlerd) { | |
1661 | DMERR("failed to create workqueue kmpath_handlerd"); | |
1662 | destroy_workqueue(kmultipathd); | |
1663 | dm_unregister_target(&multipath_target); | |
1664 | kmem_cache_destroy(_mpio_cache); | |
1665 | return -ENOMEM; | |
1666 | } | |
1667 | ||
72d94861 | 1668 | DMINFO("version %u.%u.%u loaded", |
1da177e4 LT |
1669 | multipath_target.version[0], multipath_target.version[1], |
1670 | multipath_target.version[2]); | |
1671 | ||
1672 | return r; | |
1673 | } | |
1674 | ||
1675 | static void __exit dm_multipath_exit(void) | |
1676 | { | |
bab7cfc7 | 1677 | destroy_workqueue(kmpath_handlerd); |
c557308e AK |
1678 | destroy_workqueue(kmultipathd); |
1679 | ||
10d3bd09 | 1680 | dm_unregister_target(&multipath_target); |
1da177e4 LT |
1681 | kmem_cache_destroy(_mpio_cache); |
1682 | } | |
1683 | ||
1da177e4 LT |
1684 | module_init(dm_multipath_init); |
1685 | module_exit(dm_multipath_exit); | |
1686 | ||
1687 | MODULE_DESCRIPTION(DM_NAME " multipath target"); | |
1688 | MODULE_AUTHOR("Sistina Software <dm-devel@redhat.com>"); | |
1689 | MODULE_LICENSE("GPL"); |