]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: send notifications on mirroring updates
authorJason Dillaman <dillaman@redhat.com>
Tue, 29 Mar 2016 15:42:02 +0000 (11:42 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 30 Mar 2016 21:02:02 +0000 (17:02 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/internal.cc

index d7ba808c440329f15d3fac3232ed47aaf5c004b4..23fe70f182d886c4a5cc879a56fce2dc0e02628e 100644 (file)
@@ -35,6 +35,7 @@
 #include "librbd/internal.h"
 #include "librbd/Journal.h"
 #include "librbd/journal/Types.h"
+#include "librbd/MirroringWatcher.h"
 #include "librbd/ObjectMap.h"
 #include "librbd/Operations.h"
 #include "librbd/parent_types.h"
@@ -193,7 +194,7 @@ int validate_mirroring_enabled(ImageCtx *ictx) {
       << dendl;
     return r;
   } else if (mirror_image_internal.state !=
-               cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_ENABLED) {
+               cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
     lderr(cct) << "mirroring is not currently enabled" << dendl;
     return -EINVAL;
   }
@@ -218,8 +219,7 @@ int mirror_image_enable(CephContext *cct, librados::IoCtx &io_ctx,
     return -EINVAL;
   }
 
-  mirror_image_internal.state =
-    cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_ENABLED;
+  mirror_image_internal.state = cls::rbd::MIRROR_IMAGE_STATE_ENABLED;
   if (global_image_id.empty()) {
     uuid_d uuid_gen;
     uuid_gen.generate_random();
@@ -234,6 +234,15 @@ int mirror_image_enable(CephContext *cct, librados::IoCtx &io_ctx,
     return r;
   }
 
+  r = MirroringWatcher<>::notify_image_updated(
+    io_ctx, cls::rbd::MIRROR_IMAGE_STATE_ENABLED, id,
+    mirror_image_internal.global_image_id);
+  if (r < 0) {
+    lderr(cct) << "failed to send update notification: " << cpp_strerror(r)
+               << dendl;
+    return r;
+  }
+
   ldout(cct, 20) << "image mirroring is enabled: global_id=" <<
     mirror_image_internal.global_image_id << dendl;
 
@@ -309,8 +318,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force) {
     goto remove_mirroring_image;
   }
 
-  mirror_image_internal.state =
-    cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_DISABLING;
+  mirror_image_internal.state = cls::rbd::MIRROR_IMAGE_STATE_DISABLING;
   r = cls_client::mirror_image_set(&ictx->md_ctx, ictx->id,
       mirror_image_internal);
   if (r < 0) {
@@ -318,6 +326,15 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force) {
     return r;
   }
 
+  r = MirroringWatcher<>::notify_image_updated(
+    ictx->md_ctx, cls::rbd::MIRROR_IMAGE_STATE_DISABLING,
+    ictx->id, mirror_image_internal.global_image_id);
+  if (r < 0) {
+    lderr(cct) << "failed to send update notification: " << cpp_strerror(r)
+               << dendl;
+    return r;
+  }
+
   header_oid = ::journal::Journaler::header_oid(ictx->id);
 
   while(true) {
@@ -1699,8 +1716,7 @@ remove_mirroring_image:
                 << cpp_strerror(r) << dendl;
             }
 
-            if (mirror_image.state ==
-                cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_ENABLED) {
+            if (mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
               lderr(cct) << "cannot disable journaling: image mirroring "
                 " enabled and mirror pool mode set to image" << dendl;
               return -EINVAL;
@@ -2647,7 +2663,11 @@ remove_mirroring_image:
       return -EINVAL;
     }
 
-    return mirror_image_enable_internal(ictx);
+    r = mirror_image_enable_internal(ictx);
+    if (r < 0) {
+      return r;
+    }
+    return 0;
   }
 
   int mirror_image_disable(ImageCtx *ictx, bool force) {
@@ -2668,7 +2688,11 @@ remove_mirroring_image:
       return -EINVAL;
     }
 
-    return mirror_image_disable_internal(ictx, force);
+    r = mirror_image_disable_internal(ictx, force);
+    if (r < 0) {
+      return r;
+    }
+    return 0;
   }
 
   int mirror_image_promote(ImageCtx *ictx, bool force) {
@@ -2933,6 +2957,14 @@ remove_mirroring_image:
           << cpp_strerror(r) << dendl;
         return r;
       }
+
+      r = MirroringWatcher<>::notify_mode_updated(io_ctx,
+                                                  cls::rbd::MIRROR_MODE_IMAGE);
+      if (r < 0) {
+        lderr(cct) << "failed to send update notification: " << cpp_strerror(r)
+                   << dendl;
+        return r;
+      }
     }
 
     if (next_mirror_mode == cls::rbd::MIRROR_MODE_IMAGE) {
@@ -2960,6 +2992,12 @@ remove_mirroring_image:
             lderr(cct) << "Failed to rollback mirror mode: " << cpp_strerror(r)
               << dendl;
           }
+
+          r = MirroringWatcher<>::notify_mode_updated(*io_ctx, mirror_mode);
+          if (r < 0) {
+            lderr(cct) << "failed to send update notification: "
+                       << cpp_strerror(r) << dendl;
+          }
         }
         for (const auto& pair : img_ctxs) {
           if (do_rollback && pair.second) {
@@ -3077,6 +3115,12 @@ remove_mirroring_image:
       return r;
     }
 
+    r = MirroringWatcher<>::notify_mode_updated(io_ctx, next_mirror_mode);
+    if (r < 0) {
+      lderr(cct) << "failed to send update notification: " << cpp_strerror(r)
+                 << dendl;
+      return r;
+    }
     return 0;
   }