From patchwork Thu Aug 4 12:09:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9263543 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A92F26048F for ; Thu, 4 Aug 2016 12:09:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ADF1283E1 for ; Thu, 4 Aug 2016 12:09:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C3FD28401; Thu, 4 Aug 2016 12:09:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3923B283E1 for ; Thu, 4 Aug 2016 12:09:48 +0000 (UTC) Received: from localhost ([::1]:39443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVHT9-0002S5-St for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Aug 2016 08:09:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVHSp-0002RF-Gp for qemu-devel@nongnu.org; Thu, 04 Aug 2016 08:09:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bVHSj-0003ch-Mo for qemu-devel@nongnu.org; Thu, 04 Aug 2016 08:09:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVHSY-0003Z1-LJ; Thu, 04 Aug 2016 08:09:10 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36B1CC069B53; Thu, 4 Aug 2016 12:09:10 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u74C98gd018608; Thu, 4 Aug 2016 08:09:09 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 4 Aug 2016 14:09:07 +0200 Message-Id: <1470312547-8034-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 04 Aug 2016 12:09:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.7 v2] block/qdev: Let 'drive' property fall back to node name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If a qdev block device is created with an anonymous BlockBackend (i.e. a node name rather than a BB name was given for the drive property), qdev used to return an empty string when the property was read. This patch fixes it to return the node name instead. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- v2: - Check whether the BB has even a BDS inserted. Fixes a segfault with empty anonymous BlockBackends. hw/core/qdev-properties-system.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 2ba2504..e55afe6 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -126,7 +126,16 @@ static void release_drive(Object *obj, const char *name, void *opaque) static char *print_drive(void *ptr) { - return g_strdup(blk_name(ptr)); + const char *name; + + name = blk_name(ptr); + if (!*name) { + BlockDriverState *bs = blk_bs(ptr); + if (bs) { + name = bdrv_get_node_name(bs); + } + } + return g_strdup(name); } static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,