From patchwork Wed Sep 12 12:55:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 10597515 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 0C46F15E2 for ; Wed, 12 Sep 2018 13:03:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF86229C82 for ; Wed, 12 Sep 2018 13:03:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3E2B29CB5; Wed, 12 Sep 2018 13:03:38 +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 72F9729C82 for ; Wed, 12 Sep 2018 13:03:38 +0000 (UTC) Received: from localhost ([::1]:36185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g04nx-0004OG-HD for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Sep 2018 09:03:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g04hL-00081R-Gz for qemu-devel@nongnu.org; Wed, 12 Sep 2018 08:56:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g04hI-0000Gm-BI for qemu-devel@nongnu.org; Wed, 12 Sep 2018 08:56:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49734 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g04hI-0000Fy-4U for qemu-devel@nongnu.org; Wed, 12 Sep 2018 08:56:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B62644023840; Wed, 12 Sep 2018 12:56:43 +0000 (UTC) Received: from localhost (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E8C263F38; Wed, 12 Sep 2018 12:56:38 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Wed, 12 Sep 2018 16:55:31 +0400 Message-Id: <20180912125531.32131-10-marcandre.lureau@redhat.com> In-Reply-To: <20180912125531.32131-1-marcandre.lureau@redhat.com> References: <20180912125531.32131-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 12 Sep 2018 12:56:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 12 Sep 2018 12:56:43 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 9/9] hostmem-ram: use whole path for memory region name with >= 3.1 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: Eduardo Habkost , "Michael S. Tsirkin" , Mark Cave-Ayland , dgilbert@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Igor Mammedov , Paolo Bonzini , =?utf-8?q?Andreas_F=C3=A4rber?= , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP hostmem-file and hostmem-memfd use the whole object path for the memory region name, but hostname-ram uses only the path component (the basename): qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used Total mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000 qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used Total /objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000 qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used Total /objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000 Use the whole path name with >= 3.1. Having a consistent naming allow to migrate to different hostmem backends. Signed-off-by: Marc-André Lureau Reviewed-by: Dr. David Alan Gilbert --- include/hw/compat.h | 6 +++++- backends/hostmem-ram.c | 47 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/include/hw/compat.h b/include/hw/compat.h index 6f4d5fc647..8ce7a7057b 100644 --- a/include/hw/compat.h +++ b/include/hw/compat.h @@ -2,7 +2,11 @@ #define HW_COMPAT_H #define HW_COMPAT_3_0 \ - /* empty */ + {\ + .driver = "memory-backend-ram",\ + .property = "x-component-name",\ + .value = "true",\ + }, #define HW_COMPAT_2_12 \ {\ diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index 7ddd08d370..a9eb99cf1b 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -16,21 +16,56 @@ #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" +typedef struct RamMemoryBackend { + HostMemoryBackend parent; + + bool component_name; +} RamMemoryBackend; + +#define RAM_BACKEND(obj) \ + OBJECT_CHECK(RamMemoryBackend, (obj), TYPE_MEMORY_BACKEND_RAM) + +static char * +ram_backend_get_name(RamMemoryBackend *self) +{ + /* < 3.1 use the component as memory region name */ + if (self->component_name) { + return object_get_canonical_path_component(OBJECT(self)); + } + + return object_get_canonical_path(OBJECT(self)); +} static void ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { - char *path; + char *name; if (!backend->size) { error_setg(errp, "can't create backend with size 0"); return; } - path = object_get_canonical_path_component(OBJECT(backend)); - memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), path, + name = ram_backend_get_name(RAM_BACKEND(backend)); + memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), name, backend->size, backend->share, errp); - g_free(path); + g_free(name); +} + +static bool +ram_backend_get_component_name(Object *obj, Error **errp) +{ + RamMemoryBackend *self = RAM_BACKEND(obj); + + return self->component_name; +} + +static void +ram_backend_set_component_name(Object *obj, bool value, Error **errp) +{ + RamMemoryBackend *self = RAM_BACKEND(obj); + + self->component_name = value; } static void @@ -39,11 +74,15 @@ ram_backend_class_init(ObjectClass *oc, void *data) HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc); bc->alloc = ram_backend_memory_alloc; + object_class_property_add_bool(oc, "x-component-name", + ram_backend_get_component_name, + ram_backend_set_component_name, &error_abort); } static const TypeInfo ram_backend_info = { .name = TYPE_MEMORY_BACKEND_RAM, .parent = TYPE_MEMORY_BACKEND, + .instance_size = sizeof(RamMemoryBackend), .class_init = ram_backend_class_init, };