: inode(in), offset(0), this_offset(2), next_offset(2),
release_count(0), ordered_count(0), start_shared_gen(0),
buffer(0) {
- inode->get();
}
// cons/des
dn->offset = dir_result_t::make_fpos(fg, i + readdir_offset);
// add to cached result list
- in->get();
- request->readdir_result.push_back(pair<string,Inode*>(dname, in));
+ request->readdir_result.push_back(pair<string,InodeRef>(dname, in));
ldout(cct, 15) << __func__ << " " << hex << dn->offset << dec << ": '" << dname << "' -> " << in->ino << dendl;
}
*pcreated = got_created_ino;
if (request->target) {
- (*ptarget) = request->target;
+ ptarget->swap(request->target);
ldout(cct, 20) << "make_request target is " << *ptarget->get() << dendl;
} else {
if (got_created_ino && (p = inode_map.find(vinodeno_t(created_ino, CEPH_NOSNAP))) != inode_map.end()) {
void Client::put_request(MetaRequest *request)
{
if (request->_put()) {
- if (request->inode())
- put_inode(request->take_inode());
- if (request->old_inode())
- put_inode(request->take_old_inode());
int op = -1;
if (request->success)
op = request->get_op();
- Inode *other_in = request->take_other_inode();
+ InodeRef other_in;
+ request->take_other_inode(&other_in);
delete request;
if (other_in) {
if (other_in->dir &&
(op == CEPH_MDS_OP_RMDIR || op == CEPH_MDS_OP_RENAME))
- _try_to_trim_inode(other_in);
- put_inode(other_in);
+ _try_to_trim_inode(other_in.get());
}
}
}
ldout(cct, 10) << "_closedir(" << dirp << ")" << dendl;
if (dirp->inode) {
ldout(cct, 10) << "_closedir detaching inode " << dirp->inode << dendl;
- put_inode(dirp->inode);
- dirp->inode = 0;
+ dirp->inode.reset();
}
_readdir_drop_dirp_buffer(dirp);
delete dirp;
{
ldout(cct, 10) << "_readdir_drop_dirp_buffer " << dirp << dendl;
if (dirp->buffer) {
- for (unsigned i = 0; i < dirp->buffer->size(); i++)
- put_inode((*dirp->buffer)[i].second);
delete dirp->buffer;
dirp->buffer = NULL;
}
if (dirp->inode && dirp->inode->snapid == CEPH_SNAPDIR)
op = CEPH_MDS_OP_LSSNAP;
- Inode *diri = dirp->inode;
+ InodeRef& diri = dirp->inode;
MetaRequest *req = new MetaRequest(op);
filepath path;
diri->make_nosnap_relative_path(path);
req->set_filepath(path);
- req->set_inode(diri);
+ req->set_inode(diri.get());
req->head.args.readdir.frag = fg;
if (dirp->last_name.length()) {
req->path2.set_path(dirp->last_name.c_str());
_readdir_drop_dirp_buffer(dirp);
- dirp->buffer = new vector<pair<string,Inode*> >;
+ dirp->buffer = new vector<pair<string,InodeRef> >;
dirp->buffer->swap(req->readdir_result);
if (fg != req->readdir_reply_frag) {
frag_t fg = dirp->frag();
uint32_t off = dirp->fragpos();
- Inode *diri = dirp->inode;
+ InodeRef& diri = dirp->inode;
if (dirp->at_end())
return 0;
dirp->offset = dir_result_t::make_fpos(fg, off);
while (off >= dirp->this_offset &&
off - dirp->this_offset < dirp->buffer->size()) {
- pair<string,Inode*>& ent = (*dirp->buffer)[off - dirp->this_offset];
+ pair<string,InodeRef>& ent = (*dirp->buffer)[off - dirp->this_offset];
- int stmask = fill_stat(ent.second, &st);
+ int stmask = fill_stat(ent.second, &st);
fill_dirent(&de, ent.first.c_str(), st.st_mode, st.st_ino, dirp->offset + 1);
client_lock.Unlock();
req->set_filepath(path);
req->set_inode(ino);
- int r = make_request(req, -1, -1, NULL, NULL, rand() % mdsmap->get_num_in_mds());
+ InodeRef target;
+ int r = make_request(req, -1, -1, &target, NULL, rand() % mdsmap->get_num_in_mds());
// Give caller a reference to the parent ino if they provided a pointer.
if (parent != NULL) {
if (r == 0) {
- *parent = req->target;
+ *parent = target.get();
_ll_get(*parent);
ldout(cct, 3) << "lookup_parent found parent " << (*parent)->ino << dendl;
} else {
tout(cct) << "ll_fsyncdir" << std::endl;
tout(cct) << (unsigned long)dirp << std::endl;
- return _fsync(dirp->inode, false);
+ return _fsync(dirp->inode.get(), false);
}
int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid)
#include "include/filepath.h"
#include "include/atomic.h"
#include "mds/mdstypes.h"
+#include "InodeRef.h"
#include "common/Mutex.h"
#include "messages/MClientRequest.h"
class MClientReply;
-struct Inode;
class Dentry;
struct MetaRequest {
private:
- Inode *_inode;
- Inode *_old_inode, *_other_inode;
+ InodeRef _inode, _old_inode, _other_inode;
Dentry *_dentry; //associated with path
Dentry *_old_dentry; //associated with path2
public:
uint64_t readdir_offset;
frag_t readdir_reply_frag;
- vector<pair<string,Inode*> > readdir_result;
+ vector<pair<string,InodeRef> > readdir_result;
bool readdir_end;
int readdir_num;
string readdir_last_name;
Cond *dispatch_cond; // who to kick back
list<Cond*> waitfor_safe;
- Inode *target;
+ InodeRef target;
MetaRequest(int op) :
- _inode(NULL), _old_inode(NULL), _other_inode(NULL),
_dentry(NULL), _old_dentry(NULL),
tid(0),
inode_drop(0), inode_unless(0),
readdir_offset(0), readdir_end(false), readdir_num(0),
got_unsafe(false), item(this), unsafe_item(this), unsafe_dir_item(this),
lock("MetaRequest lock"),
- caller_cond(0), dispatch_cond(0),
- target(0) {
+ caller_cond(0), dispatch_cond(0) {
memset(&head, 0, sizeof(ceph_mds_request_head));
head.op = op;
}
~MetaRequest();
- void set_inode(Inode *in);
- Inode *inode();
- Inode *take_inode() {
- Inode *i = _inode;
- _inode = 0;
- return i;
- }
- void set_old_inode(Inode *in);
- Inode *old_inode();
- Inode *take_old_inode() {
- Inode *i = _old_inode;
- _old_inode = NULL;
- return i;
- }
- void set_other_inode(Inode *in);
- Inode *other_inode();
- Inode *take_other_inode() {
- Inode *i = _other_inode;
- _other_inode = 0;
- return i;
+ void set_inode(Inode *in) {
+ _inode = in;
+ }
+ Inode *inode() {
+ return _inode.get();
+ }
+ void take_inode(InodeRef *out) {
+ out->swap(_inode);
+ }
+ void set_old_inode(Inode *in) {
+ _old_inode = in;
+ }
+ Inode *old_inode() {
+ return _old_inode.get();
+ }
+ void take_old_inode(InodeRef *out) {
+ out->swap(_old_inode);
+ }
+ void set_other_inode(Inode *in) {
+ _old_inode = in;
+ }
+ Inode *other_inode() {
+ return _other_inode.get();
+ }
+ void take_other_inode(InodeRef *out) {
+ out->swap(_other_inode);
}
void set_dentry(Dentry *d);
Dentry *dentry();