[PATCH 286/437] ubifs: convert to read/write iterators

From: Jens Axboe
Date: Thu Apr 11 2024 - 12:46:59 EST


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
fs/ubifs/debug.c | 59 ++++++++++++++++++++++--------------------------
1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 2d63f57aca6f..52f93ea1ac7f 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -2677,17 +2677,15 @@ static int dfs_file_open(struct inode *inode, struct file *file)
/**
* provide_user_output - provide output to the user reading a debugfs file.
* @val: boolean value for the answer
- * @u: the buffer to store the answer at
- * @count: size of the buffer
- * @ppos: position in the @u output buffer
+ * @iocb: metadata for IO
+ * @to: the buffer to store the answer at
*
* This is a simple helper function which stores @val boolean value in the user
* buffer when the user reads one of UBIFS debugfs files. Returns amount of
* bytes written to @u in case of success and a negative error code in case of
* failure.
*/
-static int provide_user_output(int val, char __user *u, size_t count,
- loff_t *ppos)
+static int provide_user_output(int val, struct kiocb *iocb, struct iov_iter *to)
{
char buf[3];

@@ -2698,14 +2696,13 @@ static int provide_user_output(int val, char __user *u, size_t count,
buf[1] = '\n';
buf[2] = 0x00;

- return simple_read_from_buffer(u, count, ppos, buf, 2);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, 2, to);
}

-static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
- loff_t *ppos)
+static ssize_t dfs_file_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct dentry *dent = file->f_path.dentry;
- struct ubifs_info *c = file->private_data;
+ struct dentry *dent = iocb->ki_filp->f_path.dentry;
+ struct ubifs_info *c = iocb->ki_filp->private_data;
struct ubifs_debug_info *d = c->dbg;
int val;

@@ -2726,26 +2723,25 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
else
return -EINVAL;

- return provide_user_output(val, u, count, ppos);
+ return provide_user_output(val, iocb, to);
}
-FOPS_READ_ITER_HELPER(dfs_file_read);

/**
* interpret_user_input - interpret user debugfs file input.
- * @u: user-provided buffer with the input
- * @count: buffer size
+ * @from: user-provided buffer with the input
*
* This is a helper function which interpret user input to a boolean UBIFS
* debugfs file. Returns %0 or %1 in case of success and a negative error code
* in case of failure.
*/
-static int interpret_user_input(const char __user *u, size_t count)
+static int interpret_user_input(struct iov_iter *from)
{
+ size_t count = iov_iter_count(from);
size_t buf_size;
char buf[8];

buf_size = min_t(size_t, count, (sizeof(buf) - 1));
- if (copy_from_user(buf, u, buf_size))
+ if (!copy_from_iter_full(buf, buf_size, from))
return -EFAULT;

if (buf[0] == '1')
@@ -2756,12 +2752,13 @@ static int interpret_user_input(const char __user *u, size_t count)
return -EINVAL;
}

-static ssize_t dfs_file_write(struct file *file, const char __user *u,
- size_t count, loff_t *ppos)
+static ssize_t dfs_file_write(struct kiocb *iocb, struct iov_iter *from)
{
+ struct file *file = iocb->ki_filp;
struct ubifs_info *c = file->private_data;
struct ubifs_debug_info *d = c->dbg;
struct dentry *dent = file->f_path.dentry;
+ size_t count = iov_iter_count(from);
int val;

if (file->f_path.dentry == d->dfs_dump_lprops) {
@@ -2779,7 +2776,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u,
return count;
}

- val = interpret_user_input(u, count);
+ val = interpret_user_input(from);
if (val < 0)
return val;

@@ -2802,12 +2799,11 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u,

return count;
}
-FOPS_WRITE_ITER_HELPER(dfs_file_write);

static const struct file_operations dfs_fops = {
.open = dfs_file_open,
- .read_iter = dfs_file_read_iter,
- .write_iter = dfs_file_write_iter,
+ .read_iter = dfs_file_read,
+ .write_iter = dfs_file_write,
.owner = THIS_MODULE,
.llseek = no_llseek,
};
@@ -2898,10 +2894,9 @@ static struct dentry *dfs_chk_lprops;
static struct dentry *dfs_chk_fs;
static struct dentry *dfs_tst_rcvry;

-static ssize_t dfs_global_file_read(struct file *file, char __user *u,
- size_t count, loff_t *ppos)
+static ssize_t dfs_global_file_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct dentry *dent = file->f_path.dentry;
+ struct dentry *dent = iocb->ki_filp->f_path.dentry;
int val;

if (dent == dfs_chk_gen)
@@ -2919,16 +2914,16 @@ static ssize_t dfs_global_file_read(struct file *file, char __user *u,
else
return -EINVAL;

- return provide_user_output(val, u, count, ppos);
+ return provide_user_output(val, iocb, to);
}

-static ssize_t dfs_global_file_write(struct file *file, const char __user *u,
- size_t count, loff_t *ppos)
+static ssize_t dfs_global_file_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct dentry *dent = file->f_path.dentry;
+ struct dentry *dent = iocb->ki_filp->f_path.dentry;
+ size_t count = iov_iter_count(from);
int val;

- val = interpret_user_input(u, count);
+ val = interpret_user_input(from);
if (val < 0)
return val;

@@ -2951,8 +2946,8 @@ static ssize_t dfs_global_file_write(struct file *file, const char __user *u,
}

static const struct file_operations dfs_global_fops = {
- .read = dfs_global_file_read,
- .write = dfs_global_file_write,
+ .read_iter = dfs_global_file_read,
+ .write_iter = dfs_global_file_write,
.owner = THIS_MODULE,
.llseek = no_llseek,
};
--
2.43.0