[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 4/6] raw-posix: Add full image preallocation
From: |
Hu Tao |
Subject: |
[Qemu-devel] [RFC PATCH v2 4/6] raw-posix: Add full image preallocation option |
Date: |
Wed, 27 Nov 2013 10:15:42 +0800 |
This patch adds a new option preallocation for raw format, and implements
full preallocation.
Signed-off-by: Hu Tao <address@hidden>
---
block/raw-posix.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index c563073..200886d 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1089,11 +1089,22 @@ static int raw_create(const char *filename,
QEMUOptionParameter *options,
int fd;
int result = 0;
int64_t total_size = 0;
+ int prealloc = PREALLOC_OFF;
/* Read out options */
while (options && options->name) {
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
total_size = options->value.n / BDRV_SECTOR_SIZE;
+ } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
+ if (!options->value.s || !strcmp(options->value.s, "off")) {
+ prealloc = PREALLOC_OFF;
+ } else if (!strcmp(options->value.s, "full")) {
+ prealloc = PREALLOC_FULL;
+ } else {
+ error_setg(errp, "Invalid preallocation mode: '%s'",
+ options->value.s);
+ return -EINVAL;
+ }
}
options++;
}
@@ -1108,6 +1119,12 @@ static int raw_create(const char *filename,
QEMUOptionParameter *options,
result = -errno;
error_setg_errno(errp, -result, "Could not resize file");
}
+ if (prealloc == PREALLOC_FULL &&
+ raw_preallocate2(fd, 0, total_size * BDRV_SECTOR_SIZE) != 0) {
+ result = -errno;
+ error_setg_errno(errp, -result,
+ "Could not preallocate data for the new file");
+ }
if (qemu_close(fd) != 0) {
result = -errno;
error_setg_errno(errp, -result, "Could not close the new file");
@@ -1238,6 +1255,11 @@ static QEMUOptionParameter raw_create_options[] = {
.type = OPT_SIZE,
.help = "Virtual disk size"
},
+ {
+ .name = BLOCK_OPT_PREALLOC,
+ .type = OPT_STRING,
+ .help = "Preallocation mode (allowed values: off, full)"
+ },
{ NULL }
};
--
1.8.3.1
- Re: [Qemu-devel] [RFC PATCH v2 3/6] block/raw-posix: implement bdrv_preallocate, (continued)
- [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Hu Tao, 2013/11/26
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Fam Zheng, 2013/11/26
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Hu Tao, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Fam Zheng, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Peter Lieven, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Fam Zheng, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Peter Lieven, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Hu Tao, 2013/11/28
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Peter Lieven, 2013/11/28
[Qemu-devel] [RFC PATCH v2 4/6] raw-posix: Add full image preallocation option,
Hu Tao <=
[Qemu-devel] [RFC PATCH v2 6/6] qcow2: Add full image preallocation option, Hu Tao, 2013/11/26
Re: [Qemu-devel] [RFC PATCH v2 0/6] qemu-img: add preallocation=full, Fam Zheng, 2013/11/26