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 11/12] hw/nvme: simplify copy command error handling
Date: Thu, 23 Jun 2022 23:18:20 +0200 [thread overview]
Message-ID: <20220623211821.50534-12-its@irrelevant.dk> (raw)
In-Reply-To: <20220623211821.50534-1-its@irrelevant.dk>
From: Klaus Jensen <k.jensen@samsung.com>
Move error handling down in the call stack to simplify the control flow.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
hw/nvme/ctrl.c | 50 ++++++++++++--------------------------------------
1 file changed, 12 insertions(+), 38 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 5eee730ed0cf..4d6b4c9f00ba 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -2614,7 +2614,7 @@ static void nvme_copy_bh(void *opaque)
qemu_aio_unref(iocb);
}
-static void nvme_copy_cb(void *opaque, int ret);
+static void nvme_do_copy(NvmeCopyAIOCB *iocb);
static void nvme_copy_source_range_parse_format0(void *ranges, int idx,
uint64_t *slba, uint32_t *nlb,
@@ -2726,7 +2726,7 @@ static void nvme_copy_out_completed_cb(void *opaque, int ret)
iocb->idx++;
iocb->slba += nlb;
out:
- nvme_copy_cb(iocb, iocb->ret);
+ nvme_do_copy(iocb);
}
static void nvme_copy_out_cb(void *opaque, int ret)
@@ -2738,16 +2738,8 @@ static void nvme_copy_out_cb(void *opaque, int ret)
size_t mlen;
uint8_t *mbounce;
- if (ret < 0) {
- iocb->ret = ret;
+ if (ret < 0 || iocb->ret < 0 || !ns->lbaf.ms) {
goto out;
- } else if (iocb->ret < 0) {
- goto out;
- }
-
- if (!ns->lbaf.ms) {
- nvme_copy_out_completed_cb(iocb, 0);
- return;
}
nvme_copy_source_range_parse(iocb->ranges, iocb->idx, iocb->format, NULL,
@@ -2766,7 +2758,7 @@ static void nvme_copy_out_cb(void *opaque, int ret)
return;
out:
- nvme_copy_cb(iocb, ret);
+ nvme_copy_out_completed_cb(iocb, ret);
}
static void nvme_copy_in_completed_cb(void *opaque, int ret)
@@ -2860,15 +2852,9 @@ static void nvme_copy_in_completed_cb(void *opaque, int ret)
invalid:
req->status = status;
- iocb->aiocb = NULL;
- if (iocb->bh) {
- qemu_bh_schedule(iocb->bh);
- }
-
- return;
-
+ iocb->ret = -1;
out:
- nvme_copy_cb(iocb, ret);
+ nvme_do_copy(iocb);
}
static void nvme_copy_in_cb(void *opaque, int ret)
@@ -2879,16 +2865,8 @@ static void nvme_copy_in_cb(void *opaque, int ret)
uint64_t slba;
uint32_t nlb;
- if (ret < 0) {
- iocb->ret = ret;
+ if (ret < 0 || iocb->ret < 0 || !ns->lbaf.ms) {
goto out;
- } else if (iocb->ret < 0) {
- goto out;
- }
-
- if (!ns->lbaf.ms) {
- nvme_copy_in_completed_cb(iocb, 0);
- return;
}
nvme_copy_source_range_parse(iocb->ranges, iocb->idx, iocb->format, &slba,
@@ -2904,12 +2882,11 @@ static void nvme_copy_in_cb(void *opaque, int ret)
return;
out:
- nvme_copy_cb(iocb, iocb->ret);
+ nvme_copy_in_completed_cb(iocb, ret);
}
-static void nvme_copy_cb(void *opaque, int ret)
+static void nvme_do_copy(NvmeCopyAIOCB *iocb)
{
- NvmeCopyAIOCB *iocb = opaque;
NvmeRequest *req = iocb->req;
NvmeNamespace *ns = req->ns;
uint64_t slba;
@@ -2917,10 +2894,7 @@ static void nvme_copy_cb(void *opaque, int ret)
size_t len;
uint16_t status;
- if (ret < 0) {
- iocb->ret = ret;
- goto done;
- } else if (iocb->ret < 0) {
+ if (iocb->ret < 0) {
goto done;
}
@@ -2967,6 +2941,7 @@ static void nvme_copy_cb(void *opaque, int ret)
invalid:
req->status = status;
+ iocb->ret = -1;
done:
iocb->aiocb = NULL;
if (iocb->bh) {
@@ -2974,7 +2949,6 @@ done:
}
}
-
static uint16_t nvme_copy(NvmeCtrl *n, NvmeRequest *req)
{
NvmeNamespace *ns = req->ns;
@@ -3060,7 +3034,7 @@ static uint16_t nvme_copy(NvmeCtrl *n, NvmeRequest *req)
BLOCK_ACCT_WRITE);
req->aiocb = &iocb->common;
- nvme_copy_cb(iocb, 0);
+ nvme_do_copy(iocb);
return NVME_NO_COMPLETE;
--
2.36.1
next prev parent reply other threads:[~2022-06-23 21:27 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 ` Klaus Jensen [this message]
2022-06-23 21:18 ` [PATCH 12/12] hw/nvme: align logic of format with flush Klaus Jensen
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-12-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).