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