diff options
Diffstat (limited to 'drivers/md/dm-snap.c')
-rw-r--r-- | drivers/md/dm-snap.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 57f1bf7f3b7a..3a3ba46e6d4b 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -296,6 +296,7 @@ static void __insert_origin(struct origin *o) | |||
296 | */ | 296 | */ |
297 | static int register_snapshot(struct dm_snapshot *snap) | 297 | static int register_snapshot(struct dm_snapshot *snap) |
298 | { | 298 | { |
299 | struct dm_snapshot *l; | ||
299 | struct origin *o, *new_o; | 300 | struct origin *o, *new_o; |
300 | struct block_device *bdev = snap->origin->bdev; | 301 | struct block_device *bdev = snap->origin->bdev; |
301 | 302 | ||
@@ -319,7 +320,11 @@ static int register_snapshot(struct dm_snapshot *snap) | |||
319 | __insert_origin(o); | 320 | __insert_origin(o); |
320 | } | 321 | } |
321 | 322 | ||
322 | list_add_tail(&snap->list, &o->snapshots); | 323 | /* Sort the list according to chunk size, largest-first smallest-last */ |
324 | list_for_each_entry(l, &o->snapshots, list) | ||
325 | if (l->store->chunk_size < snap->store->chunk_size) | ||
326 | break; | ||
327 | list_add_tail(&snap->list, &l->list); | ||
323 | 328 | ||
324 | up_write(&_origins_lock); | 329 | up_write(&_origins_lock); |
325 | return 0; | 330 | return 0; |
@@ -668,6 +673,11 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
668 | bio_list_init(&s->queued_bios); | 673 | bio_list_init(&s->queued_bios); |
669 | INIT_WORK(&s->queued_bios_work, flush_queued_bios); | 674 | INIT_WORK(&s->queued_bios_work, flush_queued_bios); |
670 | 675 | ||
676 | if (!s->store->chunk_size) { | ||
677 | ti->error = "Chunk size not set"; | ||
678 | goto bad_load_and_register; | ||
679 | } | ||
680 | |||
671 | /* Add snapshot to the list of snapshots for this origin */ | 681 | /* Add snapshot to the list of snapshots for this origin */ |
672 | /* Exceptions aren't triggered till snapshot_resume() is called */ | 682 | /* Exceptions aren't triggered till snapshot_resume() is called */ |
673 | if (register_snapshot(s)) { | 683 | if (register_snapshot(s)) { |
@@ -951,7 +961,7 @@ static void start_copy(struct dm_snap_pending_exception *pe) | |||
951 | 961 | ||
952 | src.bdev = bdev; | 962 | src.bdev = bdev; |
953 | src.sector = chunk_to_sector(s->store, pe->e.old_chunk); | 963 | src.sector = chunk_to_sector(s->store, pe->e.old_chunk); |
954 | src.count = min(s->store->chunk_size, dev_size - src.sector); | 964 | src.count = min((sector_t)s->store->chunk_size, dev_size - src.sector); |
955 | 965 | ||
956 | dest.bdev = s->store->cow->bdev; | 966 | dest.bdev = s->store->cow->bdev; |
957 | dest.sector = chunk_to_sector(s->store, pe->e.new_chunk); | 967 | dest.sector = chunk_to_sector(s->store, pe->e.new_chunk); |
@@ -1142,6 +1152,8 @@ static int snapshot_status(struct dm_target *ti, status_type_t type, | |||
1142 | unsigned sz = 0; | 1152 | unsigned sz = 0; |
1143 | struct dm_snapshot *snap = ti->private; | 1153 | struct dm_snapshot *snap = ti->private; |
1144 | 1154 | ||
1155 | down_write(&snap->lock); | ||
1156 | |||
1145 | switch (type) { | 1157 | switch (type) { |
1146 | case STATUSTYPE_INFO: | 1158 | case STATUSTYPE_INFO: |
1147 | if (!snap->valid) | 1159 | if (!snap->valid) |
@@ -1173,6 +1185,8 @@ static int snapshot_status(struct dm_target *ti, status_type_t type, | |||
1173 | break; | 1185 | break; |
1174 | } | 1186 | } |
1175 | 1187 | ||
1188 | up_write(&snap->lock); | ||
1189 | |||
1176 | return 0; | 1190 | return 0; |
1177 | } | 1191 | } |
1178 | 1192 | ||
@@ -1388,7 +1402,7 @@ static void origin_resume(struct dm_target *ti) | |||
1388 | struct dm_dev *dev = ti->private; | 1402 | struct dm_dev *dev = ti->private; |
1389 | struct dm_snapshot *snap; | 1403 | struct dm_snapshot *snap; |
1390 | struct origin *o; | 1404 | struct origin *o; |
1391 | chunk_t chunk_size = 0; | 1405 | unsigned chunk_size = 0; |
1392 | 1406 | ||
1393 | down_read(&_origins_lock); | 1407 | down_read(&_origins_lock); |
1394 | o = __lookup_origin(dev->bdev); | 1408 | o = __lookup_origin(dev->bdev); |
@@ -1465,7 +1479,7 @@ static int __init dm_snapshot_init(void) | |||
1465 | r = dm_register_target(&snapshot_target); | 1479 | r = dm_register_target(&snapshot_target); |
1466 | if (r) { | 1480 | if (r) { |
1467 | DMERR("snapshot target register failed %d", r); | 1481 | DMERR("snapshot target register failed %d", r); |
1468 | return r; | 1482 | goto bad_register_snapshot_target; |
1469 | } | 1483 | } |
1470 | 1484 | ||
1471 | r = dm_register_target(&origin_target); | 1485 | r = dm_register_target(&origin_target); |
@@ -1522,6 +1536,9 @@ bad2: | |||
1522 | dm_unregister_target(&origin_target); | 1536 | dm_unregister_target(&origin_target); |
1523 | bad1: | 1537 | bad1: |
1524 | dm_unregister_target(&snapshot_target); | 1538 | dm_unregister_target(&snapshot_target); |
1539 | |||
1540 | bad_register_snapshot_target: | ||
1541 | dm_exception_store_exit(); | ||
1525 | return r; | 1542 | return r; |
1526 | } | 1543 | } |
1527 | 1544 | ||