From patchwork Sat May 21 12:35:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MORITA Kazutaka X-Patchwork-Id: 96696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1AC1FB71B1 for ; Sat, 21 May 2011 22:38:09 +1000 (EST) Received: from localhost ([::1]:55082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNlRW-0008QK-1G for incoming@patchwork.ozlabs.org; Sat, 21 May 2011 08:38:06 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNlRO-0008QF-2T for qemu-devel@nongnu.org; Sat, 21 May 2011 08:37:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNlRM-0000nQ-KA for qemu-devel@nongnu.org; Sat, 21 May 2011 08:37:58 -0400 Received: from sh.osrg.net ([192.16.179.4]:39578) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNlRM-0000n1-1c for qemu-devel@nongnu.org; Sat, 21 May 2011 08:37:56 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id p4LCba6J008211; Sat, 21 May 2011 21:37:37 +0900 Received: from localhost (dfs1401.osrg.net [10.68.14.1]) by fs.osrg.net (Postfix) with ESMTP id C0C573E0099; Sat, 21 May 2011 21:37:36 +0900 (JST) From: MORITA Kazutaka To: kwolf@redhat.com Date: Sat, 21 May 2011 21:35:19 +0900 Message-Id: <1305981319-32508-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Mailer: git-send-email 1.5.6.5 X-Dispatcher: imput version 20070423(IM149) Lines: 132 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Sat, 21 May 2011 21:37:38 +0900 (JST) X-Virus-Scanned: clamav-milter 0.97 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 192.16.179.4 Cc: sheepdog@lists.wpkg.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] sheepdog: add data preallocation support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This introduces a qemu-img create option for sheepdog which allows the data to be preallocated (note that sheepdog always preallocates metadata). This is necessary to use Sheepdog volumes as a backend storage for iSCSI target. More information is available at https://sourceforge.net/apps/trac/sheepdog/wiki/General%20Protocol%20Support The option is disabled by default and you need to enable it like the following: qemu-img create sheepdog:test -o preallocation=data 1G Signed-off-by: MORITA Kazutaka Signed-off-by: FUJITA Tomonori --- block/sheepdog.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 72 insertions(+), 1 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 0392ca8..38ca9aa 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1292,6 +1292,57 @@ static int do_sd_create(char *filename, int64_t vdi_size, return 0; } +static int sd_prealloc(uint32_t vid, int64_t vdi_size) +{ + int fd, ret; + SheepdogInode *inode; + char *buf; + unsigned long idx, max_idx; + + fd = connect_to_sdog(NULL, NULL); + if (fd < 0) { + return -EIO; + } + + inode = qemu_malloc(sizeof(*inode)); + buf = qemu_malloc(SD_DATA_OBJ_SIZE); + + ret = read_object(fd, (char *)inode, vid_to_vdi_oid(vid), + 0, sizeof(*inode), 0); + + max_idx = (vdi_size + SD_DATA_OBJ_SIZE - 1) / SD_DATA_OBJ_SIZE; + + for (idx = 0; idx < max_idx; idx++) { + uint64_t oid; + oid = vid_to_data_oid(vid, idx); + + if (inode->data_vdi_id[idx]) { + ret = read_object(fd, buf, vid_to_vdi_oid(inode->data_vdi_id[idx]), + 1, SD_DATA_OBJ_SIZE, 0); + if (ret) + goto out; + } else { + memset(buf, 0, SD_DATA_OBJ_SIZE); + } + + ret = write_object(fd, buf, oid, 1, SD_DATA_OBJ_SIZE, 0, 1); + if (ret) + goto out; + + inode->data_vdi_id[idx] = vid; + ret = write_object(fd, (char *)inode, vid_to_vdi_oid(vid), + 1, sizeof(*inode), 0, 0); + if (ret) + goto out; + } +out: + free(inode); + free(buf); + closesocket(fd); + + return ret; +} + static int sd_create(const char *filename, QEMUOptionParameter *options) { int ret; @@ -1301,6 +1352,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options) BDRVSheepdogState s; char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN]; uint32_t snapid; + int prealloc = 0; strstart(filename, "sheepdog:", (const char **)&filename); @@ -1317,6 +1369,16 @@ static int sd_create(const char *filename, QEMUOptionParameter *options) vdi_size = options->value.n; } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) { backing_file = options->value.s; + } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) { + if (!options->value.s || !strcmp(options->value.s, "off")) { + prealloc = 0; + } else if (!strcmp(options->value.s, "data")) { + prealloc = 1; + } else { + error_report("Invalid preallocation mode: '%s'\n", + options->value.s); + return -EINVAL; + } } options++; } @@ -1354,7 +1416,11 @@ static int sd_create(const char *filename, QEMUOptionParameter *options) bdrv_delete(bs); } - return do_sd_create((char *)vdi, vdi_size, base_vid, &vid, 0, s.addr, s.port); + ret = do_sd_create((char *)vdi, vdi_size, base_vid, &vid, 0, s.addr, s.port); + if (!prealloc || ret) + return ret; + + return sd_prealloc(vid, vdi_size); } static void sd_close(BlockDriverState *bs) @@ -1990,6 +2056,11 @@ static QEMUOptionParameter sd_create_options[] = { .type = OPT_STRING, .help = "File name of a base image" }, + { + .name = BLOCK_OPT_PREALLOC, + .type = OPT_STRING, + .help = "Preallocation mode (allowed values: off, data)" + }, { NULL } };