Skip to content

Commit

Permalink
rgw: move all pool creation into rgw_init_ioctx
Browse files Browse the repository at this point in the history
the pool_create/application_enable logic was duplicated in three places,
and only one of them was reporting the error on ERANGE

Fixes: http://tracker.ceph.com/issues/23480

Signed-off-by: Casey Bodley <cbodley@redhat.com>
  • Loading branch information
cbodley committed Apr 19, 2018
1 parent a4778e9 commit 85d608f
Showing 1 changed file with 13 additions and 46 deletions.
59 changes: 13 additions & 46 deletions src/rgw/rgw_rados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ int rgw_init_ioctx(librados::Rados *rados, const rgw_pool& pool, IoCtx& ioctx, b
int r = rados->ioctx_create(pool.name.c_str(), ioctx);
if (r == -ENOENT && create) {
r = rados->pool_create(pool.name.c_str());
if (r == -ERANGE) {
ldout(cct, 0)
<< __func__
<< " ERROR: librados::Rados::pool_create returned " << cpp_strerror(-r)
<< " (this can be due to a pool or placement group misconfiguration, e.g."
<< " pg_num < pgp_num or mon_max_pg_per_osd exceeded)"
<< dendl;
}
if (r < 0 && r != -EEXIST) {
return r;
}
Expand Down Expand Up @@ -4878,28 +4886,10 @@ void RGWRados::pick_control_oid(const string& key, string& notify_oid)
notify_oid.append(buf);
}

int RGWRados::open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx)
int RGWRados::open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx)
{
librados::Rados *rad = get_rados_handle();
int r = rgw_init_ioctx(rad, pool, io_ctx);
if (r != -ENOENT)
return r;

if (!pools_initialized)
return r;

r = rad->pool_create(pool.name.c_str());
if (r < 0 && r != -EEXIST)
return r;

r = rgw_init_ioctx(rad, pool, io_ctx);
if (r < 0)
return r;

r = io_ctx.application_enable(pg_pool_t::APPLICATION_NAME_RGW, false);
if (r < 0 && r != -EOPNOTSUPP)
return r;
return 0;
constexpr bool create = true; // create the pool if it doesn't exist
return rgw_init_ioctx(get_rados_handle(), pool, io_ctx, create);
}

void RGWRados::build_bucket_index_marker(const string& shard_id_str, const string& shard_marker,
Expand Down Expand Up @@ -5936,32 +5926,9 @@ int RGWRados::Bucket::List::list_objects_unordered(int64_t max,
*/
int RGWRados::create_pool(const rgw_pool& pool)
{
int ret = 0;

librados::Rados *rad = get_rados_handle();
ret = rad->pool_create(pool.name.c_str(), 0);
if (ret == -EEXIST)
ret = 0;
else if (ret == -ERANGE) {
ldout(cct, 0)
<< __func__
<< " ERROR: librados::Rados::pool_create returned " << cpp_strerror(-ret)
<< " (this can be due to a pool or placement group misconfiguration, e.g."
<< " pg_num < pgp_num or mon_max_pg_per_osd exceeded)"
<< dendl;
}
if (ret < 0)
return ret;

librados::IoCtx io_ctx;
ret = rad->ioctx_create(pool.name.c_str(), io_ctx);
if (ret < 0)
return ret;

ret = io_ctx.application_enable(pg_pool_t::APPLICATION_NAME_RGW, false);
if (ret < 0 && ret != -EOPNOTSUPP)
return ret;
return 0;
constexpr bool create = true;
return rgw_init_ioctx(get_rados_handle(), pool, io_ctx, create);
}

int RGWRados::init_bucket_index(RGWBucketInfo& bucket_info, int num_shards)
Expand Down

0 comments on commit 85d608f

Please sign in to comment.