Blob Blame History Raw
From 2c1a60343710fc11a5c8bcfd022fd2a8aa6681ff Mon Sep 17 00:00:00 2001
Message-Id: <2c1a60343710fc11a5c8bcfd022fd2a8aa6681ff@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Fri, 16 Aug 2019 14:36:56 +0200
Subject: [PATCH] qemu: driver: Improve error suppression in
 qemuDomainStorageUpdatePhysical
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

None of the callers of qemuDomainStorageUpdatePhysical care about
errors.

Use the new flag for qemuDomainStorageOpenStat which suppresses some
errors and move the reset of the rest of the uncommon errors into this
function. Document what is happening in a comment for the function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 3d7ea4165b890880f43074e1e5e6e10bf0ad21d6)
https: //bugzilla.redhat.com/show_bug.cgi?id=1724808
Message-Id: <65325f9c156ebab937b81e89c9bfe6c1b6d8251b.1565958905.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_driver.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 91eeb05319..72c75e308b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11849,6 +11849,19 @@ qemuDomainStorageCloseStat(virStorageSourcePtr src,
 }
 
 
+/**
+ * qemuDomainStorageUpdatePhysical:
+ * @driver: qemu driver
+ * @cfg: qemu driver configuration object
+ * @vm: domain object
+ * @src: storage source to update
+ *
+ * Update the physical size of the disk by reading the actual size of the image
+ * on disk.
+ *
+ * Returns 0 on successful update and -1 otherwise (some uncommon errors may be
+ * reported but are reset (thus only logged)).
+ */
 static int
 qemuDomainStorageUpdatePhysical(virQEMUDriverPtr driver,
                                 virQEMUDriverConfigPtr cfg,
@@ -11862,8 +11875,11 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverPtr driver,
     if (virStorageSourceIsEmpty(src))
         return 0;
 
-    if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb, false) < 0)
+    if ((ret = qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb, true)) <= 0) {
+        if (ret < 0)
+            virResetLastError();
         return -1;
+    }
 
     ret = virStorageSourceUpdatePhysicalSize(src, fd, &sb);
 
@@ -12058,7 +12074,6 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
         if (qemuDomainStorageUpdatePhysical(driver, cfg, vm, disk->src) == 0) {
             info->physical = disk->src->physical;
         } else {
-            virResetLastError();
             info->physical = entry->physical;
         }
     } else {
@@ -20132,12 +20147,9 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
         QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx,
                                  "physical", entry->physical);
     } else {
-        if (qemuDomainStorageUpdatePhysical(driver, cfg, dom, src) == 0) {
+        if (qemuDomainStorageUpdatePhysical(driver, cfg, dom, src) == 0)
             QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx,
                                      "physical", src->physical);
-        } else {
-            virResetLastError();
-        }
     }
 
     if (qemuDomainGetStatsOneBlockNode(record, maxparams, src, block_idx,
-- 
2.22.1