From nobody Sat Jul 12 04:41:29 2025 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