Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/remote/remote_driver.c | 125 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 125 insertions(+), 0 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index affeb0f..b60d6d4 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7465,6 +7465,122 @@ done:
return rv;
}
+
+static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
+remoteCPUOpen(virConnectPtr conn,
+ virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+ int flags ATTRIBUTE_UNUSED)
+{
+ if (inside_daemon)
+ return VIR_DRV_OPEN_DECLINED;
+
+ if (conn->driver &&
+ STREQ (conn->driver->name, "remote")) {
+ struct private_data *priv = conn->privateData;
+ /* If we're here, the remote driver is already
+ * in use due to a) a QEMU uri, or b) a remote
+ * URI. So we can re-use existing connection
+ */
+ remoteDriverLock(priv);
+ priv->localUses++;
+ conn->cpuPrivateData = priv;
+ remoteDriverUnlock(priv);
+ return VIR_DRV_OPEN_SUCCESS;
+ } else if (conn->networkDriver &&
+ STREQ (conn->networkDriver->name, "remote")) {
+ struct private_data *priv = conn->networkPrivateData;
+ remoteDriverLock(priv);
+ conn->cpuPrivateData = priv;
+ priv->localUses++;
+ remoteDriverUnlock(priv);
+ return VIR_DRV_OPEN_SUCCESS;
+ } else {
+ /* Using a non-remote driver, so we need to open a
+ * new connection for network APIs, forcing it to
+ * use the UNIX transport. This handles Xen driver
+ * which doesn't have its own impl of the network APIs.
+ */
+ struct private_data *priv;
+ int ret;
+ ret = remoteOpenSecondaryDriver(conn,
+ auth,
+ flags,
+ &priv);
+ if (ret == VIR_DRV_OPEN_SUCCESS)
+ conn->cpuPrivateData = priv;
+ return ret;
+ }
+}
+
+
+static int remoteCPUClose(virConnectPtr conn)
+{
+ int ret = 0;
+ struct private_data *priv = conn->cpuPrivateData;
+
+ remoteDriverLock(priv);
+ priv->localUses--;
+ if (!priv->localUses) {
+ ret = doRemoteClose(conn, priv);
+ conn->cpuPrivateData = NULL;
+ remoteDriverUnlock(priv);
+ virMutexDestroy(&priv->lock);
+ VIR_FREE(priv);
+ }
+ if (priv)
+ remoteDriverUnlock(priv);
+ return ret;
+}
+
+
+static int
+remoteCPUCompare (virConnectPtr conn, const char *xmlDesc)
+{
+ struct private_data *priv = conn->cpuPrivateData;
+ remote_cpu_compare_args args;
+ remote_cpu_compare_ret ret;
+ int rv = VIR_CPU_COMPARE_ERROR;
+
+ remoteDriverLock (priv);
+
+ args.xml = (char *) xmlDesc;
+
+ memset (&ret, 0, sizeof (ret));
+ if (call (conn, priv, 0, REMOTE_PROC_CPU_COMPARE,
+ (xdrproc_t) xdr_remote_cpu_compare_args, (char *) &args,
+ (xdrproc_t) xdr_remote_cpu_compare_ret, (char *) &ret) == -1)
+ goto done;
+
+ rv = ret.result;
+
+done:
+ remoteDriverUnlock (priv);
+ return rv;
+}
+
+static char *
+remoteGetHostCPU (virConnectPtr conn)
+{
+ char *rv = NULL;
+ remote_get_host_cpu_ret ret;
+ struct private_data *priv = conn->privateData;
+
+ remoteDriverLock(priv);
+
+ memset (&ret, 0, sizeof ret);
+ if (call (conn, priv, 0, REMOTE_PROC_GET_HOST_CPU,
+ (xdrproc_t) xdr_void, (char *) NULL,
+ (xdrproc_t) xdr_remote_get_host_cpu_ret, (char *)&ret) == -1)
+ goto done;
+
+ /* Caller frees this. */
+ rv = ret.cpu;
+
+done:
+ remoteDriverUnlock(priv);
+ return rv;
+}
+
/*----------------------------------------------------------------------*/
@@ -8830,6 +8946,7 @@ static virDriver remote_driver = {
remoteIsSecure, /* isSecure */
remoteDomainIsActive, /* domainIsActive */
remoteDomainIsPersistent, /* domainIsPersistent */
+ remoteGetHostCPU, /* getHostCPU */
};
static virNetworkDriver network_driver = {
@@ -8928,6 +9045,13 @@ static virSecretDriver secret_driver = {
.undefine = remoteSecretUndefine
};
+static virCPUDriver cpu_driver = {
+ .name = "remote",
+ .open = remoteCPUOpen,
+ .close = remoteCPUClose,
+ .compare = remoteCPUCompare
+};
+
static virDeviceMonitor dev_monitor = {
.name = "remote",
.open = remoteDevMonOpen,
@@ -8967,6 +9091,7 @@ remoteRegister (void)
if (virRegisterStorageDriver (&storage_driver) == -1) return -1;
if (virRegisterDeviceMonitor (&dev_monitor) == -1) return -1;
if (virRegisterSecretDriver (&secret_driver) == -1) return -1;
+ if (virRegisterCPUDriver (&cpu_driver) == -1) return -1;
#ifdef WITH_LIBVIRTD
if (virRegisterStateDriver (&state_driver) == -1) return -1;
#endif
--
1.6.5.6