nvme/opal: move the command finalization to generic_pw_cmd()

opal_cmd_finalize() is part of OPAL command construction, so move it
to the common password construction function.

Change-Id: I65ecf1c9181e622f344f7e9284058e2472accd31
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1669
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Changpeng Liu 2020-04-03 23:38:59 +08:00 committed by Tomasz Zawadzki
parent 2728b774aa
commit 71327bfef8

View File

@ -1010,8 +1010,8 @@ opal_get_msid_cpin_pin(struct spdk_opal_dev *dev, struct opal_session *sess,
} }
static int static int
opal_generic_pw_cmd(struct opal_session *sess, uint8_t *key, size_t key_len, uint8_t *cpin_uid, opal_build_generic_pw_cmd(struct opal_session *sess, uint8_t *key, size_t key_len,
struct spdk_opal_dev *dev) uint8_t *cpin_uid, struct spdk_opal_dev *dev)
{ {
int err = 0; int err = 0;
@ -1036,7 +1036,11 @@ opal_generic_pw_cmd(struct opal_session *sess, uint8_t *key, size_t key_len, uin
SPDK_OPAL_ENDLIST, SPDK_OPAL_ENDLIST,
SPDK_OPAL_ENDNAME, SPDK_OPAL_ENDNAME,
SPDK_OPAL_ENDLIST); SPDK_OPAL_ENDLIST);
return err; if (err) {
return err;
}
return opal_cmd_finalize(sess, sess->hsn, sess->tsn, true);
} }
static int static int
@ -1665,17 +1669,12 @@ opal_new_user_passwd(struct spdk_opal_dev *dev, struct opal_session *sess,
uid_cpin[7] = user; uid_cpin[7] = user;
} }
ret = opal_generic_pw_cmd(sess, opal_key->key, opal_key->key_len, uid_cpin, dev); ret = opal_build_generic_pw_cmd(sess, opal_key->key, opal_key->key_len, uid_cpin, dev);
if (ret != 0) { if (ret != 0) {
SPDK_ERRLOG("Error building set password command\n"); SPDK_ERRLOG("Error building set password command\n");
return ret; return ret;
} }
ret = opal_cmd_finalize(sess, sess->hsn, sess->tsn, true);
if (ret) {
return ret;
}
ret = opal_send_recv(dev, sess); ret = opal_send_recv(dev, sess);
if (ret) { if (ret) {
return ret; return ret;
@ -1685,10 +1684,9 @@ opal_new_user_passwd(struct spdk_opal_dev *dev, struct opal_session *sess,
} }
static int static int
opal_set_sid_cpin_pin(struct spdk_opal_dev *dev, struct opal_session *sess, void *data) opal_set_sid_cpin_pin(struct spdk_opal_dev *dev, struct opal_session *sess, char *new_passwd)
{ {
uint8_t cpin_uid[OPAL_UID_LENGTH]; uint8_t cpin_uid[OPAL_UID_LENGTH];
const char *new_passwd = data;
struct spdk_opal_key opal_key = {}; struct spdk_opal_key opal_key = {};
int ret; int ret;
@ -1699,14 +1697,10 @@ opal_set_sid_cpin_pin(struct spdk_opal_dev *dev, struct opal_session *sess, void
memcpy(cpin_uid, spdk_opal_uid[UID_C_PIN_SID], OPAL_UID_LENGTH); memcpy(cpin_uid, spdk_opal_uid[UID_C_PIN_SID], OPAL_UID_LENGTH);
if (opal_generic_pw_cmd(sess, opal_key.key, opal_key.key_len, cpin_uid, dev)) { if (opal_build_generic_pw_cmd(sess, opal_key.key, opal_key.key_len, cpin_uid, dev)) {
SPDK_ERRLOG("Error building Set SID cpin\n"); SPDK_ERRLOG("Error building Set SID cpin\n");
return -ERANGE; return -ERANGE;
} }
ret = opal_cmd_finalize(sess, sess->hsn, sess->tsn, true);
if (ret) {
return ret;
}
ret = opal_send_recv(dev, sess); ret = opal_send_recv(dev, sess);
if (ret) { if (ret) {