diff mbox series

[v7,37/48] nvme: add nvme_check_rw helper

Message ID 20200415055140.466900-38-its@irrelevant.dk
State New
Headers show
Series nvme: support NVMe v1.3d, SGLs and multiple namespaces | expand

Commit Message

Klaus Jensen April 15, 2020, 5:51 a.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/block/nvme.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index c123be10fd0d..ffc49985321b 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -651,6 +651,25 @@  static inline uint16_t nvme_check_bounds(NvmeCtrl *n, uint64_t slba,
     return NVME_SUCCESS;
 }
 
+static uint16_t nvme_check_rw(NvmeCtrl *n, NvmeRequest *req)
+{
+    NvmeNamespace *ns = req->ns;
+    size_t len = req->nlb << nvme_ns_lbads(ns);
+    uint16_t status;
+
+    status = nvme_check_mdts(n, len, req);
+    if (status) {
+        return status;
+    }
+
+    status = nvme_check_bounds(n, req->slba, req->nlb, req);
+    if (status) {
+        return status;
+    }
+
+    return NVME_SUCCESS;
+}
+
 static void nvme_rw_cb(NvmeRequest *req, void *opaque)
 {
     NvmeSQueue *sq = req->sq;
@@ -810,12 +829,7 @@  static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest *req)
     trace_nvme_dev_rw(nvme_req_is_write(req) ? "write" : "read", req->nlb,
                       req->nlb << nvme_ns_lbads(req->ns), req->slba);
 
-    status = nvme_check_mdts(n, len, req);
-    if (status) {
-        goto invalid;
-    }
-
-    status = nvme_check_bounds(n, req->slba, req->nlb, req);
+    status = nvme_check_rw(n, req);
     if (status) {
         goto invalid;
     }