]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: always pass a UserPerm to public setattr variants
authorGreg Farnum <gfarnum@redhat.com>
Wed, 27 Jul 2016 22:26:07 +0000 (15:26 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Wed, 31 Aug 2016 21:38:49 +0000 (14:38 -0700)
We also recast our private _setattr() stuff to be implemented in terms of
UserPerm instead of uid/gid, and translate the other direction.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/client/Client.cc
src/client/Client.h
src/libcephfs.cc

index 28209010f2593567291770af6af110a94b90f7d6..3311311d3d7c5ab06b84b8fe63e9773cc86038b1 100644 (file)
@@ -6560,11 +6560,9 @@ force_request:
   return res;
 }
 
-int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid,
-                    InodeRef *inp)
+int Client::_setattr(Inode *in, struct stat *attr, int mask,
+                    const UserPerm& perms, InodeRef *inp)
 {
-  // FIXME
-  UserPerm perms(uid, gid);
   int ret = _do_setattr(in, attr, mask, perms, inp);
   if (ret < 0)
    return ret;
@@ -6573,21 +6571,23 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid,
   return ret;
 }
 
-int Client::_setattr(InodeRef &in, struct stat *attr, int mask)
+int Client::_setattr(InodeRef &in, struct stat *attr, int mask,
+                    const UserPerm& perms)
 {
   mask &= (CEPH_SETATTR_MODE | CEPH_SETATTR_UID |
           CEPH_SETATTR_GID | CEPH_SETATTR_MTIME |
           CEPH_SETATTR_ATIME | CEPH_SETATTR_SIZE |
           CEPH_SETATTR_CTIME);
   if (cct->_conf->client_permissions) {
-    int r = may_setattr(in.get(), attr, mask);
+    int r = may_setattr(in.get(), attr, mask, perms);
     if (r < 0)
       return r;
   }
-  return _setattr(in.get(), attr, mask);
+  return _setattr(in.get(), attr, mask, perms);
 }
 
-int Client::setattr(const char *relpath, struct stat *attr, int mask)
+int Client::setattr(const char *relpath, struct stat *attr, int mask,
+                   const UserPerm& perms)
 {
   Mutex::Locker lock(client_lock);
   tout(cct) << "setattr" << std::endl;
@@ -6596,13 +6596,14 @@ int Client::setattr(const char *relpath, struct stat *attr, int mask)
 
   filepath path(relpath);
   InodeRef in;
-  int r = path_walk(path, &in);
+  int r = path_walk(path, &in, perms);
   if (r < 0)
     return r;
-  return _setattr(in, attr, mask);
+  return _setattr(in, attr, mask, perms);
 }
 
-int Client::fsetattr(int fd, struct stat *attr, int mask)
+int Client::fsetattr(int fd, struct stat *attr, int mask,
+                    const UserPerm& perms)
 {
   Mutex::Locker lock(client_lock);
   tout(cct) << "fsetattr" << std::endl;
@@ -6616,7 +6617,7 @@ int Client::fsetattr(int fd, struct stat *attr, int mask)
   if (f->flags & O_PATH)
     return -EBADF;
 #endif
-  return _setattr(f->inode, attr, mask);
+  return _setattr(f->inode, attr, mask, perms);
 }
 
 int Client::stat(const char *relpath, struct stat *stbuf,
@@ -8705,7 +8706,9 @@ int Client::truncate(const char *relpath, loff_t length)
 {
   struct stat attr;
   attr.st_size = length;
-  return setattr(relpath, &attr, CEPH_SETATTR_SIZE);
+  // FIXME
+  UserPerm perms(get_uid(), get_gid());
+  return setattr(relpath, &attr, CEPH_SETATTR_SIZE, perms);
 }
 
 int Client::ftruncate(int fd, loff_t length) 
index c43ff714ed0992d1b155be4fd99d0f570af44119..4db706f5e48fdb001d24f6c0fea0788b1bfdb25f 100644 (file)
@@ -798,12 +798,19 @@ private:
             const UserPerm& perms, InodeRef *inp = 0);
   int _do_setattr(Inode *in, struct stat *attr, int mask, const UserPerm& perms,
                  InodeRef *inp);
-  int _setattr(Inode *in, struct stat *attr, int mask, int uid=-1, int gid=-1, InodeRef *inp = 0);
   int _setattr(Inode *in, struct stat *attr, int mask, const UserPerm& perms,
+              InodeRef *inp = 0);
+  int _setattr(Inode *in, struct stat *attr, int mask, int uid=-1, int gid=-1,
               InodeRef *inp = 0) {
-    return _setattr(in, attr, mask, perms.uid(), perms.gid(), inp);
+    UserPerm perms(uid, gid);
+    return _setattr(in, attr, mask, perms, inp);
+  }
+  int _setattr(InodeRef &in, struct stat *attr, int mask,
+              const UserPerm& perms);
+  int _setattr(InodeRef &in, struct stat *attr, int mask) {
+    UserPerm perms(get_uid(), get_gid());
+    return _setattr(in, attr, mask, perms);
   }
-  int _setattr(InodeRef &in, struct stat *attr, int mask);
   int _getattr(Inode *in, int mask, int uid=-1, int gid=-1, bool force=false);
   int _getattr(InodeRef &in, int mask, int uid=-1, int gid=-1, bool force=false) {
     return _getattr(in.get(), mask, uid, gid, force);
@@ -1063,8 +1070,8 @@ public:
   int lstat(const char *path, struct stat *stbuf, frag_info_t *dirstat=0, int mask=CEPH_STAT_CAP_INODE_ALL);
   int lstatlite(const char *path, struct statlite *buf);
 
-  int setattr(const char *relpath, struct stat *attr, int mask);
-  int fsetattr(int fd, struct stat *attr, int mask);
+  int setattr(const char *relpath, struct stat *attr, int mask, const UserPerm& perms);
+  int fsetattr(int fd, struct stat *attr, int mask, const UserPerm& perms);
   int chmod(const char *path, mode_t mode);
   int fchmod(int fd, mode_t mode);
   int lchmod(const char *path, mode_t mode);
index f72b6db3a3f8db5bdd3827a9e37407e86d530a5d..c996e8db0aebcf15e490f470f94503a6492f85f3 100644 (file)
@@ -628,7 +628,8 @@ extern "C" int ceph_setattr(struct ceph_mount_info *cmount, const char *relpath,
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
-  return cmount->get_client()->setattr(relpath, attr, mask);
+  UserPerm perms = cmount->get_client()->pick_my_perms();
+  return cmount->get_client()->setattr(relpath, attr, mask, perms);
 }
 
 // *xattr() calls supporting samba/vfs