Commit 9104fe73 authored by Ziye Yang's avatar Ziye Yang Committed by Jim Harris
Browse files

bdev: make (v)bdev init in async manner



Change-Id: I93684a004e2ae276734edbb4767b5ba1bac3dd48
Signed-off-by: default avatarZiye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/362111


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent 6e0d1dcd
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -87,10 +87,11 @@ struct spdk_bdev_module_if {
	/**
	 * Initialization function for the module.  Called by the spdk
	 * application during startup.
	 * User must call spdk_bdev_module_init_next() with return code inside this func.
	 *
	 * Modules are required to define this function.
	 */
	int (*module_init)(void);
	void (*module_init)(void);

	/**
	 * Finish function for the module.  Called by the spdk application
@@ -381,6 +382,8 @@ void spdk_scsi_nvme_translate(const struct spdk_bdev_io *bdev_io,

void spdk_bdev_module_list_add(struct spdk_bdev_module_if *bdev_module);
void spdk_vbdev_module_list_add(struct spdk_bdev_module_if *vbdev_module);
void spdk_bdev_module_init_next(int rc);
void spdk_vbdev_module_init_next(int rc);

static inline struct spdk_bdev_io *
spdk_bdev_io_from_ctx(void *ctx)
+6 −4
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@

#include "spdk_internal/log.h"

static int blockdev_aio_initialize(void);
static void blockdev_aio_initialize(void);
static void aio_free_disk(struct file_disk *fdisk);

static int
@@ -377,7 +377,8 @@ error_return:
	return NULL;
}

static int blockdev_aio_initialize(void)
static void
blockdev_aio_initialize(void)
{
	size_t i;
	struct spdk_conf_section *sp;
@@ -385,7 +386,7 @@ static int blockdev_aio_initialize(void)

	sp = spdk_conf_find_section(NULL, "AIO");
	if (!sp) {
		return 0;
		goto end;
	}

	i = 0;
@@ -415,7 +416,8 @@ static int blockdev_aio_initialize(void)
		i++;
	}

	return 0;
end:
	spdk_bdev_module_init_next(0);
}

SPDK_LOG_REGISTER_TRACE_FLAG("aio", SPDK_TRACE_AIO)
+50 −18
Original line number Diff line number Diff line
@@ -76,6 +76,9 @@ static struct spdk_bdev_mgr g_bdev_mgr = {
	.bdevs = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.bdevs),
};

static struct spdk_bdev_module_if *g_next_bdev_module;
static struct spdk_bdev_module_if *g_next_vbdev_module;

struct spdk_bdev_mgmt_channel {
};

@@ -258,11 +261,56 @@ spdk_bdev_mgmt_channel_destroy(void *io_device, void *ctx_buf)
{
}

void
spdk_bdev_module_init_next(int rc)
{
	if (rc) {
		assert(g_next_bdev_module != NULL);
		SPDK_ERRLOG("Failed to init bdev module: %s\n", g_next_bdev_module->module_name);
		spdk_subsystem_init_next(rc);
		return;
	}

	if (!g_next_bdev_module) {
		g_next_bdev_module = TAILQ_FIRST(&g_bdev_mgr.bdev_modules);
	} else {
		g_next_bdev_module = TAILQ_NEXT(g_next_bdev_module, tailq);
	}

	if (g_next_bdev_module) {
		g_next_bdev_module->module_init();
	} else {
		spdk_vbdev_module_init_next(0);
	}
}

void
spdk_vbdev_module_init_next(int rc)
{
	if (rc) {
		assert(g_next_vbdev_module != NULL);
		SPDK_ERRLOG("Failed to init vbdev module: %s\n", g_next_vbdev_module->module_name);
		spdk_subsystem_init_next(rc);
		return;
	}

	if (!g_next_vbdev_module) {
		g_next_vbdev_module = TAILQ_FIRST(&g_bdev_mgr.vbdev_modules);
	} else {
		g_next_vbdev_module = TAILQ_NEXT(g_next_vbdev_module, tailq);
	}

	if (g_next_vbdev_module) {
		g_next_vbdev_module->module_init();
	} else {
		spdk_subsystem_init_next(0);
	}
}

static void
spdk_bdev_initialize(void)
{
	int i, cache_size;
	struct spdk_bdev_module_if *bdev_module;
	int rc = 0;

	g_bdev_mgr.bdev_io_pool = spdk_mempool_create("blockdev_io",
@@ -309,22 +357,6 @@ spdk_bdev_initialize(void)
	if (!g_bdev_mgr.buf_large_pool) {
		SPDK_ERRLOG("create rbuf large pool failed\n");
		rc = -1;
		goto end;
	}

	TAILQ_FOREACH(bdev_module, &g_bdev_mgr.bdev_modules, tailq) {
		rc = bdev_module->module_init();
		if (rc) {
			rc = -1;
			goto end;
		}
	}
	TAILQ_FOREACH(bdev_module, &g_bdev_mgr.vbdev_modules, tailq) {
		rc = bdev_module->module_init();
		if (rc) {
			rc = -1;
			goto end;
		}
	}

	spdk_io_device_register(&g_bdev_mgr, spdk_bdev_mgmt_channel_create,
@@ -332,7 +364,7 @@ spdk_bdev_initialize(void)
				sizeof(struct spdk_bdev_mgmt_channel));

end:
	spdk_subsystem_init_next(rc);
	spdk_bdev_module_init_next(rc);
}

static int
+12 −7
Original line number Diff line number Diff line
@@ -221,17 +221,17 @@ cleanup:
	return rc;
}

static int
static void
vbdev_error_init(void)
{
	struct spdk_conf_section *sp;
	const char *base_bdev_name;
	int i;
	int i, rc = 0;
	struct spdk_bdev *base_bdev;

	sp = spdk_conf_find_section(NULL, "BdevError");
	if (sp == NULL) {
		return 0;
		goto end;
	}

	for (i = 0; ; i++) {
@@ -242,20 +242,25 @@ vbdev_error_init(void)
		base_bdev_name = spdk_conf_section_get_nmval(sp, "BdevError", i, 0);
		if (!base_bdev_name) {
			SPDK_ERRLOG("ErrorInjection configuration missing blockdev name\n");
			return -1;
			rc = -1;
			goto end;
		}

		base_bdev = spdk_bdev_get_by_name(base_bdev_name);
		if (!base_bdev) {
			SPDK_ERRLOG("Could not find ErrorInjection bdev %s\n", base_bdev_name);
			return -1;
			rc = -1;
			goto end;
		}

		if (spdk_vbdev_error_create(base_bdev)) {
			return -1;
			rc = -1;
			goto end;
		}
	}
	return 0;

end:
	spdk_vbdev_module_init_next(rc);
}

static void
+10 −6
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ static struct malloc_disk *g_malloc_disk_head = NULL;

int malloc_disk_count = 0;

static int blockdev_malloc_initialize(void);
static void blockdev_malloc_initialize(void);
static void blockdev_malloc_finish(void);
static void blockdev_malloc_get_spdk_running_config(FILE *fp);

@@ -421,10 +421,10 @@ static void free_malloc_disk(struct malloc_disk *mdisk)
	spdk_dma_free(mdisk);
}

static int blockdev_malloc_initialize(void)
static void blockdev_malloc_initialize(void)
{
	struct spdk_conf_section *sp = spdk_conf_find_section(NULL, "Malloc");
	int NumberOfLuns, LunSizeInMB, BlockSize, i;
	int NumberOfLuns, LunSizeInMB, BlockSize, i, rc = 0;
	uint64_t size;
	struct spdk_bdev *bdev;

@@ -434,7 +434,8 @@ static int blockdev_malloc_initialize(void)
		BlockSize = spdk_conf_section_get_intval(sp, "BlockSize");
		if ((NumberOfLuns < 1) || (LunSizeInMB < 1)) {
			SPDK_ERRLOG("Malloc section present, but no devices specified\n");
			return EINVAL;
			rc = EINVAL;
			goto end;
		}
		if (BlockSize < 1) {
			/* Default is 512 bytes */
@@ -445,11 +446,14 @@ static int blockdev_malloc_initialize(void)
			bdev = create_malloc_disk(size / BlockSize, BlockSize);
			if (bdev == NULL) {
				SPDK_ERRLOG("Could not create malloc disk\n");
				return EINVAL;
				rc = EINVAL;
				goto end;
			}
		}
	}
	return 0;

end:
	spdk_bdev_module_init_next(rc);
}

static void blockdev_malloc_finish(void)
Loading