qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [RFC PATCH v2 2/6] block: add BlockDriver.bdrv_prealloc


From: Fam Zheng
Subject: Re: [Qemu-devel] [RFC PATCH v2 2/6] block: add BlockDriver.bdrv_preallocate.
Date: Wed, 27 Nov 2013 10:35:48 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1

On 2013年11月27日 10:15, Hu Tao wrote:
This field is used to preallocate disk space for block
device.

Signed-off-by: Hu Tao <address@hidden>
---
  block.c                   | 13 +++++++++++++
  include/block/block.h     |  1 +
  include/block/block_int.h |  3 +++
  3 files changed, 17 insertions(+)

diff --git a/block.c b/block.c
index 382ea71..3985133 100644
--- a/block.c
+++ b/block.c
@@ -3102,6 +3102,19 @@ int bdrv_has_zero_init(BlockDriverState *bs)
      return 0;
  }

+int bdrv_preallocate(BlockDriverState *bs, int64_t offset, int64_t length)
+{
+    if (bs->backing_hd) {
+        return -1;

Better to use -ENOTSUP.

+    }
+
+    if (bs->drv->bdrv_preallocate) {
+        return bs->drv->bdrv_preallocate(bs, offset, length);
+    }
+
+    return -1;

-ENOTSUP

Fam

+}
+
  typedef struct BdrvCoGetBlockStatusData {
      BlockDriverState *bs;
      BlockDriverState *base;
diff --git a/include/block/block.h b/include/block/block.h
index 461eaa4..8d48c8a 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -315,6 +315,7 @@ void bdrv_drain_all(void);
  int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
  int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
  int bdrv_has_zero_init_1(BlockDriverState *bs);
+int bdrv_preallocate(BlockDriverState *bs, int64_t offset, int64_t length);
  int bdrv_has_zero_init(BlockDriverState *bs);
  int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,
                                int nb_sectors, int *pnum);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1666066..6ac3735 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -227,6 +227,9 @@ struct BlockDriver {
       */
      int (*bdrv_has_zero_init)(BlockDriverState *bs);

+    int (*bdrv_preallocate)(BlockDriverState *bs, int64_t offset,
+                            int64_t length);
+
      QLIST_ENTRY(BlockDriver) list;
  };






reply via email to

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