Commit cd7064c7 authored by Nathan Claudel's avatar Nathan Claudel Committed by Tomasz Zawadzki
Browse files

bdev_ut: store initialization order of the examine claim test modules



The test `examine_claimed` relies on the examine order of bdev modules.

However, bdev modules are registered using GCC constructors, which don't
provide any guarantee on the order of execution. As a consequence, the
test can result in a segfault if the order is not the one expected by
the test.

To fix this issue, implement the init functions of the `examine_claimed`
modules so that their relative order in the modules list is known by the
test. With this change, no change to the actual test is required.

This can be simply tested by altering the order of
`SPDK_BDEV_MODULE_REGISTER` occurences in the test file.

Change-Id: I129ec3cb48f3053ae7cace459d4de73dacf88d2d
Signed-off-by: default avatarNathan Claudel <nathan.claudel@kalrayinc.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23635


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 9ccef490
Loading
Loading
Loading
Loading
+38 −4
Original line number Diff line number Diff line
@@ -7209,6 +7209,8 @@ claim_v1_existing_v2(void)
	free_bdev(bdev);
}

static int ut_examine_claimed_init0(void);
static int ut_examine_claimed_init1(void);
static void ut_examine_claimed_config0(struct spdk_bdev *bdev);
static void ut_examine_claimed_disk0(struct spdk_bdev *bdev);
static void ut_examine_claimed_config1(struct spdk_bdev *bdev);
@@ -7218,14 +7220,14 @@ static void ut_examine_claimed_disk1(struct spdk_bdev *bdev);
struct spdk_bdev_module examine_claimed_mods[UT_MAX_EXAMINE_MODS] = {
	{
		.name = "vbdev_ut_examine0",
		.module_init = vbdev_ut_module_init,
		.module_init = ut_examine_claimed_init0,
		.module_fini = vbdev_ut_module_fini,
		.examine_config = ut_examine_claimed_config0,
		.examine_disk = ut_examine_claimed_disk0,
	},
	{
		.name = "vbdev_ut_examine1",
		.module_init = vbdev_ut_module_init,
		.module_init = ut_examine_claimed_init1,
		.module_fini = vbdev_ut_module_fini,
		.examine_config = ut_examine_claimed_config1,
		.examine_disk = ut_examine_claimed_disk1,
@@ -7252,6 +7254,38 @@ struct ut_examine_claimed_ctx {

bool ut_testing_examine_claimed;

/*
 * Store the order in which the modules were initialized,
 * since we have no guarantee on the order of execution of the constructors.
 * Modules are examined in reverse order of their initialization.
 */
static int g_ut_examine_claimed_order[UT_MAX_EXAMINE_MODS];
static int
ut_examine_claimed_init(uint32_t modnum)
{
	static int current = UT_MAX_EXAMINE_MODS;

	/* Only do this for thre first initialization of the bdev framework */
	if (current == 0) {
		return 0;
	}
	g_ut_examine_claimed_order[modnum] = --current;

	return 0;
}

static int
ut_examine_claimed_init0(void)
{
	return ut_examine_claimed_init(0);
}

static int
ut_examine_claimed_init1(void)
{
	return ut_examine_claimed_init(1);
}

static void
reset_examine_claimed_ctx(void)
{
@@ -7297,13 +7331,13 @@ examine_claimed_config(struct spdk_bdev *bdev, uint32_t modnum)
static void
ut_examine_claimed_config0(struct spdk_bdev *bdev)
{
	examine_claimed_config(bdev, 0);
	examine_claimed_config(bdev, g_ut_examine_claimed_order[0]);
}

static void
ut_examine_claimed_config1(struct spdk_bdev *bdev)
{
	examine_claimed_config(bdev, 1);
	examine_claimed_config(bdev, g_ut_examine_claimed_order[1]);
}

static void