]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: always pass UserPerm to unlink functions
authorGreg Farnum <gfarnum@redhat.com>
Mon, 11 Jul 2016 23:06:08 +0000 (16:06 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Wed, 31 Aug 2016 21:36:29 +0000 (14:36 -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 51888e50530cf42c5d7d9ba39d1da57e09e2bd96..f29d8a04bc68a3cfb0fc05bd7d6b40966709741c 100644 (file)
@@ -6153,7 +6153,7 @@ int Client::link(const char *relexisting, const char *relpath, const UserPerm& p
   return r;
 }
 
-int Client::unlink(const char *relpath)
+int Client::unlink(const char *relpath, const UserPerm& perm)
 {
   Mutex::Locker lock(client_lock);
   tout(cct) << "unlink" << std::endl;
@@ -6163,15 +6163,15 @@ int Client::unlink(const char *relpath)
   string name = path.last_dentry();
   path.pop_dentry();
   InodeRef dir;
-  int r = path_walk(path, &dir);
+  int r = path_walk(path, &dir, perm);
   if (r < 0)
     return r;
   if (cct->_conf->client_permissions) {
-    r = may_delete(dir.get(), name.c_str());
+    r = may_delete(dir.get(), name.c_str(), perm);
     if (r < 0)
       return r;
   }
-  return _unlink(dir.get(), name.c_str());
+  return _unlink(dir.get(), name.c_str(), perm);
 }
 
 int Client::rename(const char *relfrom, const char *relto)
@@ -10822,9 +10822,11 @@ int Client::ll_symlink(Inode *parent, const char *name, const char *value,
   return r;
 }
 
-int Client::_unlink(Inode *dir, const char *name, int uid, int gid)
+int Client::_unlink(Inode *dir, const char *name, const UserPerm& perm)
 {
-  ldout(cct, 3) << "_unlink(" << dir->ino << " " << name << " uid " << uid << " gid " << gid << ")" << dendl;
+  ldout(cct, 3) << "_unlink(" << dir->ino << " " << name
+               << " uid " << perm.uid() << " gid " << perm.gid()
+               << ")" << dendl;
 
   if (dir->snapid != CEPH_NOSNAP) {
     return -EROFS;
@@ -10847,7 +10849,7 @@ int Client::_unlink(Inode *dir, const char *name, int uid, int gid)
   req->dentry_drop = CEPH_CAP_FILE_SHARED;
   req->dentry_unless = CEPH_CAP_FILE_EXCL;
 
-  res = _lookup(dir, name, 0, &otherin, uid, gid);
+  res = _lookup(dir, name, 0, &otherin, perm);
   if (res < 0)
     goto fail;
   req->set_other_inode(otherin.get());
@@ -10855,7 +10857,7 @@ int Client::_unlink(Inode *dir, const char *name, int uid, int gid)
 
   req->set_inode(dir);
 
-  res = make_request(req, uid, gid);
+  res = make_request(req, perm);
 
   trim_cache();
   ldout(cct, 3) << "unlink(" << path << ") = " << res << dendl;
@@ -10866,7 +10868,7 @@ int Client::_unlink(Inode *dir, const char *name, int uid, int gid)
   return res;
 }
 
-int Client::ll_unlink(Inode *in, const char *name, int uid, int gid)
+int Client::ll_unlink(Inode *in, const char *name, const UserPerm& perm)
 {
   Mutex::Locker lock(client_lock);
 
@@ -10878,11 +10880,11 @@ int Client::ll_unlink(Inode *in, const char *name, int uid, int gid)
   tout(cct) << name << std::endl;
 
   if (!cct->_conf->fuse_default_permissions) {
-    int r = may_delete(in, name, uid, gid);
+    int r = may_delete(in, name, perm);
     if (r < 0)
       return r;
   }
-  return _unlink(in, name, uid, gid);
+  return _unlink(in, name, perm);
 }
 
 int Client::_rmdir(Inode *dir, const char *name, int uid, int gid)
index 127c5748bb8110e18217b3bd75a7fd25a6081f6d..0c243610b6500131e77547c7dca6a85362ddfcb9 100644 (file)
@@ -787,7 +787,7 @@ private:
 
   int _link(Inode *in, Inode *dir, const char *name, const UserPerm& perm,
            InodeRef *inp = 0);
-  int _unlink(Inode *dir, const char *name, int uid=-1, int gid=-1);
+  int _unlink(Inode *dir, const char *name, const UserPerm& perm);
   int _rename(Inode *olddir, const char *oname, Inode *ndir, const char *nname, int uid=-1, int gid=-1);
   int _mkdir(Inode *dir, const char *name, mode_t mode, int uid=-1, int gid=-1, InodeRef *inp = 0);
   int _rmdir(Inode *dir, const char *name, int uid=-1, int gid=-1);
@@ -1026,7 +1026,7 @@ public:
   void seekdir(dir_result_t *dirp, loff_t offset);
 
   int link(const char *existing, const char *newname, const UserPerm& perm);
-  int unlink(const char *path);
+  int unlink(const char *path, const UserPerm& perm);
   int rename(const char *from, const char *to);
 
   // dirs
@@ -1159,7 +1159,7 @@ public:
               Inode **out, int uid = -1, int gid = -1);
   int ll_symlink(Inode *in, const char *name, const char *value,
                 struct stat *attr, Inode **out, int uid = -1, int gid = -1);
-  int ll_unlink(Inode *in, const char *name, int uid = -1, int gid = -1);
+  int ll_unlink(Inode *in, const char *name, const UserPerm& perm);
   int ll_rmdir(Inode *in, const char *name, int uid = -1, int gid = -1);
   int ll_rename(Inode *parent, const char *name, Inode *newparent,
                const char *newname, int uid = -1, int gid = -1);
index d6e396f950fc81c3411fe1c58d732bc4d9bb95d7..255870f302583f9cac75f5b473d25b8dc766e007 100644 (file)
@@ -1075,7 +1075,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
       client->link(a, b, perms);
     } else if (strcmp(op, "unlink") == 0) {
       const char *a = t.get_string(buf, p);
-      client->unlink(a);
+      client->unlink(a, perms);
     } else if (strcmp(op, "rename") == 0) {
       const char *a = t.get_string(buf, p);
       const char *b = t.get_string(buf2, p);
@@ -1311,7 +1311,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
       const char *n = t.get_string(buf, p);
       if (ll_inos.count(i)) {
        i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP));
-       client->ll_unlink(i1, n);
+       client->ll_unlink(i1, n, perms);
        client->ll_put(i1);
       }
     } else if (strcmp(op, "ll_rmdir") == 0) {
@@ -1584,7 +1584,7 @@ int SyntheticClient::clean_dir(string& basedir)
       clean_dir(file);
       client->rmdir(file.c_str());
     } else {
-      client->unlink(file.c_str());
+      client->unlink(file.c_str(), perms);
     }
   }
 
