From: Jeff Layton Date: Wed, 12 Oct 2016 11:04:42 +0000 (-0400) Subject: client: lseek shouldn't do permission checking X-Git-Tag: v11.1.0~625^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=db2e7e0811679b4c284e105536ebf3327cc02ffc;p=ceph.git client: lseek shouldn't do permission checking With the addition of the UserPerm changes, ceph_lseek started checking for open permissions using the default mount perms. lseek should not require those permissions though, as it operates on an already-opened file descriptor. Remove the perms argument from most of these functions. Fixes: be9e43e2da41e91ffd8577dfd0b890cdb361a08e Signed-off-by: Jeff Layton --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 48620577ec1..5ec790b0469 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8102,7 +8102,7 @@ int Client::close(int fd) // ------------ // read, write -loff_t Client::lseek(int fd, loff_t offset, int whence, const UserPerm& perms) +loff_t Client::lseek(int fd, loff_t offset, int whence) { Mutex::Locker lock(client_lock); tout(cct) << "lseek" << std::endl; @@ -8117,18 +8117,14 @@ loff_t Client::lseek(int fd, loff_t offset, int whence, const UserPerm& perms) if (f->flags & O_PATH) return -EBADF; #endif - return _lseek(f, offset, whence, perms); + return _lseek(f, offset, whence); } -loff_t Client::_lseek(Fh *f, loff_t offset, int whence, const UserPerm& perms) +loff_t Client::_lseek(Fh *f, loff_t offset, int whence) { Inode *in = f->inode.get(); int r; - if (!may_open(f->inode.get(), f->flags, perms)) { - return -EPERM; - } - switch (whence) { case SEEK_SET: f->pos = offset; @@ -8139,7 +8135,7 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence, const UserPerm& perms) break; case SEEK_END: - r = _getattr(in, CEPH_STAT_CAP_SIZE, perms); + r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms); if (r < 0) return r; f->pos = in->size + offset; @@ -8686,7 +8682,7 @@ int Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf, * change out from under us. */ if (f->flags & O_APPEND) { - int r = _lseek(f, 0, SEEK_END, f->actor_perms); + int r = _lseek(f, 0, SEEK_END); if (r < 0) { unlock_fh_pos(f); return r; @@ -11706,15 +11702,14 @@ out: return r; } -loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence, - const UserPerm& perms) +loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence) { Mutex::Locker lock(client_lock); tout(cct) << "ll_lseek" << std::endl; tout(cct) << offset << std::endl; tout(cct) << whence << std::endl; - return _lseek(fh, offset, whence, perms); + return _lseek(fh, offset, whence); } int Client::ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl) diff --git a/src/client/Client.h b/src/client/Client.h index 353771cb1c0..91863ff4932 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -809,7 +809,6 @@ private: const char *data_pool, bool *created, const UserPerm &perms); loff_t _lseek(Fh *fh, loff_t offset, int whence); - loff_t _lseek(Fh *fh, loff_t offset, int whence, const UserPerm& perms); int _read(Fh *fh, int64_t offset, uint64_t size, bufferlist *bl); int _write(Fh *fh, int64_t offset, uint64_t size, const char *buf, const struct iovec *iov, int iovcnt); @@ -1033,7 +1032,7 @@ public: int lookup_parent(Inode *in, const UserPerm& perms, Inode **parent=NULL); int lookup_name(Inode *in, Inode *parent, const UserPerm& perms); int close(int fd); - loff_t lseek(int fd, loff_t offset, int whence, const UserPerm& perms); + loff_t lseek(int fd, loff_t offset, int whence); int read(int fd, char *buf, loff_t size, loff_t offset=-1); int preadv(int fd, const struct iovec *iov, int iovcnt, loff_t offset=-1); int write(int fd, const char *buf, loff_t size, loff_t offset=-1); @@ -1168,7 +1167,7 @@ public: int ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl); int ll_write(Fh *fh, loff_t off, loff_t len, const char *data); - loff_t ll_lseek(Fh *fh, loff_t offset, int whence, const UserPerm& perms); + loff_t ll_lseek(Fh *fh, loff_t offset, int whence); int ll_flush(Fh *fh); int ll_fsync(Fh *fh, bool syncdataonly); int ll_fallocate(Fh *fh, int mode, loff_t offset, loff_t length); diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index 77de3959647..0a48d2680cf 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1173,7 +1173,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) int fd = open_files[f]; int64_t off = t.get_int(); int64_t whence = t.get_int(); - client->lseek(fd, off, whence, perms); + client->lseek(fd, off, whence); } else if (strcmp(op, "read") == 0) { int64_t f = t.get_int(); int64_t size = t.get_int(); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index f24ff945fe4..cc8af424d35 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -833,7 +833,7 @@ extern "C" int64_t ceph_lseek(struct ceph_mount_info *cmount, int fd, { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->lseek(fd, offset, whence, cmount->default_perms); + return cmount->get_client()->lseek(fd, offset, whence); } extern "C" int ceph_read(struct ceph_mount_info *cmount, int fd, char *buf, @@ -1532,7 +1532,7 @@ extern "C" int ceph_ll_fsync(class ceph_mount_info *cmount, extern "C" off_t ceph_ll_lseek(class ceph_mount_info *cmount, Fh *fh, off_t offset, int whence) { - return (cmount->get_client()->ll_lseek(fh, offset, whence, cmount->default_perms)); + return (cmount->get_client()->ll_lseek(fh, offset, whence)); } extern "C" int ceph_ll_write(class ceph_mount_info *cmount,