diff mbox series

[16/17] hw/block/nvme: add nvme_check_rw helper

Message ID 20200629195017.1217056-17-its@irrelevant.dk
State New
Headers show
Series [01/17] hw/block/nvme: memset preallocated requests structures | expand

Commit Message

Klaus Jensen June 29, 2020, 7:50 p.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

Move various request checks to a separate function.

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

Patch

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index d836319f068a..ec08841f74b6 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -632,6 +632,28 @@  static inline uint16_t nvme_check_bounds(NvmeCtrl *n, NvmeNamespace *ns,
     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);
+    if (status) {
+        trace_pci_nvme_err_mdts(nvme_cid(req), len);
+        return status;
+    }
+
+    status = nvme_check_bounds(n, ns, req->slba, req->nlb);
+    if (status) {
+        trace_pci_nvme_err_invalid_lba_range(req->slba, req->nlb,
+                                             ns->id_ns.nsze);
+        return status;
+    }
+
+    return NVME_SUCCESS;
+}
+
 static void nvme_rw_cb(NvmeRequest *req, void *opaque)
 {
     NvmeSQueue *sq = req->sq;
@@ -822,16 +844,8 @@  static uint16_t nvme_rw(NvmeCtrl *n, NvmeRequest *req)
     trace_pci_nvme_rw(nvme_req_is_write(req) ? "write" : "read", req->nlb,
                       len, req->slba);
 
-    status = nvme_check_mdts(n, len);
+    status = nvme_check_rw(n, req);
     if (status) {
-        trace_pci_nvme_err_mdts(nvme_cid(req), len);
-        goto invalid;
-    }
-
-    status = nvme_check_bounds(n, ns, req->slba, req->nlb);
-    if (status) {
-        trace_pci_nvme_err_invalid_lba_range(req->slba, req->nlb,
-                                             ns->id_ns.nsze);
         goto invalid;
     }