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: GangCao <gang.cao@intel.com>
Reviewed-on: https://review.gerrithub.io/395677
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
GangCao 2018-01-21 18:03:27 -05:00 committed by Jim Harris
parent 9aed854be0
commit 227e7bdcf2

View File

@ -869,6 +869,54 @@ spdk_bdev_dump_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w
return 0;
}
static int
_spdk_bdev_channel_create(struct spdk_bdev_channel *ch, void *io_device)
{
struct spdk_bdev *bdev = io_device;
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) {
return -1;
}
ch->mgmt_channel = spdk_get_io_channel(&g_bdev_mgr);
if (!ch->mgmt_channel) {
return -1;
}
mgmt_ch = spdk_io_channel_get_ctx(ch->mgmt_channel);
TAILQ_FOREACH(shared_ch, &mgmt_ch->module_channels, link) {
if (shared_ch->module_ch == ch->channel) {
shared_ch->ref++;
break;
}
}
if (shared_ch == NULL) {
shared_ch = calloc(1, sizeof(*shared_ch));
if (!shared_ch) {
return -1;
}
shared_ch->io_outstanding = 0;
TAILQ_INIT(&shared_ch->nomem_io);
shared_ch->nomem_threshold = 0;
shared_ch->module_ch = ch->channel;
shared_ch->ref = 1;
TAILQ_INSERT_TAIL(&mgmt_ch->module_channels, shared_ch, link);
}
memset(&ch->stat, 0, sizeof(ch->stat));
TAILQ_INIT(&ch->queued_resets);
ch->flags = 0;
ch->module_ch = shared_ch;
return 0;
}
static void
_spdk_bdev_channel_destroy_resource(struct spdk_bdev_channel *ch)
{
@ -897,52 +945,13 @@ _spdk_bdev_channel_destroy_resource(struct spdk_bdev_channel *ch)
static int
spdk_bdev_channel_create(void *io_device, void *ctx_buf)
{
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) {
if (_spdk_bdev_channel_create(ch, io_device) != 0) {
_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;
}
mgmt_ch = spdk_io_channel_get_ctx(ch->mgmt_channel);
TAILQ_FOREACH(shared_ch, &mgmt_ch->module_channels, link) {
if (shared_ch->module_ch == ch->channel) {
shared_ch->ref++;
break;
}
}
if (shared_ch == NULL) {
shared_ch = calloc(1, sizeof(*shared_ch));
if (!shared_ch) {
_spdk_bdev_channel_destroy_resource(ch);
return -1;
}
shared_ch->io_outstanding = 0;
TAILQ_INIT(&shared_ch->nomem_io);
shared_ch->nomem_threshold = 0;
shared_ch->module_ch = ch->channel;
shared_ch->ref = 1;
TAILQ_INSERT_TAIL(&mgmt_ch->module_channels, shared_ch, link);
}
memset(&ch->stat, 0, sizeof(ch->stat));
TAILQ_INIT(&ch->queued_resets);
ch->flags = 0;
ch->module_ch = shared_ch;
#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)
{