Skip to contentSkip to conversation

sheepdog: implement .bdrv_get_allocated_file_size

PATCH Applied Liu Yuan 3 participants 3 messages Aug 7, 2013 – Aug 8, 2013 Block layer

lore
Share & tools
lore

Liu Yuan

author
#0 lore raw

PATCH 1/1 sheepdog: implement .bdrv_get_allocated_file_size

With this patch, qemu-img info sheepdog:image will show disk size for sheepdog images.

Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc MORITA Kazutaka <[email protected]>
---
 block/sheepdog.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
block/sheepdog.c +19 -0
index afe0533..7699aad 100644
@@ -2321,6 +2321,22 @@ sd_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
     return ret;
 }
 
+static int64_t sd_get_allocated_file_size(BlockDriverState *bs)
+{
+    BDRVSheepdogState *s = bs->opaque;
+    SheepdogInode *inode = &s->inode;
+    unsigned long i, last = DIV_ROUND_UP(inode->vdi_size, SD_DATA_OBJ_SIZE);
+    uint64_t size = 0;
+
+    for (i = 0; i < last; i++) {
+        if (inode->data_vdi_id[i] == 0) {
+            continue;
+        }
+        size += SD_DATA_OBJ_SIZE;
+    }
+    return size;
+}
+
 static QEMUOptionParameter sd_create_options[] = {
     {
         .name = BLOCK_OPT_SIZE,
@@ -2349,6 +2365,7 @@ static BlockDriver bdrv_sheepdog = {
     .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
+    .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
     .bdrv_truncate  = sd_truncate,
 
     .bdrv_co_readv  = sd_co_readv,
@@ -2377,6 +2394,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
+    .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
     .bdrv_truncate  = sd_truncate,
 
     .bdrv_co_readv  = sd_co_readv,
@@ -2405,6 +2423,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
+    .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
     .bdrv_truncate  = sd_truncate,
 
     .bdrv_co_readv  = sd_co_readv,
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw

At Wed, 7 Aug 2013 16:59:53 +0800,

Quoted 11 lines · Liu Yuan

With this patch, qemu-img info sheepdog:image will show disk size for sheepdog images.

Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc MORITA Kazutaka <[email protected]>
---
 block/sheepdog.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Looks good to me.

Applied
#2 lore raw

Am 08.08.2013 um 01:14 hat MORITA Kazutaka geschrieben:

Quoted 14 lines

At Wed, 7 Aug 2013 16:59:53 +0800,

Quoted 11 lines · Liu Yuan

With this patch, qemu-img info sheepdog:image will show disk size for sheepdog images.

Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc MORITA Kazutaka <[email protected]>
---
 block/sheepdog.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
Quoted 3 lines

Looks good to me.

Thanks, applied to block-next (for 1.7)

Kevin