From a3363de3c2024efb54d4dfea7882206314b6652b Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 17 Mar 2020 00:33:15 +0800 Subject: [PATCH] nvme/opal: consolidate two get_locking_ranges APIs into one Actually we can just use one API to finish the requirement. Change-Id: Ia0d3d589755e8c92f636d3d090ec642299511401 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1280 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- examples/nvme/nvme_manage/nvme_manage.c | 4 ++-- include/spdk/opal.h | 3 --- lib/nvme/nvme_opal.c | 15 ++++++--------- module/bdev/nvme/vbdev_opal.c | 8 -------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index fcc144d80d..e7c21a4b59 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -1151,13 +1151,13 @@ opal_list_locking_ranges(struct dev *iter) printf("\n"); if (passwd_p) { ret = spdk_opal_cmd_get_max_ranges(iter->opal_dev, passwd_p); - if (ret) { + if (ret <= 0) { printf("get max ranges failure: %d\n", ret); spdk_opal_dev_destruct(iter->opal_dev); return; } - max_ranges = spdk_opal_get_max_locking_ranges(iter->opal_dev); + max_ranges = ret; for (i = 0; i < max_ranges; i++) { ret = spdk_opal_cmd_get_locking_range_info(iter->opal_dev, passwd_p, OPAL_ADMIN1, i); diff --git a/include/spdk/opal.h b/include/spdk/opal.h index 670cf68de1..84f47015ab 100644 --- a/include/spdk/opal.h +++ b/include/spdk/opal.h @@ -142,7 +142,4 @@ int spdk_opal_cmd_secure_erase_locking_range(struct spdk_opal_dev *dev, enum spd struct spdk_opal_locking_range_info *spdk_opal_get_locking_range_info(struct spdk_opal_dev *dev, enum spdk_opal_locking_range id); void spdk_opal_free_locking_range_info(struct spdk_opal_dev *dev, enum spdk_opal_locking_range id); - -uint8_t spdk_opal_get_max_locking_ranges(struct spdk_opal_dev *dev); - #endif diff --git a/lib/nvme/nvme_opal.c b/lib/nvme/nvme_opal.c index 31e709f175..3c69eacb6b 100644 --- a/lib/nvme/nvme_opal.c +++ b/lib/nvme/nvme_opal.c @@ -2116,6 +2116,10 @@ spdk_opal_cmd_get_max_ranges(struct spdk_opal_dev *dev, const char *passwd) return -ENOTSUP; } + if (dev->max_ranges) { + return dev->max_ranges; + } + ret = opal_init_key(&session.opal_key, passwd, OPAL_LOCKING_RANGE_GLOBAL); if (ret != 0) { return ret; @@ -2134,17 +2138,16 @@ spdk_opal_cmd_get_max_ranges(struct spdk_opal_dev *dev, const char *passwd) ret = opal_get_max_ranges(dev); if (ret) { SPDK_ERRLOG("get max ranges error %d\n", ret); - goto end; } -end: ret += opal_end_session(dev); if (ret) { SPDK_ERRLOG("end session error %d\n", ret); } pthread_mutex_unlock(&dev->mutex_lock); - return ret; + + return (ret == 0 ? dev->max_ranges : ret); } int @@ -2444,11 +2447,5 @@ spdk_opal_free_locking_range_info(struct spdk_opal_dev *dev, enum spdk_opal_lock memset(info, 0, sizeof(*info)); } -uint8_t -spdk_opal_get_max_locking_ranges(struct spdk_opal_dev *dev) -{ - return dev->max_ranges; -} - /* Log component for opal submodule */ SPDK_LOG_REGISTER_COMPONENT("opal", SPDK_LOG_OPAL) diff --git a/module/bdev/nvme/vbdev_opal.c b/module/bdev/nvme/vbdev_opal.c index 08986c389a..e48a3749f7 100644 --- a/module/bdev/nvme/vbdev_opal.c +++ b/module/bdev/nvme/vbdev_opal.c @@ -252,14 +252,6 @@ spdk_vbdev_opal_get_info_from_bdev(const char *opal_bdev_name, const char *passw return NULL; } - if (spdk_opal_get_max_locking_ranges(nvme_ctrlr->opal_dev) == 0) { - rc = spdk_opal_cmd_get_max_ranges(nvme_ctrlr->opal_dev, password); - if (rc) { - SPDK_ERRLOG("Get locking range number failure: %d\n", rc); - return NULL; - } - } - locking_range_id = vbdev->cfg.locking_range_id; rc = spdk_opal_cmd_get_locking_range_info(nvme_ctrlr->opal_dev, password, OPAL_ADMIN1, locking_range_id);