From patchwork Tue Aug 13 04:31:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 266718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (unknown [IPv6:2001:4830:134:3::12]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 53FFE2C023F for ; Tue, 13 Aug 2013 15:40:32 +1000 (EST) Received: from localhost ([::1]:52955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96KS-0000qy-1o for incoming@patchwork.ozlabs.org; Tue, 13 Aug 2013 00:35:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96IM-00072X-Qn for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:33:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V96IE-0000Np-Cj for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:33:22 -0400 Received: from mail-pb0-x235.google.com ([2607:f8b0:400e:c01::235]:54786) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96IE-0000Ne-4W for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:33:14 -0400 Received: by mail-pb0-f53.google.com with SMTP id up15so7514784pbc.26 for ; Mon, 12 Aug 2013 21:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=NjAOrTrMS3fNTNWiMhFcy9I/nZSRwyHIYqfDow+kKlk=; b=rEC2+f6oAn0m7C3vYdTDii7E/nvp1I9dIL8IAY3VpLqLvyQgG+HcyenwTOHz+YxwOb tQxYr2MXXFLpL5Ms3DbQ7hKH3HtlmXI67Z4ZfWnaaqtw2QeIQTgfHattoB9NChDdk74n B5PZ/dvCLtAqiGCOjE/M2NiNwRJ+XfRWdQEFrxeLUQIR50OZ7RTsKqDkgcuWRGzuu149 jF/hT2pFEV/kcWZCCdvPzv0/BiIDOZPvxlZri5tjfRmeJTcAmrgCfixvZggTWc4oRIGz lxdEYITeT/V8VIfRCyKHCslXtvr4t0v4XUa5LLx3ZL/5dBwq1BwG+I/rORLaj5DtKmcR bmig== X-Received: by 10.68.143.199 with SMTP id sg7mr2501360pbb.13.1376368393465; Mon, 12 Aug 2013 21:33:13 -0700 (PDT) Received: from 11.wdongxu.kvm58 ([202.108.130.153]) by mx.google.com with ESMTPSA id mz5sm10285023pbc.18.2013.08.12.21.33.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 Aug 2013 21:33:13 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Tue, 13 Aug 2013 12:31:50 +0800 Message-Id: <1376368326-7433-10-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1376368326-7433-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1376368326-7433-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::235 Cc: kwolf@redhat.com, wdongxu@cn.ibm.com, stefanha@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V18 09/25] block: add QemuOpts support for iscsi.c 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 Signed-off-by: Dong Xu Wang --- block/iscsi.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/block/iscsi.c b/block/iscsi.c index e7c1c2b..de2fd8c 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1305,6 +1305,65 @@ static QEMUOptionParameter iscsi_create_options[] = { { NULL } }; +static int iscsi_create_new(const char *filename, QemuOpts *opts) +{ + int ret = 0; + int64_t total_size = 0; + BlockDriverState bs; + IscsiLun *iscsilun = NULL; + QDict *bs_options; + + memset(&bs, 0, sizeof(BlockDriverState)); + + /* Read out options */ + total_size = + qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; + bs.opaque = g_malloc0(sizeof(struct IscsiLun)); + iscsilun = bs.opaque; + + bs_options = qdict_new(); + qdict_put(bs_options, "filename", qstring_from_str(filename)); + ret = iscsi_open(&bs, bs_options, 0); + QDECREF(bs_options); + + if (ret != 0) { + goto out; + } + if (iscsilun->nop_timer) { + qemu_del_timer(iscsilun->nop_timer); + qemu_free_timer(iscsilun->nop_timer); + } + if (iscsilun->type != TYPE_DISK) { + ret = -ENODEV; + goto out; + } + if (bs.total_sectors < total_size) { + ret = -ENOSPC; + goto out; + } + + ret = 0; +out: + if (iscsilun->iscsi != NULL) { + iscsi_destroy_context(iscsilun->iscsi); + } + g_free(bs.opaque); + return ret; +} + +static QemuOptsList iscsi_create_opts = { + .name = "iscsi-create-opts", + .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head), + .desc = { + { + .name = BLOCK_OPT_SIZE, + .type = QEMU_OPT_SIZE, + .help = "Virtual disk size" + }, + { /* end of list */ } + } +}; + static BlockDriver bdrv_iscsi = { .format_name = "iscsi", .protocol_name = "iscsi", @@ -1313,7 +1372,9 @@ static BlockDriver bdrv_iscsi = { .bdrv_file_open = iscsi_open, .bdrv_close = iscsi_close, .bdrv_create = iscsi_create, + .bdrv_create_new = iscsi_create_new, .create_options = iscsi_create_options, + .bdrv_create_opts = &iscsi_create_opts, .bdrv_getlength = iscsi_getlength, .bdrv_truncate = iscsi_truncate,