]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: default zonegroup per realm
authorOrit Wasserman <owasserm@redhat.com>
Wed, 9 Dec 2015 10:02:13 +0000 (11:02 +0100)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:44 +0000 (16:13 -0800)
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index c9023ee12ed2d86ba705856c67ea1bcd772ac844..a7877068ba0e8cd9e9dcd7a41af8fdb138b5a15f 100644 (file)
@@ -188,7 +188,7 @@ int RGWZoneGroup::create_default(bool old_format)
   return 0;
 }
 
-const string& RGWZoneGroup::get_default_oid(bool old_region_format)
+const string RGWZoneGroup::get_default_oid(bool old_region_format)
 {
   if (old_region_format) {
     if (cct->_conf->rgw_default_region_info_oid.empty()) {
@@ -197,11 +197,15 @@ const string& RGWZoneGroup::get_default_oid(bool old_region_format)
     return cct->_conf->rgw_default_region_info_oid;
   }
 
+  string default_oid = cct->_conf->rgw_default_zonegroup_info_oid;
+
   if (cct->_conf->rgw_default_zonegroup_info_oid.empty()) {
-    return default_zone_group_info_oid;
+    default_oid = default_zone_group_info_oid;
   }
 
-  return cct->_conf->rgw_default_zonegroup_info_oid;
+  default_oid += "." + realm_id;
+
+  return default_oid;
 }
 
 const string& RGWZoneGroup::get_info_oid_prefix(bool old_region_format)
@@ -319,6 +323,38 @@ int RGWZoneGroup::remove_zone(const RGWZoneParams& zone_params)
   return update();
 }
 
+int RGWZoneGroup::read_default_id(string& default_id, bool old_format)
+{
+  if (realm_id.empty()) {
+    /* try using default realm */
+    RGWRealm realm;
+    int ret = realm.init(cct, store);
+    if (ret < 0) {
+      lderr(cct) << "could not read realm id: " << cpp_strerror(-ret) << dendl;
+      return -ENOENT;
+    }
+    realm_id = realm.get_id();
+  }
+
+  return RGWSystemMetaObj::read_default_id(default_id, old_format);
+}
+
+int RGWZoneGroup::set_as_default()
+{
+  if (realm_id.empty()) {
+    /* try using default realm */
+    RGWRealm realm;
+    int ret = realm.init(cct, store);
+    if (ret < 0) {
+      lderr(cct) << "could not read realm id: " << cpp_strerror(-ret) << dendl;
+      return -EINVAL;
+    }
+    realm_id = realm.get_id();
+  }
+
+  return RGWSystemMetaObj::set_as_default();
+}
+
 int RGWSystemMetaObj::init(CephContext *_cct, RGWRados *_store, bool setup_obj, bool old_format)
 {
   cct = _cct;
@@ -381,6 +417,7 @@ int RGWSystemMetaObj::read_default_id(string& default_id, bool old_format)
 
   int ret = read_default(default_info, get_default_oid(old_format));
   if (ret < 0) {
+    lderr(cct) << "error in read_default: " << cpp_strerror(-ret) << dendl;
     return ret;
   }
 
@@ -391,14 +428,7 @@ int RGWSystemMetaObj::read_default_id(string& default_id, bool old_format)
 
 int RGWSystemMetaObj::use_default(bool old_format)
 {
-  RGWDefaultSystemMetaObjInfo default_info;
-  int ret = read_default(default_info, get_default_oid(old_format));
-  if (ret < 0)
-    return ret;
-
-  id = default_info.default_id;
-
-  return 0;
+  return read_default_id(id, old_format);
 }
 
 int RGWSystemMetaObj::set_as_default()
@@ -736,7 +766,7 @@ const string& RGWRealm::get_pool_name(CephContext *cct)
   return cct->_conf->rgw_realm_root_pool;
 }
 
-const string& RGWRealm::get_default_oid(bool old_format)
+const string RGWRealm::get_default_oid(bool old_format)
 {
   if (cct->_conf->rgw_default_realm_info_oid.empty()) {
     return default_realm_info_oid;
@@ -1482,7 +1512,7 @@ const string& RGWZoneParams::get_pool_name(CephContext *cct)
   return cct->_conf->rgw_zone_root_pool;
 }
 
-const string& RGWZoneParams::get_default_oid(bool old_format)
+const string RGWZoneParams::get_default_oid(bool old_format)
 {
   return cct->_conf->rgw_default_zone_info_oid;
 }
index b35d346162a622b77f82e4b2abe809117c792539..324a63dc52da2efcf9d3141e4745a63509424d2e 100644 (file)
@@ -788,8 +788,8 @@ public:
     store = _store;
   }
   int init(CephContext *_cct, RGWRados *_store, bool setup_obj = true, bool old_format = false);
-  int read_default_id(string& default_id, bool old_format = false);
-  int set_as_default();
+  virtual int read_default_id(string& default_id, bool old_format = false);
+  virtual int set_as_default();
   int delete_default();
   virtual int create(bool exclusive = true);
   int delete_obj(bool old_format = false);
@@ -800,7 +800,7 @@ public:
   int write(bool exclusive);
 
   virtual const string& get_pool_name(CephContext *cct) = 0;
-  virtual const string& get_default_oid(bool old_format = false) = 0;
+  virtual const string get_default_oid(bool old_format = false) = 0;
   virtual const string& get_names_oid_prefix() = 0;
   virtual const string& get_info_oid_prefix(bool old_format = false) = 0;
   virtual const string& get_predefined_name(CephContext *cct) = 0;
@@ -868,7 +868,7 @@ struct RGWZoneParams : RGWSystemMetaObj {
   RGWZoneParams(const string& id, const string& name) : RGWSystemMetaObj(id, name) {}
 
   const string& get_pool_name(CephContext *cct);
-  const string& get_default_oid(bool old_format = false);
+  const string get_default_oid(bool old_format = false);
   const string& get_names_oid_prefix();
   const string& get_info_oid_prefix(bool old_format = false);
   const string& get_predefined_name(CephContext *cct);
@@ -1139,13 +1139,15 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
     DECODE_FINISH(bl);
   }
 
+  int read_default_id(string& default_id, bool old_format = false);
+  int set_as_default();
   int create_default(bool old_format = false);
   int equals(const string& other_zonegroup) const;
   int add_zone(const RGWZoneParams& zone_params, bool *is_master, bool *read_only, const list<string>& endpoints);
   int remove_zone(const RGWZoneParams& zone_params);
   int rename_zone(const RGWZoneParams& zone_params);
   const string& get_pool_name(CephContext *cct);
-  const string& get_default_oid(bool old_region_format = false);
+  const string get_default_oid(bool old_region_format = false);
   const string& get_info_oid_prefix(bool old_region_format = false);
   const string& get_names_oid_prefix();
   const string& get_predefined_name(CephContext *cct);
@@ -1309,7 +1311,7 @@ public:
   int create(bool exclusive = true);
   int delete_obj();
   const string& get_pool_name(CephContext *cct);
-  const string& get_default_oid(bool old_format = false);
+  const string get_default_oid(bool old_format = false);
   const string& get_names_oid_prefix();
   const string& get_info_oid_prefix(bool old_format = false);
   const string& get_predefined_name(CephContext *cct);