]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ufs: untangle ubh_...block...(), part 3
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 28 Jan 2023 00:56:44 +0000 (19:56 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 18 Oct 2024 21:35:31 +0000 (17:35 -0400)
Pass fragment number instead of a block one.  It's available in all
callers and it makes the logics inside those helpers much simpler.
The bitmap they operate upon is with bit per fragment, block being
an aligned group of 1, 2, 4 or 8 adjacent fragments.  We still
need a switch by the number of fragments in block (== number of
bits to check/set/clear), but finding the byte we need to work
with becomes uniform and that makes the things easier to follow.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/ufs/balloc.c
fs/ufs/util.h

index d76c04fbd4fa1f484495012c37e0613bb370cb3c..7694666fac185079ebbad3fd39400971cef24853 100644 (file)
@@ -95,7 +95,7 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
         * Trying to reassemble free fragments into block
         */
        blkno = ufs_fragstoblks (bbase);
-       if (ubh_isblockset(uspi, ucpi, blkno)) {
+       if (ubh_isblockset(uspi, ucpi, bbase)) {
                fs32_sub(sb, &ucg->cg_cs.cs_nffree, uspi->s_fpb);
                uspi->cs_total.cs_nffree -= uspi->s_fpb;
                fs32_sub(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, uspi->s_fpb);
@@ -182,10 +182,10 @@ do_more:
 
        for (i = bit; i < end_bit; i += uspi->s_fpb) {
                blkno = ufs_fragstoblks(i);
-               if (ubh_isblockset(uspi, ucpi, blkno)) {
+               if (ubh_isblockset(uspi, ucpi, i)) {
                        ufs_error(sb, "ufs_free_blocks", "freeing free fragment");
                }
-               ubh_setblock(uspi, ucpi, blkno);
+               ubh_setblock(uspi, ucpi, i);
                inode_sub_bytes(inode, uspi->s_fpb << uspi->s_fshift);
                if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
                        ufs_clusteracct (sb, ucpi, blkno, 1);
@@ -716,7 +716,7 @@ static u64 ufs_alloccg_block(struct inode *inode,
        /*
         * If the requested block is available, use it.
         */
-       if (ubh_isblockset(uspi, ucpi, ufs_fragstoblks(goal))) {
+       if (ubh_isblockset(uspi, ucpi, goal)) {
                result = goal;
                goto gotit;
        }
@@ -730,7 +730,7 @@ gotit:
        if (!try_add_frags(inode, uspi->s_fpb))
                return 0;
        blkno = ufs_fragstoblks(result);
-       ubh_clrblock(uspi, ucpi, blkno);
+       ubh_clrblock(uspi, ucpi, result);
        if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
                ufs_clusteracct (sb, ucpi, blkno, -1);
 
index c7196a81fb0d06a921cdf870d363b8ba683fe36c..fafae166ee553167739831f0b92d838ecaeef1f5 100644 (file)
@@ -456,65 +456,68 @@ static inline unsigned _ubh_find_last_zero_bit_(
 }      
 
 static inline int ubh_isblockset(struct ufs_sb_private_info *uspi,
-       struct ufs_cg_private_info *ucpi, unsigned block)
+       struct ufs_cg_private_info *ucpi, unsigned int frag)
 {
        struct ufs_buffer_head *ubh = UCPI_UBH(ucpi);
-       unsigned begin = ucpi->c_freeoff;
+       u8 *p = ubh_get_addr(ubh, ucpi->c_freeoff + (frag >> 3));
        u8 mask;
+
        switch (uspi->s_fpb) {
        case 8:
-               return (*ubh_get_addr (ubh, begin + block) == 0xff);
+               return *p == 0xff;
        case 4:
-               mask = 0x0f << ((block & 0x01) << 2);
-               return (*ubh_get_addr (ubh, begin + (block >> 1)) & mask) == mask;
+               mask = 0x0f << (frag & 4);
+               return (*p & mask) == mask;
        case 2:
-               mask = 0x03 << ((block & 0x03) << 1);
-               return (*ubh_get_addr (ubh, begin + (block >> 2)) & mask) == mask;
+               mask = 0x03 << (frag & 6);
+               return (*p & mask) == mask;
        case 1:
-               mask = 0x01 << (block & 0x07);
-               return (*ubh_get_addr (ubh, begin + (block >> 3)) & mask) == mask;
+               mask = 0x01 << (frag & 7);
+               return (*p & mask) == mask;
        }
        return 0;       
 }
 
 static inline void ubh_clrblock(struct ufs_sb_private_info *uspi,
-       struct ufs_cg_private_info *ucpi, unsigned block)
+       struct ufs_cg_private_info *ucpi, unsigned int frag)
 {
        struct ufs_buffer_head *ubh = UCPI_UBH(ucpi);
-       unsigned begin = ucpi->c_freeoff;
+       u8 *p = ubh_get_addr(ubh, ucpi->c_freeoff + (frag >> 3));
+
        switch (uspi->s_fpb) {
        case 8:
-               *ubh_get_addr (ubh, begin + block) = 0x00;
+               *p = 0x00;
                return; 
        case 4:
-               *ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
+               *p &= ~(0x0f << (frag & 4));
                return;
        case 2:
-               *ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
+               *p &= ~(0x03 << (frag & 6));
                return;
        case 1:
-               *ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
+               *p &= ~(0x01 << (frag & 7));
                return;
        }
 }
 
 static inline void ubh_setblock(struct ufs_sb_private_info * uspi,
-       struct ufs_cg_private_info *ucpi, unsigned block)
+       struct ufs_cg_private_info *ucpi, unsigned int frag)
 {
        struct ufs_buffer_head *ubh = UCPI_UBH(ucpi);
-       unsigned begin = ucpi->c_freeoff;
+       u8 *p = ubh_get_addr(ubh, ucpi->c_freeoff + (frag >> 3));
+
        switch (uspi->s_fpb) {
        case 8:
-               *ubh_get_addr(ubh, begin + block) = 0xff;
+               *p = 0xff;
                return;
        case 4:
-               *ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
+               *p |= 0x0f << (frag & 4);
                return;
        case 2:
-               *ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
+               *p |= 0x03 << (frag & 6);
                return;
        case 1:
-               *ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
+               *p |= 0x01 << (frag & 7);
                return;
        }
 }