From: Greg Farnum Date: Fri, 1 Feb 2013 23:51:59 +0000 (-0800) Subject: MDS: EMetaBlob::dirlump more modernization for encoder X-Git-Tag: v0.58~100^2~30 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=821b74e934b093b45a4664d216c38d43e69d4991;p=ceph.git MDS: EMetaBlob::dirlump more modernization for encoder Signed-off-by: Greg Farnum --- diff --git a/src/mds/events/EMetaBlob.h b/src/mds/events/EMetaBlob.h index 8549d22be64..3cf77d091eb 100644 --- a/src/mds/events/EMetaBlob.h +++ b/src/mds/events/EMetaBlob.h @@ -226,11 +226,11 @@ public: public: dirlump() : state(0), nfull(0), nremote(0), nnull(0), dn_decoded(true) { } - bool is_complete() { return state & STATE_COMPLETE; } + bool is_complete() const { return state & STATE_COMPLETE; } void mark_complete() { state |= STATE_COMPLETE; } - bool is_dirty() { return state & STATE_DIRTY; } + bool is_dirty() const { return state & STATE_DIRTY; } void mark_dirty() { state |= STATE_DIRTY; } - bool is_new() { return state & STATE_NEW; } + bool is_new() const { return state & STATE_NEW; } void mark_new() { state |= STATE_NEW; } bool is_importing() { return state & STATE_IMPORTING; } void mark_importing() { state |= STATE_IMPORTING; } @@ -253,8 +253,26 @@ public: p->print(out); } + string state_string() const { + string state_string; + bool marked_already = false; + if (is_complete()) { + state_string.append("complete"); + marked_already = true; + } + if (is_dirty()) { + state_string.append(marked_already ? "+dirty" : "dirty"); + marked_already = true; + } + if (is_new()) { + state_string.append(marked_already ? "+new" : "new"); + } + return state_string; + } + // if this changes, update the versioning in encode for it! void _encode_bits() const { + if (!dn_decoded) return; ::encode(dfull, dnbl); ::encode(dremote, dnbl); ::encode(dnull, dnbl); @@ -268,28 +286,10 @@ public: dn_decoded = true; } - void encode(bufferlist& bl) const { - ENCODE_START(2, 2, bl); - ::encode(fnode, bl); - ::encode(state, bl); - ::encode(nfull, bl); - ::encode(nremote, bl); - ::encode(nnull, bl); - _encode_bits(); - ::encode(dnbl, bl); - ENCODE_FINISH(bl); - } - void decode(bufferlist::iterator &bl) { - DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl) - ::decode(fnode, bl); - ::decode(state, bl); - ::decode(nfull, bl); - ::decode(nremote, bl); - ::decode(nnull, bl); - ::decode(dnbl, bl); - dn_decoded = false; // don't decode bits unless we need them. - DECODE_FINISH(bl); - } + void encode(bufferlist& bl) const; + void decode(bufferlist::iterator &bl); + void dump(Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(dirlump) diff --git a/src/mds/journal.cc b/src/mds/journal.cc index 6915ea71871..7d049c2055a 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -644,8 +644,81 @@ void EMetaBlob::nullbit::generate_test_instances(list& ls) ls.push_back(sample2); } +// EMetaBlob::dirlump + +void EMetaBlob::dirlump::encode(bufferlist& bl) const +{ + ENCODE_START(2, 2, bl); + ::encode(fnode, bl); + ::encode(state, bl); + ::encode(nfull, bl); + ::encode(nremote, bl); + ::encode(nnull, bl); + _encode_bits(); + ::encode(dnbl, bl); + ENCODE_FINISH(bl); +} + +void EMetaBlob::dirlump::decode(bufferlist::iterator &bl) +{ + DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl) + ::decode(fnode, bl); + ::decode(state, bl); + ::decode(nfull, bl); + ::decode(nremote, bl); + ::decode(nnull, bl); + ::decode(dnbl, bl); + dn_decoded = false; // don't decode bits unless we need them. + DECODE_FINISH(bl); +} + +void EMetaBlob::dirlump::dump(Formatter *f) const +{ + if (!dn_decoded) { + dirlump *me = const_cast(this); + me->_decode_bits(); + } + f->open_object_section("fnode"); + fnode.dump(f); + f->close_section(); // fnode + f->dump_string("state", state_string()); + f->dump_int("nfull", nfull); + f->dump_int("nremote", nremote); + f->dump_int("nnull", nnull); + + f->open_array_section("full bits"); + for (list >::const_iterator + iter = dfull.begin(); iter != dfull.end(); ++iter) { + f->open_object_section("fullbit"); + (*iter)->dump(f); + f->close_section(); // fullbit + } + f->close_section(); // full bits + f->open_array_section("remote bits"); + for (list::const_iterator + iter = dremote.begin(); iter != dremote.end(); ++iter) { + f->open_object_section("remotebit"); + (*iter).dump(f); + f->close_section(); // remotebit + } + f->close_section(); // remote bits + f->open_array_section("null bits"); + for (list::const_iterator + iter = dnull.begin(); iter != dnull.end(); ++iter) { + f->open_object_section("null bit"); + (*iter).dump(f); + f->close_section(); // null bit + } + f->close_section(); // null bits +} + +void EMetaBlob::dirlump::generate_test_instances(list& ls) +{ + ls.push_back(new dirlump()); +} + /** - * + * EMetaBlob proper */ void EMetaBlob::replay(MDS *mds, LogSegment *logseg, MDSlaveUpdate *slaveup) diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index b4d36c45aea..2b47296b248 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -137,7 +137,7 @@ TYPE(EImportStart) TYPE(EMetaBlob::fullbit) TYPE(EMetaBlob::remotebit) TYPE(EMetaBlob::nullbit) - +TYPE(EMetaBlob::dirlump) #ifdef WITH_RADOSGW