<div><p style="font-size:50px;margin-top:0;margin-bottom:0">👍</p><p style="margin-top:10px;margin-bottom:0">Ajay reacted via <a href="https://www.google.com/gmail/about/?utm_source=gmail-in-product&utm_medium=et&utm_campaign=emojireactionemail#app">Gmail</a></p></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, 19 Mar 2026 at 19:12, Gao Xiang <<a href="mailto:hsiangkao@linux.alibaba.com">hsiangkao@linux.alibaba.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Ajay,<br>
<br>
On 2026/3/19 21:39, Ajay Rajera wrote:<br>
> 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.<br>
<br>
The commit message should be 72-char at maximum each line.<br>
<br>
Otherwise it seems a good improvement.<br>
<br>
> <br>
> Signed-off-by: Ajay Rajera <<a href="mailto:newajay.11r@gmail.com" target="_blank">newajay.11r@gmail.com</a>><br>
> ---<br>
>   lib/diskbuf.c | 8 +++++---<br>
>   1 file changed, 5 insertions(+), 3 deletions(-)<br>
> <br>
> diff --git a/lib/diskbuf.c b/lib/diskbuf.c<br>
> index 0bf42da..4218df8 100644<br>
> --- a/lib/diskbuf.c<br>
> +++ b/lib/diskbuf.c<br>
> @@ -3,6 +3,7 @@<br>
>   #include "erofs/internal.h"<br>
>   #include "erofs/print.h"<br>
>   #include <stdio.h><br>
> +#include "erofs/lock.h"<br>
>   #include <errno.h><br>
>   #include <sys/stat.h><br>
>   #include <unistd.h><br>
> @@ -14,7 +15,7 @@ static struct erofs_diskbufstrm {<br>
>       u64 tailoffset, devpos;<br>
>       int fd;<br>
>       unsigned int alignsize;<br>
> -     bool locked;<br>
> +     erofs_mutex_t lock;<br>
>   } *dbufstrm;<br>
>   <br>
>   int erofs_diskbuf_getfd(struct erofs_diskbuf *db, u64 *fpos)<br>
> @@ -34,6 +35,7 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)<br>
>   {<br>
>       struct erofs_diskbufstrm *strm = dbufstrm + sid;<br>
>   <br>
> +     erofs_mutex_lock(&strm->lock);<br>
>       if (strm->tailoffset & (strm->alignsize - 1)) {<br>
>               strm->tailoffset = round_up(strm->tailoffset, strm->alignsize);<br>
>       }<br>
> @@ -42,7 +44,6 @@ int erofs_diskbuf_reserve(struct erofs_diskbuf *db, int sid, u64 *off)<br>
>               *off = db->offset + strm->devpos;<br>
>       db->sp = strm;<br>
>       (void)erofs_atomic_inc_return(&strm->count);<br>
> -     strm->locked = true;    /* TODO: need a real lock for MT */<br>
>       return strm->fd;<br>
>   }<br>
>   <br>
> @@ -51,9 +52,9 @@ void erofs_diskbuf_commit(struct erofs_diskbuf *db, u64 len)<br>
>       struct erofs_diskbufstrm *strm = db->sp;<br>
>   <br>
>       DBG_BUGON(!strm);<br>
> -     DBG_BUGON(!strm->locked);<br>
>       DBG_BUGON(strm->tailoffset != db->offset);<br>
>       strm->tailoffset += len;<br>
> +     erofs_mutex_unlock(&strm->lock);<br>
>   }<br>
>   <br>
>   void erofs_diskbuf_close(struct erofs_diskbuf *db)<br>
> @@ -115,6 +116,7 @@ int erofs_diskbuf_init(unsigned int nstrms)<br>
>   setupone:<br>
>               strm->tailoffset = 0;<br>
>               erofs_atomic_set(&strm->count, 1);<br>
> +             erofs_mutex_init(&strm->lock);<br>
>               if (fstat(strm->fd, &st))<br>
>                       return -errno;<br>
>               strm->alignsize = max_t(u32, st.st_blksize, getpagesize());<br>
<br>
</blockquote></div>