From: Fam Zheng <famz@redhat.com>
To: Peter Lieven <pl@kamp.de>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCHv2] block/vmdk: add basic .bdrv_check support
Date: Wed, 29 Jan 2014 17:06:35 +0800 [thread overview]
Message-ID: <20140129090635.GA16936@T430.redhat.com> (raw)
In-Reply-To: <1390984456-9429-1-git-send-email-pl@kamp.de>
On Wed, 01/29 09:34, Peter Lieven wrote:
> this adds a basic vmdk corruption check. it should detect severe
> table corruptions and file truncation.
>
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
> v2: - use %PRId64 instead of %ld [Stefan]
> - extend -> extent [Stefan]
> - fixed overlong lines
>
> block/vmdk.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 48 insertions(+)
>
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 99ca60f..e809e2e 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -1942,6 +1942,53 @@ static ImageInfo *vmdk_get_extent_info(VmdkExtent *extent)
> return info;
> }
>
> +static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result,
> + BdrvCheckMode fix)
> +{
> + BDRVVmdkState *s = bs->opaque;
> + VmdkExtent *extent = NULL;
> + int64_t sector_num = 0;
> + int64_t total_sectors = bdrv_getlength(bs) / BDRV_SECTOR_SIZE;
> + int ret;
> + uint64_t cluster_offset;
> +
> + if (fix) {
> + return -ENOTSUP;
> + }
> +
> + for (;;) {
> + if (sector_num >= total_sectors) {
> + return 0;
> + }
> + extent = find_extent(s, sector_num, extent);
> + if (!extent) {
> + fprintf(stderr,
> + "ERROR: could not find extent for sector %" PRId64 "\n",
> + sector_num);
> + break;
> + }
> + ret = get_cluster_offset(bs, extent, NULL,
> + sector_num << BDRV_SECTOR_BITS,
> + 0, &cluster_offset);
> + if (ret == VMDK_ERROR) {
> + fprintf(stderr,
> + "ERROR: could not get cluster_offset for sector %"
> + PRId64 "\n", sector_num);
> + break;
> + }
> + if (ret == VMDK_OK && cluster_offset >= bdrv_getlength(extent->file)) {
> + fprintf(stderr,
> + "ERROR: cluster offset for sector %"
> + PRId64 " points after EOF\n", sector_num);
> + break;
> + }
> + sector_num += extent->cluster_sectors;
> + }
> +
> + result->corruptions++;
> + return 0;
> +}
> +
> static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)
> {
> int i;
> @@ -2015,6 +2062,7 @@ static BlockDriver bdrv_vmdk = {
> .instance_size = sizeof(BDRVVmdkState),
> .bdrv_probe = vmdk_probe,
> .bdrv_open = vmdk_open,
> + .bdrv_check = vmdk_check,
> .bdrv_reopen_prepare = vmdk_reopen_prepare,
> .bdrv_read = vmdk_co_read,
> .bdrv_write = vmdk_co_write,
> --
> 1.7.9.5
>
Reviewed-by: Fam Zheng <famz@redhat.com>
next parent reply other threads:[~2014-01-29 9:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1390984456-9429-1-git-send-email-pl@kamp.de>
2014-01-29 9:06 ` Fam Zheng [this message]
2014-01-29 13:23 ` [Qemu-devel] [PATCHv2] block/vmdk: add basic .bdrv_check support 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=20140129090635.GA16936@T430.redhat.com \
--to=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pl@kamp.de \
--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).