Add a flush op, to return the exit code via close().
Also update bcachefs usage to use this to return fsck exit codes.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
kfree(thr);
}
-static void bch2_fsck_offline_thread_fn(struct thread_with_stdio *stdio)
+static int bch2_fsck_offline_thread_fn(struct thread_with_stdio *stdio)
{
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);
+
+ 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)
+ bch2_stdio_redirect_printf(&stdio->stdio, false, "%s: errors fixed\n", c->name);
+ if (ret & 4)
+ bch2_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 = {
return ret;
}
-static void bch2_fsck_online_thread_fn(struct thread_with_stdio *stdio)
+static int bch2_fsck_online_thread_fn(struct thread_with_stdio *stdio)
{
struct fsck_thread *thr = container_of(stdio, struct fsck_thread, thr);
struct bch_fs *c = thr->c;
up(&c->online_fsck_mutex);
bch2_ro_ref_put(c);
+ return ret;
}
static const struct thread_with_stdio_ops bch2_online_fsck_ops = {
return mask;
}
+static int thread_with_stdio_flush(struct file *file, fl_owner_t id)
+{
+ struct thread_with_stdio *thr =
+ container_of(file->private_data, struct thread_with_stdio, thr);
+
+ return thr->thr.ret;
+}
+
static long thread_with_stdio_ioctl(struct file *file, unsigned int cmd, unsigned long p)
{
struct thread_with_stdio *thr =
.read = thread_with_stdio_read,
.write = thread_with_stdio_write,
.poll = thread_with_stdio_poll,
+ .flush = thread_with_stdio_flush,
.release = thread_with_stdio_release,
.unlocked_ioctl = thread_with_stdio_ioctl,
};
.llseek = no_llseek,
.read = thread_with_stdio_read,
.poll = thread_with_stdout_poll,
+ .flush = thread_with_stdio_flush,
.release = thread_with_stdio_release,
.unlocked_ioctl = thread_with_stdio_ioctl,
};
{
struct thread_with_stdio *thr = arg;
- thr->ops->fn(thr);
+ thr->thr.ret = thr->ops->fn(thr);
thread_with_stdio_done(thr);
return 0;
struct thread_with_stdio_ops {
void (*exit)(struct thread_with_stdio *);
- void (*fn)(struct thread_with_stdio *);
+ int (*fn)(struct thread_with_stdio *);
long (*unlocked_ioctl)(struct thread_with_stdio *, unsigned int, unsigned long);
};