From: Yehuda Sadeh Date: Mon, 27 Jan 2020 21:52:09 +0000 (-0800) Subject: rgw: move a few basic types into rgw_basic_types.{h,cc} X-Git-Tag: v15.1.0~22^2~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d6cafc35aedf25f66c771d0910731a11783f3071;p=ceph.git rgw: move a few basic types into rgw_basic_types.{h,cc} To help with the fight against circular dependencies Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_basic_types.cc b/src/rgw/rgw_basic_types.cc index fbeb88d6f746c..01cca48c2185c 100644 --- a/src/rgw/rgw_basic_types.cc +++ b/src/rgw/rgw_basic_types.cc @@ -5,6 +5,8 @@ #include #include +#include "cls/user/cls_user_types.h" + #include "rgw_basic_types.h" #include "rgw_xml.h" #include "common/ceph_json.h" @@ -27,6 +29,68 @@ void encode_xml(const char *name, const rgw_user& val, Formatter *f) encode_xml(name, val.to_str(), f); } +rgw_bucket::rgw_bucket(const rgw_user& u, const cls_user_bucket& b) : + tenant(u.tenant), + name(b.name), + marker(b.marker), + bucket_id(b.bucket_id), + explicit_placement(b.explicit_placement.data_pool, + b.explicit_placement.data_extra_pool, + b.explicit_placement.index_pool) +{ +} + +void rgw_bucket::convert(cls_user_bucket *b) const +{ + b->name = name; + b->marker = marker; + b->bucket_id = bucket_id; + b->explicit_placement.data_pool = explicit_placement.data_pool.to_str(); + b->explicit_placement.data_extra_pool = explicit_placement.data_extra_pool.to_str(); + b->explicit_placement.index_pool = explicit_placement.index_pool.to_str(); +} + +std::string rgw_bucket::get_key(char tenant_delim, char id_delim, size_t reserve) const +{ + const size_t max_len = tenant.size() + sizeof(tenant_delim) + + name.size() + sizeof(id_delim) + bucket_id.size() + reserve; + + std::string key; + key.reserve(max_len); + if (!tenant.empty() && tenant_delim) { + key.append(tenant); + key.append(1, tenant_delim); + } + key.append(name); + if (!bucket_id.empty() && id_delim) { + key.append(1, id_delim); + key.append(bucket_id); + } + return key; +} + +std::string rgw_bucket_shard::get_key(char tenant_delim, char id_delim, + char shard_delim) const +{ + static constexpr size_t shard_len{12}; // ":4294967295\0" + auto key = bucket.get_key(tenant_delim, id_delim, shard_len); + if (shard_id >= 0 && shard_delim) { + key.append(1, shard_delim); + key.append(std::to_string(shard_id)); + } + return key; +} + +void encode_json_impl(const char *name, const rgw_zone_id& zid, Formatter *f) +{ + encode_json(name, zid.id, f); +} + +void decode_json_obj(rgw_zone_id& zid, JSONObj *obj) +{ + decode_json_obj(zid.id, obj); +} + namespace rgw { namespace auth { ostream& operator <<(ostream& m, const Principal& p) { diff --git a/src/rgw/rgw_basic_types.h b/src/rgw/rgw_basic_types.h index e0a3458d0a57c..0ba03bd0e27f8 100644 --- a/src/rgw/rgw_basic_types.h +++ b/src/rgw/rgw_basic_types.h @@ -8,6 +8,9 @@ #include "include/types.h" +class JSONObj; +class cls_user_bucket; + struct rgw_user { std::string tenant; std::string id; @@ -108,6 +111,372 @@ struct rgw_user { }; WRITE_CLASS_ENCODER(rgw_user) +struct rgw_pool { + std::string name; + std::string ns; + + rgw_pool() = default; + rgw_pool(const rgw_pool& _p) : name(_p.name), ns(_p.ns) {} + rgw_pool(rgw_pool&&) = default; + rgw_pool(const string& _s) { + from_str(_s); + } + rgw_pool(const string& _name, const string& _ns) : name(_name), ns(_ns) {} + + string to_str() const; + void from_str(const string& s); + + void init(const string& _s) { + from_str(_s); + } + + bool empty() const { + return name.empty(); + } + + int compare(const rgw_pool& p) const { + int r = name.compare(p.name); + if (r != 0) { + return r; + } + return ns.compare(p.ns); + } + + void encode(bufferlist& bl) const { + ENCODE_START(10, 10, bl); + encode(name, bl); + encode(ns, bl); + ENCODE_FINISH(bl); + } + + void decode_from_bucket(bufferlist::const_iterator& bl); + + void decode(bufferlist::const_iterator& bl) { + DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl); + + decode(name, bl); + + if (struct_v < 10) { + + /* + * note that rgw_pool can be used where rgw_bucket was used before + * therefore we inherit rgw_bucket's old versions. However, we only + * need the first field from rgw_bucket. unless we add more fields + * in which case we'll need to look at struct_v, and check the actual + * version. Anything older than 10 needs to be treated as old rgw_bucket + */ + + } else { + decode(ns, bl); + } + + DECODE_FINISH(bl); + } + + rgw_pool& operator=(const rgw_pool&) = default; + + bool operator==(const rgw_pool& p) const { + return (compare(p) == 0); + } + bool operator!=(const rgw_pool& p) const { + return !(*this == p); + } + bool operator<(const rgw_pool& p) const { + int r = name.compare(p.name); + if (r == 0) { + return (ns.compare(p.ns) < 0); + } + return (r < 0); + } +}; +WRITE_CLASS_ENCODER(rgw_pool) + +inline ostream& operator<<(ostream& out, const rgw_pool& p) { + out << p.to_str(); + return out; +} + +struct rgw_data_placement_target { + rgw_pool data_pool; + rgw_pool data_extra_pool; + rgw_pool index_pool; + + rgw_data_placement_target() = default; + rgw_data_placement_target(const rgw_data_placement_target&) = default; + rgw_data_placement_target(rgw_data_placement_target&&) = default; + + rgw_data_placement_target(const rgw_pool& data_pool, + const rgw_pool& data_extra_pool, + const rgw_pool& index_pool) + : data_pool(data_pool), + data_extra_pool(data_extra_pool), + index_pool(index_pool) { + } + + rgw_data_placement_target& + operator=(const rgw_data_placement_target&) = default; + + const rgw_pool& get_data_extra_pool() const { + if (data_extra_pool.empty()) { + return data_pool; + } + return data_extra_pool; + } + + int compare(const rgw_data_placement_target& t) { + int c = data_pool.compare(t.data_pool); + if (c != 0) { + return c; + } + c = data_extra_pool.compare(t.data_extra_pool); + if (c != 0) { + return c; + } + return index_pool.compare(t.index_pool); + }; + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; + +struct rgw_bucket_key { + std::string tenant; + std::string name; + std::string bucket_id; + + rgw_bucket_key(const std::string& _tenant, + const std::string& _name, + const std::string& _bucket_id) : tenant(_tenant), + name(_name), + bucket_id(_bucket_id) {} + rgw_bucket_key(const std::string& _tenant, + const std::string& _name) : tenant(_tenant), + name(_name) {} +}; + +struct rgw_bucket { + std::string tenant; + std::string name; + std::string marker; + std::string bucket_id; + rgw_data_placement_target explicit_placement; + + rgw_bucket() { } + // cppcheck-suppress noExplicitConstructor + explicit rgw_bucket(const rgw_user& u, const cls_user_bucket& b); + + rgw_bucket(const rgw_bucket_key& bk) : tenant(bk.tenant), + name(bk.name), + bucket_id(bk.bucket_id) {} + rgw_bucket(const rgw_bucket&) = default; + rgw_bucket(rgw_bucket&&) = default; + + bool match(const rgw_bucket& b) const { + return (tenant == b.tenant && + name == b.name && + (bucket_id == b.bucket_id || + bucket_id.empty() || + b.bucket_id.empty())); + } + + void convert(cls_user_bucket *b) const; + + void encode(bufferlist& bl) const { + ENCODE_START(10, 10, bl); + encode(name, bl); + encode(marker, bl); + encode(bucket_id, bl); + encode(tenant, bl); + bool encode_explicit = !explicit_placement.data_pool.empty(); + encode(encode_explicit, bl); + if (encode_explicit) { + encode(explicit_placement.data_pool, bl); + encode(explicit_placement.data_extra_pool, bl); + encode(explicit_placement.index_pool, bl); + } + ENCODE_FINISH(bl); + } + void decode(bufferlist::const_iterator& bl) { + DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl); + decode(name, bl); + if (struct_v < 10) { + decode(explicit_placement.data_pool.name, bl); + } + if (struct_v >= 2) { + decode(marker, bl); + if (struct_v <= 3) { + uint64_t id; + decode(id, bl); + char buf[16]; + snprintf(buf, sizeof(buf), "%" PRIu64, id); + bucket_id = buf; + } else { + decode(bucket_id, bl); + } + } + if (struct_v < 10) { + if (struct_v >= 5) { + decode(explicit_placement.index_pool.name, bl); + } else { + explicit_placement.index_pool = explicit_placement.data_pool; + } + if (struct_v >= 7) { + decode(explicit_placement.data_extra_pool.name, bl); + } + } + if (struct_v >= 8) { + decode(tenant, bl); + } + if (struct_v >= 10) { + bool decode_explicit = !explicit_placement.data_pool.empty(); + decode(decode_explicit, bl); + if (decode_explicit) { + decode(explicit_placement.data_pool, bl); + decode(explicit_placement.data_extra_pool, bl); + decode(explicit_placement.index_pool, bl); + } + } + DECODE_FINISH(bl); + } + + void update_bucket_id(const string& new_bucket_id) { + bucket_id = new_bucket_id; + } + + // format a key for the bucket/instance. pass delim=0 to skip a field + std::string get_key(char tenant_delim = '/', + char id_delim = ':', + size_t reserve = 0) const; + + const rgw_pool& get_data_extra_pool() const { + return explicit_placement.get_data_extra_pool(); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); + static void generate_test_instances(list& o); + + rgw_bucket& operator=(const rgw_bucket&) = default; + + bool operator<(const rgw_bucket& b) const { + if (name < b.name) { + return true; + } else if (name > b.name) { + return false; + } + + if (bucket_id < b.bucket_id) { + return true; + } else if (bucket_id > b.bucket_id) { + return false; + } + + return (tenant < b.tenant); + } + + bool operator==(const rgw_bucket& b) const { + return (tenant == b.tenant) && (name == b.name) && \ + (bucket_id == b.bucket_id); + } + bool operator!=(const rgw_bucket& b) const { + return (tenant != b.tenant) || (name != b.name) || + (bucket_id != b.bucket_id); + } +}; +WRITE_CLASS_ENCODER(rgw_bucket) + +inline ostream& operator<<(ostream& out, const rgw_bucket &b) { + out << b.tenant << ":" << b.name << "[" << b.bucket_id << "])"; + return out; +} + +struct rgw_bucket_shard { + rgw_bucket bucket; + int shard_id; + + rgw_bucket_shard() : shard_id(-1) {} + rgw_bucket_shard(const rgw_bucket& _b, int _sid) : bucket(_b), shard_id(_sid) {} + + std::string get_key(char tenant_delim = '/', char id_delim = ':', + char shard_delim = ':') const; + + bool operator<(const rgw_bucket_shard& b) const { + if (bucket < b.bucket) { + return true; + } + if (b.bucket < bucket) { + return false; + } + return shard_id < b.shard_id; + } + + bool operator==(const rgw_bucket_shard& b) const { + return (bucket == b.bucket && + shard_id == b.shard_id); + } +}; + +inline ostream& operator<<(ostream& out, const rgw_bucket_shard& bs) { + if (bs.shard_id <= 0) { + return out << bs.bucket; + } + + return out << bs.bucket << ":" << bs.shard_id; +} + + +struct rgw_zone_id { + string id; + + rgw_zone_id() {} + rgw_zone_id(const string& _id) : id(_id) {} + rgw_zone_id(string&& _id) : id(std::move(_id)) {} + + void encode(bufferlist& bl) const { + /* backward compatiblity, not using ENCODE_{START,END} macros */ + ceph::encode(id, bl); + } + + void decode(bufferlist::const_iterator& bl) { + /* backward compatiblity, not using DECODE_{START,END} macros */ + ceph::decode(id, bl); + } + + void clear() { + id.clear(); + } + + bool operator==(const string& _id) const { + return (id == _id); + } + bool operator==(const rgw_zone_id& zid) const { + return (id == zid.id); + } + bool operator!=(const rgw_zone_id& zid) const { + return (id != zid.id); + } + bool operator<(const rgw_zone_id& zid) const { + return (id < zid.id); + } + bool operator>(const rgw_zone_id& zid) const { + return (id > zid.id); + } + + bool empty() const { + return id.empty(); + } +}; +WRITE_CLASS_ENCODER(rgw_zone_id) + +static inline ostream& operator<<(ostream& os, const rgw_zone_id& zid) { + os << zid.id; + return os; +} + +void encode_json_impl(const char *name, const rgw_zone_id& zid, Formatter *f); +void decode_json_obj(rgw_zone_id& zid, JSONObj *obj); + + // Represents an identity. This is more wide-ranging than a // 'User'. Its purposes is to be matched against by an // IdentityApplier. The internal representation will doubtless change as diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 34063bfff68e4..5288ee72841d7 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -1873,37 +1873,6 @@ void rgw_raw_obj::decode_from_rgw_obj(bufferlist::const_iterator& bl) pool = old_obj.get_explicit_data_pool(); } -std::string rgw_bucket::get_key(char tenant_delim, char id_delim, size_t reserve) const -{ - const size_t max_len = tenant.size() + sizeof(tenant_delim) + - name.size() + sizeof(id_delim) + bucket_id.size() + reserve; - - std::string key; - key.reserve(max_len); - if (!tenant.empty() && tenant_delim) { - key.append(tenant); - key.append(1, tenant_delim); - } - key.append(name); - if (!bucket_id.empty() && id_delim) { - key.append(1, id_delim); - key.append(bucket_id); - } - return key; -} - -std::string rgw_bucket_shard::get_key(char tenant_delim, char id_delim, - char shard_delim) const -{ - static constexpr size_t shard_len{12}; // ":4294967295\0" - auto key = bucket.get_key(tenant_delim, id_delim, shard_len); - if (shard_id >= 0 && shard_delim) { - key.append(1, shard_delim); - key.append(std::to_string(shard_id)); - } - return key; -} - static struct rgw_name_to_flag op_type_mapping[] = { {"*", RGW_OP_TYPE_ALL}, {"read", RGW_OP_TYPE_READ}, {"write", RGW_OP_TYPE_WRITE}, @@ -2145,13 +2114,3 @@ bool RGWBucketInfo::empty_sync_policy() const return sync_policy->empty(); } -void encode_json_impl(const char *name, const rgw_zone_id& zid, Formatter *f) -{ - encode_json(name, zid.id, f); -} - -void decode_json_obj(rgw_zone_id& zid, JSONObj *obj) -{ - decode_json_obj(zid.id, obj); -} - diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index fbc2db26ab45e..9627b70155a3e 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -47,7 +47,6 @@ namespace rgw::sal { using ceph::crypto::MD5; - #define RGW_ATTR_PREFIX "user.rgw." #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_" @@ -940,134 +939,6 @@ struct RGWUserInfo }; WRITE_CLASS_ENCODER(RGWUserInfo) -struct rgw_pool { - std::string name; - std::string ns; - - rgw_pool() = default; - rgw_pool(const rgw_pool& _p) : name(_p.name), ns(_p.ns) {} - rgw_pool(rgw_pool&&) = default; - rgw_pool(const string& _s) { - from_str(_s); - } - rgw_pool(const string& _name, const string& _ns) : name(_name), ns(_ns) {} - - string to_str() const; - void from_str(const string& s); - - void init(const string& _s) { - from_str(_s); - } - - bool empty() const { - return name.empty(); - } - - int compare(const rgw_pool& p) const { - int r = name.compare(p.name); - if (r != 0) { - return r; - } - return ns.compare(p.ns); - } - - void encode(bufferlist& bl) const { - ENCODE_START(10, 10, bl); - encode(name, bl); - encode(ns, bl); - ENCODE_FINISH(bl); - } - - void decode_from_bucket(bufferlist::const_iterator& bl); - - void decode(bufferlist::const_iterator& bl) { - DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl); - - decode(name, bl); - - if (struct_v < 10) { - - /* - * note that rgw_pool can be used where rgw_bucket was used before - * therefore we inherit rgw_bucket's old versions. However, we only - * need the first field from rgw_bucket. unless we add more fields - * in which case we'll need to look at struct_v, and check the actual - * version. Anything older than 10 needs to be treated as old rgw_bucket - */ - - } else { - decode(ns, bl); - } - - DECODE_FINISH(bl); - } - - rgw_pool& operator=(const rgw_pool&) = default; - - bool operator==(const rgw_pool& p) const { - return (compare(p) == 0); - } - bool operator!=(const rgw_pool& p) const { - return !(*this == p); - } - bool operator<(const rgw_pool& p) const { - int r = name.compare(p.name); - if (r == 0) { - return (ns.compare(p.ns) < 0); - } - return (r < 0); - } -}; -WRITE_CLASS_ENCODER(rgw_pool) - -struct rgw_data_placement_target { - rgw_pool data_pool; - rgw_pool data_extra_pool; - rgw_pool index_pool; - - rgw_data_placement_target() = default; - rgw_data_placement_target(const rgw_data_placement_target&) = default; - rgw_data_placement_target(rgw_data_placement_target&&) = default; - - rgw_data_placement_target(const rgw_pool& data_pool, - const rgw_pool& data_extra_pool, - const rgw_pool& index_pool) - : data_pool(data_pool), - data_extra_pool(data_extra_pool), - index_pool(index_pool) { - } - - rgw_data_placement_target& - operator=(const rgw_data_placement_target&) = default; - - const rgw_pool& get_data_extra_pool() const { - if (data_extra_pool.empty()) { - return data_pool; - } - return data_extra_pool; - } - - int compare(const rgw_data_placement_target& t) { - int c = data_pool.compare(t.data_pool); - if (c != 0) { - return c; - } - c = data_extra_pool.compare(t.data_extra_pool); - if (c != 0) { - return c; - } - return index_pool.compare(t.index_pool); - }; - - void dump(Formatter *f) const; - void decode_json(JSONObj *obj); -}; - -inline ostream& operator<<(ostream& out, const rgw_pool& p) { - out << p.to_str(); - return out; -} - struct rgw_raw_obj { rgw_pool pool; std::string oid; @@ -1143,204 +1014,6 @@ inline ostream& operator<<(ostream& out, const rgw_raw_obj& o) { return out; } -struct rgw_bucket_key { - std::string tenant; - std::string name; - std::string bucket_id; - - rgw_bucket_key(const std::string& _tenant, - const std::string& _name, - const std::string& _bucket_id) : tenant(_tenant), - name(_name), - bucket_id(_bucket_id) {} - rgw_bucket_key(const std::string& _tenant, - const std::string& _name) : tenant(_tenant), - name(_name) {} -}; - -struct rgw_bucket { - std::string tenant; - std::string name; - std::string marker; - std::string bucket_id; - rgw_data_placement_target explicit_placement; - - rgw_bucket() { } - // cppcheck-suppress noExplicitConstructor - explicit rgw_bucket(const rgw_user& u, const cls_user_bucket& b) : - tenant(u.tenant), - name(b.name), - marker(b.marker), - bucket_id(b.bucket_id), - explicit_placement(b.explicit_placement.data_pool, - b.explicit_placement.data_extra_pool, - b.explicit_placement.index_pool) {} - rgw_bucket(const rgw_bucket_key& bk) : tenant(bk.tenant), - name(bk.name), - bucket_id(bk.bucket_id) {} - rgw_bucket(const rgw_bucket&) = default; - rgw_bucket(rgw_bucket&&) = default; - - bool match(const rgw_bucket& b) const { - return (tenant == b.tenant && - name == b.name && - (bucket_id == b.bucket_id || - bucket_id.empty() || - b.bucket_id.empty())); - } - - void convert(cls_user_bucket *b) const { - b->name = name; - b->marker = marker; - b->bucket_id = bucket_id; - b->explicit_placement.data_pool = explicit_placement.data_pool.to_str(); - b->explicit_placement.data_extra_pool = explicit_placement.data_extra_pool.to_str(); - b->explicit_placement.index_pool = explicit_placement.index_pool.to_str(); - } - - void encode(bufferlist& bl) const { - ENCODE_START(10, 10, bl); - encode(name, bl); - encode(marker, bl); - encode(bucket_id, bl); - encode(tenant, bl); - bool encode_explicit = !explicit_placement.data_pool.empty(); - encode(encode_explicit, bl); - if (encode_explicit) { - encode(explicit_placement.data_pool, bl); - encode(explicit_placement.data_extra_pool, bl); - encode(explicit_placement.index_pool, bl); - } - ENCODE_FINISH(bl); - } - void decode(bufferlist::const_iterator& bl) { - DECODE_START_LEGACY_COMPAT_LEN(10, 3, 3, bl); - decode(name, bl); - if (struct_v < 10) { - decode(explicit_placement.data_pool.name, bl); - } - if (struct_v >= 2) { - decode(marker, bl); - if (struct_v <= 3) { - uint64_t id; - decode(id, bl); - char buf[16]; - snprintf(buf, sizeof(buf), "%" PRIu64, id); - bucket_id = buf; - } else { - decode(bucket_id, bl); - } - } - if (struct_v < 10) { - if (struct_v >= 5) { - decode(explicit_placement.index_pool.name, bl); - } else { - explicit_placement.index_pool = explicit_placement.data_pool; - } - if (struct_v >= 7) { - decode(explicit_placement.data_extra_pool.name, bl); - } - } - if (struct_v >= 8) { - decode(tenant, bl); - } - if (struct_v >= 10) { - bool decode_explicit = !explicit_placement.data_pool.empty(); - decode(decode_explicit, bl); - if (decode_explicit) { - decode(explicit_placement.data_pool, bl); - decode(explicit_placement.data_extra_pool, bl); - decode(explicit_placement.index_pool, bl); - } - } - DECODE_FINISH(bl); - } - - void update_bucket_id(const string& new_bucket_id) { - bucket_id = new_bucket_id; - } - - // format a key for the bucket/instance. pass delim=0 to skip a field - std::string get_key(char tenant_delim = '/', - char id_delim = ':', - size_t reserve = 0) const; - - const rgw_pool& get_data_extra_pool() const { - return explicit_placement.get_data_extra_pool(); - } - - void dump(Formatter *f) const; - void decode_json(JSONObj *obj); - static void generate_test_instances(list& o); - - rgw_bucket& operator=(const rgw_bucket&) = default; - - bool operator<(const rgw_bucket& b) const { - if (name < b.name) { - return true; - } else if (name > b.name) { - return false; - } - - if (bucket_id < b.bucket_id) { - return true; - } else if (bucket_id > b.bucket_id) { - return false; - } - - return (tenant < b.tenant); - } - - bool operator==(const rgw_bucket& b) const { - return (tenant == b.tenant) && (name == b.name) && \ - (bucket_id == b.bucket_id); - } - bool operator!=(const rgw_bucket& b) const { - return (tenant != b.tenant) || (name != b.name) || - (bucket_id != b.bucket_id); - } -}; -WRITE_CLASS_ENCODER(rgw_bucket) - -inline ostream& operator<<(ostream& out, const rgw_bucket &b) { - out << b.tenant << ":" << b.name << "[" << b.bucket_id << "])"; - return out; -} - -struct rgw_bucket_shard { - rgw_bucket bucket; - int shard_id; - - rgw_bucket_shard() : shard_id(-1) {} - rgw_bucket_shard(const rgw_bucket& _b, int _sid) : bucket(_b), shard_id(_sid) {} - - std::string get_key(char tenant_delim = '/', char id_delim = ':', - char shard_delim = ':') const; - - bool operator<(const rgw_bucket_shard& b) const { - if (bucket < b.bucket) { - return true; - } - if (b.bucket < bucket) { - return false; - } - return shard_id < b.shard_id; - } - - bool operator==(const rgw_bucket_shard& b) const { - return (bucket == b.bucket && - shard_id == b.shard_id); - } -}; - -inline ostream& operator<<(ostream& out, const rgw_bucket_shard& bs) { - if (bs.shard_id <= 0) { - return out << bs.bucket; - } - - return out << bs.bucket << ":" << bs.shard_id; -} - struct rgw_bucket_placement { rgw_placement_rule placement_rule; rgw_bucket bucket; @@ -2743,70 +2416,4 @@ int decode_bl(bufferlist& bl, T& t) return 0; } -/* - * should avoid encoding rgw_opt_zone_nid, and rgw_zone_nid, - * these should be used for run time representation of zone, - * but internally we should keep zone ids - */ -struct rgw_opt_zone_nid { - std::optional id; - std::optional name; -}; - -struct rgw_zone_nid { - string id; - string name; -}; - -struct rgw_zone_id { - string id; - - rgw_zone_id() {} - rgw_zone_id(const string& _id) : id(_id) {} - rgw_zone_id(string&& _id) : id(std::move(_id)) {} - - void encode(bufferlist& bl) const { - /* backward compatiblity, not using ENCODE_{START,END} macros */ - ceph::encode(id, bl); - } - - void decode(bufferlist::const_iterator& bl) { - /* backward compatiblity, not using DECODE_{START,END} macros */ - ceph::decode(id, bl); - } - - void clear() { - id.clear(); - } - - bool operator==(const string& _id) const { - return (id == _id); - } - bool operator==(const rgw_zone_id& zid) const { - return (id == zid.id); - } - bool operator!=(const rgw_zone_id& zid) const { - return (id != zid.id); - } - bool operator<(const rgw_zone_id& zid) const { - return (id < zid.id); - } - bool operator>(const rgw_zone_id& zid) const { - return (id > zid.id); - } - - bool empty() const { - return id.empty(); - } -}; -WRITE_CLASS_ENCODER(rgw_zone_id) - -static inline ostream& operator<<(ostream& os, const rgw_zone_id& zid) { - os << zid.id; - return os; -} - -void encode_json_impl(const char *name, const rgw_zone_id& zid, Formatter *f); -void decode_json_obj(rgw_zone_id& zid, JSONObj *obj); - #endif