bdev/nvme: Set nvme_ns->populated to true just after nvme_ns is available

A few patches including this patch will remove nvme_ns->ref by
nvme_ns->populated and nvme_ns->bdev and remove nvme_ns->ref.

In this patch, set nvme_ns->populated to true when nvme_ns->ref is
incremented, i.e., nvme_ns is available. nvme_ctrlr_populate_namespace_done()
clears nvme_ns->populated if creating bdev failed by memset().
And add assert to nvme_ctrlr_depopulate_namespace_done() to ensure
nvme_ns->populated is false when nvme_ctrlr_depopulated_namespace_done()
is called.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I536933abb516c0a29231149ab564dc8b84245b10
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7096
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: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-03-29 23:49:25 +09:00 committed by Jim Harris
parent 8cc81fa07a
commit f26d6c73e1
2 changed files with 2 additions and 1 deletions

View File

@ -1438,6 +1438,7 @@ nvme_ctrlr_populate_standard_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
nvme_ns->ns = ns;
nvme_ns->ref = 1;
nvme_ns->populated = true;
rc = nvme_bdev_create(nvme_bdev_ctrlr, nvme_ns);
done:
@ -1565,7 +1566,6 @@ nvme_ctrlr_populate_namespace_done(struct nvme_async_probe_ctx *ctx,
assert(nvme_bdev_ctrlr != NULL);
if (rc == 0) {
nvme_ns->populated = true;
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
nvme_bdev_ctrlr->ref++;
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);

View File

@ -1455,6 +1455,7 @@ bdev_ocssd_populate_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
nvme_ns->type_ctx = ocssd_ns;
nvme_ns->ns = ns;
nvme_ns->ref = 1;
nvme_ns->populated = true;
ctx->nvme_ctx = nvme_ctx;
ctx->nvme_ns = nvme_ns;