Commit 8b61f516 authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Tomasz Zawadzki
Browse files

nvmf: fix restoring without reservation



When restoring from ptpl_file with no reservation acquired,
nvmf_ns_reservation_restore() would return -EINVAL, making it impossible
to add the namespace.

Change-Id: Ife6e177eb44be316c66789bf933810a2608d9dca
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21164


Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 17d5d6b6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2313,7 +2313,7 @@ nvmf_ns_reservation_restore(struct spdk_nvmf_ns *ns, struct spdk_nvmf_reservatio
			rkey_flag = true;
		}
	}
	if (!rkey_flag) {
	if (!rkey_flag && info->crkey != 0) {
		return -EINVAL;
	}

@@ -2342,7 +2342,7 @@ nvmf_ns_reservation_restore(struct spdk_nvmf_ns *ns, struct spdk_nvmf_reservatio
		spdk_uuid_parse(&reg->hostid, info->registrants[i].host_uuid);
		reg->rkey = info->registrants[i].rkey;
		TAILQ_INSERT_TAIL(&ns->registrants, reg, link);
		if (!spdk_uuid_compare(&holder_uuid, &reg->hostid)) {
		if (info->crkey != 0 && !spdk_uuid_compare(&holder_uuid, &reg->hostid)) {
			holder = reg;
		}
		SPDK_DEBUGLOG(nvmf, "Registrant RKEY 0x%"PRIx64", Host UUID %s\n",
+21 −0
Original line number Diff line number Diff line
@@ -1715,6 +1715,27 @@ test_nvmf_ns_reservation_restore(void)

	rc = nvmf_ns_reservation_restore(&ns, &info);
	CU_ASSERT(rc == -EINVAL);

	/* Check restore without reservation */
	spdk_uuid_fmt_lower(info.bdev_uuid, sizeof(info.bdev_uuid), &bdev.uuid);
	info.rtype = 0;
	info.crkey = 0;
	memset(info.holder_uuid, 0, SPDK_UUID_STRING_LEN);

	rc = nvmf_ns_reservation_restore(&ns, &info);
	CU_ASSERT(rc == 0);
	CU_ASSERT(ns.crkey == 0);
	CU_ASSERT(ns.rtype == 0);
	CU_ASSERT(ns.ptpl_activated == true);
	CU_ASSERT(ns.holder == NULL);
	reg0 = TAILQ_FIRST(&ns.registrants);
	reg1 = TAILQ_NEXT(reg0, link);
	CU_ASSERT(reg0->rkey = 0xb);
	CU_ASSERT(reg1->rkey = 0xc);

	rc = nvmf_ns_reservation_clear_all_registrants(&ns);
	CU_ASSERT(rc == 2);
	CU_ASSERT(TAILQ_EMPTY(&ns.registrants));
}

static void