]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/chardev.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / libbcachefs / chardev.c
index 226b39c176673a374f50ab06ad5f6d3e0a4858d8..992939152f01909cf5d92cb58504a83fe973fecd 100644 (file)
@@ -11,7 +11,6 @@
 #include "replicas.h"
 #include "super.h"
 #include "super-io.h"
-#include "thread_with_file.h"
 
 #include <linux/cdev.h>
 #include <linux/device.h>
@@ -20,6 +19,7 @@
 #include <linux/major.h>
 #include <linux/sched/task.h>
 #include <linux/slab.h>
+#include <linux/thread_with_file.h>
 #include <linux/uaccess.h>
 
 __must_check
@@ -155,19 +155,35 @@ static void bch2_fsck_thread_exit(struct thread_with_stdio *_thr)
        kfree(thr);
 }
 
-static int bch2_fsck_offline_thread_fn(void *arg)
+static int 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);
 
-       thr->thr.thr.ret = PTR_ERR_OR_ZERO(c);
-       if (!thr->thr.thr.ret)
-               bch2_fs_stop(c);
+       if (IS_ERR(c))
+               return PTR_ERR(c);
 
-       thread_with_stdio_done(&thr->thr);
-       return 0;
+       int ret = 0;
+       if (test_bit(BCH_FS_errors_fixed, &c->flags))
+               ret |= 1;
+       if (test_bit(BCH_FS_error, &c->flags))
+               ret |= 4;
+
+       bch2_fs_stop(c);
+
+       if (ret & 1)
+               stdio_redirect_printf(&stdio->stdio, false, "%s: errors fixed\n", c->name);
+       if (ret & 4)
+               stdio_redirect_printf(&stdio->stdio, false, "%s: still has errors\n", c->name);
+
+       return ret;
 }
 
+static const struct thread_with_stdio_ops bch2_offline_fsck_ops = {
+       .exit           = bch2_fsck_thread_exit,
+       .fn             = bch2_fsck_offline_thread_fn,
+};
+
 static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg)
 {
        struct bch_ioctl_fsck_offline arg;
@@ -220,9 +236,7 @@ static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_a
 
        opt_set(thr->opts, stdio, (u64)(unsigned long)&thr->thr.stdio);
 
-       ret = bch2_run_thread_with_stdio(&thr->thr,
-                       bch2_fsck_thread_exit,
-                       bch2_fsck_offline_thread_fn);
+       ret = run_thread_with_stdio(&thr->thr, &bch2_offline_fsck_ops);
 err:
        if (ret < 0) {
                if (thr)
@@ -425,7 +439,7 @@ static int bch2_data_job_release(struct inode *inode, struct file *file)
 {
        struct bch_data_ctx *ctx = container_of(file->private_data, struct bch_data_ctx, thr);
 
-       bch2_thread_with_file_exit(&ctx->thr);
+       thread_with_file_exit(&ctx->thr);
        kfree(ctx);
        return 0;
 }
@@ -475,7 +489,7 @@ static long bch2_ioctl_data(struct bch_fs *c,
        ctx->c = c;
        ctx->arg = arg;
 
-       ret = bch2_run_thread_with_file(&ctx->thr,
+       ret = run_thread_with_file(&ctx->thr,
                        &bcachefs_data_ops,
                        bch2_data_thread);
        if (ret < 0)
@@ -763,9 +777,9 @@ static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
        return ret;
 }
 
-static int bch2_fsck_online_thread_fn(void *arg)
+static int 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;
 
        c->stdio_filter = current;
@@ -793,13 +807,16 @@ static int bch2_fsck_online_thread_fn(void *arg)
        c->stdio_filter = NULL;
        c->opts.fix_errors = old_fix_errors;
 
-       thread_with_stdio_done(&thr->thr);
-
        up(&c->online_fsck_mutex);
        bch2_ro_ref_put(c);
-       return 0;
+       return ret;
 }
 
+static const struct thread_with_stdio_ops bch2_online_fsck_ops = {
+       .exit           = bch2_fsck_thread_exit,
+       .fn             = bch2_fsck_online_thread_fn,
+};
+
 static long bch2_ioctl_fsck_online(struct bch_fs *c,
                                   struct bch_ioctl_fsck_online arg)
 {
@@ -840,9 +857,7 @@ static long bch2_ioctl_fsck_online(struct bch_fs *c,
                        goto err;
        }
 
-       ret = bch2_run_thread_with_stdio(&thr->thr,
-                       bch2_fsck_thread_exit,
-                       bch2_fsck_online_thread_fn);
+       ret = run_thread_with_stdio(&thr->thr, &bch2_online_fsck_ops);
 err:
        if (ret < 0) {
                bch_err_fn(c, ret);