aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-10-18 14:39:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-18 14:39:52 -0400
commit88ed806abb981cc8ec61ee7fab93ecfe63521ebf (patch)
treef3639f4a6862598fcdbb444ef4b5bbceb63d5c46 /drivers/md
parente56d9fccb1c78283d7c163bb354be7cbbc93d9fb (diff)
parentb395f75eabb3844c99244928293796ff42feaa3d (diff)
Merge tag 'md/3.18' of git://neil.brown.name/md
Pull md updates from Neil Brown: - a few minor bug fixes - quite a lot of code tidy-up and simplification - remove PRINT_RAID_DEBUG ioctl. I'm fairly sure it is unused, and it isn't particularly useful. * tag 'md/3.18' of git://neil.brown.name/md: (21 commits) lib/raid6: Add log level to printks md: move EXPORT_SYMBOL to after function in md.c md: discard PRINT_RAID_DEBUG ioctl md: remove MD_BUG() md: clean up 'exit' labels in md_ioctl(). md: remove unnecessary test for MD_MAJOR in md_ioctl() md: don't allow "-sync" to be set for device in an active array. md: remove unwanted white space from md.c md: don't start resync thread directly from md thread. md: Just use RCU when checking for overlap between arrays. md: avoid potential long delay under pers_lock md: simplify export_array() md: discard find_rdev_nr in favour of find_rdev_nr_rcu md: use wait_event() to simplify md_super_wait() md: be more relaxed about stopping an array which isn't started. md/raid1: process_checks doesn't use its return value. md/raid5: fix init_stripe() inconsistencies md/raid10: another memory leak due to reshape. md: use set_bit/clear_bit instead of shift/mask for bi_flags changes. md/raid1: minor typos and reformatting. ...
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/bitmap.c16
-rw-r--r--drivers/md/linear.c8
-rw-r--r--drivers/md/md.c601
-rw-r--r--drivers/md/md.h34
-rw-r--r--drivers/md/multipath.c28
-rw-r--r--drivers/md/raid0.c9
-rw-r--r--drivers/md/raid1.c37
-rw-r--r--drivers/md/raid1.h2
-rw-r--r--drivers/md/raid10.c18
-rw-r--r--drivers/md/raid5.c29
-rw-r--r--drivers/md/raid5.h4
11 files changed, 260 insertions, 526 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 67f8b31e2054..da3604e73e8a 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -879,7 +879,6 @@ void bitmap_unplug(struct bitmap *bitmap)
879{ 879{
880 unsigned long i; 880 unsigned long i;
881 int dirty, need_write; 881 int dirty, need_write;
882 int wait = 0;
883 882
884 if (!bitmap || !bitmap->storage.filemap || 883 if (!bitmap || !bitmap->storage.filemap ||
885 test_bit(BITMAP_STALE, &bitmap->flags)) 884 test_bit(BITMAP_STALE, &bitmap->flags))
@@ -897,16 +896,13 @@ void bitmap_unplug(struct bitmap *bitmap)
897 clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING); 896 clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING);
898 write_page(bitmap, bitmap->storage.filemap[i], 0); 897 write_page(bitmap, bitmap->storage.filemap[i], 0);
899 } 898 }
900 if (dirty)
901 wait = 1;
902 }
903 if (wait) { /* if any writes were performed, we need to wait on them */
904 if (bitmap->storage.file)
905 wait_event(bitmap->write_wait,
906 atomic_read(&bitmap->pending_writes)==0);
907 else
908 md_super_wait(bitmap->mddev);
909 } 899 }
900 if (bitmap->storage.file)
901 wait_event(bitmap->write_wait,
902 atomic_read(&bitmap->pending_writes)==0);
903 else
904 md_super_wait(bitmap->mddev);
905
910 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) 906 if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
911 bitmap_file_kick(bitmap); 907 bitmap_file_kick(bitmap);
912} 908}
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 56f534b4a2d2..64713b77df1c 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -10,10 +10,10 @@
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option) 11 the Free Software Foundation; either version 2, or (at your option)
12 any later version. 12 any later version.
13 13
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 (for example /usr/src/linux/COPYING); if not, write to the Free 15 (for example /usr/src/linux/COPYING); if not, write to the Free
16 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/ 17*/
18 18
19#include <linux/blkdev.h> 19#include <linux/blkdev.h>
@@ -25,7 +25,7 @@
25#include "linear.h" 25#include "linear.h"
26 26
27/* 27/*
28 * find which device holds a particular offset 28 * find which device holds a particular offset
29 */ 29 */
30static inline struct dev_info *which_dev(struct mddev *mddev, sector_t sector) 30static inline struct dev_info *which_dev(struct mddev *mddev, sector_t sector)
31{ 31{
@@ -355,7 +355,6 @@ static void linear_status (struct seq_file *seq, struct mddev *mddev)
355 seq_printf(seq, " %dk rounding", mddev->chunk_sectors / 2); 355 seq_printf(seq, " %dk rounding", mddev->chunk_sectors / 2);
356} 356}
357 357
358
359static struct md_personality linear_personality = 358static struct md_personality linear_personality =
360{ 359{
361 .name = "linear", 360 .name = "linear",
@@ -379,7 +378,6 @@ static void linear_exit (void)
379 unregister_md_personality (&linear_personality); 378 unregister_md_personality (&linear_personality);
380} 379}
381 380
382
383module_init(linear_init); 381module_init(linear_init);
384module_exit(linear_exit); 382module_exit(linear_exit);
385MODULE_LICENSE("GPL"); 383MODULE_LICENSE("GPL");
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 1294238610df..4dfa15da9cb8 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1,6 +1,6 @@
1/* 1/*
2 md.c : Multiple Devices driver for Linux 2 md.c : Multiple Devices driver for Linux
3 Copyright (C) 1998, 1999, 2000 Ingo Molnar 3 Copyright (C) 1998, 1999, 2000 Ingo Molnar
4 4
5 completely rewritten, based on the MD driver code from Marc Zyngier 5 completely rewritten, based on the MD driver code from Marc Zyngier
6 6
@@ -66,8 +66,6 @@ static void autostart_arrays(int part);
66static LIST_HEAD(pers_list); 66static LIST_HEAD(pers_list);
67static DEFINE_SPINLOCK(pers_lock); 67static DEFINE_SPINLOCK(pers_lock);
68 68
69static void md_print_devices(void);
70
71static DECLARE_WAIT_QUEUE_HEAD(resync_wait); 69static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
72static struct workqueue_struct *md_wq; 70static struct workqueue_struct *md_wq;
73static struct workqueue_struct *md_misc_wq; 71static struct workqueue_struct *md_misc_wq;
@@ -75,8 +73,6 @@ static struct workqueue_struct *md_misc_wq;
75static int remove_and_add_spares(struct mddev *mddev, 73static int remove_and_add_spares(struct mddev *mddev,
76 struct md_rdev *this); 74 struct md_rdev *this);
77 75
78#define MD_BUG(x...) { printk("md: bug in file %s, line %d\n", __FILE__, __LINE__); md_print_devices(); }
79
80/* 76/*
81 * Default number of read corrections we'll attempt on an rdev 77 * Default number of read corrections we'll attempt on an rdev
82 * before ejecting it from the array. We divide the read error 78 * before ejecting it from the array. We divide the read error
@@ -218,7 +214,6 @@ static void md_new_event_inintr(struct mddev *mddev)
218static LIST_HEAD(all_mddevs); 214static LIST_HEAD(all_mddevs);
219static DEFINE_SPINLOCK(all_mddevs_lock); 215static DEFINE_SPINLOCK(all_mddevs_lock);
220 216
221
222/* 217/*
223 * iterates through all used mddevs in the system. 218 * iterates through all used mddevs in the system.
224 * We take care to grab the all_mddevs_lock whenever navigating 219 * We take care to grab the all_mddevs_lock whenever navigating
@@ -228,7 +223,7 @@ static DEFINE_SPINLOCK(all_mddevs_lock);
228 */ 223 */
229#define for_each_mddev(_mddev,_tmp) \ 224#define for_each_mddev(_mddev,_tmp) \
230 \ 225 \
231 for (({ spin_lock(&all_mddevs_lock); \ 226 for (({ spin_lock(&all_mddevs_lock); \
232 _tmp = all_mddevs.next; \ 227 _tmp = all_mddevs.next; \
233 _mddev = NULL;}); \ 228 _mddev = NULL;}); \
234 ({ if (_tmp != &all_mddevs) \ 229 ({ if (_tmp != &all_mddevs) \
@@ -241,7 +236,6 @@ static DEFINE_SPINLOCK(all_mddevs_lock);
241 _tmp = _tmp->next;}) \ 236 _tmp = _tmp->next;}) \
242 ) 237 )
243 238
244
245/* Rather than calling directly into the personality make_request function, 239/* Rather than calling directly into the personality make_request function,
246 * IO requests come here first so that we can check if the device is 240 * IO requests come here first so that we can check if the device is
247 * being suspended pending a reconfiguration. 241 * being suspended pending a reconfiguration.
@@ -488,7 +482,7 @@ void mddev_init(struct mddev *mddev)
488} 482}
489EXPORT_SYMBOL_GPL(mddev_init); 483EXPORT_SYMBOL_GPL(mddev_init);
490 484
491static struct mddev * mddev_find(dev_t unit) 485static struct mddev *mddev_find(dev_t unit)
492{ 486{
493 struct mddev *mddev, *new = NULL; 487 struct mddev *mddev, *new = NULL;
494 488
@@ -530,7 +524,7 @@ static struct mddev * mddev_find(dev_t unit)
530 kfree(new); 524 kfree(new);
531 return NULL; 525 return NULL;
532 } 526 }
533 527
534 is_free = 1; 528 is_free = 1;
535 list_for_each_entry(mddev, &all_mddevs, all_mddevs) 529 list_for_each_entry(mddev, &all_mddevs, all_mddevs)
536 if (mddev->unit == dev) { 530 if (mddev->unit == dev) {
@@ -562,7 +556,7 @@ static struct mddev * mddev_find(dev_t unit)
562 goto retry; 556 goto retry;
563} 557}
564 558
565static inline int __must_check mddev_lock(struct mddev * mddev) 559static inline int __must_check mddev_lock(struct mddev *mddev)
566{ 560{
567 return mutex_lock_interruptible(&mddev->reconfig_mutex); 561 return mutex_lock_interruptible(&mddev->reconfig_mutex);
568} 562}
@@ -570,7 +564,7 @@ static inline int __must_check mddev_lock(struct mddev * mddev)
570/* Sometimes we need to take the lock in a situation where 564/* Sometimes we need to take the lock in a situation where
571 * failure due to interrupts is not acceptable. 565 * failure due to interrupts is not acceptable.
572 */ 566 */
573static inline void mddev_lock_nointr(struct mddev * mddev) 567static inline void mddev_lock_nointr(struct mddev *mddev)
574{ 568{
575 mutex_lock(&mddev->reconfig_mutex); 569 mutex_lock(&mddev->reconfig_mutex);
576} 570}
@@ -580,14 +574,14 @@ static inline int mddev_is_locked(struct mddev *mddev)
580 return mutex_is_locked(&mddev->reconfig_mutex); 574 return mutex_is_locked(&mddev->reconfig_mutex);
581} 575}
582 576
583static inline int mddev_trylock(struct mddev * mddev) 577static inline int mddev_trylock(struct mddev *mddev)
584{ 578{
585 return mutex_trylock(&mddev->reconfig_mutex); 579 return mutex_trylock(&mddev->reconfig_mutex);
586} 580}
587 581
588static struct attribute_group md_redundancy_group; 582static struct attribute_group md_redundancy_group;
589 583
590static void mddev_unlock(struct mddev * mddev) 584static void mddev_unlock(struct mddev *mddev)
591{ 585{
592 if (mddev->to_remove) { 586 if (mddev->to_remove) {
593 /* These cannot be removed under reconfig_mutex as 587 /* These cannot be removed under reconfig_mutex as
@@ -630,17 +624,6 @@ static void mddev_unlock(struct mddev * mddev)
630 spin_unlock(&pers_lock); 624 spin_unlock(&pers_lock);
631} 625}
632 626
633static struct md_rdev * find_rdev_nr(struct mddev *mddev, int nr)
634{
635 struct md_rdev *rdev;
636
637 rdev_for_each(rdev, mddev)
638 if (rdev->desc_nr == nr)
639 return rdev;
640
641 return NULL;
642}
643
644static struct md_rdev *find_rdev_nr_rcu(struct mddev *mddev, int nr) 627static struct md_rdev *find_rdev_nr_rcu(struct mddev *mddev, int nr)
645{ 628{
646 struct md_rdev *rdev; 629 struct md_rdev *rdev;
@@ -693,11 +676,8 @@ static inline sector_t calc_dev_sboffset(struct md_rdev *rdev)
693 return MD_NEW_SIZE_SECTORS(num_sectors); 676 return MD_NEW_SIZE_SECTORS(num_sectors);
694} 677}
695 678
696static int alloc_disk_sb(struct md_rdev * rdev) 679static int alloc_disk_sb(struct md_rdev *rdev)
697{ 680{
698 if (rdev->sb_page)
699 MD_BUG();
700
701 rdev->sb_page = alloc_page(GFP_KERNEL); 681 rdev->sb_page = alloc_page(GFP_KERNEL);
702 if (!rdev->sb_page) { 682 if (!rdev->sb_page) {
703 printk(KERN_ALERT "md: out of memory.\n"); 683 printk(KERN_ALERT "md: out of memory.\n");
@@ -766,14 +746,7 @@ void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
766void md_super_wait(struct mddev *mddev) 746void md_super_wait(struct mddev *mddev)
767{ 747{
768 /* wait for all superblock writes that were scheduled to complete */ 748 /* wait for all superblock writes that were scheduled to complete */
769 DEFINE_WAIT(wq); 749 wait_event(mddev->sb_wait, atomic_read(&mddev->pending_writes)==0);
770 for(;;) {
771 prepare_to_wait(&mddev->sb_wait, &wq, TASK_UNINTERRUPTIBLE);
772 if (atomic_read(&mddev->pending_writes)==0)
773 break;
774 schedule();
775 }
776 finish_wait(&mddev->sb_wait, &wq);
777} 750}
778 751
779int sync_page_io(struct md_rdev *rdev, sector_t sector, int size, 752int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
@@ -801,17 +774,13 @@ int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
801} 774}
802EXPORT_SYMBOL_GPL(sync_page_io); 775EXPORT_SYMBOL_GPL(sync_page_io);
803 776
804static int read_disk_sb(struct md_rdev * rdev, int size) 777static int read_disk_sb(struct md_rdev *rdev, int size)
805{ 778{
806 char b[BDEVNAME_SIZE]; 779 char b[BDEVNAME_SIZE];
807 if (!rdev->sb_page) { 780
808 MD_BUG();
809 return -EINVAL;
810 }
811 if (rdev->sb_loaded) 781 if (rdev->sb_loaded)
812 return 0; 782 return 0;
813 783
814
815 if (!sync_page_io(rdev, 0, size, rdev->sb_page, READ, true)) 784 if (!sync_page_io(rdev, 0, size, rdev->sb_page, READ, true))
816 goto fail; 785 goto fail;
817 rdev->sb_loaded = 1; 786 rdev->sb_loaded = 1;
@@ -825,7 +794,7 @@ fail:
825 794
826static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2) 795static int uuid_equal(mdp_super_t *sb1, mdp_super_t *sb2)
827{ 796{
828 return sb1->set_uuid0 == sb2->set_uuid0 && 797 return sb1->set_uuid0 == sb2->set_uuid0 &&
829 sb1->set_uuid1 == sb2->set_uuid1 && 798 sb1->set_uuid1 == sb2->set_uuid1 &&
830 sb1->set_uuid2 == sb2->set_uuid2 && 799 sb1->set_uuid2 == sb2->set_uuid2 &&
831 sb1->set_uuid3 == sb2->set_uuid3; 800 sb1->set_uuid3 == sb2->set_uuid3;
@@ -861,14 +830,13 @@ abort:
861 return ret; 830 return ret;
862} 831}
863 832
864
865static u32 md_csum_fold(u32 csum) 833static u32 md_csum_fold(u32 csum)
866{ 834{
867 csum = (csum & 0xffff) + (csum >> 16); 835 csum = (csum & 0xffff) + (csum >> 16);
868 return (csum & 0xffff) + (csum >> 16); 836 return (csum & 0xffff) + (csum >> 16);
869} 837}
870 838
871static unsigned int calc_sb_csum(mdp_super_t * sb) 839static unsigned int calc_sb_csum(mdp_super_t *sb)
872{ 840{
873 u64 newcsum = 0; 841 u64 newcsum = 0;
874 u32 *sb32 = (u32*)sb; 842 u32 *sb32 = (u32*)sb;
@@ -882,7 +850,6 @@ static unsigned int calc_sb_csum(mdp_super_t * sb)
882 newcsum += sb32[i]; 850 newcsum += sb32[i];
883 csum = (newcsum & 0xffffffff) + (newcsum>>32); 851 csum = (newcsum & 0xffffffff) + (newcsum>>32);
884 852
885
886#ifdef CONFIG_ALPHA 853#ifdef CONFIG_ALPHA
887 /* This used to use csum_partial, which was wrong for several 854 /* This used to use csum_partial, which was wrong for several
888 * reasons including that different results are returned on 855 * reasons including that different results are returned on
@@ -899,7 +866,6 @@ static unsigned int calc_sb_csum(mdp_super_t * sb)
899 return csum; 866 return csum;
900} 867}
901 868
902
903/* 869/*
904 * Handle superblock details. 870 * Handle superblock details.
905 * We want to be able to handle multiple superblock formats 871 * We want to be able to handle multiple superblock formats
@@ -965,7 +931,7 @@ int md_check_no_bitmap(struct mddev *mddev)
965EXPORT_SYMBOL(md_check_no_bitmap); 931EXPORT_SYMBOL(md_check_no_bitmap);
966 932
967/* 933/*
968 * load_super for 0.90.0 934 * load_super for 0.90.0
969 */ 935 */
970static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_version) 936static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_version)
971{ 937{
@@ -1044,7 +1010,7 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
1044 ev2 = md_event(refsb); 1010 ev2 = md_event(refsb);
1045 if (ev1 > ev2) 1011 if (ev1 > ev2)
1046 ret = 1; 1012 ret = 1;
1047 else 1013 else
1048 ret = 0; 1014 ret = 0;
1049 } 1015 }
1050 rdev->sectors = rdev->sb_start; 1016 rdev->sectors = rdev->sb_start;
@@ -1118,7 +1084,7 @@ static int super_90_validate(struct mddev *mddev, struct md_rdev *rdev)
1118 if (sb->state & (1<<MD_SB_CLEAN)) 1084 if (sb->state & (1<<MD_SB_CLEAN))
1119 mddev->recovery_cp = MaxSector; 1085 mddev->recovery_cp = MaxSector;
1120 else { 1086 else {
1121 if (sb->events_hi == sb->cp_events_hi && 1087 if (sb->events_hi == sb->cp_events_hi &&
1122 sb->events_lo == sb->cp_events_lo) { 1088 sb->events_lo == sb->cp_events_lo) {
1123 mddev->recovery_cp = sb->recovery_cp; 1089 mddev->recovery_cp = sb->recovery_cp;
1124 } else 1090 } else
@@ -1146,7 +1112,7 @@ static int super_90_validate(struct mddev *mddev, struct md_rdev *rdev)
1146 ++ev1; 1112 ++ev1;
1147 if (sb->disks[rdev->desc_nr].state & ( 1113 if (sb->disks[rdev->desc_nr].state & (
1148 (1<<MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE))) 1114 (1<<MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE)))
1149 if (ev1 < mddev->events) 1115 if (ev1 < mddev->events)
1150 return -EINVAL; 1116 return -EINVAL;
1151 } else if (mddev->bitmap) { 1117 } else if (mddev->bitmap) {
1152 /* if adding to array with a bitmap, then we can accept an 1118 /* if adding to array with a bitmap, then we can accept an
@@ -1197,7 +1163,6 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
1197 struct md_rdev *rdev2; 1163 struct md_rdev *rdev2;
1198 int next_spare = mddev->raid_disks; 1164 int next_spare = mddev->raid_disks;
1199 1165
1200
1201 /* make rdev->sb match mddev data.. 1166 /* make rdev->sb match mddev data..
1202 * 1167 *
1203 * 1/ zero out disks 1168 * 1/ zero out disks
@@ -1366,7 +1331,7 @@ super_90_allow_new_offset(struct md_rdev *rdev, unsigned long long new_offset)
1366 * version 1 superblock 1331 * version 1 superblock
1367 */ 1332 */
1368 1333
1369static __le32 calc_sb_1_csum(struct mdp_superblock_1 * sb) 1334static __le32 calc_sb_1_csum(struct mdp_superblock_1 *sb)
1370{ 1335{
1371 __le32 disk_csum; 1336 __le32 disk_csum;
1372 u32 csum; 1337 u32 csum;
@@ -1430,7 +1395,6 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
1430 ret = read_disk_sb(rdev, 4096); 1395 ret = read_disk_sb(rdev, 4096);
1431 if (ret) return ret; 1396 if (ret) return ret;
1432 1397
1433
1434 sb = page_address(rdev->sb_page); 1398 sb = page_address(rdev->sb_page);
1435 1399
1436 if (sb->magic != cpu_to_le32(MD_SB_MAGIC) || 1400 if (sb->magic != cpu_to_le32(MD_SB_MAGIC) ||
@@ -1817,7 +1781,7 @@ retry:
1817 1781
1818 for (i=0; i<max_dev;i++) 1782 for (i=0; i<max_dev;i++)
1819 sb->dev_roles[i] = cpu_to_le16(0xfffe); 1783 sb->dev_roles[i] = cpu_to_le16(0xfffe);
1820 1784
1821 rdev_for_each(rdev2, mddev) { 1785 rdev_for_each(rdev2, mddev) {
1822 i = rdev2->desc_nr; 1786 i = rdev2->desc_nr;
1823 if (test_bit(Faulty, &rdev2->flags)) 1787 if (test_bit(Faulty, &rdev2->flags))
@@ -2033,18 +1997,13 @@ void md_integrity_add_rdev(struct md_rdev *rdev, struct mddev *mddev)
2033} 1997}
2034EXPORT_SYMBOL(md_integrity_add_rdev); 1998EXPORT_SYMBOL(md_integrity_add_rdev);
2035 1999
2036static int bind_rdev_to_array(struct md_rdev * rdev, struct mddev * mddev) 2000static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
2037{ 2001{
2038 char b[BDEVNAME_SIZE]; 2002 char b[BDEVNAME_SIZE];
2039 struct kobject *ko; 2003 struct kobject *ko;
2040 char *s; 2004 char *s;
2041 int err; 2005 int err;
2042 2006
2043 if (rdev->mddev) {
2044 MD_BUG();
2045 return -EINVAL;
2046 }
2047
2048 /* prevent duplicates */ 2007 /* prevent duplicates */
2049 if (find_rdev(mddev, rdev->bdev->bd_dev)) 2008 if (find_rdev(mddev, rdev->bdev->bd_dev))
2050 return -EEXIST; 2009 return -EEXIST;
@@ -2067,16 +2026,21 @@ static int bind_rdev_to_array(struct md_rdev * rdev, struct mddev * mddev)
2067 * If it is -1, assign a free number, else 2026 * If it is -1, assign a free number, else
2068 * check number is not in use 2027 * check number is not in use
2069 */ 2028 */
2029 rcu_read_lock();
2070 if (rdev->desc_nr < 0) { 2030 if (rdev->desc_nr < 0) {
2071 int choice = 0; 2031 int choice = 0;
2072 if (mddev->pers) choice = mddev->raid_disks; 2032 if (mddev->pers)
2073 while (find_rdev_nr(mddev, choice)) 2033 choice = mddev->raid_disks;
2034 while (find_rdev_nr_rcu(mddev, choice))
2074 choice++; 2035 choice++;
2075 rdev->desc_nr = choice; 2036 rdev->desc_nr = choice;
2076 } else { 2037 } else {
2077 if (find_rdev_nr(mddev, rdev->desc_nr)) 2038 if (find_rdev_nr_rcu(mddev, rdev->desc_nr)) {
2039 rcu_read_unlock();
2078 return -EBUSY; 2040 return -EBUSY;
2041 }
2079 } 2042 }
2043 rcu_read_unlock();
2080 if (mddev->max_disks && rdev->desc_nr >= mddev->max_disks) { 2044 if (mddev->max_disks && rdev->desc_nr >= mddev->max_disks) {
2081 printk(KERN_WARNING "md: %s: array is limited to %d devices\n", 2045 printk(KERN_WARNING "md: %s: array is limited to %d devices\n",
2082 mdname(mddev), mddev->max_disks); 2046 mdname(mddev), mddev->max_disks);
@@ -2118,13 +2082,10 @@ static void md_delayed_delete(struct work_struct *ws)
2118 kobject_put(&rdev->kobj); 2082 kobject_put(&rdev->kobj);
2119} 2083}
2120 2084
2121static void unbind_rdev_from_array(struct md_rdev * rdev) 2085static void unbind_rdev_from_array(struct md_rdev *rdev)
2122{ 2086{
2123 char b[BDEVNAME_SIZE]; 2087 char b[BDEVNAME_SIZE];
2124 if (!rdev->mddev) { 2088
2125 MD_BUG();
2126 return;
2127 }
2128 bd_unlink_disk_holder(rdev->bdev, rdev->mddev->gendisk); 2089 bd_unlink_disk_holder(rdev->bdev, rdev->mddev->gendisk);
2129 list_del_rcu(&rdev->same_set); 2090 list_del_rcu(&rdev->same_set);
2130 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); 2091 printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b));
@@ -2169,20 +2130,17 @@ static void unlock_rdev(struct md_rdev *rdev)
2169{ 2130{
2170 struct block_device *bdev = rdev->bdev; 2131 struct block_device *bdev = rdev->bdev;
2171 rdev->bdev = NULL; 2132 rdev->bdev = NULL;
2172 if (!bdev)
2173 MD_BUG();
2174 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); 2133 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
2175} 2134}
2176 2135
2177void md_autodetect_dev(dev_t dev); 2136void md_autodetect_dev(dev_t dev);
2178 2137
2179static void export_rdev(struct md_rdev * rdev) 2138static void export_rdev(struct md_rdev *rdev)
2180{ 2139{
2181 char b[BDEVNAME_SIZE]; 2140 char b[BDEVNAME_SIZE];
2141
2182 printk(KERN_INFO "md: export_rdev(%s)\n", 2142 printk(KERN_INFO "md: export_rdev(%s)\n",
2183 bdevname(rdev->bdev,b)); 2143 bdevname(rdev->bdev,b));
2184 if (rdev->mddev)
2185 MD_BUG();
2186 md_rdev_clear(rdev); 2144 md_rdev_clear(rdev);
2187#ifndef MODULE 2145#ifndef MODULE
2188 if (test_bit(AutoDetected, &rdev->flags)) 2146 if (test_bit(AutoDetected, &rdev->flags))
@@ -2192,7 +2150,7 @@ static void export_rdev(struct md_rdev * rdev)
2192 kobject_put(&rdev->kobj); 2150 kobject_put(&rdev->kobj);
2193} 2151}
2194 2152
2195static void kick_rdev_from_array(struct md_rdev * rdev) 2153static void kick_rdev_from_array(struct md_rdev *rdev)
2196{ 2154{
2197 unbind_rdev_from_array(rdev); 2155 unbind_rdev_from_array(rdev);
2198 export_rdev(rdev); 2156 export_rdev(rdev);
@@ -2200,153 +2158,18 @@ static void kick_rdev_from_array(struct md_rdev * rdev)
2200 2158
2201static void export_array(struct mddev *mddev) 2159static void export_array(struct mddev *mddev)
2202{ 2160{
2203 struct md_rdev *rdev, *tmp; 2161 struct md_rdev *rdev;
2204 2162
2205 rdev_for_each_safe(rdev, tmp, mddev) { 2163 while (!list_empty(&mddev->disks)) {
2206 if (!rdev->mddev) { 2164 rdev = list_first_entry(&mddev->disks, struct md_rdev,
2207 MD_BUG(); 2165 same_set);
2208 continue;
2209 }
2210 kick_rdev_from_array(rdev); 2166 kick_rdev_from_array(rdev);
2211 } 2167 }
2212 if (!list_empty(&mddev->disks))
2213 MD_BUG();
2214 mddev->raid_disks = 0; 2168 mddev->raid_disks = 0;
2215 mddev->major_version = 0; 2169 mddev->major_version = 0;
2216} 2170}
2217 2171
2218static void print_desc(mdp_disk_t *desc) 2172static void sync_sbs(struct mddev *mddev, int nospares)
2219{
2220 printk(" DISK<N:%d,(%d,%d),R:%d,S:%d>\n", desc->number,
2221 desc->major,desc->minor,desc->raid_disk,desc->state);
2222}
2223
2224static void print_sb_90(mdp_super_t *sb)
2225{
2226 int i;
2227
2228 printk(KERN_INFO
2229 "md: SB: (V:%d.%d.%d) ID:<%08x.%08x.%08x.%08x> CT:%08x\n",
2230 sb->major_version, sb->minor_version, sb->patch_version,
2231 sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3,
2232 sb->ctime);
2233 printk(KERN_INFO "md: L%d S%08d ND:%d RD:%d md%d LO:%d CS:%d\n",
2234 sb->level, sb->size, sb->nr_disks, sb->raid_disks,
2235 sb->md_minor, sb->layout, sb->chunk_size);
2236 printk(KERN_INFO "md: UT:%08x ST:%d AD:%d WD:%d"
2237 " FD:%d SD:%d CSUM:%08x E:%08lx\n",
2238 sb->utime, sb->state, sb->active_disks, sb->working_disks,
2239 sb->failed_disks, sb->spare_disks,
2240 sb->sb_csum, (unsigned long)sb->events_lo);
2241
2242 printk(KERN_INFO);
2243 for (i = 0; i < MD_SB_DISKS; i++) {
2244 mdp_disk_t *desc;
2245
2246 desc = sb->disks + i;
2247 if (desc->number || desc->major || desc->minor ||
2248 desc->raid_disk || (desc->state && (desc->state != 4))) {
2249 printk(" D %2d: ", i);
2250 print_desc(desc);
2251 }
2252 }
2253 printk(KERN_INFO "md: THIS: ");
2254 print_desc(&sb->this_disk);
2255}
2256
2257static void print_sb_1(struct mdp_superblock_1 *sb)
2258{
2259 __u8 *uuid;
2260
2261 uuid = sb->set_uuid;
2262 printk(KERN_INFO
2263 "md: SB: (V:%u) (F:0x%08x) Array-ID:<%pU>\n"
2264 "md: Name: \"%s\" CT:%llu\n",
2265 le32_to_cpu(sb->major_version),
2266 le32_to_cpu(sb->feature_map),
2267 uuid,
2268 sb->set_name,
2269 (unsigned long long)le64_to_cpu(sb->ctime)
2270 & MD_SUPERBLOCK_1_TIME_SEC_MASK);
2271
2272 uuid = sb->device_uuid;
2273 printk(KERN_INFO
2274 "md: L%u SZ%llu RD:%u LO:%u CS:%u DO:%llu DS:%llu SO:%llu"
2275 " RO:%llu\n"
2276 "md: Dev:%08x UUID: %pU\n"
2277 "md: (F:0x%08x) UT:%llu Events:%llu ResyncOffset:%llu CSUM:0x%08x\n"
2278 "md: (MaxDev:%u) \n",
2279 le32_to_cpu(sb->level),
2280 (unsigned long long)le64_to_cpu(sb->size),
2281 le32_to_cpu(sb->raid_disks),
2282 le32_to_cpu(sb->layout),
2283 le32_to_cpu(sb->chunksize),
2284 (unsigned long long)le64_to_cpu(sb->data_offset),
2285 (unsigned long long)le64_to_cpu(sb->data_size),
2286 (unsigned long long)le64_to_cpu(sb->super_offset),
2287 (unsigned long long)le64_to_cpu(sb->recovery_offset),
2288 le32_to_cpu(sb->dev_number),
2289 uuid,
2290 sb->devflags,
2291 (unsigned long long)le64_to_cpu(sb->utime) & MD_SUPERBLOCK_1_TIME_SEC_MASK,
2292 (unsigned long long)le64_to_cpu(sb->events),
2293 (unsigned long long)le64_to_cpu(sb->resync_offset),
2294 le32_to_cpu(sb->sb_csum),
2295 le32_to_cpu(sb->max_dev)
2296 );
2297}
2298
2299static void print_rdev(struct md_rdev *rdev, int major_version)
2300{
2301 char b[BDEVNAME_SIZE];
2302 printk(KERN_INFO "md: rdev %s, Sect:%08llu F:%d S:%d DN:%u\n",
2303 bdevname(rdev->bdev, b), (unsigned long long)rdev->sectors,
2304 test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags),
2305 rdev->desc_nr);
2306 if (rdev->sb_loaded) {
2307 printk(KERN_INFO "md: rdev superblock (MJ:%d):\n", major_version);
2308 switch (major_version) {
2309 case 0:
2310 print_sb_90(page_address(rdev->sb_page));
2311 break;
2312 case 1:
2313 print_sb_1(page_address(rdev->sb_page));
2314 break;
2315 }
2316 } else
2317 printk(KERN_INFO "md: no rdev superblock!\n");
2318}
2319
2320static void md_print_devices(void)
2321{
2322 struct list_head *tmp;
2323 struct md_rdev *rdev;
2324 struct mddev *mddev;
2325 char b[BDEVNAME_SIZE];
2326
2327 printk("\n");
2328 printk("md: **********************************\n");
2329 printk("md: * <COMPLETE RAID STATE PRINTOUT> *\n");
2330 printk("md: **********************************\n");
2331 for_each_mddev(mddev, tmp) {
2332
2333 if (mddev->bitmap)
2334 bitmap_print_sb(mddev->bitmap);
2335 else
2336 printk("%s: ", mdname(mddev));
2337 rdev_for_each(rdev, mddev)
2338 printk("<%s>", bdevname(rdev->bdev,b));
2339 printk("\n");
2340
2341 rdev_for_each(rdev, mddev)
2342 print_rdev(rdev, mddev->major_version);
2343 }
2344 printk("md: **********************************\n");
2345 printk("\n");
2346}
2347
2348
2349static void sync_sbs(struct mddev * mddev, int nospares)
2350{ 2173{
2351 /* Update each superblock (in-memory image), but 2174 /* Update each superblock (in-memory image), but
2352 * if we are allowed to, skip spares which already 2175 * if we are allowed to, skip spares which already
@@ -2369,7 +2192,7 @@ static void sync_sbs(struct mddev * mddev, int nospares)
2369 } 2192 }
2370} 2193}
2371 2194
2372static void md_update_sb(struct mddev * mddev, int force_change) 2195static void md_update_sb(struct mddev *mddev, int force_change)
2373{ 2196{
2374 struct md_rdev *rdev; 2197 struct md_rdev *rdev;
2375 int sync_req; 2198 int sync_req;
@@ -2390,7 +2213,7 @@ repeat:
2390 mddev->curr_resync_completed > rdev->recovery_offset) 2213 mddev->curr_resync_completed > rdev->recovery_offset)
2391 rdev->recovery_offset = mddev->curr_resync_completed; 2214 rdev->recovery_offset = mddev->curr_resync_completed;
2392 2215
2393 } 2216 }
2394 if (!mddev->persistent) { 2217 if (!mddev->persistent) {
2395 clear_bit(MD_CHANGE_CLEAN, &mddev->flags); 2218 clear_bit(MD_CHANGE_CLEAN, &mddev->flags);
2396 clear_bit(MD_CHANGE_DEVS, &mddev->flags); 2219 clear_bit(MD_CHANGE_DEVS, &mddev->flags);
@@ -2453,15 +2276,12 @@ repeat:
2453 mddev->can_decrease_events = nospares; 2276 mddev->can_decrease_events = nospares;
2454 } 2277 }
2455 2278
2456 if (!mddev->events) { 2279 /*
2457 /* 2280 * This 64-bit counter should never wrap.
2458 * oops, this 64-bit counter should never wrap. 2281 * Either we are in around ~1 trillion A.C., assuming
2459 * Either we are in around ~1 trillion A.C., assuming 2282 * 1 reboot per second, or we have a bug...
2460 * 1 reboot per second, or we have a bug: 2283 */
2461 */ 2284 WARN_ON(mddev->events == 0);
2462 MD_BUG();
2463 mddev->events --;
2464 }
2465 2285
2466 rdev_for_each(rdev, mddev) { 2286 rdev_for_each(rdev, mddev) {
2467 if (rdev->badblocks.changed) 2287 if (rdev->badblocks.changed)
@@ -2668,10 +2488,12 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
2668 set_bit(In_sync, &rdev->flags); 2488 set_bit(In_sync, &rdev->flags);
2669 err = 0; 2489 err = 0;
2670 } else if (cmd_match(buf, "-insync") && rdev->raid_disk >= 0) { 2490 } else if (cmd_match(buf, "-insync") && rdev->raid_disk >= 0) {
2671 clear_bit(In_sync, &rdev->flags); 2491 if (rdev->mddev->pers == NULL) {
2672 rdev->saved_raid_disk = rdev->raid_disk; 2492 clear_bit(In_sync, &rdev->flags);
2673 rdev->raid_disk = -1; 2493 rdev->saved_raid_disk = rdev->raid_disk;
2674 err = 0; 2494 rdev->raid_disk = -1;
2495 err = 0;
2496 }
2675 } else if (cmd_match(buf, "write_error")) { 2497 } else if (cmd_match(buf, "write_error")) {
2676 set_bit(WriteErrorSeen, &rdev->flags); 2498 set_bit(WriteErrorSeen, &rdev->flags);
2677 err = 0; 2499 err = 0;
@@ -2829,7 +2651,6 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len)
2829 return len; 2651 return len;
2830} 2652}
2831 2653
2832
2833static struct rdev_sysfs_entry rdev_slot = 2654static struct rdev_sysfs_entry rdev_slot =
2834__ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store); 2655__ATTR(slot, S_IRUGO|S_IWUSR, slot_show, slot_store);
2835 2656
@@ -2980,20 +2801,20 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
2980 2801
2981 rdev->sectors = sectors; 2802 rdev->sectors = sectors;
2982 if (sectors > oldsectors && my_mddev->external) { 2803 if (sectors > oldsectors && my_mddev->external) {
2983 /* need to check that all other rdevs with the same ->bdev 2804 /* Need to check that all other rdevs with the same
2984 * do not overlap. We need to unlock the mddev to avoid 2805 * ->bdev do not overlap. 'rcu' is sufficient to walk
2985 * a deadlock. We have already changed rdev->sectors, and if 2806 * the rdev lists safely.
2986 * we have to change it back, we will have the lock again. 2807 * This check does not provide a hard guarantee, it
2808 * just helps avoid dangerous mistakes.
2987 */ 2809 */
2988 struct mddev *mddev; 2810 struct mddev *mddev;
2989 int overlap = 0; 2811 int overlap = 0;
2990 struct list_head *tmp; 2812 struct list_head *tmp;
2991 2813
2992 mddev_unlock(my_mddev); 2814 rcu_read_lock();
2993 for_each_mddev(mddev, tmp) { 2815 for_each_mddev(mddev, tmp) {
2994 struct md_rdev *rdev2; 2816 struct md_rdev *rdev2;
2995 2817
2996 mddev_lock_nointr(mddev);
2997 rdev_for_each(rdev2, mddev) 2818 rdev_for_each(rdev2, mddev)
2998 if (rdev->bdev == rdev2->bdev && 2819 if (rdev->bdev == rdev2->bdev &&
2999 rdev != rdev2 && 2820 rdev != rdev2 &&
@@ -3003,13 +2824,12 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
3003 overlap = 1; 2824 overlap = 1;
3004 break; 2825 break;
3005 } 2826 }
3006 mddev_unlock(mddev);
3007 if (overlap) { 2827 if (overlap) {
3008 mddev_put(mddev); 2828 mddev_put(mddev);
3009 break; 2829 break;
3010 } 2830 }
3011 } 2831 }
3012 mddev_lock_nointr(my_mddev); 2832 rcu_read_unlock();
3013 if (overlap) { 2833 if (overlap) {
3014 /* Someone else could have slipped in a size 2834 /* Someone else could have slipped in a size
3015 * change here, but doing so is just silly. 2835 * change here, but doing so is just silly.
@@ -3027,7 +2847,6 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
3027static struct rdev_sysfs_entry rdev_size = 2847static struct rdev_sysfs_entry rdev_size =
3028__ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store); 2848__ATTR(size, S_IRUGO|S_IWUSR, rdev_size_show, rdev_size_store);
3029 2849
3030
3031static ssize_t recovery_start_show(struct md_rdev *rdev, char *page) 2850static ssize_t recovery_start_show(struct md_rdev *rdev, char *page)
3032{ 2851{
3033 unsigned long long recovery_start = rdev->recovery_offset; 2852 unsigned long long recovery_start = rdev->recovery_offset;
@@ -3063,7 +2882,6 @@ static ssize_t recovery_start_store(struct md_rdev *rdev, const char *buf, size_
3063static struct rdev_sysfs_entry rdev_recovery_start = 2882static struct rdev_sysfs_entry rdev_recovery_start =
3064__ATTR(recovery_start, S_IRUGO|S_IWUSR, recovery_start_show, recovery_start_store); 2883__ATTR(recovery_start, S_IRUGO|S_IWUSR, recovery_start_show, recovery_start_store);
3065 2884
3066
3067static ssize_t 2885static ssize_t
3068badblocks_show(struct badblocks *bb, char *page, int unack); 2886badblocks_show(struct badblocks *bb, char *page, int unack);
3069static ssize_t 2887static ssize_t
@@ -3084,7 +2902,6 @@ static ssize_t bb_store(struct md_rdev *rdev, const char *page, size_t len)
3084static struct rdev_sysfs_entry rdev_bad_blocks = 2902static struct rdev_sysfs_entry rdev_bad_blocks =
3085__ATTR(bad_blocks, S_IRUGO|S_IWUSR, bb_show, bb_store); 2903__ATTR(bad_blocks, S_IRUGO|S_IWUSR, bb_show, bb_store);
3086 2904
3087
3088static ssize_t ubb_show(struct md_rdev *rdev, char *page) 2905static ssize_t ubb_show(struct md_rdev *rdev, char *page)
3089{ 2906{
3090 return badblocks_show(&rdev->badblocks, page, 1); 2907 return badblocks_show(&rdev->badblocks, page, 1);
@@ -3241,7 +3058,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
3241 3058
3242 size = i_size_read(rdev->bdev->bd_inode) >> BLOCK_SIZE_BITS; 3059 size = i_size_read(rdev->bdev->bd_inode) >> BLOCK_SIZE_BITS;
3243 if (!size) { 3060 if (!size) {
3244 printk(KERN_WARNING 3061 printk(KERN_WARNING
3245 "md: %s has zero or unknown size, marking faulty!\n", 3062 "md: %s has zero or unknown size, marking faulty!\n",
3246 bdevname(rdev->bdev,b)); 3063 bdevname(rdev->bdev,b));
3247 err = -EINVAL; 3064 err = -EINVAL;
@@ -3260,7 +3077,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
3260 goto abort_free; 3077 goto abort_free;
3261 } 3078 }
3262 if (err < 0) { 3079 if (err < 0) {
3263 printk(KERN_WARNING 3080 printk(KERN_WARNING
3264 "md: could not read %s's sb, not importing!\n", 3081 "md: could not read %s's sb, not importing!\n",
3265 bdevname(rdev->bdev,b)); 3082 bdevname(rdev->bdev,b));
3266 goto abort_free; 3083 goto abort_free;
@@ -3281,8 +3098,7 @@ abort_free:
3281 * Check a full RAID array for plausibility 3098 * Check a full RAID array for plausibility
3282 */ 3099 */
3283 3100
3284 3101static void analyze_sbs(struct mddev *mddev)
3285static void analyze_sbs(struct mddev * mddev)
3286{ 3102{
3287 int i; 3103 int i;
3288 struct md_rdev *rdev, *freshest, *tmp; 3104 struct md_rdev *rdev, *freshest, *tmp;
@@ -3300,12 +3116,11 @@ static void analyze_sbs(struct mddev * mddev)
3300 default: 3116 default:
3301 printk( KERN_ERR \ 3117 printk( KERN_ERR \
3302 "md: fatal superblock inconsistency in %s" 3118 "md: fatal superblock inconsistency in %s"
3303 " -- removing from array\n", 3119 " -- removing from array\n",
3304 bdevname(rdev->bdev,b)); 3120 bdevname(rdev->bdev,b));
3305 kick_rdev_from_array(rdev); 3121 kick_rdev_from_array(rdev);
3306 } 3122 }
3307 3123
3308
3309 super_types[mddev->major_version]. 3124 super_types[mddev->major_version].
3310 validate_super(mddev, freshest); 3125 validate_super(mddev, freshest);
3311 3126
@@ -3344,7 +3159,7 @@ static void analyze_sbs(struct mddev * mddev)
3344/* Read a fixed-point number. 3159/* Read a fixed-point number.
3345 * Numbers in sysfs attributes should be in "standard" units where 3160 * Numbers in sysfs attributes should be in "standard" units where
3346 * possible, so time should be in seconds. 3161 * possible, so time should be in seconds.
3347 * However we internally use a a much smaller unit such as 3162 * However we internally use a a much smaller unit such as
3348 * milliseconds or jiffies. 3163 * milliseconds or jiffies.
3349 * This function takes a decimal number with a possible fractional 3164 * This function takes a decimal number with a possible fractional
3350 * component, and produces an integer which is the result of 3165 * component, and produces an integer which is the result of
@@ -3381,7 +3196,6 @@ int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale)
3381 return 0; 3196 return 0;
3382} 3197}
3383 3198
3384
3385static void md_safemode_timeout(unsigned long data); 3199static void md_safemode_timeout(unsigned long data);
3386 3200
3387static ssize_t 3201static ssize_t
@@ -3524,7 +3338,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
3524 /* Looks like we have a winner */ 3338 /* Looks like we have a winner */
3525 mddev_suspend(mddev); 3339 mddev_suspend(mddev);
3526 mddev->pers->stop(mddev); 3340 mddev->pers->stop(mddev);
3527 3341
3528 if (mddev->pers->sync_request == NULL && 3342 if (mddev->pers->sync_request == NULL &&
3529 pers->sync_request != NULL) { 3343 pers->sync_request != NULL) {
3530 /* need to add the md_redundancy_group */ 3344 /* need to add the md_redundancy_group */
@@ -3533,7 +3347,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
3533 "md: cannot register extra attributes for %s\n", 3347 "md: cannot register extra attributes for %s\n",
3534 mdname(mddev)); 3348 mdname(mddev));
3535 mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, "sync_action"); 3349 mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, "sync_action");
3536 } 3350 }
3537 if (mddev->pers->sync_request != NULL && 3351 if (mddev->pers->sync_request != NULL &&
3538 pers->sync_request == NULL) { 3352 pers->sync_request == NULL) {
3539 /* need to remove the md_redundancy_group */ 3353 /* need to remove the md_redundancy_group */
@@ -3611,7 +3425,6 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
3611static struct md_sysfs_entry md_level = 3425static struct md_sysfs_entry md_level =
3612__ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store); 3426__ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store);
3613 3427
3614
3615static ssize_t 3428static ssize_t
3616layout_show(struct mddev *mddev, char *page) 3429layout_show(struct mddev *mddev, char *page)
3617{ 3430{
@@ -3654,7 +3467,6 @@ layout_store(struct mddev *mddev, const char *buf, size_t len)
3654static struct md_sysfs_entry md_layout = 3467static struct md_sysfs_entry md_layout =
3655__ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store); 3468__ATTR(layout, S_IRUGO|S_IWUSR, layout_show, layout_store);
3656 3469
3657
3658static ssize_t 3470static ssize_t
3659raid_disks_show(struct mddev *mddev, char *page) 3471raid_disks_show(struct mddev *mddev, char *page)
3660{ 3472{
@@ -3859,9 +3671,9 @@ array_state_show(struct mddev *mddev, char *page)
3859 return sprintf(page, "%s\n", array_states[st]); 3671 return sprintf(page, "%s\n", array_states[st]);
3860} 3672}
3861 3673
3862static int do_md_stop(struct mddev * mddev, int ro, struct block_device *bdev); 3674static int do_md_stop(struct mddev *mddev, int ro, struct block_device *bdev);
3863static int md_set_readonly(struct mddev * mddev, struct block_device *bdev); 3675static int md_set_readonly(struct mddev *mddev, struct block_device *bdev);
3864static int do_md_run(struct mddev * mddev); 3676static int do_md_run(struct mddev *mddev);
3865static int restart_array(struct mddev *mddev); 3677static int restart_array(struct mddev *mddev);
3866 3678
3867static ssize_t 3679static ssize_t
@@ -4012,7 +3824,6 @@ new_dev_store(struct mddev *mddev, const char *buf, size_t len)
4012 minor != MINOR(dev)) 3824 minor != MINOR(dev))
4013 return -EOVERFLOW; 3825 return -EOVERFLOW;
4014 3826
4015
4016 if (mddev->persistent) { 3827 if (mddev->persistent) {
4017 rdev = md_import_device(dev, mddev->major_version, 3828 rdev = md_import_device(dev, mddev->major_version,
4018 mddev->minor_version); 3829 mddev->minor_version);
@@ -4108,7 +3919,6 @@ size_store(struct mddev *mddev, const char *buf, size_t len)
4108static struct md_sysfs_entry md_size = 3919static struct md_sysfs_entry md_size =
4109__ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store); 3920__ATTR(component_size, S_IRUGO|S_IWUSR, size_show, size_store);
4110 3921
4111
4112/* Metadata version. 3922/* Metadata version.
4113 * This is one of 3923 * This is one of
4114 * 'none' for arrays with no metadata (good luck...) 3924 * 'none' for arrays with no metadata (good luck...)
@@ -4490,7 +4300,7 @@ suspend_lo_store(struct mddev *mddev, const char *buf, size_t len)
4490 unsigned long long new = simple_strtoull(buf, &e, 10); 4300 unsigned long long new = simple_strtoull(buf, &e, 10);
4491 unsigned long long old = mddev->suspend_lo; 4301 unsigned long long old = mddev->suspend_lo;
4492 4302
4493 if (mddev->pers == NULL || 4303 if (mddev->pers == NULL ||
4494 mddev->pers->quiesce == NULL) 4304 mddev->pers->quiesce == NULL)
4495 return -EINVAL; 4305 return -EINVAL;
4496 if (buf == e || (*e && *e != '\n')) 4306 if (buf == e || (*e && *e != '\n'))
@@ -4510,7 +4320,6 @@ suspend_lo_store(struct mddev *mddev, const char *buf, size_t len)
4510static struct md_sysfs_entry md_suspend_lo = 4320static struct md_sysfs_entry md_suspend_lo =
4511__ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store); 4321__ATTR(suspend_lo, S_IRUGO|S_IWUSR, suspend_lo_show, suspend_lo_store);
4512 4322
4513
4514static ssize_t 4323static ssize_t
4515suspend_hi_show(struct mddev *mddev, char *page) 4324suspend_hi_show(struct mddev *mddev, char *page)
4516{ 4325{
@@ -4698,7 +4507,6 @@ static struct attribute_group md_redundancy_group = {
4698 .attrs = md_redundancy_attrs, 4507 .attrs = md_redundancy_attrs,
4699}; 4508};
4700 4509
4701
4702static ssize_t 4510static ssize_t
4703md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) 4511md_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
4704{ 4512{
@@ -5111,7 +4919,7 @@ int md_run(struct mddev *mddev)
5111 } else if (mddev->ro == 2) /* auto-readonly not meaningful */ 4919 } else if (mddev->ro == 2) /* auto-readonly not meaningful */
5112 mddev->ro = 0; 4920 mddev->ro = 0;
5113 4921
5114 atomic_set(&mddev->writes_pending,0); 4922 atomic_set(&mddev->writes_pending,0);
5115 atomic_set(&mddev->max_corr_read_errors, 4923 atomic_set(&mddev->max_corr_read_errors,
5116 MD_DEFAULT_MAX_CORRECTED_READ_ERRORS); 4924 MD_DEFAULT_MAX_CORRECTED_READ_ERRORS);
5117 mddev->safemode = 0; 4925 mddev->safemode = 0;
@@ -5125,9 +4933,9 @@ int md_run(struct mddev *mddev)
5125 if (rdev->raid_disk >= 0) 4933 if (rdev->raid_disk >= 0)
5126 if (sysfs_link_rdev(mddev, rdev)) 4934 if (sysfs_link_rdev(mddev, rdev))
5127 /* failure here is OK */; 4935 /* failure here is OK */;
5128 4936
5129 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 4937 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5130 4938
5131 if (mddev->flags & MD_UPDATE_SB_FLAGS) 4939 if (mddev->flags & MD_UPDATE_SB_FLAGS)
5132 md_update_sb(mddev, 0); 4940 md_update_sb(mddev, 0);
5133 4941
@@ -5307,7 +5115,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
5307 mddev_lock_nointr(mddev); 5115 mddev_lock_nointr(mddev);
5308 5116
5309 mutex_lock(&mddev->open_mutex); 5117 mutex_lock(&mddev->open_mutex);
5310 if (atomic_read(&mddev->openers) > !!bdev || 5118 if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
5311 mddev->sync_thread || 5119 mddev->sync_thread ||
5312 (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) { 5120 (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
5313 printk("md: %s still in use.\n",mdname(mddev)); 5121 printk("md: %s still in use.\n",mdname(mddev));
@@ -5339,7 +5147,7 @@ out:
5339 * 0 - completely stop and dis-assemble array 5147 * 0 - completely stop and dis-assemble array
5340 * 2 - stop but do not disassemble array 5148 * 2 - stop but do not disassemble array
5341 */ 5149 */
5342static int do_md_stop(struct mddev * mddev, int mode, 5150static int do_md_stop(struct mddev *mddev, int mode,
5343 struct block_device *bdev) 5151 struct block_device *bdev)
5344{ 5152{
5345 struct gendisk *disk = mddev->gendisk; 5153 struct gendisk *disk = mddev->gendisk;
@@ -5362,7 +5170,7 @@ static int do_md_stop(struct mddev * mddev, int mode,
5362 mddev_lock_nointr(mddev); 5170 mddev_lock_nointr(mddev);
5363 5171
5364 mutex_lock(&mddev->open_mutex); 5172 mutex_lock(&mddev->open_mutex);
5365 if (atomic_read(&mddev->openers) > !!bdev || 5173 if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
5366 mddev->sysfs_active || 5174 mddev->sysfs_active ||
5367 mddev->sync_thread || 5175 mddev->sync_thread ||
5368 (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) { 5176 (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
@@ -5512,12 +5320,12 @@ static void autorun_devices(int part)
5512 "md: cannot allocate memory for md drive.\n"); 5320 "md: cannot allocate memory for md drive.\n");
5513 break; 5321 break;
5514 } 5322 }
5515 if (mddev_lock(mddev)) 5323 if (mddev_lock(mddev))
5516 printk(KERN_WARNING "md: %s locked, cannot run\n", 5324 printk(KERN_WARNING "md: %s locked, cannot run\n",
5517 mdname(mddev)); 5325 mdname(mddev));
5518 else if (mddev->raid_disks || mddev->major_version 5326 else if (mddev->raid_disks || mddev->major_version
5519 || !list_empty(&mddev->disks)) { 5327 || !list_empty(&mddev->disks)) {
5520 printk(KERN_WARNING 5328 printk(KERN_WARNING
5521 "md: %s already running, cannot run %s\n", 5329 "md: %s already running, cannot run %s\n",
5522 mdname(mddev), bdevname(rdev0->bdev,b)); 5330 mdname(mddev), bdevname(rdev0->bdev,b));
5523 mddev_unlock(mddev); 5331 mddev_unlock(mddev);
@@ -5545,7 +5353,7 @@ static void autorun_devices(int part)
5545} 5353}
5546#endif /* !MODULE */ 5354#endif /* !MODULE */
5547 5355
5548static int get_version(void __user * arg) 5356static int get_version(void __user *arg)
5549{ 5357{
5550 mdu_version_t ver; 5358 mdu_version_t ver;
5551 5359
@@ -5559,7 +5367,7 @@ static int get_version(void __user * arg)
5559 return 0; 5367 return 0;
5560} 5368}
5561 5369
5562static int get_array_info(struct mddev * mddev, void __user * arg) 5370static int get_array_info(struct mddev *mddev, void __user *arg)
5563{ 5371{
5564 mdu_array_info_t info; 5372 mdu_array_info_t info;
5565 int nr,working,insync,failed,spare; 5373 int nr,working,insync,failed,spare;
@@ -5574,7 +5382,7 @@ static int get_array_info(struct mddev * mddev, void __user * arg)
5574 else { 5382 else {
5575 working++; 5383 working++;
5576 if (test_bit(In_sync, &rdev->flags)) 5384 if (test_bit(In_sync, &rdev->flags))
5577 insync++; 5385 insync++;
5578 else 5386 else
5579 spare++; 5387 spare++;
5580 } 5388 }
@@ -5614,7 +5422,7 @@ static int get_array_info(struct mddev * mddev, void __user * arg)
5614 return 0; 5422 return 0;
5615} 5423}
5616 5424
5617static int get_bitmap_file(struct mddev * mddev, void __user * arg) 5425static int get_bitmap_file(struct mddev *mddev, void __user * arg)
5618{ 5426{
5619 mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ 5427 mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */
5620 char *ptr, *buf = NULL; 5428 char *ptr, *buf = NULL;
@@ -5652,7 +5460,7 @@ out:
5652 return err; 5460 return err;
5653} 5461}
5654 5462
5655static int get_disk_info(struct mddev * mddev, void __user * arg) 5463static int get_disk_info(struct mddev *mddev, void __user * arg)
5656{ 5464{
5657 mdu_disk_info_t info; 5465 mdu_disk_info_t info;
5658 struct md_rdev *rdev; 5466 struct md_rdev *rdev;
@@ -5688,7 +5496,7 @@ static int get_disk_info(struct mddev * mddev, void __user * arg)
5688 return 0; 5496 return 0;
5689} 5497}
5690 5498
5691static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info) 5499static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
5692{ 5500{
5693 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; 5501 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
5694 struct md_rdev *rdev; 5502 struct md_rdev *rdev;
@@ -5702,7 +5510,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5702 /* expecting a device which has a superblock */ 5510 /* expecting a device which has a superblock */
5703 rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); 5511 rdev = md_import_device(dev, mddev->major_version, mddev->minor_version);
5704 if (IS_ERR(rdev)) { 5512 if (IS_ERR(rdev)) {
5705 printk(KERN_WARNING 5513 printk(KERN_WARNING
5706 "md: md_import_device returned %ld\n", 5514 "md: md_import_device returned %ld\n",
5707 PTR_ERR(rdev)); 5515 PTR_ERR(rdev));
5708 return PTR_ERR(rdev); 5516 return PTR_ERR(rdev);
@@ -5714,9 +5522,9 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5714 err = super_types[mddev->major_version] 5522 err = super_types[mddev->major_version]
5715 .load_super(rdev, rdev0, mddev->minor_version); 5523 .load_super(rdev, rdev0, mddev->minor_version);
5716 if (err < 0) { 5524 if (err < 0) {
5717 printk(KERN_WARNING 5525 printk(KERN_WARNING
5718 "md: %s has different UUID to %s\n", 5526 "md: %s has different UUID to %s\n",
5719 bdevname(rdev->bdev,b), 5527 bdevname(rdev->bdev,b),
5720 bdevname(rdev0->bdev,b2)); 5528 bdevname(rdev0->bdev,b2));
5721 export_rdev(rdev); 5529 export_rdev(rdev);
5722 return -EINVAL; 5530 return -EINVAL;
@@ -5736,7 +5544,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5736 if (mddev->pers) { 5544 if (mddev->pers) {
5737 int err; 5545 int err;
5738 if (!mddev->pers->hot_add_disk) { 5546 if (!mddev->pers->hot_add_disk) {
5739 printk(KERN_WARNING 5547 printk(KERN_WARNING
5740 "%s: personality does not support diskops!\n", 5548 "%s: personality does not support diskops!\n",
5741 mdname(mddev)); 5549 mdname(mddev));
5742 return -EINVAL; 5550 return -EINVAL;
@@ -5747,7 +5555,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5747 else 5555 else
5748 rdev = md_import_device(dev, -1, -1); 5556 rdev = md_import_device(dev, -1, -1);
5749 if (IS_ERR(rdev)) { 5557 if (IS_ERR(rdev)) {
5750 printk(KERN_WARNING 5558 printk(KERN_WARNING
5751 "md: md_import_device returned %ld\n", 5559 "md: md_import_device returned %ld\n",
5752 PTR_ERR(rdev)); 5560 PTR_ERR(rdev));
5753 return PTR_ERR(rdev); 5561 return PTR_ERR(rdev);
@@ -5821,7 +5629,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5821 int err; 5629 int err;
5822 rdev = md_import_device(dev, -1, 0); 5630 rdev = md_import_device(dev, -1, 0);
5823 if (IS_ERR(rdev)) { 5631 if (IS_ERR(rdev)) {
5824 printk(KERN_WARNING 5632 printk(KERN_WARNING
5825 "md: error, md_import_device() returned %ld\n", 5633 "md: error, md_import_device() returned %ld\n",
5826 PTR_ERR(rdev)); 5634 PTR_ERR(rdev));
5827 return PTR_ERR(rdev); 5635 return PTR_ERR(rdev);
@@ -5856,7 +5664,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5856 return 0; 5664 return 0;
5857} 5665}
5858 5666
5859static int hot_remove_disk(struct mddev * mddev, dev_t dev) 5667static int hot_remove_disk(struct mddev *mddev, dev_t dev)
5860{ 5668{
5861 char b[BDEVNAME_SIZE]; 5669 char b[BDEVNAME_SIZE];
5862 struct md_rdev *rdev; 5670 struct md_rdev *rdev;
@@ -5882,7 +5690,7 @@ busy:
5882 return -EBUSY; 5690 return -EBUSY;
5883} 5691}
5884 5692
5885static int hot_add_disk(struct mddev * mddev, dev_t dev) 5693static int hot_add_disk(struct mddev *mddev, dev_t dev)
5886{ 5694{
5887 char b[BDEVNAME_SIZE]; 5695 char b[BDEVNAME_SIZE];
5888 int err; 5696 int err;
@@ -5898,7 +5706,7 @@ static int hot_add_disk(struct mddev * mddev, dev_t dev)
5898 return -EINVAL; 5706 return -EINVAL;
5899 } 5707 }
5900 if (!mddev->pers->hot_add_disk) { 5708 if (!mddev->pers->hot_add_disk) {
5901 printk(KERN_WARNING 5709 printk(KERN_WARNING
5902 "%s: personality does not support diskops!\n", 5710 "%s: personality does not support diskops!\n",
5903 mdname(mddev)); 5711 mdname(mddev));
5904 return -EINVAL; 5712 return -EINVAL;
@@ -5906,7 +5714,7 @@ static int hot_add_disk(struct mddev * mddev, dev_t dev)
5906 5714
5907 rdev = md_import_device(dev, -1, 0); 5715 rdev = md_import_device(dev, -1, 0);
5908 if (IS_ERR(rdev)) { 5716 if (IS_ERR(rdev)) {
5909 printk(KERN_WARNING 5717 printk(KERN_WARNING
5910 "md: error, md_import_device() returned %ld\n", 5718 "md: error, md_import_device() returned %ld\n",
5911 PTR_ERR(rdev)); 5719 PTR_ERR(rdev));
5912 return -EINVAL; 5720 return -EINVAL;
@@ -5920,7 +5728,7 @@ static int hot_add_disk(struct mddev * mddev, dev_t dev)
5920 rdev->sectors = rdev->sb_start; 5728 rdev->sectors = rdev->sb_start;
5921 5729
5922 if (test_bit(Faulty, &rdev->flags)) { 5730 if (test_bit(Faulty, &rdev->flags)) {
5923 printk(KERN_WARNING 5731 printk(KERN_WARNING
5924 "md: can not hot-add faulty %s disk to %s!\n", 5732 "md: can not hot-add faulty %s disk to %s!\n",
5925 bdevname(rdev->bdev,b), mdname(mddev)); 5733 bdevname(rdev->bdev,b), mdname(mddev));
5926 err = -EINVAL; 5734 err = -EINVAL;
@@ -5968,7 +5776,6 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
5968 /* we should be able to change the bitmap.. */ 5776 /* we should be able to change the bitmap.. */
5969 } 5777 }
5970 5778
5971
5972 if (fd >= 0) { 5779 if (fd >= 0) {
5973 struct inode *inode; 5780 struct inode *inode;
5974 if (mddev->bitmap) 5781 if (mddev->bitmap)
@@ -6039,7 +5846,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
6039 * The minor and patch _version numbers are also kept incase the 5846 * The minor and patch _version numbers are also kept incase the
6040 * super_block handler wishes to interpret them. 5847 * super_block handler wishes to interpret them.
6041 */ 5848 */
6042static int set_array_info(struct mddev * mddev, mdu_array_info_t *info) 5849static int set_array_info(struct mddev *mddev, mdu_array_info_t *info)
6043{ 5850{
6044 5851
6045 if (info->raid_disks == 0) { 5852 if (info->raid_disks == 0) {
@@ -6048,7 +5855,7 @@ static int set_array_info(struct mddev * mddev, mdu_array_info_t *info)
6048 info->major_version >= ARRAY_SIZE(super_types) || 5855 info->major_version >= ARRAY_SIZE(super_types) ||
6049 super_types[info->major_version].name == NULL) { 5856 super_types[info->major_version].name == NULL) {
6050 /* maybe try to auto-load a module? */ 5857 /* maybe try to auto-load a module? */
6051 printk(KERN_INFO 5858 printk(KERN_INFO
6052 "md: superblock version %d not known\n", 5859 "md: superblock version %d not known\n",
6053 info->major_version); 5860 info->major_version);
6054 return -EINVAL; 5861 return -EINVAL;
@@ -6196,7 +6003,6 @@ static int update_raid_disks(struct mddev *mddev, int raid_disks)
6196 return rv; 6003 return rv;
6197} 6004}
6198 6005
6199
6200/* 6006/*
6201 * update_array_info is used to change the configuration of an 6007 * update_array_info is used to change the configuration of an
6202 * on-line array. 6008 * on-line array.
@@ -6347,7 +6153,6 @@ static inline bool md_ioctl_valid(unsigned int cmd)
6347 case GET_DISK_INFO: 6153 case GET_DISK_INFO:
6348 case HOT_ADD_DISK: 6154 case HOT_ADD_DISK:
6349 case HOT_REMOVE_DISK: 6155 case HOT_REMOVE_DISK:
6350 case PRINT_RAID_DEBUG:
6351 case RAID_AUTORUN: 6156 case RAID_AUTORUN:
6352 case RAID_VERSION: 6157 case RAID_VERSION:
6353 case RESTART_ARRAY_RW: 6158 case RESTART_ARRAY_RW:
@@ -6391,18 +6196,13 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6391 switch (cmd) { 6196 switch (cmd) {
6392 case RAID_VERSION: 6197 case RAID_VERSION:
6393 err = get_version(argp); 6198 err = get_version(argp);
6394 goto done; 6199 goto out;
6395
6396 case PRINT_RAID_DEBUG:
6397 err = 0;
6398 md_print_devices();
6399 goto done;
6400 6200
6401#ifndef MODULE 6201#ifndef MODULE
6402 case RAID_AUTORUN: 6202 case RAID_AUTORUN:
6403 err = 0; 6203 err = 0;
6404 autostart_arrays(arg); 6204 autostart_arrays(arg);
6405 goto done; 6205 goto out;
6406#endif 6206#endif
6407 default:; 6207 default:;
6408 } 6208 }
@@ -6415,7 +6215,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6415 6215
6416 if (!mddev) { 6216 if (!mddev) {
6417 BUG(); 6217 BUG();
6418 goto abort; 6218 goto out;
6419 } 6219 }
6420 6220
6421 /* Some actions do not requires the mutex */ 6221 /* Some actions do not requires the mutex */
@@ -6425,18 +6225,18 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6425 err = -ENODEV; 6225 err = -ENODEV;
6426 else 6226 else
6427 err = get_array_info(mddev, argp); 6227 err = get_array_info(mddev, argp);
6428 goto abort; 6228 goto out;
6429 6229
6430 case GET_DISK_INFO: 6230 case GET_DISK_INFO:
6431 if (!mddev->raid_disks && !mddev->external) 6231 if (!mddev->raid_disks && !mddev->external)
6432 err = -ENODEV; 6232 err = -ENODEV;
6433 else 6233 else
6434 err = get_disk_info(mddev, argp); 6234 err = get_disk_info(mddev, argp);
6435 goto abort; 6235 goto out;
6436 6236
6437 case SET_DISK_FAULTY: 6237 case SET_DISK_FAULTY:
6438 err = set_disk_faulty(mddev, new_decode_dev(arg)); 6238 err = set_disk_faulty(mddev, new_decode_dev(arg));
6439 goto abort; 6239 goto out;
6440 } 6240 }
6441 6241
6442 if (cmd == ADD_NEW_DISK) 6242 if (cmd == ADD_NEW_DISK)
@@ -6454,10 +6254,10 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6454 * and writes 6254 * and writes
6455 */ 6255 */
6456 mutex_lock(&mddev->open_mutex); 6256 mutex_lock(&mddev->open_mutex);
6457 if (atomic_read(&mddev->openers) > 1) { 6257 if (mddev->pers && atomic_read(&mddev->openers) > 1) {
6458 mutex_unlock(&mddev->open_mutex); 6258 mutex_unlock(&mddev->open_mutex);
6459 err = -EBUSY; 6259 err = -EBUSY;
6460 goto abort; 6260 goto out;
6461 } 6261 }
6462 set_bit(MD_STILL_CLOSED, &mddev->flags); 6262 set_bit(MD_STILL_CLOSED, &mddev->flags);
6463 mutex_unlock(&mddev->open_mutex); 6263 mutex_unlock(&mddev->open_mutex);
@@ -6465,10 +6265,10 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6465 } 6265 }
6466 err = mddev_lock(mddev); 6266 err = mddev_lock(mddev);
6467 if (err) { 6267 if (err) {
6468 printk(KERN_INFO 6268 printk(KERN_INFO
6469 "md: ioctl lock interrupted, reason %d, cmd %d\n", 6269 "md: ioctl lock interrupted, reason %d, cmd %d\n",
6470 err, cmd); 6270 err, cmd);
6471 goto abort; 6271 goto out;
6472 } 6272 }
6473 6273
6474 if (cmd == SET_ARRAY_INFO) { 6274 if (cmd == SET_ARRAY_INFO) {
@@ -6477,38 +6277,38 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6477 memset(&info, 0, sizeof(info)); 6277 memset(&info, 0, sizeof(info));
6478 else if (copy_from_user(&info, argp, sizeof(info))) { 6278 else if (copy_from_user(&info, argp, sizeof(info))) {
6479 err = -EFAULT; 6279 err = -EFAULT;
6480 goto abort_unlock; 6280 goto unlock;
6481 } 6281 }
6482 if (mddev->pers) { 6282 if (mddev->pers) {
6483 err = update_array_info(mddev, &info); 6283 err = update_array_info(mddev, &info);
6484 if (err) { 6284 if (err) {
6485 printk(KERN_WARNING "md: couldn't update" 6285 printk(KERN_WARNING "md: couldn't update"
6486 " array info. %d\n", err); 6286 " array info. %d\n", err);
6487 goto abort_unlock; 6287 goto unlock;
6488 } 6288 }
6489 goto done_unlock; 6289 goto unlock;
6490 } 6290 }
6491 if (!list_empty(&mddev->disks)) { 6291 if (!list_empty(&mddev->disks)) {
6492 printk(KERN_WARNING 6292 printk(KERN_WARNING
6493 "md: array %s already has disks!\n", 6293 "md: array %s already has disks!\n",
6494 mdname(mddev)); 6294 mdname(mddev));
6495 err = -EBUSY; 6295 err = -EBUSY;
6496 goto abort_unlock; 6296 goto unlock;
6497 } 6297 }
6498 if (mddev->raid_disks) { 6298 if (mddev->raid_disks) {
6499 printk(KERN_WARNING 6299 printk(KERN_WARNING
6500 "md: array %s already initialised!\n", 6300 "md: array %s already initialised!\n",
6501 mdname(mddev)); 6301 mdname(mddev));
6502 err = -EBUSY; 6302 err = -EBUSY;
6503 goto abort_unlock; 6303 goto unlock;
6504 } 6304 }
6505 err = set_array_info(mddev, &info); 6305 err = set_array_info(mddev, &info);
6506 if (err) { 6306 if (err) {
6507 printk(KERN_WARNING "md: couldn't set" 6307 printk(KERN_WARNING "md: couldn't set"
6508 " array info. %d\n", err); 6308 " array info. %d\n", err);
6509 goto abort_unlock; 6309 goto unlock;
6510 } 6310 }
6511 goto done_unlock; 6311 goto unlock;
6512 } 6312 }
6513 6313
6514 /* 6314 /*
@@ -6521,7 +6321,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6521 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE 6321 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE
6522 && cmd != GET_BITMAP_FILE) { 6322 && cmd != GET_BITMAP_FILE) {
6523 err = -ENODEV; 6323 err = -ENODEV;
6524 goto abort_unlock; 6324 goto unlock;
6525 } 6325 }
6526 6326
6527 /* 6327 /*
@@ -6530,23 +6330,23 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6530 switch (cmd) { 6330 switch (cmd) {
6531 case GET_BITMAP_FILE: 6331 case GET_BITMAP_FILE:
6532 err = get_bitmap_file(mddev, argp); 6332 err = get_bitmap_file(mddev, argp);
6533 goto done_unlock; 6333 goto unlock;
6534 6334
6535 case RESTART_ARRAY_RW: 6335 case RESTART_ARRAY_RW:
6536 err = restart_array(mddev); 6336 err = restart_array(mddev);
6537 goto done_unlock; 6337 goto unlock;
6538 6338
6539 case STOP_ARRAY: 6339 case STOP_ARRAY:
6540 err = do_md_stop(mddev, 0, bdev); 6340 err = do_md_stop(mddev, 0, bdev);
6541 goto done_unlock; 6341 goto unlock;
6542 6342
6543 case STOP_ARRAY_RO: 6343 case STOP_ARRAY_RO:
6544 err = md_set_readonly(mddev, bdev); 6344 err = md_set_readonly(mddev, bdev);
6545 goto done_unlock; 6345 goto unlock;
6546 6346
6547 case HOT_REMOVE_DISK: 6347 case HOT_REMOVE_DISK:
6548 err = hot_remove_disk(mddev, new_decode_dev(arg)); 6348 err = hot_remove_disk(mddev, new_decode_dev(arg));
6549 goto done_unlock; 6349 goto unlock;
6550 6350
6551 case ADD_NEW_DISK: 6351 case ADD_NEW_DISK:
6552 /* We can support ADD_NEW_DISK on read-only arrays 6352 /* We can support ADD_NEW_DISK on read-only arrays
@@ -6562,14 +6362,14 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6562 break; 6362 break;
6563 else 6363 else
6564 err = add_new_disk(mddev, &info); 6364 err = add_new_disk(mddev, &info);
6565 goto done_unlock; 6365 goto unlock;
6566 } 6366 }
6567 break; 6367 break;
6568 6368
6569 case BLKROSET: 6369 case BLKROSET:
6570 if (get_user(ro, (int __user *)(arg))) { 6370 if (get_user(ro, (int __user *)(arg))) {
6571 err = -EFAULT; 6371 err = -EFAULT;
6572 goto done_unlock; 6372 goto unlock;
6573 } 6373 }
6574 err = -EINVAL; 6374 err = -EINVAL;
6575 6375
@@ -6577,11 +6377,11 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6577 * does not matter, no writes are coming 6377 * does not matter, no writes are coming
6578 */ 6378 */
6579 if (ro) 6379 if (ro)
6580 goto done_unlock; 6380 goto unlock;
6581 6381
6582 /* are we are already prepared for writes? */ 6382 /* are we are already prepared for writes? */
6583 if (mddev->ro != 1) 6383 if (mddev->ro != 1)
6584 goto done_unlock; 6384 goto unlock;
6585 6385
6586 /* transitioning to readauto need only happen for 6386 /* transitioning to readauto need only happen for
6587 * arrays that call md_write_start 6387 * arrays that call md_write_start
@@ -6593,17 +6393,14 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6593 set_disk_ro(mddev->gendisk, 0); 6393 set_disk_ro(mddev->gendisk, 0);
6594 } 6394 }
6595 } 6395 }
6596 goto done_unlock; 6396 goto unlock;
6597 } 6397 }
6598 6398
6599 /* 6399 /*
6600 * The remaining ioctls are changing the state of the 6400 * The remaining ioctls are changing the state of the
6601 * superblock, so we do not allow them on read-only arrays. 6401 * superblock, so we do not allow them on read-only arrays.
6602 * However non-MD ioctls (e.g. get-size) will still come through
6603 * here and hit the 'default' below, so only disallow
6604 * 'md' ioctls, and switch to rw mode if started auto-readonly.
6605 */ 6402 */
6606 if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { 6403 if (mddev->ro && mddev->pers) {
6607 if (mddev->ro == 2) { 6404 if (mddev->ro == 2) {
6608 mddev->ro = 0; 6405 mddev->ro = 0;
6609 sysfs_notify_dirent_safe(mddev->sysfs_state); 6406 sysfs_notify_dirent_safe(mddev->sysfs_state);
@@ -6621,7 +6418,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6621 } 6418 }
6622 } else { 6419 } else {
6623 err = -EROFS; 6420 err = -EROFS;
6624 goto abort_unlock; 6421 goto unlock;
6625 } 6422 }
6626 } 6423 }
6627 6424
@@ -6633,38 +6430,32 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6633 err = -EFAULT; 6430 err = -EFAULT;
6634 else 6431 else
6635 err = add_new_disk(mddev, &info); 6432 err = add_new_disk(mddev, &info);
6636 goto done_unlock; 6433 goto unlock;
6637 } 6434 }
6638 6435
6639 case HOT_ADD_DISK: 6436 case HOT_ADD_DISK:
6640 err = hot_add_disk(mddev, new_decode_dev(arg)); 6437 err = hot_add_disk(mddev, new_decode_dev(arg));
6641 goto done_unlock; 6438 goto unlock;
6642 6439
6643 case RUN_ARRAY: 6440 case RUN_ARRAY:
6644 err = do_md_run(mddev); 6441 err = do_md_run(mddev);
6645 goto done_unlock; 6442 goto unlock;
6646 6443
6647 case SET_BITMAP_FILE: 6444 case SET_BITMAP_FILE:
6648 err = set_bitmap_file(mddev, (int)arg); 6445 err = set_bitmap_file(mddev, (int)arg);
6649 goto done_unlock; 6446 goto unlock;
6650 6447
6651 default: 6448 default:
6652 err = -EINVAL; 6449 err = -EINVAL;
6653 goto abort_unlock; 6450 goto unlock;
6654 } 6451 }
6655 6452
6656done_unlock: 6453unlock:
6657abort_unlock:
6658 if (mddev->hold_active == UNTIL_IOCTL && 6454 if (mddev->hold_active == UNTIL_IOCTL &&
6659 err != -EINVAL) 6455 err != -EINVAL)
6660 mddev->hold_active = 0; 6456 mddev->hold_active = 0;
6661 mddev_unlock(mddev); 6457 mddev_unlock(mddev);
6662 6458out:
6663 return err;
6664done:
6665 if (err)
6666 MD_BUG();
6667abort:
6668 return err; 6459 return err;
6669} 6460}
6670#ifdef CONFIG_COMPAT 6461#ifdef CONFIG_COMPAT
@@ -6726,7 +6517,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
6726 6517
6727static void md_release(struct gendisk *disk, fmode_t mode) 6518static void md_release(struct gendisk *disk, fmode_t mode)
6728{ 6519{
6729 struct mddev *mddev = disk->private_data; 6520 struct mddev *mddev = disk->private_data;
6730 6521
6731 BUG_ON(!mddev); 6522 BUG_ON(!mddev);
6732 atomic_dec(&mddev->openers); 6523 atomic_dec(&mddev->openers);
@@ -6761,7 +6552,7 @@ static const struct block_device_operations md_fops =
6761 .revalidate_disk= md_revalidate, 6552 .revalidate_disk= md_revalidate,
6762}; 6553};
6763 6554
6764static int md_thread(void * arg) 6555static int md_thread(void *arg)
6765{ 6556{
6766 struct md_thread *thread = arg; 6557 struct md_thread *thread = arg;
6767 6558
@@ -6810,6 +6601,7 @@ void md_wakeup_thread(struct md_thread *thread)
6810 wake_up(&thread->wqueue); 6601 wake_up(&thread->wqueue);
6811 } 6602 }
6812} 6603}
6604EXPORT_SYMBOL(md_wakeup_thread);
6813 6605
6814struct md_thread *md_register_thread(void (*run) (struct md_thread *), 6606struct md_thread *md_register_thread(void (*run) (struct md_thread *),
6815 struct mddev *mddev, const char *name) 6607 struct mddev *mddev, const char *name)
@@ -6835,6 +6627,7 @@ struct md_thread *md_register_thread(void (*run) (struct md_thread *),
6835 } 6627 }
6836 return thread; 6628 return thread;
6837} 6629}
6630EXPORT_SYMBOL(md_register_thread);
6838 6631
6839void md_unregister_thread(struct md_thread **threadp) 6632void md_unregister_thread(struct md_thread **threadp)
6840{ 6633{
@@ -6852,14 +6645,10 @@ void md_unregister_thread(struct md_thread **threadp)
6852 kthread_stop(thread->tsk); 6645 kthread_stop(thread->tsk);
6853 kfree(thread); 6646 kfree(thread);
6854} 6647}
6648EXPORT_SYMBOL(md_unregister_thread);
6855 6649
6856void md_error(struct mddev *mddev, struct md_rdev *rdev) 6650void md_error(struct mddev *mddev, struct md_rdev *rdev)
6857{ 6651{
6858 if (!mddev) {
6859 MD_BUG();
6860 return;
6861 }
6862
6863 if (!rdev || test_bit(Faulty, &rdev->flags)) 6652 if (!rdev || test_bit(Faulty, &rdev->flags))
6864 return; 6653 return;
6865 6654
@@ -6876,6 +6665,7 @@ void md_error(struct mddev *mddev, struct md_rdev *rdev)
6876 queue_work(md_misc_wq, &mddev->event_work); 6665 queue_work(md_misc_wq, &mddev->event_work);
6877 md_new_event_inintr(mddev); 6666 md_new_event_inintr(mddev);
6878} 6667}
6668EXPORT_SYMBOL(md_error);
6879 6669
6880/* seq_file implementation /proc/mdstat */ 6670/* seq_file implementation /proc/mdstat */
6881 6671
@@ -6898,8 +6688,7 @@ static void status_unused(struct seq_file *seq)
6898 seq_printf(seq, "\n"); 6688 seq_printf(seq, "\n");
6899} 6689}
6900 6690
6901 6691static void status_resync(struct seq_file *seq, struct mddev *mddev)
6902static void status_resync(struct seq_file *seq, struct mddev * mddev)
6903{ 6692{
6904 sector_t max_sectors, resync, res; 6693 sector_t max_sectors, resync, res;
6905 unsigned long dt, db; 6694 unsigned long dt, db;
@@ -6919,13 +6708,7 @@ static void status_resync(struct seq_file *seq, struct mddev * mddev)
6919 else 6708 else
6920 max_sectors = mddev->dev_sectors; 6709 max_sectors = mddev->dev_sectors;
6921 6710
6922 /* 6711 WARN_ON(max_sectors == 0);
6923 * Should not happen.
6924 */
6925 if (!max_sectors) {
6926 MD_BUG();
6927 return;
6928 }
6929 /* Pick 'scale' such that (resync>>scale)*1000 will fit 6712 /* Pick 'scale' such that (resync>>scale)*1000 will fit
6930 * in a sector_t, and (max_sectors>>scale) will fit in a 6713 * in a sector_t, and (max_sectors>>scale) will fit in a
6931 * u32, as those are the requirements for sector_div. 6714 * u32, as those are the requirements for sector_div.
@@ -7021,7 +6804,7 @@ static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos)
7021{ 6804{
7022 struct list_head *tmp; 6805 struct list_head *tmp;
7023 struct mddev *next_mddev, *mddev = v; 6806 struct mddev *next_mddev, *mddev = v;
7024 6807
7025 ++*pos; 6808 ++*pos;
7026 if (v == (void*)2) 6809 if (v == (void*)2)
7027 return NULL; 6810 return NULL;
@@ -7036,7 +6819,7 @@ static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos)
7036 else { 6819 else {
7037 next_mddev = (void*)2; 6820 next_mddev = (void*)2;
7038 *pos = 0x10000; 6821 *pos = 0x10000;
7039 } 6822 }
7040 spin_unlock(&all_mddevs_lock); 6823 spin_unlock(&all_mddevs_lock);
7041 6824
7042 if (v != (void*)1) 6825 if (v != (void*)1)
@@ -7132,7 +6915,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
7132 6915
7133 if (mddev->pers) { 6916 if (mddev->pers) {
7134 mddev->pers->status(seq, mddev); 6917 mddev->pers->status(seq, mddev);
7135 seq_printf(seq, "\n "); 6918 seq_printf(seq, "\n ");
7136 if (mddev->pers->sync_request) { 6919 if (mddev->pers->sync_request) {
7137 if (mddev->curr_resync > 2) { 6920 if (mddev->curr_resync > 2) {
7138 status_resync(seq, mddev); 6921 status_resync(seq, mddev);
@@ -7150,7 +6933,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
7150 seq_printf(seq, "\n"); 6933 seq_printf(seq, "\n");
7151 } 6934 }
7152 mddev_unlock(mddev); 6935 mddev_unlock(mddev);
7153 6936
7154 return 0; 6937 return 0;
7155} 6938}
7156 6939
@@ -7204,12 +6987,14 @@ static const struct file_operations md_seq_fops = {
7204 6987
7205int register_md_personality(struct md_personality *p) 6988int register_md_personality(struct md_personality *p)
7206{ 6989{
6990 printk(KERN_INFO "md: %s personality registered for level %d\n",
6991 p->name, p->level);
7207 spin_lock(&pers_lock); 6992 spin_lock(&pers_lock);
7208 list_add_tail(&p->list, &pers_list); 6993 list_add_tail(&p->list, &pers_list);
7209 printk(KERN_INFO "md: %s personality registered for level %d\n", p->name, p->level);
7210 spin_unlock(&pers_lock); 6994 spin_unlock(&pers_lock);
7211 return 0; 6995 return 0;
7212} 6996}
6997EXPORT_SYMBOL(register_md_personality);
7213 6998
7214int unregister_md_personality(struct md_personality *p) 6999int unregister_md_personality(struct md_personality *p)
7215{ 7000{
@@ -7219,10 +7004,11 @@ int unregister_md_personality(struct md_personality *p)
7219 spin_unlock(&pers_lock); 7004 spin_unlock(&pers_lock);
7220 return 0; 7005 return 0;
7221} 7006}
7007EXPORT_SYMBOL(unregister_md_personality);
7222 7008
7223static int is_mddev_idle(struct mddev *mddev, int init) 7009static int is_mddev_idle(struct mddev *mddev, int init)
7224{ 7010{
7225 struct md_rdev * rdev; 7011 struct md_rdev *rdev;
7226 int idle; 7012 int idle;
7227 int curr_events; 7013 int curr_events;
7228 7014
@@ -7276,7 +7062,7 @@ void md_done_sync(struct mddev *mddev, int blocks, int ok)
7276 // stop recovery, signal do_sync .... 7062 // stop recovery, signal do_sync ....
7277 } 7063 }
7278} 7064}
7279 7065EXPORT_SYMBOL(md_done_sync);
7280 7066
7281/* md_write_start(mddev, bi) 7067/* md_write_start(mddev, bi)
7282 * If we need to update some array metadata (e.g. 'active' flag 7068 * If we need to update some array metadata (e.g. 'active' flag
@@ -7317,6 +7103,7 @@ void md_write_start(struct mddev *mddev, struct bio *bi)
7317 wait_event(mddev->sb_wait, 7103 wait_event(mddev->sb_wait,
7318 !test_bit(MD_CHANGE_PENDING, &mddev->flags)); 7104 !test_bit(MD_CHANGE_PENDING, &mddev->flags));
7319} 7105}
7106EXPORT_SYMBOL(md_write_start);
7320 7107
7321void md_write_end(struct mddev *mddev) 7108void md_write_end(struct mddev *mddev)
7322{ 7109{
@@ -7327,6 +7114,7 @@ void md_write_end(struct mddev *mddev)
7327 mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); 7114 mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay);
7328 } 7115 }
7329} 7116}
7117EXPORT_SYMBOL(md_write_end);
7330 7118
7331/* md_allow_write(mddev) 7119/* md_allow_write(mddev)
7332 * Calling this ensures that the array is marked 'active' so that writes 7120 * Calling this ensures that the array is marked 'active' so that writes
@@ -7784,6 +7572,33 @@ no_add:
7784 return spares; 7572 return spares;
7785} 7573}
7786 7574
7575static void md_start_sync(struct work_struct *ws)
7576{
7577 struct mddev *mddev = container_of(ws, struct mddev, del_work);
7578
7579 mddev->sync_thread = md_register_thread(md_do_sync,
7580 mddev,
7581 "resync");
7582 if (!mddev->sync_thread) {
7583 printk(KERN_ERR "%s: could not start resync"
7584 " thread...\n",
7585 mdname(mddev));
7586 /* leave the spares where they are, it shouldn't hurt */
7587 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
7588 clear_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
7589 clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
7590 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
7591 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
7592 if (test_and_clear_bit(MD_RECOVERY_RECOVER,
7593 &mddev->recovery))
7594 if (mddev->sysfs_action)
7595 sysfs_notify_dirent_safe(mddev->sysfs_action);
7596 } else
7597 md_wakeup_thread(mddev->sync_thread);
7598 sysfs_notify_dirent_safe(mddev->sysfs_action);
7599 md_new_event(mddev);
7600}
7601
7787/* 7602/*
7788 * This routine is regularly called by all per-raid-array threads to 7603 * This routine is regularly called by all per-raid-array threads to
7789 * deal with generic issues like resync and super-block update. 7604 * deal with generic issues like resync and super-block update.
@@ -7900,7 +7715,7 @@ void md_check_recovery(struct mddev *mddev)
7900 7715
7901 if (!test_and_clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || 7716 if (!test_and_clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
7902 test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) 7717 test_bit(MD_RECOVERY_FROZEN, &mddev->recovery))
7903 goto unlock; 7718 goto not_running;
7904 /* no recovery is running. 7719 /* no recovery is running.
7905 * remove any failed drives, then 7720 * remove any failed drives, then
7906 * add spares if possible. 7721 * add spares if possible.
@@ -7912,7 +7727,7 @@ void md_check_recovery(struct mddev *mddev)
7912 if (mddev->pers->check_reshape == NULL || 7727 if (mddev->pers->check_reshape == NULL ||
7913 mddev->pers->check_reshape(mddev) != 0) 7728 mddev->pers->check_reshape(mddev) != 0)
7914 /* Cannot proceed */ 7729 /* Cannot proceed */
7915 goto unlock; 7730 goto not_running;
7916 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); 7731 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
7917 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 7732 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
7918 } else if ((spares = remove_and_add_spares(mddev, NULL))) { 7733 } else if ((spares = remove_and_add_spares(mddev, NULL))) {
@@ -7925,7 +7740,7 @@ void md_check_recovery(struct mddev *mddev)
7925 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 7740 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
7926 } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) 7741 } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
7927 /* nothing to be done ... */ 7742 /* nothing to be done ... */
7928 goto unlock; 7743 goto not_running;
7929 7744
7930 if (mddev->pers->sync_request) { 7745 if (mddev->pers->sync_request) {
7931 if (spares) { 7746 if (spares) {
@@ -7935,27 +7750,11 @@ void md_check_recovery(struct mddev *mddev)
7935 */ 7750 */
7936 bitmap_write_all(mddev->bitmap); 7751 bitmap_write_all(mddev->bitmap);
7937 } 7752 }
7938 mddev->sync_thread = md_register_thread(md_do_sync, 7753 INIT_WORK(&mddev->del_work, md_start_sync);
7939 mddev, 7754 queue_work(md_misc_wq, &mddev->del_work);
7940 "resync"); 7755 goto unlock;
7941 if (!mddev->sync_thread) {
7942 printk(KERN_ERR "%s: could not start resync"
7943 " thread...\n",
7944 mdname(mddev));
7945 /* leave the spares where they are, it shouldn't hurt */
7946 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
7947 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
7948 clear_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
7949 clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
7950 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
7951 } else
7952 md_wakeup_thread(mddev->sync_thread);
7953 sysfs_notify_dirent_safe(mddev->sysfs_action);
7954 md_new_event(mddev);
7955 } 7756 }
7956 unlock: 7757 not_running:
7957 wake_up(&mddev->sb_wait);
7958
7959 if (!mddev->sync_thread) { 7758 if (!mddev->sync_thread) {
7960 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery); 7759 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
7961 if (test_and_clear_bit(MD_RECOVERY_RECOVER, 7760 if (test_and_clear_bit(MD_RECOVERY_RECOVER,
@@ -7963,9 +7762,12 @@ void md_check_recovery(struct mddev *mddev)
7963 if (mddev->sysfs_action) 7762 if (mddev->sysfs_action)
7964 sysfs_notify_dirent_safe(mddev->sysfs_action); 7763 sysfs_notify_dirent_safe(mddev->sysfs_action);
7965 } 7764 }
7765 unlock:
7766 wake_up(&mddev->sb_wait);
7966 mddev_unlock(mddev); 7767 mddev_unlock(mddev);
7967 } 7768 }
7968} 7769}
7770EXPORT_SYMBOL(md_check_recovery);
7969 7771
7970void md_reap_sync_thread(struct mddev *mddev) 7772void md_reap_sync_thread(struct mddev *mddev)
7971{ 7773{
@@ -8008,6 +7810,7 @@ void md_reap_sync_thread(struct mddev *mddev)
8008 if (mddev->event_work.func) 7810 if (mddev->event_work.func)
8009 queue_work(md_misc_wq, &mddev->event_work); 7811 queue_work(md_misc_wq, &mddev->event_work);
8010} 7812}
7813EXPORT_SYMBOL(md_reap_sync_thread);
8011 7814
8012void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev) 7815void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev)
8013{ 7816{
@@ -8641,7 +8444,6 @@ void md_autodetect_dev(dev_t dev)
8641 } 8444 }
8642} 8445}
8643 8446
8644
8645static void autostart_arrays(int part) 8447static void autostart_arrays(int part)
8646{ 8448{
8647 struct md_rdev *rdev; 8449 struct md_rdev *rdev;
@@ -8665,10 +8467,9 @@ static void autostart_arrays(int part)
8665 if (IS_ERR(rdev)) 8467 if (IS_ERR(rdev))
8666 continue; 8468 continue;
8667 8469
8668 if (test_bit(Faulty, &rdev->flags)) { 8470 if (test_bit(Faulty, &rdev->flags))
8669 MD_BUG();
8670 continue; 8471 continue;
8671 } 8472
8672 set_bit(AutoDetected, &rdev->flags); 8473 set_bit(AutoDetected, &rdev->flags);
8673 list_add(&rdev->same_set, &pending_raid_disks); 8474 list_add(&rdev->same_set, &pending_raid_disks);
8674 i_passed++; 8475 i_passed++;
@@ -8736,20 +8537,8 @@ static int set_ro(const char *val, struct kernel_param *kp)
8736 8537
8737module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); 8538module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR);
8738module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); 8539module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR);
8739
8740module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR); 8540module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR);
8741 8541
8742EXPORT_SYMBOL(register_md_personality);
8743EXPORT_SYMBOL(unregister_md_personality);
8744EXPORT_SYMBOL(md_error);
8745EXPORT_SYMBOL(md_done_sync);
8746EXPORT_SYMBOL(md_write_start);
8747EXPORT_SYMBOL(md_write_end);
8748EXPORT_SYMBOL(md_register_thread);
8749EXPORT_SYMBOL(md_unregister_thread);
8750EXPORT_SYMBOL(md_wakeup_thread);
8751EXPORT_SYMBOL(md_check_recovery);
8752EXPORT_SYMBOL(md_reap_sync_thread);
8753MODULE_LICENSE("GPL"); 8542MODULE_LICENSE("GPL");
8754MODULE_DESCRIPTION("MD RAID framework"); 8543MODULE_DESCRIPTION("MD RAID framework");
8755MODULE_ALIAS("md"); 8544MODULE_ALIAS("md");
diff --git a/drivers/md/md.h b/drivers/md/md.h
index a49d991f3fe1..03cec5bdcaae 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -1,15 +1,15 @@
1/* 1/*
2 md.h : kernel internal structure of the Linux MD driver 2 md.h : kernel internal structure of the Linux MD driver
3 Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman 3 Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 2, or (at your option)
8 any later version. 8 any later version.
9 9
10 You should have received a copy of the GNU General Public License 10 You should have received a copy of the GNU General Public License
11 (for example /usr/src/linux/COPYING); if not, write to the Free 11 (for example /usr/src/linux/COPYING); if not, write to the Free
12 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 12 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13*/ 13*/
14 14
15#ifndef _MD_MD_H 15#ifndef _MD_MD_H
@@ -56,7 +56,7 @@ struct md_rdev {
56 __u64 sb_events; 56 __u64 sb_events;
57 sector_t data_offset; /* start of data in array */ 57 sector_t data_offset; /* start of data in array */
58 sector_t new_data_offset;/* only relevant while reshaping */ 58 sector_t new_data_offset;/* only relevant while reshaping */
59 sector_t sb_start; /* offset of the super block (in 512byte sectors) */ 59 sector_t sb_start; /* offset of the super block (in 512byte sectors) */
60 int sb_size; /* bytes in the superblock */ 60 int sb_size; /* bytes in the superblock */
61 int preferred_minor; /* autorun support */ 61 int preferred_minor; /* autorun support */
62 62
@@ -239,7 +239,7 @@ struct mddev {
239 minor_version, 239 minor_version,
240 patch_version; 240 patch_version;
241 int persistent; 241 int persistent;
242 int external; /* metadata is 242 int external; /* metadata is
243 * managed externally */ 243 * managed externally */
244 char metadata_type[17]; /* externally set*/ 244 char metadata_type[17]; /* externally set*/
245 int chunk_sectors; 245 int chunk_sectors;
@@ -248,7 +248,7 @@ struct mddev {
248 char clevel[16]; 248 char clevel[16];
249 int raid_disks; 249 int raid_disks;
250 int max_disks; 250 int max_disks;
251 sector_t dev_sectors; /* used size of 251 sector_t dev_sectors; /* used size of
252 * component devices */ 252 * component devices */
253 sector_t array_sectors; /* exported array size */ 253 sector_t array_sectors; /* exported array size */
254 int external_size; /* size managed 254 int external_size; /* size managed
@@ -312,7 +312,7 @@ struct mddev {
312 int parallel_resync; 312 int parallel_resync;
313 313
314 int ok_start_degraded; 314 int ok_start_degraded;
315 /* recovery/resync flags 315 /* recovery/resync flags
316 * NEEDED: we might need to start a resync/recover 316 * NEEDED: we might need to start a resync/recover
317 * RUNNING: a thread is running, or about to be started 317 * RUNNING: a thread is running, or about to be started
318 * SYNC: actually doing a resync, not a recovery 318 * SYNC: actually doing a resync, not a recovery
@@ -392,20 +392,20 @@ struct mddev {
392 392
393 unsigned int safemode; /* if set, update "clean" superblock 393 unsigned int safemode; /* if set, update "clean" superblock
394 * when no writes pending. 394 * when no writes pending.
395 */ 395 */
396 unsigned int safemode_delay; 396 unsigned int safemode_delay;
397 struct timer_list safemode_timer; 397 struct timer_list safemode_timer;
398 atomic_t writes_pending; 398 atomic_t writes_pending;
399 struct request_queue *queue; /* for plugging ... */ 399 struct request_queue *queue; /* for plugging ... */
400 400
401 struct bitmap *bitmap; /* the bitmap for the device */ 401 struct bitmap *bitmap; /* the bitmap for the device */
402 struct { 402 struct {
403 struct file *file; /* the bitmap file */ 403 struct file *file; /* the bitmap file */
404 loff_t offset; /* offset from superblock of 404 loff_t offset; /* offset from superblock of
405 * start of bitmap. May be 405 * start of bitmap. May be
406 * negative, but not '0' 406 * negative, but not '0'
407 * For external metadata, offset 407 * For external metadata, offset
408 * from start of device. 408 * from start of device.
409 */ 409 */
410 unsigned long space; /* space available at this offset */ 410 unsigned long space; /* space available at this offset */
411 loff_t default_offset; /* this is the offset to use when 411 loff_t default_offset; /* this is the offset to use when
@@ -421,7 +421,7 @@ struct mddev {
421 int external; 421 int external;
422 } bitmap_info; 422 } bitmap_info;
423 423
424 atomic_t max_corr_read_errors; /* max read retries */ 424 atomic_t max_corr_read_errors; /* max read retries */
425 struct list_head all_mddevs; 425 struct list_head all_mddevs;
426 426
427 struct attribute_group *to_remove; 427 struct attribute_group *to_remove;
@@ -439,7 +439,6 @@ struct mddev {
439 void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev); 439 void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
440}; 440};
441 441
442
443static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev) 442static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
444{ 443{
445 int faulty = test_bit(Faulty, &rdev->flags); 444 int faulty = test_bit(Faulty, &rdev->flags);
@@ -449,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
449 448
450static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors) 449static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
451{ 450{
452 atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io); 451 atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
453} 452}
454 453
455struct md_personality 454struct md_personality
@@ -463,7 +462,7 @@ struct md_personality
463 int (*stop)(struct mddev *mddev); 462 int (*stop)(struct mddev *mddev);
464 void (*status)(struct seq_file *seq, struct mddev *mddev); 463 void (*status)(struct seq_file *seq, struct mddev *mddev);
465 /* error_handler must set ->faulty and clear ->in_sync 464 /* error_handler must set ->faulty and clear ->in_sync
466 * if appropriate, and should abort recovery if needed 465 * if appropriate, and should abort recovery if needed
467 */ 466 */
468 void (*error_handler)(struct mddev *mddev, struct md_rdev *rdev); 467 void (*error_handler)(struct mddev *mddev, struct md_rdev *rdev);
469 int (*hot_add_disk) (struct mddev *mddev, struct md_rdev *rdev); 468 int (*hot_add_disk) (struct mddev *mddev, struct md_rdev *rdev);
@@ -493,7 +492,6 @@ struct md_personality
493 void *(*takeover) (struct mddev *mddev); 492 void *(*takeover) (struct mddev *mddev);
494}; 493};
495 494
496
497struct md_sysfs_entry { 495struct md_sysfs_entry {
498 struct attribute attr; 496 struct attribute attr;
499 ssize_t (*show)(struct mddev *, char *); 497 ssize_t (*show)(struct mddev *, char *);
@@ -560,7 +558,7 @@ struct md_thread {
560 void (*run) (struct md_thread *thread); 558 void (*run) (struct md_thread *thread);
561 struct mddev *mddev; 559 struct mddev *mddev;
562 wait_queue_head_t wqueue; 560 wait_queue_head_t wqueue;
563 unsigned long flags; 561 unsigned long flags;
564 struct task_struct *tsk; 562 struct task_struct *tsk;
565 unsigned long timeout; 563 unsigned long timeout;
566 void *private; 564 void *private;
@@ -594,7 +592,7 @@ extern void md_flush_request(struct mddev *mddev, struct bio *bio);
594extern void md_super_write(struct mddev *mddev, struct md_rdev *rdev, 592extern void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
595 sector_t sector, int size, struct page *page); 593 sector_t sector, int size, struct page *page);
596extern void md_super_wait(struct mddev *mddev); 594extern void md_super_wait(struct mddev *mddev);
597extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size, 595extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
598 struct page *page, int rw, bool metadata_op); 596 struct page *page, int rw, bool metadata_op);
599extern void md_do_sync(struct md_thread *thread); 597extern void md_do_sync(struct md_thread *thread);
600extern void md_new_event(struct mddev *mddev); 598extern void md_new_event(struct mddev *mddev);
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 849ad39f547b..399272f9c042 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -31,13 +31,12 @@
31 31
32#define NR_RESERVED_BUFS 32 32#define NR_RESERVED_BUFS 32
33 33
34
35static int multipath_map (struct mpconf *conf) 34static int multipath_map (struct mpconf *conf)
36{ 35{
37 int i, disks = conf->raid_disks; 36 int i, disks = conf->raid_disks;
38 37
39 /* 38 /*
40 * Later we do read balancing on the read side 39 * Later we do read balancing on the read side
41 * now we use the first available disk. 40 * now we use the first available disk.
42 */ 41 */
43 42
@@ -68,7 +67,6 @@ static void multipath_reschedule_retry (struct multipath_bh *mp_bh)
68 md_wakeup_thread(mddev->thread); 67 md_wakeup_thread(mddev->thread);
69} 68}
70 69
71
72/* 70/*
73 * multipath_end_bh_io() is called when we have finished servicing a multipathed 71 * multipath_end_bh_io() is called when we have finished servicing a multipathed
74 * operation and are ready to return a success/failure code to the buffer 72 * operation and are ready to return a success/failure code to the buffer
@@ -98,8 +96,8 @@ static void multipath_end_request(struct bio *bio, int error)
98 */ 96 */
99 char b[BDEVNAME_SIZE]; 97 char b[BDEVNAME_SIZE];
100 md_error (mp_bh->mddev, rdev); 98 md_error (mp_bh->mddev, rdev);
101 printk(KERN_ERR "multipath: %s: rescheduling sector %llu\n", 99 printk(KERN_ERR "multipath: %s: rescheduling sector %llu\n",
102 bdevname(rdev->bdev,b), 100 bdevname(rdev->bdev,b),
103 (unsigned long long)bio->bi_iter.bi_sector); 101 (unsigned long long)bio->bi_iter.bi_sector);
104 multipath_reschedule_retry(mp_bh); 102 multipath_reschedule_retry(mp_bh);
105 } else 103 } else
@@ -145,12 +143,12 @@ static void multipath_status (struct seq_file *seq, struct mddev *mddev)
145{ 143{
146 struct mpconf *conf = mddev->private; 144 struct mpconf *conf = mddev->private;
147 int i; 145 int i;
148 146
149 seq_printf (seq, " [%d/%d] [", conf->raid_disks, 147 seq_printf (seq, " [%d/%d] [", conf->raid_disks,
150 conf->raid_disks - mddev->degraded); 148 conf->raid_disks - mddev->degraded);
151 for (i = 0; i < conf->raid_disks; i++) 149 for (i = 0; i < conf->raid_disks; i++)
152 seq_printf (seq, "%s", 150 seq_printf (seq, "%s",
153 conf->multipaths[i].rdev && 151 conf->multipaths[i].rdev &&
154 test_bit(In_sync, &conf->multipaths[i].rdev->flags) ? "U" : "_"); 152 test_bit(In_sync, &conf->multipaths[i].rdev->flags) ? "U" : "_");
155 seq_printf (seq, "]"); 153 seq_printf (seq, "]");
156} 154}
@@ -195,7 +193,7 @@ static void multipath_error (struct mddev *mddev, struct md_rdev *rdev)
195 * first check if this is a queued request for a device 193 * first check if this is a queued request for a device
196 * which has just failed. 194 * which has just failed.
197 */ 195 */
198 printk(KERN_ALERT 196 printk(KERN_ALERT
199 "multipath: only one IO path left and IO error.\n"); 197 "multipath: only one IO path left and IO error.\n");
200 /* leave it active... it's all we have */ 198 /* leave it active... it's all we have */
201 return; 199 return;
@@ -242,7 +240,6 @@ static void print_multipath_conf (struct mpconf *conf)
242 } 240 }
243} 241}
244 242
245
246static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev) 243static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev)
247{ 244{
248 struct mpconf *conf = mddev->private; 245 struct mpconf *conf = mddev->private;
@@ -325,8 +322,6 @@ abort:
325 return err; 322 return err;
326} 323}
327 324
328
329
330/* 325/*
331 * This is a kernel thread which: 326 * This is a kernel thread which:
332 * 327 *
@@ -356,7 +351,7 @@ static void multipathd(struct md_thread *thread)
356 351
357 bio = &mp_bh->bio; 352 bio = &mp_bh->bio;
358 bio->bi_iter.bi_sector = mp_bh->master_bio->bi_iter.bi_sector; 353 bio->bi_iter.bi_sector = mp_bh->master_bio->bi_iter.bi_sector;
359 354
360 if ((mp_bh->path = multipath_map (conf))<0) { 355 if ((mp_bh->path = multipath_map (conf))<0) {
361 printk(KERN_ALERT "multipath: %s: unrecoverable IO read" 356 printk(KERN_ALERT "multipath: %s: unrecoverable IO read"
362 " error for block %llu\n", 357 " error for block %llu\n",
@@ -414,7 +409,7 @@ static int multipath_run (struct mddev *mddev)
414 conf = kzalloc(sizeof(struct mpconf), GFP_KERNEL); 409 conf = kzalloc(sizeof(struct mpconf), GFP_KERNEL);
415 mddev->private = conf; 410 mddev->private = conf;
416 if (!conf) { 411 if (!conf) {
417 printk(KERN_ERR 412 printk(KERN_ERR
418 "multipath: couldn't allocate memory for %s\n", 413 "multipath: couldn't allocate memory for %s\n",
419 mdname(mddev)); 414 mdname(mddev));
420 goto out; 415 goto out;
@@ -423,7 +418,7 @@ static int multipath_run (struct mddev *mddev)
423 conf->multipaths = kzalloc(sizeof(struct multipath_info)*mddev->raid_disks, 418 conf->multipaths = kzalloc(sizeof(struct multipath_info)*mddev->raid_disks,
424 GFP_KERNEL); 419 GFP_KERNEL);
425 if (!conf->multipaths) { 420 if (!conf->multipaths) {
426 printk(KERN_ERR 421 printk(KERN_ERR
427 "multipath: couldn't allocate memory for %s\n", 422 "multipath: couldn't allocate memory for %s\n",
428 mdname(mddev)); 423 mdname(mddev));
429 goto out_free_conf; 424 goto out_free_conf;
@@ -469,7 +464,7 @@ static int multipath_run (struct mddev *mddev)
469 conf->pool = mempool_create_kmalloc_pool(NR_RESERVED_BUFS, 464 conf->pool = mempool_create_kmalloc_pool(NR_RESERVED_BUFS,
470 sizeof(struct multipath_bh)); 465 sizeof(struct multipath_bh));
471 if (conf->pool == NULL) { 466 if (conf->pool == NULL) {
472 printk(KERN_ERR 467 printk(KERN_ERR
473 "multipath: couldn't allocate memory for %s\n", 468 "multipath: couldn't allocate memory for %s\n",
474 mdname(mddev)); 469 mdname(mddev));
475 goto out_free_conf; 470 goto out_free_conf;
@@ -485,7 +480,7 @@ static int multipath_run (struct mddev *mddev)
485 } 480 }
486 } 481 }
487 482
488 printk(KERN_INFO 483 printk(KERN_INFO
489 "multipath: array %s active with %d out of %d IO paths\n", 484 "multipath: array %s active with %d out of %d IO paths\n",
490 mdname(mddev), conf->raid_disks - mddev->degraded, 485 mdname(mddev), conf->raid_disks - mddev->degraded,
491 mddev->raid_disks); 486 mddev->raid_disks);
@@ -512,7 +507,6 @@ out:
512 return -EIO; 507 return -EIO;
513} 508}
514 509
515
516static int multipath_stop (struct mddev *mddev) 510static int multipath_stop (struct mddev *mddev)
517{ 511{
518 struct mpconf *conf = mddev->private; 512 struct mpconf *conf = mddev->private;
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index cf91f5910c7c..ba6b85de96d2 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -1,10 +1,9 @@
1/* 1/*
2 raid0.c : Multiple Devices driver for Linux 2 raid0.c : Multiple Devices driver for Linux
3 Copyright (C) 1994-96 Marc ZYNGIER 3 Copyright (C) 1994-96 Marc ZYNGIER
4 <zyngier@ufr-info-p7.ibp.fr> or 4 <zyngier@ufr-info-p7.ibp.fr> or
5 <maz@gloups.fdn.fr> 5 <maz@gloups.fdn.fr>
6 Copyright (C) 1999, 2000 Ingo Molnar, Red Hat 6 Copyright (C) 1999, 2000 Ingo Molnar, Red Hat
7
8 7
9 RAID-0 management functions. 8 RAID-0 management functions.
10 9
@@ -12,10 +11,10 @@
12 it under the terms of the GNU General Public License as published by 11 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option) 12 the Free Software Foundation; either version 2, or (at your option)
14 any later version. 13 any later version.
15 14
16 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
17 (for example /usr/src/linux/COPYING); if not, write to the Free 16 (for example /usr/src/linux/COPYING); if not, write to the Free
18 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 18*/
20 19
21#include <linux/blkdev.h> 20#include <linux/blkdev.h>
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 55de4f6f7eaf..40b35be34f8d 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -494,7 +494,6 @@ static void raid1_end_write_request(struct bio *bio, int error)
494 bio_put(to_put); 494 bio_put(to_put);
495} 495}
496 496
497
498/* 497/*
499 * This routine returns the disk from which the requested read should 498 * This routine returns the disk from which the requested read should
500 * be done. There is a per-array 'next expected sequential IO' sector 499 * be done. There is a per-array 'next expected sequential IO' sector
@@ -901,18 +900,18 @@ static sector_t wait_barrier(struct r1conf *conf, struct bio *bio)
901 * However if there are already pending 900 * However if there are already pending
902 * requests (preventing the barrier from 901 * requests (preventing the barrier from
903 * rising completely), and the 902 * rising completely), and the
904 * pre-process bio queue isn't empty, 903 * per-process bio queue isn't empty,
905 * then don't wait, as we need to empty 904 * then don't wait, as we need to empty
906 * that queue to get the nr_pending 905 * that queue to allow conf->start_next_window
907 * count down. 906 * to increase.
908 */ 907 */
909 wait_event_lock_irq(conf->wait_barrier, 908 wait_event_lock_irq(conf->wait_barrier,
910 !conf->array_frozen && 909 !conf->array_frozen &&
911 (!conf->barrier || 910 (!conf->barrier ||
912 ((conf->start_next_window < 911 ((conf->start_next_window <
913 conf->next_resync + RESYNC_SECTORS) && 912 conf->next_resync + RESYNC_SECTORS) &&
914 current->bio_list && 913 current->bio_list &&
915 !bio_list_empty(current->bio_list))), 914 !bio_list_empty(current->bio_list))),
916 conf->resync_lock); 915 conf->resync_lock);
917 conf->nr_waiting--; 916 conf->nr_waiting--;
918 } 917 }
@@ -1001,8 +1000,7 @@ static void unfreeze_array(struct r1conf *conf)
1001 spin_unlock_irq(&conf->resync_lock); 1000 spin_unlock_irq(&conf->resync_lock);
1002} 1001}
1003 1002
1004 1003/* duplicate the data pages for behind I/O
1005/* duplicate the data pages for behind I/O
1006 */ 1004 */
1007static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) 1005static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio)
1008{ 1006{
@@ -1471,7 +1469,6 @@ static void status(struct seq_file *seq, struct mddev *mddev)
1471 seq_printf(seq, "]"); 1469 seq_printf(seq, "]");
1472} 1470}
1473 1471
1474
1475static void error(struct mddev *mddev, struct md_rdev *rdev) 1472static void error(struct mddev *mddev, struct md_rdev *rdev)
1476{ 1473{
1477 char b[BDEVNAME_SIZE]; 1474 char b[BDEVNAME_SIZE];
@@ -1565,7 +1562,7 @@ static int raid1_spare_active(struct mddev *mddev)
1565 unsigned long flags; 1562 unsigned long flags;
1566 1563
1567 /* 1564 /*
1568 * Find all failed disks within the RAID1 configuration 1565 * Find all failed disks within the RAID1 configuration
1569 * and mark them readable. 1566 * and mark them readable.
1570 * Called under mddev lock, so rcu protection not needed. 1567 * Called under mddev lock, so rcu protection not needed.
1571 */ 1568 */
@@ -1606,7 +1603,6 @@ static int raid1_spare_active(struct mddev *mddev)
1606 return count; 1603 return count;
1607} 1604}
1608 1605
1609
1610static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev) 1606static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1611{ 1607{
1612 struct r1conf *conf = mddev->private; 1608 struct r1conf *conf = mddev->private;
@@ -1735,7 +1731,6 @@ abort:
1735 return err; 1731 return err;
1736} 1732}
1737 1733
1738
1739static void end_sync_read(struct bio *bio, int error) 1734static void end_sync_read(struct bio *bio, int error)
1740{ 1735{
1741 struct r1bio *r1_bio = bio->bi_private; 1736 struct r1bio *r1_bio = bio->bi_private;
@@ -1947,7 +1942,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
1947 return 1; 1942 return 1;
1948} 1943}
1949 1944
1950static int process_checks(struct r1bio *r1_bio) 1945static void process_checks(struct r1bio *r1_bio)
1951{ 1946{
1952 /* We have read all readable devices. If we haven't 1947 /* We have read all readable devices. If we haven't
1953 * got the block, then there is no hope left. 1948 * got the block, then there is no hope left.
@@ -2039,7 +2034,6 @@ static int process_checks(struct r1bio *r1_bio)
2039 2034
2040 bio_copy_data(sbio, pbio); 2035 bio_copy_data(sbio, pbio);
2041 } 2036 }
2042 return 0;
2043} 2037}
2044 2038
2045static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio) 2039static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
@@ -2057,8 +2051,8 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
2057 return; 2051 return;
2058 2052
2059 if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) 2053 if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
2060 if (process_checks(r1_bio) < 0) 2054 process_checks(r1_bio);
2061 return; 2055
2062 /* 2056 /*
2063 * schedule writes 2057 * schedule writes
2064 */ 2058 */
@@ -2458,7 +2452,6 @@ static void raid1d(struct md_thread *thread)
2458 blk_finish_plug(&plug); 2452 blk_finish_plug(&plug);
2459} 2453}
2460 2454
2461
2462static int init_resync(struct r1conf *conf) 2455static int init_resync(struct r1conf *conf)
2463{ 2456{
2464 int buffs; 2457 int buffs;
@@ -2722,7 +2715,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
2722 /* remove last page from this bio */ 2715 /* remove last page from this bio */
2723 bio->bi_vcnt--; 2716 bio->bi_vcnt--;
2724 bio->bi_iter.bi_size -= len; 2717 bio->bi_iter.bi_size -= len;
2725 bio->bi_flags &= ~(1<< BIO_SEG_VALID); 2718 __clear_bit(BIO_SEG_VALID, &bio->bi_flags);
2726 } 2719 }
2727 goto bio_full; 2720 goto bio_full;
2728 } 2721 }
@@ -2947,9 +2940,9 @@ static int run(struct mddev *mddev)
2947 printk(KERN_NOTICE "md/raid1:%s: not clean" 2940 printk(KERN_NOTICE "md/raid1:%s: not clean"
2948 " -- starting background reconstruction\n", 2941 " -- starting background reconstruction\n",
2949 mdname(mddev)); 2942 mdname(mddev));
2950 printk(KERN_INFO 2943 printk(KERN_INFO
2951 "md/raid1:%s: active with %d out of %d mirrors\n", 2944 "md/raid1:%s: active with %d out of %d mirrors\n",
2952 mdname(mddev), mddev->raid_disks - mddev->degraded, 2945 mdname(mddev), mddev->raid_disks - mddev->degraded,
2953 mddev->raid_disks); 2946 mddev->raid_disks);
2954 2947
2955 /* 2948 /*
diff --git a/drivers/md/raid1.h b/drivers/md/raid1.h
index 9bebca7bff2f..33bda55ef9f7 100644
--- a/drivers/md/raid1.h
+++ b/drivers/md/raid1.h
@@ -90,7 +90,6 @@ struct r1conf {
90 */ 90 */
91 int recovery_disabled; 91 int recovery_disabled;
92 92
93
94 /* poolinfo contains information about the content of the 93 /* poolinfo contains information about the content of the
95 * mempools - it changes when the array grows or shrinks 94 * mempools - it changes when the array grows or shrinks
96 */ 95 */
@@ -103,7 +102,6 @@ struct r1conf {
103 */ 102 */
104 struct page *tmppage; 103 struct page *tmppage;
105 104
106
107 /* When taking over an array from a different personality, we store 105 /* When taking over an array from a different personality, we store
108 * the new thread here until we fully activate the array. 106 * the new thread here until we fully activate the array.
109 */ 107 */
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 6703751d87d7..32e282f4c83c 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -366,7 +366,6 @@ static void raid10_end_read_request(struct bio *bio, int error)
366 struct md_rdev *rdev; 366 struct md_rdev *rdev;
367 struct r10conf *conf = r10_bio->mddev->private; 367 struct r10conf *conf = r10_bio->mddev->private;
368 368
369
370 slot = r10_bio->read_slot; 369 slot = r10_bio->read_slot;
371 dev = r10_bio->devs[slot].devnum; 370 dev = r10_bio->devs[slot].devnum;
372 rdev = r10_bio->devs[slot].rdev; 371 rdev = r10_bio->devs[slot].rdev;
@@ -1559,7 +1558,6 @@ static void make_request(struct mddev *mddev, struct bio *bio)
1559 1558
1560 md_write_start(mddev, bio); 1559 md_write_start(mddev, bio);
1561 1560
1562
1563 do { 1561 do {
1564 1562
1565 /* 1563 /*
@@ -1782,7 +1780,6 @@ static int raid10_spare_active(struct mddev *mddev)
1782 return count; 1780 return count;
1783} 1781}
1784 1782
1785
1786static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev) 1783static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1787{ 1784{
1788 struct r10conf *conf = mddev->private; 1785 struct r10conf *conf = mddev->private;
@@ -1929,7 +1926,6 @@ abort:
1929 return err; 1926 return err;
1930} 1927}
1931 1928
1932
1933static void end_sync_read(struct bio *bio, int error) 1929static void end_sync_read(struct bio *bio, int error)
1934{ 1930{
1935 struct r10bio *r10_bio = bio->bi_private; 1931 struct r10bio *r10_bio = bio->bi_private;
@@ -2295,7 +2291,6 @@ static void recovery_request_write(struct mddev *mddev, struct r10bio *r10_bio)
2295 } 2291 }
2296} 2292}
2297 2293
2298
2299/* 2294/*
2300 * Used by fix_read_error() to decay the per rdev read_errors. 2295 * Used by fix_read_error() to decay the per rdev read_errors.
2301 * We halve the read error count for every hour that has elapsed 2296 * We halve the read error count for every hour that has elapsed
@@ -2852,7 +2847,6 @@ static void raid10d(struct md_thread *thread)
2852 blk_finish_plug(&plug); 2847 blk_finish_plug(&plug);
2853} 2848}
2854 2849
2855
2856static int init_resync(struct r10conf *conf) 2850static int init_resync(struct r10conf *conf)
2857{ 2851{
2858 int buffs; 2852 int buffs;
@@ -3388,7 +3382,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
3388 /* remove last page from this bio */ 3382 /* remove last page from this bio */
3389 bio2->bi_vcnt--; 3383 bio2->bi_vcnt--;
3390 bio2->bi_iter.bi_size -= len; 3384 bio2->bi_iter.bi_size -= len;
3391 bio2->bi_flags &= ~(1<< BIO_SEG_VALID); 3385 __clear_bit(BIO_SEG_VALID, &bio2->bi_flags);
3392 } 3386 }
3393 goto bio_full; 3387 goto bio_full;
3394 } 3388 }
@@ -3776,7 +3770,6 @@ static int run(struct mddev *mddev)
3776 blk_queue_merge_bvec(mddev->queue, raid10_mergeable_bvec); 3770 blk_queue_merge_bvec(mddev->queue, raid10_mergeable_bvec);
3777 } 3771 }
3778 3772
3779
3780 if (md_integrity_register(mddev)) 3773 if (md_integrity_register(mddev))
3781 goto out_free_conf; 3774 goto out_free_conf;
3782 3775
@@ -3834,6 +3827,8 @@ static int stop(struct mddev *mddev)
3834 mempool_destroy(conf->r10bio_pool); 3827 mempool_destroy(conf->r10bio_pool);
3835 safe_put_page(conf->tmppage); 3828 safe_put_page(conf->tmppage);
3836 kfree(conf->mirrors); 3829 kfree(conf->mirrors);
3830 kfree(conf->mirrors_old);
3831 kfree(conf->mirrors_new);
3837 kfree(conf); 3832 kfree(conf);
3838 mddev->private = NULL; 3833 mddev->private = NULL;
3839 return 0; 3834 return 0;
@@ -4121,7 +4116,7 @@ static int raid10_start_reshape(struct mddev *mddev)
4121 memcpy(conf->mirrors_new, conf->mirrors, 4116 memcpy(conf->mirrors_new, conf->mirrors,
4122 sizeof(struct raid10_info)*conf->prev.raid_disks); 4117 sizeof(struct raid10_info)*conf->prev.raid_disks);
4123 smp_mb(); 4118 smp_mb();
4124 kfree(conf->mirrors_old); /* FIXME and elsewhere */ 4119 kfree(conf->mirrors_old);
4125 conf->mirrors_old = conf->mirrors; 4120 conf->mirrors_old = conf->mirrors;
4126 conf->mirrors = conf->mirrors_new; 4121 conf->mirrors = conf->mirrors_new;
4127 conf->mirrors_new = NULL; 4122 conf->mirrors_new = NULL;
@@ -4416,7 +4411,7 @@ read_more:
4416 read_bio->bi_end_io = end_sync_read; 4411 read_bio->bi_end_io = end_sync_read;
4417 read_bio->bi_rw = READ; 4412 read_bio->bi_rw = READ;
4418 read_bio->bi_flags &= (~0UL << BIO_RESET_BITS); 4413 read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
4419 read_bio->bi_flags |= 1 << BIO_UPTODATE; 4414 __set_bit(BIO_UPTODATE, &read_bio->bi_flags);
4420 read_bio->bi_vcnt = 0; 4415 read_bio->bi_vcnt = 0;
4421 read_bio->bi_iter.bi_size = 0; 4416 read_bio->bi_iter.bi_size = 0;
4422 r10_bio->master_bio = read_bio; 4417 r10_bio->master_bio = read_bio;
@@ -4473,7 +4468,7 @@ read_more:
4473 /* Remove last page from this bio */ 4468 /* Remove last page from this bio */
4474 bio2->bi_vcnt--; 4469 bio2->bi_vcnt--;
4475 bio2->bi_iter.bi_size -= len; 4470 bio2->bi_iter.bi_size -= len;
4476 bio2->bi_flags &= ~(1<<BIO_SEG_VALID); 4471 __clear_bit(BIO_SEG_VALID, &bio2->bi_flags);
4477 } 4472 }
4478 goto bio_full; 4473 goto bio_full;
4479 } 4474 }
@@ -4575,7 +4570,6 @@ static void end_reshape(struct r10conf *conf)
4575 conf->fullsync = 0; 4570 conf->fullsync = 0;
4576} 4571}
4577 4572
4578
4579static int handle_reshape_read_error(struct mddev *mddev, 4573static int handle_reshape_read_error(struct mddev *mddev,
4580 struct r10bio *r10_bio) 4574 struct r10bio *r10_bio)
4581{ 4575{
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 9f0fbecd1eb5..9c66e5997fc8 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -463,7 +463,6 @@ static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh)
463 hlist_add_head(&sh->hash, hp); 463 hlist_add_head(&sh->hash, hp);
464} 464}
465 465
466
467/* find an idle stripe, make sure it is unhashed, and return it. */ 466/* find an idle stripe, make sure it is unhashed, and return it. */
468static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash) 467static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash)
469{ 468{
@@ -531,9 +530,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)
531 BUG_ON(stripe_operations_active(sh)); 530 BUG_ON(stripe_operations_active(sh));
532 531
533 pr_debug("init_stripe called, stripe %llu\n", 532 pr_debug("init_stripe called, stripe %llu\n",
534 (unsigned long long)sh->sector); 533 (unsigned long long)sector);
535
536 remove_hash(sh);
537retry: 534retry:
538 seq = read_seqcount_begin(&conf->gen_lock); 535 seq = read_seqcount_begin(&conf->gen_lock);
539 sh->generation = conf->generation - previous; 536 sh->generation = conf->generation - previous;
@@ -542,7 +539,6 @@ retry:
542 stripe_set_idx(sector, conf, previous, sh); 539 stripe_set_idx(sector, conf, previous, sh);
543 sh->state = 0; 540 sh->state = 0;
544 541
545
546 for (i = sh->disks; i--; ) { 542 for (i = sh->disks; i--; ) {
547 struct r5dev *dev = &sh->dev[i]; 543 struct r5dev *dev = &sh->dev[i];
548 544
@@ -1350,7 +1346,6 @@ ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu)
1350 } 1346 }
1351} 1347}
1352 1348
1353
1354static void ops_complete_prexor(void *stripe_head_ref) 1349static void ops_complete_prexor(void *stripe_head_ref)
1355{ 1350{
1356 struct stripe_head *sh = stripe_head_ref; 1351 struct stripe_head *sh = stripe_head_ref;
@@ -2419,7 +2414,6 @@ static sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector,
2419 return new_sector; 2414 return new_sector;
2420} 2415}
2421 2416
2422
2423static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous) 2417static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
2424{ 2418{
2425 struct r5conf *conf = sh->raid_conf; 2419 struct r5conf *conf = sh->raid_conf;
@@ -2437,7 +2431,6 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
2437 sector_t r_sector; 2431 sector_t r_sector;
2438 struct stripe_head sh2; 2432 struct stripe_head sh2;
2439 2433
2440
2441 chunk_offset = sector_div(new_sector, sectors_per_chunk); 2434 chunk_offset = sector_div(new_sector, sectors_per_chunk);
2442 stripe = new_sector; 2435 stripe = new_sector;
2443 2436
@@ -2541,7 +2534,6 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
2541 return r_sector; 2534 return r_sector;
2542} 2535}
2543 2536
2544
2545static void 2537static void
2546schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, 2538schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
2547 int rcw, int expand) 2539 int rcw, int expand)
@@ -3013,7 +3005,6 @@ static void handle_stripe_fill(struct stripe_head *sh,
3013 set_bit(STRIPE_HANDLE, &sh->state); 3005 set_bit(STRIPE_HANDLE, &sh->state);
3014} 3006}
3015 3007
3016
3017/* handle_stripe_clean_event 3008/* handle_stripe_clean_event
3018 * any written block on an uptodate or failed drive can be returned. 3009 * any written block on an uptodate or failed drive can be returned.
3019 * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but 3010 * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but
@@ -3304,7 +3295,6 @@ static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh,
3304 } 3295 }
3305} 3296}
3306 3297
3307
3308static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, 3298static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh,
3309 struct stripe_head_state *s, 3299 struct stripe_head_state *s,
3310 int disks) 3300 int disks)
@@ -3939,7 +3929,6 @@ static void handle_stripe(struct stripe_head *sh)
3939 } 3929 }
3940 } 3930 }
3941 3931
3942
3943 /* Finish reconstruct operations initiated by the expansion process */ 3932 /* Finish reconstruct operations initiated by the expansion process */
3944 if (sh->reconstruct_state == reconstruct_state_result) { 3933 if (sh->reconstruct_state == reconstruct_state_result) {
3945 struct stripe_head *sh_src 3934 struct stripe_head *sh_src
@@ -4137,7 +4126,6 @@ static int raid5_mergeable_bvec(struct request_queue *q,
4137 return max; 4126 return max;
4138} 4127}
4139 4128
4140
4141static int in_chunk_boundary(struct mddev *mddev, struct bio *bio) 4129static int in_chunk_boundary(struct mddev *mddev, struct bio *bio)
4142{ 4130{
4143 sector_t sector = bio->bi_iter.bi_sector + get_start_sect(bio->bi_bdev); 4131 sector_t sector = bio->bi_iter.bi_sector + get_start_sect(bio->bi_bdev);
@@ -4167,7 +4155,6 @@ static void add_bio_to_retry(struct bio *bi,struct r5conf *conf)
4167 md_wakeup_thread(conf->mddev->thread); 4155 md_wakeup_thread(conf->mddev->thread);
4168} 4156}
4169 4157
4170
4171static struct bio *remove_bio_from_retry(struct r5conf *conf) 4158static struct bio *remove_bio_from_retry(struct r5conf *conf)
4172{ 4159{
4173 struct bio *bi; 4160 struct bio *bi;
@@ -4191,7 +4178,6 @@ static struct bio *remove_bio_from_retry(struct r5conf *conf)
4191 return bi; 4178 return bi;
4192} 4179}
4193 4180
4194
4195/* 4181/*
4196 * The "raid5_align_endio" should check if the read succeeded and if it 4182 * The "raid5_align_endio" should check if the read succeeded and if it
4197 * did, call bio_endio on the original bio (having bio_put the new bio 4183 * did, call bio_endio on the original bio (having bio_put the new bio
@@ -4224,7 +4210,6 @@ static void raid5_align_endio(struct bio *bi, int error)
4224 return; 4210 return;
4225 } 4211 }
4226 4212
4227
4228 pr_debug("raid5_align_endio : io error...handing IO for a retry\n"); 4213 pr_debug("raid5_align_endio : io error...handing IO for a retry\n");
4229 4214
4230 add_bio_to_retry(raid_bi, conf); 4215 add_bio_to_retry(raid_bi, conf);
@@ -4249,7 +4234,6 @@ static int bio_fits_rdev(struct bio *bi)
4249 return 1; 4234 return 1;
4250} 4235}
4251 4236
4252
4253static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio) 4237static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
4254{ 4238{
4255 struct r5conf *conf = mddev->private; 4239 struct r5conf *conf = mddev->private;
@@ -4301,7 +4285,7 @@ static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
4301 rcu_read_unlock(); 4285 rcu_read_unlock();
4302 raid_bio->bi_next = (void*)rdev; 4286 raid_bio->bi_next = (void*)rdev;
4303 align_bi->bi_bdev = rdev->bdev; 4287 align_bi->bi_bdev = rdev->bdev;
4304 align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); 4288 __clear_bit(BIO_SEG_VALID, &align_bi->bi_flags);
4305 4289
4306 if (!bio_fits_rdev(align_bi) || 4290 if (!bio_fits_rdev(align_bi) ||
4307 is_badblock(rdev, align_bi->bi_iter.bi_sector, 4291 is_badblock(rdev, align_bi->bi_iter.bi_sector,
@@ -5446,7 +5430,6 @@ raid5_skip_copy = __ATTR(skip_copy, S_IRUGO | S_IWUSR,
5446 raid5_show_skip_copy, 5430 raid5_show_skip_copy,
5447 raid5_store_skip_copy); 5431 raid5_store_skip_copy);
5448 5432
5449
5450static ssize_t 5433static ssize_t
5451stripe_cache_active_show(struct mddev *mddev, char *page) 5434stripe_cache_active_show(struct mddev *mddev, char *page)
5452{ 5435{
@@ -5898,7 +5881,6 @@ static struct r5conf *setup_conf(struct mddev *mddev)
5898 return ERR_PTR(-ENOMEM); 5881 return ERR_PTR(-ENOMEM);
5899} 5882}
5900 5883
5901
5902static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) 5884static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded)
5903{ 5885{
5904 switch (algo) { 5886 switch (algo) {
@@ -5911,7 +5893,7 @@ static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded
5911 return 1; 5893 return 1;
5912 break; 5894 break;
5913 case ALGORITHM_PARITY_0_6: 5895 case ALGORITHM_PARITY_0_6:
5914 if (raid_disk == 0 || 5896 if (raid_disk == 0 ||
5915 raid_disk == raid_disks - 1) 5897 raid_disk == raid_disks - 1)
5916 return 1; 5898 return 1;
5917 break; 5899 break;
@@ -6165,7 +6147,6 @@ static int run(struct mddev *mddev)
6165 "reshape"); 6147 "reshape");
6166 } 6148 }
6167 6149
6168
6169 /* Ok, everything is just fine now */ 6150 /* Ok, everything is just fine now */
6170 if (mddev->to_remove == &raid5_attrs_group) 6151 if (mddev->to_remove == &raid5_attrs_group)
6171 mddev->to_remove = NULL; 6152 mddev->to_remove = NULL;
@@ -6814,7 +6795,6 @@ static void raid5_quiesce(struct mddev *mddev, int state)
6814 } 6795 }
6815} 6796}
6816 6797
6817
6818static void *raid45_takeover_raid0(struct mddev *mddev, int level) 6798static void *raid45_takeover_raid0(struct mddev *mddev, int level)
6819{ 6799{
6820 struct r0conf *raid0_conf = mddev->private; 6800 struct r0conf *raid0_conf = mddev->private;
@@ -6841,7 +6821,6 @@ static void *raid45_takeover_raid0(struct mddev *mddev, int level)
6841 return setup_conf(mddev); 6821 return setup_conf(mddev);
6842} 6822}
6843 6823
6844
6845static void *raid5_takeover_raid1(struct mddev *mddev) 6824static void *raid5_takeover_raid1(struct mddev *mddev)
6846{ 6825{
6847 int chunksect; 6826 int chunksect;
@@ -6902,7 +6881,6 @@ static void *raid5_takeover_raid6(struct mddev *mddev)
6902 return setup_conf(mddev); 6881 return setup_conf(mddev);
6903} 6882}
6904 6883
6905
6906static int raid5_check_reshape(struct mddev *mddev) 6884static int raid5_check_reshape(struct mddev *mddev)
6907{ 6885{
6908 /* For a 2-drive array, the layout and chunk size can be changed 6886 /* For a 2-drive array, the layout and chunk size can be changed
@@ -7051,7 +7029,6 @@ static void *raid6_takeover(struct mddev *mddev)
7051 return setup_conf(mddev); 7029 return setup_conf(mddev);
7052} 7030}
7053 7031
7054
7055static struct md_personality raid6_personality = 7032static struct md_personality raid6_personality =
7056{ 7033{
7057 .name = "raid6", 7034 .name = "raid6",
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index bc72cd4be5f8..d59f5ca743cd 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -155,7 +155,7 @@
155 */ 155 */
156 156
157/* 157/*
158 * Operations state - intermediate states that are visible outside of 158 * Operations state - intermediate states that are visible outside of
159 * STRIPE_ACTIVE. 159 * STRIPE_ACTIVE.
160 * In general _idle indicates nothing is running, _run indicates a data 160 * In general _idle indicates nothing is running, _run indicates a data
161 * processing operation is active, and _result means the data processing result 161 * processing operation is active, and _result means the data processing result
@@ -364,7 +364,6 @@ enum {
364 * HANDLE gets cleared if stripe_handle leaves nothing locked. 364 * HANDLE gets cleared if stripe_handle leaves nothing locked.
365 */ 365 */
366 366
367
368struct disk_info { 367struct disk_info {
369 struct md_rdev *rdev, *replacement; 368 struct md_rdev *rdev, *replacement;
370}; 369};
@@ -528,7 +527,6 @@ struct r5conf {
528#define ALGORITHM_ROTATING_N_RESTART 9 /* DDF PRL=6 RLQ=2 */ 527#define ALGORITHM_ROTATING_N_RESTART 9 /* DDF PRL=6 RLQ=2 */
529#define ALGORITHM_ROTATING_N_CONTINUE 10 /*DDF PRL=6 RLQ=3 */ 528#define ALGORITHM_ROTATING_N_CONTINUE 10 /*DDF PRL=6 RLQ=3 */
530 529
531
532/* For every RAID5 algorithm we define a RAID6 algorithm 530/* For every RAID5 algorithm we define a RAID6 algorithm
533 * with exactly the same layout for data and parity, and 531 * with exactly the same layout for data and parity, and
534 * with the Q block always on the last device (N-1). 532 * with the Q block always on the last device (N-1).