bdev/nvme: simplify spdk_bdev_nvme_get_ctrlr()

Rather than iterating over the g_nvme_bdevs list to determine if a bdev
is an NVMe bdev, we can just compare the module pointer.

Also, the function can take a spdk_bdev pointer directly rather than
casting from a void pointer.

Change-Id: Iccf3c9b3263e9b2d67d07d037dc00d1cbc0f22a1
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/389899
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Daniel Verkamp 2017-11-30 13:39:22 -07:00
parent c9b18a9f3f
commit 474632ba7b
2 changed files with 6 additions and 22 deletions

View File

@ -1408,31 +1408,13 @@ bdev_nvme_get_spdk_running_config(FILE *fp)
}
struct spdk_nvme_ctrlr *
spdk_bdev_nvme_get_ctrlr(void *bdev_)
spdk_bdev_nvme_get_ctrlr(struct spdk_bdev *bdev)
{
struct nvme_bdev *btmp;
struct spdk_bdev *bdev = bdev_;
struct nvme_bdev *nbdev;
if (!bdev || !bdev->ctxt) {
if (!bdev || bdev->module != SPDK_GET_BDEV_MODULE(nvme)) {
return NULL;
}
nbdev = (struct nvme_bdev *)bdev->ctxt;
/*
* Make sure nbdev is NVMe bdev
*/
TAILQ_FOREACH(btmp, &g_nvme_bdevs, link) {
if (btmp == nbdev) {
if (nbdev->nvme_ctrlr) {
return nbdev->nvme_ctrlr->ctrlr;
} else {
return NULL;
}
}
}
return NULL;
return SPDK_CONTAINEROF(bdev, struct nvme_bdev, disk)->nvme_ctrlr->ctrlr;
}
SPDK_LOG_REGISTER_TRACE_FLAG("bdev_nvme", SPDK_TRACE_BDEV_NVME)

View File

@ -40,9 +40,11 @@
#define NVME_MAX_CONTROLLERS 1024
struct spdk_bdev;
int spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
const char *base_name,
const char **names, size_t *count);
struct spdk_nvme_ctrlr *spdk_bdev_nvme_get_ctrlr(void *bdev);
struct spdk_nvme_ctrlr *spdk_bdev_nvme_get_ctrlr(struct spdk_bdev *bdev);
#endif // SPDK_BDEV_NVME_H