[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 19/27] block/parallels: implement parallels_check me
From: |
Denis V. Lunev |
Subject: |
[Qemu-devel] [PATCH 19/27] block/parallels: implement parallels_check method of block driver |
Date: |
Tue, 28 Apr 2015 10:46:52 +0300 |
The check is very simple at the moment. It calculates necessary stats
and fix only the following errors:
- space leak at the end of the image. This would happens due to
preallocation
- clusters outside the image are zeroed. Nothing else could be done here
Signed-off-by: Denis V. Lunev <address@hidden>
Reviewed-by: Roman Kagan <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
CC: Kevin Wolf <address@hidden>
---
block/parallels.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/block/parallels.c b/block/parallels.c
index 35ffb6f..35f231a 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -242,6 +242,90 @@ static coroutine_fn int
parallels_co_readv(BlockDriverState *bs,
return ret;
}
+
+static int parallels_check(BlockDriverState *bs, BdrvCheckResult *res,
+ BdrvCheckMode fix)
+{
+ BDRVParallelsState *s = bs->opaque;
+ int64_t size, prev_off, high_off;
+ int ret;
+ uint32_t i;
+ bool flush_bat = false;
+ int cluster_size = s->tracks << BDRV_SECTOR_BITS;
+
+ size = bdrv_getlength(bs->file);
+ if (size < 0) {
+ res->check_errors++;
+ return size;
+ }
+
+ res->bfi.total_clusters = s->bat_size;
+ res->bfi.compressed_clusters = 0; /* compression is not supported */
+
+ high_off = 0;
+ prev_off = 0;
+ for (i = 0; i < s->bat_size; i++) {
+ int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS;
+ if (off == 0) {
+ prev_off = 0;
+ continue;
+ }
+
+ /* cluster outside the image */
+ if (off > size) {
+ fprintf(stderr, "%s cluster %u is outside image\n",
+ fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i);
+ res->corruptions++;
+ if (fix & BDRV_FIX_ERRORS) {
+ prev_off = 0;
+ s->bat_bitmap[i] = 0;
+ res->corruptions_fixed++;
+ flush_bat = true;
+ continue;
+ }
+ }
+
+ res->bfi.allocated_clusters++;
+ if (off > high_off) {
+ high_off = off;
+ }
+
+ if (prev_off != 0 && (prev_off + cluster_size) != off) {
+ res->bfi.fragmented_clusters++;
+ }
+ prev_off = off;
+ }
+
+ if (flush_bat) {
+ ret = bdrv_pwrite_sync(bs->file, 0, s->header, s->header_size);
+ if (ret < 0) {
+ res->check_errors++;
+ return ret;
+ }
+ }
+
+ res->image_end_offset = high_off + cluster_size;
+ if (size > res->image_end_offset) {
+ int64_t count;
+ count = DIV_ROUND_UP(size - res->image_end_offset, cluster_size);
+ fprintf(stderr, "%s space leaked at the end of the image %" PRId64
"\n",
+ fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR",
+ size - res->image_end_offset);
+ res->leaks += count;
+ if (fix & BDRV_FIX_LEAKS) {
+ ret = bdrv_truncate(bs->file, res->image_end_offset);
+ if (ret < 0) {
+ res->check_errors++;
+ return ret;
+ }
+ res->leaks_fixed += count;
+ }
+ }
+
+ return 0;
+}
+
+
static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
{
int64_t total_size, cl_size;
@@ -449,6 +533,7 @@ static BlockDriver bdrv_parallels = {
.bdrv_co_writev = parallels_co_writev,
.bdrv_create = parallels_create,
+ .bdrv_check = parallels_check,
.create_opts = ¶llels_create_opts,
};
--
1.9.1
- [Qemu-devel] [PATCH 04/27] block/parallels: read up to cluster end in one go, (continued)
- [Qemu-devel] [PATCH 04/27] block/parallels: read up to cluster end in one go, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 11/27] block/parallels: support parallels image creation, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 13/27] parallels: change copyright information in the image header, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 12/27] iotests, parallels: test for newly created parallels image via qemu-img, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 10/27] iotests, parallels: test for write into Parallels image, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 14/27] block/parallels: rename catalog_ names to bat_, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 15/27] block/parallels: create bat2sect helper, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 16/27] block/parallels: keep BAT bitmap data in little endian in memory, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 17/27] block/parallels: read parallels image header and BAT into single buffer, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 18/27] block/parallels: move parallels_open/probe to the very end of the file, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 19/27] block/parallels: implement parallels_check method of block driver,
Denis V. Lunev <=
- [Qemu-devel] [PATCH 20/27] block/parallels: implement incorrect close detection, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 22/27] block/parallels: improve image reading performance, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 21/27] iotests, parallels: check for incorrectly closed image in tests, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 23/27] block/parallels: create bat_entry_off helper, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 24/27] block/parallels: delay writing to BAT till bdrv_co_flush_to_os, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 25/27] block/parallels: add prealloc-mode and prealloc-size open paramemets, Denis V. Lunev, 2015/04/28
- [Qemu-devel] [PATCH 26/27] block/parallels: optimize linear image expansion, Denis V. Lunev, 2015/04/28