aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-05-31 12:23:48 -0400
committerJens Axboe <axboe@kernel.dk>2018-06-08 14:51:09 -0400
commitf39ae4719b1c33d048aa4d3c284d82ecf252742b (patch)
tree43973b2767d46325876629ab6f2cd7fcabaf8b7a
parent28dec870aaf704af1421ac014f7f8abf4cac7c69 (diff)
nvmet: return all zeroed buffer when we can't find an active namespace
Quote from Figure 106 in NVMe 1.3a: The Identify Namespace data structure is returned to the host for the namespace specified in the Namespace Identifier (CDW1.NSID) field if it is an active NSID. If the specified namespace is not an active NSID, then the controller returns a zero filled data structure. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Sagi Grimberg <sagi@rimberg.me> Reviewed-by: Max Gurtovoy <maxg@mellanox.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--drivers/nvme/target/admin-cmd.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index ead8fbe6922e..962532842769 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -270,8 +270,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
270 struct nvme_id_ns *id; 270 struct nvme_id_ns *id;
271 u16 status = 0; 271 u16 status = 0;
272 272
273 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid); 273 if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) {
274 if (!ns) {
275 status = NVME_SC_INVALID_NS | NVME_SC_DNR; 274 status = NVME_SC_INVALID_NS | NVME_SC_DNR;
276 goto out; 275 goto out;
277 } 276 }
@@ -279,9 +278,14 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
279 id = kzalloc(sizeof(*id), GFP_KERNEL); 278 id = kzalloc(sizeof(*id), GFP_KERNEL);
280 if (!id) { 279 if (!id) {
281 status = NVME_SC_INTERNAL; 280 status = NVME_SC_INTERNAL;
282 goto out_put_ns; 281 goto out;
283 } 282 }
284 283
284 /* return an all zeroed buffer if we can't find an active namespace */
285 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
286 if (!ns)
287 goto done;
288
285 /* 289 /*
286 * nuse = ncap = nsze isn't always true, but we have no way to find 290 * nuse = ncap = nsze isn't always true, but we have no way to find
287 * that out from the underlying device. 291 * that out from the underlying device.
@@ -306,11 +310,10 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
306 310
307 id->lbaf[0].ds = ns->blksize_shift; 311 id->lbaf[0].ds = ns->blksize_shift;
308 312
313 nvmet_put_namespace(ns);
314done:
309 status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id)); 315 status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));
310
311 kfree(id); 316 kfree(id);
312out_put_ns:
313 nvmet_put_namespace(ns);
314out: 317out:
315 nvmet_req_complete(req, status); 318 nvmet_req_complete(req, status);
316} 319}