client: use unique_ptr for locks

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
This commit is contained in:
Patrick Donnelly 2017-03-16 14:35:49 -04:00
parent fe0354a9b1
commit a5d97ad257
No known key found for this signature in database
GPG Key ID: 3A2A7E25BEA8AADB
5 changed files with 24 additions and 27 deletions

View 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())

View 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);
}

View 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; }
};

View 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)

View 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));