]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/filestore/FileStore: [Cleanup (trivial)] Initialized by nullptr, NULL or 0 instead 18980/head
authorShinobu Kinjo <shinobu@redhat.com>
Fri, 17 Nov 2017 07:02:12 +0000 (16:02 +0900)
committerShinobu Kinjo <shinobu@redhat.com>
Fri, 17 Nov 2017 07:02:12 +0000 (16:02 +0900)
Signed-off-by: Shinobu Kinjo <shinobu@redhat.com>
src/os/filestore/FileStore.cc
src/os/filestore/FileStore.h

index 35e99d667638a06da8bd1f4900809e225ad583d3..b8eab64089798919acec82a61a876d4477dcec99 100644 (file)
@@ -187,7 +187,7 @@ int FileStore::lfn_find(const ghobject_t& oid, const Index& index, IndexedPath *
   if (!path)
     path = &path2;
   int r, exist;
-  assert(NULL != index.index);
+  assert(index.index);
   r = (index.index)->lookup(oid, path, &exist);
   if (r < 0) {
     assert(!m_filestore_fail_eio || r != -EIO);
@@ -224,7 +224,7 @@ int FileStore::lfn_stat(const coll_t& cid, const ghobject_t& oid, struct stat *b
   if (r < 0)
     return r;
 
-  assert(NULL != index.index);
+  assert(index.index);
   RWLock::RLocker l((index.index)->access_lock);
 
   r = lfn_find(oid, index, &path);
@@ -268,7 +268,7 @@ int FileStore::lfn_open(const coll_t& cid,
   }
 
   int fd, exist;
-  assert(NULL != (*index).index);
+  assert((*index).index);
   if (need_lock) {
     ((*index).index)->access_lock.get_write();
   }
@@ -379,8 +379,8 @@ int FileStore::lfn_link(const coll_t& c, const coll_t& newcid, const ghobject_t&
       return r;
   }
 
-  assert(NULL != index_old.index);
-  assert(NULL != index_new.index);
+  assert(index_old.index);
+  assert(index_new.index);
 
   if (!index_same) {
 
@@ -463,7 +463,7 @@ int FileStore::lfn_unlink(const coll_t& cid, const ghobject_t& o,
     return r;
   }
 
-  assert(NULL != index.index);
+  assert(index.index);
   RWLock::WLocker l((index.index)->access_lock);
 
   {
@@ -528,7 +528,7 @@ FileStore::FileStore(CephContext* cct, const std::string &base,
   blk_size(0),
   fsid_fd(-1), op_fd(-1),
   basedir_fd(-1), current_fd(-1),
-  backend(NULL),
+  backend(nullptr),
   index_manager(cct, do_update),
   lock("FileStore::lock"),
   force_sync(false),
@@ -547,7 +547,7 @@ FileStore::FileStore(CephContext* cct, const std::string &base,
   op_tp(cct, "FileStore::op_tp", "tp_fstore_op", cct->_conf->filestore_op_threads, "filestore_op_threads"),
   op_wq(this, cct->_conf->filestore_op_thread_timeout,
        cct->_conf->filestore_op_thread_suicide_timeout, &op_tp),
-  logger(NULL),
+  logger(nullptr),
   trace_endpoint("0.0.0.0", 0, "FileStore"),
   read_error_lock("FileStore::read_error_lock"),
   m_filestore_commit_timeout(cct->_conf->filestore_commit_timeout),
@@ -643,18 +643,19 @@ FileStore::~FileStore()
 {
   for (vector<Finisher*>::iterator it = ondisk_finishers.begin(); it != ondisk_finishers.end(); ++it) {
     delete *it;
-    *it = NULL;
+    *it = nullptr;
   }
   for (vector<Finisher*>::iterator it = apply_finishers.begin(); it != apply_finishers.end(); ++it) {
     delete *it;
-    *it = NULL;
+    *it = nullptr;
   }
   cct->_conf->remove_observer(this);
   cct->get_perfcounters_collection()->remove(logger);
 
   if (journal)
-    journal->logger = NULL;
+    journal->logger = nullptr;
   delete logger;
+  logger = nullptr;
 
   if (m_filestore_do_dump) {
     dump_stop();
@@ -771,6 +772,7 @@ int FileStore::dump_journal(ostream& out)
   FileJournal *journal = new FileJournal(cct, fsid, &finisher, &sync_cond, journalpath.c_str(), m_journal_dio);
   r = journal->dump(out);
   delete journal;
+  journal = nullptr;
   return r;
 }
 
@@ -798,7 +800,7 @@ void FileStore::create_backend(long f_type)
 {
   m_fs_type = f_type;
 
-  assert(backend == NULL);
+  assert(!backend);
   backend = FileStoreBackend::create(f_type, this);
 
   dout(0) << "backend " << backend->get_name()
@@ -959,7 +961,7 @@ int FileStore::mkfs()
        assert(current_fd >= 0);
        char s[NAME_MAX];
        snprintf(s, sizeof(s), COMMIT_SNAP_ITEM, 1ull);
-       ret = backend->create_checkpoint(s, NULL);
+       ret = backend->create_checkpoint(s, nullptr);
        VOID_TEMP_FAILURE_RETRY(::close(current_fd));
        if (ret < 0 && ret != -EEXIST) {
          VOID_TEMP_FAILURE_RETRY(::close(fd));
@@ -1046,7 +1048,7 @@ int FileStore::mkfs()
  close_basedir_fd:
   VOID_TEMP_FAILURE_RETRY(::close(basedir_fd));
   delete backend;
-  backend = NULL;
+  backend = nullptr;
   return ret;
 }
 
@@ -1084,7 +1086,7 @@ int FileStore::mkjournal()
        dout(0) << __FUNC__ << ": created journal on " << journalpath << dendl;
     }
     delete journal;
-    journal = 0;
+    journal = nullptr;
   }
   return ret;
 }
@@ -1165,7 +1167,7 @@ bool FileStore::is_rotational()
     create_backend(st.f_type);
     rotational = backend->is_rotational();
     delete backend;
-    backend = NULL;
+    backend = nullptr;
   }
   dout(10) << __func__ << " " << (int)rotational << dendl;
   return rotational;
@@ -1189,7 +1191,7 @@ bool FileStore::is_journal_rotational()
     create_backend(st.f_type);
     journal_rotational = backend->is_journal_rotational();
     delete backend;
-    backend = NULL;
+    backend = nullptr;
   }
   dout(10) << __func__ << " " << (int)journal_rotational << dendl;
   return journal_rotational;
@@ -1714,7 +1716,7 @@ int FileStore::mount()
     KeyValueDB * omap_store = KeyValueDB::create(cct,
                                                 superblock.omap_backend,
                                                 omap_dir);
-    if (omap_store == NULL)
+    if (!omap_store)
     {
       derr << __FUNC__ << ": Error creating " << superblock.omap_backend << dendl;
       ret = -1;
@@ -1734,6 +1736,7 @@ int FileStore::mount()
     stringstream err;
     if (omap_store->create_and_open(err)) {
       delete omap_store;
+      omap_store = nullptr;
       derr << __FUNC__ << ": Error initializing " << superblock.omap_backend
           << " : " << err.str() << dendl;
       ret = -1;
@@ -1744,6 +1747,7 @@ int FileStore::mount()
     ret = dbomap->init(do_update);
     if (ret < 0) {
       delete dbomap;
+      dbomap = nullptr;
       derr << __FUNC__ << ": Error initializing DBObjectMap: " << ret << dendl;
       goto close_current_fd;
     }
@@ -1752,6 +1756,7 @@ int FileStore::mount()
     if (cct->_conf->filestore_debug_omap_check && !dbomap->check(err2)) {
       derr << err2.str() << dendl;
       delete dbomap;
+      dbomap = nullptr;
       ret = -EINVAL;
       goto close_current_fd;
     }
@@ -1812,7 +1817,7 @@ int FileStore::mount()
             << " with error: " << ret << dendl;
        goto close_current_fd;
       }
-      assert(NULL != index.index);
+      assert(index.index);
       RWLock::WLocker l((index.index)->access_lock);
 
       index->cleanup();
@@ -1899,7 +1904,7 @@ close_fsid_fd:
 done:
   assert(!m_filestore_fail_eio || ret != -EIO);
   delete backend;
-  backend = NULL;
+  backend = nullptr;
   object_map.reset();
   return ret;
 }
@@ -1992,7 +1997,7 @@ int FileStore::umount()
   force_sync = false;
 
   delete backend;
-  backend = NULL;
+  backend = nullptr;
 
   object_map.reset();
 
@@ -2130,6 +2135,7 @@ void FileStore::_finish_op(OpSequencer *osr)
     apply_finishers[osr->id % m_apply_finisher_num]->queue(to_queue);
   }
   delete o;
+  o = nullptr;
 }
 
 
@@ -2160,8 +2166,11 @@ int FileStore::queue_transactions(Sequencer *posr, vector<Transaction>& tls,
     dout(0) << __FUNC__ << ": objectstore_blackhole = TRUE, dropping transaction"
            << dendl;
     delete ondisk;
+    ondisk = nullptr;
     delete onreadable;
+    onreadable = nullptr;
     delete onreadable_sync;
+    onreadable_sync = nullptr;
     return 0;
   }
 
@@ -2299,6 +2308,7 @@ int FileStore::queue_transactions(Sequencer *posr, vector<Transaction>& tls,
     _op_journal_transactions(tbl, orig_len, op, ondisk, osd_op);
   } else {
     delete ondisk;
+    ondisk = nullptr;
   }
 
   // start on_readable finisher after we queue journal item, as on_readable callback
@@ -3311,8 +3321,8 @@ int FileStore::_do_fiemap(int fd, uint64_t offset, size_t len,
                           map<uint64_t, uint64_t> *m)
 {
   uint64_t i;
-  struct fiemap_extent *extent = NULL;
-  struct fiemap *fiemap = NULL;
+  struct fiemap_extent *extent = nullptr;
+  struct fiemap *fiemap = nullptr;
   int r = 0;
 
 more:
@@ -3648,7 +3658,7 @@ int FileStore::_clone(const coll_t& cid, const ghobject_t& oldoid, const ghobjec
     if (r < 0) {
       goto out2;
     }
-    assert(NULL != (index.index));
+    assert(index.index);
     RWLock::WLocker l((index.index)->access_lock);
 
     r = lfn_open(cid, newoid, true, &n, &index);
@@ -3801,7 +3811,7 @@ int FileStore::_do_copy_range(int from, int to, uint64_t srcoff, uint64_t len, u
     loff_t dstpos = dstoff;
     while (pos < end) {
       int l = MIN(end-pos, buflen);
-      r = safe_splice(from, &pos, pipefd[1], NULL, l, SPLICE_F_NONBLOCK);
+      r = safe_splice(from, &pos, pipefd[1], nullptr, l, SPLICE_F_NONBLOCK);
       dout(10) << "  safe_splice read from " << pos << "~" << l << " got " << r << dendl;
       if (r < 0) {
        derr << __FUNC__ << ": safe_splice read error at " << pos << "~" << len
@@ -3816,7 +3826,7 @@ int FileStore::_do_copy_range(int from, int to, uint64_t srcoff, uint64_t len, u
        break;
       }
 
-      r = safe_splice(pipefd[0], NULL, to, &dstpos, r, 0);
+      r = safe_splice(pipefd[0], nullptr, to, &dstpos, r, 0);
       dout(10) << " safe_splice write to " << to << " len " << r
        << " got " << r << dendl;
       if (r < 0) {
@@ -3959,6 +3969,7 @@ public:
     bt->print(*_dout);
     *_dout << dendl;
     delete bt;
+    bt = nullptr;
     ceph_abort();
   }
 private:
@@ -4264,7 +4275,7 @@ int FileStore::snapshot(const string& name)
   char s[NAME_MAX];
   snprintf(s, sizeof(s), CLUSTER_SNAP_ITEM, name.c_str());
 
-  int r = backend->create_checkpoint(s, NULL);
+  int r = backend->create_checkpoint(s, nullptr);
   if (r) {
     derr << __FUNC__ << ": " << name << " failed: " << cpp_strerror(r) << dendl;
   }
@@ -4887,12 +4898,12 @@ int FileStore::collection_empty(const coll_t& c, bool *empty)
     return r;
   }
 
-  assert(NULL != index.index);
+  assert(index.index);
   RWLock::RLocker l((index.index)->access_lock);
 
   vector<ghobject_t> ls;
   r = index->collection_list_partial(ghobject_t(), ghobject_t::get_max(),
-                                    1, &ls, NULL);
+                                    1, &ls, nullptr);
   if (r < 0) {
     derr << __FUNC__ << ": collection_list_partial returned: "
          << cpp_strerror(r) << dendl;
@@ -5012,7 +5023,7 @@ int FileStore::collection_list(const coll_t& c,
   if (r < 0)
     return r;
 
-  assert(NULL != index.index);
+  assert(index.index);
   RWLock::RLocker l((index.index)->access_lock);
 
   r = index->collection_list_partial(start, end, max, ls, next);
@@ -5045,7 +5056,7 @@ int FileStore::omap_get(const coll_t& _c, const ghobject_t &hoid,
   if (r < 0)
     return r;
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0)
@@ -5074,7 +5085,7 @@ int FileStore::omap_get_header(
   if (r < 0)
     return r;
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0)
@@ -5099,7 +5110,7 @@ int FileStore::omap_get_keys(const coll_t& _c, const ghobject_t &hoid, set<strin
   if (r < 0)
     return r;
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0)
@@ -5129,7 +5140,7 @@ int FileStore::omap_get_values(const coll_t& _c, const ghobject_t &hoid,
     goto out;
   }
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0) {
@@ -5164,7 +5175,7 @@ int FileStore::omap_check_keys(const coll_t& _c, const ghobject_t &hoid,
   if (r < 0)
     return r;
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0)
@@ -5193,7 +5204,7 @@ ObjectMap::ObjectMapIterator FileStore::get_omap_iterator(const coll_t& _c,
     return ObjectMap::ObjectMapIterator();
   }
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0) {
@@ -5282,7 +5293,7 @@ int FileStore::_destroy_collection(const coll_t& c)
     r = get_index(c, &from);
     if (r < 0)
       goto out;
-    assert(NULL != from.index);
+    assert(from.index);
     RWLock::WLocker l((from.index)->access_lock);
 
     r = from->prep_delete();
@@ -5488,7 +5499,7 @@ int FileStore::_omap_clear(const coll_t& cid, const ghobject_t &hoid,
   if (r < 0)
     return r;
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0)
@@ -5516,7 +5527,7 @@ int FileStore::_omap_setkeys(const coll_t& cid, const ghobject_t &hoid,
     return r;
   }
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0) {
@@ -5549,7 +5560,7 @@ int FileStore::_omap_rmkeys(const coll_t& cid, const ghobject_t &hoid,
   if (r < 0)
     return r;
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0)
@@ -5589,7 +5600,7 @@ int FileStore::_omap_setheader(const coll_t& cid, const ghobject_t &hoid,
   if (r < 0)
     return r;
   {
-    assert(NULL != index.index);
+    assert(index.index);
     RWLock::RLocker l((index.index)->access_lock);
     r = lfn_find(hoid, index);
     if (r < 0)
@@ -5638,10 +5649,10 @@ int FileStore::_split_collection(const coll_t& cid,
       r = get_index(dest, &to);
 
     if (!r) {
-      assert(NULL != from.index);
+      assert(from.index);
       RWLock::WLocker l1((from.index)->access_lock);
 
-      assert(NULL != to.index);
+      assert(to.index);
       RWLock::WLocker l2((to.index)->access_lock);
 
       r = from->split(rem, bits, to.index);
index a7c5b0ab3ee6212840019594873d7324fe0f5dce..131f98f13f39bda65c81754b3dd44760c20b94fd 100644 (file)
@@ -395,7 +395,7 @@ private:
     }
     OpSequencer *_dequeue() override {
       if (store->op_queue.empty())
-       return NULL;
+       return nullptr;
       OpSequencer *osr = store->op_queue.front();
       store->op_queue.pop_front();
       return osr;
@@ -430,7 +430,7 @@ private:
 
 public:
   int lfn_find(const ghobject_t& oid, const Index& index,
-                                  IndexedPath *path = NULL);
+                                  IndexedPath *path = nullptr);
   int lfn_truncate(const coll_t& cid, const ghobject_t& oid, off_t length);
   int lfn_stat(const coll_t& cid, const ghobject_t& oid, struct stat *buf);
   int lfn_open(
@@ -438,7 +438,7 @@ public:
     const ghobject_t& oid,
     bool create,
     FDRef *outfd,
-    Index *index = 0);
+    Index *index = nullptr);
 
   void lfn_close(FDRef fd);
   int lfn_link(const coll_t& c, const coll_t& newcid, const ghobject_t& o, const ghobject_t& newoid) ;
@@ -518,7 +518,7 @@ public:
 
   int queue_transactions(Sequencer *osr, vector<Transaction>& tls,
                         TrackedOpRef op = TrackedOpRef(),
-                        ThreadPool::TPHandle *handle = NULL) override;
+                        ThreadPool::TPHandle *handle = nullptr) override;
 
   /**
    * set replay guard xattr on given file