Re: [PATCH 5/6] bcachefs: BCH_IOCTL_FSCK_OFFLINE

Kent Overstreet
2023-12-08T20:34:04Z

On Fri, Dec 08, 2023 at 03:26:53PM -0500, Brian Foster wrote:
> On Wed, Dec 06, 2023 at 03:33:09PM -0500, Kent Overstreet wrote:
> > This adds a new ioctl for running fsck on a list of devices.
> >
> > Normally, if we wish to use the kernel's implementation of fsck we'd run
> > it at mount time with -o fsck. This ioctl lets us run fsck without
> > mounting, so that userspace bcachefs-tools can transparently switch to
> > the kernel's implementation of fsck when appropriate - primarily if the
> > kernel version of bcachefs better matches the filesystem on disk.
> >
> > Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> > ---
> > fs/bcachefs/bcachefs_ioctl.h | 13 +++
> > fs/bcachefs/chardev.c | 206 ++++++++++++++++++++++++++++++++++-
> > fs/bcachefs/recovery.c | 6 +-
> > 3 files changed, 219 insertions(+), 6 deletions(-)
> >
> ...
> > diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c
> > index 8e3ac2d32298..03082a001036 100644
> > --- a/fs/bcachefs/chardev.c
> > +++ b/fs/bcachefs/chardev.c
> ...
> > @@ -193,8 +196,196 @@ static long bch2_ioctl_incremental(struct bch_ioctl_incremental __user *user_arg
> > }
> > #endif
> >
> ...
> > +
> > +static const struct file_operations fsck_thread_ops = {
> > + .release = bch2_fsck_thread_release,
> > + .read = bch2_fsck_thread_read,
> > + .llseek = no_llseek,
> > +};
> > +
> > +static int bch2_fsck_offline_thread_fn(void *arg)
> > +{
> > + struct fsck_thread *thr = container_of(arg, struct fsck_thread, thr);
> > + struct bch_fs *c = bch2_fs_open(thr->devs, thr->nr_devs, thr->opts);
> > +
> > + thr->thr.ret = PTR_ERR_OR_ZERO(c);
> > + if (!thr->thr.ret)
> > + bch2_fs_stop(c);
> > +
>
> Looks pretty neat. Mainly just curious if I'm following this right...
> Basically it looks like we wire up the log output redirect to c->output
> via options, then start/stop the fs which runs "mount time" fsck (?),
> but feeding the message output to the redirect (and then fed to
> userspace via the fd/read handler just above). Hm?

Yup, just that. I still need to wire up input so that the ask_yn()
responses can get passed in, but I'm going to leave that later since I'm
focusing more on online fsck now.