#define dout_subsys ceph_subsys_rgw
-static int init_ioctx(CephContext *cct, librados::Rados *rados, const rgw_pool& pool, librados::IoCtx& ioctx, bool create)
-{
- 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;
- }
-
- r = rados->ioctx_create(pool.name.c_str(), ioctx);
- if (r < 0) {
- return r;
- }
-
- r = ioctx.application_enable(pg_pool_t::APPLICATION_NAME_RGW, false);
- if (r < 0 && r != -EOPNOTSUPP) {
- return r;
- }
- } else if (r < 0) {
- return r;
- }
- if (!pool.ns.empty()) {
- ioctx.set_namespace(pool.ns);
- }
- return 0;
-}
-
int RGWSI_RADOS::do_start()
{
- auto handles = std::vector<librados::Rados>{static_cast<size_t>(cct->_conf->rgw_num_rados_handles)};
-
- for (auto& r : handles) {
- int ret = r.init_with_context(cct);
- if (ret < 0) {
- return ret;
- }
- ret = r.connect();
- if (ret < 0) {
- return ret;
- }
+ int ret = rados.init_with_context(cct);
+ if (ret < 0) {
+ return ret;
+ }
+ ret = rados.connect();
+ if (ret < 0) {
+ return ret;
}
- std::swap(handles, rados);
return 0;
}
-librados::Rados* RGWSI_RADOS::get_rados_handle(int rados_handle)
+librados::Rados* RGWSI_RADOS::get_rados_handle()
{
- if (rados.size() == 1) {
- return &rados[0];
- }
-
- if (rados_handle >= 0) {
- if (rados_handle >= (int)rados.size()) {
- rados_handle = 0;
- }
- return &rados[rados_handle];
- }
-
- handle_lock.get_read();
- pthread_t id = pthread_self();
- std::map<pthread_t, int>:: iterator it = rados_map.find(id);
-
- if (it != rados_map.end()) {
- handle_lock.put_read();
- return &rados[it->second];
- }
- handle_lock.put_read();
- handle_lock.get_write();
- const uint32_t handle = next_rados_handle;
- rados_map[id] = handle;
- if (++next_rados_handle == rados.size()) {
- next_rados_handle = 0;
- }
- handle_lock.put_write();
- return &rados[handle];
+ return &rados;
}
uint64_t RGWSI_RADOS::instance_id()
{
- return get_rados_handle(-1)->get_instance_id();
+ return get_rados_handle()->get_instance_id();
}
-int RGWSI_RADOS::open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx, int rados_handle)
+int RGWSI_RADOS::open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx)
{
constexpr bool create = true; // create the pool if it doesn't exist
- return init_ioctx(cct, get_rados_handle(rados_handle), pool, io_ctx, create);
+ return rgw_init_ioctx(get_rados_handle(), pool, io_ctx, create);
}
int RGWSI_RADOS::pool_iterate(librados::IoCtx& io_ctx,
int RGWSI_RADOS::Obj::open()
{
- int r = rados_svc->open_pool_ctx(ref.obj.pool, ref.ioctx, rados_handle);
+ int r = rados_svc->open_pool_ctx(ref.obj.pool, ref.ioctx);
if (r < 0) {
return r;
}
int RGWSI_RADOS::Pool::create()
{
- librados::Rados *rad = rados_svc->get_rados_handle(rados_handle);
+ librados::Rados *rad = rados_svc->get_rados_handle();
int r = rad->pool_create(pool.name.c_str());
if (r < 0) {
ldout(rados_svc->cct, 0) << "WARNING: pool_create returned " << r << dendl;
vector<librados::PoolAsyncCompletion *> completions;
vector<int> rets;
- librados::Rados *rad = rados_svc->get_rados_handle(rados_handle);
+ librados::Rados *rad = rados_svc->get_rados_handle();
for (auto iter = pools.begin(); iter != pools.end(); ++iter) {
librados::PoolAsyncCompletion *c = librados::Rados::pool_async_create_completion();
completions.push_back(c);
int RGWSI_RADOS::Pool::lookup()
{
- librados::Rados *rad = rados_svc->get_rados_handle(rados_handle);
+ librados::Rados *rad = rados_svc->get_rados_handle();
int ret = rad->pool_lookup(pool.name.c_str());
if (ret < 0) {
return ret;
return -EINVAL;
}
- int r = pool.rados_svc->open_pool_ctx(pool.pool, ctx.ioctx, pool.rados_handle);
+ int r = pool.rados_svc->open_pool_ctx(pool.pool, ctx.ioctx);
if (r < 0) {
return r;
}
int RGWSI_RADOS::Handle::watch_flush()
{
- librados::Rados *rad = rados_svc->get_rados_handle(rados_handle);
+ librados::Rados *rad = rados_svc->get_rados_handle();
return rad->watch_flush();
}
-