From 8225af6cc1f2a4d93d82afcb2f174d1cd2ac8912 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 27 Feb 2019 14:08:04 -0500 Subject: [PATCH] librbd: create state machine uses new validate pool state machine Fixes: http://tracker.ceph.com/issues/38500 Signed-off-by: Jason Dillaman (cherry picked from commit 6a84ca3f24421a5150ae32e7ff380f4121d32b13) Conflicts: src/librbd/image/CreateRequest.cc: trivial resolution --- src/librbd/image/CreateRequest.cc | 73 ++++--------------------------- 1 file changed, 9 insertions(+), 64 deletions(-) diff --git a/src/librbd/image/CreateRequest.cc b/src/librbd/image/CreateRequest.cc index b4e25e08425e8..60d65033a164a 100644 --- a/src/librbd/image/CreateRequest.cc +++ b/src/librbd/image/CreateRequest.cc @@ -10,12 +10,14 @@ #include "common/ceph_context.h" #include "librbd/Journal.h" #include "librbd/MirroringWatcher.h" +#include "librbd/image/ValidatePoolRequest.h" #include "librbd/journal/CreateRequest.h" #include "librbd/journal/RemoveRequest.h" #include "librbd/mirror/EnableRequest.h" #include "librbd/io/AioCompletion.h" #include "journal/Journaler.h" + #define dout_subsys ceph_subsys_rbd #undef dout_prefix #define dout_prefix *_dout << "librbd::image::CreateRequest: " << __func__ \ @@ -261,80 +263,23 @@ void CreateRequest::validate_data_pool() { ldout(m_cct, 20) << dendl; - using klass = CreateRequest; - librados::AioCompletion *comp = - create_rados_callback(this); - - librados::ObjectReadOperation op; - op.read(0, 0, nullptr, nullptr); - - m_outbl.clear(); - int r = m_data_io_ctx.aio_operate(RBD_INFO, comp, &op, &m_outbl); - assert(r == 0); - comp->release(); + auto ctx = create_context_callback< + CreateRequest, &CreateRequest::handle_validate_data_pool>(this); + auto req = ValidatePoolRequest::create(m_data_io_ctx, m_op_work_queue, + ctx); + req->send(); } template void CreateRequest::handle_validate_data_pool(int r) { ldout(m_cct, 20) << "r=" << r << dendl; - bufferlist bl; - bl.append("overwrite validated"); - - if (r >= 0 && m_outbl.contents_equal(bl)) { - create_id_object(); - return; - } else if ((r < 0) && (r != -ENOENT)) { - lderr(m_cct) << "failed to read RBD info: " << cpp_strerror(r) << dendl; - complete(r); - return; - } - - // allocate a self-managed snapshot id if this a new pool to force - // self-managed snapshot mode - // This call is executed just once per (fresh) pool, hence we do not - // try hard to make it asynchronous (and it's pretty safe not to cause - // deadlocks). - - ldout(m_cct, 10) << "validating self-managed RBD snapshot support" << dendl; - - uint64_t snap_id; - r = m_data_io_ctx.selfmanaged_snap_create(&snap_id); if (r == -EINVAL) { - lderr(m_cct) << "pool not configured for self-managed RBD snapshot support" - << dendl; + lderr(m_cct) << "pool does not support RBD images" << dendl; complete(r); return; } else if (r < 0) { - lderr(m_cct) << "failed to allocate self-managed snapshot: " - << cpp_strerror(r) << dendl; - complete(r); - return; - } - - r = m_data_io_ctx.selfmanaged_snap_remove(snap_id); - if (r < 0) { - // we've already switched to self-managed snapshots -- no need to - // error out in case of failure here. - ldout(m_cct, 10) << "failed to release self-managed snapshot " << snap_id - << ": " << cpp_strerror(r) << dendl; - } - - ldout(m_cct, 10) << "validating overwrite support" << dendl; - - bufferlist initial_bl; - initial_bl.append("validate"); - r = m_data_io_ctx.write(RBD_INFO, initial_bl, initial_bl.length(), 0); - if (r >= 0) { - r = m_data_io_ctx.write(RBD_INFO, bl, bl.length(), 0); - } - if (r == -EOPNOTSUPP) { - lderr(m_cct) << "pool missing required overwrite support" << dendl; - complete(-EINVAL); - return; - } else if (r < 0) { - lderr(m_cct) << "failed to validate overwrite support: " << cpp_strerror(r) - << dendl; + lderr(m_cct) << "failed to validate pool: " << cpp_strerror(r) << dendl; complete(r); return; } -- 2.39.5