struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct extent_map *em = NULL;
struct extent_state *cached_state = NULL;
+ loff_t i_size = inode->i_size;
u64 lockstart;
u64 lockend;
u64 start;
u64 len;
int ret = 0;
- if (inode->i_size == 0)
+ if (i_size == 0 || *offset >= i_size)
return -ENXIO;
/*
start = max_t(loff_t, 0, *offset);
lockstart = round_down(start, fs_info->sectorsize);
- lockend = round_up(i_size_read(inode),
- fs_info->sectorsize);
+ lockend = round_up(i_size, fs_info->sectorsize);
if (lockend <= lockstart)
lockend = lockstart + fs_info->sectorsize;
lockend--;
lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend,
&cached_state);
- while (start < inode->i_size) {
+ while (start < i_size) {
em = btrfs_get_extent_fiemap(BTRFS_I(inode), start, len);
if (IS_ERR(em)) {
ret = PTR_ERR(em);
}
free_extent_map(em);
if (!ret) {
- if (whence == SEEK_DATA && start >= inode->i_size)
+ if (whence == SEEK_DATA && start >= i_size)
ret = -ENXIO;
else
- *offset = min_t(loff_t, start, inode->i_size);
+ *offset = min_t(loff_t, start, i_size);
}
unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend,
&cached_state);
struct inode *inode = file->f_mapping->host;
int ret;
- inode_lock(inode);
switch (whence) {
case SEEK_END:
case SEEK_CUR:
goto out;
case SEEK_DATA:
case SEEK_HOLE:
- if (offset >= i_size_read(inode)) {
- inode_unlock(inode);
- return -ENXIO;
- }
-
+ inode_lock_shared(inode);
ret = find_desired_extent(inode, &offset, whence);
- if (ret) {
- inode_unlock(inode);
+ inode_unlock_shared(inode);
+
+ if (ret)
return ret;
- }
}
offset = vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
out:
- inode_unlock(inode);
return offset;
}