From: Mykola Golub Date: Thu, 24 Oct 2019 15:28:36 +0000 (+0100) Subject: cls/rbd: method to set mirror snapshot copy progress X-Git-Tag: v15.1.0~565^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a27fa5fb51ff11dde39ea77a00428c4120162160;p=ceph.git cls/rbd: method to set mirror snapshot copy progress Signed-off-by: Mykola Golub --- diff --git a/src/cls/rbd/cls_rbd.cc b/src/cls/rbd/cls_rbd.cc index 54d0d90a358b..a466bd7b5190 100644 --- a/src/cls/rbd/cls_rbd.cc +++ b/src/cls/rbd/cls_rbd.cc @@ -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( + &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", diff --git a/src/cls/rbd/cls_rbd_client.cc b/src/cls/rbd/cls_rbd_client.cc index 03312d2f630c..892b089d1dfd 100644 --- a/src/cls/rbd/cls_rbd_client.cc +++ b/src/cls/rbd/cls_rbd_client.cc @@ -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, diff --git a/src/cls/rbd/cls_rbd_client.h b/src/cls/rbd/cls_rbd_client.h index fcb0ebc862ec..fea8b27a070b 100644 --- a/src/cls/rbd/cls_rbd_client.h +++ b/src/cls/rbd/cls_rbd_client.h @@ -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, diff --git a/src/test/cls_rbd/test_cls_rbd.cc b/src/test/cls_rbd/test_cls_rbd.cc index 42522cfbb135..1d77a9be6955 100644 --- a/src/test/cls_rbd/test_cls_rbd.cc +++ b/src/test/cls_rbd/test_cls_rbd.cc @@ -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( + &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)); }