Commit 2356d1d6 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev: Add helper functions to allocate/free bdev_get_iostat_ctx



Add helper functions, bdev_iostat_ctx_alloc() and bdev_iostat_ctx_free()
for the bdev_get_iostat RPC.

The following patches will allocate spdk_bdev_io_stat dynamically for
bdev_get_iostat_ctx.

This is a preparation for that.

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: Ib71d6fb92d8134d2282507e62874f19045b630b7
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15442


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 7c687dfc
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -214,6 +214,18 @@ rpc_get_iostat_done(struct rpc_get_iostat_ctx *rpc_ctx)
	free(rpc_ctx);
}

static struct bdev_get_iostat_ctx *
bdev_iostat_ctx_alloc(void)
{
	return calloc(1, sizeof(struct bdev_get_iostat_ctx));
}

static void
bdev_iostat_ctx_free(struct bdev_get_iostat_ctx *ctx)
{
	free(ctx);
}

static void
bdev_get_iostat_dump(struct spdk_json_write_ctx *w, struct spdk_bdev_io_stat *stat)
{
@@ -272,7 +284,7 @@ done:
	rpc_get_iostat_done(rpc_ctx);

	spdk_bdev_close(bdev_ctx->desc);
	free(bdev_ctx);
	bdev_iostat_ctx_free(bdev_ctx);
}

static int
@@ -282,7 +294,7 @@ bdev_get_iostat(void *ctx, struct spdk_bdev *bdev)
	struct bdev_get_iostat_ctx *bdev_ctx;
	int rc;

	bdev_ctx = calloc(1, sizeof(struct bdev_get_iostat_ctx));
	bdev_ctx = bdev_iostat_ctx_alloc();
	if (bdev_ctx == NULL) {
		SPDK_ERRLOG("Failed to allocate bdev_iostat_ctx struct\n");
		return -ENOMEM;
@@ -291,7 +303,7 @@ bdev_get_iostat(void *ctx, struct spdk_bdev *bdev)
	rc = spdk_bdev_open_ext(spdk_bdev_get_name(bdev), false, dummy_bdev_event_cb, NULL,
				&bdev_ctx->desc);
	if (rc != 0) {
		free(bdev_ctx);
		bdev_iostat_ctx_free(bdev_ctx);
		SPDK_ERRLOG("Failed to open bdev\n");
		return rc;
	}
@@ -312,7 +324,7 @@ bdev_get_per_channel_stat_done(struct spdk_bdev *bdev, void *ctx, int status)

	spdk_bdev_close(bdev_ctx->desc);

	free(bdev_ctx);
	bdev_iostat_ctx_free(bdev_ctx);
}

static void
@@ -406,7 +418,7 @@ rpc_bdev_get_iostat(struct spdk_jsonrpc_request *request,
	rpc_ctx->per_channel = req.per_channel;

	if (desc != NULL) {
		bdev_ctx = calloc(1, sizeof(struct bdev_get_iostat_ctx));
		bdev_ctx = bdev_iostat_ctx_alloc();
		if (bdev_ctx == NULL) {
			SPDK_ERRLOG("Failed to allocate bdev_iostat_ctx struct\n");
			rpc_ctx->rc = -ENOMEM;