qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 16/25] block/raw-win32: create one QEMUWin32AIOState per BDRVRawState
Date: Wed, 07 May 2014 12:34:08 +0200	[thread overview]
Message-ID: <536A0C20.2090701@redhat.com> (raw)
In-Reply-To: <1399458461-3997-17-git-send-email-stefanha@redhat.com>

Il 07/05/2014 12:27, Stefan Hajnoczi ha scritto:
> Each QEMUWin32AIOState event notifier is associated with an AioContext.
> Since BlockDriverState instances can use different AioContexts we cannot
> continue to use a global QEMUWin32AIOState.
>
> Let each BDRVRawState have its own QEMUWin32AIOState and free it when
> BDRVRawState is closed.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  block/raw-aio.h   |  1 +
>  block/raw-win32.c | 29 ++++++++++++++++-------------
>  block/win32-aio.c |  8 ++++++++
>  3 files changed, 25 insertions(+), 13 deletions(-)
>
> diff --git a/block/raw-aio.h b/block/raw-aio.h
> index 55e0ccc..6269f3d 100644
> --- a/block/raw-aio.h
> +++ b/block/raw-aio.h
> @@ -45,6 +45,7 @@ void laio_attach_aio_context(void *s, AioContext *new_context);
>  #ifdef _WIN32
>  typedef struct QEMUWin32AIOState QEMUWin32AIOState;
>  QEMUWin32AIOState *win32_aio_init(void);
> +void win32_aio_cleanup(QEMUWin32AIOState *aio);
>  int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfile);
>  BlockDriverAIOCB *win32_aio_submit(BlockDriverState *bs,
>          QEMUWin32AIOState *aio, HANDLE hfile,
> diff --git a/block/raw-win32.c b/block/raw-win32.c
> index 064ea31..cf1e9ce 100644
> --- a/block/raw-win32.c
> +++ b/block/raw-win32.c
> @@ -36,8 +36,6 @@
>  #define FTYPE_CD     1
>  #define FTYPE_HARDDISK 2
>
> -static QEMUWin32AIOState *aio;
> -
>  typedef struct RawWin32AIOData {
>      BlockDriverState *bs;
>      HANDLE hfile;
> @@ -300,15 +298,6 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
>
>      raw_parse_flags(flags, &access_flags, &overlapped);
>
> -    if ((flags & BDRV_O_NATIVE_AIO) && aio == NULL) {
> -        aio = win32_aio_init();
> -        if (aio == NULL) {
> -            error_setg(errp, "Could not initialize AIO");
> -            ret = -EINVAL;
> -            goto fail;
> -        }
> -    }
> -
>      if (filename[0] && filename[1] == ':') {
>          snprintf(s->drive_path, sizeof(s->drive_path), "%c:\\", filename[0]);
>      } else if (filename[0] == '\\' && filename[1] == '\\') {
> @@ -335,13 +324,21 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
>      }
>
>      if (flags & BDRV_O_NATIVE_AIO) {
> -        ret = win32_aio_attach(aio, s->hfile);
> +        s->aio = win32_aio_init();
> +        if (s->aio == NULL) {
> +            CloseHandle(s->hfile);
> +            error_setg(errp, "Could not initialize AIO");
> +            ret = -EINVAL;
> +            goto fail;
> +        }
> +
> +        ret = win32_aio_attach(s->aio, s->hfile);
>          if (ret < 0) {
> +            win32_aio_cleanup(s->aio);
>              CloseHandle(s->hfile);
>              error_setg_errno(errp, -ret, "Could not enable AIO");
>              goto fail;
>          }
> -        s->aio = aio;
>      }
>
>      raw_probe_alignment(bs);
> @@ -389,6 +386,12 @@ static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
>  static void raw_close(BlockDriverState *bs)
>  {
>      BDRVRawState *s = bs->opaque;
> +
> +    if (s->aio) {
> +        win32_aio_cleanup(s->aio);
> +        s->aio = NULL;
> +    }
> +
>      CloseHandle(s->hfile);
>      if (bs->open_flags & BDRV_O_TEMPORARY) {
>          unlink(bs->filename);
> diff --git a/block/win32-aio.c b/block/win32-aio.c
> index 5d1d199..b43b166 100644
> --- a/block/win32-aio.c
> +++ b/block/win32-aio.c
> @@ -204,3 +204,11 @@ out_free_state:
>      g_free(s);
>      return NULL;
>  }
> +
> +void win32_aio_cleanup(QEMUWin32AIOState *aio)
> +{
> +    qemu_aio_set_event_notifier(&aio->e, NULL);
> +    CloseHandle(aio->hIOCP);
> +    event_notifier_cleanup(&aio->e);
> +    g_free(aio);
> +}
>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

  reply	other threads:[~2014-05-07 10:34 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 10:27 [Qemu-devel] [PATCH v2 00/25] dataplane: use QEMU block layer Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 01/25] block: use BlockDriverState AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 02/25] block: acquire AioContext in bdrv_*_all() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 03/25] block: acquire AioContext in bdrv_drain_all() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 04/25] block: add bdrv_set_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 05/25] blkdebug: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 06/25] blkverify: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 07/25] curl: " Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 08/25] gluster: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 09/25] iscsi: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 14:14   ` Peter Lieven
2014-05-08 13:40     ` Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 10/25] nbd: " Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 11/25] nfs: " Stefan Hajnoczi
2014-05-07 14:12   ` Peter Lieven
2014-05-08 13:46     ` Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 12/25] qed: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 13/25] quorum: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 11:24   ` Benoît Canet
2014-05-08 11:24     ` Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 14/25] block/raw-posix: " Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 15/25] block/linux-aio: fix memory and fd leak Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 16/25] block/raw-win32: create one QEMUWin32AIOState per BDRVRawState Stefan Hajnoczi
2014-05-07 10:34   ` Paolo Bonzini [this message]
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 17/25] block/raw-win32: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:35   ` Paolo Bonzini
2014-05-08 11:25     ` Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 18/25] rbd: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 19/25] sheepdog: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 20/25] ssh: use BlockDriverState's AioContext Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 21/25] vmdk: implement .bdrv_detach/attach_aio_context() Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 22/25] dataplane: use the QEMU block layer for I/O Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 23/25] dataplane: delete IOQueue since it is no longer used Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 24/25] dataplane: implement async flush Stefan Hajnoczi
2014-05-07 10:27 ` [Qemu-devel] [PATCH v2 25/25] raw-posix: drop raw_get_aio_fd() since it is no longer used Stefan Hajnoczi

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=536A0C20.2090701@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).