Skip to content

Commit 91c9f28

Browse files
committed
btrfs: return void from btrfs_add_inode_defrag()
The potential memory allocation failure is not a fatal error, skipping autodefrag is fine and the caller inode_should_defrag() does not care about the errors. Further writes can attempt to add the inode back to the defragmentation list again. Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2769409 commit 91c9f28

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

fs/btrfs/defrag.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ static inline int need_auto_defrag(struct btrfs_fs_info *fs_info)
117117
}
118118

119119
/*
120-
* Insert a defrag record for this inode if auto defrag is enabled.
120+
* Insert a defrag record for this inode if auto defrag is enabled. No errors
121+
* returned as they're not considered fatal.
121122
*/
122-
int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
123-
struct btrfs_inode *inode, u32 extent_thresh)
123+
void btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
124+
struct btrfs_inode *inode, u32 extent_thresh)
124125
{
125126
struct btrfs_root *root = inode->root;
126127
struct btrfs_fs_info *fs_info = root->fs_info;
@@ -129,10 +130,10 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
129130
int ret;
130131

131132
if (!need_auto_defrag(fs_info))
132-
return 0;
133+
return;
133134

134135
if (test_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags))
135-
return 0;
136+
return;
136137

137138
if (trans)
138139
transid = trans->transid;
@@ -141,7 +142,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
141142

142143
defrag = kmem_cache_zalloc(btrfs_inode_defrag_cachep, GFP_NOFS);
143144
if (!defrag)
144-
return -ENOMEM;
145+
return;
145146

146147
defrag->ino = btrfs_ino(inode);
147148
defrag->transid = transid;
@@ -162,7 +163,6 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
162163
kmem_cache_free(btrfs_inode_defrag_cachep, defrag);
163164
}
164165
spin_unlock(&fs_info->defrag_inodes_lock);
165-
return 0;
166166
}
167167

168168
/*

fs/btrfs/defrag.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra,
1818
u64 newer_than, unsigned long max_to_defrag);
1919
int __init btrfs_auto_defrag_init(void);
2020
void __cold btrfs_auto_defrag_exit(void);
21-
int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
22-
struct btrfs_inode *inode, u32 extent_thresh);
21+
void btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
22+
struct btrfs_inode *inode, u32 extent_thresh);
2323
int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
2424
void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info);
2525
int btrfs_defrag_root(struct btrfs_root *root);

0 commit comments

Comments
 (0)