]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: update image name upon rename operations
authorJason Dillaman <dillaman@redhat.com>
Tue, 16 Feb 2016 17:59:42 +0000 (12:59 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 18 Feb 2016 20:45:51 +0000 (15:45 -0500)
Previously the image could not have been renamed twice without
re-opening the image.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/librbd/Operations.cc
src/librbd/operation/RenameRequest.cc
src/librbd/operation/RenameRequest.h

index ea2a915ea324287a4b6f39806889d88b32026a51..6e29292bb8dd911858e7e979ca6ade3ffb09dcf9 100644 (file)
@@ -1018,6 +1018,16 @@ struct C_InvalidateCache : public Context {
     return new Journal<ImageCtx>(*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();
 
index 3621c739a12125ed94d2eaccd47e8679d86f759a..caf9bdc9bec340910ba9c628e549cc439f472359 100644 (file)
@@ -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);
   };
index 34d5a09e4309139693efced7635b812ed0f7c8e1..ff698c28203b1547c0f1dcaef1e153cbe0ef62fb 100644 (file)
@@ -231,6 +231,8 @@ int Operations<I>::rename(const char *dstname) {
       return r;
     }
   }
+
+  m_image_ctx.set_image_name(dstname);
   return 0;
 }
 
index aa5e09fa155f8fdf97374ee3e54df8eb434afee1..3d23579af7e6f41a7e19e8e8a505021402330759 100644 (file)
@@ -70,8 +70,12 @@ bool RenameRequest<I>::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<I>::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 <typename I>
@@ -187,6 +188,12 @@ void RenameRequest<I>::send_remove_source_header() {
   rados_completion->release();
 }
 
+template <typename I>
+void RenameRequest<I>::apply() {
+  I &image_ctx = this->m_image_ctx;
+  image_ctx.set_image_name(m_dest_name);
+}
+
 } // namespace operation
 } // namespace librbd
 
index 6b47d0781a876949d2a0c82a1ca3b4fce05a7805..c2fa14eb04d1b69905474631c38d330995e0f60b 100644 (file)
@@ -80,6 +80,7 @@ private:
   void send_update_directory();
   void send_remove_source_header();
 
+  void apply();
 };
 
 } // namespace operation