[Qemu-devel] [PATCH 08/11] qed: introduce bdrv_qed_init_state

Paolo Bonzini posted 11 patches 8 years, 7 months ago
[Qemu-devel] [PATCH 08/11] qed: introduce bdrv_qed_init_state
Posted by Paolo Bonzini 8 years, 7 months ago
This will be used in the next patch, which will call bdrv_qed_do_open
with a CoMutex taken.  bdrv_qed_init_state provides a nice place to
initialize it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
        RFC->v2: new

 block/qed.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index db390efdbd..8228a50f68 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -363,6 +363,15 @@ static void coroutine_fn bdrv_qed_co_drain(BlockDriverState *bs)
     }
 }
 
+static void bdrv_qed_init_state(BlockDriverState *bs)
+{
+    BDRVQEDState *s = bs->opaque;
+
+    memset(s, 0, sizeof(BDRVQEDState));
+    s->bs = bs;
+    qemu_co_queue_init(&s->allocating_write_reqs);
+}
+
 static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flags,
                             Error **errp)
 {
@@ -371,9 +380,6 @@ static int bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flags,
     int64_t file_size;
     int ret;
 
-    s->bs = bs;
-    qemu_co_queue_init(&s->allocating_write_reqs);
-
     ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header));
     if (ret < 0) {
         return ret;
@@ -507,6 +513,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
         return -EINVAL;
     }
 
+    bdrv_qed_init_state(bs);
     return bdrv_qed_do_open(bs, options, flags, errp);
 }
 
@@ -1461,7 +1468,7 @@ static void bdrv_qed_invalidate_cache(BlockDriverState *bs, Error **errp)
 
     bdrv_qed_close(bs);
 
-    memset(s, 0, sizeof(BDRVQEDState));
+    bdrv_qed_init_state(bs);
     ret = bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
-- 
2.13.0



Re: [Qemu-devel] [PATCH 08/11] qed: introduce bdrv_qed_init_state
Posted by Eric Blake 8 years, 7 months ago
On 06/29/2017 08:27 AM, Paolo Bonzini wrote:
> This will be used in the next patch, which will call bdrv_qed_do_open
> with a CoMutex taken.  bdrv_qed_init_state provides a nice place to
> initialize it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>         RFC->v2: new
> 
>  block/qed.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH 08/11] qed: introduce bdrv_qed_init_state
Posted by Fam Zheng 8 years, 6 months ago
On Thu, 06/29 15:27, Paolo Bonzini wrote:
> diff --git a/block/qed.c b/block/qed.c
> index db390efdbd..8228a50f68 100644
> --- a/block/qed.c
> +++ b/block/qed.c
> @@ -363,6 +363,15 @@ static void coroutine_fn bdrv_qed_co_drain(BlockDriverState *bs)
>      }
>  }
>  
> +static void bdrv_qed_init_state(BlockDriverState *bs)
> +{
> +    BDRVQEDState *s = bs->opaque;

This line should be in the next patch, to keep the compiler happy
(-Wunused-variable). I'll fix it when sending pull request.

> +
> +    memset(s, 0, sizeof(BDRVQEDState));
> +    s->bs = bs;
> +    qemu_co_queue_init(&s->allocating_write_reqs);
> +}
> +

Fam