From patchwork Thu Jan 17 17:52:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 155870 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2257814jaa; Thu, 17 Jan 2019 09:53:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN6FkBZCPmRqIqMw8IVe52VNWw5u1iYePD1G019ul69WXhFzg4X2h6MBs6DtKzM47SCvMMdD X-Received: by 2002:ac8:1b82:: with SMTP id z2mr12651289qtj.321.1547747618562; Thu, 17 Jan 2019 09:53:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547747618; cv=none; d=google.com; s=arc-20160816; b=eWZRFbZzzT52nxl0OWxGqfH3odV/x+xfVVj6heQOfuVnUvearQU/pa88TXBEuvg8Bi oBoirI/xtUkEOV643gYZzTAR96DoUPUVfrUIfzxKki6rMtwqkJwZ5ucSCxGzMQV1TW8j IPLN1SFU/OVBil7HkXPF80eEcIZcJ23btJG7rJCxDcDHwDUxBumG7nN48hcRGgHyy3Wk +pY1HxLtrbU6WC6v6oiV2b+2x5Gu8L/LuK3UeeuGqm2DLzG84ECQ8zz9gTJ/qzWBqfBz D2gUIrAsy755MGeoP9OBGLJbzcxEKWHs0QwCBRq8eXGxiXz1XeA7Xl7OTDkBh1HKLkUm ImGw== 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=olzPSRtXzCI6uo4AKWT/NQTM1xeO0vjJK2WL8z+ahBg=; b=sMrpeCNE3hGGiI2vyl8cUdjioYNw8xLbWCCeMRNPTMXotgSb0lx+7U7lmUHW/GgPOL hprU9qpZM5gdhOPJzy2pdayM/2u7pEDLr5lyjGUyjM9+4qu4ZhBMpKYjo+6g8k+fciVb PXjHeqNnVzMRHoA1xmVdcJlurELUeevn4kLGfAd9iW3KkfjMatJSl3DR6B+jNGuf/jFY fFRj4VC/7Yx32pDgvrq9qVUUW1U/ji/2kNHAQam9RdlYX+txPPherUOXBbTQKeXPFjvT syLaKXXw+eiqb/HFfWCgmP4hs3CspqcMORx8h2IM0Pl+Q2Z+l4odeh9DGOkZAbinUXBT pv1A== 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 i127si5636048qkd.79.2019.01.17.09.53.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 09:53:38 -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-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) Delivered-To: libvirt-list@redhat.com 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: , 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) 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(-) -- 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 56d52e1d7e..07fa2b9209 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4160,20 +4160,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; @@ -4184,12 +4173,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 08bb2f9ebc..d2c792e415 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3404,6 +3404,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, @@ -5888,6 +5892,32 @@ 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) @@ -5996,11 +6026,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 b7a1cbe2d1..09e0ce12c4 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -360,8 +360,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def, def->hostdevs[i]->info->type = type; } - if (def->memballoon && - def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO && + if (virDomainDefHasMemballoon(def) && def->memballoon->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) def->memballoon->info.type = type; 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(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")); @@ -2460,8 +2459,7 @@ 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")); @@ -11947,8 +11945,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 aad6c12552..54abd9170a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7564,8 +7564,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,