render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
d759b5
From d108926463da19a2b025c845c60cfd78da850291 Mon Sep 17 00:00:00 2001
d759b5
Message-Id: <d108926463da19a2b025c845c60cfd78da850291@dist-git>
d759b5
From: Peter Krempa <pkrempa@redhat.com>
d759b5
Date: Fri, 16 Aug 2019 14:36:54 +0200
d759b5
Subject: [PATCH] qemu: Allow skipping some errors in qemuDomainStorageOpenStat
d759b5
MIME-Version: 1.0
d759b5
Content-Type: text/plain; charset=UTF-8
d759b5
Content-Transfer-Encoding: 8bit
d759b5
d759b5
Some callers of this function actually don't care about errors and reset
d759b5
it. The message is still logged which might irritate users in this case.
d759b5
d759b5
Add a boolean flag which will do few checks whether it actually makes
d759b5
sense to even try opening the storage file. For local files we check
d759b5
whether it exists and for remote files we at first see whether we even
d759b5
have a storage driver backend for it in the first place before trying to
d759b5
open it.
d759b5
d759b5
Other problems will still report errors but these are the most common
d759b5
scenarios which can happen here.
d759b5
d759b5
This patch changes the return value of the function so that the caller
d759b5
is able to differentiate the possibilities.
d759b5
d759b5
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d759b5
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d759b5
(cherry picked from commit ba6c12df2ceb4df9bfb7ce95deef04f96bf29462)
d759b5
https: //bugzilla.redhat.com/show_bug.cgi?id=1724808
d759b5
Message-Id: <c69a26233c1520454496f823bd6cc39ff1e7b868.1565958905.git.pkrempa@redhat.com>
d759b5
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d759b5
---
d759b5
 src/qemu/qemu_driver.c | 20 +++++++++++++++-----
d759b5
 1 file changed, 15 insertions(+), 5 deletions(-)
d759b5
d759b5
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
d759b5
index 8ecdcf3440..91eeb05319 100644
d759b5
--- a/src/qemu/qemu_driver.c
d759b5
+++ b/src/qemu/qemu_driver.c
d759b5
@@ -11778,6 +11778,7 @@ qemuDomainMemoryPeek(virDomainPtr dom,
d759b5
  * @src: storage source data
d759b5
  * @ret_fd: pointer to return open'd file descriptor
d759b5
  * @ret_sb: pointer to return stat buffer (local or remote)
d759b5
+ * @skipInaccessible: Don't report error if files are not accessible
d759b5
  *
d759b5
  * For local storage, open the file using qemuOpenFile and then use
d759b5
  * fstat() to grab the stat struct data for the caller.
d759b5
@@ -11785,7 +11786,9 @@ qemuDomainMemoryPeek(virDomainPtr dom,
d759b5
  * For remote storage, attempt to access the file and grab the stat
d759b5
  * struct data if the remote connection supports it.
d759b5
  *
d759b5
- * Returns 0 on success with @ret_fd and @ret_sb populated, -1 on failure
d759b5
+ * Returns 1 if @src was successfully opened (@ret_fd and @ret_sb is populated),
d759b5
+ * 0 if @src can't be opened and @skipInaccessible is true (no errors are
d759b5
+ * reported) or -1 otherwise (errors are reported).
d759b5
  */
d759b5
 static int
d759b5
 qemuDomainStorageOpenStat(virQEMUDriverPtr driver,
d759b5
@@ -11793,9 +11796,13 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver,
d759b5
                           virDomainObjPtr vm,
d759b5
                           virStorageSourcePtr src,
d759b5
                           int *ret_fd,
d759b5
-                          struct stat *ret_sb)
d759b5
+                          struct stat *ret_sb,
d759b5
+                          bool skipInaccessible)
d759b5
 {
d759b5
     if (virStorageSourceIsLocalStorage(src)) {
d759b5
+        if (skipInaccessible && !virFileExists(src->path))
d759b5
+            return 0;
d759b5
+
d759b5
         if ((*ret_fd = qemuOpenFile(driver, vm, src->path, O_RDONLY,
d759b5
                                     NULL)) < 0)
d759b5
             return -1;
d759b5
@@ -11806,6 +11813,9 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver,
d759b5
             return -1;
d759b5
         }
d759b5
     } else {
d759b5
+        if (skipInaccessible && virStorageFileSupportsBackingChainTraversal(src) <= 0)
d759b5
+            return 0;
d759b5
+
d759b5
         if (virStorageFileInitAs(src, cfg->user, cfg->group) < 0)
d759b5
             return -1;
d759b5
 
d759b5
@@ -11817,7 +11827,7 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver,
d759b5
         }
d759b5
     }
d759b5
 
d759b5
-    return 0;
d759b5
+    return 1;
d759b5
 }
d759b5
 
d759b5
 
d759b5
@@ -11852,7 +11862,7 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverPtr driver,
d759b5
     if (virStorageSourceIsEmpty(src))
d759b5
         return 0;
d759b5
 
d759b5
-    if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb) < 0)
d759b5
+    if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb, false) < 0)
d759b5
         return -1;
d759b5
 
d759b5
     ret = virStorageSourceUpdatePhysicalSize(src, fd, &sb);
d759b5
@@ -11903,7 +11913,7 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
d759b5
     char *buf = NULL;
d759b5
     ssize_t len;
d759b5
 
d759b5
-    if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb) < 0)
d759b5
+    if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb, false) < 0)
d759b5
         goto cleanup;
d759b5
 
d759b5
     if (virStorageSourceIsLocalStorage(src)) {
d759b5
-- 
d759b5
2.22.1
d759b5