]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: use unique_ptr to simplify resource mgmt 11543/head
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 19 Oct 2016 00:33:27 +0000 (20:33 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 19 Oct 2016 15:24:12 +0000 (11:24 -0400)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/mds/CDir.cc
src/mds/CDir.h

index 7d101ce44b73e775cf71fb803bf4a752b16a2370..50d93892914047a98e62c17d65e7f34f48646785 100644 (file)
@@ -183,7 +183,6 @@ CDir::CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth) :
   first(2),
   dirty_rstat_inodes(member_offset(CInode, dirty_rstat_item)),
   projected_version(0),  item_dirty(this), item_new(this),
-  scrub_infop(NULL),
   num_head_items(0), num_head_null(0),
   num_snap_items(0), num_snap_null(0),
   num_dirty(0), committing_version(0), committed_version(0),
@@ -195,7 +194,6 @@ CDir::CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth) :
   pop_auth_subtree_nested(ceph_clock_now(g_ceph_context)),
   num_dentries_nested(0), num_dentries_auth_subtree(0),
   num_dentries_auth_subtree_nested(0),
-  bloom(NULL),
   dir_auth(CDIR_AUTH_DEFAULT)
 {
   g_num_dir++;
@@ -639,7 +637,7 @@ void CDir::add_to_bloom(CDentry *dn)
       return;
     unsigned size = get_num_head_items() + get_num_snap_items();
     if (size < 100) size = 100;
-    bloom = new bloom_filter(size, 1.0 / size, 0);
+    bloom.reset(new bloom_filter(size, 1.0 / size, 0));
   }
   /* This size and false positive probability is completely random.*/
   bloom->insert(dn->name.c_str(), dn->name.size());
@@ -652,12 +650,6 @@ bool CDir::is_in_bloom(const string& name)
   return bloom->contains(name.c_str(), name.size());
 }
 
-void CDir::remove_bloom()
-{
-  delete bloom;
-  bloom = NULL;
-}
-
 void CDir::remove_null_dentries() {
   dout(12) << "remove_null_dentries " << *this << dendl;
 
@@ -1379,7 +1371,7 @@ void CDir::log_mark_dirty()
 
 void CDir::mark_complete() {
   state_set(STATE_COMPLETE);
-  remove_bloom();
+  bloom.reset();
 }
 
 void CDir::first_get()
@@ -2915,7 +2907,7 @@ void CDir::scrub_info_create() const
   CDir *me = const_cast<CDir*>(this);
   fnode_t *fn = me->get_projected_fnode();
 
-  scrub_info_t *si = new scrub_info_t();
+  std::unique_ptr<scrub_info_t> si(new scrub_info_t());
 
   si->last_recursive.version = si->recursive_start.version =
       fn->recursive_scrub_version;
@@ -2925,7 +2917,7 @@ void CDir::scrub_info_create() const
   si->last_local.version = fn->localized_scrub_version;
   si->last_local.time = fn->localized_scrub_stamp;
 
-  me->scrub_infop = si;
+  me->scrub_infop.swap(si);
 }
 
 void CDir::scrub_initialize(const ScrubHeaderRefConst& header)
@@ -3108,8 +3100,7 @@ void CDir::scrub_maybe_delete_info()
       !scrub_infop->last_scrub_dirty &&
       !scrub_infop->pending_scrub_error &&
       scrub_infop->dirty_scrub_stamps.empty()) {
-    delete scrub_infop;
-    scrub_infop = NULL;
+    scrub_infop.reset();
   }
 }
 
index a914afb790d25cb866409ccfc991514d56496c3d..6ccdfbd8ab0aa1d7f55ecf0bc5716a52ad11c2e3 100644 (file)
@@ -20,6 +20,7 @@
 #include "include/types.h"
 #include "include/buffer_fwd.h"
 #include "mdstypes.h"
+#include "common/bloom_filter.hpp"
 #include "common/config.h"
 #include "common/DecayCounter.h"
 
@@ -35,7 +36,6 @@
 
 class CDentry;
 class MDCache;
-class bloom_filter;
 
 struct ObjectOperation;
 
@@ -338,7 +338,7 @@ private:
 
 
 protected:
-  scrub_info_t *scrub_infop;
+  std::unique_ptr<scrub_info_t> scrub_infop;
 
   // contents of this directory
   map_t items;       // non-null AND null
@@ -395,15 +395,13 @@ protected:
   friend class C_IO_Dir_OMAP_Fetched;
   friend class C_IO_Dir_Committed;
 
-  bloom_filter *bloom;
+  std::unique_ptr<bloom_filter> bloom;
   /* If you set up the bloom filter, you must keep it accurate!
    * It's deleted when you mark_complete() and is deliberately not serialized.*/
 
  public:
   CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth);
   ~CDir() {
-    delete scrub_infop;
-    remove_bloom();
     g_num_dir--;
     g_num_dirs++;
   }
@@ -412,7 +410,7 @@ protected:
     if (!scrub_infop) {
       scrub_info_create();
     }
-    return scrub_infop;
+    return scrub_infop.get();
   }
 
 
@@ -471,7 +469,9 @@ protected:
   void add_to_bloom(CDentry *dn);
   bool is_in_bloom(const std::string& name);
   bool has_bloom() { return (bloom ? true : false); }
-  void remove_bloom();
+  void remove_bloom() {
+    bloom.reset();
+  }
 private:
   void link_inode_work( CDentry *dn, CInode *in );
   void unlink_inode_work( CDentry *dn );