From patchwork Thu Jan 23 20:31:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 313721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 266D02C00A2 for ; Fri, 24 Jan 2014 07:32:30 +1100 (EST) Received: from localhost ([::1]:43093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Qwt-0002X1-DN for incoming@patchwork.ozlabs.org; Thu, 23 Jan 2014 15:32:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6QwI-0002W6-7o for qemu-devel@nongnu.org; Thu, 23 Jan 2014 15:31:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6QwA-0004nH-NZ for qemu-devel@nongnu.org; Thu, 23 Jan 2014 15:31:50 -0500 Received: from paradis.irqsave.net ([62.212.105.220]:48170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6QwA-0004mx-56 for qemu-devel@nongnu.org; Thu, 23 Jan 2014 15:31:42 -0500 Received: from localhost.localdomain (laure.irqsave.net [192.168.77.2]) by paradis.irqsave.net (Postfix) with ESMTP id 92D355B563; Thu, 23 Jan 2014 21:59:57 +0100 (CET) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Thu, 23 Jan 2014 21:31:33 +0100 Message-Id: <1390509099-695-3-git-send-email-benoit.canet@irqsave.net> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390509099-695-1-git-send-email-benoit.canet@irqsave.net> References: <1390509099-695-1-git-send-email-benoit.canet@irqsave.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 62.212.105.220 Cc: kwolf@redhat.com, famz@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH V6 2/8] block: Allow the user to define "node-name" option both on command line and QMP. 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 From: BenoƮt Canet Signed-off-by: Benoit Canet --- block.c | 36 ++++++++++++++++++++++++++++++++++++ qapi-schema.json | 2 ++ 2 files changed, 38 insertions(+) diff --git a/block.c b/block.c index 60b70bc..d9d02d2 100644 --- a/block.c +++ b/block.c @@ -728,6 +728,33 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags) return open_flags; } +static int bdrv_assign_node_name(BlockDriverState *bs, + const char *node_name, + Error **errp) +{ + if (!node_name) { + return 0; + } + + /* empty string node name is invalid */ + if (node_name[0] == '\0') { + error_setg(errp, "Empty node name"); + return -EINVAL; + } + + /* takes care of avoiding duplicates node names */ + if (bdrv_find_node(node_name)) { + error_setg(errp, "Duplicate node name"); + return -EINVAL; + } + + /* copy node name into the bs and insert it into the graph list */ + pstrcpy(bs->node_name, sizeof(bs->node_name), node_name); + QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list); + + return 0; +} + /* * Common part for opening disk images and files * @@ -738,6 +765,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, { int ret, open_flags; const char *filename; + const char *node_name = NULL; Error *local_err = NULL; assert(drv != NULL); @@ -752,6 +780,14 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name); + node_name = qdict_get_try_str(options, "node-name"); + qdict_del(options, "node-name"); + + ret = bdrv_assign_node_name(bs, node_name, errp); + if (ret < 0) { + return ret; + } + /* bdrv_open() with directly using a protocol as drv. This layer is already * opened, so assign it to bs (while file becomes a closed BlockDriverState) * and return immediately. */ diff --git a/qapi-schema.json b/qapi-schema.json index 35f7b34..04167da 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4090,6 +4090,7 @@ # @id: #optional id by which the new block device can be referred to. # This is a required option on the top level of blockdev-add, and # currently not allowed on any other level. +# @node-name: #optional the name of a block driver state node (Since 2.0) # @discard: #optional discard-related options (default: ignore) # @cache: #optional cache-related options # @aio: #optional AIO backend (default: threads) @@ -4105,6 +4106,7 @@ { 'type': 'BlockdevOptionsBase', 'data': { 'driver': 'str', '*id': 'str', + '*node-name': 'str', '*discard': 'BlockdevDiscardOptions', '*cache': 'BlockdevCacheOptions', '*aio': 'BlockdevAioOptions',