diff options
author | Heinz Mauelshagen <hjm@redhat.com> | 2008-04-24 16:43:35 -0400 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2008-04-25 08:26:46 -0400 |
commit | 416cd17b1982217bca3dc41b9f00b0b38fdaadad (patch) | |
tree | dcb73db9876f5b973ad26b47449083b98efad1b6 /drivers/md/dm-log.c | |
parent | eb69aca5d3370b81450d68edeebc2bb9a3eb9689 (diff) |
dm log: clean interface
Clean up the dm-log interface to prepare for publishing it in include/linux.
Signed-off-by: Heinz Mauelshagen <hjm@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm-log.c')
-rw-r--r-- | drivers/md/dm-log.c | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c index 14f785fc308a..b776701cc8fa 100644 --- a/drivers/md/dm-log.c +++ b/drivers/md/dm-log.c | |||
@@ -12,13 +12,14 @@ | |||
12 | 12 | ||
13 | #include "dm-log.h" | 13 | #include "dm-log.h" |
14 | #include "dm-io.h" | 14 | #include "dm-io.h" |
15 | #include "dm.h" | ||
15 | 16 | ||
16 | #define DM_MSG_PREFIX "dirty region log" | 17 | #define DM_MSG_PREFIX "dirty region log" |
17 | 18 | ||
18 | static LIST_HEAD(_log_types); | 19 | static LIST_HEAD(_log_types); |
19 | static DEFINE_SPINLOCK(_lock); | 20 | static DEFINE_SPINLOCK(_lock); |
20 | 21 | ||
21 | int dm_register_dirty_log_type(struct dirty_log_type *type) | 22 | int dm_dirty_log_type_register(struct dm_dirty_log_type *type) |
22 | { | 23 | { |
23 | spin_lock(&_lock); | 24 | spin_lock(&_lock); |
24 | type->use_count = 0; | 25 | type->use_count = 0; |
@@ -27,8 +28,9 @@ int dm_register_dirty_log_type(struct dirty_log_type *type) | |||
27 | 28 | ||
28 | return 0; | 29 | return 0; |
29 | } | 30 | } |
31 | EXPORT_SYMBOL(dm_dirty_log_type_register); | ||
30 | 32 | ||
31 | int dm_unregister_dirty_log_type(struct dirty_log_type *type) | 33 | int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type) |
32 | { | 34 | { |
33 | spin_lock(&_lock); | 35 | spin_lock(&_lock); |
34 | 36 | ||
@@ -41,10 +43,11 @@ int dm_unregister_dirty_log_type(struct dirty_log_type *type) | |||
41 | 43 | ||
42 | return 0; | 44 | return 0; |
43 | } | 45 | } |
46 | EXPORT_SYMBOL(dm_dirty_log_type_unregister); | ||
44 | 47 | ||
45 | static struct dirty_log_type *_get_type(const char *type_name) | 48 | static struct dm_dirty_log_type *_get_type(const char *type_name) |
46 | { | 49 | { |
47 | struct dirty_log_type *type; | 50 | struct dm_dirty_log_type *type; |
48 | 51 | ||
49 | spin_lock(&_lock); | 52 | spin_lock(&_lock); |
50 | list_for_each_entry (type, &_log_types, list) | 53 | list_for_each_entry (type, &_log_types, list) |
@@ -79,10 +82,10 @@ static struct dirty_log_type *_get_type(const char *type_name) | |||
79 | * | 82 | * |
80 | * Returns: dirty_log_type* on success, NULL on failure | 83 | * Returns: dirty_log_type* on success, NULL on failure |
81 | */ | 84 | */ |
82 | static struct dirty_log_type *get_type(const char *type_name) | 85 | static struct dm_dirty_log_type *get_type(const char *type_name) |
83 | { | 86 | { |
84 | char *p, *type_name_dup; | 87 | char *p, *type_name_dup; |
85 | struct dirty_log_type *type; | 88 | struct dm_dirty_log_type *type; |
86 | 89 | ||
87 | type = _get_type(type_name); | 90 | type = _get_type(type_name); |
88 | if (type) | 91 | if (type) |
@@ -111,7 +114,7 @@ static struct dirty_log_type *get_type(const char *type_name) | |||
111 | return type; | 114 | return type; |
112 | } | 115 | } |
113 | 116 | ||
114 | static void put_type(struct dirty_log_type *type) | 117 | static void put_type(struct dm_dirty_log_type *type) |
115 | { | 118 | { |
116 | spin_lock(&_lock); | 119 | spin_lock(&_lock); |
117 | if (!--type->use_count) | 120 | if (!--type->use_count) |
@@ -119,11 +122,12 @@ static void put_type(struct dirty_log_type *type) | |||
119 | spin_unlock(&_lock); | 122 | spin_unlock(&_lock); |
120 | } | 123 | } |
121 | 124 | ||
122 | struct dirty_log *dm_create_dirty_log(const char *type_name, struct dm_target *ti, | 125 | struct dm_dirty_log *dm_dirty_log_create(const char *type_name, |
123 | unsigned int argc, char **argv) | 126 | struct dm_target *ti, |
127 | unsigned int argc, char **argv) | ||
124 | { | 128 | { |
125 | struct dirty_log_type *type; | 129 | struct dm_dirty_log_type *type; |
126 | struct dirty_log *log; | 130 | struct dm_dirty_log *log; |
127 | 131 | ||
128 | log = kmalloc(sizeof(*log), GFP_KERNEL); | 132 | log = kmalloc(sizeof(*log), GFP_KERNEL); |
129 | if (!log) | 133 | if (!log) |
@@ -144,13 +148,15 @@ struct dirty_log *dm_create_dirty_log(const char *type_name, struct dm_target *t | |||
144 | 148 | ||
145 | return log; | 149 | return log; |
146 | } | 150 | } |
151 | EXPORT_SYMBOL(dm_dirty_log_create); | ||
147 | 152 | ||
148 | void dm_destroy_dirty_log(struct dirty_log *log) | 153 | void dm_dirty_log_destroy(struct dm_dirty_log *log) |
149 | { | 154 | { |
150 | log->type->dtr(log); | 155 | log->type->dtr(log); |
151 | put_type(log->type); | 156 | put_type(log->type); |
152 | kfree(log); | 157 | kfree(log); |
153 | } | 158 | } |
159 | EXPORT_SYMBOL(dm_dirty_log_destroy); | ||
154 | 160 | ||
155 | /*----------------------------------------------------------------- | 161 | /*----------------------------------------------------------------- |
156 | * Persistent and core logs share a lot of their implementation. | 162 | * Persistent and core logs share a lot of their implementation. |
@@ -216,7 +222,7 @@ struct log_c { | |||
216 | * The touched member needs to be updated every time we access | 222 | * The touched member needs to be updated every time we access |
217 | * one of the bitsets. | 223 | * one of the bitsets. |
218 | */ | 224 | */ |
219 | static inline int log_test_bit(uint32_t *bs, unsigned bit) | 225 | static inline int log_test_bit(uint32_t *bs, unsigned bit) |
220 | { | 226 | { |
221 | return ext2_test_bit(bit, (unsigned long *) bs) ? 1 : 0; | 227 | return ext2_test_bit(bit, (unsigned long *) bs) ? 1 : 0; |
222 | } | 228 | } |
@@ -303,7 +309,7 @@ static inline int write_header(struct log_c *log) | |||
303 | * argv contains region_size followed optionally by [no]sync | 309 | * argv contains region_size followed optionally by [no]sync |
304 | *--------------------------------------------------------------*/ | 310 | *--------------------------------------------------------------*/ |
305 | #define BYTE_SHIFT 3 | 311 | #define BYTE_SHIFT 3 |
306 | static int create_log_context(struct dirty_log *log, struct dm_target *ti, | 312 | static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti, |
307 | unsigned int argc, char **argv, | 313 | unsigned int argc, char **argv, |
308 | struct dm_dev *dev) | 314 | struct dm_dev *dev) |
309 | { | 315 | { |
@@ -435,7 +441,7 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti, | |||
435 | return 0; | 441 | return 0; |
436 | } | 442 | } |
437 | 443 | ||
438 | static int core_ctr(struct dirty_log *log, struct dm_target *ti, | 444 | static int core_ctr(struct dm_dirty_log *log, struct dm_target *ti, |
439 | unsigned int argc, char **argv) | 445 | unsigned int argc, char **argv) |
440 | { | 446 | { |
441 | return create_log_context(log, ti, argc, argv, NULL); | 447 | return create_log_context(log, ti, argc, argv, NULL); |
@@ -448,7 +454,7 @@ static void destroy_log_context(struct log_c *lc) | |||
448 | kfree(lc); | 454 | kfree(lc); |
449 | } | 455 | } |
450 | 456 | ||
451 | static void core_dtr(struct dirty_log *log) | 457 | static void core_dtr(struct dm_dirty_log *log) |
452 | { | 458 | { |
453 | struct log_c *lc = (struct log_c *) log->context; | 459 | struct log_c *lc = (struct log_c *) log->context; |
454 | 460 | ||
@@ -461,7 +467,7 @@ static void core_dtr(struct dirty_log *log) | |||
461 | * | 467 | * |
462 | * argv contains log_device region_size followed optionally by [no]sync | 468 | * argv contains log_device region_size followed optionally by [no]sync |
463 | *--------------------------------------------------------------*/ | 469 | *--------------------------------------------------------------*/ |
464 | static int disk_ctr(struct dirty_log *log, struct dm_target *ti, | 470 | static int disk_ctr(struct dm_dirty_log *log, struct dm_target *ti, |
465 | unsigned int argc, char **argv) | 471 | unsigned int argc, char **argv) |
466 | { | 472 | { |
467 | int r; | 473 | int r; |
@@ -486,7 +492,7 @@ static int disk_ctr(struct dirty_log *log, struct dm_target *ti, | |||
486 | return 0; | 492 | return 0; |
487 | } | 493 | } |
488 | 494 | ||
489 | static void disk_dtr(struct dirty_log *log) | 495 | static void disk_dtr(struct dm_dirty_log *log) |
490 | { | 496 | { |
491 | struct log_c *lc = (struct log_c *) log->context; | 497 | struct log_c *lc = (struct log_c *) log->context; |
492 | 498 | ||
@@ -515,7 +521,7 @@ static void fail_log_device(struct log_c *lc) | |||
515 | dm_table_event(lc->ti->table); | 521 | dm_table_event(lc->ti->table); |
516 | } | 522 | } |
517 | 523 | ||
518 | static int disk_resume(struct dirty_log *log) | 524 | static int disk_resume(struct dm_dirty_log *log) |
519 | { | 525 | { |
520 | int r; | 526 | int r; |
521 | unsigned i; | 527 | unsigned i; |
@@ -571,38 +577,38 @@ static int disk_resume(struct dirty_log *log) | |||
571 | return r; | 577 | return r; |
572 | } | 578 | } |
573 | 579 | ||
574 | static uint32_t core_get_region_size(struct dirty_log *log) | 580 | static uint32_t core_get_region_size(struct dm_dirty_log *log) |
575 | { | 581 | { |
576 | struct log_c *lc = (struct log_c *) log->context; | 582 | struct log_c *lc = (struct log_c *) log->context; |
577 | return lc->region_size; | 583 | return lc->region_size; |
578 | } | 584 | } |
579 | 585 | ||
580 | static int core_resume(struct dirty_log *log) | 586 | static int core_resume(struct dm_dirty_log *log) |
581 | { | 587 | { |
582 | struct log_c *lc = (struct log_c *) log->context; | 588 | struct log_c *lc = (struct log_c *) log->context; |
583 | lc->sync_search = 0; | 589 | lc->sync_search = 0; |
584 | return 0; | 590 | return 0; |
585 | } | 591 | } |
586 | 592 | ||
587 | static int core_is_clean(struct dirty_log *log, region_t region) | 593 | static int core_is_clean(struct dm_dirty_log *log, region_t region) |
588 | { | 594 | { |
589 | struct log_c *lc = (struct log_c *) log->context; | 595 | struct log_c *lc = (struct log_c *) log->context; |
590 | return log_test_bit(lc->clean_bits, region); | 596 | return log_test_bit(lc->clean_bits, region); |
591 | } | 597 | } |
592 | 598 | ||
593 | static int core_in_sync(struct dirty_log *log, region_t region, int block) | 599 | static int core_in_sync(struct dm_dirty_log *log, region_t region, int block) |
594 | { | 600 | { |
595 | struct log_c *lc = (struct log_c *) log->context; | 601 | struct log_c *lc = (struct log_c *) log->context; |
596 | return log_test_bit(lc->sync_bits, region); | 602 | return log_test_bit(lc->sync_bits, region); |
597 | } | 603 | } |
598 | 604 | ||
599 | static int core_flush(struct dirty_log *log) | 605 | static int core_flush(struct dm_dirty_log *log) |
600 | { | 606 | { |
601 | /* no op */ | 607 | /* no op */ |
602 | return 0; | 608 | return 0; |
603 | } | 609 | } |
604 | 610 | ||
605 | static int disk_flush(struct dirty_log *log) | 611 | static int disk_flush(struct dm_dirty_log *log) |
606 | { | 612 | { |
607 | int r; | 613 | int r; |
608 | struct log_c *lc = (struct log_c *) log->context; | 614 | struct log_c *lc = (struct log_c *) log->context; |
@@ -620,19 +626,19 @@ static int disk_flush(struct dirty_log *log) | |||
620 | return r; | 626 | return r; |
621 | } | 627 | } |
622 | 628 | ||
623 | static void core_mark_region(struct dirty_log *log, region_t region) | 629 | static void core_mark_region(struct dm_dirty_log *log, region_t region) |
624 | { | 630 | { |
625 | struct log_c *lc = (struct log_c *) log->context; | 631 | struct log_c *lc = (struct log_c *) log->context; |
626 | log_clear_bit(lc, lc->clean_bits, region); | 632 | log_clear_bit(lc, lc->clean_bits, region); |
627 | } | 633 | } |
628 | 634 | ||
629 | static void core_clear_region(struct dirty_log *log, region_t region) | 635 | static void core_clear_region(struct dm_dirty_log *log, region_t region) |
630 | { | 636 | { |
631 | struct log_c *lc = (struct log_c *) log->context; | 637 | struct log_c *lc = (struct log_c *) log->context; |
632 | log_set_bit(lc, lc->clean_bits, region); | 638 | log_set_bit(lc, lc->clean_bits, region); |
633 | } | 639 | } |
634 | 640 | ||
635 | static int core_get_resync_work(struct dirty_log *log, region_t *region) | 641 | static int core_get_resync_work(struct dm_dirty_log *log, region_t *region) |
636 | { | 642 | { |
637 | struct log_c *lc = (struct log_c *) log->context; | 643 | struct log_c *lc = (struct log_c *) log->context; |
638 | 644 | ||
@@ -655,7 +661,7 @@ static int core_get_resync_work(struct dirty_log *log, region_t *region) | |||
655 | return 1; | 661 | return 1; |
656 | } | 662 | } |
657 | 663 | ||
658 | static void core_set_region_sync(struct dirty_log *log, region_t region, | 664 | static void core_set_region_sync(struct dm_dirty_log *log, region_t region, |
659 | int in_sync) | 665 | int in_sync) |
660 | { | 666 | { |
661 | struct log_c *lc = (struct log_c *) log->context; | 667 | struct log_c *lc = (struct log_c *) log->context; |
@@ -670,7 +676,7 @@ static void core_set_region_sync(struct dirty_log *log, region_t region, | |||
670 | } | 676 | } |
671 | } | 677 | } |
672 | 678 | ||
673 | static region_t core_get_sync_count(struct dirty_log *log) | 679 | static region_t core_get_sync_count(struct dm_dirty_log *log) |
674 | { | 680 | { |
675 | struct log_c *lc = (struct log_c *) log->context; | 681 | struct log_c *lc = (struct log_c *) log->context; |
676 | 682 | ||
@@ -681,7 +687,7 @@ static region_t core_get_sync_count(struct dirty_log *log) | |||
681 | if (lc->sync != DEFAULTSYNC) \ | 687 | if (lc->sync != DEFAULTSYNC) \ |
682 | DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "") | 688 | DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "") |
683 | 689 | ||
684 | static int core_status(struct dirty_log *log, status_type_t status, | 690 | static int core_status(struct dm_dirty_log *log, status_type_t status, |
685 | char *result, unsigned int maxlen) | 691 | char *result, unsigned int maxlen) |
686 | { | 692 | { |
687 | int sz = 0; | 693 | int sz = 0; |
@@ -701,7 +707,7 @@ static int core_status(struct dirty_log *log, status_type_t status, | |||
701 | return sz; | 707 | return sz; |
702 | } | 708 | } |
703 | 709 | ||
704 | static int disk_status(struct dirty_log *log, status_type_t status, | 710 | static int disk_status(struct dm_dirty_log *log, status_type_t status, |
705 | char *result, unsigned int maxlen) | 711 | char *result, unsigned int maxlen) |
706 | { | 712 | { |
707 | int sz = 0; | 713 | int sz = 0; |
@@ -723,7 +729,7 @@ static int disk_status(struct dirty_log *log, status_type_t status, | |||
723 | return sz; | 729 | return sz; |
724 | } | 730 | } |
725 | 731 | ||
726 | static struct dirty_log_type _core_type = { | 732 | static struct dm_dirty_log_type _core_type = { |
727 | .name = "core", | 733 | .name = "core", |
728 | .module = THIS_MODULE, | 734 | .module = THIS_MODULE, |
729 | .ctr = core_ctr, | 735 | .ctr = core_ctr, |
@@ -741,7 +747,7 @@ static struct dirty_log_type _core_type = { | |||
741 | .status = core_status, | 747 | .status = core_status, |
742 | }; | 748 | }; |
743 | 749 | ||
744 | static struct dirty_log_type _disk_type = { | 750 | static struct dm_dirty_log_type _disk_type = { |
745 | .name = "disk", | 751 | .name = "disk", |
746 | .module = THIS_MODULE, | 752 | .module = THIS_MODULE, |
747 | .ctr = disk_ctr, | 753 | .ctr = disk_ctr, |
@@ -764,14 +770,14 @@ int __init dm_dirty_log_init(void) | |||
764 | { | 770 | { |
765 | int r; | 771 | int r; |
766 | 772 | ||
767 | r = dm_register_dirty_log_type(&_core_type); | 773 | r = dm_dirty_log_type_register(&_core_type); |
768 | if (r) | 774 | if (r) |
769 | DMWARN("couldn't register core log"); | 775 | DMWARN("couldn't register core log"); |
770 | 776 | ||
771 | r = dm_register_dirty_log_type(&_disk_type); | 777 | r = dm_dirty_log_type_register(&_disk_type); |
772 | if (r) { | 778 | if (r) { |
773 | DMWARN("couldn't register disk type"); | 779 | DMWARN("couldn't register disk type"); |
774 | dm_unregister_dirty_log_type(&_core_type); | 780 | dm_dirty_log_type_unregister(&_core_type); |
775 | } | 781 | } |
776 | 782 | ||
777 | return r; | 783 | return r; |
@@ -779,15 +785,10 @@ int __init dm_dirty_log_init(void) | |||
779 | 785 | ||
780 | void __exit dm_dirty_log_exit(void) | 786 | void __exit dm_dirty_log_exit(void) |
781 | { | 787 | { |
782 | dm_unregister_dirty_log_type(&_disk_type); | 788 | dm_dirty_log_type_unregister(&_disk_type); |
783 | dm_unregister_dirty_log_type(&_core_type); | 789 | dm_dirty_log_type_unregister(&_core_type); |
784 | } | 790 | } |
785 | 791 | ||
786 | EXPORT_SYMBOL(dm_register_dirty_log_type); | ||
787 | EXPORT_SYMBOL(dm_unregister_dirty_log_type); | ||
788 | EXPORT_SYMBOL(dm_create_dirty_log); | ||
789 | EXPORT_SYMBOL(dm_destroy_dirty_log); | ||
790 | |||
791 | module_init(dm_dirty_log_init); | 792 | module_init(dm_dirty_log_init); |
792 | module_exit(dm_dirty_log_exit); | 793 | module_exit(dm_dirty_log_exit); |
793 | 794 | ||