In some cases it's useful to report the error which caused the domain
job to fail. Add an optional field for holding the error message so that
it can be later retrieved from statistics of a completed job.

Add the field name macro and code for extracting it in virsh.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 include/libvirt/libvirt-domain.h | 9 +++++++++
 tools/virsh-domain.c             | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index b440818ec2..f129e6a1af 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3612,6 +3612,15 @@ typedef enum {
  */
 # define VIR_DOMAIN_JOB_SUCCESS "success"

+/**
+ * VIR_DOMAIN_JOB_ERRMSG:
+ *
+ * virDomainGetJobStats field: Present only in statistics for a completed job.
+ * Optional error message for a failed job.
+ */
+# define VIR_DOMAIN_JOB_ERRMSG "errmsg"
+
+
 /**
  * VIR_DOMAIN_JOB_DISK_TEMP_USED:
  * virDomainGetJobStats field: current usage of temporary disk space for the
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index d52eb7bc2f..f2dc41cb31 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6228,6 +6228,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
     unsigned long long value;
     unsigned int flags = 0;
     int ivalue;
+    const char *svalue;
     int op;
     int rc;
     size_t i;
@@ -6508,6 +6509,13 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%-17s %-.3lf %s\n", _("Temporary disk space total:"), 
val, unit);
     }

+    if ((rc = virTypedParamsGetString(params, nparams, VIR_DOMAIN_JOB_ERRMSG,
+                                      &svalue)) < 0) {
+        goto save_error;
+    } else if (rc == 1) {
+        vshPrint(ctl, "%-17s %s\n", _("Error message:"), svalue);
+    }
+
     ret = true;

  cleanup:
-- 
2.26.0

Reply via email to