All of lore.kernel.org
 help / color / mirror / Atom feed
From: Klaus Jensen <its@irrelevant.dk>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Keith Busch <kbusch@kernel.org>,
	Klaus Jensen <its@irrelevant.dk>,
	Klaus Jensen <k.jensen@samsung.com>
Subject: [PATCH 12/12] hw/nvme: align logic of format with flush
Date: Thu, 23 Jun 2022 23:18:21 +0200	[thread overview]
Message-ID: <20220623211821.50534-13-its@irrelevant.dk> (raw)
In-Reply-To: <20220623211821.50534-1-its@irrelevant.dk>

From: Klaus Jensen <k.jensen@samsung.com>

Use the same logic in format as in flush, saving a bh scheduling at the
start of the operation and moving completion handling to a separately
invoked bottom halve.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 4d6b4c9f00ba..0e6f4d71134b 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -5608,8 +5608,6 @@ typedef struct NvmeFormatAIOCB {
     uint8_t pil;
 } NvmeFormatAIOCB;
 
-static void nvme_format_bh(void *opaque);
-
 static void nvme_format_cancel(BlockAIOCB *aiocb)
 {
     NvmeFormatAIOCB *iocb = container_of(aiocb, NvmeFormatAIOCB, common);
@@ -5628,6 +5626,17 @@ static const AIOCBInfo nvme_format_aiocb_info = {
     .get_aio_context = nvme_get_aio_context,
 };
 
+static void nvme_format_bh(void *opaque)
+{
+    NvmeFormatAIOCB *iocb = opaque;
+
+    iocb->common.cb(iocb->common.opaque, iocb->ret);
+
+    qemu_bh_delete(iocb->bh);
+    iocb->bh = NULL;
+    qemu_aio_unref(iocb);
+}
+
 static void nvme_format_set(NvmeNamespace *ns, uint8_t lbaf, uint8_t mset,
                             uint8_t pi, uint8_t pil)
 {
@@ -5642,6 +5651,8 @@ static void nvme_format_set(NvmeNamespace *ns, uint8_t lbaf, uint8_t mset,
     nvme_ns_init_format(ns);
 }
 
+static void nvme_do_format(NvmeFormatAIOCB *iocb);
+
 static void nvme_format_ns_cb(void *opaque, int ret)
 {
     NvmeFormatAIOCB *iocb = opaque;
@@ -5651,6 +5662,8 @@ static void nvme_format_ns_cb(void *opaque, int ret)
     if (ret < 0) {
         iocb->ret = ret;
         goto done;
+    } else if (iocb->ret < 0) {
+        goto done;
     }
 
     assert(ns);
@@ -5672,8 +5685,7 @@ static void nvme_format_ns_cb(void *opaque, int ret)
     iocb->offset = 0;
 
 done:
-    iocb->aiocb = NULL;
-    qemu_bh_schedule(iocb->bh);
+    nvme_do_format(iocb);
 }
 
 static uint16_t nvme_format_check(NvmeNamespace *ns, uint8_t lbaf, uint8_t pi)
@@ -5697,16 +5709,15 @@ static uint16_t nvme_format_check(NvmeNamespace *ns, uint8_t lbaf, uint8_t pi)
     return NVME_SUCCESS;
 }
 
-static void nvme_format_bh(void *opaque)
+static void nvme_do_format(NvmeFormatAIOCB *iocb)
 {
-    NvmeFormatAIOCB *iocb = opaque;
     NvmeRequest *req = iocb->req;
     NvmeCtrl *n = nvme_ctrl(req);
     uint16_t status;
     int i;
 
     if (iocb->ret < 0) {
-        goto done;
+        goto out;
     }
 
     if (iocb->broadcast) {
@@ -5720,26 +5731,23 @@ static void nvme_format_bh(void *opaque)
     }
 
     if (!iocb->ns) {
-        goto done;
+        goto out;
     }
 
     status = nvme_format_check(iocb->ns, iocb->lbaf, iocb->pi);
     if (status) {
         req->status = status;
-        goto done;
+        goto out;
     }
 
     iocb->ns->status = NVME_FORMAT_IN_PROGRESS;
     nvme_format_ns_cb(iocb, 0);
     return;
 
-done:
-    qemu_bh_delete(iocb->bh);
-    iocb->bh = NULL;
-
-    iocb->common.cb(iocb->common.opaque, iocb->ret);
-
-    qemu_aio_unref(iocb);
+out:
+    if (iocb->bh) {
+        qemu_bh_schedule(iocb->bh);
+    }
 }
 
 static uint16_t nvme_format(NvmeCtrl *n, NvmeRequest *req)
@@ -5786,7 +5794,7 @@ static uint16_t nvme_format(NvmeCtrl *n, NvmeRequest *req)
     }
 
     req->aiocb = &iocb->common;
-    qemu_bh_schedule(iocb->bh);
+    nvme_do_format(iocb);
 
     return NVME_NO_COMPLETE;
 
@@ -5794,6 +5802,7 @@ out:
     qemu_bh_delete(iocb->bh);
     iocb->bh = NULL;
     qemu_aio_unref(iocb);
+
     return status;
 }
 
-- 
2.36.1



  parent reply	other threads:[~2022-06-23 21:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 21:18 [PATCH 00/12] hw/nvme: misc fixes and updates Klaus Jensen
2022-06-23 21:18 ` [PATCH 01/12] hw/nvme: fix incorrect use of errp/local_err Klaus Jensen
2022-06-23 21:18 ` [PATCH 02/12] hw/nvme: remove redundant passing of PCIDevice Klaus Jensen
2022-06-23 21:18 ` [PATCH 03/12] hw/nvme: cleanup error reporting in nvme_init_pci() Klaus Jensen
2022-06-23 21:18 ` [PATCH 04/12] hw/nvme: fix numzrwa handling Klaus Jensen
2022-06-23 21:18 ` [PATCH 05/12] hw/nvme: fix accidental reintroduction of redundant code Klaus Jensen
2022-06-23 21:18 ` [PATCH 06/12] hw/nvme: fix cancellation of format operations Klaus Jensen
2022-06-23 21:18 ` [PATCH 07/12] hw/nvme: fix flush cancel Klaus Jensen
2022-06-23 21:18 ` [PATCH 08/12] hw/nvme: rework flush bh scheduling Klaus Jensen
2022-06-23 21:18 ` [PATCH 09/12] hw/nvme: improve cancellation handling in zone reset Klaus Jensen
2022-06-23 21:18 ` [PATCH 10/12] hw/nvme: improve cancellation handling in dsm Klaus Jensen
2022-06-23 21:18 ` [PATCH 11/12] hw/nvme: simplify copy command error handling Klaus Jensen
2022-06-23 21:18 ` Klaus Jensen [this message]
2022-07-14  5:37 ` [PATCH 00/12] hw/nvme: misc fixes and updates Klaus Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220623211821.50534-13-its@irrelevant.dk \
    --to=its@irrelevant.dk \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.