From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999095; cv=none; d=zohomail.com; s=zohoarc; b=aL7yR8y/3qYEirWtcjGaUQqiGeSBTcC2FVtLcGUaAVWHGrD23h53ySOBpsvZiS+okLC3YxM/rVEL+pxMvKZ0v2EbOO9GyRP6jJnr3mJ1espT3sflUF5326UG5xxhjgbCQoUrrBZpqCSJWG+X8WJlYM1i2ZebO5wSl7bszvYQmDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999095; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dBLJ6IJAkS3SLaj90xrFLg8r38ICJZPEKlRJoHIGpFg=; b=m6SM16QEw9DDb/W+mZ9+FvLsMkAHmgKxpukElZPm9YPhBkma4y9z+aY1dSp0tRQAehOgtMZJCkOvZH4f+wn45B4iW5wXy83E9WVYift0TPA2w2jV9QqhNbRR7P9uVXgKx0XVdBy6mOhDiX3BLDWcqLzMavaWAbuDG8bkypwj4S8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999095401777.1484358726216; Thu, 3 Dec 2020 04:38:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-505-K-uxZiT6OjmWEpDf_a3STQ-1; Thu, 03 Dec 2020 07:37:03 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9CA2F185E4A3; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76A731A839; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0B48F4E58F; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Caeoo002875 for ; Thu, 3 Dec 2020 07:36:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2BB3F5C1BD; Thu, 3 Dec 2020 12:36:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id A19E35C1B4 for ; Thu, 3 Dec 2020 12:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999094; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dBLJ6IJAkS3SLaj90xrFLg8r38ICJZPEKlRJoHIGpFg=; b=fPd4mqrnvHx+4enXUz8NQM1dtWVg5qfZ8Xs6ld/tJVCKKlKoiA2zhQp40FbQz8DXBqLxL4 RjNbGhHl/lvWlOavOfJJ6paNaG0/Xr7mdt1/iYLDZPIU0Ro3fCD9urjdhE9G1t2VKgHHpq 1q9WiGjxYy0rzj2MwBgQwS1LmXoQKJk= X-MC-Unique: K-uxZiT6OjmWEpDf_a3STQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 01/27] viruuid: Rework virUUIDIsValid() Date: Thu, 3 Dec 2020 13:36:04 +0100 Message-Id: <7b27afef80ace93d07c9eb1f7951d9eb3288e18f.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The only test we do when checking for UUID validity is that whether all bytes are the same (invalid UUID) or not (valid UUID). The algorithm we use is needlessly complicated. Also, the checked UUID is not modified and hence the argument can be of 'const' type. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/util/viruuid.c | 17 +++++++---------- src/util/viruuid.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/util/viruuid.c b/src/util/viruuid.c index 908b09945d..558fbb9c0d 100644 --- a/src/util/viruuid.c +++ b/src/util/viruuid.c @@ -170,25 +170,22 @@ virUUIDFormat(const unsigned char *uuid, char *uuidst= r) * Basic tests: * - Not all of the digits may be equal */ -int -virUUIDIsValid(unsigned char *uuid) +bool +virUUIDIsValid(const unsigned char *uuid) { size_t i; - unsigned int ctr =3D 1; - unsigned char c; =20 if (!uuid) - return 0; - - c =3D uuid[0]; + return false; =20 for (i =3D 1; i < VIR_UUID_BUFLEN; i++) - if (uuid[i] =3D=3D c) - ctr++; + if (uuid[i] !=3D uuid[0]) + return true; =20 - return ctr !=3D VIR_UUID_BUFLEN; + return false; } =20 + static int getDMISystemUUID(char *uuid, int len) { diff --git a/src/util/viruuid.h b/src/util/viruuid.h index 5d64e58405..b403b1906a 100644 --- a/src/util/viruuid.h +++ b/src/util/viruuid.h @@ -43,7 +43,7 @@ int virSetHostUUIDStr(const char *host_uuid); int virGetHostUUID(unsigned char *host_uuid) ATTRIBUTE_NONNULL(1) G_GNUC_N= O_INLINE; =20 -int virUUIDIsValid(unsigned char *uuid); +bool virUUIDIsValid(const unsigned char *uuid); =20 int virUUIDGenerate(unsigned char *uuid) G_GNUC_NO_INLINE; =20 --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999012; cv=none; d=zohomail.com; s=zohoarc; b=huwpMuVkPYzyuNvRlIzvrH8CTDGfN3UoFdDOXzA+6nVh8tvDuHMQoXCpzSPG09LEaYET8iFqM1Pt+XTot/nmBygLd45HO8HXFRMwrMPorf5gFc11vUcy7ST8/n+2zQclQbJx4aT90B+5FxaTy+73+L01AWofy+OeVhXhlSN1EgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999012; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eORn8FrfPDBfqvgmr2EojIt4Lizapiy/tgFegk9s8DM=; b=ZC3EbommKkYqHpTdgrzh6dkm8J7gOwcBd+Ytbm8Ke7iLu7+E7D75IcyAGzYMp9jSpKOXGrLwYZjVIySnvD0FOXJs6BcuVxpl3la647EqsLzWf4a1E3TdhGlpa38cYqNhMFWn+/dc8vUO7MnEM/tMqecYSy5sliAAE7/pkQVA6nQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999012757422.57965567032124; Thu, 3 Dec 2020 04:36:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-nRRwU5Y-NwyX1kyyrYBDEA-1; Thu, 03 Dec 2020 07:36:49 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2EA7E185E4A4; Thu, 3 Dec 2020 12:36:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D60C85D6BA; Thu, 3 Dec 2020 12:36:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3CB75180954D; Thu, 3 Dec 2020 12:36:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CafdW002890 for ; Thu, 3 Dec 2020 07:36:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 084C55C1C2; Thu, 3 Dec 2020 12:36:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D9675C1B4 for ; Thu, 3 Dec 2020 12:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999011; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eORn8FrfPDBfqvgmr2EojIt4Lizapiy/tgFegk9s8DM=; b=Dqs2T2t6ty6Oebt23WUyr0Be8JUMEo0UmKdmFBQs68GYMhIG5zmpYraAyncW81GndHEbTh /bKmALPe6f/AZBtSNTbmre4Ex9xQiek5tsVEq9D8aQUa8La9LNXBtHhRsSzIu7N+C/+3ZE CaKNIKQLB777zlREPApV7QxuaJGrPmI= X-MC-Unique: nRRwU5Y-NwyX1kyyrYBDEA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 02/27] internal.h: Introduce VIR_IS_POW2() Date: Thu, 3 Dec 2020 13:36:05 +0100 Message-Id: <6ae7963fd4a034315b5c4df5fa5279c4735c7724.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This macro checks whether given number is an integer power of two. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/internal.h | 10 +++++++++ src/qemu/qemu_validate.c | 46 +++++++++++++++++++++------------------- src/util/virrandom.c | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/internal.h b/src/internal.h index ff94e7e53e..0a03dfc46f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -237,6 +237,16 @@ (a) =3D (a) ^ (b); \ } while (0) =20 + +/** + * VIR_IS_POW2: + * + * Returns true if given number is a power of two + */ +#define VIR_IS_POW2(x) \ + ((x) && !((x) & ((x) - 1))) + + /** * virCheckFlags: * @supported: an OR'ed set of supported flags diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index e60d39a22f..6f4662b25a 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1460,20 +1460,32 @@ qemuValidateDomainDeviceDefNetwork(const virDomainN= etDef *net, return -1; } =20 - if (net->driver.virtio.rx_queue_size && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE))= { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtio rx_queue_size option is not supported= " - "with this QEMU binary")); - return -1; + if (net->driver.virtio.rx_queue_size) { + if (!VIR_IS_POW2(net->driver.virtio.rx_queue_size)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("rx_queue_size has to be a power of two")= ); + return -1; + } + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SI= ZE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio rx_queue_size option is not suppo= rted " + "with this QEMU binary")); + return -1; + } } =20 - if (net->driver.virtio.tx_queue_size && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE))= { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtio tx_queue_size option is not supported= " - "with this QEMU binary")); - return -1; + if (net->driver.virtio.tx_queue_size) { + if (!VIR_IS_POW2(net->driver.virtio.tx_queue_size)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("tx_queue_size has to be a power of two")= ); + return -1; + } + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SI= ZE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio tx_queue_size option is not suppo= rted " + "with this QEMU binary")); + return -1; + } } =20 if (net->mtu && @@ -1484,16 +1496,6 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNe= tDef *net, return -1; } =20 - if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queu= e_size - 1)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("rx_queue_size has to be a power of two")); - return -1; - } - if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queu= e_size - 1)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("tx_queue_size has to be a power of two")); - return -1; - } if (qemuValidateDomainVirtioOptions(net->virtio, qemuCaps) < 0) return -1; } diff --git a/src/util/virrandom.c b/src/util/virrandom.c index 6417232e3a..3ae1297e6b 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -89,7 +89,7 @@ double virRandom(void) */ uint32_t virRandomInt(uint32_t max) { - if ((max & (max - 1)) =3D=3D 0) + if (VIR_IS_POW2(max)) return virRandomBits(__builtin_ffs(max) - 1); =20 return virRandom() * max; --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999017; cv=none; d=zohomail.com; s=zohoarc; b=LtNSPkeInvoZ7yavsOOfQQpv/mggjEOAL+mPzzRuDu1JTbYj406HhSskM2DdK26KXxdIOTjPyeEysQ/dmJVnJ74jtd21GlA8/rd3AAOISm4MmdtKzn4TH5Tx6rap8n6QTNlfOaMM4F48zsUPMsiZGUdS/GfgGs+062pKEj11Mdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999017; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EBfmTvlly9PjuD4TpM794dJ10DVK6CbC8WPwXEUgxdw=; b=ZtDyHKpnYVoyRw2Pq3tTqTSlhDjt0mdqGJhmoS8O5FGfFyhq1YGSNXsKX0RjygBhx/IKPKYV4uD0Qd7lnbGlXYV7ax7trBmIU4ipxCOJ33rKzQqMK2sZVQK6rx2Mgs3ozzdWhFagYQ7+ZyVr/ddPNeWv0pW/etMGtKdL4YeTRH8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999017244812.6276224030539; Thu, 3 Dec 2020 04:36:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-jhJPIl_cOlGyP7FZowDc_A-1; Thu, 03 Dec 2020 07:36:53 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16AFB1081B22; Thu, 3 Dec 2020 12:36:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4A2E100164C; Thu, 3 Dec 2020 12:36:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 772861809CA2; Thu, 3 Dec 2020 12:36:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Caim9002915 for ; Thu, 3 Dec 2020 07:36:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 70F565C1BD; Thu, 3 Dec 2020 12:36:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id E45C95C1B4 for ; Thu, 3 Dec 2020 12:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999016; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EBfmTvlly9PjuD4TpM794dJ10DVK6CbC8WPwXEUgxdw=; b=db0QEOG15LVMB0anR3DAp6rbQp8jXE3NJ39Rh/SKmjWJyID73l+2os2oNT2y5vseyFXLor JRU56TELHWMI5NbrRUXFMdMskwTB2V/45T08sNvjOlxodZsf2XTQKIPimHeb/lTUyX+gB3 OZ64kIfOwEL69IwMcSi1LifhIvzT3XM= X-MC-Unique: jhJPIl_cOlGyP7FZowDc_A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 03/27] docs: Fix nvdimm example wrt to Date: Thu, 3 Dec 2020 13:36:06 +0100 Message-Id: <7d6533536cb29541808c0e18975bc8ef33da5186.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" On PPC platform it is required that a NVDIMM has an UUID. If none is provided then libvirt generates one during parsing (see v6.2.0-rc1~96 and friends). However, the example provided in our documentation is not valid XML. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- docs/formatdomain.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index ff64996af2..512939679b 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7159,7 +7159,7 @@ Example: usage of the memory devices - + 9066901e-c90a-46ad-8b55-c18868cf92ae /tmp/nvdimm @@ -7173,7 +7173,7 @@ Example: usage of the memory devices - + e39080c8-7f99-4b12-9c43-d80014e977b8 /dev/dax0.0 2048 @@ -7211,7 +7211,7 @@ Example: usage of the memory devices =20 ``uuid`` For pSeries guests, an uuid can be set to identify the nvdimm module. If - absent, libvirt will generate an uuid. automatically. This attribute is + absent, libvirt will generate an uuid automatically. This attribute is allowed only for ``model=3D'nvdimm'`` for pSeries guests. :since:`Since= 6.2.0` =20 ``source`` --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999085; cv=none; d=zohomail.com; s=zohoarc; b=QoMAI8IMG+dJFDOXZ44GEfxckiW5CVyRCVNrkHWtU2UMn5maeBhDfdjhXGFLoQ/u4tugnBqij8CUrsBXCzggMb6w1358DmVSfzKe1FhoTjzImsP9fw7zLrcEgtZBhdVkPZWlAH87DhDaW4jq4AT5EeR2WR1k2yRbMOaftVmkZ/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999085; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3Ejv+2jBlDGXguCawX2RHc44WEtmuRUQzRyta26ev9Y=; b=LDrwB4czOKQ6HE5Y2deiOKfnQwh58JpZurO4qWp7PH7BHfHr7dK4ASM5b/hGMMO1+PGWKV6Gl43V4/T+P2np5bp4/SVJrN4blvTcFvfi9N5GTONtv92jmiX4uFgqYm+6ycX00T4SYs3BbY0m4jI8TgIh1403yVGayDrRf/picVA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999085936842.3134093764365; Thu, 3 Dec 2020 04:38:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219-tOIrU74-PYKo1-nH3gqTMw-1; Thu, 03 Dec 2020 07:37:06 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4585D1005E62; Thu, 3 Dec 2020 12:36:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 250A860854; Thu, 3 Dec 2020 12:36:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E6BB21809CA2; Thu, 3 Dec 2020 12:36:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CajfM002921 for ; Thu, 3 Dec 2020 07:36:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4DC1B5C1BD; Thu, 3 Dec 2020 12:36:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id C384D5C1B4 for ; Thu, 3 Dec 2020 12:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999084; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3Ejv+2jBlDGXguCawX2RHc44WEtmuRUQzRyta26ev9Y=; b=hHqRyOwU5In/NiH8BdKwM1NUCqWgBn7AFmzP3HR5eTQ2Arburr8axsny0c9OP5FD9zHZun yYDZ/0n/OY/SIo5nDlbc22rOWh87zMhcQpzxrx9xqpU462qvP9sOlmIobQVJSfgC0O5Uen y3a4Tchkl7yGDAcBFdZzR2rNxLxzSho= X-MC-Unique: tOIrU74-PYKo1-nH3gqTMw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 04/27] domain_conf: Check NVDIMM UUID in ABI stability Date: Thu, 3 Dec 2020 13:36:07 +0100 Message-Id: <0205195f080f32b23728b02a72d50fcb1cc36bec.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The UUID is guest visible and thus shouldn't change if we want to not break guest ABI. Fixes: 08ed673901bb5b4f419b37bcce9b11d31ce370e6 Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/conf/domain_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 425e3c3710..d8df18b542 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -24204,6 +24204,12 @@ virDomainMemoryDefCheckABIStability(virDomainMemor= yDefPtr src, "source NVDIMM readonly flag")); return false; } + + if (memcmp(src->uuid, dst->uuid, VIR_UUID_BUFLEN) !=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Target NVDIMM UUID doesn't match source NVDI= MM")); + return false; + } } =20 return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info); --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999030; cv=none; d=zohomail.com; s=zohoarc; b=jDiyIn2Ecso8lMiOoTXxh+vmCnCZ5CiXF4OeIdqxT//b4o+wfy+ilU71iViZr2W5lMpR8v6XfvCYNthEuBLZz8CqPtDhnH1cF+2kW2RbjFXZO9ykeikwC1tWYQKydIKE5Nasj8hYkbXMhei3B1fj0wkFrQjoBkI7w420UcSG18s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999030; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s6q4Sfm3ACLRd5F1mkjDbncFUlkJ/C4n1bMeP5D/zpA=; b=ZJEiPqxd9uasTSoWOniLeDBQtcPyDltaC0VOLGoF7LOL+0t8DmrPDYAXa+2UNM225sCDjWgmpwOpo6r7eiVu1GQ1R+Oyw3DNxKSe/H4S/j9bpJklJUpsVmUBbs2y4cRwFVjXlJoUQUGAK9RP9aqdDhUTTACXrxLMvCJ2kM6m/r4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999030745360.74441315967624; Thu, 3 Dec 2020 04:37:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-458-NZIZuTtKO2e1WII1fx3k9g-1; Thu, 03 Dec 2020 07:37:07 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1540C1005E73; Thu, 3 Dec 2020 12:37:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E17901A7D9; Thu, 3 Dec 2020 12:37:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A63DC50034; Thu, 3 Dec 2020 12:37:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Camqc002942 for ; Thu, 3 Dec 2020 07:36:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id C2F2B5C1C2; Thu, 3 Dec 2020 12:36:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 442775C1CF for ; Thu, 3 Dec 2020 12:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999029; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=s6q4Sfm3ACLRd5F1mkjDbncFUlkJ/C4n1bMeP5D/zpA=; b=XTTH5hlLvnOvsy7UH0GXD/5xegB902QfcoiBIM53aGN4pKk1AxmnOfzAx1FFCa3N1H54Uj ifE5MfwCmf0/2P95XVGo++RAPAO3IxtLHAEuzUoQiyZCLIBXXIbDIMIeYHBEWbwCzaN0Hf 6/kBrv+XP88zbz3aOGjO7YQF1B6qh3Q= X-MC-Unique: NZIZuTtKO2e1WII1fx3k9g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 05/27] qemu_domain_address: Reformat qemuDomainAssignS390Addresses() Date: Thu, 3 Dec 2020 13:36:08 +0100 Message-Id: <152603685e6f3635231df13e71113efe1cc3ced9.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Thomas Huth Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_domain_address.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 2788dc7fb3..d872f75b38 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -408,18 +408,16 @@ qemuDomainAssignS390Addresses(virDomainDefPtr def, if (qemuDomainIsS390CCW(def) && virQEMUCapsGet(qemuCaps, QEMU_CAPS_CCW)) { if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_CCW)) - qemuDomainPrimeVfioDeviceAddresses( - def, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW); - qemuDomainPrimeVirtioDeviceAddresses( - def, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW); + qemuDomainPrimeVfioDeviceAddresses(def, VIR_DOMAIN_DEVICE_ADDR= ESS_TYPE_CCW); + + qemuDomainPrimeVirtioDeviceAddresses(def, VIR_DOMAIN_DEVICE_ADDRES= S_TYPE_CCW); =20 if (!(addrs =3D virDomainCCWAddressSetCreateFromDomain(def))) goto cleanup; =20 } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390)) { /* deal with legacy virtio-s390 */ - qemuDomainPrimeVirtioDeviceAddresses( - def, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390); + qemuDomainPrimeVirtioDeviceAddresses(def, VIR_DOMAIN_DEVICE_ADDRES= S_TYPE_VIRTIO_S390); } =20 ret =3D 0; --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999026; cv=none; d=zohomail.com; s=zohoarc; b=m0X0c9G/gznUBONoZ4lg+ecIK6wmOuTmlaXf9KfKSrwmtFEAR6KIlPCSAd7TEuHauJezCPPFqW9sBGx8P0YKOuAk89502meNR+mj+wucsig1F69m2Nyz4VsgrAC0kGtgJRXAKGxpADu/yXDaxTn2KHgasfLvXVwSGYYNCEHxrkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999026; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=buXagntCbzq225jqRiz/1AMqZDro93ICvgq5w4gKnJ0=; b=RUHSJB7MgBecOuMoPELtEnNE6ojePte3jk2rgcFbFlVonXfLTKw0PaqVqDUmNf3ZIsgnvnOY8pFTKJNH8CeQnnjcZcyP4Qcic3Y+ylLLe9t5m0BLMPj6J2QBzMnbpVZuzC/PZ/m+d11BBDKy8OHQQis6TSQYVuU5HBacf5Rjp8c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999025992305.60657007341524; Thu, 3 Dec 2020 04:37:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-xQY7lZxEMLyYitpdQiU-FA-1; Thu, 03 Dec 2020 07:37:02 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6EC6A185E4A2; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C8E25D9D7; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D49614E58E; Thu, 3 Dec 2020 12:36:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CaqhY002954 for ; Thu, 3 Dec 2020 07:36:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 420FB5C1C2; Thu, 3 Dec 2020 12:36:52 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7EDD5C1CF for ; Thu, 3 Dec 2020 12:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999024; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=buXagntCbzq225jqRiz/1AMqZDro93ICvgq5w4gKnJ0=; b=bMC8W1jztF6reOPvLQYDCtTe6EOl9gAsPRwCA4hQIlepdEGzmZ8iG9K1fSFjm+bTsJ6Wkq XzlTwLu5vkmDU/uoPtgINiXppbXo1eyXSDZmChcpjqcNzfvzGb+yha90+xDnWXl+Vx0+op n0Tb52mUUiidrZWvnnrykf/8IWiQwNo= X-MC-Unique: xQY7lZxEMLyYitpdQiU-FA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 06/27] conf: Require nvdimm path in validate step Date: Thu, 3 Dec 2020 13:36:09 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Our code expects that a nvdimm has a path defined always. And the parser does check for that. Well, not fully - only when parsing (which is an optional element). So if the element is not in the XML then the check is not performed and the assumption is broken. Verify in the memory def validator that a path was set. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/conf/domain_conf.c | 12 +++++++----- src/security/security_apparmor.c | 6 ------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d8df18b542..da14760e2d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6694,6 +6694,12 @@ virDomainMemoryDefValidate(const virDomainMemoryDef = *mem, const virDomainDef *def) { if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + if (!mem->nvdimmPath) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("path is required for model 'nvdimm'")); + return -1; + } + if (mem->discard =3D=3D VIR_TRISTATE_BOOL_YES) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("discard is not supported for nvdimms")); @@ -16690,11 +16696,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, break; =20 case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - if (!(def->nvdimmPath =3D virXPathString("string(./path)", ctxt)))= { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("path is required for model 'nvdimm'")); - return -1; - } + def->nvdimmPath =3D virXPathString("string(./path)", ctxt); =20 if (virDomainParseMemory("./alignsize", "./alignsize/@unit", ctxt, &def->alignsize, false, false) < 0) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index c2d86c6940..f306af8dd3 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -686,12 +686,6 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr, =20 switch ((virDomainMemoryModel) mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - if (mem->nvdimmPath =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("%s: nvdimm without a path"), - __func__); - return -1; - } if (!virFileExists(mem->nvdimmPath)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: \'%s\' does not exist"), --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999036; cv=none; d=zohomail.com; s=zohoarc; b=CTzbA4bhkouCxSj7lFhxCQIGLKjuZVhe03t391SV6RUSCfJgBMvxzvMY1gyianBC1fbwD6q3Eyq+LEk/0sXqgoeRpFM9GTSh5BnIZFHuNfm5b2Xc4MgiaXVlIyM/nrf4aSp6tzc5eWGs0djGNsXp426mplr4/a4HOEcBEX5D28A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999036; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FwkGxTSdVcohp5vcj+hHop+dWkb2HEHP+DyLpssAkBM=; b=WckXF6i5Gg215kWbr+LKL/oou9y5gZNBkgRZ9NlU6y3w9s2xERifbtwIKSqZJxOeR9/yz43DaLHK31+a/Lj8V4jGhkWMFUT3pZ0nGmS2207BNd4+HurCbRPjFk768QxCdn3wOpIo18AtD2vDReKD6vZtbhtS4A2F8aSBYlo5uU8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999036194641.4179426935291; Thu, 3 Dec 2020 04:37:16 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-lM-qMMbANAOFUf7O6IS9iQ-1; Thu, 03 Dec 2020 07:37:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 284F6805BFB; Thu, 3 Dec 2020 12:37:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F3C11002393; Thu, 3 Dec 2020 12:37:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6197950039; Thu, 3 Dec 2020 12:37:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Carxd002962 for ; Thu, 3 Dec 2020 07:36:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1E1C15C1CF; Thu, 3 Dec 2020 12:36:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 941AF5C1C2 for ; Thu, 3 Dec 2020 12:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999035; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FwkGxTSdVcohp5vcj+hHop+dWkb2HEHP+DyLpssAkBM=; b=M7tDp985eYhCxmZVTChwcQB5tQ6L98ecg5lEsPAWbi5Y1yNG/+6Qrd8QBVRvcY/5G42QSo J0+V1p47gsn6CuyiiFSKXtNERdi5Pj7J7Pbm6K3LRzpi+RMz8MF3K4kNiCQOwz7n50GSID QTRhKWfhBiplPufYPGt6tdr7b+JSREI= X-MC-Unique: lM-qMMbANAOFUf7O6IS9iQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 07/27] domain_conf: Fix virDomainMemoryModel type Date: Thu, 3 Dec 2020 13:36:10 +0100 Message-Id: <57be9b615338ca49212bc2bbaabf171512eb8be1.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The virDomainMemoryModel structure has a @type member which is really type of virDomainMemoryModel but we store it as int because the virDomainMemoryModelTypeFromString() call stores its retval right into it. Then, to have compiler do compile time check for us, every switch() typecasts the @type. This is needlessly verbose because the parses already has @val - a variable to store temporary values. Switch @type in the struct to virDomainMemoryModel and drop all typecasts. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/conf/domain_conf.c | 9 +++++---- src/conf/domain_conf.h | 2 +- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 4 ++-- src/security/security_apparmor.c | 2 +- src/security/security_dac.c | 4 ++-- src/security/security_selinux.c | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index da14760e2d..2a2cfd24e0 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16676,7 +16676,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, =20 ctxt->node =3D node; =20 - switch ((virDomainMemoryModel) def->model) { + switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (virDomainParseMemory("./pagesize", "./pagesize/@unit", ctxt, &def->pagesize, false, false) < 0) @@ -16897,12 +16897,13 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; } =20 - if ((def->model =3D virDomainMemoryModelTypeFromString(tmp)) <=3D 0) { + if ((val =3D virDomainMemoryModelTypeFromString(tmp)) <=3D 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid memory model '%s'"), tmp); goto error; } VIR_FREE(tmp); + def->model =3D val; =20 if ((tmp =3D virXMLPropString(memdevNode, "access"))) { if ((val =3D virDomainMemoryAccessTypeFromString(tmp)) <=3D 0) { @@ -18579,7 +18580,7 @@ virDomainMemoryFindByDefInternal(virDomainDefPtr de= f, tmp->size !=3D mem->size) continue; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: /* source stuff -> match with device */ if (tmp->pagesize !=3D mem->pagesize) @@ -27846,7 +27847,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); =20 - switch ((virDomainMemoryModel) def->model) { + switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (def->sourceNodes) { if (!(bitmap =3D virBitmapFormat(def->sourceNodes))) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 34cde22965..5853e3b290 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2322,7 +2322,7 @@ struct _virDomainMemoryDef { bool nvdimmPmem; /* valid only for NVDIMM */ =20 /* target */ - int model; /* virDomainMemoryModel */ + virDomainMemoryModel model; int targetNode; unsigned long long size; /* kibibytes */ unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */ diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 33f9b96bf8..eb64ce84da 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3280,7 +3280,7 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem) return NULL; } =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: case VIR_DOMAIN_MEMORY_MODEL_DIMM: =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 663c0af867..19a699540f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8485,7 +8485,7 @@ static int qemuDomainDefValidateMemoryHotplugDevice(const virDomainMemoryDef *mem, const virDomainDef *def) { - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (mem->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM && @@ -8598,7 +8598,7 @@ qemuDomainDefValidateMemoryHotplug(const virDomainDef= *def, for (i =3D 0; i < def->nmems; i++) { hotplugMemory +=3D def->mems[i]->size; =20 - switch ((virDomainMemoryModel) def->mems[i]->model) { + switch (def->mems[i]->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: needPCDimmCap =3D true; break; diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index f306af8dd3..eed66e460f 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -684,7 +684,7 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr, if (mem =3D=3D NULL) return 0; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (!virFileExists(mem->nvdimmPath)) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 258d246659..4f4a0a069e 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1887,7 +1887,7 @@ virSecurityDACRestoreMemoryLabel(virSecurityManagerPt= r mgr, { int ret =3D -1; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: ret =3D virSecurityDACRestoreFileLabel(mgr, mem->nvdimmPath); break; @@ -2060,7 +2060,7 @@ virSecurityDACSetMemoryLabel(virSecurityManagerPtr mg= r, uid_t user; gid_t group; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAM= E); if (seclabel && !seclabel->relabel) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index c0e76b2222..e9cd95916e 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1571,7 +1571,7 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManagerPt= r mgr, { virSecurityLabelDefPtr seclabel; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); if (!seclabel || !seclabel->relabel) @@ -1600,7 +1600,7 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityManag= erPtr mgr, int ret =3D -1; virSecurityLabelDefPtr seclabel; =20 - switch ((virDomainMemoryModel) mem->model) { + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); if (!seclabel || !seclabel->relabel) --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999026; cv=none; d=zohomail.com; s=zohoarc; b=X3c7NeJ2ZSjuxtU3Hbm4G409a9yeoBmDrv11IeEj+/YbwkNnaVlOIS89zJGh1B5gKQ/VKlTLoYjbrZid1nlyLAXsoLuNMd5XzY/2pCBKDSJgzC9AImvX4lYsQoxUAeWzI+iR57k/OPRSct/jxWTIZufKH+uIZAmoSbIrPym8/MA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999026; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wLRzEng8wY7yoBxFO8bk/ukhEgthhHXX+Ros9kuvMoM=; b=kG2Or0jCzzQ9JuK1caSPfejbz2KyshTDHswQ6AoDkoU6sV92aUg0dnD3+z/A44QAOESkz6BlV1e1PVqYNS8CpL5jGy0JvkDfBJbSlL7I0OyUhGlZEZ1sUrsn6aeVyaBHqCxEjS+BOpYSpUST8d38Mg0tYalPRiIp/E5XsGVP4Ng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999026723434.28587534387; Thu, 3 Dec 2020 04:37:06 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-aCAuOUx_PbK7UFVIXydPzg-1; Thu, 03 Dec 2020 07:37:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 514491081B29; Thu, 3 Dec 2020 12:36:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 287541F470; Thu, 3 Dec 2020 12:36:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E5E3F4EE7F; Thu, 3 Dec 2020 12:36:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CarYP002969 for ; Thu, 3 Dec 2020 07:36:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id F03A65C1C2; Thu, 3 Dec 2020 12:36:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F7A55C1CF for ; Thu, 3 Dec 2020 12:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999025; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wLRzEng8wY7yoBxFO8bk/ukhEgthhHXX+Ros9kuvMoM=; b=IPi6zOPv1NMAxRUN67kUlMiFf383s+uGwayVvP/lyfv5vExLwHzAK24Nf4bThoQHhFFbLb NH3rNkiCVCOHzaPOF9yc9xgZQfaFpMnlEpP8qjb8ooP5R1Phj63IKv2fBptTxgk93MX8a7 bBKSeCg5X60jglCBx7EglBGBqmkQ00Q= X-MC-Unique: aCAuOUx_PbK7UFVIXydPzg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 08/27] virDomainMemorySourceDefFormat: Utilize virXMLFormatElement() Date: Thu, 3 Dec 2020 13:36:11 +0100 Message-Id: <5f3249a0723d7f4d683bc3efc2f1ca0e8fd46bc2.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The virDomainMemorySourceDefFormat() uses good old style of formatting child buffer (virBufferAdjustIndent()). When switched to virXMLFormatElement() we can save a couple of lines. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/conf/domain_conf.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2a2cfd24e0..bb0d9f4501 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27839,37 +27839,32 @@ static int virDomainMemorySourceDefFormat(virBufferPtr buf, virDomainMemoryDefPtr def) { + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); g_autofree char *bitmap =3D NULL; =20 - if (!def->pagesize && !def->sourceNodes && !def->nvdimmPath) - return 0; - - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (def->sourceNodes) { if (!(bitmap =3D virBitmapFormat(def->sourceNodes))) return -1; =20 - virBufferAsprintf(buf, "%s\n", bitmap); + virBufferAsprintf(&childBuf, "%s\n", bitm= ap); } =20 if (def->pagesize) - virBufferAsprintf(buf, "%llu= \n", + virBufferAsprintf(&childBuf, "%llu\n", def->pagesize); break; =20 case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - virBufferEscapeString(buf, "%s\n", def->nvdimmPath); + virBufferEscapeString(&childBuf, "%s\n", def->nvdimmP= ath); =20 if (def->alignsize) - virBufferAsprintf(buf, "%llu\n", + virBufferAsprintf(&childBuf, "%llu\n", def->alignsize); =20 if (def->nvdimmPmem) - virBufferAddLit(buf, "\n"); + virBufferAddLit(&childBuf, "\n"); break; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -27877,8 +27872,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, break; } =20 - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virXMLFormatElement(buf, "source", NULL, &childBuf); =20 return 0; } --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999030; cv=none; d=zohomail.com; s=zohoarc; b=m9evmuiY8G9yttweFggMd8Zyo32w02br2NgbaYFEaEd9O+k3qc1yTJixi2UFoFtC/9u2kZE06D3BkRx4aRwpvdxx0hZEQgfSe+dBScUtY3NGrmaCtn1IYX9BOir4Aak/MoKTnEzEurjqvU0dyDVMzgkOBRDlarGtcCup1kR43Ws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999030; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uF1a+w6Gp2KBOhe18zgtYuDiqL+FYEgQJO/1TwZixMQ=; b=EgHmDo6RTySJDMDgmuqrPUsFwZH7WQ7UzSHF8slRscZk13e0UUYXPHX3MZb/sgLb+wWJuOcxDBMnNA5BlVxw+g1CVywbIQxYKYfzU/nnEtYYRTHYe/OuUYPFbRVHBGkxYjJi+wPykidywTLxQ/skkMzOJkoAdFcum1hGhyzp5gQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999030527678.3025443364807; Thu, 3 Dec 2020 04:37:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-_OIcellcOb6xY5VE1EG1Pg-1; Thu, 03 Dec 2020 07:37:06 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18BDC1081B24; Thu, 3 Dec 2020 12:37:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8E411A8A0; Thu, 3 Dec 2020 12:36:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B06895002F; Thu, 3 Dec 2020 12:36:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CavqW002999 for ; Thu, 3 Dec 2020 07:36:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id DACC95C1CF; Thu, 3 Dec 2020 12:36:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BCD35C1C2 for ; Thu, 3 Dec 2020 12:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999029; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=uF1a+w6Gp2KBOhe18zgtYuDiqL+FYEgQJO/1TwZixMQ=; b=gf5v7+DNGZVm53T+05sbFkub2Vhx5whfq2zQ0SRU564Ti5DU8hlhBkg9qatB1aC4l+EJEh qe1SGIoNJIgK5avFrvvC/1h+w5HDIEiZXLHO1HrQrTIlYZuiF4+kdk1xLuKsRQFLOvsJK8 vNfoCIcsWPSR28f4jGZ6ZcZuPKNVSBw= X-MC-Unique: _OIcellcOb6xY5VE1EG1Pg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 09/27] virDomainMemoryTargetDefFormat: Utilize virXMLFormatElement() Date: Thu, 3 Dec 2020 13:36:12 +0100 Message-Id: <0e0d5bfd577ff5ee3c30b9b8c97346e8e5a3cacf.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The virDomainMemoryTargetDefFormat() uses good old style of formatting child buffer (virBufferAdjustIndent()). When switched to virXMLFormatElement() we can save a couple of lines Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/conf/domain_conf.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bb0d9f4501..7d9e5d14ad 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27882,24 +27882,21 @@ static void virDomainMemoryTargetDefFormat(virBufferPtr buf, virDomainMemoryDefPtr def) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); =20 - virBufferAsprintf(buf, "%llu\n", def->size); + virBufferAsprintf(&childBuf, "%llu\n", def->= size); if (def->targetNode >=3D 0) - virBufferAsprintf(buf, "%d\n", def->targetNode); + virBufferAsprintf(&childBuf, "%d\n", def->targetNode); if (def->labelsize) { - virBufferAddLit(buf, "\n"); + g_auto(virBuffer) labelChildBuf =3D VIR_BUFFER_INIT_CHILD(&childBu= f); + + virBufferAsprintf(&labelChildBuf, "%llu\= n", def->labelsize); + virXMLFormatElement(&childBuf, "label", NULL, &labelChildBuf); } if (def->readonly) - virBufferAddLit(buf, "\n"); + virBufferAddLit(&childBuf, "\n"); =20 - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virXMLFormatElement(buf, "target", NULL, &childBuf); } =20 static int --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999030; cv=none; d=zohomail.com; s=zohoarc; b=CNKlFFgnTQ7xnFfFzJTzsC5nKsciQVnVli7tc6ZBvNxKkVtCfWX0NWvcVDV0/Wei4gM/7fNpXl4h4o51y3sfIJWWOYNXlDxs6XKS1Fcn6TLxaQQPhYY+X6OtAcxPGZmNeWoDrJh7vBoAxBJk9JBx7zWqf0aIrlDb+tcfH/w7akY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999030; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KZLxxKF1iwH0utKZo7lcc2hKDYEzuNGJMr8od5TBQpY=; b=GKPN8ycUKZXKcMHe4VeEGOC+5tOf1piPxmVN0DcRMuv5f1RJeKgmP2XdJNSb4XuAWNYe56a90xMm6ujBrOrKs7S3hjJQhcdy05lAvk4hf5jfX7IOhcHKHnTjqKnL/XhT1CP86fGzPExJ4qcE4LAkbwq2TwRrpPFuhI6Tfw6F698= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999030578579.4016466912084; Thu, 3 Dec 2020 04:37:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-IURA4IwnPPKau2fGthufyg-1; Thu, 03 Dec 2020 07:37:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A9CA8042D0; Thu, 3 Dec 2020 12:37:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA5DE5C1C2; Thu, 3 Dec 2020 12:37:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B4BF350031; Thu, 3 Dec 2020 12:37:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Caw5G003006 for ; Thu, 3 Dec 2020 07:36:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B94F35C1D5; Thu, 3 Dec 2020 12:36:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39B505C1C2 for ; Thu, 3 Dec 2020 12:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999029; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KZLxxKF1iwH0utKZo7lcc2hKDYEzuNGJMr8od5TBQpY=; b=IUS6+tEjkxdjv6DMvwkEVUd4R1+UdVARi1CMmzb0UQ4MNkAdy3c18bU4/a5r0EIeW8Zv8+ 918vJE83DbnF54qUYSZuGfAMbR4hEFv+TVax8Tr3zpzIpuCSF9CqYJjXFmXe7lPMPgf625 3o3cgLH5nwqMVmlcSveEAVlXX/9gddY= X-MC-Unique: IURA4IwnPPKau2fGthufyg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 10/27] qemu: Move mem validation into post parse validator Date: Thu, 3 Dec 2020 13:36:13 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There is this function qemuDomainDefValidateMemoryHotplug() which is called explicitly from hotplug path and the qemu's domain def validator. This is not really necessary because we can move the part that validates feature against qemuCaps into device validator which is called implicitly (from qemu driver's POV). Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_domain.c | 32 +------------------------------- src/qemu/qemu_validate.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 19a699540f..e705e8d8d5 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8544,14 +8544,12 @@ qemuDomainDefValidateMemoryHotplugDevice(const virD= omainMemoryDef *mem, */ int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def, - virQEMUCapsPtr qemuCaps, + virQEMUCapsPtr qemuCaps G_GNUC_UNUSED, const virDomainMemoryDef *mem) { unsigned int nmems =3D def->nmems; unsigned long long hotplugSpace; unsigned long long hotplugMemory =3D 0; - bool needPCDimmCap =3D false; - bool needNvdimmCap =3D false; size_t i; =20 hotplugSpace =3D def->mem.max_memory - virDomainDefGetMemoryInitial(de= f); @@ -8598,40 +8596,12 @@ qemuDomainDefValidateMemoryHotplug(const virDomainD= ef *def, for (i =3D 0; i < def->nmems; i++) { hotplugMemory +=3D def->mems[i]->size; =20 - switch (def->mems[i]->model) { - case VIR_DOMAIN_MEMORY_MODEL_DIMM: - needPCDimmCap =3D true; - break; - - case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - needNvdimmCap =3D true; - break; - - case VIR_DOMAIN_MEMORY_MODEL_NONE: - case VIR_DOMAIN_MEMORY_MODEL_LAST: - break; - } - /* already existing devices don't need to be checked on hotplug */ if (!mem && qemuDomainDefValidateMemoryHotplugDevice(def->mems[i], def) < = 0) return -1; } =20 - if (needPCDimmCap && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PC_DIMM)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("memory hotplug isn't supported by this QEMU bina= ry")); - return -1; - } - - if (needNvdimmCap && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVDIMM)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("nvdimm isn't supported by this QEMU binary")); - return -1; - } - if (hotplugMemory > hotplugSpace) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("memory device total size exceeds hotplug space")= ); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 6f4662b25a..8ceea022d7 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4595,7 +4595,16 @@ static int qemuValidateDomainDeviceDefMemory(virDomainMemoryDefPtr mem, virQEMUCapsPtr qemuCaps) { - if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PC_DIMM)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("memory hotplug isn't supported by this QEMU = binary")); + return -1; + } + break; + + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVDIMM)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("nvdimm isn't supported by this QEMU binary")= ); @@ -4609,6 +4618,11 @@ qemuValidateDomainDeviceDefMemory(virDomainMemoryDef= Ptr mem, "with this QEMU binary")); return -1; } + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; } =20 return 0; --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999036; cv=none; d=zohomail.com; s=zohoarc; b=ZIORGguDvm5STs2cvewOcMytUCnIUqV+0w99zV5mWVzkZPCM6W2PwDCsMMhmzDiX0g9+iai0PQhczbxnLGItZcSf2gl+Wv0wSUkHtw7qCYVxlVqE+XI9kHDncTyZOxNfA4aROkBsFojz7QZwNW/LPw3TXG/KD/lsmOjZER988AQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999036; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kq/l3SU13ztKdriv9G4HE09HaCX0hSS8bRJ+aJ2Nky8=; b=XR0hFv/MIYUsdbVkC8krZ0RaAfd6SRdHeFD6xry6Fp1nZZ/xKnRPq3E7wOuuwHXacxXmMSwlPGq7D4NRMlN7ItO36YVjzK4gDapo2PLXaodUnml14L0ylShWlPp9xmKC2Rtr/07T6nlbiM5xSPqtd3wg5Pake3SE2CGjmixVPT8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999036633544.3263886826924; Thu, 3 Dec 2020 04:37:16 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-NdEb3NC1MBuOJfzES01XcQ-1; Thu, 03 Dec 2020 07:37:12 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 86C70185E4B2; Thu, 3 Dec 2020 12:37:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D6B65D9E3; Thu, 3 Dec 2020 12:37:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 253D550037; Thu, 3 Dec 2020 12:37:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CaxC3003017 for ; Thu, 3 Dec 2020 07:36:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id C8F4F5C1CF; Thu, 3 Dec 2020 12:36:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AC415C1C2 for ; Thu, 3 Dec 2020 12:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999035; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kq/l3SU13ztKdriv9G4HE09HaCX0hSS8bRJ+aJ2Nky8=; b=f9aKtQoLLVGNhXdK6nGm0RY/XsHisjEXr6+BbkK0Qd6lgoFfp2dgT5IbUw4erp88dB8/pE 9CZ0H+ChVxkXFHYTzA0c0jq32elW4VXYlN/PDqGwyU4AKr582uK3JGBcHlHCelD1sju0i7 ou0pUdUwPOMLGNlT4FX0TCnzXzcQXUU= X-MC-Unique: NdEb3NC1MBuOJfzES01XcQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 11/27] conf: Move some of virDomainMemoryDef members into a union Date: Thu, 3 Dec 2020 13:36:14 +0100 Message-Id: <57e76dabdaa7f273147ed016de821050c1710ac1.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The structure has two sets of members: some for the target and some for the source. The latter is model dependant (e.g. path to a nvdimm device applies only to NVDIMM model). Move the members into an union so that it is obvious which members apply to which model. This way it's easier to maintain code cleanliness when introducing a new model. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/conf/domain_conf.c | 57 ++++++++++++++++++------------ src/conf/domain_conf.h | 16 ++++++--- src/qemu/qemu_alias.c | 13 +++++-- src/qemu/qemu_cgroup.c | 10 +++--- src/qemu/qemu_command.c | 60 +++++++++++++++++++++----------- src/qemu/qemu_namespace.c | 2 +- src/qemu/qemu_process.c | 8 ++--- src/security/security_apparmor.c | 6 ++-- src/security/security_dac.c | 4 +-- src/security/security_selinux.c | 4 +-- src/security/virt-aa-helper.c | 2 +- 11 files changed, 113 insertions(+), 69 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7d9e5d14ad..4d462b0627 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3136,8 +3136,18 @@ void virDomainMemoryDefFree(virDomainMemoryDefPtr de= f) if (!def) return; =20 - VIR_FREE(def->nvdimmPath); - virBitmapFree(def->sourceNodes); + switch (def->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + virBitmapFree(def->s.dimm.sourceNodes); + break; + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + VIR_FREE(def->s.nvdimm.path); + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } + virDomainDeviceInfoClear(&def->info); VIR_FREE(def); } @@ -6694,7 +6704,7 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *= mem, const virDomainDef *def) { if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { - if (!mem->nvdimmPath) { + if (!mem->s.nvdimm.path) { virReportError(VIR_ERR_XML_DETAIL, "%s", _("path is required for model 'nvdimm'")); return -1; @@ -16679,15 +16689,15 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (virDomainParseMemory("./pagesize", "./pagesize/@unit", ctxt, - &def->pagesize, false, false) < 0) + &def->s.dimm.pagesize, false, false) < 0) return -1; =20 if ((nodemask =3D virXPathString("string(./nodemask)", ctxt))) { - if (virBitmapParse(nodemask, &def->sourceNodes, + if (virBitmapParse(nodemask, &def->s.dimm.sourceNodes, VIR_DOMAIN_CPUMASK_LEN) < 0) return -1; =20 - if (virBitmapIsAllClear(def->sourceNodes)) { + if (virBitmapIsAllClear(def->s.dimm.sourceNodes)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'nodemask': %s"), nodem= ask); return -1; @@ -16696,14 +16706,14 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, break; =20 case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - def->nvdimmPath =3D virXPathString("string(./path)", ctxt); + def->s.nvdimm.path =3D virXPathString("string(./path)", ctxt); =20 if (virDomainParseMemory("./alignsize", "./alignsize/@unit", ctxt, - &def->alignsize, false, false) < 0) + &def->s.nvdimm.alignsize, false, false) <= 0) return -1; =20 if (virXPathBoolean("boolean(./pmem)", ctxt)) - def->nvdimmPmem =3D true; + def->s.nvdimm.pmem =3D true; =20 break; =20 @@ -18583,15 +18593,15 @@ virDomainMemoryFindByDefInternal(virDomainDefPtr = def, switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: /* source stuff -> match with device */ - if (tmp->pagesize !=3D mem->pagesize) + if (tmp->s.dimm.pagesize !=3D mem->s.dimm.pagesize) continue; =20 - if (!virBitmapEqual(tmp->sourceNodes, mem->sourceNodes)) + if (!virBitmapEqual(tmp->s.dimm.sourceNodes, mem->s.dimm.sourc= eNodes)) continue; break; =20 case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - if (STRNEQ(tmp->nvdimmPath, mem->nvdimmPath)) + if (STRNEQ(tmp->s.nvdimm.path, mem->s.nvdimm.path)) continue; break; =20 @@ -24186,15 +24196,15 @@ virDomainMemoryDefCheckABIStability(virDomainMemo= ryDefPtr src, return false; } =20 - if (src->alignsize !=3D dst->alignsize) { + if (src->s.nvdimm.alignsize !=3D dst->s.nvdimm.alignsize) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target NVDIMM alignment '%llu' doesn't match= " "source NVDIMM alignment '%llu'"), - src->alignsize, dst->alignsize); + src->s.nvdimm.alignsize, dst->s.nvdimm.alignsiz= e); return false; } =20 - if (src->nvdimmPmem !=3D dst->nvdimmPmem) { + if (src->s.nvdimm.pmem !=3D dst->s.nvdimm.pmem) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Target NVDIMM pmem flag doesn't match " "source NVDIMM pmem flag")); @@ -27844,26 +27854,27 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, =20 switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: - if (def->sourceNodes) { - if (!(bitmap =3D virBitmapFormat(def->sourceNodes))) + if (def->s.dimm.sourceNodes) { + if (!(bitmap =3D virBitmapFormat(def->s.dimm.sourceNodes))) return -1; =20 virBufferAsprintf(&childBuf, "%s\n", bitm= ap); } =20 - if (def->pagesize) + if (def->s.dimm.pagesize) { virBufferAsprintf(&childBuf, "%llu\n", - def->pagesize); + def->s.dimm.pagesize); + } break; =20 case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - virBufferEscapeString(&childBuf, "%s\n", def->nvdimmP= ath); + virBufferEscapeString(&childBuf, "%s\n", def->s.nvdim= m.path); =20 - if (def->alignsize) + if (def->s.nvdimm.alignsize) virBufferAsprintf(&childBuf, "%llu\n", - def->alignsize); + def->s.nvdimm.alignsize); =20 - if (def->nvdimmPmem) + if (def->s.nvdimm.pmem) virBufferAddLit(&childBuf, "\n"); break; =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5853e3b290..e7f8fc156f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2315,11 +2315,17 @@ struct _virDomainMemoryDef { virTristateBool discard; =20 /* source */ - virBitmapPtr sourceNodes; - unsigned long long pagesize; /* kibibytes */ - char *nvdimmPath; - unsigned long long alignsize; /* kibibytes; valid only for NVDIMM */ - bool nvdimmPmem; /* valid only for NVDIMM */ + union { + struct { + virBitmapPtr sourceNodes; + unsigned long long pagesize; /* kibibytes */ + } dimm; /* VIR_DOMAIN_MEMORY_MODEL_DIMM */ + struct { + char *path; + unsigned long long alignsize; /* kibibytes */ + bool pmem; + } nvdimm; /* VIR_DOMAIN_MEMORY_MODEL_NVDIMM */ + } s; =20 /* target */ virDomainMemoryModel model; diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index dcb6c7156d..5ebcd766a9 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -486,15 +486,22 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, size_t i; int maxidx =3D 0; int idx; - const char *prefix; + const char *prefix =3D NULL; =20 if (mem->info.alias) return 0; =20 - if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM) + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: prefix =3D "dimm"; - else + break; + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: prefix =3D "nvdimm"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } =20 if (oldAlias) { for (i =3D 0; i < def->nmems; i++) { diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index f7146a71c9..92caadf840 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -508,11 +508,11 @@ qemuSetupMemoryDevicesCgroup(virDomainObjPtr vm, if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - VIR_DEBUG("Setting devices Cgroup for NVDIMM device: %s", mem->nvdimmP= ath); - rv =3D virCgroupAllowDevicePath(priv->cgroup, mem->nvdimmPath, + VIR_DEBUG("Setting devices Cgroup for NVDIMM device: %s", mem->s.nvdim= m.path); + rv =3D virCgroupAllowDevicePath(priv->cgroup, mem->s.nvdimm.path, VIR_CGROUP_DEVICE_RW, false); virDomainAuditCgroupPath(vm, priv->cgroup, "allow", - mem->nvdimmPath, "rw", rv); + mem->s.nvdimm.path, "rw", rv); =20 return rv; } @@ -531,10 +531,10 @@ qemuTeardownMemoryDevicesCgroup(virDomainObjPtr vm, if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - rv =3D virCgroupDenyDevicePath(priv->cgroup, mem->nvdimmPath, + rv =3D virCgroupDenyDevicePath(priv->cgroup, mem->s.nvdimm.path, VIR_CGROUP_DEVICE_RWM, false); virDomainAuditCgroupPath(vm, priv->cgroup, - "deny", mem->nvdimmPath, "rwm", rv); + "deny", mem->s.nvdimm.path, "rwm", rv); return rv; } =20 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index eb64ce84da..4bd45e0638 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2958,10 +2958,13 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, int rc; g_autoptr(virJSONValue) props =3D NULL; bool nodeSpecified =3D virDomainNumatuneNodeSpecified(def->numa, mem->= targetNode); - unsigned long long pagesize =3D mem->pagesize; - bool needHugepage =3D !!pagesize; - bool useHugepage =3D !!pagesize; + unsigned long long pagesize =3D 0; + bool needHugepage =3D false; + bool useHugepage =3D false; int discard =3D mem->discard; + const char *nvdimmPath =3D NULL; + unsigned long long alignsize =3D 0; + bool nvdimmPmem =3D false; =20 /* The difference between @needHugepage and @useHugepage is that the l= atter * is true whenever huge page is defined for the current memory cell. @@ -2971,6 +2974,23 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backend= Props, =20 *backendProps =3D NULL; =20 + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + pagesize =3D mem->s.dimm.pagesize; + needHugepage =3D !!pagesize; + useHugepage =3D !!pagesize; + nodemask =3D mem->s.dimm.sourceNodes; + break; + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + nvdimmPath =3D mem->s.nvdimm.path; + alignsize =3D mem->s.nvdimm.alignsize; + nvdimmPmem =3D mem->s.nvdimm.pmem; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } + if (mem->targetNode >=3D 0) { /* memory devices could provide a invalid guest node */ if (mem->targetNode >=3D virDomainNumaGetNodeCount(def->numa)) { @@ -3076,11 +3096,11 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, if (qemuBuildMemoryBackendPropsShare(props, memAccess) < 0) return -1; =20 - } else if (useHugepage || mem->nvdimmPath || memAccess || - def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { + } else if (useHugepage || nvdimmPath || memAccess || + def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { =20 - if (mem->nvdimmPath) { - memPath =3D g_strdup(mem->nvdimmPath); + if (nvdimmPath) { + memPath =3D g_strdup(nvdimmPath); prealloc =3D true; } else if (useHugepage) { if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &m= emPath) < 0) @@ -3098,7 +3118,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, NULL) < 0) return -1; =20 - if (!mem->nvdimmPath && + if (!nvdimmPath && discard =3D=3D VIR_TRISTATE_BOOL_YES) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FI= LE_DISCARD)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -3125,18 +3145,18 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0) return -1; =20 - if (mem->alignsize) { + if (alignsize) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE_A= LIGN)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("nvdimm align property is not available " "with this QEMU binary")); return -1; } - if (virJSONValueObjectAdd(props, "U:align", mem->alignsize * 1024,= NULL) < 0) + if (virJSONValueObjectAdd(props, "U:align", alignsize * 1024, NULL= ) < 0) return -1; } =20 - if (mem->nvdimmPmem) { + if (nvdimmPmem) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE_P= MEM)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("nvdimm pmem property is not available " @@ -3147,13 +3167,10 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, return -1; } =20 - if (mem->sourceNodes) { - nodemask =3D mem->sourceNodes; - } else { - if (virDomainNumatuneMaybeGetNodeset(def->numa, priv->autoNodeset, - &nodemask, mem->targetNode) <= 0) - return -1; - } + if (!nodemask && + virDomainNumatuneMaybeGetNodeset(def->numa, priv->autoNodeset, + &nodemask, mem->targetNode) < 0) + return -1; =20 if (nodemask) { if (!virNumaNodesetIsAvailable(nodemask)) @@ -3166,8 +3183,11 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backend= Props, } =20 /* If none of the following is requested... */ - if (!needHugepage && !mem->sourceNodes && !nodeSpecified && - !mem->nvdimmPath && + if (!needHugepage && + !(mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM && + mem->s.dimm.sourceNodes) && + !nodeSpecified && + !nvdimmPath && memAccess =3D=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT && def->mem.source !=3D VIR_DOMAIN_MEMORY_SOURCE_FILE && def->mem.source !=3D VIR_DOMAIN_MEMORY_SOURCE_MEMFD && diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 1002455ddf..b8aebd1e61 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -354,7 +354,7 @@ qemuDomainSetupMemory(virDomainMemoryDefPtr mem, if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) return 0; =20 - return virStringListAdd(paths, mem->nvdimmPath); + return virStringListAdd(paths, mem->s.nvdimm.path); } =20 =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 20e90026e1..8ea7e0df05 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3885,15 +3885,15 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def, =20 for (i =3D 0; i < def->nmems; i++) { if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM && - def->mems[i]->pagesize && - def->mems[i]->pagesize !=3D system_pagesize) + def->mems[i]->s.dimm.pagesize && + def->mems[i]->s.dimm.pagesize !=3D system_pagesize) return true; } =20 if (mem && mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM && - mem->pagesize && - mem->pagesize !=3D system_pagesize) + mem->s.dimm.pagesize && + mem->s.dimm.pagesize !=3D system_pagesize) return true; =20 return false; diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index eed66e460f..78136e751e 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -686,13 +686,13 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr, =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - if (!virFileExists(mem->nvdimmPath)) { + if (!virFileExists(mem->s.nvdimm.path)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: \'%s\' does not exist"), - __func__, mem->nvdimmPath); + __func__, mem->s.nvdimm.path); return -1; } - return reload_profile(mgr, def, mem->nvdimmPath, true); + return reload_profile(mgr, def, mem->s.nvdimm.path, true); case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4f4a0a069e..44ee42e1bd 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1889,7 +1889,7 @@ virSecurityDACRestoreMemoryLabel(virSecurityManagerPt= r mgr, =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - ret =3D virSecurityDACRestoreFileLabel(mgr, mem->nvdimmPath); + ret =3D virSecurityDACRestoreFileLabel(mgr, mem->s.nvdimm.path); break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: @@ -2070,7 +2070,7 @@ virSecurityDACSetMemoryLabel(virSecurityManagerPtr mg= r, return -1; =20 ret =3D virSecurityDACSetOwnership(mgr, NULL, - mem->nvdimmPath, + mem->s.nvdimm.path, user, group, true); break; =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e9cd95916e..294c9f1db5 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1577,7 +1577,7 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManagerPt= r mgr, if (!seclabel || !seclabel->relabel) return 0; =20 - if (virSecuritySELinuxSetFilecon(mgr, mem->nvdimmPath, + if (virSecuritySELinuxSetFilecon(mgr, mem->s.nvdimm.path, seclabel->imagelabel, true) < 0) return -1; break; @@ -1606,7 +1606,7 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityManag= erPtr mgr, if (!seclabel || !seclabel->relabel) return 0; =20 - ret =3D virSecuritySELinuxRestoreFileLabel(mgr, mem->nvdimmPath, t= rue); + ret =3D virSecuritySELinuxRestoreFileLabel(mgr, mem->s.nvdimm.path= , true); break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 5a6f4a5f7d..a8a05a0a90 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1170,7 +1170,7 @@ get_files(vahControl * ctl) for (i =3D 0; i < ctl->def->nmems; i++) { if (ctl->def->mems[i] && ctl->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NV= DIMM) { - if (vah_add_file(&buf, ctl->def->mems[i]->nvdimmPath, "rw") != =3D 0) + if (vah_add_file(&buf, ctl->def->mems[i]->s.nvdimm.path, "rw")= !=3D 0) goto cleanup; } } --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999095; cv=none; d=zohomail.com; s=zohoarc; b=iReyudwKqJzTBoNoPu4nCUdWepiZ/Hb1UUHhm7hZDbDmi9Qvk0yNJla5s78FajH1Zo/S7xQuhw/3R7dvd5HRrUyFZ2UZL88MWXP+Limi02p5Ynmui5rJiffNKVher62AQk+/sCumJvxLQSMXXZj8pErLkeSJJsH7Y+5UvR2S2t8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999095; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gwWxNCpLENMfmNUU97VbmP/zSYIrVpNC1vS7j++dYtQ=; b=FkR1nRHa7lIUwBxbiIx2butC5iN5UkX2OD+qhGQrHG1JelYXKbeoZ+UADeTOy1lOXET4Hk4RTDr5cZ5EiarepyDHtAWse+l3UMC4RReFVW7ihKCNW7Q/SF84p0NvyQFGN2EvleCx1pCrExMetJu7ExXd5PWtHgkjL+xIjLJHsLI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999095810145.40189437939318; Thu, 3 Dec 2020 04:38:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555--po5rZzjOd-0KThGOvp_Hw-1; Thu, 03 Dec 2020 07:37:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5420C805BFD; Thu, 3 Dec 2020 12:37:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 303BE5C1BD; Thu, 3 Dec 2020 12:37:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E8F6E5003E; Thu, 3 Dec 2020 12:37:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Cb0BZ003030 for ; Thu, 3 Dec 2020 07:37:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id D2A3F5C1CF; Thu, 3 Dec 2020 12:37:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 298465C1C2 for ; Thu, 3 Dec 2020 12:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999094; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=gwWxNCpLENMfmNUU97VbmP/zSYIrVpNC1vS7j++dYtQ=; b=gE9D4mP/17zqe4zD7y6lN/DAt3wt7z4Z8RDOCSSoH/ewtJwL1FtAOZ56US1RV2vpWeXa90 cvnkH3TbCs5gcpNt0HBJh8P5CMOwsk9TwUfAcQRvVMEM0kShaILJdcI1P0vAfvtqi0TaW6 Fjlnr8bdkm05HU/XxRLBz6e/1XWHkSI= X-MC-Unique: -po5rZzjOd-0KThGOvp_Hw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 12/27] conf: Introduce virtio-pmem model Date: Thu, 3 Dec 2020 13:36:15 +0100 Message-Id: <8e8d3142ba6d0a45b91a7fcebe3db23888a2ea10.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The virtio-pmem is a virtio variant of NVDIMM and just like NVDIMM virtio-pmem also allows accessing host pages bypassing guest page cache. The difference is that if a regular file is used to back guest's NVDIMM (model=3D'nvdimm') the persistence of guest writes might not be guaranteed while with virtio-pmem it is. To express this new model at domain XML level, I've chose the following: /tmp/virtio_pmem 524288
The looks like for model=3D'nvdimm', except is required - this is to allow for future expansion when the model=3D'virtio' without will describe virtio-mem (which is a different device). Another difference between NVDIMM and virtio-pmem is that while the former supports NUMA node locality the latter doesn't. And also, the latter goes onto PCI bus and not into a DIMM module. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- docs/formatdomain.rst | 35 +++++- docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 113 ++++++++++++++++-- src/conf/domain_conf.h | 5 + src/qemu/qemu_alias.c | 1 + src/qemu/qemu_command.c | 2 + src/qemu/qemu_domain.c | 26 ++++ src/qemu/qemu_domain_address.c | 88 +++++++++++--- src/qemu/qemu_domain_address.h | 3 +- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_validate.c | 1 + src/security/security_apparmor.c | 1 + src/security/security_dac.c | 2 + src/security/security_selinux.c | 2 + .../memory-hotplug-virtio-pmem.xml | 54 +++++++++ ...mory-hotplug-virtio-pmem.x86_64-latest.xml | 1 + tests/qemuxml2xmltest.c | 2 + 17 files changed, 304 insertions(+), 35 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml create mode 120000 tests/qemuxml2xmloutdata/memory-hotplug-virtio-pmem.x86= _64-latest.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 512939679b..ca6bc0432e 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7187,20 +7187,31 @@ Example: usage of the memory devices + + + /tmp/virtio_pmem + + + + 524288 + + ... =20 ``model`` Provide ``dimm`` to add a virtual DIMM module to the guest. :since:`Sin= ce - 1.2.14` Provide ``nvdimm`` model adds a Non-Volatile DIMM module. - :since:`Since 3.2.0` + 1.2.14` Provide ``nvdimm`` model that adds a Non-Volatile DIMM module. + :since:`Since 3.2.0` Provide ``virtio`` model to add a paravirtualized + (persistent) memory device. :since:`Since 7.0.0` =20 ``access`` An optional attribute ``access`` ( :since:`since 3.2.0` ) that provides capability to fine tune mapping of the memory on per module basis. Valu= es are the same as `Memory Backing <#elementsMemoryBacking>`__: ``shared`` and ``private``. For ``nvdimm`` model, if using real NVDIMM DAX device as - backend, ``shared`` is required. + backend, ``shared`` is required. For ``virtio`` model with ```` + ``shared`` is required. =20 ``discard`` An optional attribute ``discard`` ( :since:`since 4.4.0` ) that provides @@ -7229,9 +7240,9 @@ Example: usage of the memory devices This element can be used to override the default set of NUMA nodes w= here the memory would be allocated. =20 - For model ``nvdimm`` this element is mandatory. The mandatory child ele= ment - ``path`` represents a path in the host that backs the nvdimm module in = the - guest. The following optional elements may be used: + For model ``nvdimm`` the ``source`` element is mandatory. The mandatory + child element ``path`` represents a path in the host that backs the nvd= imm + module in the guest. The following optional elements may be used: =20 ``alignsize`` The ``alignsize`` element defines the page size alignment used to mm= ap the @@ -7245,6 +7256,18 @@ Example: usage of the memory devices to guarantee the persistence of writes to the vNVDIMM backend, then = use the ``pmem`` element in order to utilize the feature. :since:`Since = 5.0.0` =20 + For model ``virtio`` the ``source`` element is mandatory. The following + optional elements may be used: + + ``path`` + Represents a path in the host that backs the virtio memory module in = the + guest. It is mandatory for persistent memory (i.e. when ``pmem`` is a= lso + set). + + ``pmem`` + If persistence of data is required then this element must be provided. + + ``target`` The mandatory ``target`` element configures the placement and sizing of= the added memory from the perspective of the guest. diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 795b654feb..b385bae84c 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5973,6 +5973,7 @@ dimm nvdimm + virtio diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4d462b0627..935bea1804 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1332,6 +1332,7 @@ VIR_ENUM_IMPL(virDomainMemoryModel, "", "dimm", "nvdimm", + "virtio", ); =20 VIR_ENUM_IMPL(virDomainShmemModel, @@ -3143,6 +3144,9 @@ void virDomainMemoryDefFree(virDomainMemoryDefPtr def) case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: VIR_FREE(def->s.nvdimm.path); break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + VIR_FREE(def->s.virtio.path); + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; @@ -5373,15 +5377,31 @@ static int virDomainMemoryDefPostParse(virDomainMemoryDefPtr mem, const virDomainDef *def) { - /* Although only the QEMU driver implements PPC64 support, this - * code is related to the platform specification (PAPR), i.e. it - * is hypervisor agnostic, and any future PPC64 hypervisor driver - * will have the same restriction. - */ - if (ARCH_IS_PPC64(def->os.arch) && - mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM && - virDomainNVDimmAlignSizePseries(mem) < 0) - return -1; + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + /* Although only the QEMU driver implements PPC64 support, this + * code is related to the platform specification (PAPR), i.e. it + * is hypervisor agnostic, and any future PPC64 hypervisor driver + * will have the same restriction. + */ + if (ARCH_IS_PPC64(def->os.arch) && + virDomainNVDimmAlignSizePseries(mem) < 0) + return -1; + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + /* Virtio-pmem mandates shared access so that guest writes get + * reflected in the underlying file. */ + if (mem->s.virtio.pmem && + mem->access =3D=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + mem->access =3D VIR_DOMAIN_MEMORY_ACCESS_SHARED; + break; + + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } =20 return 0; } @@ -6703,7 +6723,8 @@ static int virDomainMemoryDefValidate(const virDomainMemoryDef *mem, const virDomainDef *def) { - if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (!mem->s.nvdimm.path) { virReportError(VIR_ERR_XML_DETAIL, "%s", _("path is required for model 'nvdimm'")); @@ -6721,6 +6742,39 @@ virDomainMemoryDefValidate(const virDomainMemoryDef = *mem, _("label size is required for NVDIMM device")); return -1; } + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + if (mem->s.virtio.pmem) { + if (!mem->s.virtio.path) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("path is required for model 'virtio'")); + return -1; + } + + if (mem->access !=3D VIR_DOMAIN_MEMORY_ACCESS_SHARED) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("shared access mode required for virtio-p= mem device")); + return -1; + } + + if (mem->targetNode !=3D -1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio-pmem does not support NUMA nodes"= )); + return -1; + } + } else { + /* TODO: plain virtio-mem behaves differently then virtio-pmem= */ + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio-mem is not supported yet. is = required")); + return -1; + } + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; } =20 return 0; @@ -16717,6 +16771,14 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, =20 break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + def->s.virtio.path =3D virXPathString("string(./path)", ctxt); + + if (virXPathBoolean("boolean(./pmem)", ctxt)) + def->s.virtio.pmem =3D true; + + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; @@ -18605,6 +18667,12 @@ virDomainMemoryFindByDefInternal(virDomainDefPtr d= ef, continue; break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + if (tmp->s.virtio.pmem !=3D mem->s.virtio.pmem || + STRNEQ_NULLABLE(tmp->s.virtio.path, mem->s.virtio.path)) + continue; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; @@ -24187,7 +24255,8 @@ virDomainMemoryDefCheckABIStability(virDomainMemory= DefPtr src, return false; } =20 - if (src->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + switch (src->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (src->labelsize !=3D dst->labelsize) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target NVDIMM label size '%llu' doesn't matc= h " @@ -24223,6 +24292,21 @@ virDomainMemoryDefCheckABIStability(virDomainMemor= yDefPtr src, _("Target NVDIMM UUID doesn't match source NVDI= MM")); return false; } + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + if (src->s.virtio.pmem !=3D dst->s.virtio.pmem) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Target NVDIMM pmem flag doesn't match " + "source NVDIMM pmem flag")); + return false; + } + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; } =20 return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info); @@ -27878,6 +27962,13 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, virBufferAddLit(&childBuf, "\n"); break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + virBufferEscapeString(&childBuf, "%s\n", def->s.virti= o.path); + + if (def->s.virtio.pmem) + virBufferAddLit(&childBuf, "\n"); + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e7f8fc156f..efaa4c5473 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2306,6 +2306,7 @@ typedef enum { VIR_DOMAIN_MEMORY_MODEL_NONE, VIR_DOMAIN_MEMORY_MODEL_DIMM, /* dimm hotpluggable memory device */ VIR_DOMAIN_MEMORY_MODEL_NVDIMM, /* nvdimm memory device */ + VIR_DOMAIN_MEMORY_MODEL_VIRTIO, /* virtio-{p}mem memory device */ =20 VIR_DOMAIN_MEMORY_MODEL_LAST } virDomainMemoryModel; @@ -2325,6 +2326,10 @@ struct _virDomainMemoryDef { unsigned long long alignsize; /* kibibytes */ bool pmem; } nvdimm; /* VIR_DOMAIN_MEMORY_MODEL_NVDIMM */ + struct { + char *path; /* Required for pmem, otherwise optional */ + bool pmem; + } virtio; /* VIR_DOMAIN_MEMORY_MODEL_VIRTIO */ } s; =20 /* target */ diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 5ebcd766a9..931dbd4e84 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -498,6 +498,7 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: prefix =3D "nvdimm"; break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4bd45e0638..9c50778180 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2986,6 +2986,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, alignsize =3D mem->s.nvdimm.alignsize; nvdimmPmem =3D mem->s.nvdimm.pmem; break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; @@ -3339,6 +3340,7 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem) =20 break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e705e8d8d5..ab7938a355 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8485,6 +8485,8 @@ static int qemuDomainDefValidateMemoryHotplugDevice(const virDomainMemoryDef *mem, const virDomainDef *def) { + bool needsNuma =3D true; + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: @@ -8520,11 +8522,35 @@ qemuDomainDefValidateMemoryHotplugDevice(const virD= omainMemoryDef *mem, } break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + if (mem->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && + mem->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only 'pci' addresses are supported for the " + "virtio-pmem device")); + return -1; + } + + /* virtio-pmem doesn't have .node attribute. */ + if (mem->s.virtio.pmem) + needsNuma =3D false; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: return -1; } =20 + if (needsNuma && + virDomainNumaGetNodeCount(def->numa) !=3D 0) { + if (mem->targetNode =3D=3D -1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("target NUMA node needs to be specified for " + "memory device")); + return -1; + } + } + return 0; } =20 diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index d872f75b38..bcf6724da3 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -313,11 +313,11 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr = def, virDomainDeviceAddressType type) { /* - declare address-less virtio devices to be of address type 'type' - disks, networks, videos, consoles, controllers, memballoon and rng - in this order - if type is ccw filesystem and vsock devices are declared to be of - address type ccw + Declare address-less virtio devices to be of address type 'type' + disks, networks, videos, consoles, controllers, hostdevs, memballoo= n, + rngs and memories in this order. + If type is ccw filesystem and vsock devices are declared to be of + address type ccw. */ size_t i; =20 @@ -379,6 +379,12 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr d= ef, def->rngs[i]->info.type =3D type; } =20 + for (i =3D 0; i < def->nmems; i++) { + if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO && + def->mems[i]->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_= NONE) + def->mems[i]->info.type =3D type; + } + if (type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) { for (i =3D 0; i < def->nfss; i++) { if (def->fss[i]->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TY= PE_NONE) @@ -1040,11 +1046,23 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainD= eviceDefPtr dev, } break; =20 + case VIR_DOMAIN_DEVICE_MEMORY: + switch (dev->data.memory->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + return virtioFlags; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + return 0; + } + break; + /* These devices don't ever connect with PCI */ case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: - case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_HUB: case VIR_DOMAIN_DEVICE_REDIRDEV: case VIR_DOMAIN_DEVICE_SMARTCARD: @@ -2455,6 +2473,17 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, return -1; } =20 + for (i =3D 0; i < def->nmems; i++) { + virDomainMemoryDefPtr mem =3D def->mems[i]; + + if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO || + !virDeviceInfoPCIAddressIsWanted(&mem->info)) + continue; + + if (qemuDomainPCIAddressReserveNextAddr(addrs, &mem->info) < 0) + return -1; + } + return 0; } =20 @@ -3102,19 +3131,32 @@ qemuAssignMemoryDeviceSlot(virDomainMemoryDefPtr me= m, =20 =20 int -qemuDomainAssignMemoryDeviceSlot(virDomainDefPtr def, +qemuDomainAssignMemoryDeviceSlot(virQEMUDriverPtr driver, + virDomainObjPtr vm, virDomainMemoryDefPtr mem) { - virBitmapPtr slotmap =3D NULL; - int ret; + g_autoptr(virBitmap) slotmap =3D NULL; + virDomainDeviceDef dev =3D {.type =3D VIR_DOMAIN_DEVICE_MEMORY, .data.= memory =3D mem}; =20 - if (!(slotmap =3D qemuDomainGetMemorySlotMap(def))) - return -1; + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + if (!(slotmap =3D qemuDomainGetMemorySlotMap(vm->def))) + return -1; =20 - ret =3D qemuAssignMemoryDeviceSlot(mem, slotmap); + return qemuAssignMemoryDeviceSlot(mem, slotmap); + break; =20 - virBitmapFree(slotmap); - return ret; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + return qemuDomainEnsurePCIAddress(vm, &dev, driver); + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } + + return 0; } =20 =20 @@ -3132,8 +3174,22 @@ qemuDomainAssignMemorySlots(virDomainDefPtr def) return -1; =20 for (i =3D 0; i < def->nmems; i++) { - if (qemuAssignMemoryDeviceSlot(def->mems[i], slotmap) < 0) - goto cleanup; + virDomainMemoryDefPtr mem =3D def->mems[i]; + + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + if (qemuAssignMemoryDeviceSlot(def->mems[i], slotmap) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + /* handled in qemuDomainAssignPCIAddresses() */ + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } } =20 ret =3D 0; diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 7ef3308246..20a46160d5 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -56,7 +56,8 @@ void qemuDomainFillDeviceIsolationGroup(virDomainDefPtr d= ef, void qemuDomainReleaseDeviceAddress(virDomainObjPtr vm, virDomainDeviceInfoPtr info); =20 -int qemuDomainAssignMemoryDeviceSlot(virDomainDefPtr def, +int qemuDomainAssignMemoryDeviceSlot(virQEMUDriverPtr driver, + virDomainObjPtr vm, virDomainMemoryDefPtr mem); =20 int qemuDomainEnsureVirtioAddress(bool *releaseAddr, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 2c12ef60af..1f9df182bf 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2402,7 +2402,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (qemuDomainDefValidateMemoryHotplug(vm->def, priv->qemuCaps, mem) <= 0) goto cleanup; =20 - if (qemuDomainAssignMemoryDeviceSlot(vm->def, mem) < 0) + if (qemuDomainAssignMemoryDeviceSlot(driver, vm, mem) < 0) goto cleanup; =20 /* in cases where we are using a VM with aliases generated according t= o the diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 8ceea022d7..fc9bc7a5b4 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4620,6 +4620,7 @@ qemuValidateDomainDeviceDefMemory(virDomainMemoryDefP= tr mem, } break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 78136e751e..b22ee739d8 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -693,6 +693,7 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr, return -1; } return reload_profile(mgr, def, mem->s.nvdimm.path, true); + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 44ee42e1bd..6b681c4021 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1892,6 +1892,7 @@ virSecurityDACRestoreMemoryLabel(virSecurityManagerPt= r mgr, ret =3D virSecurityDACRestoreFileLabel(mgr, mem->s.nvdimm.path); break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -2074,6 +2075,7 @@ virSecurityDACSetMemoryLabel(virSecurityManagerPtr mg= r, user, group, true); break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 294c9f1db5..77b69447da 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1582,6 +1582,7 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManagerPt= r mgr, return -1; break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: @@ -1609,6 +1610,7 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityManag= erPtr mgr, ret =3D virSecuritySELinuxRestoreFileLabel(mgr, mem->s.nvdimm.path= , true); break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml b/tests/= qemuxml2argvdata/memory-hotplug-virtio-pmem.xml new file mode 100644 index 0000000000..3570b7d1b1 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml @@ -0,0 +1,54 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 1099511627776 + 2095104 + 2095104 + 2 + + hvm + + + + qemu64 + + + + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + +
+ + +
+ + +
+ + + + + +
+ + + + /tmp/virtio_pmem + + + + 524288 + +
+ + + diff --git a/tests/qemuxml2xmloutdata/memory-hotplug-virtio-pmem.x86_64-lat= est.xml b/tests/qemuxml2xmloutdata/memory-hotplug-virtio-pmem.x86_64-latest= .xml new file mode 120000 index 0000000000..904425abe4 --- /dev/null +++ b/tests/qemuxml2xmloutdata/memory-hotplug-virtio-pmem.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/memory-hotplug-virtio-pmem.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index c006719dee..e804db8aee 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1238,6 +1238,8 @@ mymain(void) QEMU_CAPS_DEVICE_NVDIMM_UNAR= MED); DO_TEST("memory-hotplug-nvdimm-ppc64", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST= _BRIDGE, QEMU_CAPS_DEVICE_NVDIMM); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); + DO_TEST("net-udp", NONE); =20 DO_TEST("video-virtio-gpu-device", QEMU_CAPS_DEVICE_VIRTIO_GPU); --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999087; cv=none; d=zohomail.com; s=zohoarc; b=GjuDWPm9Gjgr7bo2E4N9uKCN2Aw6fczTwr0o+mv26IoleUyt36GTSkFvwMAT6TJccduvD6faDHStH7FOOgX3OsFYUqbimsbK9SEY4G7MhYUISkHoFBIF5QKY/H556Y76PMACWh3xSKT7eZY8tfNAPs/eRZdj6pBLRjPmvcpj7x4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999087; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NwmBRGHsO7pBmxwvH2xnWCwDSnM4jWV1F1AnJF933/E=; b=avhRV/pQXcOlSDFpJCFCb4oTbCI93pxXCPDHWi86YcFROOCmROvjDlIFsbNlwXkpcuMNoP//MdEp58/rkx7kfsePuFPuWZG6lBxGMPQDB4c21NneUBUsBI/RxF+NyB+GHXLRa2izMPmh1oArnoRDvYEv1QvJBwUPF1SWasK/yRY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999087071873.7669788250623; Thu, 3 Dec 2020 04:38:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-foVjOvVmNK-Wrw8-HG6AWQ-1; Thu, 03 Dec 2020 07:37:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0ADF71081B24; Thu, 3 Dec 2020 12:37:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF8DF60C17; Thu, 3 Dec 2020 12:37:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ADB6650040; Thu, 3 Dec 2020 12:37:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Cb1SV003041 for ; Thu, 3 Dec 2020 07:37:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id AEC275C1CF; Thu, 3 Dec 2020 12:37:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 305A45C1C2 for ; Thu, 3 Dec 2020 12:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999085; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NwmBRGHsO7pBmxwvH2xnWCwDSnM4jWV1F1AnJF933/E=; b=aUmGQTeonNVE9DIdoRc7tp2qpngadwHDEICoafeeEhFimBbOWgRI4LjVYgZtHIqMRFfaDx P4J3p8jnWWH93OJUkMBGC0T/7DMlec8an4oh3lOIV2Mb74O9CHMUhj7ZQR2g8FbrkyCLeT vwSVCScZhwvnRKP7DThGDi1HmuW/5uQ= X-MC-Unique: foVjOvVmNK-Wrw8-HG6AWQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 13/27] qemu_capabilities: Introduce QEMU_CAPS_DEVICE_VIRTIO_{P}MEM_PCI Date: Thu, 3 Dec 2020 13:36:16 +0100 Message-Id: <843824ab4546292c81f186b652873cca0da76947.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In this commit two new capabilities are introduced that reflect device support by give qemu: QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ QEMU_CAPS_DEVICE_VIRTIO_PMEM_PCI, /* -device virtio-pmem-pci */ Please note, virtio-pmem device was introduced sooner (QEMU 4.1) than virtio-mem (QEMU 5.1). Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_capabilities.c | 4 ++++ src/qemu/qemu_capabilities.h | 2 ++ tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml | 2 ++ tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml | 2 ++ 7 files changed, 13 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 4d132defbd..14e6892fb2 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -609,6 +609,8 @@ VIR_ENUM_IMPL(virQEMUCaps, "ncr53c90", "dc390", "am53c974", + "virtio-mem-pci", + "virtio-pmem-pci", ); =20 =20 @@ -1325,6 +1327,8 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[= ] =3D { */ { "dc390", QEMU_CAPS_SCSI_DC390 }, { "am53c974", QEMU_CAPS_SCSI_AM53C974 }, + { "virtio-mem-pci", QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI }, + { "virtio-pmem-pci", QEMU_CAPS_DEVICE_VIRTIO_PMEM_PCI }, }; =20 =20 diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 0f90efa459..b21e56b1db 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -589,6 +589,8 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_SCSI_NCR53C90, /* built-in SCSI */ QEMU_CAPS_SCSI_DC390, /* -device dc-390 */ QEMU_CAPS_SCSI_AM53C974, /* -device am53c974 */ + QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ + QEMU_CAPS_DEVICE_VIRTIO_PMEM_PCI, /* -device virtio-pmem-pci */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.1.0.x86_64.xml index 58774fddcc..28a4b0ede0 100644 --- a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml @@ -231,6 +231,7 @@ + 4001000 0 43100241 diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.2.0.x86_64.xml index 1ba8c09374..e150741f11 100644 --- a/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml @@ -240,6 +240,7 @@ + 4002000 0 43100242 diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_5.0.0.x86_64.xml index 849727eb40..7c56d110f4 100644 --- a/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml @@ -247,6 +247,7 @@ + 5000000 0 43100241 diff --git a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_5.1.0.x86_64.xml index ff5f42a563..ae8787981a 100644 --- a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml @@ -249,6 +249,8 @@ + + 5001000 0 43100242 diff --git a/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_5.2.0.x86_64.xml index 5e9fa8575a..f0892cdbe5 100644 --- a/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml @@ -251,6 +251,8 @@ + + 5001091 0 43100243 --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999214; cv=none; d=zohomail.com; s=zohoarc; b=jt5QkusXvAflieT/+IHaBwVjMn+f/MsbRM+YXp2Wbg4YeYbMH3KpYqavy/L+n3p9J0Xy+8ec0HB4TsTe6A1P/K2AkzNI7muislgieoV/sYyygyx3EM42Z0AwjPw6VMv0kUjud70gBezY6EcQdQlZrWWFmImGuaK/WeQenpUaw10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999214; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=S6b0j5/S9UhH5grBzw+DEL2UIkvxbJ48yUt3S+Rx9jE=; b=PzyPZfCzZggrSCUD2mcIhLHD7/ed5Jv138yX+RjJbak75EHxN6o4zFlbLI/6KV6tI6VHQ5voJ5KbaEI+p7pZnsHkyW778l8AV6evCt6sVtJHeXy6tbNjKJH2YH6pWEXhsp+jb7s+rLzNf6hEv4wFr9gObG2+II52CZUr7UN66TA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999214716447.81579864299295; Thu, 3 Dec 2020 04:40:14 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-uzhd-5rFMQWozJiwAiQvew-1; Thu, 03 Dec 2020 07:37:19 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94AFF1006C96; Thu, 3 Dec 2020 12:37:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72E0D6085A; Thu, 3 Dec 2020 12:37:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 36C5D50046; Thu, 3 Dec 2020 12:37:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Cb5L9003153 for ; Thu, 3 Dec 2020 07:37:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4BDD35C1C2; Thu, 3 Dec 2020 12:37:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id C18F55C1D0 for ; Thu, 3 Dec 2020 12:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999211; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=S6b0j5/S9UhH5grBzw+DEL2UIkvxbJ48yUt3S+Rx9jE=; b=hXOxLAlUgk3fM8Bv46oYaRlWBSvAOtAqfPQ2UGhNemEm+YvZbIXWJjeZ9ALjZ/CnTZmiym pb+2++nKkFU43S4VQckaJiNYweQyxP26tkygUgv+W6a8CtNXyHjq+0vVsUCwv+Kkwbt2bq qKe1G84DSNDNoQSl3DcANLDQGpn63W0= X-MC-Unique: uzhd-5rFMQWozJiwAiQvew-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 14/27] qemu_validate: Require virtio-mem device for mem model virtio Date: Thu, 3 Dec 2020 13:36:17 +0100 Message-Id: <711d5075e71742fa746f612c7f9a28dc18f779a2.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_validate.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index fc9bc7a5b4..e4d12db3bd 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4621,6 +4621,21 @@ qemuValidateDomainDeviceDefMemory(virDomainMemoryDef= Ptr mem, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + if (mem->s.virtio.pmem) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_PMEM_PCI= )) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio-pmem isn't supported by this QEMU= binary")); + return -1; + } + } else { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI)= ) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio-mem isn't supported by this QEMU = binary")); + return -1; + } + } + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999154; cv=none; d=zohomail.com; s=zohoarc; b=KXRnVYeBYi5Rmbe2Y6Qcqq4fn8ljy993/xKDXRo1rbiv1l3CQttgbVv04AftV/0c3Q+husA+0l3l4jl8YCUDDAixK1hFLnHfLDYsS849nRC0aDwpnBAr0Whv7BJKq6veCc4IOkV6cmB2bbKqBud6KK08WzsFgX0a9mrg4GYD7k0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999154; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YVgVedkQbiHjZyuJHmUA6rQPWEUFIIPoxTYvNbK96ME=; b=K9l2+oUzqcdcN2Fj4putGsiJG/7aU2ipSCjYFMWmU7lkWjHKxhFPF5XdkMtTmjPgFcPmGpg4TVFNYZLbj+0oOy0HpDWsuoAbeBmuRt2FaJmbUPqQcKTiy84+fhEN0StS2GBEj2RbpWIEXF+1YT3vc4Q5L/npF1WGFC2kXI0QZ8s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999154141470.3616121928238; Thu, 3 Dec 2020 04:39:14 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-QlX3-MlfPzKVVXUmiLxsow-1; Thu, 03 Dec 2020 07:37:21 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47F0A805BFC; Thu, 3 Dec 2020 12:37:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E59D1A839; Thu, 3 Dec 2020 12:37:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DEADF50049; Thu, 3 Dec 2020 12:37:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Cb6tA003164 for ; Thu, 3 Dec 2020 07:37:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2AD595C1CF; Thu, 3 Dec 2020 12:37:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F4895C1C2 for ; Thu, 3 Dec 2020 12:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999153; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YVgVedkQbiHjZyuJHmUA6rQPWEUFIIPoxTYvNbK96ME=; b=L0ZBnwwjliFQ+jEh/4hwh3esieJyL8vtuujFYottI1qxWWsEOvhqb/Nw7iI5QzJWJbdxCy zHNDFUtjiCyXc7BrGT7uHJyAn+HuMWADcbLlKy9+LAAo6JnGYmpc4tnZddt7uknzGxGGyT srY2bWKpxsBH6c7pwL94ADXPlAi5PWE= X-MC-Unique: QlX3-MlfPzKVVXUmiLxsow-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 15/27] security: Relabel virtio mem Date: Thu, 3 Dec 2020 13:36:18 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/security/security_apparmor.c | 26 ++++++++++++-------- src/security/security_dac.c | 42 +++++++++++++++++--------------- src/security/security_selinux.c | 42 ++++++++++++++++++-------------- src/security/virt-aa-helper.c | 22 ++++++++++++++--- 4 files changed, 81 insertions(+), 51 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index b22ee739d8..8bf7570d4a 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -681,26 +681,32 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr, virDomainDefPtr def, virDomainMemoryDefPtr mem) { - if (mem =3D=3D NULL) - return 0; + const char *path =3D NULL; =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - if (!virFileExists(mem->s.nvdimm.path)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("%s: \'%s\' does not exist"), - __func__, mem->s.nvdimm.path); - return -1; - } - return reload_profile(mgr, def, mem->s.nvdimm.path, true); + path =3D mem->s.nvdimm.path; + break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } =20 - return 0; + if (!path) + return 0; + + if (!virFileExists(path)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%s: \'%s\' does not exist"), + __func__, path); + return -1; + } + + return reload_profile(mgr, def, path, true); } =20 =20 diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 6b681c4021..24daa41898 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1885,22 +1885,25 @@ virSecurityDACRestoreMemoryLabel(virSecurityManager= Ptr mgr, virDomainDefPtr def G_GNUC_UNUSED, virDomainMemoryDefPtr mem) { - int ret =3D -1; + const char *path =3D NULL; =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - ret =3D virSecurityDACRestoreFileLabel(mgr, mem->s.nvdimm.path); + path =3D mem->s.nvdimm.path; break; - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: - ret =3D 0; break; } =20 - return ret; + if (!path) + return 0; + + return virSecurityDACRestoreFileLabel(mgr, path); } =20 =20 @@ -2057,33 +2060,34 @@ virSecurityDACSetMemoryLabel(virSecurityManagerPtr = mgr, { virSecurityDACDataPtr priv =3D virSecurityManagerGetPrivateData(mgr); virSecurityLabelDefPtr seclabel; - int ret =3D -1; + const char *path =3D NULL; uid_t user; gid_t group; =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAM= E); - if (seclabel && !seclabel->relabel) - return 0; - - if (virSecurityDACGetIds(seclabel, priv, &user, &group, NULL, NULL= ) < 0) - return -1; - - ret =3D virSecurityDACSetOwnership(mgr, NULL, - mem->s.nvdimm.path, - user, group, true); + path =3D mem->s.nvdimm.path; break; - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: - ret =3D 0; break; } =20 - return ret; + if (!path) + return 0; + + seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME); + if (seclabel && !seclabel->relabel) + return 0; + + if (virSecurityDACGetIds(seclabel, priv, &user, &group, NULL, NULL) < = 0) + return -1; + + return virSecurityDACSetOwnership(mgr, NULL, path, user, group, true); } =20 =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 77b69447da..c0f78f8a46 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1570,26 +1570,29 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManager= Ptr mgr, virDomainMemoryDefPtr mem) { virSecurityLabelDefPtr seclabel; + const char *path =3D NULL; =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); - if (!seclabel || !seclabel->relabel) - return 0; - - if (virSecuritySELinuxSetFilecon(mgr, mem->s.nvdimm.path, - seclabel->imagelabel, true) < 0) - return -1; + path =3D mem->s.nvdimm.path; break; - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } =20 - return 0; + if (!path) + return 0; + + seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); + if (!seclabel || !seclabel->relabel) + return 0; + + return virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagelabel, t= rue); } =20 =20 @@ -1598,27 +1601,30 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityMan= agerPtr mgr, virDomainDefPtr def, virDomainMemoryDefPtr mem) { - int ret =3D -1; virSecurityLabelDefPtr seclabel; + const char *path =3D NULL; =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: - seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); - if (!seclabel || !seclabel->relabel) - return 0; - - ret =3D virSecuritySELinuxRestoreFileLabel(mgr, mem->s.nvdimm.path= , true); + path =3D mem->s.nvdimm.path; break; - case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: - ret =3D 0; break; } =20 - return ret; + if (!path) + return 0; + + seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); + if (!seclabel || !seclabel->relabel) + return 0; + + return virSecuritySELinuxRestoreFileLabel(mgr, path, true); } =20 =20 diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index a8a05a0a90..f895fecea4 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1168,11 +1168,25 @@ get_files(vahControl * ctl) } =20 for (i =3D 0; i < ctl->def->nmems; i++) { - if (ctl->def->mems[i] && - ctl->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NV= DIMM) { - if (vah_add_file(&buf, ctl->def->mems[i]->s.nvdimm.path, "rw")= !=3D 0) - goto cleanup; + virDomainMemoryDefPtr mem =3D ctl->def->mems[i]; + const char *path =3D NULL; + + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + path =3D mem->s.nvdimm.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; } + + if (path && + vah_add_file(&buf, path, "rw") !=3D 0) + goto cleanup; } =20 for (i =3D 0; i < ctl->def->nsysinfo; i++) { --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999038; cv=none; d=zohomail.com; s=zohoarc; b=BFQ+s/vp5gHSYPLppdyeh+oGDMf6R1oS0Fq+hKtKsDUk1jKhq8y4b+027Xm0p7tsBwN2peWyeftY0A0i9TiYc95KeqRCk74pOujubeEUfeEFlnN08XZogsxGaY3rVTiE9W7p2LZird6sXUjXWaAsrnKtCvaG+4XzfZW3ZWPjLFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999038; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lSphzg0FaN03RrWS8zaCuueJFkAsu3SyDpNotPwkdLg=; b=c/3jeP/Htj2G4LRiqmTqF54OJRm/9ithB7Zf+CMdgGKCnSD0YuX0uZsbN4fETAONFBDo5FBK7u6e+B0Y/N7rCjeqKos2VhiHLJdaxDAscfmx2fArAN46NueoKL9GdLx1DxnJBcUQ4uJa9ENfxMTfeZdLQLzQOg4213dLLTJFJ44= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999038656228.7362431803939; Thu, 3 Dec 2020 04:37:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-de5nGByuOCOduxszQCZoLQ-1; Thu, 03 Dec 2020 07:37:15 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0923CC292; Thu, 3 Dec 2020 12:37:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDFCD189C4; Thu, 3 Dec 2020 12:37:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A96B51809CA6; Thu, 3 Dec 2020 12:37:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Cb7D1003170 for ; Thu, 3 Dec 2020 07:37:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0901D5C1BD; Thu, 3 Dec 2020 12:37:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EAE35C1C2 for ; Thu, 3 Dec 2020 12:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999037; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lSphzg0FaN03RrWS8zaCuueJFkAsu3SyDpNotPwkdLg=; b=QyStvH9HH3rORv2MGvDlqmOr/hGImfTEdJ+2hTwfyzfMYaeVk5AXdRf2bOiBvxyTONvwmP Sl/mDHMOxCOhQ4NenodubSv3b/bs7HeGsnKYYbtxu46vx3Ky8/W3Ro3ApHGcW1eL+3Zs6p k2nn+I8KQ4GbQKdDa/7bq8ww09RmAYg= X-MC-Unique: de5nGByuOCOduxszQCZoLQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 16/27] qemu: Allow virtio-pmem in CGroups Date: Thu, 3 Dec 2020 13:36:19 +0100 Message-Id: <563a4e4e5028a3576d6483de92e8ddd03845ec74.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some users might wanto have virtio-pmem backed by a block device in which case we have to allow the device in CGroups. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_cgroup.c | 43 ++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 92caadf840..b5639de93e 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -500,19 +500,32 @@ qemuSetupMemoryDevicesCgroup(virDomainObjPtr vm, virDomainMemoryDefPtr mem) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + const char *path =3D NULL; int rv; =20 - if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + path =3D mem->s.nvdimm.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + break; + } + + if (!path) return 0; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - VIR_DEBUG("Setting devices Cgroup for NVDIMM device: %s", mem->s.nvdim= m.path); - rv =3D virCgroupAllowDevicePath(priv->cgroup, mem->s.nvdimm.path, + VIR_DEBUG("Setting devices Cgroup for memory device: %s", path); + rv =3D virCgroupAllowDevicePath(priv->cgroup, path, VIR_CGROUP_DEVICE_RW, false); - virDomainAuditCgroupPath(vm, priv->cgroup, "allow", - mem->s.nvdimm.path, "rw", rv); + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", rv); =20 return rv; } @@ -523,18 +536,28 @@ qemuTeardownMemoryDevicesCgroup(virDomainObjPtr vm, virDomainMemoryDefPtr mem) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + const char *path =3D NULL; int rv; =20 - if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) - return 0; + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + path =3D mem->s.nvdimm.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + break; + } =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - rv =3D virCgroupDenyDevicePath(priv->cgroup, mem->s.nvdimm.path, + rv =3D virCgroupDenyDevicePath(priv->cgroup, path, VIR_CGROUP_DEVICE_RWM, false); - virDomainAuditCgroupPath(vm, priv->cgroup, - "deny", mem->s.nvdimm.path, "rwm", rv); + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", path, "rwm", rv); return rv; } =20 --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999144; cv=none; d=zohomail.com; s=zohoarc; b=eIW8lAy9cADLiUHEw6T5zvXHLaaacMSUPlxJ5XXeJDiVxbNngZxfp1tUiOnPyVzhTVCY9UVvwnZtmFUinij6sib9HrNe0u4XVP8+wCSFaoT6bE2oZb7eZ8CjLqcZw+JjOhtt26oU5iqLncT43oUr69WRtytKoABBn3oGs81Pmdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999144; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4TZmAKgZOtVyuS8hJHdgTTZArur25E4uUnD9BO/Ua1k=; b=W67ueIclbE5SvEtMQjC2sACF8swQg7ABa0EmVq66L9RnQmMdO1E8LCgwykwkilKcaOcYrL225nvNG0iRuK1ERYZ1LNyfOMFiTfaIxsZx4aruBbWMW0RI8CYLmmwkvUg7yyBfKnSvrIlor4xiAmKGLlTm3OgKLK9Gs7WFpkiQ1BA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999144112418.67183243394607; Thu, 3 Dec 2020 04:39:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-8-nxFU-c58O2m7XPJOMsXi6Q-1; Thu, 03 Dec 2020 07:37:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3FE08558F3; Thu, 3 Dec 2020 12:37:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C06411002393; Thu, 3 Dec 2020 12:37:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8D2BA50042; Thu, 3 Dec 2020 12:37:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3Cb9cY003215 for ; Thu, 3 Dec 2020 07:37:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 899135C1D0; Thu, 3 Dec 2020 12:37:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08F5B5C1BD for ; Thu, 3 Dec 2020 12:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999142; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4TZmAKgZOtVyuS8hJHdgTTZArur25E4uUnD9BO/Ua1k=; b=Iu4zSoRu0iRlg5Fz7u6r+a8uxoI4fUhOwYecmYkqzco6QWNS34BLESNQPeeIvnJb4kh/CZ kKxyEHhGaFP7FPjlgHrDos7IYHwEW2zwAKq18guFc0tcdXqqFA7ze/I4y711MlRN9/dYgL tiy+koVClj+iaS2FBr77XJSul4AjKSM= X-MC-Unique: nxFU-c58O2m7XPJOMsXi6Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 17/27] qemu: Create virtio-pmem in domain namespace Date: Thu, 3 Dec 2020 13:36:20 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some users might wanto have virtio-pmem backed by a block device in which case we have to create the device in domain namespace. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_namespace.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index b8aebd1e61..360f48a2fc 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -351,10 +351,25 @@ static int qemuDomainSetupMemory(virDomainMemoryDefPtr mem, char ***paths) { - if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) + const char *path =3D NULL; + + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + path =3D mem->s.nvdimm.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + path =3D mem->s.virtio.path; + break; + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + break; + } + + if (!path) return 0; =20 - return virStringListAdd(paths, mem->s.nvdimm.path); + return virStringListAdd(paths, path); } =20 =20 --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999144; cv=none; d=zohomail.com; s=zohoarc; b=VfPWss+iP6vDbARJLvIJfsUNhN7Ev/hMuEwlVHtsUcGoU+a8FsMdnrfrhpF06wIwN1FvXmZpxpwSPoUyxBvADAAYpWhmQb9o/GejKCsOrcLn27nvFbbf/i8L+t6ndW5fiUqFp/xpCSUBc8+Jt06fqopxtjFXVn2yBBlLOJQvIwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999144; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r3ZcvwPiYoTW3E0U0OXav6wNSqgN/SZKuTuFFWTWsUY=; b=i/oDpzDQBvrmEHsdVUppxt/GQLMxEk7966NZr98nv+Rpv9F6eu6enmUACZv74EM3KyucQF8P5jRZvxHMyZR3aD+5wIcI+mGO40n07FkU0xnf1FYSBkGm7OTwa32sPEC93exOu817VTheNrl2a0a79N5NO23qePT7nF+ouG0stJE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999144514123.9232838134252; Thu, 3 Dec 2020 04:39:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-320-410U1aRpNBW0itvd0ouu_Q-1; Thu, 03 Dec 2020 07:37:23 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30A45185E4AA; Thu, 3 Dec 2020 12:37:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D340A1001901; Thu, 3 Dec 2020 12:37:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9F5AF1809CA0; Thu, 3 Dec 2020 12:37:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbC5K003235 for ; Thu, 3 Dec 2020 07:37:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8FE3C5C1BD; Thu, 3 Dec 2020 12:37:12 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10EBC5C1C2 for ; Thu, 3 Dec 2020 12:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999143; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=r3ZcvwPiYoTW3E0U0OXav6wNSqgN/SZKuTuFFWTWsUY=; b=VYvns+9DzSo9hlmtjWlLxxojq3A88nV6svROxYD0KuGzcuatKkUtuI5DxYe5RtmExdFXJO AvpOXL8gZUxipH6F52nfo0+lwBp+kWPUyMuI4hMpHatr/jSAKlJVVqj1194QHW82HBAOgF Tf5jCI7UNOsQdRWomuo3zhu15gBX9xA= X-MC-Unique: 410U1aRpNBW0itvd0ouu_Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 18/27] qemu_command: Move dimm into qemuBuildDeviceAddressStr() Date: Thu, 3 Dec 2020 13:36:21 +0100 Message-Id: <8103e6195b4bbacd9eec74c6de7c1b4778b1fda0.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" So far our memory modules could go only into DIMM slots. But with virtio model this assumption is no longer true - virtio-pmem goes onto PCI bus. But for formatting PCI address onto command line we already have a function - qemuBuildDeviceAddressStr(). Therefore, mode DIMM address generation into it so that we don't have to special case address building later on. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: Peter Krempa Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_command.c | 17 +++++++++-------- src/qemu/qemu_command.h | 5 ++++- src/qemu/qemu_hotplug.c | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9c50778180..49241fc507 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -393,6 +393,10 @@ qemuBuildDeviceAddressStr(virBufferPtr buf, virBufferAsprintf(buf, ",iobase=3D0x%x,irq=3D0x%x", info->addr.isa.iobase, info->addr.isa.irq); + } else if (info->type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM) { + virBufferAsprintf(buf, ",slot=3D%d", info->addr.dimm.slot); + if (info->addr.dimm.base) + virBufferAsprintf(buf, ",addr=3D%llu", info->addr.dimm.base); } =20 return 0; @@ -3290,7 +3294,9 @@ qemuBuildMemoryDimmBackendStr(virBufferPtr buf, =20 =20 char * -qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem) +qemuBuildMemoryDeviceStr(const virDomainDef *def, + virDomainMemoryDefPtr mem, + virQEMUCapsPtr qemuCaps) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; const char *device; @@ -3332,12 +3338,7 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem) virBufferAsprintf(&buf, "memdev=3Dmem%s,id=3D%s", mem->info.alias, mem->info.alias); =20 - if (mem->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM) { - virBufferAsprintf(&buf, ",slot=3D%d", mem->info.addr.dimm.slot= ); - if (mem->info.addr.dimm.base) - virBufferAsprintf(&buf, ",addr=3D%llu", mem->info.addr.dim= m.base); - } - + qemuBuildDeviceAddressStr(&buf, def, &mem->info, qemuCaps); break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: @@ -7478,7 +7479,7 @@ qemuBuildMemoryDeviceCommandLine(virCommandPtr cmd, virCommandAddArg(cmd, "-object"); virCommandAddArgBuffer(cmd, &buf); =20 - if (!(dimmStr =3D qemuBuildMemoryDeviceStr(def->mems[i]))) + if (!(dimmStr =3D qemuBuildMemoryDeviceStr(def, def->mems[i], priv= ->qemuCaps))) return -1; =20 virCommandAddArgList(cmd, "-device", dimmStr, NULL); diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 3da07e25a1..3cfe6ff3e9 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -155,7 +155,10 @@ int qemuBuildMemoryBackendProps(virJSONValuePtr *backe= ndProps, const virDomainMemoryDef *mem, bool force); =20 -char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem); +char * +qemuBuildMemoryDeviceStr(const virDomainDef *def, + virDomainMemoryDefPtr mem, + virQEMUCapsPtr qemuCaps); =20 /* Current, best practice */ char *qemuBuildPCIHostdevDevStr(const virDomainDef *def, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1f9df182bf..bc5dc02a2f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2412,7 +2412,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, =20 objalias =3D g_strdup_printf("mem%s", mem->info.alias); =20 - if (!(devstr =3D qemuBuildMemoryDeviceStr(mem))) + if (!(devstr =3D qemuBuildMemoryDeviceStr(vm->def, mem, priv->qemuCaps= ))) goto cleanup; =20 if (qemuBuildMemoryBackendProps(&props, objalias, cfg, --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999049; cv=none; d=zohomail.com; s=zohoarc; b=JHDmgAJSMTg0BpLnMwJkgL1MHoSq4stmoWlHcOdDIC3dIa8z8YDwL1xfE62HQ00KsYwoTHc2B0IxxZrCjZapSNoalSsu2yjWglN/uRTEaY2pNH2cl+b7fYaHlj0G18OjtH7F9WXk9fo6Nb1UaXAqQEZRq4pqTqVxtuHnuBBx2Zs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999049; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Td2tUNRCQsXXF2OLFGtWleLLIns9JX3gcNwG3a6hShM=; b=aNZ7tHSUWQBoF6EWNdKJh1ugCWpPE4VzOgEyWJJHI+kTLQEzE86d00N3ZCZxZGrgsyPwmh+15WACvjvB9qksxojTx1bfZYE++dNp/eS0Odxu+janzL9Cm1fMjFX5QseVEwkKRA1WJ5Rtue8buv11oJ9b8znBV1WTmSSvBvc+GOA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999049556746.0101887398525; Thu, 3 Dec 2020 04:37:29 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-VHdCSOKJPaSn5LeBrhvD2Q-1; Thu, 03 Dec 2020 07:37:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEEC0107ACF7; Thu, 3 Dec 2020 12:37:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDC1060C17; Thu, 3 Dec 2020 12:37:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7BBF85004B; Thu, 3 Dec 2020 12:37:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbI4e003325 for ; Thu, 3 Dec 2020 07:37:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id BE9315C1CF; Thu, 3 Dec 2020 12:37:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4033C5C1C2 for ; Thu, 3 Dec 2020 12:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999048; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Td2tUNRCQsXXF2OLFGtWleLLIns9JX3gcNwG3a6hShM=; b=Axx4NDsWNTwjXq2tuGCVlR8wgLSFZF55NEugyo4N3Bc3UxouNKZQuYXpBzhRGo7yLbrKoY ROsSSQcKxdgomVhxjku3bt65vsR7u05pfSswAp9fcKCCotVMycDaTsyCW/5E/eVmnE4CLo 3kL8yV+j/QRBKyNQYTuKOEQ7J6uMBI4= X-MC-Unique: VHdCSOKJPaSn5LeBrhvD2Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 19/27] qemu: Build command line for virtio-pmem Date: Thu, 3 Dec 2020 13:36:22 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Now we have everything prepared for generating the command line. The device alias prefix was chosen to be 'virtiopmem'. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1735375 Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_alias.c | 44 ++++++---- src/qemu/qemu_command.c | 82 ++++++++++--------- ...ory-hotplug-virtio-pmem.x86_64-latest.args | 45 ++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 120 insertions(+), 52 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_6= 4-latest.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 931dbd4e84..68d4a7b480 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -466,6 +466,28 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def, } =20 =20 +static int +qemuDeviceMemoryGetAliasID(virDomainDefPtr def, + virDomainMemoryDefPtr mem, + bool oldAlias, + const char *prefix) +{ + size_t i; + int maxidx =3D 0; + + if (!oldAlias) + return mem->info.addr.dimm.slot; + + for (i =3D 0; i < def->nmems; i++) { + int idx; + if ((idx =3D qemuDomainDeviceAliasIndex(&def->mems[i]->info, prefi= x)) >=3D maxidx) + maxidx =3D idx + 1; + } + + return maxidx; +} + + /** * qemuAssignDeviceMemoryAlias: * @def: domain definition. Necessary only if @oldAlias is true. @@ -483,10 +505,8 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, virDomainMemoryDefPtr mem, bool oldAlias) { - size_t i; - int maxidx =3D 0; - int idx; const char *prefix =3D NULL; + int idx =3D 0; =20 if (mem->info.alias) return 0; @@ -494,26 +514,22 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: prefix =3D "dimm"; + idx =3D qemuDeviceMemoryGetAliasID(def, mem, oldAlias, prefix); break; case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: prefix =3D "nvdimm"; + idx =3D qemuDeviceMemoryGetAliasID(def, mem, oldAlias, prefix); break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + prefix =3D "virtiopmem"; + idx =3D qemuDeviceMemoryGetAliasID(def, mem, true, prefix); + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } =20 - if (oldAlias) { - for (i =3D 0; i < def->nmems; i++) { - if ((idx =3D qemuDomainDeviceAliasIndex(&def->mems[i]->info, p= refix)) >=3D maxidx) - maxidx =3D idx + 1; - } - } else { - maxidx =3D mem->info.addr.dimm.slot; - } - - mem->info.alias =3D g_strdup_printf("%s%d", prefix, maxidx); + mem->info.alias =3D g_strdup_printf("%s%d", prefix, idx); =20 return 0; } @@ -688,7 +704,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCap= sPtr qemuCaps) return -1; } for (i =3D 0; i < def->nmems; i++) { - if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0) + if (qemuAssignDeviceMemoryAlias(def, def->mems[i], false) < 0) return -1; } if (def->vsock) { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 49241fc507..501deff1ee 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2957,7 +2957,8 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, virDomainMemoryAccess memAccess =3D mem->access; size_t i; g_autofree char *memPath =3D NULL; - bool prealloc =3D false; + bool wantPrealloc =3D false; + bool allowPrealloc =3D !priv->memPrealloc; virBitmapPtr nodemask =3D NULL; int rc; g_autoptr(virJSONValue) props =3D NULL; @@ -2991,6 +2992,11 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backend= Props, nvdimmPmem =3D mem->s.nvdimm.pmem; break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + nvdimmPath =3D mem->s.virtio.path; + /* virtio-pmem doesn't need prealloc, it's very likely exposing a = real + * device and thus there's nothing to prealloc */ + allowPrealloc =3D false; + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; @@ -3020,7 +3026,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, discard =3D def->mem.discard; =20 if (def->mem.allocation =3D=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) - prealloc =3D true; + wantPrealloc =3D true; =20 if (virDomainNumatuneGetMode(def->numa, mem->targetNode, &mode) < 0 && virDomainNumatuneGetMode(def->numa, -1, &mode) < 0) @@ -3095,7 +3101,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, return -1; } =20 - prealloc =3D true; + wantPrealloc =3D true; } =20 if (qemuBuildMemoryBackendPropsShare(props, memAccess) < 0) @@ -3106,11 +3112,11 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, =20 if (nvdimmPath) { memPath =3D g_strdup(nvdimmPath); - prealloc =3D true; + wantPrealloc =3D true; } else if (useHugepage) { if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &m= emPath) < 0) return -1; - prealloc =3D true; + wantPrealloc =3D true; } else { /* We can have both pagesize and mem source. If that's the cas= e, * prefer hugepages as those are more specific. */ @@ -3143,8 +3149,8 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, backendType =3D "memory-backend-ram"; } =20 - if (!priv->memPrealloc && - virJSONValueObjectAdd(props, "B:prealloc", prealloc, NULL) < 0) + if (allowPrealloc && + virJSONValueObjectAdd(props, "B:prealloc", wantPrealloc, NULL) < 0) return -1; =20 if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0) @@ -3299,7 +3305,7 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, virQEMUCapsPtr qemuCaps) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - const char *device; + const char *device =3D NULL; =20 if (!mem->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -3308,46 +3314,46 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, } =20 switch (mem->model) { - case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: case VIR_DOMAIN_MEMORY_MODEL_DIMM: - - if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM) - device =3D "pc-dimm"; - else - device =3D "nvdimm"; - - virBufferAsprintf(&buf, "%s,", device); - - if (mem->targetNode >=3D 0) - virBufferAsprintf(&buf, "node=3D%d,", mem->targetNode); - - if (mem->labelsize) - virBufferAsprintf(&buf, "label-size=3D%llu,", mem->labelsize *= 1024); - - if (virUUIDIsValid(mem->uuid)) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(mem->uuid, uuidstr); - virBufferAsprintf(&buf, "uuid=3D%s,", uuidstr); - } - - if (mem->readonly) { - virBufferAddLit(&buf, "unarmed=3Don,"); - } - - virBufferAsprintf(&buf, "memdev=3Dmem%s,id=3D%s", - mem->info.alias, mem->info.alias); - - qemuBuildDeviceAddressStr(&buf, def, &mem->info, qemuCaps); + device =3D "pc-dimm"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + device =3D "nvdimm"; break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + device =3D "virtio-pmem-pci"; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; + } + + virBufferAsprintf(&buf, "%s,", device); + + if (mem->targetNode >=3D 0) + virBufferAsprintf(&buf, "node=3D%d,", mem->targetNode); + + if (mem->labelsize) + virBufferAsprintf(&buf, "label-size=3D%llu,", mem->labelsize * 102= 4); + + if (virUUIDIsValid(mem->uuid)) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 + virUUIDFormat(mem->uuid, uuidstr); + virBufferAsprintf(&buf, "uuid=3D%s,", uuidstr); } =20 + if (mem->readonly) { + virBufferAddLit(&buf, "unarmed=3Don,"); + } + + virBufferAsprintf(&buf, "memdev=3Dmem%s,id=3D%s", + mem->info.alias, mem->info.alias); + + qemuBuildDeviceAddressStr(&buf, def, &mem->info, qemuCaps); + + return virBufferContentAndReset(&buf); } =20 diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-lates= t.args b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.ar= gs new file mode 100644 index 0000000000..e2f5097424 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.args @@ -0,0 +1,45 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i386 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-cpu qemu64 \ +-m size=3D2095104k,slots=3D16,maxmem=3D1099511627776k \ +-overcommit mem-lock=3Doff \ +-smp 2,sockets=3D2,dies=3D1,cores=3D1,threads=3D1 \ +-object memory-backend-ram,id=3Dram-node0,size=3D2145386496 \ +-numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dram-node0 \ +-object memory-backend-file,id=3Dmemvirtiopmem0,mem-path=3D/tmp/virtio_pme= m,\ +share=3Dyes,size=3D536870912 \ +-device virtio-pmem-pci,memdev=3Dmemvirtiopmem0,id=3Dvirtiopmem0,bus=3Dpci= .0,\ +addr=3D0x5 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\ +"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=3Dide.0,unit=3D0,drive=3Dlibvirt-1-format,id=3Dide0-0-0= ,bootindex=3D1 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 409680c84e..c79246e0bb 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3012,6 +3012,7 @@ mymain(void) DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-pmem"); DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-readonly"); DO_TEST_CAPS_ARCH_LATEST("memory-hotplug-nvdimm-ppc64", "ppc64"); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); =20 DO_TEST("machine-aeskeywrap-on-caps", QEMU_CAPS_AES_KEY_WRAP, --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999052; cv=none; d=zohomail.com; s=zohoarc; b=e1wPVH33RflZTbT9SmO/ht7GIab1A9hebDXnKWoPCPCBZk9GSIE+yDb43iME3rHPfDWmN9OzMn/RP8zrfFLThlQaEd8raVzFyycwjQ4HOnAPO91erm7vfxEkiEFivNxiqCuF3f5RljSmJgMDPKZpb1jACTgpJM4TpXaomQNRlOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999052; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DcbqRjieDaNnBo+8cXUdSASyiY59dyUrbGraM/lpqwc=; b=aa/6QU3gHmHiotm4hK1nw30cQD6s5AjP8Wk52fKNMGoqm2xuy2COCS9pIfFHGqIzPsVdoIfQq6p6fEKEEB5SBBaCFmPQ6tkcaBtZkeFKI9lyuwQhgKPlK9X9fpWeY4cTpQ+bwJTq1Jvccb3Suz1q/8MYJx1IKSnxCmNR2uHj7ks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999052552780.4156293194721; Thu, 3 Dec 2020 04:37:32 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-136-4BvXi-bWPUqMexhTCKNyZQ-1; Thu, 03 Dec 2020 07:37:28 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77111185E49F; Thu, 3 Dec 2020 12:37:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54FF15D6BA; Thu, 3 Dec 2020 12:37:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1F8EA5002F; Thu, 3 Dec 2020 12:37:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbLhE003338 for ; Thu, 3 Dec 2020 07:37:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id C4C9D5C1D0; Thu, 3 Dec 2020 12:37:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 456775C1C2 for ; Thu, 3 Dec 2020 12:37:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999051; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DcbqRjieDaNnBo+8cXUdSASyiY59dyUrbGraM/lpqwc=; b=N96xbZLIBtWqmLObQ0YamarIzkh7GZmWUOq3xVgidWvI3Z8TffJJXnG4c8ijMjRGIcDyEC ppOuMbIOepglQhAwJPBW0MQJYyf+uo8LnV8id06ylo5ts2/oLcOhYQ6Zujz0eInOcFwXCc N7s1b8n+63Y+1WHFNDSK+98B+yi/ZaA= X-MC-Unique: 4BvXi-bWPUqMexhTCKNyZQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 20/27] conf: Introduce virtio-mem model Date: Thu, 3 Dec 2020 13:36:23 +0100 Message-Id: <468ab48a9fb8d17aa4dfbfc68f7ac732981787f0.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" QEMU gained this new virtio-mem model. It's similar to pc-dimm in a sense that guest uses it as memory, but in a sense very different from it as it can dynamically change allocation, without need for hotplug. More specifically, the device has two attributes more (it has more of course, but these two are important here): 1) block-size - the granularity of the device. You can imagine the device being divided into blocks, each 'block-size' long. 2) requested-size - the portion of the device that is in use by the guest. And it all works like this: at guest startup/hotplug both block-size and requested-size are specified. When sysadmin wants to give some more memory to the guest, or take some back, they change the 'requested-size' attribute which is propagated to the guest where virtio-mem module takes corresponding action. This means, that 'requested-size' must be a whole number product of 'block-size' and of course has to be in rage [0, max-size] (including). The 'max-size' is yet another attribute but if not set it's "inherited" from corresponding memory-backend-* object. Therefore, two new elements are introduced under , to reflect these attributes: 4194304 0 2048 524288
The intent here is that will be allowed to change via virDomainUpdateDeviceFlags() API. Note, QEMU does inform us about success of allocation via an event - this is covered in next patches. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- docs/formatdomain.rst | 22 ++++ docs/schemas/domaincommon.rng | 10 ++ src/conf/domain_conf.c | 103 ++++++++++++++++-- src/conf/domain_conf.h | 5 + .../memory-hotplug-virtio-mem.xml | 78 +++++++++++++ ...emory-hotplug-virtio-mem.x86_64-latest.xml | 1 + tests/qemuxml2xmltest.c | 1 + 7 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml create mode 120000 tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_= 64-latest.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index ca6bc0432e..3990728939 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7187,6 +7187,17 @@ Example: usage of the memory devices + + + /tmp/virtio_mem + + + 1048576 + 0 + 2048 + 524288 + + /tmp/virtio_pmem @@ -7300,6 +7311,17 @@ Example: usage of the memory devices so other backend types should use the ``readonly`` element. :since:`= Since 5.0.0` =20 + ``block`` + The size of an individual block, granularity of division of memory mo= dule. + Must be power of two and at least equal to size of a transparent huge= page + (2MiB on x84_64). The default is hypervisor dependant. This is valid = for + ``virtio`` model only and mutually exclusive with ``pmem``. + + ``requested`` + The total size of blocks exposed to the guest. Must respect ``block`` + granularity. This is valid for ``virtio`` model only and mutually + exclusive with ``pmem``. + :anchor:`` =20 IOMMU devices diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index b385bae84c..d478b639fa 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6053,6 +6053,16 @@ + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 935bea1804..0551f6f266 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6764,10 +6764,23 @@ virDomainMemoryDefValidate(const virDomainMemoryDef= *mem, return -1; } } else { - /* TODO: plain virtio-mem behaves differently then virtio-pmem= */ - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtio-mem is not supported yet. is = required")); - return -1; + if (mem->requestedsize > mem->size) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("requested size must be smaller than @siz= e")); + return -1; + } + + if (!VIR_IS_POW2(mem->blocksize)) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("block size must be a power of two")); + return -1; + } + + if (mem->requestedsize % mem->blocksize !=3D 0) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("requested size must be an integer multip= le of block size")); + return -1; + } } break; =20 @@ -16774,9 +16787,25 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: def->s.virtio.path =3D virXPathString("string(./path)", ctxt); =20 - if (virXPathBoolean("boolean(./pmem)", ctxt)) + if (virXPathBoolean("boolean(./pmem)", ctxt)) { def->s.virtio.pmem =3D true; + } else { + if (virDomainParseMemory("./pagesize", "./pagesize/@unit", ctx= t, + &def->s.virtio.pagesize, false, false= ) < 0) + return -1; =20 + if ((nodemask =3D virXPathString("string(./nodemask)", ctxt)))= { + if (virBitmapParse(nodemask, &def->s.virtio.sourceNodes, + VIR_DOMAIN_CPUMASK_LEN) < 0) + return -1; + + if (virBitmapIsAllClear(def->s.virtio.sourceNodes)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Invalid value of 'nodemask': %s"), n= odemask); + return -1; + } + } + } break; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -16812,7 +16841,8 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, &def->size, true, false) < 0) return -1; =20 - if (def->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + switch (def->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (virDomainParseMemory("./label/size", "./label/size/@unit", ctx= t, &def->labelsize, false, false) < 0) return -1; @@ -16831,6 +16861,27 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, =20 if (virXPathBoolean("boolean(./readonly)", ctxt)) def->readonly =3D true; + + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + if (!def->s.virtio.pmem) { + if (virDomainParseMemory("./block", "./block/@unit", ctxt, + &def->blocksize, false, false) < 0) + return -1; + + if (virDomainParseMemory("./requested", "./requested/@unit", c= txt, + &def->requestedsize, false, false) < = 0) + return -1; + } + + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + /* nada */ + break; } =20 return 0; @@ -18649,7 +18700,9 @@ virDomainMemoryFindByDefInternal(virDomainDefPtr de= f, /* target info -> always present */ if (tmp->model !=3D mem->model || tmp->targetNode !=3D mem->targetNode || - tmp->size !=3D mem->size) + tmp->size !=3D mem->size || + tmp->blocksize !=3D mem->blocksize || + tmp->requestedsize !=3D mem->requestedsize) continue; =20 switch (mem->model) { @@ -24255,6 +24308,22 @@ virDomainMemoryDefCheckABIStability(virDomainMemor= yDefPtr src, return false; } =20 + if (src->blocksize !=3D dst->blocksize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target memory device block size '%llu' doesn't m= atch " + "source memory device block size '%llu'"), + dst->blocksize, src->blocksize); + return false; + } + + if (src->requestedsize !=3D dst->requestedsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target memory device requested size '%llu' doesn= 't match " + "source memory device requested size '%llu'"), + dst->requestedsize, src->requestedsize); + return false; + } + switch (src->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (src->labelsize !=3D dst->labelsize) { @@ -27967,6 +28036,18 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, =20 if (def->s.virtio.pmem) virBufferAddLit(&childBuf, "\n"); + + if (def->s.virtio.sourceNodes) { + if (!(bitmap =3D virBitmapFormat(def->s.virtio.sourceNodes))) + return -1; + + virBufferAsprintf(&childBuf, "%s\n", bitm= ap); + } + + if (def->s.virtio.pagesize) { + virBufferAsprintf(&childBuf, "%llu\n", + def->s.virtio.pagesize); + } break; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -27998,6 +28079,14 @@ virDomainMemoryTargetDefFormat(virBufferPtr buf, if (def->readonly) virBufferAddLit(&childBuf, "\n"); =20 + if (def->blocksize) { + virBufferAsprintf(&childBuf, "%llu\n", + def->blocksize); + + virBufferAsprintf(&childBuf, "%llu\n", + def->requestedsize); + } + virXMLFormatElement(buf, "target", NULL, &childBuf); } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index efaa4c5473..f16dc0a029 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2327,8 +2327,11 @@ struct _virDomainMemoryDef { bool pmem; } nvdimm; /* VIR_DOMAIN_MEMORY_MODEL_NVDIMM */ struct { + // nodemask + hugepages + no prealloc char *path; /* Required for pmem, otherwise optional */ bool pmem; + virBitmapPtr sourceNodes; + unsigned long long pagesize; /* kibibytes */ } virtio; /* VIR_DOMAIN_MEMORY_MODEL_VIRTIO */ } s; =20 @@ -2337,6 +2340,8 @@ struct _virDomainMemoryDef { int targetNode; unsigned long long size; /* kibibytes */ unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */ + unsigned long long blocksize; /* kibibytes, valid for virtio-mem only = */ + unsigned long long requestedsize; /* kibibytes, valid for virtio-mem o= nly */ bool readonly; /* valid only for NVDIMM */ =20 /* required for QEMU NVDIMM ppc64 support */ diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml b/tests/q= emuxml2argvdata/memory-hotplug-virtio-mem.xml new file mode 100644 index 0000000000..0c8d1d970e --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml @@ -0,0 +1,78 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 1099511627776 + 8388608 + 8388608 + 2 + + hvm + + + + qemu64 + + + + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + +
+ + +
+ + +
+ + + + + +
+ + + + 1048576 + 0 + 2048 + 524288 + +
+ + + + 1-3 + 2048 + + + 2097152 + 0 + 2048 + 1048576 + +
+ + + + /tmp/virtio_mem + + + 4194304 + 0 + 2048 + 524288 + +
+ + + diff --git a/tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_64-late= st.xml b/tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_64-latest.x= ml new file mode 120000 index 0000000000..a9d298129c --- /dev/null +++ b/tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/memory-hotplug-virtio-mem.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index e804db8aee..00d8f171bc 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1239,6 +1239,7 @@ mymain(void) DO_TEST("memory-hotplug-nvdimm-ppc64", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST= _BRIDGE, QEMU_CAPS_DEVICE_NVDIMM); DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-mem"); =20 DO_TEST("net-udp", NONE); =20 --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999054; cv=none; d=zohomail.com; s=zohoarc; b=kQQZ1+goV0vKNU2717nCbM+ZHwPujeMMU9uAVKS/6zu2nwz8zCC+wYzG5tyoDAzlxsQNEhiRdcYQU5xPdKFqUeDw8nz1JBLM+wGSpb2F06h1MAl/4nunpxNZiw7m3daEwegIsG4w18o4j6Io7Xa/7Gg3SQ0R/3D8aNSpsK5/fEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999054; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q+xfFctmfHUscuX+XqC82LmPzP6WFTs8gSJ3Rqbb/BY=; b=KAMZTogMKX9ntLlq3AZ0zcxjXscaiB0mmuboDN6uODP7SFnQAzK7cJkEuzD1g7lFGcL5KDJp7w0o4gzjKWv+d+O+Q6Y2MduYwGJDhZWYYgNtkOgQB+88J4yl9qukK35l7YMArG6oRoavuO1yq/stPHPCW6lX+UTqfgx7gcgZE3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999054387377.7516212907244; Thu, 3 Dec 2020 04:37:34 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-mE5MP-FZMweOo7Gax9AhiA-1; Thu, 03 Dec 2020 07:37:31 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C95351006C9A; Thu, 3 Dec 2020 12:37:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A096910023B5; Thu, 3 Dec 2020 12:37:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6DDBE1809CAD; Thu, 3 Dec 2020 12:37:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbOxl003371 for ; Thu, 3 Dec 2020 07:37:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id C4C595C1CF; Thu, 3 Dec 2020 12:37:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46D1E5C1C2 for ; Thu, 3 Dec 2020 12:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999053; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=q+xfFctmfHUscuX+XqC82LmPzP6WFTs8gSJ3Rqbb/BY=; b=TKDddq7HClLMPynVQ9D4QtOLKVJmJopt2y/l3jnFJx7gfYxFClgifUu7kcB69rVl5e1M0g +jCbh2S85CRQAXRFLqmxqOJJFWx3lx9ST54+d6YllOKG2Ngic2GXWIB8nVGRZyqo1SE9DG cD0bK2OdozTa8nq4K8VNZjHgLmp+5jk= X-MC-Unique: mE5MP-FZMweOo7Gax9AhiA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 21/27] qemu: Build command line for virtio-mem Date: Thu, 3 Dec 2020 13:36:24 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The majority of the code is prepared since virtio-pmem. The alias for virtio-mem is new ("virtiomem"). And again, prealloc doesn't make much sense - the whole point is to dynamically allocate memory for guest and possibly return it to the host (e.g. if the host is running low on memory) and this wouldn't happen with prealloc. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_alias.c | 5 +- src/qemu/qemu_command.c | 19 +++++-- ...mory-hotplug-virtio-mem.x86_64-latest.args | 53 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64= -latest.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 68d4a7b480..29c26f0b72 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -521,7 +521,10 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, idx =3D qemuDeviceMemoryGetAliasID(def, mem, oldAlias, prefix); break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: - prefix =3D "virtiopmem"; + if (mem->s.virtio.pmem) + prefix =3D "virtiopmem"; + else + prefix =3D "virtiomem"; idx =3D qemuDeviceMemoryGetAliasID(def, mem, true, prefix); break; case VIR_DOMAIN_MEMORY_MODEL_NONE: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 501deff1ee..ccbc55e376 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2992,9 +2992,14 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backend= Props, nvdimmPmem =3D mem->s.nvdimm.pmem; break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + pagesize =3D mem->s.virtio.pagesize; + needHugepage =3D !!pagesize; + useHugepage =3D !!pagesize; + nodemask =3D mem->s.virtio.sourceNodes; nvdimmPath =3D mem->s.virtio.path; - /* virtio-pmem doesn't need prealloc, it's very likely exposing a = real - * device and thus there's nothing to prealloc */ + /* virtio-pmem doesn't need prealloc. Either it's pmem and thus ve= ry + * likely exposing a real device where is nothing to prealloc, OR = it's + * virtio-mem where we want to unmap pages on the fly. */ allowPrealloc =3D false; break; case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -3322,7 +3327,10 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: - device =3D "virtio-pmem-pci"; + if (mem->s.virtio.pmem) + device =3D "virtio-pmem-pci"; + else + device =3D "virtio-mem-pci"; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: @@ -3337,6 +3345,11 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, if (mem->labelsize) virBufferAsprintf(&buf, "label-size=3D%llu,", mem->labelsize * 102= 4); =20 + if (mem->blocksize) { + virBufferAsprintf(&buf, "block-size=3D%llu,", mem->blocksize * 102= 4); + virBufferAsprintf(&buf, "requested-size=3D%llu,", mem->requestedsi= ze * 1024); + } + if (virUUIDIsValid(mem->uuid)) { char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest= .args b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args new file mode 100644 index 0000000000..c12248518d --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args @@ -0,0 +1,53 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i386 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-cpu qemu64 \ +-m size=3D2095104k,slots=3D16,maxmem=3D1099511627776k \ +-overcommit mem-lock=3Doff \ +-smp 2,sockets=3D2,dies=3D1,cores=3D1,threads=3D1 \ +-object memory-backend-ram,id=3Dram-node0,size=3D2145386496 \ +-numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dram-node0 \ +-object memory-backend-ram,id=3Dmemvirtiomem0,size=3D1073741824 \ +-device virtio-mem-pci,node=3D0,block-size=3D2097152,requested-size=3D5368= 70912,\ +memdev=3Dmemvirtiomem0,id=3Dvirtiomem0,bus=3Dpci.0,addr=3D0x2 \ +-object memory-backend-file,id=3Dmemvirtiomem1,\ +mem-path=3D/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,size=3D2147483648,\ +host-nodes=3D1-3,policy=3Dbind \ +-device virtio-mem-pci,node=3D0,block-size=3D2097152,requested-size=3D1073= 741824,\ +memdev=3Dmemvirtiomem1,id=3Dvirtiomem1,bus=3Dpci.0,addr=3D0x4 \ +-object memory-backend-file,id=3Dmemvirtiomem2,mem-path=3D/tmp/virtio_mem,\ +size=3D4294967296 \ +-device virtio-mem-pci,node=3D0,block-size=3D2097152,requested-size=3D5368= 70912,\ +memdev=3Dmemvirtiomem2,id=3Dvirtiomem2,bus=3Dpci.0,addr=3D0x5 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\ +"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=3Dide.0,unit=3D0,drive=3Dlibvirt-1-format,id=3Dide0-0-0= ,bootindex=3D1 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index c79246e0bb..13678fc891 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3013,6 +3013,7 @@ mymain(void) DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-readonly"); DO_TEST_CAPS_ARCH_LATEST("memory-hotplug-nvdimm-ppc64", "ppc64"); DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-mem"); =20 DO_TEST("machine-aeskeywrap-on-caps", QEMU_CAPS_AES_KEY_WRAP, --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999058; cv=none; d=zohomail.com; s=zohoarc; b=KxOddOb8OzNh5hTJ//QrplKjKvilLU2RD+JuHJpj+7nYh8laDNZa9xSMmHyNaZk48En+uFjd+mQB36J+5B8zBeCFYhyHHSu3r7WuANnUY87YuCmYCBP511hefItkJVlJ76SGI0wW11JdiOXJCIA4kxTsTpw3NJXa7RQDUVj3GwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999058; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+KiKvfS9YMr14BidMLoopYJpUyzFSmLHgM2KNNz/WnQ=; b=lNesolmb8H/caOlXVY0MxiXqWefLM9RltAWuDk+u9S6CyGr1luAEZq6pnOdDmXvTvr7rUCakRuq/GyapY806XMfIDKmGlwBFeP0WzgaxBye5ToZPgVENxdcsohy4rS7nMCNTu9IOE+NMoJa9oQAJq0m0mtjkTIBDep6Mj5ZPqgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999058842102.66241488758271; Thu, 3 Dec 2020 04:37:38 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-JcIiOPlwMYCoIHHtKqwH5A-1; Thu, 03 Dec 2020 07:37:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97DCD805BE1; Thu, 3 Dec 2020 12:37:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7645360C17; Thu, 3 Dec 2020 12:37:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1CE0A5004D; Thu, 3 Dec 2020 12:37:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbRDZ003403 for ; Thu, 3 Dec 2020 07:37:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id E0AC45C1CF; Thu, 3 Dec 2020 12:37:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 624D45C1C2 for ; Thu, 3 Dec 2020 12:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999057; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+KiKvfS9YMr14BidMLoopYJpUyzFSmLHgM2KNNz/WnQ=; b=Fwx9LyIWnbzjQBJRJLYKRAC8+nN4MaF+I1rQxRnhCGIa1/KaVBTd6CJ7+whc1xbaCq+/H4 YGNe2GYCG8WtrJxM5BOkq2arq84EapF2haE2S13SsN5rAhTi3nsYXXVhYWA4WTvGtcwgQm zrHjRwzdRPbSdEEB02szVP0+7IZcT20= X-MC-Unique: JcIiOPlwMYCoIHHtKqwH5A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 22/27] qemu: Wire up live update Date: Thu, 3 Dec 2020 13:36:25 +0100 Message-Id: <3f112318d583c1ddf0f10cd7a7357e7a93eb4b4a.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" As advertised in the previous commit, we want' to be able to change 'requested-size' attribute of virtio-mem on the fly. This commit does exactly that. Changing anything else is checked for and forbidden. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/conf/domain_conf.c | 23 +++++ src/conf/domain_conf.h | 3 + src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 165 ++++++++++++++++++++++++++++++++++- src/qemu/qemu_hotplug.c | 18 ++++ src/qemu/qemu_hotplug.h | 5 ++ src/qemu/qemu_monitor.c | 13 +++ src/qemu/qemu_monitor.h | 4 + src/qemu/qemu_monitor_json.c | 15 ++++ src/qemu/qemu_monitor_json.h | 5 ++ 10 files changed, 251 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0551f6f266..a4293f1749 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18762,6 +18762,29 @@ virDomainMemoryFindInactiveByDef(virDomainDefPtr d= ef, } =20 =20 +ssize_t +virDomainMemoryFindByDeviceInfo(virDomainDefPtr def, + virDomainDeviceInfoPtr info) +{ + size_t i; + + for (i =3D 0; i < def->nmems; i++) { + virDomainMemoryDefPtr tmp =3D def->mems[i]; + + if (!virDomainDeviceInfoAddressIsEqual(&tmp->info, info)) + continue; + + /* alias, if present */ + if (STRNEQ_NULLABLE(tmp->info.alias, info->alias)) + continue; + + return i; + } + + return -1; +} + + /** * virDomainMemoryInsert: * diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f16dc0a029..d0814d7639 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3584,6 +3584,9 @@ int virDomainMemoryFindByDef(virDomainDefPtr def, vir= DomainMemoryDefPtr mem) int virDomainMemoryFindInactiveByDef(virDomainDefPtr def, virDomainMemoryDefPtr mem) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; +ssize_t virDomainMemoryFindByDeviceInfo(virDomainDefPtr dev, + virDomainDeviceInfoPtr info) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 int virDomainShmemDefInsert(virDomainDefPtr def, virDomainShmemDefPtr shme= m) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2f640ef1c4..7014d602b6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -497,6 +497,7 @@ virDomainMemballoonModelTypeFromString; virDomainMemballoonModelTypeToString; virDomainMemoryDefFree; virDomainMemoryFindByDef; +virDomainMemoryFindByDeviceInfo; virDomainMemoryFindInactiveByDef; virDomainMemoryInsert; virDomainMemoryModelTypeToString; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bca1c84630..edc109cb28 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7104,6 +7104,158 @@ qemuDomainChangeDiskLive(virDomainObjPtr vm, return 0; } =20 + +static bool +qemuDomainChangeMemoryLiveValidateChange(const virDomainMemoryDef *oldDef, + const virDomainMemoryDef *newDef) +{ + /* The only thing that is allowed to change is 'requestedsize' for vir= tio + * model. */ + if (oldDef->model !=3D newDef->model) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory model from '%s' to '%s'"), + virDomainMemoryModelTypeToString(oldDef->model), + virDomainMemoryModelTypeToString(newDef->model)); + return false; + } + + if (oldDef->access !=3D newDef->access) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory access from '%s' to '%s'"), + virDomainMemoryAccessTypeToString(oldDef->access), + virDomainMemoryAccessTypeToString(newDef->access)); + return false; + } + + if (oldDef->discard !=3D newDef->discard) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory discard from '%s' to '%s'"), + virTristateBoolTypeToString(oldDef->discard), + virTristateBoolTypeToString(newDef->discard)); + return false; + } + + if (oldDef->targetNode !=3D newDef->targetNode) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory targetNode from '%d' to '%d= '"), + oldDef->targetNode, newDef->targetNode); + return false; + } + + if (oldDef->size !=3D newDef->size) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory size from '%llu' to '%llu'"= ), + oldDef->size, newDef->size); + return false; + } + + if (oldDef->blocksize !=3D newDef->blocksize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory block size from '%llu' to '= %llu'"), + oldDef->blocksize, newDef->blocksize); + return false; + } + + /* requestedsize can change */ + + if (oldDef->readonly !=3D newDef->readonly) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory pmem flag")); + return false; + } + + if (virUUIDIsValid(oldDef->uuid) && + memcmp(oldDef->uuid, newDef, VIR_UUID_BUFLEN) !=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory UUID")); + return false; + } + + switch (oldDef->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + if (STRNEQ_NULLABLE(oldDef->s.virtio.path, newDef->s.virtio.path))= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory path from '%s' to '%s'"= ), + NULLSTR(oldDef->s.virtio.path), + NULLSTR(newDef->s.virtio.path)); + return false; + } + + if (oldDef->s.virtio.pmem !=3D newDef->s.virtio.pmem) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory pmem flag")); + return false; + } + + if (!virBitmapEqual(oldDef->s.virtio.sourceNodes, + newDef->s.virtio.sourceNodes)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory source nodes")); + return false; + } + + if (oldDef->s.virtio.pagesize !=3D newDef->s.virtio.pagesize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory pagesize from '%llu' to= '%llu'"), + oldDef->s.virtio.pagesize, + newDef->s.virtio.pagesize); + return false; + } + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory of model '%s'"), + virDomainMemoryModelTypeToString(oldDef->model)); + return false; + break; + } + + return true; +} + + +static int +qemuDomainChangeMemoryLive(virQEMUDriverPtr driver G_GNUC_UNUSED, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev) +{ + virDomainMemoryDefPtr newDef =3D dev->data.memory; + virDomainMemoryDefPtr oldDef =3D NULL; + ssize_t idx; + + idx =3D virDomainMemoryFindByDeviceInfo(vm->def, &dev->data.memory->in= fo); + if (idx < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory '%s' not found"), dev->data.memory->info.= alias); + return -1; + } + + oldDef =3D vm->def->mems[idx]; + + if (newDef->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO || + newDef->s.virtio.pmem) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("changing anything but size for virt= io-mem is not implemented yet")); + return -1; + } + + if (!qemuDomainChangeMemoryLiveValidateChange(oldDef, newDef)) + return -1; + + if (qemuDomainChangeMemoryRequestedSize(driver, vm, + newDef->info.alias, + newDef->requestedsize) < 0) + return -1; + + oldDef->requestedsize =3D newDef->requestedsize; + return 0; +} + + static int qemuDomainUpdateDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev, @@ -7145,6 +7297,18 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainChangeNet(driver, vm, dev); break; =20 + case VIR_DOMAIN_DEVICE_MEMORY: + if ((idx =3D virDomainMemoryFindByDeviceInfo(vm->def, &dev->data.m= emory->info)) >=3D 0) { + oldDev.data.memory =3D vm->def->mems[idx]; + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDA= TE, + true) < 0) + return -1; + } + + ret =3D qemuDomainChangeMemoryLive(driver, vm, dev); + break; + case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: @@ -7160,7 +7324,6 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_HOSTDEV: case VIR_DOMAIN_DEVICE_CONTROLLER: case VIR_DOMAIN_DEVICE_REDIRDEV: - case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_CHR: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_TPM: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index bc5dc02a2f..a18fa6d362 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6672,3 +6672,21 @@ qemuDomainSetVcpuInternal(virQEMUDriverPtr driver, virBitmapFree(livevcpus); return ret; } + + +int +qemuDomainChangeMemoryRequestedSize(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *alias, + unsigned long long requestedsize) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + int rc; + + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorChangeMemoryRequestedSize(priv->mon, alias, requeste= dsize); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + return -1; + + return rc; +} diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 6287c5b5e8..9e551a1f82 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -160,3 +160,8 @@ int qemuHotplugAttachDBusVMState(virQEMUDriverPtr drive= r, int qemuHotplugRemoveDBusVMState(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob); + +int qemuDomainChangeMemoryRequestedSize(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *alias, + unsigned long long requestedsize); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index ce1a06c4c8..0e2cc0b76c 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4733,3 +4733,16 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions, return qemuMonitorJSONTransactionBackup(actions, device, jobname, targ= et, bitmap, syncmode); } + + +int +qemuMonitorChangeMemoryRequestedSize(qemuMonitorPtr mon, + const char *alias, + unsigned long long requestedsize) +{ + VIR_DEBUG("alias=3D%s requestedsize=3D%llu", alias, requestedsize); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONChangeMemoryRequestedSize(mon, alias, requesteds= ize); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8bc092870b..3005adc1e0 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1518,3 +1518,7 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions, const char *target, const char *bitmap, qemuMonitorTransactionBackupSyncMode syncmode= ); + +int qemuMonitorChangeMemoryRequestedSize(qemuMonitorPtr mon, + const char *alias, + unsigned long long requestedsize); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e82d762925..4046d0b3b0 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -9467,3 +9467,18 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon, return virJSONValueGetBoolean(virJSONValueObjectGet(reply, "return"), migratable); } + + +int +qemuMonitorJSONChangeMemoryRequestedSize(qemuMonitorPtr mon, + const char *alias, + unsigned long long requestedsize) +{ + g_autofree char *path =3D g_strdup_printf("/machine/peripheral/%s", al= ias); + qemuMonitorJSONObjectProperty prop =3D { + .type =3D QEMU_MONITOR_OBJECT_PROPERTY_ULONG, + .val.ul =3D requestedsize * 1024, /* monitor needs bytes */ + }; + + return qemuMonitorJSONSetObjectProperty(mon, path, "requested-size", &= prop); +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index d2928b0ffc..d4b80b5f27 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -704,3 +704,8 @@ int qemuMonitorJSONSetDBusVMStateIdList(qemuMonitorPtr = mon, int qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon, bool *migratable); + +int +qemuMonitorJSONChangeMemoryRequestedSize(qemuMonitorPtr mon, + const char *alias, + unsigned long long requestedsize); --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999213; cv=none; d=zohomail.com; s=zohoarc; b=Iss4c2KsfSC55cdHdn3uU15tU6L+gT/GpbjXoTyxFST/nOrWlF4ZtFV8S8hRzOiogdgOpqukvLtDHKmI9L/WhmMH6dBCovXyVX7EyCA6g6M0mBnVuz6sxReuWd34mjYwqKzPbHkjXurklkAHxOTOxYWHVlx6q3QI4WGnF30ZPjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999213; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fipZYEQe6uLhJWkqKO9jewquVx+KnGLCABHzv7rtVmo=; b=KYWuW6876gAaQAlnzMF5F/sYxaLeBxSUrjvJcaPY5H2B++G/lN8PIXWrmlE/vtjCdOfSjjXxACj+z1Uwf5EdL/1fCZ79W3sSDMkMW31KRE0tLWquAd1L7AiCHJFti1BDtAl+s6r+X2B45uxaTzlmaRXV8yLUqcfrz7Y0VqUIN/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999213262872.4539191705175; Thu, 3 Dec 2020 04:40:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-dkKYW67ZP828JtKI6XxZNQ-1; Thu, 03 Dec 2020 07:38:08 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8CED65705E; Thu, 3 Dec 2020 12:38:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 686E75D736; Thu, 3 Dec 2020 12:38:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 31870180954D; Thu, 3 Dec 2020 12:38:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbUWU003435 for ; Thu, 3 Dec 2020 07:37:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id EB2215C1CF; Thu, 3 Dec 2020 12:37:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C5605C1C2 for ; Thu, 3 Dec 2020 12:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999212; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fipZYEQe6uLhJWkqKO9jewquVx+KnGLCABHzv7rtVmo=; b=Z2rY06SK/IDW2G3X2NdZ6pil32FxnpDrFal33jMCYpzYqJIiKbeToi3oIQT3fFt5aDQl8G L8EKLutTzzwtsZ1mW9qH8MPrR2jLKVGIzRlZUmU0vs4ljyUAhtGw2ERN04dNCXv/RVShP6 djGRpXWF/4EU7Uf4kB89baDP3biVQ20= X-MC-Unique: dkKYW67ZP828JtKI6XxZNQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 23/27] qemu: Wire up MEMORY_DEVICE_SIZE_CHANGE event Date: Thu, 3 Dec 2020 13:36:26 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" As advertised in previous commit, this event is delivered to us when virtio-mem module changes the allocation inside the guest. It comes with one attribute - size - which holds the new size of the virtio-mem (well, allocated size), in bytes. Mind you, this is not necessarily the same number as 'requested size'. It almost certainly will be when sizing the memory up, but it might not be when sizing the memory down - the guest kernel might be unable to free some blocks. This actual size is reported in the domain XML as an output element only. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- docs/formatdomain.rst | 7 +++ docs/schemas/domaincommon.rng | 5 ++ src/conf/domain_conf.c | 24 ++++++++- src/conf/domain_conf.h | 7 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 3 ++ src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 36 +++++++++++++ src/qemu/qemu_monitor.c | 24 +++++++++ src/qemu/qemu_monitor.h | 20 ++++++++ src/qemu/qemu_monitor_json.c | 24 +++++++++ src/qemu/qemu_process.c | 96 +++++++++++++++++++++++++++++++---- 12 files changed, 236 insertions(+), 12 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 3990728939..ac87d03b33 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7196,6 +7196,7 @@ Example: usage of the memory devices 0 2048 524288 + 524288 @@ -7322,6 +7323,12 @@ Example: usage of the memory devices granularity. This is valid for ``virtio`` model only and mutually exclusive with ``pmem``. =20 + ``actual`` + The active XML for a ``virtio`` model may contain ``actual`` element = that + reflects the actual size of the corresponding virtio memory device. T= he + element is formatted into live XML and never parsed, i.e. it is + output-only element. + :anchor:`` =20 IOMMU devices diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index d478b639fa..3b12902e04 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6063,6 +6063,11 @@ + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a4293f1749..8adb3e99e2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18785,6 +18785,21 @@ virDomainMemoryFindByDeviceInfo(virDomainDefPtr de= f, } =20 =20 +ssize_t +virDomainMemoryFindByDeviceAlias(virDomainDefPtr def, + const char *alias) +{ + size_t i; + + for (i =3D 0; i < def->nmems; i++) { + if (STREQ_NULLABLE(def->mems[i]->info.alias, alias)) + return i; + } + + return -1; +} + + /** * virDomainMemoryInsert: * @@ -28086,7 +28101,8 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, =20 static void virDomainMemoryTargetDefFormat(virBufferPtr buf, - virDomainMemoryDefPtr def) + virDomainMemoryDefPtr def, + unsigned int flags) { g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); =20 @@ -28108,6 +28124,10 @@ virDomainMemoryTargetDefFormat(virBufferPtr buf, =20 virBufferAsprintf(&childBuf, "%llu\n", def->requestedsize); + if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { + virBufferAsprintf(&childBuf, "%llu\n", + def->actualsize); + } } =20 virXMLFormatElement(buf, "target", NULL, &childBuf); @@ -28142,7 +28162,7 @@ virDomainMemoryDefFormat(virBufferPtr buf, if (virDomainMemorySourceDefFormat(buf, def) < 0) return -1; =20 - virDomainMemoryTargetDefFormat(buf, def); + virDomainMemoryTargetDefFormat(buf, def, flags); =20 virDomainDeviceInfoFormat(buf, &def->info, flags); =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index d0814d7639..f8d86d704e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2342,6 +2342,9 @@ struct _virDomainMemoryDef { unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */ unsigned long long blocksize; /* kibibytes, valid for virtio-mem only = */ unsigned long long requestedsize; /* kibibytes, valid for virtio-mem o= nly */ + unsigned long long actualsize; /* kibibytes, valid for virtio-mem and + active domain only, only to report n= ever + parse */ bool readonly; /* valid only for NVDIMM */ =20 /* required for QEMU NVDIMM ppc64 support */ @@ -3588,6 +3591,10 @@ ssize_t virDomainMemoryFindByDeviceInfo(virDomainDef= Ptr dev, virDomainDeviceInfoPtr info) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 +ssize_t virDomainMemoryFindByDeviceAlias(virDomainDefPtr def, + const char *alias) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; + int virDomainShmemDefInsert(virDomainDefPtr def, virDomainShmemDefPtr shme= m) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; bool virDomainShmemDefEquals(virDomainShmemDefPtr src, virDomainShmemDefPt= r dst) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7014d602b6..1d800087fc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -497,6 +497,7 @@ virDomainMemballoonModelTypeFromString; virDomainMemballoonModelTypeToString; virDomainMemoryDefFree; virDomainMemoryFindByDef; +virDomainMemoryFindByDeviceAlias; virDomainMemoryFindByDeviceInfo; virDomainMemoryFindInactiveByDef; virDomainMemoryInsert; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ab7938a355..fc994ec282 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10554,6 +10554,9 @@ qemuProcessEventFree(struct qemuProcessEvent *event) case QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE: virObjectUnref(event->data); break; + case QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE: + qemuMonitorMemoryDeviceSizeChangeFree(event->data); + break; case QEMU_PROCESS_EVENT_PR_DISCONNECT: case QEMU_PROCESS_EVENT_LAST: break; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 010bae285d..376679da77 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -441,6 +441,7 @@ typedef enum { QEMU_PROCESS_EVENT_PR_DISCONNECT, QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED, QEMU_PROCESS_EVENT_GUEST_CRASHLOADED, + QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE, =20 QEMU_PROCESS_EVENT_LAST } qemuProcessEventType; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index edc109cb28..3d2d6bc1eb 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4284,6 +4284,39 @@ processGuestCrashloadedEvent(virQEMUDriverPtr driver, } =20 =20 +static void +processMemoryDeviceSizeChange(virQEMUDriverPtr driver, + virDomainObjPtr vm, + qemuMonitorMemoryDeviceSizeChangePtr info) +{ + virDomainMemoryDefPtr mem =3D NULL; + ssize_t idx; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto endjob; + } + + idx =3D virDomainMemoryFindByDeviceAlias(vm->def, info->devAlias); + if (idx < 0) { + VIR_DEBUG("Memory device '%s' not found", info->devAlias); + goto endjob; + } + + mem =3D vm->def->mems[idx]; + mem->actualsize =3D VIR_DIV_UP(info->size, 1024); + + /* fix the balloon size */ + ignore_value(qemuProcessRefreshBalloonState(driver, vm, QEMU_ASYNC_JOB= _NONE)); + + endjob: + qemuDomainObjEndJob(driver, vm); +} + + static void qemuProcessEventHandler(void *data, void *opaque) { struct qemuProcessEvent *processEvent =3D data; @@ -4333,6 +4366,9 @@ static void qemuProcessEventHandler(void *data, void = *opaque) case QEMU_PROCESS_EVENT_GUEST_CRASHLOADED: processGuestCrashloadedEvent(driver, vm); break; + case QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE: + processMemoryDeviceSizeChange(driver, vm, processEvent->data); + break; case QEMU_PROCESS_EVENT_LAST: break; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 0e2cc0b76c..e8a9788011 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1417,6 +1417,20 @@ qemuMonitorEmitSpiceMigrated(qemuMonitorPtr mon) } =20 =20 +int +qemuMonitorEmitMemoryDeviceSizeChange(qemuMonitorPtr mon, + const char *devAlias, + unsigned long long size) +{ + int ret =3D -1; + VIR_DEBUG("mon=3D%p, devAlias=3D'%s', size=3D%llu", mon, devAlias, siz= e); + + QEMU_MONITOR_CALLBACK(mon, ret, domainMemoryDeviceSizeChange, mon->vm,= devAlias, size); + + return ret; +} + + int qemuMonitorEmitMemoryFailure(qemuMonitorPtr mon, qemuMonitorEventMemoryFailurePtr mfp) @@ -4420,6 +4434,16 @@ qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGid= StatusPtr info) } =20 =20 +void +qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChangePtr= info) +{ + if (!info) + return; + + VIR_FREE(info->devAlias); +} + + int qemuMonitorSetWatchdogAction(qemuMonitorPtr mon, const char *action) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 3005adc1e0..2f9184c122 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -108,6 +108,14 @@ struct _qemuMonitorRdmaGidStatus { }; =20 =20 +typedef struct _qemuMonitorMemoryDeviceSizeChange qemuMonitorMemoryDeviceS= izeChange; +typedef qemuMonitorMemoryDeviceSizeChange *qemuMonitorMemoryDeviceSizeChan= gePtr; +struct _qemuMonitorMemoryDeviceSizeChange { + char *devAlias; + unsigned long long size; +}; + + typedef enum { QEMU_MONITOR_JOB_TYPE_UNKNOWN, /* internal value, not exposed by qemu = */ QEMU_MONITOR_JOB_TYPE_COMMIT, @@ -153,6 +161,7 @@ struct _qemuMonitorJobInfo { char *qemuMonitorGuestPanicEventInfoFormatMsg(qemuMonitorEventPanicInfoPtr= info); void qemuMonitorEventPanicInfoFree(qemuMonitorEventPanicInfoPtr info); void qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGidStatusPtr info); +void qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChan= gePtr info); =20 typedef void (*qemuMonitorDestroyCallback)(qemuMonitorPtr mon, virDomainObjPtr vm, @@ -374,6 +383,12 @@ typedef int (*qemuMonitorDomainMemoryFailureCallback)(= qemuMonitorPtr mon, qemuMonitorEventMemo= ryFailurePtr mfp, void *opaque); =20 +typedef int (*qemuMonitorDomainMemoryDeviceSizeChange)(qemuMonitorPtr mon, + virDomainObjPtr vm, + const char *alias, + unsigned long long = size, + void *opaque); + typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks; typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr; struct _qemuMonitorCallbacks { @@ -411,6 +426,7 @@ struct _qemuMonitorCallbacks { qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChang= ed; qemuMonitorDomainGuestCrashloadedCallback domainGuestCrashloaded; qemuMonitorDomainMemoryFailureCallback domainMemoryFailure; + qemuMonitorDomainMemoryDeviceSizeChange domainMemoryDeviceSizeChange; }; =20 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm, @@ -507,6 +523,10 @@ int qemuMonitorEmitSerialChange(qemuMonitorPtr mon, bool connected); int qemuMonitorEmitSpiceMigrated(qemuMonitorPtr mon); =20 +int qemuMonitorEmitMemoryDeviceSizeChange(qemuMonitorPtr mon, + const char *devAlias, + unsigned long long size); + int qemuMonitorEmitMemoryFailure(qemuMonitorPtr mon, qemuMonitorEventMemoryFailurePtr mfp); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 4046d0b3b0..3fd925eae1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -113,6 +113,7 @@ static void qemuMonitorJSONHandleDumpCompleted(qemuMoni= torPtr mon, virJSONValueP static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitorPtr mon= , virJSONValuePtr data); static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitorPtr mon, = virJSONValuePtr data); static void qemuMonitorJSONHandleMemoryFailure(qemuMonitorPtr mon, virJSON= ValuePtr data); +static void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitorPtr mon= , virJSONValuePtr data); =20 typedef struct { const char *type; @@ -133,6 +134,7 @@ static qemuEventHandler eventHandlers[] =3D { { "GUEST_CRASHLOADED", qemuMonitorJSONHandleGuestCrashloaded, }, { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, }, { "JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange, }, + { "MEMORY_DEVICE_SIZE_CHANGE", qemuMonitorJSONHandleMemoryDeviceSizeCh= ange, }, { "MEMORY_FAILURE", qemuMonitorJSONHandleMemoryFailure, }, { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, }, { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, }, @@ -1335,6 +1337,28 @@ qemuMonitorJSONHandleSpiceMigrated(qemuMonitorPtr mo= n, } =20 =20 +static void +qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitorPtr mon, + virJSONValuePtr data) +{ + const char *name; + unsigned long long size; + + if (!(name =3D virJSONValueObjectGetString(data, "id"))) { + VIR_WARN("missing device alias in MEMORY_DEVICE_SIZE_CHANGE event"= ); + return; + } + + if (virJSONValueObjectGetNumberUlong(data, "size", &size) < 0) { + VIR_WARN("missing new size for '%s' in MEMORY_DEVICE_SIZE_CHANGE e= vent", name); + return; + } + + + qemuMonitorEmitMemoryDeviceSizeChange(mon, name, size); +} + + static void qemuMonitorJSONHandleMemoryFailure(qemuMonitorPtr mon, virJSONValuePtr data) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8ea7e0df05..1fba9d8302 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1248,10 +1248,30 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon G= _GNUC_UNUSED, virQEMUDriverPtr driver =3D opaque; virObjectEventPtr event =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + size_t i; =20 virObjectLock(vm); event =3D virDomainEventBalloonChangeNewFromObj(vm, actual); =20 + VIR_DEBUG("New balloon size before fixup: %lld", actual); + + for (i =3D 0; i < vm->def->nmems; i++) { + virDomainMemoryDefPtr mem =3D vm->def->mems[i]; + + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + actual +=3D mem->actualsize; + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + /* nada */ + break; + } + } + VIR_DEBUG("Updating balloon from %lld to %lld kb", vm->def->mem.cur_balloon, actual); vm->def->mem.cur_balloon =3D actual; @@ -1932,6 +1952,46 @@ qemuProcessHandleMemoryFailure(qemuMonitorPtr mon G_= GNUC_UNUSED, } =20 =20 +static int +qemuProcessHandleMemoryDeviceSizeChange(qemuMonitorPtr mon G_GNUC_UNUSED, + virDomainObjPtr vm, + const char *devAlias, + unsigned long long size, + void *opaque) +{ + virQEMUDriverPtr driver =3D opaque; + struct qemuProcessEvent *processEvent =3D NULL; + qemuMonitorMemoryDeviceSizeChangePtr info =3D NULL; + int ret =3D -1; + + virObjectLock(vm); + + VIR_DEBUG("Memory device '%s' changed size to '%llu' in domain '%s'", + devAlias, size, vm->def->name); + + info =3D g_new0(qemuMonitorMemoryDeviceSizeChange, 1); + info->devAlias =3D g_strdup(devAlias); + info->size =3D size; + + processEvent =3D g_new0(struct qemuProcessEvent, 1); + processEvent->eventType =3D QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHAN= GE; + processEvent->vm =3D virObjectRef(vm); + processEvent->data =3D g_steal_pointer(&info); + + if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) { + qemuProcessEventFree(processEvent); + virObjectUnref(vm); + goto cleanup; + } + + ret =3D 0; + cleanup: + qemuMonitorMemoryDeviceSizeChangeFree(info); + virObjectUnlock(vm); + return ret; +} + + static qemuMonitorCallbacks monitorCallbacks =3D { .eofNotify =3D qemuProcessHandleMonitorEOF, .errorNotify =3D qemuProcessHandleMonitorError, @@ -1965,6 +2025,7 @@ static qemuMonitorCallbacks monitorCallbacks =3D { .domainRdmaGidStatusChanged =3D qemuProcessHandleRdmaGidStatusChanged, .domainGuestCrashloaded =3D qemuProcessHandleGuestCrashloaded, .domainMemoryFailure =3D qemuProcessHandleMemoryFailure, + .domainMemoryDeviceSizeChange =3D qemuProcessHandleMemoryDeviceSizeCha= nge, }; =20 static void @@ -2405,21 +2466,36 @@ qemuProcessRefreshBalloonState(virQEMUDriverPtr dri= ver, int asyncJob) { unsigned long long balloon; + size_t i; int rc; =20 - /* if no ballooning is available, the current size equals to the curre= nt - * full memory size */ - if (!virDomainDefHasMemballoon(vm->def)) { - vm->def->mem.cur_balloon =3D virDomainDefGetMemoryTotal(vm->def); - return 0; + if (virDomainDefHasMemballoon(vm->def)) { + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + return -1; + + rc =3D qemuMonitorGetBalloonInfo(qemuDomainGetMonitor(vm), &balloo= n); + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + return -1; + } else { + balloon =3D virDomainDefGetMemoryTotal(vm->def); } =20 - if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) - return -1; + for (i =3D 0; i < vm->def->nmems; i++) { + virDomainMemoryDefPtr mem =3D vm->def->mems[i]; + + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + balloon +=3D mem->actualsize; + break; =20 - rc =3D qemuMonitorGetBalloonInfo(qemuDomainGetMonitor(vm), &balloon); - if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) - return -1; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + /* nada */ + break; + } + } =20 vm->def->mem.cur_balloon =3D balloon; =20 --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999095; cv=none; d=zohomail.com; s=zohoarc; b=oBUKRmUyyeyqJq+2gWeIDpIoKAyWzTCou76QKDNApLCdRrcV+7xDYDXdXyAoChqW3bD1eG3Efah+HAROJXqOQrHp7qPlVGyexkU47Wb9UOCflFX7RetdfNzS5LGGvIx494I8D3dXx6avgIABGiv5+YIvVZnDByQO3oli+WVmhJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999095; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oTe6Fgxg2PGSjnXQ0/t31++MDUhRIigotF9LtiHHwQo=; b=NdUwk4F7dbnTfTT7ZTPmhwMhCMJ1UJU+cHD399seEBzMJ97V3fMX4zYqLYjqsyxYC7BD9c1pJIOa70RXipbMi6ZYMSVf1M7zooDLtVhk9wJuIl73hu6DU/1PWGC/aGzvibEO7g5k32/ePcLxb2IM8CJUX/p54FnbVUEVFyTCYEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999095713579.5571699343766; Thu, 3 Dec 2020 04:38:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236--CU3PjbSODyqAyy6b-OJEg-1; Thu, 03 Dec 2020 07:38:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0662805BF7; Thu, 3 Dec 2020 12:38:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC61460BFA; Thu, 3 Dec 2020 12:38:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 89D241809CAB; Thu, 3 Dec 2020 12:38:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbYev003452 for ; Thu, 3 Dec 2020 07:37:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2202A5C1CF; Thu, 3 Dec 2020 12:37:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97E175C1C2 for ; Thu, 3 Dec 2020 12:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999094; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oTe6Fgxg2PGSjnXQ0/t31++MDUhRIigotF9LtiHHwQo=; b=dXG78VtbFC0fsJAkKylB/ogSW8GqgzAFmnWGttoQfKCkJPB1gCkkc6nQm1mW/T0FnFsmsS jIV5w10t281Jhfs0Ssma3li+feDp1UiybV3PetwlMFRg7j06YWBjamH0CKfSl3n9xOi+LA W07hbJJSxHWmPHNJjeIo3a1Ia5TfDho= X-MC-Unique: -CU3PjbSODyqAyy6b-OJEg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 24/27] qemu: Refresh the actual size of virtio-mem on monitor reconnect Date: Thu, 3 Dec 2020 13:36:27 +0100 Message-Id: <77c283ef5de3fd01c7b93c46a83bde600884f93a.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" If the QEMU driver restarts it loses the track of the actual size of virtio-mem (because it's runtime type of information and thus not stored in XML) and therefore, we have to refresh it when reconnecting to the domain monitor. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- src/qemu/qemu_domain.c | 36 +++++++++++++++++++---- src/qemu/qemu_monitor.h | 3 ++ src/qemu/qemu_monitor_json.c | 55 +++++++++++++++++++++--------------- src/qemu/qemu_process.c | 3 ++ 4 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fc994ec282..ea05498b78 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7845,9 +7845,21 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr dr= iver, return -1; } =20 - /* if qemu doesn't support the info request, just carry on */ - if (rc =3D=3D -2) + /* If qemu doesn't support the info request, just carry on, unless we + * really need it. */ + if (rc =3D=3D -2) { + for (i =3D 0; i < vm->def->nmems; i++) { + virDomainMemoryDefPtr mem =3D vm->def->mems[i]; + + if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("qemu did not return info on vitio-mem de= vice")); + return -1; + } + } + return 0; + } =20 if (rc < 0) return -1; @@ -7862,9 +7874,23 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr dr= iver, if (!(dimm =3D virHashLookup(meminfo, mem->info.alias))) continue; =20 - mem->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM; - mem->info.addr.dimm.slot =3D dimm->slot; - mem->info.addr.dimm.base =3D dimm->address; + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + mem->actualsize =3D VIR_DIV_UP(dimm->size, 1024); + break; + + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + mem->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM; + mem->info.addr.dimm.slot =3D dimm->slot; + mem->info.addr.dimm.base =3D dimm->address; + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + /* nada */ + break; + } } =20 virHashFree(meminfo); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2f9184c122..94bef3d5d5 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1393,10 +1393,13 @@ typedef struct _qemuMonitorMemoryDeviceInfo qemuMon= itorMemoryDeviceInfo; typedef qemuMonitorMemoryDeviceInfo *qemuMonitorMemoryDeviceInfoPtr; =20 struct _qemuMonitorMemoryDeviceInfo { + /* For pc-dimm */ unsigned long long address; unsigned int slot; bool hotplugged; bool hotpluggable; + /* For virtio-mem */ + unsigned long long size; }; =20 int qemuMonitorGetMemoryDeviceInfo(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 3fd925eae1..80f159618a 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8241,7 +8241,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon, virJSONValuePtr cmd; virJSONValuePtr reply =3D NULL; virJSONValuePtr data =3D NULL; - qemuMonitorMemoryDeviceInfoPtr meminfo =3D NULL; size_t i; =20 if (!(cmd =3D qemuMonitorJSONMakeCommand("query-memory-devices", NULL)= )) @@ -8262,6 +8261,9 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon, =20 for (i =3D 0; i < virJSONValueArraySize(data); i++) { virJSONValuePtr elem =3D virJSONValueArrayGet(data, i); + g_autofree qemuMonitorMemoryDeviceInfoPtr meminfo =3D NULL; + virJSONValuePtr dimminfo; + const char *devalias; const char *type; =20 if (!(type =3D virJSONValueObjectGetString(elem, "type"))) { @@ -8271,26 +8273,23 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr m= on, goto cleanup; } =20 + if (!(dimminfo =3D virJSONValueObjectGetObject(elem, "data"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-memory-devices reply data doesn't " + "contain enum data")); + goto cleanup; + } + + if (!(devalias =3D virJSONValueObjectGetString(dimminfo, "id"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("dimm memory info data is missing 'id'")); + goto cleanup; + } + + meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); + /* dimm memory devices */ if (STREQ(type, "dimm")) { - virJSONValuePtr dimminfo; - const char *devalias; - - if (!(dimminfo =3D virJSONValueObjectGetObject(elem, "data")))= { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-memory-devices reply data doesn't " - "contain enum data")); - goto cleanup; - } - - if (!(devalias =3D virJSONValueObjectGetString(dimminfo, "id")= )) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("dimm memory info data is missing 'id'")); - goto cleanup; - } - - meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); - if (virJSONValueObjectGetNumberUlong(dimminfo, "addr", &meminfo->address) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -8321,17 +8320,27 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr m= on, =20 } =20 - if (virHashAddEntry(info, devalias, meminfo) < 0) + } else if (STREQ(type, "virtio-mem")) { + if (virJSONValueObjectGetNumberUlong(dimminfo, "size", + &meminfo->size) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing slot in dimm memory in= fo")); goto cleanup; - - meminfo =3D NULL; + } + } else { + /* type not handled yet */ + continue; } + + if (virHashAddEntry(info, devalias, meminfo) < 0) + goto cleanup; + + meminfo =3D NULL; } =20 ret =3D 0; =20 cleanup: - VIR_FREE(meminfo); virJSONValueFree(cmd); virJSONValueFree(reply); return ret; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 1fba9d8302..286818fa83 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8513,6 +8513,9 @@ qemuProcessReconnect(void *opaque) =20 qemuDomainVcpuPersistOrder(obj->def); =20 + if (qemuDomainUpdateMemoryDeviceInfo(driver, obj, QEMU_ASYNC_JOB_NONE)= < 0) + goto error; + if (qemuProcessDetectIOThreadPIDs(driver, obj, QEMU_ASYNC_JOB_NONE) < = 0) goto error; =20 --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999272; cv=none; d=zohomail.com; s=zohoarc; b=jssnJM4bg3WT6td68kLvvZBnrcL5z3wSgKitntp8I3US2AOV5psNUQmJM8zXKCrljlMhj8raVz2Ztt08eg7fcySf6depCKY6q8ennq65IZSJ+mENo/dogZLka2o8ac/X61Ul/KvvsGCCb6l9DTnP32SSfwqMMcHjgbGevQKucAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999272; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cmcKW7uq22RrwryFgYQNKeJgIMm7Wcp+8jWA23dAX+4=; b=CIViojm1mM7XG3aECHSWu5t0ljzqkJZJCHxD/ORZRIOWdz9XRSoVNXseMbFZSgPyjbuk3OdFX4dneDvBF6iHljO5RVdYQ2ehZCRuySqDifi32x/Wjm8wNW6Buyarhq4YnhjG4VjMeDr8/2HHB+nweRhxZ1BaxA+FdtImQmZYveA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999272205965.4769167777175; Thu, 3 Dec 2020 04:41:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-251-NncDe-ljPzmY9Wx2YZrE7g-1; Thu, 03 Dec 2020 07:37:47 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2EB1C1081B22; Thu, 3 Dec 2020 12:37:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BAEA1002393; Thu, 3 Dec 2020 12:37:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CBD4F1809CAF; Thu, 3 Dec 2020 12:37:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbeVL003473 for ; Thu, 3 Dec 2020 07:37:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5135C5C1D0; Thu, 3 Dec 2020 12:37:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id C71455C1CF for ; Thu, 3 Dec 2020 12:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999271; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cmcKW7uq22RrwryFgYQNKeJgIMm7Wcp+8jWA23dAX+4=; b=YETNtJb6O2rtDYYSb//gcmqeXAHP0QKmafKZkPge29mDA+mNKEZWf+MK3hst2Ao4sBRcsE fiPTD8K/oZ4SVdzB+fuP2KNpBz6r7KRcnujILO37nSap9dmsFCN3FFyy/LfylxD+qN5QKo u1kENjGM5CFOCT5lLPhbMDe23NTEWeI= X-MC-Unique: NncDe-ljPzmY9Wx2YZrE7g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 25/27] virsh: Simplify @flags handing in cmdSetmem() and cmdSetmaxmem() Date: Thu, 3 Dec 2020 13:36:28 +0100 Message-Id: <25b1e69763547cf484ec53fba01f831a00a4ff9e.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" What code tries to achieve is that if no flags were provided to either 'setmem' or 'setmaxmem' commands then the old (no flags) API is called to be able to communicate with older daemons. Well, the code can be simplified a bit. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- tools/virsh-domain.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 51a9fd90d1..eeeeaa8639 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9018,9 +9018,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_AFFECT_CONFIG; if (live) flags |=3D VIR_DOMAIN_AFFECT_LIVE; - /* none of the options were specified */ - if (!current && !live && !config) - flags =3D -1; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -9037,7 +9034,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) } kibibytes =3D VIR_DIV_UP(bytes, 1024); =20 - if (flags =3D=3D -1) { + if (flags =3D=3D 0) { if (virDomainSetMemory(dom, kibibytes) !=3D 0) ret =3D false; } else { @@ -9090,7 +9087,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); - unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT | VIR_DOMAIN_MEM_MAXI= MUM; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; =20 VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -9099,9 +9096,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_AFFECT_CONFIG; if (live) flags |=3D VIR_DOMAIN_AFFECT_LIVE; - /* none of the options were specified */ - if (!current && !live && !config) - flags =3D -1; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -9118,13 +9112,13 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) } kibibytes =3D VIR_DIV_UP(bytes, 1024); =20 - if (flags =3D=3D -1) { + if (flags =3D=3D 0) { if (virDomainSetMaxMemory(dom, kibibytes) !=3D 0) { vshError(ctl, "%s", _("Unable to change MaxMemorySize")); ret =3D false; } } else { - if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) { + if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM= _MAXIMUM) < 0) { vshError(ctl, "%s", _("Unable to change MaxMemorySize")); ret =3D false; } --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999100; cv=none; d=zohomail.com; s=zohoarc; b=Ci8iqz6bBc5m4g0t3BPoi5az/4WPBIidAZJVOwvVAATKKBnaBt7VfWJUPyKX1dMacoqXVCZqP4kIBCQkYYZgXVzMMrfFYPKS5rORJz0xs18FRezT0/jWiNGeOXR9qztjgzv3DiGc5ZeHM52p/fC0w0BXJcfnaLB07+vuczlheNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999100; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vShzL2LjSSDuLOMScGvFa8s1wS9KDVi1idEXaIVG8cs=; b=V88qSqlwQK42mMKbL6NVym0inOLmhz4qXdR4ilCyPBgK/BjTIzPWdmhEtq0+Uj+zxxw00oe8Dcz2w8qkXFT5lHGoZPh1kCXtd2c+6EeQcL7XtacyT4hNj5xsQHUWbsfg40xtfMfSzLBiZSC0j8quNtqektVx3apmYOgkHH4n7f8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999100227244.4724739302277; Thu, 3 Dec 2020 04:38:20 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-77-4W9ZynDyMCiGdMFn15z4fA-1; Thu, 03 Dec 2020 07:38:16 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDA8E1007474; Thu, 3 Dec 2020 12:38:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB5B05D735; Thu, 3 Dec 2020 12:38:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9944C5003E; Thu, 3 Dec 2020 12:38:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbhFO003491 for ; Thu, 3 Dec 2020 07:37:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6E5A25C1D0; Thu, 3 Dec 2020 12:37:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3B775C1C2 for ; Thu, 3 Dec 2020 12:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999099; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vShzL2LjSSDuLOMScGvFa8s1wS9KDVi1idEXaIVG8cs=; b=C0WRz8saK7Fjfz3x0fP8G4JnRHC6TEs/U2FzGrx/VZ92h2JwD6tqeIiogVFyMmcu+0zG7Y isOlRnV/rHLbZprEUisppTEcTeyEF/xwf4ORt5gKRrBYHckYIa/L7/rEpzfzbJUx1ZO08z IqN0BQdlXJP2qTHWlVih3pvbra/uiIc= X-MC-Unique: 4W9ZynDyMCiGdMFn15z4fA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 26/27] virsh: Introduce --virtio to setmem Date: Thu, 3 Dec 2020 13:36:29 +0100 Message-Id: <34aacfbdd6c4afca54ccab6787929012581e8ef8.1606998426.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Provide an user friendly way of modifying 'requested-size' of a virtio-mem device. New --node and --alias arguments are introduced but they are needed only if it is not clear which virtio-mem does user mean. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- docs/manpages/virsh.rst | 6 ++ tools/virsh-domain.c | 126 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 122 insertions(+), 10 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 9ef6b68422..c3c8c27a18 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4098,6 +4098,7 @@ setmem :: =20 setmem domain size [[--config] [--live] | [--current]] + [--virtio [--node NODE] | [--alias ALIAS]] =20 Change the memory allocation for a guest domain. If *--live* is specified, perform a memory balloon of a running guest. @@ -4107,6 +4108,11 @@ If *--current* is specified, it is equivalent to eit= her *--live* or Both *--live* and *--config* flags may be given, but *--current* is exclusive. If no flag is specified, behavior is different depending on hypervisor. +If *--virtio* is specified then instead of changing the memory allocation = for +whole domain the individual memory device with virtio model is changed. If +there is more than one such memory device then *--node* or *--alias* must = be +used to specify the device uniquely. *NODE* refers to the guest NUMA node = to +which the memory device is attached to and *ALIAS* is the device alias. =20 *size* is a scaled integer (see ``NOTES`` above); it defaults to kibibytes (blocks of 1024 bytes) unless you provide a suffix (and the older option diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index eeeeaa8639..7d8546d806 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8992,12 +8992,101 @@ static const vshCmdOptDef opts_setmem[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("new memory size, as scaled integer (default KiB)") }, + {.name =3D "virtio", + .type =3D VSH_OT_BOOL, + .help =3D N_("modify virtio memory instead of top level domain memory= ") + }, + {.name =3D "node", + .type =3D VSH_OT_INT, + .help =3D N_("guest numa node"), + }, + {.name =3D "alias", + .type =3D VSH_OT_STRING, + .help =3D N_("memory device alias"), + }, VIRSH_COMMON_OPT_DOMAIN_CONFIG, VIRSH_COMMON_OPT_DOMAIN_LIVE, VIRSH_COMMON_OPT_DOMAIN_CURRENT, {.name =3D NULL} }; =20 + +static int +virshDomainSetmemVirtio(vshControl *ctl, + virDomainPtr dom, + unsigned long kibibytes, + int numaNode, + const char *alias, + unsigned int flags) +{ + g_autoptr(xmlDoc) doc =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autofree char *xpath =3D NULL; + int nmems; + g_autofree xmlNodePtr *mems =3D NULL; + xmlNodePtr requestedSizeNode =3D NULL; + g_autofree char *kibibytesStr =3D NULL; + g_autoptr(xmlBuffer) xmlbuf =3D NULL; + unsigned int domainXMLFlags =3D 0; + const char *updatedMemoryXML =3D NULL; + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) + domainXMLFlags |=3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXMLFromDom(ctl, dom, domainXMLFlags, &doc, &ctxt) < = 0) + return -1; + + if (alias) { + xpath =3D g_strdup_printf("/domain/devices/memory[./alias/@name=3D= '%s']", alias); + } else if (numaNode >=3D 0) { + xpath =3D g_strdup_printf("/domain/devices/memory[./target/node/te= xt()=3D%d]", numaNode); + } else { + xpath =3D g_strdup("/domain/devices/memory[@model=3D'virtio' and n= ot(./source/pmem)]"); + } + + nmems =3D virXPathNodeSet(xpath, ctxt, &mems); + if (nmems < 0) { + vshSaveLibvirtError(); + return -1; + } else if (nmems =3D=3D 0) { + vshError(ctl, _("no virtio-mem device found")); + return -1; + } else if (nmems > 1) { + vshError(ctl, _("multiple virtio-mem devices found")); + return -1; + } + + ctxt->node =3D mems[0]; + + requestedSizeNode =3D virXPathNode("./target/requested", ctxt); + + if (!requestedSizeNode) { + vshError(ctl, _("virtio-mem device is missing ")); + return -1; + } + + kibibytesStr =3D g_strdup_printf("%lu", kibibytes); + xmlNodeSetContent(requestedSizeNode, BAD_CAST kibibytesStr); + + if (!(xmlbuf =3D xmlBufferCreate())) { + vshError(ctl, _("unable to allocate XML buffer")); + return -1; + } + + if (xmlNodeDump(xmlbuf, doc, mems[0], 0, 1) < 0) { + vshError(ctl, _("unable to format new node")); + return -1; + } + + updatedMemoryXML =3D (const char *)xmlBufferContent(xmlbuf); + + if (virDomainUpdateDeviceFlags(dom, updatedMemoryXML, flags) < 0) + return -1; + + return 0; +} + + static bool cmdSetmem(vshControl *ctl, const vshCmd *cmd) { @@ -9005,7 +9094,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) unsigned long long bytes =3D 0; unsigned long long max; unsigned long kibibytes =3D 0; - bool ret =3D true; + bool ret =3D false; bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); bool current =3D vshCommandOptBool(cmd, "current"); @@ -9013,6 +9102,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) =20 VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + VSH_EXCLUSIVE_OPTIONS("node", "alias"); =20 if (config) flags |=3D VIR_DOMAIN_AFFECT_CONFIG; @@ -9028,20 +9118,36 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) max =3D 1024ull * ULONG_MAX; else max =3D ULONG_MAX; - if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - virshDomainFree(dom); - return false; - } + if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) + goto cleanup; + kibibytes =3D VIR_DIV_UP(bytes, 1024); =20 - if (flags =3D=3D 0) { - if (virDomainSetMemory(dom, kibibytes) !=3D 0) - ret =3D false; + if (vshCommandOptBool(cmd, "virtio")) { + int numaNode =3D -1; + const char *alias =3D NULL; + + if (vshCommandOptInt(ctl, cmd, "node", &numaNode) < 0) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0) + goto cleanup; + + if (virshDomainSetmemVirtio(ctl, dom, kibibytes, + numaNode, alias, flags) < 0) + goto cleanup; } else { - if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) - ret =3D false; + if (flags =3D=3D 0) { + if (virDomainSetMemory(dom, kibibytes) !=3D 0) + goto cleanup; + } else { + if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) + goto cleanup; + } } =20 + ret =3D true; + cleanup: virshDomainFree(dom); return ret; } --=20 2.26.2 From nobody Wed May 15 13:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606999079; cv=none; d=zohomail.com; s=zohoarc; b=ErPdSu6cgn52yUsTX6a6UlbPCQx9alQAgVfbBECxxLPgbDoHOx92mcphpWcT88YSLv8q6dI5h6Qyv6CzQRv+KMGtaq6ll/R6WD5PI+Dhp4KlNKYoaSHPsva9/IBYd1Ku4tbcNaxLqgNgn0hwTc5xgkoi5VWNaBrJOrVifO/iH3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999079; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kUDh3ZSAPKYwdjE2K6ddpJb+i7M9Q2nsDw0GfEevxWM=; b=BfOHWW2EzI5Pp/AyH17EF8FrYk8EEx5Bcy1OnbVFmWsWfUSVbyEY4YEamItGkx6aJHTKc7j5mQJiC7uMrLSAEOT7yr4gFVte9YuRtIrtH4OtBl8P37+SjduWxR1iXGs5Ehrnh08vcxsoHhdYmpt1R0do6H8HIhSs7vK7qcUV1Ak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606999079083558.274884131801; Thu, 3 Dec 2020 04:37:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-Q94jQoMKPhCk-SF29ClwYw-1; Thu, 03 Dec 2020 07:37:53 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 834F58558EF; Thu, 3 Dec 2020 12:37:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B87F10016FF; Thu, 3 Dec 2020 12:37:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 28E2950030; Thu, 3 Dec 2020 12:37:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbkGW003501 for ; Thu, 3 Dec 2020 07:37:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 945695C1CF; Thu, 3 Dec 2020 12:37:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 150885C1C2 for ; Thu, 3 Dec 2020 12:37:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999075; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kUDh3ZSAPKYwdjE2K6ddpJb+i7M9Q2nsDw0GfEevxWM=; b=RSHMtaBTdSjbRVFKYBE9sCrMrnNzvoLC23Hbd8uaoZ3eS1SkN7PTuMwURaag0RqpRIX+Y+ pdxEJfvWikSA2PP9ZYfspGUP6zXOuP+I1wLajdP6DQWlgSPZmR2FtIBrZ7nXIRbpAL+n06 WZd99x0LrQhE9z1I1zFAf7q0XwaT1Dk= X-MC-Unique: Q94jQoMKPhCk-SF29ClwYw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 27/27] news: document recent virtio memory addition Date: Thu, 3 Dec 2020 13:36:30 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Tested-by: Han Han --- NEWS.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 135c4e2fe0..adedf15d2b 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -13,6 +13,15 @@ v7.0.0 (unreleased) =20 * **New features** =20 + * qemu: Introduce virtio memory support + + New ``virtio`` model is introduced for ```` device which + translates to ``virtio-pmem`` or ``virtio-mem`` on QEMU command + line. The former servers as a NVDIMM and the latter is a + paravirtualized mechanism of adding/removing memory to/from a VM. + It is exposed via ``virDomainUpdateDeviceFlags()`` API and ``virsh + setmem --virtio`` for user convenience. + * **Improvements** =20 * **Bug fixes** --=20 2.26.2