qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hanna Reitz <hreitz@redhat.com>
To: Viktor Prutyanov <viktor.prutyanov@phystech.edu>,
	philmd@redhat.com, kwolf@redhat.com, sw@weilnetz.de,
	yan@daynix.com, qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: Helge Konetzka <hk@zapateado.de>
Subject: Re: [PATCH v4] block/file-win32: add reopen handlers
Date: Wed, 25 Aug 2021 09:33:53 +0200	[thread overview]
Message-ID: <73536e56-35d9-03c0-2d7d-51d2adb4a7c1@redhat.com> (raw)
In-Reply-To: <20210824234817.13343-1-viktor.prutyanov@phystech.edu>

On 25.08.21 01:48, Viktor Prutyanov wrote:
> Make 'qemu-img commit' work on Windows.
>
> Command 'commit' requires reopening backing file in RW mode. So,
> add reopen prepare/commit/abort handlers and change dwShareMode
> for CreateFile call in order to allow further read/write reopening.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/418
>
> Suggested-by: Hanna Reitz <hreitz@redhat.com>
> Signed-off-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>
> Tested-by: Helge Konetzka <hk@zapateado.de>
> ---
>   v2:
>      - fix indentation in raw_reopen_prepare
>      - free rs if raw_reopen_prepare fails
>   v3:
>      - restore suggested-by field missed in v2
>   v4:
>      - add file type check
>      - add comment about options
>      - replace rs check with assert in raw_reopen_commit
>
>   block/file-win32.c | 100 ++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 99 insertions(+), 1 deletion(-)
>
> diff --git a/block/file-win32.c b/block/file-win32.c
> index 2642088bd6..8320495f2b 100644
> --- a/block/file-win32.c
> +++ b/block/file-win32.c

[...]

> @@ -634,6 +638,96 @@ static int coroutine_fn raw_co_create_opts(BlockDriver *drv,
>       return raw_co_create(&options, errp);
>   }
>   
> +static int raw_reopen_prepare(BDRVReopenState *state,
> +                              BlockReopenQueue *queue, Error **errp)
> +{
> +    BDRVRawState *s = state->bs->opaque;
> +    BDRVRawReopenState *rs;
> +    int access_flags;
> +    DWORD overlapped;
> +    int ret = 0;
> +
> +    if (s->type != FTYPE_FILE) {
> +        error_setg(errp, "Can only reopen files");
> +        return -EINVAL;
> +    }
> +
> +    rs = g_new0(BDRVRawReopenState, 1);
> +
> +    /*
> +     * We do not support changing any options (only flags). By leaving
> +     * all options in state->options, we tell the generic reopen code
> +     * that we do not support changing any of them, so it will verify
> +     * that their values did not change.
> +     */
> +
> +    raw_parse_flags(state->flags, s->aio != NULL, &access_flags, &overlapped);
> +    rs->hfile = CreateFile(state->bs->filename, access_flags,
> +                           FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
> +                           OPEN_EXISTING, overlapped, NULL);
> +
> +    if (rs->hfile == INVALID_HANDLE_VALUE) {
> +        int err = GetLastError();
> +
> +        error_setg_win32(errp, err, "Could not reopen '%s'",
> +                         state->bs->filename);
> +        if (err == ERROR_ACCESS_DENIED) {
> +            ret = -EACCES;
> +        } else {
> +            ret = -EINVAL;
> +        }
> +        goto fail;
> +    }
> +
> +    if (s->aio) {
> +        ret = win32_aio_attach(s->aio, rs->hfile);
> +        if (ret < 0) {
> +            error_setg_errno(errp, -ret, "Could not enable AIO");
> +            goto fail;

I believe if we fail here, we’ve already opened rs->hfile, so we must 
close it or we’d leak it.

(Sorry I missed this in my v3 review :/)

Hanna

> +        }
> +    }
> +
> +    state->opaque = rs;
> +
> +    return 0;
> +
> +fail:
> +    g_free(rs);
> +    state->opaque = NULL;
> +
> +    return ret;
> +}



      reply	other threads:[~2021-08-25  7:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 23:48 [PATCH v4] block/file-win32: add reopen handlers Viktor Prutyanov
2021-08-25  7:33 ` Hanna Reitz [this message]

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=73536e56-35d9-03c0-2d7d-51d2adb4a7c1@redhat.com \
    --to=hreitz@redhat.com \
    --cc=hk@zapateado.de \
    --cc=kwolf@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    --cc=viktor.prutyanov@phystech.edu \
    --cc=yan@daynix.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).