Prepare for the upcoming per-sbi buffer.

Signed-off-by: Hongzhen Luo <hongz...@linux.alibaba.com>
---
 include/erofs/cache.h |  9 ++++++---
 lib/cache.c           | 28 +++++++++++++++++-----------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index 234185f..288843e 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -55,15 +55,17 @@ struct erofs_buffer_block {
 
 static inline const int get_alignsize(int type, int *type_ret)
 {
+       struct erofs_sb_info *sbi = &g_sbi;
+
        if (type == DATA)
-               return erofs_blksiz(&g_sbi);
+               return erofs_blksiz(sbi);
 
        if (type == INODE) {
                *type_ret = META;
                return sizeof(struct erofs_inode_compact);
        } else if (type == DIRA) {
                *type_ret = META;
-               return erofs_blksiz(&g_sbi);
+               return erofs_blksiz(sbi);
        } else if (type == XATTR) {
                *type_ret = META;
                return sizeof(struct erofs_xattr_entry);
@@ -83,11 +85,12 @@ extern const struct erofs_bhops erofs_skip_write_bhops;
 static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)
 {
        const struct erofs_buffer_block *bb = bh->block;
+       struct erofs_sb_info *sbi = &g_sbi;
 
        if (bb->blkaddr == NULL_ADDR)
                return NULL_ADDR_UL;
 
-       return erofs_pos(&g_sbi, bb->blkaddr) +
+       return erofs_pos(sbi, bb->blkaddr) +
                (end ? list_next_entry(bh, list)->off : bh->off);
 }
 
diff --git a/lib/cache.c b/lib/cache.c
index e3dc9de..69a3055 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -51,12 +51,13 @@ void erofs_buffer_init(erofs_blk_t startblk)
 static void erofs_bupdate_mapped(struct erofs_buffer_block *bb)
 {
        struct list_head *bkt;
+       struct erofs_sb_info *sbi = &g_sbi;
 
        if (bb->blkaddr == NULL_ADDR)
                return;
 
        bkt = mapped_buckets[bb->type] +
-               (bb->buffers.off & (erofs_blksiz(&g_sbi) - 1));
+               (bb->buffers.off & (erofs_blksiz(sbi) - 1));
        list_del(&bb->mapped_list);
        list_add_tail(&bb->mapped_list, bkt);
 }
@@ -69,7 +70,8 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
                           unsigned int extrasize,
                           bool dryrun)
 {
-       const unsigned int blksiz = erofs_blksiz(&g_sbi);
+       struct erofs_sb_info *sbi = &g_sbi;
+       const unsigned int blksiz = erofs_blksiz(sbi);
        const unsigned int blkmask = blksiz - 1;
        erofs_off_t boff = bb->buffers.off;
        const erofs_off_t alignedoffset = roundup(boff, alignsize);
@@ -86,7 +88,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
                blkaddr = bb->blkaddr;
                if (blkaddr != NULL_ADDR) {
                        tailupdate = (tail_blkaddr == blkaddr +
-                                     BLK_ROUND_UP(&g_sbi, boff));
+                                     BLK_ROUND_UP(sbi, boff));
                        if (oob && !tailupdate)
                                return -EINVAL;
                }
@@ -102,7 +104,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
                bb->buffers.off = boff;
                /* need to update the tail_blkaddr */
                if (tailupdate)
-                       tail_blkaddr = blkaddr + BLK_ROUND_UP(&g_sbi, boff);
+                       tail_blkaddr = blkaddr + BLK_ROUND_UP(sbi, boff);
                erofs_bupdate_mapped(bb);
        }
        return ((alignedoffset + incr - 1) & blkmask) + 1;
@@ -125,7 +127,8 @@ static int erofs_bfind_for_attach(int type, erofs_off_t 
size,
                                  unsigned int alignsize,
                                  struct erofs_buffer_block **bbp)
 {
-       const unsigned int blksiz = erofs_blksiz(&g_sbi);
+       struct erofs_sb_info *sbi = &g_sbi;
+       const unsigned int blksiz = erofs_blksiz(sbi);
        struct erofs_buffer_block *cur, *bb;
        unsigned int used0, used_before, usedmax, used;
        int ret;
@@ -315,6 +318,7 @@ struct erofs_buffer_head *erofs_battach(struct 
erofs_buffer_head *bh,
 static erofs_blk_t __erofs_mapbh(struct erofs_buffer_block *bb)
 {
        erofs_blk_t blkaddr;
+       struct erofs_sb_info *sbi = &g_sbi;
 
        if (bb->blkaddr == NULL_ADDR) {
                bb->blkaddr = tail_blkaddr;
@@ -322,7 +326,7 @@ static erofs_blk_t __erofs_mapbh(struct erofs_buffer_block 
*bb)
                erofs_bupdate_mapped(bb);
        }
 
-       blkaddr = bb->blkaddr + BLK_ROUND_UP(&g_sbi, bb->buffers.off);
+       blkaddr = bb->blkaddr + BLK_ROUND_UP(sbi, bb->buffers.off);
        if (blkaddr > tail_blkaddr)
                tail_blkaddr = blkaddr;
 
@@ -360,7 +364,8 @@ static void erofs_bfree(struct erofs_buffer_block *bb)
 
 int erofs_bflush(struct erofs_buffer_block *bb)
 {
-       const unsigned int blksiz = erofs_blksiz(&g_sbi);
+       struct erofs_sb_info *sbi = &g_sbi;
+       const unsigned int blksiz = erofs_blksiz(sbi);
        struct erofs_buffer_block *p, *n;
        erofs_blk_t blkaddr;
 
@@ -392,11 +397,11 @@ int erofs_bflush(struct erofs_buffer_block *bb)
 
                padding = blksiz - (p->buffers.off & (blksiz - 1));
                if (padding != blksiz)
-                       erofs_dev_fillzero(&g_sbi, erofs_pos(&g_sbi, blkaddr) - 
padding,
+                       erofs_dev_fillzero(sbi, erofs_pos(sbi, blkaddr) - 
padding,
                                           padding, true);
 
                if (p->type != DATA)
-                       erofs_metablkcnt += BLK_ROUND_UP(&g_sbi, 
p->buffers.off);
+                       erofs_metablkcnt += BLK_ROUND_UP(sbi, p->buffers.off);
                erofs_dbg("block %u to %u flushed", p->blkaddr, blkaddr - 1);
                erofs_bfree(p);
        }
@@ -408,10 +413,11 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool 
tryrevoke)
        struct erofs_buffer_block *const bb = bh->block;
        const erofs_blk_t blkaddr = bh->block->blkaddr;
        bool rollback = false;
+       struct erofs_sb_info *sbi = &g_sbi;
 
        /* tail_blkaddr could be rolled back after revoking all bhs */
        if (tryrevoke && blkaddr != NULL_ADDR &&
-           tail_blkaddr == blkaddr + BLK_ROUND_UP(&g_sbi, bb->buffers.off))
+           tail_blkaddr == blkaddr + BLK_ROUND_UP(sbi, bb->buffers.off))
                rollback = true;
 
        bh->op = &erofs_drop_directly_bhops;
@@ -421,7 +427,7 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool 
tryrevoke)
                return;
 
        if (!rollback && bb->type != DATA)
-               erofs_metablkcnt += BLK_ROUND_UP(&g_sbi, bb->buffers.off);
+               erofs_metablkcnt += BLK_ROUND_UP(sbi, bb->buffers.off);
        erofs_bfree(bb);
        if (rollback)
                tail_blkaddr = blkaddr;
-- 
2.43.5

Reply via email to