From nobody Wed Nov 5 20:16:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536757441806759.8952060222522; Wed, 12 Sep 2018 06:04:01 -0700 (PDT) Received: from localhost ([::1]:36185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g04oK-0004OG-EM for importer@patchew.org; Wed, 12 Sep 2018 09:04:00 -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=20Lureau?= 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:'' Content-Transfer-Encoding: quoted-printable 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=20Lureau?= , Igor Mammedov , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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=3Dmem,size=3D1G -numa node,memde= v=3Dmem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used = Total mem 4 KiB 0x0000000000000000 0x0000000040000000 0x= 0000000040000000 qemu -m 1024 -object memory-backend-file,id=3Dmem,size=3D1G,mem-path=3D/tmp= /foo -numa node,memdev=3Dmem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used = Total /objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x= 0000000040000000 qemu -m 1024 -object memory-backend-memfd,id=3Dmem,size=3D1G -numa node,mem= dev=3Dmem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used = Total /objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x= 0000000040000000 Use the whole path name with >=3D 3.1. Having a consistent naming allow to migrate to different hostmem backends. Signed-off-by: Marc-Andr=C3=A9 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 =20 #define HW_COMPAT_3_0 \ - /* empty */ + {\ + .driver =3D "memory-backend-ram",\ + .property =3D "x-component-name",\ + .value =3D "true",\ + }, =20 #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 @@ =20 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" =20 +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)); +} =20 static void ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { - char *path; + char *name; =20 if (!backend->size) { error_setg(errp, "can't create backend with size 0"); return; } =20 - path =3D object_get_canonical_path_component(OBJECT(backend)); - memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend),= path, + name =3D 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 =3D RAM_BACKEND(obj); + + return self->component_name; +} + +static void +ram_backend_set_component_name(Object *obj, bool value, Error **errp) +{ + RamMemoryBackend *self =3D RAM_BACKEND(obj); + + self->component_name =3D value; } =20 static void @@ -39,11 +74,15 @@ ram_backend_class_init(ObjectClass *oc, void *data) HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); =20 bc->alloc =3D 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); } =20 static const TypeInfo ram_backend_info =3D { .name =3D TYPE_MEMORY_BACKEND_RAM, .parent =3D TYPE_MEMORY_BACKEND, + .instance_size =3D sizeof(RamMemoryBackend), .class_init =3D ram_backend_class_init, }; =20 --=20 2.19.0.rc1