Bug 188741

Summary: Function btrfs_uuid_scan_kthread() does not return error code on failures
Product: File System Reporter: bianpan (bianpan2010)
Component: btrfsAssignee: Josef Bacik (josef)
Status: NEW ---    
Severity: normal    
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: linux-4.9-rc6 Subsystem:
Regression: No Bisected commit-id:

Description bianpan 2016-11-25 10:53:20 UTC
Function btrfs_uuid_scan_kthread() is defined in file fs/btrfs/volumes.c. When the call to btrfs_alloc_path() fails, it assigns "-ENOMEM" to variable ret and jumps to label "out". However, 0 rather than ret is returned at the end. As a result, the callers will not be able to detect errors during the execution of btrfs_uuid_scan_kthread(). Maybe it is better to use "return ret;" instead of "return 0;" at line 356. Codes related to this bug are summarised as follows.

4094 static int btrfs_uuid_scan_kthread(void *data)
4095 {
4096     struct btrfs_fs_info *fs_info = data;
4097     struct btrfs_root *root = fs_info->tree_root;
4098     struct btrfs_key key;
4099     struct btrfs_key max_key;
4100     struct btrfs_path *path = NULL;
4101     int ret = 0;
4102     struct extent_buffer *eb;
4103     int slot;
4104     struct btrfs_root_item root_item;
4105     u32 item_size;
4106     struct btrfs_trans_handle *trans = NULL;
4107 
4108     path = btrfs_alloc_path();
4109     if (!path) {
4110         ret = -ENOMEM;
4111         goto out;
4112     }
         ...
4216 out:
4217     btrfs_free_path(path);
4218     if (trans && !IS_ERR(trans))
4219         btrfs_end_transaction(trans, fs_info->uuid_root);
4220     if (ret)
4221         btrfs_warn(fs_info, "btrfs_uuid_scan_kthread failed %d", ret);
4222     else
4223         set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags);
4224     up(&fs_info->uuid_tree_rescan_sem);
4225     return 0;       // return ret?
4226 }

Thanks very much!