]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: switch ll_open and ll_create to be UserPerm-based
authorGreg Farnum <gfarnum@redhat.com>
Thu, 28 Jul 2016 18:51:05 +0000 (11:51 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Wed, 21 Sep 2016 23:33:48 +0000 (16:33 -0700)
Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/SyntheticClient.cc
src/client/fuse_ll.cc
src/libcephfs.cc

index 0d457b4ef3a5d0676da3f7297990b597020f9477..faed0da72421b195f7c5673da599df88e12c0187 100644 (file)
@@ -11321,7 +11321,7 @@ int Client::ll_fsyncdir(dir_result_t *dirp)
   return _fsync(dirp->inode.get(), false);
 }
 
-int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid)
+int Client::ll_open(Inode *in, int flags, Fh **fhp, const UserPerm& perms)
 {
   assert(!(flags & O_CREAT));
 
@@ -11335,17 +11335,13 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid)
   tout(cct) << flags << std::endl;
 
   int r;
-  if (uid < 0) {
-    uid = get_uid();
-    gid = get_gid();
-  }
   if (!cct->_conf->fuse_default_permissions) {
-    r = may_open(in, flags, uid, gid);
+    r = may_open(in, flags, perms);
     if (r < 0)
       goto out;
   }
 
-  r = _open(in, flags, 0, fhp /* may be NULL */, uid, gid);
+  r = _open(in, flags, 0, fhp /* may be NULL */, perms);
 
  out:
   Fh *fhptr = fhp ? *fhp : NULL;
@@ -11360,14 +11356,15 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid)
 
 int Client::ll_create(Inode *parent, const char *name, mode_t mode,
                      int flags, struct stat *attr, Inode **outp, Fh **fhp,
-                     int uid, int gid)
+                     const UserPerm& perms)
 {
   Mutex::Locker lock(client_lock);
 
   vinodeno_t vparent = _get_vino(parent);
 
   ldout(cct, 3) << "ll_create " << vparent << " " << name << " 0" << oct <<
-    mode << dec << " " << flags << ", uid " << uid << ", gid " << gid << dendl;
+    mode << dec << " " << flags << ", uid " << perms.uid()
+               << ", gid " << perms.gid() << dendl;
   tout(cct) << "ll_create" << std::endl;
   tout(cct) << vparent.ino.val << std::endl;
   tout(cct) << name << std::endl;
@@ -11376,19 +11373,19 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode,
 
   bool created = false;
   InodeRef in;
-  int r = _lookup(parent, name, CEPH_STAT_CAP_INODE_ALL, &in, uid, gid);
+  int r = _lookup(parent, name, CEPH_STAT_CAP_INODE_ALL, &in, perms);
 
   if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL))
     return -EEXIST;
 
   if (r == -ENOENT && (flags & O_CREAT)) {
     if (!cct->_conf->fuse_default_permissions) {
-      r = may_create(parent, uid, gid);
+      r = may_create(parent, perms);
       if (r < 0)
        goto out;
     }
     r = _create(parent, name, flags, mode, &in, fhp /* may be NULL */,
-               0, 0, 0, NULL, &created, uid, gid);
+               0, 0, 0, NULL, &created, perms);
     if (r < 0)
       goto out;
   }
@@ -11402,7 +11399,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode,
   ldout(cct, 20) << "ll_create created = " << created << dendl;
   if (!created) {
     if (!cct->_conf->fuse_default_permissions) {
-      r = may_open(in.get(), flags, uid, gid);
+      r = may_open(in.get(), flags, perms);
       if (r < 0) {
        if (fhp && *fhp) {
          int release_r = _release_fh(*fhp);
@@ -11412,7 +11409,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode,
       }
     }
     if (fhp && (*fhp == NULL)) {
-      r = _open(in.get(), flags, mode, fhp, uid, gid);
+      r = _open(in.get(), flags, mode, fhp, perms);
       if (r < 0)
        goto out;
     }
index d10233d18f072c06927063422285960c7d9f04a3..ac45b1bf0c95ba69232e83f870e28540578831f5 100644 (file)
@@ -1202,10 +1202,10 @@ public:
                const char *newname, const UserPerm& perm);
   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, int uid = -1, int gid = -1);
