Commit 43c5293e authored by yidong0635's avatar yidong0635 Committed by Tomasz Zawadzki
Browse files

xnvme: Fix memory leak for xnvme dev.



If we use dd or bdevperf to run the xnvme bdev.
the destruct function of xnvme misses to free
dev while destructing bdev_xnvme.

xnvme_dev_close does free dev, and we can put it
in bdev_xnvme_free.

Meanwhile fixing cleanup for delete_xnvme_bdev.

This rpc for delete_xnvme_bdev doesn't really cleanup
to remove the bdev from the list and  free the names.

Fixes issue: #2654

Signed-off-by: default avataryidong0635 <dongx.yi@intel.com>
Change-Id: I1c493cb8130b012d891ba8ee90cd0bfb127207d4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14177


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 53ec23ca
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -199,6 +199,7 @@ bdev_xnvme_free(struct bdev_xnvme *xnvme)
{
	assert(xnvme != NULL);

	xnvme_dev_close(xnvme->dev);
	free(xnvme->filename);
	free(xnvme->bdev.name);
	free(xnvme);
@@ -363,13 +364,12 @@ create_xnvme_bdev(const char *name, const char *filename, const char *io_mechani
	return &xnvme->bdev;

error_return:
	xnvme_dev_close(xnvme->dev);

	bdev_xnvme_free(xnvme);
	return NULL;
}

struct delete_xnvme_bdev_ctx {
	struct bdev_xnvme *xnvme;
	spdk_delete_xnvme_complete cb_fn;
	void *cb_arg;
};
@@ -379,6 +379,7 @@ xnvme_bdev_unregister_cb(void *arg, int bdeverrno)
{
	struct delete_xnvme_bdev_ctx *ctx = arg;

	bdev_xnvme_destruct(ctx->xnvme);
	ctx->cb_fn(ctx->cb_arg, bdeverrno);
	free(ctx);
}
@@ -400,10 +401,10 @@ delete_xnvme_bdev(struct spdk_bdev *bdev, spdk_delete_xnvme_complete cb_fn, void
		return;
	}

	ctx->xnvme = xnvme;
	ctx->cb_fn = cb_fn;
	ctx->cb_arg = cb_arg;
	spdk_bdev_unregister(bdev, xnvme_bdev_unregister_cb, ctx);
	xnvme_dev_close(xnvme->dev);
}

static int