|
|
9ae3a8 |
From d78a26ac572e339d115c3485d3a19ead0e9d4dcf Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <d78a26ac572e339d115c3485d3a19ead0e9d4dcf.1418766606.git.jen@redhat.com>
|
|
|
9ae3a8 |
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
|
|
|
9ae3a8 |
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
|
|
|
9ae3a8 |
From: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 4 Dec 2014 00:05:02 -0600
|
|
|
9ae3a8 |
Subject: [CHANGE 08/31] block/vmdk: add basic .bdrv_check support
|
|
|
9ae3a8 |
To: rhvirt-patches@redhat.com,
|
|
|
9ae3a8 |
jen@redhat.com
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1417651524-18041-9-git-send-email-famz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 62681
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH v5 08/30] block/vmdk: add basic .bdrv_check support
|
|
|
9ae3a8 |
Bugzilla: 1134251
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Peter Lieven <pl@kamp.de>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
this adds a basic vmdk corruption check. it should detect severe
|
|
|
9ae3a8 |
table corruptions and file truncation.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Peter Lieven <pl@kamp.de>
|
|
|
9ae3a8 |
Reviewed-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit f43aa8e18ad83508c2786403e7230a584d357c8e)
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vmdk.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
1 file changed, 48 insertions(+)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/vmdk.c b/block/vmdk.c
|
|
|
9ae3a8 |
index 7ea3aef..eda2962 100644
|
|
|
9ae3a8 |
--- a/block/vmdk.c
|
|
|
9ae3a8 |
+++ b/block/vmdk.c
|
|
|
9ae3a8 |
@@ -1944,6 +1944,53 @@ static ImageInfo *vmdk_get_extent_info(VmdkExtent *extent)
|
|
|
9ae3a8 |
return info;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result,
|
|
|
9ae3a8 |
+ BdrvCheckMode fix)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BDRVVmdkState *s = bs->opaque;
|
|
|
9ae3a8 |
+ VmdkExtent *extent = NULL;
|
|
|
9ae3a8 |
+ int64_t sector_num = 0;
|
|
|
9ae3a8 |
+ int64_t total_sectors = bdrv_getlength(bs) / BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
+ int ret;
|
|
|
9ae3a8 |
+ uint64_t cluster_offset;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (fix) {
|
|
|
9ae3a8 |
+ return -ENOTSUP;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (;;) {
|
|
|
9ae3a8 |
+ if (sector_num >= total_sectors) {
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ extent = find_extent(s, sector_num, extent);
|
|
|
9ae3a8 |
+ if (!extent) {
|
|
|
9ae3a8 |
+ fprintf(stderr,
|
|
|
9ae3a8 |
+ "ERROR: could not find extent for sector %" PRId64 "\n",
|
|
|
9ae3a8 |
+ sector_num);
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ ret = get_cluster_offset(bs, extent, NULL,
|
|
|
9ae3a8 |
+ sector_num << BDRV_SECTOR_BITS,
|
|
|
9ae3a8 |
+ 0, &cluster_offset);
|
|
|
9ae3a8 |
+ if (ret == VMDK_ERROR) {
|
|
|
9ae3a8 |
+ fprintf(stderr,
|
|
|
9ae3a8 |
+ "ERROR: could not get cluster_offset for sector %"
|
|
|
9ae3a8 |
+ PRId64 "\n", sector_num);
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (ret == VMDK_OK && cluster_offset >= bdrv_getlength(extent->file)) {
|
|
|
9ae3a8 |
+ fprintf(stderr,
|
|
|
9ae3a8 |
+ "ERROR: cluster offset for sector %"
|
|
|
9ae3a8 |
+ PRId64 " points after EOF\n", sector_num);
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ sector_num += extent->cluster_sectors;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ result->corruptions++;
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int i;
|
|
|
9ae3a8 |
@@ -2017,6 +2064,7 @@ static BlockDriver bdrv_vmdk = {
|
|
|
9ae3a8 |
.instance_size = sizeof(BDRVVmdkState),
|
|
|
9ae3a8 |
.bdrv_probe = vmdk_probe,
|
|
|
9ae3a8 |
.bdrv_open = vmdk_open,
|
|
|
9ae3a8 |
+ .bdrv_check = vmdk_check,
|
|
|
9ae3a8 |
.bdrv_reopen_prepare = vmdk_reopen_prepare,
|
|
|
9ae3a8 |
.bdrv_read = vmdk_co_read,
|
|
|
9ae3a8 |
.bdrv_write = vmdk_co_write,
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
2.1.0
|
|
|
9ae3a8 |
|