From a1d83c72bca58f7b5bbc9afe3c080c272a996c12 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 26 Aug 2016 12:43:24 -0700 Subject: [PATCH] nvmf: treat DSM attribute as bitfield The Dataset Management command allows several operations to be specified at once; the virtual controller only supports deallocate for now, but it should just ignore the other bits in order to be spec compliant: "If the Dataset Management command is supported, all combinations of attributes [...] may be set". The spec also explicitly states that it is acceptable for controllers to choose to take no action based on information provided, so not implementing the other attributes is fine. Change-Id: Ia989dc1faa9c852660bf1299ea18fa8e7bdf4053 Signed-off-by: Daniel Verkamp --- lib/nvmf/virtual.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/nvmf/virtual.c b/lib/nvmf/virtual.c index e9aa5eeea..bbb7c97d2 100644 --- a/lib/nvmf/virtual.c +++ b/lib/nvmf/virtual.c @@ -446,10 +446,11 @@ nvmf_virtual_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_nvmf_request *req struct spdk_scsi_unmap_bdesc *unmap; struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl; + bool async = false; nr = ((cmd->cdw10 & 0x000000ff) + 1); attribute = cmd->cdw11 & 0x00000007; - if (attribute == SPDK_NVME_DSM_ATTR_DEALLOCATE) { + if (attribute & SPDK_NVME_DSM_ATTR_DEALLOCATE) { struct spdk_nvme_dsm_range *dsm_range = (struct spdk_nvme_dsm_range *)req->data; unmap = calloc(nr, sizeof(*unmap)); if (unmap == NULL) { @@ -467,11 +468,13 @@ nvmf_virtual_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_nvmf_request *req response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR; return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; } - } else { - SPDK_ERRLOG("dsm attribute:%x does not supported yet\n", attribute); - response->status.sc = SPDK_NVME_SC_INVALID_OPCODE; + async = true; } - return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS; + + if (async) { + return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS; + } + return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; } static int