Commit d1dcdb0d authored by Al Viro's avatar Al Viro Committed by Ben Hutchings

ufs: restore maintaining ->i_blocks

commit eb315d2a upstream.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
[bwh: Backported to 3.16: open-code i_blocksize()]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent bc76f8cd
...@@ -456,6 +456,7 @@ void __inode_add_bytes(struct inode *inode, loff_t bytes) ...@@ -456,6 +456,7 @@ void __inode_add_bytes(struct inode *inode, loff_t bytes)
inode->i_bytes -= 512; inode->i_bytes -= 512;
} }
} }
EXPORT_SYMBOL(__inode_add_bytes);
void inode_add_bytes(struct inode *inode, loff_t bytes) void inode_add_bytes(struct inode *inode, loff_t bytes)
{ {
......
...@@ -82,6 +82,7 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count) ...@@ -82,6 +82,7 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
"bit already cleared for fragment %u", i); "bit already cleared for fragment %u", i);
} }
inode_sub_bytes(inode, count << uspi->s_fshift);
fs32_add(sb, &ucg->cg_cs.cs_nffree, count); fs32_add(sb, &ucg->cg_cs.cs_nffree, count);
uspi->cs_total.cs_nffree += count; uspi->cs_total.cs_nffree += count;
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, count); fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, count);
...@@ -183,6 +184,7 @@ void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count) ...@@ -183,6 +184,7 @@ void ufs_free_blocks(struct inode *inode, u64 fragment, unsigned count)
ufs_error(sb, "ufs_free_blocks", "freeing free fragment"); ufs_error(sb, "ufs_free_blocks", "freeing free fragment");
} }
ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno); ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
inode_sub_bytes(inode, uspi->s_fpb << uspi->s_fshift);
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD) if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
ufs_clusteracct (sb, ucpi, blkno, 1); ufs_clusteracct (sb, ucpi, blkno, 1);
...@@ -490,6 +492,20 @@ u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment, ...@@ -490,6 +492,20 @@ u64 ufs_new_fragments(struct inode *inode, void *p, u64 fragment,
return 0; return 0;
} }
static bool try_add_frags(struct inode *inode, unsigned frags)
{
unsigned size = frags << inode->i_blkbits;
spin_lock(&inode->i_lock);
__inode_add_bytes(inode, size);
if (unlikely((u32)inode->i_blocks != inode->i_blocks)) {
__inode_sub_bytes(inode, size);
spin_unlock(&inode->i_lock);
return false;
}
spin_unlock(&inode->i_lock);
return true;
}
static u64 ufs_add_fragments(struct inode *inode, u64 fragment, static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
unsigned oldcount, unsigned newcount) unsigned oldcount, unsigned newcount)
{ {
...@@ -526,6 +542,9 @@ static u64 ufs_add_fragments(struct inode *inode, u64 fragment, ...@@ -526,6 +542,9 @@ static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
for (i = oldcount; i < newcount; i++) for (i = oldcount; i < newcount; i++)
if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i)) if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i))
return 0; return 0;
if (!try_add_frags(inode, count))
return 0;
/* /*
* Block can be extended * Block can be extended
*/ */
...@@ -643,6 +662,7 @@ static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno, ...@@ -643,6 +662,7 @@ static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno,
ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i); ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i);
i = uspi->s_fpb - count; i = uspi->s_fpb - count;
inode_sub_bytes(inode, i << uspi->s_fshift);
fs32_add(sb, &ucg->cg_cs.cs_nffree, i); fs32_add(sb, &ucg->cg_cs.cs_nffree, i);
uspi->cs_total.cs_nffree += i; uspi->cs_total.cs_nffree += i;
fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, i); fs32_add(sb, &UFS_SB(sb)->fs_cs(cgno).cs_nffree, i);
...@@ -653,6 +673,8 @@ static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno, ...@@ -653,6 +673,8 @@ static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno,
result = ufs_bitmap_search (sb, ucpi, goal, allocsize); result = ufs_bitmap_search (sb, ucpi, goal, allocsize);
if (result == INVBLOCK) if (result == INVBLOCK)
return 0; return 0;
if (!try_add_frags(inode, count))
return 0;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, result + i); ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, result + i);
...@@ -712,6 +734,8 @@ static u64 ufs_alloccg_block(struct inode *inode, ...@@ -712,6 +734,8 @@ static u64 ufs_alloccg_block(struct inode *inode,
return INVBLOCK; return INVBLOCK;
ucpi->c_rotor = result; ucpi->c_rotor = result;
gotit: gotit:
if (!try_add_frags(inode, uspi->s_fpb))
return 0;
blkno = ufs_fragstoblks(result); blkno = ufs_fragstoblks(result);
ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno); ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD) if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment