nvme/opal: deprecate spdk_opal_supported()

The spdk_opal_supported() is redundant with spdk_opal_dev_construct(),
because we only return the spdk_opal_dev structure when the drive
can support OPAL feature.

Change-Id: Ieadf271a0c8530f2440cded05ad139483a8c5937
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2383
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Changpeng Liu 2020-05-12 03:00:52 -04:00 committed by Tomasz Zawadzki
parent 18504e3f4d
commit b2947f528f
7 changed files with 303 additions and 351 deletions

View File

@ -978,11 +978,9 @@ opal_scan(struct dev *iter)
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("\n\nOpal Supported:\n");
display_controller(iter, CONTROLLER_DISPLAY_SIMPLISTIC);
opal_dump_info(spdk_opal_get_d0_features_info(iter->opal_dev));
}
printf("\n\nOpal Supported:\n");
display_controller(iter, CONTROLLER_DISPLAY_SIMPLISTIC);
opal_dump_info(spdk_opal_get_d0_features_info(iter->opal_dev));
spdk_opal_dev_destruct(iter->opal_dev);
} else {
printf("%04x:%02x:%02x.%02x: NVMe Security Support/Receive Not supported.\n",
@ -1005,29 +1003,27 @@ opal_init(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("Please input the new password for ownership:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(new_passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n...\n");
if (passwd_p) {
ret = spdk_opal_cmd_take_ownership(iter->opal_dev, passwd_p);
if (ret) {
printf("Take ownership failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_activate_locking_sp(iter->opal_dev, passwd_p);
if (ret) {
printf("Locking SP activate failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\nOpal Init Success\n");
} else {
printf("Input password invalid. Opal Init failure\n");
printf("Please input the new password for ownership:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(new_passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n...\n");
if (passwd_p) {
ret = spdk_opal_cmd_take_ownership(iter->opal_dev, passwd_p);
if (ret) {
printf("Take ownership failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_activate_locking_sp(iter->opal_dev, passwd_p);
if (ret) {
printf("Locking SP activate failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\nOpal Init Success\n");
} else {
printf("Input password invalid. Opal Init failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1063,63 +1059,61 @@ opal_setup_lockingrange(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("Please input the password for setting up locking range:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("Specify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("range length:\n");
if (!scanf("%" SCNu64, &range_length)) {
printf("Invalid range length\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("range start:\n");
if (!scanf("%" SCNu64, &range_start)) {
printf("Invalid range start address\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
while (getchar() != '\n');
ret = spdk_opal_cmd_setup_locking_range(iter->opal_dev,
OPAL_ADMIN1, locking_range_id, range_start, range_length, passwd_p);
if (ret) {
printf("Setup locking range failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_get_locking_range_info(iter->opal_dev,
passwd_p, OPAL_ADMIN1, locking_range_id);
if (ret) {
printf("Get locking range info failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
info = spdk_opal_get_locking_range_info(iter->opal_dev, locking_range_id);
printf("\nlocking range ID: %d\n", info->locking_range_id);
printf("range start: %ld\n", info->range_start);
printf("range length: %ld\n", info->range_length);
printf("read lock enabled: %d\n", info->read_lock_enabled);
printf("write lock enabled: %d\n", info->write_lock_enabled);
printf("read locked: %d\n", info->read_locked);
printf("write locked: %d\n", info->write_locked);
printf("...\n...\nOpal setup locking range success\n");
} else {
printf("Input password invalid. Opal setup locking range failure\n");
printf("Please input the password for setting up locking range:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("Specify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("range length:\n");
if (!scanf("%" SCNu64, &range_length)) {
printf("Invalid range length\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("range start:\n");
if (!scanf("%" SCNu64, &range_start)) {
printf("Invalid range start address\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
while (getchar() != '\n');
ret = spdk_opal_cmd_setup_locking_range(iter->opal_dev,
OPAL_ADMIN1, locking_range_id, range_start, range_length, passwd_p);
if (ret) {
printf("Setup locking range failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_get_locking_range_info(iter->opal_dev,
passwd_p, OPAL_ADMIN1, locking_range_id);
if (ret) {
printf("Get locking range info failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
info = spdk_opal_get_locking_range_info(iter->opal_dev, locking_range_id);
printf("\nlocking range ID: %d\n", info->locking_range_id);
printf("range start: %ld\n", info->range_start);
printf("range length: %ld\n", info->range_length);
printf("read lock enabled: %d\n", info->read_lock_enabled);
printf("write lock enabled: %d\n", info->write_lock_enabled);
printf("read locked: %d\n", info->read_locked);
printf("write locked: %d\n", info->write_locked);
printf("...\n...\nOpal setup locking range success\n");
} else {
printf("Input password invalid. Opal setup locking range failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1144,48 +1138,46 @@ opal_list_locking_ranges(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("Please input password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
ret = spdk_opal_cmd_get_max_ranges(iter->opal_dev, passwd_p);
if (ret <= 0) {
printf("get max ranges failure: %d\n", ret);
printf("Please input password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
ret = spdk_opal_cmd_get_max_ranges(iter->opal_dev, passwd_p);
if (ret <= 0) {
printf("get max ranges failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
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);
if (ret) {
printf("Get locking range info failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
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);
if (ret) {
printf("Get locking range info failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
info = spdk_opal_get_locking_range_info(iter->opal_dev, i);
if (info == NULL) {
continue;
}
printf("===============================================\n");
printf("locking range ID: %d\t", info->locking_range_id);
if (i == 0) { printf("(Global Range)"); }
printf("\n===============================================\n");
printf("range start: %ld\t", info->range_start);
printf("range length: %ld\n", info->range_length);
printf("read lock enabled: %d\t", info->read_lock_enabled);
printf("write lock enabled: %d\t", info->write_lock_enabled);
printf("read locked: %d\t", info->read_locked);
printf("write locked: %d\n", info->write_locked);
printf("\n");
info = spdk_opal_get_locking_range_info(iter->opal_dev, i);
if (info == NULL) {
continue;
}
} else {
printf("Input password invalid. List locking ranges failure\n");
printf("===============================================\n");
printf("locking range ID: %d\t", info->locking_range_id);
if (i == 0) { printf("(Global Range)"); }
printf("\n===============================================\n");
printf("range start: %ld\t", info->range_start);
printf("range length: %ld\n", info->range_length);
printf("read lock enabled: %d\t", info->read_lock_enabled);
printf("write lock enabled: %d\t", info->write_lock_enabled);
printf("read locked: %d\t", info->read_locked);
printf("write locked: %d\n", info->write_locked);
printf("\n");
}
} else {
printf("Input password invalid. List locking ranges failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1210,45 +1202,43 @@ opal_new_user_enable(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("Please input admin password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("which user to enable: ");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_enable_user(iter->opal_dev, user_id, passwd_p);
if (ret) {
printf("Enable user failure error code: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("Please set a new password for this user:");
while ((ch = getchar()) != '\n' && ch != EOF);
user_pw_p = get_line(user_pw, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
if (user_pw_p == NULL) {
printf("Input password invalid. Enable user failure\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_set_new_passwd(iter->opal_dev, user_id, user_pw_p, passwd_p, true);
if (ret) {
printf("Set new password failure error code: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("\n...\n...\nEnable User Success\n");
} else {
printf("Input password invalid. Enable user failure\n");
printf("Please input admin password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("which user to enable: ");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_enable_user(iter->opal_dev, user_id, passwd_p);
if (ret) {
printf("Enable user failure error code: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("Please set a new password for this user:");
while ((ch = getchar()) != '\n' && ch != EOF);
user_pw_p = get_line(user_pw, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
if (user_pw_p == NULL) {
printf("Input password invalid. Enable user failure\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_set_new_passwd(iter->opal_dev, user_id, user_pw_p, passwd_p, true);
if (ret) {
printf("Set new password failure error code: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("\n...\n...\nEnable User Success\n");
} else {
printf("Input password invalid. Enable user failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1273,38 +1263,36 @@ opal_change_password(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("user id: ");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
printf("user id: ");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("Password:");
while ((ch = getchar()) != '\n' && ch != EOF);
old_passwd_p = get_line(old_passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (old_passwd_p) {
printf("Please input new password:\n");
new_passwd_p = get_line(new_passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (new_passwd_p == NULL) {
printf("Input password invalid. Change password failure\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("Password:");
while ((ch = getchar()) != '\n' && ch != EOF);
old_passwd_p = get_line(old_passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (old_passwd_p) {
printf("Please input new password:\n");
new_passwd_p = get_line(new_passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (new_passwd_p == NULL) {
printf("Input password invalid. Change password failure\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
ret = spdk_opal_cmd_set_new_passwd(iter->opal_dev, user_id, new_passwd_p, old_passwd_p, false);
if (ret) {
printf("Set new password failure error code: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\n...\nChange password Success\n");
} else {
printf("Input password invalid. Change password failure\n");
ret = spdk_opal_cmd_set_new_passwd(iter->opal_dev, user_id, new_passwd_p, old_passwd_p, false);
if (ret) {
printf("Set new password failure error code: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\n...\nChange password Success\n");
} else {
printf("Input password invalid. Change password failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1327,43 +1315,39 @@ opal_add_user_to_locking_range(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("Please input admin password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("Specify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("which user to enable:\n");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
while (getchar() != '\n');
ret = spdk_opal_cmd_add_user_to_locking_range(iter->opal_dev, user_id, locking_range_id,
OPAL_READONLY,
passwd_p);
ret += spdk_opal_cmd_add_user_to_locking_range(iter->opal_dev, user_id, locking_range_id,
OPAL_READWRITE,
passwd_p);
if (ret) {
printf("Add user to locking range error: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\n...\nAdd user to locking range Success\n");
} else {
printf("Input password invalid. Add user to locking range failure\n");
printf("Please input admin password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("Specify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("which user to enable:\n");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
while (getchar() != '\n');
ret = spdk_opal_cmd_add_user_to_locking_range(iter->opal_dev, user_id, locking_range_id,
OPAL_READONLY, passwd_p);
ret += spdk_opal_cmd_add_user_to_locking_range(iter->opal_dev, user_id, locking_range_id,
OPAL_READWRITE, passwd_p);
if (ret) {
printf("Add user to locking range error: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\n...\nAdd user to locking range Success\n");
} else {
printf("Input password invalid. Add user to locking range failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1389,58 +1373,56 @@ opal_user_lock_unlock_range(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("User id: ");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
printf("User id: ");
if (!scanf("%d", &user_id)) {
printf("Invalid user id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("Please input password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("Specify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("Please input password:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n");
if (passwd_p) {
printf("Specify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
opal_locking_usage();
if (!scanf("%d", &state)) {
printf("Invalid option\n");
}
switch (state) {
case 1:
state_flag = OPAL_RWLOCK;
break;
case 2:
state_flag = OPAL_READONLY;
break;
case 3:
state_flag = OPAL_READWRITE;
break;
default:
printf("Invalid options\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
while (getchar() != '\n');
ret = spdk_opal_cmd_lock_unlock(iter->opal_dev, user_id, state_flag,
locking_range_id, passwd_p);
if (ret) {
printf("lock/unlock range failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\n...\nLock/unlock range Success\n");
} else {
printf("Input password invalid. lock/unlock range failure\n");
opal_locking_usage();
if (!scanf("%d", &state)) {
printf("Invalid option\n");
}
switch (state) {
case 1:
state_flag = OPAL_RWLOCK;
break;
case 2:
state_flag = OPAL_READONLY;
break;
case 3:
state_flag = OPAL_READWRITE;
break;
default:
printf("Invalid options\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
while (getchar() != '\n');
ret = spdk_opal_cmd_lock_unlock(iter->opal_dev, user_id, state_flag,
locking_range_id, passwd_p);
if (ret) {
printf("lock/unlock range failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\n...\nLock/unlock range Success\n");
} else {
printf("Input password invalid. lock/unlock range failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1462,24 +1444,22 @@ opal_revert_tper(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("Please be noted this operation will erase ALL DATA on this drive\n");
printf("Please don't ternminate this excecution. Otherwise undefined error may occur\n");
printf("Please input password for revert TPer:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n...\n");
if (passwd_p) {
ret = spdk_opal_cmd_revert_tper(iter->opal_dev, passwd_p);
if (ret) {
printf("Revert TPer failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\nRevert TPer Success\n");
} else {
printf("Input password invalid. Revert TPer failure\n");
printf("Please be noted this operation will erase ALL DATA on this drive\n");
printf("Please don't ternminate this excecution. Otherwise undefined error may occur\n");
printf("Please input password for revert TPer:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
printf("\n...\n");
if (passwd_p) {
ret = spdk_opal_cmd_revert_tper(iter->opal_dev, passwd_p);
if (ret) {
printf("Revert TPer failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\nRevert TPer Success\n");
} else {
printf("Input password invalid. Revert TPer failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {
@ -1502,30 +1482,28 @@ opal_erase_locking_range(struct dev *iter)
if (iter->opal_dev == NULL) {
return;
}
if (spdk_opal_supported(iter->opal_dev)) {
printf("Please be noted this operation will erase ALL DATA on this range\n");
printf("Please input password for erase locking range:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
if (passwd_p) {
printf("\nSpecify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("\n...\n");
ret = spdk_opal_cmd_secure_erase_locking_range(iter->opal_dev, OPAL_ADMIN1, locking_range_id,
passwd_p);
if (ret) {
printf("Erase locking range failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\nErase locking range Success\n");
} else {
printf("Input password invalid. Erase locking range failure\n");
printf("Please be noted this operation will erase ALL DATA on this range\n");
printf("Please input password for erase locking range:");
while ((ch = getchar()) != '\n' && ch != EOF);
passwd_p = get_line(passwd, SPDK_OPAL_MAX_PASSWORD_SIZE, stdin, true);
if (passwd_p) {
printf("\nSpecify locking range id:\n");
if (!scanf("%d", &locking_range_id)) {
printf("Invalid locking range id\n");
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("\n...\n");
ret = spdk_opal_cmd_secure_erase_locking_range(iter->opal_dev, OPAL_ADMIN1, locking_range_id,
passwd_p);
if (ret) {
printf("Erase locking range failure: %d\n", ret);
spdk_opal_dev_destruct(iter->opal_dev);
return;
}
printf("...\nErase locking range Success\n");
} else {
printf("Input password invalid. Erase locking range failure\n");
}
spdk_opal_dev_destruct(iter->opal_dev);
} else {

View File

@ -102,7 +102,7 @@ void spdk_opal_dev_destruct(struct spdk_opal_dev *dev);
struct spdk_opal_d0_features_info *spdk_opal_get_d0_features_info(struct spdk_opal_dev *dev);
bool spdk_opal_supported(struct spdk_opal_dev *dev);
__attribute__((__deprecated__)) bool spdk_opal_supported(struct spdk_opal_dev *dev);
int spdk_opal_cmd_take_ownership(struct spdk_opal_dev *dev, char *new_passwd);

View File

@ -834,7 +834,6 @@ opal_discovery0_end(struct spdk_opal_dev *dev, void *payload, uint32_t payload_s
SPDK_INFOLOG(SPDK_LOG_OPAL, "Single User Mode Not Supported\n");
}
dev->supported = true;
dev->comid = comid;
return 0;
}
@ -1766,9 +1765,7 @@ spdk_opal_cmd_take_ownership(struct spdk_opal_dev *dev, char *new_passwd)
struct spdk_opal_key opal_key = {};
struct opal_session *sess;
if (!dev || dev->supported == false) {
return -ENODEV;
}
assert(dev != NULL);
sess = opal_alloc_session(dev);
if (!sess) {
@ -2040,9 +2037,7 @@ spdk_opal_cmd_revert_tper(struct spdk_opal_dev *dev, const char *passwd)
struct opal_session *sess;
struct spdk_opal_key opal_key = {};
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, passwd);
if (ret) {
@ -2144,9 +2139,7 @@ spdk_opal_cmd_lock_unlock(struct spdk_opal_dev *dev, enum spdk_opal_user user,
struct spdk_opal_key opal_key = {};
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, passwd);
if (ret != 0) {
@ -2188,9 +2181,7 @@ spdk_opal_cmd_setup_locking_range(struct spdk_opal_dev *dev, enum spdk_opal_user
struct spdk_opal_key opal_key = {};
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, passwd);
if (ret != 0) {
@ -2231,9 +2222,7 @@ spdk_opal_cmd_get_max_ranges(struct spdk_opal_dev *dev, const char *passwd)
struct spdk_opal_key opal_key = {};
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
if (dev->max_ranges) {
return dev->max_ranges;
@ -2280,9 +2269,7 @@ spdk_opal_cmd_get_locking_range_info(struct spdk_opal_dev *dev, const char *pass
struct spdk_opal_key opal_key = {};
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, passwd);
if (ret != 0) {
@ -2323,9 +2310,7 @@ spdk_opal_cmd_enable_user(struct spdk_opal_dev *dev, enum spdk_opal_user user_id
struct spdk_opal_key opal_key = {};
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, passwd);
if (ret != 0) {
@ -2368,9 +2353,7 @@ spdk_opal_cmd_add_user_to_locking_range(struct spdk_opal_dev *dev, enum spdk_opa
struct spdk_opal_key opal_key = {};
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, passwd);
if (ret != 0) {
@ -2413,9 +2396,7 @@ spdk_opal_cmd_set_new_passwd(struct spdk_opal_dev *dev, enum spdk_opal_user user
struct spdk_opal_key new_key = {};
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&old_key, old_passwd);
if (ret != 0) {
@ -2462,9 +2443,7 @@ spdk_opal_cmd_erase_locking_range(struct spdk_opal_dev *dev, enum spdk_opal_user
struct spdk_opal_key opal_key = {};
int ret;
if (dev->supported == false) {
return -ENODEV;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, password);
if (ret != 0) {
@ -2506,9 +2485,7 @@ spdk_opal_cmd_secure_erase_locking_range(struct spdk_opal_dev *dev, enum spdk_op
struct spdk_opal_key *active_key;
int ret;
if (dev->supported == false) {
return -ENOTSUP;
}
assert(dev != NULL);
ret = opal_init_key(&opal_key, password);
if (ret != 0) {
@ -2566,7 +2543,7 @@ spdk_opal_get_d0_features_info(struct spdk_opal_dev *dev)
bool
spdk_opal_supported(struct spdk_opal_dev *dev)
{
return dev->supported;
return false;
}
struct spdk_opal_locking_range_info *

View File

@ -259,7 +259,6 @@ struct opal_session {
};
struct spdk_opal_dev {
bool supported;
struct spdk_nvme_ctrlr *ctrlr;
uint16_t comid;

View File

@ -916,7 +916,7 @@ bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
if (cdata->oacs.security) {
spdk_json_write_named_object_begin(w, "security");
spdk_json_write_named_bool(w, "opal", spdk_opal_supported(nvme_bdev_ctrlr->opal_dev));
spdk_json_write_named_bool(w, "opal", nvme_bdev_ctrlr->opal_dev ? true : false);
spdk_json_write_object_end(w);
}

View File

@ -350,7 +350,7 @@ vbdev_opal_create(const char *nvme_ctrlr_name, uint32_t nsid, uint8_t locking_ra
return -ENODEV;
}
if (!nvme_ctrlr->opal_dev || !spdk_opal_supported(nvme_ctrlr->opal_dev)) {
if (!nvme_ctrlr->opal_dev) {
SPDK_ERRLOG("Opal not supported\n");
return -ENOTSUP;
}

View File

@ -74,8 +74,7 @@ rpc_bdev_nvme_opal_init(struct spdk_jsonrpc_request *request,
/* check if opal supported */
nvme_ctrlr = nvme_bdev_ctrlr_get_by_name(req.nvme_ctrlr_name);
if (nvme_ctrlr == NULL || nvme_ctrlr->opal_dev == NULL ||
!spdk_opal_supported(nvme_ctrlr->opal_dev)) {
if (nvme_ctrlr == NULL || nvme_ctrlr->opal_dev == NULL) {
SPDK_ERRLOG("%s not support opal\n", req.nvme_ctrlr_name);
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
goto out;
@ -153,8 +152,7 @@ rpc_bdev_nvme_opal_revert(struct spdk_jsonrpc_request *request,
/* check if opal supported */
nvme_ctrlr = nvme_bdev_ctrlr_get_by_name(req.nvme_ctrlr_name);
if (nvme_ctrlr == NULL || nvme_ctrlr->opal_dev == NULL ||
!spdk_opal_supported(nvme_ctrlr->opal_dev)) {
if (nvme_ctrlr == NULL || nvme_ctrlr->opal_dev == NULL) {
SPDK_ERRLOG("%s not support opal\n", req.nvme_ctrlr_name);
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
goto out;