Commit 6158e1ce authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: Make (__)btrfs_add_inode_defrag take btrfs_inode

Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 691fa059
...@@ -3215,7 +3215,7 @@ ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen, ...@@ -3215,7 +3215,7 @@ ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen,
int btrfs_auto_defrag_init(void); int btrfs_auto_defrag_init(void);
void btrfs_auto_defrag_exit(void); void btrfs_auto_defrag_exit(void);
int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
struct inode *inode); struct btrfs_inode *inode);
int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info); int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info); void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info);
int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
......
...@@ -92,10 +92,10 @@ static int __compare_inode_defrag(struct inode_defrag *defrag1, ...@@ -92,10 +92,10 @@ static int __compare_inode_defrag(struct inode_defrag *defrag1,
* If an existing record is found the defrag item you * If an existing record is found the defrag item you
* pass in is freed * pass in is freed
*/ */
static int __btrfs_add_inode_defrag(struct inode *inode, static int __btrfs_add_inode_defrag(struct btrfs_inode *inode,
struct inode_defrag *defrag) struct inode_defrag *defrag)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb);
struct inode_defrag *entry; struct inode_defrag *entry;
struct rb_node **p; struct rb_node **p;
struct rb_node *parent = NULL; struct rb_node *parent = NULL;
...@@ -123,7 +123,7 @@ static int __btrfs_add_inode_defrag(struct inode *inode, ...@@ -123,7 +123,7 @@ static int __btrfs_add_inode_defrag(struct inode *inode,
return -EEXIST; return -EEXIST;
} }
} }
set_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags); set_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags);
rb_link_node(&defrag->rb_node, parent, p); rb_link_node(&defrag->rb_node, parent, p);
rb_insert_color(&defrag->rb_node, &fs_info->defrag_inodes); rb_insert_color(&defrag->rb_node, &fs_info->defrag_inodes);
return 0; return 0;
...@@ -145,10 +145,10 @@ static inline int __need_auto_defrag(struct btrfs_fs_info *fs_info) ...@@ -145,10 +145,10 @@ static inline int __need_auto_defrag(struct btrfs_fs_info *fs_info)
* enabled * enabled
*/ */
int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
struct inode *inode) struct btrfs_inode *inode)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb);
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = inode->root;
struct inode_defrag *defrag; struct inode_defrag *defrag;
u64 transid; u64 transid;
int ret; int ret;
...@@ -156,24 +156,24 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, ...@@ -156,24 +156,24 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
if (!__need_auto_defrag(fs_info)) if (!__need_auto_defrag(fs_info))
return 0; return 0;
if (test_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags)) if (test_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags))
return 0; return 0;
if (trans) if (trans)
transid = trans->transid; transid = trans->transid;
else else
transid = BTRFS_I(inode)->root->last_trans; transid = inode->root->last_trans;
defrag = kmem_cache_zalloc(btrfs_inode_defrag_cachep, GFP_NOFS); defrag = kmem_cache_zalloc(btrfs_inode_defrag_cachep, GFP_NOFS);
if (!defrag) if (!defrag)
return -ENOMEM; return -ENOMEM;
defrag->ino = btrfs_ino(BTRFS_I(inode)); defrag->ino = btrfs_ino(inode);
defrag->transid = transid; defrag->transid = transid;
defrag->root = root->root_key.objectid; defrag->root = root->root_key.objectid;
spin_lock(&fs_info->defrag_inodes_lock); spin_lock(&fs_info->defrag_inodes_lock);
if (!test_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags)) { if (!test_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags)) {
/* /*
* If we set IN_DEFRAG flag and evict the inode from memory, * If we set IN_DEFRAG flag and evict the inode from memory,
* and then re-read this inode, this new inode doesn't have * and then re-read this inode, this new inode doesn't have
...@@ -208,7 +208,7 @@ static void btrfs_requeue_inode_defrag(struct inode *inode, ...@@ -208,7 +208,7 @@ static void btrfs_requeue_inode_defrag(struct inode *inode,
* them together. * them together.
*/ */
spin_lock(&fs_info->defrag_inodes_lock); spin_lock(&fs_info->defrag_inodes_lock);
ret = __btrfs_add_inode_defrag(inode, defrag); ret = __btrfs_add_inode_defrag(BTRFS_I(inode), defrag);
spin_unlock(&fs_info->defrag_inodes_lock); spin_unlock(&fs_info->defrag_inodes_lock);
if (ret) if (ret)
goto out; goto out;
......
...@@ -389,12 +389,12 @@ static inline int inode_need_compress(struct inode *inode) ...@@ -389,12 +389,12 @@ static inline int inode_need_compress(struct inode *inode)
return 0; return 0;
} }
static inline void inode_should_defrag(struct inode *inode, static inline void inode_should_defrag(struct btrfs_inode *inode,
u64 start, u64 end, u64 num_bytes, u64 small_write) u64 start, u64 end, u64 num_bytes, u64 small_write)
{ {
/* If this is a small write inside eof, kick off a defrag */ /* If this is a small write inside eof, kick off a defrag */
if (num_bytes < small_write && if (num_bytes < small_write &&
(start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size)) (start > 0 || end + 1 < inode->disk_i_size))
btrfs_add_inode_defrag(NULL, inode); btrfs_add_inode_defrag(NULL, inode);
} }
...@@ -440,7 +440,8 @@ static noinline void compress_file_range(struct inode *inode, ...@@ -440,7 +440,8 @@ static noinline void compress_file_range(struct inode *inode,
int compress_type = fs_info->compress_type; int compress_type = fs_info->compress_type;
int redirty = 0; int redirty = 0;
inode_should_defrag(inode, start, end, end - start + 1, SZ_16K); inode_should_defrag(BTRFS_I(inode), start, end, end - start + 1,
SZ_16K);
actual_end = min_t(u64, isize, end + 1); actual_end = min_t(u64, isize, end + 1);
again: again:
...@@ -943,7 +944,7 @@ static noinline int cow_file_range(struct inode *inode, ...@@ -943,7 +944,7 @@ static noinline int cow_file_range(struct inode *inode,
num_bytes = max(blocksize, num_bytes); num_bytes = max(blocksize, num_bytes);
disk_num_bytes = num_bytes; disk_num_bytes = num_bytes;
inode_should_defrag(inode, start, end, num_bytes, SZ_64K); inode_should_defrag(BTRFS_I(inode), start, end, num_bytes, SZ_64K);
if (start == 0) { if (start == 0) {
/* lets try to make an inline extent */ /* lets try to make an inline extent */
......
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