This API function extends the virDomainGetState function by returning
additional state information as a dictionary of typed parameters.

Reviewed-by: Boris Fiuczynski <fiu...@linux.ibm.com>
Signed-off-by: Bjoern Walk <bw...@linux.ibm.com>
---
 include/libvirt/libvirt-domain.h | 76 ++++++++++++++++++++++++++++++++
 src/driver-hypervisor.h          |  9 ++++
 src/libvirt-domain.c             | 62 ++++++++++++++++++++++++++
 src/libvirt_public.syms          |  5 +++
 4 files changed, 152 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 7d36820b..b0118e4a 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1292,6 +1292,82 @@ int                     virDomainGetState       
(virDomainPtr domain,
                                                  int *reason,
                                                  unsigned int flags);
 
+typedef enum {
+    VIR_DOMAIN_STATE_PARAM_TYPE_NONE,
+    VIR_DOMAIN_STATE_PARAM_TYPE_QEMU_HYPERV,
+    VIR_DOMAIN_STATE_PARAM_TYPE_QEMU_S390,
+
+    VIR_DOMAIN_STATE_PARAM_TYPE_LAST
+} virDomainStateParamType;
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_TYPE:
+ * specifies the type of additional state information available
+ */
+# define VIR_DOMAIN_STATE_PARAM_TYPE "info_type"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG1:
+ * Hyper-V-specific panic state information: HV crash MSR1
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG1 
"crashed.panicked.hyperv.arg1"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG2:
+ * Hyper-V-specific panic state information: HV crash MSR2
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG2 
"crashed.panicked.hyperv.arg2"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG3:
+ * Hyper-V-specific panic state information: HV crash MSR3
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG3 
"crashed.panicked.hyperv.arg3"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG4:
+ * Hyper-V-specific panic state information: HV crash MSR4
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG4 
"crashed.panicked.hyperv.arg4"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG5:
+ * Hyper-V-specific panic state information: HV crash MSR5
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_HYPERV_ARG5 
"crashed.panicked.hyperv.arg5"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_CORE:
+ * S390-specific panic state information: panicked core
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_CORE 
"crashed.panicked.s390.core"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_PSW_MASK:
+ * S390-specific panic state information: PSW mask
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_PSW_MASK 
"crashed.panicked.s390.psw_mask"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_PSW_ADDR:
+ * S390-specific panic state information: PSW address
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_PSW_ADDR 
"crashed.panicked.s390.psw_addr"
+
+/**
+ * VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_REASON:
+ * S390-specific panic state information: human-readable reason
+ */
+# define VIR_DOMAIN_STATE_PARAM_CRASHED_PANICKED_S390_REASON 
"crashed.panicked.s390.reason"
+
+int                     virDomainGetStateParams(virDomainPtr domain,
+                                                int *state,
+                                                int *reason,
+                                                virTypedParameterPtr *params,
+                                                int *nparams,
+                                                unsigned int flags);
+
+
 /**
  * VIR_DOMAIN_CPU_STATS_CPUTIME:
  * cpu usage (sum of both vcpu and hypervisor usage) in nanoseconds,
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 5315e33d..fd6ed690 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -220,6 +220,14 @@ typedef int
                         int *reason,
                         unsigned int flags);
 
+typedef int
+(*virDrvDomainGetStateParams)(virDomainPtr domain,
+                              int *state,
+                              int *reason,
+                              virTypedParameterPtr *params,
+                              int *nparams,
+                              unsigned int flags);
+
 typedef int
 (*virDrvDomainGetControlInfo)(virDomainPtr domain,
                               virDomainControlInfoPtr info,
@@ -1390,6 +1398,7 @@ struct _virHypervisorDriver {
     virDrvDomainGetBlkioParameters domainGetBlkioParameters;
     virDrvDomainGetInfo domainGetInfo;
     virDrvDomainGetState domainGetState;
+    virDrvDomainGetStateParams domainGetStateParams;
     virDrvDomainGetControlInfo domainGetControlInfo;
     virDrvDomainSave domainSave;
     virDrvDomainSaveFlags domainSaveFlags;
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index be5b1f67..4fabae82 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -2502,6 +2502,68 @@ virDomainGetState(virDomainPtr domain,
 }
 
 
+/**
+ * virDomainGetStateParams:
+ * @domain: a domain object
+ * @state: returned state of the domain (one of virDomainState)
+ * @reason: returned reason which led to @state (one of virDomain*Reason)
+ * @params: where to store additional state information, must be freed by
+ *          the caller
+ * @nparams: number of items in @params
+ * @flags: bitwise-OR of virDomainGetStateFlags,
+ *         not currently used yet, callers should always pass 0
+ *
+ * Extract domain state. Each state is accompanied by a reason (if known)
+ * and optional detailed information.
+ *
+ * Possible fields returned in @params are defined by VIR_DOMAIN_STATE_PARAMS_*
+ * macros and new fields will likely be introduced in the future so callers
+ * may receive fields that they do not understand in case they talk to a newer
+ * server. The caller is responsible to free allocated memory returned in
+ * @params by calling virTypedParamsFree.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainGetStateParams(virDomainPtr domain,
+                        int *state,
+                        int *reason,
+                        virTypedParameterPtr *params,
+                        int *nparams,
+                        unsigned int flags)
+{
+    virConnectPtr conn = domain->conn;
+
+    VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p, flags=0x%x",
+                     params, nparams, flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    if (params)
+        virCheckNonNullArgGoto(nparams, error);
+
+    if (VIR_DRV_SUPPORTS_FEATURE(conn->driver, conn,
+                                 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
+        flags |= VIR_TYPED_PARAM_STRING_OKAY;
+
+    if (conn->driver->domainGetStateParams) {
+        int ret;
+        ret = conn->driver->domainGetStateParams(domain, state, reason,
+                                                 params, nparams, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
 /**
  * virDomainGetControlInfo:
  * @domain: a domain object
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index dbce3336..26744e27 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -819,4 +819,9 @@ LIBVIRT_5.2.0 {
         virConnectGetStoragePoolCapabilities;
 } LIBVIRT_4.10.0;
 
+LIBVIRT_5.3.0 {
+    global:
+        virDomainGetStateParams;
+} LIBVIRT_5.2.0;
+
 # .... define new API here using predicted next version number ....
-- 
2.19.1

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

Reply via email to