]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: always pass a UserPerm to chown variants
authorGreg Farnum <gfarnum@redhat.com>
Wed, 27 Jul 2016 23:05:01 +0000 (16:05 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Wed, 21 Sep 2016 23:33:46 +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/libcephfs.cc

index aa4d8ddee4193d644e37ccc4c83a798bb8bbb1b8..4e6699bdf1b39664069fe17797e5cfdd98fbc8ee 100644 (file)
@@ -6768,34 +6768,35 @@ int Client::lchmod(const char *relpath, mode_t mode, const UserPerm& perms)
   return _setattr(in, &attr, CEPH_SETATTR_MODE, perms);
 }
 
-int Client::chown(const char *relpath, int uid, int gid)
+int Client::chown(const char *relpath, uid_t new_uid, gid_t new_gid,
+                 const UserPerm& perms)
 {
   Mutex::Locker lock(client_lock);
   tout(cct) << "chown" << std::endl;
   tout(cct) << relpath << std::endl;
-  tout(cct) << uid << std::endl;
-  tout(cct) << gid << std::endl;
+  tout(cct) << new_uid << std::endl;
+  tout(cct) << new_gid << std::endl;
   filepath path(relpath);
   InodeRef in;
-  int r = path_walk(path, &in);
+  int r = path_walk(path, &in, perms);
   if (r < 0)
     return r;
   struct stat attr;
-  attr.st_uid = uid;
-  attr.st_gid = gid;
+  attr.st_uid = new_uid;
+  attr.st_gid = new_gid;
   int mask = 0;
-  if (uid != -1) mask |= CEPH_SETATTR_UID;
-  if (gid != -1) mask |= CEPH_SETATTR_GID;
-  return _setattr(in, &attr, mask);
+  if (new_uid != static_cast<uid_t>(-1)) mask |= CEPH_SETATTR_UID;
+  if (new_gid != static_cast<gid_t>(-1)) mask |= CEPH_SETATTR_GID;
+  return _setattr(in, &attr, mask, perms);
 }
 
-int Client::fchown(int fd, int uid, int gid)
+int Client::fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms)
 {
   Mutex::Locker lock(client_lock);
   tout(cct) << "fchown" << std::endl;
   tout(cct) << fd << std::endl;
-  tout(cct) << uid << std::endl;
-  tout(cct) << gid << std::endl;
+  tout(cct) << new_uid << std::endl;
+  tout(cct) << new_gid << std::endl;
   Fh *f = get_filehandle(fd);
   if (!f)
     return -EBADF;
@@ -6804,34 +6805,35 @@ int Client::fchown(int fd, int uid, int gid)
     return -EBADF;
 #endif
   struct stat attr;
-  attr.st_uid = uid;
-  attr.st_gid = gid;
+  attr.st_uid = new_uid;
+  attr.st_gid = new_gid;
   int mask = 0;
-  if (uid != -1) mask |= CEPH_SETATTR_UID;
-  if (gid != -1) mask |= CEPH_SETATTR_GID;
-  return _setattr(f->inode, &attr, mask);
+  if (new_uid != static_cast<uid_t>(-1)) mask |= CEPH_SETATTR_UID;
+  if (new_gid != static_cast<gid_t>(-1)) mask |= CEPH_SETATTR_GID;
+  return _setattr(f->inode, &attr, mask, perms);
 }
 
-int Client::lchown(const char *relpath, int uid, int gid)
+int Client::lchown(const char *relpath, uid_t new_uid, gid_t new_gid,
+                  const UserPerm& perms)
 {
   Mutex::Locker lock(client_lock);
   tout(cct) << "lchown" << std::endl;
   tout(cct) << relpath << std::endl;
-  tout(cct) << uid << std::endl;
-  tout(cct) << gid << std::endl;
+  tout(cct) << new_uid << std::endl;
+  tout(cct) << new_gid << std::endl;
   filepath path(relpath);
   InodeRef in;
   // don't follow symlinks
-  int r = path_walk(path, &in, false);
+  int r = path_walk(path, &in, perms, false);
   if (r < 0)
     return r;
   struct stat attr;
-  attr.st_uid = uid;
-  attr.st_gid = gid;
+  attr.st_uid = new_uid;
+  attr.st_gid = new_gid;
   int mask = 0;
-  if (uid != -1) mask |= CEPH_SETATTR_UID;
-  if (gid != -1) mask |= CEPH_SETATTR_GID;
-  return _setattr(in, &attr, mask);
+  if (new_uid != static_cast<uid_t>(-1)) mask |= CEPH_SETATTR_UID;
+  if (new_gid != static_cast<gid_t>(-1)) mask |= CEPH_SETATTR_GID;
+  return _setattr(in, &attr, mask, perms);
 }
 
 int Client::utime(const char *relpath, struct utimbuf *buf)
