bcachefs: %pg is banished
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 5 Jan 2024 16:58:50 +0000 (11:58 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 6 Jan 2024 04:24:21 +0000 (23:24 -0500)
not portable to userspace

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/disk_groups.c
fs/bcachefs/super-io.c
fs/bcachefs/super.c
fs/bcachefs/util.h

index 1cd6ba8..06a7df5 100644 (file)
@@ -557,7 +557,7 @@ void bch2_target_to_text(struct printbuf *out, struct bch_fs *c, unsigned v)
                        : NULL;
 
                if (ca && percpu_ref_tryget(&ca->io_ref)) {
-                       prt_printf(out, "/dev/%pg", ca->disk_sb.bdev);
+                       prt_printf(out, "/dev/%s", ca->name);
                        percpu_ref_put(&ca->io_ref);
                } else if (ca) {
                        prt_printf(out, "offline device %u", t.dev);
index 427426b..042e08a 100644 (file)
@@ -170,8 +170,12 @@ int bch2_sb_realloc(struct bch_sb_handle *sb, unsigned u64s)
                u64 max_bytes = 512 << sb->sb->layout.sb_max_size_bits;
 
                if (new_bytes > max_bytes) {
-                       pr_err("%pg: superblock too big: want %zu but have %llu",
-                              sb->bdev, new_bytes, max_bytes);
+                       struct printbuf buf = PRINTBUF;
+
+                       prt_bdevname(&buf, sb->bdev);
+                       prt_printf(&buf, ": superblock too big: want %zu but have %llu", new_bytes, max_bytes);
+                       pr_err("%s", buf.buf);
+                       printbuf_exit(&buf);
                        return -BCH_ERR_ENOSPC_sb;
                }
        }
index 8479805..9dbc359 100644 (file)
@@ -1083,17 +1083,22 @@ static int bch2_dev_in_fs(struct bch_sb_handle *fs,
            fs->sb->write_time != sb->sb->write_time) {
                struct printbuf buf = PRINTBUF;
 
-               prt_printf(&buf, "Split brain detected between %pg and %pg:",
-                          sb->bdev, fs->bdev);
+               prt_str(&buf, "Split brain detected between ");
+               prt_bdevname(&buf, sb->bdev);
+               prt_str(&buf, " and ");
+               prt_bdevname(&buf, fs->bdev);
+               prt_char(&buf, ':');
                prt_newline(&buf);
                prt_printf(&buf, "seq=%llu but write_time different, got", le64_to_cpu(sb->sb->seq));
                prt_newline(&buf);
 
-               prt_printf(&buf, "%pg ", fs->bdev);
+               prt_bdevname(&buf, fs->bdev);
+               prt_char(&buf, ' ');
                bch2_prt_datetime(&buf, le64_to_cpu(fs->sb->write_time));;
                prt_newline(&buf);
 
-               prt_printf(&buf, "%pg ", sb->bdev);
+               prt_bdevname(&buf, sb->bdev);
+               prt_char(&buf, ' ');
                bch2_prt_datetime(&buf, le64_to_cpu(sb->sb->write_time));;
                prt_newline(&buf);
 
@@ -1109,13 +1114,26 @@ static int bch2_dev_in_fs(struct bch_sb_handle *fs,
        u64 seq_from_member     = le64_to_cpu(sb->sb->seq);
 
        if (seq_from_fs && seq_from_fs < seq_from_member) {
-               pr_err("Split brain detected between %pg and %pg:\n"
-                      "%pg believes seq of %pg to be %llu, but %pg has %llu\n"
-                      "Not using %pg",
-                      sb->bdev, fs->bdev,
-                      fs->bdev, sb->bdev, seq_from_fs,
-                      sb->bdev, seq_from_member,
-                      sb->bdev);
+               struct printbuf buf = PRINTBUF;
+
+               prt_str(&buf, "Split brain detected between ");
+               prt_bdevname(&buf, sb->bdev);
+               prt_str(&buf, " and ");
+               prt_bdevname(&buf, fs->bdev);
+               prt_char(&buf, ':');
+               prt_newline(&buf);
+
+               prt_bdevname(&buf, fs->bdev);
+               prt_str(&buf, "believes seq of ");
+               prt_bdevname(&buf, sb->bdev);
+               prt_printf(&buf, " to be %llu, but ", seq_from_fs);
+               prt_bdevname(&buf, sb->bdev);
+               prt_printf(&buf, " has %llu\n", seq_from_member);
+               prt_str(&buf, "Not using ");
+               prt_bdevname(&buf, sb->bdev);
+
+               pr_err("%s", buf.buf);
+               printbuf_exit(&buf);
                return -BCH_ERR_device_splitbrain;
        }
 
@@ -1364,9 +1382,14 @@ static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
 
        bch2_dev_sysfs_online(c, ca);
 
+       struct printbuf name = PRINTBUF;
+       prt_bdevname(&name, ca->disk_sb.bdev);
+
        if (c->sb.nr_devices == 1)
-               snprintf(c->name, sizeof(c->name), "%pg", ca->disk_sb.bdev);
-       snprintf(ca->name, sizeof(ca->name), "%pg", ca->disk_sb.bdev);
+               strlcpy(c->name, name.buf, sizeof(c->name));
+       strlcpy(ca->name, name.buf, sizeof(ca->name));
+
+       printbuf_exit(&name);
 
        rebalance_wakeup(c);
        return 0;
index 92acda2..c75fc31 100644 (file)
@@ -351,6 +351,15 @@ int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *, unsigned);
 void bch2_prt_backtrace(struct printbuf *, bch_stacktrace *);
 int bch2_prt_task_backtrace(struct printbuf *, struct task_struct *, unsigned);
 
+static inline void prt_bdevname(struct printbuf *out, struct block_device *bdev)
+{
+#ifdef __KERNEL__
+       prt_printf(out, "%pg", bdev);
+#else
+       prt_str(out, bdev->name);
+#endif
+}
+
 #define NR_QUANTILES   15
 #define QUANTILE_IDX(i)        inorder_to_eytzinger0(i, NR_QUANTILES)
 #define QUANTILE_FIRST eytzinger0_first(NR_QUANTILES)