Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

NeilBrown and committed by
Linus Torvalds
4ad13663 f0d76d70

+78 -77
+72 -68
drivers/md/bitmap.c
··· 305 305 return 0; 306 306 } 307 307 308 + static void bitmap_file_kick(struct bitmap *bitmap); 308 309 /* 309 310 * write out a page to a file 310 311 */ 311 - static int write_page(struct bitmap *bitmap, struct page *page, int wait) 312 + static void write_page(struct bitmap *bitmap, struct page *page, int wait) 312 313 { 313 314 struct buffer_head *bh; 314 315 ··· 317 316 switch (write_sb_page(bitmap, page, wait)) { 318 317 case -EINVAL: 319 318 bitmap->flags |= BITMAP_WRITE_ERROR; 320 - return -EIO; 321 319 } 322 - return 0; 323 - } 320 + } else { 324 321 325 - bh = page_buffers(page); 322 + bh = page_buffers(page); 326 323 327 - while (bh && bh->b_blocknr) { 328 - atomic_inc(&bitmap->pending_writes); 329 - set_buffer_locked(bh); 330 - set_buffer_mapped(bh); 331 - submit_bh(WRITE, bh); 332 - bh = bh->b_this_page; 333 - } 324 + while (bh && bh->b_blocknr) { 325 + atomic_inc(&bitmap->pending_writes); 326 + set_buffer_locked(bh); 327 + set_buffer_mapped(bh); 328 + submit_bh(WRITE, bh); 329 + bh = bh->b_this_page; 330 + } 334 331 335 - if (wait) { 336 - wait_event(bitmap->write_wait, 337 - atomic_read(&bitmap->pending_writes)==0); 338 - return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0; 332 + if (wait) { 333 + wait_event(bitmap->write_wait, 334 + atomic_read(&bitmap->pending_writes)==0); 335 + } 339 336 } 340 - return 0; 337 + if (bitmap->flags & BITMAP_WRITE_ERROR) 338 + bitmap_file_kick(bitmap); 341 339 } 342 340 343 341 static void end_bitmap_write(struct buffer_head *bh, int uptodate) ··· 456 456 */ 457 457 458 458 /* update the event counter and sync the superblock to disk */ 459 - int bitmap_update_sb(struct bitmap *bitmap) 459 + void bitmap_update_sb(struct bitmap *bitmap) 460 460 { 461 461 bitmap_super_t *sb; 462 462 unsigned long flags; 463 463 464 464 if (!bitmap || !bitmap->mddev) /* no bitmap for this array */ 465 - return 0; 465 + return; 466 466 spin_lock_irqsave(&bitmap->lock, flags); 467 467 if (!bitmap->sb_page) { /* no superblock */ 468 468 spin_unlock_irqrestore(&bitmap->lock, flags); 469 - return 0; 469 + return; 470 470 } 471 471 spin_unlock_irqrestore(&bitmap->lock, flags); 472 472 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0); ··· 474 474 if (!bitmap->mddev->degraded) 475 475 sb->events_cleared = cpu_to_le64(bitmap->mddev->events); 476 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 480 /* print out the bitmap file superblock */ ··· 603 603 MASK_UNSET 604 604 }; 605 605 606 - /* record the state of the bitmap in the superblock */ 607 - static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits, 608 - enum bitmap_mask_op op) 606 + /* record the state of the bitmap in the superblock. Return the old value */ 607 + static int bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits, 608 + enum bitmap_mask_op op) 609 609 { 610 610 bitmap_super_t *sb; 611 611 unsigned long flags; 612 + int old; 612 613 613 614 spin_lock_irqsave(&bitmap->lock, flags); 614 615 if (!bitmap->sb_page) { /* can't set the state */ 615 616 spin_unlock_irqrestore(&bitmap->lock, flags); 616 - return; 617 + return 0; 617 618 } 618 619 spin_unlock_irqrestore(&bitmap->lock, flags); 619 620 sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0); 621 + old = le32_to_cpu(sb->state) & bits; 620 622 switch (op) { 621 623 case MASK_SET: sb->state |= cpu_to_le32(bits); 622 624 break; ··· 627 625 default: BUG(); 628 626 } 629 627 kunmap_atomic(sb, KM_USER0); 628 + return old; 630 629 } 631 630 632 631 /* ··· 721 718 { 722 719 char *path, *ptr = NULL; 723 720 724 - bitmap_mask_state(bitmap, BITMAP_STALE, MASK_SET); 725 - bitmap_update_sb(bitmap); 721 + if (bitmap_mask_state(bitmap, BITMAP_STALE, MASK_SET) == 0) { 722 + bitmap_update_sb(bitmap); 726 723 727 - if (bitmap->file) { 728 - path = kmalloc(PAGE_SIZE, GFP_KERNEL); 729 - if (path) 730 - ptr = file_path(bitmap->file, path, PAGE_SIZE); 724 + if (bitmap->file) { 725 + path = kmalloc(PAGE_SIZE, GFP_KERNEL); 726 + if (path) 727 + ptr = file_path(bitmap->file, path, PAGE_SIZE); 731 728 732 - printk(KERN_ALERT "%s: kicking failed bitmap file %s from array!\n", 733 - bmname(bitmap), ptr ? ptr : ""); 729 + printk(KERN_ALERT 730 + "%s: kicking failed bitmap file %s from array!\n", 731 + bmname(bitmap), ptr ? ptr : ""); 734 732 735 - kfree(path); 733 + kfree(path); 734 + } else 735 + printk(KERN_ALERT 736 + "%s: disabling internal bitmap due to errors\n", 737 + bmname(bitmap)); 736 738 } 737 739 738 740 bitmap_file_put(bitmap); ··· 808 800 /* this gets called when the md device is ready to unplug its underlying 809 801 * (slave) device queues -- before we let any writes go down, we need to 810 802 * sync the dirty pages of the bitmap file to disk */ 811 - int bitmap_unplug(struct bitmap *bitmap) 803 + void bitmap_unplug(struct bitmap *bitmap) 812 804 { 813 805 unsigned long i, flags; 814 806 int dirty, need_write; 815 807 struct page *page; 816 808 int wait = 0; 817 - int err; 818 809 819 810 if (!bitmap) 820 - return 0; 811 + return; 821 812 822 813 /* look at each page to see if there are any set bits that need to be 823 814 * flushed out to disk */ ··· 824 817 spin_lock_irqsave(&bitmap->lock, flags); 825 818 if (!bitmap->filemap) { 826 819 spin_unlock_irqrestore(&bitmap->lock, flags); 827 - return 0; 820 + return; 828 821 } 829 822 page = bitmap->filemap[i]; 830 823 dirty = test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); ··· 836 829 spin_unlock_irqrestore(&bitmap->lock, flags); 837 830 838 831 if (dirty | need_write) 839 - err = write_page(bitmap, page, 0); 832 + write_page(bitmap, page, 0); 840 833 } 841 834 if (wait) { /* if any writes were performed, we need to wait on them */ 842 835 if (bitmap->file) ··· 847 840 } 848 841 if (bitmap->flags & BITMAP_WRITE_ERROR) 849 842 bitmap_file_kick(bitmap); 850 - return 0; 851 843 } 852 844 853 845 static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed); ··· 895 889 bmname(bitmap), 896 890 (unsigned long) i_size_read(file->f_mapping->host), 897 891 bytes + sizeof(bitmap_super_t)); 898 - goto out; 892 + goto err; 899 893 } 900 894 901 895 ret = -ENOMEM; 902 896 903 897 bitmap->filemap = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL); 904 898 if (!bitmap->filemap) 905 - goto out; 899 + goto err; 906 900 907 901 /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned long) */ 908 902 bitmap->filemap_attr = kzalloc( 909 903 roundup( DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)), 910 904 GFP_KERNEL); 911 905 if (!bitmap->filemap_attr) 912 - goto out; 906 + goto err; 913 907 914 908 oldindex = ~0L; 915 909 ··· 942 936 } 943 937 if (IS_ERR(page)) { /* read error */ 944 938 ret = PTR_ERR(page); 945 - goto out; 939 + goto err; 946 940 } 947 941 948 942 oldindex = index; ··· 957 951 memset(paddr + offset, 0xff, 958 952 PAGE_SIZE - offset); 959 953 kunmap_atomic(paddr, KM_USER0); 960 - ret = write_page(bitmap, page, 1); 961 - if (ret) { 954 + write_page(bitmap, page, 1); 955 + 956 + ret = -EIO; 957 + if (bitmap->flags & BITMAP_WRITE_ERROR) { 962 958 /* release, page not in filemap yet */ 963 959 put_page(page); 964 - goto out; 960 + goto err; 965 961 } 966 962 } 967 963 ··· 995 987 md_wakeup_thread(bitmap->mddev->thread); 996 988 } 997 989 998 - out: 999 990 printk(KERN_INFO "%s: bitmap initialized from disk: " 1000 - "read %lu/%lu pages, set %lu bits, status: %d\n", 1001 - bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt, ret); 991 + "read %lu/%lu pages, set %lu bits\n", 992 + bmname(bitmap), bitmap->file_pages, num_pages, bit_cnt); 1002 993 994 + return 0; 995 + 996 + err: 997 + printk(KERN_INFO "%s: bitmap initialisation failed: %d\n", 998 + bmname(bitmap), ret); 1003 999 return ret; 1004 1000 } 1005 1001 ··· 1040 1028 * out to disk 1041 1029 */ 1042 1030 1043 - int bitmap_daemon_work(struct bitmap *bitmap) 1031 + void bitmap_daemon_work(struct bitmap *bitmap) 1044 1032 { 1045 1033 unsigned long j; 1046 1034 unsigned long flags; 1047 1035 struct page *page = NULL, *lastpage = NULL; 1048 - int err = 0; 1049 1036 int blocks; 1050 1037 void *paddr; 1051 1038 1052 1039 if (bitmap == NULL) 1053 - return 0; 1040 + return; 1054 1041 if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ)) 1055 - return 0; 1042 + return; 1056 1043 bitmap->daemon_lastrun = jiffies; 1057 1044 1058 1045 for (j = 0; j < bitmap->chunks; j++) { ··· 1074 1063 clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE); 1075 1064 1076 1065 spin_unlock_irqrestore(&bitmap->lock, flags); 1077 - if (need_write) { 1078 - switch (write_page(bitmap, page, 0)) { 1079 - case 0: 1080 - break; 1081 - default: 1082 - bitmap_file_kick(bitmap); 1083 - } 1084 - } 1066 + if (need_write) 1067 + write_page(bitmap, page, 0); 1085 1068 continue; 1086 1069 } 1087 1070 ··· 1084 1079 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { 1085 1080 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1086 1081 spin_unlock_irqrestore(&bitmap->lock, flags); 1087 - err = write_page(bitmap, lastpage, 0); 1082 + write_page(bitmap, lastpage, 0); 1088 1083 } else { 1089 1084 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1090 1085 spin_unlock_irqrestore(&bitmap->lock, flags); 1091 1086 } 1092 - if (err) 1093 - bitmap_file_kick(bitmap); 1094 1087 } else 1095 1088 spin_unlock_irqrestore(&bitmap->lock, flags); 1096 1089 lastpage = page; ··· 1131 1128 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { 1132 1129 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1133 1130 spin_unlock_irqrestore(&bitmap->lock, flags); 1134 - err = write_page(bitmap, lastpage, 0); 1131 + write_page(bitmap, lastpage, 0); 1135 1132 } else { 1136 1133 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1137 1134 spin_unlock_irqrestore(&bitmap->lock, flags); 1138 1135 } 1139 1136 } 1140 1137 1141 - return err; 1142 1138 } 1143 1139 1144 1140 static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, ··· 1550 1548 1551 1549 mddev->thread->timeout = bitmap->daemon_sleep * HZ; 1552 1550 1553 - return bitmap_update_sb(bitmap); 1551 + bitmap_update_sb(bitmap); 1552 + 1553 + return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0; 1554 1554 1555 1555 error: 1556 1556 bitmap_free(bitmap);
+1 -2
drivers/md/md.c
··· 1640 1640 1641 1641 static void md_update_sb(mddev_t * mddev, int force_change) 1642 1642 { 1643 - int err; 1644 1643 struct list_head *tmp; 1645 1644 mdk_rdev_t *rdev; 1646 1645 int sync_req; ··· 1726 1727 "md: updating %s RAID superblock on device (in sync %d)\n", 1727 1728 mdname(mddev),mddev->in_sync); 1728 1729 1729 - err = bitmap_update_sb(mddev->bitmap); 1730 + bitmap_update_sb(mddev->bitmap); 1730 1731 ITERATE_RDEV(mddev,rdev,tmp) { 1731 1732 char b[BDEVNAME_SIZE]; 1732 1733 dprintk(KERN_INFO "md: ");
+1 -2
drivers/md/raid1.c
··· 1526 1526 blk_remove_plug(mddev->queue); 1527 1527 spin_unlock_irqrestore(&conf->device_lock, flags); 1528 1528 /* flush any pending bitmap writes to disk before proceeding w/ I/O */ 1529 - if (bitmap_unplug(mddev->bitmap) != 0) 1530 - printk("%s: bitmap file write failed!\n", mdname(mddev)); 1529 + bitmap_unplug(mddev->bitmap); 1531 1530 1532 1531 while (bio) { /* submit pending writes */ 1533 1532 struct bio *next = bio->bi_next;
+1 -2
drivers/md/raid10.c
··· 1510 1510 blk_remove_plug(mddev->queue); 1511 1511 spin_unlock_irqrestore(&conf->device_lock, flags); 1512 1512 /* flush any pending bitmap writes to disk before proceeding w/ I/O */ 1513 - if (bitmap_unplug(mddev->bitmap) != 0) 1514 - printk("%s: bitmap file write failed!\n", mdname(mddev)); 1513 + bitmap_unplug(mddev->bitmap); 1515 1514 1516 1515 while (bio) { /* submit pending writes */ 1517 1516 struct bio *next = bio->bi_next;
+3 -3
include/linux/raid/bitmap.h
··· 262 262 263 263 char *file_path(struct file *file, char *buf, int count); 264 264 void bitmap_print_sb(struct bitmap *bitmap); 265 - int bitmap_update_sb(struct bitmap *bitmap); 265 + void bitmap_update_sb(struct bitmap *bitmap); 266 266 267 267 int bitmap_setallbits(struct bitmap *bitmap); 268 268 void bitmap_write_all(struct bitmap *bitmap); ··· 278 278 void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted); 279 279 void bitmap_close_sync(struct bitmap *bitmap); 280 280 281 - int bitmap_unplug(struct bitmap *bitmap); 282 - int bitmap_daemon_work(struct bitmap *bitmap); 281 + void bitmap_unplug(struct bitmap *bitmap); 282 + void bitmap_daemon_work(struct bitmap *bitmap); 283 283 #endif 284 284 285 285 #endif