index e5fbbb8ab1538d5efc2e2e449e01bfc10ff90017..08c555871ddbadd570400ea105937ca3730977c4 100644 (file)
@@ -1075,9 +1075,11 @@ public:
   int chmod(const char *path, mode_t mode, const UserPerm& perms);
   int fchmod(int fd, mode_t mode, const UserPerm& perms);
   int lchmod(const char *path, mode_t mode, const UserPerm& perms);
-  int chown(const char *path, int uid, int gid);
-  int fchown(int fd, int uid, int gid);
-  int lchown(const char *path, int uid, int gid);
+  int chown(const char *path, uid_t new_uid, gid_t new_gid,
+           const UserPerm& perms);
+  int fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms);
+  int lchown(const char *path, uid_t new_uid, gid_t new_gid,
+            const UserPerm& perms);
   int utime(const char *path, struct utimbuf *buf);
   int lutime(const char *path, struct utimbuf *buf);
   int flock(int fd, int operation, uint64_t owner);
index e2e06c3148bc471202e9f5402f0a7c4a51ae9909..b46ed8b1ba1d62eab5162872378ea5fcb885569d 100644 (file)
@@ -1114,7 +1114,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
       const char *a = t.get_string(buf, p);
       int64_t b = t.get_int();
       int64_t c = t.get_int();
-      client->chown(a, b, c);
+      client->chown(a, b, c, perms);
     } else if (strcmp(op, "utime") == 0) {
       const char *a = t.get_string(buf, p);
       int64_t b = t.get_int();
@@ -2728,9 +2728,9 @@ int SyntheticClient::random_walk(int num_req)
     }
     
     if (op == CEPH_MDS_OP_CHOWN) {
-      if (contents.empty())         r = client->chown( cwd.c_str(), rand(), rand() );
+      if (contents.empty())         r = client->chown(cwd.c_str(), rand(), rand(), perms);
       else
-        r = client->chown( get_random_sub(), rand(), rand() );
+        r = client->chown(get_random_sub(), rand(), rand(), perms);
     }
      
     if (op == CEPH_MDS_OP_UTIME) {
@@ -3210,8 +3210,10 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data)
    *
    */
 
+  UserPerm process_perms = client->pick_my_perms();
+
   if (base[0] != '-') 
-    client->mkdir(base, 0755, client->pick_my_perms());
+    client->mkdir(base, 0755, process_perms);
 
   ifstream f(find);
   assert(f.is_open());
@@ -3316,8 +3318,8 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data)
        }
        client->close(fd);
 
-       //client->chmod(f.c_str(), mode & 0777, perms);
-       client->chown(f.c_str(), uid, gid);
+       //client->chmod(f.c_str(), mode & 0777, perms, process_perms);
+       client->chown(f.c_str(), uid, gid, process_perms);
 
        struct utimbuf ut;
        ut.modtime = mtime;
index 2703710d9593f69c1f650371d6707463ed50a062..3ffada336b29a9d5cfcb891b62c68c766723d83f 100644 (file)
@@ -751,21 +751,24 @@ extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path,
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
-  return cmount->get_client()->chown(path, uid, gid);
+  UserPerm perms = cmount->get_client()->pick_my_perms();
+  return cmount->get_client()->chown(path, uid, gid, perms);
 }
 extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd,
                           int uid, int gid)
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
-  return cmount->get_client()->fchown(fd, uid, gid);
+  UserPerm perms = cmount->get_client()->pick_my_perms();
+  return cmount->get_client()->fchown(fd, uid, gid, perms);
 }
 extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path,
                           int uid, int gid)
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
-  return cmount->get_client()->lchown(path, uid, gid);
+  UserPerm perms = cmount->get_client()->pick_my_perms();
+  return cmount->get_client()->lchown(path, uid, gid, perms);
 }