Skip to content

Commit

Permalink
btrfs: use btrfs_inode_lock/btrfs_inode_unlock inode lock helpers
Browse files Browse the repository at this point in the history
[ Upstream commit 6470853 ]

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: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
josefbacik authored and gregkh committed May 12, 2021
1 parent 4f2fee1 commit 7bc617c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions fs/btrfs/delayed-inode.c
Expand Up @@ -1589,8 +1589,8 @@ bool btrfs_readdir_get_delayed_items(struct inode *inode,
* We can only do one readdir with delayed items at a time because of
* item->readdir_list.
*/
inode_unlock_shared(inode);
inode_lock(inode);
btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
btrfs_inode_lock(inode, 0);

mutex_lock(&delayed_node->mutex);
item = __btrfs_first_delayed_insertion_item(delayed_node);
Expand Down
18 changes: 9 additions & 9 deletions fs/btrfs/file.c
Expand Up @@ -2122,7 +2122,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
if (ret)
goto out;

inode_lock(inode);
btrfs_inode_lock(inode, 0);

atomic_inc(&root->log_batch);

Expand Down Expand Up @@ -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);
if (ret) {
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
goto out;
}

Expand Down Expand Up @@ -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
* inside btrfs_sync_log to keep things safe.
*/
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);

if (ret != BTRFS_NO_LOG_SYNC) {
if (!ret) {
Expand Down Expand Up @@ -2285,7 +2285,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)

out_release_extents:
btrfs_release_log_ctx_extents(&ctx);
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
goto out;
}

Expand Down Expand Up @@ -2868,7 +2868,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
if (ret)
return ret;

inode_lock(inode);
btrfs_inode_lock(inode, 0);
ino_size = round_up(inode->i_size, fs_info->sectorsize);
ret = find_first_non_hole(BTRFS_I(inode), &offset, &len);
if (ret < 0)
Expand Down Expand Up @@ -2908,7 +2908,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
truncated_block = true;
ret = btrfs_truncate_block(BTRFS_I(inode), offset, 0, 0);
if (ret) {
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
return ret;
}
}
Expand Down Expand Up @@ -3009,7 +3009,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
ret = ret2;
}
}
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
return ret;
}

Expand Down Expand Up @@ -3377,7 +3377,7 @@ static long btrfs_fallocate(struct file *file, int mode,

if (mode & FALLOC_FL_ZERO_RANGE) {
ret = btrfs_zero_range(inode, offset, len, mode);
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
return ret;
}

Expand Down Expand Up @@ -3487,7 +3487,7 @@ static long btrfs_fallocate(struct file *file, int mode,
unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end,
&cached_state);
out:
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
/* Let go of our reservation. */
if (ret != 0 && !(mode & FALLOC_FL_ZERO_RANGE))
btrfs_free_reserved_data_space(BTRFS_I(inode), data_reserved,
Expand Down
26 changes: 13 additions & 13 deletions fs/btrfs/ioctl.c
Expand Up @@ -226,7 +226,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
if (ret)
return ret;

inode_lock(inode);
btrfs_inode_lock(inode, 0);
fsflags = btrfs_mask_fsflags_for_type(inode, fsflags);
old_fsflags = btrfs_inode_flags_to_fsflags(binode->flags);

Expand Down Expand Up @@ -353,7 +353,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
out_end_trans:
btrfs_end_transaction(trans);
out_unlock:
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
mnt_drop_write_file(file);
return ret;
}
Expand Down Expand Up @@ -449,7 +449,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)
if (ret)
return ret;

inode_lock(inode);
btrfs_inode_lock(inode, 0);

old_flags = binode->flags;
old_i_flags = inode->i_flags;
Expand Down Expand Up @@ -501,7 +501,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)
inode->i_flags = old_i_flags;
}

inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
mnt_drop_write_file(file);

return ret;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ static noinline int btrfs_mksubvol(const struct path *parent,
out_dput:
dput(dentry);
out_unlock:
inode_unlock(dir);
btrfs_inode_unlock(dir, 0);
return error;
}

Expand Down Expand Up @@ -1624,7 +1624,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
ra_index += cluster;
}

inode_lock(inode);
btrfs_inode_lock(inode, 0);
if (IS_SWAPFILE(inode)) {
ret = -ETXTBSY;
} else {
Expand All @@ -1633,13 +1633,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
ret = cluster_pages_for_defrag(inode, pages, i, cluster);
}
if (ret < 0) {
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
goto out_ra;
}

defrag_count += ret;
balance_dirty_pages_ratelimited(inode->i_mapping);
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);

if (newer_than) {
if (newer_off == (u64)-1)
Expand Down Expand Up @@ -1687,9 +1687,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,

out_ra:
if (do_compress) {
inode_lock(inode);
btrfs_inode_lock(inode, 0);
BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE;
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
}
if (!file)
kfree(ra);
Expand Down Expand Up @@ -3124,9 +3124,9 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
goto out_dput;
}

inode_lock(inode);
btrfs_inode_lock(inode, 0);
err = btrfs_delete_subvolume(dir, dentry);
inode_unlock(inode);
btrfs_inode_unlock(inode, 0);
if (!err) {
fsnotify_rmdir(dir, dentry);
d_delete(dentry);
Expand All @@ -3135,7 +3135,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
out_dput:
dput(dentry);
out_unlock_dir:
inode_unlock(dir);
btrfs_inode_unlock(dir, 0);
free_subvol_name:
kfree(subvol_name_ptr);
free_parent:
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/reflink.c
Expand Up @@ -833,7 +833,7 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off,
return -EINVAL;

if (same_inode)
inode_lock(src_inode);
btrfs_inode_lock(src_inode, 0);
else
lock_two_nondirectories(src_inode, dst_inode);

Expand All @@ -849,7 +849,7 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off,

out_unlock:
if (same_inode)
inode_unlock(src_inode);
btrfs_inode_unlock(src_inode, 0);
else
unlock_two_nondirectories(src_inode, dst_inode);

Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/relocation.c
Expand Up @@ -2578,7 +2578,7 @@ static noinline_for_stack int prealloc_file_extent_cluster(
return btrfs_end_transaction(trans);
}

inode_lock(&inode->vfs_inode);
btrfs_inode_lock(&inode->vfs_inode, 0);
for (nr = 0; nr < cluster->nr; nr++) {
start = cluster->boundary[nr] - offset;
if (nr + 1 < cluster->nr)
Expand All @@ -2596,7 +2596,7 @@ static noinline_for_stack int prealloc_file_extent_cluster(
if (ret)
break;
}
inode_unlock(&inode->vfs_inode);
btrfs_inode_unlock(&inode->vfs_inode, 0);

if (cur_offset < prealloc_end)
btrfs_free_reserved_data_space_noquota(inode->root->fs_info,
Expand Down

0 comments on commit 7bc617c

Please sign in to comment.