[17/17] block/nvme: Check BDRVNVMeState::plugged out of nvme_process_completion
diff mbox series

Message ID 20200625184838.28172-18-philmd@redhat.com
State New
Headers show
Series
  • block/nvme: Various cleanups required to use multiple queues
Related show

Commit Message

Philippe Mathieu-Daudé June 25, 2020, 6:48 p.m. UTC
The queues are tied to the hardware, not to the block driver.
As this function doesn't need to know about the BDRVNVMeState,
move the 'plugged' check to the caller.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 block/nvme.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Stefan Hajnoczi June 26, 2020, 12:46 p.m. UTC | #1
On Thu, Jun 25, 2020 at 08:48:38PM +0200, Philippe Mathieu-Daudé wrote:
> @@ -529,10 +529,13 @@ static bool nvme_poll_queues(BDRVNVMeState *s)
>      bool progress = false;
>      int i;
>  
> +    if (s->plugged) {
> +        return false;
> +    }
>      for (i = 0; i < s->nr_queues; i++) {
>          NVMeQueuePair *q = s->queues[i];
>          qemu_mutex_lock(&q->lock);
> -        while (nvme_process_completion(s, q)) {
> +        while (nvme_process_completion(q)) {
>              /* Keep polling */
>              progress = true;
>          }

This code transformation is correct but I hope plugged can be removed
from the completion code path in the future since its purpose is for
batching submissions.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

Patch
diff mbox series

diff --git a/block/nvme.c b/block/nvme.c
index b335dfdb73..03658776f4 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -318,7 +318,7 @@  static inline int nvme_translate_error(const NvmeCqe *c)
 }
 
 /* With q->lock */
-static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q)
+static bool nvme_process_completion(NVMeQueuePair *q)
 {
     bool progress = false;
     NVMeRequest *preq;
@@ -326,7 +326,7 @@  static bool nvme_process_completion(BDRVNVMeState *s, NVMeQueuePair *q)
     NvmeCqe *c;
 
     trace_nvme_process_completion(q->index, q->inflight);
-    if (q->busy || s->plugged) {
+    if (q->busy) {
         trace_nvme_process_completion_queue_busy(q->index);
         return false;
     }
@@ -408,8 +408,8 @@  static void nvme_submit_command(BDRVNVMeState *s, NVMeQueuePair *q,
     q->need_kick++;
     if (!s->plugged) {
         nvme_kick(q);
+        nvme_process_completion(q);
     }
-    nvme_process_completion(s, q);
     qemu_mutex_unlock(&q->lock);
 }
 
@@ -529,10 +529,13 @@  static bool nvme_poll_queues(BDRVNVMeState *s)
     bool progress = false;
     int i;
 
+    if (s->plugged) {
+        return false;
+    }
     for (i = 0; i < s->nr_queues; i++) {
         NVMeQueuePair *q = s->queues[i];
         qemu_mutex_lock(&q->lock);
-        while (nvme_process_completion(s, q)) {
+        while (nvme_process_completion(q)) {
             /* Keep polling */
             progress = true;
         }
@@ -1314,7 +1317,7 @@  static void nvme_aio_unplug(BlockDriverState *bs)
         NVMeQueuePair *q = s->queues[i];
         qemu_mutex_lock(&q->lock);
         nvme_kick(q);
-        nvme_process_completion(s, q);
+        nvme_process_completion(q);
         qemu_mutex_unlock(&q->lock);
     }
 }