Commit 227e7bdc authored by GangCao's avatar GangCao Committed by Jim Harris
Browse files

bdev: introduce two channel create/destroy internal functions



This patch adds two internal functions for the channel
create and destroy.

Change-Id: I3c5ca7a0633e5a5b3f95a36ed03f2b4cb4792e4f
Signed-off-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-on: https://review.gerrithub.io/395677


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatar <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 9aed854b
Loading
Loading
Loading
Loading
+48 −32
Original line number Diff line number Diff line
@@ -869,49 +869,21 @@ spdk_bdev_dump_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w
	return 0;
}

static void
_spdk_bdev_channel_destroy_resource(struct spdk_bdev_channel *ch)
{
	struct spdk_bdev_mgmt_channel	*mgmt_channel;
	struct spdk_bdev_module_channel	*shared_ch = ch->module_ch;

	if (ch->channel) {
		spdk_put_io_channel(ch->channel);
	}

	if (ch->mgmt_channel) {
		if (shared_ch) {
			assert(shared_ch->ref > 0);
			shared_ch->ref--;
			if (shared_ch->ref == 0) {
				mgmt_channel = spdk_io_channel_get_ctx(ch->mgmt_channel);
				assert(shared_ch->io_outstanding == 0);
				TAILQ_REMOVE(&mgmt_channel->module_channels, shared_ch, link);
				free(shared_ch);
			}
		}
		spdk_put_io_channel(ch->mgmt_channel);
	}
}

static int
spdk_bdev_channel_create(void *io_device, void *ctx_buf)
_spdk_bdev_channel_create(struct spdk_bdev_channel *ch, void *io_device)
{
	struct spdk_bdev		*bdev = io_device;
	struct spdk_bdev_channel	*ch = ctx_buf;
	struct spdk_bdev_mgmt_channel	*mgmt_ch;
	struct spdk_bdev_module_channel	*shared_ch;

	ch->bdev = io_device;
	ch->channel = bdev->fn_table->get_io_channel(bdev->ctxt);
	if (!ch->channel) {
		_spdk_bdev_channel_destroy_resource(ch);
		return -1;
	}

	ch->mgmt_channel = spdk_get_io_channel(&g_bdev_mgr);
	if (!ch->mgmt_channel) {
		_spdk_bdev_channel_destroy_resource(ch);
		return -1;
	}

@@ -926,7 +898,6 @@ spdk_bdev_channel_create(void *io_device, void *ctx_buf)
	if (shared_ch == NULL) {
		shared_ch = calloc(1, sizeof(*shared_ch));
		if (!shared_ch) {
			_spdk_bdev_channel_destroy_resource(ch);
			return -1;
		}

@@ -943,6 +914,44 @@ spdk_bdev_channel_create(void *io_device, void *ctx_buf)
	ch->flags = 0;
	ch->module_ch = shared_ch;

	return 0;
}

static void
_spdk_bdev_channel_destroy_resource(struct spdk_bdev_channel *ch)
{
	struct spdk_bdev_mgmt_channel	*mgmt_channel;
	struct spdk_bdev_module_channel	*shared_ch = ch->module_ch;

	if (ch->channel) {
		spdk_put_io_channel(ch->channel);
	}

	if (ch->mgmt_channel) {
		if (shared_ch) {
			assert(shared_ch->ref > 0);
			shared_ch->ref--;
			if (shared_ch->ref == 0) {
				mgmt_channel = spdk_io_channel_get_ctx(ch->mgmt_channel);
				assert(shared_ch->io_outstanding == 0);
				TAILQ_REMOVE(&mgmt_channel->module_channels, shared_ch, link);
				free(shared_ch);
			}
		}
		spdk_put_io_channel(ch->mgmt_channel);
	}
}

static int
spdk_bdev_channel_create(void *io_device, void *ctx_buf)
{
	struct spdk_bdev_channel	*ch = ctx_buf;

	if (_spdk_bdev_channel_create(ch, io_device) != 0) {
		_spdk_bdev_channel_destroy_resource(ch);
		return -1;
	}

#ifdef SPDK_CONFIG_VTUNE
	{
		char *name;
@@ -1014,9 +1023,8 @@ _spdk_bdev_abort_queued_io(bdev_io_tailq_t *queue, struct spdk_bdev_channel *ch)
}

static void
spdk_bdev_channel_destroy(void *io_device, void *ctx_buf)
_spdk_bdev_channel_destroy(struct spdk_bdev_channel *ch)
{
	struct spdk_bdev_channel	*ch = ctx_buf;
	struct spdk_bdev_mgmt_channel	*mgmt_channel;
	struct spdk_bdev_module_channel	*shared_ch = ch->module_ch;

@@ -1030,6 +1038,14 @@ spdk_bdev_channel_destroy(void *io_device, void *ctx_buf)
	_spdk_bdev_channel_destroy_resource(ch);
}

static void
spdk_bdev_channel_destroy(void *io_device, void *ctx_buf)
{
	struct spdk_bdev_channel	*ch = ctx_buf;

	_spdk_bdev_channel_destroy(ch);
}

int
spdk_bdev_alias_add(struct spdk_bdev *bdev, const char *alias)
{