qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 13/19] block/parallels: store ParallelsHeader to the


From: Denis V. Lunev
Subject: [Qemu-devel] [PATCH 13/19] block/parallels: store ParallelsHeader to the BDRVParallelsState
Date: Tue, 30 Dec 2014 13:07:06 +0300

This would be useful for the future for speed optimizations of new block
creation in the image. At the moment each write to the catalog bitmap
results in read-modify-write transaction. It would be beneficial to
write by pages or sectors. Though in order to do that for the begining
of the image we should keep the header somethere to obtain first sector
of the image properly. BDRVParallelsState would be a good place for that.

Signed-off-by: Denis V. Lunev <address@hidden>
CC: Kevin Wolf <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
---
 block/parallels.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/block/parallels.c b/block/parallels.c
index e3abf4e..f79ddff 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -57,6 +57,8 @@ typedef struct ParallelsHeader {
 typedef struct BDRVParallelsState {
     CoMutex lock;
 
+    ParallelsHeader ph;
+
     uint32_t *catalog_bitmap;
     unsigned int catalog_size;
 
@@ -85,29 +87,28 @@ static int parallels_open(BlockDriverState *bs, QDict 
*options, int flags,
 {
     BDRVParallelsState *s = bs->opaque;
     int i;
-    ParallelsHeader ph;
     int ret;
 
-    ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));
+    ret = bdrv_pread(bs->file, 0, &s->ph, sizeof(s->ph));
     if (ret < 0) {
         goto fail;
     }
 
-    bs->total_sectors = le64_to_cpu(ph.nb_sectors);
+    bs->total_sectors = le64_to_cpu(s->ph.nb_sectors);
 
-    if (le32_to_cpu(ph.version) != HEADER_VERSION) {
+    if (le32_to_cpu(s->ph.version) != HEADER_VERSION) {
         goto fail_format;
     }
-    if (!memcmp(ph.magic, HEADER_MAGIC, 16)) {
+    if (!memcmp(s->ph.magic, HEADER_MAGIC, 16)) {
         s->off_multiplier = 1;
         bs->total_sectors = 0xffffffff & bs->total_sectors;
-    } else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) {
-        s->off_multiplier = le32_to_cpu(ph.tracks);
+    } else if (!memcmp(s->ph.magic, HEADER_MAGIC2, 16)) {
+        s->off_multiplier = le32_to_cpu(s->ph.tracks);
     } else {
         goto fail_format;
     }
 
-    s->tracks = le32_to_cpu(ph.tracks);
+    s->tracks = le32_to_cpu(s->ph.tracks);
     if (s->tracks == 0) {
         error_setg(errp, "Invalid image: Zero sectors per track");
         ret = -EINVAL;
@@ -119,7 +120,7 @@ static int parallels_open(BlockDriverState *bs, QDict 
*options, int flags,
         goto fail;
     }
 
-    s->catalog_size = le32_to_cpu(ph.catalog_entries);
+    s->catalog_size = le32_to_cpu(s->ph.catalog_entries);
     if (s->catalog_size > INT_MAX / sizeof(uint32_t)) {
         error_setg(errp, "Catalog too large");
         ret = -EFBIG;
-- 
1.9.1




reply via email to

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