public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
* [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety
@ 2026-03-19 13:39 Ajay Rajera
  2026-03-19 13:39 ` [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout Ajay Rajera
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Ajay Rajera @ 2026-03-19 13:39 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, Ajay Rajera

Replace the bool locked field in erofs_diskbufstrm with erofs_mutex_t lock to provide proper mutual exclusion for multi-threaded disk buffer operations. This addresses the TODO comment 'need a real lock for MT' by using the erofs mutex API (erofs_mutex_lock/erofs_mutex_unlock/erofs_mutex_init) instead of a simple boolean flag that provided no actual synchronization.

Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
---
 lib/diskbuf.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/diskbuf.c b/lib/diskbuf.c
index 0bf42da..4218df8 100644
--- a/lib/diskbuf.c
+++ b/lib/diskbuf.c
@@ -3,6 +3,7 @@
 #include "erofs/internal.h"
 #include "erofs/print.h"
 #include <stdio.h>
+#include "erofs/lock.h"
 #include <errno.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -14,7 +15,7 @@ static struct erofs_diskbufstrm {
 	u64 tailoffset, devpos;
 	int fd;
 	unsigned int alignsize;
-	bool locked;
+	erofs_mutex_t lock;
 } *dbufstrm;
 
 int erofs_diskbuf_getfd(struct erofs_diskbuf *db, u64 *fpos)
@@ -34,6 +35,7 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
 {
 	struct erofs_diskbufstrm *strm = dbufstrm + sid;
 
+	erofs_mutex_lock(&strm->lock);
 	if (strm->tailoffset & (strm->alignsize - 1)) {
 		strm->tailoffset = round_up(strm->tailoffset, strm->alignsize);
 	}
@@ -42,7 +44,6 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
 		*off = db->offset + strm->devpos;
 	db->sp = strm;
 	(void)erofs_atomic_inc_return(&strm->count);
-	strm->locked = true;	/* TODO: need a real lock for MT */
 	return strm->fd;
 }
 
@@ -51,9 +52,9 @@ void erofs_diskbuf_commit(struct erofs_diskbuf *db, u64 len)
 	struct erofs_diskbufstrm *strm = db->sp;
 
 	DBG_BUGON(!strm);
-	DBG_BUGON(!strm->locked);
 	DBG_BUGON(strm->tailoffset != db->offset);
 	strm->tailoffset += len;
+	erofs_mutex_unlock(&strm->lock);
 }
 
 void erofs_diskbuf_close(struct erofs_diskbuf *db)
@@ -115,6 +116,7 @@ int erofs_diskbuf_init(unsigned int nstrms)
 setupone:
 		strm->tailoffset = 0;
 		erofs_atomic_set(&strm->count, 1);
+		erofs_mutex_init(&strm->lock);
 		if (fstat(strm->fd, &st))
 			return -errno;
 		strm->alignsize = max_t(u32, st.st_blksize, getpagesize());
-- 
2.51.0.windows.1



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

* [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout
  2026-03-19 13:39 [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Ajay Rajera
@ 2026-03-19 13:39 ` Ajay Rajera
  2026-03-19 13:45   ` Gao Xiang
  2026-03-19 13:42 ` [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Gao Xiang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Ajay Rajera @ 2026-03-19 13:39 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, Ajay Rajera

Fix the FIXME in metabox.c by properly handling meta_blkaddr for 48-bit layouts. In erofs_writesb(), set meta_blkaddr to 0 on-disk when 48-bit layout is enabled since meta_blkaddr is encoded differently in that mode. Remove the now-resolved FIXME comment in metabox.c as the issue is addressed in super.c.

Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
---
 lib/metabox.c | 1 -
 lib/super.c   | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/metabox.c b/lib/metabox.c
index d6abd51..077f88b 100644
--- a/lib/metabox.c
+++ b/lib/metabox.c
@@ -62,7 +62,6 @@ int erofs_metadata_init(struct erofs_sb_info *sbi)
 		if (ret)
 			goto err_free;
 		sbi->m2gr = m2gr;
-		/* FIXME: sbi->meta_blkaddr should be 0 for 48-bit layouts */
 		sbi->meta_blkaddr = EROFS_META_NEW_ADDR;
 	}
 
diff --git a/lib/super.c b/lib/super.c
index 088c9a0..99d2a24 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -209,7 +209,7 @@ int erofs_writesb(struct erofs_sb_info *sbi)
 		.epoch     = cpu_to_le64(sbi->epoch),
 		.build_time = cpu_to_le64(sbi->build_time),
 		.fixed_nsec = cpu_to_le32(sbi->fixed_nsec),
-		.meta_blkaddr  = cpu_to_le32(sbi->meta_blkaddr),
+		.meta_blkaddr  = cpu_to_le32(erofs_sb_has_48bit(sbi) ? 0 : sbi->meta_blkaddr),
 		.xattr_blkaddr = cpu_to_le32(sbi->xattr_blkaddr),
 		.xattr_prefix_count = sbi->xattr_prefix_count,
 		.xattr_prefix_start = cpu_to_le32(sbi->xattr_prefix_start),
-- 
2.51.0.windows.1



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

* Re: [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety
  2026-03-19 13:39 [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Ajay Rajera
  2026-03-19 13:39 ` [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout Ajay Rajera
@ 2026-03-19 13:42 ` Gao Xiang
  2026-03-19 16:05   ` Ajay
  2026-03-19 13:44 ` Ajay
  2026-03-19 15:57 ` [PATCH v2 " Ajay Rajera
  3 siblings, 1 reply; 8+ messages in thread
From: Gao Xiang @ 2026-03-19 13:42 UTC (permalink / raw)
  To: Ajay Rajera, linux-erofs; +Cc: xiang

Hi Ajay,

On 2026/3/19 21:39, Ajay Rajera wrote:
> Replace the bool locked field in erofs_diskbufstrm with erofs_mutex_t lock to provide proper mutual exclusion for multi-threaded disk buffer operations. This addresses the TODO comment 'need a real lock for MT' by using the erofs mutex API (erofs_mutex_lock/erofs_mutex_unlock/erofs_mutex_init) instead of a simple boolean flag that provided no actual synchronization.

The commit message should be 72-char at maximum each line.

Otherwise it seems a good improvement.

> 
> Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
> ---
>   lib/diskbuf.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/diskbuf.c b/lib/diskbuf.c
> index 0bf42da..4218df8 100644
> --- a/lib/diskbuf.c
> +++ b/lib/diskbuf.c
> @@ -3,6 +3,7 @@
>   #include "erofs/internal.h"
>   #include "erofs/print.h"
>   #include <stdio.h>
> +#include "erofs/lock.h"
>   #include <errno.h>
>   #include <sys/stat.h>
>   #include <unistd.h>
> @@ -14,7 +15,7 @@ static struct erofs_diskbufstrm {
>   	u64 tailoffset, devpos;
>   	int fd;
>   	unsigned int alignsize;
> -	bool locked;
> +	erofs_mutex_t lock;
>   } *dbufstrm;
>   
>   int erofs_diskbuf_getfd(struct erofs_diskbuf *db, u64 *fpos)
> @@ -34,6 +35,7 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
>   {
>   	struct erofs_diskbufstrm *strm = dbufstrm + sid;
>   
> +	erofs_mutex_lock(&strm->lock);
>   	if (strm->tailoffset & (strm->alignsize - 1)) {
>   		strm->tailoffset = round_up(strm->tailoffset, strm->alignsize);
>   	}
> @@ -42,7 +44,6 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
>   		*off = db->offset + strm->devpos;
>   	db->sp = strm;
>   	(void)erofs_atomic_inc_return(&strm->count);
> -	strm->locked = true;	/* TODO: need a real lock for MT */
>   	return strm->fd;
>   }
>   
> @@ -51,9 +52,9 @@ void erofs_diskbuf_commit(struct erofs_diskbuf *db, u64 len)
>   	struct erofs_diskbufstrm *strm = db->sp;
>   
>   	DBG_BUGON(!strm);
> -	DBG_BUGON(!strm->locked);
>   	DBG_BUGON(strm->tailoffset != db->offset);
>   	strm->tailoffset += len;
> +	erofs_mutex_unlock(&strm->lock);
>   }
>   
>   void erofs_diskbuf_close(struct erofs_diskbuf *db)
> @@ -115,6 +116,7 @@ int erofs_diskbuf_init(unsigned int nstrms)
>   setupone:
>   		strm->tailoffset = 0;
>   		erofs_atomic_set(&strm->count, 1);
> +		erofs_mutex_init(&strm->lock);
>   		if (fstat(strm->fd, &st))
>   			return -errno;
>   		strm->alignsize = max_t(u32, st.st_blksize, getpagesize());



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

* Re: [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety
  2026-03-19 13:39 [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Ajay Rajera
  2026-03-19 13:39 ` [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout Ajay Rajera
  2026-03-19 13:42 ` [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Gao Xiang
@ 2026-03-19 13:44 ` Ajay
  2026-03-19 15:57 ` [PATCH v2 " Ajay Rajera
  3 siblings, 0 replies; 8+ messages in thread
From: Ajay @ 2026-03-19 13:44 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang

Hi, This is my first time submitting patches via git send-email to a
mailing list, so I apologize if there are any formatting issues or
mistakes in the submission process. Any feedback or suggestions for
improvement are appreciated.
Thanks, Ajay Rajera.

On Thu, 19 Mar 2026 at 19:09, Ajay Rajera <newajay.11r@gmail.com> wrote:
>
> Replace the bool locked field in erofs_diskbufstrm with erofs_mutex_t lock to provide proper mutual exclusion for multi-threaded disk buffer operations. This addresses the TODO comment 'need a real lock for MT' by using the erofs mutex API (erofs_mutex_lock/erofs_mutex_unlock/erofs_mutex_init) instead of a simple boolean flag that provided no actual synchronization.
>
> Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
> ---
>  lib/diskbuf.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/lib/diskbuf.c b/lib/diskbuf.c
> index 0bf42da..4218df8 100644
> --- a/lib/diskbuf.c
> +++ b/lib/diskbuf.c
> @@ -3,6 +3,7 @@
>  #include "erofs/internal.h"
>  #include "erofs/print.h"
>  #include <stdio.h>
> +#include "erofs/lock.h"
>  #include <errno.h>
>  #include <sys/stat.h>
>  #include <unistd.h>
> @@ -14,7 +15,7 @@ static struct erofs_diskbufstrm {
>         u64 tailoffset, devpos;
>         int fd;
>         unsigned int alignsize;
> -       bool locked;
> +       erofs_mutex_t lock;
>  } *dbufstrm;
>
>  int erofs_diskbuf_getfd(struct erofs_diskbuf *db, u64 *fpos)
> @@ -34,6 +35,7 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
>  {
>         struct erofs_diskbufstrm *strm = dbufstrm + sid;
>
> +       erofs_mutex_lock(&strm->lock);
>         if (strm->tailoffset & (strm->alignsize - 1)) {
>                 strm->tailoffset = round_up(strm->tailoffset, strm->alignsize);
>         }
> @@ -42,7 +44,6 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
>                 *off = db->offset + strm->devpos;
>         db->sp = strm;
>         (void)erofs_atomic_inc_return(&strm->count);
> -       strm->locked = true;    /* TODO: need a real lock for MT */
>         return strm->fd;
>  }
>
> @@ -51,9 +52,9 @@ void erofs_diskbuf_commit(struct erofs_diskbuf *db, u64 len)
>         struct erofs_diskbufstrm *strm = db->sp;
>
>         DBG_BUGON(!strm);
> -       DBG_BUGON(!strm->locked);
>         DBG_BUGON(strm->tailoffset != db->offset);
>         strm->tailoffset += len;
> +       erofs_mutex_unlock(&strm->lock);
>  }
>
>  void erofs_diskbuf_close(struct erofs_diskbuf *db)
> @@ -115,6 +116,7 @@ int erofs_diskbuf_init(unsigned int nstrms)
>  setupone:
>                 strm->tailoffset = 0;
>                 erofs_atomic_set(&strm->count, 1);
> +               erofs_mutex_init(&strm->lock);
>                 if (fstat(strm->fd, &st))
>                         return -errno;
>                 strm->alignsize = max_t(u32, st.st_blksize, getpagesize());
> --
> 2.51.0.windows.1
>


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

* Re: [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout
  2026-03-19 13:39 ` [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout Ajay Rajera
@ 2026-03-19 13:45   ` Gao Xiang
  2026-03-19 16:53     ` Ajay
  0 siblings, 1 reply; 8+ messages in thread
From: Gao Xiang @ 2026-03-19 13:45 UTC (permalink / raw)
  To: Ajay Rajera, linux-erofs; +Cc: xiang



On 2026/3/19 21:39, Ajay Rajera wrote:
> Fix the FIXME in metabox.c by properly handling meta_blkaddr for 48-bit layouts. In erofs_writesb(), set meta_blkaddr to 0 on-disk when 48-bit layout is enabled since meta_blkaddr is encoded differently in that mode. Remove the now-resolved FIXME comment in metabox.c as the issue is addressed in super.c.
> 
> Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
> ---
>   lib/metabox.c | 1 -
>   lib/super.c   | 2 +-
>   2 files changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/lib/metabox.c b/lib/metabox.c
> index d6abd51..077f88b 100644
> --- a/lib/metabox.c
> +++ b/lib/metabox.c
> @@ -62,7 +62,6 @@ int erofs_metadata_init(struct erofs_sb_info *sbi)
>   		if (ret)
>   			goto err_free;
>   		sbi->m2gr = m2gr;
> -		/* FIXME: sbi->meta_blkaddr should be 0 for 48-bit layouts */

I don't think it's a valid patch, I need to find more clue why
it was a FIXME.

>   		sbi->meta_blkaddr = EROFS_META_NEW_ADDR;
>   	}
>   
> diff --git a/lib/super.c b/lib/super.c
> index 088c9a0..99d2a24 100644
> --- a/lib/super.c
> +++ b/lib/super.c
> @@ -209,7 +209,7 @@ int erofs_writesb(struct erofs_sb_info *sbi)
>   		.epoch     = cpu_to_le64(sbi->epoch),
>   		.build_time = cpu_to_le64(sbi->build_time),
>   		.fixed_nsec = cpu_to_le32(sbi->fixed_nsec),
> -		.meta_blkaddr  = cpu_to_le32(sbi->meta_blkaddr),
> +		.meta_blkaddr  = cpu_to_le32(erofs_sb_has_48bit(sbi) ? 0 : sbi->meta_blkaddr),
>   		.xattr_blkaddr = cpu_to_le32(sbi->xattr_blkaddr),
>   		.xattr_prefix_count = sbi->xattr_prefix_count,
>   		.xattr_prefix_start = cpu_to_le32(sbi->xattr_prefix_start),



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

* [PATCH v2 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety
  2026-03-19 13:39 [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Ajay Rajera
                   ` (2 preceding siblings ...)
  2026-03-19 13:44 ` Ajay
@ 2026-03-19 15:57 ` Ajay Rajera
  3 siblings, 0 replies; 8+ messages in thread
From: Ajay Rajera @ 2026-03-19 15:57 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, Ajay Rajera

Replace the bool locked field in erofs_diskbufstrm with
erofs_mutex_t lock to provide proper mutual exclusion
for multi-threaded disk buffer operations.

This addresses the TODO comment 'need a real lock for MT'
by using the erofs mutex API (erofs_mutex_lock/
erofs_mutex_unlock/erofs_mutex_init) instead of a simple
boolean flag that provided no actual synchronization.

Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
---
 lib/diskbuf.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/diskbuf.c b/lib/diskbuf.c
index 0bf42da..4218df8 100644
--- a/lib/diskbuf.c
+++ b/lib/diskbuf.c
@@ -3,6 +3,7 @@
 #include "erofs/internal.h"
 #include "erofs/print.h"
 #include <stdio.h>
+#include "erofs/lock.h"
 #include <errno.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -14,7 +15,7 @@ static struct erofs_diskbufstrm {
 	u64 tailoffset, devpos;
 	int fd;
 	unsigned int alignsize;
-	bool locked;
+	erofs_mutex_t lock;
 } *dbufstrm;
 
 int erofs_diskbuf_getfd(struct erofs_diskbuf *db, u64 *fpos)
@@ -34,6 +35,7 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
 {
 	struct erofs_diskbufstrm *strm = dbufstrm + sid;
 
+	erofs_mutex_lock(&strm->lock);
 	if (strm->tailoffset & (strm->alignsize - 1)) {
 		strm->tailoffset = round_up(strm->tailoffset, strm->alignsize);
 	}
@@ -42,7 +44,6 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)
 		*off = db->offset + strm->devpos;
 	db->sp = strm;
 	(void)erofs_atomic_inc_return(&strm->count);
-	strm->locked = true;	/* TODO: need a real lock for MT */
 	return strm->fd;
 }
 
@@ -51,9 +52,9 @@ void erofs_diskbuf_commit(struct erofs_diskbuf *db, u64 len)
 	struct erofs_diskbufstrm *strm = db->sp;
 
 	DBG_BUGON(!strm);
-	DBG_BUGON(!strm->locked);
 	DBG_BUGON(strm->tailoffset != db->offset);
 	strm->tailoffset += len;
+	erofs_mutex_unlock(&strm->lock);
 }
 
 void erofs_diskbuf_close(struct erofs_diskbuf *db)
@@ -115,6 +116,7 @@ int erofs_diskbuf_init(unsigned int nstrms)
 setupone:
 		strm->tailoffset = 0;
 		erofs_atomic_set(&strm->count, 1);
+		erofs_mutex_init(&strm->lock);
 		if (fstat(strm->fd, &st))
 			return -errno;
 		strm->alignsize = max_t(u32, st.st_blksize, getpagesize());
-- 
2.51.0.windows.1



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

* Re: [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety
  2026-03-19 13:42 ` [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Gao Xiang
@ 2026-03-19 16:05   ` Ajay
  0 siblings, 0 replies; 8+ messages in thread
From: Ajay @ 2026-03-19 16:05 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs, xiang

[-- Attachment #1: Type: text/plain, Size: 3142 bytes --]

👍

Ajay reacted via Gmail
<https://www.google.com/gmail/about/?utm_source=gmail-in-product&utm_medium=et&utm_campaign=emojireactionemail#app>

On Thu, 19 Mar 2026 at 19:12, Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> Hi Ajay,
>
> On 2026/3/19 21:39, Ajay Rajera wrote:
> > Replace the bool locked field in erofs_diskbufstrm with erofs_mutex_t
> lock to provide proper mutual exclusion for multi-threaded disk buffer
> operations. This addresses the TODO comment 'need a real lock for MT' by
> using the erofs mutex API
> (erofs_mutex_lock/erofs_mutex_unlock/erofs_mutex_init) instead of a simple
> boolean flag that provided no actual synchronization.
>
> The commit message should be 72-char at maximum each line.
>
> Otherwise it seems a good improvement.
>
> >
> > Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
> > ---
> >   lib/diskbuf.c | 8 +++++---
> >   1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/diskbuf.c b/lib/diskbuf.c
> > index 0bf42da..4218df8 100644
> > --- a/lib/diskbuf.c
> > +++ b/lib/diskbuf.c
> > @@ -3,6 +3,7 @@
> >   #include "erofs/internal.h"
> >   #include "erofs/print.h"
> >   #include <stdio.h>
> > +#include "erofs/lock.h"
> >   #include <errno.h>
> >   #include <sys/stat.h>
> >   #include <unistd.h>
> > @@ -14,7 +15,7 @@ static struct erofs_diskbufstrm {
> >       u64 tailoffset, devpos;
> >       int fd;
> >       unsigned int alignsize;
> > -     bool locked;
> > +     erofs_mutex_t lock;
> >   } *dbufstrm;
> >
> >   int erofs_diskbuf_getfd(struct erofs_diskbuf *db, u64 *fpos)
> > @@ -34,6 +35,7 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db,
> int sid, u64 *off)
> >   {
> >       struct erofs_diskbufstrm *strm = dbufstrm + sid;
> >
> > +     erofs_mutex_lock(&strm->lock);
> >       if (strm->tailoffset & (strm->alignsize - 1)) {
> >               strm->tailoffset = round_up(strm->tailoffset,
> strm->alignsize);
> >       }
> > @@ -42,7 +44,6 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db,
> int sid, u64 *off)
> >               *off = db->offset + strm->devpos;
> >       db->sp = strm;
> >       (void)erofs_atomic_inc_return(&strm->count);
> > -     strm->locked = true;    /* TODO: need a real lock for MT */
> >       return strm->fd;
> >   }
> >
> > @@ -51,9 +52,9 @@ void erofs_diskbuf_commit(struct erofs_diskbuf *db,
> u64 len)
> >       struct erofs_diskbufstrm *strm = db->sp;
> >
> >       DBG_BUGON(!strm);
> > -     DBG_BUGON(!strm->locked);
> >       DBG_BUGON(strm->tailoffset != db->offset);
> >       strm->tailoffset += len;
> > +     erofs_mutex_unlock(&strm->lock);
> >   }
> >
> >   void erofs_diskbuf_close(struct erofs_diskbuf *db)
> > @@ -115,6 +116,7 @@ int erofs_diskbuf_init(unsigned int nstrms)
> >   setupone:
> >               strm->tailoffset = 0;
> >               erofs_atomic_set(&strm->count, 1);
> > +             erofs_mutex_init(&strm->lock);
> >               if (fstat(strm->fd, &st))
> >                       return -errno;
> >               strm->alignsize = max_t(u32, st.st_blksize, getpagesize());
>
>

[-- Attachment #2: Type: text/vnd.google.email-reaction+json, Size: 40 bytes --]

{
  "emoji": "👍",
  "version": 1
}

[-- Attachment #3: Type: text/html, Size: 4267 bytes --]

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

* Re: [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout
  2026-03-19 13:45   ` Gao Xiang
@ 2026-03-19 16:53     ` Ajay
  0 siblings, 0 replies; 8+ messages in thread
From: Ajay @ 2026-03-19 16:53 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs, xiang

Hi, I looked into the history of this FIXME (which was introduced in
your commit 6eae70b1 "erofs-utils: mkfs: enable directory data in the
metadata zone"). The reason sbi->meta_blkaddr must not be eagerly set
to 0 in lib/metabox.c for 48-bit layouts is due to how the relative
NID offset math works in memory before erofs_metazone_flush() resolves
the absolute block address. In erofs_fixup_meta_blkaddr(), meta_offset
is set to -bsz to avoid NID 0. To compensate, sbi->meta_blkaddr must
remain EROFS_META_NEW_ADDR (which equates to -1 block). Later, in
erofs_metazone_flush(), when the absolute metazone start block is
allocated, it does: sbi->meta_blkaddr += meta_blkaddr;
Since sbi->meta_blkaddr is -1 block, -1 + meta_blkaddr equals
meta_blkaddr - 1. This correctly offsets the -bsz byte offset so that
NID math (addr = meta_blkaddr * bsz + (nid << 5)) calculates the
correct actual block address without wasting space!
If we were to eagerly set sbi->meta_blkaddr = 0 in metabox.c, the
flush would set it to exactly meta_blkaddr, breaking the -bsz tracking
and causing the DBG_BUGON(sbi->meta_blkaddr != -1) assertion in
erofs_fixup_meta_blkaddr() to trip.
Since EROFS 48-bit layouts don't use the legacy meta_blkaddr field
anyway, leaving the in-memory variable as EROFS_META_NEW_ADDR is
mathematically required for the mkfs flush logic, while the on-disk
superblock value is correctly hardcoded to 0 in lib/super.c.
Because of this, the FIXME comment in metabox.c is actually outdated,
which is why the patch just removes the comment itself.

Let me know if this makes sense to you.
Thanks, Ajay Rajera.

On Thu, 19 Mar 2026 at 19:15, Gao Xiang <hsiangkao@linux.alibaba.com> wrote:
>
>
>
> On 2026/3/19 21:39, Ajay Rajera wrote:
> > Fix the FIXME in metabox.c by properly handling meta_blkaddr for 48-bit layouts. In erofs_writesb(), set meta_blkaddr to 0 on-disk when 48-bit layout is enabled since meta_blkaddr is encoded differently in that mode. Remove the now-resolved FIXME comment in metabox.c as the issue is addressed in super.c.
> >
> > Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
> > ---
> >   lib/metabox.c | 1 -
> >   lib/super.c   | 2 +-
> >   2 files changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/lib/metabox.c b/lib/metabox.c
> > index d6abd51..077f88b 100644
> > --- a/lib/metabox.c
> > +++ b/lib/metabox.c
> > @@ -62,7 +62,6 @@ int erofs_metadata_init(struct erofs_sb_info *sbi)
> >               if (ret)
> >                       goto err_free;
> >               sbi->m2gr = m2gr;
> > -             /* FIXME: sbi->meta_blkaddr should be 0 for 48-bit layouts */
>
> I don't think it's a valid patch, I need to find more clue why
> it was a FIXME.
>
> >               sbi->meta_blkaddr = EROFS_META_NEW_ADDR;
> >       }
> >
> > diff --git a/lib/super.c b/lib/super.c
> > index 088c9a0..99d2a24 100644
> > --- a/lib/super.c
> > +++ b/lib/super.c
> > @@ -209,7 +209,7 @@ int erofs_writesb(struct erofs_sb_info *sbi)
> >               .epoch     = cpu_to_le64(sbi->epoch),
> >               .build_time = cpu_to_le64(sbi->build_time),
> >               .fixed_nsec = cpu_to_le32(sbi->fixed_nsec),
> > -             .meta_blkaddr  = cpu_to_le32(sbi->meta_blkaddr),
> > +             .meta_blkaddr  = cpu_to_le32(erofs_sb_has_48bit(sbi) ? 0 : sbi->meta_blkaddr),
> >               .xattr_blkaddr = cpu_to_le32(sbi->xattr_blkaddr),
> >               .xattr_prefix_count = sbi->xattr_prefix_count,
> >               .xattr_prefix_start = cpu_to_le32(sbi->xattr_prefix_start),
>


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

end of thread, other threads:[~2026-03-19 16:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19 13:39 [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Ajay Rajera
2026-03-19 13:39 ` [PATCH 2/2] erofs-utils: lib: fix meta_blkaddr handling for 48-bit layout Ajay Rajera
2026-03-19 13:45   ` Gao Xiang
2026-03-19 16:53     ` Ajay
2026-03-19 13:42 ` [PATCH 1/2] erofs-utils: lib: replace bool locked with erofs_mutex_t for MT safety Gao Xiang
2026-03-19 16:05   ` Ajay
2026-03-19 13:44 ` Ajay
2026-03-19 15:57 ` [PATCH v2 " Ajay Rajera

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