dm snapshot: extend exception store functions

Supply dm_add_exception as a callback to the read_metadata function.
Add a status function ready for a later patch and name the functions
consistently.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

authored by

Jonathan Brassow and committed by
Alasdair G Kergon
a159c1ac 4db6bfe0

+55 -37
-1
drivers/md/dm-exception-store.c
··· 11 11 #include <linux/pagemap.h> 12 12 #include <linux/vmalloc.h> 13 13 #include <linux/slab.h> 14 - #include <linux/device-mapper.h> 15 14 16 15 #define DM_MSG_PREFIX "snapshot exception stores" 17 16
+10 -3
drivers/md/dm-exception-store.h
··· 11 11 #define _LINUX_DM_EXCEPTION_STORE 12 12 13 13 #include <linux/blkdev.h> 14 + #include <linux/device-mapper.h> 14 15 15 16 /* 16 17 * The snapshot code deals with largish chunks of the disk at a ··· 38 37 * COW device). 39 38 */ 40 39 struct dm_exception_store { 41 - 42 40 /* 43 41 * Destroys this object when you've finished with it. 44 42 */ ··· 45 45 46 46 /* 47 47 * The target shouldn't read the COW device until this is 48 - * called. 48 + * called. As exceptions are read from the COW, they are 49 + * reported back via the callback. 49 50 */ 50 - int (*read_metadata) (struct dm_exception_store *store); 51 + int (*read_metadata) (struct dm_exception_store *store, 52 + int (*callback)(void *callback_context, 53 + chunk_t old, chunk_t new), 54 + void *callback_context); 51 55 52 56 /* 53 57 * Find somewhere to store the next exception. ··· 71 67 * The snapshot is invalid, note this in the metadata. 72 68 */ 73 69 void (*drop_snapshot) (struct dm_exception_store *store); 70 + 71 + int (*status) (struct dm_exception_store *store, status_type_t status, 72 + char *result, unsigned int maxlen); 74 73 75 74 /* 76 75 * Return how full the snapshot is.
+26 -16
drivers/md/dm-snap-persistent.c
··· 395 395 * 'full' is filled in to indicate if the area has been 396 396 * filled. 397 397 */ 398 - static int insert_exceptions(struct pstore *ps, int *full) 398 + static int insert_exceptions(struct pstore *ps, 399 + int (*callback)(void *callback_context, 400 + chunk_t old, chunk_t new), 401 + void *callback_context, 402 + int *full) 399 403 { 400 404 int r; 401 405 unsigned int i; ··· 432 428 /* 433 429 * Otherwise we add the exception to the snapshot. 434 430 */ 435 - r = dm_add_exception(ps->snap, de.old_chunk, de.new_chunk); 431 + r = callback(callback_context, de.old_chunk, de.new_chunk); 436 432 if (r) 437 433 return r; 438 434 } ··· 440 436 return 0; 441 437 } 442 438 443 - static int read_exceptions(struct pstore *ps) 439 + static int read_exceptions(struct pstore *ps, 440 + int (*callback)(void *callback_context, chunk_t old, 441 + chunk_t new), 442 + void *callback_context) 444 443 { 445 444 int r, full = 1; 446 445 ··· 456 449 if (r) 457 450 return r; 458 451 459 - r = insert_exceptions(ps, &full); 452 + r = insert_exceptions(ps, callback, callback_context, &full); 460 453 if (r) 461 454 return r; 462 455 } ··· 489 482 kfree(ps); 490 483 } 491 484 492 - static int persistent_read_metadata(struct dm_exception_store *store) 485 + static int persistent_read_metadata(struct dm_exception_store *store, 486 + int (*callback)(void *callback_context, 487 + chunk_t old, chunk_t new), 488 + void *callback_context) 493 489 { 494 490 int r, uninitialized_var(new_snapshot); 495 491 struct pstore *ps = get_info(store); ··· 550 540 /* 551 541 * Read the metadata. 552 542 */ 553 - r = read_exceptions(ps); 543 + r = read_exceptions(ps, callback, callback_context); 554 544 if (r) 555 545 return r; 556 546 } ··· 558 548 return 0; 559 549 } 560 550 561 - static int persistent_prepare(struct dm_exception_store *store, 562 - struct dm_snap_exception *e) 551 + static int persistent_prepare_exception(struct dm_exception_store *store, 552 + struct dm_snap_exception *e) 563 553 { 564 554 struct pstore *ps = get_info(store); 565 555 uint32_t stride; ··· 585 575 return 0; 586 576 } 587 577 588 - static void persistent_commit(struct dm_exception_store *store, 589 - struct dm_snap_exception *e, 590 - void (*callback) (void *, int success), 591 - void *callback_context) 578 + static void persistent_commit_exception(struct dm_exception_store *store, 579 + struct dm_snap_exception *e, 580 + void (*callback) (void *, int success), 581 + void *callback_context) 592 582 { 593 583 unsigned int i; 594 584 struct pstore *ps = get_info(store); ··· 647 637 ps->callback_count = 0; 648 638 } 649 639 650 - static void persistent_drop(struct dm_exception_store *store) 640 + static void persistent_drop_snapshot(struct dm_exception_store *store) 651 641 { 652 642 struct pstore *ps = get_info(store); 653 643 ··· 685 675 686 676 store->destroy = persistent_destroy; 687 677 store->read_metadata = persistent_read_metadata; 688 - store->prepare_exception = persistent_prepare; 689 - store->commit_exception = persistent_commit; 690 - store->drop_snapshot = persistent_drop; 678 + store->prepare_exception = persistent_prepare_exception; 679 + store->commit_exception = persistent_commit_exception; 680 + store->drop_snapshot = persistent_drop_snapshot; 691 681 store->fraction_full = persistent_fraction_full; 692 682 store->context = ps; 693 683
+12 -9
drivers/md/dm-snap-transient.c
··· 28 28 kfree(store->context); 29 29 } 30 30 31 - static int transient_read_metadata(struct dm_exception_store *store) 31 + static int transient_read_metadata(struct dm_exception_store *store, 32 + int (*callback)(void *callback_context, 33 + chunk_t old, chunk_t new), 34 + void *callback_context) 32 35 { 33 36 return 0; 34 37 } 35 38 36 - static int transient_prepare(struct dm_exception_store *store, 37 - struct dm_snap_exception *e) 39 + static int transient_prepare_exception(struct dm_exception_store *store, 40 + struct dm_snap_exception *e) 38 41 { 39 42 struct transient_c *tc = (struct transient_c *) store->context; 40 43 sector_t size = get_dev_size(store->snap->cow->bdev); ··· 51 48 return 0; 52 49 } 53 50 54 - static void transient_commit(struct dm_exception_store *store, 55 - struct dm_snap_exception *e, 56 - void (*callback) (void *, int success), 57 - void *callback_context) 51 + static void transient_commit_exception(struct dm_exception_store *store, 52 + struct dm_snap_exception *e, 53 + void (*callback) (void *, int success), 54 + void *callback_context) 58 55 { 59 56 /* Just succeed */ 60 57 callback(callback_context, 1); ··· 73 70 74 71 store->destroy = transient_destroy; 75 72 store->read_metadata = transient_read_metadata; 76 - store->prepare_exception = transient_prepare; 77 - store->commit_exception = transient_commit; 73 + store->prepare_exception = transient_prepare_exception; 74 + store->commit_exception = transient_commit_exception; 78 75 store->drop_snapshot = NULL; 79 76 store->fraction_full = transient_fraction_full; 80 77
+7 -2
drivers/md/dm-snap.c
··· 430 430 list_add(&new_e->hash_list, e ? &e->hash_list : l); 431 431 } 432 432 433 - int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new) 433 + /* 434 + * Callback used by the exception stores to load exceptions when 435 + * initialising. 436 + */ 437 + static int dm_add_exception(void *context, chunk_t old, chunk_t new) 434 438 { 439 + struct dm_snapshot *s = context; 435 440 struct dm_snap_exception *e; 436 441 437 442 e = alloc_exception(); ··· 665 660 spin_lock_init(&s->tracked_chunk_lock); 666 661 667 662 /* Metadata must only be loaded into one table at once */ 668 - r = s->store.read_metadata(&s->store); 663 + r = s->store.read_metadata(&s->store, dm_add_exception, (void *)s); 669 664 if (r < 0) { 670 665 ti->error = "Failed to read snapshot metadata"; 671 666 goto bad_load_and_register;
-6
drivers/md/dm-snap.h
··· 76 76 }; 77 77 78 78 /* 79 - * Used by the exception stores to load exceptions hen 80 - * initialising. 81 - */ 82 - int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new); 83 - 84 - /* 85 79 * Return the number of sectors in the device. 86 80 */ 87 81 static inline sector_t get_dev_size(struct block_device *bdev)