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
/**
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 ***********************/
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;
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",
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,
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,
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));
}