diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-05-30 15:43:02 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2025-04-29 13:44:31 -0400 |
commit | c4f45faf076dc774c1f4d0b7b9035872829dcd82 (patch) | |
tree | 486e0469026e2e8f009c457dc70f04e0f6ac96d3 | |
parent | e564cb029119a44f442f66d360dca578563c5b5a (diff) |
bcachefs: twf: Switch to create_io_thread()
create_io_thread() is more appropriate than kthread_create() when
spinning up a thread to do work asynchronously on behalf of some
specific userspace task.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/chardev.c | 3 | ||||
-rw-r--r-- | fs/bcachefs/thread_with_file.c | 29 | ||||
-rw-r--r-- | fs/bcachefs/thread_with_file.h | 3 |
3 files changed, 22 insertions, 13 deletions
diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c index 4066946b26bc..611df41e8182 100644 --- a/fs/bcachefs/chardev.c +++ b/fs/bcachefs/chardev.c @@ -308,7 +308,7 @@ struct bch_data_ctx { struct bch_move_stats stats; }; -static int bch2_data_thread(void *arg) +static void bch2_data_thread(void *arg) { struct bch_data_ctx *ctx = container_of(arg, struct bch_data_ctx, thr); @@ -319,7 +319,6 @@ static int bch2_data_thread(void *arg) ctx->stats.ret = BCH_IOCTL_DATA_EVENT_RET_done; ctx->stats.data_type = (int) DATA_PROGRESS_DATA_TYPE_done; } - return 0; } static int bch2_data_job_release(struct inode *inode, struct file *file) diff --git a/fs/bcachefs/thread_with_file.c b/fs/bcachefs/thread_with_file.c index dea73bc1cb51..3da48b7ed929 100644 --- a/fs/bcachefs/thread_with_file.c +++ b/fs/bcachefs/thread_with_file.c @@ -13,15 +13,21 @@ void bch2_thread_with_file_exit(struct thread_with_file *thr) { - if (thr->task) { - kthread_stop(thr->task); + if (thr->task) put_task_struct(thr->task); - } +} + +static int thr_with_file_fn(void *p) +{ + struct thread_with_file *thr = p; + + thr->fn(thr); + do_exit(0); } int bch2_run_thread_with_file(struct thread_with_file *thr, const struct file_operations *fops, - int (*fn)(void *)) + void (*fn)(void *)) { struct file *file = NULL; int ret, fd = -1; @@ -38,11 +44,15 @@ int bch2_run_thread_with_file(struct thread_with_file *thr, get_task_comm(name, current); thr->ret = 0; - thr->task = kthread_create(fn, thr, "%s", name); + thr->fn = fn; + thr->task = create_io_thread(thr_with_file_fn, thr, NUMA_NO_NODE); ret = PTR_ERR_OR_ZERO(thr->task); if (ret) return ret; + set_task_comm(thr->task, name); + set_cpus_allowed_ptr(thr->task, cpu_possible_mask); + ret = get_unused_fd_flags(fd_flags); if (ret < 0) goto err; @@ -54,14 +64,15 @@ int bch2_run_thread_with_file(struct thread_with_file *thr, goto err; get_task_struct(thr->task); - wake_up_process(thr->task); + wake_up_new_task(thr->task); fd_install(fd, file); + return fd; err: if (fd >= 0) put_unused_fd(fd); if (thr->task) - kthread_stop(thr->task); + put_task_struct(thr->task); return ret; } @@ -291,14 +302,12 @@ static const struct file_operations thread_with_stdout_fops = { .unlocked_ioctl = thread_with_stdio_ioctl, }; -static int thread_with_stdio_fn(void *arg) +static void thread_with_stdio_fn(void *arg) { struct thread_with_stdio *thr = arg; thr->thr.ret = thr->ops->fn(thr); - thread_with_stdio_done(thr); - return 0; } void bch2_thread_with_stdio_init(struct thread_with_stdio *thr, diff --git a/fs/bcachefs/thread_with_file.h b/fs/bcachefs/thread_with_file.h index 72497b921911..d1aacc894ef9 100644 --- a/fs/bcachefs/thread_with_file.h +++ b/fs/bcachefs/thread_with_file.h @@ -40,6 +40,7 @@ struct task_struct; struct thread_with_file { struct task_struct *task; + void (*fn)(void *); int ret; bool done; }; @@ -47,7 +48,7 @@ struct thread_with_file { void bch2_thread_with_file_exit(struct thread_with_file *); int bch2_run_thread_with_file(struct thread_with_file *, const struct file_operations *, - int (*fn)(void *)); + void (*fn)(void *)); struct thread_with_stdio; |