On 07/24/2013 04:43 PM, Ján Tomko wrote:
Both virStoragePoolFree and virStorageVolFree reset the last error,
which might lead to the cryptic message:
An error occurred, but the cause is unknown

When the volume wasn't found, virStorageVolFree was called with NULL,
leading to an error:
invalid storage volume pointer in virStorageVolFree

This patch changes it to:
Storage volume not found: no storage vol with matching name 'tomato'
---
  src/qemu/qemu_conf.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 3e7b78a..80b8156 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1248,6 +1248,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
      char *poolxml = NULL;
      virStorageVolInfo info;
      int ret = -1;
+    virErrorPtr savedError;
if (def->type != VIR_DOMAIN_DISK_TYPE_VOLUME)
          return 0;
@@ -1324,8 +1325,14 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
      def->srcpool->voltype = info.type;
      ret = 0;
  cleanup:
-    virStoragePoolFree(pool);
-    virStorageVolFree(vol);
+    savedError = virSaveLastError();

It would be better to save error only when ret < 0.
In other place, we use format like this:

if (ret < 0 && !savedError)
    savedError = virSaveLastError();

virStoragePoolFree(pool);
virStorageVolFree(vol);

if (savedError) {
    virSetError(orig_err);
    virFreeError(orig_err);
}

Guannan

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to