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

md/raid5: use wait_on_bit() for R5_Overlap

Convert uses of wait_for_overlap wait queue with R5_Overlap bit to
wait_on_bit() / wake_up_bit().

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Link: https://lore.kernel.org/r/20240827153536.6743-2-artur.paszkiewicz@intel.com
Signed-off-by: Song Liu <song@kernel.org>

authored by

Artur Paszkiewicz and committed by
Song Liu
e6a03207 7f67fdae

+30 -36
+1 -5
drivers/md/raid5-cache.c
··· 2798 2798 { 2799 2799 struct r5l_log *log = READ_ONCE(conf->log); 2800 2800 int i; 2801 - int do_wakeup = 0; 2802 2801 sector_t tree_index; 2803 2802 void __rcu **pslot; 2804 2803 uintptr_t refcount; ··· 2814 2815 for (i = sh->disks; i--; ) { 2815 2816 clear_bit(R5_InJournal, &sh->dev[i].flags); 2816 2817 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 2817 - do_wakeup = 1; 2818 + wake_up_bit(&sh->dev[i].flags, R5_Overlap); 2818 2819 } 2819 2820 2820 2821 /* ··· 2826 2827 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) 2827 2828 if (atomic_dec_and_test(&conf->pending_full_writes)) 2828 2829 md_wakeup_thread(conf->mddev->thread); 2829 - 2830 - if (do_wakeup) 2831 - wake_up(&conf->wait_for_overlap); 2832 2830 2833 2831 spin_lock_irq(&log->stripe_in_journal_lock); 2834 2832 list_del_init(&sh->r5c);
+29 -31
drivers/md/raid5.c
··· 2337 2337 for (i = disks; i--; ) { 2338 2338 struct r5dev *dev = &sh->dev[i]; 2339 2339 if (test_and_clear_bit(R5_Overlap, &dev->flags)) 2340 - wake_up(&sh->raid_conf->wait_for_overlap); 2340 + wake_up_bit(&dev->flags, R5_Overlap); 2341 2341 } 2342 2342 } 2343 2343 local_unlock(&conf->percpu->lock); ··· 3473 3473 * With PPL only writes to consecutive data chunks within a 3474 3474 * stripe are allowed because for a single stripe_head we can 3475 3475 * only have one PPL entry at a time, which describes one data 3476 - * range. Not really an overlap, but wait_for_overlap can be 3476 + * range. Not really an overlap, but R5_Overlap can be 3477 3477 * used to handle this. 3478 3478 */ 3479 3479 sector_t sector; ··· 3652 3652 log_stripe_write_finished(sh); 3653 3653 3654 3654 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 3655 - wake_up(&conf->wait_for_overlap); 3655 + wake_up_bit(&sh->dev[i].flags, R5_Overlap); 3656 3656 3657 3657 while (bi && bi->bi_iter.bi_sector < 3658 3658 sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { ··· 3697 3697 sh->dev[i].toread = NULL; 3698 3698 spin_unlock_irq(&sh->stripe_lock); 3699 3699 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 3700 - wake_up(&conf->wait_for_overlap); 3700 + wake_up_bit(&sh->dev[i].flags, R5_Overlap); 3701 3701 if (bi) 3702 3702 s->to_read--; 3703 3703 while (bi && bi->bi_iter.bi_sector < ··· 3736 3736 BUG_ON(sh->batch_head); 3737 3737 clear_bit(STRIPE_SYNCING, &sh->state); 3738 3738 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) 3739 - wake_up(&conf->wait_for_overlap); 3739 + wake_up_bit(&sh->dev[sh->pd_idx].flags, R5_Overlap); 3740 3740 s->syncing = 0; 3741 3741 s->replacing = 0; 3742 3742 /* There is nothing more to do for sync/check/repair. ··· 4877 4877 { 4878 4878 struct stripe_head *sh, *next; 4879 4879 int i; 4880 - int do_wakeup = 0; 4881 4880 4882 4881 list_for_each_entry_safe(sh, next, &head_sh->batch_list, batch_list) { 4883 4882 ··· 4912 4913 spin_unlock_irq(&sh->stripe_lock); 4913 4914 for (i = 0; i < sh->disks; i++) { 4914 4915 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 4915 - do_wakeup = 1; 4916 + wake_up_bit(&sh->dev[i].flags, R5_Overlap); 4916 4917 sh->dev[i].flags = head_sh->dev[i].flags & 4917 4918 (~((1 << R5_WriteError) | (1 << R5_Overlap))); 4918 4919 } ··· 4926 4927 spin_unlock_irq(&head_sh->stripe_lock); 4927 4928 for (i = 0; i < head_sh->disks; i++) 4928 4929 if (test_and_clear_bit(R5_Overlap, &head_sh->dev[i].flags)) 4929 - do_wakeup = 1; 4930 + wake_up_bit(&head_sh->dev[i].flags, R5_Overlap); 4930 4931 if (head_sh->state & handle_flags) 4931 4932 set_bit(STRIPE_HANDLE, &head_sh->state); 4932 - 4933 - if (do_wakeup) 4934 - wake_up(&head_sh->raid_conf->wait_for_overlap); 4935 4933 } 4936 4934 4937 4935 static void handle_stripe(struct stripe_head *sh) ··· 5194 5198 md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), 1); 5195 5199 clear_bit(STRIPE_SYNCING, &sh->state); 5196 5200 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) 5197 - wake_up(&conf->wait_for_overlap); 5201 + wake_up_bit(&sh->dev[sh->pd_idx].flags, R5_Overlap); 5198 5202 } 5199 5203 5200 5204 /* If the failed drives are just a ReadError, then we might need ··· 5751 5755 int d; 5752 5756 again: 5753 5757 sh = raid5_get_active_stripe(conf, NULL, logical_sector, 0); 5754 - prepare_to_wait(&conf->wait_for_overlap, &w, 5755 - TASK_UNINTERRUPTIBLE); 5756 5758 set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); 5757 5759 if (test_bit(STRIPE_SYNCING, &sh->state)) { 5758 5760 raid5_release_stripe(sh); 5759 - schedule(); 5761 + wait_on_bit(&sh->dev[sh->pd_idx].flags, R5_Overlap, 5762 + TASK_UNINTERRUPTIBLE); 5760 5763 goto again; 5761 5764 } 5762 5765 clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); ··· 5767 5772 set_bit(R5_Overlap, &sh->dev[d].flags); 5768 5773 spin_unlock_irq(&sh->stripe_lock); 5769 5774 raid5_release_stripe(sh); 5770 - schedule(); 5775 + wait_on_bit(&sh->dev[d].flags, R5_Overlap, 5776 + TASK_UNINTERRUPTIBLE); 5771 5777 goto again; 5772 5778 } 5773 5779 } 5774 5780 set_bit(STRIPE_DISCARD, &sh->state); 5775 - finish_wait(&conf->wait_for_overlap, &w); 5776 5781 sh->overwrite_disks = 0; 5777 5782 for (d = 0; d < conf->raid_disks; d++) { 5778 5783 if (d == sh->pd_idx || d == sh->qd_idx) ··· 5849 5854 struct bio *bi, int forwrite, int previous) 5850 5855 { 5851 5856 int dd_idx; 5852 - int ret = 1; 5853 5857 5854 5858 spin_lock_irq(&sh->stripe_lock); 5855 5859 ··· 5864 5870 5865 5871 if (stripe_bio_overlaps(sh, bi, dd_idx, forwrite)) { 5866 5872 set_bit(R5_Overlap, &dev->flags); 5867 - ret = 0; 5868 - continue; 5873 + spin_unlock_irq(&sh->stripe_lock); 5874 + raid5_release_stripe(sh); 5875 + /* release batch_last before wait to avoid risk of deadlock */ 5876 + if (ctx->batch_last) { 5877 + raid5_release_stripe(ctx->batch_last); 5878 + ctx->batch_last = NULL; 5879 + } 5880 + md_wakeup_thread(conf->mddev->thread); 5881 + wait_on_bit(&dev->flags, R5_Overlap, TASK_UNINTERRUPTIBLE); 5882 + return 0; 5869 5883 } 5870 5884 } 5871 - 5872 - if (!ret) 5873 - goto out; 5874 5885 5875 5886 for (dd_idx = 0; dd_idx < sh->disks; dd_idx++) { 5876 5887 struct r5dev *dev = &sh->dev[dd_idx]; ··· 5892 5893 RAID5_STRIPE_SHIFT(conf), ctx->sectors_to_do); 5893 5894 } 5894 5895 5895 - out: 5896 5896 spin_unlock_irq(&sh->stripe_lock); 5897 - return ret; 5897 + return 1; 5898 5898 } 5899 5899 5900 5900 enum reshape_loc { ··· 5989 5991 goto out_release; 5990 5992 } 5991 5993 5992 - if (test_bit(STRIPE_EXPANDING, &sh->state) || 5993 - !add_all_stripe_bios(conf, ctx, sh, bi, rw, previous)) { 5994 - /* 5995 - * Stripe is busy expanding or add failed due to 5996 - * overlap. Flush everything and wait a while. 5997 - */ 5994 + if (test_bit(STRIPE_EXPANDING, &sh->state)) { 5998 5995 md_wakeup_thread(mddev->thread); 5999 5996 ret = STRIPE_SCHEDULE_AND_RETRY; 6000 5997 goto out_release; 5998 + } 5999 + 6000 + if (!add_all_stripe_bios(conf, ctx, sh, bi, rw, previous)) { 6001 + ret = STRIPE_RETRY; 6002 + goto out; 6001 6003 } 6002 6004 6003 6005 if (stripe_can_batch(sh)) {