]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: initial work to add otp as metadata provider
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 21 Nov 2017 23:11:34 +0000 (15:11 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 9 Apr 2018 14:01:02 +0000 (07:01 -0700)
To allow transparent multisite sync

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/CMakeLists.txt
src/rgw/rgw_admin.cc
src/rgw/rgw_main.cc
src/rgw/rgw_otp.cc [new file with mode: 0644]
src/rgw/rgw_otp.h [new file with mode: 0644]

index e29c89f935c3d61d3542a64c2b1434828f426e23..8ec7f19ddcc848e85d182f37987dd632e65d24a3 100644 (file)
@@ -73,6 +73,7 @@ set(rgw_a_srcs
   rgw_multi_del.cc
   rgw_sync.cc
   rgw_data_sync.cc
+  rgw_otp.cc
   rgw_sync_module.cc
   rgw_sync_module_es.cc
   rgw_sync_module_es_rest.cc
index 95243a3a478fb285f43592f9aa0674d749e0ed05..9350ae5752c9d9faffc50f9827cacb875eedcbc3 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "rgw_user.h"
 #include "rgw_bucket.h"
+#include "rgw_otp.h"
 #include "rgw_rados.h"
 #include "rgw_acl.h"
 #include "rgw_acl_s3.h"
@@ -3051,6 +3052,7 @@ int main(int argc, const char **argv)
 
   rgw_user_init(store);
   rgw_bucket_init(store->meta_mgr);
+  rgw_otp_init(store);
 
   struct rgw_curl_setup {
     rgw_curl_setup() {
index 4b346c1507b0ec00da657134bf8a2ea7ef5559f9..ac8c6e3cd3c239f79690e08e76374dc23ec88683 100644 (file)
@@ -13,6 +13,7 @@
 #include "include/stringify.h"
 #include "rgw_common.h"
 #include "rgw_rados.h"
+#include "rgw_otp.h"
 #include "rgw_period_pusher.h"
 #include "rgw_realm_reloader.h"
 #include "rgw_rest.h"
@@ -329,6 +330,7 @@ int main(int argc, const char **argv)
 
   rgw_user_init(store);
   rgw_bucket_init(store->meta_mgr);
+  rgw_otp_init(store);
   rgw_log_usage_init(g_ceph_context, store);
 
   RGWREST rest;
diff --git a/src/rgw/rgw_otp.cc b/src/rgw/rgw_otp.cc
new file mode 100644 (file)
index 0000000..cec7e06
--- /dev/null
@@ -0,0 +1,210 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include <errno.h>
+
+#include <string>
+#include <map>
+#include <boost/algorithm/string.hpp>
+
+#include "common/errno.h"
+#include "common/Formatter.h"
+#include "common/ceph_json.h"
+#include "common/backport14.h"
+#include "rgw_rados.h"
+
+#include "include/types.h"
+
+#include "rgw_common.h"
+
+#define dout_subsys ceph_subsys_rgw
+
+using namespace std;
+
+
+static RGWMetadataHandler *otp_meta_handler = NULL;
+
+
+struct RGWUserCompleteInfo {
+  RGWUserInfo info;
+  map<string, bufferlist> attrs;
+  bool has_attrs;
+
+  RGWUserCompleteInfo()
+    : has_attrs(false)
+  {}
+
+  void dump(Formatter * const f) const {
+    info.dump(f);
+    encode_json("attrs", attrs, f);
+  }
+
+  void decode_json(JSONObj *obj) {
+    decode_json_obj(info, obj);
+    has_attrs = JSONDecoder::decode_json("attrs", attrs, obj);
+  }
+};
+
+class RGWUserMetadataObject : public RGWMetadataObject {
+  RGWUserCompleteInfo uci;
+public:
+  RGWUserMetadataObject(const RGWUserCompleteInfo& _uci, obj_version& v, real_time m)
+      : uci(_uci) {
+    objv = v;
+    mtime = m;
+  }
+
+  void dump(Formatter *f) const override {
+    uci.dump(f);
+  }
+};
+
+class RGWOTPMetadataHandler : public RGWMetadataHandler {
+public:
+  string get_type() override { return "otp"; }
+
+  int get(RGWRados *store, string& entry, RGWMetadataObject **obj) override {
+#if 0
+    RGWUserCompleteInfo uci;
+    RGWObjVersionTracker objv_tracker;
+    real_time mtime;
+
+    rgw_user uid(entry);
+
+    int ret = rgw_get_user_info_by_uid(store, uid, uci.info, &objv_tracker,
+                                       &mtime, NULL, &uci.attrs);
+    if (ret < 0) {
+      return ret;
+    }
+
+    RGWUserMetadataObject *mdo = new RGWUserMetadataObject(uci, objv_tracker.read_version, mtime);
+    *obj = mdo;
+
+#endif
+    return -ENOTSUP;
+  }
+
+  int put(RGWRados *store, string& entry, RGWObjVersionTracker& objv_tracker,
+          real_time mtime, JSONObj *obj, sync_type_t sync_mode) override {
+#if 0
+    RGWUserCompleteInfo uci;
+
+    try {
+      decode_json_obj(uci, obj);
+    } catch (JSONDecoder::err& e) {
+      return -EINVAL;
+    }
+
+    map<string, bufferlist> *pattrs = NULL;
+    if (uci.has_attrs) {
+      pattrs = &uci.attrs;
+    }
+
+    rgw_user uid(entry);
+
+    RGWUserInfo old_info;
+    real_time orig_mtime;
+    int ret = rgw_get_user_info_by_uid(store, uid, old_info, &objv_tracker, &orig_mtime);
+    if (ret < 0 && ret != -ENOENT)
+      return ret;
+
+    // are we actually going to perform this put, or is it too old?
+    if (ret != -ENOENT &&
+        !check_versions(objv_tracker.read_version, orig_mtime,
+                       objv_tracker.write_version, mtime, sync_mode)) {
+      return STATUS_NO_APPLY;
+    }
+
+    ret = rgw_store_user_info(store, uci.info, &old_info, &objv_tracker, mtime, false, pattrs);
+    if (ret < 0) {
+      return ret;
+    }
+
+    return STATUS_APPLIED;
+#endif
+    return -ENOTSUP;
+  }
+
+  struct list_keys_info {
+    RGWRados *store;
+    RGWListRawObjsCtx ctx;
+  };
+
+  int remove(RGWRados *store, string& entry, RGWObjVersionTracker& objv_tracker) override {
+    RGWUserInfo info;
+
+#warning FIXME
+#if 0
+    rgw_user uid(entry);
+
+    int ret = rgw_get_user_info_by_uid(store, uid, info, &objv_tracker);
+    if (ret < 0)
+      return ret;
+
+    return rgw_delete_user(store, info, objv_tracker);
+#endif
+    return -ENOTSUP;
+  }
+
+  void get_pool_and_oid(RGWRados *store, const string& key, rgw_pool& pool, string& oid) override {
+    oid = key;
+    pool = store->get_zone_params().user_uid_pool;
+  }
+
+  int list_keys_init(RGWRados *store, const string& marker, void **phandle) override
+  {
+    auto info = ceph::make_unique<list_keys_info>();
+
+    info->store = store;
+
+    int ret = store->list_raw_objects_init(store->get_zone_params().otp_pool, marker,
+                                           &info->ctx);
+    if (ret < 0) {
+      return ret;
+    }
+
+    *phandle = (void *)info.release();
+
+    return 0;
+  }
+
+  int list_keys_next(void *handle, int max, list<string>& keys, bool *truncated) override {
+    list_keys_info *info = static_cast<list_keys_info *>(handle);
+
+    string no_filter;
+
+    keys.clear();
+
+    RGWRados *store = info->store;
+
+    list<string> unfiltered_keys;
+
+    int ret = store->list_raw_objects_next(no_filter, max, info->ctx,
+                                           keys, truncated);
+    if (ret < 0 && ret != -ENOENT)
+      return ret;                      
+    if (ret == -ENOENT) {
+      if (truncated)
+        *truncated = false;
+      return -ENOENT;
+    }
+
+    return 0;
+  }
+
+  void list_keys_complete(void *handle) override {
+    list_keys_info *info = static_cast<list_keys_info *>(handle);
+    delete info;
+  }
+
+  string get_marker(void *handle) {
+    list_keys_info *info = static_cast<list_keys_info *>(handle);
+    return info->store->list_raw_objs_get_cursor(info->ctx);
+  }
+};
+
+void rgw_otp_init(RGWRados *store)
+{
+  otp_meta_handler = new RGWOTPMetadataHandler;
+  store->meta_mgr->register_handler(otp_meta_handler);
+}
diff --git a/src/rgw/rgw_otp.h b/src/rgw/rgw_otp.h
new file mode 100644 (file)
index 0000000..c3e4106
--- /dev/null
@@ -0,0 +1,12 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_RGW_OTP_H
+#define CEPH_RGW_OTP_H
+
+class RGWRados;
+
+void rgw_otp_init(RGWRados *store);
+
+#endif
+