Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 Sistina Software Limited. |
| 3 | * |
| 4 | * This file is released under the GPL. |
| 5 | */ |
| 6 | |
| 7 | #include "dm.h" |
| 8 | #include "dm-bio-list.h" |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 9 | #include "dm-bio-record.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
| 11 | #include <linux/ctype.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/mempool.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/pagemap.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/time.h> |
| 18 | #include <linux/vmalloc.h> |
| 19 | #include <linux/workqueue.h> |
vignesh babu | 6f3c3f0 | 2007-10-19 22:38:44 +0100 | [diff] [blame] | 20 | #include <linux/log2.h> |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 21 | #include <linux/hardirq.h> |
Alasdair G Kergon | a765e20 | 2008-04-24 22:02:01 +0100 | [diff] [blame] | 22 | #include <linux/dm-io.h> |
| 23 | #include <linux/dm-dirty-log.h> |
| 24 | #include <linux/dm-kcopyd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 26 | #define DM_MSG_PREFIX "raid1" |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 27 | #define DM_IO_PAGES 64 |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 28 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 29 | #define DM_RAID1_HANDLE_ERRORS 0x01 |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 30 | #define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS) |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 31 | |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 32 | static DECLARE_WAIT_QUEUE_HEAD(_kmirrord_recovery_stopped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /*----------------------------------------------------------------- |
| 35 | * Region hash |
| 36 | * |
| 37 | * The mirror splits itself up into discrete regions. Each |
| 38 | * region can be in one of three states: clean, dirty, |
| 39 | * nosync. There is no need to put clean regions in the hash. |
| 40 | * |
| 41 | * In addition to being present in the hash table a region _may_ |
| 42 | * be present on one of three lists. |
| 43 | * |
| 44 | * clean_regions: Regions on this list have no io pending to |
| 45 | * them, they are in sync, we are no longer interested in them, |
| 46 | * they are dull. rh_update_states() will remove them from the |
| 47 | * hash table. |
| 48 | * |
| 49 | * quiesced_regions: These regions have been spun down, ready |
| 50 | * for recovery. rh_recovery_start() will remove regions from |
| 51 | * this list and hand them to kmirrord, which will schedule the |
| 52 | * recovery io with kcopyd. |
| 53 | * |
| 54 | * recovered_regions: Regions that kcopyd has successfully |
| 55 | * recovered. rh_update_states() will now schedule any delayed |
| 56 | * io, up the recovery_count, and remove the region from the |
| 57 | * hash. |
| 58 | * |
| 59 | * There are 2 locks: |
| 60 | * A rw spin lock 'hash_lock' protects just the hash table, |
| 61 | * this is never held in write mode from interrupt context, |
| 62 | * which I believe means that we only have to disable irqs when |
| 63 | * doing a write lock. |
| 64 | * |
| 65 | * An ordinary spin lock 'region_lock' that protects the three |
| 66 | * lists in the region_hash, with the 'state', 'list' and |
| 67 | * 'bhs_delayed' fields of the regions. This is used from irq |
| 68 | * context, so all other uses will have to suspend local irqs. |
| 69 | *---------------------------------------------------------------*/ |
| 70 | struct mirror_set; |
| 71 | struct region_hash { |
| 72 | struct mirror_set *ms; |
| 73 | uint32_t region_size; |
| 74 | unsigned region_shift; |
| 75 | |
| 76 | /* holds persistent region state */ |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 77 | struct dm_dirty_log *log; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* hash table */ |
| 80 | rwlock_t hash_lock; |
| 81 | mempool_t *region_pool; |
| 82 | unsigned int mask; |
| 83 | unsigned int nr_buckets; |
| 84 | struct list_head *buckets; |
| 85 | |
| 86 | spinlock_t region_lock; |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 87 | atomic_t recovery_in_flight; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | struct semaphore recovery_count; |
| 89 | struct list_head clean_regions; |
| 90 | struct list_head quiesced_regions; |
| 91 | struct list_head recovered_regions; |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 92 | struct list_head failed_recovered_regions; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | enum { |
| 96 | RH_CLEAN, |
| 97 | RH_DIRTY, |
| 98 | RH_NOSYNC, |
| 99 | RH_RECOVERING |
| 100 | }; |
| 101 | |
| 102 | struct region { |
| 103 | struct region_hash *rh; /* FIXME: can we get rid of this ? */ |
| 104 | region_t key; |
| 105 | int state; |
| 106 | |
| 107 | struct list_head hash_list; |
| 108 | struct list_head list; |
| 109 | |
| 110 | atomic_t pending; |
| 111 | struct bio_list delayed_bios; |
| 112 | }; |
| 113 | |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 114 | |
| 115 | /*----------------------------------------------------------------- |
| 116 | * Mirror set structures. |
| 117 | *---------------------------------------------------------------*/ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 118 | enum dm_raid1_error { |
| 119 | DM_RAID1_WRITE_ERROR, |
| 120 | DM_RAID1_SYNC_ERROR, |
| 121 | DM_RAID1_READ_ERROR |
| 122 | }; |
| 123 | |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 124 | struct mirror { |
Jonathan Brassow | aa5617c | 2007-10-19 22:47:58 +0100 | [diff] [blame] | 125 | struct mirror_set *ms; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 126 | atomic_t error_count; |
Al Viro | 39ed7ad | 2008-02-13 03:53:00 +0000 | [diff] [blame] | 127 | unsigned long error_type; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 128 | struct dm_dev *dev; |
| 129 | sector_t offset; |
| 130 | }; |
| 131 | |
| 132 | struct mirror_set { |
| 133 | struct dm_target *ti; |
| 134 | struct list_head list; |
| 135 | struct region_hash rh; |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 136 | struct dm_kcopyd_client *kcopyd_client; |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 137 | uint64_t features; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 138 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 139 | spinlock_t lock; /* protects the lists */ |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 140 | struct bio_list reads; |
| 141 | struct bio_list writes; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 142 | struct bio_list failures; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 143 | |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 144 | struct dm_io_client *io_client; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 145 | mempool_t *read_record_pool; |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 146 | |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 147 | /* recovery */ |
| 148 | region_t nr_regions; |
| 149 | int in_sync; |
Jonathan Brassow | fc1ff95 | 2007-07-12 17:29:15 +0100 | [diff] [blame] | 150 | int log_failure; |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 151 | atomic_t suspend; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 152 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 153 | atomic_t default_mirror; /* Default mirror */ |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 154 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 155 | struct workqueue_struct *kmirrord_wq; |
| 156 | struct work_struct kmirrord_work; |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 157 | struct timer_list timer; |
| 158 | unsigned long timer_pending; |
| 159 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 160 | struct work_struct trigger_event; |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 161 | |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 162 | unsigned int nr_mirrors; |
| 163 | struct mirror mirror[0]; |
| 164 | }; |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | /* |
| 167 | * Conversion fns |
| 168 | */ |
| 169 | static inline region_t bio_to_region(struct region_hash *rh, struct bio *bio) |
| 170 | { |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 171 | return (bio->bi_sector - rh->ms->ti->begin) >> rh->region_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static inline sector_t region_to_sector(struct region_hash *rh, region_t region) |
| 175 | { |
| 176 | return region << rh->region_shift; |
| 177 | } |
| 178 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 179 | static void wake(struct mirror_set *ms) |
| 180 | { |
| 181 | queue_work(ms->kmirrord_wq, &ms->kmirrord_work); |
| 182 | } |
| 183 | |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 184 | static void delayed_wake_fn(unsigned long data) |
| 185 | { |
| 186 | struct mirror_set *ms = (struct mirror_set *) data; |
| 187 | |
| 188 | clear_bit(0, &ms->timer_pending); |
| 189 | wake(ms); |
| 190 | } |
| 191 | |
| 192 | static void delayed_wake(struct mirror_set *ms) |
| 193 | { |
| 194 | if (test_and_set_bit(0, &ms->timer_pending)) |
| 195 | return; |
| 196 | |
| 197 | ms->timer.expires = jiffies + HZ / 5; |
| 198 | ms->timer.data = (unsigned long) ms; |
| 199 | ms->timer.function = delayed_wake_fn; |
| 200 | add_timer(&ms->timer); |
| 201 | } |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* FIXME move this */ |
| 204 | static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw); |
| 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | #define MIN_REGIONS 64 |
| 207 | #define MAX_RECOVERY 1 |
| 208 | static int rh_init(struct region_hash *rh, struct mirror_set *ms, |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 209 | struct dm_dirty_log *log, uint32_t region_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | region_t nr_regions) |
| 211 | { |
| 212 | unsigned int nr_buckets, max_buckets; |
| 213 | size_t i; |
| 214 | |
| 215 | /* |
| 216 | * Calculate a suitable number of buckets for our hash |
| 217 | * table. |
| 218 | */ |
| 219 | max_buckets = nr_regions >> 6; |
| 220 | for (nr_buckets = 128u; nr_buckets < max_buckets; nr_buckets <<= 1) |
| 221 | ; |
| 222 | nr_buckets >>= 1; |
| 223 | |
| 224 | rh->ms = ms; |
| 225 | rh->log = log; |
| 226 | rh->region_size = region_size; |
| 227 | rh->region_shift = ffs(region_size) - 1; |
| 228 | rwlock_init(&rh->hash_lock); |
| 229 | rh->mask = nr_buckets - 1; |
| 230 | rh->nr_buckets = nr_buckets; |
| 231 | |
| 232 | rh->buckets = vmalloc(nr_buckets * sizeof(*rh->buckets)); |
| 233 | if (!rh->buckets) { |
| 234 | DMERR("unable to allocate region hash memory"); |
| 235 | return -ENOMEM; |
| 236 | } |
| 237 | |
| 238 | for (i = 0; i < nr_buckets; i++) |
| 239 | INIT_LIST_HEAD(rh->buckets + i); |
| 240 | |
| 241 | spin_lock_init(&rh->region_lock); |
| 242 | sema_init(&rh->recovery_count, 0); |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 243 | atomic_set(&rh->recovery_in_flight, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | INIT_LIST_HEAD(&rh->clean_regions); |
| 245 | INIT_LIST_HEAD(&rh->quiesced_regions); |
| 246 | INIT_LIST_HEAD(&rh->recovered_regions); |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 247 | INIT_LIST_HEAD(&rh->failed_recovered_regions); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Matthew Dobson | 0eaae62a | 2006-03-26 01:37:47 -0800 | [diff] [blame] | 249 | rh->region_pool = mempool_create_kmalloc_pool(MIN_REGIONS, |
| 250 | sizeof(struct region)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | if (!rh->region_pool) { |
| 252 | vfree(rh->buckets); |
| 253 | rh->buckets = NULL; |
| 254 | return -ENOMEM; |
| 255 | } |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static void rh_exit(struct region_hash *rh) |
| 261 | { |
| 262 | unsigned int h; |
| 263 | struct region *reg, *nreg; |
| 264 | |
| 265 | BUG_ON(!list_empty(&rh->quiesced_regions)); |
| 266 | for (h = 0; h < rh->nr_buckets; h++) { |
| 267 | list_for_each_entry_safe(reg, nreg, rh->buckets + h, hash_list) { |
| 268 | BUG_ON(atomic_read(®->pending)); |
| 269 | mempool_free(reg, rh->region_pool); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if (rh->log) |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 274 | dm_dirty_log_destroy(rh->log); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (rh->region_pool) |
| 276 | mempool_destroy(rh->region_pool); |
| 277 | vfree(rh->buckets); |
| 278 | } |
| 279 | |
| 280 | #define RH_HASH_MULT 2654435387U |
| 281 | |
| 282 | static inline unsigned int rh_hash(struct region_hash *rh, region_t region) |
| 283 | { |
| 284 | return (unsigned int) ((region * RH_HASH_MULT) >> 12) & rh->mask; |
| 285 | } |
| 286 | |
| 287 | static struct region *__rh_lookup(struct region_hash *rh, region_t region) |
| 288 | { |
| 289 | struct region *reg; |
| 290 | |
| 291 | list_for_each_entry (reg, rh->buckets + rh_hash(rh, region), hash_list) |
| 292 | if (reg->key == region) |
| 293 | return reg; |
| 294 | |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | static void __rh_insert(struct region_hash *rh, struct region *reg) |
| 299 | { |
| 300 | unsigned int h = rh_hash(rh, reg->key); |
| 301 | list_add(®->hash_list, rh->buckets + h); |
| 302 | } |
| 303 | |
| 304 | static struct region *__rh_alloc(struct region_hash *rh, region_t region) |
| 305 | { |
| 306 | struct region *reg, *nreg; |
| 307 | |
| 308 | read_unlock(&rh->hash_lock); |
Daniel Kobras | c06aad8 | 2006-08-27 01:23:24 -0700 | [diff] [blame] | 309 | nreg = mempool_alloc(rh->region_pool, GFP_ATOMIC); |
| 310 | if (unlikely(!nreg)) |
| 311 | nreg = kmalloc(sizeof(struct region), GFP_NOIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | nreg->state = rh->log->type->in_sync(rh->log, region, 1) ? |
| 313 | RH_CLEAN : RH_NOSYNC; |
| 314 | nreg->rh = rh; |
| 315 | nreg->key = region; |
| 316 | |
| 317 | INIT_LIST_HEAD(&nreg->list); |
| 318 | |
| 319 | atomic_set(&nreg->pending, 0); |
| 320 | bio_list_init(&nreg->delayed_bios); |
| 321 | write_lock_irq(&rh->hash_lock); |
| 322 | |
| 323 | reg = __rh_lookup(rh, region); |
| 324 | if (reg) |
| 325 | /* we lost the race */ |
| 326 | mempool_free(nreg, rh->region_pool); |
| 327 | |
| 328 | else { |
| 329 | __rh_insert(rh, nreg); |
| 330 | if (nreg->state == RH_CLEAN) { |
| 331 | spin_lock(&rh->region_lock); |
| 332 | list_add(&nreg->list, &rh->clean_regions); |
| 333 | spin_unlock(&rh->region_lock); |
| 334 | } |
| 335 | reg = nreg; |
| 336 | } |
| 337 | write_unlock_irq(&rh->hash_lock); |
| 338 | read_lock(&rh->hash_lock); |
| 339 | |
| 340 | return reg; |
| 341 | } |
| 342 | |
| 343 | static inline struct region *__rh_find(struct region_hash *rh, region_t region) |
| 344 | { |
| 345 | struct region *reg; |
| 346 | |
| 347 | reg = __rh_lookup(rh, region); |
| 348 | if (!reg) |
| 349 | reg = __rh_alloc(rh, region); |
| 350 | |
| 351 | return reg; |
| 352 | } |
| 353 | |
| 354 | static int rh_state(struct region_hash *rh, region_t region, int may_block) |
| 355 | { |
| 356 | int r; |
| 357 | struct region *reg; |
| 358 | |
| 359 | read_lock(&rh->hash_lock); |
| 360 | reg = __rh_lookup(rh, region); |
| 361 | read_unlock(&rh->hash_lock); |
| 362 | |
| 363 | if (reg) |
| 364 | return reg->state; |
| 365 | |
| 366 | /* |
| 367 | * The region wasn't in the hash, so we fall back to the |
| 368 | * dirty log. |
| 369 | */ |
| 370 | r = rh->log->type->in_sync(rh->log, region, may_block); |
| 371 | |
| 372 | /* |
| 373 | * Any error from the dirty log (eg. -EWOULDBLOCK) gets |
| 374 | * taken as a RH_NOSYNC |
| 375 | */ |
| 376 | return r == 1 ? RH_CLEAN : RH_NOSYNC; |
| 377 | } |
| 378 | |
| 379 | static inline int rh_in_sync(struct region_hash *rh, |
| 380 | region_t region, int may_block) |
| 381 | { |
| 382 | int state = rh_state(rh, region, may_block); |
| 383 | return state == RH_CLEAN || state == RH_DIRTY; |
| 384 | } |
| 385 | |
| 386 | static void dispatch_bios(struct mirror_set *ms, struct bio_list *bio_list) |
| 387 | { |
| 388 | struct bio *bio; |
| 389 | |
| 390 | while ((bio = bio_list_pop(bio_list))) { |
| 391 | queue_bio(ms, bio, WRITE); |
| 392 | } |
| 393 | } |
| 394 | |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 395 | static void complete_resync_work(struct region *reg, int success) |
| 396 | { |
| 397 | struct region_hash *rh = reg->rh; |
| 398 | |
| 399 | rh->log->type->set_region_sync(rh->log, reg->key, success); |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 400 | |
| 401 | /* |
| 402 | * Dispatch the bios before we call 'wake_up_all'. |
| 403 | * This is important because if we are suspending, |
| 404 | * we want to know that recovery is complete and |
| 405 | * the work queue is flushed. If we wake_up_all |
| 406 | * before we dispatch_bios (queue bios and call wake()), |
| 407 | * then we risk suspending before the work queue |
| 408 | * has been properly flushed. |
| 409 | */ |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 410 | dispatch_bios(rh->ms, ®->delayed_bios); |
| 411 | if (atomic_dec_and_test(&rh->recovery_in_flight)) |
| 412 | wake_up_all(&_kmirrord_recovery_stopped); |
| 413 | up(&rh->recovery_count); |
| 414 | } |
| 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | static void rh_update_states(struct region_hash *rh) |
| 417 | { |
| 418 | struct region *reg, *next; |
| 419 | |
| 420 | LIST_HEAD(clean); |
| 421 | LIST_HEAD(recovered); |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 422 | LIST_HEAD(failed_recovered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | /* |
| 425 | * Quickly grab the lists. |
| 426 | */ |
| 427 | write_lock_irq(&rh->hash_lock); |
| 428 | spin_lock(&rh->region_lock); |
| 429 | if (!list_empty(&rh->clean_regions)) { |
Robert P. J. Day | c12bfc9 | 2008-04-24 21:42:44 +0100 | [diff] [blame] | 430 | list_splice_init(&rh->clean_regions, &clean); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Jonathan Brassow | 943317e | 2007-07-12 17:28:25 +0100 | [diff] [blame] | 432 | list_for_each_entry(reg, &clean, list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | list_del(®->hash_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | if (!list_empty(&rh->recovered_regions)) { |
Robert P. J. Day | c12bfc9 | 2008-04-24 21:42:44 +0100 | [diff] [blame] | 437 | list_splice_init(&rh->recovered_regions, &recovered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | list_for_each_entry (reg, &recovered, list) |
| 440 | list_del(®->hash_list); |
| 441 | } |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 442 | |
| 443 | if (!list_empty(&rh->failed_recovered_regions)) { |
Robert P. J. Day | c12bfc9 | 2008-04-24 21:42:44 +0100 | [diff] [blame] | 444 | list_splice_init(&rh->failed_recovered_regions, |
| 445 | &failed_recovered); |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 446 | |
| 447 | list_for_each_entry(reg, &failed_recovered, list) |
| 448 | list_del(®->hash_list); |
| 449 | } |
| 450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | spin_unlock(&rh->region_lock); |
| 452 | write_unlock_irq(&rh->hash_lock); |
| 453 | |
| 454 | /* |
| 455 | * All the regions on the recovered and clean lists have |
| 456 | * now been pulled out of the system, so no need to do |
| 457 | * any more locking. |
| 458 | */ |
| 459 | list_for_each_entry_safe (reg, next, &recovered, list) { |
| 460 | rh->log->type->clear_region(rh->log, reg->key); |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 461 | complete_resync_work(reg, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | mempool_free(reg, rh->region_pool); |
| 463 | } |
| 464 | |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 465 | list_for_each_entry_safe(reg, next, &failed_recovered, list) { |
| 466 | complete_resync_work(reg, errors_handled(rh->ms) ? 0 : 1); |
| 467 | mempool_free(reg, rh->region_pool); |
| 468 | } |
| 469 | |
Jonathan Brassow | 943317e | 2007-07-12 17:28:25 +0100 | [diff] [blame] | 470 | list_for_each_entry_safe(reg, next, &clean, list) { |
| 471 | rh->log->type->clear_region(rh->log, reg->key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | mempool_free(reg, rh->region_pool); |
Jonathan Brassow | 943317e | 2007-07-12 17:28:25 +0100 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | rh->log->type->flush(rh->log); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void rh_inc(struct region_hash *rh, region_t region) |
| 479 | { |
| 480 | struct region *reg; |
| 481 | |
| 482 | read_lock(&rh->hash_lock); |
| 483 | reg = __rh_find(rh, region); |
Jun'ichi Nomura | 844e8d9 | 2005-09-09 16:23:42 -0700 | [diff] [blame] | 484 | |
Jonathan E Brassow | 7692c5d | 2005-11-21 21:32:37 -0800 | [diff] [blame] | 485 | spin_lock_irq(&rh->region_lock); |
Jun'ichi Nomura | 844e8d9 | 2005-09-09 16:23:42 -0700 | [diff] [blame] | 486 | atomic_inc(®->pending); |
| 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | if (reg->state == RH_CLEAN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | reg->state = RH_DIRTY; |
| 490 | list_del_init(®->list); /* take off the clean list */ |
Jonathan E Brassow | 7692c5d | 2005-11-21 21:32:37 -0800 | [diff] [blame] | 491 | spin_unlock_irq(&rh->region_lock); |
| 492 | |
| 493 | rh->log->type->mark_region(rh->log, reg->key); |
| 494 | } else |
| 495 | spin_unlock_irq(&rh->region_lock); |
| 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | read_unlock(&rh->hash_lock); |
| 499 | } |
| 500 | |
| 501 | static void rh_inc_pending(struct region_hash *rh, struct bio_list *bios) |
| 502 | { |
| 503 | struct bio *bio; |
| 504 | |
| 505 | for (bio = bios->head; bio; bio = bio->bi_next) |
| 506 | rh_inc(rh, bio_to_region(rh, bio)); |
| 507 | } |
| 508 | |
| 509 | static void rh_dec(struct region_hash *rh, region_t region) |
| 510 | { |
| 511 | unsigned long flags; |
| 512 | struct region *reg; |
| 513 | int should_wake = 0; |
| 514 | |
| 515 | read_lock(&rh->hash_lock); |
| 516 | reg = __rh_lookup(rh, region); |
| 517 | read_unlock(&rh->hash_lock); |
| 518 | |
Jonathan E Brassow | 7692c5d | 2005-11-21 21:32:37 -0800 | [diff] [blame] | 519 | spin_lock_irqsave(&rh->region_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | if (atomic_dec_and_test(®->pending)) { |
Jun'ichi Nomura | 930d332 | 2006-03-27 01:17:47 -0800 | [diff] [blame] | 521 | /* |
| 522 | * There is no pending I/O for this region. |
| 523 | * We can move the region to corresponding list for next action. |
| 524 | * At this point, the region is not yet connected to any list. |
| 525 | * |
| 526 | * If the state is RH_NOSYNC, the region should be kept off |
| 527 | * from clean list. |
| 528 | * The hash entry for RH_NOSYNC will remain in memory |
| 529 | * until the region is recovered or the map is reloaded. |
| 530 | */ |
| 531 | |
| 532 | /* do nothing for RH_NOSYNC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | if (reg->state == RH_RECOVERING) { |
| 534 | list_add_tail(®->list, &rh->quiesced_regions); |
Jun'ichi Nomura | 930d332 | 2006-03-27 01:17:47 -0800 | [diff] [blame] | 535 | } else if (reg->state == RH_DIRTY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | reg->state = RH_CLEAN; |
| 537 | list_add(®->list, &rh->clean_regions); |
| 538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | should_wake = 1; |
| 540 | } |
Jonathan E Brassow | 7692c5d | 2005-11-21 21:32:37 -0800 | [diff] [blame] | 541 | spin_unlock_irqrestore(&rh->region_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | if (should_wake) |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 544 | wake(rh->ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Starts quiescing a region in preparation for recovery. |
| 549 | */ |
| 550 | static int __rh_recovery_prepare(struct region_hash *rh) |
| 551 | { |
| 552 | int r; |
| 553 | struct region *reg; |
| 554 | region_t region; |
| 555 | |
| 556 | /* |
| 557 | * Ask the dirty log what's next. |
| 558 | */ |
| 559 | r = rh->log->type->get_resync_work(rh->log, ®ion); |
| 560 | if (r <= 0) |
| 561 | return r; |
| 562 | |
| 563 | /* |
| 564 | * Get this region, and start it quiescing by setting the |
| 565 | * recovering flag. |
| 566 | */ |
| 567 | read_lock(&rh->hash_lock); |
| 568 | reg = __rh_find(rh, region); |
| 569 | read_unlock(&rh->hash_lock); |
| 570 | |
| 571 | spin_lock_irq(&rh->region_lock); |
| 572 | reg->state = RH_RECOVERING; |
| 573 | |
| 574 | /* Already quiesced ? */ |
| 575 | if (atomic_read(®->pending)) |
| 576 | list_del_init(®->list); |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 577 | else |
| 578 | list_move(®->list, &rh->quiesced_regions); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | spin_unlock_irq(&rh->region_lock); |
| 581 | |
| 582 | return 1; |
| 583 | } |
| 584 | |
| 585 | static void rh_recovery_prepare(struct region_hash *rh) |
| 586 | { |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 587 | /* Extra reference to avoid race with rh_stop_recovery */ |
| 588 | atomic_inc(&rh->recovery_in_flight); |
| 589 | |
| 590 | while (!down_trylock(&rh->recovery_count)) { |
| 591 | atomic_inc(&rh->recovery_in_flight); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | if (__rh_recovery_prepare(rh) <= 0) { |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 593 | atomic_dec(&rh->recovery_in_flight); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | up(&rh->recovery_count); |
| 595 | break; |
| 596 | } |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* Drop the extra reference */ |
| 600 | if (atomic_dec_and_test(&rh->recovery_in_flight)) |
| 601 | wake_up_all(&_kmirrord_recovery_stopped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* |
| 605 | * Returns any quiesced regions. |
| 606 | */ |
| 607 | static struct region *rh_recovery_start(struct region_hash *rh) |
| 608 | { |
| 609 | struct region *reg = NULL; |
| 610 | |
| 611 | spin_lock_irq(&rh->region_lock); |
| 612 | if (!list_empty(&rh->quiesced_regions)) { |
| 613 | reg = list_entry(rh->quiesced_regions.next, |
| 614 | struct region, list); |
| 615 | list_del_init(®->list); /* remove from the quiesced list */ |
| 616 | } |
| 617 | spin_unlock_irq(&rh->region_lock); |
| 618 | |
| 619 | return reg; |
| 620 | } |
| 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | static void rh_recovery_end(struct region *reg, int success) |
| 623 | { |
| 624 | struct region_hash *rh = reg->rh; |
| 625 | |
| 626 | spin_lock_irq(&rh->region_lock); |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 627 | if (success) |
| 628 | list_add(®->list, ®->rh->recovered_regions); |
| 629 | else { |
| 630 | reg->state = RH_NOSYNC; |
| 631 | list_add(®->list, ®->rh->failed_recovered_regions); |
| 632 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | spin_unlock_irq(&rh->region_lock); |
| 634 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 635 | wake(rh->ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Jonathan Brassow | fc1ff95 | 2007-07-12 17:29:15 +0100 | [diff] [blame] | 638 | static int rh_flush(struct region_hash *rh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Jonathan Brassow | fc1ff95 | 2007-07-12 17:29:15 +0100 | [diff] [blame] | 640 | return rh->log->type->flush(rh->log); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static void rh_delay(struct region_hash *rh, struct bio *bio) |
| 644 | { |
| 645 | struct region *reg; |
| 646 | |
| 647 | read_lock(&rh->hash_lock); |
| 648 | reg = __rh_find(rh, bio_to_region(rh, bio)); |
| 649 | bio_list_add(®->delayed_bios, bio); |
| 650 | read_unlock(&rh->hash_lock); |
| 651 | } |
| 652 | |
| 653 | static void rh_stop_recovery(struct region_hash *rh) |
| 654 | { |
| 655 | int i; |
| 656 | |
| 657 | /* wait for any recovering regions */ |
| 658 | for (i = 0; i < MAX_RECOVERY; i++) |
| 659 | down(&rh->recovery_count); |
| 660 | } |
| 661 | |
| 662 | static void rh_start_recovery(struct region_hash *rh) |
| 663 | { |
| 664 | int i; |
| 665 | |
| 666 | for (i = 0; i < MAX_RECOVERY; i++) |
| 667 | up(&rh->recovery_count); |
| 668 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 669 | wake(rh->ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 672 | #define MIN_READ_RECORDS 20 |
| 673 | struct dm_raid1_read_record { |
| 674 | struct mirror *m; |
| 675 | struct dm_bio_details details; |
| 676 | }; |
| 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* |
| 679 | * Every mirror should look like this one. |
| 680 | */ |
| 681 | #define DEFAULT_MIRROR 0 |
| 682 | |
| 683 | /* |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 684 | * This is yucky. We squirrel the mirror struct away inside |
| 685 | * bi_next for read/write buffers. This is safe since the bh |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | * doesn't get submitted to the lower levels of block layer. |
| 687 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 688 | static struct mirror *bio_get_m(struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 690 | return (struct mirror *) bio->bi_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 693 | static void bio_set_m(struct bio *bio, struct mirror *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 695 | bio->bi_next = (struct bio *) m; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 698 | static struct mirror *get_default_mirror(struct mirror_set *ms) |
| 699 | { |
| 700 | return &ms->mirror[atomic_read(&ms->default_mirror)]; |
| 701 | } |
| 702 | |
| 703 | static void set_default_mirror(struct mirror *m) |
| 704 | { |
| 705 | struct mirror_set *ms = m->ms; |
| 706 | struct mirror *m0 = &(ms->mirror[0]); |
| 707 | |
| 708 | atomic_set(&ms->default_mirror, m - m0); |
| 709 | } |
| 710 | |
| 711 | /* fail_mirror |
| 712 | * @m: mirror device to fail |
| 713 | * @error_type: one of the enum's, DM_RAID1_*_ERROR |
| 714 | * |
| 715 | * If errors are being handled, record the type of |
| 716 | * error encountered for this device. If this type |
| 717 | * of error has already been recorded, we can return; |
| 718 | * otherwise, we must signal userspace by triggering |
| 719 | * an event. Additionally, if the device is the |
| 720 | * primary device, we must choose a new primary, but |
| 721 | * only if the mirror is in-sync. |
| 722 | * |
| 723 | * This function must not block. |
| 724 | */ |
| 725 | static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type) |
| 726 | { |
| 727 | struct mirror_set *ms = m->ms; |
| 728 | struct mirror *new; |
| 729 | |
| 730 | if (!errors_handled(ms)) |
| 731 | return; |
| 732 | |
| 733 | /* |
| 734 | * error_count is used for nothing more than a |
| 735 | * simple way to tell if a device has encountered |
| 736 | * errors. |
| 737 | */ |
| 738 | atomic_inc(&m->error_count); |
| 739 | |
| 740 | if (test_and_set_bit(error_type, &m->error_type)) |
| 741 | return; |
| 742 | |
| 743 | if (m != get_default_mirror(ms)) |
| 744 | goto out; |
| 745 | |
| 746 | if (!ms->in_sync) { |
| 747 | /* |
| 748 | * Better to issue requests to same failing device |
| 749 | * than to risk returning corrupt data. |
| 750 | */ |
| 751 | DMERR("Primary mirror (%s) failed while out-of-sync: " |
| 752 | "Reads may fail.", m->dev->name); |
| 753 | goto out; |
| 754 | } |
| 755 | |
| 756 | for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++) |
| 757 | if (!atomic_read(&new->error_count)) { |
| 758 | set_default_mirror(new); |
| 759 | break; |
| 760 | } |
| 761 | |
| 762 | if (unlikely(new == ms->mirror + ms->nr_mirrors)) |
| 763 | DMWARN("All sides of mirror have failed."); |
| 764 | |
| 765 | out: |
| 766 | schedule_work(&ms->trigger_event); |
| 767 | } |
| 768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | /*----------------------------------------------------------------- |
| 770 | * Recovery. |
| 771 | * |
| 772 | * When a mirror is first activated we may find that some regions |
| 773 | * are in the no-sync state. We have to recover these by |
| 774 | * recopying from the default mirror to all the others. |
| 775 | *---------------------------------------------------------------*/ |
Alasdair G Kergon | 4cdc1d1 | 2008-03-28 14:16:10 -0700 | [diff] [blame] | 776 | static void recovery_complete(int read_err, unsigned long write_err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | void *context) |
| 778 | { |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 779 | struct region *reg = (struct region *)context; |
| 780 | struct mirror_set *ms = reg->rh->ms; |
| 781 | int m, bit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 783 | if (read_err) { |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 784 | /* Read error means the failure of default mirror. */ |
| 785 | DMERR_LIMIT("Unable to read primary mirror during recovery"); |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 786 | fail_mirror(get_default_mirror(ms), DM_RAID1_SYNC_ERROR); |
| 787 | } |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 788 | |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 789 | if (write_err) { |
Alasdair G Kergon | 4cdc1d1 | 2008-03-28 14:16:10 -0700 | [diff] [blame] | 790 | DMERR_LIMIT("Write error during recovery (error = 0x%lx)", |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 791 | write_err); |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 792 | /* |
| 793 | * Bits correspond to devices (excluding default mirror). |
| 794 | * The default mirror cannot change during recovery. |
| 795 | */ |
| 796 | for (m = 0; m < ms->nr_mirrors; m++) { |
| 797 | if (&ms->mirror[m] == get_default_mirror(ms)) |
| 798 | continue; |
| 799 | if (test_bit(bit, &write_err)) |
| 800 | fail_mirror(ms->mirror + m, |
| 801 | DM_RAID1_SYNC_ERROR); |
| 802 | bit++; |
| 803 | } |
| 804 | } |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 805 | |
Jonathan Brassow | ce503f5 | 2006-06-26 00:27:30 -0700 | [diff] [blame] | 806 | rh_recovery_end(reg, !(read_err || write_err)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static int recover(struct mirror_set *ms, struct region *reg) |
| 810 | { |
| 811 | int r; |
| 812 | unsigned int i; |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 813 | struct dm_io_region from, to[DM_KCOPYD_MAX_REGIONS], *dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | struct mirror *m; |
| 815 | unsigned long flags = 0; |
| 816 | |
| 817 | /* fill in the source */ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 818 | m = get_default_mirror(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | from.bdev = m->dev->bdev; |
| 820 | from.sector = m->offset + region_to_sector(reg->rh, reg->key); |
| 821 | if (reg->key == (ms->nr_regions - 1)) { |
| 822 | /* |
| 823 | * The final region may be smaller than |
| 824 | * region_size. |
| 825 | */ |
| 826 | from.count = ms->ti->len & (reg->rh->region_size - 1); |
| 827 | if (!from.count) |
| 828 | from.count = reg->rh->region_size; |
| 829 | } else |
| 830 | from.count = reg->rh->region_size; |
| 831 | |
| 832 | /* fill in the destinations */ |
| 833 | for (i = 0, dest = to; i < ms->nr_mirrors; i++) { |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 834 | if (&ms->mirror[i] == get_default_mirror(ms)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | continue; |
| 836 | |
| 837 | m = ms->mirror + i; |
| 838 | dest->bdev = m->dev->bdev; |
| 839 | dest->sector = m->offset + region_to_sector(reg->rh, reg->key); |
| 840 | dest->count = from.count; |
| 841 | dest++; |
| 842 | } |
| 843 | |
| 844 | /* hand to kcopyd */ |
Jonathan Brassow | f7c83e2 | 2008-10-10 13:36:59 +0100 | [diff] [blame] | 845 | if (!errors_handled(ms)) |
| 846 | set_bit(DM_KCOPYD_IGNORE_ERROR, &flags); |
| 847 | |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 848 | r = dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to, |
| 849 | flags, recovery_complete, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | return r; |
| 852 | } |
| 853 | |
| 854 | static void do_recovery(struct mirror_set *ms) |
| 855 | { |
| 856 | int r; |
| 857 | struct region *reg; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 858 | struct dm_dirty_log *log = ms->rh.log; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
| 860 | /* |
| 861 | * Start quiescing some regions. |
| 862 | */ |
| 863 | rh_recovery_prepare(&ms->rh); |
| 864 | |
| 865 | /* |
| 866 | * Copy any already quiesced regions. |
| 867 | */ |
| 868 | while ((reg = rh_recovery_start(&ms->rh))) { |
| 869 | r = recover(ms, reg); |
| 870 | if (r) |
| 871 | rh_recovery_end(reg, 0); |
| 872 | } |
| 873 | |
| 874 | /* |
| 875 | * Update the in sync flag. |
| 876 | */ |
| 877 | if (!ms->in_sync && |
| 878 | (log->type->get_sync_count(log) == ms->nr_regions)) { |
| 879 | /* the sync is complete */ |
| 880 | dm_table_event(ms->ti->table); |
| 881 | ms->in_sync = 1; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /*----------------------------------------------------------------- |
| 886 | * Reads |
| 887 | *---------------------------------------------------------------*/ |
| 888 | static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector) |
| 889 | { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 890 | struct mirror *m = get_default_mirror(ms); |
| 891 | |
| 892 | do { |
| 893 | if (likely(!atomic_read(&m->error_count))) |
| 894 | return m; |
| 895 | |
| 896 | if (m-- == ms->mirror) |
| 897 | m += ms->nr_mirrors; |
| 898 | } while (m != get_default_mirror(ms)); |
| 899 | |
| 900 | return NULL; |
| 901 | } |
| 902 | |
| 903 | static int default_ok(struct mirror *m) |
| 904 | { |
| 905 | struct mirror *default_mirror = get_default_mirror(m->ms); |
| 906 | |
| 907 | return !atomic_read(&default_mirror->error_count); |
| 908 | } |
| 909 | |
| 910 | static int mirror_available(struct mirror_set *ms, struct bio *bio) |
| 911 | { |
| 912 | region_t region = bio_to_region(&ms->rh, bio); |
| 913 | |
| 914 | if (ms->rh.log->type->in_sync(ms->rh.log, region, 0)) |
| 915 | return choose_mirror(ms, bio->bi_sector) ? 1 : 0; |
| 916 | |
| 917 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /* |
| 921 | * remap a buffer to a particular mirror. |
| 922 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 923 | static sector_t map_sector(struct mirror *m, struct bio *bio) |
| 924 | { |
| 925 | return m->offset + (bio->bi_sector - m->ms->ti->begin); |
| 926 | } |
| 927 | |
| 928 | static void map_bio(struct mirror *m, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
| 930 | bio->bi_bdev = m->dev->bdev; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 931 | bio->bi_sector = map_sector(m, bio); |
| 932 | } |
| 933 | |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 934 | static void map_region(struct dm_io_region *io, struct mirror *m, |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 935 | struct bio *bio) |
| 936 | { |
| 937 | io->bdev = m->dev->bdev; |
| 938 | io->sector = map_sector(m, bio); |
| 939 | io->count = bio->bi_size >> 9; |
| 940 | } |
| 941 | |
| 942 | /*----------------------------------------------------------------- |
| 943 | * Reads |
| 944 | *---------------------------------------------------------------*/ |
| 945 | static void read_callback(unsigned long error, void *context) |
| 946 | { |
| 947 | struct bio *bio = context; |
| 948 | struct mirror *m; |
| 949 | |
| 950 | m = bio_get_m(bio); |
| 951 | bio_set_m(bio, NULL); |
| 952 | |
| 953 | if (likely(!error)) { |
| 954 | bio_endio(bio, 0); |
| 955 | return; |
| 956 | } |
| 957 | |
| 958 | fail_mirror(m, DM_RAID1_READ_ERROR); |
| 959 | |
| 960 | if (likely(default_ok(m)) || mirror_available(m->ms, bio)) { |
| 961 | DMWARN_LIMIT("Read failure on mirror device %s. " |
| 962 | "Trying alternative device.", |
| 963 | m->dev->name); |
| 964 | queue_bio(m->ms, bio, bio_rw(bio)); |
| 965 | return; |
| 966 | } |
| 967 | |
| 968 | DMERR_LIMIT("Read failure on mirror device %s. Failing I/O.", |
| 969 | m->dev->name); |
| 970 | bio_endio(bio, -EIO); |
| 971 | } |
| 972 | |
| 973 | /* Asynchronous read. */ |
| 974 | static void read_async_bio(struct mirror *m, struct bio *bio) |
| 975 | { |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 976 | struct dm_io_region io; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 977 | struct dm_io_request io_req = { |
| 978 | .bi_rw = READ, |
| 979 | .mem.type = DM_IO_BVEC, |
| 980 | .mem.ptr.bvec = bio->bi_io_vec + bio->bi_idx, |
| 981 | .notify.fn = read_callback, |
| 982 | .notify.context = bio, |
| 983 | .client = m->ms->io_client, |
| 984 | }; |
| 985 | |
| 986 | map_region(&io, m, bio); |
| 987 | bio_set_m(bio, m); |
| 988 | (void) dm_io(&io_req, 1, &io, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | static void do_reads(struct mirror_set *ms, struct bio_list *reads) |
| 992 | { |
| 993 | region_t region; |
| 994 | struct bio *bio; |
| 995 | struct mirror *m; |
| 996 | |
| 997 | while ((bio = bio_list_pop(reads))) { |
| 998 | region = bio_to_region(&ms->rh, bio); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 999 | m = get_default_mirror(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
| 1001 | /* |
| 1002 | * We can only read balance if the region is in sync. |
| 1003 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1004 | if (likely(rh_in_sync(&ms->rh, region, 1))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | m = choose_mirror(ms, bio->bi_sector); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1006 | else if (m && atomic_read(&m->error_count)) |
| 1007 | m = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1009 | if (likely(m)) |
| 1010 | read_async_bio(m, bio); |
| 1011 | else |
| 1012 | bio_endio(bio, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | /*----------------------------------------------------------------- |
| 1017 | * Writes. |
| 1018 | * |
| 1019 | * We do different things with the write io depending on the |
| 1020 | * state of the region that it's in: |
| 1021 | * |
| 1022 | * SYNC: increment pending, use kcopyd to write to *all* mirrors |
| 1023 | * RECOVERING: delay the io until recovery completes |
| 1024 | * NOSYNC: increment pending, just write to the default mirror |
| 1025 | *---------------------------------------------------------------*/ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1026 | |
| 1027 | /* __bio_mark_nosync |
| 1028 | * @ms |
| 1029 | * @bio |
| 1030 | * @done |
| 1031 | * @error |
| 1032 | * |
| 1033 | * The bio was written on some mirror(s) but failed on other mirror(s). |
| 1034 | * We can successfully endio the bio but should avoid the region being |
| 1035 | * marked clean by setting the state RH_NOSYNC. |
| 1036 | * |
| 1037 | * This function is _not_ safe in interrupt context! |
| 1038 | */ |
| 1039 | static void __bio_mark_nosync(struct mirror_set *ms, |
| 1040 | struct bio *bio, unsigned done, int error) |
| 1041 | { |
| 1042 | unsigned long flags; |
| 1043 | struct region_hash *rh = &ms->rh; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1044 | struct dm_dirty_log *log = ms->rh.log; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1045 | struct region *reg; |
| 1046 | region_t region = bio_to_region(rh, bio); |
| 1047 | int recovering = 0; |
| 1048 | |
| 1049 | /* We must inform the log that the sync count has changed. */ |
| 1050 | log->type->set_region_sync(log, region, 0); |
| 1051 | ms->in_sync = 0; |
| 1052 | |
| 1053 | read_lock(&rh->hash_lock); |
| 1054 | reg = __rh_find(rh, region); |
| 1055 | read_unlock(&rh->hash_lock); |
| 1056 | |
| 1057 | /* region hash entry should exist because write was in-flight */ |
| 1058 | BUG_ON(!reg); |
| 1059 | BUG_ON(!list_empty(®->list)); |
| 1060 | |
| 1061 | spin_lock_irqsave(&rh->region_lock, flags); |
| 1062 | /* |
| 1063 | * Possible cases: |
| 1064 | * 1) RH_DIRTY |
| 1065 | * 2) RH_NOSYNC: was dirty, other preceeding writes failed |
| 1066 | * 3) RH_RECOVERING: flushing pending writes |
| 1067 | * Either case, the region should have not been connected to list. |
| 1068 | */ |
| 1069 | recovering = (reg->state == RH_RECOVERING); |
| 1070 | reg->state = RH_NOSYNC; |
| 1071 | BUG_ON(!list_empty(®->list)); |
| 1072 | spin_unlock_irqrestore(&rh->region_lock, flags); |
| 1073 | |
| 1074 | bio_endio(bio, error); |
| 1075 | if (recovering) |
| 1076 | complete_resync_work(reg, 0); |
| 1077 | } |
| 1078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | static void write_callback(unsigned long error, void *context) |
| 1080 | { |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1081 | unsigned i, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | struct bio *bio = (struct bio *) context; |
| 1083 | struct mirror_set *ms; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1084 | int uptodate = 0; |
| 1085 | int should_wake = 0; |
| 1086 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1088 | ms = bio_get_m(bio)->ms; |
| 1089 | bio_set_m(bio, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
| 1091 | /* |
| 1092 | * NOTE: We don't decrement the pending count here, |
| 1093 | * instead it is done by the targets endio function. |
| 1094 | * This way we handle both writes to SYNC and NOSYNC |
| 1095 | * regions with the same code. |
| 1096 | */ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1097 | if (likely(!error)) |
| 1098 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1100 | for (i = 0; i < ms->nr_mirrors; i++) |
| 1101 | if (test_bit(i, &error)) |
| 1102 | fail_mirror(ms->mirror + i, DM_RAID1_WRITE_ERROR); |
| 1103 | else |
| 1104 | uptodate = 1; |
| 1105 | |
| 1106 | if (unlikely(!uptodate)) { |
| 1107 | DMERR("All replicated volumes dead, failing I/O"); |
| 1108 | /* None of the writes succeeded, fail the I/O. */ |
| 1109 | ret = -EIO; |
| 1110 | } else if (errors_handled(ms)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | /* |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1112 | * Need to raise event. Since raising |
| 1113 | * events can block, we need to do it in |
| 1114 | * the main thread. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | */ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1116 | spin_lock_irqsave(&ms->lock, flags); |
| 1117 | if (!ms->failures.head) |
| 1118 | should_wake = 1; |
| 1119 | bio_list_add(&ms->failures, bio); |
| 1120 | spin_unlock_irqrestore(&ms->lock, flags); |
| 1121 | if (should_wake) |
| 1122 | wake(ms); |
| 1123 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1125 | out: |
| 1126 | bio_endio(bio, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static void do_write(struct mirror_set *ms, struct bio *bio) |
| 1130 | { |
| 1131 | unsigned int i; |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 1132 | struct dm_io_region io[ms->nr_mirrors], *dest = io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | struct mirror *m; |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 1134 | struct dm_io_request io_req = { |
| 1135 | .bi_rw = WRITE, |
| 1136 | .mem.type = DM_IO_BVEC, |
| 1137 | .mem.ptr.bvec = bio->bi_io_vec + bio->bi_idx, |
| 1138 | .notify.fn = write_callback, |
| 1139 | .notify.context = bio, |
| 1140 | .client = ms->io_client, |
| 1141 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1143 | for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) |
| 1144 | map_region(dest++, m, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1146 | /* |
| 1147 | * Use default mirror because we only need it to retrieve the reference |
| 1148 | * to the mirror set in write_callback(). |
| 1149 | */ |
| 1150 | bio_set_m(bio, get_default_mirror(ms)); |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 1151 | |
| 1152 | (void) dm_io(&io_req, ms->nr_mirrors, io, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | static void do_writes(struct mirror_set *ms, struct bio_list *writes) |
| 1156 | { |
| 1157 | int state; |
| 1158 | struct bio *bio; |
| 1159 | struct bio_list sync, nosync, recover, *this_list = NULL; |
| 1160 | |
| 1161 | if (!writes->head) |
| 1162 | return; |
| 1163 | |
| 1164 | /* |
| 1165 | * Classify each write. |
| 1166 | */ |
| 1167 | bio_list_init(&sync); |
| 1168 | bio_list_init(&nosync); |
| 1169 | bio_list_init(&recover); |
| 1170 | |
| 1171 | while ((bio = bio_list_pop(writes))) { |
| 1172 | state = rh_state(&ms->rh, bio_to_region(&ms->rh, bio), 1); |
| 1173 | switch (state) { |
| 1174 | case RH_CLEAN: |
| 1175 | case RH_DIRTY: |
| 1176 | this_list = &sync; |
| 1177 | break; |
| 1178 | |
| 1179 | case RH_NOSYNC: |
| 1180 | this_list = &nosync; |
| 1181 | break; |
| 1182 | |
| 1183 | case RH_RECOVERING: |
| 1184 | this_list = &recover; |
| 1185 | break; |
| 1186 | } |
| 1187 | |
| 1188 | bio_list_add(this_list, bio); |
| 1189 | } |
| 1190 | |
| 1191 | /* |
| 1192 | * Increment the pending counts for any regions that will |
| 1193 | * be written to (writes to recover regions are going to |
| 1194 | * be delayed). |
| 1195 | */ |
| 1196 | rh_inc_pending(&ms->rh, &sync); |
| 1197 | rh_inc_pending(&ms->rh, &nosync); |
Jonathan Brassow | fc1ff95 | 2007-07-12 17:29:15 +0100 | [diff] [blame] | 1198 | ms->log_failure = rh_flush(&ms->rh) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | |
| 1200 | /* |
| 1201 | * Dispatch io. |
| 1202 | */ |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1203 | if (unlikely(ms->log_failure)) { |
| 1204 | spin_lock_irq(&ms->lock); |
| 1205 | bio_list_merge(&ms->failures, &sync); |
| 1206 | spin_unlock_irq(&ms->lock); |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 1207 | wake(ms); |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1208 | } else |
Jonathan Brassow | fc1ff95 | 2007-07-12 17:29:15 +0100 | [diff] [blame] | 1209 | while ((bio = bio_list_pop(&sync))) |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1210 | do_write(ms, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
| 1212 | while ((bio = bio_list_pop(&recover))) |
| 1213 | rh_delay(&ms->rh, bio); |
| 1214 | |
| 1215 | while ((bio = bio_list_pop(&nosync))) { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1216 | map_bio(get_default_mirror(ms), bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | generic_make_request(bio); |
| 1218 | } |
| 1219 | } |
| 1220 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1221 | static void do_failures(struct mirror_set *ms, struct bio_list *failures) |
| 1222 | { |
| 1223 | struct bio *bio; |
| 1224 | |
| 1225 | if (!failures->head) |
| 1226 | return; |
| 1227 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1228 | if (!ms->log_failure) { |
| 1229 | while ((bio = bio_list_pop(failures))) |
| 1230 | __bio_mark_nosync(ms, bio, bio->bi_size, 0); |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | /* |
| 1235 | * If the log has failed, unattempted writes are being |
| 1236 | * put on the failures list. We can't issue those writes |
| 1237 | * until a log has been marked, so we must store them. |
| 1238 | * |
| 1239 | * If a 'noflush' suspend is in progress, we can requeue |
| 1240 | * the I/O's to the core. This give userspace a chance |
| 1241 | * to reconfigure the mirror, at which point the core |
| 1242 | * will reissue the writes. If the 'noflush' flag is |
| 1243 | * not set, we have no choice but to return errors. |
| 1244 | * |
| 1245 | * Some writes on the failures list may have been |
| 1246 | * submitted before the log failure and represent a |
| 1247 | * failure to write to one of the devices. It is ok |
| 1248 | * for us to treat them the same and requeue them |
| 1249 | * as well. |
| 1250 | */ |
| 1251 | if (dm_noflush_suspending(ms->ti)) { |
| 1252 | while ((bio = bio_list_pop(failures))) |
| 1253 | bio_endio(bio, DM_ENDIO_REQUEUE); |
| 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | if (atomic_read(&ms->suspend)) { |
| 1258 | while ((bio = bio_list_pop(failures))) |
| 1259 | bio_endio(bio, -EIO); |
| 1260 | return; |
| 1261 | } |
| 1262 | |
| 1263 | spin_lock_irq(&ms->lock); |
| 1264 | bio_list_merge(&ms->failures, failures); |
| 1265 | spin_unlock_irq(&ms->lock); |
| 1266 | |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 1267 | delayed_wake(ms); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | static void trigger_event(struct work_struct *work) |
| 1271 | { |
| 1272 | struct mirror_set *ms = |
| 1273 | container_of(work, struct mirror_set, trigger_event); |
| 1274 | |
| 1275 | dm_table_event(ms->ti->table); |
| 1276 | } |
| 1277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | /*----------------------------------------------------------------- |
| 1279 | * kmirrord |
| 1280 | *---------------------------------------------------------------*/ |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 1281 | static void do_mirror(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | { |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1283 | struct mirror_set *ms =container_of(work, struct mirror_set, |
| 1284 | kmirrord_work); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1285 | struct bio_list reads, writes, failures; |
| 1286 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1288 | spin_lock_irqsave(&ms->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | reads = ms->reads; |
| 1290 | writes = ms->writes; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1291 | failures = ms->failures; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | bio_list_init(&ms->reads); |
| 1293 | bio_list_init(&ms->writes); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1294 | bio_list_init(&ms->failures); |
| 1295 | spin_unlock_irqrestore(&ms->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
| 1297 | rh_update_states(&ms->rh); |
| 1298 | do_recovery(ms); |
| 1299 | do_reads(ms, &reads); |
| 1300 | do_writes(ms, &writes); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1301 | do_failures(ms, &failures); |
Mikulas Patocka | 7ff14a3 | 2008-04-24 22:10:47 +0100 | [diff] [blame] | 1302 | |
| 1303 | dm_table_unplug_all(ms->ti->table); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | /*----------------------------------------------------------------- |
| 1308 | * Target functions |
| 1309 | *---------------------------------------------------------------*/ |
| 1310 | static struct mirror_set *alloc_context(unsigned int nr_mirrors, |
| 1311 | uint32_t region_size, |
| 1312 | struct dm_target *ti, |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1313 | struct dm_dirty_log *dl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | { |
| 1315 | size_t len; |
| 1316 | struct mirror_set *ms = NULL; |
| 1317 | |
| 1318 | if (array_too_big(sizeof(*ms), sizeof(ms->mirror[0]), nr_mirrors)) |
| 1319 | return NULL; |
| 1320 | |
| 1321 | len = sizeof(*ms) + (sizeof(ms->mirror[0]) * nr_mirrors); |
| 1322 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 1323 | ms = kzalloc(len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | if (!ms) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1325 | ti->error = "Cannot allocate mirror context"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | return NULL; |
| 1327 | } |
| 1328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | spin_lock_init(&ms->lock); |
| 1330 | |
| 1331 | ms->ti = ti; |
| 1332 | ms->nr_mirrors = nr_mirrors; |
| 1333 | ms->nr_regions = dm_sector_div_up(ti->len, region_size); |
| 1334 | ms->in_sync = 0; |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1335 | ms->log_failure = 0; |
| 1336 | atomic_set(&ms->suspend, 0); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1337 | atomic_set(&ms->default_mirror, DEFAULT_MIRROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1339 | len = sizeof(struct dm_raid1_read_record); |
| 1340 | ms->read_record_pool = mempool_create_kmalloc_pool(MIN_READ_RECORDS, |
| 1341 | len); |
| 1342 | if (!ms->read_record_pool) { |
| 1343 | ti->error = "Error creating mirror read_record_pool"; |
| 1344 | kfree(ms); |
| 1345 | return NULL; |
| 1346 | } |
| 1347 | |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 1348 | ms->io_client = dm_io_client_create(DM_IO_PAGES); |
| 1349 | if (IS_ERR(ms->io_client)) { |
| 1350 | ti->error = "Error creating dm_io client"; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1351 | mempool_destroy(ms->read_record_pool); |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 1352 | kfree(ms); |
| 1353 | return NULL; |
| 1354 | } |
| 1355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | if (rh_init(&ms->rh, ms, dl, region_size, ms->nr_regions)) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1357 | ti->error = "Error creating dirty region hash"; |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1358 | dm_io_client_destroy(ms->io_client); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1359 | mempool_destroy(ms->read_record_pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | kfree(ms); |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | |
| 1364 | return ms; |
| 1365 | } |
| 1366 | |
| 1367 | static void free_context(struct mirror_set *ms, struct dm_target *ti, |
| 1368 | unsigned int m) |
| 1369 | { |
| 1370 | while (m--) |
| 1371 | dm_put_device(ti, ms->mirror[m].dev); |
| 1372 | |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 1373 | dm_io_client_destroy(ms->io_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | rh_exit(&ms->rh); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1375 | mempool_destroy(ms->read_record_pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | kfree(ms); |
| 1377 | } |
| 1378 | |
| 1379 | static inline int _check_region_size(struct dm_target *ti, uint32_t size) |
| 1380 | { |
vignesh babu | 6f3c3f0 | 2007-10-19 22:38:44 +0100 | [diff] [blame] | 1381 | return !(size % (PAGE_SIZE >> 9) || !is_power_of_2(size) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | size > ti->len); |
| 1383 | } |
| 1384 | |
| 1385 | static int get_mirror(struct mirror_set *ms, struct dm_target *ti, |
| 1386 | unsigned int mirror, char **argv) |
| 1387 | { |
Andrew Morton | 4ee218c | 2006-03-27 01:17:48 -0800 | [diff] [blame] | 1388 | unsigned long long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | |
Andrew Morton | 4ee218c | 2006-03-27 01:17:48 -0800 | [diff] [blame] | 1390 | if (sscanf(argv[1], "%llu", &offset) != 1) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1391 | ti->error = "Invalid offset"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | return -EINVAL; |
| 1393 | } |
| 1394 | |
| 1395 | if (dm_get_device(ti, argv[0], offset, ti->len, |
| 1396 | dm_table_get_mode(ti->table), |
| 1397 | &ms->mirror[mirror].dev)) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1398 | ti->error = "Device lookup failure"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | return -ENXIO; |
| 1400 | } |
| 1401 | |
Jonathan Brassow | aa5617c | 2007-10-19 22:47:58 +0100 | [diff] [blame] | 1402 | ms->mirror[mirror].ms = ms; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1403 | atomic_set(&(ms->mirror[mirror].error_count), 0); |
| 1404 | ms->mirror[mirror].error_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | ms->mirror[mirror].offset = offset; |
| 1406 | |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | /* |
| 1411 | * Create dirty log: log_type #log_params <log_params> |
| 1412 | */ |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1413 | static struct dm_dirty_log *create_dirty_log(struct dm_target *ti, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | unsigned int argc, char **argv, |
| 1415 | unsigned int *args_used) |
| 1416 | { |
| 1417 | unsigned int param_count; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1418 | struct dm_dirty_log *dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
| 1420 | if (argc < 2) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1421 | ti->error = "Insufficient mirror log arguments"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | return NULL; |
| 1423 | } |
| 1424 | |
| 1425 | if (sscanf(argv[1], "%u", ¶m_count) != 1) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1426 | ti->error = "Invalid mirror log argument count"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | return NULL; |
| 1428 | } |
| 1429 | |
| 1430 | *args_used = 2 + param_count; |
| 1431 | |
| 1432 | if (argc < *args_used) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1433 | ti->error = "Insufficient mirror log arguments"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | return NULL; |
| 1435 | } |
| 1436 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1437 | dl = dm_dirty_log_create(argv[0], ti, param_count, argv + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | if (!dl) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1439 | ti->error = "Error creating mirror dirty log"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | return NULL; |
| 1441 | } |
| 1442 | |
| 1443 | if (!_check_region_size(ti, dl->type->get_region_size(dl))) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1444 | ti->error = "Invalid region size"; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1445 | dm_dirty_log_destroy(dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | return NULL; |
| 1447 | } |
| 1448 | |
| 1449 | return dl; |
| 1450 | } |
| 1451 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1452 | static int parse_features(struct mirror_set *ms, unsigned argc, char **argv, |
| 1453 | unsigned *args_used) |
| 1454 | { |
| 1455 | unsigned num_features; |
| 1456 | struct dm_target *ti = ms->ti; |
| 1457 | |
| 1458 | *args_used = 0; |
| 1459 | |
| 1460 | if (!argc) |
| 1461 | return 0; |
| 1462 | |
| 1463 | if (sscanf(argv[0], "%u", &num_features) != 1) { |
| 1464 | ti->error = "Invalid number of features"; |
| 1465 | return -EINVAL; |
| 1466 | } |
| 1467 | |
| 1468 | argc--; |
| 1469 | argv++; |
| 1470 | (*args_used)++; |
| 1471 | |
| 1472 | if (num_features > argc) { |
| 1473 | ti->error = "Not enough arguments to support feature count"; |
| 1474 | return -EINVAL; |
| 1475 | } |
| 1476 | |
| 1477 | if (!strcmp("handle_errors", argv[0])) |
| 1478 | ms->features |= DM_RAID1_HANDLE_ERRORS; |
| 1479 | else { |
| 1480 | ti->error = "Unrecognised feature requested"; |
| 1481 | return -EINVAL; |
| 1482 | } |
| 1483 | |
| 1484 | (*args_used)++; |
| 1485 | |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | /* |
| 1490 | * Construct a mirror mapping: |
| 1491 | * |
| 1492 | * log_type #log_params <log_params> |
| 1493 | * #mirrors [mirror_path offset]{2,} |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1494 | * [#features <features>] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | * |
| 1496 | * log_type is "core" or "disk" |
| 1497 | * #log_params is between 1 and 3 |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1498 | * |
| 1499 | * If present, features must be "handle_errors". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) |
| 1502 | { |
| 1503 | int r; |
| 1504 | unsigned int nr_mirrors, m, args_used; |
| 1505 | struct mirror_set *ms; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1506 | struct dm_dirty_log *dl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
| 1508 | dl = create_dirty_log(ti, argc, argv, &args_used); |
| 1509 | if (!dl) |
| 1510 | return -EINVAL; |
| 1511 | |
| 1512 | argv += args_used; |
| 1513 | argc -= args_used; |
| 1514 | |
| 1515 | if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 || |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 1516 | nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1517 | ti->error = "Invalid number of mirrors"; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1518 | dm_dirty_log_destroy(dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | return -EINVAL; |
| 1520 | } |
| 1521 | |
| 1522 | argv++, argc--; |
| 1523 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1524 | if (argc < nr_mirrors * 2) { |
| 1525 | ti->error = "Too few mirror arguments"; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1526 | dm_dirty_log_destroy(dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | return -EINVAL; |
| 1528 | } |
| 1529 | |
| 1530 | ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl); |
| 1531 | if (!ms) { |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1532 | dm_dirty_log_destroy(dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | return -ENOMEM; |
| 1534 | } |
| 1535 | |
| 1536 | /* Get the mirror parameter sets */ |
| 1537 | for (m = 0; m < nr_mirrors; m++) { |
| 1538 | r = get_mirror(ms, ti, m, argv); |
| 1539 | if (r) { |
| 1540 | free_context(ms, ti, m); |
| 1541 | return r; |
| 1542 | } |
| 1543 | argv += 2; |
| 1544 | argc -= 2; |
| 1545 | } |
| 1546 | |
| 1547 | ti->private = ms; |
Alasdair G Kergon | d88854f | 2005-07-07 17:59:34 -0700 | [diff] [blame] | 1548 | ti->split_io = ms->rh.region_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1550 | ms->kmirrord_wq = create_singlethread_workqueue("kmirrord"); |
| 1551 | if (!ms->kmirrord_wq) { |
| 1552 | DMERR("couldn't start kmirrord"); |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1553 | r = -ENOMEM; |
| 1554 | goto err_free_context; |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1555 | } |
| 1556 | INIT_WORK(&ms->kmirrord_work, do_mirror); |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 1557 | init_timer(&ms->timer); |
| 1558 | ms->timer_pending = 0; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1559 | INIT_WORK(&ms->trigger_event, trigger_event); |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1560 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1561 | r = parse_features(ms, argc, argv, &args_used); |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1562 | if (r) |
| 1563 | goto err_destroy_wq; |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1564 | |
| 1565 | argv += args_used; |
| 1566 | argc -= args_used; |
| 1567 | |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 1568 | /* |
| 1569 | * Any read-balancing addition depends on the |
| 1570 | * DM_RAID1_HANDLE_ERRORS flag being present. |
| 1571 | * This is because the decision to balance depends |
| 1572 | * on the sync state of a region. If the above |
| 1573 | * flag is not present, we ignore errors; and |
| 1574 | * the sync state may be inaccurate. |
| 1575 | */ |
| 1576 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1577 | if (argc) { |
| 1578 | ti->error = "Too many mirror arguments"; |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1579 | r = -EINVAL; |
| 1580 | goto err_destroy_wq; |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 1583 | r = dm_kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client); |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1584 | if (r) |
| 1585 | goto err_destroy_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1587 | wake(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | return 0; |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1589 | |
| 1590 | err_destroy_wq: |
| 1591 | destroy_workqueue(ms->kmirrord_wq); |
| 1592 | err_free_context: |
| 1593 | free_context(ms, ti, ms->nr_mirrors); |
| 1594 | return r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | static void mirror_dtr(struct dm_target *ti) |
| 1598 | { |
| 1599 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
| 1600 | |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 1601 | del_timer_sync(&ms->timer); |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1602 | flush_workqueue(ms->kmirrord_wq); |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 1603 | dm_kcopyd_client_destroy(ms->kcopyd_client); |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1604 | destroy_workqueue(ms->kmirrord_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | free_context(ms, ti, ms->nr_mirrors); |
| 1606 | } |
| 1607 | |
| 1608 | static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw) |
| 1609 | { |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1610 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | int should_wake = 0; |
| 1612 | struct bio_list *bl; |
| 1613 | |
| 1614 | bl = (rw == WRITE) ? &ms->writes : &ms->reads; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1615 | spin_lock_irqsave(&ms->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | should_wake = !(bl->head); |
| 1617 | bio_list_add(bl, bio); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1618 | spin_unlock_irqrestore(&ms->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | |
| 1620 | if (should_wake) |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1621 | wake(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | /* |
| 1625 | * Mirror mapping function |
| 1626 | */ |
| 1627 | static int mirror_map(struct dm_target *ti, struct bio *bio, |
| 1628 | union map_info *map_context) |
| 1629 | { |
| 1630 | int r, rw = bio_rw(bio); |
| 1631 | struct mirror *m; |
| 1632 | struct mirror_set *ms = ti->private; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1633 | struct dm_raid1_read_record *read_record = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | |
| 1635 | if (rw == WRITE) { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1636 | /* Save region for mirror_end_io() handler */ |
| 1637 | map_context->ll = bio_to_region(&ms->rh, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | queue_bio(ms, bio, rw); |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1639 | return DM_MAPIO_SUBMITTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | r = ms->rh.log->type->in_sync(ms->rh.log, |
| 1643 | bio_to_region(&ms->rh, bio), 0); |
| 1644 | if (r < 0 && r != -EWOULDBLOCK) |
| 1645 | return r; |
| 1646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | /* |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1648 | * If region is not in-sync queue the bio. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1650 | if (!r || (r == -EWOULDBLOCK)) { |
| 1651 | if (rw == READA) |
| 1652 | return -EWOULDBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | queue_bio(ms, bio, rw); |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1655 | return DM_MAPIO_SUBMITTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1658 | /* |
| 1659 | * The region is in-sync and we can perform reads directly. |
| 1660 | * Store enough information so we can retry if it fails. |
| 1661 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | m = choose_mirror(ms, bio->bi_sector); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1663 | if (unlikely(!m)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | return -EIO; |
| 1665 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1666 | read_record = mempool_alloc(ms->read_record_pool, GFP_NOIO); |
| 1667 | if (likely(read_record)) { |
| 1668 | dm_bio_record(&read_record->details, bio); |
| 1669 | map_context->ptr = read_record; |
| 1670 | read_record->m = m; |
| 1671 | } |
| 1672 | |
| 1673 | map_bio(m, bio); |
| 1674 | |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1675 | return DM_MAPIO_REMAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | static int mirror_end_io(struct dm_target *ti, struct bio *bio, |
| 1679 | int error, union map_info *map_context) |
| 1680 | { |
| 1681 | int rw = bio_rw(bio); |
| 1682 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1683 | struct mirror *m = NULL; |
| 1684 | struct dm_bio_details *bd = NULL; |
| 1685 | struct dm_raid1_read_record *read_record = map_context->ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | |
| 1687 | /* |
| 1688 | * We need to dec pending if this was a write. |
| 1689 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1690 | if (rw == WRITE) { |
| 1691 | rh_dec(&ms->rh, map_context->ll); |
| 1692 | return error; |
| 1693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1695 | if (error == -EOPNOTSUPP) |
| 1696 | goto out; |
| 1697 | |
| 1698 | if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio)) |
| 1699 | goto out; |
| 1700 | |
| 1701 | if (unlikely(error)) { |
| 1702 | if (!read_record) { |
| 1703 | /* |
| 1704 | * There wasn't enough memory to record necessary |
| 1705 | * information for a retry or there was no other |
| 1706 | * mirror in-sync. |
| 1707 | */ |
Adrian Bunk | e03f1a8 | 2008-02-19 19:44:19 +0000 | [diff] [blame] | 1708 | DMERR_LIMIT("Mirror read failed."); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1709 | return -EIO; |
| 1710 | } |
Adrian Bunk | e03f1a8 | 2008-02-19 19:44:19 +0000 | [diff] [blame] | 1711 | |
| 1712 | m = read_record->m; |
| 1713 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1714 | DMERR("Mirror read failed from %s. Trying alternative device.", |
| 1715 | m->dev->name); |
| 1716 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1717 | fail_mirror(m, DM_RAID1_READ_ERROR); |
| 1718 | |
| 1719 | /* |
| 1720 | * A failed read is requeued for another attempt using an intact |
| 1721 | * mirror. |
| 1722 | */ |
| 1723 | if (default_ok(m) || mirror_available(ms, bio)) { |
| 1724 | bd = &read_record->details; |
| 1725 | |
| 1726 | dm_bio_restore(bd, bio); |
| 1727 | mempool_free(read_record, ms->read_record_pool); |
| 1728 | map_context->ptr = NULL; |
| 1729 | queue_bio(ms, bio, rw); |
| 1730 | return 1; |
| 1731 | } |
| 1732 | DMERR("All replicated volumes dead, failing I/O"); |
| 1733 | } |
| 1734 | |
| 1735 | out: |
| 1736 | if (read_record) { |
| 1737 | mempool_free(read_record, ms->read_record_pool); |
| 1738 | map_context->ptr = NULL; |
| 1739 | } |
| 1740 | |
| 1741 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1744 | static void mirror_presuspend(struct dm_target *ti) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | { |
| 1746 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1747 | struct dm_dirty_log *log = ms->rh.log; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1749 | atomic_set(&ms->suspend, 1); |
| 1750 | |
| 1751 | /* |
| 1752 | * We must finish up all the work that we've |
| 1753 | * generated (i.e. recovery work). |
| 1754 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | rh_stop_recovery(&ms->rh); |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 1756 | |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 1757 | wait_event(_kmirrord_recovery_stopped, |
| 1758 | !atomic_read(&ms->rh.recovery_in_flight)); |
| 1759 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1760 | if (log->type->presuspend && log->type->presuspend(log)) |
| 1761 | /* FIXME: need better error handling */ |
| 1762 | DMWARN("log presuspend failed"); |
| 1763 | |
| 1764 | /* |
| 1765 | * Now that recovery is complete/stopped and the |
| 1766 | * delayed bios are queued, we need to wait for |
| 1767 | * the worker thread to complete. This way, |
| 1768 | * we know that all of our I/O has been pushed. |
| 1769 | */ |
| 1770 | flush_workqueue(ms->kmirrord_wq); |
| 1771 | } |
| 1772 | |
| 1773 | static void mirror_postsuspend(struct dm_target *ti) |
| 1774 | { |
| 1775 | struct mirror_set *ms = ti->private; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1776 | struct dm_dirty_log *log = ms->rh.log; |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1777 | |
Jonathan Brassow | 6b3df0d | 2007-10-19 22:47:57 +0100 | [diff] [blame] | 1778 | if (log->type->postsuspend && log->type->postsuspend(log)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | /* FIXME: need better error handling */ |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1780 | DMWARN("log postsuspend failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static void mirror_resume(struct dm_target *ti) |
| 1784 | { |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1785 | struct mirror_set *ms = ti->private; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1786 | struct dm_dirty_log *log = ms->rh.log; |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1787 | |
| 1788 | atomic_set(&ms->suspend, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | if (log->type->resume && log->type->resume(log)) |
| 1790 | /* FIXME: need better error handling */ |
| 1791 | DMWARN("log resume failed"); |
| 1792 | rh_start_recovery(&ms->rh); |
| 1793 | } |
| 1794 | |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1795 | /* |
| 1796 | * device_status_char |
| 1797 | * @m: mirror device/leg we want the status of |
| 1798 | * |
| 1799 | * We return one character representing the most severe error |
| 1800 | * we have encountered. |
| 1801 | * A => Alive - No failures |
| 1802 | * D => Dead - A write failure occurred leaving mirror out-of-sync |
| 1803 | * S => Sync - A sychronization failure occurred, mirror out-of-sync |
| 1804 | * R => Read - A read failure occurred, mirror data unaffected |
| 1805 | * |
| 1806 | * Returns: <char> |
| 1807 | */ |
| 1808 | static char device_status_char(struct mirror *m) |
| 1809 | { |
| 1810 | if (!atomic_read(&(m->error_count))) |
| 1811 | return 'A'; |
| 1812 | |
| 1813 | return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' : |
| 1814 | (test_bit(DM_RAID1_SYNC_ERROR, &(m->error_type))) ? 'S' : |
| 1815 | (test_bit(DM_RAID1_READ_ERROR, &(m->error_type))) ? 'R' : 'U'; |
| 1816 | } |
| 1817 | |
| 1818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | static int mirror_status(struct dm_target *ti, status_type_t type, |
| 1820 | char *result, unsigned int maxlen) |
| 1821 | { |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1822 | unsigned int m, sz = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1824 | struct dm_dirty_log *log = ms->rh.log; |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1825 | char buffer[ms->nr_mirrors + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | switch (type) { |
| 1828 | case STATUSTYPE_INFO: |
| 1829 | DMEMIT("%d ", ms->nr_mirrors); |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1830 | for (m = 0; m < ms->nr_mirrors; m++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | DMEMIT("%s ", ms->mirror[m].dev->name); |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1832 | buffer[m] = device_status_char(&(ms->mirror[m])); |
| 1833 | } |
| 1834 | buffer[m] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1836 | DMEMIT("%llu/%llu 1 %s ", |
| 1837 | (unsigned long long)log->type->get_sync_count(ms->rh.log), |
| 1838 | (unsigned long long)ms->nr_regions, buffer); |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1839 | |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1840 | sz += log->type->status(ms->rh.log, type, result+sz, maxlen-sz); |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | break; |
| 1843 | |
| 1844 | case STATUSTYPE_TABLE: |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1845 | sz = log->type->status(ms->rh.log, type, result, maxlen); |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1846 | |
Jonathan Brassow | e52b8f6 | 2006-10-03 01:15:32 -0700 | [diff] [blame] | 1847 | DMEMIT("%d", ms->nr_mirrors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | for (m = 0; m < ms->nr_mirrors; m++) |
Jonathan Brassow | e52b8f6 | 2006-10-03 01:15:32 -0700 | [diff] [blame] | 1849 | DMEMIT(" %s %llu", ms->mirror[m].dev->name, |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1850 | (unsigned long long)ms->mirror[m].offset); |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1851 | |
| 1852 | if (ms->features & DM_RAID1_HANDLE_ERRORS) |
| 1853 | DMEMIT(" 1 handle_errors"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | static struct target_type mirror_target = { |
| 1860 | .name = "mirror", |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1861 | .version = {1, 0, 20}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | .module = THIS_MODULE, |
| 1863 | .ctr = mirror_ctr, |
| 1864 | .dtr = mirror_dtr, |
| 1865 | .map = mirror_map, |
| 1866 | .end_io = mirror_end_io, |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1867 | .presuspend = mirror_presuspend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | .postsuspend = mirror_postsuspend, |
| 1869 | .resume = mirror_resume, |
| 1870 | .status = mirror_status, |
| 1871 | }; |
| 1872 | |
| 1873 | static int __init dm_mirror_init(void) |
| 1874 | { |
| 1875 | int r; |
| 1876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | r = dm_register_target(&mirror_target); |
Heinz Mauelshagen | 769aef3 | 2008-04-24 21:43:09 +0100 | [diff] [blame] | 1878 | if (r < 0) |
Alasdair G Kergon | 0cd3312 | 2007-07-12 17:27:01 +0100 | [diff] [blame] | 1879 | DMERR("Failed to register mirror target"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | |
| 1881 | return r; |
| 1882 | } |
| 1883 | |
| 1884 | static void __exit dm_mirror_exit(void) |
| 1885 | { |
| 1886 | int r; |
| 1887 | |
| 1888 | r = dm_unregister_target(&mirror_target); |
| 1889 | if (r < 0) |
Alasdair G Kergon | 0cd3312 | 2007-07-12 17:27:01 +0100 | [diff] [blame] | 1890 | DMERR("unregister failed %d", r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | /* Module hooks */ |
| 1894 | module_init(dm_mirror_init); |
| 1895 | module_exit(dm_mirror_exit); |
| 1896 | |
| 1897 | MODULE_DESCRIPTION(DM_NAME " mirror target"); |
| 1898 | MODULE_AUTHOR("Joe Thornber"); |
| 1899 | MODULE_LICENSE("GPL"); |