bdev/nvme: handle namespace resize event
while the size of namespace is changed, the resize event will be notified. Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com> Signed-off-by: Evgeniy Kochetov <evgeniik@mellanox.com> Signed-off-by: Allen Zhu <allenz@mellanox.com> Change-Id: I5d85f17df898dc21c0ae1eb9f529dcb624a457ac Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/849 Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
75c2135de5
commit
52a0feb404
@ -1799,20 +1799,29 @@ nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
{
|
{
|
||||||
uint32_t i, nn = ctrlr->cdata.nn;
|
uint32_t i, nn = ctrlr->cdata.nn;
|
||||||
struct spdk_nvme_ns_data *nsdata;
|
struct spdk_nvme_ns_data *nsdata;
|
||||||
|
bool ns_is_active;
|
||||||
|
|
||||||
for (i = 0; i < nn; i++) {
|
for (i = 0; i < nn; i++) {
|
||||||
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 = &ctrlr->nsdata[nsid - 1];
|
||||||
|
ns_is_active = spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid);
|
||||||
|
|
||||||
if ((nsdata->ncap == 0) && spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid)) {
|
if (nsdata->ncap && ns_is_active) {
|
||||||
|
if (nvme_ns_update(ns) != 0) {
|
||||||
|
SPDK_ERRLOG("Failed to update active NS %u\n", nsid);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((nsdata->ncap == 0) && ns_is_active) {
|
||||||
if (nvme_ns_construct(ns, nsid, ctrlr) != 0) {
|
if (nvme_ns_construct(ns, nsid, ctrlr) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsdata->ncap && !spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid)) {
|
if (nsdata->ncap && !ns_is_active) {
|
||||||
nvme_ns_destruct(ns);
|
nvme_ns_destruct(ns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -901,6 +901,7 @@ void nvme_ns_set_identify_data(struct spdk_nvme_ns *ns);
|
|||||||
int nvme_ns_construct(struct spdk_nvme_ns *ns, uint32_t id,
|
int nvme_ns_construct(struct spdk_nvme_ns *ns, uint32_t id,
|
||||||
struct spdk_nvme_ctrlr *ctrlr);
|
struct spdk_nvme_ctrlr *ctrlr);
|
||||||
void nvme_ns_destruct(struct spdk_nvme_ns *ns);
|
void nvme_ns_destruct(struct spdk_nvme_ns *ns);
|
||||||
|
int nvme_ns_update(struct spdk_nvme_ns *ns);
|
||||||
|
|
||||||
int nvme_fabric_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value);
|
int nvme_fabric_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value);
|
||||||
int nvme_fabric_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value);
|
int nvme_fabric_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value);
|
||||||
|
@ -394,3 +394,8 @@ void nvme_ns_destruct(struct spdk_nvme_ns *ns)
|
|||||||
ns->sectors_per_stripe = 0;
|
ns->sectors_per_stripe = 0;
|
||||||
ns->flags = 0;
|
ns->flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nvme_ns_update(struct spdk_nvme_ns *ns)
|
||||||
|
{
|
||||||
|
return nvme_ctrlr_identify_ns(ns);
|
||||||
|
}
|
||||||
|
@ -1120,7 +1120,12 @@ nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|||||||
{
|
{
|
||||||
struct spdk_nvme_ctrlr *ctrlr = nvme_bdev_ctrlr->ctrlr;
|
struct spdk_nvme_ctrlr *ctrlr = nvme_bdev_ctrlr->ctrlr;
|
||||||
struct nvme_bdev_ns *ns;
|
struct nvme_bdev_ns *ns;
|
||||||
|
struct spdk_nvme_ns *nvme_ns;
|
||||||
|
struct nvme_bdev *bdev;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
int rc;
|
||||||
|
uint64_t num_sectors;
|
||||||
|
bool ns_is_active;
|
||||||
|
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
/* Initialize this count to 1 to handle the populate functions
|
/* Initialize this count to 1 to handle the populate functions
|
||||||
@ -1133,7 +1138,28 @@ nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|||||||
uint32_t nsid = i + 1;
|
uint32_t nsid = i + 1;
|
||||||
|
|
||||||
ns = nvme_bdev_ctrlr->namespaces[i];
|
ns = nvme_bdev_ctrlr->namespaces[i];
|
||||||
if (!ns->populated && spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid)) {
|
ns_is_active = spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid);
|
||||||
|
|
||||||
|
if (ns->populated && ns_is_active && ns->type == NVME_BDEV_NS_STANDARD) {
|
||||||
|
/* NS is still there but attributes may have changed */
|
||||||
|
nvme_ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
||||||
|
num_sectors = spdk_nvme_ns_get_num_sectors(nvme_ns);
|
||||||
|
bdev = TAILQ_FIRST(&ns->bdevs);
|
||||||
|
if (bdev->disk.blockcnt != num_sectors) {
|
||||||
|
SPDK_NOTICELOG("NSID %u is resized: bdev name %s, old size %lu, new size %lu\n",
|
||||||
|
nsid,
|
||||||
|
bdev->disk.name,
|
||||||
|
bdev->disk.blockcnt,
|
||||||
|
num_sectors);
|
||||||
|
rc = spdk_bdev_notify_blockcnt_change(&bdev->disk, num_sectors);
|
||||||
|
if (rc != 0) {
|
||||||
|
SPDK_ERRLOG("Could not change num blocks for nvme bdev: name %s, errno: %d.\n",
|
||||||
|
bdev->disk.name, rc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ns->populated && ns_is_active) {
|
||||||
ns->id = nsid;
|
ns->id = nsid;
|
||||||
ns->ctrlr = nvme_bdev_ctrlr;
|
ns->ctrlr = nvme_bdev_ctrlr;
|
||||||
if (spdk_nvme_ctrlr_is_ocssd_supported(ctrlr)) {
|
if (spdk_nvme_ctrlr_is_ocssd_supported(ctrlr)) {
|
||||||
@ -1150,7 +1176,7 @@ nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|||||||
nvme_ctrlr_populate_namespace(nvme_bdev_ctrlr, ns, ctx);
|
nvme_ctrlr_populate_namespace(nvme_bdev_ctrlr, ns, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ns->populated && !spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid)) {
|
if (ns->populated && !ns_is_active) {
|
||||||
nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, ns);
|
nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, ns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -457,6 +457,12 @@ nvme_ns_construct(struct spdk_nvme_ns *ns, uint32_t id,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
nvme_ns_update(struct spdk_nvme_ns *ns)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
spdk_pci_device_detach(struct spdk_pci_device *device)
|
spdk_pci_device_detach(struct spdk_pci_device *device)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user