+  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,
-               struct stat *attr, Inode **out, Fh **fhp, int uid = -1,
-               int gid = -1);
+               struct stat *attr, Inode **out, Fh **fhp,
+               const UserPerm& perms);
   int ll_read_block(Inode *in, uint64_t blockid, char *buf,  uint64_t offset,
                    uint64_t length, file_layout_t* layout);
 
index e45b4ad20899e7050664cd8ded93424ac76c84e1..d2fa9fc6df31c1f904ed83cabb1a647dd7c91551 100644 (file)
@@ -1374,7 +1374,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
       Fh *fhp;
       if (ll_inos.count(i)) {
        i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP));
-       if (client->ll_open(i1, f, &fhp) == 0)
+       if (client->ll_open(i1, f, &fhp, perms) == 0)
          ll_files[r] = fhp;
        client->ll_put(i1);
       }
@@ -1389,7 +1389,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
       if (ll_inos.count(i)) {
        Fh *fhp;
        i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP));
-       if (client->ll_create(i1, n, m, f, &attr, NULL, &fhp) == 0) {
+       if (client->ll_create(i1, n, m, f, &attr, NULL, &fhp, perms) == 0) {
          ll_inos[ri] = attr.st_ino;
          ll_files[r] = fhp;
        }
index 42bd14431ce8ad3cfc225ab1bce0442774763150..89ec8ee77d18f5890fb9b8b6e5555233ec454d4d 100644 (file)
@@ -477,8 +477,9 @@ static void fuse_ll_open(fuse_req_t req, fuse_ino_t ino,
   const struct fuse_ctx *ctx = fuse_req_ctx(req);
   Inode *in = cfuse->iget(ino);
   Fh *fh = NULL;
+  UserPerm perms(ctx->uid, ctx->gid);
 
-  int r = cfuse->client->ll_open(in, fi->flags, &fh, ctx->uid, ctx->gid);
+  int r = cfuse->client->ll_open(in, fi->flags, &fh, perms);
   if (r == 0) {
     fi->fh = (uint64_t)fh;
 #if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8)
@@ -677,12 +678,13 @@ static void fuse_ll_create(fuse_req_t req, fuse_ino_t parent, const char *name,
   Inode *i1 = cfuse->iget(parent), *i2;
   struct fuse_entry_param fe;
   Fh *fh = NULL;
+  UserPerm perms(ctx->uid, ctx->gid);
 
   memset(&fe, 0, sizeof(fe));
 
   // pass &i2 for the created inode so that ll_create takes an initial ll_ref
   int r = cfuse->client->ll_create(i1, name, mode, fi->flags, &fe.attr, &i2,
-                                  &fh, ctx->uid, ctx->gid);
+                                  &fh, perms);
   if (r == 0) {
     fi->fh = (uint64_t)fh;
     fe.ino = cfuse->make_fake_ino(fe.attr.st_ino, fe.attr.st_dev);
index 0d1036366897c55a8b515836a25c9722a29ea3cf..0ef9337980e76662d98f6ca7175eb7a33e8b2706 100644 (file)
@@ -1450,7 +1450,8 @@ extern "C" int ceph_ll_setattr(class ceph_mount_info *cmount,
 extern "C" int ceph_ll_open(class ceph_mount_info *cmount, Inode *in,
                            int flags, Fh **fh, int uid, int gid)
 {
-  return (cmount->get_client()->ll_open(in, flags, fh, uid, gid));
+  UserPerm perms(uid, gid);
+  return (cmount->get_client()->ll_open(in, flags, fh, perms));
 }
 
 extern "C" int ceph_ll_read(class ceph_mount_info *cmount, Fh* filehandle,
@@ -1546,8 +1547,9 @@ extern "C" int ceph_ll_create(class ceph_mount_info *cmount,
                              mode_t mode, int flags, struct stat *attr,
                              struct Inode **out, Fh **fhp, int uid, int gid)
 {
+  UserPerm perms(uid, gid);
   return (cmount->get_client())->ll_create(parent, name, mode, flags,
-                                          attr, out, fhp, uid, gid);
+                                          attr, out, fhp, perms);
 }
 
 extern "C" int ceph_ll_mknod(class ceph_mount_info *cmount,