From: Fam Zheng <famz@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/2] vmdk: Fix error for JSON descriptor file names
Date: Thu, 4 Dec 2014 09:08:25 +0800 [thread overview]
Message-ID: <20141204010825.GA21315@ad.nay.redhat.com> (raw)
In-Reply-To: <1417615043-26174-2-git-send-email-mreitz@redhat.com>
On Wed, 12/03 14:57, Max Reitz wrote:
> If vmdk blindly tries to use path_combine() using bs->file->filename as
> the base file name, this will result in a bad error message for JSON
> file names when calling bdrv_open(). It is better to only try
> bs->file->exact_filename; if that is empty, bs->file->filename will be
> useless for path_combine() and an error should be emitted (containing
> bs->file->filename because desc_file_path (which is
> bs->file->exact_filename) is empty).
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 2 +-
> block/vmdk.c | 10 +++++++++-
> include/block/block.h | 1 +
> 3 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/block.c b/block.c
> index 591fbe4..239ae5f 100644
> --- a/block.c
> +++ b/block.c
> @@ -229,7 +229,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
> }
>
> /* check if the path starts with "<protocol>:" */
> -static int path_has_protocol(const char *path)
> +int path_has_protocol(const char *path)
> {
> const char *p;
>
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 2cbfd3e..65413a1 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -818,6 +818,14 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
> goto next_line;
> }
>
> + if (!path_is_absolute(fname) && !path_has_protocol(fname) &&
If I read the VMDK spec correctly, fname can't have protocol (as a format spec
it hasn't a single word on protocol :). But it's not wrong to check. I continue
reading thinking it as "true".
fname, on the other hand, is in most cases a relative path. In this case, this
condition falls to desc_file_path, which is bs->file->exact_filename. This will
be non-empty for local files, so the path_combine below will work.
If fname is absolute, path_combine will also work.
So it is correct.
> + !desc_file_path[0])
> + {
> + error_setg(errp, "Cannot use relative extent paths with VMDK "
> + "descriptor file '%s'", bs->file->filename);
> + return -EINVAL;
> + }
> +
> path_combine(extent_path, sizeof(extent_path),
> desc_file_path, fname);
> extent_file = NULL;
> @@ -894,7 +902,7 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
> }
> s->create_type = g_strdup(ct);
> s->desc_offset = 0;
> - ret = vmdk_parse_extents(buf, bs, bs->file->filename, errp);
> + ret = vmdk_parse_extents(buf, bs, bs->file->exact_filename, errp);
> exit:
> return ret;
> }
> diff --git a/include/block/block.h b/include/block/block.h
> index 610be9f..919c8f5 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -401,6 +401,7 @@ void bdrv_get_full_backing_filename(BlockDriverState *bs,
> char *dest, size_t sz);
> int bdrv_is_snapshot(BlockDriverState *bs);
>
> +int path_has_protocol(const char *path);
Exporting path_has_protocol could be a separate patch but I don't have a strong
objection as this patch is still short.
Reviewed-by: Fam Zheng <famz@redhat.com>
> int path_is_absolute(const char *path);
> void path_combine(char *dest, int dest_size,
> const char *base_path,
> --
> 1.9.3
>
next prev parent reply other threads:[~2014-12-04 1:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-03 13:57 [Qemu-devel] [PATCH v2 0/2] vmdk: Fix error for JSON descriptor file names Max Reitz
2014-12-03 13:57 ` [Qemu-devel] [PATCH v2 1/2] " Max Reitz
2014-12-04 1:08 ` Fam Zheng [this message]
2014-12-03 13:57 ` [Qemu-devel] [PATCH v2 2/2] iotests: Add test for vmdk JSON " Max Reitz
2014-12-04 1:09 ` Fam Zheng
2014-12-12 13:15 ` [Qemu-devel] [PATCH v2 0/2] vmdk: Fix error for JSON descriptor " 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=20141204010825.GA21315@ad.nay.redhat.com \
--to=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@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).