qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [RFC PATCH v2 3/6] block/raw-posix: implement bdrv_prea


From: Fam Zheng
Subject: Re: [Qemu-devel] [RFC PATCH v2 3/6] block/raw-posix: implement bdrv_preallocate
Date: Wed, 27 Nov 2013 10:40:42 +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:
Signed-off-by: Hu Tao <address@hidden>
---
  block/raw-posix.c | 34 ++++++++++++++++++++++++++++++++++
  1 file changed, 34 insertions(+)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index f836c8e..c563073 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1050,6 +1050,39 @@ static int64_t 
raw_get_allocated_file_size(BlockDriverState *bs)
      return (int64_t)st.st_blocks * 512;
  }

+#ifdef __linux__
+static int raw_preallocate2(int fd, int64_t offset, int64_t length)
+{
+    int ret = -1;
+
+    ret = fallocate(fd, 0, offset, length);
+
+    /* fallback to posix_fallocate() if fallocate() is not supported */
+    if (ret < 0 && (errno == ENOSYS || errno == EOPNOTSUPP)) {
+        ret = posix_fallocate(fd, offset, length);
+    }
+
+    return ret;
+}
+#else
+static int raw_preallocate2(int fd, int64_t offset, int64_t length)
+{
+    return posix_fallocate(fd, offset, length);
+}
+#endif
+
+static int raw_preallocate(BlockDriverState *bs, int64_t offset, int64_t 
length)
+{
+    BDRVRawState *s = bs->opaque;
+    int64_t len = bdrv_getlength(bs);
+
+    if (offset + length < 0 || offset + length > len) {
+        return -1;

-EINVAL

Fam

+    }
+
+    return raw_preallocate2(s->fd, offset, length);
+}
+
  static int raw_create(const char *filename, QEMUOptionParameter *options,
                        Error **errp)
  {
@@ -1221,6 +1254,7 @@ static BlockDriver bdrv_file = {
      .bdrv_close = raw_close,
      .bdrv_create = raw_create,
      .bdrv_has_zero_init = bdrv_has_zero_init_1,
+    .bdrv_preallocate = raw_preallocate,
      .bdrv_co_get_block_status = raw_co_get_block_status,

      .bdrv_aio_readv = raw_aio_readv,





reply via email to

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