diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-07-24 23:06:40 -0700 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-11-10 21:56:35 -0800 |
commit | d5cc66e95744065f96024add4bf7d7e019be54ac (patch) | |
tree | 6d134aaa14c6420f4193734dbe49a4ee32d2bb06 /drivers/md/bcache/bset.c | |
parent | 3a3b6a4e075188342b58d4b6560f5540af64cac0 (diff) |
bcache: bch_(btree|extent)_ptr_invalid()
Trying to treat btree pointers and leaf node pointers the same way was a
mistake - going to start being more explicit about the type of
key/pointer we're dealing with. This is the first part of that
refactoring; this patch shouldn't change any actual behaviour.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md/bcache/bset.c')
-rw-r--r-- | drivers/md/bcache/bset.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c index 6bffde478926..b615348c45fc 100644 --- a/drivers/md/bcache/bset.c +++ b/drivers/md/bcache/bset.c @@ -73,19 +73,9 @@ void bch_keylist_pop_front(struct keylist *l) /* Pointer validation */ -bool __bch_ptr_invalid(struct cache_set *c, int level, const struct bkey *k) +static bool __ptr_invalid(struct cache_set *c, const struct bkey *k) { unsigned i; - char buf[80]; - - if (level && (!KEY_PTRS(k) || !KEY_SIZE(k) || KEY_DIRTY(k))) - goto bad; - - if (!level && KEY_SIZE(k) > KEY_OFFSET(k)) - goto bad; - - if (!KEY_SIZE(k)) - return true; for (i = 0; i < KEY_PTRS(k); i++) if (ptr_available(c, k, i)) { @@ -96,13 +86,46 @@ bool __bch_ptr_invalid(struct cache_set *c, int level, const struct bkey *k) if (KEY_SIZE(k) + r > c->sb.bucket_size || bucket < ca->sb.first_bucket || bucket >= ca->sb.nbuckets) - goto bad; + return true; } return false; +} + +bool bch_btree_ptr_invalid(struct cache_set *c, const struct bkey *k) +{ + char buf[80]; + + if (!KEY_PTRS(k) || !KEY_SIZE(k) || KEY_DIRTY(k)) + goto bad; + + if (__ptr_invalid(c, k)) + goto bad; + + return false; +bad: + bch_bkey_to_text(buf, sizeof(buf), k); + cache_bug(c, "spotted btree ptr %s: %s", buf, bch_ptr_status(c, k)); + return true; +} + +bool bch_extent_ptr_invalid(struct cache_set *c, const struct bkey *k) +{ + char buf[80]; + + if (!KEY_SIZE(k)) + return true; + + if (KEY_SIZE(k) > KEY_OFFSET(k)) + goto bad; + + if (__ptr_invalid(c, k)) + goto bad; + + return false; bad: bch_bkey_to_text(buf, sizeof(buf), k); - cache_bug(c, "spotted bad key %s: %s", buf, bch_ptr_status(c, k)); + cache_bug(c, "spotted extent %s: %s", buf, bch_ptr_status(c, k)); return true; } |