From 1d20e73dad9ca95c24adb0a73bb6cd9d19c2c810 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 15 Sep 2008 16:01:07 -0700 Subject: [PATCH] objectstore: clonerange, list->vector encoding --- src/os/ObjectStore.h | 97 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 7ee51f404fff1..6881eda75e9a0 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -31,8 +31,8 @@ #include /* or */ #endif /* DARWIN */ -#include -using std::list; +#include +using std::vector; #ifndef MIN # define MIN(a,b) ((a) < (b) ? (a):(b)) @@ -76,16 +76,17 @@ public: */ class Transaction { public: - static const int OP_WRITE = 10; // oid, offset, len, bl - static const int OP_ZERO = 11; // oid, offset, len - static const int OP_TRUNCATE = 12; // oid, len - static const int OP_REMOVE = 13; // oid - static const int OP_SETATTR = 14; // oid, attrname, bl - static const int OP_SETATTRS = 15; // oid, attrset - static const int OP_RMATTR = 16; // oid, attrname - static const int OP_CLONE = 17; // oid, newoid - - static const int OP_TRIMCACHE = 18; // oid, offset, len + static const int OP_WRITE = 10; // cid, oid, offset, len, bl + static const int OP_ZERO = 11; // cid, oid, offset, len + static const int OP_TRUNCATE = 12; // cid, oid, len + static const int OP_REMOVE = 13; // cid, oid + static const int OP_SETATTR = 14; // cid, oid, attrname, bl + static const int OP_SETATTRS = 15; // cid, oid, attrset + static const int OP_RMATTR = 16; // cid, oid, attrname + static const int OP_CLONE = 17; // cid, oid, newoid + static const int OP_CLONERANGE = 18; // cid, oid, newoid, offset, len + + static const int OP_TRIMCACHE = 19; // cid, oid, offset, len static const int OP_MKCOLL = 20; // cid static const int OP_RMCOLL = 21; // cid @@ -98,55 +99,49 @@ public: private: int len; int blen; // for btrfs transactions - list ops; - list bls; - list oids; - list cids; - list lengths; + vector ops; + vector bls; + vector oids; + vector cids; + vector lengths; // for these guys, just use a pointer. // but, decode to a full value, and create pointers to that. - list attrnames; - list attrnames2; - list *> attrsets; - list > attrsets2; + vector attrnames; + vector attrnames2; + vector *> attrsets; + vector > attrsets2; + + unsigned opp, blp, oidp, cidp, lengthp, attrnamep, attrsetp; public: int get_len() { return len ? len : ops.size(); } int get_btrfs_len() { return blen; } bool have_op() { - return !ops.empty(); + return opp < ops.size(); } int get_num_ops() { return ops.size(); } int get_op() { - int op = ops.front(); - ops.pop_front(); - return op; + return ops[opp++]; } void get_bl(bufferlist& bl) { - bl.claim(bls.front()); - bls.pop_front(); + bl = bls[blp++]; } void get_oid(pobject_t& oid) { - oid = oids.front(); - oids.pop_front(); + oid = oids[oidp++]; } void get_cid(coll_t& cid) { - cid = cids.front(); - cids.pop_front(); + cid = cids[cidp++]; } void get_length(__u64& len) { - len = lengths.front(); - lengths.pop_front(); + len = lengths[lengthp++]; } void get_attrname(const char * &p) { - p = attrnames.front(); - attrnames.pop_front(); + p = attrnames[attrnamep++]; } void get_pattrset(map* &ps) { - ps = attrsets.front(); - attrsets.pop_front(); + ps = attrsets[attrsetp++]; } void write(coll_t cid, pobject_t oid, __u64 off, size_t len, const bufferlist& bl) { @@ -238,6 +233,17 @@ public: len++; blen += 5; } + void clone_range(coll_t cid, pobject_t oid, pobject_t noid, __u64 off, __u64 len) { + int op = OP_CLONERANGE; + ops.push_back(op); + cids.push_back(cid); + oids.push_back(oid); + oids.push_back(noid); + lengths.push_back(off); + lengths.push_back(len); + len++; + blen += 5; + } void create_collection(coll_t cid) { int op = OP_MKCOLL; ops.push_back(op); @@ -303,9 +309,16 @@ public: // etc. - Transaction() : len(0) {} - Transaction(bufferlist::iterator &p) : len(0) { decode(p); } - Transaction(bufferlist &bl) : len(0) { + Transaction() : + len(0), + opp(0), blp(0), oidp(0), cidp(0), lengthp(0), attrnamep(0), attrsetp(0) {} + Transaction(bufferlist::iterator &p) : + len(0), + opp(0), blp(0), oidp(0), cidp(0), lengthp(0), attrnamep(0), attrsetp(0) + { decode(p); } + Transaction(bufferlist &bl) : + len(0), + opp(0), blp(0), oidp(0), cidp(0), lengthp(0), attrnamep(0), attrsetp(0) { bufferlist::iterator p = bl.begin(); decode(p); } @@ -326,12 +339,12 @@ public: ::decode(cids, bl); ::decode(lengths, bl); ::decode(attrnames2, bl); - for (list::iterator p = attrnames2.begin(); + for (vector::iterator p = attrnames2.begin(); p != attrnames2.end(); ++p) attrnames.push_back((*p).c_str()); ::decode(attrsets2, bl); - for (list >::iterator p = attrsets2.begin(); + for (vector >::iterator p = attrsets2.begin(); p != attrsets2.end(); ++p) attrsets.push_back(&(*p)); -- 2.39.5