From: Jason Dillaman Date: Tue, 16 Feb 2016 17:59:42 +0000 (-0500) Subject: librbd: update image name upon rename operations X-Git-Tag: v10.1.0~357^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3d8d9da3488d21c1a2a77636ce658dcfbbd7f999;p=ceph.git 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 --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index ea2a915ea324..6e29292bb8dd 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 3621c739a121..caf9bdc9bec3 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 34d5a09e4309..ff698c28203b 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 aa5e09fa155f..3d23579af7e6 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 6b47d0781a87..c2fa14eb04d1 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