summaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2019-09-27 13:23:18 +0300
committerDavid Sterba <dsterba@suse.com>2019-11-18 12:47:00 +0100
commitbc80230e0e7bc779cd553c2326ea5b3a5bac303b (patch)
treede85f0acbee7fffa6e28d8d156b57f61889d46dd /fs/btrfs
parent2034f3b470ccfd4103737cf4d2a25a52ce9ad002 (diff)
downloadlinux-bc80230e0e7bc779cd553c2326ea5b3a5bac303b.tar.bz2
btrfs: Return offset from find_desired_extent
Instead of using an input pointer parameter as the return value and have an int as the return type of find_desired_extent, rework the function to directly return the found offset. Doing that the 'ret' variable in btrfs_llseek_file can be removed. Additional (subjective) benefit is that btrfs' llseek function now resemebles those of the other major filesystems. Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/file.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 949212289c89..32e620981485 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -3351,7 +3351,8 @@ out:
return ret;
}
-static int find_desired_extent(struct inode *inode, loff_t *offset, int whence)
+static loff_t find_desired_extent(struct inode *inode, loff_t offset,
+ int whence)
{
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct extent_map *em = NULL;
@@ -3363,14 +3364,14 @@ static int find_desired_extent(struct inode *inode, loff_t *offset, int whence)
u64 len;
int ret = 0;
- if (i_size == 0 || *offset >= i_size)
+ if (i_size == 0 || offset >= i_size)
return -ENXIO;
/*
- * *offset can be negative, in this case we start finding DATA/HOLE from
+ * offset can be negative, in this case we start finding DATA/HOLE from
* the very start of the file.
*/
- start = max_t(loff_t, 0, *offset);
+ start = max_t(loff_t, 0, offset);
lockstart = round_down(start, fs_info->sectorsize);
lockend = round_up(i_size, fs_info->sectorsize);
@@ -3405,21 +3406,23 @@ static int find_desired_extent(struct inode *inode, loff_t *offset, int whence)
cond_resched();
}
free_extent_map(em);
- if (!ret) {
+ unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend,
+ &cached_state);
+ if (ret) {
+ offset = ret;
+ } else {
if (whence == SEEK_DATA && start >= i_size)
- ret = -ENXIO;
+ offset = -ENXIO;
else
- *offset = min_t(loff_t, start, i_size);
+ offset = min_t(loff_t, start, i_size);
}
- unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend,
- &cached_state);
- return ret;
+
+ return offset;
}
static loff_t btrfs_file_llseek(struct file *file, loff_t offset, int whence)
{
struct inode *inode = file->f_mapping->host;
- int ret;
switch (whence) {
default:
@@ -3427,13 +3430,14 @@ static loff_t btrfs_file_llseek(struct file *file, loff_t offset, int whence)
case SEEK_DATA:
case SEEK_HOLE:
inode_lock_shared(inode);
- ret = find_desired_extent(inode, &offset, whence);
+ offset = find_desired_extent(inode, offset, whence);
inode_unlock_shared(inode);
-
- if (ret)
- return ret;
+ break;
}
+ if (offset < 0)
+ return offset;
+
return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
}