From 469e50646c7d83e1f4e59ea90aeeefbd437976e8 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 16 Aug 2017 09:48:09 -0700 Subject: [PATCH] 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 (cherry picked from commit 6448d4927fb4cfc29392ff58da8775d68e3e875b) --- src/client/Client.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index cc0a93c3667..fd1b0ae02b6 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) -- 2.47.3