]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/rbd: prevent image_status when mirror image is not created
authorArthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
Thu, 22 Jul 2021 14:37:47 +0000 (16:37 +0200)
committerArthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
Wed, 12 Jan 2022 09:03:38 +0000 (10:03 +0100)
This prevent image_status_set to succeed when there is no mirror image
yet. This solves some stale entries that were not removed in
rbd-mirror and prevent to add entries that would not be visible from the
rbd cli.

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
(cherry picked from commit 416e25794af0252ec45b35c897c8cf2e91aca383)

src/cls/rbd/cls_rbd.cc

index 15a13a1b1b4234a2921c4e1804be8499e063babf..dfa06907bc199f7e1ff045a5b668c59d9ed54e07 100644 (file)
@@ -5049,7 +5049,22 @@ int image_status_set(cls_method_context_t hctx, const string &global_image_id,
   ondisk_status.up = false;
   ondisk_status.last_update = ceph_clock_now();
 
-  int r = cls_get_request_origin(hctx, &ondisk_status.origin);
+  std::string global_id_key = global_key(global_image_id);
+  std::string image_id;
+  int r = read_key(hctx, global_id_key, &image_id);
+  if (r < 0) {
+    return 0;
+  }
+  cls::rbd::MirrorImage mirror_image;
+  r = image_get(hctx, image_id, &mirror_image);
+  if (r < 0) {
+    return 0;
+  }
+  if (mirror_image.state != cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
+    return 0;
+  }
+
+  r = cls_get_request_origin(hctx, &ondisk_status.origin);
   ceph_assert(r == 0);
 
   bufferlist bl;