@@ -1842,6 +1842,7 @@ int SyntheticClient::make_files(int num, int count, int priv, bool more)
 {
   int whoami = client->get_nodeid().v;
   char d[255];
+  UserPerm perms = client->pick_my_perms();
 
   if (priv) {
     for (int c=0; c<count; c++) {
@@ -1872,7 +1873,7 @@ int SyntheticClient::make_files(int num, int count, int priv, bool more)
       if (more) {
         client->lstat(d, &st);
         int fd = client->open(d, O_RDONLY);
-        client->unlink(d);
+        client->unlink(d, perms);
         client->close(fd);
       }
 
@@ -1941,6 +1942,7 @@ int SyntheticClient::open_shared(int num, int count)
 {
   // files
   char d[255];
+  UserPerm perms = client->pick_my_perms();
   for (int c=0; c<count; c++) {
     // open
     list<int> fds;
@@ -1953,7 +1955,7 @@ int SyntheticClient::open_shared(int num, int count)
     if (false && client->get_nodeid() == 0)
       for (int n=0; n<num; n++) {
        snprintf(d, sizeof(d), "test/file.%d", n);
-       client->unlink(d);
+       client->unlink(d, perms);
       }
 
     while (!fds.empty()) {
@@ -2016,7 +2018,8 @@ int SyntheticClient::check_first_primary(int fh)
 
 int SyntheticClient::rm_file(string& fn)
 {
-  return client->unlink(fn.c_str());
+  UserPerm perms = client->pick_my_perms();
+  return client->unlink(fn.c_str(), perms);
 }
 
 int SyntheticClient::write_file(string& fn, int size, loff_t wrsize)   // size is in MB, wrsize in bytes
@@ -2687,7 +2690,7 @@ int SyntheticClient::random_walk(int num_req)
       if (contents.empty())
         op = CEPH_MDS_OP_READDIR;
       else 
-        r = client->unlink( get_random_sub() );   // will fail on dirs
+        r = client->unlink(get_random_sub(), perms);   // will fail on dirs
     }
      
     if (op == CEPH_MDS_OP_RENAME) {
@@ -2888,7 +2891,7 @@ void SyntheticClient::foo()
       }
       for (int i=0; i<10; i++) {
        snprintf(b, sizeof(b), "/b/%d", i);
-       client->unlink(b);
+       client->unlink(b, perms);
       }
     }
     return;
@@ -2897,7 +2900,7 @@ void SyntheticClient::foo()
     // bug1.cpp
     const char *fn = "blah";
     char buffer[8192]; 
-    client->unlink(fn);
+    client->unlink(fn, perms);
     int handle = client->open(fn,O_CREAT|O_RDWR,S_IRWXU);
     assert(handle>=0);
     int r=client->write(handle,buffer,8192);
@@ -2993,7 +2996,7 @@ void SyntheticClient::foo()
       char dst[80];
       snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
       snprintf(dst, sizeof(dst), "syn.0.0/dir.%d/dir.%d/newlink.%d", d, e, f);
-      client->unlink(dst);
+      client->unlink(dst, perms);
     }
 
     
@@ -3010,12 +3013,12 @@ void SyntheticClient::foo()
   
   // unlink fun
   client->mknod("a", 0644);
-  client->unlink("a");
+  client->unlink("a", perms);
   client->mknod("b", 0644);
   client->link("b", "c", perms);
-  client->unlink("c");
+  client->unlink("c", perms);
   client->mkdir("d", 0755);
-  client->unlink("d");
+  client->unlink("d", perms);
   client->rmdir("d");
 
   // rename fun
@@ -3136,11 +3139,11 @@ int SyntheticClient::thrash_links(const char *basedir, int dirs, int files, int
        break;
       case 1: 
        client->mknod(src.c_str(), 0755); 
-       client->unlink(dst.c_str());
+       client->unlink(dst.c_str(), perms);
        client->link(src.c_str(), dst.c_str(), perms); 
        break;
-      case 2: client->unlink(src.c_str()); break;
-      case 3: client->unlink(dst.c_str()); break;
+      case 2: client->unlink(src.c_str(), perms); break;
+      case 3: client->unlink(dst.c_str(), perms); break;
        //case 4: client->mknod(src.c_str(), 0755); break;
        //case 5: client->mknod(dst.c_str(), 0755); break;
       }
index 3390f3b4e0804a33c9c4a8d88c6c650a5568c5f4..9f1139cb389fa180273dfeae7bf7ce75343e2587 100644 (file)
@@ -377,8 +377,9 @@ static void fuse_ll_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
   CephFuse::Handle *cfuse = fuse_ll_req_prepare(req);
   const struct fuse_ctx *ctx = fuse_req_ctx(req);
   Inode *in = cfuse->iget(parent);
+  UserPerm perm(ctx->uid, ctx->gid);
 
-  int r = cfuse->client->ll_unlink(in, name, ctx->uid, ctx->gid);
+  int r = cfuse->client->ll_unlink(in, name, perm);
   fuse_reply_err(req, -r);
 
   cfuse->iput(in); // iput required
index abcf303e33b942492c54e0ded30a4196d4d060c2..12a51e8f09f7145feb2e08752d53ff3f75b8621a 100644 (file)
@@ -553,7 +553,8 @@ extern "C" int ceph_unlink(struct ceph_mount_info *cmount, const char *path)
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
-  return cmount->get_client()->unlink(path);
+  UserPerm perms = cmount->get_client()->pick_my_perms();
+  return cmount->get_client()->unlink(path, perms);
 }
 
 extern "C" int ceph_rename(struct ceph_mount_info *cmount, const char *from,
@@ -1585,7 +1586,8 @@ extern "C" int ceph_ll_unlink(class ceph_mount_info *cmount,
                              Inode *in, const char *name,
                              int uid, int gid)
 {
-  return (cmount->get_client()->ll_unlink(in, name, uid, gid));
+  UserPerm perms(uid, gid);
+  return (cmount->get_client()->ll_unlink(in, name, perms));
 }
 
 extern "C" int ceph_ll_statfs(class ceph_mount_info *cmount,