#include "byteorder.h"
#include "buffer.h"
-
// --------------------------------------
// base types
#include <vector>
#include <string>
#include <ext/hash_map>
+#include "triple.h"
+
+// pair
+template<class A, class B>
+inline void encode(const std::pair<A,B> &p, bufferlist &bl)
+{
+ encode(p.first, bl);
+ encode(p.second, bl);
+}
+template<class A, class B>
+inline void decode(std::pair<A,B> &pa, bufferlist::iterator &p)
+{
+ decode(pa.first, p);
+ decode(pa.second, p);
+}
+
+// triple
+template<class A, class B, class C>
+inline void encode(const triple<A,B,C> &t, bufferlist &bl)
+{
+ encode(t.first, bl);
+ encode(t.second, bl);
+ encode(t.third, bl);
+}
+template<class A, class B, class C>
+inline void decode(triple<A,B,C> &t, bufferlist::iterator &p)
+{
+ decode(t.first, p);
+ decode(t.second, p);
+ decode(t.third, p);
+}
+
+
+// list (pointers)
+template<class T>
+inline void encode(const std::list<T*>& ls, bufferlist& bl)
+{
+ // should i pre- or post- count?
+ if (!ls.empty()) {
+ unsigned pos = bl.length();
+ __u32 n = 0;
+ encode(n, bl);
+ for (typename std::list<T*>::const_iterator p = ls.begin(); p != ls.end(); ++p) {
+ n++;
+ encode(**p, bl);
+ }
+ bl.copy_in(pos, sizeof(n), (char*)&n);
+ } else {
+ __u32 n = ls.size(); // FIXME: this is slow on a list.
+ encode(n, bl);
+ for (typename std::list<T*>::const_iterator p = ls.begin(); p != ls.end(); ++p)
+ encode(**p, bl);
+ }
+}
+template<class T>
+inline void decode(std::list<T*>& ls, bufferlist::iterator& p)
+{
+ __u32 n;
+ decode(n, p);
+ ls.clear();
+ while (n--)
+ ls.push_back(new T(p));
+}
// list
}
}
+// vector (pointers)
+template<class T>
+inline void encode(const std::vector<T*>& v, bufferlist& bl)
+{
+ __u32 n = v.size();
+ encode(n, bl);
+ for (typename std::vector<T*>::const_iterator p = v.begin(); p != v.end(); ++p)
+ encode(**p, bl);
+}
+template<class T>
+inline void decode(std::vector<T*>& v, bufferlist::iterator& p)
+{
+ __u32 n;
+ decode(n, p);
+ v.resize(n);
+ for (__u32 i=0; i<n; i++)
+ v[i] = new T(p);
+}
+
// vector
template<class T>
inline void encode(const std::vector<T>& v, bufferlist& bl)
decode(v[i], p);
}
+// map (pointers)
+template<class T, class U>
+inline void encode(const std::map<T,U*>& m, bufferlist& bl)
+{
+ __u32 n = m.size();
+ encode(n, bl);
+ for (typename std::map<T,U*>::const_iterator p = m.begin(); p != m.end(); ++p) {
+ encode(p->first, bl);
+ encode(*p->second, bl);
+ }
+}
+template<class T, class U>
+inline void decode(std::map<T,U*>& m, bufferlist::iterator& p)
+{
+ __u32 n;
+ decode(n, p);
+ m.clear();
+ while (n--) {
+ T k;
+ decode(k, p);
+ m[k] = new U(p);
+ }
+}
+
// map
template<class T, class U>
inline void encode(const std::map<T,U>& m, bufferlist& bl)
}
// encoding
- void _encode(bufferlist& bl) const {
+ void encode(bufferlist& bl) const {
::encode(_splits, bl);
}
- void _decode(bufferlist& bl, int& off) {
- ::_decode(_splits, bl, off);
- }
- void _decode(bufferlist::iterator& p) {
+ void decode(bufferlist::iterator& p) {
::decode(_splits, p);
}
out << ")";
}
};
+WRITE_CLASS_ENCODERS(fragtree_t)
inline std::ostream& operator<<(std::ostream& out, fragtree_t& ft)
{
A first;
B second;
C third;
+
triple() {}
triple(A f, B s, C t) : first(f), second(s), third(t) {}
};
version_t file_data_version; // auth only
// file type
- bool is_symlink() { return (mode & S_IFMT) == S_IFLNK; }
- bool is_dir() { return (mode & S_IFMT) == S_IFDIR; }
- bool is_file() { return (mode & S_IFMT) == S_IFREG; }
+ bool is_symlink() const { return (mode & S_IFMT) == S_IFLNK; }
+ bool is_dir() const { return (mode & S_IFMT) == S_IFDIR; }
+ bool is_file() const { return (mode & S_IFMT) == S_IFREG; }
};
static inline void encode(const inode_t &i, bufferlist &bl) {
#include "mdstypes.h"
#include "include/buffer.h"
-
// anchor ops
#define ANCHOR_OP_LOOKUP 1
#define ANCHOR_OP_LOOKUP_REPLY -2
//ref_dn(rd),
nref(nr) { }
- void _encode(bufferlist &bl) {
- bl.append((char*)&ino, sizeof(ino));
- bl.append((char*)&dirfrag, sizeof(dirfrag));
- bl.append((char*)&nref, sizeof(nref));
- //::_encode(ref_dn, bl);
+ void encode(bufferlist &bl) const {
+ ::encode(ino, bl);
+ ::encode(dirfrag, bl);
+ ::encode(nref, bl);
}
- void _decode(bufferlist& bl, int& off) {
- bl.copy(off, sizeof(ino), (char*)&ino);
- off += sizeof(ino);
- bl.copy(off, sizeof(dirfrag), (char*)&dirfrag);
- off += sizeof(dirfrag);
- bl.copy(off, sizeof(nref), (char*)&nref);
- off += sizeof(nref);
- //::_decode(ref_dn, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(ino, bl);
+ ::decode(dirfrag, bl);
+ ::decode(nref, bl);
}
};
+WRITE_CLASS_ENCODERS(Anchor)
inline ostream& operator<<(ostream& out, Anchor& a)
{
bufferlist bl;
// version
- bl.append((char*)&version, sizeof(version));
-
- // # anchors
- size_t size = anchor_map.size();
- bl.append((char*)&size, sizeof(size));
-
- // anchors
- for (hash_map<inodeno_t, Anchor>::iterator it = anchor_map.begin();
- it != anchor_map.end();
- it++) {
- it->second._encode(bl);
- dout(15) << "save encoded " << it->second << dendl;
- }
+ ::encode(version, bl);
+ ::encode(anchor_map, bl);
// pending
- ::_encode(pending_reqmds, bl);
- ::_encode(pending_create, bl);
- ::_encode(pending_destroy, bl);
-
- size_t s = pending_update.size();
- bl.append((char*)&s, sizeof(s));
- for (map<version_t, pair<inodeno_t, vector<Anchor> > >::iterator p = pending_update.begin();
- p != pending_update.end();
- ++p) {
- bl.append((char*)&p->first, sizeof(p->first));
- bl.append((char*)&p->second.first, sizeof(p->second.first));
- ::_encode(p->second.second, bl);
- }
+ ::encode(pending_reqmds, bl);
+ ::encode(pending_create, bl);
+ ::encode(pending_destroy, bl);
+ ::encode(pending_update, bl);
// write!
object_t oid = object_t(MDS_INO_ANCHORTABLE+mds->get_nodeid(), 0);
{
dout(10) << "_loaded got " << bl.length() << " bytes" << dendl;
- int off = 0;
- bl.copy(off, sizeof(version), (char*)&version);
- off += sizeof(version);
+ bufferlist::iterator p = bl.begin();
- size_t size;
- bl.copy(off, sizeof(size), (char*)&size);
- off += sizeof(size);
+ ::decode(version, p);
+ ::decode(anchor_map, p);
- for (size_t n=0; n<size; n++) {
- Anchor a;
- a._decode(bl, off);
- anchor_map[a.ino] = a;
- dout(15) << "load_2 decoded " << a << dendl;
- }
-
- ::_decode(pending_reqmds, bl, off);
- ::_decode(pending_create, bl, off);
- ::_decode(pending_destroy, bl, off);
-
- size_t s;
- bl.copy(off, sizeof(s), (char*)&s);
- off += sizeof(s);
- for (size_t i=0; i<s; i++) {
- version_t atid;
- bl.copy(off, sizeof(atid), (char*)&atid);
- off += sizeof(atid);
- inodeno_t ino;
- bl.copy(off, sizeof(ino), (char*)&ino);
- off += sizeof(ino);
-
- pending_update[atid].first = ino;
- ::_decode(pending_update[atid].second, bl, off);
- }
+ ::decode(pending_reqmds, p);
+ ::decode(pending_create, p);
+ ::decode(pending_destroy, p);
+ ::decode(pending_update, p);
- assert(off == (int)bl.length());
+ assert(p.end());
// done.
opened = true;
lockstate(dn->lock.get_replica_state()),
dir_offset(dn->get_dir_offset()),
remote_ino(dn->get_remote_ino()), remote_d_type(dn->get_remote_d_type()) { }
+ CDentryDiscover(bufferlist::iterator &p) { decode(p); }
string& get_dname() { return dname; }
int get_nonce() { return replica_nonce; }
dn->lock.set_state( lockstate );
}
- void _encode(bufferlist& bl) {
- ::_encode(dname, bl);
- ::_encode(dir_offset, bl);
- ::_encode(remote_ino, bl);
- ::_encode(remote_d_type, bl);
- ::_encode(replica_nonce, bl);
- ::_encode(lockstate, bl);
+ void encode(bufferlist &bl) const {
+ ::encode(dname, bl);
+ ::encode(dir_offset, bl);
+ ::encode(remote_ino, bl);
+ ::encode(remote_d_type, bl);
+ ::encode(replica_nonce, bl);
+ ::encode(lockstate, bl);
}
- void _decode(bufferlist& bl, int& off) {
- ::_decode(dname, bl, off);
- ::_decode(dir_offset, bl, off);
- ::_decode(remote_ino, bl, off);
- ::_decode(remote_d_type, bl, off);
- ::_decode(replica_nonce, bl, off);
- ::_decode(lockstate, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(dname, bl);
+ ::decode(dir_offset, bl);
+ ::decode(remote_ino, bl);
+ ::decode(remote_d_type, bl);
+ ::decode(replica_nonce, bl);
+ ::decode(lockstate, bl);
}
-
};
-
+WRITE_CLASS_ENCODERS(CDentryDiscover)
#endif
// decode.
int len = bl.length();
- int off = 0;
+ bufferlist::iterator p = bl.begin();
version_t got_version;
- ::_decode(got_version, bl, off);
+ ::decode(got_version, p);
dout(10) << "_fetched version " << got_version
<< ", " << len << " bytes"
<< dendl;
int32_t n;
- ::_decode(n, bl, off);
+ ::decode(n, p);
//int num_new_inodes_loaded = 0;
for (int i=0; i<n; i++) {
- off_t dn_offset = off;
+ off_t dn_offset = p.get_off();
// marker
- char type = bl[off];
- ++off;
+ char type;
+ ::decode(type, p);
// dname
string dname;
- ::_decode(dname, bl, off);
+ ::decode(dname, p);
dout(24) << "_fetched parsed marker '" << type << "' dname '" << dname << dendl;
CDentry *dn = lookup(dname); // existing dentry?
// hard link
inodeno_t ino;
unsigned char d_type;
- ::_decode(ino, bl, off);
- ::_decode(d_type, bl, off);
+ ::decode(ino, p);
+ ::decode(d_type, p);
if (dn) {
if (dn->get_inode() == 0) {
// parse out inode
inode_t inode;
- ::_decode(inode, bl, off);
+ ::decode(inode, p);
string symlink;
if (inode.is_symlink())
- ::_decode(symlink, bl, off);
+ ::decode(symlink, p);
fragtree_t fragtree;
- fragtree._decode(bl, off);
+ ::decode(fragtree, p);
if (dn) {
if (dn->get_inode() == 0) {
}
}
} else {
- dout(1) << "corrupt directory, i got tag char '" << type << "' val " << (int)(type)
- << " at pos " << off << dendl;
+ dout(1) << "corrupt directory, i got tag char '" << type << "' val " << (int)(type)
+ << " at offset " << p.get_off() << dendl;
assert(0);
}
}
}
}
- //assert(off == len); no, directories may shrink. add this back in when we properly truncate objects on write.
+ //assert(off == len); FIXME no, directories may shrink. add this back in when we properly truncate objects on write.
// take the loaded version?
// only if we are a fresh CDir* with no prior state.
// encode
bufferlist bl;
- ::_encode(version, bl);
+ ::encode(version, bl);
int32_t n = nitems;
- ::_encode(n, bl);
+ ::encode(n, bl);
for (map_t::iterator it = items.begin();
it != items.end();
// marker, name, ino
bl.append( "L", 1 ); // remote link
- ::_encode(it->first, bl);
- ::_encode(ino, bl);
- ::_encode(d_type, bl);
+ ::encode(it->first, bl);
+ ::encode(ino, bl);
+ ::encode(d_type, bl);
} else {
// primary link
CInode *in = dn->get_inode();
// marker, name, inode, [symlink string]
bl.append( "I", 1 ); // inode
- ::_encode(it->first, bl);
- ::_encode(in->inode, bl);
+ ::encode(it->first, bl);
+ ::encode(in->inode, bl);
if (in->is_symlink()) {
// include symlink destination!
dout(18) << " inlcuding symlink ptr " << in->symlink << dendl;
- ::_encode(in->symlink, bl);
+ ::encode(in->symlink, bl);
}
- in->dirfragtree._encode(bl);
+ ::encode(in->dirfragtree, bl);
}
}
assert(n == 0);
dir_rep = dir->dir_rep;
rep_by = dir->dir_rep_by;
}
+ CDirDiscover(bufferlist::iterator &p) { decode(p); }
void update_dir(CDir *dir) {
assert(dir->dirfrag() == dirfrag);
dirfrag_t get_dirfrag() { return dirfrag; }
- void _encode(bufferlist& bl) {
- bl.append((char*)&dirfrag, sizeof(dirfrag));
- bl.append((char*)&nonce, sizeof(nonce));
- bl.append((char*)&dir_rep, sizeof(dir_rep));
- ::_encode(rep_by, bl);
+ void encode(bufferlist& bl) const {
+ ::encode(dirfrag, bl);
+ ::encode(nonce, bl);
+ ::encode(dir_rep, bl);
+ ::encode(rep_by, bl);
}
- void _decode(bufferlist& bl, int& off) {
- bl.copy(off, sizeof(dirfrag), (char*)&dirfrag);
- off += sizeof(dirfrag);
- bl.copy(off, sizeof(nonce), (char*)&nonce);
- off += sizeof(nonce);
- bl.copy(off, sizeof(dir_rep), (char*)&dir_rep);
- off += sizeof(dir_rep);
- ::_decode(rep_by, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(dirfrag, bl);
+ ::decode(nonce, bl);
+ ::decode(dir_rep, bl);
+ ::decode(rep_by, bl);
}
};
+WRITE_CLASS_ENCODERS(CDirDiscover)
case CEPH_LOCK_IDFT:
{
// encode the raw tree
- dirfragtree._encode(bl);
+ ::encode(dirfragtree, bl);
// also specify which frags are mine
set<frag_t> myfrags;
frag_t fg = (*p)->get_frag();
myfrags.insert(fg);
}
- _encode(myfrags, bl);
+ ::encode(myfrags, bl);
}
break;
void CInode::decode_lock_state(int type, bufferlist& bl)
{
- int off = 0;
+ bufferlist::iterator p = bl.begin();
utime_t tm;
switch (type) {
case CEPH_LOCK_IAUTH:
- _decode(tm, bl, off);
+ ::decode(tm, p);
if (inode.ctime < tm) inode.ctime = tm;
- _decode(inode.mode, bl, off);
- _decode(inode.uid, bl, off);
- _decode(inode.gid, bl, off);
+ ::decode(inode.mode, p);
+ ::decode(inode.uid, p);
+ ::decode(inode.gid, p);
break;
case CEPH_LOCK_ILINK:
- _decode(tm, bl, off);
+ ::decode(tm, p);
if (inode.ctime < tm) inode.ctime = tm;
- _decode(inode.nlink, bl, off);
- _decode(inode.anchored, bl, off);
+ ::decode(inode.nlink, p);
+ ::decode(inode.anchored, p);
break;
case CEPH_LOCK_IDFT:
{
fragtree_t temp;
- temp._decode(bl, off);
+ ::decode(temp, p);
set<frag_t> authfrags;
- _decode(authfrags, bl, off);
+ ::decode(authfrags, p);
if (is_auth()) {
// auth. believe replica's auth frags only.
for (set<frag_t>::iterator p = authfrags.begin(); p != authfrags.end(); ++p)
break;
case CEPH_LOCK_IFILE:
- _decode(inode.size, bl, off);
- _decode(inode.mtime, bl, off);
- _decode(inode.atime, bl, off);
+ ::decode(inode.size, p);
+ ::decode(inode.mtime, p);
+ ::decode(inode.atime, p);
break;
case CEPH_LOCK_IDIR:
- //::_decode(inode.size, bl, off);
- _decode(tm, bl, off);
+ //::_decode(inode.size, p);
+ ::decode(tm, p);
if (inode.mtime < tm) {
inode.mtime = tm;
if (is_auth()) {
}
if (0) {
map<frag_t,int> dfsz;
- ::_decode(dfsz, bl, off);
+ ::decode(dfsz, p);
// hmm which to keep?
}
break;
{
::encode(inode, bl);
::encode(symlink, bl);
- dirfragtree._encode(bl);
+ ::encode(dirfragtree, bl);
bool dirty = is_dirty();
::encode(dirty, bl);
}
::decode(symlink, p);
- dirfragtree._decode(p);
+ ::decode(dirfragtree, p);
bool dirty;
::decode(dirty, p);
filelock_state = in->filelock.get_replica_state();
dirlock_state = in->dirlock.get_replica_state();
}
+ CInodeDiscover(bufferlist::iterator &p) {
+ decode(p);
+ }
inodeno_t get_ino() { return inode.ino; }
int get_replica_nonce() { return replica_nonce; }
in->dirlock.set_state(dirlock_state);
}
- void _encode(bufferlist& bl) {
- ::_encode(inode, bl);
- ::_encode(symlink, bl);
- dirfragtree._encode(bl);
- ::_encode(replica_nonce, bl);
- ::_encode(authlock_state, bl);
- ::_encode(linklock_state, bl);
- ::_encode(dirfragtreelock_state, bl);
- ::_encode(filelock_state, bl);
- ::_encode(dirlock_state, bl);
- }
-
- void _decode(bufferlist& bl, int& off) {
- ::_decode(inode, bl, off);
- ::_decode(symlink, bl, off);
- dirfragtree._decode(bl, off);
- ::_decode(replica_nonce, bl, off);
- ::_decode(authlock_state, bl, off);
- ::_decode(linklock_state, bl, off);
- ::_decode(dirfragtreelock_state, bl, off);
- ::_decode(filelock_state, bl, off);
- ::_decode(dirlock_state, bl, off);
+ void encode(bufferlist &bl) const {
+ ::encode(inode, bl);
+ ::encode(symlink, bl);
+ ::encode(dirfragtree, bl);
+ ::encode(replica_nonce, bl);
+ ::encode(authlock_state, bl);
+ ::encode(linklock_state, bl);
+ ::encode(dirfragtreelock_state, bl);
+ ::encode(filelock_state, bl);
+ ::encode(dirlock_state, bl);
+ }
+
+ void decode(bufferlist::iterator &p) {
+ ::decode(inode, p);
+ ::decode(symlink, p);
+ ::decode(dirfragtree, p);
+ ::decode(replica_nonce, p);
+ ::decode(authlock_state, p);
+ ::decode(linklock_state, p);
+ ::decode(dirfragtreelock_state, p);
+ ::decode(filelock_state, p);
+ ::decode(dirlock_state, p);
}
};
-
+WRITE_CLASS_ENCODERS(CInodeDiscover)
#endif
LogEvent *LogEvent::decode(bufferlist& bl)
{
// parse type, length
- int off = 0;
- int type;
- bl.copy(off, sizeof(type), (char*)&type);
- off += sizeof(type);
+ bufferlist::iterator p = bl.begin();
+ __u32 type;
+ ::decode(type, p);
- int length = bl.length() - off;
+ int length = bl.length() - p.get_off();
generic_dout(15) << "decode_log_event type " << type << ", size " << length << dendl;
assert(type > 0);
}
// decode
- le->decode_payload(bl, off);
+ le->decode(p);
return le;
}
// generic log event
class LogEvent {
private:
- int _type;
+ __u32 _type;
off_t _start_off,_end_off;
friend class MDLog;
off_t get_end_off() { return _end_off; }
// encoding
- virtual void encode_payload(bufferlist& bl) = 0;
- virtual void decode_payload(bufferlist& bl, int& off) = 0;
+ virtual void encode(bufferlist& bl) const = 0;
+ virtual void decode(bufferlist::iterator &bl) = 0;
static LogEvent *decode(bufferlist &bl);
CDentry *MDCache::add_replica_stray(bufferlist &bl, CInode *in, int from)
{
list<Context*> finished;
- int off = 0;
+ bufferlist::iterator p = bl.begin();
// inode
- CInodeDiscover indis;
- indis._decode(bl, off);
+ CInodeDiscover indis(p);
CInode *strayin = add_replica_inode(indis, NULL, finished);
dout(15) << "strayin " << *strayin << dendl;
// dir
- CDirDiscover dirdis;
- dirdis._decode(bl, off);
+ CDirDiscover dirdis(p);
CDir *straydir = add_replica_dir(strayin, dirdis.get_dirfrag().frag, dirdis,
from, finished);
dout(15) << "straydir " << *straydir << dendl;
// dentry
- CDentryDiscover dndis;
- dndis._decode(bl, off);
+ CDentryDiscover dndis(p);
string straydname;
in->name_stray_dentry(straydname);
// freshly replicate basedir to peer on merge
CDir *base = resultfrags.front();
CDirDiscover *basedis = base->replicate_to(*p);
- basedis->_encode(notify->basebl);
+ basedis->encode(notify->basebl);
delete basedis;
}
mds->send_message_mds(notify, *p);
// add replica dir (for merge)?
// (adjust_dir_fragments expects base to already exist, if non-auth)
if (notify->get_bits() < 0) {
- CDirDiscover basedis;
- int off = 0;
- basedis._decode(notify->basebl, off);
+ bufferlist::iterator p = notify->basebl.begin();
+ CDirDiscover basedis(p);
add_replica_dir(diri, notify->get_basefrag(), basedis,
notify->get_source().num(), waiters);
}
// encode it, with event type
{
bufferlist bl;
- ::_encode(le->_type, bl);
- le->encode_payload(bl);
+ ::encode(le->_type, bl);
+ le->encode(bl);
// journal it.
journaler->append_entry(bl); // bl is destroyed.
CInodeDiscover *indis = straydn->dir->inode->replicate_to(who);
CDirDiscover *dirdis = straydn->dir->replicate_to(who);
CDentryDiscover *dndis = straydn->replicate_to(who);
- indis->_encode(req->stray);
- dirdis->_encode(req->stray);
- dndis->_encode(req->stray);
+ indis->encode(req->stray);
+ dirdis->encode(req->stray);
+ dndis->encode(req->stray);
delete indis;
delete dirdis;
delete dndis;
void set_trace(vector<Anchor>& t) { trace = t; }
vector<Anchor>& get_trace() { return trace; }
- void encode_payload(bufferlist& bl) {
- bl.append((char*)&op, sizeof(op));
- bl.append((char*)&ino, sizeof(ino));
- bl.append((char*)&atid, sizeof(atid));
- ::_encode(trace, bl);
- bl.append((char*)&version, sizeof(version));
- bl.append((char*)&reqmds, sizeof(reqmds));
+ void encode(bufferlist& bl) const {
+ ::encode(op, bl);
+ ::encode(ino, bl);
+ ::encode(atid, bl);
+ ::encode(trace, bl);
+ ::encode(version, bl);
+ ::encode(reqmds, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- bl.copy(off, sizeof(op), (char*)&op);
- off += sizeof(op);
- bl.copy(off, sizeof(ino), (char*)&ino);
- off += sizeof(ino);
- bl.copy(off, sizeof(atid), (char*)&atid);
- off += sizeof(atid);
- ::_decode(trace, bl, off);
- bl.copy(off, sizeof(version), (char*)&version);
- off += sizeof(version);
- bl.copy(off, sizeof(reqmds), (char*)&reqmds);
- off += sizeof(reqmds);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(op, bl);
+ ::decode(ino, bl);
+ ::decode(atid, bl);
+ ::decode(trace, bl);
+ ::decode(version, bl);
+ ::decode(reqmds, bl);
}
void print(ostream& out) {
LogEvent(EVENT_ANCHORCLIENT),
op(o), atid(at) { }
- void encode_payload(bufferlist& bl) {
- bl.append((char*)&op, sizeof(op));
- bl.append((char*)&atid, sizeof(atid));
+ void encode(bufferlist &bl) const {
+ ::encode(op, bl);
+ ::encode(atid, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- bl.copy(off, sizeof(op), (char*)&op);
- off += sizeof(op);
- bl.copy(off, sizeof(atid), (char*)&atid);
- off += sizeof(atid);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(op, bl);
+ ::decode(atid, bl);
}
void print(ostream& out) {
out << "EExport " << base << " " << metablob;
}
- virtual void encode_payload(bufferlist& bl) {
- metablob._encode(bl);
- bl.append((char*)&base, sizeof(base));
- ::_encode(bounds, bl);
+ void encode(bufferlist& bl) const {
+ ::encode(metablob, bl);
+ ::encode(base, bl);
+ ::encode(bounds, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- metablob._decode(bl, off);
- bl.copy(off, sizeof(base), (char*)&base);
- off += sizeof(base);
- ::_decode(bounds, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(metablob, bl);
+ ::decode(base, bl);
+ ::decode(bounds, bl);
}
void replay(MDS *mds);
out << "EFragment " << ino << " " << basefrag << " by " << bits << " " << metablob;
}
- void encode_payload(bufferlist& bl) {
- ::_encode(ino, bl);
- ::_encode(basefrag, bl);
- ::_encode(bits, bl);
- metablob._encode(bl);
+ void encode(bufferlist &bl) const {
+ ::encode(ino, bl);
+ ::encode(basefrag, bl);
+ ::encode(bits, bl);
+ ::encode(metablob, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- ::_decode(ino, bl, off);
- ::_decode(basefrag, bl, off);
- ::_decode(bits, bl, off);
- metablob._decode(bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(ino, bl);
+ ::decode(basefrag, bl);
+ ::decode(bits, bl);
+ ::decode(metablob, bl);
}
void replay(MDS *mds);
out << " failed";
}
- virtual void encode_payload(bufferlist& bl) {
- bl.append((char*)&base, sizeof(base));
- bl.append((char*)&success, sizeof(success));
+ void encode(bufferlist& bl) const {
+ ::encode(base, bl);
+ ::encode(success, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- bl.copy(off, sizeof(base), (char*)&base);
- off += sizeof(base);
- bl.copy(off, sizeof(success), (char*)&success);
- off += sizeof(success);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(base, bl);
+ ::decode(success, bl);
}
void replay(MDS *mds);
out << "EImportStart " << base << " " << metablob;
}
- virtual void encode_payload(bufferlist& bl) {
- bl.append((char*)&base, sizeof(base));
- metablob._encode(bl);
- ::_encode(bounds, bl);
- ::_encode(cmapv, bl);
- ::_encode(client_map, bl);
+ void encode(bufferlist &bl) const {
+ ::encode(base, bl);
+ ::encode(metablob, bl);
+ ::encode(bounds, bl);
+ ::encode(cmapv, bl);
+ ::encode(client_map, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- bl.copy(off, sizeof(base), (char*)&base);
- off += sizeof(base);
- metablob._decode(bl, off);
- ::_decode(bounds, bl, off);
- ::_decode(cmapv, bl, off);
- ::_decode(client_map, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(base, bl);
+ ::decode(metablob, bl);
+ ::decode(bounds, bl);
+ ::decode(cmapv, bl);
+ ::decode(client_map, bl);
}
void replay(MDS *mds);
class EMetaBlob {
+public:
/* fullbit - a regular dentry + inode
*/
struct fullbit {
dn(d), dnv(v), inode(i), dirfragtree(dft), dirty(dr) { }
fullbit(const string& d, version_t v, inode_t& i, fragtree_t dft, string& sym, bool dr) :
dn(d), dnv(v), inode(i), dirfragtree(dft), symlink(sym), dirty(dr) { }
- fullbit(bufferlist& bl, int& off) { _decode(bl, off); }
- void _encode(bufferlist& bl) {
- ::_encode(dn, bl);
- ::_encode(dnv, bl);
- ::_encode(inode, bl);
- dirfragtree._encode(bl);
+ fullbit(bufferlist::iterator &p) { decode(p); }
+ fullbit() {}
+
+ void encode(bufferlist& bl) const {
+ ::encode(dn, bl);
+ ::encode(dnv, bl);
+ ::encode(inode, bl);
+ ::encode(dirfragtree, bl);
if (inode.is_symlink())
- ::_encode(symlink, bl);
- ::_encode(dirty, bl);
+ ::encode(symlink, bl);
+ ::encode(dirty, bl);
}
- void _decode(bufferlist& bl, int& off) {
- ::_decode(dn, bl, off);
- ::_decode(dnv, bl, off);
- ::_decode(inode, bl, off);
- dirfragtree._decode(bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(dn, bl);
+ ::decode(dnv, bl);
+ ::decode(inode, bl);
+ ::decode(dirfragtree, bl);
if (inode.is_symlink())
- ::_decode(symlink, bl, off);
- ::_decode(dirty, bl, off);
+ ::decode(symlink, bl);
+ ::decode(dirty, bl);
}
void print(ostream& out) {
out << " fullbit dn " << dn << " dnv " << dnv
<< " dirty=" << dirty << std::endl;
}
};
+ WRITE_CLASS_ENCODERS(fullbit)
/* remotebit - a dentry + remote inode link (i.e. just an ino)
*/
remotebit(const string& d, version_t v, inodeno_t i, unsigned char dt, bool dr) :
dn(d), dnv(v), ino(i), d_type(dt), dirty(dr) { }
- remotebit(bufferlist& bl, int& off) { _decode(bl, off); }
- void _encode(bufferlist& bl) {
- ::_encode(dn, bl);
- ::_encode(dnv, bl);
- ::_encode(ino, bl);
- ::_encode(d_type, bl);
- ::_encode(dirty, bl);
+ remotebit(bufferlist::iterator &p) { decode(p); }
+ remotebit() {}
+
+ void encode(bufferlist& bl) const {
+ ::encode(dn, bl);
+ ::encode(dnv, bl);
+ ::encode(ino, bl);
+ ::encode(d_type, bl);
+ ::encode(dirty, bl);
}
- void _decode(bufferlist& bl, int& off) {
- ::_decode(dn, bl, off);
- ::_decode(dnv, bl, off);
- ::_decode(ino, bl, off);
- ::_decode(d_type, bl, off);
- ::_decode(dirty, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(dn, bl);
+ ::decode(dnv, bl);
+ ::decode(ino, bl);
+ ::decode(d_type, bl);
+ ::decode(dirty, bl);
}
void print(ostream& out) {
out << " remotebit dn " << dn << " dnv " << dnv
<< " dirty=" << dirty << std::endl;
}
};
+ WRITE_CLASS_ENCODERS(remotebit)
/*
* nullbit - a null dentry
string dn;
version_t dnv;
bool dirty;
+
nullbit(const string& d, version_t v, bool dr) : dn(d), dnv(v), dirty(dr) { }
- nullbit(bufferlist& bl, int& off) { _decode(bl, off); }
- void _encode(bufferlist& bl) {
- ::_encode(dn, bl);
- ::_encode(dnv, bl);
- ::_encode(dirty, bl);
+ nullbit(bufferlist::iterator &p) { decode(p); }
+ nullbit() {}
+
+ void encode(bufferlist& bl) const {
+ ::encode(dn, bl);
+ ::encode(dnv, bl);
+ ::encode(dirty, bl);
}
- void _decode(bufferlist& bl, int& off) {
- ::_decode(dn, bl, off);
- ::_decode(dnv, bl, off);
- ::_decode(dirty, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(dn, bl);
+ ::decode(dnv, bl);
+ ::decode(dirty, bl);
}
void print(ostream& out) {
out << " nullbit dn " << dn << " dnv " << dnv
<< " dirty=" << dirty << std::endl;
}
};
+ WRITE_CLASS_ENCODERS(nullbit)
/* dirlump - contains metadata for any dir we have contents for.
int nfull, nremote, nnull;
private:
- bufferlist dnbl;
+ mutable bufferlist dnbl;
bool dn_decoded;
list<fullbit> dfull;
list<remotebit> dremote;
p->print(out);
}
- void _encode_bits() {
- for (list<fullbit>::iterator p = dfull.begin(); p != dfull.end(); ++p)
- p->_encode(dnbl);
- for (list<remotebit>::iterator p = dremote.begin(); p != dremote.end(); ++p)
- p->_encode(dnbl);
- for (list<nullbit>::iterator p = dnull.begin(); p != dnull.end(); ++p)
- p->_encode(dnbl);
+ void _encode_bits() const {
+ ::encode(dfull, dnbl);
+ ::encode(dremote, dnbl);
+ ::encode(dnull, dnbl);
}
void _decode_bits() {
if (dn_decoded) return;
- int off = 0;
- for (int i=0; i<nfull; i++)
- dfull.push_back(fullbit(dnbl, off));
- for (int i=0; i<nremote; i++)
- dremote.push_back(remotebit(dnbl, off));
- for (int i=0; i<nnull; i++)
- dnull.push_back(nullbit(dnbl, off));
+ bufferlist::iterator p = dnbl.begin();
+ ::decode(dfull, p);
+ ::decode(dremote, p);
+ ::decode(dnull, p);
dn_decoded = true;
}
- void _encode(bufferlist& bl) {
- ::_encode(dirv, bl);
- ::_encode(state, bl);
- ::_encode(nfull, bl);
- ::_encode(nremote, bl);
- ::_encode(nnull, bl);
+ void encode(bufferlist& bl) const {
+ ::encode(dirv, bl);
+ ::encode(state, bl);
+ ::encode(nfull, bl);
+ ::encode(nremote, bl);
+ ::encode(nnull, bl);
_encode_bits();
- ::_encode_destructively(dnbl, bl);
+ ::encode(dnbl, bl);
}
- void _decode(bufferlist& bl, int& off) {
- ::_decode(dirv, bl, off);
- ::_decode(state, bl, off);
- ::_decode(nfull, bl, off);
- ::_decode(nremote, bl, off);
- ::_decode(nnull, bl, off);
- ::_decode(dnbl, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(dirv, 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.
}
};
+ WRITE_CLASS_ENCODERS(dirlump)
private:
// my lumps. preserve the order we added them in a list.
// encoding
- void _encode(bufferlist& bl) {
- int32_t n = lump_map.size();
- ::_encode(n, bl);
- for (list<dirfrag_t>::iterator i = lump_order.begin();
- i != lump_order.end();
- ++i) {
- dirfrag_t dirfrag = *i;
- ::_encode(dirfrag, bl);
- lump_map[*i]._encode(bl);
- }
- ::_encode(atids, bl);
- ::_encode(dirty_inode_mtimes, bl);
- ::_encode(allocated_inos, bl);
+ void encode(bufferlist& bl) const {
+ ::encode(lump_map, bl);
+ ::encode(atids, bl);
+ ::encode(dirty_inode_mtimes, bl);
+ ::encode(allocated_inos, bl);
if (!allocated_inos.empty())
- ::_encode(alloc_tablev, bl);
- ::_encode(truncated_inodes, bl);
- ::_encode(client_reqs, bl);
+ ::encode(alloc_tablev, bl);
+ ::encode(truncated_inodes, bl);
+ ::encode(client_reqs, bl);
}
- void _decode(bufferlist& bl, int& off) {
- int32_t n;
- ::_decode(n, bl, off);
- for (int i=0; i<n; i++) {
- dirfrag_t dirfrag;
- ::_decode(dirfrag, bl, off);
- lump_order.push_back(dirfrag);
- lump_map[dirfrag]._decode(bl, off);
- }
- ::_decode(atids, bl, off);
- ::_decode(dirty_inode_mtimes, bl, off);
- ::_decode(allocated_inos, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(lump_map, bl);
+ ::decode(atids, bl);
+ ::decode(dirty_inode_mtimes, bl);
+ ::decode(allocated_inos, bl);
if (!allocated_inos.empty())
- ::_decode(alloc_tablev, bl, off);
- ::_decode(truncated_inodes, bl, off);
- ::_decode(client_reqs, bl, off);
+ ::decode(alloc_tablev, bl);
+ ::decode(truncated_inodes, bl);
+ ::decode(client_reqs, bl);
}
-
+
void print(ostream& out) const {
out << "[metablob";
if (!lump_order.empty())
void update_segment(LogSegment *ls);
void replay(MDS *mds, LogSegment *ls=0);
};
+WRITE_CLASS_ENCODERS(EMetaBlob)
+WRITE_CLASS_ENCODERS(EMetaBlob::fullbit)
+WRITE_CLASS_ENCODERS(EMetaBlob::remotebit)
+WRITE_CLASS_ENCODERS(EMetaBlob::nullbit)
+WRITE_CLASS_ENCODERS(EMetaBlob::dirlump)
inline ostream& operator<<(ostream& out, const EMetaBlob& t) {
t.print(out);
inos.push_back(ino);
}
- void encode_payload(bufferlist& bl) {
- metablob._encode(bl);
- ::_encode(inos, bl);
+ void encode(bufferlist &bl) const {
+ ::encode(metablob, bl);
+ ::encode(inos, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- metablob._decode(bl, off);
- ::_decode(inos, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(metablob, bl);
+ ::decode(inos, bl);
}
void update_segment();
out << "purgefinish " << ino << " " << oldsize << " ->" << newsize;
}
- virtual void encode_payload(bufferlist& bl) {
- bl.append((char*)&ino, sizeof(ino));
- bl.append((char*)&newsize, sizeof(newsize));
- bl.append((char*)&oldsize, sizeof(oldsize));
+ void encode(bufferlist &bl) const {
+ ::encode(ino, bl);
+ ::encode(newsize, bl);
+ ::encode(oldsize, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- ::_decode(ino, bl, off);
- ::_decode(newsize, bl, off);
- ::_decode(oldsize, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(ino, bl);
+ ::decode(newsize, bl);
+ ::decode(oldsize, bl);
}
void update_segment();
cmapv(v) {
}
- void encode_payload(bufferlist& bl) {
- ::_encode(client_inst, bl);
- ::_encode(open, bl);
- ::_encode(cmapv, bl);
+ void encode(bufferlist &bl) const {
+ ::encode(client_inst, bl);
+ ::encode(open, bl);
+ ::encode(cmapv, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- ::_decode(client_inst, bl, off);
- ::_decode(open, bl, off);
- ::_decode(cmapv, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(client_inst, bl);
+ ::decode(open, bl);
+ ::decode(cmapv, bl);
}
cmapv(v) {
}
- void encode_payload(bufferlist& bl) {
- ::_encode(client_map, bl);
- ::_encode(cmapv, bl);
+ void encode(bufferlist &bl) const {
+ ::encode(client_map, bl);
+ ::encode(cmapv, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- ::_decode(client_map, bl, off);
- ::_decode(cmapv, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(client_map, bl);
+ ::decode(cmapv, bl);
}
out << commit << " " << rollback;
}
- void encode_payload(bufferlist& bl) {
- ::_encode(type, bl);
- ::_encode(reqid, bl);
- ::_encode(master, bl);
- ::_encode(op, bl);
- commit._encode(bl);
- rollback._encode(bl);
+ void encode(bufferlist &bl) const {
+ ::encode(type, bl);
+ ::encode(reqid, bl);
+ ::encode(master, bl);
+ ::encode(op, bl);
+ ::encode(commit, bl);
+ ::encode(rollback, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- ::_decode(type, bl, off);
- ::_decode(reqid, bl, off);
- ::_decode(master, bl, off);
- ::_decode(op, bl, off);
- commit._decode(bl, off);
- rollback._decode(bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(type, bl);
+ ::decode(reqid, bl);
+ ::decode(master, bl);
+ ::decode(op, bl);
+ ::decode(commit, bl);
+ ::decode(rollback, bl);
}
void replay(MDS *mds);
LogEvent(EVENT_STRING) {
}
- void decode_payload(bufferlist& bl, int& off) {
- ::_decode(event, bl, off);
+ void encode(bufferlist& bl) const {
+ ::encode(event, bl);
}
- void encode_payload(bufferlist& bl) {
- ::_encode(event, bl);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(event, bl);
}
void print(ostream& out) {
<< metablob;
}
- void encode_payload(bufferlist& bl) {
- metablob._encode(bl);
- ::_encode(subtrees, bl);
+ void encode(bufferlist& bl) const {
+ ::encode(metablob, bl);
+ ::encode(subtrees, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- metablob._decode(bl, off);
- ::_decode(subtrees, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(metablob, bl);
+ ::decode(subtrees, bl);
}
void replay(MDS *mds);
out << metablob;
}
- void encode_payload(bufferlist& bl) {
- ::_encode(type, bl);
- metablob._encode(bl);
- ::_encode(client_map, bl);
+ void encode(bufferlist &bl) const {
+ ::encode(type, bl);
+ ::encode(metablob, bl);
+ ::encode(client_map, bl);
}
- void decode_payload(bufferlist& bl, int& off) {
- ::_decode(type, bl, off);
- metablob._decode(bl, off);
- ::_decode(client_map, bl, off);
+ void decode(bufferlist::iterator &bl) {
+ ::decode(type, bl);
+ ::decode(metablob, bl);
+ ::decode(client_map, bl);
}
void update_segment();
version_t get_atid() { return atid; }
virtual void decode_payload() {
- int off = 0;
- payload.copy(off, sizeof(op), (char*)&op);
- off += sizeof(op);
- payload.copy(off, sizeof(ino), (char*)&ino);
- off += sizeof(ino);
- payload.copy(off, sizeof(atid), (char*)&atid);
- off += sizeof(atid);
- ::_decode(trace, payload, off);
+ bufferlist::iterator p = payload.begin();
+ ::decode(op, p);
+ ::decode(ino, p);
+ ::decode(atid, p);
+ ::decode(trace, p);
}
virtual void encode_payload() {
- payload.append((char*)&op, sizeof(op));
- payload.append((char*)&ino, sizeof(ino));
- payload.append((char*)&atid, sizeof(atid));
- ::_encode(trace, payload);
+ ::encode(op, payload);
+ ::encode(ino, payload);
+ ::encode(atid, payload);
+ ::encode(trace, payload);
}
};
map<inodeno_t, int> inodes;
map<dirfrag_t, int> dirs;
map<dirfrag_t, map<string,int> > dentries;
+
+ void encode(bufferlist &bl) const {
+ ::encode(inodes, bl);
+ ::encode(dirs, bl);
+ ::encode(dentries, bl);
+ }
+ void decode(bufferlist::iterator &bl) {
+ ::decode(inodes, bl);
+ ::decode(dirs, bl);
+ ::decode(dentries, bl);
+ }
};
+ WRITE_CLASS_ENCODERS(realm)
+
map<dirfrag_t, realm> realms;
int get_from() { return from; }
}
void decode_payload() {
- int off = 0;
-
- payload.copy(off, sizeof(from), (char*)&from);
- off += sizeof(from);
-
- int nr;
- payload.copy(off, sizeof(nr), (char*)&nr);
- off += sizeof(nr);
-
- while (nr--) {
- dirfrag_t r;
- payload.copy(off, sizeof(r), (char*)&r);
- off += sizeof(r);
-
- ::_decode(realms[r].inodes, payload, off);
- ::_decode(realms[r].dirs, payload, off);
-
- int n;
- payload.copy(off, sizeof(int), (char*)&n);
- off += sizeof(int);
- for (int i=0; i<n; i++) {
- dirfrag_t df;
- payload.copy(off, sizeof(df), (char*)&df);
- off += sizeof(df);
- ::_decode(realms[r].dentries[df], payload, off);
- }
- }
+ bufferlist::iterator p = payload.begin();
+ ::decode(from, p);
+ ::decode(realms, p);
}
void encode_payload() {
- payload.append((char*)&from, sizeof(from));
-
- int nr = realms.size();
- payload.append((char*)&nr, sizeof(nr));
-
- for (map<dirfrag_t,realm>::iterator q = realms.begin();
- q != realms.end();
- ++q) {
- payload.append((char*)&q->first, sizeof(q->first));
-
- ::_encode(q->second.inodes, payload);
- ::_encode(q->second.dirs, payload);
-
- int n = q->second.dentries.size();
- payload.append((char*)&n, sizeof(n));
- for (map<dirfrag_t, map<string,int> >::iterator p = q->second.dentries.begin();
- p != q->second.dentries.end();
- ++p) {
- payload.append((char*)&p->first, sizeof(p->first));
- ::_encode(p->second, payload);
- }
- }
+ ::encode(from, payload);
+ ::encode(realms, payload);
}
};
+WRITE_CLASS_ENCODERS(MCacheExpire::realm)
+
#endif
}
void decode_payload() {
- int off = 0;
- payload.copy(off, sizeof(dirfrag), (char*)&dirfrag);
- off += sizeof(dirfrag);
- ::_decode(dn, payload, off);
+ bufferlist::iterator p = payload.begin();
+ ::decode(dirfrag, p);
+ ::decode(dn, p);
bool isstray;
- payload.copy(off, sizeof(isstray), (char*)&isstray);
- off += sizeof(isstray);
+ ::decode(isstray, p);
if (isstray) {
- strayin = new CInodeDiscover;
- strayin->_decode(payload, off);
- straydir = new CDirDiscover;
- straydir->_decode(payload, off);
- straydn = new CDentryDiscover;
- straydn->_decode(payload, off);
+ strayin = new CInodeDiscover(p);
+ straydir = new CDirDiscover(p);
+ straydn = new CDentryDiscover(p);
}
}
void encode_payload() {
- payload.append((char*)&dirfrag,sizeof(dirfrag));
- ::_encode(dn, payload);
+ ::encode(dirfrag, payload);
+ ::encode(dn, payload);
bool isstray = strayin ? true:false;
- payload.append((char*)&isstray, sizeof(isstray));
+ ::encode(isstray, payload);
if (isstray) {
- strayin->_encode(payload);
- straydir->_encode(payload);
- straydn->_encode(payload);
+ strayin->encode(payload);
+ straydir->encode(payload);
+ straydn->encode(payload);
}
}
};
// ...
virtual void decode_payload() {
- int off = 0;
- ::_decode(base_ino, payload, off);
- ::_decode(base_dir_frag, payload, off);
- ::_decode(wanted_base_dir, payload, off);
- ::_decode(wanted_xlocked, payload, off);
- ::_decode(flag_error_dn, payload, off);
- ::_decode(flag_error_ino, payload, off);
- ::_decode(flag_error_dir, payload, off);
- ::_decode(no_base_dir, payload, off);
- ::_decode(no_base_dentry, payload, off);
- ::_decode(error_dentry, payload, off);
- ::_decode(dir_auth_hint, payload, off);
+ bufferlist::iterator p = payload.begin();
+ ::decode(base_ino, p);
+ ::decode(base_dir_frag, p);
+ ::decode(wanted_base_dir, p);
+ ::decode(wanted_xlocked, p);
+ ::decode(flag_error_dn, p);
+ ::decode(flag_error_ino, p);
+ ::decode(flag_error_dir, p);
+ ::decode(no_base_dir, p);
+ ::decode(no_base_dentry, p);
+ ::decode(error_dentry, p);
+ ::decode(dir_auth_hint, p);
- // dirs
- int n;
- payload.copy(off, sizeof(int), (char*)&n);
- off += sizeof(int);
- for (int i=0; i<n; i++) {
- dirs.push_back( new CDirDiscover() );
- dirs[i]->_decode(payload, off);
- }
-
- // inodes
- payload.copy(off, sizeof(int), (char*)&n);
- off += sizeof(int);
- for (int i=0; i<n; i++) {
- inodes.push_back( new CInodeDiscover() );
- inodes[i]->_decode(payload, off);
- }
-
- // dentries
- payload.copy(off, sizeof(int), (char*)&n);
- off += sizeof(int);
- for (int i=0; i<n; i++) {
- dentries.push_back( new CDentryDiscover() );
- dentries[i]->_decode(payload, off);
- }
+ ::decode(dirs, p);
+ ::decode(inodes, p);
+ ::decode(dentries, p);
}
void encode_payload() {
- ::_encode(base_ino, payload);
- ::_encode(base_dir_frag, payload);
- ::_encode(wanted_base_dir, payload);
- ::_encode(wanted_xlocked, payload);
- ::_encode(flag_error_dn, payload);
- ::_encode(flag_error_ino, payload);
- ::_encode(flag_error_dir, payload);
- ::_encode(no_base_dir, payload);
- ::_encode(no_base_dentry, payload);
- ::_encode(error_dentry, payload);
- ::_encode(dir_auth_hint, payload);
-
- // dirs
- int n = dirs.size();
- payload.append((char*)&n, sizeof(int));
- for (vector<CDirDiscover*>::iterator it = dirs.begin();
- it != dirs.end();
- it++)
- (*it)->_encode( payload );
-
- // inodes
- n = inodes.size();
- payload.append((char*)&n, sizeof(int));
- for (vector<CInodeDiscover*>::iterator it = inodes.begin();
- it != inodes.end();
- it++)
- (*it)->_encode( payload );
-
- // dentries
- n = dentries.size();
- payload.append((char*)&n, sizeof(int));
- for (vector<CDentryDiscover*>::iterator it = dentries.begin();
- it != dentries.end();
- it++)
- (*it)->_encode( payload );
+ ::encode(base_ino, payload);
+ ::encode(base_dir_frag, payload);
+ ::encode(wanted_base_dir, payload);
+ ::encode(wanted_xlocked, payload);
+ ::encode(flag_error_dn, payload);
+ ::encode(flag_error_ino, payload);
+ ::encode(flag_error_dir, payload);
+ ::encode(no_base_dir, payload);
+ ::encode(no_base_dentry, payload);
+ ::encode(error_dentry, payload);
+ ::encode(dir_auth_hint, payload);
+
+ ::encode(dirs, payload);
+ ::encode(inodes, payload);
+ ::encode(dentries, payload);
}
};
}
virtual void decode_payload() {
- int off = 0;
- payload.copy(off, sizeof(dirfrag), (char*)&dirfrag);
- off += sizeof(dirfrag);
-
- ::_decode(bounds, payload, off);
-
- // inodes
- int ni;
- payload.copy(off, sizeof(int), (char*)&ni);
- off += sizeof(int);
- for (int i=0; i<ni; i++) {
- // inode
- CInodeDiscover *in = new CInodeDiscover;
- in->_decode(payload, off);
- inodes.push_back(in);
-
- // dentry
- CDentryDiscover *dn = new CDentryDiscover;
- dn->_decode(payload, off);
- dentries.push_back(dn);
-
- // dentry
- string d;
- _decode(d, payload, off);
- inode_dentry[in->get_ino()] = d;
-
- // dir ino
- dirfrag_t df;
- payload.copy(off, sizeof(df), (char*)&df);
- off += sizeof(df);
- inode_dirfrag[in->get_ino()] = df;
-
- // child frags
- ::_decode(frags_by_ino[in->get_ino()], payload, off);
- }
-
- // dirs
- int nd;
- payload.copy(off, sizeof(int), (char*)&nd);
- off += sizeof(int);
- for (int i=0; i<nd; i++) {
- CDirDiscover *dir = new CDirDiscover;
- dir->_decode(payload, off);
- dirfrags[dir->get_dirfrag()] = dir;
- }
-
- ::_decode(bystanders, payload, off);
+ bufferlist::iterator p = payload.begin();
+ ::decode(dirfrag, p);
+ ::decode(bounds, p);
+ ::decode(inodes, p);
+ ::decode(dentries, p);
+ ::decode(inode_dirfrag, p);
+ ::decode(inode_dentry, p);
+ ::decode(frags_by_ino, p);
+ ::decode(dirfrags, p);
+ ::decode(bystanders, p);
}
virtual void encode_payload() {
- payload.append((char*)&dirfrag, sizeof(dirfrag));
-
- ::_encode(bounds, payload);
-
- // inodes
- int ni = inodes.size();
- payload.append((char*)&ni, sizeof(int));
- list<CDentryDiscover*>::iterator dit = dentries.begin();
- list<CInodeDiscover*>::iterator iit = inodes.begin();
- while (iit != inodes.end()) {
- (*iit)->_encode(payload);
- (*dit)->_encode(payload);
-
- // dentry name
- _encode(inode_dentry[(*iit)->get_ino()], payload);
-
- // dir ino
- dirfrag_t df = inode_dirfrag[(*iit)->get_ino()];
- payload.append((char*)&df, sizeof(df));
-
- // child frags
- ::_encode(frags_by_ino[(*iit)->get_ino()], payload);
-
- iit++;
- dit++;
- }
-
- // dirs
- int nd = dirfrags.size();
- payload.append((char*)&nd, sizeof(int));
- for (map<dirfrag_t,CDirDiscover*>::iterator dit = dirfrags.begin();
- dit != dirfrags.end();
- dit++)
- dit->second->_encode(payload);
-
- ::_encode(bystanders, payload);
+ ::encode(dirfrag, payload);
+ ::encode(bounds, payload);
+ ::encode(inodes, payload);
+ ::encode(dentries, payload);
+ ::encode(inode_dirfrag, payload);
+ ::encode(inode_dentry, payload);
+ ::encode(frags_by_ino, payload);
+ ::encode(dirfrags, payload);
+ ::encode(bystanders, payload);
}
};
void decode(bufferlist::iterator& p) {
::decode(inode, p);
::decode(symlink, p);
- dirfragtree._decode(p);
+ ::decode(dirfragtree, p);
}
void encode(bufferlist& bl) const {
::encode(inode, bl);
::encode(symlink, bl);
- dirfragtree._encode(bl);
+ ::encode(dirfragtree, bl);
}
};
WRITE_CLASS_ENCODERS(inode_full)