summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-07-23 16:13:07 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:08:08 +0300
commit277c981c634f3e64dd99523aabfd9ed5e6c5be55 (patch)
tree71639c412531bfe8e8e992508645bedf8fdcc8fa /fs
parentbb1b3658aa7259bdacf7500abdeb8fdff61a51ba (diff)
downloadlinux-277c981c634f3e64dd99523aabfd9ed5e6c5be55.tar.xz
bcachefs: fix bch2_val_to_text()
was returning wrong value Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/alloc.c8
-rw-r--r--fs/bcachefs/alloc.h2
-rw-r--r--fs/bcachefs/bkey_methods.c21
-rw-r--r--fs/bcachefs/bkey_methods.h3
-rw-r--r--fs/bcachefs/dirent.c16
-rw-r--r--fs/bcachefs/dirent.h2
-rw-r--r--fs/bcachefs/extents.c10
-rw-r--r--fs/bcachefs/extents.h4
-rw-r--r--fs/bcachefs/inode.c6
-rw-r--r--fs/bcachefs/inode.h2
-rw-r--r--fs/bcachefs/quota.c8
-rw-r--r--fs/bcachefs/quota.h2
-rw-r--r--fs/bcachefs/xattr.c32
-rw-r--r--fs/bcachefs/xattr.h2
14 files changed, 72 insertions, 46 deletions
diff --git a/fs/bcachefs/alloc.c b/fs/bcachefs/alloc.c
index 19523226afd8..ea1dc52e5ff6 100644
--- a/fs/bcachefs/alloc.c
+++ b/fs/bcachefs/alloc.c
@@ -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 {
diff --git a/fs/bcachefs/alloc.h b/fs/bcachefs/alloc.h
index 2a6500d6f97a..739df233236c 100644
--- a/fs/bcachefs/alloc.h
+++ b/fs/bcachefs/alloc.h
@@ -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, \
diff --git a/fs/bcachefs/bkey_methods.c b/fs/bcachefs/bkey_methods.c
index 017425a534c6..8c6c2ca3c992 100644
--- a/fs/bcachefs/bkey_methods.c
+++ b/fs/bcachefs/bkey_methods.c
@@ -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;
}
diff --git a/fs/bcachefs/bkey_methods.h b/fs/bcachefs/bkey_methods.h
index 04c80f3603cc..989b577da928 100644
--- a/fs/bcachefs/bkey_methods.h
+++ b/fs/bcachefs/bkey_methods.h
@@ -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);
diff --git a/fs/bcachefs/dirent.c b/fs/bcachefs/dirent.c
index 18078cc2ca62..d5e174e1e59f 100644
--- a/fs/bcachefs/dirent.c
+++ b/fs/bcachefs/dirent.c
@@ -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,
diff --git a/fs/bcachefs/dirent.h b/fs/bcachefs/dirent.h
index d02dc3e10d95..ac28f83d6b2d 100644
--- a/fs/bcachefs/dirent.h
+++ b/fs/bcachefs/dirent.h
@@ -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, \
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index 2c1cf29e265a..e0150fbe85af 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -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,
diff --git a/fs/bcachefs/extents.h b/fs/bcachefs/extents.h
index 15aed3c0665b..0598d6309697 100644
--- a/fs/bcachefs/extents.h
+++ b/fs/bcachefs/extents.h
@@ -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 *);
diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c
index f40ec37d7f0f..002232ffed62 100644
--- a/fs/bcachefs/inode.c
+++ b/fs/bcachefs/inode.c
@@ -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,
diff --git a/fs/bcachefs/inode.h b/fs/bcachefs/inode.h
index bd6166c40e6f..ce423a5f2af5 100644
--- a/fs/bcachefs/inode.h
+++ b/fs/bcachefs/inode.h
@@ -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, \
diff --git a/fs/bcachefs/quota.c b/fs/bcachefs/quota.c
index 0adbfe523f51..0a305ad08188 100644
--- a/fs/bcachefs/quota.c
+++ b/fs/bcachefs/quota.c
@@ -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
diff --git a/fs/bcachefs/quota.h b/fs/bcachefs/quota.h
index 4a76b49f9e00..9650e518cd64 100644
--- a/fs/bcachefs/quota.h
+++ b/fs/bcachefs/quota.h
@@ -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, \
diff --git a/fs/bcachefs/xattr.c b/fs/bcachefs/xattr.c
index cb84bdabb6ed..44bf4a2f3c84 100644
--- a/fs/bcachefs/xattr.c
+++ b/fs/bcachefs/xattr.c
@@ -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,
diff --git a/fs/bcachefs/xattr.h b/fs/bcachefs/xattr.h
index 0e7d2fa86213..b2fe1dc42b83 100644
--- a/fs/bcachefs/xattr.h
+++ b/fs/bcachefs/xattr.h
@@ -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, \