From nobody Thu May 2 12:35:11 2024 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 1505140497158603.3512337088144; Mon, 11 Sep 2017 07:34:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB6D822F2F6; Mon, 11 Sep 2017 14:34:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73BE06B569; Mon, 11 Sep 2017 14:34:55 +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 07C523FAD1; Mon, 11 Sep 2017 14:34:54 +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 v8BEWpjW024900 for ; Mon, 11 Sep 2017 10:32:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 936A36F99F; Mon, 11 Sep 2017 14:32:51 +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 5B6601797F for ; Mon, 11 Sep 2017 14:32:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EB6D822F2F6 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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:45 -0400 Message-Id: <20170911143247.9636-2-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 1/3] qemu: Be more selective when determining cdrom for taint messaging 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 11 Sep 2017 14:34:56 +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 Commit id '99a2d6af2' was a bit too aggressive with determining whether the provided path was a "physical" cd-rom in order to generate a taint message due to the possibility of some guest and host trying to control the tray. For cd-rom guest devices backed to some VIR_STORAGE_TYPE_FILE storage, this wouldn't be a problem and as such it shouldn't be a problem for guest devices using some sort of block device on the host such as iSCSI, LVM, or a Disk pool would present. So before issuing a taint message, let's check if the provided path of the VIR_STORAGE_TYPE_BLOCK backed device is a "known" physical cdrom name by comparing the beginning of the path w/ "/dev/cdrom" and "/dev/sr". Also since it's possible the provided path could resolve to some /dev/srN device, let's get that path as well and perform the same check. Signed-off-by: John Ferlan --- src/qemu/qemu_domain.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7203189..1b0c778 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4722,6 +4722,35 @@ qemuDomainDefFormatLive(virQEMUDriverPtr driver, } =20 =20 +/* qemuDomainFilePathIsHostCDROM + * @path: Supplied path. + * + * Determine if the path is a host CD-ROM path. Typically this is + * either /dev/cdrom[n] or /dev/srN, so those are easy checks, but + * it's also possible that @path resolves to /dev/srN, so check for + * those conditions on @path in order to emit the tainted message. + * + * Returns true if the path is a CDROM, false otherwise or on error. + */ +static bool +qemuDomainFilePathIsHostCDROM(const char *path) +{ + bool ret =3D false; + char *linkpath =3D NULL; + + if (virFileResolveLink(path, &linkpath) < 0) + goto cleanup; + + if (STRPREFIX(path, "/dev/cdrom") || STRPREFIX(path, "/dev/sr") || + STRPREFIX(linkpath, "/dev/sr")) + ret =3D true; + + cleanup: + VIR_FREE(linkpath); + return ret; +} + + void qemuDomainObjTaint(virQEMUDriverPtr driver, virDomainObjPtr obj, virDomainTaintFlags taint, @@ -4840,7 +4869,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) + disk->src->path && qemuDomainFilePathIsHostCDROM(disk->src->path)) qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH, logCtxt); =20 --=20 2.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 12:35:11 2024 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 150514037546921.624904358919252; Mon, 11 Sep 2017 07:32:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EE6B54F53; Mon, 11 Sep 2017 14:32:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 191FE5C881; Mon, 11 Sep 2017 14:32:54 +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 808F23FACF; Mon, 11 Sep 2017 14:32:53 +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 v8BEWpDs024905 for ; Mon, 11 Sep 2017 10:32:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id EDD4C1797F; Mon, 11 Sep 2017 14:32:51 +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 B50876FDCC for ; Mon, 11 Sep 2017 14:32:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3EE6B54F53 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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:46 -0400 Message-Id: <20170911143247.9636-3-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 2/3] nodedev: Add capability bit to detect 'cdrom' devices 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 11 Sep 2017 14:32:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add the capability to detect and list any/all cdrom devices Signed-off-by: John Ferlan --- include/libvirt/libvirt-nodedev.h | 1 + src/conf/node_device_conf.c | 6 +++++- src/conf/node_device_conf.h | 5 ++++- src/conf/virnodedeviceobj.c | 21 ++++++++++++++++++--- src/node_device/node_device_driver.c | 1 + src/node_device/node_device_udev.c | 2 ++ tools/virsh-nodedev.c | 3 +++ tools/virsh.pod | 2 +- 8 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 25e8724..140c8f2 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -82,6 +82,7 @@ typedef enum { VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES =3D 1 << 13, /* Capabl= e of mediated devices */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV =3D 1 << 14, /* Mediat= ed device */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV =3D 1 << 15, /* CCW de= vice */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_CDROM =3D 1 << 16, /* CDROM = capable device */ } virConnectListAllNodeDeviceFlags; =20 int virConnectListAllNodeDevices (virConnectPtr conn, diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bf84fd2..54f36a3 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -63,7 +63,8 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST, "drm", "mdev_types", "mdev", - "ccw") + "ccw", + "cdrom") =20 VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST, "80203", @@ -603,6 +604,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: + case VIR_NODE_DEV_CAP_CDROM: case VIR_NODE_DEV_CAP_LAST: break; } @@ -1895,6 +1897,7 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_SCSI_GENERIC: + case VIR_NODE_DEV_CAP_CDROM: case VIR_NODE_DEV_CAP_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown capability type '%d' for '%s'"), @@ -2223,6 +2226,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_CCW_DEV: + case VIR_NODE_DEV_CAP_CDROM: case VIR_NODE_DEV_CAP_LAST: /* This case is here to shutup the compiler */ break; diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index da56eaf..b5e1f16 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -67,6 +67,7 @@ typedef enum { VIR_NODE_DEV_CAP_MDEV_TYPES, /* Device capable of mediated devi= ces */ VIR_NODE_DEV_CAP_MDEV, /* Mediated device */ VIR_NODE_DEV_CAP_CCW_DEV, /* s390 CCW device */ + VIR_NODE_DEV_CAP_CDROM, /* CDROM capable device */ =20 VIR_NODE_DEV_CAP_LAST } virNodeDevCapType; @@ -85,6 +86,7 @@ typedef enum { VIR_NODE_DEV_CAP_STORAGE_REMOVABLE =3D (1 << 0), VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE =3D (1 << 1), VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE =3D (1 << 2), + VIR_NODE_DEV_CAP_STORAGE_CDROM =3D (1 << 3), } virNodeDevStorageCapFlags; =20 typedef enum { @@ -377,7 +379,8 @@ virNodeDevCapMdevTypeFree(virNodeDevCapMdevTypePtr type= ); VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV | \ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV) + VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV | \ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_CDROM) =20 char * virNodeDeviceGetParentName(virConnectPtr conn, diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index b0dcee1..e3e2078 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -131,6 +131,8 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); const char *mdev_types =3D virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_MDEV_TYPES); + const char *cdrom_types =3D + virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_CDROM); =20 while (caps) { if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) { @@ -151,13 +153,18 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, return 1; break; =20 + case VIR_NODE_DEV_CAP_STORAGE: + if ((STREQ(cap, cdrom_types) && + (caps->data.storage.flags & VIR_NODE_DEV_CAP_STORAGE_= CDROM))) + return 1; + break; + case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_USB_DEV: case VIR_NODE_DEV_CAP_USB_INTERFACE: case VIR_NODE_DEV_CAP_NET: case VIR_NODE_DEV_CAP_SCSI_TARGET: case VIR_NODE_DEV_CAP_SCSI: - case VIR_NODE_DEV_CAP_STORAGE: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_SCSI_GENERIC: @@ -165,6 +172,7 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_MDEV: case VIR_NODE_DEV_CAP_CCW_DEV: + case VIR_NODE_DEV_CAP_CDROM: case VIR_NODE_DEV_CAP_LAST: break; } @@ -707,13 +715,18 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr obj, return true; break; =20 + case VIR_NODE_DEV_CAP_STORAGE: + if (type =3D=3D VIR_NODE_DEV_CAP_CDROM && + (cap->data.storage.flags & VIR_NODE_DEV_CAP_STORAGE_CDROM)) + return true; + break; + case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_USB_DEV: case VIR_NODE_DEV_CAP_USB_INTERFACE: case VIR_NODE_DEV_CAP_NET: case VIR_NODE_DEV_CAP_SCSI_TARGET: case VIR_NODE_DEV_CAP_SCSI: - case VIR_NODE_DEV_CAP_STORAGE: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_SCSI_GENERIC: @@ -721,6 +734,7 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr obj, case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_MDEV: case VIR_NODE_DEV_CAP_CCW_DEV: + case VIR_NODE_DEV_CAP_CDROM: case VIR_NODE_DEV_CAP_LAST: break; } @@ -867,7 +881,8 @@ virNodeDeviceMatch(virNodeDeviceObjPtr obj, MATCH(DRM) || MATCH(MDEV_TYPES) || MATCH(MDEV) || - MATCH(CCW_DEV))) + MATCH(CCW_DEV) || + MATCH(CDROM))) return false; } =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index facfeb6..adae917 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -90,6 +90,7 @@ nodeDeviceUpdateCaps(virNodeDeviceDefPtr def) case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_MDEV: case VIR_NODE_DEV_CAP_CCW_DEV: + case VIR_NODE_DEV_CAP_CDROM: case VIR_NODE_DEV_CAP_LAST: break; } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index f417745..bebfec4 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -920,6 +920,7 @@ udevProcessCDROM(struct udev_device *device, VIR_FREE(def->caps->data.storage.drive_type); if (VIR_STRDUP(def->caps->data.storage.drive_type, "cdrom") < 0) return -1; + def->caps->data.storage.flags |=3D VIR_NODE_DEV_CAP_STORAGE_CDROM; =20 if (udevHasDeviceProperty(device, "ID_CDROM_MEDIA") && udevGetIntProperty(device, "ID_CDROM_MEDIA", &has_media, 0) < 0) @@ -1303,6 +1304,7 @@ udevGetDeviceDetails(struct udev_device *device, case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: + case VIR_NODE_DEV_CAP_CDROM: case VIR_NODE_DEV_CAP_LAST: break; } diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c7ef6bf..ba1592b 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -463,6 +463,9 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd A= TTRIBUTE_UNUSED) case VIR_NODE_DEV_CAP_CCW_DEV: flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV; break; + case VIR_NODE_DEV_CAP_CDROM: + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_CDROM; + break; case VIR_NODE_DEV_CAP_LAST: break; } diff --git a/tools/virsh.pod b/tools/virsh.pod index 01453be..2ba7762 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3243,7 +3243,7 @@ I is used to filter the list by capability types= , the types must be separated by comma, e.g. --cap pci,scsi. Valid capability types include 'system', 'pci', 'usb_device', 'usb', 'net', 'scsi_host', 'scsi_target', 'scsi', 'storage', 'fc_host', 'vports', 'scsi_generic', 'drm', 'mdev', -'mdev_types', 'ccw'. +'mdev_types', 'ccw', 'cdrom'. If I<--tree> is used, the output is formatted in a tree representing paren= ts of each node. I and I<--tree> are mutually exclusive. =20 --=20 2.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 12:35:11 2024 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