]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: meta_be, bucket: meta be context can be strongly typed
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 5 Jun 2019 00:49:18 +0000 (17:49 -0700)
committerCasey Bodley <cbodley@redhat.com>
Mon, 29 Jul 2019 19:20:48 +0000 (15:20 -0400)
When passing around the ctx for higher level non-generic functionality
it is better to have a strongly typed context. This is especially important
in the bucket entrypoint and bucket instance case where we can accidentally
confuse the two. There were cases where we created one and used it where
the other one was needed.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/services/svc_bucket.cc
src/rgw/services/svc_bucket.h
src/rgw/services/svc_bucket_types.h [new file with mode: 0644]

index cce90e3f05aa1395d85f6738da6c158558f73bae..bd07751a2ffd33e6facd553f062e06928be08d16 100644 (file)
@@ -2304,7 +2304,7 @@ public:
   void init(RGWSI_Bucket *bucket_svc,
             RGWBucketCtl *bucket_ctl) override {
     base_init(bucket_svc->ctx(),
-              bucket_svc->get_ep_be_handler());
+              bucket_svc->get_ep_be_handler().get());
     svc.bucket = bucket_svc;
     ctl.bucket = bucket_ctl;
   }
@@ -2330,7 +2330,9 @@ public:
     real_time mtime;
     map<string, bufferlist> attrs;
 
-    int ret = svc.bucket->read_bucket_entrypoint_info(op->ctx(), entry, &be, &ot, &mtime, &attrs, y);
+    RGWSI_Bucket_EP_Ctx ctx(op->ctx());
+
+    int ret = svc.bucket->read_bucket_entrypoint_info(ctx, entry, &be, &ot, &mtime, &attrs, y);
     if (ret < 0)
       return ret;
 
@@ -2353,7 +2355,9 @@ public:
 
     real_time orig_mtime;
 
-    int ret = svc.bucket->read_bucket_entrypoint_info(op->ctx(), entry, &be, &objv_tracker, &orig_mtime, nullptr, y);
+    RGWSI_Bucket_EP_Ctx ctx(op->ctx());
+
+    int ret = svc.bucket->read_bucket_entrypoint_info(ctx, entry, &be, &objv_tracker, &orig_mtime, nullptr, y);
     if (ret < 0)
       return ret;
 
@@ -2367,13 +2371,20 @@ public:
       lderr(svc.bucket->ctx()) << "could not unlink bucket=" << entry << " owner=" << be.owner << dendl;
     }
 
-    ret = svc.bucket->remove_bucket_entrypoint_info(op->ctx(), entry, &objv_tracker);
+    ret = svc.bucket->remove_bucket_entrypoint_info(ctx, entry, &objv_tracker);
     if (ret < 0) {
       lderr(svc.bucket->ctx()) << "could not delete bucket=" << entry << dendl;
     }
     /* idempotent */
     return 0;
   }
+
+  int call(std::function<int(RGWSI_Bucket_EP_Ctx& ctx)> f) {
+    return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
+      RGWSI_Bucket_EP_Ctx ctx(op->ctx());
+      return f(ctx);
+    });
+  }
 };
 
 class RGWMetadataHandlerPut_Bucket : public RGWMetadataHandlerPut_SObj
@@ -2419,7 +2430,9 @@ int RGWMetadataHandlerPut_Bucket::put_checked()
   auto mtime = obj->get_mtime();
   auto pattrs = obj->get_pattrs();
 
