From: Patrick Donnelly Date: Wed, 16 Aug 2017 16:48:09 +0000 (-0700) Subject: client: refactor clear set uid/gid if -1 X-Git-Tag: v13.0.0~26^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6448d4927fb4cfc29392ff58da8775d68e3e875b;p=ceph.git client: refactor clear set uid/gid if -1 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 --- diff --git a/src/client/Client.cc b/src/client/Client.cc index e461ab4a59eb..c23f10117702 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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(-1)) { + mask &= ~CEPH_SETATTR_UID; + } + if ((mask & CEPH_SETATTR_GID) && attr->st_gid == static_cast(-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(-1)) mask |= CEPH_SETATTR_UID; - if (new_gid != static_cast(-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)