diff options
author | Li Dongyang <[email protected]> | 2013-06-13 13:51:09 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2013-07-02 09:24:43 -0700 |
commit | 802e7b5feb0135483de119eac1da192404eb5bb7 (patch) | |
tree | 79e9810d340a3fdc66aa5c557bad3cddb7b72efc /module/zfs/zpl_file.c | |
parent | cf91b2b6b2baaca1e56f23c985e3261cd98bd3f0 (diff) |
Add SEEK_DATA/SEEK_HOLE to lseek()/llseek()
The approach taken was the rework zfs_holey() as little as
possible and then just wrap the code as needed to ensure
correct locking and error handling.
Tested with xfstests 285 and 286. All tests pass except for
7-9 of 285 which try to reserve blocks first via fallocate(2)
and fail because fallocate(2) is not yet supported.
Note that the filp->f_lock spinlock did not exist prior to
Linux 2.6.30, but we avoid the need for autotools check by
virtue of the fact that SEEK_DATA/SEEK_HOLE support was not
added until Linux 3.1.
An autoconf check was added for lseek_execute() which is
currently a private function but the expectation is that it
will be exported perhaps as early as Linux 3.11.
Reviewed-by: Richard Laager <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #1384
Diffstat (limited to 'module/zfs/zpl_file.c')
-rw-r--r-- | module/zfs/zpl_file.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/module/zfs/zpl_file.c b/module/zfs/zpl_file.c index c6d97db50..ebae6bfe2 100644 --- a/module/zfs/zpl_file.c +++ b/module/zfs/zpl_file.c @@ -235,6 +235,28 @@ zpl_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos) return (wrote); } +static loff_t +zpl_llseek(struct file *filp, loff_t offset, int whence) +{ +#if defined(SEEK_HOLE) && defined(SEEK_DATA) + if (whence == SEEK_DATA || whence == SEEK_HOLE) { + struct inode *ip = filp->f_mapping->host; + loff_t maxbytes = ip->i_sb->s_maxbytes; + loff_t error; + + spl_inode_lock(ip); + error = -zfs_holey(ip, whence, &offset); + if (error == 0) + error = lseek_execute(filp, ip, offset, maxbytes); + spl_inode_unlock(ip); + + return (error); + } +#endif /* SEEK_HOLE && SEEK_DATA */ + + return generic_file_llseek(filp, offset, whence); +} + /* * It's worth taking a moment to describe how mmap is implemented * for zfs because it differs considerably from other Linux filesystems. @@ -464,7 +486,7 @@ const struct address_space_operations zpl_address_space_operations = { const struct file_operations zpl_file_operations = { .open = zpl_open, .release = zpl_release, - .llseek = generic_file_llseek, + .llseek = zpl_llseek, .read = zpl_read, .write = zpl_write, .mmap = zpl_mmap, |