]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Report errors if arguments of the schedinfo command are incorrect
authorPeter Krempa <pkrempa@redhat.com>
Mon, 3 Dec 2012 13:17:52 +0000 (14:17 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 3 Dec 2012 15:37:10 +0000 (16:37 +0100)
Libvirt's helper API's when called directly don't raise the error so
that virsh remembers it. Subsequent calls to libvirt API's might reset
the error.

In case of schedinfo virDomainFree() in the cleanup section resets the
error when virTypedParameterAssignFromStr() fails.

This patch adds function vshSaveLibvirtError() that can be called after
calling libvirt helper APIs to ensure the error is remembered.

tools/virsh-domain.c
tools/virsh.c
tools/virsh.h

index 73ebba9f3cf46f1d187c75ec2eba14ce7df484e1..1f7aff7a94728ad1c4172fba918fecf4c0e26605 100644 (file)
@@ -3512,8 +3512,10 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
             if (virTypedParameterAssign(&(params[nparams++]),
                                         param->field,
                                         param->type,
-                                        val) < 0)
+                                        val) < 0) {
+                vshSaveLibvirtError();
                 goto cleanup;
+            }
 
             continue;
         }
@@ -3523,8 +3525,10 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
             if (virTypedParameterAssignFromStr(&(params[nparams++]),
                                                param->field,
                                                param->type,
-                                               set_val) < 0)
+                                               set_val) < 0) {
+                vshSaveLibvirtError();
                 goto cleanup;
+            }
 
             continue;
         }
index dea3f824937541a366adcd29c41a6aa703817e72..322f7785b9d3f365bb68cf53432bb136eee0aac0 100644 (file)
@@ -240,6 +240,15 @@ virshErrorHandler(void *unused ATTRIBUTE_UNUSED, virErrorPtr error)
         virDefaultErrorFunc(error);
 }
 
+/* Store a libvirt error that is from a helper API that doesn't raise errors
+ * so it doesn't get overwritten */
+void
+vshSaveLibvirtError(void)
+{
+    virFreeError(last_error);
+    last_error = virSaveLastError();
+}
+
 /*
  * Reset libvirt error on graceful fallback paths
  */
index ba44f42a72ccbb95927ad109cebfa8dd06da26ec..6913ed1298d095455c7fbed4308827d5393680a7 100644 (file)
@@ -346,6 +346,7 @@ struct _vshCtrlData {
 extern virErrorPtr last_error;
 void vshReportError(vshControl *ctl);
 void vshResetLibvirtError(void);
+void vshSaveLibvirtError(void);
 
 /* allocation wrappers */
 void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);