diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2017-03-19 15:56:34 -0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2017-03-19 17:31:47 -0800 |
commit | 5ec39af8eaba49aee7bafa44c661da39e2f40dc3 (patch) | |
tree | 1fb1a981602cbf22c7d2b2dba1168c715d7cecb5 /libbcache/bkey_methods.c | |
parent | bb1941de5378a7b8122d3575dcbc7d0aeb6326f0 (diff) |
Rename from bcache-tools to bcachefs-tools
Diffstat (limited to 'libbcache/bkey_methods.c')
-rw-r--r-- | libbcache/bkey_methods.c | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/libbcache/bkey_methods.c b/libbcache/bkey_methods.c deleted file mode 100644 index 2908489c..00000000 --- a/libbcache/bkey_methods.c +++ /dev/null @@ -1,127 +0,0 @@ - -#include "bcache.h" -#include "bkey_methods.h" -#include "btree_types.h" -#include "dirent.h" -#include "error.h" -#include "extents.h" -#include "inode.h" -#include "xattr.h" - -const struct bkey_ops *bch_bkey_ops[] = { - [BKEY_TYPE_EXTENTS] = &bch_bkey_extent_ops, - [BKEY_TYPE_INODES] = &bch_bkey_inode_ops, - [BKEY_TYPE_DIRENTS] = &bch_bkey_dirent_ops, - [BKEY_TYPE_XATTRS] = &bch_bkey_xattr_ops, - [BKEY_TYPE_BTREE] = &bch_bkey_btree_ops, -}; - -/* Returns string indicating reason for being invalid, or NULL if valid: */ -const char *bkey_invalid(struct bch_fs *c, enum bkey_type type, - struct bkey_s_c k) -{ - const struct bkey_ops *ops = bch_bkey_ops[type]; - - if (k.k->u64s < BKEY_U64s) - return "u64s too small"; - - if (k.k->size && - (bkey_deleted(k.k) || !ops->is_extents)) - return "nonzero size field"; - - switch (k.k->type) { - case KEY_TYPE_DELETED: - case KEY_TYPE_DISCARD: - return NULL; - - case KEY_TYPE_ERROR: - return bkey_val_bytes(k.k) != 0 - ? "value size should be zero" - : NULL; - - case KEY_TYPE_COOKIE: - return bkey_val_bytes(k.k) != sizeof(struct bch_cookie) - ? "incorrect value size" - : NULL; - - default: - if (k.k->type < KEY_TYPE_GENERIC_NR) - return "invalid type"; - - return ops->key_invalid(c, k); - } -} - -const char *btree_bkey_invalid(struct bch_fs *c, struct btree *b, - struct bkey_s_c k) -{ - if (bkey_cmp(bkey_start_pos(k.k), b->data->min_key) < 0) - return "key before start of btree node"; - - if (bkey_cmp(k.k->p, b->data->max_key) > 0) - return "key past end of btree node"; - - if (k.k->p.snapshot) - return "nonzero snapshot"; - - return bkey_invalid(c, btree_node_type(b), k); -} - -void bkey_debugcheck(struct bch_fs *c, struct btree *b, struct bkey_s_c k) -{ - enum bkey_type type = btree_node_type(b); - const struct bkey_ops *ops = bch_bkey_ops[type]; - const char *invalid; - - BUG_ON(!k.k->u64s); - - invalid = btree_bkey_invalid(c, b, k); - if (invalid) { - char buf[160]; - - bch_bkey_val_to_text(c, type, buf, sizeof(buf), k); - bch_fs_bug(c, "invalid bkey %s: %s", buf, invalid); - return; - } - - if (k.k->type >= KEY_TYPE_GENERIC_NR && - ops->key_debugcheck) - ops->key_debugcheck(c, b, k); -} - -void bch_val_to_text(struct bch_fs *c, enum bkey_type type, - char *buf, size_t size, struct bkey_s_c k) -{ - const struct bkey_ops *ops = bch_bkey_ops[type]; - - if (k.k->type >= KEY_TYPE_GENERIC_NR && - ops->val_to_text) - ops->val_to_text(c, buf, size, k); -} - -void bch_bkey_val_to_text(struct bch_fs *c, enum bkey_type type, - char *buf, size_t size, struct bkey_s_c k) -{ - const struct bkey_ops *ops = bch_bkey_ops[type]; - char *out = buf, *end = buf + size; - - out += bch_bkey_to_text(out, end - out, k.k); - - if (k.k->type >= KEY_TYPE_GENERIC_NR && - ops->val_to_text) { - out += scnprintf(out, end - out, " -> "); - ops->val_to_text(c, out, end - out, k); - } -} - -void bch_bkey_swab(enum bkey_type type, - const struct bkey_format *f, - struct bkey_packed *k) -{ - const struct bkey_ops *ops = bch_bkey_ops[type]; - - bch_bkey_swab_key(f, k); - - if (ops->swab) - ops->swab(f, k); -} |