From 3d8d9da3488d21c1a2a77636ce658dcfbbd7f999 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 16 Feb 2016 12:59:42 -0500 Subject: [PATCH] librbd: update image name upon rename operations Previously the image could not have been renamed twice without re-opening the image. Signed-off-by: Jason Dillaman --- src/librbd/ImageCtx.cc | 10 ++++++++++ src/librbd/ImageCtx.h | 2 ++ src/librbd/Operations.cc | 2 ++ src/librbd/operation/RenameRequest.cc | 17 ++++++++++++----- src/librbd/operation/RenameRequest.h | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index ea2a915ea3242..6e29292bb8dd9 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -1018,6 +1018,16 @@ struct C_InvalidateCache : public Context { return new Journal(*this); } + void ImageCtx::set_image_name(const std::string &image_name) { + // update the name so rename can be invoked repeatedly + RWLock::RLocker owner_locker(m_image_ctx.owner_lock); + RWLock::WLocker snap_locker(m_image_ctx.snap_lock); + name = image_name; + if (old_format) { + header_oid = util::old_header_name(image_name); + } + } + void ImageCtx::notify_update() { state->handle_update_notification(); diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index 3621c739a1212..caf9bdc9bec34 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -276,6 +276,8 @@ namespace librbd { void clear_pending_completions(); + void set_image_name(const std::string &name); + void notify_update(); void notify_update(Context *on_finish); }; diff --git a/src/librbd/Operations.cc b/src/librbd/Operations.cc index 34d5a09e43091..ff698c28203b1 100644 --- a/src/librbd/Operations.cc +++ b/src/librbd/Operations.cc @@ -231,6 +231,8 @@ int Operations::rename(const char *dstname) { return r; } } + + m_image_ctx.set_image_name(dstname); return 0; } diff --git a/src/librbd/operation/RenameRequest.cc b/src/librbd/operation/RenameRequest.cc index aa5e09fa155f8..3d23579af7e6f 100644 --- a/src/librbd/operation/RenameRequest.cc +++ b/src/librbd/operation/RenameRequest.cc @@ -70,8 +70,12 @@ bool RenameRequest::should_complete(int r) { return true; } + if (m_state == STATE_REMOVE_SOURCE_HEADER) { + apply(); + return true; + } + RWLock::RLocker owner_lock(image_ctx.owner_lock); - bool finished = false; switch (m_state) { case STATE_READ_SOURCE_HEADER: send_write_destination_header(); @@ -82,14 +86,11 @@ bool RenameRequest::should_complete(int r) { case STATE_UPDATE_DIRECTORY: send_remove_source_header(); break; - case STATE_REMOVE_SOURCE_HEADER: - finished = true; - break; default: assert(false); break; } - return finished; + return false; } template @@ -187,6 +188,12 @@ void RenameRequest::send_remove_source_header() { rados_completion->release(); } +template +void RenameRequest::apply() { + I &image_ctx = this->m_image_ctx; + image_ctx.set_image_name(m_dest_name); +} + } // namespace operation } // namespace librbd diff --git a/src/librbd/operation/RenameRequest.h b/src/librbd/operation/RenameRequest.h index 6b47d0781a876..c2fa14eb04d1b 100644 --- a/src/librbd/operation/RenameRequest.h +++ b/src/librbd/operation/RenameRequest.h @@ -80,6 +80,7 @@ private: void send_update_directory(); void send_remove_source_header(); + void apply(); }; } // namespace operation -- 2.39.5