diff mbox series

block: convert the debugfs interface to read/write iterators

Message ID dc58cf1e-cfbc-4771-80b8-4dfdf5d7f0d1@kernel.dk (mailing list archive)
State New, archived
Headers show
Series block: convert the debugfs interface to read/write iterators | expand

Commit Message

Jens Axboe April 9, 2024, 3 p.m. UTC
Convert the block debugfs interface to use read/write iterators rather
than the older style ->read()/->write().

No intended functional changes in this patch.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

This is part of a larger series that intends to fully kill the old
read/write interface.

Comments

Bart Van Assche April 9, 2024, 9:36 p.m. UTC | #1
On 4/9/24 08:00, Jens Axboe wrote:
> Convert the block debugfs interface to use read/write iterators rather
> than the older style ->read()/->write().

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Nitesh Shetty April 10, 2024, 7:18 p.m. UTC | #2
On 09/04/24 09:00AM, Jens Axboe wrote:
>Convert the block debugfs interface to use read/write iterators rather
>than the older style ->read()/->write().
>
>No intended functional changes in this patch.
>
>Signed-off-by: Jens Axboe <axboe@kernel.dk>
>
Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
diff mbox series

Patch

diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index 94668e72ab09..a9fa3d7311ac 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -119,9 +119,10 @@  static int queue_state_show(void *data, struct seq_file *m)
 	return 0;
 }
 
-static ssize_t queue_state_write(void *data, const char __user *buf,
-				 size_t count, loff_t *ppos)
+static ssize_t queue_state_write(void *data, struct kiocb *iocb,
+				 struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	struct request_queue *q = data;
 	char opbuf[16] = { }, *op;
 
@@ -137,7 +138,7 @@  static ssize_t queue_state_write(void *data, const char __user *buf,
 		goto inval;
 	}
 
-	if (copy_from_user(opbuf, buf, count))
+	if (!copy_from_iter_full(opbuf, count, from))
 		return -EFAULT;
 	op = strstrip(opbuf);
 	if (strcmp(op, "run") == 0) {
@@ -540,12 +541,11 @@  static int blk_mq_debugfs_show(struct seq_file *m, void *v)
 	return attr->show(data, m);
 }
 
-static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf,
-				    size_t count, loff_t *ppos)
+static ssize_t blk_mq_debugfs_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *m = file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	const struct blk_mq_debugfs_attr *attr = m->private;
-	void *data = d_inode(file->f_path.dentry->d_parent)->i_private;
+	void *data = d_inode(iocb->ki_filp->f_path.dentry->d_parent)->i_private;
 
 	/*
 	 * Attributes that only implement .seq_ops are read-only and 'attr' is
@@ -554,7 +554,7 @@  static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf,
 	if (attr == data || !attr->write)
 		return -EPERM;
 
-	return attr->write(data, buf, count, ppos);
+	return attr->write(data, iocb, from);
 }
 
 static int blk_mq_debugfs_open(struct inode *inode, struct file *file)
@@ -591,8 +591,8 @@  static int blk_mq_debugfs_release(struct inode *inode, struct file *file)
 
 static const struct file_operations blk_mq_debugfs_fops = {
 	.open		= blk_mq_debugfs_open,
-	.read		= seq_read,
-	.write		= blk_mq_debugfs_write,
+	.read_iter	= seq_read_iter,
+	.write_iter	= blk_mq_debugfs_write,
 	.llseek		= seq_lseek,
 	.release	= blk_mq_debugfs_release,
 };
diff --git a/block/blk-mq-debugfs.h b/block/blk-mq-debugfs.h
index 9c7d4b6117d4..22c65e5ff430 100644
--- a/block/blk-mq-debugfs.h
+++ b/block/blk-mq-debugfs.h
@@ -12,7 +12,7 @@  struct blk_mq_debugfs_attr {
 	const char *name;
 	umode_t mode;
 	int (*show)(void *, struct seq_file *);
-	ssize_t (*write)(void *, const char __user *, size_t, loff_t *);
+	ssize_t (*write)(void *, struct kiocb *, struct iov_iter *);
 	/* Set either .show or .seq_ops. */
 	const struct seq_operations *seq_ops;
 };