From: Matt Benjamin Date: Thu, 17 Dec 2015 22:32:25 +0000 (-0500) Subject: librgw: update posix-style read path X-Git-Tag: v10.1.0~382^2~95 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e4b0c2be448ed242dfba8331b1b69e41676b4db7;p=ceph.git librgw: update posix-style read path 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 --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 7f3f20803b0b..2e22882a0768 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -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( @@ -969,7 +971,7 @@ int rgw_readv(struct rgw_fs *rgw_fs, ++ix; } } - +#endif return rc; } diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index ef85a690596d..a4c69e38ea7e 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -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(ulp_buffer)+off, bp.c_str()+s_off, bytes); + nread += bytes; + off += bytes; + s_off -= bytes; + } return 0; } diff --git a/src/test/librgw_file_aw.cc b/src/test/librgw_file_aw.cc index 1b3a08370d69..b6355b098f35 100644 --- a/src/test/librgw_file_aw.cc +++ b/src/test/librgw_file_aw.cc @@ -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;