From patchwork Sat Nov 17 15:13:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 199857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B1EC02C0086 for ; Sun, 18 Nov 2012 02:13:40 +1100 (EST) Received: from localhost ([::1]:52411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZk5S-0000iu-9i for incoming@patchwork.ozlabs.org; Sat, 17 Nov 2012 10:13:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZk5J-0000ie-6G for qemu-devel@nongnu.org; Sat, 17 Nov 2012 10:13:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TZk5G-0000HG-3i for qemu-devel@nongnu.org; Sat, 17 Nov 2012 10:13:29 -0500 Received: from ssl.dlhnet.de ([91.198.192.8]:54112 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZk5F-0000HA-Tc for qemu-devel@nongnu.org; Sat, 17 Nov 2012 10:13:26 -0500 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id C484C14CAF2; Sat, 17 Nov 2012 16:13:24 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ssl.dlh.net Received: from ssl.dlh.net ([127.0.0.1]) by localhost (ssl.dlh.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id usBVGm5tBK1g; Sat, 17 Nov 2012 16:13:24 +0100 (CET) Received: from [82.141.7.8] (unknown [82.141.7.8]) by ssl.dlh.net (Postfix) with ESMTPSA id 02FC314C9E9; Sat, 17 Nov 2012 16:13:24 +0100 (CET) Message-ID: <50A7A994.3020705@dlhnet.de> Date: Sat, 17 Nov 2012 16:13:24 +0100 From: Peter Lieven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: Kevin Wolf , Paolo Bonzini , aderumier@odiso.com, ronnie sahlberg Subject: [Qemu-devel] [PATCH] iscsi: add iscsi_create 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 patch adds support for bdrv_create. This allows e.g. to use qemu-img to convert from any supported device to an iscsi backed storage as destination. Signed-off-by: Peter Lieven diff --git a/block/iscsi.c b/block/iscsi.c index 4bc3d4b..eb586cb 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -952,6 +952,54 @@ static void iscsi_close(BlockDriverState *bs) memset(iscsilun, 0, sizeof(IscsiLun)); } +static int iscsi_create(const char *filename, QEMUOptionParameter *options) { + int ret = 0; + int64_t total_size = 0; + BlockDriverState bs; + IscsiLun *iscsilun = NULL; + + memset(&bs, 0, sizeof(BlockDriverState)); + + /* Read out options */ + while (options && options->name) { + if (!strcmp(options->name, "size")) { + total_size = options->value.n / BDRV_SECTOR_SIZE; + } + options++; + } + + bs.opaque = g_malloc0(sizeof(struct IscsiLun)); + iscsilun = bs.opaque; + + if ((ret = iscsi_open(&bs, filename, 0)) != 0) { + goto out; + } + if (iscsilun->type != TYPE_DISK) { + ret = -ENODEV; + goto out; + } + if (bs.total_sectors < total_size) { + ret = -ENOSPC; + } + + ret = 0; +out: + if (iscsilun->iscsi != NULL) { + iscsi_destroy_context(iscsilun->iscsi); + } + g_free(bs.opaque); + return ret; +} + +static QEMUOptionParameter iscsi_create_options[] = { + { + .name = BLOCK_OPT_SIZE, + .type = OPT_SIZE, + .help = "Virtual disk size" + }, + { NULL } +}; + static BlockDriver bdrv_iscsi = { .format_name = "iscsi", .protocol_name = "iscsi", @@ -959,6 +1007,8 @@ static BlockDriver bdrv_iscsi = { .instance_size = sizeof(IscsiLun), .bdrv_file_open = iscsi_open, .bdrv_close = iscsi_close, + .bdrv_create = iscsi_create, + .create_options = iscsi_create_options, .bdrv_getlength = iscsi_getlength,