Skip to content

Commit

Permalink
excessive checks in ufs_write_failed() and ufs_evict_inode()
Browse files Browse the repository at this point in the history
As it is, short copy in write() to append-only file will fail
to truncate the excessive allocated blocks.  As the matter of
fact, all checks in ufs_truncate_blocks() are either redundant
or wrong for that caller.  As for the only other caller
(ufs_evict_inode()), we only need the file type checks there.

Cc: [email protected]
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jun 9, 2017
1 parent 006351a commit babef37
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions fs/ufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,9 @@ void ufs_evict_inode(struct inode * inode)
truncate_inode_pages_final(&inode->i_data);
if (want_delete) {
inode->i_size = 0;
if (inode->i_blocks)
if (inode->i_blocks &&
(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
S_ISLNK(inode->i_mode)))
ufs_truncate_blocks(inode);
}

Expand Down Expand Up @@ -1103,7 +1105,7 @@ static int ufs_alloc_lastblock(struct inode *inode, loff_t size)
return err;
}

static void __ufs_truncate_blocks(struct inode *inode)
static void ufs_truncate_blocks(struct inode *inode)
{
struct ufs_inode_info *ufsi = UFS_I(inode);
struct super_block *sb = inode->i_sb;
Expand Down Expand Up @@ -1186,24 +1188,14 @@ static int ufs_truncate(struct inode *inode, loff_t size)

truncate_setsize(inode, size);

__ufs_truncate_blocks(inode);
ufs_truncate_blocks(inode);
inode->i_mtime = inode->i_ctime = current_time(inode);
mark_inode_dirty(inode);
out:
UFSD("EXIT: err %d\n", err);
return err;
}

static void ufs_truncate_blocks(struct inode *inode)
{
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
S_ISLNK(inode->i_mode)))
return;
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return;
__ufs_truncate_blocks(inode);
}

int ufs_setattr(struct dentry *dentry, struct iattr *attr)
{
struct inode *inode = d_inode(dentry);
Expand Down

0 comments on commit babef37

Please sign in to comment.