aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/bcache/super.c1
-rw-r--r--drivers/md/bitmap.c16
-rw-r--r--drivers/md/dm-bufio.c1
-rw-r--r--drivers/md/dm-crypt.c34
-rw-r--r--drivers/md/dm-stats.c2
-rw-r--r--drivers/md/linear.c8
-rw-r--r--drivers/md/md.c605
-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.c77
-rw-r--r--drivers/md/raid1.h2
-rw-r--r--drivers/md/raid10.c18
-rw-r--r--drivers/md/raid5.c47
-rw-r--r--drivers/md/raid5.h4
15 files changed, 319 insertions, 567 deletions
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index d4713d098a39..4dd2bb7167f0 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -842,6 +842,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
842 q->limits.logical_block_size = block_size; 842 q->limits.logical_block_size = block_size;
843 q->limits.physical_block_size = block_size; 843 q->limits.physical_block_size = block_size;
844 set_bit(QUEUE_FLAG_NONROT, &d->disk->queue->queue_flags); 844 set_bit(QUEUE_FLAG_NONROT, &d->disk->queue->queue_flags);
845 clear_bit(QUEUE_FLAG_ADD_RANDOM, &d->disk->queue->queue_flags);
845 set_bit(QUEUE_FLAG_DISCARD, &d->disk->queue->queue_flags); 846 set_bit(QUEUE_FLAG_DISCARD, &d->disk->queue->queue_flags);
846 847
847 blk_queue_flush(q, REQ_FLUSH|REQ_FUA); 848 blk_queue_flush(q, REQ_FLUSH|REQ_FUA);
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/dm-bufio.c b/drivers/md/dm-bufio.c
index 9a4b1bf6f3f4..c33b49792b87 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -785,7 +785,6 @@ static void __wait_for_free_buffer(struct dm_bufio_client *c)
785 785
786 io_schedule(); 786 io_schedule();
787 787
788 set_task_state(current, TASK_RUNNING);
789 remove_wait_queue(&c->free_buffer_wait, &wait); 788 remove_wait_queue(&c->free_buffer_wait, &wait);
790 789
791 dm_bufio_lock(c); 790 dm_bufio_lock(c);
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index ce11a90a33c3..08981be7baa1 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -526,29 +526,26 @@ static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
526 u8 *data) 526 u8 *data)
527{ 527{
528 struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk; 528 struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk;
529 struct { 529 SHASH_DESC_ON_STACK(desc, lmk->hash_tfm);
530 struct shash_desc desc;
531 char ctx[crypto_shash_descsize(lmk->hash_tfm)];
532 } sdesc;
533 struct md5_state md5state; 530 struct md5_state md5state;
534 __le32 buf[4]; 531 __le32 buf[4];
535 int i, r; 532 int i, r;
536 533
537 sdesc.desc.tfm = lmk->hash_tfm; 534 desc->tfm = lmk->hash_tfm;
538 sdesc.desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP; 535 desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
539 536
540 r = crypto_shash_init(&sdesc.desc); 537 r = crypto_shash_init(desc);
541 if (r) 538 if (r)
542 return r; 539 return r;
543 540
544 if (lmk->seed) { 541 if (lmk->seed) {
545 r = crypto_shash_update(&sdesc.desc, lmk->seed, LMK_SEED_SIZE); 542 r = crypto_shash_update(desc, lmk->seed, LMK_SEED_SIZE);
546 if (r) 543 if (r)
547 return r; 544 return r;
548 } 545 }
549 546
550 /* Sector is always 512B, block size 16, add data of blocks 1-31 */ 547 /* Sector is always 512B, block size 16, add data of blocks 1-31 */
551 r = crypto_shash_update(&sdesc.desc, data + 16, 16 * 31); 548 r = crypto_shash_update(desc, data + 16, 16 * 31);
552 if (r) 549 if (r)
553 return r; 550 return r;
554 551
@@ -557,12 +554,12 @@ static int crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
557 buf[1] = cpu_to_le32((((u64)dmreq->iv_sector >> 32) & 0x00FFFFFF) | 0x80000000); 554 buf[1] = cpu_to_le32((((u64)dmreq->iv_sector >> 32) & 0x00FFFFFF) | 0x80000000);
558 buf[2] = cpu_to_le32(4024); 555 buf[2] = cpu_to_le32(4024);
559 buf[3] = 0; 556 buf[3] = 0;
560 r = crypto_shash_update(&sdesc.desc, (u8 *)buf, sizeof(buf)); 557 r = crypto_shash_update(desc, (u8 *)buf, sizeof(buf));
561 if (r) 558 if (r)
562 return r; 559 return r;
563 560
564 /* No MD5 padding here */ 561 /* No MD5 padding here */
565 r = crypto_shash_export(&sdesc.desc, &md5state); 562 r = crypto_shash_export(desc, &md5state);
566 if (r) 563 if (r)
567 return r; 564 return r;
568 565
@@ -679,10 +676,7 @@ static int crypt_iv_tcw_whitening(struct crypt_config *cc,
679 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw; 676 struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw;
680 u64 sector = cpu_to_le64((u64)dmreq->iv_sector); 677 u64 sector = cpu_to_le64((u64)dmreq->iv_sector);
681 u8 buf[TCW_WHITENING_SIZE]; 678 u8 buf[TCW_WHITENING_SIZE];
682 struct { 679 SHASH_DESC_ON_STACK(desc, tcw->crc32_tfm);
683 struct shash_desc desc;
684 char ctx[crypto_shash_descsize(tcw->crc32_tfm)];
685 } sdesc;
686 int i, r; 680 int i, r;
687 681
688 /* xor whitening with sector number */ 682 /* xor whitening with sector number */
@@ -691,16 +685,16 @@ static int crypt_iv_tcw_whitening(struct crypt_config *cc,
691 crypto_xor(&buf[8], (u8 *)&sector, 8); 685 crypto_xor(&buf[8], (u8 *)&sector, 8);
692 686
693 /* calculate crc32 for every 32bit part and xor it */ 687 /* calculate crc32 for every 32bit part and xor it */
694 sdesc.desc.tfm = tcw->crc32_tfm; 688 desc->tfm = tcw->crc32_tfm;
695 sdesc.desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP; 689 desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
696 for (i = 0; i < 4; i++) { 690 for (i = 0; i < 4; i++) {
697 r = crypto_shash_init(&sdesc.desc); 691 r = crypto_shash_init(desc);
698 if (r) 692 if (r)
699 goto out; 693 goto out;
700 r = crypto_shash_update(&sdesc.desc, &buf[i * 4], 4); 694 r = crypto_shash_update(desc, &buf[i * 4], 4);
701 if (r) 695 if (r)
702 goto out; 696 goto out;
703 r = crypto_shash_final(&sdesc.desc, &buf[i * 4]); 697 r = crypto_shash_final(desc, &buf[i * 4]);
704 if (r) 698 if (r)
705 goto out; 699 goto out;
706 } 700 }
diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
index 42a057aa3811..f478a4c96d2f 100644
--- a/drivers/md/dm-stats.c
+++ b/drivers/md/dm-stats.c
@@ -548,7 +548,7 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
548 * A race condition can at worst result in the merged flag being 548 * A race condition can at worst result in the merged flag being
549 * misrepresented, so we don't have to disable preemption here. 549 * misrepresented, so we don't have to disable preemption here.
550 */ 550 */
551 last = __this_cpu_ptr(stats->last); 551 last = raw_cpu_ptr(stats->last);
552 stats_aux->merged = 552 stats_aux->merged =
553 (bi_sector == (ACCESS_ONCE(last->last_sector) && 553 (bi_sector == (ACCESS_ONCE(last->last_sector) &&
554 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) == 554 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
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..9233c71138f1 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,12 +5115,13 @@ 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));
5314 if (did_freeze) { 5122 if (did_freeze) {
5315 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 5123 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
5124 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5316 md_wakeup_thread(mddev->thread); 5125 md_wakeup_thread(mddev->thread);
5317 } 5126 }
5318 err = -EBUSY; 5127 err = -EBUSY;
@@ -5327,6 +5136,8 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
5327 mddev->ro = 1; 5136 mddev->ro = 1;
5328 set_disk_ro(mddev->gendisk, 1); 5137 set_disk_ro(mddev->gendisk, 1);
5329 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 5138 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
5139 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5140 md_wakeup_thread(mddev->thread);
5330 sysfs_notify_dirent_safe(mddev->sysfs_state); 5141 sysfs_notify_dirent_safe(mddev->sysfs_state);
5331 err = 0; 5142 err = 0;
5332 } 5143 }
@@ -5339,7 +5150,7 @@ out:
5339 * 0 - completely stop and dis-assemble array 5150 * 0 - completely stop and dis-assemble array
5340 * 2 - stop but do not disassemble array 5151 * 2 - stop but do not disassemble array
5341 */ 5152 */
5342static int do_md_stop(struct mddev * mddev, int mode, 5153static int do_md_stop(struct mddev *mddev, int mode,
5343 struct block_device *bdev) 5154 struct block_device *bdev)
5344{ 5155{
5345 struct gendisk *disk = mddev->gendisk; 5156 struct gendisk *disk = mddev->gendisk;
@@ -5362,7 +5173,7 @@ static int do_md_stop(struct mddev * mddev, int mode,
5362 mddev_lock_nointr(mddev); 5173 mddev_lock_nointr(mddev);
5363 5174
5364 mutex_lock(&mddev->open_mutex); 5175 mutex_lock(&mddev->open_mutex);
5365 if (atomic_read(&mddev->openers) > !!bdev || 5176 if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
5366 mddev->sysfs_active || 5177 mddev->sysfs_active ||
5367 mddev->sync_thread || 5178 mddev->sync_thread ||
5368 (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) { 5179 (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
@@ -5370,6 +5181,7 @@ static int do_md_stop(struct mddev * mddev, int mode,
5370 mutex_unlock(&mddev->open_mutex); 5181 mutex_unlock(&mddev->open_mutex);
5371 if (did_freeze) { 5182 if (did_freeze) {
5372 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 5183 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
5184 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5373 md_wakeup_thread(mddev->thread); 5185 md_wakeup_thread(mddev->thread);
5374 } 5186 }
5375 return -EBUSY; 5187 return -EBUSY;
@@ -5512,12 +5324,12 @@ static void autorun_devices(int part)
5512 "md: cannot allocate memory for md drive.\n"); 5324 "md: cannot allocate memory for md drive.\n");
5513 break; 5325 break;
5514 } 5326 }
5515 if (mddev_lock(mddev)) 5327 if (mddev_lock(mddev))
5516 printk(KERN_WARNING "md: %s locked, cannot run\n", 5328 printk(KERN_WARNING "md: %s locked, cannot run\n",
5517 mdname(mddev)); 5329 mdname(mddev));
5518 else if (mddev->raid_disks || mddev->major_version 5330 else if (mddev->raid_disks || mddev->major_version
5519 || !list_empty(&mddev->disks)) { 5331 || !list_empty(&mddev->disks)) {
5520 printk(KERN_WARNING 5332 printk(KERN_WARNING
5521 "md: %s already running, cannot run %s\n", 5333 "md: %s already running, cannot run %s\n",
5522 mdname(mddev), bdevname(rdev0->bdev,b)); 5334 mdname(mddev), bdevname(rdev0->bdev,b));
5523 mddev_unlock(mddev); 5335 mddev_unlock(mddev);
@@ -5545,7 +5357,7 @@ static void autorun_devices(int part)
5545} 5357}
5546#endif /* !MODULE */ 5358#endif /* !MODULE */
5547 5359
5548static int get_version(void __user * arg) 5360static int get_version(void __user *arg)
5549{ 5361{
5550 mdu_version_t ver; 5362 mdu_version_t ver;
5551 5363
@@ -5559,7 +5371,7 @@ static int get_version(void __user * arg)
5559 return 0; 5371 return 0;
5560} 5372}
5561 5373
5562static int get_array_info(struct mddev * mddev, void __user * arg) 5374static int get_array_info(struct mddev *mddev, void __user *arg)
5563{ 5375{
5564 mdu_array_info_t info; 5376 mdu_array_info_t info;
5565 int nr,working,insync,failed,spare; 5377 int nr,working,insync,failed,spare;
@@ -5574,7 +5386,7 @@ static int get_array_info(struct mddev * mddev, void __user * arg)
5574 else { 5386 else {
5575 working++; 5387 working++;
5576 if (test_bit(In_sync, &rdev->flags)) 5388 if (test_bit(In_sync, &rdev->flags))
5577 insync++; 5389 insync++;
5578 else 5390 else
5579 spare++; 5391 spare++;
5580 } 5392 }
@@ -5614,7 +5426,7 @@ static int get_array_info(struct mddev * mddev, void __user * arg)
5614 return 0; 5426 return 0;
5615} 5427}
5616 5428
5617static int get_bitmap_file(struct mddev * mddev, void __user * arg) 5429static int get_bitmap_file(struct mddev *mddev, void __user * arg)
5618{ 5430{
5619 mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ 5431 mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */
5620 char *ptr, *buf = NULL; 5432 char *ptr, *buf = NULL;
@@ -5652,7 +5464,7 @@ out:
5652 return err; 5464 return err;
5653} 5465}
5654 5466
5655static int get_disk_info(struct mddev * mddev, void __user * arg) 5467static int get_disk_info(struct mddev *mddev, void __user * arg)
5656{ 5468{
5657 mdu_disk_info_t info; 5469 mdu_disk_info_t info;
5658 struct md_rdev *rdev; 5470 struct md_rdev *rdev;
@@ -5688,7 +5500,7 @@ static int get_disk_info(struct mddev * mddev, void __user * arg)
5688 return 0; 5500 return 0;
5689} 5501}
5690 5502
5691static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info) 5503static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
5692{ 5504{
5693 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; 5505 char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
5694 struct md_rdev *rdev; 5506 struct md_rdev *rdev;
@@ -5702,7 +5514,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5702 /* expecting a device which has a superblock */ 5514 /* expecting a device which has a superblock */
5703 rdev = md_import_device(dev, mddev->major_version, mddev->minor_version); 5515 rdev = md_import_device(dev, mddev->major_version, mddev->minor_version);
5704 if (IS_ERR(rdev)) { 5516 if (IS_ERR(rdev)) {
5705 printk(KERN_WARNING 5517 printk(KERN_WARNING
5706 "md: md_import_device returned %ld\n", 5518 "md: md_import_device returned %ld\n",
5707 PTR_ERR(rdev)); 5519 PTR_ERR(rdev));
5708 return PTR_ERR(rdev); 5520 return PTR_ERR(rdev);
@@ -5714,9 +5526,9 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5714 err = super_types[mddev->major_version] 5526 err = super_types[mddev->major_version]
5715 .load_super(rdev, rdev0, mddev->minor_version); 5527 .load_super(rdev, rdev0, mddev->minor_version);
5716 if (err < 0) { 5528 if (err < 0) {
5717 printk(KERN_WARNING 5529 printk(KERN_WARNING
5718 "md: %s has different UUID to %s\n", 5530 "md: %s has different UUID to %s\n",
5719 bdevname(rdev->bdev,b), 5531 bdevname(rdev->bdev,b),
5720 bdevname(rdev0->bdev,b2)); 5532 bdevname(rdev0->bdev,b2));
5721 export_rdev(rdev); 5533 export_rdev(rdev);
5722 return -EINVAL; 5534 return -EINVAL;
@@ -5736,7 +5548,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5736 if (mddev->pers) { 5548 if (mddev->pers) {
5737 int err; 5549 int err;
5738 if (!mddev->pers->hot_add_disk) { 5550 if (!mddev->pers->hot_add_disk) {
5739 printk(KERN_WARNING 5551 printk(KERN_WARNING
5740 "%s: personality does not support diskops!\n", 5552 "%s: personality does not support diskops!\n",
5741 mdname(mddev)); 5553 mdname(mddev));
5742 return -EINVAL; 5554 return -EINVAL;
@@ -5747,7 +5559,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5747 else 5559 else
5748 rdev = md_import_device(dev, -1, -1); 5560 rdev = md_import_device(dev, -1, -1);
5749 if (IS_ERR(rdev)) { 5561 if (IS_ERR(rdev)) {
5750 printk(KERN_WARNING 5562 printk(KERN_WARNING
5751 "md: md_import_device returned %ld\n", 5563 "md: md_import_device returned %ld\n",
5752 PTR_ERR(rdev)); 5564 PTR_ERR(rdev));
5753 return PTR_ERR(rdev); 5565 return PTR_ERR(rdev);
@@ -5821,7 +5633,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5821 int err; 5633 int err;
5822 rdev = md_import_device(dev, -1, 0); 5634 rdev = md_import_device(dev, -1, 0);
5823 if (IS_ERR(rdev)) { 5635 if (IS_ERR(rdev)) {
5824 printk(KERN_WARNING 5636 printk(KERN_WARNING
5825 "md: error, md_import_device() returned %ld\n", 5637 "md: error, md_import_device() returned %ld\n",
5826 PTR_ERR(rdev)); 5638 PTR_ERR(rdev));
5827 return PTR_ERR(rdev); 5639 return PTR_ERR(rdev);
@@ -5856,7 +5668,7 @@ static int add_new_disk(struct mddev * mddev, mdu_disk_info_t *info)
5856 return 0; 5668 return 0;
5857} 5669}
5858 5670
5859static int hot_remove_disk(struct mddev * mddev, dev_t dev) 5671static int hot_remove_disk(struct mddev *mddev, dev_t dev)
5860{ 5672{
5861 char b[BDEVNAME_SIZE]; 5673 char b[BDEVNAME_SIZE];
5862 struct md_rdev *rdev; 5674 struct md_rdev *rdev;
@@ -5882,7 +5694,7 @@ busy:
5882 return -EBUSY; 5694 return -EBUSY;
5883} 5695}
5884 5696
5885static int hot_add_disk(struct mddev * mddev, dev_t dev) 5697static int hot_add_disk(struct mddev *mddev, dev_t dev)
5886{ 5698{
5887 char b[BDEVNAME_SIZE]; 5699 char b[BDEVNAME_SIZE];
5888 int err; 5700 int err;
@@ -5898,7 +5710,7 @@ static int hot_add_disk(struct mddev * mddev, dev_t dev)
5898 return -EINVAL; 5710 return -EINVAL;
5899 } 5711 }
5900 if (!mddev->pers->hot_add_disk) { 5712 if (!mddev->pers->hot_add_disk) {
5901 printk(KERN_WARNING 5713 printk(KERN_WARNING
5902 "%s: personality does not support diskops!\n", 5714 "%s: personality does not support diskops!\n",
5903 mdname(mddev)); 5715 mdname(mddev));
5904 return -EINVAL; 5716 return -EINVAL;
@@ -5906,7 +5718,7 @@ static int hot_add_disk(struct mddev * mddev, dev_t dev)
5906 5718
5907 rdev = md_import_device(dev, -1, 0); 5719 rdev = md_import_device(dev, -1, 0);
5908 if (IS_ERR(rdev)) { 5720 if (IS_ERR(rdev)) {
5909 printk(KERN_WARNING 5721 printk(KERN_WARNING
5910 "md: error, md_import_device() returned %ld\n", 5722 "md: error, md_import_device() returned %ld\n",
5911 PTR_ERR(rdev)); 5723 PTR_ERR(rdev));
5912 return -EINVAL; 5724 return -EINVAL;
@@ -5920,7 +5732,7 @@ static int hot_add_disk(struct mddev * mddev, dev_t dev)
5920 rdev->sectors = rdev->sb_start; 5732 rdev->sectors = rdev->sb_start;
5921 5733
5922 if (test_bit(Faulty, &rdev->flags)) { 5734 if (test_bit(Faulty, &rdev->flags)) {
5923 printk(KERN_WARNING 5735 printk(KERN_WARNING
5924 "md: can not hot-add faulty %s disk to %s!\n", 5736 "md: can not hot-add faulty %s disk to %s!\n",
5925 bdevname(rdev->bdev,b), mdname(mddev)); 5737 bdevname(rdev->bdev,b), mdname(mddev));
5926 err = -EINVAL; 5738 err = -EINVAL;
@@ -5968,7 +5780,6 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
5968 /* we should be able to change the bitmap.. */ 5780 /* we should be able to change the bitmap.. */
5969 } 5781 }
5970 5782
5971
5972 if (fd >= 0) { 5783 if (fd >= 0) {
5973 struct inode *inode; 5784 struct inode *inode;
5974 if (mddev->bitmap) 5785 if (mddev->bitmap)
@@ -6039,7 +5850,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
6039 * The minor and patch _version numbers are also kept incase the 5850 * The minor and patch _version numbers are also kept incase the
6040 * super_block handler wishes to interpret them. 5851 * super_block handler wishes to interpret them.
6041 */ 5852 */
6042static int set_array_info(struct mddev * mddev, mdu_array_info_t *info) 5853static int set_array_info(struct mddev *mddev, mdu_array_info_t *info)
6043{ 5854{
6044 5855
6045 if (info->raid_disks == 0) { 5856 if (info->raid_disks == 0) {
@@ -6048,7 +5859,7 @@ static int set_array_info(struct mddev * mddev, mdu_array_info_t *info)
6048 info->major_version >= ARRAY_SIZE(super_types) || 5859 info->major_version >= ARRAY_SIZE(super_types) ||
6049 super_types[info->major_version].name == NULL) { 5860 super_types[info->major_version].name == NULL) {
6050 /* maybe try to auto-load a module? */ 5861 /* maybe try to auto-load a module? */
6051 printk(KERN_INFO 5862 printk(KERN_INFO
6052 "md: superblock version %d not known\n", 5863 "md: superblock version %d not known\n",
6053 info->major_version); 5864 info->major_version);
6054 return -EINVAL; 5865 return -EINVAL;
@@ -6196,7 +6007,6 @@ static int update_raid_disks(struct mddev *mddev, int raid_disks)
6196 return rv; 6007 return rv;
6197} 6008}
6198 6009
6199
6200/* 6010/*
6201 * update_array_info is used to change the configuration of an 6011 * update_array_info is used to change the configuration of an
6202 * on-line array. 6012 * on-line array.
@@ -6347,7 +6157,6 @@ static inline bool md_ioctl_valid(unsigned int cmd)
6347 case GET_DISK_INFO: 6157 case GET_DISK_INFO:
6348 case HOT_ADD_DISK: 6158 case HOT_ADD_DISK:
6349 case HOT_REMOVE_DISK: 6159 case HOT_REMOVE_DISK:
6350 case PRINT_RAID_DEBUG:
6351 case RAID_AUTORUN: 6160 case RAID_AUTORUN:
6352 case RAID_VERSION: 6161 case RAID_VERSION:
6353 case RESTART_ARRAY_RW: 6162 case RESTART_ARRAY_RW:
@@ -6391,18 +6200,13 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6391 switch (cmd) { 6200 switch (cmd) {
6392 case RAID_VERSION: 6201 case RAID_VERSION:
6393 err = get_version(argp); 6202 err = get_version(argp);
6394 goto done; 6203 goto out;
6395
6396 case PRINT_RAID_DEBUG:
6397 err = 0;
6398 md_print_devices();
6399 goto done;
6400 6204
6401#ifndef MODULE 6205#ifndef MODULE
6402 case RAID_AUTORUN: 6206 case RAID_AUTORUN:
6403 err = 0; 6207 err = 0;
6404 autostart_arrays(arg); 6208 autostart_arrays(arg);
6405 goto done; 6209 goto out;
6406#endif 6210#endif
6407 default:; 6211 default:;
6408 } 6212 }
@@ -6415,7 +6219,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6415 6219
6416 if (!mddev) { 6220 if (!mddev) {
6417 BUG(); 6221 BUG();
6418 goto abort; 6222 goto out;
6419 } 6223 }
6420 6224
6421 /* Some actions do not requires the mutex */ 6225 /* Some actions do not requires the mutex */
@@ -6425,18 +6229,18 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6425 err = -ENODEV; 6229 err = -ENODEV;
6426 else 6230 else
6427 err = get_array_info(mddev, argp); 6231 err = get_array_info(mddev, argp);
6428 goto abort; 6232 goto out;
6429 6233
6430 case GET_DISK_INFO: 6234 case GET_DISK_INFO:
6431 if (!mddev->raid_disks && !mddev->external) 6235 if (!mddev->raid_disks && !mddev->external)
6432 err = -ENODEV; 6236 err = -ENODEV;
6433 else 6237 else
6434 err = get_disk_info(mddev, argp); 6238 err = get_disk_info(mddev, argp);
6435 goto abort; 6239 goto out;
6436 6240
6437 case SET_DISK_FAULTY: 6241 case SET_DISK_FAULTY:
6438 err = set_disk_faulty(mddev, new_decode_dev(arg)); 6242 err = set_disk_faulty(mddev, new_decode_dev(arg));
6439 goto abort; 6243 goto out;
6440 } 6244 }
6441 6245
6442 if (cmd == ADD_NEW_DISK) 6246 if (cmd == ADD_NEW_DISK)
@@ -6454,10 +6258,10 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6454 * and writes 6258 * and writes
6455 */ 6259 */
6456 mutex_lock(&mddev->open_mutex); 6260 mutex_lock(&mddev->open_mutex);
6457 if (atomic_read(&mddev->openers) > 1) { 6261 if (mddev->pers && atomic_read(&mddev->openers) > 1) {
6458 mutex_unlock(&mddev->open_mutex); 6262 mutex_unlock(&mddev->open_mutex);
6459 err = -EBUSY; 6263 err = -EBUSY;
6460 goto abort; 6264 goto out;
6461 } 6265 }
6462 set_bit(MD_STILL_CLOSED, &mddev->flags); 6266 set_bit(MD_STILL_CLOSED, &mddev->flags);
6463 mutex_unlock(&mddev->open_mutex); 6267 mutex_unlock(&mddev->open_mutex);
@@ -6465,10 +6269,10 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6465 } 6269 }
6466 err = mddev_lock(mddev); 6270 err = mddev_lock(mddev);
6467 if (err) { 6271 if (err) {
6468 printk(KERN_INFO 6272 printk(KERN_INFO
6469 "md: ioctl lock interrupted, reason %d, cmd %d\n", 6273 "md: ioctl lock interrupted, reason %d, cmd %d\n",
6470 err, cmd); 6274 err, cmd);
6471 goto abort; 6275 goto out;
6472 } 6276 }
6473 6277
6474 if (cmd == SET_ARRAY_INFO) { 6278 if (cmd == SET_ARRAY_INFO) {
@@ -6477,38 +6281,38 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6477 memset(&info, 0, sizeof(info)); 6281 memset(&info, 0, sizeof(info));
6478 else if (copy_from_user(&info, argp, sizeof(info))) { 6282 else if (copy_from_user(&info, argp, sizeof(info))) {
6479 err = -EFAULT; 6283 err = -EFAULT;
6480 goto abort_unlock; 6284 goto unlock;
6481 } 6285 }
6482 if (mddev->pers) { 6286 if (mddev->pers) {
6483 err = update_array_info(mddev, &info); 6287 err = update_array_info(mddev, &info);
6484 if (err) { 6288 if (err) {
6485 printk(KERN_WARNING "md: couldn't update" 6289 printk(KERN_WARNING "md: couldn't update"
6486 " array info. %d\n", err); 6290 " array info. %d\n", err);
6487 goto abort_unlock; 6291 goto unlock;
6488 } 6292 }
6489 goto done_unlock; 6293 goto unlock;
6490 } 6294 }
6491 if (!list_empty(&mddev->disks)) { 6295 if (!list_empty(&mddev->disks)) {
6492 printk(KERN_WARNING 6296 printk(KERN_WARNING
6493 "md: array %s already has disks!\n", 6297 "md: array %s already has disks!\n",
6494 mdname(mddev)); 6298 mdname(mddev));
6495 err = -EBUSY; 6299 err = -EBUSY;
6496 goto abort_unlock; 6300 goto unlock;
6497 } 6301 }
6498 if (mddev->raid_disks) { 6302 if (mddev->raid_disks) {
6499 printk(KERN_WARNING 6303 printk(KERN_WARNING
6500 "md: array %s already initialised!\n", 6304 "md: array %s already initialised!\n",
6501 mdname(mddev)); 6305 mdname(mddev));
6502 err = -EBUSY; 6306 err = -EBUSY;
6503 goto abort_unlock; 6307 goto unlock;
6504 } 6308 }
6505 err = set_array_info(mddev, &info); 6309 err = set_array_info(mddev, &info);
6506 if (err) { 6310 if (err) {
6507 printk(KERN_WARNING "md: couldn't set" 6311 printk(KERN_WARNING "md: couldn't set"
6508 " array info. %d\n", err); 6312 " array info. %d\n", err);
6509 goto abort_unlock; 6313 goto unlock;
6510 } 6314 }
6511 goto done_unlock; 6315 goto unlock;
6512 } 6316 }
6513 6317
6514 /* 6318 /*
@@ -6521,7 +6325,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6521 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE 6325 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE
6522 && cmd != GET_BITMAP_FILE) { 6326 && cmd != GET_BITMAP_FILE) {
6523 err = -ENODEV; 6327 err = -ENODEV;
6524 goto abort_unlock; 6328 goto unlock;
6525 } 6329 }
6526 6330
6527 /* 6331 /*
@@ -6530,23 +6334,23 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6530 switch (cmd) { 6334 switch (cmd) {
6531 case GET_BITMAP_FILE: 6335 case GET_BITMAP_FILE:
6532 err = get_bitmap_file(mddev, argp); 6336 err = get_bitmap_file(mddev, argp);
6533 goto done_unlock; 6337 goto unlock;
6534 6338
6535 case RESTART_ARRAY_RW: 6339 case RESTART_ARRAY_RW:
6536 err = restart_array(mddev); 6340 err = restart_array(mddev);
6537 goto done_unlock; 6341 goto unlock;
6538 6342
6539 case STOP_ARRAY: 6343 case STOP_ARRAY:
6540 err = do_md_stop(mddev, 0, bdev); 6344 err = do_md_stop(mddev, 0, bdev);
6541 goto done_unlock; 6345 goto unlock;
6542 6346
6543 case STOP_ARRAY_RO: 6347 case STOP_ARRAY_RO:
6544 err = md_set_readonly(mddev, bdev); 6348 err = md_set_readonly(mddev, bdev);
6545 goto done_unlock; 6349 goto unlock;
6546 6350
6547 case HOT_REMOVE_DISK: 6351 case HOT_REMOVE_DISK:
6548 err = hot_remove_disk(mddev, new_decode_dev(arg)); 6352 err = hot_remove_disk(mddev, new_decode_dev(arg));
6549 goto done_unlock; 6353 goto unlock;
6550 6354
6551 case ADD_NEW_DISK: 6355 case ADD_NEW_DISK:
6552 /* We can support ADD_NEW_DISK on read-only arrays 6356 /* We can support ADD_NEW_DISK on read-only arrays
@@ -6562,14 +6366,14 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6562 break; 6366 break;
6563 else 6367 else
6564 err = add_new_disk(mddev, &info); 6368 err = add_new_disk(mddev, &info);
6565 goto done_unlock; 6369 goto unlock;
6566 } 6370 }
6567 break; 6371 break;
6568 6372
6569 case BLKROSET: 6373 case BLKROSET:
6570 if (get_user(ro, (int __user *)(arg))) { 6374 if (get_user(ro, (int __user *)(arg))) {
6571 err = -EFAULT; 6375 err = -EFAULT;
6572 goto done_unlock; 6376 goto unlock;
6573 } 6377 }
6574 err = -EINVAL; 6378 err = -EINVAL;
6575 6379
@@ -6577,11 +6381,11 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6577 * does not matter, no writes are coming 6381 * does not matter, no writes are coming
6578 */ 6382 */
6579 if (ro) 6383 if (ro)
6580 goto done_unlock; 6384 goto unlock;
6581 6385
6582 /* are we are already prepared for writes? */ 6386 /* are we are already prepared for writes? */
6583 if (mddev->ro != 1) 6387 if (mddev->ro != 1)
6584 goto done_unlock; 6388 goto unlock;
6585 6389
6586 /* transitioning to readauto need only happen for 6390 /* transitioning to readauto need only happen for
6587 * arrays that call md_write_start 6391 * arrays that call md_write_start
@@ -6593,17 +6397,14 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6593 set_disk_ro(mddev->gendisk, 0); 6397 set_disk_ro(mddev->gendisk, 0);
6594 } 6398 }
6595 } 6399 }
6596 goto done_unlock; 6400 goto unlock;
6597 } 6401 }
6598 6402
6599 /* 6403 /*
6600 * The remaining ioctls are changing the state of the 6404 * The remaining ioctls are changing the state of the
6601 * superblock, so we do not allow them on read-only arrays. 6405 * 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 */ 6406 */
6606 if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { 6407 if (mddev->ro && mddev->pers) {
6607 if (mddev->ro == 2) { 6408 if (mddev->ro == 2) {
6608 mddev->ro = 0; 6409 mddev->ro = 0;
6609 sysfs_notify_dirent_safe(mddev->sysfs_state); 6410 sysfs_notify_dirent_safe(mddev->sysfs_state);
@@ -6621,7 +6422,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6621 } 6422 }
6622 } else { 6423 } else {
6623 err = -EROFS; 6424 err = -EROFS;
6624 goto abort_unlock; 6425 goto unlock;
6625 } 6426 }
6626 } 6427 }
6627 6428
@@ -6633,38 +6434,32 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
6633 err = -EFAULT; 6434 err = -EFAULT;
6634 else 6435 else
6635 err = add_new_disk(mddev, &info); 6436 err = add_new_disk(mddev, &info);
6636 goto done_unlock; 6437 goto unlock;
6637 } 6438 }
6638 6439
6639 case HOT_ADD_DISK: 6440 case HOT_ADD_DISK:
6640 err = hot_add_disk(mddev, new_decode_dev(arg)); 6441 err = hot_add_disk(mddev, new_decode_dev(arg));
6641 goto done_unlock; 6442 goto unlock;
6642 6443
6643 case RUN_ARRAY: 6444 case RUN_ARRAY:
6644 err = do_md_run(mddev); 6445 err = do_md_run(mddev);
6645 goto done_unlock; 6446 goto unlock;
6646 6447
6647 case SET_BITMAP_FILE: 6448 case SET_BITMAP_FILE:
6648 err = set_bitmap_file(mddev, (int)arg); 6449 err = set_bitmap_file(mddev, (int)arg);
6649 goto done_unlock; 6450 goto unlock;
6650 6451
6651 default: 6452 default:
6652 err = -EINVAL; 6453 err = -EINVAL;
6653 goto abort_unlock; 6454 goto unlock;
6654 } 6455 }
6655 6456
6656done_unlock: 6457unlock:
6657abort_unlock:
6658 if (mddev->hold_active == UNTIL_IOCTL && 6458 if (mddev->hold_active == UNTIL_IOCTL &&
6659 err != -EINVAL) 6459 err != -EINVAL)
6660 mddev->hold_active = 0; 6460 mddev->hold_active = 0;
6661 mddev_unlock(mddev); 6461 mddev_unlock(mddev);
6662 6462out:
6663 return err;
6664done:
6665 if (err)
6666 MD_BUG();
6667abort:
6668 return err; 6463 return err;
6669} 6464}
6670#ifdef CONFIG_COMPAT 6465#ifdef CONFIG_COMPAT
@@ -6726,7 +6521,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
6726 6521
6727static void md_release(struct gendisk *disk, fmode_t mode) 6522static void md_release(struct gendisk *disk, fmode_t mode)
6728{ 6523{
6729 struct mddev *mddev = disk->private_data; 6524 struct mddev *mddev = disk->private_data;
6730 6525
6731 BUG_ON(!mddev); 6526 BUG_ON(!mddev);
6732 atomic_dec(&mddev->openers); 6527 atomic_dec(&mddev->openers);
@@ -6761,7 +6556,7 @@ static const struct block_device_operations md_fops =
6761 .revalidate_disk= md_revalidate, 6556 .revalidate_disk= md_revalidate,
6762}; 6557};
6763 6558
6764static int md_thread(void * arg) 6559static int md_thread(void *arg)
6765{ 6560{
6766 struct md_thread *thread = arg; 6561 struct md_thread *thread = arg;
6767 6562
@@ -6810,6 +6605,7 @@ void md_wakeup_thread(struct md_thread *thread)
6810 wake_up(&thread->wqueue); 6605 wake_up(&thread->wqueue);
6811 } 6606 }
6812} 6607}
6608EXPORT_SYMBOL(md_wakeup_thread);
6813 6609
6814struct md_thread *md_register_thread(void (*run) (struct md_thread *), 6610struct md_thread *md_register_thread(void (*run) (struct md_thread *),
6815 struct mddev *mddev, const char *name) 6611 struct mddev *mddev, const char *name)
@@ -6835,6 +6631,7 @@ struct md_thread *md_register_thread(void (*run) (struct md_thread *),
6835 } 6631 }
6836 return thread; 6632 return thread;
6837} 6633}
6634EXPORT_SYMBOL(md_register_thread);
6838 6635
6839void md_unregister_thread(struct md_thread **threadp) 6636void md_unregister_thread(struct md_thread **threadp)
6840{ 6637{
@@ -6852,14 +6649,10 @@ void md_unregister_thread(struct md_thread **threadp)
6852 kthread_stop(thread->tsk); 6649 kthread_stop(thread->tsk);
6853 kfree(thread); 6650 kfree(thread);
6854} 6651}
6652EXPORT_SYMBOL(md_unregister_thread);
6855 6653
6856void md_error(struct mddev *mddev, struct md_rdev *rdev) 6654void md_error(struct mddev *mddev, struct md_rdev *rdev)
6857{ 6655{
6858 if (!mddev) {
6859 MD_BUG();
6860 return;
6861 }
6862
6863 if (!rdev || test_bit(Faulty, &rdev->flags)) 6656 if (!rdev || test_bit(Faulty, &rdev->flags))
6864 return; 6657 return;
6865 6658
@@ -6876,6 +6669,7 @@ void md_error(struct mddev *mddev, struct md_rdev *rdev)
6876 queue_work(md_misc_wq, &mddev->event_work); 6669 queue_work(md_misc_wq, &mddev->event_work);
6877 md_new_event_inintr(mddev); 6670 md_new_event_inintr(mddev);
6878} 6671}
6672EXPORT_SYMBOL(md_error);
6879 6673
6880/* seq_file implementation /proc/mdstat */ 6674/* seq_file implementation /proc/mdstat */
6881 6675
@@ -6898,8 +6692,7 @@ static void status_unused(struct seq_file *seq)
6898 seq_printf(seq, "\n"); 6692 seq_printf(seq, "\n");
6899} 6693}
6900 6694
6901 6695static void status_resync(struct seq_file *seq, struct mddev *mddev)
6902static void status_resync(struct seq_file *seq, struct mddev * mddev)
6903{ 6696{
6904 sector_t max_sectors, resync, res; 6697 sector_t max_sectors, resync, res;
6905 unsigned long dt, db; 6698 unsigned long dt, db;
@@ -6919,13 +6712,7 @@ static void status_resync(struct seq_file *seq, struct mddev * mddev)
6919 else 6712 else
6920 max_sectors = mddev->dev_sectors; 6713 max_sectors = mddev->dev_sectors;
6921 6714
6922 /* 6715 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 6716 /* Pick 'scale' such that (resync>>scale)*1000 will fit
6930 * in a sector_t, and (max_sectors>>scale) will fit in a 6717 * in a sector_t, and (max_sectors>>scale) will fit in a
6931 * u32, as those are the requirements for sector_div. 6718 * u32, as those are the requirements for sector_div.
@@ -7021,7 +6808,7 @@ static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos)
7021{ 6808{
7022 struct list_head *tmp; 6809 struct list_head *tmp;
7023 struct mddev *next_mddev, *mddev = v; 6810 struct mddev *next_mddev, *mddev = v;
7024 6811
7025 ++*pos; 6812 ++*pos;
7026 if (v == (void*)2) 6813 if (v == (void*)2)
7027 return NULL; 6814 return NULL;
@@ -7036,7 +6823,7 @@ static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos)
7036 else { 6823 else {
7037 next_mddev = (void*)2; 6824 next_mddev = (void*)2;
7038 *pos = 0x10000; 6825 *pos = 0x10000;
7039 } 6826 }
7040 spin_unlock(&all_mddevs_lock); 6827 spin_unlock(&all_mddevs_lock);
7041 6828
7042 if (v != (void*)1) 6829 if (v != (void*)1)
@@ -7132,7 +6919,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
7132 6919
7133 if (mddev->pers) { 6920 if (mddev->pers) {
7134 mddev->pers->status(seq, mddev); 6921 mddev->pers->status(seq, mddev);
7135 seq_printf(seq, "\n "); 6922 seq_printf(seq, "\n ");
7136 if (mddev->pers->sync_request) { 6923 if (mddev->pers->sync_request) {
7137 if (mddev->curr_resync > 2) { 6924 if (mddev->curr_resync > 2) {
7138 status_resync(seq, mddev); 6925 status_resync(seq, mddev);
@@ -7150,7 +6937,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
7150 seq_printf(seq, "\n"); 6937 seq_printf(seq, "\n");
7151 } 6938 }
7152 mddev_unlock(mddev); 6939 mddev_unlock(mddev);
7153 6940
7154 return 0; 6941 return 0;
7155} 6942}
7156 6943
@@ -7204,12 +6991,14 @@ static const struct file_operations md_seq_fops = {
7204 6991
7205int register_md_personality(struct md_personality *p) 6992int register_md_personality(struct md_personality *p)
7206{ 6993{
6994 printk(KERN_INFO "md: %s personality registered for level %d\n",
6995 p->name, p->level);
7207 spin_lock(&pers_lock); 6996 spin_lock(&pers_lock);
7208 list_add_tail(&p->list, &pers_list); 6997 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); 6998 spin_unlock(&pers_lock);
7211 return 0; 6999 return 0;
7212} 7000}
7001EXPORT_SYMBOL(register_md_personality);
7213 7002
7214int unregister_md_personality(struct md_personality *p) 7003int unregister_md_personality(struct md_personality *p)
7215{ 7004{
@@ -7219,10 +7008,11 @@ int unregister_md_personality(struct md_personality *p)
7219 spin_unlock(&pers_lock); 7008 spin_unlock(&pers_lock);
7220 return 0; 7009 return 0;
7221} 7010}
7011EXPORT_SYMBOL(unregister_md_personality);
7222 7012
7223static int is_mddev_idle(struct mddev *mddev, int init) 7013static int is_mddev_idle(struct mddev *mddev, int init)
7224{ 7014{
7225 struct md_rdev * rdev; 7015 struct md_rdev *rdev;
7226 int idle; 7016 int idle;
7227 int curr_events; 7017 int curr_events;
7228 7018
@@ -7276,7 +7066,7 @@ void md_done_sync(struct mddev *mddev, int blocks, int ok)
7276 // stop recovery, signal do_sync .... 7066 // stop recovery, signal do_sync ....
7277 } 7067 }
7278} 7068}
7279 7069EXPORT_SYMBOL(md_done_sync);
7280 7070
7281/* md_write_start(mddev, bi) 7071/* md_write_start(mddev, bi)
7282 * If we need to update some array metadata (e.g. 'active' flag 7072 * If we need to update some array metadata (e.g. 'active' flag
@@ -7317,6 +7107,7 @@ void md_write_start(struct mddev *mddev, struct bio *bi)
7317 wait_event(mddev->sb_wait, 7107 wait_event(mddev->sb_wait,
7318 !test_bit(MD_CHANGE_PENDING, &mddev->flags)); 7108 !test_bit(MD_CHANGE_PENDING, &mddev->flags));
7319} 7109}
7110EXPORT_SYMBOL(md_write_start);
7320 7111
7321void md_write_end(struct mddev *mddev) 7112void md_write_end(struct mddev *mddev)
7322{ 7113{
@@ -7327,6 +7118,7 @@ void md_write_end(struct mddev *mddev)
7327 mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay); 7118 mod_timer(&mddev->safemode_timer, jiffies + mddev->safemode_delay);
7328 } 7119 }
7329} 7120}
7121EXPORT_SYMBOL(md_write_end);
7330 7122
7331/* md_allow_write(mddev) 7123/* md_allow_write(mddev)
7332 * Calling this ensures that the array is marked 'active' so that writes 7124 * Calling this ensures that the array is marked 'active' so that writes
@@ -7784,6 +7576,33 @@ no_add:
7784 return spares; 7576 return spares;
7785} 7577}
7786 7578
7579static void md_start_sync(struct work_struct *ws)
7580{
7581 struct mddev *mddev = container_of(ws, struct mddev, del_work);
7582
7583 mddev->sync_thread = md_register_thread(md_do_sync,
7584 mddev,
7585 "resync");
7586 if (!mddev->sync_thread) {
7587 printk(KERN_ERR "%s: could not start resync"
7588 " thread...\n",
7589 mdname(mddev));
7590 /* leave the spares where they are, it shouldn't hurt */
7591 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
7592 clear_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
7593 clear_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
7594 clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
7595 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
7596 if (test_and_clear_bit(MD_RECOVERY_RECOVER,
7597 &mddev->recovery))
7598 if (mddev->sysfs_action)
7599 sysfs_notify_dirent_safe(mddev->sysfs_action);
7600 } else
7601 md_wakeup_thread(mddev->sync_thread);
7602 sysfs_notify_dirent_safe(mddev->sysfs_action);
7603 md_new_event(mddev);
7604}
7605
7787/* 7606/*
7788 * This routine is regularly called by all per-raid-array threads to 7607 * This routine is regularly called by all per-raid-array threads to
7789 * deal with generic issues like resync and super-block update. 7608 * deal with generic issues like resync and super-block update.
@@ -7900,7 +7719,7 @@ void md_check_recovery(struct mddev *mddev)
7900 7719
7901 if (!test_and_clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || 7720 if (!test_and_clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
7902 test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) 7721 test_bit(MD_RECOVERY_FROZEN, &mddev->recovery))
7903 goto unlock; 7722 goto not_running;
7904 /* no recovery is running. 7723 /* no recovery is running.
7905 * remove any failed drives, then 7724 * remove any failed drives, then
7906 * add spares if possible. 7725 * add spares if possible.
@@ -7912,7 +7731,7 @@ void md_check_recovery(struct mddev *mddev)
7912 if (mddev->pers->check_reshape == NULL || 7731 if (mddev->pers->check_reshape == NULL ||
7913 mddev->pers->check_reshape(mddev) != 0) 7732 mddev->pers->check_reshape(mddev) != 0)
7914 /* Cannot proceed */ 7733 /* Cannot proceed */
7915 goto unlock; 7734 goto not_running;
7916 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); 7735 set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
7917 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 7736 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
7918 } else if ((spares = remove_and_add_spares(mddev, NULL))) { 7737 } else if ((spares = remove_and_add_spares(mddev, NULL))) {
@@ -7925,7 +7744,7 @@ void md_check_recovery(struct mddev *mddev)
7925 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 7744 clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
7926 } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) 7745 } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
7927 /* nothing to be done ... */ 7746 /* nothing to be done ... */
7928 goto unlock; 7747 goto not_running;
7929 7748
7930 if (mddev->pers->sync_request) { 7749 if (mddev->pers->sync_request) {
7931 if (spares) { 7750 if (spares) {
@@ -7935,27 +7754,11 @@ void md_check_recovery(struct mddev *mddev)
7935 */ 7754 */
7936 bitmap_write_all(mddev->bitmap); 7755 bitmap_write_all(mddev->bitmap);
7937 } 7756 }
7938 mddev->sync_thread = md_register_thread(md_do_sync, 7757 INIT_WORK(&mddev->del_work, md_start_sync);
7939 mddev, 7758 queue_work(md_misc_wq, &mddev->del_work);
7940 "resync"); 7759 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 } 7760 }
7956 unlock: 7761 not_running:
7957 wake_up(&mddev->sb_wait);
7958
7959 if (!mddev->sync_thread) { 7762 if (!mddev->sync_thread) {
7960 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery); 7763 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
7961 if (test_and_clear_bit(MD_RECOVERY_RECOVER, 7764 if (test_and_clear_bit(MD_RECOVERY_RECOVER,
@@ -7963,9 +7766,12 @@ void md_check_recovery(struct mddev *mddev)
7963 if (mddev->sysfs_action) 7766 if (mddev->sysfs_action)
7964 sysfs_notify_dirent_safe(mddev->sysfs_action); 7767 sysfs_notify_dirent_safe(mddev->sysfs_action);
7965 } 7768 }
7769 unlock:
7770 wake_up(&mddev->sb_wait);
7966 mddev_unlock(mddev); 7771 mddev_unlock(mddev);
7967 } 7772 }
7968} 7773}
7774EXPORT_SYMBOL(md_check_recovery);
7969 7775
7970void md_reap_sync_thread(struct mddev *mddev) 7776void md_reap_sync_thread(struct mddev *mddev)
7971{ 7777{
@@ -8008,6 +7814,7 @@ void md_reap_sync_thread(struct mddev *mddev)
8008 if (mddev->event_work.func) 7814 if (mddev->event_work.func)
8009 queue_work(md_misc_wq, &mddev->event_work); 7815 queue_work(md_misc_wq, &mddev->event_work);
8010} 7816}
7817EXPORT_SYMBOL(md_reap_sync_thread);
8011 7818
8012void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev) 7819void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev)
8013{ 7820{
@@ -8641,7 +8448,6 @@ void md_autodetect_dev(dev_t dev)
8641 } 8448 }
8642} 8449}
8643 8450
8644
8645static void autostart_arrays(int part) 8451static void autostart_arrays(int part)
8646{ 8452{
8647 struct md_rdev *rdev; 8453 struct md_rdev *rdev;
@@ -8665,10 +8471,9 @@ static void autostart_arrays(int part)
8665 if (IS_ERR(rdev)) 8471 if (IS_ERR(rdev))
8666 continue; 8472 continue;
8667 8473
8668 if (test_bit(Faulty, &rdev->flags)) { 8474 if (test_bit(Faulty, &rdev->flags))
8669 MD_BUG();
8670 continue; 8475 continue;
8671 } 8476
8672 set_bit(AutoDetected, &rdev->flags); 8477 set_bit(AutoDetected, &rdev->flags);
8673 list_add(&rdev->same_set, &pending_raid_disks); 8478 list_add(&rdev->same_set, &pending_raid_disks);
8674 i_passed++; 8479 i_passed++;
@@ -8736,20 +8541,8 @@ static int set_ro(const char *val, struct kernel_param *kp)
8736 8541
8737module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); 8542module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR);
8738module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR); 8543module_param(start_dirty_degraded, int, S_IRUGO|S_IWUSR);
8739
8740module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR); 8544module_param_call(new_array, add_named_array, NULL, NULL, S_IWUSR);
8741 8545
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"); 8546MODULE_LICENSE("GPL");
8754MODULE_DESCRIPTION("MD RAID framework"); 8547MODULE_DESCRIPTION("MD RAID framework");
8755MODULE_ALIAS("md"); 8548MODULE_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 d7690f86fdb9..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
@@ -540,11 +539,7 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
540 has_nonrot_disk = 0; 539 has_nonrot_disk = 0;
541 choose_next_idle = 0; 540 choose_next_idle = 0;
542 541
543 if (conf->mddev->recovery_cp < MaxSector && 542 choose_first = (conf->mddev->recovery_cp < this_sector + sectors);
544 (this_sector + sectors >= conf->next_resync))
545 choose_first = 1;
546 else
547 choose_first = 0;
548 543
549 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) { 544 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) {
550 sector_t dist; 545 sector_t dist;
@@ -831,7 +826,7 @@ static void flush_pending_writes(struct r1conf *conf)
831 * there is no normal IO happeing. It must arrange to call 826 * there is no normal IO happeing. It must arrange to call
832 * lower_barrier when the particular background IO completes. 827 * lower_barrier when the particular background IO completes.
833 */ 828 */
834static void raise_barrier(struct r1conf *conf) 829static void raise_barrier(struct r1conf *conf, sector_t sector_nr)
835{ 830{
836 spin_lock_irq(&conf->resync_lock); 831 spin_lock_irq(&conf->resync_lock);
837 832
@@ -841,6 +836,7 @@ static void raise_barrier(struct r1conf *conf)
841 836
842 /* block any new IO from starting */ 837 /* block any new IO from starting */
843 conf->barrier++; 838 conf->barrier++;
839 conf->next_resync = sector_nr;
844 840
845 /* For these conditions we must wait: 841 /* For these conditions we must wait:
846 * A: while the array is in frozen state 842 * A: while the array is in frozen state
@@ -849,14 +845,17 @@ static void raise_barrier(struct r1conf *conf)
849 * C: next_resync + RESYNC_SECTORS > start_next_window, meaning 845 * C: next_resync + RESYNC_SECTORS > start_next_window, meaning
850 * next resync will reach to the window which normal bios are 846 * next resync will reach to the window which normal bios are
851 * handling. 847 * handling.
848 * D: while there are any active requests in the current window.
852 */ 849 */
853 wait_event_lock_irq(conf->wait_barrier, 850 wait_event_lock_irq(conf->wait_barrier,
854 !conf->array_frozen && 851 !conf->array_frozen &&
855 conf->barrier < RESYNC_DEPTH && 852 conf->barrier < RESYNC_DEPTH &&
853 conf->current_window_requests == 0 &&
856 (conf->start_next_window >= 854 (conf->start_next_window >=
857 conf->next_resync + RESYNC_SECTORS), 855 conf->next_resync + RESYNC_SECTORS),
858 conf->resync_lock); 856 conf->resync_lock);
859 857
858 conf->nr_pending++;
860 spin_unlock_irq(&conf->resync_lock); 859 spin_unlock_irq(&conf->resync_lock);
861} 860}
862 861
@@ -866,6 +865,7 @@ static void lower_barrier(struct r1conf *conf)
866 BUG_ON(conf->barrier <= 0); 865 BUG_ON(conf->barrier <= 0);
867 spin_lock_irqsave(&conf->resync_lock, flags); 866 spin_lock_irqsave(&conf->resync_lock, flags);
868 conf->barrier--; 867 conf->barrier--;
868 conf->nr_pending--;
869 spin_unlock_irqrestore(&conf->resync_lock, flags); 869 spin_unlock_irqrestore(&conf->resync_lock, flags);
870 wake_up(&conf->wait_barrier); 870 wake_up(&conf->wait_barrier);
871} 871}
@@ -877,12 +877,10 @@ static bool need_to_wait_for_sync(struct r1conf *conf, struct bio *bio)
877 if (conf->array_frozen || !bio) 877 if (conf->array_frozen || !bio)
878 wait = true; 878 wait = true;
879 else if (conf->barrier && bio_data_dir(bio) == WRITE) { 879 else if (conf->barrier && bio_data_dir(bio) == WRITE) {
880 if (conf->next_resync < RESYNC_WINDOW_SECTORS) 880 if ((conf->mddev->curr_resync_completed
881 wait = true; 881 >= bio_end_sector(bio)) ||
882 else if ((conf->next_resync - RESYNC_WINDOW_SECTORS 882 (conf->next_resync + NEXT_NORMALIO_DISTANCE
883 >= bio_end_sector(bio)) || 883 <= bio->bi_iter.bi_sector))
884 (conf->next_resync + NEXT_NORMALIO_DISTANCE
885 <= bio->bi_iter.bi_sector))
886 wait = false; 884 wait = false;
887 else 885 else
888 wait = true; 886 wait = true;
@@ -902,25 +900,25 @@ static sector_t wait_barrier(struct r1conf *conf, struct bio *bio)
902 * However if there are already pending 900 * However if there are already pending
903 * requests (preventing the barrier from 901 * requests (preventing the barrier from
904 * rising completely), and the 902 * rising completely), and the
905 * pre-process bio queue isn't empty, 903 * per-process bio queue isn't empty,
906 * then don't wait, as we need to empty 904 * then don't wait, as we need to empty
907 * that queue to get the nr_pending 905 * that queue to allow conf->start_next_window
908 * count down. 906 * to increase.
909 */ 907 */
910 wait_event_lock_irq(conf->wait_barrier, 908 wait_event_lock_irq(conf->wait_barrier,
911 !conf->array_frozen && 909 !conf->array_frozen &&
912 (!conf->barrier || 910 (!conf->barrier ||
913 ((conf->start_next_window < 911 ((conf->start_next_window <
914 conf->next_resync + RESYNC_SECTORS) && 912 conf->next_resync + RESYNC_SECTORS) &&
915 current->bio_list && 913 current->bio_list &&
916 !bio_list_empty(current->bio_list))), 914 !bio_list_empty(current->bio_list))),
917 conf->resync_lock); 915 conf->resync_lock);
918 conf->nr_waiting--; 916 conf->nr_waiting--;
919 } 917 }
920 918
921 if (bio && bio_data_dir(bio) == WRITE) { 919 if (bio && bio_data_dir(bio) == WRITE) {
922 if (conf->next_resync + NEXT_NORMALIO_DISTANCE 920 if (bio->bi_iter.bi_sector >=
923 <= bio->bi_iter.bi_sector) { 921 conf->mddev->curr_resync_completed) {
924 if (conf->start_next_window == MaxSector) 922 if (conf->start_next_window == MaxSector)
925 conf->start_next_window = 923 conf->start_next_window =
926 conf->next_resync + 924 conf->next_resync +
@@ -1002,8 +1000,7 @@ static void unfreeze_array(struct r1conf *conf)
1002 spin_unlock_irq(&conf->resync_lock); 1000 spin_unlock_irq(&conf->resync_lock);
1003} 1001}
1004 1002
1005 1003/* duplicate the data pages for behind I/O
1006/* duplicate the data pages for behind I/O
1007 */ 1004 */
1008static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) 1005static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio)
1009{ 1006{
@@ -1186,6 +1183,7 @@ read_again:
1186 atomic_read(&bitmap->behind_writes) == 0); 1183 atomic_read(&bitmap->behind_writes) == 0);
1187 } 1184 }
1188 r1_bio->read_disk = rdisk; 1185 r1_bio->read_disk = rdisk;
1186 r1_bio->start_next_window = 0;
1189 1187
1190 read_bio = bio_clone_mddev(bio, GFP_NOIO, mddev); 1188 read_bio = bio_clone_mddev(bio, GFP_NOIO, mddev);
1191 bio_trim(read_bio, r1_bio->sector - bio->bi_iter.bi_sector, 1189 bio_trim(read_bio, r1_bio->sector - bio->bi_iter.bi_sector,
@@ -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];
@@ -1548,8 +1545,13 @@ static void close_sync(struct r1conf *conf)
1548 mempool_destroy(conf->r1buf_pool); 1545 mempool_destroy(conf->r1buf_pool);
1549 conf->r1buf_pool = NULL; 1546 conf->r1buf_pool = NULL;
1550 1547
1548 spin_lock_irq(&conf->resync_lock);
1551 conf->next_resync = 0; 1549 conf->next_resync = 0;
1552 conf->start_next_window = MaxSector; 1550 conf->start_next_window = MaxSector;
1551 conf->current_window_requests +=
1552 conf->next_window_requests;
1553 conf->next_window_requests = 0;
1554 spin_unlock_irq(&conf->resync_lock);
1553} 1555}
1554 1556
1555static int raid1_spare_active(struct mddev *mddev) 1557static int raid1_spare_active(struct mddev *mddev)
@@ -1560,7 +1562,7 @@ static int raid1_spare_active(struct mddev *mddev)
1560 unsigned long flags; 1562 unsigned long flags;
1561 1563
1562 /* 1564 /*
1563 * Find all failed disks within the RAID1 configuration 1565 * Find all failed disks within the RAID1 configuration
1564 * and mark them readable. 1566 * and mark them readable.
1565 * Called under mddev lock, so rcu protection not needed. 1567 * Called under mddev lock, so rcu protection not needed.
1566 */ 1568 */
@@ -1601,7 +1603,6 @@ static int raid1_spare_active(struct mddev *mddev)
1601 return count; 1603 return count;
1602} 1604}
1603 1605
1604
1605static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev) 1606static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev)
1606{ 1607{
1607 struct r1conf *conf = mddev->private; 1608 struct r1conf *conf = mddev->private;
@@ -1730,7 +1731,6 @@ abort:
1730 return err; 1731 return err;
1731} 1732}
1732 1733
1733
1734static void end_sync_read(struct bio *bio, int error) 1734static void end_sync_read(struct bio *bio, int error)
1735{ 1735{
1736 struct r1bio *r1_bio = bio->bi_private; 1736 struct r1bio *r1_bio = bio->bi_private;
@@ -1942,7 +1942,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
1942 return 1; 1942 return 1;
1943} 1943}
1944 1944
1945static int process_checks(struct r1bio *r1_bio) 1945static void process_checks(struct r1bio *r1_bio)
1946{ 1946{
1947 /* We have read all readable devices. If we haven't 1947 /* We have read all readable devices. If we haven't
1948 * got the block, then there is no hope left. 1948 * got the block, then there is no hope left.
@@ -2034,7 +2034,6 @@ static int process_checks(struct r1bio *r1_bio)
2034 2034
2035 bio_copy_data(sbio, pbio); 2035 bio_copy_data(sbio, pbio);
2036 } 2036 }
2037 return 0;
2038} 2037}
2039 2038
2040static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio) 2039static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
@@ -2052,8 +2051,8 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
2052 return; 2051 return;
2053 2052
2054 if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) 2053 if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
2055 if (process_checks(r1_bio) < 0) 2054 process_checks(r1_bio);
2056 return; 2055
2057 /* 2056 /*
2058 * schedule writes 2057 * schedule writes
2059 */ 2058 */
@@ -2150,7 +2149,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
2150 d--; 2149 d--;
2151 rdev = conf->mirrors[d].rdev; 2150 rdev = conf->mirrors[d].rdev;
2152 if (rdev && 2151 if (rdev &&
2153 test_bit(In_sync, &rdev->flags)) 2152 !test_bit(Faulty, &rdev->flags))
2154 r1_sync_page_io(rdev, sect, s, 2153 r1_sync_page_io(rdev, sect, s,
2155 conf->tmppage, WRITE); 2154 conf->tmppage, WRITE);
2156 } 2155 }
@@ -2162,7 +2161,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
2162 d--; 2161 d--;
2163 rdev = conf->mirrors[d].rdev; 2162 rdev = conf->mirrors[d].rdev;
2164 if (rdev && 2163 if (rdev &&
2165 test_bit(In_sync, &rdev->flags)) { 2164 !test_bit(Faulty, &rdev->flags)) {
2166 if (r1_sync_page_io(rdev, sect, s, 2165 if (r1_sync_page_io(rdev, sect, s,
2167 conf->tmppage, READ)) { 2166 conf->tmppage, READ)) {
2168 atomic_add(s, &rdev->corrected_errors); 2167 atomic_add(s, &rdev->corrected_errors);
@@ -2453,7 +2452,6 @@ static void raid1d(struct md_thread *thread)
2453 blk_finish_plug(&plug); 2452 blk_finish_plug(&plug);
2454} 2453}
2455 2454
2456
2457static int init_resync(struct r1conf *conf) 2455static int init_resync(struct r1conf *conf)
2458{ 2456{
2459 int buffs; 2457 int buffs;
@@ -2541,9 +2539,8 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
2541 2539
2542 bitmap_cond_end_sync(mddev->bitmap, sector_nr); 2540 bitmap_cond_end_sync(mddev->bitmap, sector_nr);
2543 r1_bio = mempool_alloc(conf->r1buf_pool, GFP_NOIO); 2541 r1_bio = mempool_alloc(conf->r1buf_pool, GFP_NOIO);
2544 raise_barrier(conf);
2545 2542
2546 conf->next_resync = sector_nr; 2543 raise_barrier(conf, sector_nr);
2547 2544
2548 rcu_read_lock(); 2545 rcu_read_lock();
2549 /* 2546 /*
@@ -2718,7 +2715,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
2718 /* remove last page from this bio */ 2715 /* remove last page from this bio */
2719 bio->bi_vcnt--; 2716 bio->bi_vcnt--;
2720 bio->bi_iter.bi_size -= len; 2717 bio->bi_iter.bi_size -= len;
2721 bio->bi_flags &= ~(1<< BIO_SEG_VALID); 2718 __clear_bit(BIO_SEG_VALID, &bio->bi_flags);
2722 } 2719 }
2723 goto bio_full; 2720 goto bio_full;
2724 } 2721 }
@@ -2943,9 +2940,9 @@ static int run(struct mddev *mddev)
2943 printk(KERN_NOTICE "md/raid1:%s: not clean" 2940 printk(KERN_NOTICE "md/raid1:%s: not clean"
2944 " -- starting background reconstruction\n", 2941 " -- starting background reconstruction\n",
2945 mdname(mddev)); 2942 mdname(mddev));
2946 printk(KERN_INFO 2943 printk(KERN_INFO
2947 "md/raid1:%s: active with %d out of %d mirrors\n", 2944 "md/raid1:%s: active with %d out of %d mirrors\n",
2948 mdname(mddev), mddev->raid_disks - mddev->degraded, 2945 mdname(mddev), mddev->raid_disks - mddev->degraded,
2949 mddev->raid_disks); 2946 mddev->raid_disks);
2950 2947
2951 /* 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 183588b11fc1..9c66e5997fc8 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -64,6 +64,10 @@
64#define cpu_to_group(cpu) cpu_to_node(cpu) 64#define cpu_to_group(cpu) cpu_to_node(cpu)
65#define ANY_GROUP NUMA_NO_NODE 65#define ANY_GROUP NUMA_NO_NODE
66 66
67static bool devices_handle_discard_safely = false;
68module_param(devices_handle_discard_safely, bool, 0644);
69MODULE_PARM_DESC(devices_handle_discard_safely,
70 "Set to Y if all devices in each array reliably return zeroes on reads from discarded regions");
67static struct workqueue_struct *raid5_wq; 71static struct workqueue_struct *raid5_wq;
68/* 72/*
69 * Stripe cache 73 * Stripe cache
@@ -459,7 +463,6 @@ static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh)
459 hlist_add_head(&sh->hash, hp); 463 hlist_add_head(&sh->hash, hp);
460} 464}
461 465
462
463/* 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. */
464static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash) 467static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash)
465{ 468{
@@ -527,9 +530,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)
527 BUG_ON(stripe_operations_active(sh)); 530 BUG_ON(stripe_operations_active(sh));
528 531
529 pr_debug("init_stripe called, stripe %llu\n", 532 pr_debug("init_stripe called, stripe %llu\n",
530 (unsigned long long)sh->sector); 533 (unsigned long long)sector);
531
532 remove_hash(sh);
533retry: 534retry:
534 seq = read_seqcount_begin(&conf->gen_lock); 535 seq = read_seqcount_begin(&conf->gen_lock);
535 sh->generation = conf->generation - previous; 536 sh->generation = conf->generation - previous;
@@ -538,7 +539,6 @@ retry:
538 stripe_set_idx(sector, conf, previous, sh); 539 stripe_set_idx(sector, conf, previous, sh);
539 sh->state = 0; 540 sh->state = 0;
540 541
541
542 for (i = sh->disks; i--; ) { 542 for (i = sh->disks; i--; ) {
543 struct r5dev *dev = &sh->dev[i]; 543 struct r5dev *dev = &sh->dev[i];
544 544
@@ -1346,7 +1346,6 @@ ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu)
1346 } 1346 }
1347} 1347}
1348 1348
1349
1350static void ops_complete_prexor(void *stripe_head_ref) 1349static void ops_complete_prexor(void *stripe_head_ref)
1351{ 1350{
1352 struct stripe_head *sh = stripe_head_ref; 1351 struct stripe_head *sh = stripe_head_ref;
@@ -2415,7 +2414,6 @@ static sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector,
2415 return new_sector; 2414 return new_sector;
2416} 2415}
2417 2416
2418
2419static 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)
2420{ 2418{
2421 struct r5conf *conf = sh->raid_conf; 2419 struct r5conf *conf = sh->raid_conf;
@@ -2433,7 +2431,6 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
2433 sector_t r_sector; 2431 sector_t r_sector;
2434 struct stripe_head sh2; 2432 struct stripe_head sh2;
2435 2433
2436
2437 chunk_offset = sector_div(new_sector, sectors_per_chunk); 2434 chunk_offset = sector_div(new_sector, sectors_per_chunk);
2438 stripe = new_sector; 2435 stripe = new_sector;
2439 2436
@@ -2537,7 +2534,6 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
2537 return r_sector; 2534 return r_sector;
2538} 2535}
2539 2536
2540
2541static void 2537static void
2542schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, 2538schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
2543 int rcw, int expand) 2539 int rcw, int expand)
@@ -3009,7 +3005,6 @@ static void handle_stripe_fill(struct stripe_head *sh,
3009 set_bit(STRIPE_HANDLE, &sh->state); 3005 set_bit(STRIPE_HANDLE, &sh->state);
3010} 3006}
3011 3007
3012
3013/* handle_stripe_clean_event 3008/* handle_stripe_clean_event
3014 * 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.
3015 * 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
@@ -3300,7 +3295,6 @@ static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh,
3300 } 3295 }
3301} 3296}
3302 3297
3303
3304static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, 3298static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh,
3305 struct stripe_head_state *s, 3299 struct stripe_head_state *s,
3306 int disks) 3300 int disks)
@@ -3935,7 +3929,6 @@ static void handle_stripe(struct stripe_head *sh)
3935 } 3929 }
3936 } 3930 }
3937 3931
3938
3939 /* Finish reconstruct operations initiated by the expansion process */ 3932 /* Finish reconstruct operations initiated by the expansion process */
3940 if (sh->reconstruct_state == reconstruct_state_result) { 3933 if (sh->reconstruct_state == reconstruct_state_result) {
3941 struct stripe_head *sh_src 3934 struct stripe_head *sh_src
@@ -4133,7 +4126,6 @@ static int raid5_mergeable_bvec(struct request_queue *q,
4133 return max; 4126 return max;
4134} 4127}
4135 4128
4136
4137static int in_chunk_boundary(struct mddev *mddev, struct bio *bio) 4129static int in_chunk_boundary(struct mddev *mddev, struct bio *bio)
4138{ 4130{
4139 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);
@@ -4163,7 +4155,6 @@ static void add_bio_to_retry(struct bio *bi,struct r5conf *conf)
4163 md_wakeup_thread(conf->mddev->thread); 4155 md_wakeup_thread(conf->mddev->thread);
4164} 4156}
4165 4157
4166
4167static struct bio *remove_bio_from_retry(struct r5conf *conf) 4158static struct bio *remove_bio_from_retry(struct r5conf *conf)
4168{ 4159{
4169 struct bio *bi; 4160 struct bio *bi;
@@ -4187,7 +4178,6 @@ static struct bio *remove_bio_from_retry(struct r5conf *conf)
4187 return bi; 4178 return bi;
4188} 4179}
4189 4180
4190
4191/* 4181/*
4192 * 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
4193 * 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
@@ -4220,7 +4210,6 @@ static void raid5_align_endio(struct bio *bi, int error)
4220 return; 4210 return;
4221 } 4211 }
4222 4212
4223
4224 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");
4225 4214
4226 add_bio_to_retry(raid_bi, conf); 4215 add_bio_to_retry(raid_bi, conf);
@@ -4245,7 +4234,6 @@ static int bio_fits_rdev(struct bio *bi)
4245 return 1; 4234 return 1;
4246} 4235}
4247 4236
4248
4249static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio) 4237static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
4250{ 4238{
4251 struct r5conf *conf = mddev->private; 4239 struct r5conf *conf = mddev->private;
@@ -4297,7 +4285,7 @@ static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
4297 rcu_read_unlock(); 4285 rcu_read_unlock();
4298 raid_bio->bi_next = (void*)rdev; 4286 raid_bio->bi_next = (void*)rdev;
4299 align_bi->bi_bdev = rdev->bdev; 4287 align_bi->bi_bdev = rdev->bdev;
4300 align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); 4288 __clear_bit(BIO_SEG_VALID, &align_bi->bi_flags);
4301 4289
4302 if (!bio_fits_rdev(align_bi) || 4290 if (!bio_fits_rdev(align_bi) ||
4303 is_badblock(rdev, align_bi->bi_iter.bi_sector, 4291 is_badblock(rdev, align_bi->bi_iter.bi_sector,
@@ -5442,7 +5430,6 @@ raid5_skip_copy = __ATTR(skip_copy, S_IRUGO | S_IWUSR,
5442 raid5_show_skip_copy, 5430 raid5_show_skip_copy,
5443 raid5_store_skip_copy); 5431 raid5_store_skip_copy);
5444 5432
5445
5446static ssize_t 5433static ssize_t
5447stripe_cache_active_show(struct mddev *mddev, char *page) 5434stripe_cache_active_show(struct mddev *mddev, char *page)
5448{ 5435{
@@ -5894,7 +5881,6 @@ static struct r5conf *setup_conf(struct mddev *mddev)
5894 return ERR_PTR(-ENOMEM); 5881 return ERR_PTR(-ENOMEM);
5895} 5882}
5896 5883
5897
5898static 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)
5899{ 5885{
5900 switch (algo) { 5886 switch (algo) {
@@ -5907,7 +5893,7 @@ static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded
5907 return 1; 5893 return 1;
5908 break; 5894 break;
5909 case ALGORITHM_PARITY_0_6: 5895 case ALGORITHM_PARITY_0_6:
5910 if (raid_disk == 0 || 5896 if (raid_disk == 0 ||
5911 raid_disk == raid_disks - 1) 5897 raid_disk == raid_disks - 1)
5912 return 1; 5898 return 1;
5913 break; 5899 break;
@@ -6161,7 +6147,6 @@ static int run(struct mddev *mddev)
6161 "reshape"); 6147 "reshape");
6162 } 6148 }
6163 6149
6164
6165 /* Ok, everything is just fine now */ 6150 /* Ok, everything is just fine now */
6166 if (mddev->to_remove == &raid5_attrs_group) 6151 if (mddev->to_remove == &raid5_attrs_group)
6167 mddev->to_remove = NULL; 6152 mddev->to_remove = NULL;
@@ -6208,7 +6193,7 @@ static int run(struct mddev *mddev)
6208 mddev->queue->limits.discard_granularity = stripe; 6193 mddev->queue->limits.discard_granularity = stripe;
6209 /* 6194 /*
6210 * unaligned part of discard request will be ignored, so can't 6195 * unaligned part of discard request will be ignored, so can't
6211 * guarantee discard_zerors_data 6196 * guarantee discard_zeroes_data
6212 */ 6197 */
6213 mddev->queue->limits.discard_zeroes_data = 0; 6198 mddev->queue->limits.discard_zeroes_data = 0;
6214 6199
@@ -6233,6 +6218,18 @@ static int run(struct mddev *mddev)
6233 !bdev_get_queue(rdev->bdev)-> 6218 !bdev_get_queue(rdev->bdev)->
6234 limits.discard_zeroes_data) 6219 limits.discard_zeroes_data)
6235 discard_supported = false; 6220 discard_supported = false;
6221 /* Unfortunately, discard_zeroes_data is not currently
6222 * a guarantee - just a hint. So we only allow DISCARD
6223 * if the sysadmin has confirmed that only safe devices
6224 * are in use by setting a module parameter.
6225 */
6226 if (!devices_handle_discard_safely) {
6227 if (discard_supported) {
6228 pr_info("md/raid456: discard support disabled due to uncertainty.\n");
6229 pr_info("Set raid456.devices_handle_discard_safely=Y to override.\n");
6230 }
6231 discard_supported = false;
6232 }
6236 } 6233 }
6237 6234
6238 if (discard_supported && 6235 if (discard_supported &&
@@ -6798,7 +6795,6 @@ static void raid5_quiesce(struct mddev *mddev, int state)
6798 } 6795 }
6799} 6796}
6800 6797
6801
6802static void *raid45_takeover_raid0(struct mddev *mddev, int level) 6798static void *raid45_takeover_raid0(struct mddev *mddev, int level)
6803{ 6799{
6804 struct r0conf *raid0_conf = mddev->private; 6800 struct r0conf *raid0_conf = mddev->private;
@@ -6825,7 +6821,6 @@ static void *raid45_takeover_raid0(struct mddev *mddev, int level)
6825 return setup_conf(mddev); 6821 return setup_conf(mddev);
6826} 6822}
6827 6823
6828
6829static void *raid5_takeover_raid1(struct mddev *mddev) 6824static void *raid5_takeover_raid1(struct mddev *mddev)
6830{ 6825{
6831 int chunksect; 6826 int chunksect;
@@ -6886,7 +6881,6 @@ static void *raid5_takeover_raid6(struct mddev *mddev)
6886 return setup_conf(mddev); 6881 return setup_conf(mddev);
6887} 6882}
6888 6883
6889
6890static int raid5_check_reshape(struct mddev *mddev) 6884static int raid5_check_reshape(struct mddev *mddev)
6891{ 6885{
6892 /* 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
@@ -7035,7 +7029,6 @@ static void *raid6_takeover(struct mddev *mddev)
7035 return setup_conf(mddev); 7029 return setup_conf(mddev);
7036} 7030}
7037 7031
7038
7039static struct md_personality raid6_personality = 7032static struct md_personality raid6_personality =
7040{ 7033{
7041 .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).