]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/rbd: method to set mirror snapshot copy progress
authorMykola Golub <mgolub@suse.com>
Thu, 24 Oct 2019 15:28:36 +0000 (16:28 +0100)
committerMykola Golub <mgolub@suse.com>
Tue, 10 Dec 2019 15:45:30 +0000 (15:45 +0000)
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/cls/rbd/cls_rbd.cc
src/cls/rbd/cls_rbd_client.cc
src/cls/rbd/cls_rbd_client.h
src/test/cls_rbd/test_cls_rbd.cc

index 54d0d90a358b5e8cd38bf946203fd192f7f2dc9d..a466bd7b5190acf0ae9e9155e6f1da5ff6a963e8 100644 (file)
@@ -5704,6 +5704,40 @@ int image_snapshot_unlink_peer(cls_method_context_t hctx,
   return 0;
 }
 
+int image_snapshot_set_copy_progress(cls_method_context_t hctx,
+                                     uint64_t snap_id, bool copied,
+                                     uint64_t last_copied_object_number) {
+  cls_rbd_snap snap;
+  std::string snap_key;
+  key_from_snap_id(snap_id, &snap_key);
+  int r = read_key(hctx, snap_key, &snap);
+  if (r < 0) {
+    if (r != -ENOENT) {
+      CLS_ERR("Could not read snapshot meta off disk: %s",
+              cpp_strerror(r).c_str());
+    }
+    return r;
+  }
+
+  auto non_primary = boost::get<cls::rbd::MirrorNonPrimarySnapshotNamespace>(
+    &snap.snapshot_namespace);
+  if (non_primary == nullptr) {
+    CLS_LOG(5, "mirror_image_snapshot_set_copy_progress " \
+            "not mirroring snapshot snap_id=%" PRIu64, snap_id);
+    return -EINVAL;
+  }
+
+  non_primary->copied = copied;
+  non_primary->last_copied_object_number = last_copied_object_number;
+
+  r = image::snapshot::write(hctx, snap_key, std::move(snap));
+  if (r < 0) {
+    return r;
+  }
+
+  return 0;
+}
+
 } // namespace mirror
 
 /**
@@ -6717,6 +6751,42 @@ int mirror_image_snapshot_unlink_peer(cls_method_context_t hctx, bufferlist *in,
   return 0;
 }
 
+/**
+ * Input:
+ * @param snap_id: snapshot id
+ * @param copied: true if shapshot fully copied
+ * @param last_copied_object_number: last copied object number
+ *
+ * Output:
+ * @returns 0 on success, negative error code on failure
+ */
+int mirror_image_snapshot_set_copy_progress(cls_method_context_t hctx,
+                                            bufferlist *in,
+                                            bufferlist *out) {
+  uint64_t snap_id;
+  bool copied;
+  uint64_t last_copied_object_number;
+  try {
+    auto iter = in->cbegin();
+    decode(snap_id, iter);
+    decode(copied, iter);
+    decode(last_copied_object_number, iter);
+  } catch (const buffer::error &err) {
+    return -EINVAL;
+  }
+
+  CLS_LOG(20, "mirror_image_snapshot_set_copy_progress snap_id=%" PRIu64 \
+          " copied=%d last_copied_object_number=%" PRIu64, snap_id, copied,
+          last_copied_object_number);
+
+  int r = mirror::image_snapshot_set_copy_progress(hctx, snap_id, copied,
+                                                   last_copied_object_number);
+  if (r < 0) {
+    return r;
+  }
+  return 0;
+}
+
 namespace group {
 
 /********************** methods for rbd_group_directory ***********************/
@@ -8086,6 +8156,7 @@ CLS_INIT(rbd)
   cls_method_handle_t h_mirror_image_map_update;
   cls_method_handle_t h_mirror_image_map_remove;
   cls_method_handle_t h_mirror_image_snapshot_unlink_peer;
+  cls_method_handle_t h_mirror_image_snapshot_set_copy_progress;
   cls_method_handle_t h_group_dir_list;
   cls_method_handle_t h_group_dir_add;
   cls_method_handle_t h_group_dir_remove;
@@ -8435,6 +8506,10 @@ CLS_INIT(rbd)
                           CLS_METHOD_RD | CLS_METHOD_WR,
                           mirror_image_snapshot_unlink_peer,
                           &h_mirror_image_snapshot_unlink_peer);
