Commit d4455fac authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

proc: mandate ->proc_lseek in "struct proc_ops"

Now that proc_ops are separate from file_operations and other operations
it easy to check all instances to have ->proc_lseek hook and remove check
in main code.

Note:
nonseekable_open() files naturally don't require ->proc_lseek.

Garbage collect pde_lseek() function.

[adobriyan@gmail.com: smoke test lseek()]
  Link: https://lkml.kernel.org/r/YG4OIhChOrVTPgdN@localhost.localdomain

Link: https://lkml.kernel.org/r/YFYX0Bzwxlc7aBa/@localhost.localdomainSigned-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b793cd9a
...@@ -201,6 +201,7 @@ static ssize_t empty_read(struct file *file, char __user *buf, ...@@ -201,6 +201,7 @@ static ssize_t empty_read(struct file *file, char __user *buf,
static const struct proc_ops empty_proc_ops = { static const struct proc_ops empty_proc_ops = {
.proc_read = empty_read, .proc_read = empty_read,
.proc_lseek = default_llseek,
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
...@@ -227,6 +227,7 @@ static ssize_t prism2_aux_dump_proc_no_read(struct file *file, char __user *buf, ...@@ -227,6 +227,7 @@ static ssize_t prism2_aux_dump_proc_no_read(struct file *file, char __user *buf,
static const struct proc_ops prism2_aux_dump_proc_ops = { static const struct proc_ops prism2_aux_dump_proc_ops = {
.proc_read = prism2_aux_dump_proc_no_read, .proc_read = prism2_aux_dump_proc_no_read,
.proc_lseek = default_llseek,
}; };
......
...@@ -616,6 +616,7 @@ static const struct file_operations esas2r_proc_fops = { ...@@ -616,6 +616,7 @@ static const struct file_operations esas2r_proc_fops = {
}; };
static const struct proc_ops esas2r_proc_ops = { static const struct proc_ops esas2r_proc_ops = {
.proc_lseek = default_llseek,
.proc_ioctl = esas2r_proc_ioctl, .proc_ioctl = esas2r_proc_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.proc_compat_ioctl = compat_ptr_ioctl, .proc_compat_ioctl = compat_ptr_ioctl,
......
...@@ -273,25 +273,15 @@ void proc_entry_rundown(struct proc_dir_entry *de) ...@@ -273,25 +273,15 @@ void proc_entry_rundown(struct proc_dir_entry *de)
spin_unlock(&de->pde_unload_lock); spin_unlock(&de->pde_unload_lock);
} }
static loff_t pde_lseek(struct proc_dir_entry *pde, struct file *file, loff_t offset, int whence)
{
typeof_member(struct proc_ops, proc_lseek) lseek;
lseek = pde->proc_ops->proc_lseek;
if (!lseek)
lseek = default_llseek;
return lseek(file, offset, whence);
}
static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence) static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
{ {
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
loff_t rv = -EINVAL; loff_t rv = -EINVAL;
if (pde_is_permanent(pde)) { if (pde_is_permanent(pde)) {
return pde_lseek(pde, file, offset, whence); return pde->proc_ops->proc_lseek(file, offset, whence);
} else if (use_pde(pde)) { } else if (use_pde(pde)) {
rv = pde_lseek(pde, file, offset, whence); rv = pde->proc_ops->proc_lseek(file, offset, whence);
unuse_pde(pde); unuse_pde(pde);
} }
return rv; return rv;
......
...@@ -32,6 +32,7 @@ struct proc_ops { ...@@ -32,6 +32,7 @@ struct proc_ops {
ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *); ssize_t (*proc_read)(struct file *, char __user *, size_t, loff_t *);
ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *); ssize_t (*proc_read_iter)(struct kiocb *, struct iov_iter *);
ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *); ssize_t (*proc_write)(struct file *, const char __user *, size_t, loff_t *);
/* mandatory unless nonseekable_open() or equivalent is used */
loff_t (*proc_lseek)(struct file *, loff_t, int); loff_t (*proc_lseek)(struct file *, loff_t, int);
int (*proc_release)(struct inode *, struct file *); int (*proc_release)(struct inode *, struct file *);
__poll_t (*proc_poll)(struct file *, struct poll_table_struct *); __poll_t (*proc_poll)(struct file *, struct poll_table_struct *);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
// Test // Test
// 1) read of every file in /proc // 1) read and lseek on every file in /proc
// 2) readlink of every symlink in /proc // 2) readlink of every symlink in /proc
// 3) recursively (1) + (2) for every directory in /proc // 3) recursively (1) + (2) for every directory in /proc
// 4) write to /proc/*/clear_refs and /proc/*/task/*/clear_refs // 4) write to /proc/*/clear_refs and /proc/*/task/*/clear_refs
...@@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename) ...@@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK); fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
if (fd == -1) if (fd == -1)
return; return;
/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
(void)lseek(fd, 0, SEEK_SET);
rv = read(fd, buf, sizeof(buf)); rv = read(fd, buf, sizeof(buf));
assert((0 <= rv && rv <= sizeof(buf)) || rv == -1); assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
close(fd); close(fd);
......
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