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:
parent
c9b18a9f3f
commit
474632ba7b
@ -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) {
|
||||
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 {
|
||||
if (!bdev || bdev->module != SPDK_GET_BDEV_MODULE(nvme)) {
|
||||
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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user