99cbc7
From 829716665e195f34e484c1aec691a02d5035ae3a Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <829716665e195f34e484c1aec691a02d5035ae3a@dist-git>
99cbc7
From: Peter Krempa <pkrempa@redhat.com>
99cbc7
Date: Fri, 16 Aug 2019 14:36:57 +0200
99cbc7
Subject: [PATCH] qemu: Allow suppressing errors from qemuStorageLimitsRefresh
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
qemuStorageLimitsRefresh uses qemuDomainStorageOpenStat internally and
99cbc7
there are callers which don't care about the error. Propagate the
99cbc7
skipInaccessible flag so that we can log less errors.
99cbc7
99cbc7
Callers currently don't care about the return value change.
99cbc7
99cbc7
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
(cherry picked from commit ea26e22f94cea989b566e13e1930d76e06baf2c9)
99cbc7
https: //bugzilla.redhat.com/show_bug.cgi?id=1724808
99cbc7
Message-Id: <dd9323d0f10b7ad2992c389d37d1a643040ba743.1565958906.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, 13 insertions(+), 7 deletions(-)
99cbc7
99cbc7
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
99cbc7
index 72c75e308b..88a9f565c4 100644
99cbc7
--- a/src/qemu/qemu_driver.c
99cbc7
+++ b/src/qemu/qemu_driver.c
99cbc7
@@ -11894,6 +11894,7 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverPtr driver,
99cbc7
  * @cfg: driver configuration data
99cbc7
  * @vm: domain object
99cbc7
  * @src: storage source data
99cbc7
+ * @skipInaccessible: Suppress reporting of common errors when accessing @src
99cbc7
  *
99cbc7
  * Refresh the capacity and allocation limits of a given storage source.
99cbc7
  *
99cbc7
@@ -11915,22 +11916,27 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverPtr driver,
99cbc7
  * is sparse, but the amount of sparseness changes due to writes or
99cbc7
  * punching holes), and physical size of a non-raw file can change.
99cbc7
  *
99cbc7
- * Returns 0 on success, -1 on failure
99cbc7
+ * Returns 1 if @src was successfully updated, 0 if @src can't be opened and
99cbc7
+ * @skipInaccessible is true (no errors are reported) or -1 otherwise (errors
99cbc7
+ * are reported).
99cbc7
  */
99cbc7
 static int
99cbc7
 qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
99cbc7
                          virQEMUDriverConfigPtr cfg,
99cbc7
                          virDomainObjPtr vm,
99cbc7
-                         virStorageSourcePtr src)
99cbc7
+                         virStorageSourcePtr src,
99cbc7
+                         bool skipInaccessible)
99cbc7
 {
99cbc7
+    int rc;
99cbc7
     int ret = -1;
99cbc7
     int fd = -1;
99cbc7
     struct stat sb;
99cbc7
     char *buf = NULL;
99cbc7
     ssize_t len;
99cbc7
 
99cbc7
-    if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb, false) < 0)
99cbc7
-        goto cleanup;
99cbc7
+    if ((rc = qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb,
99cbc7
+                                        skipInaccessible)) <= 0)
99cbc7
+        return rc;
99cbc7
 
99cbc7
     if (virStorageSourceIsLocalStorage(src)) {
99cbc7
         if ((len = virFileReadHeaderFD(fd, VIR_STORAGE_MAX_HEADER, &buf)) < 0) {
99cbc7
@@ -11958,7 +11964,7 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
99cbc7
         S_ISBLK(sb.st_mode))
99cbc7
         src->allocation = 0;
99cbc7
 
99cbc7
-    ret = 0;
99cbc7
+    ret = 1;
99cbc7
 
99cbc7
  cleanup:
99cbc7
     VIR_FREE(buf);
99cbc7
@@ -12011,7 +12017,7 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
99cbc7
 
99cbc7
     /* for inactive domains we have to peek into the files */
99cbc7
     if (!virDomainObjIsActive(vm)) {
99cbc7
-        if ((qemuStorageLimitsRefresh(driver, cfg, vm, disk->src)) < 0)
99cbc7
+        if ((qemuStorageLimitsRefresh(driver, cfg, vm, disk->src, false)) < 0)
99cbc7
             goto endjob;
99cbc7
 
99cbc7
         info->capacity = disk->src->capacity;
99cbc7
@@ -20029,7 +20035,7 @@ qemuDomainGetStatsOneBlockFallback(virQEMUDriverPtr driver,
99cbc7
     if (virStorageSourceIsEmpty(src))
99cbc7
         return 0;
99cbc7
 
99cbc7
-    if (qemuStorageLimitsRefresh(driver, cfg, dom, src) < 0) {
99cbc7
+    if (qemuStorageLimitsRefresh(driver, cfg, dom, src, false) < 0) {
99cbc7
         virResetLastError();
99cbc7
         return 0;
99cbc7
     }
99cbc7
-- 
99cbc7
2.22.1
99cbc7