From patchwork Wed Jan 23 21:32:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 156401 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1201490jaa; Wed, 23 Jan 2019 13:33:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN50vXr5DLqz+zd6JrmH1rU7hKkMcAFaR+f/ujeaZ78mABpBYQttz5oHe1JuZA4TXLIGgEyM X-Received: by 2002:a37:af42:: with SMTP id y63mr3219877qke.251.1548279213753; Wed, 23 Jan 2019 13:33:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548279213; cv=none; d=google.com; s=arc-20160816; b=YgBJPzpOYMPgh3pb0vYTxNTl9uHAH4EEle7QlJpCLZG47v4mo+iJViFYcOFFoG65H+ b4RXvht7/bTl+CGs1gK7hOI76t1o270CWzLx7Wzdw/bns7fzI2qnORfVbapziKWvxY4l t+Gr737GzLHdMANNvxOyusy0rFzMzouRYCNez3iEGKI3EQHyLb9aX97c14TObSaHXrSQ 1np0jHZf+Wf74QCipG/66ujkJGQfbyvYUbspBjiV8bG4MiqMGO3Lry/PnnJqtvZzY+xp WcJ00TxFgTHxwPvK0In8vK+CySxyIm3LEWyLh5bb3LRyN+lKyGTUrHmMqg+D3wAc7+e6 l7Nw== 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=0jh5bKjab9wzQfj4u5tcK1OcmRQr2GwG0GsAVceIBO0=; b=JMJ7/+T7gtdFvG6jFhEOM0oJTmy5uzXYSGSk/HOtZX/ba8jUdu2Iyl1bS6ehXHIgb4 hE+4OLlt55WJAxzPCBOzBa9LDHNDdgHJxkLBnjrEQWVqygilbs931Nuc4q8GkDtEOeSm efLB81gzHrwISggPHt2fc5YCQ1obQQX4rKb4mWpGvub+La79FkVpLtkVjUc0dpV0lQDi Yjg77unEpEKzP9EBvZtmzOix1qpJq1jg6PyWaq1Wt/a6c5yKQIMxnBTJwDU8JES+idcC hEnyhivw5QWazKAiQRk93cnY1igcLnbDsqfQlpBEH5KF7QEh23PFWiDMyIjlgqqQ7j5f wWQw== 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 k15si3289170qke.86.2019.01.23.13.33.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 13:33:33 -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 186D87FDF3; Wed, 23 Jan 2019 21:33:32 +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 C746B6C212; Wed, 23 Jan 2019 21:33:31 +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 731B318033A1; Wed, 23 Jan 2019 21:33:31 +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 x0NLXIhj032268 for ; Wed, 23 Jan 2019 16:33:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id CFC00BA8B; Wed, 23 Jan 2019 21:33:18 +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 F2EA8BA96; Wed, 23 Jan 2019 21:33:17 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 23 Jan 2019 16:32:32 -0500 Message-Id: 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 04/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.14 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:32 +0000 (UTC) Move the rng->model == VIRTIO check to parse time. This also allows us to remove similar checks throughout the qemu driver Signed-off-by: Cole Robinson --- src/qemu/qemu_command.c | 8 -------- src/qemu/qemu_domain.c | 23 +++++++++++++++++++++-- src/qemu/qemu_domain_address.c | 9 ++++----- tests/qemuxml2xmltest.c | 9 ++++++--- 4 files changed, 31 insertions(+), 18 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 2d05b4a93b..bbc85e75f0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5871,14 +5871,6 @@ qemuBuildRNGDevStr(const virDomainDef *def, { virBuffer buf = VIR_BUFFER_INITIALIZER; - if (dev->model != VIR_DOMAIN_RNG_MODEL_VIRTIO || - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_RNG)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("this qemu doesn't support RNG device type '%s'"), - virDomainRNGModelTypeToString(dev->model)); - goto error; - } - if (!qemuDomainCheckCCWS390AddressSupport(def, dev->info, qemuCaps, dev->source.file)) goto error; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a0ab55d5db..27cdb30ca2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4536,12 +4536,31 @@ qemuDomainSmartcardDefValidate(const virDomainSmartcardDef *def) static int -qemuDomainRNGDefValidate(const virDomainRNGDef *def) +qemuDomainRNGDefValidate(const virDomainRNGDef *def, + virQEMUCapsPtr qemuCaps) { + bool model_supported = false; + if (def->backend == VIR_DOMAIN_RNG_BACKEND_EGD && qemuDomainChrSourceDefValidate(def->source.chardev) < 0) return -1; + switch ((virDomainRNGModel) def->model) { + case VIR_DOMAIN_RNG_MODEL_VIRTIO: + model_supported = virQEMUCapsGet(qemuCaps, + QEMU_CAPS_DEVICE_VIRTIO_RNG); + break; + case VIR_DOMAIN_RNG_MODEL_LAST: + break; + } + + if (!model_supported) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("this qemu doesn't support RNG device type '%s'"), + virDomainRNGModelTypeToString(def->model)); + return -1; + } + return 0; } @@ -6073,7 +6092,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, break; case VIR_DOMAIN_DEVICE_RNG: - ret = qemuDomainRNGDefValidate(dev->data.rng); + ret = qemuDomainRNGDefValidate(dev->data.rng, qemuCaps); break; case VIR_DOMAIN_DEVICE_REDIRDEV: diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 1802c36b86..f2ae0804a8 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -364,8 +364,8 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def, def->memballoon->info.type = type; for (i = 0; i < def->nrngs; i++) { - if (def->rngs[i]->model == VIR_DOMAIN_RNG_MODEL_VIRTIO && - def->rngs[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) + /* All devices accepted by the qemu driver are virtio */ + if (def->rngs[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) def->rngs[i]->info.type = type; } @@ -2276,10 +2276,9 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def, goto error; } - /* VirtIO RNG */ + /* rng. the qemu driver only accepts virtio rng devices */ for (i = 0; i < def->nrngs; i++) { - if (def->rngs[i]->model != VIR_DOMAIN_RNG_MODEL_VIRTIO || - !virDeviceInfoPCIAddressIsWanted(&def->rngs[i]->info)) + if (!virDeviceInfoPCIAddressIsWanted(&def->rngs[i]->info)) continue; if (qemuDomainPCIAddressReserveNextAddr(addrs, &def->rngs[i]->info) < 0) diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 82e2c0ee0f..b2c0c8505d 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -585,8 +585,10 @@ mymain(void) DO_TEST("disk-serial", NONE); - DO_TEST("virtio-rng-random", NONE); - DO_TEST("virtio-rng-egd", NONE); + DO_TEST("virtio-rng-random", + QEMU_CAPS_DEVICE_VIRTIO_RNG); + DO_TEST("virtio-rng-egd", + QEMU_CAPS_DEVICE_VIRTIO_RNG); DO_TEST("pseries-nvram", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE); @@ -1019,7 +1021,8 @@ mymain(void) DO_TEST("disk-backing-chains-index", NONE); DO_TEST("disk-backing-chains-noindex", NONE); - DO_TEST("chardev-label", NONE); + DO_TEST("chardev-label", + QEMU_CAPS_DEVICE_VIRTIO_RNG); DO_TEST("cpu-numa1", NONE); DO_TEST("cpu-numa2", NONE);