Commit 3a8852d3 authored by Evgeniy Kochetov's avatar Evgeniy Kochetov Committed by Tomasz Zawadzki
Browse files

nvme: Move nsdata to namespace structure



Signed-off-by: default avatarEvgeniy Kochetov <evgeniik@nvidia.com>
Change-Id: I6083331a24dbf90170096cb98e6371ef2d4e6f9d
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6500


Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 030b9f26
Loading
Loading
Loading
Loading
+6 −15
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
 *   BSD LICENSE
 *
 *   Copyright (c) Intel Corporation. All rights reserved.
 *   Copyright (c) 2019, 2020 Mellanox Technologies LTD. All rights reserved.
 *   Copyright (c) 2019-2021 Mellanox Technologies LTD. All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
@@ -1990,7 +1990,7 @@ nvme_ctrlr_identify_ns_async(struct spdk_nvme_ns *ns)
	struct spdk_nvme_ctrlr *ctrlr = ns->ctrlr;
	struct spdk_nvme_ns_data *nsdata;

	nsdata = &ctrlr->nsdata[ns->id - 1];
	nsdata = &ns->nsdata;

	nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_WAIT_FOR_IDENTIFY_NS,
			     ctrlr->opts.admin_timeout_ms);
@@ -2477,10 +2477,6 @@ nvme_ctrlr_destruct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
		ctrlr->num_ns = 0;
	}

	if (ctrlr->nsdata) {
		spdk_free(ctrlr->nsdata);
		ctrlr->nsdata = NULL;
	}

	spdk_free(ctrlr->nsdata_zns);
	ctrlr->nsdata_zns = NULL;
@@ -2500,10 +2496,11 @@ nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr)
		struct spdk_nvme_ns	*ns = &ctrlr->ns[i];
		uint32_t		nsid = i + 1;

		nsdata = &ctrlr->nsdata[nsid - 1];
		nsdata = &ns->nsdata;
		ns_is_active = spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid);

		if (nsdata->ncap && ns_is_active) {
			SPDK_DEBUGLOG(nvme, "Namespace %u was updated\n", nsid);
			if (nvme_ns_update(ns) != 0) {
				SPDK_ERRLOG("Failed to update active NS %u\n", nsid);
				continue;
@@ -2511,12 +2508,14 @@ nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr)
		}

		if ((nsdata->ncap == 0) && ns_is_active) {
			SPDK_DEBUGLOG(nvme, "Namespace %u was added\n", nsid);
			if (nvme_ns_construct(ns, nsid, ctrlr) != 0) {
				continue;
			}
		}

		if (nsdata->ncap && !ns_is_active) {
			SPDK_DEBUGLOG(nvme, "Namespace %u was removed\n", nsid);
			nvme_ns_destruct(ns);
		}
	}
@@ -2546,14 +2545,6 @@ nvme_ctrlr_construct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
			goto fail;
		}

		ctrlr->nsdata = spdk_zmalloc(nn * sizeof(struct spdk_nvme_ns_data), 64,
					     NULL, SPDK_ENV_SOCKET_ID_ANY,
					     SPDK_MALLOC_SHARE | SPDK_MALLOC_DMA);
		if (ctrlr->nsdata == NULL) {
			rc = -ENOMEM;
			goto fail;
		}

		ctrlr->nsdata_zns = spdk_zmalloc(nn * sizeof(struct spdk_nvme_zns_ns_data *), 64,
						 NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_SHARE);
		if (ctrlr->nsdata_zns == NULL) {
+7 −4
Original line number Diff line number Diff line
/*-
 *   BSD LICENSE
 *
 *   Copyright (c) Intel Corporation.
 *   All rights reserved.
 *   Copyright (c) Intel Corporation. All rights reserved.
 *   Copyright (c) 2021 Mellanox Technologies LTD. All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
@@ -46,8 +46,11 @@ spdk_nvme_ctrlr_is_ocssd_supported(struct spdk_nvme_ctrlr *ctrlr)
		 * Current QEMU OpenChannel Device needs to check nsdata->vs[0].
		 * Here check nsdata->vs[0] of the first namespace.
		 */
		if (ctrlr->cdata.vid == SPDK_PCI_VID_CNEXLABS) {
			if (ctrlr->num_ns && ctrlr->nsdata[0].vendor_specific[0] == 0x1) {
		if (ctrlr->cdata.vid == SPDK_PCI_VID_CNEXLABS && ctrlr->num_ns) {
			uint32_t nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr);
			struct spdk_nvme_ns *ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);

			if (ns && ns->nsdata.vendor_specific[0] == 0x1) {
				return true;
			}
		}
+4 −8
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
 *   BSD LICENSE
 *
 *   Copyright (c) Intel Corporation. All rights reserved.
 *   Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved.
 *   Copyright (c) 2020, 2021 Mellanox Technologies LTD. All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
@@ -494,6 +494,9 @@ struct spdk_nvme_ns {

	uint32_t			ana_group_id;
	enum spdk_nvme_ana_state	ana_state;

	/* Identify Namespace data. */
	struct spdk_nvme_ns_data	nsdata;
};

/**
@@ -811,13 +814,6 @@ struct spdk_nvme_ctrlr {
	 */
	uint32_t			*active_ns_list;

	/**
	 * Array of Identify Namespace data.
	 *
	 * Stored separately from ns since nsdata should not normally be accessed during I/O.
	 */
	struct spdk_nvme_ns_data	*nsdata;

	/**
	 * Array of pointers to Zoned Namespace Command Set Specific Identify Namespace data.
	 */
+2 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
 *   BSD LICENSE
 *
 *   Copyright (c) Intel Corporation. All rights reserved.
 *   Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved.
 *   Copyright (c) 2020, 2021 Mellanox Technologies LTD. All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
@@ -36,7 +36,7 @@
static inline struct spdk_nvme_ns_data *
_nvme_ns_get_data(struct spdk_nvme_ns *ns)
{
	return &ns->ctrlr->nsdata[ns->id - 1];
	return &ns->nsdata;
}

/**
+6 −0
Original line number Diff line number Diff line
@@ -32,9 +32,15 @@
 */

#include "spdk_cunit.h"
#include "common/lib/test_env.c"

#include "nvme/nvme_ctrlr_ocssd_cmd.c"

DEFINE_STUB(spdk_nvme_ctrlr_get_ns, struct spdk_nvme_ns *,
	    (struct spdk_nvme_ctrlr *ctrlr, uint32_t ns_id), NULL);
DEFINE_STUB(spdk_nvme_ctrlr_get_first_active_ns, uint32_t,
	    (struct spdk_nvme_ctrlr *ctrlr), 0);

#define DECLARE_AND_CONSTRUCT_CTRLR()	\
	struct spdk_nvme_ctrlr	ctrlr = {};	\
	struct spdk_nvme_qpair	adminq = {};	\
Loading