Commit b63570f7 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_print_opts()

Make sure early error messages get redirected, for
kernel-fsck-from-userland.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 130d229f
...@@ -265,6 +265,9 @@ do { \ ...@@ -265,6 +265,9 @@ do { \
#define bch2_fmt(_c, fmt) bch2_log_msg(_c, fmt "\n") #define bch2_fmt(_c, fmt) bch2_log_msg(_c, fmt "\n")
__printf(2, 3)
void bch2_print_opts(struct bch_opts *, const char *, ...);
__printf(2, 3) __printf(2, 3)
void __bch2_print(struct bch_fs *c, const char *fmt, ...); void __bch2_print(struct bch_fs *c, const char *fmt, ...);
......
...@@ -717,6 +717,7 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts, ...@@ -717,6 +717,7 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts,
if (IS_ERR(sb->bdev_handle)) { if (IS_ERR(sb->bdev_handle)) {
ret = PTR_ERR(sb->bdev_handle); ret = PTR_ERR(sb->bdev_handle);
prt_printf(&err, "error opening %s: %s", path, bch2_err_str(ret));
goto err; goto err;
} }
sb->bdev = sb->bdev_handle->bdev; sb->bdev = sb->bdev_handle->bdev;
...@@ -743,9 +744,9 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts, ...@@ -743,9 +744,9 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts,
prt_printf(&err2, "bcachefs (%s): error reading default superblock: %s\n", prt_printf(&err2, "bcachefs (%s): error reading default superblock: %s\n",
path, err.buf); path, err.buf);
if (ret == -BCH_ERR_invalid_sb_magic && ignore_notbchfs_msg) if (ret == -BCH_ERR_invalid_sb_magic && ignore_notbchfs_msg)
printk(KERN_INFO "%s", err2.buf); bch2_print_opts(opts, KERN_INFO "%s", err2.buf);
else else
printk(KERN_ERR "%s", err2.buf); bch2_print_opts(opts, KERN_ERR "%s", err2.buf);
printbuf_exit(&err2); printbuf_exit(&err2);
printbuf_reset(&err); printbuf_reset(&err);
...@@ -808,16 +809,16 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts, ...@@ -808,16 +809,16 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts,
ret = bch2_sb_validate(sb, &err, READ); ret = bch2_sb_validate(sb, &err, READ);
if (ret) { if (ret) {
printk(KERN_ERR "bcachefs (%s): error validating superblock: %s\n", bch2_print_opts(opts, KERN_ERR "bcachefs (%s): error validating superblock: %s\n",
path, err.buf); path, err.buf);
goto err_no_print; goto err_no_print;
} }
out: out:
printbuf_exit(&err); printbuf_exit(&err);
return ret; return ret;
err: err:
printk(KERN_ERR "bcachefs (%s): error reading superblock: %s\n", bch2_print_opts(opts, KERN_ERR "bcachefs (%s): error reading superblock: %s\n",
path, err.buf); path, err.buf);
err_no_print: err_no_print:
bch2_free_super(sb); bch2_free_super(sb);
goto out; goto out;
......
...@@ -87,6 +87,23 @@ const char * const bch2_fs_flag_strs[] = { ...@@ -87,6 +87,23 @@ const char * const bch2_fs_flag_strs[] = {
NULL NULL
}; };
void bch2_print_opts(struct bch_opts *opts, const char *fmt, ...)
{
struct stdio_redirect *stdio = (void *)(unsigned long)opts->stdio;
va_list args;
va_start(args, fmt);
if (likely(!stdio)) {
vprintk(fmt, args);
} else {
if (fmt[0] == KERN_SOH[0])
fmt += 2;
bch2_stdio_redirect_vprintf(stdio, true, fmt, args);
}
va_end(args);
}
void __bch2_print(struct bch_fs *c, const char *fmt, ...) void __bch2_print(struct bch_fs *c, const char *fmt, ...)
{ {
struct stdio_redirect *stdio = bch2_fs_stdio_redirect(c); struct stdio_redirect *stdio = bch2_fs_stdio_redirect(c);
......
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