From: Greg Farnum Date: Thu, 28 Jul 2016 01:17:54 +0000 (-0700) Subject: client: always pass a UserPerm to seek variants X-Git-Tag: v11.0.1~36^2~73 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=be9e43e2da41e91ffd8577dfd0b890cdb361a08e;p=ceph.git client: always pass a UserPerm to seek variants Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 3fd8f8efaed4..0d457b4ef3a5 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7914,7 +7914,7 @@ int Client::close(int fd) // ------------ // read, write -loff_t Client::lseek(int fd, loff_t offset, int whence) +loff_t Client::lseek(int fd, loff_t offset, int whence, const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "lseek" << std::endl; @@ -7929,14 +7929,18 @@ loff_t Client::lseek(int fd, loff_t offset, int whence) if (f->flags & O_PATH) return -EBADF; #endif - return _lseek(f, offset, whence); + return _lseek(f, offset, whence, perms); } -loff_t Client::_lseek(Fh *f, loff_t offset, int whence) +loff_t Client::_lseek(Fh *f, loff_t offset, int whence, const UserPerm& perms) { 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; @@ -7947,7 +7951,7 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence) break; case SEEK_END: - r = _getattr(in, CEPH_STAT_CAP_SIZE); + r = _getattr(in, CEPH_STAT_CAP_SIZE, perms); if (r < 0) return r; f->pos = in->size + offset; @@ -8492,7 +8496,9 @@ 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); + // FIXME + UserPerm perms(0, 0); + int r = _lseek(f, 0, SEEK_END, perms); if (r < 0) { unlock_fh_pos(f); return r; @@ -11436,14 +11442,15 @@ out: return r; } -loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence) +loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence, + const UserPerm& perms) { 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); + return _lseek(fh, offset, whence, perms); } 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 9fb6f1f44457..ebf9bbae343d 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -833,6 +833,7 @@ private: bool *created, int uid, int gid); 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); @@ -1086,7 +1087,7 @@ public: int lookup_parent(Inode *in, Inode **parent=NULL); int lookup_name(Inode *in, Inode *parent); int close(int fd); - loff_t lseek(int fd, loff_t offset, int whence); + loff_t lseek(int fd, loff_t offset, int whence, const UserPerm& perms); 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); @@ -1214,7 +1215,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); + loff_t ll_lseek(Fh *fh, loff_t offset, int whence, const UserPerm& perms); 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 839af89dfb8e..e45b4ad20899 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1172,7 +1172,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); + client->lseek(fd, off, whence, perms); } 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 a0a329d48119..0d1036366897 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -838,7 +838,8 @@ 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); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->lseek(fd, offset, whence, perms); } extern "C" int ceph_read(struct ceph_mount_info *cmount, int fd, char *buf, @@ -1510,7 +1511,8 @@ 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)); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return (cmount->get_client()->ll_lseek(fh, offset, whence, perms)); } extern "C" int ceph_ll_write(class ceph_mount_info *cmount,