]> git.baikalelectronics.ru Git - kernel.git/commitdiff
proc: add a read_iter method to proc proc_ops
authorChristoph Hellwig <hch@lst.de>
Thu, 3 Sep 2020 14:22:31 +0000 (16:22 +0200)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 4 Sep 2020 01:26:24 +0000 (21:26 -0400)
This will allow proc files to implement iter read semantics.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/proc/inode.c
include/linux/proc_fs.h

index 93dd20457375043d17399f3229a5f25161ef6005..58c075e2a452d63cdc230d9aeb134a2426550ef4 100644 (file)
@@ -297,6 +297,21 @@ static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
        return rv;
 }
 
+static ssize_t proc_reg_read_iter(struct kiocb *iocb, struct iov_iter *iter)
+{
+       struct proc_dir_entry *pde = PDE(file_inode(iocb->ki_filp));
+       ssize_t ret;
+
+       if (pde_is_permanent(pde))
+               return pde->proc_ops->proc_read_iter(iocb, iter);
+
+       if (!use_pde(pde))
+               return -EIO;
+       ret = pde->proc_ops->proc_read_iter(iocb, iter);
+       unuse_pde(pde);
+       return ret;
+}
+
 static ssize_t pde_read(struct proc_dir_entry *pde, struct file *file, char __user *buf, size_t count, loff_t *ppos)
 {
        typeof_member(struct proc_ops, proc_read) read;
@@ -578,6 +593,18 @@ static const struct file_operations proc_reg_file_ops = {
        .release        = proc_reg_release,
 };
 
+static const struct file_operations proc_iter_file_ops = {
+       .llseek         = proc_reg_llseek,
+       .read_iter      = proc_reg_read_iter,
+       .write          = proc_reg_write,
+       .poll           = proc_reg_poll,
+       .unlocked_ioctl = proc_reg_unlocked_ioctl,
+       .mmap           = proc_reg_mmap,
+       .get_unmapped_area = proc_reg_get_unmapped_area,
+       .open           = proc_reg_open,
+       .release        = proc_reg_release,
+};
+
 #ifdef CONFIG_COMPAT
 static const struct file_operations proc_reg_file_ops_compat = {
        .llseek         = proc_reg_llseek,
@@ -591,6 +618,19 @@ static const struct file_operations proc_reg_file_ops_compat = {
        .open           = proc_reg_open,
        .release        = proc_reg_release,
 };
+
+static const struct file_operations proc_iter_file_ops_compat = {
+       .llseek         = proc_reg_llseek,
+       .read_iter      = proc_reg_read_iter,
+       .write          = proc_reg_write,
+       .poll           = proc_reg_poll,
+       .unlocked_ioctl = proc_reg_unlocked_ioctl,
+       .compat_ioctl   = proc_reg_compat_ioctl,
+       .mmap           = proc_reg_mmap,
+       .get_unmapped_area = proc_reg_get_unmapped_area,
+       .open           = proc_reg_open,
+       .release        = proc_reg_release,
+};
 #endif
 
 static void proc_put_link(void *p)
@@ -642,10 +682,17 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
 
        if (S_ISREG(inode->i_mode)) {
                inode->i_op = de->proc_iops;
-               inode->i_fop = &proc_reg_file_ops;
+               if (de->proc_ops->proc_read_iter)
+                       inode->i_fop = &proc_iter_file_ops;
+               else
+                       inode->i_fop = &proc_reg_file_ops;
 #ifdef CONFIG_COMPAT
-               if (de->proc_ops->proc_compat_ioctl)
-                       inode->i_fop = &proc_reg_file_ops_compat;
+               if (de->proc_ops->proc_compat_ioctl) {
+                       if (de->proc_ops->proc_read_iter)
+                               inode->i_fop = &proc_iter_file_ops_compat;
+                       else
+                               inode->i_fop = &proc_reg_file_ops_compat;
+               }
 #endif
        } else if (S_ISDIR(inode->i_mode)) {
                inode->i_op = de->proc_iops;
index 2df965cd09742da05b5f3ee7613ce32199391b14..270cab43ca3dadc92db669c403558d321630faeb 100644 (file)
@@ -30,6 +30,7 @@ struct proc_ops {
        unsigned int proc_flags;
        int     (*proc_open)(struct inode *, struct file *);
        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_write)(struct file *, const char __user *, size_t, loff_t *);
        loff_t  (*proc_lseek)(struct file *, loff_t, int);
        int     (*proc_release)(struct inode *, struct file *);