From: Josef Bacik <josef@redhat.com> To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, xfs@oss.sgi.com, viro@ZenIV.linux.org.uk Subject: [PATCH 4/4] fs: handle SEEK_HOLE/SEEK_DATA properly in all fs's that define their own llseek Date: Tue, 28 Jun 2011 11:33:18 -0400 [thread overview] Message-ID: <1309275199-10801-4-git-send-email-josef@redhat.com> (raw) In-Reply-To: <1309275199-10801-1-git-send-email-josef@redhat.com> This converts everybody to handle SEEK_HOLE/SEEK_DATA properly. In some cases we just return -EINVAL, in others we do the normal generic thing, and in others we're simply making sure that the properly due-dilligence is done. For example in NFS/CIFS we need to make sure the file size is update properly for the SEEK_HOLE and SEEK_DATA case, but since it calls the generic llseek stuff itself that is all we have to do. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com> --- fs/block_dev.c | 11 ++++++++--- fs/ceph/dir.c | 8 +++++++- fs/ceph/file.c | 20 ++++++++++++++++++-- fs/cifs/cifsfs.c | 7 +++++-- fs/fuse/file.c | 21 +++++++++++++++++++-- fs/hpfs/dir.c | 4 ++++ fs/nfs/file.c | 7 +++++-- 7 files changed, 66 insertions(+), 12 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 610e8e0..966617a 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -355,20 +355,25 @@ static loff_t block_llseek(struct file *file, loff_t offset, int origin) mutex_lock(&bd_inode->i_mutex); size = i_size_read(bd_inode); + retval = -EINVAL; switch (origin) { - case 2: + case SEEK_END: offset += size; break; - case 1: + case SEEK_CUR: offset += file->f_pos; + case SEEK_SET: + break; + default: + goto out; } - retval = -EINVAL; if (offset >= 0 && offset <= size) { if (offset != file->f_pos) { file->f_pos = offset; } retval = offset; } +out: mutex_unlock(&bd_inode->i_mutex); return retval; } diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index ef8f08c..79cd77c 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -446,14 +446,19 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin) loff_t retval; mutex_lock(&inode->i_mutex); + retval = -EINVAL; switch (origin) { case SEEK_END: offset += inode->i_size + 2; /* FIXME */ break; case SEEK_CUR: offset += file->f_pos; + case SEEK_SET: + break; + default: + goto out; } - retval = -EINVAL; + if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) { if (offset != file->f_pos) { file->f_pos = offset; @@ -477,6 +482,7 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin) if (offset > old_offset) fi->dir_release_count--; } +out: mutex_unlock(&inode->i_mutex); return retval; } diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 9542f07..774feb1 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -770,13 +770,16 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int origin) mutex_lock(&inode->i_mutex); __ceph_do_pending_vmtruncate(inode); - switch (origin) { - case SEEK_END: + if (origin != SEEK_CUR || origin != SEEK_SET) { ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE); if (ret < 0) { offset = ret; goto out; } + } + + switch (origin) { + case SEEK_END: offset += inode->i_size; break; case SEEK_CUR: @@ -792,6 +795,19 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int origin) } offset += file->f_pos; break; + case SEEK_DATA: + if (offset >= inode->i_size) { + ret = -ENXIO; + goto out; + } + break; + case SEEK_HOLE: + if (offset >= inode->i_size) { + ret = -ENXIO; + goto out; + } + offset = inode->i_size; + break; } if (offset < 0 || offset > inode->i_sb->s_maxbytes) { diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 35f9154..5feb6bb 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -746,8 +746,11 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, static loff_t cifs_llseek(struct file *file, loff_t offset, int origin) { - /* origin == SEEK_END => we must revalidate the cached file length */ - if (origin == SEEK_END) { + /* + * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate + * the cached file length + */ + if (origin != SEEK_SET || origin != SEEK_CUR) { int rc; struct inode *inode = file->f_path.dentry->d_inode; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 82a6646..73b89df 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1600,15 +1600,32 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin) struct inode *inode = file->f_path.dentry->d_inode; mutex_lock(&inode->i_mutex); - switch (origin) { - case SEEK_END: + if (origin != SEEK_CUR || origin != SEEK_SET) { retval = fuse_update_attributes(inode, NULL, file, NULL); if (retval) goto exit; + } + + switch (origin) { + case SEEK_END: offset += i_size_read(inode); break; case SEEK_CUR: offset += file->f_pos; + break; + case SEEK_DATA: + if (offset >= i_size_read(inode)) { + retval = -ENXIO; + goto exit; + } + break; + case SEEK_HOLE: + if (offset >= i_size_read(inode)) { + retval = -ENXIO; + goto exit; + } + offset = i_size_read(inode); + break; } retval = -EINVAL; if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) { diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c index f46ae02..96a8ed9 100644 --- a/fs/hpfs/dir.c +++ b/fs/hpfs/dir.c @@ -29,6 +29,10 @@ static loff_t hpfs_dir_lseek(struct file *filp, loff_t off, int whence) struct hpfs_inode_info *hpfs_inode = hpfs_i(i); struct super_block *s = i->i_sb; + /* Somebody else will have to figure out what to do here */ + if (whence == SEEK_DATA || whence == SEEK_HOLE) + return -EINVAL; + hpfs_lock(s); /*printk("dir lseek\n");*/ diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 2f093ed..2c1705b 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -187,8 +187,11 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin) filp->f_path.dentry->d_name.name, offset, origin); - /* origin == SEEK_END => we must revalidate the cached file length */ - if (origin == SEEK_END) { + /* + * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate + * the cached file length + */ + if (origin != SEEK_SET || origin != SEEK_CUR) { struct inode *inode = filp->f_mapping->host; int retval = nfs_revalidate_file_size(inode, filp); -- 1.7.5.2
WARNING: multiple messages have this Message-ID (diff)
From: Josef Bacik <josef@redhat.com> To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, xfs@oss.sgi.com, viro@ZenIV.linux.org.uk Subject: [PATCH 4/4] fs: handle SEEK_HOLE/SEEK_DATA properly in all fs's that define their own llseek Date: Tue, 28 Jun 2011 11:33:18 -0400 [thread overview] Message-ID: <1309275199-10801-4-git-send-email-josef@redhat.com> (raw) In-Reply-To: <1309275199-10801-1-git-send-email-josef@redhat.com> This converts everybody to handle SEEK_HOLE/SEEK_DATA properly. In some cases we just return -EINVAL, in others we do the normal generic thing, and in others we're simply making sure that the properly due-dilligence is done. For example in NFS/CIFS we need to make sure the file size is update properly for the SEEK_HOLE and SEEK_DATA case, but since it calls the generic llseek stuff itself that is all we have to do. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com> --- fs/block_dev.c | 11 ++++++++--- fs/ceph/dir.c | 8 +++++++- fs/ceph/file.c | 20 ++++++++++++++++++-- fs/cifs/cifsfs.c | 7 +++++-- fs/fuse/file.c | 21 +++++++++++++++++++-- fs/hpfs/dir.c | 4 ++++ fs/nfs/file.c | 7 +++++-- 7 files changed, 66 insertions(+), 12 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 610e8e0..966617a 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -355,20 +355,25 @@ static loff_t block_llseek(struct file *file, loff_t offset, int origin) mutex_lock(&bd_inode->i_mutex); size = i_size_read(bd_inode); + retval = -EINVAL; switch (origin) { - case 2: + case SEEK_END: offset += size; break; - case 1: + case SEEK_CUR: offset += file->f_pos; + case SEEK_SET: + break; + default: + goto out; } - retval = -EINVAL; if (offset >= 0 && offset <= size) { if (offset != file->f_pos) { file->f_pos = offset; } retval = offset; } +out: mutex_unlock(&bd_inode->i_mutex); return retval; } diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index ef8f08c..79cd77c 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -446,14 +446,19 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin) loff_t retval; mutex_lock(&inode->i_mutex); + retval = -EINVAL; switch (origin) { case SEEK_END: offset += inode->i_size + 2; /* FIXME */ break; case SEEK_CUR: offset += file->f_pos; + case SEEK_SET: + break; + default: + goto out; } - retval = -EINVAL; + if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) { if (offset != file->f_pos) { file->f_pos = offset; @@ -477,6 +482,7 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin) if (offset > old_offset) fi->dir_release_count--; } +out: mutex_unlock(&inode->i_mutex); return retval; } diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 9542f07..774feb1 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -770,13 +770,16 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int origin) mutex_lock(&inode->i_mutex); __ceph_do_pending_vmtruncate(inode); - switch (origin) { - case SEEK_END: + if (origin != SEEK_CUR || origin != SEEK_SET) { ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE); if (ret < 0) { offset = ret; goto out; } + } + + switch (origin) { + case SEEK_END: offset += inode->i_size; break; case SEEK_CUR: @@ -792,6 +795,19 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int origin) } offset += file->f_pos; break; + case SEEK_DATA: + if (offset >= inode->i_size) { + ret = -ENXIO; + goto out; + } + break; + case SEEK_HOLE: + if (offset >= inode->i_size) { + ret = -ENXIO; + goto out; + } + offset = inode->i_size; + break; } if (offset < 0 || offset > inode->i_sb->s_maxbytes) { diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 35f9154..5feb6bb 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -746,8 +746,11 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, static loff_t cifs_llseek(struct file *file, loff_t offset, int origin) { - /* origin == SEEK_END => we must revalidate the cached file length */ - if (origin == SEEK_END) { + /* + * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate + * the cached file length + */ + if (origin != SEEK_SET || origin != SEEK_CUR) { int rc; struct inode *inode = file->f_path.dentry->d_inode; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 82a6646..73b89df 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1600,15 +1600,32 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin) struct inode *inode = file->f_path.dentry->d_inode; mutex_lock(&inode->i_mutex); - switch (origin) { - case SEEK_END: + if (origin != SEEK_CUR || origin != SEEK_SET) { retval = fuse_update_attributes(inode, NULL, file, NULL); if (retval) goto exit; + } + + switch (origin) { + case SEEK_END: offset += i_size_read(inode); break; case SEEK_CUR: offset += file->f_pos; + break; + case SEEK_DATA: + if (offset >= i_size_read(inode)) { + retval = -ENXIO; + goto exit; + } + break; + case SEEK_HOLE: + if (offset >= i_size_read(inode)) { + retval = -ENXIO; + goto exit; + } + offset = i_size_read(inode); + break; } retval = -EINVAL; if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) { diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c index f46ae02..96a8ed9 100644 --- a/fs/hpfs/dir.c +++ b/fs/hpfs/dir.c @@ -29,6 +29,10 @@ static loff_t hpfs_dir_lseek(struct file *filp, loff_t off, int whence) struct hpfs_inode_info *hpfs_inode = hpfs_i(i); struct super_block *s = i->i_sb; + /* Somebody else will have to figure out what to do here */ + if (whence == SEEK_DATA || whence == SEEK_HOLE) + return -EINVAL; + hpfs_lock(s); /*printk("dir lseek\n");*/ diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 2f093ed..2c1705b 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -187,8 +187,11 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin) filp->f_path.dentry->d_name.name, offset, origin); - /* origin == SEEK_END => we must revalidate the cached file length */ - if (origin == SEEK_END) { + /* + * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate + * the cached file length + */ + if (origin != SEEK_SET || origin != SEEK_CUR) { struct inode *inode = filp->f_mapping->host; int retval = nfs_revalidate_file_size(inode, filp); -- 1.7.5.2 _______________________________________________ xfs mailing list xfs@oss.sgi.com http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2011-06-28 15:33 UTC|newest] Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-06-28 15:33 [PATCH 1/4] fs: add SEEK_HOLE and SEEK_DATA flags Josef Bacik 2011-06-28 15:33 ` Josef Bacik 2011-06-28 15:33 ` [PATCH 2/4] Btrfs: implement our own ->llseek Josef Bacik 2011-06-28 15:33 ` Josef Bacik 2011-06-28 15:33 ` [PATCH 3/4] Ext4: handle SEEK_HOLE/SEEK_DATA generically Josef Bacik 2011-06-28 15:33 ` Josef Bacik 2011-06-28 16:29 ` Andreas Dilger 2011-06-28 17:34 ` Josef Bacik 2011-06-28 15:33 ` Josef Bacik [this message] 2011-06-28 15:33 ` [PATCH 4/4] fs: handle SEEK_HOLE/SEEK_DATA properly in all fs's that define their own llseek Josef Bacik 2011-06-28 15:33 ` [PATCH] xfstests 255: add a seek_data/seek_hole tester Josef Bacik 2011-06-28 15:33 ` Josef Bacik 2011-06-29 6:53 ` Dave Chinner 2011-06-29 6:53 ` Dave Chinner 2011-06-29 6:53 ` Dave Chinner 2011-06-29 6:53 ` Dave Chinner 2011-06-29 7:40 ` Christoph Hellwig 2011-06-29 7:40 ` Christoph Hellwig 2011-06-29 10:42 ` Pádraig Brady 2011-06-29 10:42 ` Pádraig Brady 2011-06-29 10:42 ` Pádraig Brady 2011-06-29 10:42 ` Pádraig Brady 2011-06-29 17:29 ` Sunil Mushran 2011-06-29 17:29 ` Sunil Mushran 2011-06-29 17:29 ` Sunil Mushran 2011-06-29 17:29 ` Sunil Mushran 2011-06-29 17:36 ` Christoph Hellwig 2011-06-29 17:36 ` Christoph Hellwig 2011-06-29 17:40 ` Sunil Mushran 2011-06-29 17:40 ` Sunil Mushran 2011-06-29 21:29 ` Pádraig Brady 2011-06-29 21:29 ` Pádraig Brady 2011-06-29 21:29 ` Pádraig Brady 2011-07-01 9:37 ` Christoph Hellwig 2011-07-01 9:37 ` Christoph Hellwig 2011-06-29 17:10 ` Sunil Mushran 2011-06-29 17:10 ` Sunil Mushran 2011-06-29 17:52 ` Josef Bacik 2011-06-29 17:52 ` Josef Bacik 2011-06-29 13:19 ` Josef Bacik 2011-06-29 13:19 ` Josef Bacik 2011-06-29 13:19 ` Josef Bacik 2011-08-25 6:06 ` Christoph Hellwig 2011-08-25 6:06 ` Christoph Hellwig 2011-08-25 6:40 ` Dave Chinner 2011-08-25 6:40 ` Dave Chinner 2011-08-25 6:51 ` Andreas Dilger 2011-08-25 6:51 ` Andreas Dilger 2011-08-26 1:35 ` Dave Chinner 2011-08-26 1:35 ` Dave Chinner 2011-08-26 6:24 ` Marco Stornelli 2011-08-26 6:24 ` Marco Stornelli 2011-08-26 6:24 ` Marco Stornelli 2011-08-26 14:41 ` Zach Brown 2011-08-26 14:41 ` Zach Brown 2011-08-26 14:41 ` Zach Brown 2011-08-26 14:41 ` Zach Brown 2011-08-27 8:30 ` Marco Stornelli 2011-08-27 8:30 ` Marco Stornelli 2011-08-28 10:17 ` Marco Stornelli 2011-08-28 10:17 ` Marco Stornelli 2011-08-30 17:42 ` Sunil Mushran 2011-08-30 17:42 ` Sunil Mushran 2011-08-31 1:17 ` Sunil Mushran 2011-08-31 1:17 ` Sunil Mushran 2011-08-31 3:29 ` Dave Chinner 2011-08-31 3:29 ` Dave Chinner 2011-08-31 3:53 ` david 2011-08-31 3:53 ` david 2011-08-31 4:43 ` Sunil Mushran 2011-08-31 4:43 ` Sunil Mushran 2011-08-31 9:05 ` Pádraig Brady 2011-08-31 9:05 ` Pádraig Brady 2011-08-31 9:05 ` Pádraig Brady 2011-08-31 4:48 ` Dan Merillat 2011-08-31 4:48 ` Dan Merillat 2011-07-29 9:58 ` [PATCH 1/4] fs: add SEEK_HOLE and SEEK_DATA flags Marco Stornelli 2011-07-29 9:58 ` Marco Stornelli 2011-08-20 9:41 ` Marco Stornelli 2011-08-20 9:41 ` Marco Stornelli 2011-08-20 10:03 ` Marco Stornelli 2011-08-20 10:03 ` Marco Stornelli 2011-08-20 15:36 ` Sunil Mushran 2011-08-20 15:36 ` Sunil Mushran 2011-08-20 16:32 ` Marco Stornelli 2011-08-20 16:32 ` Marco Stornelli 2011-08-22 6:08 ` Sunil Mushran 2011-08-22 6:08 ` Sunil Mushran 2011-08-22 10:56 ` Marco Stornelli 2011-08-22 10:56 ` Marco Stornelli 2011-08-22 10:56 ` Marco Stornelli 2011-08-22 10:56 ` Marco Stornelli 2011-08-22 15:57 ` Sunil Mushran 2011-08-22 15:57 ` Sunil Mushran 2011-08-22 17:56 ` Marco Stornelli 2011-08-22 17:56 ` Marco Stornelli 2011-08-22 21:22 ` Sunil Mushran 2011-08-22 21:22 ` Sunil Mushran 2011-08-23 17:44 ` Marco Stornelli 2011-08-23 17:44 ` Marco Stornelli 2011-08-31 0:35 ` Dave Chinner 2011-08-31 0:35 ` Dave Chinner [not found] ` <CAGpXXZ+xjhadprkc_LiP3qUypLLkCxdeEmo8+K+6mOnBuNhmLg@mail.gmail.com> 2011-08-20 17:18 ` Greg Freemyer -- strict thread matches above, loose matches on Subject: below -- 2011-06-27 18:02 Josef Bacik 2011-06-27 18:02 ` [PATCH 4/4] fs: handle SEEK_HOLE/SEEK_DATA properly in all fs's that define their own llseek Josef Bacik
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1309275199-10801-4-git-send-email-josef@redhat.com \ --to=josef@redhat.com \ --cc=linux-btrfs@vger.kernel.org \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=viro@ZenIV.linux.org.uk \ --cc=xfs@oss.sgi.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.