Commit e7478158 authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Al Viro

fs: clear or set FMODE_LSEEK based on llseek function

Pipe-like behaviour on llseek(2) (i.e. unconditionally failing with
-ESPIPE) can be expresses in 3 ways:
	1) ->llseek set to NULL in file_operations
	2) ->llseek set to no_llseek in file_operations
	3) FMODE_LSEEK *not* set in ->f_mode.

Enforce (3) in cases (1) and (2); that will allow to simplify the
checks and eventually get rid of no_llseek boilerplate.
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent b13baccc
...@@ -235,6 +235,8 @@ static struct file *alloc_file(const struct path *path, int flags, ...@@ -235,6 +235,8 @@ static struct file *alloc_file(const struct path *path, int flags,
file->f_mapping = path->dentry->d_inode->i_mapping; file->f_mapping = path->dentry->d_inode->i_mapping;
file->f_wb_err = filemap_sample_wb_err(file->f_mapping); file->f_wb_err = filemap_sample_wb_err(file->f_mapping);
file->f_sb_err = file_sample_sb_err(file); file->f_sb_err = file_sample_sb_err(file);
if (fop->llseek && fop->llseek != no_llseek)
file->f_mode |= FMODE_LSEEK;
if ((file->f_mode & FMODE_READ) && if ((file->f_mode & FMODE_READ) &&
likely(fop->read || fop->read_iter)) likely(fop->read || fop->read_iter))
file->f_mode |= FMODE_CAN_READ; file->f_mode |= FMODE_CAN_READ;
......
...@@ -858,6 +858,10 @@ static int do_dentry_open(struct file *f, ...@@ -858,6 +858,10 @@ static int do_dentry_open(struct file *f,
if ((f->f_mode & FMODE_WRITE) && if ((f->f_mode & FMODE_WRITE) &&
likely(f->f_op->write || f->f_op->write_iter)) likely(f->f_op->write || f->f_op->write_iter))
f->f_mode |= FMODE_CAN_WRITE; f->f_mode |= FMODE_CAN_WRITE;
if ((f->f_mode & FMODE_LSEEK) && !f->f_op->llseek)
f->f_mode &= ~FMODE_LSEEK;
if ((f->f_mode & FMODE_LSEEK) && f->f_op->llseek == no_llseek)
f->f_mode &= ~FMODE_LSEEK;
if (f->f_mapping->a_ops && f->f_mapping->a_ops->direct_IO) if (f->f_mapping->a_ops && f->f_mapping->a_ops->direct_IO)
f->f_mode |= FMODE_CAN_ODIRECT; f->f_mode |= FMODE_CAN_ODIRECT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment