From 7fc05b4821d5baf171f99957523c80163f56d890 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 19 Oct 2015 14:37:04 -0400 Subject: [PATCH] os/ObjectStore: helpers for validating map and set to bl Test/validate the encoding, and reference the resulting (encoded) data in a bufferlist. Signed-off-by: Sage Weil --- src/os/ObjectStore.cc | 35 +++++++++++++++++++++++++++++++++++ src/os/ObjectStore.h | 10 ++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index 8e8886baa6172..aa62fbda691d4 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -25,6 +25,41 @@ #include "newstore/NewStore.h" #endif +void decode_str_str_map_to_bl(bufferlist::iterator& p, + bufferlist *out) +{ + bufferlist::iterator start = p; + __u32 n; + ::decode(n, p); + unsigned len = 4; + while (n--) { + __u32 l; + ::decode(l, p); + p.advance(l); + len += 4 + l; + ::decode(l, p); + p.advance(l); + len += 4 + l; + } + start.copy(len, *out); +} + +void decode_str_set_to_bl(bufferlist::iterator& p, + bufferlist *out) +{ + bufferlist::iterator start = p; + __u32 n; + ::decode(n, p); + unsigned len = 4; + while (n--) { + __u32 l; + ::decode(l, p); + p.advance(l); + len += 4 + l; + } + start.copy(len, *out); +} + ObjectStore *ObjectStore::create(CephContext *cct, const string& type, const string& data, diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index ba4c7d2852d10..dcb7e601ccd85 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -84,6 +84,10 @@ static inline void encode(const map *attrset, bufferlist &bl) ::encode(*attrset, bl); } +// this isn't the best place for these, but... +void decode_str_str_map_to_bl(bufferlist::iterator& p, bufferlist *out); +void decode_str_set_to_bl(bufferlist::iterator& p, bufferlist *out); + // Flag bits typedef uint32_t osflagbits_t; const int SKIP_JOURNAL_REPLAY = 1 << 0; @@ -836,9 +840,15 @@ public: void decode_attrset(map& aset) { ::decode(aset, data_bl_p); } + void decode_attrset_bl(bufferlist *pbl) { + decode_str_str_map_to_bl(data_bl_p, pbl); + } void decode_keyset(set &keys){ ::decode(keys, data_bl_p); } + void decode_keyset_bl(bufferlist *pbl){ + decode_str_set_to_bl(data_bl_p, pbl); + } const ghobject_t &get_oid(__le32 oid_id) { assert(oid_id < objects.size()); -- 2.39.5