ufs_trunc_..indirect(): more massage towards unifying

Instead of manually checking that the array contains only zeroes,
find the position of the last non-zero (in __ufs_truncate(), where
we can conveniently do that) and use that to tell if there's
any non-zero in the array tail passed to ufs_trunc_...indirect().

The goal of all that clumsiness is to get fold these functions
together.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2015-06-18 14:55:50 -04:00
parent 85416288bf
commit 6775e24d9c
1 changed files with 26 additions and 17 deletions

View File

@ -1069,7 +1069,7 @@ next1:
}
static void ufs_trunc_indirect(struct inode *inode, unsigned *offsets, void *p)
static void ufs_trunc_indirect(struct inode *inode, unsigned *offsets, int depth2, void *p)
{
struct super_block *sb = inode->i_sb;
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
@ -1078,7 +1078,7 @@ static void ufs_trunc_indirect(struct inode *inode, unsigned *offsets, void *p)
u64 tmp, frag_to_free = 0;
unsigned free_count = 0;
unsigned from = offsets ? *offsets : 0;
bool to_free = !offsets || !from;
bool to_free = !offsets || !depth2;
unsigned i;
tmp = ufs_data_ptr_to_cpu(sb, p);
@ -1135,14 +1135,14 @@ static void ufs_trunc_indirect(struct inode *inode, unsigned *offsets, void *p)
ubh_brelse (ind_ubh);
}
static void ufs_trunc_dindirect(struct inode *inode, unsigned *offsets, void *p)
static void ufs_trunc_dindirect(struct inode *inode, unsigned *offsets, int depth2, void *p)
{
struct super_block *sb = inode->i_sb;
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
struct ufs_buffer_head *dind_bh;
u64 tmp;
void *dind;
bool free_it = !offsets || !(offsets[0] || offsets[1]);
bool free_it = !offsets || !depth2;
unsigned dindirect_block = offsets ? *offsets++ : 0;
unsigned i;
@ -1162,7 +1162,7 @@ static void ufs_trunc_dindirect(struct inode *inode, unsigned *offsets, void *p)
tmp = ufs_data_ptr_to_cpu(sb, dind);
if (!tmp)
continue;
ufs_trunc_indirect(inode, offsets, dind);
ufs_trunc_indirect(inode, offsets, depth2 - 1, dind);
ubh_mark_buffer_dirty(dind_bh);
}
@ -1182,7 +1182,7 @@ static void ufs_trunc_dindirect(struct inode *inode, unsigned *offsets, void *p)
ubh_brelse (dind_bh);
}
static void ufs_trunc_tindirect(struct inode *inode, unsigned *offsets)
static void ufs_trunc_tindirect(struct inode *inode, unsigned *offsets, int depth2)
{
struct super_block *sb = inode->i_sb;
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
@ -1190,7 +1190,7 @@ static void ufs_trunc_tindirect(struct inode *inode, unsigned *offsets)
struct ufs_buffer_head * tind_bh;
u64 tmp;
void *tind, *p;
bool free_it = !offsets || !(offsets[0] || offsets[1] || offsets[2]);
bool free_it = !offsets || !depth2;
unsigned tindirect_block = offsets ? *offsets++ : 0;
unsigned i;
@ -1207,7 +1207,7 @@ static void ufs_trunc_tindirect(struct inode *inode, unsigned *offsets)
for (i = tindirect_block ; i < uspi->s_apb ; i++, offsets = NULL) {
tind = ubh_get_data_ptr(uspi, tind_bh, i);
ufs_trunc_dindirect(inode, offsets, tind);
ufs_trunc_dindirect(inode, offsets, depth2 - 1, tind);
ubh_mark_buffer_dirty(tind_bh);
}
if (free_it) {
@ -1303,31 +1303,40 @@ static void __ufs_truncate_blocks(struct inode *inode)
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
unsigned offsets[4];
int depth = ufs_block_to_path(inode, DIRECT_BLOCK, offsets);
int depth2;
if (!depth)
return;
/* find the last non-zero in offsets[] */
for (depth2 = depth - 1; depth2; depth2--)
if (offsets[depth2])
break;
mutex_lock(&ufsi->truncate_mutex);
switch (depth) {
case 1:
ufs_trunc_direct(inode);
ufs_trunc_indirect(inode, NULL,
ufs_trunc_indirect(inode, NULL, 0,
ufs_get_direct_data_ptr(uspi, ufsi, UFS_IND_BLOCK));
ufs_trunc_dindirect(inode, NULL,
ufs_trunc_dindirect(inode, NULL, 0,
ufs_get_direct_data_ptr(uspi, ufsi, UFS_DIND_BLOCK));
ufs_trunc_tindirect(inode, NULL);
ufs_trunc_tindirect(inode, NULL, 0);
break;
case 2:
ufs_trunc_indirect(inode, offsets + 1,
ufs_trunc_indirect(inode, offsets + 1, depth2,
ufs_get_direct_data_ptr(uspi, ufsi, UFS_IND_BLOCK));
ufs_trunc_dindirect(inode, NULL,
ufs_trunc_dindirect(inode, NULL, 0,
ufs_get_direct_data_ptr(uspi, ufsi, UFS_DIND_BLOCK));
ufs_trunc_tindirect(inode, NULL);
ufs_trunc_tindirect(inode, NULL, 0);
break;
case 3:
ufs_trunc_dindirect(inode, offsets + 1,
ufs_trunc_dindirect(inode, offsets + 1, depth2,
ufs_get_direct_data_ptr(uspi, ufsi, UFS_DIND_BLOCK));
ufs_trunc_tindirect(inode, NULL);
ufs_trunc_tindirect(inode, NULL, 0);
break;
case 4:
ufs_trunc_tindirect(inode, offsets + 1);
ufs_trunc_tindirect(inode, offsets + 1, depth2);
}
ufsi->i_lastfrag = DIRECT_FRAGMENT;
mutex_unlock(&ufsi->truncate_mutex);