bdev/ocssd: Process only the head of nvme_ns->bdevs

The range parameter was deprecated from bdev_ocssd_create(), and
hence one ocssd_bdev can be created per one ocssd_ns now.
Hence process only one ocssd_bdev per one ocssd_ns. The following
patches will replace a linked list nvme_ns->bdevs by a pointer
nvme_ns->bdev.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I824d26f4d2f73326238a6426634e28cfd655a04d
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6224
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: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
Shuhei Matsumoto 2021-02-17 21:01:24 +09:00 committed by Tomasz Zawadzki
parent 90c56d965d
commit 56d8cc8d72

View File

@ -122,36 +122,24 @@ bdev_ocssd_config_json(struct spdk_json_write_ctx *w)
return 0;
}
static void
ocssd_bdev_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev *nvme_bdev)
{
struct nvme_bdev_ns *nvme_ns;
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
nvme_ns = nvme_bdev_to_bdev_ns(nvme_bdev);
assert(nvme_ns != NULL);
nvme_bdev_ctrlr = nvme_ns->ctrlr;
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "bdev_ocssd_create");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "ctrlr_name", nvme_bdev_ctrlr->name);
spdk_json_write_named_string(w, "bdev_name", nvme_bdev->disk.name);
spdk_json_write_named_uint32(w, "nsid", nvme_ns->id);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
void
bdev_ocssd_namespace_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *nvme_ns)
{
struct nvme_bdev *nvme_bdev;
TAILQ_FOREACH(nvme_bdev, &nvme_ns->bdevs, tailq) {
ocssd_bdev_config_json(w, nvme_bdev);
}
nvme_bdev = TAILQ_FIRST(&nvme_ns->bdevs);
assert(nvme_bdev != NULL);
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "bdev_ocssd_create");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "ctrlr_name", nvme_ns->ctrlr->name);
spdk_json_write_named_string(w, "bdev_name", nvme_bdev->disk.name);
spdk_json_write_named_uint32(w, "nsid", nvme_ns->id);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
static int
@ -320,20 +308,6 @@ bdev_ocssd_to_chunk_info_offset(struct bdev_ocssd_ns *ocssd_ns, uint64_t lba)
return grp * geo->num_pu * geo->num_chk + pu * geo->num_chk + chk;
}
static bool
bdev_ocssd_lba_in_range(struct ocssd_bdev *ocssd_bdev,
struct bdev_ocssd_ns *ocssd_ns, uint64_t lba)
{
const struct spdk_ocssd_geometry_data *geometry = &ocssd_ns->geometry;
const struct bdev_ocssd_lba_offsets *offsets = &ocssd_ns->lba_offsets;
const struct bdev_ocssd_range *range = &ocssd_bdev->range;
uint64_t punit;
punit = bdev_ocssd_to_parallel_unit(geometry, offsets, lba);
return punit >= range->begin && punit <= range->end;
}
static void
bdev_ocssd_reset_sgl(void *ref, uint32_t sgl_offset)
{
@ -901,9 +875,10 @@ bdev_ocssd_get_io_channel(void *ctx)
static void
bdev_ocssd_free_namespace(struct nvme_bdev_ns *nvme_ns)
{
struct nvme_bdev *bdev, *tmp;
struct nvme_bdev *bdev;
TAILQ_FOREACH_SAFE(bdev, &nvme_ns->bdevs, tailq, tmp) {
bdev = TAILQ_FIRST(&nvme_ns->bdevs);
if (bdev != NULL) {
spdk_bdev_unregister(&bdev->disk, NULL, NULL);
}
@ -921,7 +896,6 @@ bdev_ocssd_push_media_events(struct nvme_bdev_ns *nvme_ns,
const struct spdk_ocssd_geometry_data *geometry = &ocssd_ns->geometry;
struct spdk_bdev_media_event event;
struct nvme_bdev *nvme_bdev;
struct ocssd_bdev *ocssd_bdev;
size_t num_blocks, lba;
int rc;
@ -936,13 +910,7 @@ bdev_ocssd_push_media_events(struct nvme_bdev_ns *nvme_ns,
return;
}
TAILQ_FOREACH(nvme_bdev, &nvme_ns->bdevs, tailq) {
ocssd_bdev = SPDK_CONTAINEROF(nvme_bdev, struct ocssd_bdev, nvme_bdev);
if (bdev_ocssd_lba_in_range(ocssd_bdev, ocssd_ns, chunk_entry->lba)) {
break;
}
}
nvme_bdev = TAILQ_FIRST(&nvme_ns->bdevs);
if (nvme_bdev == NULL) {
SPDK_INFOLOG(bdev_ocssd, "Dropping media management event\n");
return;
@ -971,7 +939,8 @@ bdev_ocssd_notify_media_management(struct nvme_bdev_ns *nvme_ns)
{
struct nvme_bdev *nvme_bdev;
TAILQ_FOREACH(nvme_bdev, &nvme_ns->bdevs, tailq) {
nvme_bdev = TAILQ_FIRST(&nvme_ns->bdevs);
if (nvme_bdev != NULL) {
spdk_bdev_notify_media_management(&nvme_bdev->disk);
}
}