From patchwork Thu Sep 20 10:32:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B780214BD for ; Thu, 20 Sep 2018 10:47:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A784B2CD7D for ; Thu, 20 Sep 2018 10:47:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A4382CD84; Thu, 20 Sep 2018 10:47:02 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 3D9442CD7D for ; Thu, 20 Sep 2018 10:47:02 +0000 (UTC) Received: from localhost ([::1]:49425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wU9-0006tS-5V for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:47:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHx-0003fI-8p for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHw-00079H-DE for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHw-00078q-3h; Thu, 20 Sep 2018 06:34:24 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69C37308404D; Thu, 20 Sep 2018 10:34:23 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74DE53091327; Thu, 20 Sep 2018 10:34:15 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:37 +0200 Message-Id: <20180920103243.28474-17-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 20 Sep 2018 10:34:23 +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 v3 16/22] memory-device: add optional function get_device_id() 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When reporting the id of virtio-based memory devices, we always have to take the one of the proxy device (parent), not the one of the memory device directly. Let's generalize this by allowing memory devices to specify an optional "get_device_id" function. This id can then be used to report errors to the user from memory-device.c code, without having to special case e.g. virtio devices. While at it, properly treat id == NULL and report "(unnamed)" instead. Details: When the user creates a virtio device (e.g. virtio-balloon-pci), two devices are actually created. 1. Virtio proxy device (e.g. TYPE_VIRTIO_BALLOON_PCI) 2. The "real" virtio device (e.g. TYPE_VIRTIO_BALLOON). 1. aliases all properties of 2, so 2. can be properly configured using 1. 1. gets the device ID set specified by the user. 2. gets no ID set. If we want to make 2. a MemoryDevice but report errors/information to the user, we always have to report the id of 1. (because that's the device the user instantiated and configured). Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/mem/memory-device.c | 7 +++++-- include/hw/mem/memory-device.h | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 534bd38313..92878fc327 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -174,8 +174,11 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { - const DeviceState *d = DEVICE(md); - error_setg(errp, "address range conflicts with '%s'", d->id); + const char *id = mdc->get_device_id ? mdc->get_device_id(md) : + DEVICE(md)->id; + + error_setg(errp, "address range conflicts with '%s'", + id ? id : "(unnamed)"); goto out; } new_addr = QEMU_ALIGN_UP(md_addr + md_size, align); diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index fd0b43c224..66143cffc6 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -42,6 +42,9 @@ typedef struct MemoryDeviceState { * of multiple successive memory regions, a covering memory region is to * be used. Scattered memory regions are not supported for single devices. * @fill_device_info: Translate current @md state into #MemoryDeviceInfo. + * @get_device_id: Optional. Allows memory devices behind proxy devices + * (e.g. virtio based) to report the id of the proxy device to the user + * instead of the (empty) id of the memory device. */ typedef struct MemoryDeviceClass { /* private */ @@ -54,6 +57,7 @@ typedef struct MemoryDeviceClass { MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); + const char *(*get_device_id)(const MemoryDeviceState *md); } MemoryDeviceClass; MemoryDeviceInfoList *qmp_memory_device_list(void);