diff mbox

[13/19] block/parallels: store ParallelsHeader to the BDRVParallelsState

Message ID 1419934032-24216-4-git-send-email-den@openvz.org
State New
Headers show

Commit Message

Denis V. Lunev Dec. 30, 2014, 10:07 a.m. UTC
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 <den@openvz.org>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/parallels.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Roman Kagan Jan. 13, 2015, 2:13 p.m. UTC | #1
On Tue, Dec 30, 2014 at 01:07:06PM +0300, Denis V. Lunev wrote:
> 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 <den@openvz.org>
> CC: Kevin Wolf <kwolf@redhat.com>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  block/parallels.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)

Acked-by: Roman Kagan <rkagan@parallels.com>

Roman.
diff mbox

Patch

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;