-  return handler->svc.bucket->store_bucket_entrypoint_info(op->ctx(), entry,
+  RGWSI_Bucket_EP_Ctx ctx(op->ctx());
+
+  return handler->svc.bucket->store_bucket_entrypoint_info(ctx, entry,
                                                            be,
                                                            false,
                                                            mtime,
@@ -2512,6 +2525,8 @@ public:
                 optional_yield y) override {
     auto cct = svc.bucket->ctx();
 
+    RGWSI_Bucket_EP_Ctx ctx(op->ctx());
+
     ldout(cct, 5) << "SKIP: bucket removal is not allowed on archive zone: bucket:" << entry << " ... proceeding to rename" << dendl;
 
     string tenant_name, bucket_name;
@@ -2526,7 +2541,7 @@ public:
 
     RGWBucketEntryPoint be;
     map<string, bufferlist> attrs;
-    int ret = svc.bucket->read_bucket_entrypoint_info(op->ctx(), entry, &be, &objv_tracker, &mtime, &attrs, y);
+    int ret = svc.bucket->read_bucket_entrypoint_info(ctx, entry, &be, &objv_tracker, &mtime, &attrs, y);
     if (ret < 0) {
         return ret;
     }
@@ -2539,7 +2554,9 @@ public:
     ceph::real_time orig_mtime;
     RGWBucketInfo old_bi;
 
-    ret = svc.bucket->read_bucket_instance_info(op->ctx(), bi_meta_name, &old_bi, &orig_mtime, &attrs_m, y);
+    ret = ctl.bucket->read_bucket_instance_info(be.bucket, &old_bi, y, RGWBucketCtl::BucketInstance::GetParams()
+                                                                    .set_mtime(&orig_mtime)
+                                                                    .set_attrs(&attrs_m));
     if (ret < 0) {
         return ret;
     }
@@ -2573,7 +2590,10 @@ public:
 
     new_be.bucket.name = new_bucket_name;
 
-    ret = svc.bucket->store_bucket_instance_info(op->ctx(), bi_meta_name, new_bi, false, orig_mtime, &attrs_m, y);
+    ret = ctl.bucket->store_bucket_instance_info(be.bucket, new_bi, y, RGWBucketCtl::BucketInstance::PutParams()
+                                                                    .set_exclusive(false)
+                                                                    .set_mtime(orig_mtime)
+                                                                    .set_attrs(&attrs_m));
     if (ret < 0) {
       ldout(cct, 0) << "ERROR: failed to put new bucket instance info for bucket=" << new_bi.bucket << " ret=" << ret << dendl;
       return ret;
@@ -2584,7 +2604,7 @@ public:
     RGWObjVersionTracker ot;
     ot.generate_new_write_ver(cct);
 
-    ret = svc.bucket->store_bucket_entrypoint_info(op->ctx(), RGWSI_Bucket::get_entrypoint_meta_key(new_be.bucket),
+    ret = svc.bucket->store_bucket_entrypoint_info(ctx, RGWSI_Bucket::get_entrypoint_meta_key(new_be.bucket),
                                                    new_be, true, mtime, &attrs, nullptr, y);
     if (ret < 0) {
       ldout(cct, 0) << "ERROR: failed to put new bucket entrypoint for bucket=" << new_be.bucket << " ret=" << ret << dendl;
@@ -2611,7 +2631,7 @@ public:
     // whether it was a newly created bucket entrypoint ...  in which case we
     // should ignore the error and move forward, or whether it is a higher version
     // of the same bucket instance ... in which we should retry
-    ret = svc.bucket->remove_bucket_entrypoint_info(op->ctx(),
+    ret = svc.bucket->remove_bucket_entrypoint_info(ctx,
                                                     RGWSI_Bucket::get_entrypoint_meta_key(be.bucket),
                                                     &objv_tracker,
                                                     y);
@@ -2620,7 +2640,7 @@ public:
       return ret;
     }
 
-    ret = svc.bucket->remove_bucket_instance_info(op->ctx(), bi_meta_name, nullptr, y);
+    ret = ctl.bucket->remove_bucket_instance_info(be.bucket, old_bi, y);
     if (ret < 0) {
         lderr(cct) << "could not delete bucket=" << entry << dendl;
     }
@@ -2661,25 +2681,25 @@ public:
 };
 
 class RGWBucketInstanceMetadataHandler : public RGWBucketInstanceMetadataHandlerBase {
-  int read_bucket_instance_entry(RGWSI_MetaBackend_Handler::Op *op,
+  int read_bucket_instance_entry(RGWSI_Bucket_BI_Ctx& ctx,
                                  const string& entry,
                                  RGWBucketCompleteInfo *bi,
                                  ceph::real_time *pmtime,
                                  optional_yield y) {
-    return svc.bucket->read_bucket_instance_info(op->ctx(),
+    return svc.bucket->read_bucket_instance_info(ctx,
                                                  entry,
                                                  &bi->info,
                                                  pmtime, &bi->attrs,
                                                  y);
   }
 
-  int remove_bucket_instance_entry(RGWSI_MetaBackend_Handler::Op *op,
+  int remove_bucket_instance_entry(RGWSI_Bucket_BI_Ctx& ctx,
                                    const string& entry,
                                    RGWObjVersionTracker *objv_tracker,
                                    const ceph::real_time& mtime,
                                    optional_yield y) {
 #warning mtime?
-    return svc.bucket->remove_bucket_instance_info(op->ctx(), entry, objv_tracker, y);
+    return svc.bucket->remove_bucket_instance_info(ctx, entry, objv_tracker, y);
   }
 
 
@@ -2696,7 +2716,7 @@ public:
            RGWSI_Bucket *bucket_svc,
            RGWSI_BucketIndex *bi_svc) {
     base_init(bucket_svc->ctx(),
-              bucket_svc->get_bi_be_handler());
+              bucket_svc->get_bi_be_handler().get());
     svc.zone = zone_svc;
     svc.bucket = bucket_svc;
     svc.bi = bi_svc;
@@ -2720,7 +2740,9 @@ public:
     RGWBucketCompleteInfo bci;
     real_time mtime;
 
-    int ret = svc.bucket->read_bucket_instance_info(op->ctx(), entry, &bci.info, &mtime, &bci.attrs, y);
+    RGWSI_Bucket_BI_Ctx ctx(op->ctx());
+
+    int ret = svc.bucket->read_bucket_instance_info(ctx, entry, &bci.info, &mtime, &bci.attrs, y);
     if (ret < 0)
       return ret;
 
@@ -2739,11 +2761,20 @@ public:
                 optional_yield y) override {
     RGWBucketCompleteInfo bci;
 
-    int ret = read_bucket_instance_entry(op, entry, &bci, nullptr, y);
+    RGWSI_Bucket_BI_Ctx ctx(op->ctx());
+
+    int ret = read_bucket_instance_entry(ctx, entry, &bci, nullptr, y);
     if (ret < 0 && ret != -ENOENT)
       return ret;
 
-    return svc.bucket->remove_bucket_instance_info(op->ctx(), entry, &bci.info.objv_tracker);
+    return svc.bucket->remove_bucket_instance_info(ctx, entry, &bci.info.objv_tracker);
+  }
+
+  int call(std::function<int(RGWSI_Bucket_BI_Ctx& ctx)> f) {
+    return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
+      RGWSI_Bucket_BI_Ctx ctx(op->ctx());
+      return f(ctx);
+    });
   }
 };
 
@@ -2902,14 +2933,23 @@ void RGWBucketCtl::init(RGWUserCtl *user_ctl,
   bi_be_handler = bmi_handler->get_be_handler();
 }
 
+int RGWBucketCtl::call(std::function<int(RGWSI_Bucket_X_Ctx& ctx)> f) {
+  return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ep_ctx) {
+    return bmi_handler->call([&](RGWSI_Bucket_BI_Ctx& bi_ctx) {
+      RGWSI_Bucket_X_Ctx ctx{ep_ctx, bi_ctx};
+      return f(ctx);
+    });
+  });
+}
+
 int RGWBucketCtl::read_bucket_entrypoint_info(const rgw_bucket& bucket,
                                               RGWBucketEntryPoint *info,
                                               optional_yield y,
                                               ceph::optional_ref_default<RGWBucketCtl::Bucket::GetParams> _params)
 {
   auto& params = *_params;
-  return bucket_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return svc.bucket->read_bucket_entrypoint_info(op->ctx(),
+  return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) {
+    return svc.bucket->read_bucket_entrypoint_info(ctx,
                                                    RGWSI_Bucket::get_entrypoint_meta_key(bucket),
                                                    info,
                                                    params.objv_tracker,
@@ -2927,8 +2967,8 @@ int RGWBucketCtl::store_bucket_entrypoint_info(const rgw_bucket& bucket,
                                                ceph::optional_ref_default<RGWBucketCtl::Bucket::PutParams> _params)
 {
   auto& params = *_params;
-  return bucket_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return svc.bucket->store_bucket_entrypoint_info(op->ctx(),
+  return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) {
+    return svc.bucket->store_bucket_entrypoint_info(ctx,
                                                     RGWSI_Bucket::get_entrypoint_meta_key(bucket),
                                                     info,
                                                     params.exclusive,
@@ -2944,8 +2984,8 @@ int RGWBucketCtl::remove_bucket_entrypoint_info(const rgw_bucket& bucket,
                                                 ceph::optional_ref_default<RGWBucketCtl::Bucket::RemoveParams> _params)
 {
   auto& params = *_params;
-  return bucket_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return svc.bucket->remove_bucket_entrypoint_info(op->ctx(),
+  return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) {
+    return svc.bucket->remove_bucket_entrypoint_info(ctx,
                                                      RGWSI_Bucket::get_entrypoint_meta_key(bucket),
                                                      params.objv_tracker);
   });
@@ -2956,8 +2996,8 @@ int RGWBucketCtl::read_bucket_instance_info(const rgw_bucket& bucket,
                                             ceph::optional_ref_default<RGWBucketCtl::BucketInstance::GetParams> _params)
 {
   auto& params = *_params;
-  int ret = bi_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return svc.bucket->read_bucket_instance_info(op->ctx(),
+  int ret = bmi_handler->call([&](RGWSI_Bucket_BI_Ctx& ctx) {
+    return svc.bucket->read_bucket_instance_info(ctx,
                                                  RGWSI_Bucket::get_bi_meta_key(bucket),
                                                  info,
                                                  params.mtime,
@@ -2978,7 +3018,7 @@ int RGWBucketCtl::read_bucket_instance_info(const rgw_bucket& bucket,
   return 0;
 }
 
-int RGWBucketCtl::do_store_bucket_instance_info(RGWSI_MetaBackend_Handler::Op *op,
+int RGWBucketCtl::do_store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                                 const rgw_bucket& bucket,
                                                 RGWBucketInfo& info,
                                                 optional_yield y,
@@ -2989,7 +3029,7 @@ int RGWBucketCtl::do_store_bucket_instance_info(RGWSI_MetaBackend_Handler::Op *o
     info.objv_tracker = *params.objv_tracker;
   }
 
-  return svc.bucket->store_bucket_instance_info(op->ctx(),
+  return svc.bucket->store_bucket_instance_info(ctx,
                                                 RGWSI_Bucket::get_bi_meta_key(bucket),
                                                 info,
                                                 params.exclusive,
@@ -3003,8 +3043,8 @@ int RGWBucketCtl::store_bucket_instance_info(const rgw_bucket& bucket,
                                             optional_yield y,
                                             ceph::optional_ref_default<RGWBucketCtl::BucketInstance::PutParams> _params)
 {
-  return bi_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return do_store_bucket_instance_info(op, bucket, info, _params, y);
+  return bmi_handler->call([&](RGWSI_Bucket_BI_Ctx& ctx) {
+    return do_store_bucket_instance_info(ctx, bucket, info, _params, y);
   });
 }
 
@@ -3018,15 +3058,15 @@ int RGWBucketCtl::remove_bucket_instance_info(const rgw_bucket& bucket,
     info.objv_tracker = *params.objv_tracker;
   }
 
-  return bi_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return svc.bucket->remove_bucket_instance_info(op->ctx(),
+  return bmi_handler->call([&](RGWSI_Bucket_BI_Ctx& ctx) {
+    return svc.bucket->remove_bucket_instance_info(ctx,
                                                    RGWSI_Bucket::get_bi_meta_key(bucket),
                                                    &info.objv_tracker,
                                                    y);
   });
 }
 
-int RGWBucketCtl::convert_old_bucket_info(RGWSI_MetaBackend_Handler::Op *op,
+int RGWBucketCtl::convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx,
                                           const rgw_bucket& bucket,
                                           optional_yield y)
 {
@@ -3039,7 +3079,7 @@ int RGWBucketCtl::convert_old_bucket_info(RGWSI_MetaBackend_Handler::Op *op,
 
   ldout(cct, 10) << "RGWRados::convert_old_bucket_info(): bucket=" << bucket << dendl;
 
-  int ret = svc.bucket->read_bucket_entrypoint_info(op->ctx(),
+  int ret = svc.bucket->read_bucket_entrypoint_info(ctx.ep,
                                                     RGWSI_Bucket::get_entrypoint_meta_key(bucket),
                                                     &entry_point, &ot, &ep_mtime, &attrs, y);
   if (ret < 0) {
@@ -3058,7 +3098,7 @@ int RGWBucketCtl::convert_old_bucket_info(RGWSI_MetaBackend_Handler::Op *op,
 
   ot.generate_new_write_ver(cct);
 
-  ret = svc.bucket->store_linked_bucket_info(op->ctx(), info, false, ep_mtime, &ot.write_version, &attrs, true, y);
+  ret = svc.bucket->store_linked_bucket_info(ctx.bi, info, false, ep_mtime, &ot.write_version, &attrs, true, y);
   if (ret < 0) {
     ldout(cct, 0) << "ERROR: failed to put_linked_bucket_info(): " << ret << dendl;
     return ret;
@@ -3072,19 +3112,19 @@ int RGWBucketCtl::set_bucket_instance_attrs(RGWBucketInfo& bucket_info,
                                             RGWObjVersionTracker *objv_tracker,
                                             optional_yield y)
 {
-  return bi_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
+  return call([&](RGWSI_Bucket_X_Ctx& ctx) {
     rgw_bucket& bucket = bucket_info.bucket;
 
     if (!bucket_info.has_instance_obj) {
       /* an old bucket object, need to convert it */
-        int ret = convert_old_bucket_info(op, bucket, y);
+        int ret = convert_old_bucket_info(ctx, bucket, y);
         if (ret < 0) {
           ldout(cct, 0) << "ERROR: failed converting old bucket info: " << ret << dendl;
           return ret;
         }
     }
 
-    return do_store_bucket_instance_info(op,
+    return do_store_bucket_instance_info(ctx.bi,
                                          bucket,
                                          bucket_info,
                                          y,
@@ -3099,12 +3139,12 @@ int RGWBucketCtl::link_bucket(const rgw_user& user_id,
                               ceph::real_time creation_time,
                               bool update_entrypoint)
 {
-  return bucket_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return do_link_bucket(op, user_id, bucket, creation_time, update_entrypoint);
+  return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) {
+    return do_link_bucket(ctx, user_id, bucket, creation_time, update_entrypoint);
   });
 }
 
-int RGWBucketCtl::do_link_bucket(RGWSI_MetaBackend_Handler::Op *op,
+int RGWBucketCtl::do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx,
                                  const rgw_user& user_id,
                                  const rgw_bucket& bucket,
                                  ceph::real_time creation_time,
@@ -3121,7 +3161,7 @@ int RGWBucketCtl::do_link_bucket(RGWSI_MetaBackend_Handler::Op *op,
 
   if (update_entrypoint) {
     meta_key = RGWSI_Bucket::get_entrypoint_meta_key(bucket);
-    ret = svc.bucket->read_bucket_entrypoint_info(op->ctx(),
+    ret = svc.bucket->read_bucket_entrypoint_info(ctx,
                                                   meta_key,
                                                   &ep, &ot,
                                                   nullptr, &attrs);
@@ -3144,13 +3184,13 @@ int RGWBucketCtl::do_link_bucket(RGWSI_MetaBackend_Handler::Op *op,
   ep.linked = true;
   ep.owner = user_id;
   ep.bucket = bucket;
-  ret = svc.bucket->store_bucket_entrypoint_info(op->ctx(), meta_key, ep, false, real_time(), &attrs, &ot);
+  ret = svc.bucket->store_bucket_entrypoint_info(ctx, meta_key, ep, false, real_time(), &attrs, &ot);
   if (ret < 0)
     goto done_err;
 
   return 0;
 done_err:
-  int r = do_unlink_bucket(op, user_id, bucket, true);
+  int r = do_unlink_bucket(ctx, user_id, bucket, true);
   if (r < 0) {
     ldout(cct, 0) << "ERROR: failed unlinking bucket on error cleanup: "
                            << cpp_strerror(-r) << dendl;
@@ -3160,12 +3200,12 @@ done_err:
 
 int RGWBucketCtl::unlink_bucket(const rgw_user& user_id, const rgw_bucket& bucket, bool update_entrypoint)
 {
-  return bucket_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return do_unlink_bucket(op, user_id, bucket, update_entrypoint);
+  return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) {
+    return do_unlink_bucket(ctx, user_id, bucket, update_entrypoint);
   });
 }
 
-int RGWBucketCtl::do_unlink_bucket(RGWSI_MetaBackend_Handler::Op *op,
+int RGWBucketCtl::do_unlink_bucket(RGWSI_Bucket_EP_Ctx& ctx,
                                    const rgw_user& user_id,
                                    const rgw_bucket& bucket,
                                    bool update_entrypoint)
@@ -3183,7 +3223,7 @@ int RGWBucketCtl::do_unlink_bucket(RGWSI_MetaBackend_Handler::Op *op,
   RGWObjVersionTracker ot;
   map<string, bufferlist> attrs;
   string meta_key = RGWSI_Bucket::get_entrypoint_meta_key(bucket);
-  ret = svc.bucket->read_bucket_entrypoint_info(op->ctx(), meta_key, &ep, &ot, nullptr, &attrs);
+  ret = svc.bucket->read_bucket_entrypoint_info(ctx, meta_key, &ep, &ot, nullptr, &attrs);
   if (ret == -ENOENT)
     return 0;
   if (ret < 0)
@@ -3198,23 +3238,23 @@ int RGWBucketCtl::do_unlink_bucket(RGWSI_MetaBackend_Handler::Op *op,
   }
 
   ep.linked = false;
-  return svc.bucket->store_bucket_entrypoint_info(op->ctx(), meta_key, ep, false, real_time(), &attrs, &ot);
+  return svc.bucket->store_bucket_entrypoint_info(ctx, meta_key, ep, false, real_time(), &attrs, &ot);
 }
 
 int RGWBucketCtl::read_bucket_stats(const rgw_bucket& bucket,
                                     RGWBucketEnt *result,
                                     optional_yield y)
 {
-  return bi_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return svc.bucket->read_bucket_stats(op->ctx(), bucket, result, y);
+  return call([&](RGWSI_Bucket_X_Ctx& ctx) {
+    return svc.bucket->read_bucket_stats(ctx, bucket, result, y);
   });
 }
 
 int RGWBucketCtl::read_buckets_stats(map<string, RGWBucketEnt>& m,
                                      optional_yield y)
 {
-  return bi_be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) {
-    return svc.bucket->read_buckets_stats(op->ctx(), m, y);
+  return call([&](RGWSI_Bucket_X_Ctx& ctx) {
+    return svc.bucket->read_buckets_stats(ctx, m, y);
   });
 }
 
index 1c5fdbcb376fec31039e3b8dd66cde07b73e1551..21b3545e10f2ddb4e5bebd4493bcbb481ae1b311 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "rgw_formats.h"
 
+#include "services/svc_bucket_types.h"
+
 class RGWSI_Meta;
 class RGWBucketMetadataHandler;
 class RGWBucketInstanceMetadataHandler;
@@ -600,8 +602,10 @@ class RGWBucketCtl
   RGWBucketMetadataHandler *bm_handler;
   RGWBucketInstanceMetadataHandler *bmi_handler;
 
-  RGWSI_MetaBackend_Handler *bucket_be_handler; /* bucket backend handler */
-  RGWSI_MetaBackend_Handler *bi_be_handler; /* bucket instance backend handler */
+  RGWSI_Bucket_BE_Handler bucket_be_handler; /* bucket backend handler */
+  RGWSI_BucketInstance_BE_Handler bi_be_handler; /* bucket instance backend handler */
+
+  int call(std::function<int(RGWSI_Bucket_X_Ctx& ctx)> f);
   
 public:
   RGWBucketCtl(RGWSI_Zone *zone_svc,
@@ -758,27 +762,27 @@ public:
   int read_bucket_entrypoint_info(const rgw_bucket& bucket,
                                   RGWBucketEntryPoint *info,
                                   optional_yield y,
-                                  ceph::optional_ref_default<RGWBucketCtl::Bucket::GetParams> params);
+                                  ceph::optional_ref_default<RGWBucketCtl::Bucket::GetParams> params = std::nullopt);
   int store_bucket_entrypoint_info(const rgw_bucket& bucket,
                                    RGWBucketEntryPoint& info,
                                    optional_yield y,
-                                   ceph::optional_ref_default<RGWBucketCtl::Bucket::PutParams> params);
+                                   ceph::optional_ref_default<RGWBucketCtl::Bucket::PutParams> params = std::nullopt);
   int remove_bucket_entrypoint_info(const rgw_bucket& bucket,
                                     optional_yield y,
-                                    ceph::optional_ref_default<RGWBucketCtl::Bucket::RemoveParams> params);
+                                    ceph::optional_ref_default<RGWBucketCtl::Bucket::RemoveParams> params = std::nullopt);
 
   /* bucket instance */
   int read_bucket_instance_info(const rgw_bucket& bucket,
                                   RGWBucketInfo *info,
-                                  ceph::optional_ref_default<RGWBucketCtl::BucketInstance::GetParams> params);
+                                  ceph::optional_ref_default<RGWBucketCtl::BucketInstance::GetParams> params = std::nullopt);
   int store_bucket_instance_info(const rgw_bucket& bucket,
                                    RGWBucketInfo& info,
                                    optional_yield y,
-                                   ceph::optional_ref_default<RGWBucketCtl::BucketInstance::PutParams> params);
+                                   ceph::optional_ref_default<RGWBucketCtl::BucketInstance::PutParams> params = std::nullopt);
   int remove_bucket_instance_info(const rgw_bucket& bucket,
-                                  RGWBucketInfo& info,
                                   optional_yield y,
-                                  ceph::optional_ref_default<RGWBucketCtl::BucketInstance::RemoveParams> params);
+                                  RGWBucketInfo& info,
+                                  ceph::optional_ref_default<RGWBucketCtl::BucketInstance::RemoveParams> params = std::nullopt);
 
   int set_bucket_instance_attrs(RGWBucketInfo& bucket_info,
                                 map<string, bufferlist>& attrs,
@@ -806,23 +810,23 @@ public:
   int sync_user_stats(const rgw_user& user_id, const RGWBucketInfo& bucket_info);
 
 private:
-  int convert_old_bucket_info(RGWSI_MetaBackend_Handler::Op *op,
+  int convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx,
                               const rgw_bucket& bucket,
                               optional_yield y);
 
-  int do_store_bucket_instance_info(RGWSI_MetaBackend_Handler::Op *op,
+  int do_store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                     const rgw_bucket& bucket,
                                     RGWBucketInfo& info,
                                     optional_yield y,
                                     ceph::optional_ref_default<RGWBucketCtl::BucketInstance::PutParams> params);
 
-  int do_link_bucket(RGWSI_MetaBackend_Handler::Op *op,
+  int do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx,
                      const rgw_user& user,
                      const rgw_bucket& bucket,
                      ceph::real_time creation_time,
                      bool update_entrypoint);
 
-  int do_unlink_bucket(RGWSI_MetaBackend_Handler::Op *op,
+  int do_unlink_bucket(RGWSI_Bucket_EP_Ctx& ctx,
                        const rgw_user& user_id,
                        const rgw_bucket& bucket,
                        bool update_entrypoint);
index 10decb40011483a4265664398aa49e1c9d5c8ea3..2bcf4cd03820238693784d2f3d3f3fb0f6da445d 100644 (file)
@@ -179,13 +179,17 @@ int RGWSI_Bucket::do_start()
 
   /* create first backend handler for bucket entrypoints */
 
-  int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, &ep_be_handler);
+  RGWSI_MetaBackend_Handler *ep_handler;
+
+  int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, &ep_handler);
   if (r < 0) {
     ldout(ctx(), 0) << "ERROR: failed to create be handler: r=" << r << dendl;
     return r;
   }
 
-  RGWSI_MetaBackend_Handler_SObj *ep_bh = static_cast<RGWSI_MetaBackend_Handler_SObj *>(ep_be_handler);
+  ep_be_handler = ep_handler;
+
+  RGWSI_MetaBackend_Handler_SObj *ep_bh = static_cast<RGWSI_MetaBackend_Handler_SObj *>(ep_handler);
 
   auto ep_module = new RGWSI_Bucket_Module(svc);
   ep_be_module.reset(ep_module);
@@ -193,13 +197,17 @@ int RGWSI_Bucket::do_start()
 
   /* create a second backend handler for bucket instance */
 
-  r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, &bi_be_handler);
+  RGWSI_MetaBackend_Handler *bi_handler;
+
+  r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, &bi_handler);
   if (r < 0) {
     ldout(ctx(), 0) << "ERROR: failed to create be handler: r=" << r << dendl;
     return r;
   }
 
-  RGWSI_MetaBackend_Handler_SObj *bi_bh = static_cast<RGWSI_MetaBackend_Handler_SObj *>(bi_be_handler);
+  bi_be_handler = bi_handler;
+
+  RGWSI_MetaBackend_Handler_SObj *bi_bh = static_cast<RGWSI_MetaBackend_Handler_SObj *>(bi_handler);
 
   auto bi_module = new RGWSI_BucketInstance_Module(svc);
   bi_be_module.reset(bi_module);
@@ -208,7 +216,7 @@ int RGWSI_Bucket::do_start()
   return 0;
 }
 
-int RGWSI_Bucket::read_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::read_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx,
                                               const string& key,
                                               RGWBucketEntryPoint *entry_point,
                                               RGWObjVersionTracker *objv_tracker,
@@ -223,7 +231,7 @@ int RGWSI_Bucket::read_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
   auto params = RGWSI_MBSObj_GetParams(&bl, pattrs, pmtime).set_cache_info(cache_info)
                                                            .set_refresh_version(refresh_version);
                                                     
-  int ret = svc.meta_be->get_entry(ctx, key, params, objv_tracker);
+  int ret = svc.meta_be->get_entry(ctx.get(), key, params, objv_tracker);
   if (ret < 0) {
     return ret;
   }
@@ -238,7 +246,7 @@ int RGWSI_Bucket::read_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
   return 0;
 }
 
-int RGWSI_Bucket::store_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::store_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx,
                                                const string& key,
                                                RGWBucketEntryPoint& info,
                                                bool exclusive,
@@ -252,7 +260,7 @@ int RGWSI_Bucket::store_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
 
   RGWSI_MBSObj_PutParams params(bl, pattrs, mtime, exclusive);
 
-  int ret = svc.meta_be->put_entry(ctx, key, params, objv_tracker);
+  int ret = svc.meta_be->put_entry(ctx.get(), key, params, objv_tracker);
   if (ret == -EEXIST) {
     /* well, if it's exclusive we shouldn't overwrite it, because we might race with another
      * bucket operation on this specific bucket (e.g., being synced from the master), but
@@ -272,15 +280,15 @@ int RGWSI_Bucket::store_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
   return ret;
 }
 
-int RGWSI_Bucket::remove_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::remove_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx,
                                                 const string& key,
                                                 optional_yield y)
 {
   RGWSI_MBSObj_RemoveParams params;
-  return svc.meta_be->remove_entry(ctx, key, params, objv_tracker, y);
+  return svc.meta_be->remove_entry(ctx.get(), key, params, objv_tracker, y);
 }
 
-int RGWSI_Bucket::read_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                             const string& key,
                                             RGWBucketInfo *info,
                                             real_time *pmtime, map<string, bufferlist> *pattrs,
@@ -315,7 +323,7 @@ int RGWSI_Bucket::read_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
   return 0;
 }
 
-int RGWSI_Bucket::do_read_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::do_read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                                const string& key,
                                                RGWBucketInfo *info,
                                                real_time *pmtime, map<string, bufferlist> *pattrs,
@@ -329,7 +337,7 @@ int RGWSI_Bucket::do_read_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
   auto params = RGWSI_MBSObj_GetParams(&bl, pattrs, pmtime).set_cache_info(cache_info)
                                                            .set_refresh_version(refresh_version);
 
-  int ret = svc.meta_be->get_entry(ctx, key, params, &ot, y);
+  int ret = svc.meta_be->get_entry(ctx.get(), key, params, &ot, y);
   if (ret < 0) {
     return ret;
   }
@@ -349,7 +357,7 @@ int RGWSI_Bucket::do_read_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
   return 0;
 }
 
-int RGWSI_Bucket::read_bucket_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::read_bucket_info(RGWSI_Bucket_X_Ctx& ctx,
                                    const rgw_bucket& bucket,
                                    RGWBucketInfo *info,
                                    real_time *pmtime,
@@ -383,7 +391,7 @@ int RGWSI_Bucket::read_bucket_info(RGWSI_MetaBackend::Context *ctx,
   }
 
   if (!bucket.bucket_id.empty()) {
-    return read_bucket_instance_info(ctx, get_bi_meta_key(bucket),
+    return read_bucket_instance_info(ctx.bi, get_bi_meta_key(bucket),
                                      info,
                                      pmtime, pattrs,
                                      &cache_info, refresh_version,
@@ -395,7 +403,7 @@ int RGWSI_Bucket::read_bucket_info(RGWSI_MetaBackend::Context *ctx,
   real_time ep_mtime;
   RGWObjVersionTracker ot;
   rgw_cache_entry_info entry_cache_info;
-  int ret = read_bucket_entrypoint_info(ctx, bucket_entry,
+  int ret = read_bucket_entrypoint_info(ctx.ep, bucket_entry,
                                         &entry_point, &ot, &ep_mtime, pattrs,
                                         &entry_cache_info, refresh_version,
                                         y);
@@ -426,7 +434,7 @@ int RGWSI_Bucket::read_bucket_info(RGWSI_MetaBackend::Context *ctx,
 
   /* read bucket instance info */
 
-  ret = read_bucket_instance_info(ctx, get_bi_meta_key(entry_point.bucket),
+  ret = read_bucket_instance_info(ctx.bi, get_bi_meta_key(entry_point.bucket),
                                   &e.info, &e.mtime, &e.attrs,
                                   &cache_info, refresh_version, y);
   e.info.ep_objv = ot.read_version;
@@ -459,7 +467,7 @@ int RGWSI_Bucket::read_bucket_info(RGWSI_MetaBackend::Context *ctx,
 }
 
 
-int RGWSI_Bucket::store_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                              const string& key,
                                              RGWBucketInfo& info,
                                              bool exclusive,
@@ -472,7 +480,7 @@ int RGWSI_Bucket::store_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
 
   RGWSI_MBSObj_PutParams params(bl, pattrs, mtime, exclusive);
 
-  int ret = svc.meta_be->put_entry(ctx, key, params, &info.objv_tracker, y);
+  int ret = svc.meta_be->put_entry(ctx.get(), key, params, &info.objv_tracker, y);
   if (ret == -EEXIST) {
     /* well, if it's exclusive we shouldn't overwrite it, because we might race with another
      * bucket operation on this specific bucket (e.g., being synced from the master), but
@@ -492,13 +500,13 @@ int RGWSI_Bucket::store_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
   return ret;
 }
 
-int RGWSI_Bucket::remove_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::remove_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                               const string& key,
                                               RGWObjVersionTracker *objv_tracker,
                                               optional_yield y)
 {
   RGWSI_MBSObj_RemoveParams params;
-  return svc.meta_be->remove_entry(ctx, key, params, objv_tracker, y);
+  return svc.meta_be->remove_entry(ctx.get(), key, params, objv_tracker, y);
 }
 
 int RGWSI_Bucket::read_bucket_stats(const RGWBucketInfo& bucket_info,
@@ -520,7 +528,7 @@ int RGWSI_Bucket::read_bucket_stats(const RGWBucketInfo& bucket_info,
   return 0;
 }
 
-int RGWSI_Bucket::read_bucket_stats(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::read_bucket_stats(RGWSI_Bucket_X_Ctx& ctx,
                                     const rgw_bucket& bucket,
                                     RGWBucketEnt *ent,
                                     optional_yield y)
@@ -534,7 +542,7 @@ int RGWSI_Bucket::read_bucket_stats(RGWSI_MetaBackend::Context *ctx,
   return read_bucket_stats(bucket_info, ent, y);
 }
 
-int RGWSI_Bucket::read_buckets_stats(RGWSI_MetaBackend::Context *ctx,
+int RGWSI_Bucket::read_buckets_stats(RGWSI_Bucket_X_Ctx& ctx,
                                      map<string, RGWBucketEnt>& m,
                                      optional_yield y)
 {
index 5a0bb6563914a430dc652deab56dfd4e71ba4202..5f32c08be44c364708e98329be2f133d7b0f4ca2 100644 (file)
@@ -20,6 +20,7 @@
 #include "rgw/rgw_service.h"
 
 #include "svc_meta_be.h"
+#include "svc_bucket_types.h"
 
 class RGWSI_Zone;
 class RGWSI_SysObj;
@@ -45,14 +46,14 @@ class RGWSI_Bucket : public RGWServiceInstance
   using RGWChainedCacheImpl_bucket_info_cache_entry = RGWChainedCacheImpl<bucket_info_cache_entry>;
   unique_ptr<RGWChainedCacheImpl_bucket_info_cache_entry> binfo_cache;
 
-  RGWSI_MetaBackend_Handler *ep_be_handler;
+  RGWSI_Bucket_BE_Handler ep_be_handler;
   std::unique_ptr<RGWSI_MetaBackend::Module> ep_be_module;
-  RGWSI_MetaBackend_Handler *bi_be_handler;
+  RGWSI_BucketInstance_BE_Handler bi_be_handler;
   std::unique_ptr<RGWSI_MetaBackend::Module> bi_be_module;
 
   int do_start() override;
 
-  int do_read_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+  int do_read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                    const string& key,
                                    RGWBucketInfo *info,
                                    real_time *pmtime,
@@ -82,11 +83,11 @@ public:
   static string get_entrypoint_meta_key(const rgw_bucket& bucket);
   static string get_bi_meta_key(const rgw_bucket& bucket);
 
-  RGWSI_MetaBackend_Handler *get_ep_be_handler() {
+  RGWSI_Bucket_BE_Handler& get_ep_be_handler() {
     return ep_be_handler;
   }
 
-  RGWSI_MetaBackend_Handler *get_bi_be_handler() {
+  RGWSI_BucketInstance_BE_Handler& get_bi_be_handler() {
     return bi_be_handler;
   }
 
@@ -99,7 +100,7 @@ public:
            RGWSI_SyncModules *_sync_modules);
 
 
-  int read_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
+  int read_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx,
                                   const string& key,
                                   RGWBucketEntryPoint *entry_point,
                                   RGWObjVersionTracker *objv_tracker,
@@ -109,7 +110,7 @@ public:
                                   rgw_cache_entry_info *cache_info = nullptr,
                                   boost::optional<obj_version> refresh_version = boost::none);
 
-  int store_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
+  int store_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx,
                                    const string& key,
                                    RGWBucketEntryPoint& info,
                                    bool exclusive,
@@ -118,12 +119,12 @@ public:
                                    RGWObjVersionTracker *objv_tracker,
                                    optional_yield y);
 
-  int remove_bucket_entrypoint_info(RGWSI_MetaBackend::Context *ctx,
+  int remove_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx,
                                     const string& key,
                                     RGWObjVersionTracker *objv_tracker,
                                     optional_yield y);
 
-  int read_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+  int read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                 const string& key,
                                 RGWBucketInfo *info,
                                 real_time *pmtime,
@@ -132,7 +133,7 @@ public:
                                 rgw_cache_entry_info *cache_info = nullptr,
                                 boost::optional<obj_version> refresh_version = boost::none);
 
-  int read_bucket_info(RGWSI_MetaBackend::Context *ctx,
+  int read_bucket_info(RGWSI_Bucket_X_Ctx& ep_ctx,
                        const rgw_bucket& bucket,
                        RGWBucketInfo *info,
                        real_time *pmtime,
@@ -140,7 +141,7 @@ public:
                        boost::optional<obj_version> refresh_version,
                        optional_yield y);
 
-  int store_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+  int store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                  const string& key,
                                  RGWBucketInfo& info,
                                  bool exclusive,
@@ -148,17 +149,17 @@ public:
                                  map<string, bufferlist> *pattrs,
                                  optional_yield y);
 
-  int remove_bucket_instance_info(RGWSI_MetaBackend::Context *ctx,
+  int remove_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx,
                                   const string& key,
                                   RGWObjVersionTracker *objv_tracker,
                                   optional_yield y);
 
-  int read_bucket_stats(RGWSI_MetaBackend::Context *ctx,
+  int read_bucket_stats(RGWSI_Bucket_X_Ctx& ctx,
                         const rgw_bucket& bucket,
                         RGWBucketEnt *ent,
                         optional_yield y);
 
-  int read_buckets_stats(RGWSI_MetaBackend::Context *ctx,
+  int read_buckets_stats(RGWSI_Bucket_X_Ctx& ctx,
                          map<string, RGWBucketEnt>& m,
                          optional_yield y);
 };
diff --git a/src/rgw/services/svc_bucket_types.h b/src/rgw/services/svc_bucket_types.h
new file mode 100644 (file)
index 0000000..8cb677c
--- /dev/null
@@ -0,0 +1,34 @@
+
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+
+#pragma once
+
+#include "common/ptr_wrapper.h"
+
+#include "svc_meta_be_types.h"
+
+class RGWSI_MetaBackend_Handler;
+
+using RGWSI_Bucket_BE_Handler = ptr_wrapper<RGWSI_MetaBackend_Handler, RGWSI_META_BE_TYPES::BUCKET>;
+using RGWSI_BucketInstance_BE_Handler = ptr_wrapper<RGWSI_MetaBackend_Handler, RGWSI_META_BE_TYPES::BI>;
+
+
+using RGWSI_Bucket_EP_Ctx = ptr_wrapper<RGWSI_MetaBackend::Context, RGWSI_META_BE_TYPES::BUCKET>;
+using RGWSI_Bucket_BI_Ctx = ptr_wrapper<RGWSI_MetaBackend::Context, RGWSI_META_BE_TYPES::BI>;
+
+struct RGWSI_Bucket_X_Ctx {
+  RGWSI_Bucket_EP_Ctx ep;
+  RGWSI_Bucket_BI_Ctx bi;
+};
+