Skip to content

Commit a782e86

Browse files
committed
Merge tag 'pull-work.lseek' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs lseek updates from Al Viro: "Jason's lseek series. Saner handling of 'lseek should fail with ESPIPE' - this gets rid of the magical no_llseek thing and makes checks consistent. In particular, the ad-hoc "can we do splice via internal pipe" checks got saner (and somewhat more permissive, which is what Jason had been after, AFAICT)" * tag 'pull-work.lseek' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: fs: remove no_llseek fs: check FMODE_LSEEK to control internal pipe splicing vfio: do not set FMODE_LSEEK flag dma-buf: remove useless FMODE_LSEEK flag fs: do not compare against ->llseek fs: clear or set FMODE_LSEEK based on llseek function
2 parents d939551 + 868941b commit a782e86

File tree

12 files changed

+26
-31
lines changed

12 files changed

+26
-31
lines changed

Documentation/filesystems/porting.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,3 +914,11 @@ Calling conventions for file_open_root() changed; now it takes struct path *
914914
instead of passing mount and dentry separately. For callers that used to
915915
pass <mnt, mnt->mnt_root> pair (i.e. the root of given mount), a new helper
916916
is provided - file_open_root_mnt(). In-tree users adjusted.
917+
918+
---
919+
920+
**mandatory**
921+
922+
no_llseek is gone; don't set .llseek to that - just leave it NULL instead.
923+
Checks for "does that file have llseek(2), or should it fail with ESPIPE"
924+
should be done by looking at FMODE_LSEEK in file->f_mode.

drivers/dma-buf/dma-buf.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
549549
goto err_dmabuf;
550550
}
551551

552-
file->f_mode |= FMODE_LSEEK;
553552
dmabuf->file = file;
554553

555554
mutex_init(&dmabuf->lock);

drivers/gpu/drm/drm_file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@ EXPORT_SYMBOL(drm_release_noglobal);
552552
* Since events are used by the KMS API for vblank and page flip completion this
553553
* means all modern display drivers must use it.
554554
*
555-
* @offset is ignored, DRM events are read like a pipe. Therefore drivers also
556-
* must set the &file_operation.llseek to no_llseek(). Polling support is
555+
* @offset is ignored, DRM events are read like a pipe. Polling support is
557556
* provided by drm_poll().
558557
*
559558
* This function will only ever read a full event. Therefore userspace must

drivers/vfio/vfio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ static struct file *vfio_device_open(struct vfio_device *device)
11321132
* Appears to be missing by lack of need rather than
11331133
* explicitly prevented. Now there's need.
11341134
*/
1135-
filep->f_mode |= (FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
1135+
filep->f_mode |= (FMODE_PREAD | FMODE_PWRITE);
11361136

11371137
if (device->group->type == VFIO_NO_IOMMU)
11381138
dev_warn(device->dev, "vfio-noiommu device opened by user "

fs/coredump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,9 @@ static int __dump_skip(struct coredump_params *cprm, size_t nr)
816816
{
817817
static char zeroes[PAGE_SIZE];
818818
struct file *file = cprm->file;
819-
if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
819+
if (file->f_mode & FMODE_LSEEK) {
820820
if (dump_interrupted() ||
821-
file->f_op->llseek(file, nr, SEEK_CUR) < 0)
821+
vfs_llseek(file, nr, SEEK_CUR) < 0)
822822
return 0;
823823
cprm->pos += nr;
824824
return 1;

fs/file_table.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ static struct file *alloc_file(const struct path *path, int flags,
235235
file->f_mapping = path->dentry->d_inode->i_mapping;
236236
file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
237237
file->f_sb_err = file_sample_sb_err(file);
238+
if (fop->llseek)
239+
file->f_mode |= FMODE_LSEEK;
238240
if ((file->f_mode & FMODE_READ) &&
239241
likely(fop->read || fop->read_iter))
240242
file->f_mode |= FMODE_CAN_READ;

fs/open.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ static int do_dentry_open(struct file *f,
888888
if ((f->f_mode & FMODE_WRITE) &&
889889
likely(f->f_op->write || f->f_op->write_iter))
890890
f->f_mode |= FMODE_CAN_WRITE;
891+
if ((f->f_mode & FMODE_LSEEK) && !f->f_op->llseek)
892+
f->f_mode &= ~FMODE_LSEEK;
891893
if (f->f_mapping->a_ops && f->f_mapping->a_ops->direct_IO)
892894
f->f_mode |= FMODE_CAN_ODIRECT;
893895

fs/overlayfs/copy_up.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ static int ovl_copy_up_data(struct ovl_fs *ofs, struct path *old,
226226
/* Couldn't clone, so now we try to copy the data */
227227

228228
/* Check if lower fs supports seek operation */
229-
if (old_file->f_mode & FMODE_LSEEK &&
230-
old_file->f_op->llseek)
229+
if (old_file->f_mode & FMODE_LSEEK)
231230
skip_hole = true;
232231

233232
while (len) {

fs/read_write.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,6 @@ loff_t noop_llseek(struct file *file, loff_t offset, int whence)
227227
}
228228
EXPORT_SYMBOL(noop_llseek);
229229

230-
loff_t no_llseek(struct file *file, loff_t offset, int whence)
231-
{
232-
return -ESPIPE;
233-
}
234-
EXPORT_SYMBOL(no_llseek);
235-
236230
loff_t default_llseek(struct file *file, loff_t offset, int whence)
237231
{
238232
struct inode *inode = file_inode(file);
@@ -290,14 +284,9 @@ EXPORT_SYMBOL(default_llseek);
290284

291285
loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
292286
{
293-
loff_t (*fn)(struct file *, loff_t, int);
294-
295-
fn = no_llseek;
296-
if (file->f_mode & FMODE_LSEEK) {
297-
if (file->f_op->llseek)
298-
fn = file->f_op->llseek;
299-
}
300-
return fn(file, offset, whence);
287+
if (!(file->f_mode & FMODE_LSEEK))
288+
return -ESPIPE;
289+
return file->f_op->llseek(file, offset, whence);
301290
}
302291
EXPORT_SYMBOL(vfs_llseek);
303292

fs/splice.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,17 +814,15 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
814814
{
815815
struct pipe_inode_info *pipe;
816816
long ret, bytes;
817-
umode_t i_mode;
818817
size_t len;
819818
int i, flags, more;
820819

821820
/*
822-
* We require the input being a regular file, as we don't want to
823-
* randomly drop data for eg socket -> socket splicing. Use the
824-
* piped splicing for that!
821+
* We require the input to be seekable, as we don't want to randomly
822+
* drop data for eg socket -> socket splicing. Use the piped splicing
823+
* for that!
825824
*/
826-
i_mode = file_inode(in)->i_mode;
827-
if (unlikely(!S_ISREG(i_mode) && !S_ISBLK(i_mode)))
825+
if (unlikely(!(in->f_mode & FMODE_LSEEK)))
828826
return -EINVAL;
829827

830828
/*

0 commit comments

Comments
 (0)