Implement virFileCheckCDROM in virStorageBackendVolOpen to check if
cdrom backend is ready. Skip the error of cdrom not ready.

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

Signed-off-by: Han Han <h...@redhat.com>
---
 src/storage/storage_util.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index da99043e0a..08b625d136 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1509,6 +1509,7 @@ virStorageBackendVolOpen(const char *path, struct stat 
*sb,
     int fd, mode = 0;
     char *base = last_component(path);
     bool noerror = (flags & VIR_STORAGE_VOL_OPEN_NOERROR);
+    virFileCDRomStatus cd_status;
 
     if (lstat(path, sb) < 0) {
         if (errno == ENOENT) {
@@ -1545,6 +1546,13 @@ virStorageBackendVolOpen(const char *path, struct stat 
*sb,
         return -1;
     }
 
+    if (virFileCheckCDROM(path, &cd_status)) {
+        if (cd_status != VIR_FILE_CDROM_DISC_OK) {
+            VIR_WARN("ignoring CDROM %s is not ready", path);
+            return -2;
+        }
+    }
+
     /* 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.17.1

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

Reply via email to