From nobody Wed May 1 23:20:39 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 150464472392621.299430949385624; Tue, 5 Sep 2017 13:52:03 -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 43FCB3E2DE; Tue, 5 Sep 2017 20:52:01 +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 114345D6A3; Tue, 5 Sep 2017 20:52:00 +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 C4EA63FACE; Tue, 5 Sep 2017 20:51:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v85KptP4020998 for ; Tue, 5 Sep 2017 16:51:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 142CA1851C; Tue, 5 Sep 2017 20:51:55 +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 D10131850C for ; Tue, 5 Sep 2017 20:51:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 43FCB3E2DE Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Tue, 5 Sep 2017 16:51:51 -0400 Message-Id: <20170905205151.6740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] 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.30]); Tue, 05 Sep 2017 20:52:02 +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. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 2 +- src/util/virfile.c | 48 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virfile.h | 4 ++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f30a04b..0354568 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1680,6 +1680,7 @@ virFileGetMountSubtree; virFileHasSuffix; virFileInData; virFileIsAbsPath; +virFileIsCDROM; virFileIsDir; virFileIsExecutable; virFileIsLink; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9cff501..426c577 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4807,7 +4807,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 && virFileIsCDROM(disk->src->path)) qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH, logCtxt); =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index 2f28e83..4c31949 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -4166,3 +4166,51 @@ virFileReadValueString(char **value, const char *for= mat, ...) VIR_FREE(str); return ret; } + + +#if defined(__linux__) + +/* virFileIsCDROM + * @path: Supplied path. + * + * Determine if the path is a CD-ROM path. Typically on Linux systems this + * is either /dev/cdrom or /dev/sr0, so those are easy checks. Still if + * someone is trying to be tricky, we can resolve the link to /dev/cdrom + * and compare it to the resolved link of the supplied @path to compare + * if they're the same. + * + * Returns true if the path is a CDROM, false otherwise. + */ +bool +virFileIsCDROM(const char *path) +{ + bool ret =3D false; + char *linkpath =3D NULL; + char *cdrompath =3D NULL; + + if (STREQ(path, "/dev/cdrom") || STREQ(path, "/dev/sr0")) + return true; + + if (virFileResolveLink(path, &linkpath) < 0 || + virFileResolveLink("/dev/cdrom", &cdrompath) < 0) + goto cleanup; + + ret =3D STREQ(linkpath, cdrompath); + + cleanup: + VIR_FREE(linkpath); + VIR_FREE(cdrompath); + return ret; +} + +#else /* __linux__ */ + +bool +virFileIsCDROM(const char *path) +{ + /* XXX implement me :-) */ + virReportUnsupportedError(); + return false; +} + +#endif /* __linux__ */ diff --git a/src/util/virfile.h b/src/util/virfile.h index 57ceb80..21caabf 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -352,4 +352,8 @@ int virFileInData(int fd, int *inData, long long *length); =20 +bool +virFileIsCDROM(const char *path) + ATTRIBUTE_NONNULL(1); + #endif /* __VIR_FILE_H */ --=20 2.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list