Skip to content

Commit

Permalink
Merge pull request #5222: client: reference counting 'struct Fh'
Browse files Browse the repository at this point in the history
Reviewed-by: Loic Dachary <ldachary@redhat.com>
  • Loading branch information
ldachary committed Jul 19, 2015
2 parents 7e68cd3 + 3c8cdea commit b621f95
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
21 changes: 17 additions & 4 deletions src/client/Client.cc
Expand Up @@ -254,8 +254,7 @@ void Client::tear_down_cache()
++it) {
Fh *fh = it->second;
ldout(cct, 1) << "tear_down_cache forcing close of fh " << it->first << " ino " << fh->inode->ino << dendl;
put_inode(fh->inode);
delete fh;
_release_fh(fh);
}
fd_map.clear();

Expand Down Expand Up @@ -6697,12 +6696,20 @@ int Client::_release_fh(Fh *f)
ldout(cct, 10) << "_release_fh " << f << " on inode " << *in << " no async_err state" << dendl;
}

put_inode(in);
delete f;
_put_fh(f);

return err;
}

void Client::_put_fh(Fh *f)
{
int left = f->put();
if (!left) {
put_inode(f->inode);
delete f;
}
}

int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid, int gid)
{
int cmode = ceph_flags_to_mode(flags);
Expand Down Expand Up @@ -7042,10 +7049,16 @@ int Client::_read(Fh *f, int64_t offset, uint64_t size, bufferlist *bl)
return r < 0 ? r : bl->length();
}

Client::C_Readahead::C_Readahead(Client *c, Fh *f) :
client(c), f(f) {
f->get();
}

void Client::C_Readahead::finish(int r) {
lgeneric_subdout(client->cct, client, 20) << "client." << client->get_nodeid() << " " << "C_Readahead on " << f->inode << dendl;
client->put_cap_ref(f->inode, CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE);
f->readahead.dec_pending();
client->_put_fh(f);
}

int Client::_read_async(Fh *f, uint64_t off, uint64_t len, bufferlist *bl)
Expand Down
5 changes: 2 additions & 3 deletions src/client/Client.h
Expand Up @@ -628,14 +628,13 @@ class Client : public Dispatcher {

Fh *_create_fh(Inode *in, int flags, int cmode);
int _release_fh(Fh *fh);
void _put_fh(Fh *fh);


struct C_Readahead : public Context {
Client *client;
Fh *f;
C_Readahead(Client *c, Fh *f)
: client(c),
f(f) { }
C_Readahead(Client *c, Fh *f);
void finish(int r);
};

Expand Down
7 changes: 5 additions & 2 deletions src/client/Fh.h
Expand Up @@ -11,7 +11,8 @@ class ceph_lock_state_t;
// file handle for any open file state

struct Fh {
Inode *inode;
int _ref;
Inode *inode;
loff_t pos;
int mds; // have to talk to mds we opened with (for now)
int mode; // the mode i opened the file with
Expand All @@ -26,8 +27,10 @@ struct Fh {
ceph_lock_state_t *fcntl_locks;
ceph_lock_state_t *flock_locks;

Fh() : inode(0), pos(0), mds(0), mode(0), flags(0), pos_locked(false),
Fh() : _ref(1), inode(0), pos(0), mds(0), mode(0), flags(0), pos_locked(false),
readahead(), fcntl_locks(NULL), flock_locks(NULL) {}
void get() { ++_ref; }
int put() { return --_ref; }
};


Expand Down

0 comments on commit b621f95

Please sign in to comment.