From: John Spray Date: Mon, 19 May 2014 14:08:33 +0000 (+0100) Subject: mds: Make EMetaBlob::dirlump::_decode_bits const X-Git-Tag: v0.82~48^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bac434de0cc9edaf06d987722e10ba87aaab4892;p=ceph.git mds: Make EMetaBlob::dirlump::_decode_bits const This requires making the late-decoded attributes mutable. The motivation is to allow get_paths and all the code downstream of that to be const too. Signed-off-by: John Spray --- diff --git a/src/mds/LogEvent.h b/src/mds/LogEvent.h index 1152ade84765..67c22e75233f 100644 --- a/src/mds/LogEvent.h +++ b/src/mds/LogEvent.h @@ -115,7 +115,7 @@ public: * If the subclass embeds a MetaBlob, return it here so that * tools can examine metablobs while traversing lists of LogEvent. */ - virtual EMetaBlob *get_metablob() {return NULL;} + virtual EMetaBlob const *get_metablob() const {return NULL;} }; inline ostream& operator<<(ostream& out, LogEvent& le) { diff --git a/src/mds/events/EMetaBlob.h b/src/mds/events/EMetaBlob.h index 22c5c4e6f5ea..b70dc534a0d2 100644 --- a/src/mds/events/EMetaBlob.h +++ b/src/mds/events/EMetaBlob.h @@ -202,10 +202,10 @@ public: private: mutable bufferlist dnbl; - bool dn_decoded; - list > dfull; - list dremote; - list dnull; + mutable bool dn_decoded; + mutable list > dfull; + mutable list dremote; + mutable list dnull; public: dirlump() : state(0), nfull(0), nremote(0), nnull(0), dn_decoded(true) { } @@ -221,9 +221,13 @@ public: bool is_dirty_dft() { return state & STATE_DIRTYDFT; } void mark_dirty_dft() { state |= STATE_DIRTYDFT; } - list > &get_dfull() { return dfull; } - list &get_dremote() { return dremote; } - list &get_dnull() { return dnull; } + const list > &get_dfull() const { return dfull; } + const list &get_dremote() const { return dremote; } + const list &get_dnull() const { return dnull; } + + void add_dnull(nullbit const &n) { dnull.push_back(n); }; + void add_dfull(ceph::shared_ptr const &p) { dfull.push_back(p); }; + void add_dremote(remotebit const &r) { dremote.push_back(r); }; void print(dirfrag_t dirfrag, ostream& out) { out << "dirlump " << dirfrag << " v " << fnode.version @@ -263,7 +267,7 @@ public: ::encode(dremote, dnbl); ::encode(dnull, dnbl); } - void _decode_bits() { + void _decode_bits() const { if (dn_decoded) return; bufferlist::iterator p = dnbl.begin(); ::decode(dfull, p); @@ -313,9 +317,9 @@ private: public: void encode(bufferlist& bl) const; void decode(bufferlist::iterator& bl); - void get_inodes(std::set &inodes); - void get_paths(std::vector &paths); - void get_dentries(std::map > &dentries); + void get_inodes(std::set &inodes) const; + void get_paths(std::vector &paths) const; + void get_dentries(std::map > &dentries) const; entity_name_t get_client_name() const {return client_name;} void dump(Formatter *f) const; @@ -381,10 +385,10 @@ private: void add_null_dentry(dirlump& lump, CDentry *dn, bool dirty) { // add the dir lump.nnull++; - lump.get_dnull().push_back(nullbit(dn->get_name(), - dn->first, dn->last, - dn->get_projected_version(), - dirty)); + lump.add_dnull(nullbit(dn->get_name(), + dn->first, dn->last, + dn->get_projected_version(), + dirty)); } void add_remote_dentry(CDentry *dn, bool dirty) { @@ -400,11 +404,11 @@ private: rdt = dn->get_projected_linkage()->get_remote_d_type(); } lump.nremote++; - lump.get_dremote().push_back(remotebit(dn->get_name(), - dn->first, dn->last, - dn->get_projected_version(), - rino, rdt, - dirty)); + lump.add_dremote(remotebit(dn->get_name(), + dn->first, dn->last, + dn->get_projected_version(), + rino, rdt, + dirty)); } // return remote pointer to to-be-journaled inode @@ -434,14 +438,14 @@ private: sr->encode(snapbl); lump.nfull++; - lump.get_dfull().push_back(ceph::shared_ptr(new fullbit(dn->get_name(), - dn->first, dn->last, - dn->get_projected_version(), - *pi, in->dirfragtree, - *in->get_projected_xattrs(), - in->symlink, snapbl, - state, - &in->old_inodes))); + lump.add_dfull(ceph::shared_ptr(new fullbit(dn->get_name(), + dn->first, dn->last, + dn->get_projected_version(), + *pi, in->dirfragtree, + *in->get_projected_xattrs(), + in->symlink, snapbl, + state, + &in->old_inodes))); } // convenience: primary or remote? figure it out. diff --git a/src/mds/events/EOpen.h b/src/mds/events/EOpen.h index baf93344a230..d1c41558b40a 100644 --- a/src/mds/events/EOpen.h +++ b/src/mds/events/EOpen.h @@ -49,7 +49,7 @@ public: void update_segment(); void replay(MDS *mds); - EMetaBlob *get_metablob() {return &metablob;} + EMetaBlob const *get_metablob() const {return &metablob;} }; #endif diff --git a/src/mds/events/EUpdate.h b/src/mds/events/EUpdate.h index d0be0a4f28bc..d6d82410c14d 100644 --- a/src/mds/events/EUpdate.h +++ b/src/mds/events/EUpdate.h @@ -45,7 +45,7 @@ public: void update_segment(); void replay(MDS *mds); - EMetaBlob *get_metablob() {return &metablob;} + EMetaBlob const *get_metablob() const {return &metablob;} }; #endif diff --git a/src/mds/journal.cc b/src/mds/journal.cc index 9f2829f36d56..5a3d1045b497 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -821,27 +821,27 @@ void EMetaBlob::decode(bufferlist::iterator &bl) * dirlumps, and the inodes of the dirs themselves. */ void EMetaBlob::get_inodes( - std::set &inodes) + std::set &inodes) const { // For all dirlumps in this metablob - for (std::map::iterator i = lump_map.begin(); i != lump_map.end(); ++i) { + for (std::map::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { // Record inode of dirlump inodeno_t const dir_ino = i->first.ino; inodes.insert(dir_ino); // Decode dirlump bits - dirlump &dl = i->second; + dirlump const &dl = i->second; dl._decode_bits(); // Record inodes of fullbits - list > &fb_list = dl.get_dfull(); + list > const &fb_list = dl.get_dfull(); for (list >::const_iterator iter = fb_list.begin(); iter != fb_list.end(); ++iter) { inodes.insert((*iter)->inode.ino); } // Record inodes of remotebits - list &rb_list = dl.get_dremote(); + list const &rb_list = dl.get_dremote(); for (list::const_iterator iter = rb_list.begin(); iter != rb_list.end(); ++iter) { inodes.insert(iter->ino); @@ -854,17 +854,17 @@ void EMetaBlob::get_inodes( * Get a map of dirfrag to set of dentries in that dirfrag which are * touched in this operation. */ -void EMetaBlob::get_dentries(std::map > &dentries) +void EMetaBlob::get_dentries(std::map > &dentries) const { - for (std::map::iterator i = lump_map.begin(); i != lump_map.end(); ++i) { - dirlump &dl = i->second; + for (std::map::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { + dirlump const &dl = i->second; dirfrag_t const &df = i->first; // Get all bits dl._decode_bits(); - list > &fb_list = dl.get_dfull(); - list &nb_list = dl.get_dnull(); - list &rb_list = dl.get_dremote(); + list > const &fb_list = dl.get_dfull(); + list const &nb_list = dl.get_dnull(); + list const &rb_list = dl.get_dremote(); // For all bits, store dentry for (list >::const_iterator @@ -889,12 +889,9 @@ void EMetaBlob::get_dentries(std::map > &dentri * Calculate all paths that we can infer are touched by this metablob. Only uses * information local to this metablob so it may only be the path within the * subtree. - * - * This is not const because the contained dirlump and 'bit' objects - * are modified by being decoded. */ void EMetaBlob::get_paths( - std::vector &paths) + std::vector &paths) const { // Each dentry has a 'location' which is a 2-tuple of parent inode and dentry name typedef std::pair Location; @@ -916,14 +913,14 @@ void EMetaBlob::get_paths( // First pass // ========== // Build a tiny local metadata cache for the path structure in this metablob - for (std::map::iterator i = lump_map.begin(); i != lump_map.end(); ++i) { + for (std::map::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { inodeno_t const dir_ino = i->first.ino; - dirlump &dl = i->second; + dirlump const &dl = i->second; dl._decode_bits(); - list > &fb_list = dl.get_dfull(); - list &nb_list = dl.get_dnull(); - list &rb_list = dl.get_dremote(); + list > const &fb_list = dl.get_dfull(); + list const &nb_list = dl.get_dnull(); + list const &rb_list = dl.get_dremote(); for (list >::const_iterator iter = fb_list.begin(); iter != fb_list.end(); ++iter) { @@ -950,12 +947,12 @@ void EMetaBlob::get_paths( // Second pass // =========== // Output paths for all childless nodes in the metablob - for (std::map::iterator i = lump_map.begin(); i != lump_map.end(); ++i) { + for (std::map::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { inodeno_t const dir_ino = i->first.ino; - dirlump &dl = i->second; + dirlump const &dl = i->second; dl._decode_bits(); - list > &fb_list = dl.get_dfull(); + list > const &fb_list = dl.get_dfull(); for (list >::const_iterator iter = fb_list.begin(); iter != fb_list.end(); ++iter) { std::string const &dentry = (*iter)->dn; @@ -967,14 +964,14 @@ void EMetaBlob::get_paths( } } - list &nb_list = dl.get_dnull(); + list const &nb_list = dl.get_dnull(); for (list::const_iterator iter = nb_list.begin(); iter != nb_list.end(); ++iter) { std::string const &dentry = iter->dn; leaf_locations.push_back(Location(dir_ino, dentry)); } - list &rb_list = dl.get_dremote(); + list const &rb_list = dl.get_dremote(); for (list::const_iterator iter = rb_list.begin(); iter != rb_list.end(); ++iter) { std::string const &dentry = iter->dn; @@ -1215,7 +1212,7 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg, MDSlaveUpdate *slaveup) lump._decode_bits(); // full dentry+inode pairs - for (list >::iterator pp = lump.get_dfull().begin(); + for (list >::const_iterator pp = lump.get_dfull().begin(); pp != lump.get_dfull().end(); ++pp) { ceph::shared_ptr p = *pp; @@ -1296,7 +1293,7 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg, MDSlaveUpdate *slaveup) } // remote dentries - for (list::iterator p = lump.get_dremote().begin(); + for (list::const_iterator p = lump.get_dremote().begin(); p != lump.get_dremote().end(); ++p) { CDentry *dn = dir->lookup_exact_snap(p->dn, p->dnlast); @@ -1329,7 +1326,7 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg, MDSlaveUpdate *slaveup) } // null dentries - for (list::iterator p = lump.get_dnull().begin(); + for (list::const_iterator p = lump.get_dnull().begin(); p != lump.get_dnull().end(); ++p) { CDentry *dn = dir->lookup_exact_snap(p->dn, p->dnlast); diff --git a/src/tools/cephfs/EventOutput.cc b/src/tools/cephfs/EventOutput.cc index c762558a4cd1..63cb574521d4 100644 --- a/src/tools/cephfs/EventOutput.cc +++ b/src/tools/cephfs/EventOutput.cc @@ -73,7 +73,7 @@ void EventOutput::list() const { for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) { std::vector ev_paths; - EMetaBlob *emb = i->second.log_event->get_metablob(); + EMetaBlob const *emb = i->second.log_event->get_metablob(); if (emb) { emb->get_paths(ev_paths); } diff --git a/src/tools/cephfs/JournalFilter.cc b/src/tools/cephfs/JournalFilter.cc index 929925289599..9bd766fd183d 100644 --- a/src/tools/cephfs/JournalFilter.cc +++ b/src/tools/cephfs/JournalFilter.cc @@ -48,7 +48,7 @@ bool JournalFilter::apply(uint64_t pos, LogEvent &le) const /* Filtering by client */ if (client_name.num()) { - EMetaBlob *metablob = le.get_metablob(); + EMetaBlob const *metablob = le.get_metablob(); if (metablob) { if (metablob->get_client_name() != client_name) { return false; @@ -65,7 +65,7 @@ bool JournalFilter::apply(uint64_t pos, LogEvent &le) const /* Filtering by inode */ if (inode) { - EMetaBlob *metablob = le.get_metablob(); + EMetaBlob const *metablob = le.get_metablob(); if (metablob) { std::set inodes; metablob->get_inodes(inodes); @@ -86,7 +86,7 @@ bool JournalFilter::apply(uint64_t pos, LogEvent &le) const /* Filtering by frag and dentry */ if (!frag_dentry.empty() || frag.ino) { - EMetaBlob *metablob = le.get_metablob(); + EMetaBlob const *metablob = le.get_metablob(); if (metablob) { std::map > dentries; metablob->get_dentries(dentries); @@ -129,7 +129,7 @@ bool JournalFilter::apply(uint64_t pos, LogEvent &le) const /* Filtering by file path */ if (!path_expr.empty()) { - EMetaBlob *metablob = le.get_metablob(); + EMetaBlob const *metablob = le.get_metablob(); if (metablob) { std::vector paths; metablob->get_paths(paths); diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index b04c2befc038..0a1a1b2f1105 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -325,7 +325,7 @@ int JournalTool::main_event(std::vector &argv) for (JournalScanner::EventMap::iterator i = js.events.begin(); i != js.events.end(); ++i) { LogEvent *le = i->second.log_event; - EMetaBlob *mb = le->get_metablob(); + EMetaBlob const *mb = le->get_metablob(); if (mb) { replay_offline(*mb, dry_run); } @@ -476,13 +476,13 @@ int JournalTool::journal_reset() } -int JournalTool::replay_offline(EMetaBlob &metablob, bool const dry_run) +int JournalTool::replay_offline(EMetaBlob const &metablob, bool const dry_run) { int r; // Replay roots - for (list >::iterator p = metablob.roots.begin(); p != metablob.roots.end(); ++p) { - EMetaBlob::fullbit &fb = *(*p); + for (list >::const_iterator p = metablob.roots.begin(); p != metablob.roots.end(); ++p) { + EMetaBlob::fullbit const &fb = *(*p); inodeno_t ino = fb.inode.ino; dout(4) << __func__ << ": updating root 0x" << std::hex << ino << std::dec << dendl; @@ -534,9 +534,9 @@ int JournalTool::replay_offline(EMetaBlob &metablob, bool const dry_run) // indicate renamed directories) // Replay fullbits (dentry+inode) - for (list::iterator lp = metablob.lump_order.begin(); lp != metablob.lump_order.end(); ++lp) { - dirfrag_t &frag = *lp; - EMetaBlob::dirlump &lump = metablob.lump_map[frag]; + for (list::const_iterator lp = metablob.lump_order.begin(); lp != metablob.lump_order.end(); ++lp) { + dirfrag_t const &frag = *lp; + EMetaBlob::dirlump const &lump = metablob.lump_map.find(frag)->second; lump._decode_bits(); object_t frag_object_id = InodeStore::get_object_name(frag.ino, frag.frag, ""); @@ -565,9 +565,9 @@ int JournalTool::replay_offline(EMetaBlob &metablob, bool const dry_run) } // Try to get the existing dentry - list > &fb_list = lump.get_dfull(); - for (list >::iterator fbi = fb_list.begin(); fbi != fb_list.end(); ++fbi) { - EMetaBlob::fullbit &fb = *(*fbi); + list > const &fb_list = lump.get_dfull(); + for (list >::const_iterator fbi = fb_list.begin(); fbi != fb_list.end(); ++fbi) { + EMetaBlob::fullbit const &fb = *(*fbi); // Get a key like "foobar_head" std::string key; @@ -612,7 +612,7 @@ int JournalTool::replay_offline(EMetaBlob &metablob, bool const dry_run) } } - list &nb_list = lump.get_dnull(); + list const &nb_list = lump.get_dnull(); for (list::const_iterator iter = nb_list.begin(); iter != nb_list.end(); ++iter) { EMetaBlob::nullbit const &nb = *iter; @@ -633,7 +633,7 @@ int JournalTool::replay_offline(EMetaBlob &metablob, bool const dry_run) } } - for (std::vector::iterator i = metablob.destroyed_inodes.begin(); + for (std::vector::const_iterator i = metablob.destroyed_inodes.begin(); i != metablob.destroyed_inodes.end(); ++i) { dout(4) << "Destroyed inode: " << *i << dendl; // TODO: if it was a dir, then delete its dirfrag objects diff --git a/src/tools/cephfs/JournalTool.h b/src/tools/cephfs/JournalTool.h index 1c5745493f95..759876674ace 100644 --- a/src/tools/cephfs/JournalTool.h +++ b/src/tools/cephfs/JournalTool.h @@ -55,7 +55,7 @@ class JournalTool : public MDSUtility librados::IoCtx io; // Metadata backing store manipulation - int replay_offline(EMetaBlob &metablob, bool const dry_run); + int replay_offline(EMetaBlob const &metablob, bool const dry_run); // Splicing int erase_region(JournalScanner const &jp, uint64_t const pos, uint64_t const length);