From nobody Sun Feb 8 12:13:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154774761909097.90929655219975; Thu, 17 Jan 2019 09:53:39 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 1A3271326B7; Thu, 17 Jan 2019 17:53:36 +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 CF5E15ED52; Thu, 17 Jan 2019 17:53:35 +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 88E19180BAAC; Thu, 17 Jan 2019 17:53:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0HHrEQc005555 for ; Thu, 17 Jan 2019 12:53:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9C518600D6; Thu, 17 Jan 2019 17:53:14 +0000 (UTC) Received: from worklaptop.redhat.com (ovpn-122-144.rdu2.redhat.com [10.10.122.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C784600C6; Thu, 17 Jan 2019 17:53:14 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 17 Jan 2019 12:52:38 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/18] qemu: Move memballoon validation out of command.c 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 17 Jan 2019 17:53:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If we validate that memballoon is NONE or VIRTIO earlier, we can simplify some checks in some driver APIs Signed-off-by: Cole Robinson --- src/qemu/qemu_command.c | 17 ----------------- src/qemu/qemu_domain.c | 35 +++++++++++++++++++++++++++++++++- src/qemu/qemu_domain_address.c | 3 +-- src/qemu/qemu_driver.c | 9 +++------ src/qemu/qemu_process.c | 3 +-- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 56d52e1d7e..07fa2b9209 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4160,20 +4160,9 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd, { virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 - if (STRPREFIX(def->os.machine, "s390-virtio") && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon) - def->memballoon->model =3D VIR_DOMAIN_MEMBALLOON_MODEL_NONE; - if (!virDomainDefHasMemballoon(def)) return 0; =20 - if (def->memballoon->model !=3D VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Memory balloon device type '%s' is not supported= by this version of qemu"), - virDomainMemballoonModelTypeToString(def->memballoo= n->model)); - return -1; - } - if (qemuBuildVirtioDevStr(&buf, "virtio-balloon", def->memballoon->info.type) < 0) { goto error; @@ -4184,12 +4173,6 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd, goto error; =20 if (def->memballoon->autodeflate !=3D VIR_TRISTATE_SWITCH_ABSENT) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE= )) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("deflate-on-oom is not supported by this QEMU= binary")); - goto error; - } - virBufferAsprintf(&buf, ",deflate-on-oom=3D%s", virTristateSwitchTypeToString(def->memballoon->a= utodeflate)); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 08bb2f9ebc..d2c792e415 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3404,6 +3404,10 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, def->memballoon =3D memballoon; } =20 + if (STRPREFIX(def->os.machine, "s390-virtio") && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon) + def->memballoon->model =3D VIR_DOMAIN_MEMBALLOON_MODEL_NONE; + if (addDefaultUSBKBD && def->ngraphics > 0 && virDomainDefMaybeAddInput(def, @@ -5888,6 +5892,32 @@ qemuDomainDeviceDefValidateInput(const virDomainInpu= tDef *input, } =20 =20 +static int +qemuDomainDeviceDefValidateMemballoon(const virDomainMemballoonDef *membal= loon, + virQEMUCapsPtr qemuCaps) +{ + if (!memballoon || + memballoon->model =3D=3D VIR_DOMAIN_MEMBALLOON_MODEL_NONE) + return 0; + + if (memballoon->model !=3D VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Memory balloon device type '%s' is not supported= by this version of qemu"), + virDomainMemballoonModelTypeToString(memballoon->mo= del)); + return -1; + } + + if (memballoon->autodeflate !=3D VIR_TRISTATE_SWITCH_ABSENT && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deflate-on-oom is not supported by this QEMU bin= ary")); + return -1; + } + + return 0; +} + + static int qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info, virQEMUCapsPtr qemuCaps) @@ -5996,11 +6026,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDe= f *dev, ret =3D qemuDomainDeviceDefValidateInput(dev->data.input, def, qem= uCaps); break; =20 + case VIR_DOMAIN_DEVICE_MEMBALLOON: + ret =3D qemuDomainDeviceDefValidateMemballoon(dev->data.memballoon= , qemuCaps); + break; + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_HUB: - case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_MEMORY: diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index b7a1cbe2d1..09e0ce12c4 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -360,8 +360,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr de= f, def->hostdevs[i]->info->type =3D type; } =20 - if (def->memballoon && - def->memballoon->model =3D=3D VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO && + if (virDomainDefHasMemballoon(def) && def->memballoon->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_N= ONE) def->memballoon->info.type =3D type; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1d961707cc..949c09aba4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2436,8 +2436,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPt= r dom, int period, priv =3D vm->privateData; =20 if (def) { - if (!def->memballoon || - def->memballoon->model !=3D VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO= ) { + if (!virDomainDefHasMemballoon(def)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Memory balloon model must be virtio to set t= he" " collection period")); @@ -2460,8 +2459,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPt= r dom, int period, } =20 if (persistentDef) { - if (!persistentDef->memballoon || - persistentDef->memballoon->model !=3D VIR_DOMAIN_MEMBALLOON_MO= DEL_VIRTIO) { + if (!virDomainDefHasMemballoon(def)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Memory balloon model must be virtio to set t= he" " collection period")); @@ -11947,8 +11945,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriverPtr driv= er, if (virDomainObjCheckActive(vm) < 0) return -1; =20 - if (vm->def->memballoon && - vm->def->memballoon->model =3D=3D VIR_DOMAIN_MEMBALLOON_MODEL_VIRT= IO) { + if (virDomainDefHasMemballoon(vm->def)) { qemuDomainObjEnterMonitor(driver, vm); ret =3D qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm), vm->def->memballoon, stats, nr_sta= ts); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index aad6c12552..54abd9170a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7564,8 +7564,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UN= USED, if (running) { virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED); - if (vm->def->memballoon && - vm->def->memballoon->model =3D=3D VIR_DOMAIN_MEMBALLOON_MODEL_= VIRTIO && + if (virDomainDefHasMemballoon(vm->def) && vm->def->memballoon->period) { qemuDomainObjEnterMonitor(driver, vm); qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list