]> git.apps.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)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 16 Aug 2017 16:50:05 +0000 (09:50 -0700)
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>
src/client/Client.cc

index e461ab4a59eb2157f20e0db8c7441858d511e84a..c23f101177026f674ecc9148071bbae0182255c9 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)