From nobody Fri May 3 09:58:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1624013368334862.3525580187452; Fri, 18 Jun 2021 03:49:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-566-lrbnCxPRPU6huup8Ai4fZA-1; Fri, 18 Jun 2021 06:49:24 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CD621932482; Fri, 18 Jun 2021 10:49:18 +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 7B7B610016F4; Fri, 18 Jun 2021 10:49:13 +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 953A71809C99; Fri, 18 Jun 2021 10:49:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15IAkTHP020065 for ; Fri, 18 Jun 2021 06:46:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id DE91ED7B0C; Fri, 18 Jun 2021 10:46:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9236D7B11 for ; Fri, 18 Jun 2021 10:46:25 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 05D49803D56 for ; Fri, 18 Jun 2021 10:46:25 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-fYRDr2UnMQiM1oGpR4UBdA-1; Fri, 18 Jun 2021 06:46:23 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15IAY8i7153187 for ; Fri, 18 Jun 2021 06:46:22 -0400 Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 398rettvf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 18 Jun 2021 06:46:21 -0400 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 15IAbZdF002385 for ; Fri, 18 Jun 2021 10:46:19 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06fra.de.ibm.com with ESMTP id 394m6h9t8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 18 Jun 2021 10:46:19 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 15IAkGHC15008054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jun 2021 10:46:16 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 65578A4062; Fri, 18 Jun 2021 10:46:16 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 344C5A405F; Fri, 18 Jun 2021 10:46:16 +0000 (GMT) Received: from t46lp68.lnxne.boe (unknown [9.152.108.100]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 18 Jun 2021 10:46:16 +0000 (GMT) X-MC-Unique: lrbnCxPRPU6huup8Ai4fZA-1 X-MC-Unique: fYRDr2UnMQiM1oGpR4UBdA-1 From: Shalini Chellathurai Saroja To: libvir-list@redhat.com Subject: [PATCH libvirt v1] conf: verify for duplicate hostdevs Date: Fri, 18 Jun 2021 12:46:12 +0200 Message-Id: <20210618104612.279981-1-shalini@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ubvH6FW0yivxYPF4J8K0VgiE4tBnOILH X-Proofpoint-ORIG-GUID: ubvH6FW0yivxYPF4J8K0VgiE4tBnOILH X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-18_04:2021-06-18, 2021-06-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 mlxscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106180060 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: bwalk@linux.ibm.com, fiuczy@linux.ibm.com, shalini@linux.ibm.com 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is possible to define/edit(in shut off state) a domain XML with same hostdev device repeated more than once, as shown below. This behavior is not expected. So, this patch fixes it. vser1: [...] [...]
[...] $ virsh define vser1 Domain 'vser1' defined from vser1 Signed-off-by: Shalini Chellathurai Saroja Reviewed-by: Bjoern Walk Reviewed-by: Boris Fiuczynski Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 2 + src/conf/domain_validate.c | 21 ++++++++++ src/libvirt_private.syms | 1 + .../hostdev-mdev-duplicate.err | 1 + .../hostdev-mdev-duplicate.xml | 41 +++++++++++++++++++ .../hostdev-pci-duplicate.err | 1 + .../hostdev-pci-duplicate.xml | 40 ++++++++++++++++++ .../hostdev-scsi-duplicate.err | 1 + .../hostdev-scsi-duplicate.xml | 40 ++++++++++++++++++ .../hostdev-usb-duplicate.err | 1 + .../hostdev-usb-duplicate.xml | 40 ++++++++++++++++++ tests/qemuxml2argvtest.c | 8 ++++ 13 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/hostdev-mdev-duplicate.err create mode 100644 tests/qemuxml2argvdata/hostdev-mdev-duplicate.xml create mode 100644 tests/qemuxml2argvdata/hostdev-pci-duplicate.err create mode 100644 tests/qemuxml2argvdata/hostdev-pci-duplicate.xml create mode 100644 tests/qemuxml2argvdata/hostdev-scsi-duplicate.err create mode 100644 tests/qemuxml2argvdata/hostdev-scsi-duplicate.xml create mode 100644 tests/qemuxml2argvdata/hostdev-usb-duplicate.err create mode 100644 tests/qemuxml2argvdata/hostdev-usb-duplicate.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f65509d8..5746f69e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15369,7 +15369,7 @@ virDomainHostdevMatchCaps(virDomainHostdevDef *a, } =20 =20 -static int +int virDomainHostdevMatch(virDomainHostdevDef *a, virDomainHostdevDef *b) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f706c498..4d9d499b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3590,6 +3590,8 @@ virDomainHostdevDef * virDomainHostdevRemove(virDomainDef *def, size_t i); int virDomainHostdevFind(virDomainDef *def, virDomainHostdevDef *match, virDomainHostdevDef **found); +int virDomainHostdevMatch(virDomainHostdevDef *a, + virDomainHostdevDef *b); =20 virDomainGraphicsListenDef * virDomainGraphicsGetListen(virDomainGraphicsDef *def, size_t i); diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 2124d25d..df2ab473 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1068,7 +1068,25 @@ virDomainDefDuplicateDiskInfoValidate(const virDomai= nDef *def) return 0; } =20 +static int +virDomainDefDuplicateHostdevInfoValidate(const virDomainDef *def) +{ + size_t i; + size_t j; =20 + for (i =3D 0; i < def->nhostdevs; i++) { + for (j =3D i + 1; j < def->nhostdevs; j++) { + if (virDomainHostdevMatch(def->hostdevs[i], + def->hostdevs[j])) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Hostdev already exists in the domain configuration"= )); + return -1; + } + } + } + + return 0; +} =20 /** * virDomainDefDuplicateDriveAddressesValidate: @@ -1529,6 +1547,9 @@ virDomainDefValidateInternal(const virDomainDef *def, if (virDomainDefDuplicateDiskInfoValidate(def) < 0) return -1; =20 + if (virDomainDefDuplicateHostdevInfoValidate(def) < 0) + return -1; + if (virDomainDefDuplicateDriveAddressesValidate(def) < 0) return -1; =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2efa7876..f0d1b7b4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -457,6 +457,7 @@ virDomainHostdevDefFree; virDomainHostdevDefNew; virDomainHostdevFind; virDomainHostdevInsert; +virDomainHostdevMatch; virDomainHostdevModeTypeToString; virDomainHostdevRemove; virDomainHostdevSubsysPCIBackendTypeToString; diff --git a/tests/qemuxml2argvdata/hostdev-mdev-duplicate.err b/tests/qemu= xml2argvdata/hostdev-mdev-duplicate.err new file mode 100644 index 00000000..590afd30 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-mdev-duplicate.err @@ -0,0 +1 @@ +XML error: Hostdev already exists in the domain configuration diff --git a/tests/qemuxml2argvdata/hostdev-mdev-duplicate.xml b/tests/qemu= xml2argvdata/hostdev-mdev-duplicate.xml new file mode 100644 index 00000000..1c5e3263 --- /dev/null +++ b/tests/qemuxml2argvdata/hostdev-mdev-duplicate.xml @@ -0,0 +1,41 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + +
+ + + +
+ + + +