[libvirt] [PATCH 2/2] storage: Improve error handling on cdrom backend

Han Han hhan at redhat.com
Wed Jul 11 02:52:07 UTC 2018


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 <hhan at redhat.com>
---
 src/storage/storage_util.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index da99043e0a..38a91541fd 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1506,7 +1506,7 @@ int
 virStorageBackendVolOpen(const char *path, struct stat *sb,
                          unsigned int flags)
 {
-    int fd, mode = 0;
+    int fd, cd_status, mode = 0;
     char *base = last_component(path);
     bool noerror = (flags & VIR_STORAGE_VOL_OPEN_NOERROR);
 
@@ -1545,6 +1545,19 @@ virStorageBackendVolOpen(const char *path, struct stat *sb,
         return -1;
     }
 
+    if (virFileCheckCDROM(path, &cd_status)) {
+        if (cd_status != VIR_FILE_CDROM_DISC_OK) {
+            if (noerror) {
+                VIR_WARN("ignoring CDROM %s is not ready", path);
+                return -2;
+            }
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("CDROM %s is not ready", path);
+            return -1;
+        }
+        VIR_INFO("CDROM backend %s is ok", path);
+    }
+
     /* 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




More information about the libvir-list mailing list