diff mbox

[14/19] block/parallels: create catalog_offset helper

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

Commit Message

Denis V. Lunev Dec. 30, 2014, 10:07 a.m. UTC
to calculate entry offset inside catalog bitmap in parallels image.
This is a matter of convinience.

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/parallels.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Roman Kagan Jan. 13, 2015, 2:14 p.m. UTC | #1
On Tue, Dec 30, 2014 at 01:07:07PM +0300, Denis V. Lunev wrote:
> to calculate entry offset inside catalog bitmap in parallels image.
> This is a matter of convinience.
> 
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Kevin Wolf <kwolf@redhat.com>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  block/parallels.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

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

Roman.
diff mbox

Patch

diff --git a/block/parallels.c b/block/parallels.c
index f79ddff..d072276 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -67,6 +67,12 @@  typedef struct BDRVParallelsState {
     unsigned int off_multiplier;
 } BDRVParallelsState;
 
+
+static uint32_t catalog_offset(uint32_t index)
+{
+    return sizeof(ParallelsHeader) + sizeof(uint32_t) * index;
+}
+
 static int parallels_probe(const uint8_t *buf, int buf_size, const char *filename)
 {
     const ParallelsHeader *ph = (const void *)buf;
@@ -188,8 +194,7 @@  static int64_t allocate_sector(BlockDriverState *bs, int64_t sector_num)
 
     tmp = cpu_to_le32(s->catalog_bitmap[idx]);
 
-    ret = bdrv_pwrite_sync(bs->file,
-            sizeof(ParallelsHeader) + idx * sizeof(tmp), &tmp, sizeof(tmp));
+    ret = bdrv_pwrite_sync(bs->file, catalog_offset(idx), &tmp, sizeof(tmp));
     if (ret < 0) {
         return ret;
     }
@@ -342,8 +347,7 @@  static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
     }
 
     cat_entries = DIV_ROUND_UP(total_size, cl_size);
-    cat_sectors = DIV_ROUND_UP(cat_entries * sizeof(uint32_t) +
-                               sizeof(ParallelsHeader), cl_size);
+    cat_sectors = DIV_ROUND_UP(catalog_offset(cat_entries), cl_size);
     cat_sectors = (cat_sectors *  cl_size) >> BDRV_SECTOR_BITS;
 
     memset(&header, 0, sizeof(header));