Commit 4c88d56d authored by Damiano Cipriani's avatar Damiano Cipriani Committed by Tomasz Zawadzki
Browse files

blob: add shallow copy status callback



Added a callback to shallow copy function that will be repeteadly
called during operation with status updates like the number of
clusters actually copied.

Change-Id: I6f2fb94fb38e8b17636ee2b5e106cd2a44697d09
Signed-off-by: default avatarDamiano Cipriani <damiano.cipriani@suse.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/19248


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 2dbbbbd8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -150,6 +150,14 @@ typedef int (*spdk_bs_esnap_dev_create)(void *bs_ctx, void *blob_ctx, struct spd
					const void *esnap_id, uint32_t id_size,
					struct spdk_bs_dev **bs_dev);

/**
 * Blob shallow copy status callback.
 *
 * \param copied_clusters Actual number of copied clusters by the shallow copy operation
 * \param cb_arg Callback argument.
 */
typedef void (*spdk_blob_shallow_copy_status)(uint64_t copied_clusters, void *cb_arg);

struct spdk_bs_dev_cb_args {
	spdk_bs_dev_cpl		cb_fn;
	struct spdk_io_channel	*channel;
@@ -803,6 +811,8 @@ void spdk_bs_blob_decouple_parent(struct spdk_blob_store *bs, struct spdk_io_cha
 * \param channel IO channel used to copy the blob.
 * \param blobid The id of the blob.
 * \param ext_dev The device to copy on
 * \param status_cb_fn Called repeatedly during operation with status updates
 * \param status_cb_arg Argument passed to function status_cb_fn.
 * \param cb_fn Called when the operation is complete.
 * \param cb_arg Argument passed to function cb_fn.
 *
@@ -810,6 +820,7 @@ void spdk_bs_blob_decouple_parent(struct spdk_blob_store *bs, struct spdk_io_cha
 */
int spdk_bs_blob_shallow_copy(struct spdk_blob_store *bs, struct spdk_io_channel *channel,
			      spdk_blob_id blobid, struct spdk_bs_dev *ext_dev,
			      spdk_blob_shallow_copy_status status_cb_fn, void *status_cb_arg,
			      spdk_blob_op_complete cb_fn, void *cb_arg);


+16 −0
Original line number Diff line number Diff line
@@ -7150,6 +7150,15 @@ struct shallow_copy_ctx {

	/* Struct for external device writing */
	struct spdk_bs_dev_cb_args ext_args;

	/* Actual number of copied clusters */
	uint64_t copied_clusters_count;

	/* Status callback for updates about the ongoing operation */
	spdk_blob_shallow_copy_status status_cb;

	/* Argument passed to function status_cb */
	void *status_cb_arg;
};

static void
@@ -7186,6 +7195,10 @@ bs_shallow_copy_bdev_write_cpl(struct spdk_io_channel *channel, void *cb_arg, in
	}

	ctx->cluster++;
	if (ctx->status_cb) {
		ctx->copied_clusters_count++;
		ctx->status_cb(ctx->copied_clusters_count, ctx->status_cb_arg);
	}

	bs_shallow_copy_cluster_find_next(ctx);
}
@@ -7299,6 +7312,7 @@ blobstore block size\n", _blob->id);
int
spdk_bs_blob_shallow_copy(struct spdk_blob_store *bs, struct spdk_io_channel *channel,
			  spdk_blob_id blobid, struct spdk_bs_dev *ext_dev,
			  spdk_blob_shallow_copy_status status_cb_fn, void *status_cb_arg,
			  spdk_blob_op_complete cb_fn, void *cb_arg)
{
	struct shallow_copy_ctx *ctx;
@@ -7316,6 +7330,8 @@ spdk_bs_blob_shallow_copy(struct spdk_blob_store *bs, struct spdk_io_channel *ch
	ctx->cpl.u.bs_basic.cb_arg = cb_arg;
	ctx->bserrno = 0;
	ctx->blob_channel = channel;
	ctx->status_cb = status_cb_fn;
	ctx->status_cb_arg = status_cb_arg;
	ctx->read_buff = spdk_malloc(bs->cluster_sz, bs->dev->blocklen, NULL,
				     SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
	if (!ctx->read_buff) {
+15 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ char *g_xattr_names[] = {"first", "second", "third"};
char *g_xattr_values[] = {"one", "two", "three"};
uint64_t g_ctx = 1729;
bool g_use_extent_table = false;
uint64_t g_copied_clusters_count = 0;

struct spdk_bs_super_block_ver1 {
	uint8_t		signature[8];
@@ -202,6 +203,12 @@ blob_op_with_handle_complete2(void *cb_arg, struct spdk_blob *blob, int bserrno)
	}
}

static void
blob_shallow_copy_status_cb(uint64_t copied_clusters, void *cb_arg)
{
	g_copied_clusters_count = copied_clusters;
}

static void
ut_bs_reload(struct spdk_blob_store **bs, struct spdk_bs_opts *opts)
{
@@ -9369,6 +9376,7 @@ blob_shallow_copy(void)
	/* Shallow copy with a not read only blob */
	ext_dev = init_ext_dev(num_clusters * 1024 * 1024, DEV_BUFFER_BLOCKLEN);
	rc = spdk_bs_blob_shallow_copy(bs, blob_ch, blobid, ext_dev,
				       blob_shallow_copy_status_cb, NULL,
				       blob_op_complete, NULL);
	CU_ASSERT(rc == 0);
	poll_threads();
@@ -9384,6 +9392,7 @@ blob_shallow_copy(void)
	/* Shallow copy over a spdk_bs_dev with incorrect size */
	ext_dev = init_ext_dev(1, DEV_BUFFER_BLOCKLEN);
	rc = spdk_bs_blob_shallow_copy(bs, blob_ch, blobid, ext_dev,
				       blob_shallow_copy_status_cb, NULL,
				       blob_op_complete, NULL);
	CU_ASSERT(rc == 0);
	poll_threads();
@@ -9393,6 +9402,7 @@ blob_shallow_copy(void)
	/* Shallow copy over a spdk_bs_dev with incorrect block len */
	ext_dev = init_ext_dev(num_clusters * 1024 * 1024, DEV_BUFFER_BLOCKLEN * 2);
	rc = spdk_bs_blob_shallow_copy(bs, blob_ch, blobid, ext_dev,
				       blob_shallow_copy_status_cb, NULL,
				       blob_op_complete, NULL);
	CU_ASSERT(rc == 0);
	poll_threads();
@@ -9413,10 +9423,14 @@ blob_shallow_copy(void)

	/* Correct shallow copy of blob over bdev */
	rc = spdk_bs_blob_shallow_copy(bs, blob_ch, blobid, ext_dev,
				       blob_shallow_copy_status_cb, NULL,
				       blob_op_complete, NULL);
	CU_ASSERT(rc == 0);
	poll_threads();
	poll_thread_times(0, 1);
	CU_ASSERT(g_copied_clusters_count == 1);
	poll_thread_times(0, 2);
	CU_ASSERT(g_bserrno == 0);
	CU_ASSERT(g_copied_clusters_count == 2);

	/* Read from bdev */
	/* Only cluster 1 and 3 must be filled */