[libvirt PATCH 13/16] src: define virDomainGetTainting API

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

 



This API allows fetching a list of tainting codes against the domain.

Internally tainting is defined as a bitmask with enum fields. Most,
but not all, of the fields are somewhat QEMU specific in reality
though. The idea of exposing the enum in the public API thus feels
a little questionable. This API takes the approach of exposing the
the string format of the enum codes and declaring the string codes
are (potentially) hypervisor specific.

IOW, callers of the API can display the codes but should treat them
as a opaque strings.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h |  3 ++
 src/driver-hypervisor.h          |  5 ++++
 src/libvirt-domain.c             | 48 ++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  1 +
 4 files changed, 57 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index cef16e6361..d04140bf60 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -5122,5 +5122,8 @@ int virDomainAuthorizedSSHKeysSet(virDomainPtr domain,
 int virDomainGetDeprecations(virDomainPtr domain,
                              char ***msgs,
                              unsigned int flags);
+int virDomainGetTainting(virDomainPtr domain,
+                         char ***codes,
+                         unsigned int flags);
 
 #endif /* LIBVIRT_DOMAIN_H */
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 2f804dba1f..96111cd10a 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1404,6 +1404,10 @@ typedef int
 (*virDrvDomainGetDeprecations)(virDomainPtr domain,
                                char ***msgs,
                                unsigned int flags);
+typedef int
+(*virDrvDomainGetTainting)(virDomainPtr domain,
+                           char ***codes,
+                           unsigned int flags);
 
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
@@ -1671,4 +1675,5 @@ struct _virHypervisorDriver {
     virDrvDomainAuthorizedSSHKeysGet domainAuthorizedSSHKeysGet;
     virDrvDomainAuthorizedSSHKeysSet domainAuthorizedSSHKeysSet;
     virDrvDomainGetDeprecations domainGetDeprecations;
+    virDrvDomainGetTainting domainGetTainting;
 };
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 9e3b118483..c053f35d3e 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -13149,3 +13149,51 @@ virDomainGetDeprecations(virDomainPtr domain,
     virDispatchError(conn);
     return -1;
 }
+
+
+/**
+ * virDomainGetTainting:
+ * @domain: a domain object
+ * @codes: pointer to a variable to store tainting codes
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Fetch a list of all tainting codes for the VM and
+ * store them into @msgs array which is allocated upon
+ * successful return and is NULL terminated. The caller is
+ * responsible for freeing @msgs when no longer needed.
+ *
+ * Note that some hypervisors may only report tainting
+ * codes while the VM is in a running state. The list
+ * tainting codes is also hypervisor specific.
+ *
+ * Returns: number of messages stored in @msgs,
+ *          -1 otherwise.
+ */
+int
+virDomainGetTainting(virDomainPtr domain,
+                     char ***codes,
+                     unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "codes=%p, flags=0x%x", codes, flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+    virCheckNonNullArgGoto(codes, error);
+
+    if (conn->driver->domainGetTainting) {
+        int ret;
+        ret = conn->driver->domainGetTainting(domain, codes, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+ error:
+    virDispatchError(conn);
+    return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 345c5685bf..246fbaf1dc 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -882,6 +882,7 @@ LIBVIRT_6.10.0 {
 LIBVIRT_7.1.0 {
     global:
         virDomainGetDeprecations;
+        virDomainGetTainting;
 } LIBVIRT_6.10.0;
 
 # .... define new API here using predicted next version number ....
-- 
2.29.2




[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