From: Greg Farnum Date: Wed, 27 Jul 2016 23:05:01 +0000 (-0700) Subject: client: always pass a UserPerm to chown variants X-Git-Tag: v11.0.1~36^2~78 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f648baf96da834a0a7ca05af2cfa10a15c37df72;p=ceph.git client: always pass a UserPerm to chown variants Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index aa4d8ddee419..4e6699bdf1b3 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6768,34 +6768,35 @@ int Client::lchmod(const char *relpath, mode_t mode, const UserPerm& perms) return _setattr(in, &attr, CEPH_SETATTR_MODE, perms); } -int Client::chown(const char *relpath, int uid, int gid) +int Client::chown(const char *relpath, uid_t new_uid, gid_t new_gid, + const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "chown" << std::endl; tout(cct) << relpath << std::endl; - tout(cct) << uid << std::endl; - tout(cct) << gid << std::endl; + tout(cct) << new_uid << std::endl; + tout(cct) << new_gid << std::endl; filepath path(relpath); InodeRef in; - int r = path_walk(path, &in); + int r = path_walk(path, &in, perms); if (r < 0) return r; struct stat attr; - attr.st_uid = uid; - attr.st_gid = gid; + attr.st_uid = new_uid; + attr.st_gid = new_gid; int mask = 0; - if (uid != -1) mask |= CEPH_SETATTR_UID; - if (gid != -1) mask |= CEPH_SETATTR_GID; - return _setattr(in, &attr, mask); + 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); } -int Client::fchown(int fd, int uid, int gid) +int Client::fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "fchown" << std::endl; tout(cct) << fd << std::endl; - tout(cct) << uid << std::endl; - tout(cct) << gid << std::endl; + tout(cct) << new_uid << std::endl; + tout(cct) << new_gid << std::endl; Fh *f = get_filehandle(fd); if (!f) return -EBADF; @@ -6804,34 +6805,35 @@ int Client::fchown(int fd, int uid, int gid) return -EBADF; #endif struct stat attr; - attr.st_uid = uid; - attr.st_gid = gid; + attr.st_uid = new_uid; + attr.st_gid = new_gid; int mask = 0; - if (uid != -1) mask |= CEPH_SETATTR_UID; - if (gid != -1) mask |= CEPH_SETATTR_GID; - return _setattr(f->inode, &attr, mask); + if (new_uid != static_cast(-1)) mask |= CEPH_SETATTR_UID; + if (new_gid != static_cast(-1)) mask |= CEPH_SETATTR_GID; + return _setattr(f->inode, &attr, mask, perms); } -int Client::lchown(const char *relpath, int uid, int gid) +int Client::lchown(const char *relpath, uid_t new_uid, gid_t new_gid, + const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "lchown" << std::endl; tout(cct) << relpath << std::endl; - tout(cct) << uid << std::endl; - tout(cct) << gid << std::endl; + tout(cct) << new_uid << std::endl; + tout(cct) << new_gid << std::endl; filepath path(relpath); InodeRef in; // don't follow symlinks - int r = path_walk(path, &in, false); + int r = path_walk(path, &in, perms, false); if (r < 0) return r; struct stat attr; - attr.st_uid = uid; - attr.st_gid = gid; + attr.st_uid = new_uid; + attr.st_gid = new_gid; int mask = 0; - if (uid != -1) mask |= CEPH_SETATTR_UID; - if (gid != -1) mask |= CEPH_SETATTR_GID; - return _setattr(in, &attr, mask); + 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); } int Client::utime(const char *relpath, struct utimbuf *buf) diff --git a/src/client/Client.h b/src/client/Client.h index e5fbbb8ab153..08c555871ddb 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1075,9 +1075,11 @@ public: int chmod(const char *path, mode_t mode, const UserPerm& perms); int fchmod(int fd, mode_t mode, const UserPerm& perms); int lchmod(const char *path, mode_t mode, const UserPerm& perms); - int chown(const char *path, int uid, int gid); - int fchown(int fd, int uid, int gid); - int lchown(const char *path, int uid, int gid); + int chown(const char *path, uid_t new_uid, gid_t new_gid, + const UserPerm& perms); + int fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms); + int lchown(const char *path, uid_t new_uid, gid_t new_gid, + const UserPerm& perms); int utime(const char *path, struct utimbuf *buf); int lutime(const char *path, struct utimbuf *buf); int flock(int fd, int operation, uint64_t owner); diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index e2e06c3148bc..b46ed8b1ba1d 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1114,7 +1114,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) const char *a = t.get_string(buf, p); int64_t b = t.get_int(); int64_t c = t.get_int(); - client->chown(a, b, c); + client->chown(a, b, c, perms); } else if (strcmp(op, "utime") == 0) { const char *a = t.get_string(buf, p); int64_t b = t.get_int(); @@ -2728,9 +2728,9 @@ int SyntheticClient::random_walk(int num_req) } if (op == CEPH_MDS_OP_CHOWN) { - if (contents.empty()) r = client->chown( cwd.c_str(), rand(), rand() ); + if (contents.empty()) r = client->chown(cwd.c_str(), rand(), rand(), perms); else - r = client->chown( get_random_sub(), rand(), rand() ); + r = client->chown(get_random_sub(), rand(), rand(), perms); } if (op == CEPH_MDS_OP_UTIME) { @@ -3210,8 +3210,10 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data) * */ + UserPerm process_perms = client->pick_my_perms(); + if (base[0] != '-') - client->mkdir(base, 0755, client->pick_my_perms()); + client->mkdir(base, 0755, process_perms); ifstream f(find); assert(f.is_open()); @@ -3316,8 +3318,8 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data) } client->close(fd); - //client->chmod(f.c_str(), mode & 0777, perms); - client->chown(f.c_str(), uid, gid); + //client->chmod(f.c_str(), mode & 0777, perms, process_perms); + client->chown(f.c_str(), uid, gid, process_perms); struct utimbuf ut; ut.modtime = mtime; diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 2703710d9593..3ffada336b29 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -751,21 +751,24 @@ extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path, { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->chown(path, uid, gid); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->chown(path, uid, gid, perms); } extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd, int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->fchown(fd, uid, gid); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->fchown(fd, uid, gid, perms); } extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->lchown(path, uid, gid); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->lchown(path, uid, gid, perms); }