Commit e1b81e67 authored by Mingming's avatar Mingming Committed by Chris Mason

btrfs delete ordered inode handling fix

Use btrfs_release_file instead of a put_inode call
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent da496f2a
...@@ -978,6 +978,12 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, ...@@ -978,6 +978,12 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
return num_written ? num_written : err; return num_written ? num_written : err;
} }
static int btrfs_release_file (struct inode * inode, struct file * filp)
{
btrfs_del_ordered_inode(inode);
return 0;
}
static int btrfs_sync_file(struct file *file, static int btrfs_sync_file(struct file *file,
struct dentry *dentry, int datasync) struct dentry *dentry, int datasync)
{ {
...@@ -1044,6 +1050,7 @@ struct file_operations btrfs_file_operations = { ...@@ -1044,6 +1050,7 @@ struct file_operations btrfs_file_operations = {
.write = btrfs_file_write, .write = btrfs_file_write,
.mmap = btrfs_file_mmap, .mmap = btrfs_file_mmap,
.open = generic_file_open, .open = generic_file_open,
.release = btrfs_release_file,
.fsync = btrfs_sync_file, .fsync = btrfs_sync_file,
.unlocked_ioctl = btrfs_ioctl, .unlocked_ioctl = btrfs_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
......
...@@ -857,15 +857,11 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -857,15 +857,11 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
nr = trans->blocks_used; nr = trans->blocks_used;
if (inode->i_nlink == 0) { if (inode->i_nlink == 0) {
int found;
/* if the inode isn't linked anywhere, /* if the inode isn't linked anywhere,
* we don't need to worry about * we don't need to worry about
* data=ordered * data=ordered
*/ */
found = btrfs_del_ordered_inode(inode); btrfs_del_ordered_inode(inode);
if (found == 1) {
atomic_dec(&inode->i_count);
}
} }
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
...@@ -1271,24 +1267,6 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -1271,24 +1267,6 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
return err; return err;
} }
void btrfs_put_inode(struct inode *inode)
{
int ret;
if (!BTRFS_I(inode)->ordered_trans) {
return;
}
if (mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ||
mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK))
return;
ret = btrfs_del_ordered_inode(inode);
if (ret == 1) {
atomic_dec(&inode->i_count);
}
}
void btrfs_delete_inode(struct inode *inode) void btrfs_delete_inode(struct inode *inode)
{ {
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
......
...@@ -231,7 +231,7 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, ...@@ -231,7 +231,7 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
return 1; return 1;
} }
static int __btrfs_del_ordered_inode(struct btrfs_ordered_inode_tree *tree, static void __btrfs_del_ordered_inode(struct btrfs_ordered_inode_tree *tree,
struct inode *inode, struct inode *inode,
u64 root_objectid, u64 objectid) u64 root_objectid, u64 objectid)
{ {
...@@ -243,31 +243,38 @@ static int __btrfs_del_ordered_inode(struct btrfs_ordered_inode_tree *tree, ...@@ -243,31 +243,38 @@ static int __btrfs_del_ordered_inode(struct btrfs_ordered_inode_tree *tree,
node = __tree_search(&tree->tree, root_objectid, objectid, &prev); node = __tree_search(&tree->tree, root_objectid, objectid, &prev);
if (!node) { if (!node) {
write_unlock(&tree->lock); write_unlock(&tree->lock);
return 0; return;
} }
rb_erase(node, &tree->tree); rb_erase(node, &tree->tree);
BTRFS_I(inode)->ordered_trans = 0; BTRFS_I(inode)->ordered_trans = 0;
write_unlock(&tree->lock); write_unlock(&tree->lock);
atomic_dec(&inode->i_count);
entry = rb_entry(node, struct tree_entry, rb_node); entry = rb_entry(node, struct tree_entry, rb_node);
kfree(entry); kfree(entry);
return 1; return;
} }
int btrfs_del_ordered_inode(struct inode *inode) void btrfs_del_ordered_inode(struct inode *inode)
{ {
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
u64 root_objectid = root->root_key.objectid; u64 root_objectid = root->root_key.objectid;
int ret = 0;
if (!BTRFS_I(inode)->ordered_trans) {
return;
}
if (mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ||
mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK))
return;
spin_lock(&root->fs_info->new_trans_lock); spin_lock(&root->fs_info->new_trans_lock);
if (root->fs_info->running_transaction) { if (root->fs_info->running_transaction) {
struct btrfs_ordered_inode_tree *tree; struct btrfs_ordered_inode_tree *tree;
tree = &root->fs_info->running_transaction->ordered_inode_tree; tree = &root->fs_info->running_transaction->ordered_inode_tree;
ret = __btrfs_del_ordered_inode(tree, inode, root_objectid, __btrfs_del_ordered_inode(tree, inode, root_objectid,
inode->i_ino); inode->i_ino);
} }
spin_unlock(&root->fs_info->new_trans_lock); spin_unlock(&root->fs_info->new_trans_lock);
return ret;
} }
int btrfs_ordered_throttle(struct btrfs_root *root, struct inode *inode) int btrfs_ordered_throttle(struct btrfs_root *root, struct inode *inode)
......
...@@ -38,6 +38,6 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, ...@@ -38,6 +38,6 @@ int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree,
u64 *root_objectid, u64 *objectid, u64 *root_objectid, u64 *objectid,
struct inode **inode); struct inode **inode);
int btrfs_del_ordered_inode(struct inode *inode); void btrfs_del_ordered_inode(struct inode *inode);
int btrfs_ordered_throttle(struct btrfs_root *root, struct inode *inode); int btrfs_ordered_throttle(struct btrfs_root *root, struct inode *inode);
#endif #endif
...@@ -487,7 +487,6 @@ static void btrfs_unlockfs(struct super_block *sb) ...@@ -487,7 +487,6 @@ static void btrfs_unlockfs(struct super_block *sb)
static struct super_operations btrfs_super_ops = { static struct super_operations btrfs_super_ops = {
.delete_inode = btrfs_delete_inode, .delete_inode = btrfs_delete_inode,
.put_inode = btrfs_put_inode,
.put_super = btrfs_put_super, .put_super = btrfs_put_super,
.write_super = btrfs_write_super, .write_super = btrfs_write_super,
.sync_fs = btrfs_sync_fs, .sync_fs = btrfs_sync_fs,
......
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