]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Filer.h: use C_GatherBuilder
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 28 Jun 2011 00:40:58 +0000 (17:40 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 30 Jun 2011 17:24:03 +0000 (10:24 -0700)
Filer.h now uses C_GatherBuilder to avoid memory leaks.

Also, C_GatherBuilder's constructor now takes a Context.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/include/Context.h
src/mds/LogSegment.h
src/mds/MDCache.cc
src/mds/MDLog.cc
src/mds/journal.cc
src/osdc/Filer.h

index 4f913d7f82204c9a31effdd3ddc70bfbbcbc48e1..17bb3ff7bc3eaa7296092734cbca1e297ce40a9b 100644 (file)
@@ -259,15 +259,17 @@ public:
 class C_GatherBuilder
 {
 public:
-  C_GatherBuilder(CephContext *cct_)
-    : cct(cct_), c_gather(NULL)
+  C_GatherBuilder(CephContext *cct_, Context *ctx_)
+    : cct(cct_), c_gather(NULL), ctx(ctx_)
   {
   }
   ~C_GatherBuilder() {
+    if (!c_gather)
+      delete ctx;
   }
   Context *new_sub() {
     if (!c_gather) {
-      c_gather = new C_Gather(cct);
+      c_gather = new C_Gather(cct, ctx);
     }
     return c_gather->new_sub();
   }
@@ -280,6 +282,7 @@ public:
 private:
   CephContext *cct;
   C_Gather *c_gather;
+  Context *ctx;
 };
 
 #undef DOUT_SUBSYS
index 85cb0c9723f007c04678a168b5b113c8b0a021c1..7c7360466a59ec9e9dcadca7987b3701c1c2419c 100644 (file)
@@ -66,7 +66,7 @@ class LogSegment {
   map<int,version_t> tablev;
 
   // try to expire
-  C_Gather *try_to_expire(MDS *mds);
+  void try_to_expire(MDS *mds, C_GatherBuilder &gather_bld);
 
   // cons
   LogSegment(loff_t off) :
index 845ed677011d1be3de4b7a9f97821db3e8744291..a3f32f867fa44eaa32f57e2d0286633945fecb33 100644 (file)
@@ -3592,6 +3592,14 @@ void MDCache::handle_cache_rejoin_weak(MMDSCacheRejoin *weak)
   }
 }
 
