From nobody Sun Feb 8 17:21:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1505140397175736.263487106996; Mon, 11 Sep 2017 07:33:17 -0700 (PDT) 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 CD63F16480F; Mon, 11 Sep 2017 14:33:15 +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 ABBA461296; Mon, 11 Sep 2017 14:33:15 +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 757AC1806100; Mon, 11 Sep 2017 14:33:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8BEWqoS024916 for ; Mon, 11 Sep 2017 10:32:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 55DDC6F99F; Mon, 11 Sep 2017 14:32:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-120.phx2.redhat.com [10.3.116.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CE361797F for ; Mon, 11 Sep 2017 14:32:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CD63F16480F Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Mon, 11 Sep 2017 10:32:47 -0400 Message-Id: <20170911143247.9636-4-jferlan@redhat.com> In-Reply-To: <20170911143247.9636-1-jferlan@redhat.com> References: <20170911143247.9636-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/3] qemu: Add inquiry to nodedev for cdrom taint checking 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.26]); Mon, 11 Sep 2017 14:33:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1471225 Since we can now easily determine from the node device driver which devices are physical cdrom devices, let's make in inquiry of the node device driver to get a list of all cdrom devices and compare the input resolved path to that list to ensure we haven't missed anything. Signed-off-by: John Ferlan --- src/qemu/qemu_domain.c | 53 +++++++++++++++++++++++++++++++++++++++++++++= ---- src/qemu/qemu_domain.h | 2 ++ src/qemu/qemu_driver.c | 4 ++-- src/qemu/qemu_process.c | 2 +- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1b0c778..a1302a5 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -41,6 +41,7 @@ #include "virfile.h" #include "domain_addr.h" #include "domain_event.h" +#include "node_device_conf.h" #include "virtime.h" #include "virnetdevopenvswitch.h" #include "virstoragefile.h" @@ -4723,6 +4724,7 @@ qemuDomainDefFormatLive(virQEMUDriverPtr driver, =20 =20 /* qemuDomainFilePathIsHostCDROM + * @conn: A virConnectPtr * @path: Supplied path. * * Determine if the path is a host CD-ROM path. Typically this is @@ -4730,23 +4732,64 @@ qemuDomainDefFormatLive(virQEMUDriverPtr driver, * it's also possible that @path resolves to /dev/srN, so check for * those conditions on @path in order to emit the tainted message. * + * If that doesn't work, then let's check with the nodedev driver to + * get a list of all cdrom's on the host and then compare the resolved + * linkpath for @path to each cdrom in the list looking for a match. + * * Returns true if the path is a CDROM, false otherwise or on error. */ static bool -qemuDomainFilePathIsHostCDROM(const char *path) +qemuDomainFilePathIsHostCDROM(virConnectPtr conn, + const char *path) { bool ret =3D false; char *linkpath =3D NULL; + int ndevices =3D 0; + virNodeDevicePtr *devices =3D NULL; + unsigned int flags =3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_CDROM; + size_t i; + char *xml =3D NULL; + virNodeDeviceDefPtr def =3D NULL; =20 if (virFileResolveLink(path, &linkpath) < 0) goto cleanup; =20 if (STRPREFIX(path, "/dev/cdrom") || STRPREFIX(path, "/dev/sr") || - STRPREFIX(linkpath, "/dev/sr")) + STRPREFIX(linkpath, "/dev/sr")) { ret =3D true; + goto cleanup; + } + + /* Get a list of all 'cdrom' devices from NodeDevice and search + * through the list looking to compare the resolved @linkpath + * to list of host console device(s). */ + if (conn && + (ndevices =3D virConnectListAllNodeDevices(conn, &devices, flags) = > 0)) { + for (i =3D 0; i < ndevices; i++) { + if (!(xml =3D virNodeDeviceGetXMLDesc(devices[i], 0))) + goto cleanup; + + if (!(def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE= , NULL))) + goto cleanup; + VIR_FREE(xml); + + if (STREQ(def->caps->data.storage.block, linkpath)) { + ret =3D true; + goto cleanup; + } + + virNodeDeviceDefFree(def); + def =3D NULL; + } + } =20 cleanup: VIR_FREE(linkpath); + virNodeDeviceDefFree(def); + VIR_FREE(xml); + for (i =3D 0; i < ndevices; i++) + virObjectUnref(devices[i]); + VIR_FREE(devices); return ret; } =20 @@ -4809,6 +4852,7 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver, =20 =20 void qemuDomainObjCheckTaint(virQEMUDriverPtr driver, + virConnectPtr conn, virDomainObjPtr obj, qemuDomainLogContextPtr logCtxt) { @@ -4835,7 +4879,7 @@ void qemuDomainObjCheckTaint(virQEMUDriverPtr driver, qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HOST_CPU, logCtxt= ); =20 for (i =3D 0; i < obj->def->ndisks; i++) - qemuDomainObjCheckDiskTaint(driver, obj, obj->def->disks[i], logCt= xt); + qemuDomainObjCheckDiskTaint(driver, conn, obj, obj->def->disks[i],= logCtxt); =20 for (i =3D 0; i < obj->def->nhostdevs; i++) qemuDomainObjCheckHostdevTaint(driver, obj, obj->def->hostdevs[i], @@ -4852,6 +4896,7 @@ void qemuDomainObjCheckTaint(virQEMUDriverPtr driver, =20 =20 void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver, + virConnectPtr conn, virDomainObjPtr obj, virDomainDiskDefPtr disk, qemuDomainLogContextPtr logCtxt) @@ -4869,7 +4914,7 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr dri= ver, =20 if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM && virStorageSourceGetActualType(disk->src) =3D=3D VIR_STORAGE_TYPE_B= LOCK && - disk->src->path && qemuDomainFilePathIsHostCDROM(disk->src->path)) + disk->src->path && qemuDomainFilePathIsHostCDROM(conn, disk->src->= path)) qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH, logCtxt); =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 5f6e361..2e0a949 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -552,9 +552,11 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver, qemuDomainLogContextPtr logCtxt); =20 void qemuDomainObjCheckTaint(virQEMUDriverPtr driver, + virConnectPtr conn, virDomainObjPtr obj, qemuDomainLogContextPtr logCtxt); void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver, + virConnectPtr conn, virDomainObjPtr obj, virDomainDiskDefPtr disk, qemuDomainLogContextPtr logCtxt); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6255d89..13d6ef7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7505,7 +7505,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, =20 switch ((virDomainDeviceType) dev->type) { case VIR_DOMAIN_DEVICE_DISK: - qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL); + qemuDomainObjCheckDiskTaint(driver, conn, vm, dev->data.disk, NULL= ); ret =3D qemuDomainAttachDeviceDiskLive(conn, driver, vm, dev); if (!ret) { alias =3D dev->data.disk->info.alias; @@ -7784,7 +7784,7 @@ qemuDomainUpdateDeviceLive(virConnectPtr conn, =20 switch ((virDomainDeviceType) dev->type) { case VIR_DOMAIN_DEVICE_DISK: - qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL); + qemuDomainObjCheckDiskTaint(driver, conn, vm, dev->data.disk, NULL= ); ret =3D qemuDomainChangeDiskLive(conn, vm, dev, driver, force); break; case VIR_DOMAIN_DEVICE_GRAPHICS: diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ab81d65..0aa3ebf 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5557,7 +5557,7 @@ qemuProcessLaunch(virConnectPtr conn, =20 qemuLogOperation(vm, "starting up", cmd, logCtxt); =20 - qemuDomainObjCheckTaint(driver, vm, logCtxt); + qemuDomainObjCheckTaint(driver, conn, vm, logCtxt); =20 qemuDomainLogContextMarkPosition(logCtxt); =20 --=20 2.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list