]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: abstract out the guts of ll_create into _ll_create
authorJeff Layton <jlayton@redhat.com>
Mon, 24 Oct 2016 14:02:59 +0000 (10:02 -0400)
committerJeff Layton <jlayton@redhat.com>
Tue, 25 Oct 2016 17:06:28 +0000 (13:06 -0400)
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 <jlayton@redhat.com>
src/client/Client.cc
src/client/Client.h

index 969113a9aa192d133ba43682eceef811c078d931..6f4c2b1dd738a8068fe8609146e9a1fcffebcbb8 100644 (file)
@@ -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;
index d2b4755baba1c833e7837079498849c475a4007a..a48f30b290789c5d5cf9bba0f8a1567b40a507b0 100644 (file)
@@ -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);