]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: use unique_ptr for locks 17851/head
authorPatrick Donnelly <pdonnell@redhat.com>
Thu, 16 Mar 2017 18:35:49 +0000 (14:35 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 20 Sep 2017 23:21:54 +0000 (16:21 -0700)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/client/Client.cc
src/client/Fh.cc
src/client/Fh.h
src/client/Inode.cc
src/client/Inode.h

index c46cd1e12b63eb96c57362667f269997e27ed95c..7d963024f5b5ee42950e42e245c6f771937d5f39 100644 (file)
@@ -9755,12 +9755,12 @@ int Client::_do_filelock(Inode *in, Fh *fh, int lock_type, int op, int sleep,
       ceph_lock_state_t *lock_state;
       if (lock_type == CEPH_LOCK_FCNTL) {
        if (!in->fcntl_locks)
-         in->fcntl_locks = new ceph_lock_state_t(cct, CEPH_LOCK_FCNTL);
-       lock_state = in->fcntl_locks;
+         in->fcntl_locks.reset(new ceph_lock_state_t(cct, CEPH_LOCK_FCNTL));
+       lock_state = in->fcntl_locks.get();
       } else if (lock_type == CEPH_LOCK_FLOCK) {
        if (!in->flock_locks)
-         in->flock_locks = new ceph_lock_state_t(cct, CEPH_LOCK_FLOCK);
-       lock_state = in->flock_locks;
+         in->flock_locks.reset(new ceph_lock_state_t(cct, CEPH_LOCK_FLOCK));
+       lock_state = in->flock_locks.get();
       } else {
        ceph_abort();
        return -EINVAL;
@@ -9770,12 +9770,12 @@ int Client::_do_filelock(Inode *in, Fh *fh, int lock_type, int op, int sleep,
       if (!removing) {
        if (lock_type == CEPH_LOCK_FCNTL) {
          if (!fh->fcntl_locks)
-           fh->fcntl_locks = new ceph_lock_state_t(cct, CEPH_LOCK_FCNTL);
-         lock_state = fh->fcntl_locks;
+           fh->fcntl_locks.reset(new ceph_lock_state_t(cct, CEPH_LOCK_FCNTL));
+         lock_state = fh->fcntl_locks.get();
        } else {
          if (!fh->flock_locks)
-           fh->flock_locks = new ceph_lock_state_t(cct, CEPH_LOCK_FLOCK);
-         lock_state = fh->flock_locks;
+           fh->flock_locks.reset(new ceph_lock_state_t(cct, CEPH_LOCK_FLOCK));
+         lock_state = fh->flock_locks.get();
        }
        _update_lock_state(fl, owner, lock_state);
       }
@@ -9826,7 +9826,7 @@ void Client::_encode_filelocks(Inode *in, bufferlist& bl)
   unsigned nr_fcntl_locks = in->fcntl_locks ? in->fcntl_locks->held_locks.size() : 0;
   ::encode(nr_fcntl_locks, bl);
   if (nr_fcntl_locks) {
-    ceph_lock_state_t* lock_state = in->fcntl_locks;
+    auto &lock_state = in->fcntl_locks;
     for(multimap<uint64_t, ceph_filelock>::iterator p = lock_state->held_locks.begin();
        p != lock_state->held_locks.end();
        ++p)
@@ -9836,7 +9836,7 @@ void Client::_encode_filelocks(Inode *in, bufferlist& bl)
   unsigned nr_flock_locks = in->flock_locks ? in->flock_locks->held_locks.size() : 0;
   ::encode(nr_flock_locks, bl);
   if (nr_flock_locks) {
-    ceph_lock_state_t* lock_state = in->flock_locks;
+    auto &lock_state = in->flock_locks;
     for(multimap<uint64_t, ceph_filelock>::iterator p = lock_state->held_locks.begin();
        p != lock_state->held_locks.end();
        ++p)
@@ -9858,20 +9858,20 @@ void Client::_release_filelocks(Fh *fh)
   list<pair<int, ceph_filelock> > to_release;
 
   if (fh->fcntl_locks) {
-    ceph_lock_state_t* lock_state = fh->fcntl_locks;
+    auto &lock_state = fh->fcntl_locks;
     for(multimap<uint64_t, ceph_filelock>::iterator p = lock_state->held_locks.begin();
        p != lock_state->held_locks.end();
        ++p)
       to_release.push_back(pair<int, ceph_filelock>(CEPH_LOCK_FCNTL, p->second));
-    delete fh->fcntl_locks;
+    lock_state.reset();
   }
   if (fh->flock_locks) {
-    ceph_lock_state_t* lock_state = fh->flock_locks;
+    auto &lock_state = fh->flock_locks;
     for(multimap<uint64_t, ceph_filelock>::iterator p = lock_state->held_locks.begin();
        p != lock_state->held_locks.end();
        ++p)
       to_release.push_back(pair<int, ceph_filelock>(CEPH_LOCK_FLOCK, p->second));
-    delete fh->flock_locks;
+    lock_state.reset();
   }
 
   if (to_release.empty())
index b2c68a2cb373fc4eaf4699f7a0cec5996428c4cc..a51dca3121ad876f19140cfe2212821f023dda36 100644 (file)
@@ -20,7 +20,7 @@
 
 Fh::Fh(InodeRef in, int flags, int cmode, const UserPerm &perms) :
     inode(in), _ref(1), pos(0), mds(0), mode(cmode), flags(flags), pos_locked(false),
-    actor_perms(perms), readahead(), fcntl_locks(NULL), flock_locks(NULL)
+    actor_perms(perms), readahead()
 {
   inode->add_fh(this);
 }
index 979456c5a16b2778352cb65f4c9bce91a0a63bac..6bc4d1a38fcb0fa750fb0fd8f92aa9a92a89b0f4 100644 (file)
@@ -5,9 +5,9 @@
 #include "include/types.h"
 #include "InodeRef.h"
 #include "UserPerm.h"
+#include "mds/flock.h"
 
 class Cond;
-class ceph_lock_state_t;
 class Inode;
 
 // file handle for any open file state
@@ -28,8 +28,8 @@ struct Fh {
   Readahead readahead;
 
   // file lock
-  ceph_lock_state_t *fcntl_locks;
-  ceph_lock_state_t *flock_locks;
+  std::unique_ptr<ceph_lock_state_t> fcntl_locks;
+  std::unique_ptr<ceph_lock_state_t> flock_locks;
 
   // IO error encountered by any writeback on this Inode while
   // this Fh existed (i.e. an fsync on another Fh will still show
@@ -43,10 +43,11 @@ struct Fh {
       async_err = 0;
       return e;
   }
-  
+
   Fh() = delete;
   Fh(InodeRef in, int flags, int cmode, const UserPerm &perms);
   ~Fh();
+
   void get() { ++_ref; }
   int put() { return --_ref; }
 };
index 286c5c234e4a9672b647b8a86764885b2f4d3f05..e8c6e35122ca1697fa41c265ccf25bc5fa6d5618 100644 (file)
@@ -26,9 +26,6 @@ Inode::~Inode()
       << std::hex << ino << std::dec << dendl;
     assert(oset.objects.empty());
   }
-
-  delete fcntl_locks;
-  delete flock_locks;
 }
 
 ostream& operator<<(ostream &out, const Inode &in)
index e8ce367aa83504de23142c8fd0ab02b9640b596b..dd9c3e5d9b7affadfd7e3adbe0d877aee2c12750 100644 (file)
@@ -7,6 +7,7 @@
 #include "include/types.h"
 #include "include/xlist.h"
 
+#include "mds/flock.h"
 #include "mds/mdstypes.h" // hrm
 
 #include "osdc/ObjectCacher.h"
@@ -21,7 +22,6 @@ class Dentry;
 class Dir;
 struct SnapRealm;
 struct Inode;
-class ceph_lock_state_t;
 class MetaRequest;
 class filepath;
 class Fh;
@@ -223,8 +223,8 @@ struct Inode {
   }
 
   // file locks
-  ceph_lock_state_t *fcntl_locks;
-  ceph_lock_state_t *flock_locks;
+  std::unique_ptr<ceph_lock_state_t> fcntl_locks;
+  std::unique_ptr<ceph_lock_state_t> flock_locks;
 
   xlist<MetaRequest*> unsafe_ops;
 
@@ -245,8 +245,7 @@ struct Inode {
       snaprealm(0), snaprealm_item(this),
       oset((void *)this, newlayout->pool_id, this->ino),
       reported_size(0), wanted_max_size(0), requested_max_size(0),
-      _ref(0), ll_ref(0), dn_set(),
-      fcntl_locks(NULL), flock_locks(NULL)
+      _ref(0), ll_ref(0), dn_set()
   {
     memset(&dir_layout, 0, sizeof(dir_layout));
     memset(&quota, 0, sizeof(quota));