From: Orit Wasserman Date: Mon, 26 Oct 2015 16:59:12 +0000 (+0100) Subject: rgw: add RGWRegionMap for backward compatability X-Git-Tag: v10.1.0~354^2~282 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ac6dcc7809da08ff920e6f5d6144f060e23a2e0d;p=ceph.git rgw: add RGWRegionMap for backward compatability Signed-off-by: Orit Wasserman --- diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index f743c2af3025..f13828b5c757 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -962,6 +962,22 @@ void RGWPeriodConfig::decode_json(JSONObj *obj) JSONDecoder::decode_json("user_quota", user_quota, obj); } +void RGWRegionMap::dump(Formatter *f) const +{ + encode_json("regions", regions, f); + encode_json("master_region", master_region, f); + encode_json("bucket_quota", bucket_quota, f); + encode_json("user_quota", user_quota, f); +} + +void RGWRegionMap::decode_json(JSONObj *obj) +{ + JSONDecoder::decode_json("regions", regions, obj); + JSONDecoder::decode_json("master_region", master_region, obj); + JSONDecoder::decode_json("bucket_quota", bucket_quota, obj); + JSONDecoder::decode_json("user_quota", user_quota, obj); +} + void RGWZoneGroupMap::dump(Formatter *f) const { encode_json("zonegroups", zonegroups, f); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 14070df94883..5d30877b9e49 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1361,7 +1361,6 @@ int RGWPeriodMap::update(const RGWZoneGroup& zonegroup) return 0; } - int RGWZoneGroupMap::read(CephContext *cct, RGWRados *store) { RGWPeriod period; @@ -1379,7 +1378,27 @@ int RGWZoneGroupMap::read(CephContext *cct, RGWRados *store) { return 0; } - + +void RGWRegionMap::encode(bufferlist& bl) const { + ENCODE_START( 3, 1, bl); + ::encode(regions, bl); + ::encode(master_region, bl); + ::encode(bucket_quota, bl); + ::encode(user_quota, bl); + ENCODE_FINISH(bl); +} + +void RGWRegionMap::decode(bufferlist::iterator& bl) { + DECODE_START(3, bl); + ::decode(regions, bl); + ::decode(master_region, bl); + if (struct_v >= 2) + ::decode(bucket_quota, bl); + if (struct_v >= 3) + ::decode(user_quota, bl); + DECODE_FINISH(bl); +} + void RGWZoneGroupMap::encode(bufferlist& bl) const { ENCODE_START( 3, 1, bl); ::encode(zonegroups, bl); @@ -2950,6 +2969,7 @@ int RGWRados::convert_regionmap() */ int RGWRados::replace_region_with_zonegroup() { + /* copy default region */ /* convert default region to default zonegroup */ string default_oid = cct->_conf->rgw_default_region_info_oid; @@ -2977,7 +2997,6 @@ int RGWRados::replace_region_with_zonegroup() lderr(cct) << "failed to list regions: ret "<< ret << " " << cpp_strerror(-ret) << dendl; return ret; } - list::iterator iter; /* create zonegroups */ for (iter = regions.begin(); iter != regions.end(); ++iter) diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index f2c58e0a2875..adf9a1031cc3 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1199,6 +1199,23 @@ struct RGWPeriodConfig WRITE_CLASS_ENCODER(RGWPeriodConfig) /* for backward comaptability */ +struct RGWRegionMap { + + map regions; + + string master_region; + + RGWQuotaInfo bucket_quota; + RGWQuotaInfo user_quota; + + void encode(bufferlist& bl) const; + void decode(bufferlist::iterator& bl); + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; +WRITE_CLASS_ENCODER(RGWRegionMap) + struct RGWZoneGroupMap { map zonegroups; diff --git a/src/rgw/rgw_rest_config.cc b/src/rgw/rgw_rest_config.cc index 0c25e0c6ca21..321125624f85 100644 --- a/src/rgw/rgw_rest_config.cc +++ b/src/rgw/rgw_rest_config.cc @@ -24,7 +24,7 @@ #define dout_subsys ceph_subsys_rgw void RGWOp_ZoneGroupMap_Get::execute() { - http_ret = zone_group_map.read(g_ceph_context, store); + http_ret = zonegroup_map.read(g_ceph_context, store); if (http_ret < 0) { dout(5) << "failed to read zone_group map" << dendl; } @@ -37,7 +37,27 @@ void RGWOp_ZoneGroupMap_Get::send_response() { if (http_ret < 0) return; - - encode_json("region-map", zone_group_map, s->formatter); - flusher.flush(); + + if (old_format) { + RGWRegionMap region_map; + region_map.regions = zonegroup_map.zonegroups; + region_map.master_region = zonegroup_map.master_zonegroup; + region_map.bucket_quota = zonegroup_map.bucket_quota; + region_map.user_quota = zonegroup_map.user_quota; + encode_json("region-map", region_map, s->formatter); + } else { + encode_json("zonegroup-map", zonegroup_map, s->formatter); + } + flusher.flush(); +} + +RGWOp* RGWHandler_Config::op_get() { + bool exists; + string type = s->info.args.get("type", &exists); + + if (type.compare("zonegroup-map") == 0) { + return new RGWOp_ZoneGroupMap_Get(false); + } else { + return new RGWOp_ZoneGroupMap_Get(true); + } } diff --git a/src/rgw/rgw_rest_config.h b/src/rgw/rgw_rest_config.h index 8b22d240b214..d4be7c0a6c89 100644 --- a/src/rgw/rgw_rest_config.h +++ b/src/rgw/rgw_rest_config.h @@ -15,9 +15,10 @@ #define CEPH_RGW_REST_CONFIG_H class RGWOp_ZoneGroupMap_Get : public RGWRESTOp { - RGWZoneGroupMap zone_group_map; + RGWZoneGroupMap zonegroup_map; + bool old_format; public: - RGWOp_ZoneGroupMap_Get() {} + RGWOp_ZoneGroupMap_Get(bool _old_format) : old_format(_old_format) {} ~RGWOp_ZoneGroupMap_Get() {} int verify_permission() { @@ -26,13 +27,17 @@ public: void execute(); virtual void send_response(); virtual const string name() { - return "get_region_map"; + if (old_format) { + return "get_region_map"; + } else { + return "get_zonegroup_map"; + } } }; class RGWHandler_Config : public RGWHandler_Auth_S3 { protected: - RGWOp *op_get() { return new RGWOp_ZoneGroupMap_Get; } + RGWOp *op_get(); int read_permissions(RGWOp*) { return 0;