From 2938dc14b01feebd21494361c50a0c0e4c1c5d83 Mon Sep 17 00:00:00 2001 From: Chunyang Hui Date: Thu, 24 Oct 2019 18:14:19 +0800 Subject: [PATCH] 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: Chunyang Hui Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472591 Reviewed-by: Changpeng Liu Reviewed-by: yidong0635 Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- lib/nvme/nvme_opal.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/nvme/nvme_opal.c b/lib/nvme/nvme_opal.c index 94d27ecd9..2933404ef 100644 --- a/lib/nvme/nvme_opal.c +++ b/lib/nvme/nvme_opal.c @@ -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;