]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: fix rgw_read, add unit test
authorMatt Benjamin <mbenjamin@redhat.com>
Mon, 11 Jan 2016 22:51:15 +0000 (17:51 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:07:54 +0000 (12:07 -0500)
rgw_read had been trivially broken by the relative path change,
fixed.

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

index 9d38e644ca35facf89b93c3a50fce0bb368e82b1..6a11e22ef0d27ec2e12e695ecb391f401a13b15d 100644 (file)
@@ -1048,9 +1048,7 @@ int rgw_read(struct rgw_fs *rgw_fs,
   if (! rgw_fh->is_file())
     return -EINVAL;
 
-  RGWReadRequest req(cct, fs->get_user(), rgw_fh->bucket_name(),
-                   rgw_fh->object_name(), offset, length,
-                   buffer);
+  RGWReadRequest req(cct, fs->get_user(), rgw_fh, offset, length, buffer);
 
   int rc = rgwlib.get_fe()->execute_req(&req);
   if ((rc == 0) &&
index 64b219bf29889ede9421c5f4a8d3cfd0db36b0eb..bacd9463ef436ba2a6f57808e1b764bd6357d4c1 100644 (file)
@@ -1286,18 +1286,17 @@ class RGWReadRequest : public RGWLibRequest,
                       public RGWGetObj /* RGWOp */
 {
 public:
-  const std::string& bucket_name;
-  const std::string& obj_name;
+  RGWFileHandle* rgw_fh;
   void *ulp_buffer;
   size_t nread;
   size_t read_len;
   bool do_hexdump = false;
 
   RGWReadRequest(CephContext* _cct, RGWUserInfo *_user,
-               const std::string& _bname, const std::string& _oname,
-               uint64_t off, uint64_t len, void *_ulp_buffer)
-    : RGWLibRequest(_cct, _user), bucket_name(_bname), obj_name(_oname),
-      ulp_buffer(_ulp_buffer), nread(0), read_len(len) {
+                RGWFileHandle* _rgw_fh, uint64_t off, uint64_t len,
+                void *_ulp_buffer)
+    : RGWLibRequest(_cct, _user), rgw_fh(_rgw_fh), ulp_buffer(_ulp_buffer),
+      nread(0), read_len(len) {
     magic = 76;
     op = this;
 
@@ -1329,10 +1328,10 @@ public:
     s->op = OP_GET;
 
     /* XXX derp derp derp */
-    std::string uri = make_uri(bucket_name, obj_name);
-    s->relative_uri = uri;
-    s->info.request_uri = uri; // XXX
-    s->info.effective_uri = uri;
+    s->relative_uri = make_uri(rgw_fh->bucket_name(),
+                              rgw_fh->relative_object_name());
+    s->info.request_uri = s->relative_uri; // XXX
+    s->info.effective_uri = s->relative_uri;
     s->info.request_params = "";
     s->info.domain = ""; /* XXX ? */
 
index 88ec5c60d705b3f599e41a0687f64044c702ea1d..ff4ddbddc4f052c90ea63bb983c3d173f0538836 100644 (file)
@@ -419,6 +419,41 @@ TEST(LibRGW, GETATTR_DIRS1)
   }
 }
 
+TEST(LibRGW, READ_DIRS1)
+{
+  if (do_dirs1) {
+    int rc;
+    char buf[256];
+    uint64_t nread;
+    for (auto& dirs_rec : dirs_vec) {
+      obj_rec& dir = get<0>(dirs_rec);
+      if (verbose) {
+       std::cout << "read back objects in "
+                 << dir.rgw_fh->full_object_name()
+                 << std::endl;
+      }
+      for (auto& sobj : get<1>(dirs_rec)) {
+       /* only the first 2 file objects have data */
+       if ((sobj.rgw_fh->object_name().find("sfile_0")
+            != std::string::npos) ||
+           (sobj.rgw_fh->object_name().find("sfile_1")
+            != std::string::npos)) {
+         ASSERT_TRUE(sobj.rgw_fh->is_file());
+         // do it
+         memset(buf, 0, 256);
+         rc = rgw_read(fs, sobj.fh, 0, 256, &nread, buf, RGW_READ_FLAG_NONE);
+         ASSERT_EQ(rc, 0);
+         if (verbose) {
+           std::cout << "\tread back from " << sobj.name
+                     << " : \"" << buf << "\""
+                     << std::endl;
+         }
+       }
+      }
+    }
+  }
+}
+
 TEST(LibRGW, RELEASE_DIRS1) {
   if (do_dirs1) {
     /* force release of handles for children of dirs1--force subsequent