Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
include/libvirt/libvirt.h.in | 7 ++++++
src/driver.h | 9 ++++++++
src/libvirt.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
src/libvirt_public.syms | 1 +
src/remote/remote_driver.c | 1 +
src/remote/remote_protocol.x | 20 ++++++++++++++++-
src/remote_protocol-structs | 11 ++++++++++
7 files changed, 100 insertions(+), 1 deletion(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 594521e..de2d606 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1585,6 +1585,13 @@ int virNodeGetInfo (virConnectPtr
conn,
virNodeInfoPtr info);
char * virConnectGetCapabilities (virConnectPtr conn);
+char * virConnectGetDomainCapabilities(virConnectPtr conn,
+ const char *emulatorbin,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags);
+
int virNodeGetCPUStats (virConnectPtr conn,
int cpuNum,
virNodeCPUStatsPtr params,
diff --git a/src/driver.h b/src/driver.h
index 6e72e92..1fbea1b 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -126,6 +126,14 @@ typedef int
typedef char *
(*virDrvConnectGetCapabilities)(virConnectPtr conn);
+typedef char *
+(*virDrvConnectGetDomainCapabilities)(virConnectPtr conn,
+ const char *emulatorbin,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags);
+
typedef int
(*virDrvConnectListDomains)(virConnectPtr conn,
int *ids,
@@ -1412,6 +1420,7 @@ struct _virDriver {
virDrvDomainGetTime domainGetTime;
virDrvDomainSetTime domainSetTime;
virDrvNodeGetFreePages nodeGetFreePages;
+ virDrvConnectGetDomainCapabilities connectGetDomainCapabilities;
};
diff --git a/src/libvirt.c b/src/libvirt.c
index 566f984..fa4b9de 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -21189,3 +21189,55 @@ virNetworkDHCPLeaseFree(virNetworkDHCPLeasePtr lease)
VIR_FREE(lease->clientid);
VIR_FREE(lease);
}
+
+/**
+ * virConnectGetDomainCapabilities:
+ * @conn: pointer to the hypervisor connection
+ * @emulatorbin: path to emulator
+ * @arch: domain architecture
+ * @machine: machine type
+ * @virttype: virtualization type
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Prior creating a domain (for instance via virDomainCreateXML
+ * or virDomainDefineXML) it may be suitable to know what the
+ * underlying emulator and/or libvirt is capable of. For
+ * instance, if host, libvirt and qemu is capable of VFIO
+ * passthrough and so on.
+ *
+ * Returns NULL in case of error, or an XML string
+ * defining the capabilities.
+ */
+char *
+virConnectGetDomainCapabilities(virConnectPtr conn,
+ const char *emulatorbin,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags)
+{
+ VIR_DEBUG("conn=%p, emulatorbin=%s, arch=%s, "
+ "machine=%s, virttype=%s, flags=%x",
+ conn, emulatorbin, arch, machine, virttype, flags);
+
+ virResetLastError();
+
+ virCheckConnectReturn(conn, NULL);
+
+ if (conn->driver->connectGetDomainCapabilities) {
+ char *ret;
+ ret = conn->driver->connectGetDomainCapabilities(conn, emulatorbin,
+ arch, machine,
+ virttype, flags);
+ if (!ret)
+ goto error;
+ VIR_DEBUG("conn=%p, ret=%s", conn, ret);
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(conn);
+ return NULL;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index f64462e..3088ee8 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -664,6 +664,7 @@ LIBVIRT_1.2.6 {
virNetworkDHCPLeaseFree;
virNetworkGetDHCPLeases;
virNetworkGetDHCPLeasesForMAC;
+ virConnectGetDomainCapabilities;
} LIBVIRT_1.2.5;
# .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 76ce4a9..549c238 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8070,6 +8070,7 @@ static virDriver remote_driver = {
.domainGetTime = remoteDomainGetTime, /* 1.2.5 */
.domainSetTime = remoteDomainSetTime, /* 1.2.5 */
.nodeGetFreePages = remoteNodeGetFreePages, /* 1.2.6 */
+ .connectGetDomainCapabilities = remoteConnectGetDomainCapabilities, /* 1.2.6 */
};
static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 4b75bdb..9d141e9 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -478,6 +478,18 @@ struct remote_connect_get_capabilities_ret {
remote_nonnull_string capabilities;
};
+struct remote_connect_get_domain_capabilities_args {
+ remote_string emulatorbin;
+ remote_string arch;
+ remote_string machine;
+ remote_string virttype;
+ unsigned int flags;
+};
+
+struct remote_connect_get_domain_capabilities_ret {
+ remote_nonnull_string capabilities;
+};
+
struct remote_node_get_cpu_stats_args {
int cpuNum;
int nparams;
@@ -5419,5 +5431,11 @@ enum remote_procedure {
* @generate: none
* @acl: network:read
*/
- REMOTE_PROC_NETWORK_GET_DHCP_LEASES_FOR_MAC = 342
+ REMOTE_PROC_NETWORK_GET_DHCP_LEASES_FOR_MAC = 342,
+
+ /**
+ * @generate: both
+ * @acl: connect:read
+ */
+ REMOTE_PROC_CONNECT_GET_DOMAIN_CAPABILITIES = 343
};
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 222f125..d926cc6 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -148,6 +148,16 @@ struct remote_node_get_info_ret {
struct remote_connect_get_capabilities_ret {
remote_nonnull_string capabilities;
};
+struct remote_connect_get_domain_capabilities_args {
+ remote_string emulatorbin;
+ remote_string arch;
+ remote_string machine;
+ remote_string virttype;
+ u_int flags;
+};
+struct remote_connect_get_domain_capabilities_ret {
+ remote_nonnull_string capabilities;
+};
struct remote_node_get_cpu_stats_args {
int cpuNum;
int nparams;
@@ -2864,4 +2874,5 @@ enum remote_procedure {
REMOTE_PROC_NODE_GET_FREE_PAGES = 340,
REMOTE_PROC_NETWORK_GET_DHCP_LEASES = 341,
REMOTE_PROC_NETWORK_GET_DHCP_LEASES_FOR_MAC = 342,
+ REMOTE_PROC_CONNECT_GET_DOMAIN_CAPABILITIES = 343,
};
--
1.8.5.5