From: Jeff Layton Date: Mon, 24 Oct 2016 14:02:59 +0000 (-0400) Subject: client: abstract out the guts of ll_create into _ll_create X-Git-Tag: v11.1.0~383^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bf5c3d13e480a8fb19c41172cbae6ea776687156;p=ceph.git client: abstract out the guts of ll_create into _ll_create Make a common function that can be called and move the handling of the out inode reference and attribute handling into the caller. Signed-off-by: Jeff Layton --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 969113a9aa19..6f4c2b1dd738 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -11670,17 +11670,15 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, const UserPerm& perms) return r; } -int Client::ll_create(Inode *parent, const char *name, mode_t mode, - int flags, struct stat *attr, Inode **outp, Fh **fhp, +int Client::_ll_create(Inode *parent, const char *name, mode_t mode, + int flags, InodeRef *in, int caps, Fh **fhp, const UserPerm& perms) { *fhp = NULL; - Mutex::Locker lock(client_lock); - vinodeno_t vparent = _get_vino(parent); - ldout(cct, 3) << "ll_create " << vparent << " " << name << " 0" << oct << + ldout(cct, 3) << "_ll_create " << vparent << " " << name << " 0" << oct << mode << dec << " " << flags << ", uid " << perms.uid() << ", gid " << perms.gid() << dendl; tout(cct) << "ll_create" << std::endl; @@ -11690,8 +11688,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, tout(cct) << flags << std::endl; bool created = false; - InodeRef in; - int r = _lookup(parent, name, CEPH_STAT_CAP_INODE_ALL, &in, perms); + int r = _lookup(parent, name, caps, in, perms); if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL)) return -EEXIST; @@ -11702,7 +11699,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, if (r < 0) goto out; } - r = _create(parent, name, flags, mode, &in, fhp, 0, 0, 0, NULL, &created, + r = _create(parent, name, flags, mode, in, fhp, 0, 0, 0, NULL, &created, perms); if (r < 0) goto out; @@ -11711,13 +11708,12 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, if (r < 0) goto out; - assert(in); - fill_stat(in, attr); + assert(*in); - ldout(cct, 20) << "ll_create created = " << created << dendl; + ldout(cct, 20) << "_ll_create created = " << created << dendl; if (!created) { if (!cct->_conf->fuse_default_permissions) { - r = may_open(in.get(), flags, perms); + r = may_open(in->get(), flags, perms); if (r < 0) { if (*fhp) { int release_r = _release_fh(*fhp); @@ -11727,30 +11723,55 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, } } if (*fhp == NULL) { - r = _open(in.get(), flags, mode, fhp, perms); + r = _open(in->get(), flags, mode, fhp, perms); if (r < 0) goto out; } } out: - if (r < 0) - attr->st_ino = 0; - if (*fhp) { ll_unclosed_fh_set.insert(*fhp); } + + ino_t ino = 0; + if (r >= 0) { + Inode *inode = in->get(); + if (use_faked_inos()) + ino = inode->faked_ino; + else + ino = inode->ino; + } + tout(cct) << (unsigned long)*fhp << std::endl; - tout(cct) << attr->st_ino << std::endl; - ldout(cct, 3) << "ll_create " << parent << " " << name << " 0" << oct << + tout(cct) << ino << std::endl; + ldout(cct, 3) << "_ll_create " << parent << " " << name << " 0" << oct << mode << dec << " " << flags << " = " << r << " (" << *fhp << " " << - hex << attr->st_ino << dec << ")" << dendl; + hex << ino << dec << ")" << dendl; - // passing an Inode in outp requires an additional ref - if (outp) { - if (in) + return r; +} + +int Client::ll_create(Inode *parent, const char *name, mode_t mode, + int flags, struct stat *attr, Inode **outp, Fh **fhp, + const UserPerm& perms) +{ + InodeRef in; + Mutex::Locker lock(client_lock); + + int r = _ll_create(parent, name, mode, flags, &in, CEPH_STAT_CAP_INODE_ALL, + fhp, perms); + if (r >= 0) { + assert(in); + + // passing an Inode in outp requires an additional ref + if (outp) { _ll_get(in.get()); - *outp = in.get(); + *outp = in.get(); + } + fill_stat(in, attr); + } else { + attr->st_ino = 0; } return r; diff --git a/src/client/Client.h b/src/client/Client.h index d2b4755baba1..a48f30b29078 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1150,6 +1150,9 @@ public: int ll_link(Inode *in, Inode *newparent, const char *newname, struct stat *attr, const UserPerm& perm); int ll_open(Inode *in, int flags, Fh **fh, const UserPerm& perms); + int _ll_create(Inode *parent, const char *name, mode_t mode, + int flags, InodeRef *in, int caps, Fh **fhp, + const UserPerm& perms); int ll_create(Inode *parent, const char *name, mode_t mode, int flags, struct stat *attr, Inode **out, Fh **fhp, const UserPerm& perms);