+class C_MDC_RejoinGatherFinish : public Context {
+  MDCache *cache;
+public:
+  C_MDC_RejoinGatherFinish(MDCache *c) : cache(c) {}
+  void finish(int r) {
+    cache->rejoin_gather_finish();
+  }
+};
 
 /**
  * parallel_fetch -- make a pass at fetching a bunch of paths in parallel
@@ -3607,7 +3615,7 @@ C_Gather *MDCache::parallel_fetch(map<inodeno_t,filepath>& pathmap, set<inodeno_
 {
   dout(10) << "parallel_fetch on " << pathmap.size() << " paths" << dendl;
 
-  C_GatherBuilder gather_bld(g_ceph_context);
+  C_GatherBuilder gather_bld(g_ceph_context, new C_MDC_RejoinGatherFinish(this));
 
   // scan list
   set<CDir*> fetch_queue;
@@ -4278,17 +4286,6 @@ void MDCache::rejoin_trim_undef_inodes()
   assert(rejoin_undef_inodes.empty());
 }
 
-class C_MDC_RejoinGatherFinish : public Context {
-  MDCache *cache;
-public:
-  C_MDC_RejoinGatherFinish(MDCache *c) : cache(c) {}
-  void finish(int r) {
-    cache->rejoin_gather_finish();
-  }
-};
-
-
-
 void MDCache::rejoin_gather_finish() 
 {
   dout(10) << "rejoin_gather_finish" << dendl;
@@ -4302,7 +4299,6 @@ void MDCache::rejoin_gather_finish()
   if (!cap_import_paths.empty()) {
     C_Gather *gather = parallel_fetch(cap_import_paths, cap_imports_missing);
     if (gather) {
-      gather->set_finisher(new C_MDC_RejoinGatherFinish(this));
       return;
     }
   }
index cff21aed462419d87f1803bdf50508b54fb04eda..0157c691b3101dc170c50fe418f773c94a6a9a67 100644 (file)
@@ -340,13 +340,13 @@ void MDLog::trim(int m)
 
 void MDLog::try_expire(LogSegment *ls)
 {
-  C_Gather *exp = ls->try_to_expire(mds);
-  if (exp) {
+  C_GatherBuilder gather_bld(g_ceph_context, new C_MaybeExpiredSegment(this, ls));
+  ls->try_to_expire(mds, gather_bld);
+  if (gather_bld.has_subs()) {
     assert(expiring_segments.count(ls) == 0);
     expiring_segments.insert(ls);
     expiring_events += ls->num_events;
     dout(5) << "try_expire expiring segment " << ls->offset << dendl;
-    exp->set_finisher(new C_MaybeExpiredSegment(this, ls));
   } else {
     dout(10) << "try_expire expired segment " << ls->offset << dendl;
     _expired(ls);
index 305cdcd949f7b5d536b9ca3988765ef719b62ecb..64d7c4f8af219770fbf721b6f8267ee77e475942 100644 (file)
 // -----------------------
 // LogSegment
 
-C_Gather *LogSegment::try_to_expire(MDS *mds)
+void LogSegment::try_to_expire(MDS *mds, C_GatherBuilder &gather_bld)
 {
-  C_GatherBuilder gather_bld(g_ceph_context);
-
   set<CDir*> commit;
 
   dout(6) << "LogSegment(" << offset << ").try_to_expire" << dendl;
@@ -260,10 +258,8 @@ C_Gather *LogSegment::try_to_expire(MDS *mds)
   if (gather_bld.has_subs()) {
     dout(6) << "LogSegment(" << offset << ").try_to_expire waiting" << dendl;
     mds->mdlog->flush();
-    return gather_bld.get();
   } else {
     dout(6) << "LogSegment(" << offset << ").try_to_expire success" << dendl;
-    return NULL;
   }
 }
 
index 4ec89f5e6fdccac1cb1620a071cc9257302ecec8..065ed1eb1ce15ae0b562751fe428318b5b96fb5e 100644 (file)
@@ -196,19 +196,16 @@ class Filer {
       ops[0].op.extent.truncate_size = extents[0].offset;
       objecter->_modify(extents[0].oid, extents[0].oloc, ops, mtime, snapc, flags, onack, oncommit);
     } else {
-      C_Gather *gack = 0, *gcom = 0;
-      if (onack)
-       gack = new C_Gather(cct, onack);
-      if (oncommit)
-       gcom = new C_Gather(cct, oncommit);
+      C_GatherBuilder gack(cct, onack);
+      C_GatherBuilder gcom(cct, oncommit);
       for (vector<ObjectExtent>::iterator p = extents.begin(); p != extents.end(); p++) {
        vector<OSDOp> ops(1);
        ops[0].op.op = CEPH_OSD_OP_TRIMTRUNC;
        ops[0].op.extent.truncate_size = p->offset;
        ops[0].op.extent.truncate_seq = truncate_seq;
        objecter->_modify(p->oid, p->oloc, ops, mtime, snapc, flags,
-                         gack ? gack->new_sub():0,
-                         gcom ? gcom->new_sub():0);
+                         onack ? gack.new_sub():0,
+                         oncommit ? gcom.new_sub():0);
       }
     }
     return 0;
@@ -233,22 +230,19 @@ class Filer {
        objecter->zero(extents[0].oid, extents[0].oloc, extents[0].offset, extents[0].length, 
                       snapc, mtime, flags, onack, oncommit);
     } else {
-      C_Gather *gack = 0, *gcom = 0;
-      if (onack)
-       gack = new C_Gather(cct, onack);
-      if (oncommit)
-       gcom = new C_Gather(cct, oncommit);
+      C_GatherBuilder gack(cct, onack);
+      C_GatherBuilder gcom(cct, oncommit);
       for (vector<ObjectExtent>::iterator p = extents.begin(); p != extents.end(); p++) {
        if (p->offset == 0 && p->length == layout->fl_object_size)
          objecter->remove(p->oid, p->oloc,
                           snapc, mtime, flags,
-                          gack ? gack->new_sub():0,
-                          gcom ? gcom->new_sub():0);
+                          onack ? gack.new_sub():0,
+                          oncommit ? gcom.new_sub():0);
        else
          objecter->zero(p->oid, p->oloc, p->offset, p->length, 
                         snapc, mtime, flags,
-                        gack ? gack->new_sub():0,
-                        gcom ? gcom->new_sub():0);
+                        onack ? gack.new_sub():0,
+                        oncommit ? gcom.new_sub():0);
       }
     }
     return 0;