From: Greg Farnum Date: Wed, 27 Jul 2016 23:45:46 +0000 (-0700) Subject: client: always pass a UserPerm to truncate variants X-Git-Tag: v11.0.1~36^2~76 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9aae93adf6bdc591118261b3520d84aa79254de7;p=ceph.git client: always pass a UserPerm to truncate variants Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 2a91a78df2a..29d6f116544 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8706,16 +8706,14 @@ int Client::_flush(Fh *f) return err; } -int Client::truncate(const char *relpath, loff_t length) +int Client::truncate(const char *relpath, loff_t length, const UserPerm& perms) { struct stat attr; attr.st_size = length; - // FIXME - UserPerm perms(get_uid(), get_gid()); return setattr(relpath, &attr, CEPH_SETATTR_SIZE, perms); } -int Client::ftruncate(int fd, loff_t length) +int Client::ftruncate(int fd, loff_t length, const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "ftruncate" << std::endl; @@ -8731,7 +8729,7 @@ int Client::ftruncate(int fd, loff_t length) #endif struct stat attr; attr.st_size = length; - return _setattr(f->inode, &attr, CEPH_SETATTR_SIZE); + return _setattr(f->inode, &attr, CEPH_SETATTR_SIZE, perms); } int Client::fsync(int fd, bool syncdataonly) diff --git a/src/client/Client.h b/src/client/Client.h index f25593c0454..9b6843784c6 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1083,7 +1083,7 @@ public: int utime(const char *path, struct utimbuf *buf, const UserPerm& perms); int lutime(const char *path, struct utimbuf *buf, const UserPerm& perms); int flock(int fd, int operation, uint64_t owner); - int truncate(const char *path, loff_t size); + int truncate(const char *path, loff_t size, const UserPerm& perms); // file ops int mknod(const char *path, mode_t mode, dev_t rdev=0); @@ -1100,7 +1100,7 @@ public: int write(int fd, const char *buf, loff_t size, loff_t offset=-1); int pwritev(int fd, const struct iovec *iov, int iovcnt, loff_t offset=-1); int fake_write_size(int fd, loff_t size); - int ftruncate(int fd, loff_t size); + int ftruncate(int fd, loff_t size, const UserPerm& perms); int fsync(int fd, bool syncdataonly); int fstat(int fd, struct stat *stbuf, int mask=CEPH_STAT_CAP_INODE_ALL); int fallocate(int fd, int mode, loff_t offset, loff_t length); diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index 482992f18d8..a71dfe2388a 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -849,7 +849,7 @@ int SyntheticClient::run() sargs.push_front(file); int iarg1 = iargs.front(); iargs.pop_front(); if (run_me()) { - client->truncate(file.c_str(), iarg1); + client->truncate(file.c_str(), iarg1, perms); } did_run_me(); } @@ -1199,12 +1199,12 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) } else if (strcmp(op, "truncate") == 0) { const char *a = t.get_string(buf, p); int64_t l = t.get_int(); - client->truncate(a, l); + client->truncate(a, l, perms); } else if (strcmp(op, "ftruncate") == 0) { int64_t f = t.get_int(); int fd = open_files[f]; int64_t l = t.get_int(); - client->ftruncate(fd, l); + client->ftruncate(fd, l, perms); } else if (strcmp(op, "fsync") == 0) { int64_t f = t.get_int(); int64_t b = t.get_int(); @@ -3314,7 +3314,7 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data) if (data) { client->write(fd, "", 0, size); } else { - client->truncate(f.c_str(), size); + client->truncate(f.c_str(), size, perms); } client->close(fd); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index a66c145bedc..8d47cf5d3dd 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -794,7 +794,8 @@ extern "C" int ceph_truncate(struct ceph_mount_info *cmount, const char *path, { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->truncate(path, size); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->truncate(path, size, perms); } // file ops @@ -874,7 +875,8 @@ extern "C" int ceph_ftruncate(struct ceph_mount_info *cmount, int fd, int64_t si { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->ftruncate(fd, size); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->ftruncate(fd, size, perms); } extern "C" int ceph_fsync(struct ceph_mount_info *cmount, int fd, int syncdataonly)