diff options
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r-- | drivers/md/md.c | 302 |
1 files changed, 187 insertions, 115 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index cb20d0b0555a..11567c7999a2 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/blkdev.h> | 36 | #include <linux/blkdev.h> |
37 | #include <linux/sysctl.h> | 37 | #include <linux/sysctl.h> |
38 | #include <linux/seq_file.h> | 38 | #include <linux/seq_file.h> |
39 | #include <linux/smp_lock.h> | ||
39 | #include <linux/buffer_head.h> /* for invalidate_bdev */ | 40 | #include <linux/buffer_head.h> /* for invalidate_bdev */ |
40 | #include <linux/poll.h> | 41 | #include <linux/poll.h> |
41 | #include <linux/ctype.h> | 42 | #include <linux/ctype.h> |
@@ -261,7 +262,7 @@ static int md_make_request(struct request_queue *q, struct bio *bio) | |||
261 | * Once ->stop is called and completes, the module will be completely | 262 | * Once ->stop is called and completes, the module will be completely |
262 | * unused. | 263 | * unused. |
263 | */ | 264 | */ |
264 | static void mddev_suspend(mddev_t *mddev) | 265 | void mddev_suspend(mddev_t *mddev) |
265 | { | 266 | { |
266 | BUG_ON(mddev->suspended); | 267 | BUG_ON(mddev->suspended); |
267 | mddev->suspended = 1; | 268 | mddev->suspended = 1; |
@@ -269,13 +270,15 @@ static void mddev_suspend(mddev_t *mddev) | |||
269 | wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0); | 270 | wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0); |
270 | mddev->pers->quiesce(mddev, 1); | 271 | mddev->pers->quiesce(mddev, 1); |
271 | } | 272 | } |
273 | EXPORT_SYMBOL_GPL(mddev_suspend); | ||
272 | 274 | ||
273 | static void mddev_resume(mddev_t *mddev) | 275 | void mddev_resume(mddev_t *mddev) |
274 | { | 276 | { |
275 | mddev->suspended = 0; | 277 | mddev->suspended = 0; |
276 | wake_up(&mddev->sb_wait); | 278 | wake_up(&mddev->sb_wait); |
277 | mddev->pers->quiesce(mddev, 0); | 279 | mddev->pers->quiesce(mddev, 0); |
278 | } | 280 | } |
281 | EXPORT_SYMBOL_GPL(mddev_resume); | ||
279 | 282 | ||
280 | int mddev_congested(mddev_t *mddev, int bits) | 283 | int mddev_congested(mddev_t *mddev, int bits) |
281 | { | 284 | { |
@@ -353,7 +356,7 @@ static void md_submit_barrier(struct work_struct *ws) | |||
353 | /* an empty barrier - all done */ | 356 | /* an empty barrier - all done */ |
354 | bio_endio(bio, 0); | 357 | bio_endio(bio, 0); |
355 | else { | 358 | else { |
356 | bio->bi_rw &= ~(1<<BIO_RW_BARRIER); | 359 | bio->bi_rw &= ~REQ_HARDBARRIER; |
357 | if (mddev->pers->make_request(mddev, bio)) | 360 | if (mddev->pers->make_request(mddev, bio)) |
358 | generic_make_request(bio); | 361 | generic_make_request(bio); |
359 | mddev->barrier = POST_REQUEST_BARRIER; | 362 | mddev->barrier = POST_REQUEST_BARRIER; |
@@ -384,6 +387,51 @@ void md_barrier_request(mddev_t *mddev, struct bio *bio) | |||
384 | } | 387 | } |
385 | EXPORT_SYMBOL(md_barrier_request); | 388 | EXPORT_SYMBOL(md_barrier_request); |
386 | 389 | ||
390 | /* Support for plugging. | ||
391 | * This mirrors the plugging support in request_queue, but does not | ||
392 | * require having a whole queue | ||
393 | */ | ||
394 | static void plugger_work(struct work_struct *work) | ||
395 | { | ||
396 | struct plug_handle *plug = | ||
397 | container_of(work, struct plug_handle, unplug_work); | ||
398 | plug->unplug_fn(plug); | ||
399 | } | ||
400 | static void plugger_timeout(unsigned long data) | ||
401 | { | ||
402 | struct plug_handle *plug = (void *)data; | ||
403 | kblockd_schedule_work(NULL, &plug->unplug_work); | ||
404 | } | ||
405 | void plugger_init(struct plug_handle *plug, | ||
406 | void (*unplug_fn)(struct plug_handle *)) | ||
407 | { | ||
408 | plug->unplug_flag = 0; | ||
409 | plug->unplug_fn = unplug_fn; | ||
410 | init_timer(&plug->unplug_timer); | ||
411 | plug->unplug_timer.function = plugger_timeout; | ||
412 | plug->unplug_timer.data = (unsigned long)plug; | ||
413 | INIT_WORK(&plug->unplug_work, plugger_work); | ||
414 | } | ||
415 | EXPORT_SYMBOL_GPL(plugger_init); | ||
416 | |||
417 | void plugger_set_plug(struct plug_handle *plug) | ||
418 | { | ||
419 | if (!test_and_set_bit(PLUGGED_FLAG, &plug->unplug_flag)) | ||
420 | mod_timer(&plug->unplug_timer, jiffies + msecs_to_jiffies(3)+1); | ||
421 | } | ||
422 | EXPORT_SYMBOL_GPL(plugger_set_plug); | ||
423 | |||
424 | int plugger_remove_plug(struct plug_handle *plug) | ||
425 | { | ||
426 | if (test_and_clear_bit(PLUGGED_FLAG, &plug->unplug_flag)) { | ||
427 | del_timer(&plug->unplug_timer); | ||
428 | return 1; | ||
429 | } else | ||
430 | return 0; | ||
431 | } | ||
432 | EXPORT_SYMBOL_GPL(plugger_remove_plug); | ||
433 | |||
434 | |||
387 | static inline mddev_t *mddev_get(mddev_t *mddev) | 435 | static inline mddev_t *mddev_get(mddev_t *mddev) |
388 | { | 436 | { |
389 | atomic_inc(&mddev->active); | 437 | atomic_inc(&mddev->active); |
@@ -416,7 +464,7 @@ static void mddev_put(mddev_t *mddev) | |||
416 | spin_unlock(&all_mddevs_lock); | 464 | spin_unlock(&all_mddevs_lock); |
417 | } | 465 | } |
418 | 466 | ||
419 | static void mddev_init(mddev_t *mddev) | 467 | void mddev_init(mddev_t *mddev) |
420 | { | 468 | { |
421 | mutex_init(&mddev->open_mutex); | 469 | mutex_init(&mddev->open_mutex); |
422 | mutex_init(&mddev->reconfig_mutex); | 470 | mutex_init(&mddev->reconfig_mutex); |
@@ -436,6 +484,7 @@ static void mddev_init(mddev_t *mddev) | |||
436 | mddev->resync_max = MaxSector; | 484 | mddev->resync_max = MaxSector; |
437 | mddev->level = LEVEL_NONE; | 485 | mddev->level = LEVEL_NONE; |
438 | } | 486 | } |
487 | EXPORT_SYMBOL_GPL(mddev_init); | ||
439 | 488 | ||
440 | static mddev_t * mddev_find(dev_t unit) | 489 | static mddev_t * mddev_find(dev_t unit) |
441 | { | 490 | { |
@@ -532,25 +581,31 @@ static void mddev_unlock(mddev_t * mddev) | |||
532 | * an access to the files will try to take reconfig_mutex | 581 | * an access to the files will try to take reconfig_mutex |
533 | * while holding the file unremovable, which leads to | 582 | * while holding the file unremovable, which leads to |
534 | * a deadlock. | 583 | * a deadlock. |
535 | * So hold open_mutex instead - we are allowed to take | 584 | * So hold set sysfs_active while the remove in happeing, |
536 | * it while holding reconfig_mutex, and md_run can | 585 | * and anything else which might set ->to_remove or my |
537 | * use it to wait for the remove to complete. | 586 | * otherwise change the sysfs namespace will fail with |
587 | * -EBUSY if sysfs_active is still set. | ||
588 | * We set sysfs_active under reconfig_mutex and elsewhere | ||
589 | * test it under the same mutex to ensure its correct value | ||
590 | * is seen. | ||
538 | */ | 591 | */ |
539 | struct attribute_group *to_remove = mddev->to_remove; | 592 | struct attribute_group *to_remove = mddev->to_remove; |
540 | mddev->to_remove = NULL; | 593 | mddev->to_remove = NULL; |
541 | mutex_lock(&mddev->open_mutex); | 594 | mddev->sysfs_active = 1; |
542 | mutex_unlock(&mddev->reconfig_mutex); | 595 | mutex_unlock(&mddev->reconfig_mutex); |
543 | 596 | ||
544 | if (to_remove != &md_redundancy_group) | 597 | if (mddev->kobj.sd) { |
545 | sysfs_remove_group(&mddev->kobj, to_remove); | 598 | if (to_remove != &md_redundancy_group) |
546 | if (mddev->pers == NULL || | 599 | sysfs_remove_group(&mddev->kobj, to_remove); |
547 | mddev->pers->sync_request == NULL) { | 600 | if (mddev->pers == NULL || |
548 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); | 601 | mddev->pers->sync_request == NULL) { |
549 | if (mddev->sysfs_action) | 602 | sysfs_remove_group(&mddev->kobj, &md_redundancy_group); |
550 | sysfs_put(mddev->sysfs_action); | 603 | if (mddev->sysfs_action) |
551 | mddev->sysfs_action = NULL; | 604 | sysfs_put(mddev->sysfs_action); |
605 | mddev->sysfs_action = NULL; | ||
606 | } | ||
552 | } | 607 | } |
553 | mutex_unlock(&mddev->open_mutex); | 608 | mddev->sysfs_active = 0; |
554 | } else | 609 | } else |
555 | mutex_unlock(&mddev->reconfig_mutex); | 610 | mutex_unlock(&mddev->reconfig_mutex); |
556 | 611 | ||
@@ -675,11 +730,11 @@ void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, | |||
675 | * if zero is reached. | 730 | * if zero is reached. |
676 | * If an error occurred, call md_error | 731 | * If an error occurred, call md_error |
677 | * | 732 | * |
678 | * As we might need to resubmit the request if BIO_RW_BARRIER | 733 | * As we might need to resubmit the request if REQ_HARDBARRIER |
679 | * causes ENOTSUPP, we allocate a spare bio... | 734 | * causes ENOTSUPP, we allocate a spare bio... |
680 | */ | 735 | */ |
681 | struct bio *bio = bio_alloc(GFP_NOIO, 1); | 736 | struct bio *bio = bio_alloc(GFP_NOIO, 1); |
682 | int rw = (1<<BIO_RW) | (1<<BIO_RW_SYNCIO) | (1<<BIO_RW_UNPLUG); | 737 | int rw = REQ_WRITE | REQ_SYNC | REQ_UNPLUG; |
683 | 738 | ||
684 | bio->bi_bdev = rdev->bdev; | 739 | bio->bi_bdev = rdev->bdev; |
685 | bio->bi_sector = sector; | 740 | bio->bi_sector = sector; |
@@ -691,7 +746,7 @@ void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, | |||
691 | atomic_inc(&mddev->pending_writes); | 746 | atomic_inc(&mddev->pending_writes); |
692 | if (!test_bit(BarriersNotsupp, &rdev->flags)) { | 747 | if (!test_bit(BarriersNotsupp, &rdev->flags)) { |
693 | struct bio *rbio; | 748 | struct bio *rbio; |
694 | rw |= (1<<BIO_RW_BARRIER); | 749 | rw |= REQ_HARDBARRIER; |
695 | rbio = bio_clone(bio, GFP_NOIO); | 750 | rbio = bio_clone(bio, GFP_NOIO); |
696 | rbio->bi_private = bio; | 751 | rbio->bi_private = bio; |
697 | rbio->bi_end_io = super_written_barrier; | 752 | rbio->bi_end_io = super_written_barrier; |
@@ -736,7 +791,7 @@ int sync_page_io(struct block_device *bdev, sector_t sector, int size, | |||
736 | struct completion event; | 791 | struct completion event; |
737 | int ret; | 792 | int ret; |
738 | 793 | ||
739 | rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); | 794 | rw |= REQ_SYNC | REQ_UNPLUG; |
740 | 795 | ||
741 | bio->bi_bdev = bdev; | 796 | bio->bi_bdev = bdev; |
742 | bio->bi_sector = sector; | 797 | bio->bi_sector = sector; |
@@ -1811,11 +1866,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) | |||
1811 | goto fail; | 1866 | goto fail; |
1812 | 1867 | ||
1813 | ko = &part_to_dev(rdev->bdev->bd_part)->kobj; | 1868 | ko = &part_to_dev(rdev->bdev->bd_part)->kobj; |
1814 | if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { | 1869 | if (sysfs_create_link(&rdev->kobj, ko, "block")) |
1815 | kobject_del(&rdev->kobj); | 1870 | /* failure here is OK */; |
1816 | goto fail; | 1871 | rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state"); |
1817 | } | ||
1818 | rdev->sysfs_state = sysfs_get_dirent(rdev->kobj.sd, NULL, "state"); | ||
1819 | 1872 | ||
1820 | list_add_rcu(&rdev->same_set, &mddev->disks); | 1873 | list_add_rcu(&rdev->same_set, &mddev->disks); |
1821 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); | 1874 | bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); |
@@ -2334,8 +2387,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len) | |||
2334 | set_bit(In_sync, &rdev->flags); | 2387 | set_bit(In_sync, &rdev->flags); |
2335 | err = 0; | 2388 | err = 0; |
2336 | } | 2389 | } |
2337 | if (!err && rdev->sysfs_state) | 2390 | if (!err) |
2338 | sysfs_notify_dirent(rdev->sysfs_state); | 2391 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
2339 | return err ? err : len; | 2392 | return err ? err : len; |
2340 | } | 2393 | } |
2341 | static struct rdev_sysfs_entry rdev_state = | 2394 | static struct rdev_sysfs_entry rdev_state = |
@@ -2430,14 +2483,10 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) | |||
2430 | rdev->raid_disk = -1; | 2483 | rdev->raid_disk = -1; |
2431 | return err; | 2484 | return err; |
2432 | } else | 2485 | } else |
2433 | sysfs_notify_dirent(rdev->sysfs_state); | 2486 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
2434 | sprintf(nm, "rd%d", rdev->raid_disk); | 2487 | sprintf(nm, "rd%d", rdev->raid_disk); |
2435 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) | 2488 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) |
2436 | printk(KERN_WARNING | 2489 | /* failure here is OK */; |
2437 | "md: cannot register " | ||
2438 | "%s for %s\n", | ||
2439 | nm, mdname(rdev->mddev)); | ||
2440 | |||
2441 | /* don't wakeup anyone, leave that to userspace. */ | 2490 | /* don't wakeup anyone, leave that to userspace. */ |
2442 | } else { | 2491 | } else { |
2443 | if (slot >= rdev->mddev->raid_disks) | 2492 | if (slot >= rdev->mddev->raid_disks) |
@@ -2447,7 +2496,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) | |||
2447 | clear_bit(Faulty, &rdev->flags); | 2496 | clear_bit(Faulty, &rdev->flags); |
2448 | clear_bit(WriteMostly, &rdev->flags); | 2497 | clear_bit(WriteMostly, &rdev->flags); |
2449 | set_bit(In_sync, &rdev->flags); | 2498 | set_bit(In_sync, &rdev->flags); |
2450 | sysfs_notify_dirent(rdev->sysfs_state); | 2499 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
2451 | } | 2500 | } |
2452 | return len; | 2501 | return len; |
2453 | } | 2502 | } |
@@ -2695,6 +2744,24 @@ static struct kobj_type rdev_ktype = { | |||
2695 | .default_attrs = rdev_default_attrs, | 2744 | .default_attrs = rdev_default_attrs, |
2696 | }; | 2745 | }; |
2697 | 2746 | ||
2747 | void md_rdev_init(mdk_rdev_t *rdev) | ||
2748 | { | ||
2749 | rdev->desc_nr = -1; | ||
2750 | rdev->saved_raid_disk = -1; | ||
2751 | rdev->raid_disk = -1; | ||
2752 | rdev->flags = 0; | ||
2753 | rdev->data_offset = 0; | ||
2754 | rdev->sb_events = 0; | ||
2755 | rdev->last_read_error.tv_sec = 0; | ||
2756 | rdev->last_read_error.tv_nsec = 0; | ||
2757 | atomic_set(&rdev->nr_pending, 0); | ||
2758 | atomic_set(&rdev->read_errors, 0); | ||
2759 | atomic_set(&rdev->corrected_errors, 0); | ||
2760 | |||
2761 | INIT_LIST_HEAD(&rdev->same_set); | ||
2762 | init_waitqueue_head(&rdev->blocked_wait); | ||
2763 | } | ||
2764 | EXPORT_SYMBOL_GPL(md_rdev_init); | ||
2698 | /* | 2765 | /* |
2699 | * Import a device. If 'super_format' >= 0, then sanity check the superblock | 2766 | * Import a device. If 'super_format' >= 0, then sanity check the superblock |
2700 | * | 2767 | * |
@@ -2718,6 +2785,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi | |||
2718 | return ERR_PTR(-ENOMEM); | 2785 | return ERR_PTR(-ENOMEM); |
2719 | } | 2786 | } |
2720 | 2787 | ||
2788 | md_rdev_init(rdev); | ||
2721 | if ((err = alloc_disk_sb(rdev))) | 2789 | if ((err = alloc_disk_sb(rdev))) |
2722 | goto abort_free; | 2790 | goto abort_free; |
2723 | 2791 | ||
@@ -2727,18 +2795,6 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi | |||
2727 | 2795 | ||
2728 | kobject_init(&rdev->kobj, &rdev_ktype); | 2796 | kobject_init(&rdev->kobj, &rdev_ktype); |
2729 | 2797 | ||
2730 | rdev->desc_nr = -1; | ||
2731 | rdev->saved_raid_disk = -1; | ||
2732 | rdev->raid_disk = -1; | ||
2733 | rdev->flags = 0; | ||
2734 | rdev->data_offset = 0; | ||
2735 | rdev->sb_events = 0; | ||
2736 | rdev->last_read_error.tv_sec = 0; | ||
2737 | rdev->last_read_error.tv_nsec = 0; | ||
2738 | atomic_set(&rdev->nr_pending, 0); | ||
2739 | atomic_set(&rdev->read_errors, 0); | ||
2740 | atomic_set(&rdev->corrected_errors, 0); | ||
2741 | |||
2742 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; | 2798 | size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; |
2743 | if (!size) { | 2799 | if (!size) { |
2744 | printk(KERN_WARNING | 2800 | printk(KERN_WARNING |
@@ -2767,9 +2823,6 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi | |||
2767 | } | 2823 | } |
2768 | } | 2824 | } |
2769 | 2825 | ||
2770 | INIT_LIST_HEAD(&rdev->same_set); | ||
2771 | init_waitqueue_head(&rdev->blocked_wait); | ||
2772 | |||
2773 | return rdev; | 2826 | return rdev; |
2774 | 2827 | ||
2775 | abort_free: | 2828 | abort_free: |
@@ -2960,7 +3013,9 @@ level_store(mddev_t *mddev, const char *buf, size_t len) | |||
2960 | * - new personality will access other array. | 3013 | * - new personality will access other array. |
2961 | */ | 3014 | */ |
2962 | 3015 | ||
2963 | if (mddev->sync_thread || mddev->reshape_position != MaxSector) | 3016 | if (mddev->sync_thread || |
3017 | mddev->reshape_position != MaxSector || | ||
3018 | mddev->sysfs_active) | ||
2964 | return -EBUSY; | 3019 | return -EBUSY; |
2965 | 3020 | ||
2966 | if (!mddev->pers->quiesce) { | 3021 | if (!mddev->pers->quiesce) { |
@@ -3437,7 +3492,7 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len) | |||
3437 | if (err) | 3492 | if (err) |
3438 | return err; | 3493 | return err; |
3439 | else { | 3494 | else { |
3440 | sysfs_notify_dirent(mddev->sysfs_state); | 3495 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
3441 | return len; | 3496 | return len; |
3442 | } | 3497 | } |
3443 | } | 3498 | } |
@@ -3735,7 +3790,7 @@ action_store(mddev_t *mddev, const char *page, size_t len) | |||
3735 | } | 3790 | } |
3736 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | 3791 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
3737 | md_wakeup_thread(mddev->thread); | 3792 | md_wakeup_thread(mddev->thread); |
3738 | sysfs_notify_dirent(mddev->sysfs_action); | 3793 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
3739 | return len; | 3794 | return len; |
3740 | } | 3795 | } |
3741 | 3796 | ||
@@ -4281,13 +4336,14 @@ static int md_alloc(dev_t dev, char *name) | |||
4281 | disk->disk_name); | 4336 | disk->disk_name); |
4282 | error = 0; | 4337 | error = 0; |
4283 | } | 4338 | } |
4284 | if (sysfs_create_group(&mddev->kobj, &md_bitmap_group)) | 4339 | if (mddev->kobj.sd && |
4340 | sysfs_create_group(&mddev->kobj, &md_bitmap_group)) | ||
4285 | printk(KERN_DEBUG "pointless warning\n"); | 4341 | printk(KERN_DEBUG "pointless warning\n"); |
4286 | abort: | 4342 | abort: |
4287 | mutex_unlock(&disks_mutex); | 4343 | mutex_unlock(&disks_mutex); |
4288 | if (!error) { | 4344 | if (!error && mddev->kobj.sd) { |
4289 | kobject_uevent(&mddev->kobj, KOBJ_ADD); | 4345 | kobject_uevent(&mddev->kobj, KOBJ_ADD); |
4290 | mddev->sysfs_state = sysfs_get_dirent(mddev->kobj.sd, NULL, "array_state"); | 4346 | mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state"); |
4291 | } | 4347 | } |
4292 | mddev_put(mddev); | 4348 | mddev_put(mddev); |
4293 | return error; | 4349 | return error; |
@@ -4325,14 +4381,14 @@ static void md_safemode_timeout(unsigned long data) | |||
4325 | if (!atomic_read(&mddev->writes_pending)) { | 4381 | if (!atomic_read(&mddev->writes_pending)) { |
4326 | mddev->safemode = 1; | 4382 | mddev->safemode = 1; |
4327 | if (mddev->external) | 4383 | if (mddev->external) |
4328 | sysfs_notify_dirent(mddev->sysfs_state); | 4384 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
4329 | } | 4385 | } |
4330 | md_wakeup_thread(mddev->thread); | 4386 | md_wakeup_thread(mddev->thread); |
4331 | } | 4387 | } |
4332 | 4388 | ||
4333 | static int start_dirty_degraded; | 4389 | static int start_dirty_degraded; |
4334 | 4390 | ||
4335 | static int md_run(mddev_t *mddev) | 4391 | int md_run(mddev_t *mddev) |
4336 | { | 4392 | { |
4337 | int err; | 4393 | int err; |
4338 | mdk_rdev_t *rdev; | 4394 | mdk_rdev_t *rdev; |
@@ -4344,13 +4400,9 @@ static int md_run(mddev_t *mddev) | |||
4344 | 4400 | ||
4345 | if (mddev->pers) | 4401 | if (mddev->pers) |
4346 | return -EBUSY; | 4402 | return -EBUSY; |
4347 | 4403 | /* Cannot run until previous stop completes properly */ | |
4348 | /* These two calls synchronise us with the | 4404 | if (mddev->sysfs_active) |
4349 | * sysfs_remove_group calls in mddev_unlock, | 4405 | return -EBUSY; |
4350 | * so they must have completed. | ||
4351 | */ | ||
4352 | mutex_lock(&mddev->open_mutex); | ||
4353 | mutex_unlock(&mddev->open_mutex); | ||
4354 | 4406 | ||
4355 | /* | 4407 | /* |
4356 | * Analyze all RAID superblock(s) | 4408 | * Analyze all RAID superblock(s) |
@@ -4397,7 +4449,7 @@ static int md_run(mddev_t *mddev) | |||
4397 | return -EINVAL; | 4449 | return -EINVAL; |
4398 | } | 4450 | } |
4399 | } | 4451 | } |
4400 | sysfs_notify_dirent(rdev->sysfs_state); | 4452 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
4401 | } | 4453 | } |
4402 | 4454 | ||
4403 | spin_lock(&pers_lock); | 4455 | spin_lock(&pers_lock); |
@@ -4496,11 +4548,12 @@ static int md_run(mddev_t *mddev) | |||
4496 | return err; | 4548 | return err; |
4497 | } | 4549 | } |
4498 | if (mddev->pers->sync_request) { | 4550 | if (mddev->pers->sync_request) { |
4499 | if (sysfs_create_group(&mddev->kobj, &md_redundancy_group)) | 4551 | if (mddev->kobj.sd && |
4552 | sysfs_create_group(&mddev->kobj, &md_redundancy_group)) | ||
4500 | printk(KERN_WARNING | 4553 | printk(KERN_WARNING |
4501 | "md: cannot register extra attributes for %s\n", | 4554 | "md: cannot register extra attributes for %s\n", |
4502 | mdname(mddev)); | 4555 | mdname(mddev)); |
4503 | mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, NULL, "sync_action"); | 4556 | mddev->sysfs_action = sysfs_get_dirent_safe(mddev->kobj.sd, "sync_action"); |
4504 | } else if (mddev->ro == 2) /* auto-readonly not meaningful */ | 4557 | } else if (mddev->ro == 2) /* auto-readonly not meaningful */ |
4505 | mddev->ro = 0; | 4558 | mddev->ro = 0; |
4506 | 4559 | ||
@@ -4518,8 +4571,7 @@ static int md_run(mddev_t *mddev) | |||
4518 | char nm[20]; | 4571 | char nm[20]; |
4519 | sprintf(nm, "rd%d", rdev->raid_disk); | 4572 | sprintf(nm, "rd%d", rdev->raid_disk); |
4520 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) | 4573 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) |
4521 | printk("md: cannot register %s for %s\n", | 4574 | /* failure here is OK */; |
4522 | nm, mdname(mddev)); | ||
4523 | } | 4575 | } |
4524 | 4576 | ||
4525 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | 4577 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
@@ -4531,12 +4583,12 @@ static int md_run(mddev_t *mddev) | |||
4531 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ | 4583 | md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ |
4532 | 4584 | ||
4533 | md_new_event(mddev); | 4585 | md_new_event(mddev); |
4534 | sysfs_notify_dirent(mddev->sysfs_state); | 4586 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
4535 | if (mddev->sysfs_action) | 4587 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
4536 | sysfs_notify_dirent(mddev->sysfs_action); | ||
4537 | sysfs_notify(&mddev->kobj, NULL, "degraded"); | 4588 | sysfs_notify(&mddev->kobj, NULL, "degraded"); |
4538 | return 0; | 4589 | return 0; |
4539 | } | 4590 | } |
4591 | EXPORT_SYMBOL_GPL(md_run); | ||
4540 | 4592 | ||
4541 | static int do_md_run(mddev_t *mddev) | 4593 | static int do_md_run(mddev_t *mddev) |
4542 | { | 4594 | { |
@@ -4545,7 +4597,11 @@ static int do_md_run(mddev_t *mddev) | |||
4545 | err = md_run(mddev); | 4597 | err = md_run(mddev); |
4546 | if (err) | 4598 | if (err) |
4547 | goto out; | 4599 | goto out; |
4548 | 4600 | err = bitmap_load(mddev); | |
4601 | if (err) { | ||
4602 | bitmap_destroy(mddev); | ||
4603 | goto out; | ||
4604 | } | ||
4549 | set_capacity(mddev->gendisk, mddev->array_sectors); | 4605 | set_capacity(mddev->gendisk, mddev->array_sectors); |
4550 | revalidate_disk(mddev->gendisk); | 4606 | revalidate_disk(mddev->gendisk); |
4551 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); | 4607 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
@@ -4573,7 +4629,7 @@ static int restart_array(mddev_t *mddev) | |||
4573 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | 4629 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
4574 | md_wakeup_thread(mddev->thread); | 4630 | md_wakeup_thread(mddev->thread); |
4575 | md_wakeup_thread(mddev->sync_thread); | 4631 | md_wakeup_thread(mddev->sync_thread); |
4576 | sysfs_notify_dirent(mddev->sysfs_state); | 4632 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
4577 | return 0; | 4633 | return 0; |
4578 | } | 4634 | } |
4579 | 4635 | ||
@@ -4644,9 +4700,10 @@ static void md_clean(mddev_t *mddev) | |||
4644 | mddev->bitmap_info.chunksize = 0; | 4700 | mddev->bitmap_info.chunksize = 0; |
4645 | mddev->bitmap_info.daemon_sleep = 0; | 4701 | mddev->bitmap_info.daemon_sleep = 0; |
4646 | mddev->bitmap_info.max_write_behind = 0; | 4702 | mddev->bitmap_info.max_write_behind = 0; |
4703 | mddev->plug = NULL; | ||
4647 | } | 4704 | } |
4648 | 4705 | ||
4649 | static void md_stop_writes(mddev_t *mddev) | 4706 | void md_stop_writes(mddev_t *mddev) |
4650 | { | 4707 | { |
4651 | if (mddev->sync_thread) { | 4708 | if (mddev->sync_thread) { |
4652 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); | 4709 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
@@ -4666,11 +4723,10 @@ static void md_stop_writes(mddev_t *mddev) | |||
4666 | md_update_sb(mddev, 1); | 4723 | md_update_sb(mddev, 1); |
4667 | } | 4724 | } |
4668 | } | 4725 | } |
4726 | EXPORT_SYMBOL_GPL(md_stop_writes); | ||
4669 | 4727 | ||
4670 | static void md_stop(mddev_t *mddev) | 4728 | void md_stop(mddev_t *mddev) |
4671 | { | 4729 | { |
4672 | md_stop_writes(mddev); | ||
4673 | |||
4674 | mddev->pers->stop(mddev); | 4730 | mddev->pers->stop(mddev); |
4675 | if (mddev->pers->sync_request && mddev->to_remove == NULL) | 4731 | if (mddev->pers->sync_request && mddev->to_remove == NULL) |
4676 | mddev->to_remove = &md_redundancy_group; | 4732 | mddev->to_remove = &md_redundancy_group; |
@@ -4678,6 +4734,7 @@ static void md_stop(mddev_t *mddev) | |||
4678 | mddev->pers = NULL; | 4734 | mddev->pers = NULL; |
4679 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); | 4735 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
4680 | } | 4736 | } |
4737 | EXPORT_SYMBOL_GPL(md_stop); | ||
4681 | 4738 | ||
4682 | static int md_set_readonly(mddev_t *mddev, int is_open) | 4739 | static int md_set_readonly(mddev_t *mddev, int is_open) |
4683 | { | 4740 | { |
@@ -4697,7 +4754,7 @@ static int md_set_readonly(mddev_t *mddev, int is_open) | |||
4697 | mddev->ro = 1; | 4754 | mddev->ro = 1; |
4698 | set_disk_ro(mddev->gendisk, 1); | 4755 | set_disk_ro(mddev->gendisk, 1); |
4699 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); | 4756 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
4700 | sysfs_notify_dirent(mddev->sysfs_state); | 4757 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
4701 | err = 0; | 4758 | err = 0; |
4702 | } | 4759 | } |
4703 | out: | 4760 | out: |
@@ -4711,26 +4768,29 @@ out: | |||
4711 | */ | 4768 | */ |
4712 | static int do_md_stop(mddev_t * mddev, int mode, int is_open) | 4769 | static int do_md_stop(mddev_t * mddev, int mode, int is_open) |
4713 | { | 4770 | { |
4714 | int err = 0; | ||
4715 | struct gendisk *disk = mddev->gendisk; | 4771 | struct gendisk *disk = mddev->gendisk; |
4716 | mdk_rdev_t *rdev; | 4772 | mdk_rdev_t *rdev; |
4717 | 4773 | ||
4718 | mutex_lock(&mddev->open_mutex); | 4774 | mutex_lock(&mddev->open_mutex); |
4719 | if (atomic_read(&mddev->openers) > is_open) { | 4775 | if (atomic_read(&mddev->openers) > is_open || |
4776 | mddev->sysfs_active) { | ||
4720 | printk("md: %s still in use.\n",mdname(mddev)); | 4777 | printk("md: %s still in use.\n",mdname(mddev)); |
4721 | err = -EBUSY; | 4778 | mutex_unlock(&mddev->open_mutex); |
4722 | } else if (mddev->pers) { | 4779 | return -EBUSY; |
4780 | } | ||
4723 | 4781 | ||
4782 | if (mddev->pers) { | ||
4724 | if (mddev->ro) | 4783 | if (mddev->ro) |
4725 | set_disk_ro(disk, 0); | 4784 | set_disk_ro(disk, 0); |
4726 | 4785 | ||
4786 | md_stop_writes(mddev); | ||
4727 | md_stop(mddev); | 4787 | md_stop(mddev); |
4728 | mddev->queue->merge_bvec_fn = NULL; | 4788 | mddev->queue->merge_bvec_fn = NULL; |
4729 | mddev->queue->unplug_fn = NULL; | 4789 | mddev->queue->unplug_fn = NULL; |
4730 | mddev->queue->backing_dev_info.congested_fn = NULL; | 4790 | mddev->queue->backing_dev_info.congested_fn = NULL; |
4731 | 4791 | ||
4732 | /* tell userspace to handle 'inactive' */ | 4792 | /* tell userspace to handle 'inactive' */ |
4733 | sysfs_notify_dirent(mddev->sysfs_state); | 4793 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
4734 | 4794 | ||
4735 | list_for_each_entry(rdev, &mddev->disks, same_set) | 4795 | list_for_each_entry(rdev, &mddev->disks, same_set) |
4736 | if (rdev->raid_disk >= 0) { | 4796 | if (rdev->raid_disk >= 0) { |
@@ -4740,21 +4800,17 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open) | |||
4740 | } | 4800 | } |
4741 | 4801 | ||
4742 | set_capacity(disk, 0); | 4802 | set_capacity(disk, 0); |
4803 | mutex_unlock(&mddev->open_mutex); | ||
4743 | revalidate_disk(disk); | 4804 | revalidate_disk(disk); |
4744 | 4805 | ||
4745 | if (mddev->ro) | 4806 | if (mddev->ro) |
4746 | mddev->ro = 0; | 4807 | mddev->ro = 0; |
4747 | 4808 | } else | |
4748 | err = 0; | 4809 | mutex_unlock(&mddev->open_mutex); |
4749 | } | ||
4750 | mutex_unlock(&mddev->open_mutex); | ||
4751 | if (err) | ||
4752 | return err; | ||
4753 | /* | 4810 | /* |
4754 | * Free resources if final stop | 4811 | * Free resources if final stop |
4755 | */ | 4812 | */ |
4756 | if (mode == 0) { | 4813 | if (mode == 0) { |
4757 | |||
4758 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); | 4814 | printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); |
4759 | 4815 | ||
4760 | bitmap_destroy(mddev); | 4816 | bitmap_destroy(mddev); |
@@ -4771,13 +4827,11 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open) | |||
4771 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); | 4827 | kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); |
4772 | if (mddev->hold_active == UNTIL_STOP) | 4828 | if (mddev->hold_active == UNTIL_STOP) |
4773 | mddev->hold_active = 0; | 4829 | mddev->hold_active = 0; |
4774 | |||
4775 | } | 4830 | } |
4776 | err = 0; | ||
4777 | blk_integrity_unregister(disk); | 4831 | blk_integrity_unregister(disk); |
4778 | md_new_event(mddev); | 4832 | md_new_event(mddev); |
4779 | sysfs_notify_dirent(mddev->sysfs_state); | 4833 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
4780 | return err; | 4834 | return 0; |
4781 | } | 4835 | } |
4782 | 4836 | ||
4783 | #ifndef MODULE | 4837 | #ifndef MODULE |
@@ -5138,7 +5192,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) | |||
5138 | if (err) | 5192 | if (err) |
5139 | export_rdev(rdev); | 5193 | export_rdev(rdev); |
5140 | else | 5194 | else |
5141 | sysfs_notify_dirent(rdev->sysfs_state); | 5195 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
5142 | 5196 | ||
5143 | md_update_sb(mddev, 1); | 5197 | md_update_sb(mddev, 1); |
5144 | if (mddev->degraded) | 5198 | if (mddev->degraded) |
@@ -5331,8 +5385,11 @@ static int set_bitmap_file(mddev_t *mddev, int fd) | |||
5331 | err = 0; | 5385 | err = 0; |
5332 | if (mddev->pers) { | 5386 | if (mddev->pers) { |
5333 | mddev->pers->quiesce(mddev, 1); | 5387 | mddev->pers->quiesce(mddev, 1); |
5334 | if (fd >= 0) | 5388 | if (fd >= 0) { |
5335 | err = bitmap_create(mddev); | 5389 | err = bitmap_create(mddev); |
5390 | if (!err) | ||
5391 | err = bitmap_load(mddev); | ||
5392 | } | ||
5336 | if (fd < 0 || err) { | 5393 | if (fd < 0 || err) { |
5337 | bitmap_destroy(mddev); | 5394 | bitmap_destroy(mddev); |
5338 | fd = -1; /* make sure to put the file */ | 5395 | fd = -1; /* make sure to put the file */ |
@@ -5581,6 +5638,8 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) | |||
5581 | mddev->bitmap_info.default_offset; | 5638 | mddev->bitmap_info.default_offset; |
5582 | mddev->pers->quiesce(mddev, 1); | 5639 | mddev->pers->quiesce(mddev, 1); |
5583 | rv = bitmap_create(mddev); | 5640 | rv = bitmap_create(mddev); |
5641 | if (!rv) | ||
5642 | rv = bitmap_load(mddev); | ||
5584 | if (rv) | 5643 | if (rv) |
5585 | bitmap_destroy(mddev); | 5644 | bitmap_destroy(mddev); |
5586 | mddev->pers->quiesce(mddev, 0); | 5645 | mddev->pers->quiesce(mddev, 0); |
@@ -5813,7 +5872,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, | |||
5813 | if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { | 5872 | if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { |
5814 | if (mddev->ro == 2) { | 5873 | if (mddev->ro == 2) { |
5815 | mddev->ro = 0; | 5874 | mddev->ro = 0; |
5816 | sysfs_notify_dirent(mddev->sysfs_state); | 5875 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
5817 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | 5876 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
5818 | md_wakeup_thread(mddev->thread); | 5877 | md_wakeup_thread(mddev->thread); |
5819 | } else { | 5878 | } else { |
@@ -5902,6 +5961,7 @@ static int md_open(struct block_device *bdev, fmode_t mode) | |||
5902 | mddev_t *mddev = mddev_find(bdev->bd_dev); | 5961 | mddev_t *mddev = mddev_find(bdev->bd_dev); |
5903 | int err; | 5962 | int err; |
5904 | 5963 | ||
5964 | lock_kernel(); | ||
5905 | if (mddev->gendisk != bdev->bd_disk) { | 5965 | if (mddev->gendisk != bdev->bd_disk) { |
5906 | /* we are racing with mddev_put which is discarding this | 5966 | /* we are racing with mddev_put which is discarding this |
5907 | * bd_disk. | 5967 | * bd_disk. |
@@ -5910,6 +5970,7 @@ static int md_open(struct block_device *bdev, fmode_t mode) | |||
5910 | /* Wait until bdev->bd_disk is definitely gone */ | 5970 | /* Wait until bdev->bd_disk is definitely gone */ |
5911 | flush_scheduled_work(); | 5971 | flush_scheduled_work(); |
5912 | /* Then retry the open from the top */ | 5972 | /* Then retry the open from the top */ |
5973 | unlock_kernel(); | ||
5913 | return -ERESTARTSYS; | 5974 | return -ERESTARTSYS; |
5914 | } | 5975 | } |
5915 | BUG_ON(mddev != bdev->bd_disk->private_data); | 5976 | BUG_ON(mddev != bdev->bd_disk->private_data); |
@@ -5923,6 +5984,7 @@ static int md_open(struct block_device *bdev, fmode_t mode) | |||
5923 | 5984 | ||
5924 | check_disk_size_change(mddev->gendisk, bdev); | 5985 | check_disk_size_change(mddev->gendisk, bdev); |
5925 | out: | 5986 | out: |
5987 | unlock_kernel(); | ||
5926 | return err; | 5988 | return err; |
5927 | } | 5989 | } |
5928 | 5990 | ||
@@ -5931,8 +5993,10 @@ static int md_release(struct gendisk *disk, fmode_t mode) | |||
5931 | mddev_t *mddev = disk->private_data; | 5993 | mddev_t *mddev = disk->private_data; |
5932 | 5994 | ||
5933 | BUG_ON(!mddev); | 5995 | BUG_ON(!mddev); |
5996 | lock_kernel(); | ||
5934 | atomic_dec(&mddev->openers); | 5997 | atomic_dec(&mddev->openers); |
5935 | mddev_put(mddev); | 5998 | mddev_put(mddev); |
5999 | unlock_kernel(); | ||
5936 | 6000 | ||
5937 | return 0; | 6001 | return 0; |
5938 | } | 6002 | } |
@@ -6059,10 +6123,12 @@ void md_error(mddev_t *mddev, mdk_rdev_t *rdev) | |||
6059 | mddev->pers->error_handler(mddev,rdev); | 6123 | mddev->pers->error_handler(mddev,rdev); |
6060 | if (mddev->degraded) | 6124 | if (mddev->degraded) |
6061 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); | 6125 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
6062 | sysfs_notify_dirent(rdev->sysfs_state); | 6126 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
6063 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); | 6127 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
6064 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | 6128 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
6065 | md_wakeup_thread(mddev->thread); | 6129 | md_wakeup_thread(mddev->thread); |
6130 | if (mddev->event_work.func) | ||
6131 | schedule_work(&mddev->event_work); | ||
6066 | md_new_event_inintr(mddev); | 6132 | md_new_event_inintr(mddev); |
6067 | } | 6133 | } |
6068 | 6134 | ||
@@ -6520,7 +6586,7 @@ void md_write_start(mddev_t *mddev, struct bio *bi) | |||
6520 | spin_unlock_irq(&mddev->write_lock); | 6586 | spin_unlock_irq(&mddev->write_lock); |
6521 | } | 6587 | } |
6522 | if (did_change) | 6588 | if (did_change) |
6523 | sysfs_notify_dirent(mddev->sysfs_state); | 6589 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
6524 | wait_event(mddev->sb_wait, | 6590 | wait_event(mddev->sb_wait, |
6525 | !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && | 6591 | !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && |
6526 | !test_bit(MD_CHANGE_PENDING, &mddev->flags)); | 6592 | !test_bit(MD_CHANGE_PENDING, &mddev->flags)); |
@@ -6563,7 +6629,7 @@ int md_allow_write(mddev_t *mddev) | |||
6563 | mddev->safemode = 1; | 6629 | mddev->safemode = 1; |
6564 | spin_unlock_irq(&mddev->write_lock); | 6630 | spin_unlock_irq(&mddev->write_lock); |
6565 | md_update_sb(mddev, 0); | 6631 | md_update_sb(mddev, 0); |
6566 | sysfs_notify_dirent(mddev->sysfs_state); | 6632 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
6567 | } else | 6633 | } else |
6568 | spin_unlock_irq(&mddev->write_lock); | 6634 | spin_unlock_irq(&mddev->write_lock); |
6569 | 6635 | ||
@@ -6574,6 +6640,14 @@ int md_allow_write(mddev_t *mddev) | |||
6574 | } | 6640 | } |
6575 | EXPORT_SYMBOL_GPL(md_allow_write); | 6641 | EXPORT_SYMBOL_GPL(md_allow_write); |
6576 | 6642 | ||
6643 | void md_unplug(mddev_t *mddev) | ||
6644 | { | ||
6645 | if (mddev->queue) | ||
6646 | blk_unplug(mddev->queue); | ||
6647 | if (mddev->plug) | ||
6648 | mddev->plug->unplug_fn(mddev->plug); | ||
6649 | } | ||
6650 | |||
6577 | #define SYNC_MARKS 10 | 6651 | #define SYNC_MARKS 10 |
6578 | #define SYNC_MARK_STEP (3*HZ) | 6652 | #define SYNC_MARK_STEP (3*HZ) |
6579 | void md_do_sync(mddev_t *mddev) | 6653 | void md_do_sync(mddev_t *mddev) |
@@ -6752,12 +6826,13 @@ void md_do_sync(mddev_t *mddev) | |||
6752 | >= mddev->resync_max - mddev->curr_resync_completed | 6826 | >= mddev->resync_max - mddev->curr_resync_completed |
6753 | )) { | 6827 | )) { |
6754 | /* time to update curr_resync_completed */ | 6828 | /* time to update curr_resync_completed */ |
6755 | blk_unplug(mddev->queue); | 6829 | md_unplug(mddev); |
6756 | wait_event(mddev->recovery_wait, | 6830 | wait_event(mddev->recovery_wait, |
6757 | atomic_read(&mddev->recovery_active) == 0); | 6831 | atomic_read(&mddev->recovery_active) == 0); |
6758 | mddev->curr_resync_completed = | 6832 | mddev->curr_resync_completed = |
6759 | mddev->curr_resync; | 6833 | mddev->curr_resync; |
6760 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); | 6834 | if (mddev->persistent) |
6835 | set_bit(MD_CHANGE_CLEAN, &mddev->flags); | ||
6761 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); | 6836 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
6762 | } | 6837 | } |
6763 | 6838 | ||
@@ -6829,7 +6904,7 @@ void md_do_sync(mddev_t *mddev) | |||
6829 | * about not overloading the IO subsystem. (things like an | 6904 | * about not overloading the IO subsystem. (things like an |
6830 | * e2fsck being done on the RAID array should execute fast) | 6905 | * e2fsck being done on the RAID array should execute fast) |
6831 | */ | 6906 | */ |
6832 | blk_unplug(mddev->queue); | 6907 | md_unplug(mddev); |
6833 | cond_resched(); | 6908 | cond_resched(); |
6834 | 6909 | ||
6835 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 | 6910 | currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 |
@@ -6848,7 +6923,7 @@ void md_do_sync(mddev_t *mddev) | |||
6848 | * this also signals 'finished resyncing' to md_stop | 6923 | * this also signals 'finished resyncing' to md_stop |
6849 | */ | 6924 | */ |
6850 | out: | 6925 | out: |
6851 | blk_unplug(mddev->queue); | 6926 | md_unplug(mddev); |
6852 | 6927 | ||
6853 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); | 6928 | wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); |
6854 | 6929 | ||
@@ -6950,10 +7025,7 @@ static int remove_and_add_spares(mddev_t *mddev) | |||
6950 | sprintf(nm, "rd%d", rdev->raid_disk); | 7025 | sprintf(nm, "rd%d", rdev->raid_disk); |
6951 | if (sysfs_create_link(&mddev->kobj, | 7026 | if (sysfs_create_link(&mddev->kobj, |
6952 | &rdev->kobj, nm)) | 7027 | &rdev->kobj, nm)) |
6953 | printk(KERN_WARNING | 7028 | /* failure here is OK */; |
6954 | "md: cannot register " | ||
6955 | "%s for %s\n", | ||
6956 | nm, mdname(mddev)); | ||
6957 | spares++; | 7029 | spares++; |
6958 | md_new_event(mddev); | 7030 | md_new_event(mddev); |
6959 | set_bit(MD_CHANGE_DEVS, &mddev->flags); | 7031 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
@@ -7046,7 +7118,7 @@ void md_check_recovery(mddev_t *mddev) | |||
7046 | mddev->safemode = 0; | 7118 | mddev->safemode = 0; |
7047 | spin_unlock_irq(&mddev->write_lock); | 7119 | spin_unlock_irq(&mddev->write_lock); |
7048 | if (did_change) | 7120 | if (did_change) |
7049 | sysfs_notify_dirent(mddev->sysfs_state); | 7121 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
7050 | } | 7122 | } |
7051 | 7123 | ||
7052 | if (mddev->flags) | 7124 | if (mddev->flags) |
@@ -7085,7 +7157,7 @@ void md_check_recovery(mddev_t *mddev) | |||
7085 | mddev->recovery = 0; | 7157 | mddev->recovery = 0; |
7086 | /* flag recovery needed just to double check */ | 7158 | /* flag recovery needed just to double check */ |
7087 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | 7159 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
7088 | sysfs_notify_dirent(mddev->sysfs_action); | 7160 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
7089 | md_new_event(mddev); | 7161 | md_new_event(mddev); |
7090 | goto unlock; | 7162 | goto unlock; |
7091 | } | 7163 | } |
@@ -7147,7 +7219,7 @@ void md_check_recovery(mddev_t *mddev) | |||
7147 | mddev->recovery = 0; | 7219 | mddev->recovery = 0; |
7148 | } else | 7220 | } else |
7149 | md_wakeup_thread(mddev->sync_thread); | 7221 | md_wakeup_thread(mddev->sync_thread); |
7150 | sysfs_notify_dirent(mddev->sysfs_action); | 7222 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
7151 | md_new_event(mddev); | 7223 | md_new_event(mddev); |
7152 | } | 7224 | } |
7153 | unlock: | 7225 | unlock: |
@@ -7156,7 +7228,7 @@ void md_check_recovery(mddev_t *mddev) | |||
7156 | if (test_and_clear_bit(MD_RECOVERY_RECOVER, | 7228 | if (test_and_clear_bit(MD_RECOVERY_RECOVER, |
7157 | &mddev->recovery)) | 7229 | &mddev->recovery)) |
7158 | if (mddev->sysfs_action) | 7230 | if (mddev->sysfs_action) |
7159 | sysfs_notify_dirent(mddev->sysfs_action); | 7231 | sysfs_notify_dirent_safe(mddev->sysfs_action); |
7160 | } | 7232 | } |
7161 | mddev_unlock(mddev); | 7233 | mddev_unlock(mddev); |
7162 | } | 7234 | } |
@@ -7164,7 +7236,7 @@ void md_check_recovery(mddev_t *mddev) | |||
7164 | 7236 | ||
7165 | void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) | 7237 | void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) |
7166 | { | 7238 | { |
7167 | sysfs_notify_dirent(rdev->sysfs_state); | 7239 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
7168 | wait_event_timeout(rdev->blocked_wait, | 7240 | wait_event_timeout(rdev->blocked_wait, |
7169 | !test_bit(Blocked, &rdev->flags), | 7241 | !test_bit(Blocked, &rdev->flags), |
7170 | msecs_to_jiffies(5000)); | 7242 | msecs_to_jiffies(5000)); |