]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add empty_on_enoent flag to RGWSimpleRadosReadCR
authorCasey Bodley <cbodley@redhat.com>
Wed, 8 Jun 2016 13:37:26 +0000 (09:37 -0400)
committerCasey Bodley <cbodley@redhat.com>
Fri, 22 Jul 2016 02:14:20 +0000 (22:14 -0400)
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>
src/rgw/rgw_cr_rados.h

index 24a284d63d52765f205d7907bd9da742f00c47fb..81cae4d281302d16ce51851a2da060cc5ba4205c 100644 (file)
@@ -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();
   }
@@ -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;
     }
@@ -245,8 +246,6 @@ int RGWSimpleRadosReadCR<T>::request_complete()
     } catch (buffer::error& err) {
       return -EIO;
     }
-  } else {
-    *result = T();
   }
 
   return handle_data(*result);