aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/bitmap.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2007-07-17 07:06:13 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-17 13:23:15 -0400
commit4ad1366376bfef32ec0ffa12d1faa483d6f330bd (patch)
tree87a9c864ec5ebd446f6c99f3298bc7638efa8f1e /drivers/md/bitmap.c
parentf0d76d70bc77b9b11256a3a23e98e80878be1578 (diff)
md: change bitmap_unplug and others to void functions
bitmap_unplug only ever returns 0, so it may as well be void. Two callers try to print a message if it returns non-zero, but that message is already printed by bitmap_file_kick. write_page returns an error which is not consistently checked. It always causes BITMAP_WRITE_ERROR to be set on an error, and that can more conveniently be checked. When the return of write_page is checked, an error causes bitmap_file_kick to be called - so move that call into write_page - and protect against recursive calls into bitmap_file_kick. bitmap_update_sb returns an error that is never checked. So make these 'void' and be consistent about checking the bit. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/md/bitmap.c')
-rw-r--r--drivers/md/bitmap.c140
1 files changed, 72 insertions, 68 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index ae94f3beb5fc..927cb34c4805 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -305,10 +305,11 @@ static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
305 return 0; 305 return 0;
306} 306}
307 307
308static void bitmap_file_kick(struct bitmap *bitmap);
308/* 309/*
309 * write out a page to a file 310 * write out a page to a file
310 */ 311 */
311static int write_page(struct bitmap *bitmap, struct page *page, int wait) 312static void write_page(struct bitmap *bitmap, struct page *page, int wait)
312{ 313{
313 struct buffer_head *bh; 314 struct buffer_head *bh;
314 315
@@ -316,27 +317,26 @@ static int write_page(struct bitmap *bitmap, struct page *page, int wait)
316 switch (write_sb_page(bitmap, page, wait)) { 317 switch (write_sb_page(bitmap, page, wait)) {
317 case -EINVAL: 318 case -EINVAL:
318 bitmap->flags |= BITMAP_WRITE_ERROR; 319 bitmap->flags |= BITMAP_WRITE_ERROR;
319 return -EIO;
320 } 320 }
321 return 0; 321 } else {
322 }
323 322
324 bh = page_buffers(page); 323 bh = page_buffers(page);
325 324
326 while (bh && bh->b_blocknr) { 325 while (bh && bh->b_blocknr) {
327 atomic_inc(&bitmap->pending_writes); 326 atomic_inc(&bitmap->pending_writes);
328 set_buffer_locked(bh); 327 set_buffer_locked(bh);
329 set_buffer_mapped(bh); 328 set_buffer_mapped(bh);
330 submit_bh(WRITE, bh); 329 submit_bh(WRITE, bh);
331 bh = bh->b_this_page; 330 bh = bh->b_this_page;
332 } 331 }
333 332
334 if (wait) { 333 if (wait) {
335 wait_event(bitmap->write_wait, 334 wait_event(bitmap->write_wait,
336 atomic_read(&bitmap->pending_writes)==0); 335 atomic_read(&bitmap->pending_writes)==0);
337 return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0; 336 }
338 } 337 }
339 return 0; 338 if (bitmap->flags & BITMAP_WRITE_ERROR)
339 bitmap_file_kick(bitmap);
340} 340}
341 341
342static void end_bitmap_write(struct buffer_head *bh, int uptodate) 342static void end_bitmap_write(struct buffer_head *bh, int uptodate)
@@ -456,17 +456,17 @@ out:
456 */ 456 */
457 457
458/* update the event counter and sync the superblock to disk */ 458/* update the event counter and sync the superblock to disk */
459int bitmap_update_sb(struct bitmap *bitmap) 459void bitmap_update_sb(struct bitmap *bitmap)
460{ 460{
461 bitmap_super_t *sb; 461 bitmap_super_t *sb;
462 unsigned long flags; 462 unsigned long flags;
463 463
464 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ 464 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */
465 return 0; 465 return;
466 spin_lock_irqsave(&bitmap->lock, flags); 466 spin_lock_irqsave(&bitmap->lock, flags);
467 if (!bitmap->sb_page) { /* no superblock */ 467 if (!bitmap->sb_page) { /* no superblock */
468 spin_unlock_irqrestore(&bitmap->lock, flags); 468 spin_unlock_irqrestore(&bitmap->lock, flags);
469 return 0; 469 return;
470 } 470 }
471 spin_unlock_irqrestore(&bitmap->lock, flags); 471 spin_unlock_irqrestore(&bitmap->lock, flags);
472 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0); 472 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
@@ -474,7 +474,7 @@ int bitmap_update_sb(struct bitmap *bitmap)
474 if (!bitmap->mddev->degraded) 474 if (!bitmap->mddev->degraded)
475 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); 475 sb->events_cleared = cpu_to_le64(bitmap->mddev->events);
476 kunmap_atomic(sb, KM_USER0); 476 kunmap_atomic(sb, KM_USER0);
477 return write_page(bitmap, bitmap->sb_page, 1); 477 write_page(bitmap, bitmap->sb_page, 1);
478} 478}
479 479
480/* print out the bitmap file superblock */ 480/* print out the bitmap file superblock */
@@ -603,20 +603,22 @@ enum bitmap_mask_op {
603 MASK_UNSET 603 MASK_UNSET
604}; 604};
605 605
606/* record the state of the bitmap in the superblock */ 606/* record the state of the bitmap in the superblock. Return the old value */
607static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits, 607static int bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits,
608 enum bitmap_mask_op op) 608 enum bitmap_mask_op op)
609{ 609{
610 bitmap_super_t *sb; 610 bitmap_super_t *sb;
611 unsigned long flags; 611 unsigned long flags;
612 int old;
612 613
613 spin_lock_irqsave(&bitmap->lock, flags); 614 spin_lock_irqsave(&bitmap->lock, flags);
614 if (!bitmap->sb_page) { /* can't set the state */ 615 if (!bitmap->sb_page) { /* can't set the state */
615 spin_unlock_irqrestore(&bitmap->lock, flags); 616 spin_unlock_irqrestore(&bitmap->lock, flags);
616 return; 617 return 0;
617 } 618 }
618 spin_unlock_irqrestore(&bitmap->lock, flags); 619 spin_unlock_irqrestore(&bitmap->lock, flags);
619 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0); 620 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
621 old = le32_to_cpu(sb->state) & bits;
620 switch (op) { 622 switch (op) {
621 case MASK_SET: sb->state |= cpu_to_le32(bits); 623 case MASK_SET: sb->state |= cpu_to_le32(bits);
622 break; 624 break;
@@ -625,6 +627,7 @@ static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits,
625 default: BUG(); 627 default: BUG();
626 } 628 }
627 kunmap_atomic(sb, KM_USER0); 629 kunmap_atomic(sb, KM_USER0);
630 return old;
628} 631}
629 632
630/* 633/*
@@ -718,18 +721,23 @@ static void bitmap_file_kick(struct bitmap *bitmap)
718{ 721{
719 char *path, *ptr = NULL; 722 char *path, *ptr = NULL;
720 723
721 bitmap_mask_state(bitmap, BITMAP_STALE, MASK_SET); 724 if (bitmap_mask_state(bitmap, BITMAP_STALE, MASK_SET) == 0) {
722 bitmap_update_sb(bitmap); 725 bitmap_update_sb(bitmap);
723 726
724 if (bitmap->file) { 727 if (bitmap->file) {
725 path = kmalloc(PAGE_SIZE, GFP_KERNEL); 728 path = kmalloc(PAGE_SIZE, GFP_KERNEL);
726 if (path) 729 if (path)
727 ptr = file_path(bitmap->file, path, PAGE_SIZE); 730 ptr = file_path(bitmap->file, path, PAGE_SIZE);
728 731
729 printk(KERN_ALERT "%s: kicking failed bitmap file %s from array!\n", 732 printk(KERN_ALERT
730 bmname(bitmap), ptr ? ptr : ""); 733 "%s: kicking failed bitmap file %s from array!\n",
734 bmname(bitmap), ptr ? ptr : "");
731 735
732 kfree(path); 736 kfree(path);
737 } else
738 printk(KERN_ALERT
739 "%s: disabling internal bitmap due to errors\n",
740 bmname(bitmap));
733 } 741 }
734 742
735 bitmap_file_put(bitmap); 743 bitmap_file_put(bitmap);
@@ -800,16 +808,15 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
800/* this gets called when the md device is ready to unplug its underlying 808/* this gets called when the md device is ready to unplug its underlying
801 * (slave) device queues -- before we let any writes go down, we need to 809 * (slave) device queues -- before we let any writes go down, we need to
802 * sync the dirty pages of the bitmap file to disk */ 810 * sync the dirty pages of the bitmap file to disk */
803int bitmap_unplug(struct bitmap *bitmap) 811void bitmap_unplug(struct bitmap *bitmap)
804{ 812{
805 unsigned long i, flags; 813 unsigned long i, flags;
806 int dirty, need_write; 814 int dirty, need_write;
807 struct page *page; 815 struct page *page;
808 int wait = 0; 816 int wait = 0;
809 int err;
810 817
811 if (!bitmap) 818 if (!bitmap)
812 return 0; 819 return;
813 820
814 /* look at each page to see if there are any set bits that need to be 821 /* look at each page to see if there are any set bits that need to be
815 * flushed out to disk */ 822 * flushed out to disk */
@@ -817,7 +824,7 @@ int bitmap_unplug(struct bitmap *bitmap)
817 spin_lock_irqsave(&bitmap->lock, flags); 824 spin_lock_irqsave(&bitmap->lock, flags);
818 if (!bitmap->filemap) { 825 if (!bitmap->filemap) {
819 spin_unlock_irqrestore(&bitmap->lock, flags); 826 spin_unlock_irqrestore(&bitmap->lock, flags);
820 return 0; 827 return;
821 } 828 }
822 page = bitmap->filemap[i]; 829 page = bitmap->filemap[i];
823 dirty = test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); 830 dirty = test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
@@ -829,7 +836,7 @@ int bitmap_unplug(struct bitmap *bitmap)
829 spin_unlock_irqrestore(&bitmap->lock, flags); 836 spin_unlock_irqrestore(&bitmap->lock, flags);
830 837
831 if (dirty | need_write) 838 if (dirty | need_write)
832 err = write_page(bitmap, page, 0); 839 write_page(bitmap, page, 0);
833 } 840 }
834 if (wait) { /* if any writes were performed, we need to wait on them */ 841 if (wait) { /* if any writes were performed, we need to wait on them */
835 if (bitmap->file) 842 if (bitmap->file)
@@ -840,7 +847,6 @@ int bitmap_unplug(struct bitmap *bitmap)
840 } 847 }
841 if (bitmap->flags & BITMAP_WRITE_ERROR) 848 if (bitmap->flags & BITMAP_WRITE_ERROR)
842 bitmap_file_kick(bitmap); 849 bitmap_file_kick(bitmap);
843 return 0;
844} 850}
845 851
846static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed); 852static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
@@ -889,21 +895,21 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
889 bmname(bitmap), 895 bmname(bitmap),
890 (unsigned long) i_size_read(file->f_mapping->host), 896 (unsigned long) i_size_read(file->f_mapping->host),
891 bytes + sizeof(bitmap_super_t)); 897 bytes + sizeof(bitmap_super_t));
892 goto out; 898 goto err;
893 } 899 }
894 900
895 ret = -ENOMEM; 901 ret = -ENOMEM;
896 902
897 bitmap->filemap = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL); 903 bitmap->filemap = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
898 if (!bitmap->filemap) 904 if (!bitmap->filemap)
899 goto out; 905 goto err;
900 906
901 /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned long) */ 907 /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned long) */
902 bitmap->filemap_attr = kzalloc( 908 bitmap->filemap_attr = kzalloc(
903 roundup( DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)), 909 roundup( DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)),
904 GFP_KERNEL); 910 GFP_KERNEL);
905 if (!bitmap->filemap_attr) 911 if (!bitmap->filemap_attr)
906 goto out; 912 goto err;
907 913
908 oldindex = ~0L; 914 oldindex = ~0L;
909 915
@@ -936,7 +942,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
936 } 942 }
937 if (IS_ERR(page)) { /* read error */ 943 if (IS_ERR(page)) { /* read error */
938 ret = PTR_ERR(page); 944 ret = PTR_ERR(page);
939 goto out; 945 goto err;
940 } 946 }
941 947
942 oldindex = index; 948 oldindex = index;
@@ -951,11 +957,13 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
951 memset(paddr + offset, 0xff, 957 memset(paddr + offset, 0xff,
952 PAGE_SIZE - offset); 958 PAGE_SIZE - offset);
953 kunmap_atomic(paddr, KM_USER0); 959 kunmap_atomic(paddr, KM_USER0);
954 ret = write_page(bitmap, page, 1); 960 write_page(bitmap, page, 1);
955 if (ret) { 961
962 ret = -EIO;
963 if (bitmap->flags & BITMAP_WRITE_ERROR) {
956 /* release, page not in filemap yet */ 964 /* release, page not in filemap yet */
957 put_page(page); 965 put_page(page);
958 goto out; 966 goto err;
959 } 967 }
960 } 968 }
961 969
@@ -987,11 +995,15 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
987 md_wakeup_thread(bitmap->mddev->thread); 995 md_wakeup_thread(bitmap->mddev->thread);
988 } 996 }
989 997
990out:
991 printk(KERN_INFO "%s: bitmap initialized from disk: " 998 printk(KERN_INFO "%s: bitmap initialized from disk: "
992 "read %lu/%lu pages, set %lu bits, status: %d\n", 999 "read %lu/%lu pages, set %lu bits\n",
993 bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt, ret); 1000 bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt);
1001
1002 return 0;
994 1003
1004 err:
1005 printk(KERN_INFO "%s: bitmap initialisation failed: %d\n",
1006 bmname(bitmap), ret);
995 return ret; 1007 return ret;
996} 1008}
997 1009
@@ -1028,19 +1040,18 @@ static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
1028 * out to disk 1040 * out to disk
1029 */ 1041 */
1030 1042
1031int bitmap_daemon_work(struct bitmap *bitmap) 1043void bitmap_daemon_work(struct bitmap *bitmap)
1032{ 1044{
1033 unsigned long j; 1045 unsigned long j;
1034 unsigned long flags; 1046 unsigned long flags;
1035 struct page *page = NULL, *lastpage = NULL; 1047 struct page *page = NULL, *lastpage = NULL;
1036 int err = 0;
1037 int blocks; 1048 int blocks;
1038 void *paddr; 1049 void *paddr;
1039 1050
1040 if (bitmap == NULL) 1051 if (bitmap == NULL)
1041 return 0; 1052 return;
1042 if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ)) 1053 if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ))
1043 return 0; 1054 return;
1044 bitmap->daemon_lastrun = jiffies; 1055 bitmap->daemon_lastrun = jiffies;
1045 1056
1046 for (j = 0; j < bitmap->chunks; j++) { 1057 for (j = 0; j < bitmap->chunks; j++) {
@@ -1063,14 +1074,8 @@ int bitmap_daemon_work(struct bitmap *bitmap)
1063 clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE); 1074 clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
1064 1075
1065 spin_unlock_irqrestore(&bitmap->lock, flags); 1076 spin_unlock_irqrestore(&bitmap->lock, flags);
1066 if (need_write) { 1077 if (need_write)
1067 switch (write_page(bitmap, page, 0)) { 1078 write_page(bitmap, page, 0);
1068 case 0:
1069 break;
1070 default:
1071 bitmap_file_kick(bitmap);
1072 }
1073 }
1074 continue; 1079 continue;
1075 } 1080 }
1076 1081
@@ -1079,13 +1084,11 @@ int bitmap_daemon_work(struct bitmap *bitmap)
1079 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { 1084 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
1080 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1085 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1081 spin_unlock_irqrestore(&bitmap->lock, flags); 1086 spin_unlock_irqrestore(&bitmap->lock, flags);
1082 err = write_page(bitmap, lastpage, 0); 1087 write_page(bitmap, lastpage, 0);
1083 } else { 1088 } else {
1084 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1089 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1085 spin_unlock_irqrestore(&bitmap->lock, flags); 1090 spin_unlock_irqrestore(&bitmap->lock, flags);
1086 } 1091 }
1087 if (err)
1088 bitmap_file_kick(bitmap);
1089 } else 1092 } else
1090 spin_unlock_irqrestore(&bitmap->lock, flags); 1093 spin_unlock_irqrestore(&bitmap->lock, flags);
1091 lastpage = page; 1094 lastpage = page;
@@ -1128,14 +1131,13 @@ int bitmap_daemon_work(struct bitmap *bitmap)
1128 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { 1131 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
1129 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1132 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1130 spin_unlock_irqrestore(&bitmap->lock, flags); 1133 spin_unlock_irqrestore(&bitmap->lock, flags);
1131 err = write_page(bitmap, lastpage, 0); 1134 write_page(bitmap, lastpage, 0);
1132 } else { 1135 } else {
1133 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1136 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1134 spin_unlock_irqrestore(&bitmap->lock, flags); 1137 spin_unlock_irqrestore(&bitmap->lock, flags);
1135 } 1138 }
1136 } 1139 }
1137 1140
1138 return err;
1139} 1141}
1140 1142
1141static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, 1143static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
@@ -1548,7 +1550,9 @@ int bitmap_create(mddev_t *mddev)
1548 1550
1549 mddev->thread->timeout = bitmap->daemon_sleep * HZ; 1551 mddev->thread->timeout = bitmap->daemon_sleep * HZ;
1550 1552
1551 return bitmap_update_sb(bitmap); 1553 bitmap_update_sb(bitmap);
1554
1555 return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0;
1552 1556
1553 error: 1557 error:
1554 bitmap_free(bitmap); 1558 bitmap_free(bitmap);