Skip to content

Commit

Permalink
rgw: add empty_on_enoent flag to RGWSimpleRadosReadCR
Browse files Browse the repository at this point in the history
RGWSimpleRadosReadCR won't currently fail with ENOENT, but instead
passes an empty object to handle_data(). add an empty_on_enoent flag to
the constructor, defaulting to true, to make this behavior optional for
callers that do want to fail on ENOENT

Signed-off-by: Casey Bodley <cbodley@redhat.com>
  • Loading branch information
cbodley committed Jul 22, 2016
1 parent a0294e6 commit c5c95e7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/rgw/rgw_cr_rados.h
Expand Up @@ -180,22 +180,21 @@ class RGWSimpleRadosReadCR : public RGWSimpleCoroutine {
rgw_bucket pool;
string oid;

map<string, bufferlist> *pattrs;
map<string, bufferlist> *pattrs{nullptr};

T *result;
/// on ENOENT, call handle_data() with an empty object instead of failing
const bool empty_on_enoent;

RGWAsyncGetSystemObj *req;
RGWAsyncGetSystemObj *req{nullptr};

public:
RGWSimpleRadosReadCR(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store,
const rgw_bucket& _pool, const string& _oid,
T *_result) : RGWSimpleCoroutine(_store->ctx()),
async_rados(_async_rados), store(_store),
obj_ctx(store),
pool(_pool), oid(_oid),
pattrs(NULL),
result(_result),
req(NULL) { }
T *_result, bool empty_on_enoent = true)
: RGWSimpleCoroutine(_store->ctx()), async_rados(_async_rados), store(_store),
obj_ctx(store), pool(_pool), oid(_oid), result(_result),
empty_on_enoent(empty_on_enoent) {}
~RGWSimpleRadosReadCR() {
request_cleanup();
}
Expand Down Expand Up @@ -235,7 +234,9 @@ int RGWSimpleRadosReadCR<T>::request_complete()
{
int ret = req->get_ret_status();
retcode = ret;
if (ret != -ENOENT) {
if (ret == -ENOENT && empty_on_enoent) {
*result = T();
} else {
if (ret < 0) {
return ret;
}
Expand All @@ -245,8 +246,6 @@ int RGWSimpleRadosReadCR<T>::request_complete()
} catch (buffer::error& err) {
return -EIO;
}
} else {
*result = T();
}

return handle_data(*result);
Expand Down

0 comments on commit c5c95e7

Please sign in to comment.