From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtTNE-0004KH-IQ for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:30:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtTN6-0007ly-6i for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:30:04 -0500 Received: from [222.73.24.84] (port=51822 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtTN5-0007li-RM for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:29:56 -0500 From: Hu Tao Date: Thu, 19 Dec 2013 10:27:39 +0800 Message-Id: <920fcea5edb4c0549b3e041799187757bd4c72df.1387419339.git.hutao@cn.fujitsu.com> In-Reply-To: References: Subject: [Qemu-devel] [RFC PATCH v3 4/6] raw-posix: Add full image preallocation option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Peter Lieven , hutao@cn.fujitsu.com This patch adds a new option preallocation for raw format, and implements full preallocation. Signed-off-by: Hu Tao --- block/raw-posix.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/block/raw-posix.c b/block/raw-posix.c index 19181f2..e09e170 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1199,11 +1199,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++; } @@ -1218,6 +1229,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"); @@ -1373,6 +1390,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.7.11.7