]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: always pass a UserPerm to seek variants
authorGreg Farnum <gfarnum@redhat.com>
Thu, 28 Jul 2016 01:17:54 +0000 (18:17 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Wed, 21 Sep 2016 23:33:47 +0000 (16:33 -0700)
Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/SyntheticClient.cc
src/libcephfs.cc

index 3fd8f8efaed41d37e49406f0fb505ae9de53538f..0d457b4ef3a5d0676da3f7297990b597020f9477 100644 (file)
@@ -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)
index 9fb6f1f44457c613f7af0e2062f52409396bdf39..ebf9bbae343dda9c9def2a00c81bae78601e12c0 100644 (file)
@@ -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);
index 839af89dfb8ee936b63f3776d8840380fc4a18e8..e45b4ad20899e7050664cd8ded93424ac76c84e1 100644 (file)
@@ -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();
index a0a329d48119c1301ee96351efac9042e69be013..0d1036366897c55a8b515836a25c9722a29ea3cf 100644 (file)
@@ -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,