From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631544998; cv=none; d=zohomail.com; s=zohoarc; b=XZvPc7eeAQfUMBdiLLFUbXOv6cXdgW11/zeYfpDTRxWbiXCk3jylsjCLzigTJAsCYUw4/pa5g7BtpldAuhrFrubDLqoTQjghBhfJZ0qRS8EOVDysi0UPWEjuVodwzdnHJx8R/R4qw0XK+4iRKmAf03Z48Nn6iQWRLwNKJqypkJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544998; h=Content-Type:Content-Transfer-Encoding:Cc: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=HMAz/OmOqtnM7fF7OHCIa//4pROujjvCVI4WA/m77QQ=; b=eIrvpcQ01ccVyWQQkJcPkA20/Y0JPN2on/0HRdHRrpCgFxFAJQAOsSnA43TTPd3iJ6KXa69zeKmLD6TOydrGJKywvaw9Wh7sWx/a2IqidNV4JQ4/88E4P8N/HbVYN3Bl8P5xaS6dvk2lSyCIqHry7Uzc8n8c9WdPXqOSnUvqIew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631544998101825.4539958404208; Mon, 13 Sep 2021 07:56:38 -0700 (PDT) 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-592-t6d211eYPD-daaETxfx98g-1; Mon, 13 Sep 2021 10:56:35 -0400 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 1007D18A0760; Mon, 13 Sep 2021 14:56:30 +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 E5ACF5C1D1; Mon, 13 Sep 2021 14:56: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 B74D21800B89; Mon, 13 Sep 2021 14:56:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEquSc021089 for ; Mon, 13 Sep 2021 10:52:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id C2DF4188E4; Mon, 13 Sep 2021 14:52:56 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25AD96A908; Mon, 13 Sep 2021 14:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544997; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=HMAz/OmOqtnM7fF7OHCIa//4pROujjvCVI4WA/m77QQ=; b=RgGwT583JPvrfiSNvzI3NOUjFHx99G1VA02++47HMRCjJx5svnF1bASX1tqw2f/NRBfn3W sqCtcWigeA7OF3NrtGGUAASeJX61KK0TkLBJsWQIaxtuwb2h42u+r11loSduTsW1TdSSKL XfXZKMJGU5D9/y8edNnIWSLr8AO7+4o= X-MC-Unique: t6d211eYPD-daaETxfx98g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 01/16] virhostmem: Introduce virHostMemGetTHPSize() Date: Mon, 13 Sep 2021 16:52:29 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544999487100001 Content-Type: text/plain; charset="utf-8" New virHostMemGetTHPSize() is introduced which allows caller to obtain THP PMD (Page Middle Directory) size, which is equal to the minimal size that THP can use, taken from kernel doc (Documentation/admin-guide/mm/transhuge.rst): Some userspace (such as a test program, or an optimized memory allocation library) may want to know the size (in bytes) of a transparent hugepage:: cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size Since this size depends on the host architecture and the kernel it won't change whilst libvirtd is running. Therefore, we can use virOnce() and cache the value. Of course, we can be running under kernel that has THP disabled or has no notion of THP at all. In that case a negative value is returned to signal error. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virhostmem.c | 54 ++++++++++++++++++++++++++++++++++++++++ src/util/virhostmem.h | 3 +++ tests/domaincapsmock.c | 9 +++++++ 4 files changed, 67 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2778fe7f8f..d42d3abcce 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2408,6 +2408,7 @@ virHostMemGetFreePages; virHostMemGetInfo; virHostMemGetParameters; virHostMemGetStats; +virHostMemGetTHPSize; virHostMemSetParameters; =20 =20 diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index b13c3fe38e..5984dfab3f 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -45,11 +45,14 @@ #include "virstring.h" #include "virnuma.h" #include "virlog.h" +#include "virthread.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("util.hostmem"); =20 +static unsigned long long virHostTHPPMDSize; /* in kibibytes */ +static virOnceControl virHostMemGetTHPSizeOnce =3D VIR_ONCE_CONTROL_INITIA= LIZER; =20 #ifdef __FreeBSD__ # define BSD_MEMORY_STATS_ALL 4 @@ -930,3 +933,54 @@ virHostMemAllocPages(unsigned int npages, =20 return ncounts; } + +#if defined(__linux__) +# define HPAGE_PMD_SIZE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pm= d_size" +static void +virHostMemGetTHPSizeSysfs(unsigned long long *size) +{ + if (virFileReadValueUllong(size, "%s", HPAGE_PMD_SIZE_PATH) < 0) { + VIR_WARN("unable to get THP PMD size: %s", g_strerror(errno)); + return; + } + + /* Size is now in bytes. Convert to KiB. */ + *size >>=3D 10; +} +#endif /* defined(__linux__) */ + + +static void +virHostMemGetTHPSizeOnceInit(void) +{ +#if defined(__linux__) + virHostMemGetTHPSizeSysfs(&virHostTHPPMDSize); +#else /* !defined(__linux__) */ + VIR_WARN("Getting THP size not ported yet"); +#endif /* !defined(__linux__) */ +} + + +/** + * virHostMemGetTHPSize: + * @size: returned size of THP in kibibytes + * + * Obtain Transparent Huge Page size in kibibytes. The size + * depends on host architecture and kernel. Because of virOnce(), + * do not rely on errno in case of failure. + * + * Returns: 0 on success, + * -1 on failure. + */ +int +virHostMemGetTHPSize(unsigned long long *size) +{ + if (virOnce(&virHostMemGetTHPSizeOnce, virHostMemGetTHPSizeOnceInit) <= 0) + return -1; + + if (virHostTHPPMDSize =3D=3D 0) + return -1; + + *size =3D virHostTHPPMDSize; + return 0; +} diff --git a/src/util/virhostmem.h b/src/util/virhostmem.h index 3265215d84..c36de94f0f 100644 --- a/src/util/virhostmem.h +++ b/src/util/virhostmem.h @@ -55,3 +55,6 @@ int virHostMemAllocPages(unsigned int npages, unsigned int cellCount, int lastCell, bool add); + +int virHostMemGetTHPSize(unsigned long long *size) + G_GNUC_NO_INLINE; diff --git a/tests/domaincapsmock.c b/tests/domaincapsmock.c index 0a6c541f77..d382d06e27 100644 --- a/tests/domaincapsmock.c +++ b/tests/domaincapsmock.c @@ -17,6 +17,7 @@ #include =20 #include "virhostcpu.h" +#include "virhostmem.h" =20 #if WITH_QEMU # include "virmock.h" @@ -51,3 +52,11 @@ virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCa= ps) return real_virQEMUCapsGetKVMSupportsSecureGuest(qemuCaps); } #endif + +int +virHostMemGetTHPSize(unsigned long long *size) +{ + /* Pretend Transparent Huge Page size is 2MiB. */ + *size =3D 2048; + return 0; +} --=20 2.32.0 From nobody Fri Apr 26 17:27:02 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=1631544883; cv=none; d=zohomail.com; s=zohoarc; b=cLyErsP3PZ+h47i/I15g1GcOpwc50kHzOQcELa/LSAKR80I1/MN4UWfeM7aOz/2MXBXUl4qlYzYf3j+t4M3mLIJzG5r7YKO4c1VnhiReVy4NfzQWnDZJuvXHcIT1QG1OhWD4fz6x9OnNiTXD49Iy0DLCzRpyzlRr6JvCZZ2q5dk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544883; h=Content-Type:Content-Transfer-Encoding:Cc: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=ASHA8BvGRdIkjum0A6jO/cjd/zJGXmyOfKmhjksIaOc=; b=MggkFUQ7uyOdMf/F6bmgAZ20pnJImPwgXHqWjBoDrWC8i8mm7rFyJCdUwClhoISrM7fds4gRw9mth3G1oHBNpajuaxRVN3H9mMDb7V1mE3AIL58+05gNJiuDpKnjcHFvtM9UaW9sia3o4dFRVSmlzDqWTGNIigIGPc8/ObtQ+GU= 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) 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 1631544883437430.16765343226325; Mon, 13 Sep 2021 07:54:43 -0700 (PDT) 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-229-ydrrr0bgN9SzebdeDdHcrg-1; Mon, 13 Sep 2021 10:54:29 -0400 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 21F42101520F; Mon, 13 Sep 2021 14:54:24 +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 F2F005D9D3; Mon, 13 Sep 2021 14:54: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 9500A4EA29; Mon, 13 Sep 2021 14:54:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEqvTY021098 for ; Mon, 13 Sep 2021 10:52:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id B7467188E4; Mon, 13 Sep 2021 14:52:57 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A8916A8F8; Mon, 13 Sep 2021 14:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544882; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=ASHA8BvGRdIkjum0A6jO/cjd/zJGXmyOfKmhjksIaOc=; b=dFmgLBeLhCU9zBvTXeUULCBfwGdTm9c/aeRu1usBhqzWmGrwr+ZoEv+2wCVEIbTD/wWP3t w4n0FPhI7DSwUrjW+5sh/LkRagD+87bqmxk8x2YbNNSTUJtyZvhk+qIXlj+DMpnzc1+Kyy vJmBg2Z7JX5elCzfaLLWsTxFr5DbVFg= X-MC-Unique: ydrrr0bgN9SzebdeDdHcrg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 02/16] qemu_capabilities: Introduce QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI Date: Mon, 13 Sep 2021 16:52:30 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544885568100001 Content-Type: text/plain; charset="utf-8" This commit introduces a new capability that reflects virtio-mem-pci device support in QEMU: QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ The virtio-mem-pci device was introduced in QEMU 5.1. Signed-off-by: Michal Privoznik --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml | 1 + 6 files changed, 7 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f27a621f8c..711dc2f248 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -638,6 +638,7 @@ VIR_ENUM_IMPL(virQEMUCaps, "query-display-options", /* QEMU_CAPS_QUERY_DISPLAY_OPTIONS = */ "s390-pv-guest", /* QEMU_CAPS_S390_PV_GUEST */ "set-action", /* QEMU_CAPS_SET_ACTION */ + "virtio-mem-pci", /* QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI */ ); =20 =20 @@ -1354,6 +1355,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[= ] =3D { { "virtio-gpu-gl-pci", QEMU_CAPS_VIRTIO_GPU_GL_PCI }, { "virtio-vga-gl", QEMU_CAPS_VIRTIO_VGA_GL }, { "s390-pv-guest", QEMU_CAPS_S390_PV_GUEST }, + { "virtio-mem-pci", QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI }, }; =20 =20 diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f3379f556c..1e88591975 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -618,6 +618,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_QUERY_DISPLAY_OPTIONS, /* 'query-display-options' qmp comman= d present */ QEMU_CAPS_S390_PV_GUEST, /* -object s390-pv-guest,... */ QEMU_CAPS_SET_ACTION, /* 'set-action' QMP command */ + QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_5.1.0.x86_64.xml index fc0b502ef9..ff984afaa4 100644 --- a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml @@ -245,6 +245,7 @@ + 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 cb1226fc04..1d6ac320b3 100644 --- a/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml @@ -246,6 +246,7 @@ + 5002000 0 43100243 diff --git a/tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_6.0.0.x86_64.xml index d03b8aa726..8be83614ad 100644 --- a/tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml @@ -254,6 +254,7 @@ + 6000000 0 43100242 diff --git a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_6.1.0.x86_64.xml index 8239f4266a..20ec221deb 100644 --- a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml @@ -256,6 +256,7 @@ + 6001000 0 43100243 --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631544906; cv=none; d=zohomail.com; s=zohoarc; b=LpekWfRbo+RJ8y0cyMrKqcH3xK0S0Lkv2g46/bIZnU0LDPTwaVopJa9eydH9OYIZDIHIZDanjDLq+RZ3QC5ZjPnzZUxxAs90RoUINAoOEJz3PPsludwxmubzEUOyM0TAhMqRKaI939w/B0OgBBV2L3O148ZLEs1ezpXT6hxT0bc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544906; h=Content-Type:Content-Transfer-Encoding:Cc: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=kJJX5GqI+Nsbj+iWYcBboOb+0o69mFVLRi4fMEMCTYw=; b=A0jqwUmcOYPS4c/t1ibOxxSXh+kEFeXcBm8BtsU7liDnspvJcxXqj0ILx9j9RthDPjpzxNZcG5BUOhgr52JHcoFXa0Ewuz8XOZFBkWR8DBIEE1SlzvT0O8IMX4aWVFCSghDEWVllwK3c8cGYDuZDir48jkW+zLrpQ7p2K69HR3E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631544906443544.7311694188303; Mon, 13 Sep 2021 07:55:06 -0700 (PDT) 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-6tEClpGhOhC10qnMXUUKTQ-1; Mon, 13 Sep 2021 10:54:58 -0400 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 1B3456125E; Mon, 13 Sep 2021 14:54:53 +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 EC62D1017CE6; Mon, 13 Sep 2021 14:54:52 +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 BA7A11800FE4; Mon, 13 Sep 2021 14:54:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEqwav021106 for ; Mon, 13 Sep 2021 10:52:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id AAD1769324; Mon, 13 Sep 2021 14:52:58 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EC70188E4; Mon, 13 Sep 2021 14:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544905; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=kJJX5GqI+Nsbj+iWYcBboOb+0o69mFVLRi4fMEMCTYw=; b=M0uFalnFllMepYxN0kZ5ZZmptcgNjZkBqEITXL3PRZ2iofpeZMlOFeqrwMPxxRxekldEFA yUqqJ+2bB0afcGs31XAkcz4p9DnIs4IEkdK8wPZpMC3MnjcWoqfAapUMYX5eRAdmWciTYl 1Ru3PEzC4vvgAzFkcJHSIz7PgsJ11tY= X-MC-Unique: 6tEClpGhOhC10qnMXUUKTQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 03/16] qemu_capabilities: Introduce QEMU_CAPS_MEMORY_BACKEND_RESERVE Date: Mon, 13 Sep 2021 16:52:31 +0200 Message-Id: <30487c15591683f5a706c7d5b63afbd2913ff726.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544908203100003 Content-Type: text/plain; charset="utf-8" This capability tracks whether memory-backend-* supports .reserve attribute which is going to be important for backends associated with virtio-mem devices. Signed-off-by: Michal Privoznik --- src/qemu/qemu_capabilities.c | 4 ++++ src/qemu/qemu_capabilities.h | 3 +++ tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml | 1 + 3 files changed, 8 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 711dc2f248..f92ef069d1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -639,6 +639,9 @@ VIR_ENUM_IMPL(virQEMUCaps, "s390-pv-guest", /* QEMU_CAPS_S390_PV_GUEST */ "set-action", /* QEMU_CAPS_SET_ACTION */ "virtio-mem-pci", /* QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI */ + + /* 410 */ + "memory-backend-file.reserve", /* QEMU_CAPS_MEMORY_BACKEND_R= ESERVE */ ); =20 =20 @@ -1719,6 +1722,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsObjec= tPropsMemoryBackendFile[] =3D * supported. The 'x-' prefix was kept for compatibility with already * released qemu versions. */ { "x-use-canonical-path-for-ramblock-id", QEMU_CAPS_X_USE_CANONICAL_PA= TH_FOR_RAMBLOCK_ID }, + { "reserve", QEMU_CAPS_MEMORY_BACKEND_RESERVE }, }; =20 static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsMemoryBackendMe= mfd[] =3D { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 1e88591975..79a7df4f7d 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -620,6 +620,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_SET_ACTION, /* 'set-action' QMP command */ QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ =20 + /* 410 */ + QEMU_CAPS_MEMORY_BACKEND_RESERVE, /* -object memory-backend-*.reserve= =3D */ + QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; =20 diff --git a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_6.1.0.x86_64.xml index 20ec221deb..ba4b65f04d 100644 --- a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml @@ -257,6 +257,7 @@ + 6001000 0 43100243 --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631545061; cv=none; d=zohomail.com; s=zohoarc; b=N9UeUt9juyMG4P8JaVFlPnHwceHARWv3azAxi1OQijoMtyMZmGrTCX/DWUEKpHTXIW3M6jtLu1m+grmIPQU/E36U1+lZ9D40blAltkflq+HGi6q5N8hZZ/NFx+rNdrCTuHBy93512snxbmVumci2DZtuhYQMpP2Vygn+B6oSOaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631545061; h=Content-Type:Content-Transfer-Encoding:Cc: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=kkC9fNrRp3CbXvEhothPok/bwvy8pZE151wHpCwZeWI=; b=WOQBKptbwiC/jZ2nqTRLVCDjob2t/DOIFPWIgEjwqygWUW/AFDhNbtBWrYKzgslMNG0OpvLGGVadisseL6tkkfKM1JEyY1Jf5poE+rf1sMjnBouqx1Wg+4MV4DMI6/uUY9tDqBdFAkKAFW3QGtRTtCEwiacxBXCI5BOrkidrrPc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631545061675975.2141300509705; Mon, 13 Sep 2021 07:57:41 -0700 (PDT) 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-446-ZhzGZywYPHu-xaDnIcEB6w-1; Mon, 13 Sep 2021 10:56:39 -0400 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 829548030AF; Mon, 13 Sep 2021 14:56:34 +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 5B0901972E; Mon, 13 Sep 2021 14:56:34 +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 2CB961800B9E; Mon, 13 Sep 2021 14:56:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEqxdg021111 for ; Mon, 13 Sep 2021 10:52:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id C5790188E4; Mon, 13 Sep 2021 14:52:59 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 023546A8F5; Mon, 13 Sep 2021 14:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631545060; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=kkC9fNrRp3CbXvEhothPok/bwvy8pZE151wHpCwZeWI=; b=UobNf/EfKXXBcuwRTxbiSpoym6YI0poNac6FfCr0o4FeFgRzYEMVXisIIcO7qMu07SfG5n HVa1mhBVCz3FsK1mQeha7ePkGUo4CBN8UuzUVMX0MMiPYyT1xQfZO/atmgJw8+0bsG5JOo DpHBhmY+OERzXFOtlWGb+ZVc5Fr3gng= X-MC-Unique: ZhzGZywYPHu-xaDnIcEB6w-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 04/16] conf: Introduce virtio-mem model Date: Mon, 13 Sep 2021 16:52:32 +0200 Message-Id: <59adbec610170e6ffb180639dec738c2513e0c90.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631545063194100001 Content-Type: text/plain; charset="utf-8" The virtio-mem is paravirtualized mechanism of adding/removing memory to/from a VM. A virtio-mem-pci device is split into blocks of equal size which are then exposed (all or only a requested portion of them) to the guest kernel to use as regular memory. Therefore, the device has two important attributes: 1) block-size, which defines the size of a block 2) requested-size, which defines how much memory (in bytes) is the device requested to expose to the guest. The 'block-size' is configured on command line and immutable throughout device's lifetime. The 'requested-size' can be set on the command line too, but also is adjustable via monitor. In fact, that is how management software places its requests to change the memory allocation. If it wants to give more memory to the guest it changes 'requested-size' to a bigger value, and if it wants to shrink guest memory it changes the 'requested-size' to a smaller value. Note, value of zero means that guest should release all memory offered by the device. Of course, guest has to cooperate. Therefore, there is a third attribute 'size' which is read only and reflects how much memory the guest still has. This can be different to 'requested-size', obviously. Because of name clash, I've named it 'current' and it is dealt with in future commits (it is a runtime information anyway). In the backend, memory for virtio-mem is backed by usual objects: memory-backend-{ram,file,memfd} and their size puts the cap on the amount of memory that a virtio-mem device can offer to a guest. But we are already able to express this info using under . Therefore, we need only two more elements to cover 'block-size' and 'requested-size' attributes. This is the XML I've came up with: 1-3 2048 2097152 0 2048 1048576
I hope by now it is obvious that: 1) 'requested-size' must be an integer multiple of 'block-size', and 2) virtio-mem-pci device goes onto PCI bus and thus needs PCI address. Then there is a limitation that the minimal 'block-size' is transparent huge page size (I'll leave this without explanation). Signed-off-by: Michal Privoznik --- docs/formatdomain.rst | 38 +++++++++-- docs/schemas/domaincommon.rng | 11 +++ src/conf/domain_conf.c | 53 ++++++++++++++- src/conf/domain_conf.h | 3 + src/conf/domain_validate.c | 39 +++++++++++ src/qemu/qemu_alias.c | 1 + src/qemu/qemu_command.c | 1 + src/qemu/qemu_domain.c | 10 +++ src/qemu/qemu_domain_address.c | 38 ++++++++--- src/qemu/qemu_process.c | 2 + src/qemu/qemu_validate.c | 8 +++ src/security/security_apparmor.c | 1 + src/security/security_dac.c | 2 + src/security/security_selinux.c | 2 + .../memory-hotplug-virtio-mem.xml | 67 +++++++++++++++++++ ...emory-hotplug-virtio-mem.x86_64-latest.xml | 1 + tests/qemuxml2xmltest.c | 1 + 17 files changed, 261 insertions(+), 17 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 9173d9f1d6..c327e1deae 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7790,6 +7790,18 @@ Example: usage of the memory devices 524288 + + + 1-3 + 2048 + + + 2097152 + 0 + 2048 + 1048576 + + ... =20 @@ -7797,7 +7809,8 @@ Example: usage of the memory devices Provide ``dimm`` to add a virtual DIMM module to the guest. :since:`Sin= ce 1.2.14` Provide ``nvdimm`` model that adds a Non-Volatile DIMM module. :since:`Since 3.2.0` Provide ``virtio-pmem`` model to add a paravirtual= ized - persistent memory device. :since:`Since 7.1.0` + persistent memory device. :since:`Since 7.1.0` Provide ``virtio-mem`` m= odel + to add paravirtualized memory device. :since:`Since 7.4.0` =20 ``access`` An optional attribute ``access`` ( :since:`since 3.2.0` ) that provides @@ -7820,10 +7833,11 @@ Example: usage of the memory devices allowed only for ``model=3D'nvdimm'`` for pSeries guests. :since:`Since= 6.2.0` =20 ``source`` - For model ``dimm`` this element is optional and allows to fine tune the - source of the memory used for the given memory device. If the element i= s not - provided defaults configured via ``numatune`` are used. If ``dimm`` is - provided, then the following optional elements can be provided as well: + For model ``dimm`` and model ``virtio-mem`` this element is optional and + allows to fine tune the source of the memory used for the given memory + device. If the element is not provided defaults configured via ``numatu= ne`` + are used. If the element is provided, then the following optional eleme= nts + can be provided: =20 ``pagesize`` This element can be used to override the default host page size used= for @@ -7862,7 +7876,8 @@ Example: usage of the memory devices added memory from the perspective of the guest. =20 The mandatory ``size`` subelement configures the size of the added memo= ry as - a scaled integer. + a scaled integer. For ``virtio-mem`` this represents the maximum possib= le + size exposed to the guest. =20 The ``node`` subelement configures the guest NUMA node to attach the me= mory to. The element shall be used only if the guest has NUMA nodes configur= ed. @@ -7889,6 +7904,17 @@ Example: usage of the memory devices so other backend types should use the ``readonly`` element. :since:`= Since 5.0.0` =20 + ``block`` + For ``virtio-mem`` only. + The size of an individual block, granularity of division of memory bl= ock. + Must be power of two and at least equal to size of a transparent huge= page + (2MiB on x84_64). The default is hypervisor dependent. + + ``requested`` + For ``virtio-mem`` only. + The total size exposed to the guest. Must respect ``block`` granulari= ty + and be smaller than or equal to ``size``. + :anchor:`` =20 IOMMU devices diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 11fa24f398..82fdc7c8b5 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6595,6 +6595,7 @@ dimm nvdimm virtio-pmem + virtio-mem @@ -6682,6 +6683,16 @@ + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 858f6f923a..c4cac65a7b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1392,6 +1392,7 @@ VIR_ENUM_IMPL(virDomainMemoryModel, "dimm", "nvdimm", "virtio-pmem", + "virtio-mem", ); =20 VIR_ENUM_IMPL(virDomainShmemModel, @@ -5494,6 +5495,7 @@ virDomainMemoryDefPostParse(virDomainMemoryDef *mem, } break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: @@ -14650,6 +14652,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, =20 switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (virDomainParseMemory("./pagesize", "./pagesize/@unit", ctxt, &def->pagesize, false, false) < 0) return -1; @@ -14716,7 +14719,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; @@ -14735,6 +14739,23 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, =20 if (virXPathBoolean("boolean(./readonly)", ctxt)) def->readonly =3D true; + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (virDomainParseMemory("./block", "./block/@unit", ctxt, + &def->blocksize, false, false) < 0) + return -1; + + if (virDomainParseMemory("./requested", "./requested/@unit", ctxt, + &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_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; } =20 return 0; @@ -16491,11 +16512,14 @@ virDomainMemoryFindByDefInternal(virDomainDef *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) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: /* source stuff -> match with device */ if (tmp->pagesize !=3D mem->pagesize) continue; @@ -21875,6 +21899,22 @@ virDomainMemoryDefCheckABIStability(virDomainMemor= yDef *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; + } + if (src->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { if (src->labelsize !=3D dst->labelsize) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -25780,6 +25820,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf, =20 switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (def->sourceNodes) { if (!(bitmap =3D virBitmapFormat(def->sourceNodes))) return -1; @@ -25836,6 +25877,14 @@ virDomainMemoryTargetDefFormat(virBuffer *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 c7e6df7981..3bdfb66a16 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2472,6 +2472,7 @@ typedef enum { VIR_DOMAIN_MEMORY_MODEL_DIMM, /* dimm hotpluggable memory device */ VIR_DOMAIN_MEMORY_MODEL_NVDIMM, /* nvdimm memory device */ VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM, /* virtio-pmem memory device */ + VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM, /* virtio-mem memory device */ =20 VIR_DOMAIN_MEMORY_MODEL_LAST } virDomainMemoryModel; @@ -2492,6 +2493,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 only for VIRTIO_MEM = */ + unsigned long long requestedsize; /* kibibytes; valid only for VIRTIO_= MEM */ bool readonly; /* valid only for NVDIMM */ =20 /* required for QEMU NVDIMM ppc64 support */ diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 1bc62c364d..f023d22f23 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -28,6 +28,7 @@ #include "virlog.h" #include "virutil.h" #include "virstring.h" +#include "virhostmem.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -1966,6 +1967,8 @@ static int virDomainMemoryDefValidate(const virDomainMemoryDef *mem, const virDomainDef *def) { + unsigned long long thpSize; + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (!mem->nvdimmPath) { @@ -2019,6 +2022,42 @@ virDomainMemoryDefValidate(const virDomainMemoryDef = *mem, _("virtio-pmem does not support NUMA nodes")); return -1; } + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (mem->requestedsize > mem->size) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("requested size must be smaller than or equal= to @size")); + 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 (virHostMemGetTHPSize(&thpSize) < 0) { + /* We failed to get THP size, fall back to a sane default. On + * almost every architecture the size will be 2MiB, except for= some + * funky arches like sparc and m68k. Use 2MiB and refine later= if + * somebody complains. */ + thpSize =3D 2048; + } + + if (mem->blocksize < thpSize) { + virReportError(VIR_ERR_XML_DETAIL, + _("block size too small, must be at least %lluK= iB"), + thpSize); + return -1; + } + + if (mem->requestedsize % mem->blocksize !=3D 0) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("requested size must be an integer multiple o= f block size")); + return -1; + } + break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: break; diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index ed47fa335a..79e8953b2f 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -522,6 +522,7 @@ qemuAssignDeviceMemoryAlias(virDomainDef *def, case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: prefix =3D "virtiopmem"; break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4d29313f45..594e5643b1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3317,6 +3317,7 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, device =3D "virtio-pmem-pci"; break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5de7461fb3..298f9b076d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9038,6 +9038,16 @@ qemuDomainDefValidateMemoryHotplugDevice(const virDo= mainMemoryDef *mem, needsNuma =3D false; break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + 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, + _("only 'pci' addresses are supported for the %= s device"), + virDomainMemoryModelTypeToString(mem->model)); + return -1; + } + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: return -1; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 392368bd38..c43ad23cf5 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -380,9 +380,18 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDef *def, } =20 for (i =3D 0; i < def->nmems; i++) { - if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM= && - def->mems[i]->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_= NONE) - def->mems[i]->info.type =3D type; + switch (def->mems[i]->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (def->mems[i]->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_T= YPE_NONE) + def->mems[i]->info.type =3D type; + 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: + break; + } } =20 if (type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) { @@ -1010,6 +1019,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDev= iceDef *dev, case VIR_DOMAIN_DEVICE_MEMORY: switch (dev->data.memory->model) { case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: return virtioFlags; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -2370,12 +2380,19 @@ qemuDomainAssignDevicePCISlots(virDomainDef *def, for (i =3D 0; i < def->nmems; i++) { virDomainMemoryDef *mem =3D def->mems[i]; =20 - if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM || - !virDeviceInfoPCIAddressIsWanted(&mem->info)) - continue; - - if (qemuDomainPCIAddressReserveNextAddr(addrs, &mem->info) < 0) - return -1; + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (virDeviceInfoPCIAddressIsWanted(&mem->info) && + qemuDomainPCIAddressReserveNextAddr(addrs, &mem->info) < 0) + return -1; + 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: + break; + } } =20 return 0; @@ -3034,6 +3051,7 @@ qemuDomainAssignMemoryDeviceSlot(virQEMUDriver *drive= r, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: return qemuDomainEnsurePCIAddress(vm, &dev, driver); break; =20 @@ -3059,6 +3077,7 @@ qemuDomainReleaseMemoryDeviceSlot(virDomainObj *vm, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: qemuDomainReleaseDeviceAddress(vm, &mem->info); break; =20 @@ -3093,6 +3112,7 @@ qemuDomainAssignMemorySlots(virDomainDef *def) break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: /* handled in qemuDomainAssignPCIAddresses() */ break; case VIR_DOMAIN_MEMORY_MODEL_NONE: diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 632cb817b9..07bd7e928a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3791,6 +3791,7 @@ qemuProcessDomainMemoryDefNeedHugepagesPath(const vir= DomainMemoryDef *mem, { switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: return mem->pagesize && mem->pagesize !=3D system_pagesize; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -3859,6 +3860,7 @@ qemuProcessNeedMemoryBackingPath(virDomainDef *def, if (mem) { switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (mem->access !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) { /* No need to check for access mode on the target node, * it was checked for in the previous loop. */ diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 9d93f373ab..5eaa6fa5ac 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4993,6 +4993,14 @@ qemuValidateDomainDeviceDefMemory(virDomainMemoryDef= *mem, } break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio-mem isn't supported by this QEMU bina= ry")); + return -1; + } + break; + 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 d942ea5005..2cc15ba6af 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -693,6 +693,7 @@ AppArmorSetMemoryLabel(virSecurityManager *mgr, return reload_profile(mgr, def, mem->nvdimmPath, true); case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 04b9ecf028..1733d63410 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1849,6 +1849,7 @@ virSecurityDACRestoreMemoryLabel(virSecurityManager *= mgr, break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: ret =3D 0; @@ -2033,6 +2034,7 @@ virSecurityDACSetMemoryLabel(virSecurityManager *mgr, break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: ret =3D 0; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 0e5ea0366d..cc72453329 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1582,6 +1582,7 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManager *= mgr, =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } @@ -1609,6 +1610,7 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityManag= er *mgr, break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: ret =3D 0; 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..c10528aad8 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml @@ -0,0 +1,67 @@ + + 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 + +
+ + + 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 6d3526f91f..ccefef3a5c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1214,6 +1214,7 @@ mymain(void) QEMU_CAPS_DEVICE_NVDIMM, QEMU_CAPS_LAST, ARG_END); DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-mem"); =20 DO_TEST_NOCAPS("net-udp"); =20 --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631544904; cv=none; d=zohomail.com; s=zohoarc; b=n+uMvlVx0Ru0kHHxlalV4C+GW3bKtBkQeRRV1Oqv17sHYUDXnx6WAegA/zRdpitnVIvObtnziVI9PGWKGEwl4RHETyISA2mZ+N2Xx8vHzSdezIDpkkkfsvgtbQ8lGf3Gs5ZnTQyNfPdr3noFFgFwnAPNx+2rCtytobBIbs61pto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544904; h=Content-Type:Content-Transfer-Encoding:Cc: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=Fnoz82RDMAK214X882QGdK9bnWrNLye8o8JYmKjgWw8=; b=GtJJuqcu++CMtY371FXU6IL5FIJOFsRFi1teGqKuaa3kLqrMsCFbOSpekdGwsgy1qR++G6gjnG8r0r8PHPitRCh8rt+wzIEGX+/SOecoM1MBUDe18NZtYUsveplsKFy6e9bjcyRSPVRNs7kWnzbOpYfwkqaTWD20wLYc7UxHVmQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16315449047794.514409087602189; Mon, 13 Sep 2021 07:55:04 -0700 (PDT) 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-488-H0sfxBNtNsO8ckGBvW8dtg-1; Mon, 13 Sep 2021 10:55:01 -0400 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 29DC3824FAD; Mon, 13 Sep 2021 14:54:56 +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 07FA460C9F; Mon, 13 Sep 2021 14:54: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 CC0691806D03; Mon, 13 Sep 2021 14:54:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEr0dV021131 for ; Mon, 13 Sep 2021 10:53:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id B974B69324; Mon, 13 Sep 2021 14:53:00 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CEA4188E4; Mon, 13 Sep 2021 14:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544903; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Fnoz82RDMAK214X882QGdK9bnWrNLye8o8JYmKjgWw8=; b=WvZSkiw7kCZrNuY3GvOzc+iyRtK5+swbJhHxS4QJmLQlzK28eH8E4Mps/jTzBQ+h4uKh54 0E4NKnhcZF3Cpdv52FQRlXS/r139tpvV6zfKjFVWlo2QSZfuTCYv3fkaHKQbNRM1czU3B9 aRs26FNWfs+DaukwekomwnJthbItegE= X-MC-Unique: H0sfxBNtNsO8ckGBvW8dtg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 05/16] qemu: Build command line for virtio-mem Date: Mon, 13 Sep 2021 16:52:33 +0200 Message-Id: <407f2fa93a3919a77740fabf979f22ad257b837f.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544906159100001 Content-Type: text/plain; charset="utf-8" Nothing special is happening here. All important changes were done when for 'virtio-pmem' (adjusting the code to put virtio memory on PCI bus, generating alias using qemuDomainDeviceAliasIndex(). The only bit that might look suspicious is no prealloc for virtio-mem. But if you think about it, the whole purpose of this device is to change amount of memory exposed to guest on the fly. There is no point in locking the whole backend in memory. Signed-off-by: Michal Privoznik --- src/qemu/qemu_alias.c | 9 +++- src/qemu/qemu_command.c | 24 +++++++++-- ...mory-hotplug-virtio-mem.x86_64-latest.args | 41 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 70 insertions(+), 5 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 79e8953b2f..81a1e7eeed 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -475,8 +475,11 @@ qemuDeviceMemoryGetAliasID(virDomainDef *def, size_t i; int maxidx =3D 0; =20 - /* virtio-pmem goes onto PCI bus and thus DIMM address is not valid */ - if (!oldAlias && mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM) + /* virtio-pmem and virtio-mem go onto PCI bus and thus DIMM address is= not + * valid */ + if (!oldAlias && + mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM && + mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) return mem->info.addr.dimm.slot; =20 for (i =3D 0; i < def->nmems; i++) { @@ -523,6 +526,8 @@ qemuAssignDeviceMemoryAlias(virDomainDef *def, prefix =3D "virtiopmem"; break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + prefix =3D "virtiomem"; + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 594e5643b1..91f3094ac8 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3136,9 +3136,19 @@ qemuBuildMemoryBackendProps(virJSONValue **backendPr= ops, virJSONValueObjectAdd(props, "b:x-use-canonical-path-for-ramblock-= id", false, NULL) < 0) return -1; =20 - if (!priv->memPrealloc && - virJSONValueObjectAdd(props, "B:prealloc", prealloc, NULL) < 0) - return -1; + if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) { + /* Explicitly disable prealloc for virtio-mem */ + if (priv->memPrealloc && + virJSONValueObjectAppendBoolean(props, "prealloc", 0) < 0) + return -1; + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MEMORY_BACKEND_RESERV= E) && + virJSONValueObjectAppendBoolean(props, "reserve", 0) < 0) + return -1; + } else { + if (!priv->memPrealloc && + virJSONValueObjectAdd(props, "B:prealloc", prealloc, NULL) < 0) + return -1; + } =20 if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0) return -1; @@ -3318,6 +3328,9 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + device =3D "virtio-mem-pci"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: @@ -3334,6 +3347,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 (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..22ee1bc459 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args @@ -0,0 +1,41 @@ +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 \ +/usr/bin/qemu-system-i386 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tm= p/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 '{"qom-type":"memory-backend-ram","id":"ram-node0","size":21453864= 96}' \ +-numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dram-node0 \ +-object '{"qom-type":"memory-backend-ram","id":"memvirtiomem0","reserve":f= alse,"size":1073741824}' \ +-device virtio-mem-pci,node=3D0,block-size=3D2097152,requested-size=3D5368= 70912,memdev=3Dmemvirtiomem0,id=3Dvirtiomem0,bus=3Dpci.0,addr=3D0x2 \ +-object '{"qom-type":"memory-backend-file","id":"memvirtiomem1","mem-path"= :"/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1","reserve":false,"size":21474= 83648,"host-nodes":[1,2,3],"policy":"bind"}' \ +-device virtio-mem-pci,node=3D0,block-size=3D2097152,requested-size=3D1073= 741824,memdev=3Dmemvirtiomem1,id=3Dvirtiomem1,bus=3Dpci.0,addr=3D0x3 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-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","no= de-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 \ +-audiodev id=3Daudio1,driver=3Dnone \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x4 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 74af93b08f..23f4a8471f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3143,6 +3143,7 @@ mymain(void) ARG_END); DO_TEST_CAPS_VER("memory-hotplug-virtio-pmem", "5.2.0"); 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.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631544880; cv=none; d=zohomail.com; s=zohoarc; b=PXz94pSbVaMM4BPLCZewh0lp9HqalsEs6TnqSrsKVB+6efPJwL+mdeq2hkQPcUXBOGBLLohKENwm8f38pF2IQOppnIRxn35Zc8EPb3R6m84AvwpUYrGHtDxFIo1cFZDyGdV6/+aRJUfHoxG0RVIMZrWbRWJjUFbu1SFnQ25bHAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544880; h=Content-Type:Content-Transfer-Encoding:Cc: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=R5Ocif2BZPiWX4Ia21epYrL/t+U2P+1B57Hn/+8x0eU=; b=C851rWsKxIq4m/ppcdVrzmoNnrJv2y5qeHpYQZE4Cyr41HnrZgtxymX50rJ7lq5ZJDFKtcGjzfkeOPvq9OZ559TGdmPvQXuuv20wK9Zd2KYujllVQlQY7LHV4L8T0kuLII07cOUFKdITNeyCWb5u4JTcg8yn4Cihw6HfHvUQQNw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631544880220334.5550535749759; Mon, 13 Sep 2021 07:54:40 -0700 (PDT) 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-62-ouXj-VevPNijlnsLhODpwg-1; Mon, 13 Sep 2021 10:54:36 -0400 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 9DB8E8E4CD7; Mon, 13 Sep 2021 14:54:27 +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 823CF781EE; Mon, 13 Sep 2021 14:54:27 +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 50DAD4EA37; Mon, 13 Sep 2021 14:54:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEr1Ue021138 for ; Mon, 13 Sep 2021 10:53:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id ACE7769324; Mon, 13 Sep 2021 14:53:01 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10BE7188E4; Mon, 13 Sep 2021 14:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544879; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=R5Ocif2BZPiWX4Ia21epYrL/t+U2P+1B57Hn/+8x0eU=; b=H4jO1wrzCZO+ReRkkXBGYku666z3x2uZD0OWLjLIlJuxdfHHylNGZkI0MiLXITd2GXAucC TuXYnWK3SjGSfotqICn9GfNLnMP/75EfaEnFnMZArEpAaAmgjZJDC98JqRcAlajrMO6L00 Vv+JzwM4P1jP+o6+ne8XS/EeTD42NFc= X-MC-Unique: ouXj-VevPNijlnsLhODpwg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 06/16] qemu: Wire up live update Date: Mon, 13 Sep 2021 16:52:34 +0200 Message-Id: <21b42b9ae49cf5074cd8a3af675b3a843d5ff62b.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544881368100001 Content-Type: text/plain; charset="utf-8" As advertised in one of previous commits, 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. Once guest has changed the allocation, QEMU emits an event which we will use to track the allocation. In the next commit. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 47 +++++++++- src/conf/domain_conf.h | 5 + src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 174 ++++++++++++++++++++++++++++++++++- src/qemu/qemu_hotplug.c | 18 ++++ src/qemu/qemu_hotplug.h | 5 + src/qemu/qemu_monitor.c | 13 +++ src/qemu/qemu_monitor.h | 5 + src/qemu/qemu_monitor_json.c | 15 +++ src/qemu/qemu_monitor_json.h | 5 + 10 files changed, 286 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c4cac65a7b..9562065499 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16574,6 +16574,50 @@ virDomainMemoryFindInactiveByDef(virDomainDef *def, } =20 =20 +/** + * virDomainMemoryFindByDeviceInfo: + * @def: domain defintion + * @info: device info to match + * @pos: store position within array + * + * For given domain definition @def find device with + * matching address and matching device alias (if set in @info, + * otherwise ignored). + * + * If @pos is not NULL then the position of the matched device + * within the array is stored there. + * + * Returns: device if found, + * NULL otherwise. + */ +virDomainMemoryDef * +virDomainMemoryFindByDeviceInfo(virDomainDef *def, + virDomainDeviceInfo *info, + int *pos) +{ + size_t i; + + for (i =3D 0; i < def->nmems; i++) { + virDomainMemoryDef *tmp =3D def->mems[i]; + + if (!virDomainDeviceInfoAddressIsEqual(&tmp->info, info)) + continue; + + /* alias, if present */ + if (info->alias && + STRNEQ_NULLABLE(tmp->info.alias, info->alias)) + continue; + + if (pos) + *pos =3D i; + + return tmp; + } + + return NULL; +} + + /** * virDomainMemoryInsert: * @@ -28567,7 +28611,8 @@ virDomainDefCompatibleDevice(virDomainDef *def, return -1; } =20 - if ((virDomainDefGetMemoryTotal(def) + sz) > def->mem.max_memory) { + if (action =3D=3D VIR_DOMAIN_DEVICE_ACTION_ATTACH && + (virDomainDefGetMemoryTotal(def) + sz) > def->mem.max_memory) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Attaching memory device with size '%llu' wou= ld " "exceed domain's maxMemory config size '%llu'= "), diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3bdfb66a16..e9d8e0c7ae 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3806,6 +3806,11 @@ int virDomainMemoryFindByDef(virDomainDef *def, virD= omainMemoryDef *mem) int virDomainMemoryFindInactiveByDef(virDomainDef *def, virDomainMemoryDef *mem) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; +virDomainMemoryDef * +virDomainMemoryFindByDeviceInfo(virDomainDef *dev, + virDomainDeviceInfo *info, + int *pos) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 int virDomainShmemDefInsert(virDomainDef *def, virDomainShmemDef *shmem) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d42d3abcce..3f9035c25b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -508,6 +508,7 @@ virDomainMemballoonModelTypeFromString; virDomainMemballoonModelTypeToString; virDomainMemoryDefFree; virDomainMemoryFindByDef; +virDomainMemoryFindByDeviceInfo; virDomainMemoryFindInactiveByDef; virDomainMemoryInsert; virDomainMemoryModelTypeToString; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index dfc27572c4..d05052a3d7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7087,6 +7087,175 @@ qemuDomainChangeDiskLive(virDomainObj *vm, return 0; } =20 + +static bool +qemuDomainChangeMemoryLiveValidateChange(const virDomainMemoryDef *oldDef, + const virDomainMemoryDef *newDef) +{ + /* The only thing that is allowed to change is 'requestedsize' for + * virtio-mem model. Check if user isn't trying to sneak in change for + * something else. */ + + switch (oldDef->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory of model '%s'"), + virDomainMemoryModelTypeToString(oldDef->model)); + return false; + break; + } + + 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 (!virBitmapEqual(oldDef->sourceNodes, + newDef->sourceNodes)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory source nodes")); + return false; + } + + if (oldDef->pagesize !=3D newDef->pagesize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory pagesize from '%llu' to '%l= lu'"), + oldDef->pagesize, + newDef->pagesize); + return false; + } + + if (STRNEQ_NULLABLE(oldDef->nvdimmPath, newDef->nvdimmPath)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory path from '%s' to '%s'"), + NULLSTR(oldDef->nvdimmPath), + NULLSTR(newDef->nvdimmPath)); + return false; + } + + if (oldDef->alignsize !=3D newDef->alignsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory align size from '%llu' to '= %llu'"), + oldDef->alignsize, newDef->alignsize); + return false; + } + + if (oldDef->nvdimmPmem !=3D newDef->nvdimmPmem) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory pmem from '%d' to '%d'"), + oldDef->nvdimmPmem, newDef->nvdimmPmem); + 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->labelsize !=3D newDef->labelsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory label size from '%llu' to '= %llu'"), + oldDef->labelsize, newDef->labelsize); + 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 ((oldDef->uuid || newDef->uuid) && + !(oldDef->uuid && newDef->uuid && + memcmp(oldDef->uuid, newDef->uuid, VIR_UUID_BUFLEN) =3D=3D 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory UUID")); + return false; + } + + return true; +} + + +static int +qemuDomainChangeMemoryLive(virQEMUDriver *driver G_GNUC_UNUSED, + virDomainObj *vm, + virDomainDeviceDef *dev) +{ + virDomainDeviceDef oldDev =3D { .type =3D VIR_DOMAIN_DEVICE_MEMORY }; + virDomainMemoryDef *newDef =3D dev->data.memory; + virDomainMemoryDef *oldDef =3D NULL; + + oldDef =3D virDomainMemoryFindByDeviceInfo(vm->def, &dev->data.memory-= >info, NULL); + if (!oldDef) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory '%s' not found"), dev->data.memory->info.= alias); + return -1; + } + + oldDev.data.memory =3D oldDef; + + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDATE, + true) < 0) + 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(virDomainObj *vm, virDomainDeviceDef *dev, @@ -7128,6 +7297,10 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm, ret =3D qemuDomainChangeNet(driver, vm, dev); break; =20 + case VIR_DOMAIN_DEVICE_MEMORY: + ret =3D qemuDomainChangeMemoryLive(driver, vm, dev); + break; + case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: @@ -7143,7 +7316,6 @@ qemuDomainUpdateDeviceLive(virDomainObj *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 9c16ab4567..ccfd83cf66 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6800,3 +6800,21 @@ qemuDomainSetVcpuInternal(virQEMUDriver *driver, virBitmapFree(livevcpus); return ret; } + + +int +qemuDomainChangeMemoryRequestedSize(virQEMUDriver *driver, + virDomainObj *vm, + const char *alias, + unsigned long long requestedsize) +{ + qemuDomainObjPrivate *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 b5f7afb076..ae8feb459c 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -166,3 +166,8 @@ int qemuHotplugAttachDBusVMState(virQEMUDriver *driver, int qemuHotplugRemoveDBusVMState(virQEMUDriver *driver, virDomainObj *vm, qemuDomainAsyncJob asyncJob); + +int qemuDomainChangeMemoryRequestedSize(virQEMUDriver *driver, + virDomainObj *vm, + const char *alias, + unsigned long long requestedsize); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 42846349c4..24119ef66e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4625,3 +4625,16 @@ qemuMonitorSetAction(qemuMonitor *mon, =20 return qemuMonitorJSONSetAction(mon, shutdown, reboot, watchdog, panic= ); } + + +int +qemuMonitorChangeMemoryRequestedSize(qemuMonitor *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 2f08357c0c..0ebe73ac04 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1537,3 +1537,8 @@ qemuMonitorSetAction(qemuMonitor *mon, qemuMonitorActionReboot reboot, qemuMonitorActionWatchdog watchdog, qemuMonitorActionPanic panic); + +int +qemuMonitorChangeMemoryRequestedSize(qemuMonitor *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 8d3c4031a6..d5e95f3dda 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -9404,3 +9404,18 @@ qemuMonitorJSONSetAction(qemuMonitor *mon, =20 return 0; } + + +int +qemuMonitorJSONChangeMemoryRequestedSize(qemuMonitor *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 c8cf734a1c..0289f8c3bf 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -710,3 +710,8 @@ qemuMonitorJSONSetAction(qemuMonitor *mon, qemuMonitorActionReboot reboot, qemuMonitorActionWatchdog watchdog, qemuMonitorActionPanic panic); + +int +qemuMonitorJSONChangeMemoryRequestedSize(qemuMonitor *mon, + const char *alias, + unsigned long long requestedsize); --=20 2.32.0 From nobody Fri Apr 26 17:27:02 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=1631544909; cv=none; d=zohomail.com; s=zohoarc; b=HEkepKySbC0LZLHylks9n+48QyXLewB8l4LU5FnZPSQXGf/MRYDSJii/B3gbMmeZpjdIb2UN4aNCGOoN5tnZ+royu3xuG1I5NzFCzF2WI/xFIodQMV2HsXa+RXTWxIfL8HyQepDXnA0Dunb15UK1lPThXRNw0kNXX8pO0q2mdb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544909; h=Content-Type:Content-Transfer-Encoding:Cc: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=uSwztreATB3D8S0PffmpswsKnDReYCoaYdGHz54dYmo=; b=HwaInrdbABk3rEqBQKfFSMtBLwl67n2dh535RZNEk7tt3cD0+5I4dGaowJjLuAzgu6bEDRiItefttgOL2wvf5gGD54MegmZ/qyoUtLFhc5R30we8dV/pXBmdQQVR7nsO0kzMmv2A+DEcEEG/NZ2pSwBAw6ga34J8KueEA23jTlo= 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) 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 1631544909806219.89717529934137; Mon, 13 Sep 2021 07:55:09 -0700 (PDT) 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-523-rnOuuFQaN2ayw9m5UrL2dw-1; Mon, 13 Sep 2021 10:55:05 -0400 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 8AAF01922976; Mon, 13 Sep 2021 14:54: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 44F8D6D98C; Mon, 13 Sep 2021 14:54: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 F11C11805986; Mon, 13 Sep 2021 14:54:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEr2tk021144 for ; Mon, 13 Sep 2021 10:53:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id A06086A8F8; Mon, 13 Sep 2021 14:53:02 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04653188E4; Mon, 13 Sep 2021 14:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544908; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=uSwztreATB3D8S0PffmpswsKnDReYCoaYdGHz54dYmo=; b=VKDQ2U6AQblikq5lhWMZAH0516y9X3Earx4fAaN5+lUEePq+eheGKRr5/DX4YvZ9U3ndpV 37xtZUCNBAY3SiXw/KL/UYarUuCf9JeWCkEgXJeNbLCPpkz7p8NakjTn+anBVzyUTN09m3 2To/4qhtEhDFG4vsqJBLODLoyx0F3FY= X-MC-Unique: rnOuuFQaN2ayw9m5UrL2dw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 07/16] qemu: Wire up offline update Date: Mon, 13 Sep 2021 16:52:35 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544910748100001 Content-Type: text/plain; charset="utf-8" Updating offline XML of devices might come handy when dealing with virtio-mem devices. But it's implemented to just replace one virDomainMemoryDef with another so it can be used to change almost anything. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d05052a3d7..10ff8519c5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7764,6 +7764,7 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef, virDomainDiskDef *newDisk; virDomainGraphicsDef *newGraphics; virDomainNetDef *net; + virDomainMemoryDef *mem; virDomainDeviceDef oldDev =3D { .type =3D dev->type }; int pos; =20 @@ -7826,6 +7827,23 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef, dev->data.net =3D NULL; break; =20 + case VIR_DOMAIN_DEVICE_MEMORY: + mem =3D virDomainMemoryFindByDeviceInfo(vmdef, &dev->data.memory->= info, &pos); + if (!mem) { + virReportError(VIR_ERR_INVALID_ARG, "%s", _("memory not found"= )); + return -1; + } + + oldDev.data.memory =3D mem; + if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDATE, + false) < 0) + return -1; + + virDomainMemoryDefFree(vmdef->mems[pos]); + vmdef->mems[pos] =3D g_steal_pointer(&dev->data.memory); + break; + case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: @@ -7842,7 +7860,6 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef, case VIR_DOMAIN_DEVICE_CONTROLLER: case VIR_DOMAIN_DEVICE_REDIRDEV: case VIR_DOMAIN_DEVICE_CHR: - case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631545025; cv=none; d=zohomail.com; s=zohoarc; b=l6r1Z7W1tj5ClYGZ1LV1lTgS6GgFIgIzYWKUymeBcJW4FAMzmcLqz9EyQrwxgLzCN0C0te3h2FVH7nbTtgsu3HWRNlK7kIxjybwQU4d/AOo2/g1IYf1q/z+P84iwhRUGdUJGJ/7yGHvhbQOBtIs3RH4oDe2PvaJZhhdjq2XIplc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631545025; h=Content-Type:Content-Transfer-Encoding:Cc: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=H6khb8OenATRPPq0R5Xp7Uf+VlQ5QxYkqU0VbxU0js0=; b=AK41qcFbxMsBDMuvEy7bM+risCM8la7Vh4W8/0Zyp09TbRKolAOKgI7W8qdxNWKjjtvIfusVAAUS1PbxBtbJeSt2Pt2V+PrGurOmMYFYQSEB4H/N5wgrffaKz1Ycda3XXw643fEtEl4Zmkmi+zcx1j47pifuoWOoesjRDCA/f/o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631545025587465.84983946610726; Mon, 13 Sep 2021 07:57:05 -0700 (PDT) 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-4-MBKcxQNdPeOjNZvWvDtatg-1; Mon, 13 Sep 2021 10:56:45 -0400 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 39FA4101451B; Mon, 13 Sep 2021 14:56:37 +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 1C6C45C3E0; Mon, 13 Sep 2021 14:56:37 +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 E165F1805986; Mon, 13 Sep 2021 14:56:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEr64E021170 for ; Mon, 13 Sep 2021 10:53:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id DE518188E4; Mon, 13 Sep 2021 14:53:06 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4247D6A907; Mon, 13 Sep 2021 14:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631545024; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=H6khb8OenATRPPq0R5Xp7Uf+VlQ5QxYkqU0VbxU0js0=; b=Gr4JEr4iiTh/hiGxgvBWbfGMQFac3Bw8WQrsk2T8OfHcoOmNocGNtROhYzotG2qUfJgyZj aNp1UwribijPnwb6jwyqcxkXkxWTDLNieZPadrDnOjec/baBY8HePbh7U+yfiRhkFxxJk5 04km1TEASXNifTQG3E42vG4iyjeW7pU= X-MC-Unique: MBKcxQNdPeOjNZvWvDtatg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 08/16] Introduce property to virtio-mem Date: Mon, 13 Sep 2021 16:52:36 +0200 Message-Id: <0abdbf054a72d204646c3dd738d58bca6168b90b.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631545026809100001 Content-Type: text/plain; charset="utf-8" The virtio-mem has another property that isn't exposed yet: current size exposed to the guest. Please note, that this is different to because esp. on sizing the memory down guest may refuse to release some blocks. Therefore, let's have another size to report in the XML. But because of its nature, the won't be parsed and is report only (for live XMLs). Signed-off-by: Michal Privoznik --- docs/formatdomain.rst | 7 +++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 9 +++++++-- src/conf/domain_conf.h | 3 +++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index c327e1deae..7dc93d6abe 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7800,6 +7800,7 @@ Example: usage of the memory devices 0 2048 1048576 + 524288 @@ -7915,6 +7916,12 @@ Example: usage of the memory devices The total size exposed to the guest. Must respect ``block`` granulari= ty and be smaller than or equal to ``size``. =20 + ``current`` + Active XML for ``virtio-mem`` model may contain ``current`` element t= hat + reflects the current size of the corresponding virtio memory device. = The + 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 82fdc7c8b5..a68f794262 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6693,6 +6693,11 @@ + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9562065499..c91dd9d81c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25905,7 +25905,8 @@ virDomainMemorySourceDefFormat(virBuffer *buf, =20 static void virDomainMemoryTargetDefFormat(virBuffer *buf, - virDomainMemoryDef *def) + virDomainMemoryDef *def, + unsigned int flags) { g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); =20 @@ -25927,6 +25928,10 @@ virDomainMemoryTargetDefFormat(virBuffer *buf, =20 virBufferAsprintf(&childBuf, "%llu\n", def->requestedsize); + if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { + virBufferAsprintf(&childBuf, "%llu\n", + def->currentsize); + } } =20 virXMLFormatElement(buf, "target", NULL, &childBuf); @@ -25959,7 +25964,7 @@ virDomainMemoryDefFormat(virBuffer *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 e9d8e0c7ae..91bf52ff3b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2495,6 +2495,9 @@ struct _virDomainMemoryDef { unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */ unsigned long long blocksize; /* kibibytes; valid only for VIRTIO_MEM = */ unsigned long long requestedsize; /* kibibytes; valid only for VIRTIO_= MEM */ + unsigned long long currentsize; /* kibibytes, valid for VIRTIO_MEM and + active domain only, only to report = never + parse */ bool readonly; /* valid only for NVDIMM */ =20 /* required for QEMU NVDIMM ppc64 support */ --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631544910; cv=none; d=zohomail.com; s=zohoarc; b=jUcPCOrQhb0UdWw2z2gaz8BmP9qAU3AaeUSSdrXz7Ga6yjbQhemtcq2XFa4UygKwubT8cN/1JJZrgRkricldXLh8GpuNoVUW6B4dTGZlG8dVSClwbaGth5k6CHVFQw+ZFmNaJU7vn6lYSw2TMWhTHFaWE/rYBUCodyXhfKHsx2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544910; h=Content-Type:Content-Transfer-Encoding:Cc: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=JW7pgVoAk/dHeL8kBbnO7CjRWUDC7Yc/RQPcVmDOTmE=; b=G0AKTEPedhnz4Ds+BjdwSw8CxAmP1mrNSX4Uu6dDLr/kwtE3xGL718eT7HtFbzVFIESnR+4culy3QSrAStxEGtwc7QFcbpd7hUZ+yvrZi8nRMZ+A0Tl8g6+kcMGH5x6EibCAUwVhxCC8RBBcnOdThDOqvQLNaLb7QXWo0olC7cc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631544910337601.0356199089126; Mon, 13 Sep 2021 07:55:10 -0700 (PDT) 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-170-cAmdRnFrNrqU3kD_36DW8A-1; Mon, 13 Sep 2021 10:55:07 -0400 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 4BB8D101F7A1; Mon, 13 Sep 2021 14:55:02 +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 288425C3DF; Mon, 13 Sep 2021 14:55:02 +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 E982C181A1CF; Mon, 13 Sep 2021 14:55:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DErFvm021185 for ; Mon, 13 Sep 2021 10:53:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 66C3C69324; Mon, 13 Sep 2021 14:53:15 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDBBB188E4; Mon, 13 Sep 2021 14:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544909; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=JW7pgVoAk/dHeL8kBbnO7CjRWUDC7Yc/RQPcVmDOTmE=; b=fB9ru9VOyoNv85eWYRt1MD5QK12H70I5qOaPRC5dIqgp3CxnfHWbo7nwXTdqCtPk7nyCci p9YQ26m040Kdv3MdFjahwbojyb2VNBzOUWsTv9QzUG4GhqpzX7NBjWa0l3l55ThDoXSPFQ DB/B6lkYDbxWYnCje2CRAXDqk9oDMBI= X-MC-Unique: cAmdRnFrNrqU3kD_36DW8A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 09/16] conf: Introduce virDomainMemoryFindByDeviceAlias() Date: Mon, 13 Sep 2021 16:52:37 +0200 Message-Id: <19a11e67a109261e0b95add785383f1d9377b050.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544910771100002 Content-Type: text/plain; charset="utf-8" This function will be needed in the next commit where we will want to find virtio-mem given its alias by QEMU on the monitor. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 17 +++++++++++++++++ src/conf/domain_conf.h | 5 +++++ src/libvirt_private.syms | 1 + 3 files changed, 23 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c91dd9d81c..ae0218a674 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16618,6 +16618,23 @@ virDomainMemoryFindByDeviceInfo(virDomainDef *def, } =20 =20 +virDomainMemoryDef * +virDomainMemoryFindByDeviceAlias(virDomainDef *def, + const char *alias) +{ + size_t i; + + for (i =3D 0; i < def->nmems; i++) { + virDomainMemoryDef *tmp =3D def->mems[i]; + + if (STREQ_NULLABLE(tmp->info.alias, alias)) + return tmp; + } + + return NULL; +} + + /** * virDomainMemoryInsert: * diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 91bf52ff3b..2ce32934d5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3815,6 +3815,11 @@ virDomainMemoryFindByDeviceInfo(virDomainDef *dev, int *pos) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 +virDomainMemoryDef * +virDomainMemoryFindByDeviceAlias(virDomainDef *def, + const char *alias) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; + int virDomainShmemDefInsert(virDomainDef *def, virDomainShmemDef *shmem) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; bool virDomainShmemDefEquals(virDomainShmemDef *src, virDomainShmemDef *ds= t) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3f9035c25b..dfb1e29ca0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -508,6 +508,7 @@ virDomainMemballoonModelTypeFromString; virDomainMemballoonModelTypeToString; virDomainMemoryDefFree; virDomainMemoryFindByDef; +virDomainMemoryFindByDeviceAlias; virDomainMemoryFindByDeviceInfo; virDomainMemoryFindInactiveByDef; virDomainMemoryInsert; --=20 2.32.0 From nobody Fri Apr 26 17:27:02 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=1631545009; cv=none; d=zohomail.com; s=zohoarc; b=GNjWWdyqmlmETd8f7qUc6flMSPckAKUzpid0VWlBXJjZpaCyIfvMdEANLUxG/Xmh7TKEM0peCP5aBg18kKJO2ZTVitfbn2nssDn+7aRhpyMQ4xrwKv5oGxoqJVGNedOQE6jphi09LHGK79JeV2NUzUEkUOj4eEYxVRS1DkpZizU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631545009; h=Content-Type:Content-Transfer-Encoding:Cc: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=Tdu4evBwJgGH9aYj6wSRNckIjTddsyuDKMOWQeqzFkw=; b=aaXm+3brMAB5gZ6Sa30trPAr0k6t9PnPdi1ug3la7xu9990/DMnaDApGdz/XEwXqbUPl4LaU3pWzOSmpwz8t8QXMymIqceUvxVrGkG3Qy3QI+sUDOqvJkepOZmPg80/F/lzYZEeCQQgAoX4244gZd6gxytH6XhmlwlqLQkK9NsA= 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) 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 1631545009472484.17829026004495; Mon, 13 Sep 2021 07:56:49 -0700 (PDT) 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-369-edew9ewoOGOdxR90HJT6UA-1; Mon, 13 Sep 2021 10:56:46 -0400 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 E79DC8E4CD7; Mon, 13 Sep 2021 14:56:39 +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 CA84460871; Mon, 13 Sep 2021 14:56:39 +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 9A56A1800FE4; Mon, 13 Sep 2021 14:56:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DErGw6021193 for ; Mon, 13 Sep 2021 10:53:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5D9F269324; Mon, 13 Sep 2021 14:53:16 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2DF6188E4; Mon, 13 Sep 2021 14:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631545008; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Tdu4evBwJgGH9aYj6wSRNckIjTddsyuDKMOWQeqzFkw=; b=W3jPsqif5+EKMgUUnEyhd9D4N1ga8x1h8Q+hmZD0hsHSpmWZvXgQU9UyW2HpkT4jqhhm2Q 7IL/+b7TnYUIsme/4y7HGfv42QSCSmAX+kJTFaDNitR91UZL00pbX7MAu3ZISNGAPCQpgI ZyW+9mHAGvt+CTpzgD82ZOyaLanwI7s= X-MC-Unique: edew9ewoOGOdxR90HJT6UA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 10/16] qemu: Wire up MEMORY_DEVICE_SIZE_CHANGE event Date: Mon, 13 Sep 2021 16:52:38 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631545011003100001 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 current size is reported in the domain XML as an output element only. Signed-off-by: Michal Privoznik --- examples/c/misc/event-test.c | 17 ++++++ include/libvirt/libvirt-domain.h | 24 +++++++++ src/conf/domain_event.c | 84 +++++++++++++++++++++++++++++ src/conf/domain_event.h | 10 ++++ src/libvirt_private.syms | 2 + src/qemu/qemu_domain.c | 3 ++ src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 37 +++++++++++++ src/qemu/qemu_monitor.c | 21 ++++++++ src/qemu/qemu_monitor.h | 20 +++++++ src/qemu/qemu_monitor_json.c | 24 +++++++++ src/qemu/qemu_process.c | 42 +++++++++++++++ src/remote/remote_daemon_dispatch.c | 30 +++++++++++ src/remote/remote_driver.c | 32 +++++++++++ src/remote/remote_protocol.x | 15 +++++- src/remote_protocol-structs | 7 +++ tools/virsh-domain.c | 20 +++++++ 17 files changed, 388 insertions(+), 1 deletion(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 10c707e66b..1eec76c79d 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -982,6 +982,22 @@ myDomainEventMemoryFailureCallback(virConnectPtr conn = G_GNUC_UNUSED, } =20 =20 +static int +myDomainEventMemoryDeviceSizeChangeCallback(virConnectPtr conn G_GNUC_UNUS= ED, + virDomainPtr dom, + const char *alias, + unsigned long long size, + void *opaque G_GNUC_UNUSED) +{ + /* Casts to uint64_t to work around mingw not knowing %lld */ + printf("%s EVENT: Domain %s(%d) memory device size change: " + "alias: '%s' new size %" PRIu64 "'\n", + __func__, virDomainGetName(dom), virDomainGetID(dom), + alias, (uint64_t)size); + return 0; +} + + static int myDomainEventMigrationIterationCallback(virConnectPtr conn G_GNUC_UNUSED, virDomainPtr dom, @@ -1113,6 +1129,7 @@ struct domainEventData domainEvents[] =3D { DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_METADATA_CHANGE, myDomainEventMetadat= aChangeCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD, myDomainEventBlockTh= resholdCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE, myDomainEventMemoryFa= ilureCallback), + DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE, myDomainEv= entMemoryDeviceSizeChangeCallback), }; =20 struct storagePoolEventData { diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 7ef8ac51e5..eaafcc6b29 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4655,6 +4655,29 @@ typedef void (*virConnectDomainEventMemoryFailureCal= lback)(virConnectPtr conn, void *opaque); =20 =20 +/** + * virConnectDomainEventMemoryDeviceSizeChangeCallback: + * @conn: connection object + * @dom: domain on which the event occurred + * @alias: memory device alias + * @size: new current size of memory device (in KiB) + * @opaque: application specified data + * + * The callback occurs when the guest acknowledges request to change size = of + * memory device (so far only virtio-mem model supports this). The @size t= hen + * reflects the new amount of guest visible memory (in kibibytes). + * + * The callback signature to use when registering for an event of type + * VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE with + * virConnectDomainEventRegisterAny(). + */ +typedef void (*virConnectDomainEventMemoryDeviceSizeChangeCallback)(virCon= nectPtr conn, + virDom= ainPtr dom, + const = char *alias, + unsign= ed long long size, + void *= opaque); + + /** * VIR_DOMAIN_EVENT_CALLBACK: * @@ -4698,6 +4721,7 @@ typedef enum { VIR_DOMAIN_EVENT_ID_METADATA_CHANGE =3D 23, /* virConnectDomainEventMe= tadataChangeCallback */ VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD =3D 24, /* virConnectDomainEventBl= ockThresholdCallback */ VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE =3D 25, /* virConnectDomainEventMe= moryFailureCallback */ + VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE =3D 26, /* virConnectDom= ainEventMemoryDeviceSizeChangeCallback */ =20 # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_EVENT_ID_LAST diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 15a3baedf7..18539e348b 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -58,6 +58,7 @@ static virClass *virDomainEventDeviceRemovalFailedClass; static virClass *virDomainEventMetadataChangeClass; static virClass *virDomainEventBlockThresholdClass; static virClass *virDomainEventMemoryFailureClass; +static virClass *virDomainEventMemoryDeviceSizeChangeClass; =20 static void virDomainEventDispose(void *obj); static void virDomainEventLifecycleDispose(void *obj); @@ -81,6 +82,7 @@ static void virDomainEventDeviceRemovalFailedDispose(void= *obj); static void virDomainEventMetadataChangeDispose(void *obj); static void virDomainEventBlockThresholdDispose(void *obj); static void virDomainEventMemoryFailureDispose(void *obj); +static void virDomainEventMemoryDeviceSizeChangeDispose(void *obj); =20 static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, @@ -277,6 +279,15 @@ struct _virDomainEventMemoryFailure { }; typedef struct _virDomainEventMemoryFailure virDomainEventMemoryFailure; =20 +struct _virDomainEventMemoryDeviceSizeChange { + virDomainEvent parent; + + char *alias; + unsigned long long size; +}; +typedef struct _virDomainEventMemoryDeviceSizeChange virDomainEventMemoryD= eviceSizeChange; +typedef virDomainEventMemoryDeviceSizeChange *virDomainEventMemoryDeviceSi= zeChangePtr; + static int virDomainEventsOnceInit(void) { @@ -324,6 +335,8 @@ virDomainEventsOnceInit(void) return -1; if (!VIR_CLASS_NEW(virDomainEventMemoryFailure, virDomainEventClass)) return -1; + if (!VIR_CLASS_NEW(virDomainEventMemoryDeviceSizeChange, virDomainEven= tClass)) + return -1; return 0; } =20 @@ -540,6 +553,14 @@ virDomainEventMemoryFailureDispose(void *obj) VIR_DEBUG("obj=3D%p", event); } =20 +static void +virDomainEventMemoryDeviceSizeChangeDispose(void *obj) +{ + virDomainEventMemoryDeviceSizeChangePtr event =3D obj; + VIR_DEBUG("obj=3D%p", event); + + g_free(event->alias); +} =20 static void * virDomainEventNew(virClass *klass, @@ -1664,6 +1685,57 @@ virDomainEventMemoryFailureNewFromDom(virDomainPtr d= om, recipient, action, flags); } =20 + +static virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNew(int id, + const char *name, + unsigned char *uuid, + const char *alias, + unsigned long long size) +{ + virDomainEventMemoryDeviceSizeChangePtr ev; + + if (virDomainEventsInitialize() < 0) + return NULL; + + if (!(ev =3D virDomainEventNew(virDomainEventMemoryDeviceSizeChangeCla= ss, + VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CH= ANGE, + id, name, uuid))) + return NULL; + + ev->alias =3D g_strdup(alias); + ev->size =3D size; + + return (virObjectEvent *)ev; +} + + +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromObj(virDomainObj *obj, + const char *alias, + unsigned long long size) +{ + return virDomainEventMemoryDeviceSizeChangeNew(obj->def->id, + obj->def->name, + obj->def->uuid, + alias, + size); +} + + +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromDom(virDomainPtr dom, + const char *alias, + unsigned long long size) +{ + return virDomainEventMemoryDeviceSizeChangeNew(dom->id, + dom->name, + dom->uuid, + alias, + size); +} + + static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, virObjectEvent *event, @@ -1960,6 +2032,18 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn, goto cleanup; } =20 + case VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE: + { + virDomainEventMemoryDeviceSizeChangePtr memoryDeviceSizeChange= Event; + + memoryDeviceSizeChangeEvent =3D (virDomainEventMemoryDeviceSiz= eChangePtr)event; + ((virConnectDomainEventMemoryDeviceSizeChangeCallback)cb)(conn= , dom, + memo= ryDeviceSizeChangeEvent->alias, + memo= ryDeviceSizeChangeEvent->size, + cbop= aque); + goto cleanup; + } + case VIR_DOMAIN_EVENT_ID_LAST: break; } diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index 2a59e613cd..4a9f6b988b 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -267,6 +267,16 @@ virDomainEventMemoryFailureNewFromDom(virDomainPtr dom, int action, unsigned int flags); =20 +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromObj(virDomainObj *obj, + const char *alias, + unsigned long long size); + +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromDom(virDomainPtr dom, + const char *alias, + unsigned long long size); + int virDomainEventStateRegister(virConnectPtr conn, virObjectEventState *state, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dfb1e29ca0..83fd2b022a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -726,6 +726,8 @@ virDomainEventLifecycleNew; virDomainEventLifecycleNewFromDef; virDomainEventLifecycleNewFromDom; virDomainEventLifecycleNewFromObj; +virDomainEventMemoryDeviceSizeChangeNewFromDom; +virDomainEventMemoryDeviceSizeChangeNewFromObj; virDomainEventMemoryFailureNewFromDom; virDomainEventMemoryFailureNewFromObj; virDomainEventMetadataChangeNewFromDom; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 298f9b076d..325e45d009 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11033,6 +11033,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 ae9d76ec4a..802de93e2e 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -438,6 +438,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 10ff8519c5..712ec68f7c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4254,6 +4254,40 @@ processGuestCrashloadedEvent(virQEMUDriver *driver, } =20 =20 +static void +processMemoryDeviceSizeChange(virQEMUDriver *driver, + virDomainObj *vm, + qemuMonitorMemoryDeviceSizeChange *info) +{ + virDomainMemoryDef *mem =3D NULL; + virObjectEvent *event =3D NULL; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto endjob; + } + + mem =3D virDomainMemoryFindByDeviceAlias(vm->def, info->devAlias); + if (!mem) { + VIR_DEBUG("Memory device '%s' not found", info->devAlias); + goto endjob; + } + + mem->currentsize =3D VIR_DIV_UP(info->size, 1024); + + event =3D virDomainEventMemoryDeviceSizeChangeNewFromObj(vm, + info->devAlias, + mem->currentsiz= e); + + endjob: + qemuDomainObjEndJob(driver, vm); + virObjectEventStateQueue(driver->domainEventState, event); +} + + static void qemuProcessEventHandler(void *data, void *opaque) { struct qemuProcessEvent *processEvent =3D data; @@ -4303,6 +4337,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 24119ef66e..5fc23f13d3 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1382,6 +1382,17 @@ qemuMonitorEmitSpiceMigrated(qemuMonitor *mon) } =20 =20 +void +qemuMonitorEmitMemoryDeviceSizeChange(qemuMonitor *mon, + const char *devAlias, + unsigned long long size) +{ + VIR_DEBUG("mon=3D%p, devAlias=3D'%s', size=3D%llu", mon, devAlias, siz= e); + + QEMU_MONITOR_CALLBACK(mon, domainMemoryDeviceSizeChange, mon->vm, devA= lias, size); +} + + void qemuMonitorEmitMemoryFailure(qemuMonitor *mon, qemuMonitorEventMemoryFailure *mfp) @@ -4266,6 +4277,16 @@ qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGid= Status *info) } =20 =20 +void +qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChangePtr= info) +{ + if (!info) + return; + + g_free(info->devAlias); +} + + int qemuMonitorSetWatchdogAction(qemuMonitor *mon, const char *action) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 0ebe73ac04..962b516542 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -101,6 +101,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_ACTION_SHUTDOWN_KEEP, /* do not change the current settin= g */ QEMU_MONITOR_ACTION_SHUTDOWN_POWEROFF, @@ -187,6 +195,7 @@ struct _qemuMonitorJobInfo { char *qemuMonitorGuestPanicEventInfoFormatMsg(qemuMonitorEventPanicInfo *i= nfo); void qemuMonitorEventPanicInfoFree(qemuMonitorEventPanicInfo *info); void qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGidStatus *info); +void qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChan= ge *info); =20 typedef void (*qemuMonitorDestroyCallback)(qemuMonitor *mon, virDomainObj *vm, @@ -403,6 +412,12 @@ typedef void (*qemuMonitorDomainMemoryFailureCallback)= (qemuMonitor *mon, qemuMonitorEventMem= oryFailure *mfp, void *opaque); =20 +typedef int (*qemuMonitorDomainMemoryDeviceSizeChange)(qemuMonitor *mon, + virDomainObj *vm, + const char *alias, + unsigned long long = size, + void *opaque); + typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks; struct _qemuMonitorCallbacks { qemuMonitorEofNotifyCallback eofNotify; @@ -437,6 +452,7 @@ struct _qemuMonitorCallbacks { qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChang= ed; qemuMonitorDomainGuestCrashloadedCallback domainGuestCrashloaded; qemuMonitorDomainMemoryFailureCallback domainMemoryFailure; + qemuMonitorDomainMemoryDeviceSizeChange domainMemoryDeviceSizeChange; }; =20 qemuMonitor *qemuMonitorOpen(virDomainObj *vm, @@ -532,6 +548,10 @@ void qemuMonitorEmitSerialChange(qemuMonitor *mon, bool connected); void qemuMonitorEmitSpiceMigrated(qemuMonitor *mon); =20 +void qemuMonitorEmitMemoryDeviceSizeChange(qemuMonitor *mon, + const char *devAlias, + unsigned long long size); + void qemuMonitorEmitMemoryFailure(qemuMonitor *mon, qemuMonitorEventMemoryFailure *mfp); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d5e95f3dda..ddce0fd2cd 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -112,6 +112,7 @@ static void qemuMonitorJSONHandleDumpCompleted(qemuMoni= tor *mon, virJSONValue *d static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitor *mon, = virJSONValue *data); static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, vi= rJSONValue *data); static void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONVa= lue *data); +static void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, = virJSONValue *data); =20 typedef struct { const char *type; @@ -132,6 +133,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, }, @@ -1313,6 +1315,28 @@ qemuMonitorJSONHandleSpiceMigrated(qemuMonitor *mon, } =20 =20 +static void +qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, + virJSONValue *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(qemuMonitor *mon, virJSONValue *data) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 07bd7e928a..8ca496cfb4 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1833,6 +1833,47 @@ qemuProcessHandleMemoryFailure(qemuMonitor *mon G_GN= UC_UNUSED, } =20 =20 +static int +qemuProcessHandleMemoryDeviceSizeChange(qemuMonitor *mon G_GNUC_UNUSED, + virDomainObj *vm, + const char *devAlias, + unsigned long long size, + void *opaque) +{ + virQEMUDriver *driver =3D opaque; + struct qemuProcessEvent *processEvent =3D NULL; + qemuMonitorMemoryDeviceSizeChange *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; + } + + processEvent =3D NULL; + ret =3D 0; + cleanup: + qemuProcessEventFree(processEvent); + virObjectUnlock(vm); + return ret; +} + + static qemuMonitorCallbacks monitorCallbacks =3D { .eofNotify =3D qemuProcessHandleMonitorEOF, .errorNotify =3D qemuProcessHandleMonitorError, @@ -1866,6 +1907,7 @@ static qemuMonitorCallbacks monitorCallbacks =3D { .domainRdmaGidStatusChanged =3D qemuProcessHandleRdmaGidStatusChanged, .domainGuestCrashloaded =3D qemuProcessHandleGuestCrashloaded, .domainMemoryFailure =3D qemuProcessHandleMemoryFailure, + .domainMemoryDeviceSizeChange =3D qemuProcessHandleMemoryDeviceSizeCha= nge, }; =20 static void diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 0bac7d4f51..bcfeadc2ae 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1334,6 +1334,35 @@ remoteRelayDomainEventMemoryFailure(virConnectPtr co= nn, } =20 =20 +static int +remoteRelayDomainEventMemoryDeviceSizeChange(virConnectPtr conn, + virDomainPtr dom, + const char *alias, + unsigned long long size, + void *opaque) +{ + daemonClientEventCallback *callback =3D opaque; + remote_domain_event_memory_device_size_change_msg data; + + if (callback->callbackID < 0 || + !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) + return -1; + + /* build return data */ + memset(&data, 0, sizeof(data)); + data.callbackID =3D callback->callbackID; + data.alias =3D g_strdup(alias); + data.size =3D size; + make_nonnull_domain(&data.dom, dom); + + remoteDispatchObjectEventSend(callback->client, remoteProgram, + REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_S= IZE_CHANGE, + (xdrproc_t)xdr_remote_domain_event_memor= y_device_size_change_msg, + &data); + return 0; +} + + static virConnectDomainEventGenericCallback domainEventCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot), @@ -1361,6 +1390,7 @@ static virConnectDomainEventGenericCallback domainEve= ntCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMetadataChange), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockThreshold), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMemoryFailure), + VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMemoryDeviceSizeChange= ), }; =20 G_STATIC_ASSERT(G_N_ELEMENTS(domainEventCallbacks) =3D=3D VIR_DOMAIN_EVENT= _ID_LAST); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index b64a86af63..ae6dc849ff 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -410,6 +410,10 @@ remoteDomainBuildEventMemoryFailure(virNetClientProgra= m *prog, void *evdata, void *opaque); =20 static void +remoteDomainBuildEventMemoryDeviceSizeChange(virNetClientProgram *prog, + virNetClient *client, + void *evdata, void *opaque); +static void remoteConnectNotifyEventConnectionClosed(virNetClientProgram *prog G_GNUC_= UNUSED, virNetClient *client G_GNUC_UNUSE= D, void *evdata, void *opaque); @@ -624,6 +628,10 @@ static virNetClientProgramEvent remoteEvents[] =3D { remoteDomainBuildEventMemoryFailure, sizeof(remote_domain_event_memory_failure_msg), (xdrproc_t)xdr_remote_domain_event_memory_failure_msg }, + { REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_SIZE_CHANGE, + remoteDomainBuildEventMemoryDeviceSizeChange, + sizeof(remote_domain_event_memory_device_size_change_msg), + (xdrproc_t)xdr_remote_domain_event_memory_device_size_change_msg }, }; =20 static void @@ -5436,6 +5444,30 @@ remoteDomainBuildEventMemoryFailure(virNetClientProg= ram *prog G_GNUC_UNUSED, } =20 =20 +static void +remoteDomainBuildEventMemoryDeviceSizeChange(virNetClientProgram *prog G_G= NUC_UNUSED, + virNetClient *client G_GNUC_U= NUSED, + void *evdata, void *opaque) +{ + virConnectPtr conn =3D opaque; + remote_domain_event_memory_device_size_change_msg *msg =3D evdata; + struct private_data *priv =3D conn->privateData; + virDomainPtr dom; + virObjectEvent *event =3D NULL; + + if (!(dom =3D get_nonnull_domain(conn, msg->dom))) + return; + + event =3D virDomainEventMemoryDeviceSizeChangeNewFromDom(dom, + msg->alias, + msg->size); + + virObjectUnref(dom); + + virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackI= D); +} + + static int remoteStreamSend(virStreamPtr st, const char *data, diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index df1b126b0c..34c2751755 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3855,6 +3855,13 @@ struct remote_domain_start_dirty_rate_calc_args { }; =20 =20 +struct remote_domain_event_memory_device_size_change_msg { + int callbackID; + remote_nonnull_domain dom; + remote_nonnull_string alias; + unsigned hyper size; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6818,5 +6825,11 @@ enum remote_procedure { * @acl: network:write * @acl: network:save */ - REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS =3D 432 + REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS =3D 432, + + /** + * @generate: both + * @acl: none + */ + REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_SIZE_CHANGE =3D 433 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index dad83361fa..b91e1b867f 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3206,6 +3206,12 @@ struct remote_domain_start_dirty_rate_calc_args { int seconds; u_int flags; }; +struct remote_domain_event_memory_device_size_change_msg { + int callbackID; + remote_nonnull_domain dom; + remote_nonnull_string alias; + uint64_t size; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3639,4 +3645,5 @@ enum remote_procedure { REMOTE_PROC_NODE_DEVICE_CREATE =3D 430, REMOTE_PROC_NWFILTER_DEFINE_XML_FLAGS =3D 431, REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS =3D 432, + REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_SIZE_CHANGE =3D 433, }; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e5bd1fdd75..b06f651c13 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13148,6 +13148,24 @@ virshEventMemoryFailurePrint(virConnectPtr conn G_= GNUC_UNUSED, } =20 =20 +static void +virshEventMemoryDeviceSizeChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + unsigned long long size, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, + _("event 'memory-device-size-change' for domain '%s'= :\n" + "alias: %s\nsize: %llu\n"), + virDomainGetName(dom), alias, size); + + virshEventPrint(opaque, &buf); +} + + virshDomainEventCallback virshDomainEventCallbacks[] =3D { { "lifecycle", VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), }, @@ -13199,6 +13217,8 @@ virshDomainEventCallback virshDomainEventCallbacks[= ] =3D { VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), }, { "memory-failure", VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryFailurePrint), }, + { "memory-device-size-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryDeviceSizeChangePrint), }, }; G_STATIC_ASSERT(VIR_DOMAIN_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshDomainEv= entCallbacks)); =20 --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631544969; cv=none; d=zohomail.com; s=zohoarc; b=jp69MxBvG9lpYRDG6T8buVe526BXVAD7pf9SURl5o6AXry99G0lTCs8Y4fqCCoUXFEjWXSQP1Vf/cuIC96b1rvrE6ZBDZPP1v0fIyuCbRXr2Ezzhzn8icKVNc91O1P88nRaCKqizuvsHB46d1QSJZFDjc9dZH/5pOPiXPcOtFUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544969; h=Content-Type:Content-Transfer-Encoding:Cc: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=SIDdNzc+jewLBaUFn5Q49vqW+VgznPL3r6QuzmOmUhw=; b=BLhY7OOZHjPDG7fUadthoGKLFZFBjqk5d2PB2mvbhRhVlQnTeJXW4Nllru5342pr+be/5U4JPUNl7F+XdTsVQHvPpHp5/388qS2nUBN0WcEN9Sc4avELVdLEr/2ka36fVYmHHkTdo6i4dGl45083G20HCrB+1I2E60ba2WlcPiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631544969545694.2257400713111; Mon, 13 Sep 2021 07:56:09 -0700 (PDT) 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-71-LWw5eFOsO_O0UIszMIG_ZA-1; Mon, 13 Sep 2021 10:55:11 -0400 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 1F6DD79EE7; Mon, 13 Sep 2021 14:55:06 +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 0357B60871; Mon, 13 Sep 2021 14:55: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 BE8344EA42; Mon, 13 Sep 2021 14:55:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DErHLd021202 for ; Mon, 13 Sep 2021 10:53:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5088D188E4; Mon, 13 Sep 2021 14:53:17 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id A94886A8F8; Mon, 13 Sep 2021 14:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544968; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=SIDdNzc+jewLBaUFn5Q49vqW+VgznPL3r6QuzmOmUhw=; b=QwWG2oNvGkSmSuN3HYOg7imSg0KkV8Vblux3gvUkZYAPhxoSNHHz0sENvrMf5teGyCQyb/ /sSVjNNRsZdq+ljpMPXPUHwlAixRRWfrOSRBDg+jF0xTBzT26d/A6gZWyb3oze97od9+Z3 aHHGvgFEPaYu2ORsMt+micToKF4fzz4= X-MC-Unique: LWw5eFOsO_O0UIszMIG_ZA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 11/16] qemu: Refresh the current size of virtio-mem on monitor reconnect Date: Mon, 13 Sep 2021 16:52:39 +0200 Message-Id: <0ebf1e4d8eb2f29b2153c39a389c2d3060ec7aa7.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544971628100001 Content-Type: text/plain; charset="utf-8" If the QEMU driver restarts it loses the track of the current 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 --- src/qemu/qemu_domain.c | 20 +++++++++++-- src/qemu/qemu_monitor.h | 3 ++ src/qemu/qemu_monitor_json.c | 58 ++++++++++++++++++++++-------------- src/qemu/qemu_process.c | 3 ++ 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 325e45d009..00c6ae877c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8375,9 +8375,23 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriver *driv= er, 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: + mem->currentsize =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_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } } =20 virHashFree(meminfo); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 962b516542..648fe293ed 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1385,10 +1385,13 @@ int qemuMonitorSetIOThread(qemuMonitor *mon, =20 typedef struct _qemuMonitorMemoryDeviceInfo qemuMonitorMemoryDeviceInfo; struct _qemuMonitorMemoryDeviceInfo { + /* For pc-dimm */ unsigned long long address; unsigned int slot; bool hotplugged; bool hotpluggable; + /* For virtio-mem */ + unsigned long long size; /* in bytes */ }; =20 int qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index ddce0fd2cd..a4e60b4ee9 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7984,7 +7984,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, virJSONValue *cmd; virJSONValue *reply =3D NULL; virJSONValue *data =3D NULL; - qemuMonitorMemoryDeviceInfo *meminfo =3D NULL; size_t i; =20 if (!(cmd =3D qemuMonitorJSONMakeCommand("query-memory-devices", NULL)= )) @@ -8005,6 +8004,9 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, =20 for (i =3D 0; i < virJSONValueArraySize(data); i++) { virJSONValue *elem =3D virJSONValueArrayGet(data, i); + g_autofree qemuMonitorMemoryDeviceInfo *meminfo =3D NULL; + virJSONValue *dimminfo; + const char *devalias; const char *type; =20 if (!(type =3D virJSONValueObjectGetString(elem, "type"))) { @@ -8014,26 +8016,26 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, 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; + } + + /* While 'id' attribute is marked as optional in QEMU's QAPI + * specification, Libvirt always sets it. Thus we can fail if not + * present. */ + 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")) { - virJSONValue *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", @@ -8064,17 +8066,27 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, =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 size in virtio memory = info")); 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 8ca496cfb4..b2ac5937ec 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8718,6 +8718,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.32.0 From nobody Fri Apr 26 17:27:02 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=1631544887; cv=none; d=zohomail.com; s=zohoarc; b=GrvI9BYFtRl+7v0XmZBIqUAXukHt2DSjBUscIYlG3HJoJV048w4l5CyciC8SPd+STCB6AqWBo1aa40TjRI4FzzNxN6uIai23hJ/YDXJwycjQGRKwkUMGhLrHZguJw7c++xGhNB8aLZ2u9ZFN1edoB0UE1M9zHsMGgzSFbZdmdYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544887; h=Content-Type:Content-Transfer-Encoding:Cc: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=WJGbf9OsJL4WEjkcaryXZrfRcbQaB43iOXDPvssR8f0=; b=G5TyftQTzkl1yq2IauCQcXrAKjBbbYh0Ba9xiCqnrfhchmjjGfIqJW6c1c5Ky27mwD6MjpIn4nik6ouXZ1DJSJ8WWX1p5KyFrknZ3KsqC5VgUfK+raD562pNg1y373sT5OHnBrOeH0r4rAgOEr5h2/S9Q95gEkR8l6rYL6SeSn8= 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) 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 1631544887390888.8375885094131; Mon, 13 Sep 2021 07:54:47 -0700 (PDT) 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-471-kh9UuEVWOQqR1eGgo7r0yQ-1; Mon, 13 Sep 2021 10:54:39 -0400 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 2576E824FA6; Mon, 13 Sep 2021 14:54:32 +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 0793F188E4; Mon, 13 Sep 2021 14:54:32 +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 C6E594EA3B; Mon, 13 Sep 2021 14:54:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DErId2021213 for ; Mon, 13 Sep 2021 10:53:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 442E669324; Mon, 13 Sep 2021 14:53:18 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CF3A188E4; Mon, 13 Sep 2021 14:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544886; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=WJGbf9OsJL4WEjkcaryXZrfRcbQaB43iOXDPvssR8f0=; b=aXHbAAI7/GxLI+/xUfOIBceUq7qgEvtZOneCQTQGozAyZLGqepoXeh9n046vk72b3/djUJ 0hQbKFRoI01PLh8UL2OLWhSYB8YQaNyYR6AVF1vNT44bwwCKCyTFYV1Hm87qFtqJsT4Lqf n/r2l4d21nEZORsY67FlAqXVkiM6wbo= X-MC-Unique: kh9UuEVWOQqR1eGgo7r0yQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 12/16] qemu: Account for both memballoon and virtio-mem Date: Mon, 13 Sep 2021 16:52:40 +0200 Message-Id: <3ca8d22cfafdaba129c0b0c6bb4ad364fe89ca47.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544888018100001 Content-Type: text/plain; charset="utf-8" Reporting how much memory is exposed to the guest happens under which is taken from def->mem.cur_balloon. The reported amount should account for both balloon size and the sum of @currentsize of all virtio-mems. For instance, if domain has 4GiB via balloon and additional 2GiB via virtio-mem, then the domain XML should report 6GiB. The same applies for domain statistics. The way to achieve this is to account for either balloon or virtio-mem when the size of the other is changed, e.g. on balloon change we have to add all @currentsize (for non virtio-mem these will be zero, so the check for memory model is needless, but makes it more obvious what's happening), and vice versa. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 9 +++++++++ src/qemu/qemu_process.c | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 712ec68f7c..84adeec1c2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4261,6 +4261,7 @@ processMemoryDeviceSizeChange(virQEMUDriver *driver, { virDomainMemoryDef *mem =3D NULL; virObjectEvent *event =3D NULL; + unsigned long long balloon; =20 if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) return; @@ -4276,7 +4277,15 @@ processMemoryDeviceSizeChange(virQEMUDriver *driver, goto endjob; } =20 + /* If this looks weird it's because it is. The balloon size + * as reported by QEMU does not include any of @currentsize. + * It really contains just the balloon size. But in domain + * definition we want to report also sum of @currentsize. Do + * a bit of math to fix the domain definition. */ + balloon =3D vm->def->mem.cur_balloon - mem->currentsize; mem->currentsize =3D VIR_DIV_UP(info->size, 1024); + balloon +=3D mem->currentsize; + vm->def->mem.cur_balloon =3D balloon; =20 event =3D virDomainEventMemoryDeviceSizeChangeNewFromObj(vm, info->devAlias, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b2ac5937ec..f8e7345329 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1213,10 +1213,22 @@ qemuProcessHandleBalloonChange(qemuMonitor *mon G_G= NUC_UNUSED, virQEMUDriver *driver =3D opaque; virObjectEvent *event =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + size_t i; =20 virObjectLock(vm); event =3D virDomainEventBalloonChangeNewFromObj(vm, actual); =20 + /* We want the balloon size stored in domain definition to + * account for the actual size of virtio-mem too. But the + * balloon size as reported by QEMU (@actual) contains just + * the balloon size without any virtio-mem. Do a wee bit of + * math to fix it. */ + VIR_DEBUG("balloon size before fix is %lld", actual); + for (i =3D 0; i < vm->def->nmems; i++) { + if (vm->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_= MEM) + actual +=3D vm->def->mems[i]->currentsize; + } + VIR_DEBUG("Updating balloon from %lld to %lld kb", vm->def->mem.cur_balloon, actual); vm->def->mem.cur_balloon =3D actual; @@ -2343,6 +2355,7 @@ qemuProcessRefreshBalloonState(virQEMUDriver *driver, 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 @@ -2359,6 +2372,18 @@ qemuProcessRefreshBalloonState(virQEMUDriver *driver, if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) return -1; =20 + /* We want the balloon size stored in domain definition to + * account for the actual size of virtio-mem too. But the + * balloon size as reported by QEMU (@balloon) contains just + * the balloon size without any virtio-mem. Do a wee bit of + * math to fix it. */ + VIR_DEBUG("balloon size before fix is %lld", balloon); + for (i =3D 0; i < vm->def->nmems; i++) { + if (vm->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_= MEM) + balloon +=3D vm->def->mems[i]->currentsize; + } + VIR_DEBUG("Updating balloon from %lld to %lld kb", + vm->def->mem.cur_balloon, balloon); vm->def->mem.cur_balloon =3D balloon; =20 return 0; --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631545016; cv=none; d=zohomail.com; s=zohoarc; b=RPmg9fbeTgovDJ7qvYBFw8Xx8ZPYpbvyuaxoWN+WPF+ax2Rl1IxRWrhijR8eYvL5WwKH34vlES/p2cs4/vFlzM2lybBwam/m7rvE44hm8YqsdSksZG+4+AGKiTWtcn9NEkhYlZEL52k3fZ1ACTnO3Dvor9LY9428SKWbEoDAFVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631545016; h=Content-Type:Content-Transfer-Encoding:Cc: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=AjfLNqmRLXZmsTHzPszYvD3zN1UG4hbpGa5JDkRLOp4=; b=VHIyRdlPcul926lYGpEu2vznBJSwfp3nrttCO84K9mZ3LdGdPEF2oXuBjoJ5gbuydCXjdjUMKzc3P/F3lUrlAh8ldSg5sQb7tAvJqkDXEXeK3hlMWS3dE2gvwopZrjpAEtOR0/Dhv9lozNgm7vdQdOlTiWx3kBMXBnruWBi29fs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631545015963286.4039686939391; Mon, 13 Sep 2021 07:56:55 -0700 (PDT) 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-184-J_ZuAvl7N4C4lCqyrZj8sg-1; Mon, 13 Sep 2021 10:56:53 -0400 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 7E2D78E4CEA; Mon, 13 Sep 2021 14:56:42 +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 62DDD781E8; Mon, 13 Sep 2021 14:56:42 +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 2DA274EA2A; Mon, 13 Sep 2021 14:56:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DErJMd021226 for ; Mon, 13 Sep 2021 10:53:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3821769324; Mon, 13 Sep 2021 14:53:19 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FDA8188E4; Mon, 13 Sep 2021 14:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631545014; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=AjfLNqmRLXZmsTHzPszYvD3zN1UG4hbpGa5JDkRLOp4=; b=WsENnPS7QA3blOsPjiz2xXfqkQAcP4hIGFrSiCD7qJLWHx89xJuKNHYkYP+kklxaOSbyq3 J6oUE84syGqm5fnijkZ9wjgtToJrFbViIoYZJRs6MT++wjbsEanolDtFSHDDdCyxAC7i18 GTQ1Isqw/4FrdVE97W6fRsVf3IFp0oc= X-MC-Unique: J_ZuAvl7N4C4lCqyrZj8sg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 13/16] qemuDomainSetMemoryFlags: Take virtio-mem into consideration Date: Mon, 13 Sep 2021 16:52:41 +0200 Message-Id: <61c7d8c6b316c93cd45fca00562c0a74b8c8da77.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631545017920100001 Content-Type: text/plain; charset="utf-8" The qemuDomainSetMemoryFlags() allows for memballoon () changes for both active and inactive guests. And just before doing any change, we have to make sure that the new size is not greater than the total memory (). However, the total memory includes not only the regular guest memory, but also sum of maximum sizes of all virtio-mems (in fact all memory devices for that matter). But virtio-mem devices are modified differently (via virDomainUpdateDevice()) and thus the upper limit for new balloon size has to be lowered. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 84adeec1c2..171a5217a4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2388,12 +2388,28 @@ static int qemuDomainSetMemoryFlags(virDomainPtr do= m, unsigned long newmem, } else { /* resize the current memory */ unsigned long oldmax =3D 0; + size_t i; =20 - if (def) + if (def) { oldmax =3D virDomainDefGetMemoryTotal(def); + + /* While virtio-mem is regular mem from guest POV, it can't be + * modified through this API. */ + for (i =3D 0; i < def->nmems; i++) { + if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIR= TIO_MEM) + oldmax -=3D def->mems[i]->size; + } + } + if (persistentDef) { - if (!oldmax || oldmax > virDomainDefGetMemoryTotal(persistentD= ef)) + if (!def || oldmax > virDomainDefGetMemoryTotal(persistentDef)= ) { oldmax =3D virDomainDefGetMemoryTotal(persistentDef); + + for (i =3D 0; i < persistentDef->nmems; i++) { + if (persistentDef->mems[i]->model =3D=3D VIR_DOMAIN_ME= MORY_MODEL_VIRTIO_MEM) + oldmax -=3D persistentDef->mems[i]->size; + } + } } =20 if (newmem > oldmax) { --=20 2.32.0 From nobody Fri Apr 26 17:27:02 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=1631544896; cv=none; d=zohomail.com; s=zohoarc; b=nvpZDBFUY6vgEUFTIlWNurLnqhAe062g+GYZhOe3cNJDG68HciNcf2I/HbXDsOpgnl9w4nDv2+whlL7iHp+Sa4nkBhW/Ba+xgbPg8QKZgXEa15YRp2/T8bcMjQLBDc82Gs7V9Hq3k6+qcvrPjgzwgXZFVTzZooqwviylvw7NI34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631544896; h=Content-Type:Content-Transfer-Encoding:Cc: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=61e6vo6pkVOcxCIm7WI+QOKNMvuwu4XbXQOvUgZFdLQ=; b=bDlaq+ODWU3bPMuj0ovrr8Q5aHjSZeeMLRtu1aXoj3FQn9D1ZtldYF4YYVANmxa+s+TRXBzWlH5Pg4he7yJ53q0XM1fp93YY9+x5LoWvK9he0T0HfAy/H/05SEpgemR4Rq15Zh24DfeSdWSCU7uZh8op2kTlAOq7hlyyw6UBUJ4= 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) 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 163154489673012.512315352799078; Mon, 13 Sep 2021 07:54:56 -0700 (PDT) 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-367-Jm1iPObIPfyTAwITNaYoiA-1; Mon, 13 Sep 2021 10:54:44 -0400 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 04F14802690; Mon, 13 Sep 2021 14:54:38 +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 D48B45C1D1; Mon, 13 Sep 2021 14:54:37 +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 9F0FB1800B8B; Mon, 13 Sep 2021 14:54:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DErO2G021251 for ; Mon, 13 Sep 2021 10:53:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D34A188E4; Mon, 13 Sep 2021 14:53:24 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8390A6A8F5; Mon, 13 Sep 2021 14:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631544895; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=61e6vo6pkVOcxCIm7WI+QOKNMvuwu4XbXQOvUgZFdLQ=; b=HyeXGD5PF2OMlA6djtIf+iYf2A6Yr/8FCpMpx5p4gOQGLloeWnTdVpEPZcmG+1nTyzm5Dx BYcNREeOGoDC/uzFraezVdQJlqcfGTH6JdRKkITcVWB96CoUN69O9Jkc1zwrifW2EJNrvI iPFiYhqWc8N36RnGOfQt9h5HP8Y1bqY= X-MC-Unique: Jm1iPObIPfyTAwITNaYoiA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 14/16] virsh: Introduce update-memory-device command Date: Mon, 13 Sep 2021 16:52:42 +0200 Message-Id: <803a4ce78167fb8a3864318ec5416f1ef5ee6ea1.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631544897348100001 Content-Type: text/plain; charset="utf-8" New 'update-memory-device' command is introduced which aims on making it user friendly to change device. So far I just need to change so I'm introducing --requested-size only; but the idea is that this is extensible for other cases too. For instance, want to change ? A new --my-element argument can be easily introduced. Signed-off-by: Michal Privoznik --- docs/manpages/virsh.rst | 30 ++++++++ tools/virsh-domain.c | 161 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 9561b3f59d..c57937a55a 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4919,6 +4919,36 @@ results as some fields may be autogenerated and thus= match devices other than expected. =20 =20 +update-memory-device +-------------------- + +**Syntax:** + +:: + + update-memory-device domain [--print-xml] [[--alias alias] | [--node no= de]] + [[--live] [--config] | [--current]] + [--requested-size size] + +This command finds ```` device inside given *domain*, changes +requested values and passes updated device XML to daemon. If *--print-xml*= is +specified then the device is not changed, but the updated device XML is pr= inted +to stdout. If there are more than one ```` devices in *domain* u= se +*--alias* or *--node* to select the desired one. + +If *--live* is specified, affect a running domain. +If *--config* is specified, affect the next startup of a persistent guest. +If *--current* is specified, it is equivalent to either *--live* or +*--config*, depending on the current state of the guest. +Both *--live* and *--config* flags may be given, but *--current* is +exclusive. Not specifying any flag is the same as specifying *--current*. + +If *--requested-size* is specified then ```` under memory targ= et is +changed to requested *size* (as scaled integer, see ``NOTES`` above). It +defaults to kibibytes if no suffix is provided. The option is valid only f= or +``virtio-mem`` memory device model. + + change-media ------------ =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index b06f651c13..0c02ce5ae0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8910,6 +8910,161 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) return true; } =20 + +/* + * "update-memory-device" command + */ +static const vshCmdInfo info_update_memory_device[] =3D { + {.name =3D "help", + .data =3D N_("update memory device of a domain") + }, + {.name =3D "desc", + .data =3D N_("Update values of a memory device of a domain") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_update_memory_device[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D "print-xml", + .type =3D VSH_OT_BOOL, + .help =3D N_("print updated memory device XML instead of executing th= e change") + }, + {.name =3D "alias", + .type =3D VSH_OT_STRING, + .completer =3D virshDomainDeviceAliasCompleter, + .help =3D N_("memory device alias") + }, + {.name =3D "node", + .type =3D VSH_OT_INT, + .help =3D N_("memory device target node") + }, + {.name =3D "requested-size", + .type =3D VSH_OT_INT, + .help =3D N_("new value of size, as scaled integer (defa= ult KiB)") + }, + {.name =3D NULL} +}; + +static int +virshGetUpdatedMemoryXML(char **updatedMemoryXML, + vshControl *ctl, + const vshCmd *cmd, + virDomainPtr dom, + unsigned int flags) +{ + const char *alias =3D NULL; + bool nodeOpt =3D false; + unsigned int node =3D 0; + 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; + unsigned int domainXMLFlags =3D 0; + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) + domainXMLFlags |=3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXMLFromDom(ctl, dom, domainXMLFlags, &doc, &ctxt) < = 0) + return -1; + + nodeOpt =3D vshCommandOptBool(cmd, "node"); + if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || + vshCommandOptUInt(ctl, cmd, "node", &node) < 0) { + return -1; + } + + if (nodeOpt) { + xpath =3D g_strdup_printf("/domain/devices/memory[./target/node=3D= '%u']", node); + } else if (alias) { + xpath =3D g_strdup_printf("/domain/devices/memory[./alias/@name=3D= '%s']", alias); + } else { + xpath =3D g_strdup("/domain/devices/memory"); + } + + nmems =3D virXPathNodeSet(xpath, ctxt, &mems); + if (nmems < 0) { + vshSaveLibvirtError(); + return -1; + } else if (nmems =3D=3D 0) { + vshError(ctl, _("no memory device found")); + return -1; + } else if (nmems > 1) { + vshError(ctl, _("multiple memory devices found, use --alias or --n= ode to select one")); + return -1; + } + + ctxt->node =3D mems[0]; + + if (vshCommandOptBool(cmd, "requested-size")) { + xmlNodePtr requestedSizeNode; + g_autofree char *kibibytesStr =3D NULL; + unsigned long long bytes =3D 0; + unsigned long kibibytes =3D 0; + + if (vshCommandOptScaledInt(ctl, cmd, "requested-size", &bytes, 102= 4, ULLONG_MAX) < 0) + return -1; + kibibytes =3D VIR_DIV_UP(bytes, 1024); + + 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 (!(*updatedMemoryXML =3D virXMLNodeToString(doc, mems[0]))) { + vshSaveLibvirtError(); + return -1; + } + + return 0; +} + +static bool +cmdUpdateMemoryDevice(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool current =3D vshCommandOptBool(cmd, "current"); + g_autofree char *updatedMemoryXML =3D NULL; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + VSH_EXCLUSIVE_OPTIONS("node", "alias"); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virshGetUpdatedMemoryXML(&updatedMemoryXML, ctl, cmd, dom, flags) = < 0) + return false; + + if (vshCommandOptBool(cmd, "print-xml")) { + vshPrint(ctl, "%s", updatedMemoryXML); + } else { + if (virDomainUpdateDeviceFlags(dom, updatedMemoryXML, flags) < 0) + return false; + } + + return true; +} + + /* * "memtune" command */ @@ -14675,6 +14830,12 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_update_device, .flags =3D 0 }, + {.name =3D "update-memory-device", + .handler =3D cmdUpdateMemoryDevice, + .opts =3D opts_update_memory_device, + .info =3D info_update_memory_device, + .flags =3D 0 + }, {.name =3D "vcpucount", .handler =3D cmdVcpucount, .opts =3D opts_vcpucount, --=20 2.32.0 From nobody Fri Apr 26 17:27:02 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=1631545017; cv=none; d=zohomail.com; s=zohoarc; b=jEyXQGGAITQxKWk5oF9fjYkqrN3fvrGEeKSB9mpKt0LmfeW8lwMUnkr91Enml/lUYpL7DoKEtqgZ6Wt9EVvlKWyt9YjxHEWApJef16dC/YTZW3/QpVcaXDW9cWMU9YAanzujga7Kg3tcnLiA0f8FtlpsQG9WOKUedxYdAOXDITA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631545017; h=Content-Type:Content-Transfer-Encoding:Cc: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=W0+tW3PE7vDXTog90oU7XZgKzgd9+p6PhwM/Ebwzwb8=; b=hbCJ+RP7i/ViOpEn0tPZt0IjChJVx+t4f+xkizPcmpKnI5gnHXsFGYUn/4CYxUYG/7k4WSu2TqhtjYb8dbjFrPBs30DtWkgpK2pY481tr0B6orEq65SSuJOba67o/9leqINcja6+a0ASCi5xnulyKEcI1jxD1m6sQz/jerIb/Ys= 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) 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 1631545017501159.86821852338335; Mon, 13 Sep 2021 07:56:57 -0700 (PDT) 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-289-CK_eUC4_OyuDrPiwMauewA-1; Mon, 13 Sep 2021 10:56:54 -0400 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 1890B835DFA; Mon, 13 Sep 2021 14:56:46 +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 EECC85C1D1; Mon, 13 Sep 2021 14:56:45 +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 C23F21800B8B; Mon, 13 Sep 2021 14:56:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DEraYV021279 for ; Mon, 13 Sep 2021 10:53:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A717188E4; Mon, 13 Sep 2021 14:53:36 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9353F6A8F5; Mon, 13 Sep 2021 14:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631545016; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=W0+tW3PE7vDXTog90oU7XZgKzgd9+p6PhwM/Ebwzwb8=; b=D5WHThBj/DUo1ryyqxMDwOpKxDCIsUSmj3N1M9dGxHbXJ988JNEqa0DqP4SXn3SlcqR57i E2fXVHjiCCsdUBm+kBqF5e78TZC0CH/fJZAX/Brh0FJaJd1OztRKbIRw1kds9t9G6dooC7 UYH4xxssLS8d4WxHSomKB2TNGsiEjJM= X-MC-Unique: CK_eUC4_OyuDrPiwMauewA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 15/16] news: document recent virtio memory addition Date: Mon, 13 Sep 2021 16:52:43 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631545017978100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- NEWS.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 4521499db7..68afc01633 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -17,6 +17,13 @@ v7.8.0 (unreleased) =20 * **New features** =20 + * Introduce virtio-mem ```` model + + New virtio-mem model is introduced for ```` device which is a + paravirtualized mechanism of adding/removing memory to/from a VM. Use + ``virDomainUpdateDeviceFlags()`` API to adjust amount of memory or ``v= irsh + update-memory-device`` for convenience. + * **Improvements** =20 * **Bug fixes** --=20 2.32.0 From nobody Fri Apr 26 17:27:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1631545017; cv=none; d=zohomail.com; s=zohoarc; b=HNGc+NAfT7cs8jEhj0ayB8mCKAX56Qu3Thb2PTzzM+qr8/LPmgv3kZGotuL8klQE7hpVWB1kR3rqgwmTBUCzHgTyFrIpCPW0M8uU8XtIcGIkutjD62HbzPiFze3kRrsxkSiRL82HJ2AlJ1f1qQAFWCN0OHP9FQP75c0C3QpzWmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631545017; h=Content-Type:Content-Transfer-Encoding:Cc: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=5Vr7xtZchMYJKtgaloUBkg9wcCFoqRpocUrkk7NGsFM=; b=ZeuCh7Fs3Iw2z83287+kD1hGjpf6Dd795StEvZTUTug7jg78t8QbUX60P9LrenfBBG/0YayupYLMa1bf6ud0Psd7LOtexDfIQZgtIpoeACanwRklrQAytptHWK7F2pE4FmYUYe7IBAduD2g8u6DMJropibHWS1XwRpfymxAUcpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631545017818228.7739532965178; Mon, 13 Sep 2021 07:56:57 -0700 (PDT) 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-554-fek2c_rsOYGtIxP-y4PaiA-1; Mon, 13 Sep 2021 10:56:54 -0400 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 CDBBE100F968; Mon, 13 Sep 2021 14:56: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 6B2B35C23A; Mon, 13 Sep 2021 14:56: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 3C2064EA30; Mon, 13 Sep 2021 14:56:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18DErevo021296 for ; Mon, 13 Sep 2021 10:53:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 668696B556; Mon, 13 Sep 2021 14:53:40 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB86E6A8F5; Mon, 13 Sep 2021 14:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631545016; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=5Vr7xtZchMYJKtgaloUBkg9wcCFoqRpocUrkk7NGsFM=; b=JuYSA45RPALI6awDsXtmydlKGGAMMx16fWKg48LQ+M7tXG4ILjTZ22+PXR9A/blMO0hcP0 FkU42if3IeW05Kcyf9UVUG5+JlZ3+6R8tsbQ0gVr6+NZ2VQ49LGf/FhGwdwYG9Tz0pZ1Fm cA2+eFW1Xb2xheiSY4y87U5zG4mPW3M= X-MC-Unique: fek2c_rsOYGtIxP-y4PaiA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 16/16] kbase: Document virtio-mem Date: Mon, 13 Sep 2021 16:52:44 +0200 Message-Id: <551845aee7c2a5e5ebe34833ef33eaff510f4cc3.1631544341.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1631545020023100005 Content-Type: text/plain; charset="utf-8" This commit adds new memorydevices.rst page which should serve all models of memory devices. Yet, I'm documenting virtio-mem quirks only. Signed-off-by: Michal Privoznik --- docs/kbase/index.rst | 4 + docs/kbase/memorydevices.rst | 150 +++++++++++++++++++++++++++++++++++ docs/kbase/meson.build | 1 + 3 files changed, 155 insertions(+) create mode 100644 docs/kbase/memorydevices.rst diff --git a/docs/kbase/index.rst b/docs/kbase/index.rst index 351ea2c93b..09b19ed1af 100644 --- a/docs/kbase/index.rst +++ b/docs/kbase/index.rst @@ -52,6 +52,10 @@ Usage `PCI topology <../pci-addresses.html>`__ Addressing schemes for PCI devices =20 +`Memory devices `__ + Memory devices and their use + + Internals / Debugging --------------------- =20 diff --git a/docs/kbase/memorydevices.rst b/docs/kbase/memorydevices.rst new file mode 100644 index 0000000000..7f58a4247b --- /dev/null +++ b/docs/kbase/memorydevices.rst @@ -0,0 +1,150 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Memory devices +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. contents:: + +Basics +=3D=3D=3D=3D=3D=3D + +Memory devices can be divided into two families: volatile and non-volatile. +The former is typical RAM memory: it's volatile and thus its contents does= n't +survive guest reboots or power cycles. The latter retains its contents acr= oss +reboots or power outages. + +In Libvirt, there are two models for volatile memory: + +* ``dimm`` model: + + :: + + + + 523264 + 0 + +
+ + +* ``virtio-mem`` model: + + :: + + + + 1048576 + 0 + 2048 + 524288 + +
+ + +Then there are two models for non-volatile memory: + +* ``nvdimm`` model: + + :: + + + + /tmp/nvdimm + + + 523264 + 0 + +
+ + +* ``virtio-pmem`` model: + + :: + + + + /tmp/virtio_pmem + + + 524288 + +
+ + + +Please note that (maybe somewhat surprisingly) virtio models go onto PCI b= us +instead of DIMM slots. + +Furthermore, DIMMs can have ```` element which configures backend= for +devices. For NVDIMMs the element is mandatory and reflects where the conte= nt +is saved. + +See `memory devices documentation <../formatdomain.html#elementsMemory>`_. + +``virtio-mem`` model +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The ``virtio-mem`` model can be viewed as revised memory balloon. It offers +adding and removing memory (without the actual hotplug of the device). It +solves problems that memory balloon can't solve on its own and thus is more +flexible than DIMM + balloon solution. ``virtio-mem`` is NUMA aware, and t= hus +memory can be inflated/deflated only for a subset of guest NUMA nodes. Al= so, +it works with chunks that are either exposed to guest or reclaimed from it. + +See https://virtio-mem.gitlab.io/ + +Under the hood, ``virtio-mem`` device is split into chunks of equal size w= hich +are then exposed to the guest. Either all of them or only a portion depend= ing +on user's request. Therefore there are three important sizes for +``virtio-mem``. All are to be found under ```` element: + +#. The maximum size the device can ever offer, exposed under ```` +#. The size of a single block, exposed under ```` +#. The current size exposed to the guest, exposed under ```` + +For instance, in the following example the maximum size is 4GiB, the block= size +is 2MiB and only 1GiB should be exposed to the guest: + + :: + + + + 4194304 + 2048 + 1048576 + + + +Please note that ```` must be an integer multiple of ```` +size or zero (no blocks exposed to the guest) and has to be less or equal = to +```` (all blocks exposed to the guest). Furthermore, QEMU recommend= s the +```` size to be as big as a Transparent Huge Page (usually 2MiB). + +To change the size exposed to the guest, users should pass memory device X= ML +with nothing but ```` changed into the +``virDomainUpdateDeviceFlags()`` API. For user's convenience this can be d= one +via virsh too: + + :: + + # virsh update-memory-device $dom --requested-size 2GiB + +If there are two or more ```` devices then ``--alias`` shall be u= sed +to tell virsh which memory device should be updated. + +For running guests there is fourth size that can be found under ````: + + :: + + 2097152 + +The ```` reflects the current size used by the guest. In general= it +can differ from ````. Reasons include guest kernel missing +``virtio-mem`` module and thus being unable to take offered memory, or gue= st +kernel being unable to free memory. Since ```` only reports siz= e to +users, the element is never parsed. It is formatted only into live XML. + +Since changing ```` allocation requires cooperation with guest +kernel, requests for change are not instant. Therefore, libvirt emits +``VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE`` event whenever current +allocation changed. diff --git a/docs/kbase/meson.build b/docs/kbase/meson.build index 73dc11837f..af067db453 100644 --- a/docs/kbase/meson.build +++ b/docs/kbase/meson.build @@ -10,6 +10,7 @@ docs_kbase_files =3D [ 'locking-lockd', 'locking', 'locking-sanlock', + 'memorydevices', 'merging_disk_image_chains', 'migrationinternals', 'qemu-core-dump', --=20 2.32.0