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