BUCKET_OBJECT_SHARD,
BUCKET_RESYNC_ENCRYPTED_MULTIPART,
POLICY,
- POOL_ADD,
- POOL_RM,
- POOLS_LIST,
LOG_LIST,
LOG_SHOW,
LOG_RM,
{ "bucket object shard", OPT::BUCKET_OBJECT_SHARD },
{ "bucket resync encrypted multipart", OPT::BUCKET_RESYNC_ENCRYPTED_MULTIPART },
{ "policy", OPT::POLICY },
- { "pool add", OPT::POOL_ADD },
- { "pool rm", OPT::POOL_RM },
- { "pool list", OPT::POOLS_LIST },
- { "pools list", OPT::POOLS_LIST },
{ "log list", OPT::LOG_LIST },
{ "log show", OPT::LOG_SHOW },
{ "log rm", OPT::LOG_RM },
}
}
- if (opt_cmd == OPT::POOL_ADD) {
- if (pool_name.empty()) {
- cerr << "need to specify pool to add!" << std::endl;
- exit(1);
- }
-
- int ret = static_cast<rgw::sal::RadosStore*>(driver)->svc()->zone->add_bucket_placement(dpp(), pool, null_yield);
- if (ret < 0)
- cerr << "failed to add bucket placement: " << cpp_strerror(-ret) << std::endl;
- }
-
- if (opt_cmd == OPT::POOL_RM) {
- if (pool_name.empty()) {
- cerr << "need to specify pool to remove!" << std::endl;
- exit(1);
- }
-
- int ret = static_cast<rgw::sal::RadosStore*>(driver)->svc()->zone->remove_bucket_placement(dpp(), pool, null_yield);
- if (ret < 0)
- cerr << "failed to remove bucket placement: " << cpp_strerror(-ret) << std::endl;
- }
-
- if (opt_cmd == OPT::POOLS_LIST) {
- set<rgw_pool> pools;
- int ret = static_cast<rgw::sal::RadosStore*>(driver)->svc()->zone->list_placement_set(dpp(), pools, null_yield);
- if (ret < 0) {
- cerr << "could not list placement set: " << cpp_strerror(-ret) << std::endl;
- return -ret;
- }
- formatter->reset();
- formatter->open_array_section("pools");
- for (auto siter = pools.begin(); siter != pools.end(); ++siter) {
- formatter->open_object_section("pool");
- formatter->dump_string("name", siter->to_str());
- formatter->close_section();
- }
- formatter->close_section();
- formatter->flush(cout);
- cout << std::endl;
- }
-
if (opt_cmd == OPT::USAGE_SHOW) {
uint64_t start_epoch = 0;
uint64_t end_epoch = (uint64_t)-1;
int RGWSI_Zone::select_bucket_location_by_rule(const DoutPrefixProvider *dpp, const rgw_placement_rule& location_rule, RGWZonePlacementInfo *rule_info, optional_yield y)
{
if (location_rule.name.empty()) {
- /* we can only reach here if we're trying to set a bucket location from a bucket
- * created on a different zone, using a legacy / default pool configuration
- */
- if (rule_info) {
- return select_legacy_bucket_placement(dpp, rule_info, y);
- }
-
- return 0;
+ return -EINVAL;
}
/*
rgw_placement_rule *pselected_rule, RGWZonePlacementInfo *rule_info,
optional_yield y)
{
- if (!zone_params->placement_pools.empty()) {
- return select_new_bucket_location(dpp, user_info, zonegroup_id, placement_rule,
- pselected_rule, rule_info, y);
- }
-
- if (pselected_rule) {
- pselected_rule->clear();
- }
-
- if (rule_info) {
- return select_legacy_bucket_placement(dpp, rule_info, y);
- }
-
- return 0;
-}
-
-int RGWSI_Zone::select_legacy_bucket_placement(const DoutPrefixProvider *dpp, RGWZonePlacementInfo *rule_info,
- optional_yield y)
-{
- bufferlist map_bl;
- map<string, bufferlist> m;
- string pool_name;
- bool write_map = false;
-
- rgw_raw_obj obj(zone_params->domain_root, avail_pools);
-
- auto sysobj = sysobj_svc->get_obj(obj);
- int ret = sysobj.rop().read(dpp, &map_bl, y);
- if (ret < 0) {
- goto read_omap;
- }
-
- try {
- auto iter = map_bl.cbegin();
- decode(m, iter);
- } catch (buffer::error& err) {
- ldpp_dout(dpp, 0) << "ERROR: couldn't decode avail_pools" << dendl;
- }
-
-read_omap:
- if (m.empty()) {
- ret = sysobj.omap().get_all(dpp, &m, y);
-
- write_map = true;
- }
-
- if (ret < 0 || m.empty()) {
- vector<rgw_pool> pools;
- string s = string("default.") + default_storage_pool_suffix;
- pools.push_back(rgw_pool(s));
- vector<int> retcodes;
- bufferlist bl;
- ret = rados_svc->pool().create(dpp, pools, &retcodes);
- if (ret < 0)
- return ret;
- ret = sysobj.omap().set(dpp, s, bl, y);
- if (ret < 0)
- return ret;
- m[s] = bl;
- }
-
- if (write_map) {
- bufferlist new_bl;
- encode(m, new_bl);
- ret = sysobj.wop().write(dpp, new_bl, y);
- if (ret < 0) {
- ldpp_dout(dpp, 0) << "WARNING: could not save avail pools map info ret=" << ret << dendl;
- }
- }
-
- auto miter = m.begin();
- if (m.size() > 1) {
- // choose a pool at random
- auto r = ceph::util::generate_random_number<size_t>(0, m.size() - 1);
- std::advance(miter, r);
- }
- pool_name = miter->first;
-
- rgw_pool pool = pool_name;
-
- rule_info->storage_classes.set_storage_class(RGW_STORAGE_CLASS_STANDARD, &pool, nullptr);
- rule_info->data_extra_pool = pool_name;
- rule_info->index_pool = pool_name;
- rule_info->index_type = rgw::BucketIndexType::Normal;
-
- return 0;
-}
-
-int RGWSI_Zone::update_placement_map(const DoutPrefixProvider *dpp, optional_yield y)
-{
- bufferlist header;
- map<string, bufferlist> m;
- rgw_raw_obj obj(zone_params->domain_root, avail_pools);
-
- auto sysobj = sysobj_svc->get_obj(obj);
- int ret = sysobj.omap().get_all(dpp, &m, y);
- if (ret < 0)
- return ret;
-
- bufferlist new_bl;
- encode(m, new_bl);
- ret = sysobj.wop().write(dpp, new_bl, y);
- if (ret < 0) {
- ldpp_dout(dpp, 0) << "WARNING: could not save avail pools map info ret=" << ret << dendl;
- }
-
- return ret;
-}
-
-int RGWSI_Zone::add_bucket_placement(const DoutPrefixProvider *dpp, const rgw_pool& new_pool, optional_yield y)
-{
- int ret = rados_svc->pool(new_pool).lookup();
- if (ret < 0) { // DNE, or something
- return ret;
- }
-
- rgw_raw_obj obj(zone_params->domain_root, avail_pools);
- auto sysobj = sysobj_svc->get_obj(obj);
-
- bufferlist empty_bl;
- ret = sysobj.omap().set(dpp, new_pool.to_str(), empty_bl, y);
-
- // don't care about return value
- update_placement_map(dpp, y);
-
- return ret;
-}
-
-int RGWSI_Zone::remove_bucket_placement(const DoutPrefixProvider *dpp, const rgw_pool& old_pool, optional_yield y)
-{
- rgw_raw_obj obj(zone_params->domain_root, avail_pools);
- auto sysobj = sysobj_svc->get_obj(obj);
- int ret = sysobj.omap().del(dpp, old_pool.to_str(), y);
-
- // don't care about return value
- update_placement_map(dpp, y);
-
- return ret;
-}
-
-int RGWSI_Zone::list_placement_set(const DoutPrefixProvider *dpp, set<rgw_pool>& names, optional_yield y)
-{
- bufferlist header;
- map<string, bufferlist> m;
-
- rgw_raw_obj obj(zone_params->domain_root, avail_pools);
- auto sysobj = sysobj_svc->get_obj(obj);
- int ret = sysobj.omap().get_all(dpp, &m, y);
- if (ret < 0)
- return ret;
-
- names.clear();
- map<string, bufferlist>::iterator miter;
- for (miter = m.begin(); miter != m.end(); ++miter) {
- names.insert(rgw_pool(miter->first));
+ if (zone_params->placement_pools.empty()) {
+ return -EINVAL; // legacy placement no longer supported
}
- return names.size();
+ return select_new_bucket_location(dpp, user_info, zonegroup_id, placement_rule,
+ pselected_rule, rule_info, y);
}
bool RGWSI_Zone::get_redirect_zone_endpoint(string *endpoint)
int init_zg_from_period(const DoutPrefixProvider *dpp, optional_yield y);
int init_zg_from_local(const DoutPrefixProvider *dpp, optional_yield y);
- int update_placement_map(const DoutPrefixProvider *dpp, optional_yield y);
-
int create_default_zg(const DoutPrefixProvider *dpp, optional_yield y);
int init_default_zone(const DoutPrefixProvider *dpp, optional_yield y);
int select_bucket_placement(const DoutPrefixProvider *dpp, const RGWUserInfo& user_info, const std::string& zonegroup_id,
const rgw_placement_rule& rule,
rgw_placement_rule *pselected_rule, RGWZonePlacementInfo *rule_info, optional_yield y);
- int select_legacy_bucket_placement(const DoutPrefixProvider *dpp, RGWZonePlacementInfo *rule_info, optional_yield y);
int select_new_bucket_location(const DoutPrefixProvider *dpp, const RGWUserInfo& user_info, const std::string& zonegroup_id,
const rgw_placement_rule& rule,
rgw_placement_rule *pselected_rule_name, RGWZonePlacementInfo *rule_info,
optional_yield y);
int select_bucket_location_by_rule(const DoutPrefixProvider *dpp, const rgw_placement_rule& location_rule, RGWZonePlacementInfo *rule_info, optional_yield y);
- int add_bucket_placement(const DoutPrefixProvider *dpp, const rgw_pool& new_pool, optional_yield y);
- int remove_bucket_placement(const DoutPrefixProvider *dpp, const rgw_pool& old_pool, optional_yield y);
- int list_placement_set(const DoutPrefixProvider *dpp, std::set<rgw_pool>& names, optional_yield y);
-
bool is_meta_master() const;
bool need_to_sync() const;