[libvirt-go PATCH 2/2] Add support for AMD SEV platform info

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

 



Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 connect.go        | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 connect_compat.go | 12 +++++++++++
 connect_compat.h  |  7 +++++++
 3 files changed, 78 insertions(+)

diff --git a/connect.go b/connect.go
index e3e643e..8bb5fe6 100644
--- a/connect.go
+++ b/connect.go
@@ -2765,3 +2765,62 @@ func (c *Connect) GetAllDomainStats(doms []*Domain, statsTypes DomainStatsTypes,
 
 	return stats, nil
 }
+
+type NodeSEVParameters struct {
+	PdhSet             bool
+	Pdh                string
+	CertChainSet       bool
+	CertChain          string
+	CbitposSet         bool
+	Cbitpos            uint
+	ReducedPhysBitsSet bool
+	ReducedPhysBits    uint
+}
+
+func getNodeSEVFieldInfo(params *NodeSEVParameters) map[string]typedParamsFieldInfo {
+	return map[string]typedParamsFieldInfo{
+		C.VIR_NODE_SEV_PDH: typedParamsFieldInfo{
+			set: &params.PdhSet,
+			s:   &params.Pdh,
+		},
+		C.VIR_NODE_SEV_CERT_CHAIN: typedParamsFieldInfo{
+			set: &params.CertChainSet,
+			s:   &params.CertChain,
+		},
+		C.VIR_NODE_SEV_CBITPOS: typedParamsFieldInfo{
+			set: &params.CbitposSet,
+			ui:   &params.Cbitpos,
+		},
+		C.VIR_NODE_SEV_REDUCED_PHYS_BITS: typedParamsFieldInfo{
+			set: &params.ReducedPhysBitsSet,
+			ui:   &params.ReducedPhysBits,
+		},
+	}
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetSEVInfo
+func (c *Connect) GetSEVInfo(flags uint32) (*NodeSEVParameters, error) {
+	if C.LIBVIR_VERSION_NUMBER < 4005000 {
+		return nil, GetNotImplementedError("virNodeGetSEVInfo")
+	}
+
+	params := &NodeSEVParameters{}
+	info := getNodeSEVFieldInfo(params)
+
+	var cparams *C.virTypedParameter
+	var nparams C.int
+
+	ret := C.virNodeGetSEVInfoCompat(c.ptr, (*C.virTypedParameterPtr)(unsafe.Pointer(&cparams)), &nparams, C.uint(flags))
+	if ret == -1 {
+		return nil, GetLastError()
+	}
+
+	defer C.virTypedParamsFree(cparams, nparams)
+
+	_, err := typedParamsUnpackLen(cparams, int(nparams), info)
+	if err != nil {
+		return nil, err
+	}
+
+	return params, nil
+}
diff --git a/connect_compat.go b/connect_compat.go
index 617bc4a..544def2 100644
--- a/connect_compat.go
+++ b/connect_compat.go
@@ -157,5 +157,17 @@ int virConnectCompareHypervisorCPUCompat(virConnectPtr conn,
 #endif
 }
 
+int virNodeGetSEVInfoCompat(virConnectPtr conn,
+			    virTypedParameterPtr *params,
+			    int *nparams,
+			    unsigned int flags)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+    assert(0); // Caller should have checked version
+#else
+    return virNodeGetSEVInfo(conn, params, nparams, flags);
+#endif
+}
+
 */
 import "C"
diff --git a/connect_compat.h b/connect_compat.h
index 432ed0c..cd6d678 100644
--- a/connect_compat.h
+++ b/connect_compat.h
@@ -236,4 +236,11 @@ int virConnectCompareHypervisorCPUCompat(virConnectPtr conn,
 					 const char *xmlCPU,
 					 unsigned int flags);
 
+/* 4.5.0 */
+
+int virNodeGetSEVInfoCompat(virConnectPtr conn,
+                            virTypedParameterPtr *params,
+                            int *nparams,
+                            unsigned int flags);
+
 #endif /* LIBVIRT_GO_CONNECT_COMPAT_H__ */
-- 
2.14.4

--
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