Skip to content

Commit dce3e8d

Browse files
author
Al Viro
committed
ufs: untangle ubh_...block...(), part 3
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 <[email protected]>
1 parent 8bec061 commit dce3e8d

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

fs/ufs/balloc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
9595
* Trying to reassemble free fragments into block
9696
*/
9797
blkno = ufs_fragstoblks (bbase);
98-
if (ubh_isblockset(uspi, ucpi, blkno)) {
98+
if (ubh_isblockset(uspi, ucpi, bbase)) {
9999
fs32_sub(sb, &ucg->cg_cs.cs_nffree, uspi->s_fpb);
100100
uspi->cs_total.cs_nffree -= uspi->s_fpb;
101101
fs32_sub(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, uspi->s_fpb);
@@ -182,10 +182,10 @@ void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count)
182182

183183
for (i = bit; i < end_bit; i += uspi->s_fpb) {
184184
blkno = ufs_fragstoblks(i);
185-
if (ubh_isblockset(uspi, ucpi, blkno)) {
185+
if (ubh_isblockset(uspi, ucpi, i)) {
186186
ufs_error(sb, "ufs_free_blocks", "freeing free fragment");
187187
}
188-
ubh_setblock(uspi, ucpi, blkno);
188+
ubh_setblock(uspi, ucpi, i);
189189
inode_sub_bytes(inode, uspi->s_fpb << uspi->s_fshift);
190190
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
191191
ufs_clusteracct (sb, ucpi, blkno, 1);
@@ -716,7 +716,7 @@ static u64 ufs_alloccg_block(struct inode *inode,
716716
/*
717717
* If the requested block is available, use it.
718718
*/
719-
if (ubh_isblockset(uspi, ucpi, ufs_fragstoblks(goal))) {
719+
if (ubh_isblockset(uspi, ucpi, goal)) {
720720
result = goal;
721721
goto gotit;
722722
}
@@ -730,7 +730,7 @@ static u64 ufs_alloccg_block(struct inode *inode,
730730
if (!try_add_frags(inode, uspi->s_fpb))
731731
return 0;
732732
blkno = ufs_fragstoblks(result);
733-
ubh_clrblock(uspi, ucpi, blkno);
733+
ubh_clrblock(uspi, ucpi, result);
734734
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
735735
ufs_clusteracct (sb, ucpi, blkno, -1);
736736

fs/ufs/util.h

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -456,65 +456,68 @@ static inline unsigned _ubh_find_last_zero_bit_(
456456
}
457457

458458
static inline int ubh_isblockset(struct ufs_sb_private_info *uspi,
459-
struct ufs_cg_private_info *ucpi, unsigned block)
459+
struct ufs_cg_private_info *ucpi, unsigned int frag)
460460
{
461461
struct ufs_buffer_head *ubh = UCPI_UBH(ucpi);
462-
unsigned begin = ucpi->c_freeoff;
462+
u8 *p = ubh_get_addr(ubh, ucpi->c_freeoff + (frag >> 3));
463463
u8 mask;
464+
464465
switch (uspi->s_fpb) {
465466
case 8:
466-
return (*ubh_get_addr (ubh, begin + block) == 0xff);
467+
return *p == 0xff;
467468
case 4:
468-
mask = 0x0f << ((block & 0x01) << 2);
469-
return (*ubh_get_addr (ubh, begin + (block >> 1)) & mask) == mask;
469+
mask = 0x0f << (frag & 4);
470+
return (*p & mask) == mask;
470471
case 2:
471-
mask = 0x03 << ((block & 0x03) << 1);
472-
return (*ubh_get_addr (ubh, begin + (block >> 2)) & mask) == mask;
472+
mask = 0x03 << (frag & 6);
473+
return (*p & mask) == mask;
473474
case 1:
474-
mask = 0x01 << (block & 0x07);
475-
return (*ubh_get_addr (ubh, begin + (block >> 3)) & mask) == mask;
475+
mask = 0x01 << (frag & 7);
476+
return (*p & mask) == mask;
476477
}
477478
return 0;
478479
}
479480

480481
static inline void ubh_clrblock(struct ufs_sb_private_info *uspi,
481-
struct ufs_cg_private_info *ucpi, unsigned block)
482+
struct ufs_cg_private_info *ucpi, unsigned int frag)
482483
{
483484
struct ufs_buffer_head *ubh = UCPI_UBH(ucpi);
484-
unsigned begin = ucpi->c_freeoff;
485+
u8 *p = ubh_get_addr(ubh, ucpi->c_freeoff + (frag >> 3));
486+
485487
switch (uspi->s_fpb) {
486488
case 8:
487-
*ubh_get_addr (ubh, begin + block) = 0x00;
489+
*p = 0x00;
488490
return;
489491
case 4:
490-
*ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
492+
*p &= ~(0x0f << (frag & 4));
491493
return;
492494
case 2:
493-
*ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
495+
*p &= ~(0x03 << (frag & 6));
494496
return;
495497
case 1:
496-
*ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
498+
*p &= ~(0x01 << (frag & 7));
497499
return;
498500
}
499501
}
500502

501503
static inline void ubh_setblock(struct ufs_sb_private_info * uspi,
502-
struct ufs_cg_private_info *ucpi, unsigned block)
504+
struct ufs_cg_private_info *ucpi, unsigned int frag)
503505
{
504506
struct ufs_buffer_head *ubh = UCPI_UBH(ucpi);
505-
unsigned begin = ucpi->c_freeoff;
507+
u8 *p = ubh_get_addr(ubh, ucpi->c_freeoff + (frag >> 3));
508+
506509
switch (uspi->s_fpb) {
507510
case 8:
508-
*ubh_get_addr(ubh, begin + block) = 0xff;
511+
*p = 0xff;
509512
return;
510513
case 4:
511-
*ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
514+
*p |= 0x0f << (frag & 4);
512515
return;
513516
case 2:
514-
*ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
517+
*p |= 0x03 << (frag & 6);
515518
return;
516519
case 1:
517-
*ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
520+
*p |= 0x01 << (frag & 7);
518521
return;
519522
}
520523
}

0 commit comments

Comments
 (0)