]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: implement RGWGetObjRequest
authorMatt Benjamin <mbenjamin@redhat.com>
Wed, 28 Oct 2015 21:53:06 +0000 (17:53 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:05:21 +0000 (12:05 -0500)
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/include/rados/rgw_file.h
src/rgw/rgw_file.cc
src/rgw/rgw_file.h
src/test/librgw_file_gp.cc

index f068e6761d72b7ef79e750b6f46f969c07f2c4a6..27c67caaaed125bff962d51a91229ed2c857a556 100644 (file)
@@ -191,8 +191,8 @@ int rgw_close(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
    read data from file
 */
 int rgw_read(struct rgw_fs *rgw_fs,
-            struct rgw_file_handle *fh, uint64_t offset,
-            size_t length, void *buffer);
+           struct rgw_file_handle *fh, uint64_t offset,
+           size_t length, size_t *bytes_read, void *buffer);
 
 /* XXX add release fn and UIO type */
 int rgw_readv(struct rgw_fs *rgw_fs,
index 2d9a80f4e853addbf7bc0865b9395adc3c570039..298eea88dca630df3522c94779df0ebb4ae3a7c1 100644 (file)
@@ -309,10 +309,40 @@ int rgw_readdir(struct rgw_fs *rgw_fs,
    read data from file
 */
 int rgw_read(struct rgw_fs *rgw_fs,
-            struct rgw_file_handle *fh, uint64_t offset,
-            size_t length, void *buffer)
+           struct rgw_file_handle *fh, uint64_t offset,
+           size_t length, size_t *bytes_read, void *buffer)
 {
-  return 0;
+  CephContext* cct = static_cast<CephContext*>(rgw_fs->rgw);
+  RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
+  RGWFileHandle* rgw_fh = get_rgwfh(fh);
+
+  if (! rgw_fh->is_object())
+    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);
+
+  int rc = librgw.get_fe()->execute_req(&req);
+
+  if (! rc) {
+    uint64_t off = 0;
+    for (auto& bp : bl.buffers()) {
+      size_t bytes = std::min(length, size_t(bp.length()));
+      memcpy(static_cast<char*>(buffer)+off, bp.c_str(), bytes);
+      nread += bytes;
+      off += bytes;
+      if (off >= length)
+       break;
+    }
+  }
+
+  *bytes_read = nread;
+
+  return rc;
 }
 
 /*
index 77bf5d186e03058963d1ba4112bfe0f50865e0cc..9f171e2e56f27ddd5b0ceaf7fa4a1f7007ed9e83 100644 (file)
@@ -451,13 +451,21 @@ class RGWGetObjRequest : public RGWLibRequest,
 public:
   const std::string& bucket_name;
   const std::string& obj_name;
-  buffer::list bl;
+  buffer::list& bl;
 
   RGWGetObjRequest(CephContext* _cct, RGWUserInfo *_user,
-                 const std::string& _bname, const std::string& _oname)
-    : RGWLibRequest(_cct, _user), bucket_name(_bname), obj_name(_oname) {
+                 const std::string& _bname, const std::string& _oname,
+                 uint64_t off, uint64_t len, buffer::list& _bl)
+    : RGWLibRequest(_cct, _user), bucket_name(_bname), obj_name(_oname),
+      bl(_bl) {
     magic = 76;
     op = this;
+
+    /* fixup RGWGetObj (already know range parameters) */
+    RGWGetObj::range_parsed = true;
+    RGWGetObj::partial_content = true;
+    RGWGetObj::ofs = off;
+    RGWGetObj::end = off + len;
   }
 
   buffer::list& get_bl() { return bl; }
@@ -495,6 +503,23 @@ public:
     return 0;
   }
 
+  virtual int get_params() {
+    return 0;
+  }
+
+  virtual int send_response_data(ceph::buffer::list& _bl, off_t s_off,
+                               off_t e_off) {
+    /* XXX deal with offsets */
+    bl.claim_append(_bl);
+    return 0;
+  }
+
+  virtual int send_response_data_error() {
+    /* S3 implementation just sends nothing--there is no side effect
+     * to simulate here */
+    return 0;
+  }
+
 }; /* RGWGetObjRequest */
 
 /*
index a04cad76a9a8129d840a880fce605e117c78b6a5..e2bc1301a338aaa45b7f71dd0e453578ec7e0d75 100644 (file)
@@ -175,14 +175,18 @@ TEST(LibRGW, LIST_OBJECTS) {
 }
 
 TEST(LibRGW, LOOKUP_OBJECT) {
-  int ret = rgw_lookup(fs, bucket_fh, object_name.c_str(), &object_fh,
-                     0 /* flags */);
-  ASSERT_EQ(ret, 0);
+  if (do_get || do_put) {
+    int ret = rgw_lookup(fs, bucket_fh, object_name.c_str(), &object_fh,
+                       0 /* flags */);
+    ASSERT_EQ(ret, 0);
+  }
 }
 
 TEST(LibRGW, OBJ_OPEN) {
-  int ret = rgw_open(fs, object_fh, 0 /* flags */);
-  ASSERT_EQ(ret, 0);
+  if (do_get || do_put) {
+    int ret = rgw_open(fs, object_fh, 0 /* flags */);
+    ASSERT_EQ(ret, 0);
+  }
 }
 
 TEST(LibRGW, PUT_OBJECT) {
@@ -194,7 +198,23 @@ TEST(LibRGW, PUT_OBJECT) {
 }
 
 TEST(LibRGW, GET_OBJECT) {
-  /* XXX soon */
+  if (do_get) {
+    char sbuf[512];
+    memset(sbuf, 0, 512);
+    uint64_t nread;
+    int ret = rgw_read(fs, object_fh, 0 /* off */, 512 /* len */, &nread, sbuf);
+    ASSERT_EQ(ret, 0);
+    buffer::list bl;
+    bl.push_back(buffer::create_static(nread, sbuf));
+    bl.hexdump(std::cout);
+  }
+}
+
+TEST(LibRGW, DELETE_OBJECT) {
+  if (do_delete) {
+    int ret = rgw_unlink(fs, bucket_fh, object_name.c_str());
+    ASSERT_EQ(ret, 0);
+  }
 }
 
 TEST(LibRGW, CLEANUP) {
@@ -256,6 +276,9 @@ int main(int argc, char *argv[])
     } else if (ceph_argparse_flag(args, arg_iter, "--put",
                                            (char*) nullptr)) {
       do_put = true;
+    } else if (ceph_argparse_flag(args, arg_iter, "--delete",
+                                           (char*) nullptr)) {
+      do_delete = true;
     } else if (ceph_argparse_flag(args, arg_iter, "--prelist",
                                            (char*) nullptr)) {
       do_pre_list = true;