Commit ae9e5441 authored by Joel Cunningham's avatar Joel Cunningham Committed by Tomasz Zawadzki
Browse files

test/unit/nvmf: add test for preempt other unregister



Add a persistent reservation preempt test that exercises unregistering
others only and does not take the reservation.

This test case was missing.  For preempt-and-abort, we should have the
hostid of the unregistered host.

Change-Id: Ie6451349feb145b0c380fe844198b9c9a7a9d05a
Signed-off-by: default avatarJoel Cunningham <joel.cunningham@oracle.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26676


Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarChangpeng Liu <changpeliu@tencent.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
parent 39037ac5
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -1345,6 +1345,72 @@ test_reservation_acquire_preempt_no_holder(enum spdk_nvme_reservation_acquire_ac
	ut_reservation_deinit();
}

static void
test_reservation_acquire_preempt_unregister_others(enum spdk_nvme_reservation_acquire_action
		preempt_type)
{
	struct spdk_nvmf_request *req;
	struct spdk_nvme_cpl *rsp;
	struct spdk_nvmf_registrant *reg;
	uint32_t gen;
	bool is_abort = (preempt_type == SPDK_NVME_RESERVE_PREEMPT_ABORT);
	uint64_t a_rkey = 0xa1;
	uint64_t b_rkey = 0xb1;
	uint64_t c_rkey = 0xc1;

	printf("Executing test: %s with acquire type: %d\n", __func__, preempt_type);

	ut_reservation_init();

	req = ut_reservation_build_req(16);
	rsp = &req->rsp->nvme_cpl;
	rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
	SPDK_CU_ASSERT_FATAL(req != NULL);

	ut_reservation_build_registrants();

	/* ctrlr1_A Acquire */
	gen = g_ns.gen;
	ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
					     SPDK_NVME_RESERVE_WRITE_EXCLUSIVE, a_rkey, 0x0);
	nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr1_A, req);
	SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
	reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
	SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE);
	SPDK_CU_ASSERT_FATAL(g_ns.crkey == a_rkey);
	SPDK_CU_ASSERT_FATAL(g_ns.holder == reg);
	SPDK_CU_ASSERT_FATAL(g_ns.gen == gen);
	SPDK_CU_ASSERT_FATAL(g_ns.preempt_abort == NULL);

	/* ctrlr_B preempts C but doesn't acquire reservation */
	ut_reservation_build_acquire_request(req, preempt_type, 0,
					     SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, b_rkey, c_rkey);
	nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_B, req);
	SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
	/* Registration for B is maintained, C is unregistered */
	reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
	SPDK_CU_ASSERT_FATAL(reg != NULL);
	reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_C.hostid);
	SPDK_CU_ASSERT_FATAL(reg == NULL);
	/* Reservation A is maintained */
	SPDK_CU_ASSERT_FATAL(g_ns.crkey == a_rkey);
	SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE);
	SPDK_CU_ASSERT_FATAL(g_ns.gen - gen == 1);
	if (is_abort) {
		/* C was preempeted */
		SPDK_CU_ASSERT_FATAL(g_ns.preempt_abort);
		SPDK_CU_ASSERT_FATAL(g_ns.preempt_abort->hostids_cnt == 1);
		SPDK_CU_ASSERT_FATAL(hostid_list_contains_id(g_ns.preempt_abort->hostids,
				     g_ns.preempt_abort->hostids_cnt, &g_ctrlr_C.hostid));
		SPDK_CU_ASSERT_FATAL(g_ns.preempt_abort->hostids_gen == 1);
	} else {
		SPDK_CU_ASSERT_FATAL(g_ns.preempt_abort == NULL);
	}

	ut_reservation_free_req(req);
	ut_reservation_deinit();
}

static void
test_reservation_acquire_preempt_self(enum spdk_nvme_reservation_acquire_action preempt_type)
{
@@ -1464,6 +1530,8 @@ test_reservation_acquire_preempt(void)
	test_reservation_acquire_preempt_no_holder(SPDK_NVME_RESERVE_PREEMPT_ABORT);
	test_reservation_acquire_preempt_self(SPDK_NVME_RESERVE_PREEMPT);
	test_reservation_acquire_preempt_self(SPDK_NVME_RESERVE_PREEMPT_ABORT);
	test_reservation_acquire_preempt_unregister_others(SPDK_NVME_RESERVE_PREEMPT);
	test_reservation_acquire_preempt_unregister_others(SPDK_NVME_RESERVE_PREEMPT_ABORT);
}

static void