Commit 40680f2f authored by Jan Kara's avatar Jan Kara

ext3: Convert ext3 to new truncate calling convention

Mostly trivial conversion. We fix a bug that IS_IMMUTABLE and IS_APPEND files
could not be truncated during failed writes as we change the code.  In fact the
test is not needed at all because both IS_IMMUTABLE and IS_APPEND is tested in
upper layers in do_sys_[f]truncate(), may_write(), etc.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 99cb1a31
...@@ -71,7 +71,6 @@ const struct file_operations ext3_file_operations = { ...@@ -71,7 +71,6 @@ const struct file_operations ext3_file_operations = {
}; };
const struct inode_operations ext3_file_inode_operations = { const struct inode_operations ext3_file_inode_operations = {
.truncate = ext3_truncate,
.setattr = ext3_setattr, .setattr = ext3_setattr,
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT3_FS_XATTR
.setxattr = generic_setxattr, .setxattr = generic_setxattr,
......
...@@ -234,12 +234,10 @@ void ext3_evict_inode (struct inode *inode) ...@@ -234,12 +234,10 @@ void ext3_evict_inode (struct inode *inode)
if (inode->i_blocks) if (inode->i_blocks)
ext3_truncate(inode); ext3_truncate(inode);
/* /*
* Kill off the orphan record which ext3_truncate created. * Kill off the orphan record created when the inode lost the last
* AKPM: I think this can be inside the above `if'. * link. Note that ext3_orphan_del() has to be able to cope with the
* Note that ext3_orphan_del() has to be able to cope with the * deletion of a non-existent orphan - ext3_truncate() could
* deletion of a non-existent orphan - this is because we don't * have removed the record.
* know if ext3_truncate() actually created an orphan record.
* (Well, we could do this if we need to, but heck - it works)
*/ */
ext3_orphan_del(handle, inode); ext3_orphan_del(handle, inode);
EXT3_I(inode)->i_dtime = get_seconds(); EXT3_I(inode)->i_dtime = get_seconds();
...@@ -890,6 +888,9 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -890,6 +888,9 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
if (!create || err == -EIO) if (!create || err == -EIO)
goto cleanup; goto cleanup;
/*
* Block out ext3_truncate while we alter the tree
*/
mutex_lock(&ei->truncate_mutex); mutex_lock(&ei->truncate_mutex);
/* /*
...@@ -938,9 +939,6 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -938,9 +939,6 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
*/ */
count = ext3_blks_to_allocate(partial, indirect_blks, count = ext3_blks_to_allocate(partial, indirect_blks,
maxblocks, blocks_to_boundary); maxblocks, blocks_to_boundary);
/*
* Block out ext3_truncate while we alter the tree
*/
err = ext3_alloc_branch(handle, inode, indirect_blks, &count, goal, err = ext3_alloc_branch(handle, inode, indirect_blks, &count, goal,
offsets + (partial - chain), partial); offsets + (partial - chain), partial);
...@@ -1849,7 +1847,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1849,7 +1847,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
loff_t end = offset + iov_length(iov, nr_segs); loff_t end = offset + iov_length(iov, nr_segs);
if (end > isize) if (end > isize)
vmtruncate(inode, isize); ext3_truncate_failed_write(inode);
} }
if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries))
goto retry; goto retry;
...@@ -1863,7 +1861,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1863,7 +1861,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
/* This is really bad luck. We've written the data /* This is really bad luck. We've written the data
* but cannot extend i_size. Truncate allocated blocks * but cannot extend i_size. Truncate allocated blocks
* and pretend the write failed... */ * and pretend the write failed... */
ext3_truncate(inode); ext3_truncate_failed_write(inode);
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
goto out; goto out;
} }
...@@ -2414,8 +2412,6 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2414,8 +2412,6 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
int ext3_can_truncate(struct inode *inode) int ext3_can_truncate(struct inode *inode)
{ {
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return 0;
if (S_ISREG(inode->i_mode)) if (S_ISREG(inode->i_mode))
return 1; return 1;
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
...@@ -3264,9 +3260,8 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -3264,9 +3260,8 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
if ((attr->ia_valid & ATTR_SIZE) && if ((attr->ia_valid & ATTR_SIZE) &&
attr->ia_size != i_size_read(inode)) { attr->ia_size != i_size_read(inode)) {
rc = vmtruncate(inode, attr->ia_size); truncate_setsize(inode, attr->ia_size);
if (rc) ext3_truncate(inode);
goto err_out;
} }
setattr_copy(inode, attr); setattr_copy(inode, attr);
......
...@@ -913,7 +913,7 @@ extern void ext3_dirty_inode(struct inode *, int); ...@@ -913,7 +913,7 @@ extern void ext3_dirty_inode(struct inode *, int);
extern int ext3_change_inode_journal_flag(struct inode *, int); extern int ext3_change_inode_journal_flag(struct inode *, int);
extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *); extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *);
extern int ext3_can_truncate(struct inode *inode); extern int ext3_can_truncate(struct inode *inode);
extern void ext3_truncate (struct inode *); extern void ext3_truncate(struct inode *inode);
extern void ext3_set_inode_flags(struct inode *); extern void ext3_set_inode_flags(struct inode *);
extern void ext3_get_inode_flags(struct ext3_inode_info *); extern void ext3_get_inode_flags(struct ext3_inode_info *);
extern void ext3_set_aops(struct inode *inode); extern void ext3_set_aops(struct inode *inode);
......
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