]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/super-io.c
Merge pull request #190 from Dikay900/fs_free_space
[bcachefs-tools-debian] / libbcachefs / super-io.c
index 332d41e1c0a32082988f70ded38bd004b35444c0..136c01403c95465c23488504c0f2e92798bd10e2 100644 (file)
@@ -13,6 +13,7 @@
 #include "replicas.h"
 #include "quota.h"
 #include "sb-clean.h"
+#include "sb-errors.h"
 #include "sb-members.h"
 #include "super-io.h"
 #include "super.h"
@@ -165,6 +166,7 @@ void bch2_free_super(struct bch_sb_handle *sb)
        if (!IS_ERR_OR_NULL(sb->bdev))
                blkdev_put(sb->bdev, sb->holder);
        kfree(sb->holder);
+       kfree(sb->sb_name);
 
        kfree(sb->sb);
        memset(sb, 0, sizeof(*sb));
@@ -656,12 +658,13 @@ reread:
        return 0;
 }
 
-int bch2_read_super(const char *path, struct bch_opts *opts,
-                   struct bch_sb_handle *sb)
+static int __bch2_read_super(const char *path, struct bch_opts *opts,
+                   struct bch_sb_handle *sb, bool ignore_notbchfs_msg)
 {
        u64 offset = opt_get(*opts, sb);
        struct bch_sb_layout layout;
        struct printbuf err = PRINTBUF;
+       struct printbuf err2 = PRINTBUF;
        __le64 *i;
        int ret;
 #ifndef __KERNEL__
@@ -674,6 +677,10 @@ retry:
        if (!sb->holder)
                return -ENOMEM;
 
+       sb->sb_name = kstrdup(path, GFP_KERNEL);
+       if (!sb->sb_name)
+               return -ENOMEM;
+
 #ifndef __KERNEL__
        if (opt_get(*opts, direct_io) == false)
                sb->mode |= BLK_OPEN_BUFFERED;
@@ -720,8 +727,14 @@ retry:
        if (opt_defined(*opts, sb))
                goto err;
 
-       printk(KERN_ERR "bcachefs (%s): error reading default superblock: %s",
+       prt_printf(&err2, "bcachefs (%s): error reading default superblock: %s\n",
               path, err.buf);
+       if (ret == -BCH_ERR_invalid_sb_magic && ignore_notbchfs_msg)
+               printk(KERN_INFO "%s", err2.buf);
+       else
+               printk(KERN_ERR "%s", err2.buf);
+
+       printbuf_exit(&err2);
        printbuf_reset(&err);
 
        /*
@@ -782,7 +795,7 @@ got_super:
 
        ret = bch2_sb_validate(sb, &err, READ);
        if (ret) {
-               printk(KERN_ERR "bcachefs (%s): error validating superblock: %s",
+               printk(KERN_ERR "bcachefs (%s): error validating superblock: %s\n",
                       path, err.buf);
                goto err_no_print;
        }
@@ -790,13 +803,27 @@ out:
        printbuf_exit(&err);
        return ret;
 err:
-       printk(KERN_ERR "bcachefs (%s): error reading superblock: %s",
+       printk(KERN_ERR "bcachefs (%s): error reading superblock: %s\n",
               path, err.buf);
 err_no_print:
        bch2_free_super(sb);
        goto out;
 }
 
+int bch2_read_super(const char *path, struct bch_opts *opts,
+                   struct bch_sb_handle *sb)
+{
+       return __bch2_read_super(path, opts, sb, false);
+}
+
+/* provide a silenced version for mount.bcachefs */
+
+int bch2_read_super_silent(const char *path, struct bch_opts *opts,
+                   struct bch_sb_handle *sb)
+{
+       return __bch2_read_super(path, opts, sb, true);
+}
+
 /* write superblock: */
 
 static void write_super_endio(struct bio *bio)
@@ -805,7 +832,12 @@ static void write_super_endio(struct bio *bio)
 
        /* XXX: return errors directly */
 
-       if (bch2_dev_io_err_on(bio->bi_status, ca, "superblock write error: %s",
+       if (bch2_dev_io_err_on(bio->bi_status, ca,
+                              bio_data_dir(bio)
+                              ? BCH_MEMBER_ERROR_write
+                              : BCH_MEMBER_ERROR_read,
+                              "superblock %s error: %s",
+                              bio_data_dir(bio) ? "write" : "read",
                               bch2_blk_status_to_str(bio->bi_status)))
                ca->sb_write_error = 1;
 
@@ -884,15 +916,17 @@ int bch2_write_super(struct bch_fs *c)
 
        le64_add_cpu(&c->disk_sb.sb->seq, 1);
 
-       if (test_bit(BCH_FS_ERROR, &c->flags))
+       if (test_bit(BCH_FS_error, &c->flags))
                SET_BCH_SB_HAS_ERRORS(c->disk_sb.sb, 1);
-       if (test_bit(BCH_FS_TOPOLOGY_ERROR, &c->flags))
+       if (test_bit(BCH_FS_topology_error, &c->flags))
                SET_BCH_SB_HAS_TOPOLOGY_ERRORS(c->disk_sb.sb, 1);
 
        SET_BCH_SB_BIG_ENDIAN(c->disk_sb.sb, CPU_BIG_ENDIAN);
 
        bch2_sb_counters_from_cpu(c);
-       bch_members_cpy_v2_v1(&c->disk_sb);
+       bch2_sb_members_from_cpu(c);
+       bch2_sb_members_cpy_v2_v1(&c->disk_sb);
+       bch2_sb_errors_from_cpu(c);
 
        for_each_online_member(ca, c, i)
                bch2_sb_from_fs(c, ca);
@@ -1175,7 +1209,7 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
        prt_printf(out, "Created:");
        prt_tab(out);
        if (sb->time_base_lo)
-               pr_time(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC));
+               bch2_prt_datetime(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC));
        else
                prt_printf(out, "(not set)");
        prt_newline(out);