]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: Make EMetaBlob::dirlump::_decode_bits const
authorJohn Spray <john.spray@inktank.com>
Mon, 19 May 2014 14:08:33 +0000 (15:08 +0100)
committerJohn Spray <john.spray@inktank.com>
Tue, 20 May 2014 13:07:52 +0000 (14:07 +0100)
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 <john.spray@inktank.com>
src/mds/LogEvent.h
src/mds/events/EMetaBlob.h
src/mds/events/EOpen.h
src/mds/events/EUpdate.h
src/mds/journal.cc
src/tools/cephfs/EventOutput.cc
src/tools/cephfs/JournalFilter.cc
src/tools/cephfs/JournalTool.cc
src/tools/cephfs/JournalTool.h

index 1152ade84765446e8d3b01fcf042286e940ae587..67c22e75233ff15b09b64d618e8a1b0812effe07 100644 (file)
@@ -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) {
index 22c5c4e6f5ea3ea1ebfa7b53597d1094423a53e3..b70dc534a0d27a8145ab3100792805afe03fb3f0 100644 (file)
@@ -202,10 +202,10 @@ public:
 
   private:
     mutable bufferlist dnbl;
-    bool dn_decoded;
-    list<ceph::shared_ptr<fullbit> >   dfull;
-    list<remotebit> dremote;
-    list<nullbit>   dnull;
+    mutable bool dn_decoded;
+    mutable list<ceph::shared_ptr<fullbit> > dfull;
+    mutable list<remotebit> dremote;
+    mutable list<nullbit> 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<ceph::shared_ptr<fullbit> >   &get_dfull()   { return dfull; }
-    list<remotebit> &get_dremote() { return dremote; }
-    list<nullbit>   &get_dnull()   { return dnull; }
+    const list<ceph::shared_ptr<fullbit> > &get_dfull()   const { return dfull; }
+    const list<remotebit>                  &get_dremote() const { return dremote; }
+    const list<nullbit>                    &get_dnull()   const { return dnull; }
+
+    void add_dnull(nullbit const &n)                   { dnull.push_back(n); };
+    void add_dfull(ceph::shared_ptr<fullbit> 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<inodeno_t> &inodes);
-  void get_paths(std::vector<std::string> &paths);
-  void get_dentries(std::map<dirfrag_t, std::set<std::string> > &dentries);
+  void get_inodes(std::set<inodeno_t> &inodes) const;
+  void get_paths(std::vector<std::string> &paths) const;
+  void get_dentries(std::map<dirfrag_t, std::set<std::string> > &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<fullbit>(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<fullbit>(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.
index baf93344a230d18e3fdd3f57a7da3c6c29ff58ea..d1c41558b40ad0587118d80bd678e69e57aaa016 100644 (file)
@@ -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
index d0be0a4f28bcc195963e793c5f501329845396f2..d6d82410c14d38f27a25178b379f3b81fc03612e 100644 (file)
@@ -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
index 9f2829f36d563578cb221b80632b800c59425fb5..5a3d1045b49735d706e83657bafec6b6481bb9ee 100644 (file)
@@ -821,27 +821,27 @@ void EMetaBlob::decode(bufferlist::iterator &bl)
  * dirlumps, and the inodes of the dirs themselves.
  */
 void EMetaBlob::get_inodes(
-    std::set<inodeno_t> &inodes)
+    std::set<inodeno_t> &inodes) const
 {
   // For all dirlumps in this metablob
-  for (std::map<dirfrag_t, dirlump>::iterator i = lump_map.begin(); i != lump_map.end(); ++i) {
+  for (std::map<dirfrag_t, dirlump>::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<ceph::shared_ptr<fullbit> > &fb_list = dl.get_dfull();
+    list<ceph::shared_ptr<fullbit> > const &fb_list = dl.get_dfull();
     for (list<ceph::shared_ptr<fullbit> >::const_iterator
         iter = fb_list.begin(); iter != fb_list.end(); ++iter) {
       inodes.insert((*iter)->inode.ino);
     }
 
     // Record inodes of remotebits
-    list<remotebit> &rb_list = dl.get_dremote();
+    list<remotebit> const &rb_list = dl.get_dremote();
     for (list<remotebit>::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<dirfrag_t, std::set<std::string> > &dentries)
+void EMetaBlob::get_dentries(std::map<dirfrag_t, std::set<std::string> > &dentries) const
 {
-  for (std::map<dirfrag_t, dirlump>::iterator i = lump_map.begin(); i != lump_map.end(); ++i) {
-    dirlump &dl = i->second;
+  for (std::map<dirfrag_t, dirlump>::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<ceph::shared_ptr<fullbit> > &fb_list = dl.get_dfull();
-    list<nullbit> &nb_list = dl.get_dnull();
-    list<remotebit> &rb_list = dl.get_dremote();
+    list<ceph::shared_ptr<fullbit> > const &fb_list = dl.get_dfull();
+    list<nullbit> const &nb_list = dl.get_dnull();
+    list<remotebit> const &rb_list = dl.get_dremote();
 
     // For all bits, store dentry
     for (list<ceph::shared_ptr<fullbit> >::const_iterator
@@ -889,12 +889,9 @@ void EMetaBlob::get_dentries(std::map<dirfrag_t, std::set<std::string> > &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<std::string> &paths)
+    std::vector<std::string> &paths) const
 {
   // Each dentry has a 'location' which is a 2-tuple of parent inode and dentry name
   typedef std::pair<inodeno_t, std::string> 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<dirfrag_t, dirlump>::iterator i = lump_map.begin(); i != lump_map.end(); ++i) {
+  for (std::map<dirfrag_t, dirlump>::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<ceph::shared_ptr<fullbit> > &fb_list = dl.get_dfull();
-    list<nullbit> &nb_list = dl.get_dnull();
-    list<remotebit> &rb_list = dl.get_dremote();
+    list<ceph::shared_ptr<fullbit> > const &fb_list = dl.get_dfull();
+    list<nullbit> const &nb_list = dl.get_dnull();
+    list<remotebit> const &rb_list = dl.get_dremote();
 
     for (list<ceph::shared_ptr<fullbit> >::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<dirfrag_t, dirlump>::iterator i = lump_map.begin(); i != lump_map.end(); ++i) {
+  for (std::map<dirfrag_t, dirlump>::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<ceph::shared_ptr<fullbit> > &fb_list = dl.get_dfull();
+    list<ceph::shared_ptr<fullbit> > const &fb_list = dl.get_dfull();
     for (list<ceph::shared_ptr<fullbit> >::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<nullbit> &nb_list = dl.get_dnull();
+    list<nullbit> const &nb_list = dl.get_dnull();
     for (list<nullbit>::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<remotebit> &rb_list = dl.get_dremote();
+    list<remotebit> const &rb_list = dl.get_dremote();
     for (list<remotebit>::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<ceph::shared_ptr<fullbit> >::iterator pp = lump.get_dfull().begin();
+    for (list<ceph::shared_ptr<fullbit> >::const_iterator pp = lump.get_dfull().begin();
         pp != lump.get_dfull().end();
         ++pp) {
       ceph::shared_ptr<fullbit> p = *pp;
@@ -1296,7 +1293,7 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg, MDSlaveUpdate *slaveup)
     }
 
     // remote dentries
-    for (list<remotebit>::iterator p = lump.get_dremote().begin();
+    for (list<remotebit>::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<nullbit>::iterator p = lump.get_dnull().begin();
+    for (list<nullbit>::const_iterator p = lump.get_dnull().begin();
         p != lump.get_dnull().end();
         ++p) {
       CDentry *dn = dir->lookup_exact_snap(p->dn, p->dnlast);
index c762558a4cd1ed16f7d3e1d9d5de1ee59f85faee..63cb574521d4da846b921d5e79c04824c1eba54b 100644 (file)
@@ -73,7 +73,7 @@ void EventOutput::list() const
 {
   for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) {
     std::vector<std::string> 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);
     }
index 929925289599f6bfcd147a889d84a762e00cc320..9bd766fd183de73a81d14ea23dab0d28e17fd89a 100644 (file)
@@ -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<inodeno_t> 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<dirfrag_t, std::set<std::string> > 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<std::string> paths;
       metablob->get_paths(paths);
index b04c2befc038b65efc21ef8a1c2506e20bdf0364..0a1a1b2f1105b7bc014911fcabdd474a4e9760e9 100644 (file)
@@ -325,7 +325,7 @@ int JournalTool::main_event(std::vector<const char*> &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<ceph::shared_ptr<EMetaBlob::fullbit> >::iterator p = metablob.roots.begin(); p != metablob.roots.end(); ++p) {
-    EMetaBlob::fullbit &fb = *(*p);
+  for (list<ceph::shared_ptr<EMetaBlob::fullbit> >::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<dirfrag_t>::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<dirfrag_t>::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<ceph::shared_ptr<EMetaBlob::fullbit> > &fb_list = lump.get_dfull();
-    for (list<ceph::shared_ptr<EMetaBlob::fullbit> >::iterator fbi = fb_list.begin(); fbi != fb_list.end(); ++fbi) {
-      EMetaBlob::fullbit &fb = *(*fbi);
+    list<ceph::shared_ptr<EMetaBlob::fullbit> > const &fb_list = lump.get_dfull();
+    for (list<ceph::shared_ptr<EMetaBlob::fullbit> >::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<EMetaBlob::nullbit> &nb_list = lump.get_dnull();
+    list<EMetaBlob::nullbit> const &nb_list = lump.get_dnull();
     for (list<EMetaBlob::nullbit>::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<inodeno_t>::iterator i = metablob.destroyed_inodes.begin();
+  for (std::vector<inodeno_t>::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
index 1c5745493f9551e80c5989e76b76e07da87c4ec5..759876674ace797a8809c04b73b6508341b57de4 100644 (file)
@@ -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);