[PATCH 289/437] fs/bcachefs: convert to read/write iterators

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


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
fs/bcachefs/chardev.c | 10 +++++-----
fs/bcachefs/debug.c | 24 ++++++++++++++++--------
fs/bcachefs/thread_with_file.c | 14 ++++++++------
3 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c
index cbfa6459bdbc..9f27c3f4b960 100644
--- a/fs/bcachefs/chardev.c
+++ b/fs/bcachefs/chardev.c
@@ -438,10 +438,9 @@ static int bch2_data_job_release(struct inode *inode, struct file *file)
return 0;
}

-static ssize_t bch2_data_job_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
+static ssize_t bch2_data_job_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct bch_data_ctx *ctx = container_of(file->private_data, struct bch_data_ctx, thr);
+ struct bch_data_ctx *ctx = container_of(iocb->ki_filp->private_data, struct bch_data_ctx, thr);
struct bch_fs *c = ctx->c;
struct bch_ioctl_data_event e = {
.type = BCH_DATA_EVENT_PROGRESS,
@@ -451,16 +450,17 @@ static ssize_t bch2_data_job_read(struct file *file, char __user *buf,
.p.sectors_done = atomic64_read(&ctx->stats.sectors_seen),
.p.sectors_total = bch2_fs_usage_read_short(c).used,
};
+ size_t len = iov_iter_count(to);

if (len < sizeof(e))
return -EINVAL;

- return copy_to_user_errcode(buf, &e, sizeof(e)) ?: sizeof(e);
+ return copy_to_iter(&e, sizeof(e), to);
}

static const struct file_operations bcachefs_data_ops = {
.release = bch2_data_job_release,
- .read = bch2_data_job_read,
+ .read_iter = bch2_data_job_read,
.llseek = no_llseek,
};

diff --git a/fs/bcachefs/debug.c b/fs/bcachefs/debug.c
index 208ce6f0fc43..9b5c7aa57fda 100644
--- a/fs/bcachefs/debug.c
+++ b/fs/bcachefs/debug.c
@@ -384,12 +384,13 @@ static ssize_t bch2_read_btree(struct file *file, char __user *buf,
}))) ?:
i->ret;
}
+FOPS_READ_ITER_HELPER(bch2_read_btree);

static const struct file_operations btree_debug_ops = {
.owner = THIS_MODULE,
.open = bch2_dump_open,
.release = bch2_dump_release,
- .read = bch2_read_btree,
+ .read_iter = bch2_read_btree_iter,
};

static ssize_t bch2_read_btree_formats(struct file *file, char __user *buf,
@@ -438,12 +439,13 @@ static ssize_t bch2_read_btree_formats(struct file *file, char __user *buf,

return ret ?: i->ret;
}
+FOPS_READ_ITER_HELPER(bch2_read_btree_formats);

static const struct file_operations btree_format_debug_ops = {
.owner = THIS_MODULE,
.open = bch2_dump_open,
.release = bch2_dump_release,
- .read = bch2_read_btree_formats,
+ .read_iter = bch2_read_btree_formats_iter,
};

static ssize_t bch2_read_bfloat_failed(struct file *file, char __user *buf,
@@ -477,12 +479,13 @@ static ssize_t bch2_read_bfloat_failed(struct file *file, char __user *buf,
}))) ?:
i->ret;
}
+FOPS_READ_ITER_HELPER(bch2_read_bfloat_failed);

static const struct file_operations bfloat_failed_debug_ops = {
.owner = THIS_MODULE,
.open = bch2_dump_open,
.release = bch2_dump_release,
- .read = bch2_read_bfloat_failed,
+ .read_iter = bch2_read_bfloat_failed_iter,
};

