]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: update posix-style read path
authorMatt Benjamin <mbenjamin@redhat.com>
Thu, 17 Dec 2015 22:32:25 +0000 (17:32 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:06:55 +0000 (12:06 -0500)
Update RGWGetObj to take ulp buffer rather than transferring the
elements of a buffer::list and re-traversing it.

This breaks the readv variant, but that was not final.  What it
fixes is offset handling.

Also, skip CREATE_BUCKET if not requested, in librgw_file_aw.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h
src/test/librgw_file_aw.cc

index 7f3f20803b0ba370e99b8cd25aa4521af31985b9..2e22882a07682bc058fcf7278ec6fcba4008381b 100644 (file)
@@ -854,15 +854,12 @@ int rgw_read(struct rgw_fs *rgw_fs,
   if (! rgw_fh->is_file())
     return -EINVAL;
 
-  size_t nread = 0;
-
-  /* XXX testing only */
-  buffer::list bl;
   RGWGetObjRequest req(cct, fs->get_user(), rgw_fh->bucket_name(),
-                     rgw_fh->object_name(), offset, length, bl);
+                      rgw_fh->object_name(), offset, length,
+                      buffer);
 
   int rc = librgw.get_fe()->execute_req(&req);
-
+#if 0
   if (! rc) {
     uint64_t off = 0;
     for (auto& bp : bl.buffers()) {
@@ -874,8 +871,11 @@ int rgw_read(struct rgw_fs *rgw_fs,
        break;
     }
   }
-
-  *bytes_read = nread;
+#endif
+  if ((rc == 0) &&
+      (req.get_ret() == 0)) {
+    *bytes_read = req.nread;
+  }
 
   return rc;
 }
@@ -936,13 +936,15 @@ int rgw_readv(struct rgw_fs *rgw_fs,
   if (! rgw_fh->is_file())
     return -EINVAL;
 
+  int rc = 0;
+#if 0 /* XXX */
   buffer::list bl;
   RGWGetObjRequest req(cct, fs->get_user(), rgw_fh->bucket_name(),
                      rgw_fh->object_name(), uio->uio_offset, uio->uio_resid,
                      bl);
   req.do_hexdump = false;
 
-  int rc = librgw.get_fe()->execute_req(&req);
+  rc = librgw.get_fe()->execute_req(&req);
 
   if (! rc) {
     RGWReadV* rdv = static_cast<RGWReadV*>(
@@ -969,7 +971,7 @@ int rgw_readv(struct rgw_fs *rgw_fs,
       ++ix;
     }
   }
-
+#endif
   return rc;
 }
 
index ef85a690596dc8be0e39ced3003cd35bcf66e8dc..a4c69e38ea7e8a25fa728363a0a3bbd3a96fa2e6 100644 (file)
@@ -1066,14 +1066,16 @@ class RGWGetObjRequest : public RGWLibRequest,
 public:
   const std::string& bucket_name;
   const std::string& obj_name;
-  buffer::list& bl;
+  void *ulp_buffer;
+  size_t nread;
+  size_t read_len;
   bool do_hexdump = false;
 
   RGWGetObjRequest(CephContext* _cct, RGWUserInfo *_user,
                  const std::string& _bname, const std::string& _oname,
-                 uint64_t off, uint64_t len, buffer::list& _bl)
+                 uint64_t off, uint64_t len, void *_ulp_buffer)
     : RGWLibRequest(_cct, _user), bucket_name(_bname), obj_name(_oname),
-      bl(_bl) {
+      ulp_buffer(_ulp_buffer), nread(0), read_len(len) {
     magic = 76;
     op = this;
 
@@ -1085,8 +1087,6 @@ public:
     RGWGetObj::end = off + len;
   }
 
-  buffer::list& get_bl() { return bl; }
-
   virtual bool only_bucket() { return false; }
 
   virtual int op_init() {
@@ -1124,17 +1124,26 @@ public:
     return 0;
   }
 
-  virtual int send_response_data(ceph::buffer::list& _bl, off_t s_off,
+  virtual int send_response_data(ceph::buffer::list& bl, off_t s_off,
                                off_t e_off) {
-    /* XXX deal with offsets */
     if (do_hexdump) {
       dout(15) << __func__ << " s_off " << s_off
-              << " e_off " << e_off << " len " << _bl.length()
+              << " e_off " << e_off << " len " << bl.length()
               << " ";
-      _bl.hexdump(*_dout);
+      bl.hexdump(*_dout);
       *_dout << dendl;
     }
-    bl.claim_append(_bl);
+    uint64_t off = 0;
+    for (auto& bp : bl.buffers()) {
+      if (nread >= read_len)
+       break;
+      size_t bytes = std::min(std::min(read_len, size_t(bp.length())),
+                             size_t(e_off));
+      memcpy(static_cast<char*>(ulp_buffer)+off, bp.c_str()+s_off, bytes);
+      nread += bytes;
+      off += bytes;
+      s_off -= bytes;
+    }
     return 0;
   }
 
index 1b3a08370d69132d1576dd96ae78eea457834546..b6355b098f350534cc6797e5769602f2733313f8 100644 (file)
@@ -37,6 +37,7 @@ namespace {
   string secret_key("");
   struct rgw_fs *fs = nullptr;
 
+  bool do_create = false;
   bool do_delete = false;
   bool do_verify = false;
   bool do_hexdump = false;
@@ -175,10 +176,12 @@ TEST(LibRGW, MOUNT) {
 }
 
 TEST(LibRGW, CREATE_BUCKET) {
-  struct stat st;
-  struct rgw_file_handle *fh;
-  int ret = rgw_mkdir(fs, fs->root_fh, bucket_name.c_str(), 755, &st, &fh);
-  ASSERT_EQ(ret, 0);
+  if (do_create) {
+    struct stat st;
+    struct rgw_file_handle *fh;
+    int ret = rgw_mkdir(fs, fs->root_fh, bucket_name.c_str(), 755, &st, &fh);
+    ASSERT_EQ(ret, 0);
+  }
 }
 
 TEST(LibRGW, LOOKUP_BUCKET) {
@@ -318,6 +321,9 @@ int main(int argc, char *argv[])
     } else if (ceph_argparse_flag(args, arg_iter, "--verify",
                                            (char*) nullptr)) {
       do_verify = true;
+    } else if (ceph_argparse_flag(args, arg_iter, "--create",
+                                           (char*) nullptr)) {
+      do_create = true;
     } else if (ceph_argparse_flag(args, arg_iter, "--delete",
                                            (char*) nullptr)) {
       do_delete = true;