public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] xfs: add lock protection when remove perag from radix tree
@ 2023-12-04  4:39 Long Li
  2023-12-04  4:39 ` [PATCH 2/2] xfs: fix perag leak when growfs fails Long Li
  2023-12-05  4:35 ` [PATCH 1/2] xfs: add lock protection when remove perag from radix tree Christoph Hellwig
  0 siblings, 2 replies; 7+ messages in thread
From: Long Li @ 2023-12-04  4:39 UTC (permalink / raw)
  To: djwong, chandanbabu; +Cc: linux-xfs, yi.zhang, houtao1, leo.lilong, yangerkun

Look at the perag insertion into the radix tree, protected by
mp->m_perag_lock. When the file system is unmounted, the perag is
removed from the radix tree, also protected by mp->m_perag_lock.
Therefore, mp->m_perag_lock is also added when removing a perag
from the radix tree in error path in xfs_initialize_perag().

Signed-off-by: Long Li <leo.lilong@huawei.com>
---
 fs/xfs/libxfs/xfs_ag.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
index f9f4d694640d..cc10a3ca052f 100644
--- a/fs/xfs/libxfs/xfs_ag.c
+++ b/fs/xfs/libxfs/xfs_ag.c
@@ -424,13 +424,17 @@ xfs_initialize_perag(
 
 out_remove_pag:
 	xfs_defer_drain_free(&pag->pag_intents_drain);
+	spin_lock(&mp->m_perag_lock);
 	radix_tree_delete(&mp->m_perag_tree, index);
+	spin_unlock(&mp->m_perag_lock);
 out_free_pag:
 	kmem_free(pag);
 out_unwind_new_pags:
 	/* unwind any prior newly initialized pags */
 	for (index = first_initialised; index < agcount; index++) {
+		spin_lock(&mp->m_perag_lock);
 		pag = radix_tree_delete(&mp->m_perag_tree, index);
+		spin_unlock(&mp->m_perag_lock);
 		if (!pag)
 			break;
 		xfs_buf_hash_destroy(pag);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-12-06 12:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04  4:39 [PATCH 1/2] xfs: add lock protection when remove perag from radix tree Long Li
2023-12-04  4:39 ` [PATCH 2/2] xfs: fix perag leak when growfs fails Long Li
2023-12-05  4:38   ` Christoph Hellwig
2023-12-06 12:48     ` Long Li
2023-12-05  4:35 ` [PATCH 1/2] xfs: add lock protection when remove perag from radix tree Christoph Hellwig
2023-12-05 21:28   ` Dave Chinner
2023-12-06 12:32     ` Long Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox