bcachefs: fix bch2_val_to_text()
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 23 Jul 2018 13:13:07 +0000 (09:13 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:08 +0000 (17:08 -0400)
was returning wrong value

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
14 files changed:
fs/bcachefs/alloc.c
fs/bcachefs/alloc.h
fs/bcachefs/bkey_methods.c
fs/bcachefs/bkey_methods.h
fs/bcachefs/dirent.c
fs/bcachefs/dirent.h
fs/bcachefs/extents.c
fs/bcachefs/extents.h
fs/bcachefs/inode.c
fs/bcachefs/inode.h
fs/bcachefs/quota.c
fs/bcachefs/quota.h
fs/bcachefs/xattr.c
fs/bcachefs/xattr.h

index 19523226afd8b477f601f0797a0f0e1379e78aa1..ea1dc52e5ff6ea780ee5a610da3c13db6c865dca 100644 (file)
@@ -154,8 +154,8 @@ const char *bch2_alloc_invalid(const struct bch_fs *c, struct bkey_s_c k)
        return NULL;
 }
 
-void bch2_alloc_to_text(struct bch_fs *c, char *buf,
-                       size_t size, struct bkey_s_c k)
+int bch2_alloc_to_text(struct bch_fs *c, char *buf,
+                      size_t size, struct bkey_s_c k)
 {
        buf[0] = '\0';
 
@@ -163,6 +163,8 @@ void bch2_alloc_to_text(struct bch_fs *c, char *buf,
        case BCH_ALLOC:
                break;
        }
+
+       return 0;
 }
 
 static inline unsigned get_alloc_field(const u8 **p, unsigned bytes)
@@ -2067,6 +2069,8 @@ not_enough:
         * invalidated on disk:
         */
        if (invalidating_data) {
+               BUG();
+               pr_info("holding writes");
                pr_debug("invalidating existing data");
                set_bit(BCH_FS_HOLD_BTREE_WRITES, &c->flags);
        } else {
index 2a6500d6f97acc1616b6054a07c52f11d70a49c3..739df233236c33c8330d36ede894bd9602be16f4 100644 (file)
@@ -12,7 +12,7 @@ struct bch_devs_List;
 #define ALLOC_SCAN_BATCH(ca)           ((ca)->mi.nbuckets >> 9)
 
 const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);
-void bch2_alloc_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
+int bch2_alloc_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
 
 #define bch2_bkey_alloc_ops (struct bkey_ops) {                \
        .key_invalid    = bch2_alloc_invalid,           \
index 017425a534c6ca13e90c68e05056ecea37b4a97e..8c6c2ca3c9929cfe054173c38b5066b6645ab117 100644 (file)
@@ -123,16 +123,27 @@ void bch2_bkey_debugcheck(struct bch_fs *c, struct btree *b, struct bkey_s_c k)
 
 #define p(...) (out += scnprintf(out, end - out, __VA_ARGS__))
 
+int bch2_bpos_to_text(char *buf, size_t size, struct bpos pos)
+{
+       char *out = buf, *end = buf + size;
+
+       if (!bkey_cmp(pos, POS_MIN))
+               p("POS_MIN");
+       else if (!bkey_cmp(pos, POS_MAX))
+               p("POS_MAX");
+       else
+               p("%llu:%llu", pos.inode, pos.offset);
+
+       return out - buf;
+}
+
 int bch2_bkey_to_text(char *buf, size_t size, const struct bkey *k)
 {
        char *out = buf, *end = buf + size;
 
        p("u64s %u type %u ", k->u64s, k->type);
 
-       if (bkey_cmp(k->p, POS_MAX))
-               p("%llu:%llu", k->p.inode, k->p.offset);
-       else
-               p("POS_MAX");
+       out += bch2_bpos_to_text(out, end - out, k->p);
 
        p(" snap %u len %u ver %llu", k->p.snapshot, k->size, k->version.lo);
 
@@ -160,7 +171,7 @@ int bch2_val_to_text(struct bch_fs *c, enum bkey_type type,
                break;
        default:
                if (k.k->type >= KEY_TYPE_GENERIC_NR && ops->val_to_text)
-                       ops->val_to_text(c, buf, size, k);
+                       out += ops->val_to_text(c, out, end - out, k);
                break;
        }
 
index 04c80f3603cc00f92004ff633bc1873a0806803a..989b577da928dc5035ad9b4c17eb987a789c8969 100644 (file)
@@ -57,7 +57,7 @@ struct bkey_ops {
                                       struct bkey_s_c);
        void            (*key_debugcheck)(struct bch_fs *, struct btree *,
                                          struct bkey_s_c);
-       void            (*val_to_text)(struct bch_fs *, char *,
+       int             (*val_to_text)(struct bch_fs *, char *,
                                       size_t, struct bkey_s_c);
        void            (*swab)(const struct bkey_format *, struct bkey_packed *);
        key_filter_fn   key_normalize;
@@ -73,6 +73,7 @@ const char *bch2_bkey_in_btree_node(struct btree *, struct bkey_s_c);
 
 void bch2_bkey_debugcheck(struct bch_fs *, struct btree *, struct bkey_s_c);
 
+int bch2_bpos_to_text(char *, size_t, struct bpos);
 int bch2_bkey_to_text(char *, size_t, const struct bkey *);
 int bch2_val_to_text(struct bch_fs *, enum bkey_type,
                     char *, size_t, struct bkey_s_c);
index 18078cc2ca622975050118129bd3aefbdf5a715e..d5e174e1e59f4fc8bd98e645f928030667240bce 100644 (file)
@@ -122,24 +122,26 @@ const char *bch2_dirent_invalid(const struct bch_fs *c, struct bkey_s_c k)
        }
 }
 
-void bch2_dirent_to_text(struct bch_fs *c, char *buf,
-                        size_t size, struct bkey_s_c k)
+int bch2_dirent_to_text(struct bch_fs *c, char *buf,
+                       size_t size, struct bkey_s_c k)
 {
+       char *out = buf, *end = buf + size;
        struct bkey_s_c_dirent d;
-       size_t n = 0;
 
        switch (k.k->type) {
        case BCH_DIRENT:
                d = bkey_s_c_to_dirent(k);
 
-               n += bch_scnmemcpy(buf + n, size - n, d.v->d_name,
-                                  bch2_dirent_name_bytes(d));
-               n += scnprintf(buf + n, size - n, " -> %llu", d.v->d_inum);
+               out += bch_scnmemcpy(out, end - out, d.v->d_name,
+                                    bch2_dirent_name_bytes(d));
+               out += scnprintf(out, end - out, " -> %llu", d.v->d_inum);
                break;
        case BCH_DIRENT_WHITEOUT:
-               scnprintf(buf, size, "whiteout");
+               out += scnprintf(out, end - out, "whiteout");
                break;
        }
+
+       return out - buf;
 }
 
 static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans,
index d02dc3e10d95434d5268e329c7c5a93f77b3ebd3..ac28f83d6b2daa2c878c43012d1db62474d72403 100644 (file)
@@ -7,7 +7,7 @@
 extern const struct bch_hash_desc bch2_dirent_hash_desc;
 
 const char *bch2_dirent_invalid(const struct bch_fs *, struct bkey_s_c);
-void bch2_dirent_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
+int bch2_dirent_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
 
 #define bch2_bkey_dirent_ops (struct bkey_ops) {       \
        .key_invalid    = bch2_dirent_invalid,          \
index 2c1cf29e265ac05c5b8e35d40155dc4a7fdb85af..e0150fbe85afdbd8e3965b079595dc47fe62753b 100644 (file)
@@ -733,8 +733,8 @@ err:
                      mark.gen, (unsigned) mark.v.counter);
 }
 
-void bch2_btree_ptr_to_text(struct bch_fs *c, char *buf,
-                           size_t size, struct bkey_s_c k)
+int bch2_btree_ptr_to_text(struct bch_fs *c, char *buf,
+                          size_t size, struct bkey_s_c k)
 {
        char *out = buf, *end = buf + size;
        const char *invalid;
@@ -748,6 +748,7 @@ void bch2_btree_ptr_to_text(struct bch_fs *c, char *buf,
        if (invalid)
                p(" invalid: %s", invalid);
 #undef p
+       return out - buf;
 }
 
 int bch2_btree_pick_ptr(struct bch_fs *c, const struct btree *b,
@@ -1877,8 +1878,8 @@ void bch2_extent_debugcheck(struct bch_fs *c, struct btree *b, struct bkey_s_c k
        }
 }
 
-void bch2_extent_to_text(struct bch_fs *c, char *buf,
-                        size_t size, struct bkey_s_c k)
+int bch2_extent_to_text(struct bch_fs *c, char *buf,
+                       size_t size, struct bkey_s_c k)
 {
        char *out = buf, *end = buf + size;
        const char *invalid;
@@ -1892,6 +1893,7 @@ void bch2_extent_to_text(struct bch_fs *c, char *buf,
        if (invalid)
                p(" invalid: %s", invalid);
 #undef p
+       return out - buf;
 }
 
 static void bch2_extent_crc_init(union bch_extent_crc *crc,
index 15aed3c0665b767be5ad922b27beec31c9e478ab..0598d630969772396fda49b44f6fdaeec3cf9c1b 100644 (file)
@@ -19,7 +19,7 @@ union bch_extent_crc;
 const char *bch2_btree_ptr_invalid(const struct bch_fs *, struct bkey_s_c);
 void bch2_btree_ptr_debugcheck(struct bch_fs *, struct btree *,
                               struct bkey_s_c);
-void bch2_btree_ptr_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
+int bch2_btree_ptr_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
 void bch2_ptr_swab(const struct bkey_format *, struct bkey_packed *);
 
 #define bch2_bkey_btree_ops (struct bkey_ops) {                        \
@@ -31,7 +31,7 @@ void bch2_ptr_swab(const struct bkey_format *, struct bkey_packed *);
 
 const char *bch2_extent_invalid(const struct bch_fs *, struct bkey_s_c);
 void bch2_extent_debugcheck(struct bch_fs *, struct btree *, struct bkey_s_c);
-void bch2_extent_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
+int bch2_extent_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
 bool bch2_ptr_normalize(struct bch_fs *, struct btree *, struct bkey_s);
 enum merge_result bch2_extent_merge(struct bch_fs *, struct btree *,
                                    struct bkey_i *, struct bkey_i *);
index f40ec37d7f0fbc1b145c28825091d211471f8fe9..002232ffed6219082b41ad7943e35d5c8691eabe 100644 (file)
@@ -228,8 +228,8 @@ const char *bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k)
        }
 }
 
-void bch2_inode_to_text(struct bch_fs *c, char *buf,
-                       size_t size, struct bkey_s_c k)
+int bch2_inode_to_text(struct bch_fs *c, char *buf,
+                      size_t size, struct bkey_s_c k)
 {
        char *out = buf, *end = out + size;
        struct bkey_s_c_inode inode;
@@ -249,6 +249,8 @@ void bch2_inode_to_text(struct bch_fs *c, char *buf,
 #undef  BCH_INODE_FIELD
                break;
        }
+
+       return out - buf;
 }
 
 void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u,
index bd6166c40e6f9c9a030278b57f9bd31a7d726cd0..ce423a5f2af59f9fb68541653f7dbd72f343c18f 100644 (file)
@@ -7,7 +7,7 @@
 #include <linux/math64.h>
 
 const char *bch2_inode_invalid(const struct bch_fs *, struct bkey_s_c);
-void bch2_inode_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
+int bch2_inode_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
 
 #define bch2_bkey_inode_ops (struct bkey_ops) {                \
        .key_invalid    = bch2_inode_invalid,           \
index 0adbfe523f51649bb27c3e0d0eee7564b2b042c4..0a305ad0818873295270bbf649b900d0ab95bec5 100644 (file)
@@ -46,10 +46,10 @@ static const char * const bch2_quota_counters[] = {
        "inodes",
 };
 
-void bch2_quota_to_text(struct bch_fs *c, char *buf,
-                       size_t size, struct bkey_s_c k)
+int bch2_quota_to_text(struct bch_fs *c, char *buf,
+                      size_t size, struct bkey_s_c k)
 {
-       char *out = buf, *end= buf + size;
+       char *out = buf, *end = buf + size;
        struct bkey_s_c_quota dq;
        unsigned i;
 
@@ -64,6 +64,8 @@ void bch2_quota_to_text(struct bch_fs *c, char *buf,
                                         le64_to_cpu(dq.v->c[i].softlimit));
                break;
        }
+
+       return out - buf;
 }
 
 #ifdef CONFIG_BCACHEFS_QUOTA
index 4a76b49f9e005c2957bb4876bcd253aed36a6d50..9650e518cd644b30155be5c77f61b1539453b531 100644 (file)
@@ -8,7 +8,7 @@
 extern const struct bch_sb_field_ops bch_sb_field_ops_quota;
 
 const char *bch2_quota_invalid(const struct bch_fs *, struct bkey_s_c);
-void bch2_quota_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
+int bch2_quota_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
 
 #define bch2_bkey_quota_ops (struct bkey_ops) {                \
        .key_invalid    = bch2_quota_invalid,           \
index cb84bdabb6ed5f9604c26cc7dc97b73437b9266d..44bf4a2f3c840e69b8e01b2815027e28f0bd7ef6 100644 (file)
@@ -111,12 +111,12 @@ const char *bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k)
        }
 }
 
-void bch2_xattr_to_text(struct bch_fs *c, char *buf,
-                       size_t size, struct bkey_s_c k)
+int bch2_xattr_to_text(struct bch_fs *c, char *buf,
+                      size_t size, struct bkey_s_c k)
 {
+       char *out = buf, *end = buf + size;
        const struct xattr_handler *handler;
        struct bkey_s_c_xattr xattr;
-       size_t n = 0;
 
        switch (k.k->type) {
        case BCH_XATTR:
@@ -124,24 +124,26 @@ void bch2_xattr_to_text(struct bch_fs *c, char *buf,
 
                handler = bch2_xattr_type_to_handler(xattr.v->x_type);
                if (handler && handler->prefix)
-                       n += scnprintf(buf + n, size - n, "%s", handler->prefix);
+                       out += scnprintf(out, end - out, "%s", handler->prefix);
                else if (handler)
-                       n += scnprintf(buf + n, size - n, "(type %u)",
-                                      xattr.v->x_type);
+                       out += scnprintf(out, end - out, "(type %u)",
+                                        xattr.v->x_type);
                else
-                       n += scnprintf(buf + n, size - n, "(unknown type %u)",
-                                      xattr.v->x_type);
-
-               n += bch_scnmemcpy(buf + n, size - n, xattr.v->x_name,
-                                  xattr.v->x_name_len);
-               n += scnprintf(buf + n, size - n, ":");
-               n += bch_scnmemcpy(buf + n, size - n, xattr_val(xattr.v),
-                                  le16_to_cpu(xattr.v->x_val_len));
+                       out += scnprintf(out, end - out, "(unknown type %u)",
+                                        xattr.v->x_type);
+
+               out += bch_scnmemcpy(out, end - out, xattr.v->x_name,
+                                    xattr.v->x_name_len);
+               out += scnprintf(out, end - out, ":");
+               out += bch_scnmemcpy(out, end - out, xattr_val(xattr.v),
+                                    le16_to_cpu(xattr.v->x_val_len));
                break;
        case BCH_XATTR_WHITEOUT:
-               scnprintf(buf, size, "whiteout");
+               out += scnprintf(out, end - out, "whiteout");
                break;
        }
+
+       return out - buf;
 }
 
 int bch2_xattr_get(struct bch_fs *c, struct bch_inode_info *inode,
index 0e7d2fa862134c84752f89b4f35718d46a623444..b2fe1dc42b831f4420fdfa4fe77f3dbaf398a111 100644 (file)
@@ -7,7 +7,7 @@
 extern const struct bch_hash_desc bch2_xattr_hash_desc;
 
 const char *bch2_xattr_invalid(const struct bch_fs *, struct bkey_s_c);
-void bch2_xattr_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
+int bch2_xattr_to_text(struct bch_fs *, char *, size_t, struct bkey_s_c);
 
 #define bch2_bkey_xattr_ops (struct bkey_ops) {                \
        .key_invalid    = bch2_xattr_invalid,           \