[PATCH v2 3/7] lib: introduce virDomainGetStateParams function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
Signed-off-by: Bjoern Walk <bwalk@xxxxxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h | 76 ++++++++++++++++++++++++++++++++
 src/driver-hypervisor.h          |  9 ++++
 src/libvirt-domain.c             | 64 +++++++++++++++++++++++++++
 src/libvirt_public.syms          |  1 +
 4 files changed, 150 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 1d5bdb54..79ebcba2 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1278,6 +1278,82 @@ int                     virDomainGetState       (virDomainPtr domain,
                                                  int *reason,
                                                  unsigned int flags);
 
+typedef enum {
+    VIR_DOMAIN_STATE_INFO_TYPE_NONE,
+    VIR_DOMAIN_STATE_INFO_TYPE_QEMU_HYPERV,
+    VIR_DOMAIN_STATE_INFO_TYPE_QEMU_S390,
+
+    VIR_DOMAIN_STATE_INFO_TYPE_LAST
+} virDomainStateInfoType;
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_INFO_TYPE:
+ * specifies the type of additional state information available
+ */
+# define VIR_DOMAIN_STATE_PARAMS_INFO_TYPE "info_type"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG1:
+ * Hyper-V-specific panic state information: HV crash MSR1
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG1 "panic_hyperv_msr1"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG2:
+ * Hyper-V-specific panic state information: HV crash MSR2
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG2 "panic_hyperv_msr2"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG3:
+ * Hyper-V-specific panic state information: HV crash MSR3
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG3 "panic_hyperv_msr3"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG4:
+ * Hyper-V-specific panic state information: HV crash MSR4
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG4 "panic_hyperv_msr4"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG5:
+ * Hyper-V-specific panic state information: HV crash MSR5
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_HYPERV_ARG5 "panic_hyperv_msr5"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_CORE:
+ * S390-specific panic state information: panicked core
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_CORE "panic_s390_core"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_PSW_MASK:
+ * S390-specific panic state information: PSW mask
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_PSW_MASK "panic_s390_psw_mask"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_PSW_ADDR:
+ * S390-specific panic state information: PSW address
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_PSW_ADDR "panic_s390_psw_addr"
+
+/**
+ * VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_PSW_REASON:
+ * S390-specific panic state information: human-readable reason
+ */
+# define VIR_DOMAIN_STATE_PARAMS_PANIC_INFO_S390_PSW_REASON "panic_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..349c8498 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -2502,6 +2502,70 @@ 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;
+
+    VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p, flags=0x%x",
+                     params, nparams, flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    virCheckNonNullArgGoto(params, error);
+    virCheckNonNullArgGoto(nparams, error);
+
+    conn = domain->conn;
+
+    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..9e6d473a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -817,6 +817,7 @@ LIBVIRT_4.10.0 {
 LIBVIRT_5.2.0 {
     global:
         virConnectGetStoragePoolCapabilities;
+        virDomainGetStateParams;
 } LIBVIRT_4.10.0;
 
 # .... define new API here using predicted next version number ....
-- 
2.17.0

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux