Commit 2938dc14 authored by Chunyang Hui's avatar Chunyang Hui Committed by Tomasz Zawadzki
Browse files

Opal: Add clean response buffer process



For nvme Opal, most of the commands are a combination
of security send and receive. There are cases that
application send the security send command and is
shutdown before sending security receive command.
In these cases, when the application restarts, an opal
command will send security send command again and will
cause command sequence error.

Thus, we do a receive first and memset the response
buffer before security send and receive.

Change-Id: Iba02c8074457919816ca576cd00ef9eee6d6dadf
Signed-off-by: default avatarChunyang Hui <chunyang.hui@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472591


Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avataryidong0635 <dongx.yi@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent f1d0fc75
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -55,6 +55,23 @@ opal_error_to_human(int error)
	return spdk_opal_errors[error];
}

static int
opal_flush_response_buffer(struct spdk_opal_dev *dev)
{
	void *response = dev->resp;
	int ret = 0;

	ret = spdk_nvme_ctrlr_security_receive(dev->dev_handler, SPDK_SCSI_SECP_TCG, dev->comid,
					       0, response, IO_BUFFER_LENGTH);
	if (ret) {
		SPDK_ERRLOG("Security Receive Error on dev = %p\n", dev);
		return ret;
	}

	memset(response, 0, IO_BUFFER_LENGTH);
	return 0;
}

static int
opal_send_cmd(struct spdk_opal_dev *dev)
{
@@ -104,6 +121,11 @@ opal_send_recv(struct spdk_opal_dev *dev, spdk_opal_cb cb, void *data)
{
	int ret;

	ret = opal_flush_response_buffer(dev);
	if (ret) {
		return ret;
	}

	ret = opal_send_cmd(dev);
	if (ret) {
		return ret;