Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

+9 -9
+7 -7
fs/btrfs/defrag.c
··· 117 117 } 118 118 119 119 /* 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. 121 122 */ 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) 124 125 { 125 126 struct btrfs_root *root = inode->root; 126 127 struct btrfs_fs_info *fs_info = root->fs_info; ··· 130 129 int ret; 131 130 132 131 if (!need_auto_defrag(fs_info)) 133 - return 0; 132 + return; 134 133 135 134 if (test_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags)) 136 - return 0; 135 + return; 137 136 138 137 if (trans) 139 138 transid = trans->transid; ··· 142 141 143 142 defrag = kmem_cache_zalloc(btrfs_inode_defrag_cachep, GFP_NOFS); 144 143 if (!defrag) 145 - return -ENOMEM; 144 + return; 146 145 147 146 defrag->ino = btrfs_ino(inode); 148 147 defrag->transid = transid; ··· 163 162 kmem_cache_free(btrfs_inode_defrag_cachep, defrag); 164 163 } 165 164 spin_unlock(&fs_info->defrag_inodes_lock); 166 - return 0; 167 165 } 168 166 169 167 /*
+2 -2
fs/btrfs/defrag.h
··· 18 18 u64 newer_than, unsigned long max_to_defrag); 19 19 int __init btrfs_auto_defrag_init(void); 20 20 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); 23 23 int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info); 24 24 void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info); 25 25 int btrfs_defrag_root(struct btrfs_root *root);