Commit 64708539 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: use btrfs_inode_lock/btrfs_inode_unlock inode lock helpers

A few places we intermix btrfs_inode_lock with a inode_unlock, and some
places we just use inode_lock/inode_unlock instead of btrfs_inode_lock.

None of these places are using this incorrectly, but as we adjust some
of these callers it would be nice to keep everything consistent, so
convert everybody to use btrfs_inode_lock/btrfs_inode_unlock.
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 8318ba79
...@@ -1573,8 +1573,8 @@ bool btrfs_readdir_get_delayed_items(struct inode *inode, ...@@ -1573,8 +1573,8 @@ bool btrfs_readdir_get_delayed_items(struct inode *inode,
* We can only do one readdir with delayed items at a time because of * We can only do one readdir with delayed items at a time because of
* item->readdir_list. * item->readdir_list.
*/ */
inode_unlock_shared(inode); btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
inode_lock(inode); btrfs_inode_lock(inode, 0);
mutex_lock(&delayed_node->mutex); mutex_lock(&delayed_node->mutex);
item = __btrfs_first_delayed_insertion_item(delayed_node); item = __btrfs_first_delayed_insertion_item(delayed_node);
......
...@@ -2122,7 +2122,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -2122,7 +2122,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
if (ret) if (ret)
goto out; goto out;
inode_lock(inode); btrfs_inode_lock(inode, 0);
atomic_inc(&root->log_batch); atomic_inc(&root->log_batch);
...@@ -2154,7 +2154,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -2154,7 +2154,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
*/ */
ret = start_ordered_ops(inode, start, end); ret = start_ordered_ops(inode, start, end);
if (ret) { if (ret) {
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
goto out; goto out;
} }
...@@ -2255,7 +2255,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -2255,7 +2255,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
* file again, but that will end up using the synchronization * file again, but that will end up using the synchronization
* inside btrfs_sync_log to keep things safe. * inside btrfs_sync_log to keep things safe.
*/ */
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
if (ret != BTRFS_NO_LOG_SYNC) { if (ret != BTRFS_NO_LOG_SYNC) {
if (!ret) { if (!ret) {
...@@ -2285,7 +2285,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -2285,7 +2285,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
out_release_extents: out_release_extents:
btrfs_release_log_ctx_extents(&ctx); btrfs_release_log_ctx_extents(&ctx);
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
goto out; goto out;
} }
...@@ -2867,7 +2867,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) ...@@ -2867,7 +2867,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
if (ret) if (ret)
return ret; return ret;
inode_lock(inode); btrfs_inode_lock(inode, 0);
ino_size = round_up(inode->i_size, fs_info->sectorsize); ino_size = round_up(inode->i_size, fs_info->sectorsize);
ret = find_first_non_hole(BTRFS_I(inode), &offset, &len); ret = find_first_non_hole(BTRFS_I(inode), &offset, &len);
if (ret < 0) if (ret < 0)
...@@ -2907,7 +2907,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) ...@@ -2907,7 +2907,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
truncated_block = true; truncated_block = true;
ret = btrfs_truncate_block(BTRFS_I(inode), offset, 0, 0); ret = btrfs_truncate_block(BTRFS_I(inode), offset, 0, 0);
if (ret) { if (ret) {
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
return ret; return ret;
} }
} }
...@@ -3008,7 +3008,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) ...@@ -3008,7 +3008,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
ret = ret2; ret = ret2;
} }
} }
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
return ret; return ret;
} }
...@@ -3376,7 +3376,7 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -3376,7 +3376,7 @@ static long btrfs_fallocate(struct file *file, int mode,
if (mode & FALLOC_FL_ZERO_RANGE) { if (mode & FALLOC_FL_ZERO_RANGE) {
ret = btrfs_zero_range(inode, offset, len, mode); ret = btrfs_zero_range(inode, offset, len, mode);
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
return ret; return ret;
} }
...@@ -3486,7 +3486,7 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -3486,7 +3486,7 @@ static long btrfs_fallocate(struct file *file, int mode,
unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end,
&cached_state); &cached_state);
out: out:
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
/* Let go of our reservation. */ /* Let go of our reservation. */
if (ret != 0 && !(mode & FALLOC_FL_ZERO_RANGE)) if (ret != 0 && !(mode & FALLOC_FL_ZERO_RANGE))
btrfs_free_reserved_data_space(BTRFS_I(inode), data_reserved, btrfs_free_reserved_data_space(BTRFS_I(inode), data_reserved,
......
...@@ -226,7 +226,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -226,7 +226,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
if (ret) if (ret)
return ret; return ret;
inode_lock(inode); btrfs_inode_lock(inode, 0);
fsflags = btrfs_mask_fsflags_for_type(inode, fsflags); fsflags = btrfs_mask_fsflags_for_type(inode, fsflags);
old_fsflags = btrfs_inode_flags_to_fsflags(binode->flags); old_fsflags = btrfs_inode_flags_to_fsflags(binode->flags);
...@@ -353,7 +353,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -353,7 +353,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
out_end_trans: out_end_trans:
btrfs_end_transaction(trans); btrfs_end_transaction(trans);
out_unlock: out_unlock:
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
mnt_drop_write_file(file); mnt_drop_write_file(file);
return ret; return ret;
} }
...@@ -449,7 +449,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg) ...@@ -449,7 +449,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)
if (ret) if (ret)
return ret; return ret;
inode_lock(inode); btrfs_inode_lock(inode, 0);
old_flags = binode->flags; old_flags = binode->flags;
old_i_flags = inode->i_flags; old_i_flags = inode->i_flags;
...@@ -501,7 +501,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg) ...@@ -501,7 +501,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)
inode->i_flags = old_i_flags; inode->i_flags = old_i_flags;
} }
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
mnt_drop_write_file(file); mnt_drop_write_file(file);
return ret; return ret;
...@@ -1014,7 +1014,7 @@ static noinline int btrfs_mksubvol(const struct path *parent, ...@@ -1014,7 +1014,7 @@ static noinline int btrfs_mksubvol(const struct path *parent,
out_dput: out_dput:
dput(dentry); dput(dentry);
out_unlock: out_unlock:
inode_unlock(dir); btrfs_inode_unlock(dir, 0);
return error; return error;
} }
...@@ -1612,7 +1612,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ...@@ -1612,7 +1612,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
ra_index += cluster; ra_index += cluster;
} }
inode_lock(inode); btrfs_inode_lock(inode, 0);
if (IS_SWAPFILE(inode)) { if (IS_SWAPFILE(inode)) {
ret = -ETXTBSY; ret = -ETXTBSY;
} else { } else {
...@@ -1621,13 +1621,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ...@@ -1621,13 +1621,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
ret = cluster_pages_for_defrag(inode, pages, i, cluster); ret = cluster_pages_for_defrag(inode, pages, i, cluster);
} }
if (ret < 0) { if (ret < 0) {
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
goto out_ra; goto out_ra;
} }
defrag_count += ret; defrag_count += ret;
balance_dirty_pages_ratelimited(inode->i_mapping); balance_dirty_pages_ratelimited(inode->i_mapping);
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
if (newer_than) { if (newer_than) {
if (newer_off == (u64)-1) if (newer_off == (u64)-1)
...@@ -1675,9 +1675,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ...@@ -1675,9 +1675,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
out_ra: out_ra:
if (do_compress) { if (do_compress) {
inode_lock(inode); btrfs_inode_lock(inode, 0);
BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE; BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE;
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
} }
if (!file) if (!file)
kfree(ra); kfree(ra);
...@@ -3112,9 +3112,9 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, ...@@ -3112,9 +3112,9 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
goto out_dput; goto out_dput;
} }
inode_lock(inode); btrfs_inode_lock(inode, 0);
err = btrfs_delete_subvolume(dir, dentry); err = btrfs_delete_subvolume(dir, dentry);
inode_unlock(inode); btrfs_inode_unlock(inode, 0);
if (!err) { if (!err) {
fsnotify_rmdir(dir, dentry); fsnotify_rmdir(dir, dentry);
d_delete(dentry); d_delete(dentry);
...@@ -3123,7 +3123,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, ...@@ -3123,7 +3123,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
out_dput: out_dput:
dput(dentry); dput(dentry);
out_unlock_dir: out_unlock_dir:
inode_unlock(dir); btrfs_inode_unlock(dir, 0);
free_subvol_name: free_subvol_name:
kfree(subvol_name_ptr); kfree(subvol_name_ptr);
free_parent: free_parent:
......
...@@ -833,7 +833,7 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off, ...@@ -833,7 +833,7 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off,
return -EINVAL; return -EINVAL;
if (same_inode) if (same_inode)
inode_lock(src_inode); btrfs_inode_lock(src_inode, 0);
else else
lock_two_nondirectories(src_inode, dst_inode); lock_two_nondirectories(src_inode, dst_inode);
...@@ -849,7 +849,7 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off, ...@@ -849,7 +849,7 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off,
out_unlock: out_unlock:
if (same_inode) if (same_inode)
inode_unlock(src_inode); btrfs_inode_unlock(src_inode, 0);
else else
unlock_two_nondirectories(src_inode, dst_inode); unlock_two_nondirectories(src_inode, dst_inode);
......
...@@ -2578,7 +2578,7 @@ static noinline_for_stack int prealloc_file_extent_cluster( ...@@ -2578,7 +2578,7 @@ static noinline_for_stack int prealloc_file_extent_cluster(
return btrfs_end_transaction(trans); return btrfs_end_transaction(trans);
} }
inode_lock(&inode->vfs_inode); btrfs_inode_lock(&inode->vfs_inode, 0);
for (nr = 0; nr < cluster->nr; nr++) { for (nr = 0; nr < cluster->nr; nr++) {
start = cluster->boundary[nr] - offset; start = cluster->boundary[nr] - offset;
if (nr + 1 < cluster->nr) if (nr + 1 < cluster->nr)
...@@ -2596,7 +2596,7 @@ static noinline_for_stack int prealloc_file_extent_cluster( ...@@ -2596,7 +2596,7 @@ static noinline_for_stack int prealloc_file_extent_cluster(
if (ret) if (ret)
break; break;
} }
inode_unlock(&inode->vfs_inode); btrfs_inode_unlock(&inode->vfs_inode, 0);
if (cur_offset < prealloc_end) if (cur_offset < prealloc_end)
btrfs_free_reserved_data_space_noquota(inode->root->fs_info, btrfs_free_reserved_data_space_noquota(inode->root->fs_info,
......
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