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