nvme: Move nsdata to namespace structure
Signed-off-by: Evgeniy 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: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
030b9f2608
commit
3a8852d384
@ -2,7 +2,7 @@
|
|||||||
* BSD LICENSE
|
* BSD LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (c) Intel Corporation. All rights reserved.
|
* 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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* 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_ctrlr *ctrlr = ns->ctrlr;
|
||||||
struct spdk_nvme_ns_data *nsdata;
|
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,
|
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_WAIT_FOR_IDENTIFY_NS,
|
||||||
ctrlr->opts.admin_timeout_ms);
|
ctrlr->opts.admin_timeout_ms);
|
||||||
@ -2477,10 +2477,6 @@ nvme_ctrlr_destruct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
ctrlr->num_ns = 0;
|
ctrlr->num_ns = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctrlr->nsdata) {
|
|
||||||
spdk_free(ctrlr->nsdata);
|
|
||||||
ctrlr->nsdata = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
spdk_free(ctrlr->nsdata_zns);
|
spdk_free(ctrlr->nsdata_zns);
|
||||||
ctrlr->nsdata_zns = NULL;
|
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];
|
struct spdk_nvme_ns *ns = &ctrlr->ns[i];
|
||||||
uint32_t nsid = i + 1;
|
uint32_t nsid = i + 1;
|
||||||
|
|
||||||
nsdata = &ctrlr->nsdata[nsid - 1];
|
nsdata = &ns->nsdata;
|
||||||
ns_is_active = spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid);
|
ns_is_active = spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid);
|
||||||
|
|
||||||
if (nsdata->ncap && ns_is_active) {
|
if (nsdata->ncap && ns_is_active) {
|
||||||
|
SPDK_DEBUGLOG(nvme, "Namespace %u was updated\n", nsid);
|
||||||
if (nvme_ns_update(ns) != 0) {
|
if (nvme_ns_update(ns) != 0) {
|
||||||
SPDK_ERRLOG("Failed to update active NS %u\n", nsid);
|
SPDK_ERRLOG("Failed to update active NS %u\n", nsid);
|
||||||
continue;
|
continue;
|
||||||
@ -2511,12 +2508,14 @@ nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((nsdata->ncap == 0) && ns_is_active) {
|
if ((nsdata->ncap == 0) && ns_is_active) {
|
||||||
|
SPDK_DEBUGLOG(nvme, "Namespace %u was added\n", nsid);
|
||||||
if (nvme_ns_construct(ns, nsid, ctrlr) != 0) {
|
if (nvme_ns_construct(ns, nsid, ctrlr) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsdata->ncap && !ns_is_active) {
|
if (nsdata->ncap && !ns_is_active) {
|
||||||
|
SPDK_DEBUGLOG(nvme, "Namespace %u was removed\n", nsid);
|
||||||
nvme_ns_destruct(ns);
|
nvme_ns_destruct(ns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2546,14 +2545,6 @@ nvme_ctrlr_construct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
goto fail;
|
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,
|
ctrlr->nsdata_zns = spdk_zmalloc(nn * sizeof(struct spdk_nvme_zns_ns_data *), 64,
|
||||||
NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_SHARE);
|
NULL, SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_SHARE);
|
||||||
if (ctrlr->nsdata_zns == NULL) {
|
if (ctrlr->nsdata_zns == NULL) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*-
|
/*-
|
||||||
* BSD LICENSE
|
* BSD LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (c) Intel Corporation.
|
* Copyright (c) Intel Corporation. All rights reserved.
|
||||||
* All rights reserved.
|
* Copyright (c) 2021 Mellanox Technologies LTD. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* 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].
|
* Current QEMU OpenChannel Device needs to check nsdata->vs[0].
|
||||||
* Here check nsdata->vs[0] of the first namespace.
|
* Here check nsdata->vs[0] of the first namespace.
|
||||||
*/
|
*/
|
||||||
if (ctrlr->cdata.vid == SPDK_PCI_VID_CNEXLABS) {
|
if (ctrlr->cdata.vid == SPDK_PCI_VID_CNEXLABS && ctrlr->num_ns) {
|
||||||
if (ctrlr->num_ns && ctrlr->nsdata[0].vendor_specific[0] == 0x1) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* BSD LICENSE
|
* BSD LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (c) Intel Corporation. All rights reserved.
|
* 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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -494,6 +494,9 @@ struct spdk_nvme_ns {
|
|||||||
|
|
||||||
uint32_t ana_group_id;
|
uint32_t ana_group_id;
|
||||||
enum spdk_nvme_ana_state ana_state;
|
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;
|
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.
|
* Array of pointers to Zoned Namespace Command Set Specific Identify Namespace data.
|
||||||
*/
|
*/
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* BSD LICENSE
|
* BSD LICENSE
|
||||||
*
|
*
|
||||||
* Copyright (c) Intel Corporation. All rights reserved.
|
* 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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -36,7 +36,7 @@
|
|||||||
static inline struct spdk_nvme_ns_data *
|
static inline struct spdk_nvme_ns_data *
|
||||||
_nvme_ns_get_data(struct spdk_nvme_ns *ns)
|
_nvme_ns_get_data(struct spdk_nvme_ns *ns)
|
||||||
{
|
{
|
||||||
return &ns->ctrlr->nsdata[ns->id - 1];
|
return &ns->nsdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,9 +32,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "spdk_cunit.h"
|
#include "spdk_cunit.h"
|
||||||
|
#include "common/lib/test_env.c"
|
||||||
|
|
||||||
#include "nvme/nvme_ctrlr_ocssd_cmd.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() \
|
#define DECLARE_AND_CONSTRUCT_CTRLR() \
|
||||||
struct spdk_nvme_ctrlr ctrlr = {}; \
|
struct spdk_nvme_ctrlr ctrlr = {}; \
|
||||||
struct spdk_nvme_qpair adminq = {}; \
|
struct spdk_nvme_qpair adminq = {}; \
|
||||||
|
@ -94,8 +94,7 @@ test_nvme_ns_construct(void)
|
|||||||
{
|
{
|
||||||
struct spdk_nvme_ns ns = {};
|
struct spdk_nvme_ns ns = {};
|
||||||
uint32_t id = 1;
|
uint32_t id = 1;
|
||||||
struct spdk_nvme_ns_data ctrlr_nsdata = {};
|
struct spdk_nvme_ctrlr ctrlr = { };
|
||||||
struct spdk_nvme_ctrlr ctrlr = { .nsdata = &ctrlr_nsdata };
|
|
||||||
|
|
||||||
nvme_ns_construct(&ns, id, &ctrlr);
|
nvme_ns_construct(&ns, id, &ctrlr);
|
||||||
CU_ASSERT(ns.id == 1);
|
CU_ASSERT(ns.id == 1);
|
||||||
@ -106,8 +105,7 @@ test_nvme_ns_uuid(void)
|
|||||||
{
|
{
|
||||||
struct spdk_nvme_ns ns = {};
|
struct spdk_nvme_ns ns = {};
|
||||||
uint32_t id = 1;
|
uint32_t id = 1;
|
||||||
struct spdk_nvme_ns_data nsdata = {};
|
struct spdk_nvme_ctrlr ctrlr = {};
|
||||||
struct spdk_nvme_ctrlr ctrlr = { .nsdata = &nsdata };
|
|
||||||
const struct spdk_uuid *uuid;
|
const struct spdk_uuid *uuid;
|
||||||
struct spdk_uuid expected_uuid;
|
struct spdk_uuid expected_uuid;
|
||||||
|
|
||||||
@ -170,8 +168,7 @@ test_nvme_ns_csi(void)
|
|||||||
{
|
{
|
||||||
struct spdk_nvme_ns ns = {};
|
struct spdk_nvme_ns ns = {};
|
||||||
uint32_t id = 1;
|
uint32_t id = 1;
|
||||||
struct spdk_nvme_ns_data nsdata = {};
|
struct spdk_nvme_ctrlr ctrlr = {};
|
||||||
struct spdk_nvme_ctrlr ctrlr = { .nsdata = &nsdata };
|
|
||||||
enum spdk_nvme_csi csi;
|
enum spdk_nvme_csi csi;
|
||||||
|
|
||||||
/* Empty list - SPDK_NVME_CSI_NVM should be returned */
|
/* Empty list - SPDK_NVME_CSI_NVM should be returned */
|
||||||
@ -218,8 +215,7 @@ static void
|
|||||||
test_nvme_ns_data(void)
|
test_nvme_ns_data(void)
|
||||||
{
|
{
|
||||||
struct spdk_nvme_ns ns = {};
|
struct spdk_nvme_ns ns = {};
|
||||||
struct spdk_nvme_ns_data ctrlr_nsdata = {};
|
struct spdk_nvme_ctrlr ctrlr = { };
|
||||||
struct spdk_nvme_ctrlr ctrlr = { .nsdata = &ctrlr_nsdata };
|
|
||||||
struct spdk_nvme_ns_data expected_nsdata = {
|
struct spdk_nvme_ns_data expected_nsdata = {
|
||||||
.nsze = 1000,
|
.nsze = 1000,
|
||||||
.ncap = 1000,
|
.ncap = 1000,
|
||||||
|
Loading…
Reference in New Issue
Block a user