From: Matt Benjamin Date: Mon, 11 Jan 2016 22:51:15 +0000 (-0500) Subject: librgw: fix rgw_read, add unit test X-Git-Tag: v10.1.0~382^2~40 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ce62d805953c95159c36155fa1cfc6f9cb202ea5;p=ceph.git librgw: fix rgw_read, add unit test rgw_read had been trivially broken by the relative path change, fixed. Signed-off-by: Matt Benjamin --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 9d38e644ca35f..6a11e22ef0d27 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -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) && diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index 64b219bf29889..bacd9463ef436 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -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 ? */ diff --git a/src/test/librgw_file_nfsns.cc b/src/test/librgw_file_nfsns.cc index 88ec5c60d705b..ff4ddbddc4f05 100644 --- a/src/test/librgw_file_nfsns.cc +++ b/src/test/librgw_file_nfsns.cc @@ -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