From ea51474ab0afc1ce6adce0d30440673e554e9dde Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Thu, 17 Dec 2015 14:54:26 -0500 Subject: [PATCH] librgw: sequential rgw_write works This commit finishes hooking up RGWWriteRequest, and its supporting RGWLibContinuedRequest. The rgw_read call now fails--trivially, because it never handled starting offset correctly. Signed-off-by: Matt Benjamin --- src/rgw/librgw.cc | 35 ++++++++++++++++------------------- src/rgw/rgw_file.cc | 3 ++- src/rgw/rgw_file.h | 12 +++++++++--- src/rgw/rgw_lib.h | 26 ++++++++++++++++++++------ src/test/librgw_file_aw.cc | 2 +- 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/rgw/librgw.cc b/src/rgw/librgw.cc index 3fb7b88dcc2..40cf4562a11 100644 --- a/src/rgw/librgw.cc +++ b/src/rgw/librgw.cc @@ -273,8 +273,6 @@ done: int RGWLibProcess::start_request(RGWLibContinuedReq* req) { - int ret = 0; - int op_ret = 0; dout(1) << "====== " << __func__ << " starting new continued request req=" << hex << req << dec @@ -294,21 +292,8 @@ int RGWLibProcess::start_request(RGWLibContinuedReq* req) struct req_state* s = req->get_state(); - /* XXXX the below stanza can be completely internalized--req has - * all these objects */ - -#if 0 - /* XXX and -then- stash req_state pointers everywhere they are needed */ - ret = req->init(rgw_env, &rados_ctx, io, s); - if (ret < 0) { - dout(10) << "failed to initialize request" << dendl; - abort_req(s, op, ret); - goto done; - } -#endif - /* req is-a RGWOp, currently initialized separately */ - ret = req->op_init(); + int ret = req->op_init(); if (ret < 0) { dout(10) << "failed to initialize RGWOp" << dendl; abort_req(s, op, ret); @@ -367,15 +352,27 @@ int RGWLibProcess::start_request(RGWLibContinuedReq* req) op->pre_exec(); req->exec_start(); - op_ret = op->get_ret(); - done: return (ret < 0 ? ret : s->err.ret); } int RGWLibProcess::finish_request(RGWLibContinuedReq* req) { - return 0; + RGWOp *op = (req->op) ? req->op : dynamic_cast(req); + if (! op) { + dout(1) << "failed to derive cognate RGWOp (invalid op?)" << dendl; + return -EINVAL; + } + + int ret = req->exec_finish(); + int op_ret = op->get_ret(); + + dout(1) << "====== " << __func__ + << " finishing continued request req=" << hex << req << dec + << " op status=" << op_ret + << " ======" << dendl; + + return ret; } int RGWLibFrontend::init() diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 137abb755fd..7f3f20803b0 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -142,7 +142,8 @@ int RGWFileHandle::close() int rc = 0; file* f = get(&variant_type); if (f && (f->write_req)) { - rc = librgw.get_fe()->finish_req(f->write_req); + rc = f->write_req->exec_finish(); + // rc = librgw.get_fe()->finish_req(f->write_req); // XXX if (! rc) { rc = f->write_req->get_ret(); if (! rc) { diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index c6b2e2d7feb..ef85a690596 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -204,8 +204,8 @@ namespace rgw { public: RGWFileHandle(RGWLibFS* fs, uint32_t fs_inst, RGWFileHandle* _parent, const fh_key& _fhk, std::string& _name, uint32_t _flags) - : bucket(nullptr), parent(_parent), name(std::move(_name)), fhk(_fhk), - flags(_flags) { + : refcnt(0), fs(fs), bucket(nullptr), parent(_parent), + name(std::move(_name)), fhk(_fhk), flags(_flags) { if (parent->is_root()) { fh.fh_type = RGW_FS_TYPE_DIRECTORY; @@ -1472,6 +1472,12 @@ public: : RGWLibContinuedReq(_cct, _user), bucket_name(_bname), obj_name(_oname), rgw_fh(_fh), processor(nullptr), last_off(0), next_off(0), bytes_written(0), multipart(false) { + + int ret = header_init(); + if (ret == 0) { + ret = init_from_header(get_state()); + } + magic = 81; op = this; } @@ -1540,7 +1546,7 @@ public: } void put_data(off_t off, buffer::list& _bl) { - next_off = off; + ofs = off; data.claim(_bl); } diff --git a/src/rgw/rgw_lib.h b/src/rgw/rgw_lib.h index a139fc9cea6..ad87b17fb89 100644 --- a/src/rgw/rgw_lib.h +++ b/src/rgw/rgw_lib.h @@ -46,7 +46,9 @@ class RGWLibIO : public RGWClientIO { RGWUserInfo user_info; public: - RGWLibIO() {} + RGWLibIO() { + get_env().set("HTTP_HOST", ""); + } RGWLibIO(const RGWUserInfo &_user_info) : user_info(_user_info) {} @@ -155,14 +157,26 @@ class RGWLibContinuedReq : public RGWLibRequest { public: RGWLibContinuedReq(CephContext* _cct, RGWUserInfo* _user) - : RGWLibRequest(_cct, _user), rstate(_cct, &io_ctx.get_env(), _user), - rados_ctx(librgw.get_store(), &rstate) + : RGWLibRequest(_cct, _user), io_ctx(), + rstate(_cct, &io_ctx.get_env(), _user), rados_ctx(librgw.get_store(), + &rstate) { io_ctx.init(_cct); - /* XXX for now, use ""; could be a legit hostname, or, in future, - * perhaps a tenant (Yehuda) */ - io_ctx.get_env().set("HTTP_HOST", ""); + RGWRequest::init_state(&rstate); + RGWHandler::init(rados_ctx.store, &rstate, &io_ctx); + + /* fixup _s->req */ + get_state()->req = this; + + log_init(); + + get_state()->obj_ctx = &rados_ctx; + get_state()->req_id = store->unique_id(id); + get_state()->trans_id = store->unique_trans_id(id); + + log_format(get_state(), "initializing for trans_id = %s", + get_state()->trans_id.c_str()); } inline RGWRados* get_store() { return store; } diff --git a/src/test/librgw_file_aw.cc b/src/test/librgw_file_aw.cc index 0ab3fb481b8..b25af049509 100644 --- a/src/test/librgw_file_aw.cc +++ b/src/test/librgw_file_aw.cc @@ -231,7 +231,7 @@ TEST(LibRGW, GET_OBJECT) { struct iovec *iovs = zp_set1.get_iovs(); for (int ix : {2 , 3}) { struct iovec *iov = &iovs[ix]; - int ret = rgw_read(fs, object_fh, offset, iov[ix-2].iov_len, &nread, + int ret = rgw_read(fs, object_fh, offset, iovs[ix-2].iov_len, &nread, iov->iov_base); offset += iov->iov_len; ASSERT_EQ(ret, 0); -- 2.47.3