+  cls_register_cxx_method(h_class, "mirror_image_snapshot_set_copy_progress",
+                          CLS_METHOD_RD | CLS_METHOD_WR,
+                          mirror_image_snapshot_set_copy_progress,
+                          &h_mirror_image_snapshot_set_copy_progress);
 
   /* methods for the groups feature */
   cls_register_cxx_method(h_class, "group_dir_list",
index 03312d2f630c091100ba7390428b4ef1845a9875..892b089d1dfddc21c168412f6df27cc28ee150b7 100644 (file)
@@ -2464,6 +2464,26 @@ int mirror_image_snapshot_unlink_peer(librados::IoCtx *ioctx,
   return ioctx->operate(oid, &op);
 }
 
+void mirror_image_snapshot_set_copy_progress(librados::ObjectWriteOperation *op,
+                                             snapid_t snap_id, bool copied,
+                                             uint64_t copy_progress) {
+  bufferlist bl;
+  encode(snap_id, bl);
+  encode(copied, bl);
+  encode(copy_progress, bl);
+
+  op->exec("rbd", "mirror_image_snapshot_set_copy_progress", bl);
+}
+
+int mirror_image_snapshot_set_copy_progress(librados::IoCtx *ioctx,
+                                            const std::string &oid,
+                                            snapid_t snap_id, bool copied,
+                                            uint64_t copy_progress) {
+  librados::ObjectWriteOperation op;
+  mirror_image_snapshot_set_copy_progress(&op, snap_id, copied, copy_progress);
+  return ioctx->operate(oid, &op);
+}
+
 // Groups functions
 int group_dir_list(librados::IoCtx *ioctx, const std::string &oid,
                    const std::string &start, uint64_t max_return,
index fcb0ebc862ec326285a941cd889b9266b4370d57..fea8b27a070b28c0e11d7bf4a5accc665472b3f9 100644 (file)
@@ -526,6 +526,14 @@ int mirror_image_snapshot_unlink_peer(librados::IoCtx *ioctx,
                                       const std::string &oid,
                                       snapid_t snap_id,
                                       const std::string &mirror_peer_uuid);
+void mirror_image_snapshot_set_copy_progress(librados::ObjectWriteOperation *op,
+                                             snapid_t snap_id, bool copied,
+                                             uint64_t copy_progress);
+int mirror_image_snapshot_set_copy_progress(librados::IoCtx *ioctx,
+                                            const std::string &oid,
+                                            snapid_t snap_id, bool copied,
+                                            uint64_t copy_progress);
+
 // Groups functions
 int group_dir_list(librados::IoCtx *ioctx, const std::string &oid,
                    const std::string &start, uint64_t max_return,
index 42522cfbb135cde4ff758aebf44f680d30e405ff..1d77a9be6955a5690d3c4570a3d8163d77f16191 100644 (file)
@@ -2282,6 +2282,15 @@ TEST_F(TestClsRbd, mirror_snapshot) {
   ASSERT_FALSE(nsn->copied);
   ASSERT_EQ(nsn->last_copied_object_number, 0);
 
+  ASSERT_EQ(0, mirror_image_snapshot_set_copy_progress(&ioctx, oid, 2, true,
+                                                       10));
+  ASSERT_EQ(0, snapshot_get(&ioctx, oid, 2, &snap));
+  nsn = boost::get<cls::rbd::MirrorNonPrimarySnapshotNamespace>(
+    &snap.snapshot_namespace);
+  ASSERT_NE(nullptr, nsn);
+  ASSERT_TRUE(nsn->copied);
+  ASSERT_EQ(nsn->last_copied_object_number, 10);
+
   ASSERT_EQ(0, snapshot_remove(&ioctx, oid, 1));
   ASSERT_EQ(0, snapshot_remove(&ioctx, oid, 2));
 }