From patchwork Wed Jan 23 21:32:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 156399 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1201437jaa; Wed, 23 Jan 2019 13:33:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN7L71O52dehIb4mAhvnGmaIB3AYak1X3o9t49aFaMlHhEubE38TxmdYkLGyWjvexbEYq/ZH X-Received: by 2002:ac8:31ed:: with SMTP id i42mr4082903qte.323.1548279209330; Wed, 23 Jan 2019 13:33:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548279209; cv=none; d=google.com; s=arc-20160816; b=EZ6EVqeFykXm4fitCi5tyWxmAwcpnHYN+N+TpA6ATsrZT1n4qlZVdoJ3VMGGUQ0j0j xTSBbrQ3CR6KnVo4Jmm9Lr648Bkj4aQn8e5EC2+v5LSfdSL8NAu+/8QCEnfgiNzwAhwn X/oSfblM7bJpZrU7UWfYcuJUN11GrAcf5m5a7Wcjicb0kQ+KHxHLcCyn6uunl01fwAar uM/SrLUR28ihdDQefa4Ycc2nI+JskKbcB6m/Ql9g0ZehI9jVLyVqHORyyd8M+CbDc0Kv cnI/syFlqB/RLfjM1SShMhBYElCoFIJePjol9Tlx3FxZUaKR0A6f+EjsLAhBDqHwDeZp Atjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=K2kL8qqcxUhITNw95t0TAVxPljuK0vfR7A88Ea7mLek=; b=c9sGntyLkzzSXiCOB3lVvii1D98fTDZSKBLmvcfx0yCpZ0m0L94sA8PiWxgyDXznG3 /9plReDeWg4O8NWmk8xgEDyLbAelnWE8Fq3RTr7J6slezw1HoPf4nyVdqt33kMPeNYFy 2QlpPtHXSufqK/bSHVmbRUfcqxhN0CjNzZP+d2+EvNbCmNbOIeZhXVpob7/y0Nh1yDFz iFw53dVUoLgjbMCnpaOd4POqzndF/BdluYNyT3RoF6dxYwwG6NRiLJVZgIsju6WMJNVv u+jJiJjAOxTbAmKtNkeAf9oeTcsX6nO1GqbtYQ0FO446iPCMIhyChYRH6ouaoYfepCB7 5bDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id t1si2675224qkj.73.2019.01.23.13.33.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 13:33:29 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 mx1.redhat.com (Postfix) with ESMTPS id D8BC77FDE6; Wed, 23 Jan 2019 21:33:27 +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 9BAB360469; Wed, 23 Jan 2019 21:33: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 54CAB18033A1; Wed, 23 Jan 2019 21:33:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0NLXHXK032261 for ; Wed, 23 Jan 2019 16:33:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id B09A8BA8B; Wed, 23 Jan 2019 21:33:17 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-120-34.rdu2.redhat.com [10.10.120.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE851BA50; Wed, 23 Jan 2019 21:33:16 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 23 Jan 2019 16:32:31 -0500 Message-Id: <4125ca8687d60bf72f717b5642adf6cf95739759.1548278585.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/25] qemu: Move validation out of qemu_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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 23 Jan 2019 21:33:28 +0000 (UTC) If we validate that memballoon is NONE|VIRTIO at parse time, we can drop similar checks elsewhere in the qemu driver Signed-off-by: Cole Robinson --- src/qemu/qemu_command.c | 17 ---------------- src/qemu/qemu_domain.c | 36 +++++++++++++++++++++++++++++++++- src/qemu/qemu_domain_address.c | 10 ++++------ src/qemu/qemu_driver.c | 17 +++++++--------- src/qemu/qemu_process.c | 3 +-- 5 files changed, 47 insertions(+), 36 deletions(-) -- 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 128cf331b3..2d05b4a93b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4046,20 +4046,9 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd, { virBuffer buf = VIR_BUFFER_INITIALIZER; - if (STRPREFIX(def->os.machine, "s390-virtio") && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon) - def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE; - if (!virDomainDefHasMemballoon(def)) return 0; - if (def->memballoon->model != 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->memballoon->model)); - return -1; - } - if (qemuBuildVirtioDevStr(&buf, "virtio-balloon", def->memballoon->info.type) < 0) { goto error; @@ -4070,12 +4059,6 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd, goto error; if (def->memballoon->autodeflate != 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=%s", virTristateSwitchTypeToString(def->memballoon->autodeflate)); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1376819020..a0ab55d5db 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3481,6 +3481,10 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, def->memballoon = memballoon; } + if (STRPREFIX(def->os.machine, "s390-virtio") && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_S390) && def->memballoon) + def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE; + if (addDefaultUSBKBD && def->ngraphics > 0 && virDomainDefMaybeAddInput(def, @@ -5980,6 +5984,33 @@ qemuDomainDeviceDefValidateInput(const virDomainInputDef *input, } +static int +qemuDomainDeviceDefValidateMemballoon(const virDomainMemballoonDef *memballoon, + virQEMUCapsPtr qemuCaps) +{ + if (!memballoon || + memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) { + return 0; + } + + if (memballoon->model != 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->model)); + return -1; + } + + if (memballoon->autodeflate != 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 binary")); + return -1; + } + + return 0; +} + + static int qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info, virQEMUCapsPtr qemuCaps) @@ -6088,11 +6119,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, ret = qemuDomainDeviceDefValidateInput(dev->data.input, def, qemuCaps); break; + case VIR_DOMAIN_DEVICE_MEMBALLOON: + ret = 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 cb1e5f9e40..1802c36b86 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -358,8 +358,8 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def, def->hostdevs[i]->info->type = type; } - if (def->memballoon && - def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO && + /* All memballoon devices accepted by the qemu driver are virtio */ + if (virDomainDefHasMemballoon(def) && def->memballoon->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) def->memballoon->info.type = type; @@ -2268,11 +2268,9 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, goto error; } - /* VirtIO balloon */ - if (def->memballoon && - def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO && + /* memballoon. the qemu driver only accepts virtio memballoon devices */ + if (virDomainDefHasMemballoon(def) && virDeviceInfoPCIAddressIsWanted(&def->memballoon->info)) { - if (qemuDomainPCIAddressReserveNextAddr(addrs, &def->memballoon->info) < 0) goto error; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 90319261ff..26a83a754b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2439,11 +2439,10 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, priv = vm->privateData; if (def) { - if (!def->memballoon || - def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { + if (!virDomainDefHasMemballoon(def)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Memory balloon model must be virtio to set the" - " collection period")); + _("No memory balloon device configured, " + "can not set the collection period")); goto endjob; } @@ -2463,11 +2462,10 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period, } if (persistentDef) { - if (!persistentDef->memballoon || - persistentDef->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { + if (!virDomainDefHasMemballoon(def)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Memory balloon model must be virtio to set the" - " collection period")); + _("No memory balloon device configured, " + "can not set the collection period")); goto endjob; } persistentDef->memballoon->period = period; @@ -11964,8 +11962,7 @@ qemuDomainMemoryStatsInternal(virQEMUDriverPtr driver, if (virDomainObjCheckActive(vm) < 0) return -1; - if (vm->def->memballoon && - vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) { + if (virDomainDefHasMemballoon(vm->def)) { qemuDomainObjEnterMonitor(driver, vm); ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm), vm->def->memballoon, stats, nr_stats); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8120201eb6..9ccc3601a2 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7593,8 +7593,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, if (running) { virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED); - if (vm->def->memballoon && - vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO && + if (virDomainDefHasMemballoon(vm->def) && vm->def->memballoon->period) { qemuDomainObjEnterMonitor(driver, vm); qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,