https://bugzilla.redhat.com/show_bug.cgi?id=1596096

Implement virFileCheckCDROM in virStorageBackendVolOpen to check if
cdrom backend is ok. Report more detailed error if not ok.

Signed-off-by: Han Han <h...@redhat.com>
---
 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 stat 
*sb,
         return -1;
     }
 
+#if defined(__linux__)
+    virFileCDRomStatus cd_status = 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 open"),
+                               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
-- 
2.19.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to