Commit a6777ca4 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: thread_with_stdio: kill thread_with_stdio_done()

Move the cleanup code to a wrapper function, where we can call it after
the thread_with_stdio fn exits.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 60e1baa8
...@@ -155,17 +155,14 @@ static void bch2_fsck_thread_exit(struct thread_with_stdio *_thr) ...@@ -155,17 +155,14 @@ static void bch2_fsck_thread_exit(struct thread_with_stdio *_thr)
kfree(thr); kfree(thr);
} }
static int bch2_fsck_offline_thread_fn(void *arg) static void bch2_fsck_offline_thread_fn(struct thread_with_stdio *stdio)
{ {
struct fsck_thread *thr = container_of(arg, struct fsck_thread, thr); struct fsck_thread *thr = container_of(stdio, struct fsck_thread, thr);
struct bch_fs *c = bch2_fs_open(thr->devs, thr->nr_devs, thr->opts); struct bch_fs *c = bch2_fs_open(thr->devs, thr->nr_devs, thr->opts);
thr->thr.thr.ret = PTR_ERR_OR_ZERO(c); thr->thr.thr.ret = PTR_ERR_OR_ZERO(c);
if (!thr->thr.thr.ret) if (!thr->thr.thr.ret)
bch2_fs_stop(c); bch2_fs_stop(c);
thread_with_stdio_done(&thr->thr);
return 0;
} }
static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg) static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg)
...@@ -763,9 +760,9 @@ static long bch2_ioctl_disk_resize_journal(struct bch_fs *c, ...@@ -763,9 +760,9 @@ static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
return ret; return ret;
} }
static int bch2_fsck_online_thread_fn(void *arg) static void bch2_fsck_online_thread_fn(struct thread_with_stdio *stdio)
{ {
struct fsck_thread *thr = container_of(arg, struct fsck_thread, thr); struct fsck_thread *thr = container_of(stdio, struct fsck_thread, thr);
struct bch_fs *c = thr->c; struct bch_fs *c = thr->c;
c->stdio_filter = current; c->stdio_filter = current;
...@@ -793,11 +790,8 @@ static int bch2_fsck_online_thread_fn(void *arg) ...@@ -793,11 +790,8 @@ static int bch2_fsck_online_thread_fn(void *arg)
c->stdio_filter = NULL; c->stdio_filter = NULL;
c->opts.fix_errors = old_fix_errors; c->opts.fix_errors = old_fix_errors;
thread_with_stdio_done(&thr->thr);
up(&c->online_fsck_mutex); up(&c->online_fsck_mutex);
bch2_ro_ref_put(c); bch2_ro_ref_put(c);
return 0;
} }
static long bch2_ioctl_fsck_online(struct bch_fs *c, static long bch2_ioctl_fsck_online(struct bch_fs *c,
......
...@@ -228,15 +228,29 @@ static const struct file_operations thread_with_stdio_fops = { ...@@ -228,15 +228,29 @@ static const struct file_operations thread_with_stdio_fops = {
.release = thread_with_stdio_release, .release = thread_with_stdio_release,
}; };
static int thread_with_stdio_fn(void *arg)
{
struct thread_with_stdio *thr = arg;
thr->fn(thr);
thr->thr.done = true;
thr->stdio.done = true;
wake_up(&thr->stdio.input.wait);
wake_up(&thr->stdio.output.wait);
return 0;
}
int bch2_run_thread_with_stdio(struct thread_with_stdio *thr, int bch2_run_thread_with_stdio(struct thread_with_stdio *thr,
void (*exit)(struct thread_with_stdio *), void (*exit)(struct thread_with_stdio *),
int (*fn)(void *)) void (*fn)(struct thread_with_stdio *))
{ {
stdio_buf_init(&thr->stdio.input); stdio_buf_init(&thr->stdio.input);
stdio_buf_init(&thr->stdio.output); stdio_buf_init(&thr->stdio.output);
thr->exit = exit; thr->exit = exit;
thr->fn = fn;
return bch2_run_thread_with_file(&thr->thr, &thread_with_stdio_fops, fn); return bch2_run_thread_with_file(&thr->thr, &thread_with_stdio_fops, thread_with_stdio_fn);
} }
int bch2_stdio_redirect_read(struct stdio_redirect *stdio, char *ubuf, size_t len) int bch2_stdio_redirect_read(struct stdio_redirect *stdio, char *ubuf, size_t len)
......
...@@ -21,19 +21,12 @@ struct thread_with_stdio { ...@@ -21,19 +21,12 @@ struct thread_with_stdio {
struct thread_with_file thr; struct thread_with_file thr;
struct stdio_redirect stdio; struct stdio_redirect stdio;
void (*exit)(struct thread_with_stdio *); void (*exit)(struct thread_with_stdio *);
void (*fn)(struct thread_with_stdio *);
}; };
static inline void thread_with_stdio_done(struct thread_with_stdio *thr)
{
thr->thr.done = true;
thr->stdio.done = true;
wake_up(&thr->stdio.input.wait);
wake_up(&thr->stdio.output.wait);
}
int bch2_run_thread_with_stdio(struct thread_with_stdio *, int bch2_run_thread_with_stdio(struct thread_with_stdio *,
void (*exit)(struct thread_with_stdio *), void (*exit)(struct thread_with_stdio *),
int (*fn)(void *)); void (*fn)(struct thread_with_stdio *));
int bch2_stdio_redirect_read(struct stdio_redirect *, char *, size_t); int bch2_stdio_redirect_read(struct stdio_redirect *, char *, size_t);
int bch2_stdio_redirect_readline(struct stdio_redirect *, char *, size_t); int bch2_stdio_redirect_readline(struct stdio_redirect *, char *, size_t);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment