Re: [PATCH] ocfs2: Protect local_alloc_state updates in load/shutdown

From: Ginger

Date: Mon Sep 28 2026 - 04:09:12 EST


Hi Markus,

Thanks for checking. Do the following changes match your expectation? Thanks.

Sincerely,
Ginger
---
fs/ocfs2/localalloc.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -342,8 +342,10 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb)
goto bail;
}

- osb->local_alloc_bh = alloc_bh;
- osb->local_alloc_state = OCFS2_LA_ENABLED;
+ scoped_guard(spinlock, &osb->osb_lock) {
+ osb->local_alloc_bh = alloc_bh;
+ osb->local_alloc_state = OCFS2_LA_ENABLED;
+ }

bail:
if (status < 0)
@@ -392,7 +394,9 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *os
goto out;
}

- osb->local_alloc_state = OCFS2_LA_DISABLED;
+ scoped_guard(spinlock, &osb->osb_lock) {
+ osb->local_alloc_state = OCFS2_LA_DISABLED;
+ }

ocfs2_resmap_uninit(&osb->osb_la_resmap);

@@ -441,8 +445,10 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *os
ocfs2_journal_dirty(handle, bh);

brelse(bh);
- osb->local_alloc_bh = NULL;
- osb->local_alloc_state = OCFS2_LA_UNUSED;
+ scoped_guard(spinlock, &osb->osb_lock) {
+ osb->local_alloc_bh = NULL;
+ osb->local_alloc_state = OCFS2_LA_UNUSED;
+ }

status = ocfs2_sync_local_to_main(osb, handle, alloc_copy,
main_bm_inode, main_bm_bh);
--
2.43.0

On Thu, Sep 24, 2026 at 6:55 PM Markus Elfring <Markus.Elfring@xxxxxx> wrote:
>
> …
> > Take osb->osb_lock when updating both fields.
>
> May lock guards be applied in affected function implementations?
>
> Regards,
> Markus