From nobody Fri May 3 10:56:33 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540526866249196.67332238970937; Thu, 25 Oct 2018 21:07:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50CC63082DD4; Fri, 26 Oct 2018 04:07:44 +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 C25621974A; Fri, 26 Oct 2018 04:07:43 +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 BBC1D1800533; Fri, 26 Oct 2018 04:07:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9Q3dUWL032743 for ; Thu, 25 Oct 2018 23:39:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4719D4A7; Fri, 26 Oct 2018 03:39:30 +0000 (UTC) Received: from hansolo.pek2.redhat.com (wlc-trust-100.pek2.redhat.com [10.72.3.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D3CC4A6; Fri, 26 Oct 2018 03:39:28 +0000 (UTC) From: Han Han To: libvir-list@redhat.com Date: Fri, 26 Oct 2018 11:39:15 +0800 Message-Id: <20181026033916.6535-2-hhan@redhat.com> In-Reply-To: <20181026033916.6535-1-hhan@redhat.com> References: <20181026033916.6535-1-hhan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Han Han Subject: [libvirt] [PATCH v4 1/2] util: Refactor virFileIsCDROM to virFileCheckCDROM 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 26 Oct 2018 04:07:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Refactor virFileIsCDROM to virFileCheckCDROM for checking cdrom status. Add add enum type virFileCDRomStatus. Now virFileCheckCDROM could be used to check the cdrom drive status such as ok, no disc, tray open, drive not ready, or unknown. Signed-off-by: Han Han --- src/libvirt_private.syms | 2 +- src/qemu/qemu_domain.c | 4 ++-- src/util/virfile.c | 36 +++++++++++++++++++++++++++++++----- src/util/virfile.h | 12 +++++++++++- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 335210c31d..c61b613325 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1802,6 +1802,7 @@ virFileActivateDirOverride; virFileBindMountDevice; virFileBuildPath; virFileCanonicalizePath; +virFileCheckCDROM; virFileChownFiles; virFileClose; virFileComparePaths; @@ -1824,7 +1825,6 @@ virFileGetMountSubtree; virFileHasSuffix; virFileInData; virFileIsAbsPath; -virFileIsCDROM; virFileIsDir; virFileIsExecutable; virFileIsLink; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ba3fff607a..f34243d2b2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7806,7 +7806,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 && virFileIsCDROM(disk->src->path) =3D=3D 1) + disk->src->path && virFileCheckCDROM(disk->src->path, NULL) =3D=3D= 1) qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH, logCtxt); =20 @@ -8760,7 +8760,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM && src->format =3D=3D VIR_STORAGE_FILE_RAW && virStorageSourceIsBlockLocal(src) && - virFileIsCDROM(src->path) =3D=3D 1) + virFileCheckCDROM(src->path, NULL) =3D=3D 1) src->hostcdrom =3D true; =20 ret =3D 0; diff --git a/src/util/virfile.c b/src/util/virfile.c index f6f9e4ceda..04b4c274dd 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1957,18 +1957,22 @@ int virFileIsMountPoint(const char *file) =20 #if defined(__linux__) /** - * virFileIsCDROM: + * virFileCheckCDROM: * @path: File to check + * @cd_status: Filled with the status of the CDROM if non-NULL. See + * virFileCDRomStatus. * * Returns 1 if @path is a cdrom device 0 if it is not a cdrom and -1 on * error. 'errno' of the failure is preserved and no libvirt errors are * reported. */ int -virFileIsCDROM(const char *path) +virFileCheckCDROM(const char *path, + virFileCDRomStatus *cd_status) { struct stat st; VIR_AUTOCLOSE fd =3D -1; + int status; =20 if ((fd =3D open(path, O_RDONLY | O_NONBLOCK)) < 0) return -1; @@ -1980,16 +1984,38 @@ virFileIsCDROM(const char *path) return 0; =20 /* Attempt to detect via a CDROM specific ioctl */ - if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) >=3D 0) + if ((status =3D ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT)) < 0) + return 0; + + if (!cd_status) return 1; =20 - return 0; + switch (status) { + case CDS_NO_INFO: + *cd_status =3D VIR_FILE_CDROM_UNKNOWN; + break; + case CDS_NO_DISC: + *cd_status =3D VIR_FILE_CDROM_NO_DISC; + break; + case CDS_TRAY_OPEN: + *cd_status =3D VIR_FILE_CDROM_TRAY_OPEN; + break; + case CDS_DRIVE_NOT_READY: + *cd_status =3D VIR_FILE_CDROM_DRIVE_NOT_READY; + break; + case CDS_DISC_OK: + *cd_status =3D VIR_FILE_CDROM_DISC_OK; + break; + } + + return 1; } =20 #else =20 int -virFileIsCDROM(const char *path) +virFileCheckCDROM(const char *path, + virFileCDRomStatus *cd_status ATTRIBUTE_UNUSED) { if (STRPREFIX(path, "/dev/cd") || STRPREFIX(path, "/dev/acd")) diff --git a/src/util/virfile.h b/src/util/virfile.h index 0f7dece958..1e5127badb 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -224,7 +224,17 @@ enum { int virFileIsSharedFSType(const char *path, int fstypes) ATTRIBUTE_NONNULL= (1); int virFileIsSharedFS(const char *path) ATTRIBUTE_NONNULL(1); int virFileIsMountPoint(const char *file) ATTRIBUTE_NONNULL(1); -int virFileIsCDROM(const char *path) + +typedef enum { + VIR_FILE_CDROM_DISC_OK, + VIR_FILE_CDROM_UNKNOWN, + VIR_FILE_CDROM_NO_DISC, + VIR_FILE_CDROM_TRAY_OPEN, + VIR_FILE_CDROM_DRIVE_NOT_READY, +} virFileCDRomStatus; + +int virFileCheckCDROM(const char *path, + virFileCDRomStatus *cd_status) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; =20 int virFileGetMountSubtree(const char *mtabpath, --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 10:56:33 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540525596509436.40840218766607; Thu, 25 Oct 2018 20:46:36 -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 19EB843A33; Fri, 26 Oct 2018 03:46:33 +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 36DD75D9C5; Fri, 26 Oct 2018 03:46:30 +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 B88411800533; Fri, 26 Oct 2018 03:46:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9Q3dWAF032752 for ; Thu, 25 Oct 2018 23:39:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1EBC14A7; Fri, 26 Oct 2018 03:39:32 +0000 (UTC) Received: from hansolo.pek2.redhat.com (wlc-trust-100.pek2.redhat.com [10.72.3.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D82755E1B4; Fri, 26 Oct 2018 03:39:30 +0000 (UTC) From: Han Han To: libvir-list@redhat.com Date: Fri, 26 Oct 2018 11:39:16 +0800 Message-Id: <20181026033916.6535-3-hhan@redhat.com> In-Reply-To: <20181026033916.6535-1-hhan@redhat.com> References: <20181026033916.6535-1-hhan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Han Han Subject: [libvirt] [PATCH v4 2/2] storage: Improve error handling on cdrom backend 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: , 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.30]); Fri, 26 Oct 2018 03:46:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1596096 Implement virFileCheckCDROM in virStorageBackendVolOpen to check if cdrom backend is ok. Report more detailed error if not ok. Signed-off-by: Han Han --- src/storage/storage_util.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 318a556656..c9f89b817a 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1601,6 +1601,38 @@ virStorageBackendVolOpen(const char *path, struct st= at *sb, return -1; } =20 +#if defined(__linux__) + virFileCDRomStatus cd_status =3D VIR_FILE_CDROM_UNKNOWN; + + if (virFileCheckCDROM(path, &cd_status) > 0) { + switch (cd_status) { + case VIR_FILE_CDROM_UNKNOWN: + virReportError(VIR_ERR_NO_STORAGE_VOL, + _("unknown status for CDROM storage vol '%s= '"), + path); + return -1; + case VIR_FILE_CDROM_NO_DISC: + virReportError(VIR_ERR_NO_STORAGE_VOL, + _("no disc in CDROM storage vol '%s'"), + path); + return -1; + case VIR_FILE_CDROM_TRAY_OPEN: + virReportError(VIR_ERR_NO_STORAGE_VOL, + _("the tray of CDROM storage vol '%s' is op= en"), + path); + return -1; + case VIR_FILE_CDROM_DRIVE_NOT_READY: + virReportError(VIR_ERR_NO_STORAGE_VOL, + _("CDROM storage vol '%s' is not ready"), + path); + return -1; + case VIR_FILE_CDROM_DISC_OK: + VIR_INFO("CDROM storage vol %s is OK", path); + break; + } + } +#endif /* defined(__linux__) */ + /* O_NONBLOCK should only matter during open() for fifos and * sockets, which we already filtered; but using it prevents a * TOCTTOU race. However, later on we will want to read() the --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list