From patchwork Wed Jan 23 21:32:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 156400 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1201440jaa; Wed, 23 Jan 2019 13:33:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN6aglL5oJjxKVWTJHvPSxirq6dqEh2F5q8eMeybbbnKce0i2Lsy53X4zZG/L5qbbqpaepG2 X-Received: by 2002:a37:4d03:: with SMTP id a3mr3341323qkb.181.1548279209527; 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=1HlJKdGFHzloRjika4BxetV4pVEvkKZ5tjdncSNq2kCvawKbTJdQYgDDFtcGZjLsMn e5wLzbYFfA7efWhxStN4RwtN6Y1lEMNqfVHJOuuWy8OwojKp1JAp0FV4Fv8eovgz3Ew2 dDrXyEBVb3QIM930uqNygs3kQhi9EVIwUxNO+4Tcd+yaLvjxX7bNXoYJpVaxp+u10SoH 2mn/MBy351MQtsmZkZ/mthiE+8bOs4xFMvYb3dIO1TzXf2MoZOJZBYV1+YyuxTcT+hpa 1MaYb9Q4N/4sEjxkoYlB7BhryN8QYkXe0aXzfedkN12F+Dsb62nV/LZ/mOGTzagVdmiO 9fAg== 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=3/Fdey+3TKVytSTM7C5BST5pdfHLOYxpkvJnmKJADxw=; b=IPCfi07ZkXsKcxerUtHMrUuENwEv3cDFXdiST2wbRlVukA2Z4GmzlGzJXrmrWol8v7 vSZOPhNlF2Yp/+o0D1f3dP5UF8AwlOpIuATcZlt4wx1ZMVSM/hu3xyGwgkGoDRziaE1w RQxd8b3Ulg7CDvHDwxRYEpOr4AXVRsgbRd1TTZ1vcjEQE6Ne9NkGWPQzJIXkysnxAFeo HFTHXLm5MUh0Z78XIbrwS4mHv8J7LMIPmq12A8OuA8jXzZqfHR277iueZFflwDgFh2oc trZirbs9MxEAwsxbF0sSwAivSGtEQcul+9fMP5xFjcQ/0MyaKT2L6NW37BCb7nxd09EQ hyyA== 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 j90si1036694qtd.27.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-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 mx1.redhat.com (Postfix) with ESMTPS id C2E1512F91F; 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 91FF565F72; 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 4BF4B180BAAC; 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 x0NLXGYP032253 for ; Wed, 23 Jan 2019 16:33:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB4B3BA8B; Wed, 23 Jan 2019 21:33:16 +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 E993DBA50; Wed, 23 Jan 2019 21:33:15 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 23 Jan 2019 16:32:30 -0500 Message-Id: <47ddb9fa42a14fdb72e1dfd8d4a66752ebee00ea.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 02/25] conf: Add virDomainNetIsVirtioModel 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 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 23 Jan 2019 21:33:28 +0000 (UTC) This will be extended in the future, so let's simplify things by centralizing the checks. Signed-off-by: Cole Robinson --- src/conf/domain_conf.c | 15 +++++++++++---- src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_domain_address.c | 2 +- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_interface.c | 8 ++++---- src/security/virt-aa-helper.c | 2 +- tests/qemuxml2argvmock.c | 2 +- 10 files changed, 23 insertions(+), 14 deletions(-) -- 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Reviewed-by: Andrea Bolognani diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 564248e021..bcdb6b0a3a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4732,7 +4732,7 @@ virDomainDeviceDefPostParseCommon(virDomainDeviceDefPtr dev, if (dev->type == VIR_DOMAIN_DEVICE_NET) { virDomainNetDefPtr net = dev->data.net; - if (STRNEQ_NULLABLE(net->model, "virtio") && + if (!virDomainNetIsVirtioModel(net) && virDomainCheckVirtioOptions(net->virtio) < 0) return -1; } @@ -11338,7 +11338,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, break; case VIR_DOMAIN_NET_TYPE_VHOSTUSER: - if (STRNEQ_NULLABLE(def->model, "virtio")) { + if (!virDomainNetIsVirtioModel(def)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Wrong or no 'type' attribute " "specified with . " @@ -11567,7 +11567,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, } if (def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && - STREQ_NULLABLE(def->model, "virtio")) { + virDomainNetIsVirtioModel(def)) { if (backend != NULL) { if ((val = virDomainNetBackendTypeFromString(backend)) < 0 || val == VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT) { @@ -25462,7 +25462,7 @@ virDomainNetDefFormat(virBufferPtr buf, if (def->model) { virBufferEscapeString(buf, "\n", def->model); - if (STREQ(def->model, "virtio")) { + if (virDomainNetIsVirtioModel(def)) { char *str = NULL, *gueststr = NULL, *hoststr = NULL; int rc = 0; @@ -29716,6 +29716,13 @@ virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface) } +bool +virDomainNetIsVirtioModel(const virDomainNetDef *net) +{ + return STREQ_NULLABLE(net->model, "virtio"); +} + + /* Return listens[i] from the appropriate union for the graphics * type, or NULL if this is an unsuitable type, or the index is out of * bounds. If force0 is TRUE, i == 0, and there is no listen array, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7776a3afb2..218aa4dd94 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3217,6 +3217,7 @@ virNetDevBandwidthPtr virDomainNetGetActualBandwidth(virDomainNetDefPtr iface); virNetDevVlanPtr virDomainNetGetActualVlan(virDomainNetDefPtr iface); bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface); +bool virDomainNetIsVirtioModel(const virDomainNetDef *net); int virDomainNetAppendIPAddress(virDomainNetDefPtr def, const char *address, int family, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c3d6306809..6f4809a68a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -469,6 +469,7 @@ virDomainNetGetActualType; virDomainNetGetActualVirtPortProfile; virDomainNetGetActualVlan; virDomainNetInsert; +virDomainNetIsVirtioModel; virDomainNetNotifyActualDevice; virDomainNetReleaseActualDevice; virDomainNetRemove; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2fb7d32dd4..128cf331b3 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3654,7 +3654,7 @@ qemuBuildNicDevStr(virDomainDefPtr def, bool usingVirtio = false; char macaddr[VIR_MAC_STRING_BUFLEN]; - if (STREQ(net->model, "virtio")) { + if (virDomainNetIsVirtioModel(net)) { if (qemuBuildVirtioDevStr(&buf, "virtio-net", net->info.type) < 0) goto error; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 32a43f2064..1376819020 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4665,7 +4665,7 @@ qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net) return -1; } - if (STREQ_NULLABLE(net->model, "virtio")) { + if (virDomainNetIsVirtioModel(net)) { if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("rx_queue_size has to be a power of two")); diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 9e0b50d41e..cb1e5f9e40 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -320,7 +320,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def, for (i = 0; i < def->nnets; i++) { virDomainNetDefPtr net = def->nets[i]; - if (STREQ_NULLABLE(net->model, "virtio") && + if (virDomainNetIsVirtioModel(net) && net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { net->info.type = type; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1df80fcab6..5894c3dd49 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3710,7 +3710,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, goto cleanup; } - if (olddev->model && STREQ(olddev->model, "virtio") && + if (virDomainNetIsVirtioModel(olddev) && (olddev->driver.virtio.name != newdev->driver.virtio.name || olddev->driver.virtio.txmode != newdev->driver.virtio.txmode || olddev->driver.virtio.ioeventfd != newdev->driver.virtio.ioeventfd || diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 2607dea1f5..2816db908a 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -261,7 +261,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP; - if (net->model && STREQ(net->model, "virtio")) + if (virDomainNetIsVirtioModel(net)) macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR; if (virNetDevMacVLanCreateWithVPortProfile(net->ifname, @@ -434,7 +434,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, template_ifname = true; } - if (net->model && STREQ(net->model, "virtio")) + if (virDomainNetIsVirtioModel(net)) tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR; if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, tapfdSize, @@ -533,7 +533,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, template_ifname = true; } - if (net->model && STREQ(net->model, "virtio")) + if (virDomainNetIsVirtioModel(net)) tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR; if (virQEMUDriverIsPrivileged(driver)) { @@ -653,7 +653,7 @@ qemuInterfaceOpenVhostNet(virDomainDefPtr def, } /* If the nic model isn't virtio, don't try to open. */ - if (!(net->model && STREQ(net->model, "virtio"))) { + if (!virDomainNetIsVirtioModel(net)) { if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("vhost-net is only supported for " diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 46443a3153..56d7cfadf1 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1255,7 +1255,7 @@ get_files(vahControl * ctl) if (net && net->model) { if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_QEMU) continue; - if (STRNEQ(net->model, "virtio")) + if (!virDomainNetIsVirtioModel(net)) continue; } needsvhost = true; diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index b300793732..3f0c1c3fef 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -228,7 +228,7 @@ qemuInterfaceOpenVhostNet(virDomainDefPtr def ATTRIBUTE_UNUSED, { size_t i; - if (!(net->model && STREQ(net->model, "virtio"))) { + if (!virDomainNetIsVirtioModel(net)) { *vhostfdSize = 0; return 0; }