static void bch2_cached_btree_node_to_text(struct printbuf *out, struct bch_fs *c,
@@ -584,12 +587,13 @@ static ssize_t bch2_cached_btree_nodes_read(struct file *file, char __user *buf,

return ret ?: i->ret;
}
+FOPS_READ_ITER_HELPER(bch2_cached_btree_nodes_read);

static const struct file_operations cached_btree_nodes_ops = {
.owner = THIS_MODULE,
.open = bch2_dump_open,
.release = bch2_dump_release,
- .read = bch2_cached_btree_nodes_read,
+ .read_iter = bch2_cached_btree_nodes_read_iter,
};

static ssize_t bch2_btree_transactions_read(struct file *file, char __user *buf,
@@ -648,12 +652,13 @@ static ssize_t bch2_btree_transactions_read(struct file *file, char __user *buf,

return ret ?: i->ret;
}
+FOPS_READ_ITER_HELPER(bch2_btree_transactions_read);

static const struct file_operations btree_transactions_ops = {
.owner = THIS_MODULE,
.open = bch2_dump_open,
.release = bch2_dump_release,
- .read = bch2_btree_transactions_read,
+ .read_iter = bch2_btree_transactions_read_iter,
};

static ssize_t bch2_journal_pins_read(struct file *file, char __user *buf,
@@ -685,12 +690,13 @@ static ssize_t bch2_journal_pins_read(struct file *file, char __user *buf,

return i->ret;
}
+FOPS_READ_ITER_HELPER(bch2_journal_pins_read);

static const struct file_operations journal_pins_ops = {
.owner = THIS_MODULE,
.open = bch2_dump_open,
.release = bch2_dump_release,
- .read = bch2_journal_pins_read,
+ .read_iter = bch2_journal_pins_read_iter,
};

static int btree_transaction_stats_open(struct inode *inode, struct file *file)
@@ -792,12 +798,13 @@ static ssize_t btree_transaction_stats_read(struct file *file, char __user *buf,

return i->ret;
}
+FOPS_READ_ITER_HELPER(btree_transaction_stats_read);

static const struct file_operations btree_transaction_stats_op = {
.owner = THIS_MODULE,
.open = btree_transaction_stats_open,
.release = btree_transaction_stats_release,
- .read = btree_transaction_stats_read,
+ .read_iter = btree_transaction_stats_read_iter,
};

static ssize_t bch2_btree_deadlock_read(struct file *file, char __user *buf,
@@ -852,12 +859,13 @@ static ssize_t bch2_btree_deadlock_read(struct file *file, char __user *buf,

return ret ?: i->ret;
}
+FOPS_READ_ITER_HELPER(bch2_btree_deadlock_read);

static const struct file_operations btree_deadlock_ops = {
.owner = THIS_MODULE,
.open = bch2_dump_open,
.release = bch2_dump_release,
- .read = bch2_btree_deadlock_read,
+ .read_iter = bch2_btree_deadlock_read_iter,
};

void bch2_fs_debug_exit(struct bch_fs *c)
diff --git a/fs/bcachefs/thread_with_file.c b/fs/bcachefs/thread_with_file.c
index 940db15d6a93..fa6f333605da 100644
--- a/fs/bcachefs/thread_with_file.c
+++ b/fs/bcachefs/thread_with_file.c
@@ -27,11 +27,11 @@ int bch2_run_thread_with_file(struct thread_with_file *thr,
int ret, fd = -1;
unsigned fd_flags = O_CLOEXEC;

- if (fops->read && fops->write)
+ if (fops->read_iter && fops->write_iter)
fd_flags |= O_RDWR;
- else if (fops->read)
+ else if (fops->read_iter)
fd_flags |= O_RDONLY;
- else if (fops->write)
+ else if (fops->write_iter)
fd_flags |= O_WRONLY;

char name[TASK_COMM_LEN];
@@ -145,6 +145,7 @@ static ssize_t thread_with_stdio_read(struct file *file, char __user *ubuf,

return copied ?: ret;
}
+FOPS_READ_ITER_HELPER(thread_with_stdio_read);

static int thread_with_stdio_release(struct inode *inode, struct file *file)
{
@@ -211,6 +212,7 @@ static ssize_t thread_with_stdio_write(struct file *file, const char __user *ubu

return copied ?: ret;
}
+FOPS_WRITE_ITER_HELPER(thread_with_stdio_write);

static __poll_t thread_with_stdio_poll(struct file *file, struct poll_table_struct *wait)
{
@@ -267,8 +269,8 @@ static long thread_with_stdio_ioctl(struct file *file, unsigned int cmd, unsigne

static const struct file_operations thread_with_stdio_fops = {
.llseek = no_llseek,
- .read = thread_with_stdio_read,
- .write = thread_with_stdio_write,
+ .read_iter = thread_with_stdio_read_iter,
+ .write_iter = thread_with_stdio_write_iter,
.poll = thread_with_stdio_poll,
.flush = thread_with_stdio_flush,
.release = thread_with_stdio_release,
@@ -277,7 +279,7 @@ static const struct file_operations thread_with_stdio_fops = {

static const struct file_operations thread_with_stdout_fops = {
.llseek = no_llseek,
- .read = thread_with_stdio_read,
+ .read_iter = thread_with_stdio_read_iter,
.poll = thread_with_stdout_poll,
.flush = thread_with_stdio_flush,
.release = thread_with_stdio_release,
--
2.43.0