mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 12:11:40 +00:00
gfs2: Implement SEEK_HOLE / SEEK_DATA via iomap
So far, lseek on gfs2 did not report holes. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Bob Peterson <rpeterso@redhat.com>
This commit is contained in:
parent
aac1a55b45
commit
3a27411cb4
@ -60,9 +60,7 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)
|
||||
loff_t error;
|
||||
|
||||
switch (whence) {
|
||||
case SEEK_END: /* These reference inode->i_size */
|
||||
case SEEK_DATA:
|
||||
case SEEK_HOLE:
|
||||
case SEEK_END:
|
||||
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
|
||||
&i_gh);
|
||||
if (!error) {
|
||||
@ -70,8 +68,21 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)
|
||||
gfs2_glock_dq_uninit(&i_gh);
|
||||
}
|
||||
break;
|
||||
|
||||
case SEEK_DATA:
|
||||
error = gfs2_seek_data(file, offset);
|
||||
break;
|
||||
|
||||
case SEEK_HOLE:
|
||||
error = gfs2_seek_hole(file, offset);
|
||||
break;
|
||||
|
||||
case SEEK_CUR:
|
||||
case SEEK_SET:
|
||||
/*
|
||||
* These don't reference inode->i_size and don't depend on the
|
||||
* block mapping, so we don't need the glock.
|
||||
*/
|
||||
error = generic_file_llseek(file, offset, whence);
|
||||
break;
|
||||
default:
|
||||
|
@ -2029,6 +2029,44 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
loff_t gfs2_seek_data(struct file *file, loff_t offset)
|
||||
{
|
||||
struct inode *inode = file->f_mapping->host;
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
loff_t ret;
|
||||
|
||||
inode_lock_shared(inode);
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
|
||||
if (!ret)
|
||||
ret = iomap_seek_data(inode, offset, &gfs2_iomap_ops);
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
inode_unlock_shared(inode);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
return vfs_setpos(file, ret, inode->i_sb->s_maxbytes);
|
||||
}
|
||||
|
||||
loff_t gfs2_seek_hole(struct file *file, loff_t offset)
|
||||
{
|
||||
struct inode *inode = file->f_mapping->host;
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
loff_t ret;
|
||||
|
||||
inode_lock_shared(inode);
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
|
||||
if (!ret)
|
||||
ret = iomap_seek_hole(inode, offset, &gfs2_iomap_ops);
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
inode_unlock_shared(inode);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
return vfs_setpos(file, ret, inode->i_sb->s_maxbytes);
|
||||
}
|
||||
|
||||
const struct inode_operations gfs2_file_iops = {
|
||||
.permission = gfs2_permission,
|
||||
.setattr = gfs2_setattr,
|
||||
|
@ -109,6 +109,8 @@ extern int gfs2_setattr_simple(struct inode *inode, struct iattr *attr);
|
||||
extern struct inode *gfs2_lookup_simple(struct inode *dip, const char *name);
|
||||
extern void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf);
|
||||
extern int gfs2_open_common(struct inode *inode, struct file *file);
|
||||
extern loff_t gfs2_seek_data(struct file *file, loff_t offset);
|
||||
extern loff_t gfs2_seek_hole(struct file *file, loff_t offset);
|
||||
|
||||
extern const struct inode_operations gfs2_file_iops;
|
||||
extern const struct inode_operations gfs2_dir_iops;
|
||||
|
Loading…
Reference in New Issue
Block a user