render / rpms / libvirt

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