From 0e99b3b2fa38c33538e9b1dece4109ffc087a7e2 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 13 Oct 2017 16:46:37 -0700 Subject: [PATCH] rgw: fix rest read crf handling of extra data also fix splice coroutine Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_cr_rest.cc | 27 +++++++++++++++++---------- src/rgw/rgw_cr_rest.h | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_cr_rest.cc b/src/rgw/rgw_cr_rest.cc index dfe22fa451a2a..cfcf737892454 100644 --- a/src/rgw/rgw_cr_rest.cc +++ b/src/rgw/rgw_cr_rest.cc @@ -32,6 +32,7 @@ class RGWCRHTTPGetDataCB : public RGWGetDataCB { int64_t io_id; bufferlist data; bufferlist extra_data; + bool got_all_extra_data{false}; public: RGWCRHTTPGetDataCB(RGWCoroutinesEnv *_env, RGWCoroutine *_cr, int64_t _io_id) : lock("RGWCRHTTPGetDataCB"), env(_env), cr(_cr), io_id(_io_id) {} @@ -39,17 +40,18 @@ public: { Mutex::Locker l(lock); - if (!has_all_extra_data()) { + if (!got_all_extra_data) { off_t max = extra_data_len - extra_data.length(); if (max > bl_len) { max = bl_len; } bl.splice(0, max, &extra_data); bl_len -= max; + got_all_extra_data = extra_data.length() == extra_data_len; } if (bl_len == bl.length()) { - data.claim_append(bl); + data.append(bl); } else { bl.splice(0, bl_len, &data); } @@ -82,7 +84,7 @@ public: } bool has_all_extra_data() { - return (extra_data.length() == extra_data_len); + return got_all_extra_data; } }; @@ -145,7 +147,8 @@ int RGWStreamReadHTTPResourceCRF::decode_rest_obj(map& headers, int RGWStreamReadHTTPResourceCRF::read(bufferlist *out, uint64_t max_size, bool *io_pending) { reenter(&read_state) { - while (!req->is_done()) { + while (!req->is_done() || + in_cb->has_data()) { *io_pending = true; if (!in_cb->has_data()) { yield caller->io_block(0, req->get_io_id()); @@ -180,6 +183,11 @@ int RGWStreamReadHTTPResourceCRF::read(bufferlist *out, uint64_t max_size, bool return 0; } +bool RGWStreamReadHTTPResourceCRF::is_done() +{ + return req->is_done(); +} + void RGWStreamWriteHTTPResourceCRF::send_ready(const rgw_rest_obj& rest_obj) { req->set_send_length(rest_obj.content_len); @@ -249,14 +257,13 @@ int RGWStreamSpliceCR::operate() { ldout(cct, 20) << "read " << bl.length() << " bytes" << dendl; - if (bl.length() == 0) { - break; + if (!in_crf->has_attrs()) { + assert (bl.length() == 0); + continue; } - if (!in_crf->has_attrs()) { - /* shouldn't happen */ - ldout(cct, 0) << "ERROR: " << __func__ << ": can't handle !in_ctf->has_attrs" << dendl; - return set_cr_error(-EIO); + if (bl.length() == 0 && in_crf->is_done()) { + break; } if (!sent_attrs) { diff --git a/src/rgw/rgw_cr_rest.h b/src/rgw/rgw_cr_rest.h index 512082b5e0951..370e56658d248 100644 --- a/src/rgw/rgw_cr_rest.h +++ b/src/rgw/rgw_cr_rest.h @@ -375,6 +375,7 @@ public: int decode_rest_obj(map& headers, bufferlist& extra_data, rgw_rest_obj *info); bool has_attrs() override; void get_attrs(std::map *attrs); + bool is_done(); virtual bool need_extra_data() { return false; } void set_req(RGWHTTPStreamRWRequest *r) { -- 2.39.5