From patchwork Tue Feb 20 15:30:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13564151 X-Patchwork-Delegate: snitzer@redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D8347603E for ; Tue, 20 Feb 2024 15:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443074; cv=none; b=KQG6MHqejbvU04N5Qwbp23aiX5aGJXjPIs0RWvst00ZFzS+xI9pah/kPlP/al4IGY41MhzKOgIkleU1JZIUuCdlKU/5qQ2SvjZKpr7oqQsc5XDxDQ5XQS6z+dK+1NPMI0voLg++NTUf8tbLEBe1ROvS1IBoDTimDhVMgO+rWsVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443074; c=relaxed/simple; bh=Od8CNV1ADNzBsZEw3RmV5QRga8xdhcUYMZWd2Bz5k0I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sAjr1u2Jg2faLnNc8QvxSRagE+oflh9o4qeWibDR8+q9IZTIAzpmEcruPE43dgVIDLNqwuDw6VJ+qqq6Ywk+BOUTQgiduzH+PLlPDRRKKKuT8EHMLukuEaQ7D0eybYqEZ38BV4AxoHvlJ5+txxZv9o2U3/SNVhjWgjq32xcc910= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FvC/McHT; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FvC/McHT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708443072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+cSYOLk5T0RhspTKBTniAyv+0yvTwfvGhLqNsD6fFzw=; b=FvC/McHTF2y8X3ZhwhkHBEabn1prRJbA4dG9zcET8R5IvcsDaomwRcFts8pGiUqXrkWSX1 XMykmrBAaEHH2bSDkNKb472ot1PuAjbeqxPEzdDFmJ8bvazjkk0AfWDcgLykCV5DPNHrCg Laf6DRt3/tU10w2wdATt4tNMva78HRM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-yqz_JE1iOdKK6VSTgx-teg-1; Tue, 20 Feb 2024 10:31:10 -0500 X-MC-Unique: yqz_JE1iOdKK6VSTgx-teg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71221108C0AA; Tue, 20 Feb 2024 15:31:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0D94200B436; Tue, 20 Feb 2024 15:31:05 +0000 (UTC) From: Xiao Ni To: song@kernel.org Cc: yukuai1@huaweicloud.com, bmarzins@redhat.com, heinzm@redhat.com, snitzer@kernel.org, ncroxon@redhat.com, neilb@suse.de, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev Subject: [PATCH RFC 1/4] dm-raid/md: Clear MD_RECOVERY_WAIT when stopping dmraid Date: Tue, 20 Feb 2024 23:30:56 +0800 Message-Id: <20240220153059.11233-2-xni@redhat.com> In-Reply-To: <20240220153059.11233-1-xni@redhat.com> References: <20240220153059.11233-1-xni@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 MD_RECOVERY_WAIT is used by dmraid to delay reshape process by patch commit 644e2537fdc7 ("dm raid: fix stripe adding reshape deadlock"). Before patch commit f52f5c71f3d4b ("md: fix stopping sync thread") dmraid stopped sync thread directy by calling md_reap_sync_thread. After this patch dmraid stops sync thread asynchronously as md does. This is right. Now the dmraid stop process is like this: 1. raid_postsuspend->md_stop_writes->__md_stop_writes->stop_sync_thread. stop_sync_thread sets MD_RECOVERY_INTR and wait until MD_RECOVERY_RUNNING is cleared 2. md_do_sync finds MD_RECOVERY_WAIT is set and return. (This is the root cause for this deadlock. We hope md_do_sync can set MD_RECOVERY_DONE) 3. md thread calls md_check_recovery (This is the place to reap sync thread. Because MD_RECOVERY_DONE is not set. md thread can't reap sync thread) 4. raid_dtr stops/free struct mddev and release dmraid related resources dmraid only sets MD_RECOVERY_WAIT but doesn't clear it. It needs to clear this bit when stopping the dmraid before stopping sync thread. But the deadlock still can happen sometimes even MD_RECOVERY_WAIT is cleared before stopping sync thread. It's the reason stop_sync_thread only wakes up task. If the task isn't running, it still needs to wake up sync thread too. This deadlock can be reproduced 100% by these commands: modprobe brd rd_size=34816 rd_nr=5 while [ 1 ]; do vgcreate test_vg /dev/ram* lvcreate --type raid5 -L 16M -n test_lv test_vg lvconvert -y --stripes 4 /dev/test_vg/test_lv vgremove test_vg -ff sleep 1 done Fixes: 644e2537fdc7 ("dm raid: fix stripe adding reshape deadlock") Fixes: f52f5c71f3d4 ("md: fix stopping sync thread") Signed-off-by: Xiao Ni --- drivers/md/dm-raid.c | 2 ++ drivers/md/md.c | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index eb009d6bb03a..325767c1140f 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -3796,6 +3796,8 @@ static void raid_postsuspend(struct dm_target *ti) struct raid_set *rs = ti->private; if (!test_and_set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { + if (test_bit(MD_RECOVERY_WAIT, &rs->md.recovery)) + clear_bit(MD_RECOVERY_WAIT, &rs->md.recovery); /* Writes have to be stopped before suspending to avoid deadlocks. */ if (!test_bit(MD_RECOVERY_FROZEN, &rs->md.recovery)) md_stop_writes(&rs->md); diff --git a/drivers/md/md.c b/drivers/md/md.c index 2266358d8074..54790261254d 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4904,6 +4904,7 @@ static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq) * never happen */ md_wakeup_thread_directly(mddev->sync_thread); + md_wakeup_thread(mddev->sync_thread); if (work_pending(&mddev->sync_work)) flush_work(&mddev->sync_work); From patchwork Tue Feb 20 15:30:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13564152 X-Patchwork-Delegate: snitzer@redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D0B2762C1 for ; Tue, 20 Feb 2024 15:31:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443078; cv=none; b=sG1++OBf2nA49nbJ2RQnqd2ndCsnSUt4v1EITuaFyMMPa9fYOmwi8GJw/xsgRXwCtV085ONlFBvttG+vf+3tQGuugrQZIlni6d0lVBB2WSTsam79fZAQvEtupTgQU7dHoS53p6bb6JuloctxqKFn8xgQkDe6jc/GSWgzD0Hq4+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443078; c=relaxed/simple; bh=p3zF3ZqBApEKi6a/GhK0dmTJTW+SmZ/mHlGibr6LBm0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kWs+XR0yJGgsZKjlcctoSES8cg+zDYx/MR34edzSXlNXKUHeJyhbsDwzHaU19yFD3rIFv0lGnaOYliUphIyd/KFRITqbEYd/+DpGLdYTTfC7KmqCzuD87AEHUXNUtDZEy69LY6EJsROhQijNotWxKKkLYC8ePSHg1C8V0b7c6BE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aSFv+8ej; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aSFv+8ej" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708443076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rR6JN4gU7y3tOWM/kqUBGRZmH6XeMtMRLTOjNJqe0CU=; b=aSFv+8ejj+LGygnPxqD8hJtMmwTLWYUC/lEWft3KVg298vVs0M/B4Atb8FYB4WSOXXDFLl HnOEF4L83iqntH5rX/EaUO2VLR4m1WR62UONYdkfZqKqa6lGM+6apsEbIM9LXzniin4mnM ME+gzk/7gSyzbl2E6T/t+pIjGUFfaQk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-Zf9acdOYN5-RHJFAe6OEow-1; Tue, 20 Feb 2024 10:31:14 -0500 X-MC-Unique: Zf9acdOYN5-RHJFAe6OEow-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F0B38185A786; Tue, 20 Feb 2024 15:31:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C9C32022AAC; Tue, 20 Feb 2024 15:31:09 +0000 (UTC) From: Xiao Ni To: song@kernel.org Cc: yukuai1@huaweicloud.com, bmarzins@redhat.com, heinzm@redhat.com, snitzer@kernel.org, ncroxon@redhat.com, neilb@suse.de, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev Subject: [PATCH RFC 2/4] md: Set MD_RECOVERY_FROZEN before stop sync thread Date: Tue, 20 Feb 2024 23:30:57 +0800 Message-Id: <20240220153059.11233-3-xni@redhat.com> In-Reply-To: <20240220153059.11233-1-xni@redhat.com> References: <20240220153059.11233-1-xni@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 After patch commit f52f5c71f3d4b ("md: fix stopping sync thread"), dmraid stops sync thread asynchronously. The calling process is: dev_remove->dm_destroy->__dm_destroy->raid_postsuspend->raid_dtr raid_postsuspend does two jobs. First, it stops sync thread. Then it suspend array. Now it can stop sync thread successfully. But it doesn't set MD_RECOVERY_FROZEN. It's introduced by patch f52f5c71f3d4b. So after raid_postsuspend, the sync thread starts again. raid_dtr can't stop the sync thread because the array is already suspended. This can be reproduced easily by those commands: while [ 1 ]; do vgcreate test_vg /dev/loop0 /dev/loop1 lvcreate --type raid1 -L 400M -m 1 -n test_lv test_vg lvchange -an test_vg vgremove test_vg -ff done Fixes: f52f5c71f3d4 ("md: fix stopping sync thread") Signed-off-by: Xiao Ni --- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/md/md.c b/drivers/md/md.c index 54790261254d..77e3af7cf6bb 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6337,6 +6337,7 @@ static void __md_stop_writes(struct mddev *mddev) void md_stop_writes(struct mddev *mddev) { mddev_lock_nointr(mddev); + set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); __md_stop_writes(mddev); mddev_unlock(mddev); } From patchwork Tue Feb 20 15:30:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13564153 X-Patchwork-Delegate: snitzer@redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E18F9762DA for ; Tue, 20 Feb 2024 15:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443085; cv=none; b=KfwlIXfu/pfPTtrBP2jGb55TWyxZN2Qea4v8QfD4A6ow8zcaPt0sTtzZt4AvpnCWtTfQZzNTWVI0IO+y/p/J7p/b8nd1rmyM3WvSFJK+9/NQtXgmZWU4JCvbGfyELegjnIzmoMjIkmAiiV5U+B/z2tfBF/a4casWecZnAhKY64s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443085; c=relaxed/simple; bh=oSgRYGTEf/dulFhIkSuOVRWdtR0hwQ2/A/X0d3W4ilk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=faYaLf0GFH/tDlo2/6BnA2QFtEm6sd1nclAeLCvWrq20xl4k9MshTdW/15zUes2pIu0Fe4a6nsT3f45MGLPJbjTyplwjbxm9pnlcCu8LteM6oFoLhwl9QVANQ6WrY5tzLZ7zRXcLLMrHzk+UpxbE59DhmctLj/nCyxV4zERBJYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OecHJrn6; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OecHJrn6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708443082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CiRXDnsLJGZiZ2myApdsnHktPfLZueKk1fT0FIW8PV0=; b=OecHJrn6BbYAE9083Vs8H4lGIRdWpf7dMhN48za75Bpwq8d3U1wdyMPi8Vi6z3Q8D8wfNq lQ6kQ5v+qMmWQYW57y2ilc7IodN3PEaRx/qDRjBJz5Dq8jwOXOuxROW+KSLJB24aN2ng1R PVY4hW0iNu/+XDVJTwgHepT1sbFPJ6E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-pNuu2t83Olqs_QRSf56vZw-1; Tue, 20 Feb 2024 10:31:19 -0500 X-MC-Unique: pNuu2t83Olqs_QRSf56vZw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6BEFB84F9D1; Tue, 20 Feb 2024 15:31:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id A10CC20229A4; Tue, 20 Feb 2024 15:31:14 +0000 (UTC) From: Xiao Ni To: song@kernel.org Cc: yukuai1@huaweicloud.com, bmarzins@redhat.com, heinzm@redhat.com, snitzer@kernel.org, ncroxon@redhat.com, neilb@suse.de, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev Subject: [PATCH RFC 3/4] md: Missing decrease active_io for flush io Date: Tue, 20 Feb 2024 23:30:58 +0800 Message-Id: <20240220153059.11233-4-xni@redhat.com> In-Reply-To: <20240220153059.11233-1-xni@redhat.com> References: <20240220153059.11233-1-xni@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 If all flush bios finish fast, it doesn't decrease active_io. And it will stuck when stopping array. This can be reproduced by lvm2 test shell/integrity-caching.sh. But it can't reproduce 100%. Fixes: fa2bbff7b0b4 ("md: synchronize flush io with array reconfiguration") Signed-off-by: Xiao Ni --- drivers/md/md.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 77e3af7cf6bb..a41bed286fd2 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -579,8 +579,12 @@ static void submit_flushes(struct work_struct *ws) rcu_read_lock(); } rcu_read_unlock(); - if (atomic_dec_and_test(&mddev->flush_pending)) + if (atomic_dec_and_test(&mddev->flush_pending)) { + /* The pair is percpu_ref_get() from md_flush_request() */ + percpu_ref_put(&mddev->active_io); + queue_work(md_wq, &mddev->flush_work); + } } static void md_submit_flush_data(struct work_struct *ws) From patchwork Tue Feb 20 15:30:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13564154 X-Patchwork-Delegate: snitzer@redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A613762D3 for ; Tue, 20 Feb 2024 15:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443090; cv=none; b=Gvr+tMJ3vPDItuKPQYtWIBaqrnIYQVzPpXegnM14R+K+Ic5GfIXfG6m067Adyl+6iMcG9jyuOWY4gQY/2rRqR/Dpm6/l8+25ZAnmaJU22HpZBZnZKZsEom+3lUO+tOB9+JrX3VyOQwOor5u6oRGoSHB346vmipCLBJEFFFTowZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708443090; c=relaxed/simple; bh=YQgRhjJnmOdq6hzxnwElyN0M+rhLrw16jErkKXYFXnw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jcmpQzDSYPdi18rgf+BpZw6VvlKf35e+GztfwA37bXq1OeoHrnsVRu1nuLKOtO6pf7J4M9sJcdX+G/zGJW7/rbkbbmd1TXXQgXi6At+gZOksbfjJQUBQgsQNhdUeYhif62ahdQmGomAgKam64qw3MqoWihNFu1Qg3VXR62xukzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TBNIJOwZ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TBNIJOwZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708443087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3O/l03CW7RpLup6cJbwXZ5GvVgqZNdwKAG705VYtdgA=; b=TBNIJOwZsIyoJSOuGNmK+eDNTdVoJN6/WM6TO31F9GyDi0m6qtis2OVGDtB5H1hDCFwgIf whb8VViBf/9o/4kgP7/+rudP1syzvf8s8A9PXlxiPC91PDlYOPLQBR3WMTyi7hXWv5hH+E LmltCAwBYri4VHR3kSNB7oWuCBfhuAY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-4YJFml8aPvaP5-_Lkmn2GA-1; Tue, 20 Feb 2024 10:31:23 -0500 X-MC-Unique: 4YJFml8aPvaP5-_Lkmn2GA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB2803816448; Tue, 20 Feb 2024 15:31:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2681D20229A4; Tue, 20 Feb 2024 15:31:18 +0000 (UTC) From: Xiao Ni To: song@kernel.org Cc: yukuai1@huaweicloud.com, bmarzins@redhat.com, heinzm@redhat.com, snitzer@kernel.org, ncroxon@redhat.com, neilb@suse.de, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev Subject: [PATCH RFC V2 4/4] md/raid5: Don't check crossing reshape when reshape hasn't started Date: Tue, 20 Feb 2024 23:30:59 +0800 Message-Id: <20240220153059.11233-5-xni@redhat.com> In-Reply-To: <20240220153059.11233-1-xni@redhat.com> References: <20240220153059.11233-1-xni@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 stripe_ahead_of_reshape is used to check if a stripe region cross the reshape position. So first, change the function name to stripe_across_reshape to describe the usage of this function. For reshape backwards, it starts reshape from the end of array and conf-> reshape_progress is init to raid5_size. During reshape, if previous is true (set in make_stripe_request) and max_sector >= conf->reshape_progress, ios should wait until reshape window moves forward. But ios don't need to wait if max_sector is raid5_size. And put the conditions into the function directly to make understand the codes easily. This can be reproduced easily by lvm2 test shell/lvconvert-raid-reshape.sh For dm raid reshape, before starting sync thread, it needs to reload table some times. In one time dm raid uses MD_RECOVERY_WAIT to delay reshape and it doesn't start sync thread this time. Then one io comes in and it waits because stripe_ahead_of_reshape returns true because it's a backward reshape and max_sectors > conf->reshape_progress. But the reshape hasn't started. So skip this check when reshape_progress is raid5_size Fixes: 486f60558607 ("md/raid5: Check all disks in a stripe_head for reshape progress") Signed-off-by: Xiao Ni --- drivers/md/raid5.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 8497880135ee..4c71df4e2370 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -5832,17 +5832,12 @@ static bool ahead_of_reshape(struct mddev *mddev, sector_t sector, sector >= reshape_sector; } -static bool range_ahead_of_reshape(struct mddev *mddev, sector_t min, - sector_t max, sector_t reshape_sector) -{ - return mddev->reshape_backwards ? max < reshape_sector : - min >= reshape_sector; -} - -static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf, +static sector_t raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks); +static bool stripe_across_reshape(struct mddev *mddev, struct r5conf *conf, struct stripe_head *sh) { sector_t max_sector = 0, min_sector = MaxSector; + sector_t reshape_pos = 0; bool ret = false; int dd_idx; @@ -5856,9 +5851,12 @@ static bool stripe_ahead_of_reshape(struct mddev *mddev, struct r5conf *conf, spin_lock_irq(&conf->device_lock); - if (!range_ahead_of_reshape(mddev, min_sector, max_sector, - conf->reshape_progress)) - /* mismatch, need to try again */ + reshape_pos = conf->reshape_progress; + if (mddev->reshape_backwards) { + if (max_sector >= reshape_pos && + reshape_pos != raid5_size(mddev, 0, 0)) + ret = true; + } else if (min_sector < reshape_pos) ret = true; spin_unlock_irq(&conf->device_lock); @@ -5969,7 +5967,7 @@ static enum stripe_result make_stripe_request(struct mddev *mddev, } if (unlikely(previous) && - stripe_ahead_of_reshape(mddev, conf, sh)) { + stripe_across_reshape(mddev, conf, sh)) { /* * Expansion moved on while waiting for a stripe. * Expansion could still move past after this