qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 18/27] block/parallels: implement parallels_chec


From: Denis V. Lunev
Subject: Re: [Qemu-devel] [PATCH 18/27] block/parallels: implement parallels_check method of block driver
Date: Tue, 10 Mar 2015 17:29:18 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

On 10/03/15 17:24, Roman Kagan wrote:
On Tue, Mar 10, 2015 at 11:51:12AM +0300, Denis V. Lunev wrote:
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>
CC: Roman Kagan <address@hidden>
CC: Kevin Wolf <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
---
  block/parallels.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 82 insertions(+)

diff --git a/block/parallels.c b/block/parallels.c
index 65f6418..e5b475e 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -228,6 +228,87 @@ fail:
      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)
+            continue;
If you don't update prev_off here you can get fragmentation stats wrong
(dunno how important it is)

ok. by the way, I have missed braces here...

+
+        /* 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) {
+                s->bat_bitmap[i] = 0;
+                res->corruptions_fixed++;
+                flush_bat = true;
+                continue;
+            }
Ditto

Roman.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]