diff mbox series

[16/25] block/nvme: Simplify ADMIN queue access

Message ID 20201027135547.374946-17-philmd@redhat.com
State Superseded
Headers show
Series block/nvme: Fix Aarch64 host | expand

Commit Message

Philippe Mathieu-Daudé Oct. 27, 2020, 1:55 p.m. UTC
We don't need to dereference from BDRVNVMeState each time.
Use a NVMeQueuePair pointer to the admin queue and use it.
The nvme_init() becomes easier to review, matching the style
of nvme_add_io_queue().

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

Comments

Eric Auger Oct. 28, 2020, 2:25 p.m. UTC | #1
On 10/27/20 2:55 PM, Philippe Mathieu-Daudé wrote:
> We don't need to dereference from BDRVNVMeState each time.

> Use a NVMeQueuePair pointer to the admin queue and use it.

double "use"
> The nvme_init() becomes easier to review, matching the style

> of nvme_add_io_queue().>

> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Eric Auger <eric.auger@redhat.com>


Eric

> ---

>  block/nvme.c | 12 ++++++------

>  1 file changed, 6 insertions(+), 6 deletions(-)

> 

> diff --git a/block/nvme.c b/block/nvme.c

> index d5df30ec074..2d3648694b0 100644

> --- a/block/nvme.c

> +++ b/block/nvme.c

> @@ -699,6 +699,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,

>                       Error **errp)

>  {

>      BDRVNVMeState *s = bs->opaque;

> +    NVMeQueuePair *q;

>      AioContext *aio_context = bdrv_get_aio_context(bs);

>      int ret;

>      uint64_t cap;

> @@ -781,19 +782,18 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,

>  

>      /* Set up admin queue. */

>      s->queues = g_new(NVMeQueuePair *, 1);

> -    s->queues[INDEX_ADMIN] = nvme_create_queue_pair(s, aio_context, 0,

> -                                                          NVME_QUEUE_SIZE,

> -                                                          errp);

> -    if (!s->queues[INDEX_ADMIN]) {

> +    q = nvme_create_queue_pair(s, aio_context, 0, NVME_QUEUE_SIZE, errp);

> +    if (!q) {

>          ret = -EINVAL;

>          goto out;

>      }

> +    s->queues[INDEX_ADMIN] = q;

>      s->queue_count = 1;

>      QEMU_BUILD_BUG_ON((NVME_QUEUE_SIZE - 1) & 0xF000);

>      regs->aqa = cpu_to_le32(((NVME_QUEUE_SIZE - 1) << AQA_ACQS_SHIFT) |

>                              ((NVME_QUEUE_SIZE - 1) << AQA_ASQS_SHIFT));

> -    regs->asq = cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova);

> -    regs->acq = cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova);

> +    regs->asq = cpu_to_le64(q->sq.iova);

> +    regs->acq = cpu_to_le64(q->cq.iova);

>  

>      /* After setting up all control registers we can enable device now. */

>      regs->cc = cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << CC_IOCQES_SHIFT) |

>
Stefan Hajnoczi Oct. 28, 2020, 3:19 p.m. UTC | #2
On Tue, Oct 27, 2020 at 02:55:38PM +0100, Philippe Mathieu-Daudé wrote:
> We don't need to dereference from BDRVNVMeState each time.
> Use a NVMeQueuePair pointer to the admin queue and use it.
> The nvme_init() becomes easier to review, matching the style
> of nvme_add_io_queue().
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  block/nvme.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

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

Patch

diff --git a/block/nvme.c b/block/nvme.c
index d5df30ec074..2d3648694b0 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -699,6 +699,7 @@  static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
                      Error **errp)
 {
     BDRVNVMeState *s = bs->opaque;
+    NVMeQueuePair *q;
     AioContext *aio_context = bdrv_get_aio_context(bs);
     int ret;
     uint64_t cap;
@@ -781,19 +782,18 @@  static int nvme_init(BlockDriverState *bs, const char *device, int namespace,
 
     /* Set up admin queue. */
     s->queues = g_new(NVMeQueuePair *, 1);
-    s->queues[INDEX_ADMIN] = nvme_create_queue_pair(s, aio_context, 0,
-                                                          NVME_QUEUE_SIZE,
-                                                          errp);
-    if (!s->queues[INDEX_ADMIN]) {
+    q = nvme_create_queue_pair(s, aio_context, 0, NVME_QUEUE_SIZE, errp);
+    if (!q) {
         ret = -EINVAL;
         goto out;
     }
+    s->queues[INDEX_ADMIN] = q;
     s->queue_count = 1;
     QEMU_BUILD_BUG_ON((NVME_QUEUE_SIZE - 1) & 0xF000);
     regs->aqa = cpu_to_le32(((NVME_QUEUE_SIZE - 1) << AQA_ACQS_SHIFT) |
                             ((NVME_QUEUE_SIZE - 1) << AQA_ASQS_SHIFT));
-    regs->asq = cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova);
-    regs->acq = cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova);
+    regs->asq = cpu_to_le64(q->sq.iova);
+    regs->acq = cpu_to_le64(q->cq.iova);
 
     /* After setting up all control registers we can enable device now. */
     regs->cc = cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << CC_IOCQES_SHIFT) |