From 4bb48ee4ae49355e3a4bcd7424545c04ce284f89 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 24 Jun 2015 15:50:10 +0800 Subject: [PATCH] client: convert Fh::inode to smart pointer Signed-off-by: Yan, Zheng (cherry picked from commit dac11e6b4b1e8766ee5165366cf021d9ee91d3ae) --- src/client/Client.cc | 49 ++++++++++++++++++++++--------------------- src/client/Client.h | 1 + src/client/Fh.h | 6 +++--- src/client/fuse_ll.cc | 2 +- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 47bc6a9077d45..2fc1b4196115c 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6615,7 +6615,6 @@ Fh *Client::_create_fh(Inode *in, int flags, int cmode) // inode assert(in); f->inode = in; - f->inode->get(); ldout(cct, 10) << "_create_fh " << in->ino << " mode " << cmode << dendl; @@ -6649,7 +6648,7 @@ int Client::_release_fh(Fh *f) { //ldout(cct, 3) << "op: client->close(open_files[ " << fh << " ]);" << dendl; //ldout(cct, 3) << "op: open_files.erase( " << fh << " );" << dendl; - Inode *in = f->inode; + Inode *in = f->inode.get(); ldout(cct, 5) << "_release_fh " << f << " mode " << f->mode << " on " << *in << dendl; if (in->snapid == CEPH_NOSNAP) { @@ -6687,10 +6686,8 @@ int Client::_release_fh(Fh *f) void Client::_put_fh(Fh *f) { int left = f->put(); - if (!left) { - put_inode(f->inode); + if (!left) delete f; - } } int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid, int gid) @@ -6778,7 +6775,7 @@ loff_t Client::lseek(int fd, loff_t offset, int whence) loff_t Client::_lseek(Fh *f, loff_t offset, int whence) { - Inode *in = f->inode; + Inode *in = f->inode.get(); int r; switch (whence) { @@ -6909,7 +6906,7 @@ int Client::read(int fd, char *buf, loff_t size, loff_t offset) int Client::_read(Fh *f, int64_t offset, uint64_t size, bufferlist *bl) { const md_config_t *conf = cct->_conf; - Inode *in = f->inode; + Inode *in = f->inode.get(); //bool lazy = f->mode == CEPH_FILE_MODE_LAZY; @@ -7043,14 +7040,14 @@ Client::C_Readahead::~C_Readahead() { 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); + client->put_cap_ref(f->inode.get(), CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE); f->readahead.dec_pending(); } int Client::_read_async(Fh *f, uint64_t off, uint64_t len, bufferlist *bl) { const md_config_t *conf = cct->_conf; - Inode *in = f->inode; + Inode *in = f->inode.get(); ldout(cct, 10) << "_read_async " << *in << " " << off << "~" << len << dendl; @@ -7114,7 +7111,7 @@ int Client::_read_async(Fh *f, uint64_t off, uint64_t len, bufferlist *bl) int Client::_read_sync(Fh *f, uint64_t off, uint64_t len, bufferlist *bl, bool *checkeof) { - Inode *in = f->inode; + Inode *in = f->inode.get(); uint64_t pos = off; int left = len; int read = 0; @@ -7246,7 +7243,7 @@ int Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf) } //ldout(cct, 7) << "write fh " << fh << " size " << size << " offset " << offset << dendl; - Inode *in = f->inode; + Inode *in = f->inode.get(); assert(in->snapid == CEPH_NOSNAP); @@ -7444,7 +7441,7 @@ done: int Client::_flush(Fh *f) { - Inode *in = f->inode; + Inode *in = f->inode.get(); int err = in->async_err; if (err != 0) { ldout(cct, 1) << __func__ << ": " << f << " on inode " << *in << " caught async_err = " @@ -7504,8 +7501,7 @@ int Client::fsync(int fd, bool syncdataonly) int Client::_fsync(Fh *f, bool syncdataonly) { int r = 0; - - Inode *in = f->inode; + Inode *in = f->inode.get(); ceph_tid_t wait_on_flush = 0; bool flushed_metadata = false; Mutex lock("Client::_fsync::lock"); @@ -7855,7 +7851,7 @@ void Client::_release_filelocks(Fh *fh) if (!fh->fcntl_locks && !fh->flock_locks) return; - Inode *in = fh->inode; + Inode *in = fh->inode.get(); ldout(cct, 10) << "_release_filelocks " << fh << " ino " << in->ino << dendl; list > to_release; @@ -7926,7 +7922,7 @@ void Client::_update_lock_state(struct flock *fl, uint64_t owner, int Client::_getlk(Fh *fh, struct flock *fl, uint64_t owner) { - Inode *in = fh->inode; + Inode *in = fh->inode.get(); ldout(cct, 10) << "_getlk " << fh << " ino " << in->ino << dendl; int ret = _do_filelock(in, fh, CEPH_LOCK_FCNTL, CEPH_MDS_OP_GETFILELOCK, 0, fl, owner); return ret; @@ -7934,7 +7930,7 @@ int Client::_getlk(Fh *fh, struct flock *fl, uint64_t owner) int Client::_setlk(Fh *fh, struct flock *fl, uint64_t owner, int sleep, void *fuse_req) { - Inode *in = fh->inode; + Inode *in = fh->inode.get(); ldout(cct, 10) << "_setlk " << fh << " ino " << in->ino << dendl; int ret = _do_filelock(in, fh, CEPH_LOCK_FCNTL, CEPH_MDS_OP_SETFILELOCK, sleep, fl, owner, fuse_req); ldout(cct, 10) << "_setlk " << fh << " ino " << in->ino << " result=" << ret << dendl; @@ -7943,7 +7939,7 @@ int Client::_setlk(Fh *fh, struct flock *fl, uint64_t owner, int sleep, void *fu int Client::_flock(Fh *fh, int cmd, uint64_t owner, void *fuse_req) { - Inode *in = fh->inode; + Inode *in = fh->inode.get(); ldout(cct, 10) << "_flock " << fh << " ino " << in->ino << dendl; int sleep = !(cmd & LOCK_NB); @@ -8097,7 +8093,7 @@ int Client::lazyio_synchronize(int fd, loff_t offset, size_t count) Fh *f = get_filehandle(fd); if (!f) return -EBADF; - Inode *in = f->inode; + Inode *in = f->inode.get(); _fsync(f, true); _release(in); @@ -9564,6 +9560,11 @@ int Client::ll_file_layout(Inode *in, ceph_file_layout *layout) return 0; } +int Client::ll_file_layout(Fh *fh, ceph_file_layout *layout) +{ + return ll_file_layout(fh->inode.get(), layout); +} + /* Currently we cannot take advantage of redundancy in reads, since we would have to go through all possible placement groups (a potentially quite large number determined by a hash), and use CRUSH @@ -9962,7 +9963,7 @@ int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length) if (objecter->osdmap_full_flag() && !(mode & FALLOC_FL_PUNCH_HOLE)) return -ENOSPC; - Inode *in = fh->inode; + Inode *in = fh->inode.get(); if (in->snapid != CEPH_NOSNAP) return -EROFS; @@ -10212,7 +10213,7 @@ int Client::fdescribe_layout(int fd, ceph_file_layout *lp) Fh *f = get_filehandle(fd); if (!f) return -EBADF; - Inode *in = f->inode; + Inode *in = f->inode.get(); *lp = in->layout; @@ -10263,7 +10264,7 @@ int Client::get_file_extent_osds(int fd, loff_t off, loff_t *len, vector& o Fh *f = get_filehandle(fd); if (!f) return -EBADF; - Inode *in = f->inode; + Inode *in = f->inode.get(); vector extents; Striper::file_to_extents(cct, in->ino, &in->layout, off, 1, in->truncate_size, extents); @@ -10317,7 +10318,7 @@ int Client::get_file_stripe_address(int fd, loff_t offset, vector Fh *f = get_filehandle(fd); if (!f) return -EBADF; - Inode *in = f->inode; + Inode *in = f->inode.get(); // which object? vector extents; @@ -10363,7 +10364,7 @@ int Client::enumerate_layout(int fd, vector& result, Fh *f = get_filehandle(fd); if (!f) return -EBADF; - Inode *in = f->inode; + Inode *in = f->inode.get(); // map to a list of extents Striper::file_to_extents(cct, in->ino, &in->layout, offset, length, in->truncate_size, result); diff --git a/src/client/Client.h b/src/client/Client.h index 2a7e75f93706d..ad4d3f26a058d 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -963,6 +963,7 @@ public: int ll_getlk(Fh *fh, struct flock *fl, uint64_t owner); int ll_setlk(Fh *fh, struct flock *fl, uint64_t owner, int sleep, void *fuse_req); int ll_flock(Fh *fh, int cmd, uint64_t owner, void *fuse_req); + int ll_file_layout(Fh *fh, ceph_file_layout *layout); void ll_interrupt(void *d); int ll_get_stripe_osd(struct Inode *in, uint64_t blockno, ceph_file_layout* layout); diff --git a/src/client/Fh.h b/src/client/Fh.h index dcf70cdbbe991..db3a28c47a8fe 100644 --- a/src/client/Fh.h +++ b/src/client/Fh.h @@ -3,16 +3,16 @@ #include "common/Readahead.h" #include "include/types.h" +#include "InodeRef.h" -struct Inode; class Cond; class ceph_lock_state_t; // file handle for any open file state struct Fh { + InodeRef 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 @@ -27,7 +27,7 @@ struct Fh { ceph_lock_state_t *fcntl_locks; ceph_lock_state_t *flock_locks; - Fh() : _ref(1), inode(0), pos(0), mds(0), mode(0), flags(0), pos_locked(false), + Fh() : _ref(1), 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; } diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index f9c380c9cb4fd..4bae900468d61 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -486,7 +486,7 @@ static void fuse_ll_ioctl(fuse_req_t req, fuse_ino_t ino, int cmd, void *arg, st struct ceph_file_layout layout; struct ceph_ioctl_layout l; Fh *fh = (Fh*)fi->fh; - cfuse->client->ll_file_layout(fh->inode, &layout); + cfuse->client->ll_file_layout(fh, &layout); l.stripe_unit = layout.fl_stripe_unit; l.stripe_count = layout.fl_stripe_count; l.object_size = layout.fl_object_size; -- 2.39.5