From 4f39774610cac5e8de019b0be2aec2548b1acfd0 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 15 Apr 2020 12:27:53 +0200 Subject: [PATCH] API: Add VIR_DOMAIN_JOB_ERRMSG domain job statistics field 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 Reviewed-by: Eric Blake --- 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 502685f44b..0704529458 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6226,6 +6226,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; @@ -6506,6 +6507,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: