Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dm-snapshot.c |
| 3 | * |
| 4 | * Copyright (C) 2001-2002 Sistina Software (UK) Limited. |
| 5 | * |
| 6 | * This file is released under the GPL. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/device-mapper.h> |
Mikulas Patocka | 90fa152 | 2009-01-06 03:04:54 +0000 | [diff] [blame] | 11 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/fs.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/kdev_t.h> |
| 15 | #include <linux/list.h> |
| 16 | #include <linux/mempool.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/vmalloc.h> |
vignesh babu | 6f3c3f0 | 2007-10-19 22:38:44 +0100 | [diff] [blame] | 20 | #include <linux/log2.h> |
Alasdair G Kergon | a765e20 | 2008-04-24 22:02:01 +0100 | [diff] [blame] | 21 | #include <linux/dm-kcopyd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Jonathan Brassow | aea53d9 | 2009-01-06 03:05:15 +0000 | [diff] [blame] | 23 | #include "dm-exception-store.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 25 | #define DM_MSG_PREFIX "snapshots" |
| 26 | |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 27 | static const char dm_snapshot_merge_target_name[] = "snapshot-merge"; |
| 28 | |
| 29 | #define dm_target_is_snapshot_merge(ti) \ |
| 30 | ((ti)->type->name == dm_snapshot_merge_target_name) |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | /* |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 33 | * The size of the mempool used to track chunks in use. |
| 34 | */ |
| 35 | #define MIN_IOS 256 |
| 36 | |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 37 | #define DM_TRACKED_CHUNK_HASH_SIZE 16 |
| 38 | #define DM_TRACKED_CHUNK_HASH(x) ((unsigned long)(x) & \ |
| 39 | (DM_TRACKED_CHUNK_HASH_SIZE - 1)) |
| 40 | |
Jon Brassow | 191437a | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 41 | struct dm_exception_table { |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 42 | uint32_t hash_mask; |
| 43 | unsigned hash_shift; |
| 44 | struct list_head *table; |
| 45 | }; |
| 46 | |
| 47 | struct dm_snapshot { |
| 48 | struct rw_semaphore lock; |
| 49 | |
| 50 | struct dm_dev *origin; |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 51 | struct dm_dev *cow; |
| 52 | |
| 53 | struct dm_target *ti; |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 54 | |
| 55 | /* List of snapshots per Origin */ |
| 56 | struct list_head list; |
| 57 | |
Mike Snitzer | d8ddb1c | 2009-12-10 23:52:35 +0000 | [diff] [blame] | 58 | /* |
| 59 | * You can't use a snapshot if this is 0 (e.g. if full). |
| 60 | * A snapshot-merge target never clears this. |
| 61 | */ |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 62 | int valid; |
| 63 | |
| 64 | /* Origin writes don't trigger exceptions until this is set */ |
| 65 | int active; |
| 66 | |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 67 | atomic_t pending_exceptions_count; |
| 68 | |
Mike Snitzer | 924e600 | 2010-03-06 02:32:33 +0000 | [diff] [blame] | 69 | mempool_t *pending_pool; |
| 70 | |
Jon Brassow | 191437a | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 71 | struct dm_exception_table pending; |
| 72 | struct dm_exception_table complete; |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * pe_lock protects all pending_exception operations and access |
| 76 | * as well as the snapshot_bios list. |
| 77 | */ |
| 78 | spinlock_t pe_lock; |
| 79 | |
Mike Snitzer | 924e600 | 2010-03-06 02:32:33 +0000 | [diff] [blame] | 80 | /* Chunks with outstanding reads */ |
| 81 | spinlock_t tracked_chunk_lock; |
Mike Snitzer | 924e600 | 2010-03-06 02:32:33 +0000 | [diff] [blame] | 82 | struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE]; |
| 83 | |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 84 | /* The on disk metadata handler */ |
| 85 | struct dm_exception_store *store; |
| 86 | |
| 87 | struct dm_kcopyd_client *kcopyd_client; |
| 88 | |
Mike Snitzer | 924e600 | 2010-03-06 02:32:33 +0000 | [diff] [blame] | 89 | /* Wait for events based on state_bits */ |
| 90 | unsigned long state_bits; |
| 91 | |
| 92 | /* Range of chunks currently being merged. */ |
| 93 | chunk_t first_merging_chunk; |
| 94 | int num_merging_chunks; |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 95 | |
Mike Snitzer | d8ddb1c | 2009-12-10 23:52:35 +0000 | [diff] [blame] | 96 | /* |
| 97 | * The merge operation failed if this flag is set. |
| 98 | * Failure modes are handled as follows: |
| 99 | * - I/O error reading the header |
| 100 | * => don't load the target; abort. |
| 101 | * - Header does not have "valid" flag set |
| 102 | * => use the origin; forget about the snapshot. |
| 103 | * - I/O error when reading exceptions |
| 104 | * => don't load the target; abort. |
| 105 | * (We can't use the intermediate origin state.) |
| 106 | * - I/O error while merging |
| 107 | * => stop merging; set merge_failed; process I/O normally. |
| 108 | */ |
| 109 | int merge_failed; |
| 110 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 111 | /* |
| 112 | * Incoming bios that overlap with chunks being merged must wait |
| 113 | * for them to be committed. |
| 114 | */ |
| 115 | struct bio_list bios_queued_during_merge; |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 118 | /* |
| 119 | * state_bits: |
| 120 | * RUNNING_MERGE - Merge operation is in progress. |
| 121 | * SHUTDOWN_MERGE - Set to signal that merge needs to be stopped; |
| 122 | * cleared afterwards. |
| 123 | */ |
| 124 | #define RUNNING_MERGE 0 |
| 125 | #define SHUTDOWN_MERGE 1 |
| 126 | |
Mikulas Patocka | c241104 | 2010-08-12 04:13:51 +0100 | [diff] [blame] | 127 | struct dm_dev *dm_snap_origin(struct dm_snapshot *s) |
| 128 | { |
| 129 | return s->origin; |
| 130 | } |
| 131 | EXPORT_SYMBOL(dm_snap_origin); |
| 132 | |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 133 | struct dm_dev *dm_snap_cow(struct dm_snapshot *s) |
| 134 | { |
| 135 | return s->cow; |
| 136 | } |
| 137 | EXPORT_SYMBOL(dm_snap_cow); |
| 138 | |
Jonathan Brassow | ccc45ea | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 139 | static sector_t chunk_to_sector(struct dm_exception_store *store, |
| 140 | chunk_t chunk) |
| 141 | { |
| 142 | return chunk << store->chunk_shift; |
| 143 | } |
| 144 | |
| 145 | static int bdev_equal(struct block_device *lhs, struct block_device *rhs) |
| 146 | { |
| 147 | /* |
| 148 | * There is only ever one instance of a particular block |
| 149 | * device so we can compare pointers safely. |
| 150 | */ |
| 151 | return lhs == rhs; |
| 152 | } |
| 153 | |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 154 | struct dm_snap_pending_exception { |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 155 | struct dm_exception e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Origin buffers waiting for this to complete are held |
| 159 | * in a bio list |
| 160 | */ |
| 161 | struct bio_list origin_bios; |
| 162 | struct bio_list snapshot_bios; |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* Pointer back to snapshot context */ |
| 165 | struct dm_snapshot *snap; |
| 166 | |
| 167 | /* |
| 168 | * 1 indicates the exception has already been sent to |
| 169 | * kcopyd. |
| 170 | */ |
| 171 | int started; |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 172 | |
| 173 | /* |
| 174 | * For writing a complete chunk, bypassing the copy. |
| 175 | */ |
| 176 | struct bio *full_bio; |
| 177 | bio_end_io_t *full_bio_end_io; |
| 178 | void *full_bio_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | /* |
| 182 | * Hash table mapping origin volumes to lists of snapshots and |
| 183 | * a lock to protect it |
| 184 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 185 | static struct kmem_cache *exception_cache; |
| 186 | static struct kmem_cache *pending_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 188 | struct dm_snap_tracked_chunk { |
| 189 | struct hlist_node node; |
| 190 | chunk_t chunk; |
| 191 | }; |
| 192 | |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 193 | static void init_tracked_chunk(struct bio *bio) |
| 194 | { |
| 195 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); |
| 196 | INIT_HLIST_NODE(&c->node); |
| 197 | } |
| 198 | |
| 199 | static bool is_bio_tracked(struct bio *bio) |
| 200 | { |
| 201 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); |
| 202 | return !hlist_unhashed(&c->node); |
| 203 | } |
| 204 | |
| 205 | static void track_chunk(struct dm_snapshot *s, struct bio *bio, chunk_t chunk) |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 206 | { |
Mikulas Patocka | 42bc954 | 2012-12-21 20:23:38 +0000 | [diff] [blame] | 207 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 208 | |
| 209 | c->chunk = chunk; |
| 210 | |
Mikulas Patocka | 9aa0c0e | 2012-12-21 20:23:33 +0000 | [diff] [blame] | 211 | spin_lock_irq(&s->tracked_chunk_lock); |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 212 | hlist_add_head(&c->node, |
| 213 | &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]); |
Mikulas Patocka | 9aa0c0e | 2012-12-21 20:23:33 +0000 | [diff] [blame] | 214 | spin_unlock_irq(&s->tracked_chunk_lock); |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 215 | } |
| 216 | |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 217 | static void stop_tracking_chunk(struct dm_snapshot *s, struct bio *bio) |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 218 | { |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 219 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 220 | unsigned long flags; |
| 221 | |
| 222 | spin_lock_irqsave(&s->tracked_chunk_lock, flags); |
| 223 | hlist_del(&c->node); |
| 224 | spin_unlock_irqrestore(&s->tracked_chunk_lock, flags); |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Mikulas Patocka | a8d41b5 | 2008-07-21 12:00:34 +0100 | [diff] [blame] | 227 | static int __chunk_is_tracked(struct dm_snapshot *s, chunk_t chunk) |
| 228 | { |
| 229 | struct dm_snap_tracked_chunk *c; |
Mikulas Patocka | a8d41b5 | 2008-07-21 12:00:34 +0100 | [diff] [blame] | 230 | int found = 0; |
| 231 | |
| 232 | spin_lock_irq(&s->tracked_chunk_lock); |
| 233 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 234 | hlist_for_each_entry(c, |
Mikulas Patocka | a8d41b5 | 2008-07-21 12:00:34 +0100 | [diff] [blame] | 235 | &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)], node) { |
| 236 | if (c->chunk == chunk) { |
| 237 | found = 1; |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | spin_unlock_irq(&s->tracked_chunk_lock); |
| 243 | |
| 244 | return found; |
| 245 | } |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | /* |
Mike Snitzer | 615d1eb | 2009-12-10 23:52:29 +0000 | [diff] [blame] | 248 | * This conflicting I/O is extremely improbable in the caller, |
| 249 | * so msleep(1) is sufficient and there is no need for a wait queue. |
| 250 | */ |
| 251 | static void __check_for_conflicting_io(struct dm_snapshot *s, chunk_t chunk) |
| 252 | { |
| 253 | while (__chunk_is_tracked(s, chunk)) |
| 254 | msleep(1); |
| 255 | } |
| 256 | |
| 257 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | * One of these per registered origin, held in the snapshot_origins hash |
| 259 | */ |
| 260 | struct origin { |
| 261 | /* The origin device */ |
| 262 | struct block_device *bdev; |
| 263 | |
| 264 | struct list_head hash_list; |
| 265 | |
| 266 | /* List of snapshots for this origin */ |
| 267 | struct list_head snapshots; |
| 268 | }; |
| 269 | |
| 270 | /* |
| 271 | * Size of the hash table for origin volumes. If we make this |
| 272 | * the size of the minors list then it should be nearly perfect |
| 273 | */ |
| 274 | #define ORIGIN_HASH_SIZE 256 |
| 275 | #define ORIGIN_MASK 0xFF |
| 276 | static struct list_head *_origins; |
| 277 | static struct rw_semaphore _origins_lock; |
| 278 | |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 279 | static DECLARE_WAIT_QUEUE_HEAD(_pending_exceptions_done); |
| 280 | static DEFINE_SPINLOCK(_pending_exceptions_done_spinlock); |
| 281 | static uint64_t _pending_exceptions_done_count; |
| 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | static int init_origin_hash(void) |
| 284 | { |
| 285 | int i; |
| 286 | |
| 287 | _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head), |
| 288 | GFP_KERNEL); |
| 289 | if (!_origins) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 290 | DMERR("unable to allocate memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return -ENOMEM; |
| 292 | } |
| 293 | |
| 294 | for (i = 0; i < ORIGIN_HASH_SIZE; i++) |
| 295 | INIT_LIST_HEAD(_origins + i); |
| 296 | init_rwsem(&_origins_lock); |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static void exit_origin_hash(void) |
| 302 | { |
| 303 | kfree(_origins); |
| 304 | } |
| 305 | |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 306 | static unsigned origin_hash(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
| 308 | return bdev->bd_dev & ORIGIN_MASK; |
| 309 | } |
| 310 | |
| 311 | static struct origin *__lookup_origin(struct block_device *origin) |
| 312 | { |
| 313 | struct list_head *ol; |
| 314 | struct origin *o; |
| 315 | |
| 316 | ol = &_origins[origin_hash(origin)]; |
| 317 | list_for_each_entry (o, ol, hash_list) |
| 318 | if (bdev_equal(o->bdev, origin)) |
| 319 | return o; |
| 320 | |
| 321 | return NULL; |
| 322 | } |
| 323 | |
| 324 | static void __insert_origin(struct origin *o) |
| 325 | { |
| 326 | struct list_head *sl = &_origins[origin_hash(o->bdev)]; |
| 327 | list_add_tail(&o->hash_list, sl); |
| 328 | } |
| 329 | |
| 330 | /* |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 331 | * _origins_lock must be held when calling this function. |
| 332 | * Returns number of snapshots registered using the supplied cow device, plus: |
| 333 | * snap_src - a snapshot suitable for use as a source of exception handover |
| 334 | * snap_dest - a snapshot capable of receiving exception handover. |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 335 | * snap_merge - an existing snapshot-merge target linked to the same origin. |
| 336 | * There can be at most one snapshot-merge target. The parameter is optional. |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 337 | * |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 338 | * Possible return values and states of snap_src and snap_dest. |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 339 | * 0: NULL, NULL - first new snapshot |
| 340 | * 1: snap_src, NULL - normal snapshot |
| 341 | * 2: snap_src, snap_dest - waiting for handover |
| 342 | * 2: snap_src, NULL - handed over, waiting for old to be deleted |
| 343 | * 1: NULL, snap_dest - source got destroyed without handover |
| 344 | */ |
| 345 | static int __find_snapshots_sharing_cow(struct dm_snapshot *snap, |
| 346 | struct dm_snapshot **snap_src, |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 347 | struct dm_snapshot **snap_dest, |
| 348 | struct dm_snapshot **snap_merge) |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 349 | { |
| 350 | struct dm_snapshot *s; |
| 351 | struct origin *o; |
| 352 | int count = 0; |
| 353 | int active; |
| 354 | |
| 355 | o = __lookup_origin(snap->origin->bdev); |
| 356 | if (!o) |
| 357 | goto out; |
| 358 | |
| 359 | list_for_each_entry(s, &o->snapshots, list) { |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 360 | if (dm_target_is_snapshot_merge(s->ti) && snap_merge) |
| 361 | *snap_merge = s; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 362 | if (!bdev_equal(s->cow->bdev, snap->cow->bdev)) |
| 363 | continue; |
| 364 | |
| 365 | down_read(&s->lock); |
| 366 | active = s->active; |
| 367 | up_read(&s->lock); |
| 368 | |
| 369 | if (active) { |
| 370 | if (snap_src) |
| 371 | *snap_src = s; |
| 372 | } else if (snap_dest) |
| 373 | *snap_dest = s; |
| 374 | |
| 375 | count++; |
| 376 | } |
| 377 | |
| 378 | out: |
| 379 | return count; |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * On success, returns 1 if this snapshot is a handover destination, |
| 384 | * otherwise returns 0. |
| 385 | */ |
| 386 | static int __validate_exception_handover(struct dm_snapshot *snap) |
| 387 | { |
| 388 | struct dm_snapshot *snap_src = NULL, *snap_dest = NULL; |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 389 | struct dm_snapshot *snap_merge = NULL; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 390 | |
| 391 | /* Does snapshot need exceptions handed over to it? */ |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 392 | if ((__find_snapshots_sharing_cow(snap, &snap_src, &snap_dest, |
| 393 | &snap_merge) == 2) || |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 394 | snap_dest) { |
| 395 | snap->ti->error = "Snapshot cow pairing for exception " |
| 396 | "table handover failed"; |
| 397 | return -EINVAL; |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * If no snap_src was found, snap cannot become a handover |
| 402 | * destination. |
| 403 | */ |
| 404 | if (!snap_src) |
| 405 | return 0; |
| 406 | |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 407 | /* |
| 408 | * Non-snapshot-merge handover? |
| 409 | */ |
| 410 | if (!dm_target_is_snapshot_merge(snap->ti)) |
| 411 | return 1; |
| 412 | |
| 413 | /* |
| 414 | * Do not allow more than one merging snapshot. |
| 415 | */ |
| 416 | if (snap_merge) { |
| 417 | snap->ti->error = "A snapshot is already merging."; |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 421 | if (!snap_src->store->type->prepare_merge || |
| 422 | !snap_src->store->type->commit_merge) { |
| 423 | snap->ti->error = "Snapshot exception store does not " |
| 424 | "support snapshot-merge."; |
| 425 | return -EINVAL; |
| 426 | } |
| 427 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 428 | return 1; |
| 429 | } |
| 430 | |
| 431 | static void __insert_snapshot(struct origin *o, struct dm_snapshot *s) |
| 432 | { |
| 433 | struct dm_snapshot *l; |
| 434 | |
| 435 | /* Sort the list according to chunk size, largest-first smallest-last */ |
| 436 | list_for_each_entry(l, &o->snapshots, list) |
| 437 | if (l->store->chunk_size < s->store->chunk_size) |
| 438 | break; |
| 439 | list_add_tail(&s->list, &l->list); |
| 440 | } |
| 441 | |
| 442 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | * Make a note of the snapshot and its origin so we can look it |
| 444 | * up when the origin has a write on it. |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 445 | * |
| 446 | * Also validate snapshot exception store handovers. |
| 447 | * On success, returns 1 if this registration is a handover destination, |
| 448 | * otherwise returns 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | */ |
| 450 | static int register_snapshot(struct dm_snapshot *snap) |
| 451 | { |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 452 | struct origin *o, *new_o = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | struct block_device *bdev = snap->origin->bdev; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 454 | int r = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Mikulas Patocka | 60c856c8 | 2008-10-30 13:33:12 +0000 | [diff] [blame] | 456 | new_o = kmalloc(sizeof(*new_o), GFP_KERNEL); |
| 457 | if (!new_o) |
| 458 | return -ENOMEM; |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | down_write(&_origins_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 462 | r = __validate_exception_handover(snap); |
| 463 | if (r < 0) { |
| 464 | kfree(new_o); |
| 465 | goto out; |
| 466 | } |
| 467 | |
| 468 | o = __lookup_origin(bdev); |
Mikulas Patocka | 60c856c8 | 2008-10-30 13:33:12 +0000 | [diff] [blame] | 469 | if (o) |
| 470 | kfree(new_o); |
| 471 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | /* New origin */ |
Mikulas Patocka | 60c856c8 | 2008-10-30 13:33:12 +0000 | [diff] [blame] | 473 | o = new_o; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* Initialise the struct */ |
| 476 | INIT_LIST_HEAD(&o->snapshots); |
| 477 | o->bdev = bdev; |
| 478 | |
| 479 | __insert_origin(o); |
| 480 | } |
| 481 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 482 | __insert_snapshot(o, snap); |
| 483 | |
| 484 | out: |
| 485 | up_write(&_origins_lock); |
| 486 | |
| 487 | return r; |
| 488 | } |
| 489 | |
| 490 | /* |
| 491 | * Move snapshot to correct place in list according to chunk size. |
| 492 | */ |
| 493 | static void reregister_snapshot(struct dm_snapshot *s) |
| 494 | { |
| 495 | struct block_device *bdev = s->origin->bdev; |
| 496 | |
| 497 | down_write(&_origins_lock); |
| 498 | |
| 499 | list_del(&s->list); |
| 500 | __insert_snapshot(__lookup_origin(bdev), s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 502 | up_write(&_origins_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static void unregister_snapshot(struct dm_snapshot *s) |
| 506 | { |
| 507 | struct origin *o; |
| 508 | |
| 509 | down_write(&_origins_lock); |
| 510 | o = __lookup_origin(s->origin->bdev); |
| 511 | |
| 512 | list_del(&s->list); |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 513 | if (o && list_empty(&o->snapshots)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | list_del(&o->hash_list); |
| 515 | kfree(o); |
| 516 | } |
| 517 | |
| 518 | up_write(&_origins_lock); |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | * Implementation of the exception hash tables. |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 523 | * The lowest hash_shift bits of the chunk number are ignored, allowing |
| 524 | * some consecutive chunks to be grouped together. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | */ |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 526 | static int dm_exception_table_init(struct dm_exception_table *et, |
| 527 | uint32_t size, unsigned hash_shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | unsigned int i; |
| 530 | |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 531 | et->hash_shift = hash_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | et->hash_mask = size - 1; |
| 533 | et->table = dm_vcalloc(size, sizeof(struct list_head)); |
| 534 | if (!et->table) |
| 535 | return -ENOMEM; |
| 536 | |
| 537 | for (i = 0; i < size; i++) |
| 538 | INIT_LIST_HEAD(et->table + i); |
| 539 | |
| 540 | return 0; |
| 541 | } |
| 542 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 543 | static void dm_exception_table_exit(struct dm_exception_table *et, |
| 544 | struct kmem_cache *mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
| 546 | struct list_head *slot; |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 547 | struct dm_exception *ex, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | int i, size; |
| 549 | |
| 550 | size = et->hash_mask + 1; |
| 551 | for (i = 0; i < size; i++) { |
| 552 | slot = et->table + i; |
| 553 | |
| 554 | list_for_each_entry_safe (ex, next, slot, hash_list) |
| 555 | kmem_cache_free(mem, ex); |
| 556 | } |
| 557 | |
| 558 | vfree(et->table); |
| 559 | } |
| 560 | |
Jon Brassow | 191437a | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 561 | static uint32_t exception_hash(struct dm_exception_table *et, chunk_t chunk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 563 | return (chunk >> et->hash_shift) & et->hash_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 566 | static void dm_remove_exception(struct dm_exception *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
| 568 | list_del(&e->hash_list); |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * Return the exception data for a sector, or NULL if not |
| 573 | * remapped. |
| 574 | */ |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 575 | static struct dm_exception *dm_lookup_exception(struct dm_exception_table *et, |
| 576 | chunk_t chunk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
| 578 | struct list_head *slot; |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 579 | struct dm_exception *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
| 581 | slot = &et->table[exception_hash(et, chunk)]; |
| 582 | list_for_each_entry (e, slot, hash_list) |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 583 | if (chunk >= e->old_chunk && |
| 584 | chunk <= e->old_chunk + dm_consecutive_chunk_count(e)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | return e; |
| 586 | |
| 587 | return NULL; |
| 588 | } |
| 589 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 590 | static struct dm_exception *alloc_completed_exception(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 592 | struct dm_exception *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | e = kmem_cache_alloc(exception_cache, GFP_NOIO); |
| 595 | if (!e) |
| 596 | e = kmem_cache_alloc(exception_cache, GFP_ATOMIC); |
| 597 | |
| 598 | return e; |
| 599 | } |
| 600 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 601 | static void free_completed_exception(struct dm_exception *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
| 603 | kmem_cache_free(exception_cache, e); |
| 604 | } |
| 605 | |
Mikulas Patocka | 92e8681 | 2008-07-21 12:00:35 +0100 | [diff] [blame] | 606 | static struct dm_snap_pending_exception *alloc_pending_exception(struct dm_snapshot *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
Mikulas Patocka | 92e8681 | 2008-07-21 12:00:35 +0100 | [diff] [blame] | 608 | struct dm_snap_pending_exception *pe = mempool_alloc(s->pending_pool, |
| 609 | GFP_NOIO); |
| 610 | |
Mikulas Patocka | 879129d2 | 2008-10-30 13:33:16 +0000 | [diff] [blame] | 611 | atomic_inc(&s->pending_exceptions_count); |
Mikulas Patocka | 92e8681 | 2008-07-21 12:00:35 +0100 | [diff] [blame] | 612 | pe->snap = s; |
| 613 | |
| 614 | return pe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 617 | static void free_pending_exception(struct dm_snap_pending_exception *pe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
Mikulas Patocka | 879129d2 | 2008-10-30 13:33:16 +0000 | [diff] [blame] | 619 | struct dm_snapshot *s = pe->snap; |
| 620 | |
| 621 | mempool_free(pe, s->pending_pool); |
| 622 | smp_mb__before_atomic_dec(); |
| 623 | atomic_dec(&s->pending_exceptions_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 626 | static void dm_insert_exception(struct dm_exception_table *eh, |
| 627 | struct dm_exception *new_e) |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 628 | { |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 629 | struct list_head *l; |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 630 | struct dm_exception *e = NULL; |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 631 | |
| 632 | l = &eh->table[exception_hash(eh, new_e->old_chunk)]; |
| 633 | |
| 634 | /* Add immediately if this table doesn't support consecutive chunks */ |
| 635 | if (!eh->hash_shift) |
| 636 | goto out; |
| 637 | |
| 638 | /* List is ordered by old_chunk */ |
| 639 | list_for_each_entry_reverse(e, l, hash_list) { |
| 640 | /* Insert after an existing chunk? */ |
| 641 | if (new_e->old_chunk == (e->old_chunk + |
| 642 | dm_consecutive_chunk_count(e) + 1) && |
| 643 | new_e->new_chunk == (dm_chunk_number(e->new_chunk) + |
| 644 | dm_consecutive_chunk_count(e) + 1)) { |
| 645 | dm_consecutive_chunk_count_inc(e); |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 646 | free_completed_exception(new_e); |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 647 | return; |
| 648 | } |
| 649 | |
| 650 | /* Insert before an existing chunk? */ |
| 651 | if (new_e->old_chunk == (e->old_chunk - 1) && |
| 652 | new_e->new_chunk == (dm_chunk_number(e->new_chunk) - 1)) { |
| 653 | dm_consecutive_chunk_count_inc(e); |
| 654 | e->old_chunk--; |
| 655 | e->new_chunk--; |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 656 | free_completed_exception(new_e); |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 657 | return; |
| 658 | } |
| 659 | |
| 660 | if (new_e->old_chunk > e->old_chunk) |
| 661 | break; |
| 662 | } |
| 663 | |
| 664 | out: |
| 665 | list_add(&new_e->hash_list, e ? &e->hash_list : l); |
| 666 | } |
| 667 | |
Jonathan Brassow | a159c1a | 2009-01-06 03:05:19 +0000 | [diff] [blame] | 668 | /* |
| 669 | * Callback used by the exception stores to load exceptions when |
| 670 | * initialising. |
| 671 | */ |
| 672 | static int dm_add_exception(void *context, chunk_t old, chunk_t new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
Jonathan Brassow | a159c1a | 2009-01-06 03:05:19 +0000 | [diff] [blame] | 674 | struct dm_snapshot *s = context; |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 675 | struct dm_exception *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 677 | e = alloc_completed_exception(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | if (!e) |
| 679 | return -ENOMEM; |
| 680 | |
| 681 | e->old_chunk = old; |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 682 | |
| 683 | /* Consecutive_count is implicitly initialised to zero */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | e->new_chunk = new; |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 685 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 686 | dm_insert_exception(&s->complete, e); |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return 0; |
| 689 | } |
| 690 | |
Mikulas Patocka | 7e201b3 | 2009-12-10 23:52:08 +0000 | [diff] [blame] | 691 | /* |
| 692 | * Return a minimum chunk size of all snapshots that have the specified origin. |
| 693 | * Return zero if the origin has no snapshots. |
| 694 | */ |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 695 | static uint32_t __minimum_chunk_size(struct origin *o) |
Mikulas Patocka | 7e201b3 | 2009-12-10 23:52:08 +0000 | [diff] [blame] | 696 | { |
| 697 | struct dm_snapshot *snap; |
| 698 | unsigned chunk_size = 0; |
| 699 | |
| 700 | if (o) |
| 701 | list_for_each_entry(snap, &o->snapshots, list) |
| 702 | chunk_size = min_not_zero(chunk_size, |
| 703 | snap->store->chunk_size); |
| 704 | |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 705 | return (uint32_t) chunk_size; |
Mikulas Patocka | 7e201b3 | 2009-12-10 23:52:08 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | /* |
| 709 | * Hard coded magic. |
| 710 | */ |
| 711 | static int calc_max_buckets(void) |
| 712 | { |
| 713 | /* use a fixed size of 2MB */ |
| 714 | unsigned long mem = 2 * 1024 * 1024; |
| 715 | mem /= sizeof(struct list_head); |
| 716 | |
| 717 | return mem; |
| 718 | } |
| 719 | |
| 720 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | * Allocate room for a suitable hash table. |
| 722 | */ |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 723 | static int init_hash_tables(struct dm_snapshot *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
| 725 | sector_t hash_size, cow_dev_size, origin_dev_size, max_buckets; |
| 726 | |
| 727 | /* |
| 728 | * Calculate based on the size of the original volume or |
| 729 | * the COW volume... |
| 730 | */ |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 731 | cow_dev_size = get_dev_size(s->cow->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | origin_dev_size = get_dev_size(s->origin->bdev); |
| 733 | max_buckets = calc_max_buckets(); |
| 734 | |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 735 | hash_size = min(origin_dev_size, cow_dev_size) >> s->store->chunk_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | hash_size = min(hash_size, max_buckets); |
| 737 | |
Mikulas Patocka | 8e87b9b | 2009-12-10 23:51:54 +0000 | [diff] [blame] | 738 | if (hash_size < 64) |
| 739 | hash_size = 64; |
Robert P. J. Day | 8defd83 | 2008-02-08 02:10:06 +0000 | [diff] [blame] | 740 | hash_size = rounddown_pow_of_two(hash_size); |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 741 | if (dm_exception_table_init(&s->complete, hash_size, |
| 742 | DM_CHUNK_CONSECUTIVE_BITS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | return -ENOMEM; |
| 744 | |
| 745 | /* |
| 746 | * Allocate hash table for in-flight exceptions |
| 747 | * Make this smaller than the real hash table |
| 748 | */ |
| 749 | hash_size >>= 3; |
| 750 | if (hash_size < 64) |
| 751 | hash_size = 64; |
| 752 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 753 | if (dm_exception_table_init(&s->pending, hash_size, 0)) { |
| 754 | dm_exception_table_exit(&s->complete, exception_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | return -ENOMEM; |
| 756 | } |
| 757 | |
| 758 | return 0; |
| 759 | } |
| 760 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 761 | static void merge_shutdown(struct dm_snapshot *s) |
| 762 | { |
| 763 | clear_bit_unlock(RUNNING_MERGE, &s->state_bits); |
| 764 | smp_mb__after_clear_bit(); |
| 765 | wake_up_bit(&s->state_bits, RUNNING_MERGE); |
| 766 | } |
| 767 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 768 | static struct bio *__release_queued_bios_after_merge(struct dm_snapshot *s) |
| 769 | { |
| 770 | s->first_merging_chunk = 0; |
| 771 | s->num_merging_chunks = 0; |
| 772 | |
| 773 | return bio_list_get(&s->bios_queued_during_merge); |
| 774 | } |
| 775 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 776 | /* |
| 777 | * Remove one chunk from the index of completed exceptions. |
| 778 | */ |
| 779 | static int __remove_single_exception_chunk(struct dm_snapshot *s, |
| 780 | chunk_t old_chunk) |
| 781 | { |
| 782 | struct dm_exception *e; |
| 783 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 784 | e = dm_lookup_exception(&s->complete, old_chunk); |
| 785 | if (!e) { |
| 786 | DMERR("Corruption detected: exception for block %llu is " |
| 787 | "on disk but not in memory", |
| 788 | (unsigned long long)old_chunk); |
| 789 | return -EINVAL; |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * If this is the only chunk using this exception, remove exception. |
| 794 | */ |
| 795 | if (!dm_consecutive_chunk_count(e)) { |
| 796 | dm_remove_exception(e); |
| 797 | free_completed_exception(e); |
| 798 | return 0; |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * The chunk may be either at the beginning or the end of a |
| 803 | * group of consecutive chunks - never in the middle. We are |
| 804 | * removing chunks in the opposite order to that in which they |
| 805 | * were added, so this should always be true. |
| 806 | * Decrement the consecutive chunk counter and adjust the |
| 807 | * starting point if necessary. |
| 808 | */ |
| 809 | if (old_chunk == e->old_chunk) { |
| 810 | e->old_chunk++; |
| 811 | e->new_chunk++; |
| 812 | } else if (old_chunk != e->old_chunk + |
| 813 | dm_consecutive_chunk_count(e)) { |
| 814 | DMERR("Attempt to merge block %llu from the " |
| 815 | "middle of a chunk range [%llu - %llu]", |
| 816 | (unsigned long long)old_chunk, |
| 817 | (unsigned long long)e->old_chunk, |
| 818 | (unsigned long long) |
| 819 | e->old_chunk + dm_consecutive_chunk_count(e)); |
| 820 | return -EINVAL; |
| 821 | } |
| 822 | |
| 823 | dm_consecutive_chunk_count_dec(e); |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 828 | static void flush_bios(struct bio *bio); |
| 829 | |
| 830 | static int remove_single_exception_chunk(struct dm_snapshot *s) |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 831 | { |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 832 | struct bio *b = NULL; |
| 833 | int r; |
| 834 | chunk_t old_chunk = s->first_merging_chunk + s->num_merging_chunks - 1; |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 835 | |
| 836 | down_write(&s->lock); |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 837 | |
| 838 | /* |
| 839 | * Process chunks (and associated exceptions) in reverse order |
| 840 | * so that dm_consecutive_chunk_count_dec() accounting works. |
| 841 | */ |
| 842 | do { |
| 843 | r = __remove_single_exception_chunk(s, old_chunk); |
| 844 | if (r) |
| 845 | goto out; |
| 846 | } while (old_chunk-- > s->first_merging_chunk); |
| 847 | |
| 848 | b = __release_queued_bios_after_merge(s); |
| 849 | |
| 850 | out: |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 851 | up_write(&s->lock); |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 852 | if (b) |
| 853 | flush_bios(b); |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 854 | |
| 855 | return r; |
| 856 | } |
| 857 | |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 858 | static int origin_write_extent(struct dm_snapshot *merging_snap, |
| 859 | sector_t sector, unsigned chunk_size); |
| 860 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 861 | static void merge_callback(int read_err, unsigned long write_err, |
| 862 | void *context); |
| 863 | |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 864 | static uint64_t read_pending_exceptions_done_count(void) |
| 865 | { |
| 866 | uint64_t pending_exceptions_done; |
| 867 | |
| 868 | spin_lock(&_pending_exceptions_done_spinlock); |
| 869 | pending_exceptions_done = _pending_exceptions_done_count; |
| 870 | spin_unlock(&_pending_exceptions_done_spinlock); |
| 871 | |
| 872 | return pending_exceptions_done; |
| 873 | } |
| 874 | |
| 875 | static void increment_pending_exceptions_done_count(void) |
| 876 | { |
| 877 | spin_lock(&_pending_exceptions_done_spinlock); |
| 878 | _pending_exceptions_done_count++; |
| 879 | spin_unlock(&_pending_exceptions_done_spinlock); |
| 880 | |
| 881 | wake_up_all(&_pending_exceptions_done); |
| 882 | } |
| 883 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 884 | static void snapshot_merge_next_chunks(struct dm_snapshot *s) |
| 885 | { |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 886 | int i, linear_chunks; |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 887 | chunk_t old_chunk, new_chunk; |
| 888 | struct dm_io_region src, dest; |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 889 | sector_t io_size; |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 890 | uint64_t previous_count; |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 891 | |
| 892 | BUG_ON(!test_bit(RUNNING_MERGE, &s->state_bits)); |
| 893 | if (unlikely(test_bit(SHUTDOWN_MERGE, &s->state_bits))) |
| 894 | goto shut; |
| 895 | |
| 896 | /* |
| 897 | * valid flag never changes during merge, so no lock required. |
| 898 | */ |
| 899 | if (!s->valid) { |
| 900 | DMERR("Snapshot is invalid: can't merge"); |
| 901 | goto shut; |
| 902 | } |
| 903 | |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 904 | linear_chunks = s->store->type->prepare_merge(s->store, &old_chunk, |
| 905 | &new_chunk); |
| 906 | if (linear_chunks <= 0) { |
Mike Snitzer | d8ddb1c | 2009-12-10 23:52:35 +0000 | [diff] [blame] | 907 | if (linear_chunks < 0) { |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 908 | DMERR("Read error in exception store: " |
| 909 | "shutting down merge"); |
Mike Snitzer | d8ddb1c | 2009-12-10 23:52:35 +0000 | [diff] [blame] | 910 | down_write(&s->lock); |
| 911 | s->merge_failed = 1; |
| 912 | up_write(&s->lock); |
| 913 | } |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 914 | goto shut; |
| 915 | } |
| 916 | |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 917 | /* Adjust old_chunk and new_chunk to reflect start of linear region */ |
| 918 | old_chunk = old_chunk + 1 - linear_chunks; |
| 919 | new_chunk = new_chunk + 1 - linear_chunks; |
| 920 | |
| 921 | /* |
| 922 | * Use one (potentially large) I/O to copy all 'linear_chunks' |
| 923 | * from the exception store to the origin |
| 924 | */ |
| 925 | io_size = linear_chunks * s->store->chunk_size; |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 926 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 927 | dest.bdev = s->origin->bdev; |
| 928 | dest.sector = chunk_to_sector(s->store, old_chunk); |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 929 | dest.count = min(io_size, get_dev_size(dest.bdev) - dest.sector); |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 930 | |
| 931 | src.bdev = s->cow->bdev; |
| 932 | src.sector = chunk_to_sector(s->store, new_chunk); |
| 933 | src.count = dest.count; |
| 934 | |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 935 | /* |
| 936 | * Reallocate any exceptions needed in other snapshots then |
| 937 | * wait for the pending exceptions to complete. |
| 938 | * Each time any pending exception (globally on the system) |
| 939 | * completes we are woken and repeat the process to find out |
| 940 | * if we can proceed. While this may not seem a particularly |
| 941 | * efficient algorithm, it is not expected to have any |
| 942 | * significant impact on performance. |
| 943 | */ |
| 944 | previous_count = read_pending_exceptions_done_count(); |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 945 | while (origin_write_extent(s, dest.sector, io_size)) { |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 946 | wait_event(_pending_exceptions_done, |
| 947 | (read_pending_exceptions_done_count() != |
| 948 | previous_count)); |
| 949 | /* Retry after the wait, until all exceptions are done. */ |
| 950 | previous_count = read_pending_exceptions_done_count(); |
| 951 | } |
| 952 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 953 | down_write(&s->lock); |
| 954 | s->first_merging_chunk = old_chunk; |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 955 | s->num_merging_chunks = linear_chunks; |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 956 | up_write(&s->lock); |
| 957 | |
Mike Snitzer | 8a2d528 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 958 | /* Wait until writes to all 'linear_chunks' drain */ |
| 959 | for (i = 0; i < linear_chunks; i++) |
| 960 | __check_for_conflicting_io(s, old_chunk + i); |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 961 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 962 | dm_kcopyd_copy(s->kcopyd_client, &src, 1, &dest, 0, merge_callback, s); |
| 963 | return; |
| 964 | |
| 965 | shut: |
| 966 | merge_shutdown(s); |
| 967 | } |
| 968 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 969 | static void error_bios(struct bio *bio); |
| 970 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 971 | static void merge_callback(int read_err, unsigned long write_err, void *context) |
| 972 | { |
| 973 | struct dm_snapshot *s = context; |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 974 | struct bio *b = NULL; |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 975 | |
| 976 | if (read_err || write_err) { |
| 977 | if (read_err) |
| 978 | DMERR("Read error: shutting down merge."); |
| 979 | else |
| 980 | DMERR("Write error: shutting down merge."); |
| 981 | goto shut; |
| 982 | } |
| 983 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 984 | if (s->store->type->commit_merge(s->store, |
| 985 | s->num_merging_chunks) < 0) { |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 986 | DMERR("Write error in exception store: shutting down merge"); |
| 987 | goto shut; |
| 988 | } |
| 989 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 990 | if (remove_single_exception_chunk(s) < 0) |
| 991 | goto shut; |
| 992 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 993 | snapshot_merge_next_chunks(s); |
| 994 | |
| 995 | return; |
| 996 | |
| 997 | shut: |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 998 | down_write(&s->lock); |
Mike Snitzer | d8ddb1c | 2009-12-10 23:52:35 +0000 | [diff] [blame] | 999 | s->merge_failed = 1; |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1000 | b = __release_queued_bios_after_merge(s); |
| 1001 | up_write(&s->lock); |
| 1002 | error_bios(b); |
| 1003 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1004 | merge_shutdown(s); |
| 1005 | } |
| 1006 | |
| 1007 | static void start_merge(struct dm_snapshot *s) |
| 1008 | { |
| 1009 | if (!test_and_set_bit(RUNNING_MERGE, &s->state_bits)) |
| 1010 | snapshot_merge_next_chunks(s); |
| 1011 | } |
| 1012 | |
| 1013 | static int wait_schedule(void *ptr) |
| 1014 | { |
| 1015 | schedule(); |
| 1016 | |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | /* |
| 1021 | * Stop the merging process and wait until it finishes. |
| 1022 | */ |
| 1023 | static void stop_merge(struct dm_snapshot *s) |
| 1024 | { |
| 1025 | set_bit(SHUTDOWN_MERGE, &s->state_bits); |
| 1026 | wait_on_bit(&s->state_bits, RUNNING_MERGE, wait_schedule, |
| 1027 | TASK_UNINTERRUPTIBLE); |
| 1028 | clear_bit(SHUTDOWN_MERGE, &s->state_bits); |
| 1029 | } |
| 1030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | * Construct a snapshot mapping: <origin_dev> <COW-dev> <p/n> <chunk-size> |
| 1033 | */ |
| 1034 | static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) |
| 1035 | { |
| 1036 | struct dm_snapshot *s; |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1037 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | int r = -EINVAL; |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1039 | char *origin_path, *cow_path; |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 1040 | unsigned args_used, num_flush_bios = 1; |
Mike Snitzer | 10b8106 | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1041 | fmode_t origin_mode = FMODE_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
Mark McLoughlin | 4c7e3bf | 2006-10-03 01:15:25 -0700 | [diff] [blame] | 1043 | if (argc != 4) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1044 | ti->error = "requires exactly 4 arguments"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | r = -EINVAL; |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1046 | goto bad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Mike Snitzer | 10b8106 | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1049 | if (dm_target_is_snapshot_merge(ti)) { |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 1050 | num_flush_bios = 2; |
Mike Snitzer | 10b8106 | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1051 | origin_mode = FMODE_WRITE; |
| 1052 | } |
| 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1055 | if (!s) { |
Jonathan Brassow | a2d2b03 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1056 | ti->error = "Cannot allocate private snapshot structure"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | r = -ENOMEM; |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1058 | goto bad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Mikulas Patocka | c241104 | 2010-08-12 04:13:51 +0100 | [diff] [blame] | 1061 | origin_path = argv[0]; |
| 1062 | argv++; |
| 1063 | argc--; |
| 1064 | |
| 1065 | r = dm_get_device(ti, origin_path, origin_mode, &s->origin); |
| 1066 | if (r) { |
| 1067 | ti->error = "Cannot get origin device"; |
| 1068 | goto bad_origin; |
| 1069 | } |
| 1070 | |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1071 | cow_path = argv[0]; |
| 1072 | argv++; |
| 1073 | argc--; |
| 1074 | |
Milan Broz | 024d37e | 2011-03-24 13:52:14 +0000 | [diff] [blame] | 1075 | r = dm_get_device(ti, cow_path, dm_table_get_mode(ti->table), &s->cow); |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1076 | if (r) { |
| 1077 | ti->error = "Cannot get COW device"; |
| 1078 | goto bad_cow; |
| 1079 | } |
| 1080 | |
| 1081 | r = dm_exception_store_create(ti, argc, argv, s, &args_used, &s->store); |
| 1082 | if (r) { |
| 1083 | ti->error = "Couldn't create exception store"; |
| 1084 | r = -EINVAL; |
| 1085 | goto bad_store; |
| 1086 | } |
| 1087 | |
| 1088 | argv += args_used; |
| 1089 | argc -= args_used; |
| 1090 | |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1091 | s->ti = ti; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | s->valid = 1; |
Alasdair G Kergon | aa14ede | 2006-02-01 03:04:50 -0800 | [diff] [blame] | 1093 | s->active = 0; |
Mikulas Patocka | 879129d2 | 2008-10-30 13:33:16 +0000 | [diff] [blame] | 1094 | atomic_set(&s->pending_exceptions_count, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | init_rwsem(&s->lock); |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1096 | INIT_LIST_HEAD(&s->list); |
Alasdair G Kergon | ca3a931 | 2006-10-03 01:15:30 -0700 | [diff] [blame] | 1097 | spin_lock_init(&s->pe_lock); |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1098 | s->state_bits = 0; |
Mike Snitzer | d8ddb1c | 2009-12-10 23:52:35 +0000 | [diff] [blame] | 1099 | s->merge_failed = 0; |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1100 | s->first_merging_chunk = 0; |
| 1101 | s->num_merging_chunks = 0; |
| 1102 | bio_list_init(&s->bios_queued_during_merge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | |
| 1104 | /* Allocate hash table for COW data */ |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1105 | if (init_hash_tables(s)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | ti->error = "Unable to allocate hash table space"; |
| 1107 | r = -ENOMEM; |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1108 | goto bad_hash_tables; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Mikulas Patocka | fa34ce7 | 2011-05-29 13:03:13 +0100 | [diff] [blame] | 1111 | s->kcopyd_client = dm_kcopyd_client_create(); |
| 1112 | if (IS_ERR(s->kcopyd_client)) { |
| 1113 | r = PTR_ERR(s->kcopyd_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | ti->error = "Could not create kcopyd client"; |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1115 | goto bad_kcopyd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Mikulas Patocka | 92e8681 | 2008-07-21 12:00:35 +0100 | [diff] [blame] | 1118 | s->pending_pool = mempool_create_slab_pool(MIN_IOS, pending_cache); |
| 1119 | if (!s->pending_pool) { |
| 1120 | ti->error = "Could not allocate mempool for pending exceptions"; |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1121 | goto bad_pending_pool; |
Mikulas Patocka | 92e8681 | 2008-07-21 12:00:35 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1124 | for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++) |
| 1125 | INIT_HLIST_HEAD(&s->tracked_chunk_hash[i]); |
| 1126 | |
| 1127 | spin_lock_init(&s->tracked_chunk_lock); |
| 1128 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1129 | ti->private = s; |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 1130 | ti->num_flush_bios = num_flush_bios; |
Mikulas Patocka | 42bc954 | 2012-12-21 20:23:38 +0000 | [diff] [blame] | 1131 | ti->per_bio_data_size = sizeof(struct dm_snap_tracked_chunk); |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1132 | |
| 1133 | /* Add snapshot to the list of snapshots for this origin */ |
| 1134 | /* Exceptions aren't triggered till snapshot_resume() is called */ |
| 1135 | r = register_snapshot(s); |
| 1136 | if (r == -ENOMEM) { |
| 1137 | ti->error = "Snapshot origin struct allocation failed"; |
| 1138 | goto bad_load_and_register; |
| 1139 | } else if (r < 0) { |
| 1140 | /* invalid handover, register_snapshot has set ti->error */ |
| 1141 | goto bad_load_and_register; |
| 1142 | } |
| 1143 | |
| 1144 | /* |
| 1145 | * Metadata must only be loaded into one table at once, so skip this |
| 1146 | * if metadata will be handed over during resume. |
| 1147 | * Chunk size will be set during the handover - set it to zero to |
| 1148 | * ensure it's ignored. |
| 1149 | */ |
| 1150 | if (r > 0) { |
| 1151 | s->store->chunk_size = 0; |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
Jonathan Brassow | 493df71 | 2009-04-02 19:55:31 +0100 | [diff] [blame] | 1155 | r = s->store->type->read_metadata(s->store, dm_add_exception, |
| 1156 | (void *)s); |
Milan Broz | 0764147 | 2007-07-12 17:28:13 +0100 | [diff] [blame] | 1157 | if (r < 0) { |
Mark McLoughlin | f9cea4f | 2006-10-03 01:15:25 -0700 | [diff] [blame] | 1158 | ti->error = "Failed to read snapshot metadata"; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1159 | goto bad_read_metadata; |
Milan Broz | 0764147 | 2007-07-12 17:28:13 +0100 | [diff] [blame] | 1160 | } else if (r > 0) { |
| 1161 | s->valid = 0; |
| 1162 | DMWARN("Snapshot is marked invalid."); |
Mark McLoughlin | f9cea4f | 2006-10-03 01:15:25 -0700 | [diff] [blame] | 1163 | } |
Alasdair G Kergon | aa14ede | 2006-02-01 03:04:50 -0800 | [diff] [blame] | 1164 | |
Mikulas Patocka | 3f2412d | 2009-10-16 23:18:16 +0100 | [diff] [blame] | 1165 | if (!s->store->chunk_size) { |
| 1166 | ti->error = "Chunk size not set"; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1167 | goto bad_read_metadata; |
Mikulas Patocka | 3f2412d | 2009-10-16 23:18:16 +0100 | [diff] [blame] | 1168 | } |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1169 | |
| 1170 | r = dm_set_target_max_io_len(ti, s->store->chunk_size); |
| 1171 | if (r) |
| 1172 | goto bad_read_metadata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
| 1174 | return 0; |
| 1175 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1176 | bad_read_metadata: |
| 1177 | unregister_snapshot(s); |
| 1178 | |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1179 | bad_load_and_register: |
Mikulas Patocka | 92e8681 | 2008-07-21 12:00:35 +0100 | [diff] [blame] | 1180 | mempool_destroy(s->pending_pool); |
| 1181 | |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1182 | bad_pending_pool: |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 1183 | dm_kcopyd_client_destroy(s->kcopyd_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1185 | bad_kcopyd: |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1186 | dm_exception_table_exit(&s->pending, pending_cache); |
| 1187 | dm_exception_table_exit(&s->complete, exception_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1189 | bad_hash_tables: |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1190 | dm_exception_store_destroy(s->store); |
| 1191 | |
| 1192 | bad_store: |
| 1193 | dm_put_device(ti, s->cow); |
| 1194 | |
| 1195 | bad_cow: |
Mikulas Patocka | c241104 | 2010-08-12 04:13:51 +0100 | [diff] [blame] | 1196 | dm_put_device(ti, s->origin); |
| 1197 | |
| 1198 | bad_origin: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | kfree(s); |
| 1200 | |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1201 | bad: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | return r; |
| 1203 | } |
| 1204 | |
Milan Broz | 31c93a0c | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 1205 | static void __free_exceptions(struct dm_snapshot *s) |
| 1206 | { |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 1207 | dm_kcopyd_client_destroy(s->kcopyd_client); |
Milan Broz | 31c93a0c | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 1208 | s->kcopyd_client = NULL; |
| 1209 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1210 | dm_exception_table_exit(&s->pending, pending_cache); |
| 1211 | dm_exception_table_exit(&s->complete, exception_cache); |
Milan Broz | 31c93a0c | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 1212 | } |
| 1213 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1214 | static void __handover_exceptions(struct dm_snapshot *snap_src, |
| 1215 | struct dm_snapshot *snap_dest) |
| 1216 | { |
| 1217 | union { |
| 1218 | struct dm_exception_table table_swap; |
| 1219 | struct dm_exception_store *store_swap; |
| 1220 | } u; |
| 1221 | |
| 1222 | /* |
| 1223 | * Swap all snapshot context information between the two instances. |
| 1224 | */ |
| 1225 | u.table_swap = snap_dest->complete; |
| 1226 | snap_dest->complete = snap_src->complete; |
| 1227 | snap_src->complete = u.table_swap; |
| 1228 | |
| 1229 | u.store_swap = snap_dest->store; |
| 1230 | snap_dest->store = snap_src->store; |
| 1231 | snap_src->store = u.store_swap; |
| 1232 | |
| 1233 | snap_dest->store->snap = snap_dest; |
| 1234 | snap_src->store->snap = snap_src; |
| 1235 | |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1236 | snap_dest->ti->max_io_len = snap_dest->store->chunk_size; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1237 | snap_dest->valid = snap_src->valid; |
| 1238 | |
| 1239 | /* |
| 1240 | * Set source invalid to ensure it receives no further I/O. |
| 1241 | */ |
| 1242 | snap_src->valid = 0; |
| 1243 | } |
| 1244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | static void snapshot_dtr(struct dm_target *ti) |
| 1246 | { |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1247 | #ifdef CONFIG_DM_DEBUG |
| 1248 | int i; |
| 1249 | #endif |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1250 | struct dm_snapshot *s = ti->private; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1251 | struct dm_snapshot *snap_src = NULL, *snap_dest = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1253 | down_read(&_origins_lock); |
| 1254 | /* Check whether exception handover must be cancelled */ |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1255 | (void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL); |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1256 | if (snap_src && snap_dest && (s == snap_src)) { |
| 1257 | down_write(&snap_dest->lock); |
| 1258 | snap_dest->valid = 0; |
| 1259 | up_write(&snap_dest->lock); |
| 1260 | DMERR("Cancelling snapshot handover."); |
| 1261 | } |
| 1262 | up_read(&_origins_lock); |
| 1263 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1264 | if (dm_target_is_snapshot_merge(ti)) |
| 1265 | stop_merge(s); |
| 1266 | |
Alasdair G Kergon | 138728dc | 2006-03-27 01:17:50 -0800 | [diff] [blame] | 1267 | /* Prevent further origin writes from using this snapshot. */ |
| 1268 | /* After this returns there can be no new kcopyd jobs. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | unregister_snapshot(s); |
| 1270 | |
Mikulas Patocka | 879129d2 | 2008-10-30 13:33:16 +0000 | [diff] [blame] | 1271 | while (atomic_read(&s->pending_exceptions_count)) |
Mikulas Patocka | 90fa152 | 2009-01-06 03:04:54 +0000 | [diff] [blame] | 1272 | msleep(1); |
Mikulas Patocka | 879129d2 | 2008-10-30 13:33:16 +0000 | [diff] [blame] | 1273 | /* |
| 1274 | * Ensure instructions in mempool_destroy aren't reordered |
| 1275 | * before atomic_read. |
| 1276 | */ |
| 1277 | smp_mb(); |
| 1278 | |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1279 | #ifdef CONFIG_DM_DEBUG |
| 1280 | for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++) |
| 1281 | BUG_ON(!hlist_empty(&s->tracked_chunk_hash[i])); |
| 1282 | #endif |
| 1283 | |
Milan Broz | 31c93a0c | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 1284 | __free_exceptions(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
Mikulas Patocka | 92e8681 | 2008-07-21 12:00:35 +0100 | [diff] [blame] | 1286 | mempool_destroy(s->pending_pool); |
| 1287 | |
Jonathan Brassow | fee1998 | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1288 | dm_exception_store_destroy(s->store); |
Alasdair G Kergon | 138728dc | 2006-03-27 01:17:50 -0800 | [diff] [blame] | 1289 | |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1290 | dm_put_device(ti, s->cow); |
| 1291 | |
Mikulas Patocka | c241104 | 2010-08-12 04:13:51 +0100 | [diff] [blame] | 1292 | dm_put_device(ti, s->origin); |
| 1293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | kfree(s); |
| 1295 | } |
| 1296 | |
| 1297 | /* |
| 1298 | * Flush a list of buffers. |
| 1299 | */ |
| 1300 | static void flush_bios(struct bio *bio) |
| 1301 | { |
| 1302 | struct bio *n; |
| 1303 | |
| 1304 | while (bio) { |
| 1305 | n = bio->bi_next; |
| 1306 | bio->bi_next = NULL; |
| 1307 | generic_make_request(bio); |
| 1308 | bio = n; |
| 1309 | } |
| 1310 | } |
| 1311 | |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 1312 | static int do_origin(struct dm_dev *origin, struct bio *bio); |
| 1313 | |
| 1314 | /* |
| 1315 | * Flush a list of buffers. |
| 1316 | */ |
| 1317 | static void retry_origin_bios(struct dm_snapshot *s, struct bio *bio) |
| 1318 | { |
| 1319 | struct bio *n; |
| 1320 | int r; |
| 1321 | |
| 1322 | while (bio) { |
| 1323 | n = bio->bi_next; |
| 1324 | bio->bi_next = NULL; |
| 1325 | r = do_origin(s->origin, bio); |
| 1326 | if (r == DM_MAPIO_REMAPPED) |
| 1327 | generic_make_request(bio); |
| 1328 | bio = n; |
| 1329 | } |
| 1330 | } |
| 1331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | /* |
| 1333 | * Error a list of buffers. |
| 1334 | */ |
| 1335 | static void error_bios(struct bio *bio) |
| 1336 | { |
| 1337 | struct bio *n; |
| 1338 | |
| 1339 | while (bio) { |
| 1340 | n = bio->bi_next; |
| 1341 | bio->bi_next = NULL; |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1342 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | bio = n; |
| 1344 | } |
| 1345 | } |
| 1346 | |
Alasdair G Kergon | 695368a | 2006-10-03 01:15:31 -0700 | [diff] [blame] | 1347 | static void __invalidate_snapshot(struct dm_snapshot *s, int err) |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1348 | { |
| 1349 | if (!s->valid) |
| 1350 | return; |
| 1351 | |
| 1352 | if (err == -EIO) |
| 1353 | DMERR("Invalidating snapshot: Error reading/writing."); |
| 1354 | else if (err == -ENOMEM) |
| 1355 | DMERR("Invalidating snapshot: Unable to allocate exception."); |
| 1356 | |
Jonathan Brassow | 493df71 | 2009-04-02 19:55:31 +0100 | [diff] [blame] | 1357 | if (s->store->type->drop_snapshot) |
| 1358 | s->store->type->drop_snapshot(s->store); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1359 | |
| 1360 | s->valid = 0; |
| 1361 | |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1362 | dm_table_event(s->ti->table); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1363 | } |
| 1364 | |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1365 | static void pending_complete(struct dm_snap_pending_exception *pe, int success) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | { |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 1367 | struct dm_exception *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | struct dm_snapshot *s = pe->snap; |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1369 | struct bio *origin_bios = NULL; |
| 1370 | struct bio *snapshot_bios = NULL; |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1371 | struct bio *full_bio = NULL; |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1372 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1374 | if (!success) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | /* Read/write error - snapshot is unusable */ |
| 1376 | down_write(&s->lock); |
Alasdair G Kergon | 695368a | 2006-10-03 01:15:31 -0700 | [diff] [blame] | 1377 | __invalidate_snapshot(s, -EIO); |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1378 | error = 1; |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1379 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1382 | e = alloc_completed_exception(); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1383 | if (!e) { |
| 1384 | down_write(&s->lock); |
Alasdair G Kergon | 695368a | 2006-10-03 01:15:31 -0700 | [diff] [blame] | 1385 | __invalidate_snapshot(s, -ENOMEM); |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1386 | error = 1; |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1387 | goto out; |
| 1388 | } |
| 1389 | *e = pe->e; |
| 1390 | |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1391 | down_write(&s->lock); |
| 1392 | if (!s->valid) { |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1393 | free_completed_exception(e); |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1394 | error = 1; |
| 1395 | goto out; |
| 1396 | } |
| 1397 | |
Mike Snitzer | 615d1eb | 2009-12-10 23:52:29 +0000 | [diff] [blame] | 1398 | /* Check for conflicting reads */ |
| 1399 | __check_for_conflicting_io(s, pe->e.old_chunk); |
Mikulas Patocka | a8d41b5 | 2008-07-21 12:00:34 +0100 | [diff] [blame] | 1400 | |
| 1401 | /* |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1402 | * Add a proper exception, and remove the |
| 1403 | * in-flight exception from the list. |
| 1404 | */ |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1405 | dm_insert_exception(&s->complete, e); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1406 | |
Jonathan Brassow | a2d2b03 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1407 | out: |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1408 | dm_remove_exception(&pe->e); |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1409 | snapshot_bios = bio_list_get(&pe->snapshot_bios); |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 1410 | origin_bios = bio_list_get(&pe->origin_bios); |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1411 | full_bio = pe->full_bio; |
| 1412 | if (full_bio) { |
| 1413 | full_bio->bi_end_io = pe->full_bio_end_io; |
| 1414 | full_bio->bi_private = pe->full_bio_private; |
| 1415 | } |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 1416 | free_pending_exception(pe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 1418 | increment_pending_exceptions_done_count(); |
| 1419 | |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1420 | up_write(&s->lock); |
| 1421 | |
| 1422 | /* Submit any pending write bios */ |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1423 | if (error) { |
| 1424 | if (full_bio) |
| 1425 | bio_io_error(full_bio); |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1426 | error_bios(snapshot_bios); |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1427 | } else { |
| 1428 | if (full_bio) |
| 1429 | bio_endio(full_bio, 0); |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1430 | flush_bios(snapshot_bios); |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1431 | } |
Alasdair G Kergon | 9d493fa | 2006-10-03 01:15:29 -0700 | [diff] [blame] | 1432 | |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 1433 | retry_origin_bios(s, origin_bios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | static void commit_callback(void *context, int success) |
| 1437 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1438 | struct dm_snap_pending_exception *pe = context; |
| 1439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | pending_complete(pe, success); |
| 1441 | } |
| 1442 | |
| 1443 | /* |
| 1444 | * Called when the copy I/O has finished. kcopyd actually runs |
| 1445 | * this code so don't block. |
| 1446 | */ |
Alasdair G Kergon | 4cdc1d1 | 2008-03-28 14:16:10 -0700 | [diff] [blame] | 1447 | static void copy_callback(int read_err, unsigned long write_err, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1449 | struct dm_snap_pending_exception *pe = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | struct dm_snapshot *s = pe->snap; |
| 1451 | |
| 1452 | if (read_err || write_err) |
| 1453 | pending_complete(pe, 0); |
| 1454 | |
| 1455 | else |
| 1456 | /* Update the metadata if we are persistent */ |
Jonathan Brassow | 493df71 | 2009-04-02 19:55:31 +0100 | [diff] [blame] | 1457 | s->store->type->commit_exception(s->store, &pe->e, |
| 1458 | commit_callback, pe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /* |
| 1462 | * Dispatches the copy operation to kcopyd. |
| 1463 | */ |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1464 | static void start_copy(struct dm_snap_pending_exception *pe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | { |
| 1466 | struct dm_snapshot *s = pe->snap; |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 1467 | struct dm_io_region src, dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | struct block_device *bdev = s->origin->bdev; |
| 1469 | sector_t dev_size; |
| 1470 | |
| 1471 | dev_size = get_dev_size(bdev); |
| 1472 | |
| 1473 | src.bdev = bdev; |
Jonathan Brassow | 71fab00 | 2009-04-02 19:55:33 +0100 | [diff] [blame] | 1474 | src.sector = chunk_to_sector(s->store, pe->e.old_chunk); |
Mikulas Patocka | df96eee | 2009-10-16 23:18:17 +0100 | [diff] [blame] | 1475 | src.count = min((sector_t)s->store->chunk_size, dev_size - src.sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1477 | dest.bdev = s->cow->bdev; |
Jonathan Brassow | 71fab00 | 2009-04-02 19:55:33 +0100 | [diff] [blame] | 1478 | dest.sector = chunk_to_sector(s->store, pe->e.new_chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | dest.count = src.count; |
| 1480 | |
| 1481 | /* Hand over to kcopyd */ |
Jonathan Brassow | a2d2b03 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1482 | dm_kcopyd_copy(s->kcopyd_client, &src, 1, &dest, 0, copy_callback, pe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1485 | static void full_bio_end_io(struct bio *bio, int error) |
| 1486 | { |
| 1487 | void *callback_data = bio->bi_private; |
| 1488 | |
| 1489 | dm_kcopyd_do_callback(callback_data, 0, error ? 1 : 0); |
| 1490 | } |
| 1491 | |
| 1492 | static void start_full_bio(struct dm_snap_pending_exception *pe, |
| 1493 | struct bio *bio) |
| 1494 | { |
| 1495 | struct dm_snapshot *s = pe->snap; |
| 1496 | void *callback_data; |
| 1497 | |
| 1498 | pe->full_bio = bio; |
| 1499 | pe->full_bio_end_io = bio->bi_end_io; |
| 1500 | pe->full_bio_private = bio->bi_private; |
| 1501 | |
| 1502 | callback_data = dm_kcopyd_prepare_callback(s->kcopyd_client, |
| 1503 | copy_callback, pe); |
| 1504 | |
| 1505 | bio->bi_end_io = full_bio_end_io; |
| 1506 | bio->bi_private = callback_data; |
| 1507 | |
| 1508 | generic_make_request(bio); |
| 1509 | } |
| 1510 | |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1511 | static struct dm_snap_pending_exception * |
| 1512 | __lookup_pending_exception(struct dm_snapshot *s, chunk_t chunk) |
| 1513 | { |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1514 | struct dm_exception *e = dm_lookup_exception(&s->pending, chunk); |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1515 | |
| 1516 | if (!e) |
| 1517 | return NULL; |
| 1518 | |
| 1519 | return container_of(e, struct dm_snap_pending_exception, e); |
| 1520 | } |
| 1521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | /* |
| 1523 | * Looks to see if this snapshot already has a pending exception |
| 1524 | * for this chunk, otherwise it allocates a new one and inserts |
| 1525 | * it into the pending table. |
| 1526 | * |
| 1527 | * NOTE: a write lock must be held on snap->lock before calling |
| 1528 | * this. |
| 1529 | */ |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1530 | static struct dm_snap_pending_exception * |
Mikulas Patocka | c662139 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1531 | __find_pending_exception(struct dm_snapshot *s, |
| 1532 | struct dm_snap_pending_exception *pe, chunk_t chunk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | { |
Mikulas Patocka | c662139 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1534 | struct dm_snap_pending_exception *pe2; |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1535 | |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1536 | pe2 = __lookup_pending_exception(s, chunk); |
| 1537 | if (pe2) { |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1538 | free_pending_exception(pe); |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1539 | return pe2; |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | pe->e.old_chunk = chunk; |
| 1543 | bio_list_init(&pe->origin_bios); |
| 1544 | bio_list_init(&pe->snapshot_bios); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1545 | pe->started = 0; |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1546 | pe->full_bio = NULL; |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1547 | |
Jonathan Brassow | 493df71 | 2009-04-02 19:55:31 +0100 | [diff] [blame] | 1548 | if (s->store->type->prepare_exception(s->store, &pe->e)) { |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1549 | free_pending_exception(pe); |
| 1550 | return NULL; |
| 1551 | } |
| 1552 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1553 | dm_insert_exception(&s->pending, &pe->e); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | return pe; |
| 1556 | } |
| 1557 | |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 1558 | static void remap_exception(struct dm_snapshot *s, struct dm_exception *e, |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 1559 | struct bio *bio, chunk_t chunk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | { |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1561 | bio->bi_bdev = s->cow->bdev; |
Jonathan Brassow | 71fab00 | 2009-04-02 19:55:33 +0100 | [diff] [blame] | 1562 | bio->bi_sector = chunk_to_sector(s->store, |
| 1563 | dm_chunk_number(e->new_chunk) + |
| 1564 | (chunk - e->old_chunk)) + |
| 1565 | (bio->bi_sector & |
| 1566 | s->store->chunk_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1569 | static int snapshot_map(struct dm_target *ti, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 1571 | struct dm_exception *e; |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1572 | struct dm_snapshot *s = ti->private; |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1573 | int r = DM_MAPIO_REMAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | chunk_t chunk; |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1575 | struct dm_snap_pending_exception *pe = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1577 | init_tracked_chunk(bio); |
| 1578 | |
Tejun Heo | d87f4c1 | 2010-09-03 11:56:19 +0200 | [diff] [blame] | 1579 | if (bio->bi_rw & REQ_FLUSH) { |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1580 | bio->bi_bdev = s->cow->bdev; |
Mikulas Patocka | 494b3ee | 2009-06-22 10:12:25 +0100 | [diff] [blame] | 1581 | return DM_MAPIO_REMAPPED; |
| 1582 | } |
| 1583 | |
Jonathan Brassow | 71fab00 | 2009-04-02 19:55:33 +0100 | [diff] [blame] | 1584 | chunk = sector_to_chunk(s->store, bio->bi_sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | |
| 1586 | /* Full snapshots are not usable */ |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1587 | /* To get here the table must be live so s->active is always set. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | if (!s->valid) |
Alasdair G Kergon | f6a80ea | 2005-07-12 15:53:01 -0700 | [diff] [blame] | 1589 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1591 | /* FIXME: should only take write lock if we need |
| 1592 | * to copy an exception */ |
| 1593 | down_write(&s->lock); |
| 1594 | |
| 1595 | if (!s->valid) { |
| 1596 | r = -EIO; |
| 1597 | goto out_unlock; |
| 1598 | } |
| 1599 | |
| 1600 | /* If the block is already remapped - use that, else remap it */ |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1601 | e = dm_lookup_exception(&s->complete, chunk); |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1602 | if (e) { |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 1603 | remap_exception(s, e, bio, chunk); |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1604 | goto out_unlock; |
| 1605 | } |
| 1606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | /* |
| 1608 | * Write to snapshot - higher level takes care of RW/RO |
| 1609 | * flags so we should only get this if we are |
| 1610 | * writeable. |
| 1611 | */ |
| 1612 | if (bio_rw(bio) == WRITE) { |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1613 | pe = __lookup_pending_exception(s, chunk); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1614 | if (!pe) { |
Mikulas Patocka | c662139 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1615 | up_write(&s->lock); |
| 1616 | pe = alloc_pending_exception(s); |
| 1617 | down_write(&s->lock); |
| 1618 | |
| 1619 | if (!s->valid) { |
| 1620 | free_pending_exception(pe); |
| 1621 | r = -EIO; |
| 1622 | goto out_unlock; |
| 1623 | } |
| 1624 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1625 | e = dm_lookup_exception(&s->complete, chunk); |
Mikulas Patocka | 35bf659 | 2009-04-02 19:55:26 +0100 | [diff] [blame] | 1626 | if (e) { |
| 1627 | free_pending_exception(pe); |
| 1628 | remap_exception(s, e, bio, chunk); |
| 1629 | goto out_unlock; |
| 1630 | } |
| 1631 | |
Mikulas Patocka | c662139 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1632 | pe = __find_pending_exception(s, pe, chunk); |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1633 | if (!pe) { |
| 1634 | __invalidate_snapshot(s, -ENOMEM); |
| 1635 | r = -EIO; |
| 1636 | goto out_unlock; |
| 1637 | } |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1638 | } |
| 1639 | |
Milan Broz | d74f81f | 2008-02-08 02:11:27 +0000 | [diff] [blame] | 1640 | remap_exception(s, &pe->e, bio, chunk); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1641 | |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1642 | r = DM_MAPIO_SUBMITTED; |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1643 | |
Mikulas Patocka | a6e50b4 | 2011-08-02 12:32:04 +0100 | [diff] [blame] | 1644 | if (!pe->started && |
| 1645 | bio->bi_size == (s->store->chunk_size << SECTOR_SHIFT)) { |
| 1646 | pe->started = 1; |
| 1647 | up_write(&s->lock); |
| 1648 | start_full_bio(pe, bio); |
| 1649 | goto out; |
| 1650 | } |
| 1651 | |
| 1652 | bio_list_add(&pe->snapshot_bios, bio); |
| 1653 | |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1654 | if (!pe->started) { |
| 1655 | /* this is protected by snap->lock */ |
| 1656 | pe->started = 1; |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1657 | up_write(&s->lock); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1658 | start_copy(pe); |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1659 | goto out; |
| 1660 | } |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1661 | } else { |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1662 | bio->bi_bdev = s->origin->bdev; |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1663 | track_chunk(s, bio, chunk); |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
Jonathan Brassow | a2d2b03 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1666 | out_unlock: |
Alasdair G Kergon | ba40a2a | 2006-10-03 01:15:28 -0700 | [diff] [blame] | 1667 | up_write(&s->lock); |
Jonathan Brassow | a2d2b03 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1668 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | return r; |
| 1670 | } |
| 1671 | |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1672 | /* |
| 1673 | * A snapshot-merge target behaves like a combination of a snapshot |
| 1674 | * target and a snapshot-origin target. It only generates new |
| 1675 | * exceptions in other snapshots and not in the one that is being |
| 1676 | * merged. |
| 1677 | * |
| 1678 | * For each chunk, if there is an existing exception, it is used to |
| 1679 | * redirect I/O to the cow device. Otherwise I/O is sent to the origin, |
| 1680 | * which in turn might generate exceptions in other snapshots. |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1681 | * If merging is currently taking place on the chunk in question, the |
| 1682 | * I/O is deferred by adding it to s->bios_queued_during_merge. |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1683 | */ |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1684 | static int snapshot_merge_map(struct dm_target *ti, struct bio *bio) |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1685 | { |
| 1686 | struct dm_exception *e; |
| 1687 | struct dm_snapshot *s = ti->private; |
| 1688 | int r = DM_MAPIO_REMAPPED; |
| 1689 | chunk_t chunk; |
| 1690 | |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1691 | init_tracked_chunk(bio); |
| 1692 | |
Tejun Heo | d87f4c1 | 2010-09-03 11:56:19 +0200 | [diff] [blame] | 1693 | if (bio->bi_rw & REQ_FLUSH) { |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 1694 | if (!dm_bio_get_target_bio_nr(bio)) |
Mike Snitzer | 10b8106 | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1695 | bio->bi_bdev = s->origin->bdev; |
| 1696 | else |
| 1697 | bio->bi_bdev = s->cow->bdev; |
Mike Snitzer | 10b8106 | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1698 | return DM_MAPIO_REMAPPED; |
| 1699 | } |
| 1700 | |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1701 | chunk = sector_to_chunk(s->store, bio->bi_sector); |
| 1702 | |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1703 | down_write(&s->lock); |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1704 | |
Mikulas Patocka | d2fdb77 | 2009-12-10 23:52:36 +0000 | [diff] [blame] | 1705 | /* Full merging snapshots are redirected to the origin */ |
| 1706 | if (!s->valid) |
| 1707 | goto redirect_to_origin; |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1708 | |
| 1709 | /* If the block is already remapped - use that */ |
| 1710 | e = dm_lookup_exception(&s->complete, chunk); |
| 1711 | if (e) { |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1712 | /* Queue writes overlapping with chunks being merged */ |
| 1713 | if (bio_rw(bio) == WRITE && |
| 1714 | chunk >= s->first_merging_chunk && |
| 1715 | chunk < (s->first_merging_chunk + |
| 1716 | s->num_merging_chunks)) { |
| 1717 | bio->bi_bdev = s->origin->bdev; |
| 1718 | bio_list_add(&s->bios_queued_during_merge, bio); |
| 1719 | r = DM_MAPIO_SUBMITTED; |
| 1720 | goto out_unlock; |
| 1721 | } |
Mikulas Patocka | 17aa033 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1722 | |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1723 | remap_exception(s, e, bio, chunk); |
Mikulas Patocka | 17aa033 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1724 | |
| 1725 | if (bio_rw(bio) == WRITE) |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1726 | track_chunk(s, bio, chunk); |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1727 | goto out_unlock; |
| 1728 | } |
| 1729 | |
Mikulas Patocka | d2fdb77 | 2009-12-10 23:52:36 +0000 | [diff] [blame] | 1730 | redirect_to_origin: |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1731 | bio->bi_bdev = s->origin->bdev; |
| 1732 | |
| 1733 | if (bio_rw(bio) == WRITE) { |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1734 | up_write(&s->lock); |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1735 | return do_origin(s->origin, bio); |
| 1736 | } |
| 1737 | |
| 1738 | out_unlock: |
Mikulas Patocka | 9fe86254 | 2009-12-10 23:52:33 +0000 | [diff] [blame] | 1739 | up_write(&s->lock); |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1740 | |
| 1741 | return r; |
| 1742 | } |
| 1743 | |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1744 | static int snapshot_end_io(struct dm_target *ti, struct bio *bio, int error) |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1745 | { |
| 1746 | struct dm_snapshot *s = ti->private; |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1747 | |
Mikulas Patocka | ee18026 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1748 | if (is_bio_tracked(bio)) |
| 1749 | stop_tracking_chunk(s, bio); |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 1750 | |
| 1751 | return 0; |
| 1752 | } |
| 1753 | |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1754 | static void snapshot_merge_presuspend(struct dm_target *ti) |
| 1755 | { |
| 1756 | struct dm_snapshot *s = ti->private; |
| 1757 | |
| 1758 | stop_merge(s); |
| 1759 | } |
| 1760 | |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1761 | static int snapshot_preresume(struct dm_target *ti) |
| 1762 | { |
| 1763 | int r = 0; |
| 1764 | struct dm_snapshot *s = ti->private; |
| 1765 | struct dm_snapshot *snap_src = NULL, *snap_dest = NULL; |
| 1766 | |
| 1767 | down_read(&_origins_lock); |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1768 | (void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL); |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1769 | if (snap_src && snap_dest) { |
| 1770 | down_read(&snap_src->lock); |
| 1771 | if (s == snap_src) { |
| 1772 | DMERR("Unable to resume snapshot source until " |
| 1773 | "handover completes."); |
| 1774 | r = -EINVAL; |
Mike Snitzer | b83b2f2 | 2011-01-13 19:59:59 +0000 | [diff] [blame] | 1775 | } else if (!dm_suspended(snap_src->ti)) { |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1776 | DMERR("Unable to perform snapshot handover until " |
| 1777 | "source is suspended."); |
| 1778 | r = -EINVAL; |
| 1779 | } |
| 1780 | up_read(&snap_src->lock); |
| 1781 | } |
| 1782 | up_read(&_origins_lock); |
| 1783 | |
| 1784 | return r; |
| 1785 | } |
| 1786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | static void snapshot_resume(struct dm_target *ti) |
| 1788 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1789 | struct dm_snapshot *s = ti->private; |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1790 | struct dm_snapshot *snap_src = NULL, *snap_dest = NULL; |
| 1791 | |
| 1792 | down_read(&_origins_lock); |
Mikulas Patocka | 9d3b15c | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1793 | (void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL); |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 1794 | if (snap_src && snap_dest) { |
| 1795 | down_write(&snap_src->lock); |
| 1796 | down_write_nested(&snap_dest->lock, SINGLE_DEPTH_NESTING); |
| 1797 | __handover_exceptions(snap_src, snap_dest); |
| 1798 | up_write(&snap_dest->lock); |
| 1799 | up_write(&snap_src->lock); |
| 1800 | } |
| 1801 | up_read(&_origins_lock); |
| 1802 | |
| 1803 | /* Now we have correct chunk size, reregister */ |
| 1804 | reregister_snapshot(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
Alasdair G Kergon | aa14ede | 2006-02-01 03:04:50 -0800 | [diff] [blame] | 1806 | down_write(&s->lock); |
| 1807 | s->active = 1; |
| 1808 | up_write(&s->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1811 | static uint32_t get_origin_minimum_chunksize(struct block_device *bdev) |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1812 | { |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1813 | uint32_t min_chunksize; |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1814 | |
| 1815 | down_read(&_origins_lock); |
| 1816 | min_chunksize = __minimum_chunk_size(__lookup_origin(bdev)); |
| 1817 | up_read(&_origins_lock); |
| 1818 | |
| 1819 | return min_chunksize; |
| 1820 | } |
| 1821 | |
| 1822 | static void snapshot_merge_resume(struct dm_target *ti) |
| 1823 | { |
| 1824 | struct dm_snapshot *s = ti->private; |
| 1825 | |
| 1826 | /* |
| 1827 | * Handover exceptions from existing snapshot. |
| 1828 | */ |
| 1829 | snapshot_resume(ti); |
| 1830 | |
| 1831 | /* |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1832 | * snapshot-merge acts as an origin, so set ti->max_io_len |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1833 | */ |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1834 | ti->max_io_len = get_origin_minimum_chunksize(s->origin->bdev); |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 1835 | |
| 1836 | start_merge(s); |
| 1837 | } |
| 1838 | |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 1839 | static void snapshot_status(struct dm_target *ti, status_type_t type, |
| 1840 | unsigned status_flags, char *result, unsigned maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | { |
Jonathan Brassow | 2e4a31d | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1842 | unsigned sz = 0; |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 1843 | struct dm_snapshot *snap = ti->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
| 1845 | switch (type) { |
| 1846 | case STATUSTYPE_INFO: |
Mikulas Patocka | 94e76572 | 2009-12-10 23:51:53 +0000 | [diff] [blame] | 1847 | |
| 1848 | down_write(&snap->lock); |
| 1849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | if (!snap->valid) |
Jonathan Brassow | 2e4a31d | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1851 | DMEMIT("Invalid"); |
Mike Snitzer | d8ddb1c | 2009-12-10 23:52:35 +0000 | [diff] [blame] | 1852 | else if (snap->merge_failed) |
| 1853 | DMEMIT("Merge failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | else { |
Mike Snitzer | 985903b | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1855 | if (snap->store->type->usage) { |
| 1856 | sector_t total_sectors, sectors_allocated, |
| 1857 | metadata_sectors; |
| 1858 | snap->store->type->usage(snap->store, |
| 1859 | &total_sectors, |
| 1860 | §ors_allocated, |
| 1861 | &metadata_sectors); |
| 1862 | DMEMIT("%llu/%llu %llu", |
| 1863 | (unsigned long long)sectors_allocated, |
| 1864 | (unsigned long long)total_sectors, |
| 1865 | (unsigned long long)metadata_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | } |
| 1867 | else |
Jonathan Brassow | 2e4a31d | 2009-04-02 19:55:34 +0100 | [diff] [blame] | 1868 | DMEMIT("Unknown"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
Mikulas Patocka | 94e76572 | 2009-12-10 23:51:53 +0000 | [diff] [blame] | 1870 | |
| 1871 | up_write(&snap->lock); |
| 1872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | break; |
| 1874 | |
| 1875 | case STATUSTYPE_TABLE: |
| 1876 | /* |
| 1877 | * kdevname returns a static pointer so we need |
| 1878 | * to make private copies if the output is to |
| 1879 | * make sense. |
| 1880 | */ |
Mike Snitzer | fc56f6f | 2009-12-10 23:52:12 +0000 | [diff] [blame] | 1881 | DMEMIT("%s %s", snap->origin->name, snap->cow->name); |
Jonathan Brassow | 1e302a9 | 2009-04-02 19:55:35 +0100 | [diff] [blame] | 1882 | snap->store->type->status(snap->store, type, result + sz, |
| 1883 | maxlen - sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | break; |
| 1885 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Mike Snitzer | 8811f46 | 2009-09-04 20:40:19 +0100 | [diff] [blame] | 1888 | static int snapshot_iterate_devices(struct dm_target *ti, |
| 1889 | iterate_devices_callout_fn fn, void *data) |
| 1890 | { |
| 1891 | struct dm_snapshot *snap = ti->private; |
Mikulas Patocka | 1e5554c | 2010-08-12 04:13:50 +0100 | [diff] [blame] | 1892 | int r; |
Mike Snitzer | 8811f46 | 2009-09-04 20:40:19 +0100 | [diff] [blame] | 1893 | |
Mikulas Patocka | 1e5554c | 2010-08-12 04:13:50 +0100 | [diff] [blame] | 1894 | r = fn(ti, snap->origin, 0, ti->len, data); |
| 1895 | |
| 1896 | if (!r) |
| 1897 | r = fn(ti, snap->cow, 0, get_dev_size(snap->cow->bdev), data); |
| 1898 | |
| 1899 | return r; |
Mike Snitzer | 8811f46 | 2009-09-04 20:40:19 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | /*----------------------------------------------------------------- |
| 1904 | * Origin methods |
| 1905 | *---------------------------------------------------------------*/ |
Mikulas Patocka | 9eaae8f | 2009-12-10 23:52:28 +0000 | [diff] [blame] | 1906 | |
| 1907 | /* |
| 1908 | * If no exceptions need creating, DM_MAPIO_REMAPPED is returned and any |
| 1909 | * supplied bio was ignored. The caller may submit it immediately. |
| 1910 | * (No remapping actually occurs as the origin is always a direct linear |
| 1911 | * map.) |
| 1912 | * |
| 1913 | * If further exceptions are required, DM_MAPIO_SUBMITTED is returned |
| 1914 | * and any supplied bio is added to a list to be submitted once all |
| 1915 | * the necessary exceptions exist. |
| 1916 | */ |
| 1917 | static int __origin_write(struct list_head *snapshots, sector_t sector, |
| 1918 | struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | { |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 1920 | int r = DM_MAPIO_REMAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | struct dm_snapshot *snap; |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 1922 | struct dm_exception *e; |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 1923 | struct dm_snap_pending_exception *pe; |
| 1924 | struct dm_snap_pending_exception *pe_to_start_now = NULL; |
| 1925 | struct dm_snap_pending_exception *pe_to_start_last = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | chunk_t chunk; |
| 1927 | |
| 1928 | /* Do all the snapshots on this origin */ |
| 1929 | list_for_each_entry (snap, snapshots, list) { |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 1930 | /* |
| 1931 | * Don't make new exceptions in a merging snapshot |
| 1932 | * because it has effectively been deleted |
| 1933 | */ |
| 1934 | if (dm_target_is_snapshot_merge(snap->ti)) |
| 1935 | continue; |
| 1936 | |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1937 | down_write(&snap->lock); |
| 1938 | |
Alasdair G Kergon | aa14ede | 2006-02-01 03:04:50 -0800 | [diff] [blame] | 1939 | /* Only deal with valid and active snapshots */ |
| 1940 | if (!snap->valid || !snap->active) |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1941 | goto next_snapshot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | |
Alasdair G Kergon | d5e404c | 2005-07-12 15:53:05 -0700 | [diff] [blame] | 1943 | /* Nothing to do if writing beyond end of snapshot */ |
Mikulas Patocka | 9eaae8f | 2009-12-10 23:52:28 +0000 | [diff] [blame] | 1944 | if (sector >= dm_table_get_size(snap->ti->table)) |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1945 | goto next_snapshot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | |
| 1947 | /* |
| 1948 | * Remember, different snapshots can have |
| 1949 | * different chunk sizes. |
| 1950 | */ |
Mikulas Patocka | 9eaae8f | 2009-12-10 23:52:28 +0000 | [diff] [blame] | 1951 | chunk = sector_to_chunk(snap->store, sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
| 1953 | /* |
| 1954 | * Check exception table to see if block |
| 1955 | * is already remapped in this snapshot |
| 1956 | * and trigger an exception if not. |
| 1957 | */ |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1958 | e = dm_lookup_exception(&snap->complete, chunk); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1959 | if (e) |
| 1960 | goto next_snapshot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1962 | pe = __lookup_pending_exception(snap, chunk); |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 1963 | if (!pe) { |
Mikulas Patocka | c662139 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1964 | up_write(&snap->lock); |
| 1965 | pe = alloc_pending_exception(snap); |
| 1966 | down_write(&snap->lock); |
| 1967 | |
| 1968 | if (!snap->valid) { |
| 1969 | free_pending_exception(pe); |
| 1970 | goto next_snapshot; |
| 1971 | } |
| 1972 | |
Jon Brassow | 3510cb9 | 2009-12-10 23:52:11 +0000 | [diff] [blame] | 1973 | e = dm_lookup_exception(&snap->complete, chunk); |
Mikulas Patocka | 35bf659 | 2009-04-02 19:55:26 +0100 | [diff] [blame] | 1974 | if (e) { |
| 1975 | free_pending_exception(pe); |
| 1976 | goto next_snapshot; |
| 1977 | } |
| 1978 | |
Mikulas Patocka | c662139 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1979 | pe = __find_pending_exception(snap, pe, chunk); |
Mikulas Patocka | 2913808 | 2009-04-02 19:55:25 +0100 | [diff] [blame] | 1980 | if (!pe) { |
| 1981 | __invalidate_snapshot(snap, -ENOMEM); |
| 1982 | goto next_snapshot; |
| 1983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 1986 | r = DM_MAPIO_SUBMITTED; |
| 1987 | |
| 1988 | /* |
| 1989 | * If an origin bio was supplied, queue it to wait for the |
| 1990 | * completion of this exception, and start this one last, |
| 1991 | * at the end of the function. |
| 1992 | */ |
| 1993 | if (bio) { |
| 1994 | bio_list_add(&pe->origin_bios, bio); |
| 1995 | bio = NULL; |
| 1996 | |
| 1997 | if (!pe->started) { |
| 1998 | pe->started = 1; |
| 1999 | pe_to_start_last = pe; |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 2000 | } |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | if (!pe->started) { |
| 2004 | pe->started = 1; |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2005 | pe_to_start_now = pe; |
Alasdair G Kergon | 76df1c6 | 2006-03-27 01:17:45 -0800 | [diff] [blame] | 2006 | } |
| 2007 | |
Jonathan Brassow | a2d2b03 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 2008 | next_snapshot: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | up_write(&snap->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2011 | if (pe_to_start_now) { |
| 2012 | start_copy(pe_to_start_now); |
| 2013 | pe_to_start_now = NULL; |
| 2014 | } |
Alasdair G Kergon | b4b610f | 2006-03-27 01:17:44 -0800 | [diff] [blame] | 2015 | } |
| 2016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | /* |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2018 | * Submit the exception against which the bio is queued last, |
| 2019 | * to give the other exceptions a head start. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | */ |
Mikulas Patocka | 515ad66 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2021 | if (pe_to_start_last) |
| 2022 | start_copy(pe_to_start_last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | |
| 2024 | return r; |
| 2025 | } |
| 2026 | |
| 2027 | /* |
| 2028 | * Called on a write from the origin driver. |
| 2029 | */ |
| 2030 | static int do_origin(struct dm_dev *origin, struct bio *bio) |
| 2031 | { |
| 2032 | struct origin *o; |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 2033 | int r = DM_MAPIO_REMAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
| 2035 | down_read(&_origins_lock); |
| 2036 | o = __lookup_origin(origin->bdev); |
| 2037 | if (o) |
Mikulas Patocka | 9eaae8f | 2009-12-10 23:52:28 +0000 | [diff] [blame] | 2038 | r = __origin_write(&o->snapshots, bio->bi_sector, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | up_read(&_origins_lock); |
| 2040 | |
| 2041 | return r; |
| 2042 | } |
| 2043 | |
| 2044 | /* |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 2045 | * Trigger exceptions in all non-merging snapshots. |
| 2046 | * |
| 2047 | * The chunk size of the merging snapshot may be larger than the chunk |
| 2048 | * size of some other snapshot so we may need to reallocate multiple |
| 2049 | * chunks in other snapshots. |
| 2050 | * |
| 2051 | * We scan all the overlapping exceptions in the other snapshots. |
| 2052 | * Returns 1 if anything was reallocated and must be waited for, |
| 2053 | * otherwise returns 0. |
| 2054 | * |
| 2055 | * size must be a multiple of merging_snap's chunk_size. |
| 2056 | */ |
| 2057 | static int origin_write_extent(struct dm_snapshot *merging_snap, |
| 2058 | sector_t sector, unsigned size) |
| 2059 | { |
| 2060 | int must_wait = 0; |
| 2061 | sector_t n; |
| 2062 | struct origin *o; |
| 2063 | |
| 2064 | /* |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 2065 | * The origin's __minimum_chunk_size() got stored in max_io_len |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 2066 | * by snapshot_merge_resume(). |
| 2067 | */ |
| 2068 | down_read(&_origins_lock); |
| 2069 | o = __lookup_origin(merging_snap->origin->bdev); |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 2070 | for (n = 0; n < size; n += merging_snap->ti->max_io_len) |
Mikulas Patocka | 73dfd07 | 2009-12-10 23:52:34 +0000 | [diff] [blame] | 2071 | if (__origin_write(&o->snapshots, sector + n, NULL) == |
| 2072 | DM_MAPIO_SUBMITTED) |
| 2073 | must_wait = 1; |
| 2074 | up_read(&_origins_lock); |
| 2075 | |
| 2076 | return must_wait; |
| 2077 | } |
| 2078 | |
| 2079 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | * Origin: maps a linear range of a device, with hooks for snapshotting. |
| 2081 | */ |
| 2082 | |
| 2083 | /* |
| 2084 | * Construct an origin mapping: <dev_path> |
| 2085 | * The context for an origin is merely a 'struct dm_dev *' |
| 2086 | * pointing to the real device. |
| 2087 | */ |
| 2088 | static int origin_ctr(struct dm_target *ti, unsigned int argc, char **argv) |
| 2089 | { |
| 2090 | int r; |
| 2091 | struct dm_dev *dev; |
| 2092 | |
| 2093 | if (argc != 1) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 2094 | ti->error = "origin: incorrect number of arguments"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | return -EINVAL; |
| 2096 | } |
| 2097 | |
Nikanth Karthikesan | 8215d6e | 2010-03-06 02:32:27 +0000 | [diff] [blame] | 2098 | r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | if (r) { |
| 2100 | ti->error = "Cannot get target device"; |
| 2101 | return r; |
| 2102 | } |
| 2103 | |
| 2104 | ti->private = dev; |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 2105 | ti->num_flush_bios = 1; |
Mikulas Patocka | 494b3ee | 2009-06-22 10:12:25 +0100 | [diff] [blame] | 2106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | return 0; |
| 2108 | } |
| 2109 | |
| 2110 | static void origin_dtr(struct dm_target *ti) |
| 2111 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 2112 | struct dm_dev *dev = ti->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | dm_put_device(ti, dev); |
| 2114 | } |
| 2115 | |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 2116 | static int origin_map(struct dm_target *ti, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 2118 | struct dm_dev *dev = ti->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | bio->bi_bdev = dev->bdev; |
| 2120 | |
Tejun Heo | d87f4c1 | 2010-09-03 11:56:19 +0200 | [diff] [blame] | 2121 | if (bio->bi_rw & REQ_FLUSH) |
Mikulas Patocka | 494b3ee | 2009-06-22 10:12:25 +0100 | [diff] [blame] | 2122 | return DM_MAPIO_REMAPPED; |
| 2123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | /* Only tell snapshots if this is a write */ |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 2125 | return (bio_rw(bio) == WRITE) ? do_origin(dev, bio) : DM_MAPIO_REMAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | /* |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 2129 | * Set the target "max_io_len" field to the minimum of all the snapshots' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | * chunk sizes. |
| 2131 | */ |
| 2132 | static void origin_resume(struct dm_target *ti) |
| 2133 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 2134 | struct dm_dev *dev = ti->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 2136 | ti->max_io_len = get_origin_minimum_chunksize(dev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 2139 | static void origin_status(struct dm_target *ti, status_type_t type, |
| 2140 | unsigned status_flags, char *result, unsigned maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | { |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 2142 | struct dm_dev *dev = ti->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | |
| 2144 | switch (type) { |
| 2145 | case STATUSTYPE_INFO: |
| 2146 | result[0] = '\0'; |
| 2147 | break; |
| 2148 | |
| 2149 | case STATUSTYPE_TABLE: |
| 2150 | snprintf(result, maxlen, "%s", dev->name); |
| 2151 | break; |
| 2152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Mikulas Patocka | b1d5552 | 2010-08-12 04:14:02 +0100 | [diff] [blame] | 2155 | static int origin_merge(struct dm_target *ti, struct bvec_merge_data *bvm, |
| 2156 | struct bio_vec *biovec, int max_size) |
| 2157 | { |
| 2158 | struct dm_dev *dev = ti->private; |
| 2159 | struct request_queue *q = bdev_get_queue(dev->bdev); |
| 2160 | |
| 2161 | if (!q->merge_bvec_fn) |
| 2162 | return max_size; |
| 2163 | |
| 2164 | bvm->bi_bdev = dev->bdev; |
Mikulas Patocka | b1d5552 | 2010-08-12 04:14:02 +0100 | [diff] [blame] | 2165 | |
| 2166 | return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); |
| 2167 | } |
| 2168 | |
Mike Snitzer | 8811f46 | 2009-09-04 20:40:19 +0100 | [diff] [blame] | 2169 | static int origin_iterate_devices(struct dm_target *ti, |
| 2170 | iterate_devices_callout_fn fn, void *data) |
| 2171 | { |
| 2172 | struct dm_dev *dev = ti->private; |
| 2173 | |
| 2174 | return fn(ti, dev, 0, ti->len, data); |
| 2175 | } |
| 2176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | static struct target_type origin_target = { |
| 2178 | .name = "snapshot-origin", |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 2179 | .version = {1, 8, 1}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | .module = THIS_MODULE, |
| 2181 | .ctr = origin_ctr, |
| 2182 | .dtr = origin_dtr, |
| 2183 | .map = origin_map, |
| 2184 | .resume = origin_resume, |
| 2185 | .status = origin_status, |
Mikulas Patocka | b1d5552 | 2010-08-12 04:14:02 +0100 | [diff] [blame] | 2186 | .merge = origin_merge, |
Mike Snitzer | 8811f46 | 2009-09-04 20:40:19 +0100 | [diff] [blame] | 2187 | .iterate_devices = origin_iterate_devices, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | }; |
| 2189 | |
| 2190 | static struct target_type snapshot_target = { |
| 2191 | .name = "snapshot", |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 2192 | .version = {1, 11, 1}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | .module = THIS_MODULE, |
| 2194 | .ctr = snapshot_ctr, |
| 2195 | .dtr = snapshot_dtr, |
| 2196 | .map = snapshot_map, |
Mikulas Patocka | cd45daf | 2008-07-21 12:00:32 +0100 | [diff] [blame] | 2197 | .end_io = snapshot_end_io, |
Mike Snitzer | c1f0c18 | 2009-12-10 23:52:24 +0000 | [diff] [blame] | 2198 | .preresume = snapshot_preresume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | .resume = snapshot_resume, |
| 2200 | .status = snapshot_status, |
Mike Snitzer | 8811f46 | 2009-09-04 20:40:19 +0100 | [diff] [blame] | 2201 | .iterate_devices = snapshot_iterate_devices, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | }; |
| 2203 | |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2204 | static struct target_type merge_target = { |
| 2205 | .name = dm_snapshot_merge_target_name, |
Mikulas Patocka | 42bc954 | 2012-12-21 20:23:38 +0000 | [diff] [blame] | 2206 | .version = {1, 2, 0}, |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2207 | .module = THIS_MODULE, |
| 2208 | .ctr = snapshot_ctr, |
| 2209 | .dtr = snapshot_dtr, |
Mikulas Patocka | 3452c2a | 2009-12-10 23:52:31 +0000 | [diff] [blame] | 2210 | .map = snapshot_merge_map, |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2211 | .end_io = snapshot_end_io, |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 2212 | .presuspend = snapshot_merge_presuspend, |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2213 | .preresume = snapshot_preresume, |
Mikulas Patocka | 1e03f97 | 2009-12-10 23:52:32 +0000 | [diff] [blame] | 2214 | .resume = snapshot_merge_resume, |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2215 | .status = snapshot_status, |
| 2216 | .iterate_devices = snapshot_iterate_devices, |
| 2217 | }; |
| 2218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | static int __init dm_snapshot_init(void) |
| 2220 | { |
| 2221 | int r; |
| 2222 | |
Alasdair G Kergon | 4db6bfe | 2009-01-06 03:05:17 +0000 | [diff] [blame] | 2223 | r = dm_exception_store_init(); |
| 2224 | if (r) { |
| 2225 | DMERR("Failed to initialize exception stores"); |
| 2226 | return r; |
| 2227 | } |
| 2228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | r = dm_register_target(&snapshot_target); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2230 | if (r < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | DMERR("snapshot target register failed %d", r); |
Jonathan Brassow | 034a186 | 2009-10-16 23:18:14 +0100 | [diff] [blame] | 2232 | goto bad_register_snapshot_target; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | r = dm_register_target(&origin_target); |
| 2236 | if (r < 0) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 2237 | DMERR("Origin target register failed %d", r); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2238 | goto bad_register_origin_target; |
| 2239 | } |
| 2240 | |
| 2241 | r = dm_register_target(&merge_target); |
| 2242 | if (r < 0) { |
| 2243 | DMERR("Merge target register failed %d", r); |
| 2244 | goto bad_register_merge_target; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | r = init_origin_hash(); |
| 2248 | if (r) { |
| 2249 | DMERR("init_origin_hash failed."); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2250 | goto bad_origin_hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
Jon Brassow | 1d4989c | 2009-12-10 23:52:10 +0000 | [diff] [blame] | 2253 | exception_cache = KMEM_CACHE(dm_exception, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | if (!exception_cache) { |
| 2255 | DMERR("Couldn't create exception cache."); |
| 2256 | r = -ENOMEM; |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2257 | goto bad_exception_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
Alasdair G Kergon | 028867a | 2007-07-12 17:26:32 +0100 | [diff] [blame] | 2260 | pending_cache = KMEM_CACHE(dm_snap_pending_exception, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | if (!pending_cache) { |
| 2262 | DMERR("Couldn't create pending cache."); |
| 2263 | r = -ENOMEM; |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2264 | goto bad_pending_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | return 0; |
| 2268 | |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2269 | bad_pending_cache: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | kmem_cache_destroy(exception_cache); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2271 | bad_exception_cache: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | exit_origin_hash(); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2273 | bad_origin_hash: |
| 2274 | dm_unregister_target(&merge_target); |
| 2275 | bad_register_merge_target: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | dm_unregister_target(&origin_target); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2277 | bad_register_origin_target: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | dm_unregister_target(&snapshot_target); |
Jonathan Brassow | 034a186 | 2009-10-16 23:18:14 +0100 | [diff] [blame] | 2279 | bad_register_snapshot_target: |
| 2280 | dm_exception_store_exit(); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | return r; |
| 2283 | } |
| 2284 | |
| 2285 | static void __exit dm_snapshot_exit(void) |
| 2286 | { |
Mikulas Patocka | 10d3bd0 | 2009-01-06 03:04:58 +0000 | [diff] [blame] | 2287 | dm_unregister_target(&snapshot_target); |
| 2288 | dm_unregister_target(&origin_target); |
Mikulas Patocka | d698aa4 | 2009-12-10 23:52:30 +0000 | [diff] [blame] | 2289 | dm_unregister_target(&merge_target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | |
| 2291 | exit_origin_hash(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | kmem_cache_destroy(pending_cache); |
| 2293 | kmem_cache_destroy(exception_cache); |
Alasdair G Kergon | 4db6bfe | 2009-01-06 03:05:17 +0000 | [diff] [blame] | 2294 | |
| 2295 | dm_exception_store_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | /* Module hooks */ |
| 2299 | module_init(dm_snapshot_init); |
| 2300 | module_exit(dm_snapshot_exit); |
| 2301 | |
| 2302 | MODULE_DESCRIPTION(DM_NAME " snapshot target"); |
| 2303 | MODULE_AUTHOR("Joe Thornber"); |
| 2304 | MODULE_LICENSE("GPL"); |
Mikulas Patocka | 23cb210 | 2013-03-01 22:45:47 +0000 | [diff] [blame^] | 2305 | MODULE_ALIAS("dm-snapshot-origin"); |
| 2306 | MODULE_ALIAS("dm-snapshot-merge"); |