]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: refactor clear set uid/gid if -1
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 16 Aug 2017 16:48:09 +0000 (09:48 -0700)
committerNathan Cutler <ncutler@suse.com>
Tue, 5 Sep 2017 09:27:46 +0000 (11:27 +0200)
libfuse already does not set FUSE_SET_ATTR_UID if the chown uid is -1. However,
another libcephfs client could call setattr directly with -1 as the uid/gid so we
should handle that potential case.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit 6448d4927fb4cfc29392ff58da8775d68e3e875b)

src/client/Client.cc

index cc0a93c366778d22ec7e4fa4784dfece86c17303..fd1b0ae02b687b8065aaa7f98647d86054cbf0b5 100644 (file)
@@ -6845,6 +6845,14 @@ int Client::_setattr(InodeRef &in, struct stat *attr, int mask,
 
   stat_to_statx(attr, &stx);
   mask &= ~CEPH_SETATTR_BTIME;
+
+  if ((mask & CEPH_SETATTR_UID) && attr->st_uid == static_cast<uid_t>(-1)) {
+    mask &= ~CEPH_SETATTR_UID;
+  }
+  if ((mask & CEPH_SETATTR_GID) && attr->st_gid == static_cast<uid_t>(-1)) {
+    mask &= ~CEPH_SETATTR_GID;
+  }
+
   return _setattrx(in, &stx, mask, perms);
 }
 
@@ -7196,10 +7204,7 @@ int Client::chown(const char *relpath, uid_t new_uid, gid_t new_gid,
   struct stat attr;
   attr.st_uid = new_uid;
   attr.st_gid = new_gid;
-  int mask = 0;
-  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);
+  return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID, perms);
 }
 
 int Client::fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms)