[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/50] block/nvme: separate nvme_get_free_req cases for coroutine/
From: |
Kevin Wolf |
Subject: |
[PULL 03/50] block/nvme: separate nvme_get_free_req cases for coroutine/non-coroutine context |
Date: |
Fri, 7 Oct 2022 12:47:05 +0200 |
From: Paolo Bonzini <pbonzini@redhat.com>
nvme_get_free_req has very difference semantics when called in
coroutine context (where it waits) and in non-coroutine context
(where it doesn't). Split the two cases to make it clear what
is being requested.
Cc: qemu-block@nongnu.org
Reviewed-by: Alberto Faria <afaria@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20220922084924.201610-2-pbonzini@redhat.com>
[kwolf: Fixed up coding style]
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/nvme.c | 48 ++++++++++++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 01fb28aa63..0870f87bc6 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -293,34 +293,42 @@ static void nvme_kick(NVMeQueuePair *q)
q->need_kick = 0;
}
-/* Find a free request element if any, otherwise:
- * a) if in coroutine context, try to wait for one to become available;
- * b) if not in coroutine, return NULL;
- */
-static NVMeRequest *nvme_get_free_req(NVMeQueuePair *q)
+static NVMeRequest *nvme_get_free_req_nofail_locked(NVMeQueuePair *q)
{
NVMeRequest *req;
- qemu_mutex_lock(&q->lock);
-
- while (q->free_req_head == -1) {
- if (qemu_in_coroutine()) {
- trace_nvme_free_req_queue_wait(q->s, q->index);
- qemu_co_queue_wait(&q->free_req_queue, &q->lock);
- } else {
- qemu_mutex_unlock(&q->lock);
- return NULL;
- }
- }
-
req = &q->reqs[q->free_req_head];
q->free_req_head = req->free_req_next;
req->free_req_next = -1;
-
- qemu_mutex_unlock(&q->lock);
return req;
}
+/* Return a free request element if any, otherwise return NULL. */
+static NVMeRequest *nvme_get_free_req_nowait(NVMeQueuePair *q)
+{
+ QEMU_LOCK_GUARD(&q->lock);
+ if (q->free_req_head == -1) {
+ return NULL;
+ }
+ return nvme_get_free_req_nofail_locked(q);
+}
+
+/*
+ * Wait for a free request to become available if necessary, then
+ * return it.
+ */
+static coroutine_fn NVMeRequest *nvme_get_free_req(NVMeQueuePair *q)
+{
+ QEMU_LOCK_GUARD(&q->lock);
+
+ while (q->free_req_head == -1) {
+ trace_nvme_free_req_queue_wait(q->s, q->index);
+ qemu_co_queue_wait(&q->free_req_queue, &q->lock);
+ }
+
+ return nvme_get_free_req_nofail_locked(q);
+}
+
/* With q->lock */
static void nvme_put_free_req_locked(NVMeQueuePair *q, NVMeRequest *req)
{
@@ -506,7 +514,7 @@ static int nvme_admin_cmd_sync(BlockDriverState *bs,
NvmeCmd *cmd)
AioContext *aio_context = bdrv_get_aio_context(bs);
NVMeRequest *req;
int ret = -EINPROGRESS;
- req = nvme_get_free_req(q);
+ req = nvme_get_free_req_nowait(q);
if (!req) {
return -EBUSY;
}
--
2.37.3
- [PULL 00/50] Block layer patches, Kevin Wolf, 2022/10/07
- [PULL 01/50] Revert "qapi: fix examples of blockdev-add with qcow2", Kevin Wolf, 2022/10/07
- [PULL 02/50] coroutine: Drop coroutine_fn annotation from qemu_coroutine_self(), Kevin Wolf, 2022/10/07
- [PULL 04/50] block: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 08/50] blkverify: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 21/50] vmdk: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 06/50] nbd: remove incorrect coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 07/50] coroutine: remove incorrect coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 03/50] block/nvme: separate nvme_get_free_req cases for coroutine/non-coroutine context,
Kevin Wolf <=
- [PULL 25/50] 9p: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 28/50] quorum: Remove unnecessary forward declaration, Kevin Wolf, 2022/10/07
- [PULL 23/50] coroutine-lock: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 31/50] job.c: API functions not used outside should be static, Kevin Wolf, 2022/10/07
- [PULL 32/50] aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED, Kevin Wolf, 2022/10/07
- [PULL 17/50] curl: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 11/50] nbd: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 15/50] qcow2: add missing coroutine_fn annotations, Kevin Wolf, 2022/10/07
- [PULL 37/50] jobs: use job locks also in the unit tests, Kevin Wolf, 2022/10/07
- [PULL 33/50] job.c: add job_lock/unlock while keeping job.h intact, Kevin Wolf, 2022/10/07