diff --git a/src/client/Client.cc b/src/client/Client.cc index c46cd1e12b6..7d963024f5b 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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::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::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 > to_release; if (fh->fcntl_locks) { - ceph_lock_state_t* lock_state = fh->fcntl_locks; + auto &lock_state = fh->fcntl_locks; for(multimap::iterator p = lock_state->held_locks.begin(); p != lock_state->held_locks.end(); ++p) to_release.push_back(pair(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::iterator p = lock_state->held_locks.begin(); p != lock_state->held_locks.end(); ++p) to_release.push_back(pair(CEPH_LOCK_FLOCK, p->second)); - delete fh->flock_locks; + lock_state.reset(); } if (to_release.empty()) diff --git a/src/client/Fh.cc b/src/client/Fh.cc index b2c68a2cb37..a51dca3121a 100644 --- a/src/client/Fh.cc +++ b/src/client/Fh.cc @@ -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); } diff --git a/src/client/Fh.h b/src/client/Fh.h index 979456c5a16..6bc4d1a38fc 100644 --- a/src/client/Fh.h +++ b/src/client/Fh.h @@ -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 fcntl_locks; + std::unique_ptr 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; } }; diff --git a/src/client/Inode.cc b/src/client/Inode.cc index 286c5c234e4..e8c6e35122c 100644 --- a/src/client/Inode.cc +++ b/src/client/Inode.cc @@ -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) diff --git a/src/client/Inode.h b/src/client/Inode.h index e8ce367aa83..dd9c3e5d9b7 100644 --- a/src/client/Inode.h +++ b/src/client/Inode.h @@ -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 fcntl_locks; + std::unique_ptr flock_locks; xlist 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("a, 0, sizeof(quota));