+Wed Apr 4 15:18:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
+
+ * src/xen_unified.c et al: Unified Xen driver. Architecture
+ described here:
+ https://www.redhat.com/archives/libvir-list/2007-March/msg00396.html
+
Wed Apr 4 10:30:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* configure.in, qemud/Makefile.am: Set QEMUD_PID_FILE macro
#include "xen_internal.h"
#include "xend_internal.h"
#include "xs_internal.h"
+#include "xen_unified.h"
static int fdServer = -1;
static int debug = 0;
proxyInitXen(void) {
int ret;
unsigned long xenVersion2;
+ xenUnifiedPrivatePtr priv;
+
+ /* Allocate per-connection private data. */
+ priv = malloc (sizeof *priv);
+ if (!priv) {
+ fprintf(stderr, "Failed to allocate private data\n");
+ return(-1);
+ }
+ conn->privateData = priv;
+
+ priv->handle = -1;
+ priv->xendConfigVersion = -1;
+ priv->type = -1;
+ priv->len = -1;
+ priv->addr = NULL;
+ priv->xshandle = NULL;
+ priv->proxy = -1;
ret = xenHypervisorOpen(conn, NULL, VIR_DRV_OPEN_QUIET);
if (ret < 0) {
hash.c hash.h \
test.c test.h \
xml.c xml.h \
+ xen_unified.c xen_unified.h \
xen_internal.c xen_internal.h \
xs_internal.c xs_internal.h \
xend_internal.c xend_internal.h \
* List of registered drivers numbers
*/
typedef enum {
- VIR_DRV_XEN_HYPERVISOR = 1,
- VIR_DRV_XEN_STORE = 2,
- VIR_DRV_XEN_DAEMON = 3,
- VIR_DRV_TEST = 4,
- VIR_DRV_XEN_PROXY = 5,
- VIR_DRV_XEN_XM = 6,
- VIR_DRV_QEMU = 7
+ VIR_DRV_XEN_UNIFIED = 1,
+ VIR_DRV_TEST = 2,
+ VIR_DRV_QEMU = 3,
} virDrvNo;
VIR_DRV_OPEN_RO = 2
} virDrvOpenFlag;
-typedef int
- (*virDrvOpen) (virConnectPtr conn,
- const char *name,
- int flags);
+/* Status codes returned from driver open call. */
+typedef enum {
+ /* Opened successfully. */
+ VIR_DRV_OPEN_SUCCESS = 0,
+
+ /* 'name' is not for us. */
+ VIR_DRV_OPEN_DECLINED = -1,
+
+ /* 'name' is for us, but there was some error. virConnectOpen will
+ * return an error rather than continue probing the other drivers.
+ */
+ VIR_DRV_OPEN_ERROR = -2,
+} virDrvOpenStatus;
+
+typedef virDrvOpenStatus
+ (*virDrvOpen) (virConnectPtr conn,
+ const char *name,
+ int flags);
typedef int
(*virDrvClose) (virConnectPtr conn);
typedef const char *
(*virDrvGetVersion) (virConnectPtr conn,
unsigned long *hvVer);
typedef int
- (*virDrvGetMaxVcpus) (virConnectPtr conn);
+ (*virDrvGetMaxVcpus) (virConnectPtr conn, const char *type);
typedef int
(*virDrvNodeGetInfo) (virConnectPtr conn,
virNodeInfoPtr info);
*
* Structure associated to a virtualization driver, defining the various
* entry points for it.
+ *
+ * All drivers must support the following fields/methods:
+ * - no
+ * - name
+ * - open
+ * - close
*/
struct _virDriver {
int no; /* the number virDrvNo */
*
* Structure associated to a network virtualization driver, defining the various
* entry points for it.
+ *
+ * All drivers must support the following fields/methods:
+ * - open
+ * - close
*/
struct _virNetworkDriver {
virDrvOpen open;
goto failed;
}
ret->magic = VIR_CONNECT_MAGIC;
- ret->nb_drivers = 0;
- ret->handle = -1;
- ret->qemud_fd = -1;
+ ret->driver = NULL;
+ ret->networkDriver = NULL;
+ ret->privateData = NULL;
+ ret->networkPrivateData = NULL;
ret->domains = virHashCreate(20);
if (ret->domains == NULL)
goto failed;
unsigned int magic; /* specific value to check */
int uses; /* reference count */
- /* the list of available drivers for that connection */
- virDriverPtr drivers[MAX_DRIVERS];
- int nb_drivers;
-
- /* the list of available network drivers */
- virNetworkDriverPtr networkDrivers[MAX_DRIVERS];
- int nb_network_drivers;
-
- /* extra data needed by drivers */
- int handle; /* internal handle used for hypercall */
- struct xs_handle *xshandle;/* handle to talk to the xenstore */
- int proxy; /* file descriptor if using the proxy */
- int xendConfigVersion; /* XenD config version */
-
- /* connection to xend */
- int type; /* PF_UNIX or PF_INET */
- int len; /* lenght of addr */
- struct sockaddr *addr; /* type of address used */
- struct sockaddr_un addr_un; /* the unix address */
- struct sockaddr_in addr_in; /* the inet address */
-
- int qemud_fd; /* connection to qemud */
-
- /* error stuff */
+
+ /* The underlying hypervisor driver and network driver. */
+ virDriverPtr driver;
+ virNetworkDriverPtr networkDriver;
+
+ /* Private data pointer which can be used by driver and
+ * network driver as they wish.
+ * NB: 'private' is a reserved word in C++.
+ */
+ void * privateData;
+ void * networkPrivateData;
+
+ /* Per-connection error. */
virError err; /* the last error */
virErrorFunc handler; /* associated handlet */
void *userData; /* the user data */
#include "internal.h"
#include "driver.h"
-#ifdef WITH_XEN
-#include <xs.h>
-#include "xen_internal.h"
-#include "xend_internal.h"
-#include "xs_internal.h"
-#include "xm_internal.h"
-#endif
-#include "proxy_internal.h"
#include "xml.h"
#include "test.h"
+#include "xen_unified.h"
#include "qemu_internal.h"
/*
return (-1);
/*
- * Note that the order is important the first ones have a higher priority
+ * Note that the order is important: the first ones have a higher
+ * priority when calling virConnectOpen.
*/
#ifdef WITH_XEN
- xenHypervisorRegister();
- xenProxyRegister();
- xenDaemonRegister();
- xenStoreRegister();
- xenXMRegister();
+ if (xenUnifiedRegister () == -1) return -1;
#endif
#ifdef WITH_TEST
- testRegister();
+ if (testRegister() == -1) return -1;
#endif
#ifdef WITH_QEMU
- qemuRegister();
+ if (qemuRegister() == -1) return -1;
#endif
return(0);
return(-1);
}
+ if (driver->no < 0) {
+ virLibConnError
+ (NULL, VIR_ERR_INVALID_ARG,
+ "virRegisterDriver: tried to register an internal Xen driver");
+ return -1;
+ }
+
virDriverTab[virDriverTabCount] = driver;
return virDriverTabCount++;
}
return (0);
}
-/**
- * virConnectOpen:
- * @name: optional argument currently unused, pass NULL
- *
- * This function should be called first to get a connection to the
- * Hypervisor and xen store
- *
- * Returns a pointer to the hypervisor connection or NULL in case of error
- */
-virConnectPtr
-virConnectOpen(const char *name)
+static virConnectPtr
+do_open (const char *name, int flags)
{
- int i, res, for_xen = 0;
+ int i, res;
virConnectPtr ret = NULL;
if (!initialized)
if (virInitialize() < 0)
return NULL;
- if (name == NULL) {
- name = "Xen";
- for_xen = 1;
- } else if (!strncasecmp(name, "xen", 3)) {
- for_xen = 1;
- }
-
ret = virGetConnect();
if (ret == NULL) {
virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
goto failed;
}
- for (i = 0;i < virDriverTabCount;i++) {
- if ((virDriverTab[i]->open != NULL)) {
- res = virDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET);
- /*
- * For a default connect to Xen make sure we manage to contact
- * all related drivers.
- */
- if ((res < 0) && (for_xen) &&
- (!strncasecmp(virDriverTab[i]->name, "xen", 3)) &&
- (virDriverTab[i]->no != VIR_DRV_XEN_PROXY))
- goto failed;
- if (res == 0)
- ret->drivers[ret->nb_drivers++] = virDriverTab[i];
- }
+ for (i = 0; i < virDriverTabCount; i++) {
+ res = virDriverTab[i]->open (ret, name, flags);
+ if (res == VIR_DRV_OPEN_ERROR) goto failed;
+ else if (res == VIR_DRV_OPEN_SUCCESS) {
+ ret->driver = virDriverTab[i];
+ break;
+ }
}
- for (i = 0;i < virNetworkDriverTabCount;i++) {
- if ((virNetworkDriverTab[i]->open != NULL) &&
- (res = virNetworkDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET)) == 0) {
- ret->networkDrivers[ret->nb_network_drivers++] = virNetworkDriverTab[i];
- }
+ if (!ret->driver) {
+ virLibConnError (NULL, VIR_ERR_NO_SUPPORT, name);
+ goto failed;
}
- if ((ret->nb_drivers == 0) && (ret->nb_network_drivers == 0)) {
- /* we failed to find an adequate driver */
- virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
- goto failed;
+ for (i = 0; i < virNetworkDriverTabCount; i++) {
+ res = virNetworkDriverTab[i]->open (ret, name, flags);
+ if (res == -1) goto failed;
+ else if (res == 0) {
+ ret->networkDriver = virNetworkDriverTab[i];
+ break;
+ }
}
- return (ret);
+ return ret;
failed:
- if (ret != NULL) {
- for (i = 0;i < ret->nb_drivers;i++) {
- if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
- ret->drivers[i]->close(ret);
- }
- for (i = 0;i < ret->nb_network_drivers;i++) {
- if ((ret->networkDrivers[i] != NULL) && (ret->networkDrivers[i]->close != NULL))
- ret->networkDrivers[i]->close(ret);
- }
+ if (ret->driver) ret->driver->close (ret);
virFreeConnect(ret);
- }
return (NULL);
}
+/**
+ * virConnectOpen:
+ * @name: optional argument currently unused, pass NULL
+ *
+ * This function should be called first to get a connection to the
+ * Hypervisor and xen store
+ *
+ * Returns a pointer to the hypervisor connection or NULL in case of error
+ */
+virConnectPtr
+virConnectOpen (const char *name)
+{
+ return do_open (name, VIR_DRV_OPEN_QUIET);
+}
+
/**
* virConnectOpenReadOnly:
* @name: optional argument currently unused, pass NULL
virConnectPtr
virConnectOpenReadOnly(const char *name)
{
- int i, res;
- virConnectPtr ret = NULL;
-
- if (!initialized)
- if (virInitialize() < 0)
- return NULL;
-
- if (name == NULL)
- name = "Xen";
-
- ret = virGetConnect();
- if (ret == NULL) {
- virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
- goto failed;
- }
-
- for (i = 0;i < virDriverTabCount;i++) {
- if ((virDriverTab[i]->open != NULL)) {
- res = virDriverTab[i]->open(ret, name,
- VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO);
- if (res == 0)
- ret->drivers[ret->nb_drivers++] = virDriverTab[i];
-
- }
- }
- for (i = 0;i < virNetworkDriverTabCount;i++) {
- if ((virNetworkDriverTab[i]->open != NULL) &&
- (res = virNetworkDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET|VIR_DRV_OPEN_RO)) == 0) {
- ret->networkDrivers[ret->nb_network_drivers++] = virNetworkDriverTab[i];
- }
- }
- if ((ret->nb_drivers == 0) && (ret->nb_network_drivers == 0)) {
- if (name == NULL)
- virLibConnError(NULL, VIR_ERR_NO_CONNECT,
- _("Xen Daemon or Xen Store"));
- else
- /* we failed to find an adequate driver */
- virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
- goto failed;
- }
- ret->flags = VIR_CONNECT_RO;
-
- return (ret);
-
-failed:
- if (ret != NULL) {
- for (i = 0;i < ret->nb_drivers;i++) {
- if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
- ret->drivers[i]->close(ret);
- }
- for (i = 0;i < ret->nb_network_drivers;i++) {
- if ((ret->networkDrivers[i] != NULL) && (ret->networkDrivers[i]->close != NULL))
- ret->networkDrivers[i]->close(ret);
- }
- virFreeConnect(ret);
- }
- return (NULL);
+ return do_open (name, VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO);
}
/**
int
virConnectClose(virConnectPtr conn)
{
- int i;
-
if (!VIR_IS_CONNECT(conn))
return (-1);
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) && (conn->drivers[i]->close != NULL))
- conn->drivers[i]->close(conn);
- }
- for (i = 0;i < conn->nb_network_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) && (conn->networkDrivers[i]->close != NULL))
- conn->networkDrivers[i]->close(conn);
- }
+
+ conn->driver->close (conn);
+ if (conn->networkDriver)
+ conn->networkDriver->close (conn);
+
if (virFreeConnect(conn) < 0)
return (-1);
return (0);
const char *
virConnectGetType(virConnectPtr conn)
{
- int i;
const char *ret;
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
}
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->type != NULL)) {
- ret = conn->drivers[i]->type(conn);
- if (ret != NULL)
- return(ret);
- }
- }
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->name != NULL)) {
- return(conn->drivers[i]->name);
- }
+
+ if (conn->driver->type) {
+ ret = conn->driver->type (conn);
+ if (ret) return ret;
}
- return(NULL);
+ return conn->driver->name;
}
/**
int
virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
{
- int ret, i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
return (-1);
}
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->version != NULL)) {
- ret = conn->drivers[i]->version(conn, hvVer);
- if (ret == 0)
- return(0);
- }
- }
+ if (conn->driver->version)
+ return conn->driver->version (conn, hvVer);
- return (-1);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return -1;
}
/**
virConnectGetMaxVcpus(virConnectPtr conn,
const char *type)
{
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
- if (type == NULL)
- type = "Xen";
- for (i = 0;i < MAX_DRIVERS;i++) {
- if ((virDriverTab[i] != NULL) &&
- (!strcmp(virDriverTab[i]->name, type))) {
- ret = conn->drivers[i]->getMaxVcpus(conn);
- if (ret >= 0)
- return(ret);
- }
- }
-
- return (-1);
+ if (conn->driver->getMaxVcpus)
+ return conn->driver->getMaxVcpus (conn, type);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return -1;
}
/**
int
virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
{
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->listDomains != NULL)) {
- ret = conn->drivers[i]->listDomains(conn, ids, maxids);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->driver->listDomains)
+ return conn->driver->listDomains (conn, ids, maxids);
- return (-1);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return -1;
}
/**
int
virConnectNumOfDomains(virConnectPtr conn)
{
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->numOfDomains != NULL)) {
- ret = conn->drivers[i]->numOfDomains(conn);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->driver->numOfDomains)
+ return conn->driver->numOfDomains (conn);
- return(-1);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return -1;
}
/**
virDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
unsigned int flags)
{
- virDomainPtr ret;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainCreateLinux != NULL)) {
- ret = conn->drivers[i]->domainCreateLinux(conn, xmlDesc, flags);
- if (ret != NULL)
- return(ret);
- }
- }
- return(NULL);
+ if (conn->driver->domainCreateLinux)
+ return conn->driver->domainCreateLinux (conn, xmlDesc, flags);
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return NULL;
}
virDomainPtr
virDomainLookupByID(virConnectPtr conn, int id)
{
- virDomainPtr ret;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainLookupByID != NULL)) {
- ret = conn->drivers[i]->domainLookupByID(conn, id);
- if (ret)
- return(ret);
- }
- }
+ if (conn->driver->domainLookupByID)
+ return conn->driver->domainLookupByID (conn, id);
- return (NULL);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return NULL;
}
/**
virDomainPtr
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
- virDomainPtr ret;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainLookupByUUID != NULL)) {
- ret = conn->drivers[i]->domainLookupByUUID(conn, uuid);
- if (ret)
- return(ret);
- }
- }
+ if (conn->driver->domainLookupByUUID)
+ return conn->driver->domainLookupByUUID (conn, uuid);
- return (NULL);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return NULL;
}
/**
virDomainPtr
virDomainLookupByName(virConnectPtr conn, const char *name)
{
- virDomainPtr ret = NULL;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainLookupByName != NULL)) {
- ret = conn->drivers[i]->domainLookupByName(conn, name);
- if (ret)
- return(ret);
- }
- }
- return (NULL);
+ if (conn->driver->domainLookupByName)
+ return conn->driver->domainLookupByName (conn, name);
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return NULL;
}
/**
int
virDomainDestroy(virDomainPtr domain)
{
- int i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
return (-1);
}
- /*
- * Go though the driver registered entry points but use the
- * XEN_HYPERVISOR directly only as a last mechanism
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainDestroy != NULL)) {
- if (conn->drivers[i]->domainDestroy(domain) == 0)
- return (0);
- }
- }
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainDestroy != NULL)) {
- if (conn->drivers[i]->domainDestroy(domain) == 0)
- return (0);
- }
- }
+ if (conn->driver->domainDestroy)
+ return conn->driver->domainDestroy (domain);
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return -1;
}
/**
int
virDomainSuspend(virDomainPtr domain)
{
- int i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
conn = domain->conn;
- /*
- * Go though the driver registered entry points but use the
- * XEN_HYPERVISOR directly only as a last mechanism
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainSuspend != NULL)) {
- if (conn->drivers[i]->domainSuspend(domain) == 0)
- return (0);
- }
- }
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainSuspend != NULL)) {
- if (conn->drivers[i]->domainSuspend(domain) == 0)
- return (0);
- }
- }
+ if (conn->driver->domainSuspend)
+ return conn->driver->domainSuspend (domain);
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return -1;
}
/**
int
virDomainResume(virDomainPtr domain)
{
- int i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
conn = domain->conn;
- /*
- * Go though the driver registered entry points but use the
- * XEN_HYPERVISOR directly only as a last mechanism
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainResume != NULL)) {
- if (conn->drivers[i]->domainResume(domain) == 0)
- return(0);
- }
- }
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainResume != NULL)) {
- if (conn->drivers[i]->domainResume(domain) == 0)
- return(0);
- }
- }
+ if (conn->driver->domainResume)
+ return conn->driver->domainResume (domain);
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ return -1;
}
/**
int
virDomainSave(virDomainPtr domain, const char *to)
{
- int ret, i;
char filepath[4096];
virConnectPtr conn;
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainSave != NULL)) {
- ret = conn->drivers[i]->domainSave(domain, to);
- if (ret == 0)
- return(0);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainSave)
+ return conn->driver->domainSave (domain, to);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainRestore(virConnectPtr conn, const char *from)
{
- int ret, i;
char filepath[4096];
if (!VIR_IS_CONNECT(conn)) {
from = &filepath[0];
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainSave != NULL)) {
- ret = conn->drivers[i]->domainRestore(conn, from);
- if (ret == 0)
- return(0);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainRestore)
+ return conn->driver->domainRestore (conn, from);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainCoreDump(virDomainPtr domain, const char *to, int flags)
{
- int ret, i;
char filepath[4096];
virConnectPtr conn;
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainCoreDump != NULL)) {
- ret = conn->drivers[i]->domainCoreDump(domain, to, flags);
- if (ret == 0)
- return(0);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainCoreDump)
+ return conn->driver->domainCoreDump (domain, to, flags);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainShutdown(virDomainPtr domain)
{
- int ret = -1, i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
conn = domain->conn;
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainShutdown != NULL)) {
- if (conn->drivers[i]->domainShutdown(domain) == 0)
- ret = 0;
- }
- }
-
- if (ret != 0) {
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (ret);
- }
+ if (conn->driver->domainShutdown)
+ return conn->driver->domainShutdown (domain);
- return (ret);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainReboot(virDomainPtr domain, unsigned int flags)
{
- int ret = -1, i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
conn = domain->conn;
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainReboot != NULL)) {
- if (conn->drivers[i]->domainReboot(domain, flags) == 0)
- ret = 0;
- }
- }
-
- if (ret != 0) {
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (ret);
- }
+ if (conn->driver->domainReboot)
+ return conn->driver->domainReboot (domain, flags);
- return (ret);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
if (domain->id == 0) {
memset(uuid, 0, VIR_UUID_BUFLEN);
} else {
-#ifdef WITH_XEN
+#if 0
+ /* Probably legacy code: It appears that we always fill in
+ * the UUID when creating the virDomain structure, so this
+ * shouldn't be necessary.
+ */
if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) &&
(domain->uuid[2] == 0) && (domain->uuid[3] == 0) &&
(domain->uuid[4] == 0) && (domain->uuid[5] == 0) &&
}
if (virDomainGetUUID(domain, &uuid[0]))
- return (-1);
+ return (-1);
snprintf(buf, VIR_UUID_STRING_BUFLEN,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
char *
virDomainGetOSType(virDomainPtr domain)
{
- char *str = NULL;
- int i;
+ virConnectPtr conn;
if (!VIR_IS_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
return (NULL);
}
- for (i = 0;i < domain->conn->nb_drivers;i++) {
- if ((domain->conn->drivers[i] != NULL) &&
- (domain->conn->drivers[i]->domainGetOSType != NULL)) {
- str = domain->conn->drivers[i]->domainGetOSType(domain);
- if (str != NULL)
- break;
- }
- }
+ conn = domain->conn;
+
+ if (conn->driver->domainGetOSType)
+ return conn->driver->domainGetOSType (domain);
- return (str);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
unsigned long
virDomainGetMaxMemory(virDomainPtr domain)
{
- unsigned long ret = 0;
virConnectPtr conn;
- int i;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
conn = domain->conn;
- /*
- * in that case instead of trying only though one method try all availble.
- * If needed that can be changed back if it's a performcance problem.
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainGetMaxMemory != NULL)) {
- ret = conn->drivers[i]->domainGetMaxMemory(domain);
- if (ret != 0)
- return(ret);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainGetMaxMemory)
+ return conn->driver->domainGetMaxMemory (domain);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return 0;
}
/**
int
virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
{
- int ret = -1 , i;
virConnectPtr conn;
if (domain == NULL) {
}
conn = domain->conn;
- /*
- * in that case instead of trying only though one method try all availble.
- * If needed that can be changed back if it's a performcance problem.
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainSetMaxMemory != NULL)) {
- if (conn->drivers[i]->domainSetMaxMemory(domain, memory) == 0)
- ret = 0;
- }
- }
- if (ret != 0) {
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
- }
- return (ret);
+ if (conn->driver->domainSetMaxMemory)
+ return conn->driver->domainSetMaxMemory (domain, memory);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainSetMemory(virDomainPtr domain, unsigned long memory)
{
- int ret = -1 , i;
virConnectPtr conn;
if (domain == NULL) {
conn = domain->conn;
- /*
- * in that case instead of trying only though one method try all availble.
- * If needed that can be changed back if it's a performcance problem.
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainSetMemory != NULL)) {
- if (conn->drivers[i]->domainSetMemory(domain, memory) == 0)
- ret = 0;
- }
- }
- if (ret != 0) {
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
- }
- return (ret);
+ if (conn->driver->domainSetMemory)
+ return conn->driver->domainSetMemory (domain, memory);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
{
- int i;
+ virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
memset(info, 0, sizeof(virDomainInfo));
- for (i = 0;i < domain->conn->nb_drivers;i++) {
- if ((domain->conn->drivers[i] != NULL) &&
- (domain->conn->drivers[i]->domainGetInfo != NULL)) {
- if (domain->conn->drivers[i]->domainGetInfo(domain, info) == 0)
- return 0;
- }
- }
+ conn = domain->conn;
+
+ if (conn->driver->domainGetInfo)
+ return conn->driver->domainGetInfo (domain, info);
- return (-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
char *
virDomainGetXMLDesc(virDomainPtr domain, int flags)
{
- int i;
- char *ret = NULL;
+ virConnectPtr conn;
+
if (!VIR_IS_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
return (NULL);
return (NULL);
}
- for (i = 0;i < domain->conn->nb_drivers;i++) {
- if ((domain->conn->drivers[i] != NULL) &&
- (domain->conn->drivers[i]->domainDumpXML != NULL)) {
- ret = domain->conn->drivers[i]->domainDumpXML(domain, flags);
- if (ret)
- break;
- }
- }
- if (!ret) {
- virLibConnError(domain->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (NULL);
- }
- return(ret);
+ conn = domain->conn;
+
+ if (conn->driver->domainDumpXML)
+ return conn->driver->domainDumpXML (domain, flags);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
* Returns 0 in case of success and -1 in case of failure.
*/
int
-virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) {
- int i;
- int ret = -1;
-
+virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
+{
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
return (-1);
}
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->nodeGetInfo != NULL)) {
- ret = conn->drivers[i]->nodeGetInfo(conn, info);
- if (ret == 0)
- break;
- }
- }
- if (ret != 0) {
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
- }
- return(0);
+ if (conn->driver->nodeGetInfo)
+ return conn->driver->nodeGetInfo (conn, info);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
char *
virConnectGetCapabilities (virConnectPtr conn)
{
- int i;
-
if (!VIR_IS_CONNECT (conn)) {
virLibConnError (conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return NULL;
}
- for (i = 0; i < conn->nb_drivers; i++) {
- if (conn->drivers[i] && conn->drivers[i]->getCapabilities) {
- return conn->drivers[i]->getCapabilities (conn);
- }
- }
+ if (conn->driver->getCapabilities)
+ return conn->driver->getCapabilities (conn);
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
return NULL;
}
*/
virDomainPtr
virDomainDefineXML(virConnectPtr conn, const char *xml) {
- virDomainPtr ret = NULL;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainDefineXML != NULL)) {
- ret = conn->drivers[i]->domainDefineXML(conn, xml);
- if (ret)
- return(ret);
- }
- }
+ if (conn->driver->domainDefineXML)
+ return conn->driver->domainDefineXML (conn, xml);
- return(ret);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
*/
int
virDomainUndefine(virDomainPtr domain) {
- int ret, i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainUndefine != NULL)) {
- ret = conn->drivers[i]->domainUndefine(domain);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->driver->domainUndefine)
+ return conn->driver->domainUndefine (domain);
- return(-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virConnectNumOfDefinedDomains(virConnectPtr conn)
{
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->numOfDefinedDomains != NULL)) {
- ret = conn->drivers[i]->numOfDefinedDomains(conn);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->driver->numOfDefinedDomains)
+ return conn->driver->numOfDefinedDomains (conn);
- return(-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virConnectListDefinedDomains(virConnectPtr conn, char **const names,
int maxnames) {
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->listDefinedDomains != NULL)) {
- ret = conn->drivers[i]->listDefinedDomains(conn, names, maxnames);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->driver->listDefinedDomains)
+ return conn->driver->listDefinedDomains (conn, names, maxnames);
- return (-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
*/
int
virDomainCreate(virDomainPtr domain) {
- int i, ret = -1;
virConnectPtr conn;
+
if (domain == NULL) {
TODO
return (-1);
return (-1);
}
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainCreate != NULL)) {
- ret = conn->drivers[i]->domainCreate(domain);
- if (ret == 0)
- return(ret);
- }
- }
- return(ret);
+ if (conn->driver->domainCreate)
+ return conn->driver->domainCreate (domain);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
*/
int
virDomainGetAutostart(virDomainPtr domain,
- int *autostart) {
- int i;
+ int *autostart)
+{
+ virConnectPtr conn;
if (!VIR_IS_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
return (-1);
}
- for (i = 0;i < domain->conn->nb_drivers;i++) {
- if ((domain->conn->drivers[i] != NULL) &&
- (domain->conn->drivers[i]->domainGetAutostart != NULL) &&
- (domain->conn->drivers[i]->domainGetAutostart(domain, autostart) == 0))
- return (0);
- }
- virLibConnError(domain->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ conn = domain->conn;
+
+ if (conn->driver->domainGetAutostart)
+ return conn->driver->domainGetAutostart (domain, autostart);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
*/
int
virDomainSetAutostart(virDomainPtr domain,
- int autostart) {
- int i;
+ int autostart)
+{
+ virConnectPtr conn;
if (!VIR_IS_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
return (-1);
}
- for (i = 0;i < domain->conn->nb_drivers;i++) {
- if ((domain->conn->drivers[i] != NULL) &&
- (domain->conn->drivers[i]->domainSetAutostart != NULL) &&
- (domain->conn->drivers[i]->domainSetAutostart(domain, autostart) == 0))
- return (0);
- }
- virLibConnError(domain->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ conn = domain->conn;
+
+ if (conn->driver->domainSetAutostart)
+ return conn->driver->domainSetAutostart (domain, autostart);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
{
- int i;
virConnectPtr conn;
if (domain == NULL) {
}
conn = domain->conn;
- /*
- * Go though the driver registered entry points but use the
- * XEN_HYPERVISOR directly only as a last mechanism
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainSetVcpus != NULL)) {
- if (conn->drivers[i]->domainSetVcpus(domain, nvcpus) == 0)
- return(0);
- }
- }
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
- (conn->drivers[i]->domainSetVcpus != NULL)) {
- if (conn->drivers[i]->domainSetVcpus(domain, nvcpus) == 0)
- return(0);
- }
- }
+ if (conn->driver->domainSetVcpus)
+ return conn->driver->domainSetVcpus (domain, nvcpus);
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
unsigned char *cpumap, int maplen)
{
- int i;
virConnectPtr conn;
if (domain == NULL) {
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
+
conn = domain->conn;
- /*
- * Go though the driver registered entry points
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainPinVcpu != NULL)) {
- if (conn->drivers[i]->domainPinVcpu(domain, vcpu,
- cpumap, maplen) == 0)
- return(0);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainPinVcpu)
+ return conn->driver->domainPinVcpu (domain, vcpu, cpumap, maplen);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
unsigned char *cpumaps, int maplen)
{
- int ret;
- int i;
virConnectPtr conn;
if (domain == NULL) {
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
+
conn = domain->conn;
- /*
- * Go though the driver registered entry points
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainGetVcpus != NULL)) {
- ret = conn->drivers[i]->domainGetVcpus(domain, info, maxinfo,
- cpumaps, maplen);
- if (ret >= 0)
- return(ret);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainGetVcpus)
+ return conn->driver->domainGetVcpus (domain, info, maxinfo,
+ cpumaps, maplen);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
* Returns the maximum of virtual CPU or -1 in case of error.
*/
int
-virDomainGetMaxVcpus(virDomainPtr domain) {
- int i;
- int ret = 0;
+virDomainGetMaxVcpus(virDomainPtr domain)
+{
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
conn = domain->conn;
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainGetMaxVcpus != NULL)) {
- ret = conn->drivers[i]->domainGetMaxVcpus(domain);
- if (ret != 0)
- return(ret);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainGetMaxVcpus)
+ return conn->driver->domainGetMaxVcpus (domain);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
int
virDomainAttachDevice(virDomainPtr domain, char *xml)
{
- int ret;
- int i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
}
conn = domain->conn;
- /*
- * Go though the driver registered entry points
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainAttachDevice != NULL)) {
- ret = conn->drivers[i]->domainAttachDevice(domain, xml);
- if (ret >= 0)
- return(ret);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainAttachDevice)
+ return conn->driver->domainAttachDevice (domain, xml);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virDomainDetachDevice(virDomainPtr domain, char *xml)
{
- int ret;
- int i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
}
conn = domain->conn;
- /*
- * Go though the driver registered entry points
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->drivers[i] != NULL) &&
- (conn->drivers[i]->domainDetachDevice != NULL)) {
- ret = conn->drivers[i]->domainDetachDevice(domain, xml);
- if (ret >= 0)
- return(ret);
- }
- }
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ if (conn->driver->domainDetachDevice)
+ return conn->driver->domainDetachDevice (domain, xml);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virConnectNumOfNetworks(virConnectPtr conn)
{
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_network_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->numOfNetworks != NULL)) {
- ret = conn->networkDrivers[i]->numOfNetworks(conn);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->numOfNetworks)
+ return conn->networkDriver->numOfNetworks (conn);
- return(-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
{
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->listNetworks != NULL)) {
- ret = conn->networkDrivers[i]->listNetworks(conn, names, maxnames);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->listNetworks)
+ return conn->networkDriver->listNetworks (conn, names, maxnames);
- return (-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virConnectNumOfDefinedNetworks(virConnectPtr conn)
{
- int ret = -1;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->numOfDefinedNetworks != NULL)) {
- ret = conn->networkDrivers[i]->numOfDefinedNetworks(conn);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->numOfDefinedNetworks)
+ return conn->networkDriver->numOfDefinedNetworks (conn);
- return(-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
*/
int
virConnectListDefinedNetworks(virConnectPtr conn, char **const names,
- int maxnames) {
- int ret = -1;
- int i;
-
+ int maxnames)
+{
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->listDefinedNetworks != NULL)) {
- ret = conn->networkDrivers[i]->listDefinedNetworks(conn, names, maxnames);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->listDefinedNetworks)
+ return conn->networkDriver->listDefinedNetworks (conn,
+ names, maxnames);
- return (-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
virNetworkPtr
virNetworkLookupByName(virConnectPtr conn, const char *name)
{
- virNetworkPtr ret = NULL;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->networkLookupByName != NULL)) {
- ret = conn->networkDrivers[i]->networkLookupByName(conn, name);
- if (ret)
- return(ret);
- }
- }
- return (NULL);
+ if (conn->networkDriver && conn->networkDriver->networkLookupByName)
+ return conn->networkDriver->networkLookupByName (conn, name);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
virNetworkPtr
virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
- virNetworkPtr ret;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->networkLookupByUUID != NULL)) {
- ret = conn->networkDrivers[i]->networkLookupByUUID(conn, uuid);
- if (ret)
- return(ret);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->networkLookupByUUID)
+ return conn->networkDriver->networkLookupByUUID (conn, uuid);
- return (NULL);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
virNetworkPtr
virNetworkCreateXML(virConnectPtr conn, const char *xmlDesc)
{
- virNetworkPtr ret;
- int i;
-
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->networkCreateXML != NULL)) {
- ret = conn->networkDrivers[i]->networkCreateXML(conn, xmlDesc);
- if (ret != NULL)
- return(ret);
- }
- }
- return(NULL);
+ if (conn->networkDriver && conn->networkDriver->networkCreateXML)
+ return conn->networkDriver->networkCreateXML (conn, xmlDesc);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
* Returns NULL in case of error, a pointer to the network otherwise
*/
virNetworkPtr
-virNetworkDefineXML(virConnectPtr conn, const char *xml) {
- virNetworkPtr ret = NULL;
- int i;
-
+virNetworkDefineXML(virConnectPtr conn, const char *xml)
+{
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
return (NULL);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->networkDefineXML != NULL)) {
- ret = conn->networkDrivers[i]->networkDefineXML(conn, xml);
- if (ret)
- return(ret);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->networkDefineXML)
+ return conn->networkDriver->networkDefineXML (conn, xml);
- return(ret);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
*/
int
virNetworkUndefine(virNetworkPtr network) {
- int ret, i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_NETWORK(network)) {
return (-1);
}
- /* Go though the driver registered entry points */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->networkUndefine != NULL)) {
- ret = conn->networkDrivers[i]->networkUndefine(network);
- if (ret >= 0)
- return(ret);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->networkUndefine)
+ return conn->networkDriver->networkUndefine (network);
- return(-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
* Returns 0 in case of success, -1 in case of error
*/
int
-virNetworkCreate(virNetworkPtr network) {
- int i, ret = -1;
+virNetworkCreate(virNetworkPtr network)
+{
virConnectPtr conn;
if (network == NULL) {
TODO
return (-1);
}
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->networkCreate != NULL)) {
- ret = conn->networkDrivers[i]->networkCreate(network);
- if (ret == 0)
- return(ret);
- }
- }
- return(ret);
+ if (conn->networkDriver && conn->networkDriver->networkCreate)
+ return conn->networkDriver->networkCreate (network);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
int
virNetworkDestroy(virNetworkPtr network)
{
- int i;
virConnectPtr conn;
if (!VIR_IS_CONNECTED_NETWORK(network)) {
return (-1);
}
- /*
- * Go though the driver registered entry points
- */
- for (i = 0;i < conn->nb_drivers;i++) {
- if ((conn->networkDrivers[i] != NULL) &&
- (conn->networkDrivers[i]->networkDestroy != NULL)) {
- if (conn->networkDrivers[i]->networkDestroy(network) == 0)
- return (0);
- }
- }
+ if (conn->networkDriver && conn->networkDriver->networkDestroy)
+ return conn->networkDriver->networkDestroy (network);
- virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
char *
virNetworkGetXMLDesc(virNetworkPtr network, int flags)
{
- int i;
- char *ret = NULL;
+ virConnectPtr conn;
+
if (!VIR_IS_NETWORK(network)) {
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
return (NULL);
return (NULL);
}
- for (i = 0;i < network->conn->nb_network_drivers;i++) {
- if ((network->conn->networkDrivers[i] != NULL) &&
- (network->conn->networkDrivers[i]->networkDumpXML != NULL)) {
- ret = network->conn->networkDrivers[i]->networkDumpXML(network, flags);
- if (ret)
- break;
- }
- }
- if (!ret) {
- virLibConnError(network->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (NULL);
- }
- return(ret);
+ conn = network->conn;
+
+ if (conn->networkDriver && conn->networkDriver->networkDumpXML)
+ return conn->networkDriver->networkDumpXML (network, flags);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
char *
virNetworkGetBridgeName(virNetworkPtr network)
{
- int i;
- char *ret = NULL;
+ virConnectPtr conn;
+
if (!VIR_IS_NETWORK(network)) {
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
return (NULL);
}
- for (i = 0;i < network->conn->nb_network_drivers;i++) {
- if ((network->conn->networkDrivers[i] != NULL) &&
- (network->conn->networkDrivers[i]->networkGetBridgeName != NULL)) {
- ret = network->conn->networkDrivers[i]->networkGetBridgeName(network);
- if (ret)
- break;
- }
- }
- if (!ret) {
- virLibConnError(network->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (NULL);
- }
- return(ret);
+ conn = network->conn;
+
+ if (conn->networkDriver && conn->networkDriver->networkGetBridgeName)
+ return conn->networkDriver->networkGetBridgeName (network);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return NULL;
}
/**
*/
int
virNetworkGetAutostart(virNetworkPtr network,
- int *autostart) {
- int i;
+ int *autostart)
+{
+ virConnectPtr conn;
if (!VIR_IS_NETWORK(network)) {
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
return (-1);
}
- for (i = 0;i < network->conn->nb_network_drivers;i++) {
- if ((network->conn->networkDrivers[i] != NULL) &&
- (network->conn->networkDrivers[i]->networkGetAutostart != NULL) &&
- (network->conn->networkDrivers[i]->networkGetAutostart(network, autostart) == 0))
- return (0);
- }
- virLibConnError(network->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ conn = network->conn;
+
+ if (conn->networkDriver && conn->networkDriver->networkGetAutostart)
+ return conn->networkDriver->networkGetAutostart (network, autostart);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/**
*/
int
virNetworkSetAutostart(virNetworkPtr network,
- int autostart) {
- int i;
+ int autostart)
+{
+ virConnectPtr conn;
if (!VIR_IS_NETWORK(network)) {
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
return (-1);
}
- for (i = 0;i < network->conn->nb_network_drivers;i++) {
- if ((network->conn->networkDrivers[i] != NULL) &&
- (network->conn->networkDrivers[i]->networkSetAutostart != NULL) &&
- (network->conn->networkDrivers[i]->networkSetAutostart(network, autostart) == 0))
- return (0);
- }
- virLibConnError(network->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
- return (-1);
+ conn = network->conn;
+
+ if (conn->networkDriver && conn->networkDriver->networkSetAutostart)
+ return conn->networkDriver->networkSetAutostart (network, autostart);
+
+ virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
+ return -1;
}
/*
#include "internal.h"
#include "driver.h"
#include "proxy_internal.h"
+#include "xen_unified.h"
#define STANDALONE
static char *xenProxyDomainDumpXML(virDomainPtr domain, int flags);
static char *xenProxyDomainGetOSType(virDomainPtr domain);
-static virDriver xenProxyDriver = {
- VIR_DRV_XEN_PROXY,
+virDriver xenProxyDriver = {
+ -1,
"XenProxy",
0,
xenProxyOpen, /* open */
};
/**
- * xenProxyRegister:
+ * xenProxyInit:
*
- * Registers the xenHypervisor driver
+ * Initialise the xen proxy driver.
*/
-void xenProxyRegister(void)
+int
+xenProxyInit (void)
{
- virRegisterDriver(&xenProxyDriver);
+ return 0;
}
+
/************************************************************************
* *
* Error handling *
* Shutdown the Xen proxy communication layer
*/
static int
-xenProxyClose(virConnectPtr conn) {
- if ((conn == NULL) || (conn->proxy < 0))
- return(-1);
- virProxyCloseClientSocket(conn->proxy);
- conn->proxy = -1;
- return (0);
+xenProxyClose(virConnectPtr conn)
+{
+ xenUnifiedPrivatePtr priv;
+
+ if (conn == NULL) {
+ virProxyError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (!priv) {
+ virProxyError (NULL, VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
+ return -1;
+ }
+
+ /* Fail silently. */
+ if (priv->proxy == -1)
+ return -1;
+
+ virProxyCloseClientSocket (priv->proxy);
+ priv->proxy = -1;
+
+ return 0;
}
static int
static int serial = 0;
int ret;
virProxyPacketPtr res = NULL;
+ xenUnifiedPrivatePtr priv;
- if ((conn == NULL) || (conn->proxy < 0))
- return(-1);
+ if (conn == NULL) {
+ virProxyError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (!priv) {
+ virProxyError (NULL, VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
+ return -1;
+ }
+
+ /* Fail silently. */
+ if (priv->proxy == -1)
+ return -1;
/*
* normal communication serial numbers are in 0..4095
serial = 0;
request->version = PROXY_PROTO_VERSION;
request->serial = serial;
- ret = virProxyWriteClientSocket(conn->proxy, (const char *) request,
+ ret = virProxyWriteClientSocket(priv->proxy, (const char *) request,
request->len);
if (ret < 0)
return(-1);
retry:
if (answer == NULL) {
/* read in situ */
- ret = virProxyReadClientSocket(conn->proxy, (char *) request,
+ ret = virProxyReadClientSocket(priv->proxy, (char *) request,
sizeof(virProxyPacket), quiet);
if (ret < 0)
return(-1);
}
} else {
/* read in packet provided */
- ret = virProxyReadClientSocket(conn->proxy, (char *) answer,
+ ret = virProxyReadClientSocket(priv->proxy, (char *) answer,
sizeof(virProxyPacket), quiet);
if (ret < 0)
return(-1);
return(-1);
}
if (res->len > sizeof(virProxyPacket)) {
- ret = virProxyReadClientSocket(conn->proxy,
+ ret = virProxyReadClientSocket(priv->proxy,
(char *) &(answer->extra.arg[0]),
res->len - ret, quiet);
if (ret != (int) (res->len - sizeof(virProxyPacket))) {
* Returns 0 in case of success, and -1 in case of failure
*/
int
-xenProxyOpen(virConnectPtr conn, const char *name, int flags)
+xenProxyOpen(virConnectPtr conn, const char *name ATTRIBUTE_UNUSED, int flags)
{
virProxyPacket req;
int ret;
int fd;
+ xenUnifiedPrivatePtr priv;
- if ((name != NULL) && (strcasecmp(name, "xen")))
- return(-1);
if (!(flags & VIR_DRV_OPEN_RO))
return(-1);
-
- conn->proxy = -1;
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ priv->proxy = -1;
+
fd = virProxyOpenClientSocket(PROXY_SOCKET_PATH);
if (fd < 0) {
if (!(flags & VIR_DRV_OPEN_QUIET))
virProxyError(conn, VIR_ERR_NO_XEN, PROXY_SOCKET_PATH);
- return(-1);
+ return(-1);
}
- conn->proxy = fd;
+ priv->proxy = fd;
memset(&req, 0, sizeof(req));
req.command = VIR_PROXY_NONE;
};
typedef struct _virProxyFullPacket virProxyFullPacket;
typedef virProxyFullPacket *virProxyFullPacketPtr;
-/*
- * Functions callable from libvirt library
- */
-void xenProxyRegister(void);
+
+extern virDriver xenProxyDriver;
+int xenProxyInit (void);
#ifdef __cplusplus
}
#include "xml.h"
#include "protocol.h"
-
+/**
+ * qemuPrivatePtr:
+ *
+ * Per-connection private data.
+ */
+struct _qemuPrivate {
+ int qemud_fd; /* Connection to libvirt qemu daemon. */
+};
+struct _qemuNetworkPrivate {
+ int qemud_fd;
+ int shared;
+};
+typedef struct _qemuPrivate *qemuPrivatePtr;
+typedef struct _qemuNetworkPrivate *qemuNetworkPrivatePtr;
static void
qemuError(virConnectPtr con,
* Returns the associated file descriptor or -1 in case of failure
*/
static int
-qemuOpenClientUNIX(virConnectPtr conn, const char *path, int autostart) {
+qemuOpenClientUNIX(virConnectPtr conn ATTRIBUTE_UNUSED,
+ const char *path, int autostart) {
int fd;
struct sockaddr_un addr;
int trials = 0;
retry:
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- return(-1);
+ return VIR_DRV_OPEN_ERROR;
}
/*
usleep(5000 * trials * trials);
goto retry;
}
- return (-1);
+ return VIR_DRV_OPEN_ERROR;
}
- conn->qemud_fd = fd;
-
- return (0);
+ return fd;
}
* connection closes.
*/
static int qemuProcessRequest(virConnectPtr conn,
- virDomainPtr dom,
- struct qemud_packet *req,
- struct qemud_packet *reply) {
+ int qemud_fd,
+ virDomainPtr dom,
+ struct qemud_packet *req,
+ struct qemud_packet *reply) {
char *out = (char *)req;
int outDone = 0;
int outLeft = sizeof(struct qemud_packet_header) + req->header.dataSize;
/* Block sending entire outgoing packet */
while (outLeft) {
- int got = write(conn->qemud_fd, out+outDone, outLeft);
+ int got = write(qemud_fd, out+outDone, outLeft);
if (got < 0) {
return -1;
}
/* Block waiting for header to come back */
while (inLeft) {
- int done = read(conn->qemud_fd, in+inGot, inLeft);
+ int done = read(qemud_fd, in+inGot, inLeft);
if (done <= 0) {
return -1;
}
/* Now block reading in body */
inLeft = reply->header.dataSize;
while (inLeft) {
- int done = read(conn->qemud_fd, in+inGot, inLeft);
+ int done = read(qemud_fd, in+inGot, inLeft);
if (done <= 0) {
return -1;
}
int autostart = 0;
if (uri->server != NULL) {
- return -1;
+ return VIR_DRV_OPEN_ERROR;
}
if (!strcmp(uri->path, "/system")) {
if (readonly) {
if (snprintf(path, sizeof(path), "%s/run/libvirt/qemud-sock-ro", LOCAL_STATE_DIR) >= (int)sizeof(path)) {
- return -1;
+ return VIR_DRV_OPEN_ERROR;
}
} else {
if (snprintf(path, sizeof(path), "%s/run/libvirt/qemud-sock", LOCAL_STATE_DIR) >= (int)sizeof(path)) {
- return -1;
+ return VIR_DRV_OPEN_ERROR;
}
}
} else if (!strcmp(uri->path, "/session")) {
int uid;
if ((uid = geteuid()) < 0) {
- return -1;
+ return VIR_DRV_OPEN_ERROR;
}
if (!(pw = getpwuid(uid)))
- return -1;
+ return VIR_DRV_OPEN_ERROR;
if (snprintf(path, sizeof(path), "@%s/.libvirt/qemud-sock", pw->pw_dir) == sizeof(path)) {
- return -1;
+ return VIR_DRV_OPEN_ERROR;
}
autostart = 1;
}
const char *name,
int flags){
xmlURIPtr uri;
+ qemuPrivatePtr priv;
+ int ret;
if (!name) {
- return -1;
+ return VIR_DRV_OPEN_DECLINED;
}
uri = xmlParseURI(name);
if (uri == NULL) {
if (!(flags & VIR_DRV_OPEN_QUIET))
qemuError(conn, NULL, VIR_ERR_NO_SUPPORT, name);
- return(-1);
+ return VIR_DRV_OPEN_DECLINED;
}
if (!uri->scheme ||
strcmp(uri->scheme, "qemu") ||
!uri->path) {
xmlFreeURI(uri);
- return -1;
+ return VIR_DRV_OPEN_DECLINED;
+ }
+
+ /* Create per-connection private data. */
+ priv = conn->privateData = malloc (sizeof *priv);
+ if (!priv) {
+ qemuError (conn, NULL, VIR_ERR_NO_MEMORY, __FUNCTION__);
+ return VIR_DRV_OPEN_ERROR;
}
- conn->qemud_fd = -1;
- qemuOpenConnection(conn, uri, flags & VIR_DRV_OPEN_RO ? 1 : 0);
+ ret = qemuOpenConnection(conn, uri, flags & VIR_DRV_OPEN_RO ? 1 : 0);
xmlFreeURI(uri);
- if (conn->qemud_fd < 0) {
- return -1;
+ if (ret < 0) {
+ free (priv);
+ conn->privateData = NULL;
+ return VIR_DRV_OPEN_ERROR;
}
- return 0;
+ priv->qemud_fd = ret;
+
+ return VIR_DRV_OPEN_SUCCESS;
}
-static int qemuClose (virConnectPtr conn) {
- if (conn->qemud_fd != -1) {
- close(conn->qemud_fd);
- conn->qemud_fd = -1;
+static int
+qemuClose (virConnectPtr conn)
+{
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
+
+ if (priv->qemud_fd != -1) {
+ close (priv->qemud_fd);
+ priv->qemud_fd = -1;
}
+
+ free (priv);
+ conn->privateData = NULL;
+
return 0;
}
static int qemuGetVersion(virConnectPtr conn,
unsigned long *hvVer) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_GET_VERSION;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static int qemuNodeGetInfo(virConnectPtr conn,
virNodeInfoPtr info) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_GET_NODEINFO;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
{
struct qemud_packet req, reply;
char *xml;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
/* Punt the request across to the daemon, because the daemon
* has tables describing available architectures.
req.header.type = QEMUD_PKT_GET_CAPABILITIES;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
static int qemuNumOfDomains(virConnectPtr conn) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_NUM_DOMAINS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
int maxids) {
struct qemud_packet req, reply;
int i, nDomains;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_LIST_DOMAINS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
struct qemud_packet req, reply;
virDomainPtr dom;
int len = strlen(xmlDesc);
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
if (len > (QEMUD_MAX_XML_LEN-1)) {
return NULL;
strcpy(req.data.domainCreateRequest.xml, xmlDesc);
req.data.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0';
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
int id) {
struct qemud_packet req, reply;
virDomainPtr dom;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_LOOKUP_BY_ID;
req.header.dataSize = sizeof(req.data.domainLookupByIDRequest);
req.data.domainLookupByIDRequest.id = id;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
const unsigned char *uuid) {
struct qemud_packet req, reply;
virDomainPtr dom;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_LOOKUP_BY_UUID;
req.header.dataSize = sizeof(req.data.domainLookupByUUIDRequest);
memmove(req.data.domainLookupByUUIDRequest.uuid, uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
const char *name) {
struct qemud_packet req, reply;
virDomainPtr dom;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
if (strlen(name) > (QEMUD_MAX_NAME_LEN-1))
return NULL;
req.header.dataSize = sizeof(req.data.domainLookupByNameRequest);
strcpy(req.data.domainLookupByNameRequest.name, name);
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
static int qemuDestroyDomain(virDomainPtr domain) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) domain->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_DESTROY;
req.header.dataSize = sizeof(req.data.domainDestroyRequest);
req.data.domainDestroyRequest.id = domain->id;
- if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(domain->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
return qemuDestroyDomain(domain);
}
-static int qemuResumeDomain(virDomainPtr domain ATTRIBUTE_UNUSED) {
+static int qemuResumeDomain(virDomainPtr domain) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) domain->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_RESUME;
req.header.dataSize = sizeof(req.data.domainResumeRequest);
req.data.domainResumeRequest.id = domain->id;
- if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(domain->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
return 0;
}
-static int qemuPauseDomain(virDomainPtr domain ATTRIBUTE_UNUSED) {
+static int qemuPauseDomain(virDomainPtr domain) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) domain->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_SUSPEND;
req.header.dataSize = sizeof(req.data.domainSuspendRequest);
req.data.domainSuspendRequest.id = domain->id;
- if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(domain->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static int qemuGetDomainInfo(virDomainPtr domain,
virDomainInfoPtr info) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) domain->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_GET_INFO;
req.header.dataSize = sizeof(req.data.domainGetInfoRequest);
memmove(req.data.domainGetInfoRequest.uuid, domain->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(domain->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static char *qemuDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) domain->conn->privateData;
req.header.type = QEMUD_PKT_DUMP_XML;
req.header.dataSize = sizeof(req.data.domainDumpXMLRequest);
memmove(req.data.domainDumpXMLRequest.uuid, domain->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(domain->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
static int qemuNumOfDefinedDomains(virConnectPtr conn) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_NUM_DEFINED_DOMAINS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
int maxnames){
struct qemud_packet req, reply;
int i, nDomains;
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
req.header.type = QEMUD_PKT_LIST_DEFINED_DOMAINS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static int qemuDomainCreate(virDomainPtr dom) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) dom->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_START;
req.header.dataSize = sizeof(req.data.domainStartRequest);
memcpy(req.data.domainStartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(dom->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
struct qemud_packet req, reply;
virDomainPtr dom;
int len = strlen(xml);
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
if (len > (QEMUD_MAX_XML_LEN-1)) {
return NULL;
strcpy(req.data.domainDefineRequest.xml, xml);
req.data.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0';
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
static int qemuUndefine(virDomainPtr dom) {
struct qemud_packet req, reply;
int ret = 0;
+ qemuPrivatePtr priv = (qemuPrivatePtr) dom->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_UNDEFINE;
req.header.dataSize = sizeof(req.data.domainUndefineRequest);
memcpy(req.data.domainUndefineRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(dom->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
ret = -1;
goto cleanup;
}
static int qemuDomainGetAutostart(virDomainPtr dom,
int *autostart) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) dom->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_GET_AUTOSTART;
req.header.dataSize = sizeof(req.data.domainGetAutostartRequest);
memmove(req.data.domainGetAutostartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(dom->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static int qemuDomainSetAutostart(virDomainPtr dom,
int autostart) {
struct qemud_packet req, reply;
+ qemuPrivatePtr priv = (qemuPrivatePtr) dom->conn->privateData;
req.header.type = QEMUD_PKT_DOMAIN_SET_AUTOSTART;
req.header.dataSize = sizeof(req.data.domainSetAutostartRequest);
req.data.domainSetAutostartRequest.autostart = (autostart != 0);
memmove(req.data.domainSetAutostartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(dom->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
}
static int qemuNetworkOpen(virConnectPtr conn,
- const char *name,
+ const char *name ATTRIBUTE_UNUSED,
int flags) {
- xmlURIPtr uri = NULL;
- int ret = -1;
+ qemuNetworkPrivatePtr netpriv = NULL;
+
+ if (!(netpriv = malloc(sizeof(struct _qemuNetworkPrivate)))) {
+ qemuError (conn, NULL, VIR_ERR_NO_MEMORY, __FUNCTION__);
+ return VIR_DRV_OPEN_ERROR;
+ }
- if (conn->qemud_fd != -1)
+ if (!strcmp(conn->driver->name, "QEMU")) {
+ /* QEMU driver is active - just re-use existing connection */
+ qemuPrivatePtr priv = (qemuPrivatePtr) conn->privateData;
+ netpriv->qemud_fd = priv->qemud_fd;
+ netpriv->shared = 1;
+ conn->networkPrivateData = netpriv;
return 0;
+ } else {
+ /* Non-QEMU driver is active - open a new connection */
+ const char *drvname = geteuid() == 0 ? "qemu:///system" : "qemu://session";
+ xmlURIPtr uri = xmlParseURI(drvname);
+ int ret = qemuOpenConnection(conn, uri, flags & VIR_DRV_OPEN_RO ? 1 : 0);
+ xmlFreeURI(uri);
- if (name)
- uri = xmlParseURI(name);
+ if (ret < 0) {
+ free(netpriv);
+ return ret;
+ } else {
+ netpriv->qemud_fd = ret;
+ netpriv->shared = 0;
+ conn->networkPrivateData = netpriv;
+ return 0;
+ }
+ }
+}
- if (uri && uri->scheme && !strcmp(uri->scheme, "qemu"))
- ret = qemuOpen(conn, name, flags);
- else if (geteuid() == 0)
- ret = qemuOpen(conn, "qemu:///system", flags);
- else
- ret = qemuOpen(conn, "qemu:///session", flags);
+static int
+qemuNetworkClose (virConnectPtr conn)
+{
+ qemuNetworkPrivatePtr netpriv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
- if (uri)
- xmlFreeURI(uri);
+ if (!netpriv->shared)
+ close(netpriv->qemud_fd);
+ free(netpriv);
+ conn->networkPrivateData = NULL;
- return ret;
+ return 0;
}
static int qemuNumOfNetworks(virConnectPtr conn) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
req.header.type = QEMUD_PKT_NUM_NETWORKS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
int maxnames) {
struct qemud_packet req, reply;
int i, nNetworks;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
req.header.type = QEMUD_PKT_LIST_NETWORKS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static int qemuNumOfDefinedNetworks(virConnectPtr conn) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
req.header.type = QEMUD_PKT_NUM_DEFINED_NETWORKS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
int maxnames) {
struct qemud_packet req, reply;
int i, nNetworks;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
req.header.type = QEMUD_PKT_LIST_DEFINED_NETWORKS;
req.header.dataSize = 0;
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
const unsigned char *uuid) {
struct qemud_packet req, reply;
virNetworkPtr network;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_LOOKUP_BY_UUID;
req.header.dataSize = sizeof(req.data.networkLookupByUUIDRequest);
memmove(req.data.networkLookupByUUIDRequest.uuid, uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
const char *name) {
struct qemud_packet req, reply;
virNetworkPtr network;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
if (strlen(name) > (QEMUD_MAX_NAME_LEN-1))
return NULL;
req.header.dataSize = sizeof(req.data.networkLookupByNameRequest);
strcpy(req.data.networkLookupByNameRequest.name, name);
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
struct qemud_packet req, reply;
virNetworkPtr network;
int len = strlen(xmlDesc);
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
if (len > (QEMUD_MAX_XML_LEN-1)) {
return NULL;
strcpy(req.data.networkCreateRequest.xml, xmlDesc);
req.data.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0';
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
struct qemud_packet req, reply;
virNetworkPtr network;
int len = strlen(xml);
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
if (len > (QEMUD_MAX_XML_LEN-1)) {
return NULL;
strcpy(req.data.networkDefineRequest.xml, xml);
req.data.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0';
- if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
static int qemuNetworkUndefine(virNetworkPtr network) {
struct qemud_packet req, reply;
int ret = 0;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) network->conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_UNDEFINE;
req.header.dataSize = sizeof(req.data.networkUndefineRequest);
memcpy(req.data.networkUndefineRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(network->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
ret = -1;
goto cleanup;
}
static int qemuNetworkCreate(virNetworkPtr network) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) network->conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_START;
req.header.dataSize = sizeof(req.data.networkStartRequest);
memcpy(req.data.networkStartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(network->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static int qemuNetworkDestroy(virNetworkPtr network) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) network->conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_DESTROY;
req.header.dataSize = sizeof(req.data.networkDestroyRequest);
memcpy(req.data.networkDestroyRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(network->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static char * qemuNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSED) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) network->conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_DUMP_XML;
req.header.dataSize = sizeof(req.data.networkDumpXMLRequest);
memmove(req.data.networkDumpXMLRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(network->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
static char * qemuNetworkGetBridgeName(virNetworkPtr network) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) network->conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_GET_BRIDGE_NAME;
req.header.dataSize = sizeof(req.data.networkGetBridgeNameRequest);
memmove(req.data.networkGetBridgeNameRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(network->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return NULL;
}
static int qemuNetworkGetAutostart(virNetworkPtr network,
int *autostart) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) network->conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_GET_AUTOSTART;
req.header.dataSize = sizeof(req.data.networkGetAutostartRequest);
memmove(req.data.networkGetAutostartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(network->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static int qemuNetworkSetAutostart(virNetworkPtr network,
int autostart) {
struct qemud_packet req, reply;
+ qemuNetworkPrivatePtr priv = (qemuNetworkPrivatePtr) network->conn->networkPrivateData;
req.header.type = QEMUD_PKT_NETWORK_SET_AUTOSTART;
req.header.dataSize = sizeof(req.data.networkSetAutostartRequest);
req.data.networkSetAutostartRequest.autostart = (autostart != 0);
memmove(req.data.networkSetAutostartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
- if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
+ if (qemuProcessRequest(network->conn, priv->qemud_fd, NULL, &req, &reply) < 0) {
return -1;
}
static virNetworkDriver qemuNetworkDriver = {
qemuNetworkOpen, /* open */
- qemuClose, /* close */
+ qemuNetworkClose, /* close */
qemuNumOfNetworks, /* numOfNetworks */
qemuListNetworks, /* listNetworks */
qemuNumOfDefinedNetworks, /* numOfDefinedNetworks */
*
* Registers QEmu/KVM in libvirt driver system
*/
-void qemuRegister(void) {
- virRegisterDriver(&qemuDriver);
- virRegisterNetworkDriver(&qemuNetworkDriver);
+int
+qemuRegister (void)
+{
+ if (virRegisterDriver(&qemuDriver) == -1)
+ return -1;
+ if (virRegisterNetworkDriver(&qemuNetworkDriver) == -1)
+ return -1;
+
+ return 0;
}
#endif /* WITH_QEMU */
extern "C" {
#endif
- void qemuRegister(void);
+int qemuRegister(void);
#ifdef __cplusplus
}
NULL, /* domainSetAutostart */
};
+/* Per-connection private data. */
+struct _testPrivate {
+ int handle;
+};
+typedef struct _testPrivate *testPrivatePtr;
+
typedef struct _testDev {
char name[20];
virDeviceMode mode;
*
* Registers the test driver
*/
-void testRegister(void)
+int
+testRegister(void)
{
- virRegisterDriver(&testDriver);
+ return virRegisterDriver(&testDriver);
}
static int testLoadDomain(virConnectPtr conn,
virDomainRestart onReboot = VIR_DOMAIN_RESTART;
virDomainRestart onPoweroff = VIR_DOMAIN_DESTROY;
virDomainRestart onCrash = VIR_DOMAIN_RENAME_RESTART;
+ testPrivatePtr priv;
if (gettimeofday(&tv, NULL) < 0) {
testError(conn, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
if (obj)
xmlXPathFreeObject(obj);
-
-
-
obj = xmlXPathEval(BAD_CAST "string(/domain/vcpu[1])", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
if (obj)
xmlXPathFreeObject(obj);
- con = &node->connections[conn->handle];
+ priv = (testPrivatePtr) conn->privateData;
+ con = &node->connections[priv->handle];
for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (!con->domains[i].active) {
int connid) {
int u;
struct timeval tv;
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
if (gettimeofday(&tv, NULL) < 0) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
- return (-1);
+ return VIR_DRV_OPEN_ERROR;
}
- conn->handle = connid;
+ priv->handle = connid;
node->connections[connid].active = 1;
memmove(&node->connections[connid].nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
xmlXPathContextPtr ctxt = NULL;
xmlXPathObjectPtr obj = NULL;
virNodeInfoPtr nodeInfo;
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
if ((fd = open(file, O_RDONLY)) < 0) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("loading host definition file"));
- return (-1);
+ return VIR_DRV_OPEN_ERROR;
}
if (!(xml = xmlReadFd(fd, file, NULL,
goto error;
}
- conn->handle = connid;
+ priv->handle = connid;
node->connections[connid].active = 1;
node->connections[connid].numDomains = 0;
memmove(&node->connections[connid].nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
xmlFreeDoc(xml);
if (fd != -1)
close(fd);
- return (-1);
+ return VIR_DRV_OPEN_ERROR;
}
static int getNextConnection(void) {
static int getDomainIndex(virDomainPtr domain) {
int i;
testCon *con;
- con = &node->connections[domain->conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) domain->conn->privateData;
+
+ con = &node->connections[priv->handle];
for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (domain->id >= 0) {
if (domain->id == con->domains[i].id)
{
xmlURIPtr uri;
int ret, connid;
+ testPrivatePtr priv;
- if (!name) {
- return (-1);
- }
+ if (!name)
+ return VIR_DRV_OPEN_DECLINED;
uri = xmlParseURI(name);
if (uri == NULL) {
if (!(flags & VIR_DRV_OPEN_QUIET))
testError(conn, NULL, VIR_ERR_NO_SUPPORT, name);
- return(-1);
+ return VIR_DRV_OPEN_DECLINED;
}
if (!uri->scheme ||
strcmp(uri->scheme, "test") ||
!uri->path) {
xmlFreeURI(uri);
- return (-1);
+ return VIR_DRV_OPEN_DECLINED;
}
if ((connid = getNextConnection()) < 0) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("too many connections"));
- return (-1);
+ return VIR_DRV_OPEN_ERROR;
}
+ /* Allocate per-connection private data. */
+ priv = conn->privateData = malloc (sizeof (struct _testPrivate));
+ if (!priv) {
+ testError(NULL, NULL, VIR_ERR_NO_MEMORY, "allocating private data");
+ return VIR_DRV_OPEN_ERROR;
+ }
+ priv->handle = -1;
+
if (!strcmp(uri->path, "/default")) {
ret = testOpenDefault(conn,
connid);
xmlFreeURI(uri);
+ if (ret < 0) free (conn->privateData);
+
return (ret);
}
int testClose(virConnectPtr conn)
{
- testCon *con = &node->connections[conn->handle];
- con->active = 0;
- conn->handle = -1;
- memset(con, 0, sizeof(testCon));
- return (0);
+ testPrivatePtr priv;
+
+ if (!conn) {
+ testError (NULL, NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+
+ priv = (testPrivatePtr) conn->privateData;
+ if (!priv) {
+ testError (NULL, NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+
+ if (priv->handle >= 0) {
+ testCon *con = &node->connections[priv->handle];
+ con->active = 0;
+ memset (con, 0, sizeof *con); // RWMJ - why?
+ }
+
+ free (priv);
+ return 0;
}
int testGetVersion(virConnectPtr conn ATTRIBUTE_UNUSED,
int testNodeGetInfo(virConnectPtr conn,
virNodeInfoPtr info)
{
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
memcpy(info, &con->nodeInfo, sizeof(virNodeInfo));
return (0);
}
int testNumOfDomains(virConnectPtr conn)
{
int numActive = 0, i;
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (!con->domains[i].active ||
con->domains[i].info.state == VIR_DOMAIN_SHUTOFF)
testCon *con;
int domid, handle = -1, i;
virDomainPtr dom;
+ testPrivatePtr priv;
if (!VIR_IS_CONNECT(conn)) {
testError(conn, NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
testError(conn, NULL, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
return (NULL);
}
+
+ priv = (testPrivatePtr) conn->privateData;
- con = &node->connections[conn->handle];
+ con = &node->connections[priv->handle];
if (con->numDomains == MAX_DOMAINS) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("too many domains"));
virDomainPtr testLookupDomainByID(virConnectPtr conn,
int id)
{
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
virDomainPtr dom;
int i, idx = -1;
virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
const unsigned char *uuid)
{
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
virDomainPtr dom = NULL;
int i, idx = -1;
for (i = 0 ; i < MAX_DOMAINS ; i++) {
virDomainPtr testLookupDomainByName(virConnectPtr conn,
const char *name)
{
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
virDomainPtr dom = NULL;
int i, idx = -1;
for (i = 0 ; i < MAX_DOMAINS ; i++) {
int *ids,
int maxids)
{
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
int n, i;
for (i = 0, n = 0 ; i < MAX_DOMAINS && n < maxids ; i++) {
{
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+
+ con = &node->connections[priv->handle];
con->domains[domidx].active = 0;
return (0);
}
{
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+
+ con = &node->connections[priv->handle];
con->domains[domidx].info.state = VIR_DOMAIN_RUNNING;
return (0);
}
{
testCon *con;\
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+
+ con = &node->connections[priv->handle];
con->domains[domidx].info.state = VIR_DOMAIN_PAUSED;
return (0);
}
testCon *con;
int domidx;
struct timeval tv;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+
+ con = &node->connections[priv->handle];
if (gettimeofday(&tv, NULL) < 0) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
testCon *con;
int domidx;
struct timeval tv;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
if (gettimeofday(&tv, NULL) < 0) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
struct timeval tv;
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
if (gettimeofday(&tv, NULL) < 0) {
testError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
unsigned long testGetMaxMemory(virDomainPtr domain) {
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
return con->domains[domidx].info.maxMem;
}
{
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
/* XXX validate not over host memory wrt to other domains */
con->domains[domidx].info.maxMem = memory;
return (0);
{
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
if (memory > con->domains[domidx].info.maxMem) {
testError(domain->conn, domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
unsigned int nrCpus) {
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
/* We allow more cpus in guest than host */
if (nrCpus > 32) {
unsigned char *uuid;
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (NULL);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
if (!(buf = virBufferNew(4000))) {
return (NULL);
int testNumOfDefinedDomains(virConnectPtr conn) {
int numInactive = 0, i;
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (!con->domains[i].active ||
con->domains[i].info.state != VIR_DOMAIN_SHUTOFF)
int testListDefinedDomains(virConnectPtr conn,
char **const names,
int maxnames) {
- testCon *con = &node->connections[conn->handle];
+ testPrivatePtr priv = (testPrivatePtr) conn->privateData;
+ testCon *con = &node->connections[priv->handle];
int n = 0, i;
for (i = 0, n = 0 ; i < MAX_DOMAINS && n < maxnames ; i++) {
int testDomainCreate(virDomainPtr domain) {
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
if (con->domains[domidx].info.state != VIR_DOMAIN_SHUTOFF) {
testError(domain->conn, domain, VIR_ERR_INTERNAL_ERROR,
int testDomainUndefine(virDomainPtr domain) {
testCon *con;
int domidx;
+ testPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
((domidx = getDomainIndex(domain)) < 0)) {
testError((domain ? domain->conn : NULL), domain, VIR_ERR_INVALID_ARG,
return (-1);
}
- con = &node->connections[domain->conn->handle];
+ priv = (testPrivatePtr) domain->conn->privateData;
+ con = &node->connections[priv->handle];
if (con->domains[domidx].info.state != VIR_DOMAIN_SHUTOFF) {
testError(domain->conn, domain, VIR_ERR_INTERNAL_ERROR,
extern "C" {
#endif
- void testRegister(void);
+int testRegister(void);
#ifdef __cplusplus
}
#include "internal.h"
#include "driver.h"
+#include "xen_unified.h"
#include "xen_internal.h"
#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd"
#endif
#ifndef PROXY
-static virDriver xenHypervisorDriver = {
- VIR_DRV_XEN_HYPERVISOR,
+virDriver xenHypervisorDriver = {
+ -1,
"Xen",
(DOM0_INTERFACE_VERSION >> 24) * 1000000 +
((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
xenHypervisorClose, /* close */
xenHypervisorGetType, /* type */
xenHypervisorGetVersion, /* version */
- xenHypervisorNumOfMaxVcpus, /* getMaxVcpus */
+ xenHypervisorGetMaxVcpus, /* getMaxVcpus */
NULL, /* nodeGetInfo */
xenHypervisorGetCapabilities, /* getCapabilities */
xenHypervisorListDomains, /* listDomains */
* Initialize the hypervisor layer. Try to detect the kind of interface
* used i.e. pre or post changeset 10277
*/
-static int
+int
xenHypervisorInit(void)
{
int fd, ret, cmd, errcode;
if (initialized) {
if (hypervisor_version == -1)
- return(-1);
+ return (-1);
return(0);
}
initialized = 1;
ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
if (ret < 0) {
hypervisor_version = -1;
- return (-1);
+ return(-1);
}
fd = ret;
ipt = malloc(sizeof(virVcpuInfo));
if (ipt == NULL){
#ifdef DEBUG
- fprintf(stderr, "Memory allocation failed at xenHypervisorIniti()\n");
+ fprintf(stderr, "Memory allocation failed at xenHypervisorInit()\n");
#endif
return(-1);
}
return(0);
}
-#ifndef PROXY
-/**
- * xenHypervisorRegister:
- *
- * Registers the xenHypervisor driver
- */
-void xenHypervisorRegister(void)
-{
- if (initialized == 0)
- xenHypervisorInit();
-
- virRegisterDriver(&xenHypervisorDriver);
-}
-#endif /* !PROXY */
-
/**
* xenHypervisorOpen:
* @conn: pointer to the connection block
* Returns 0 or -1 in case of error.
*/
int
-xenHypervisorOpen(virConnectPtr conn, const char *name, int flags)
+xenHypervisorOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
+ const char *name ATTRIBUTE_UNUSED, int flags)
{
int ret;
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
if (initialized == 0)
- xenHypervisorInit();
-
- if ((name != NULL) && (strcasecmp(name, "xen")))
- return(-1);
+ if (xenHypervisorInit() == -1)
+ return -1;
- conn->handle = -1;
+ priv->handle = -1;
ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
if (ret < 0) {
virXenError(VIR_ERR_NO_XEN, XEN_HYPERVISOR_SOCKET, 0);
return (-1);
}
- conn->handle = ret;
+
+ priv->handle = ret;
return(0);
}
xenHypervisorClose(virConnectPtr conn)
{
int ret;
+ xenUnifiedPrivatePtr priv;
- if ((conn == NULL) || (conn->handle < 0))
+ if (conn == NULL)
return (-1);
- ret = close(conn->handle);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
+ if (priv->handle < 0)
+ return -1;
+
+ ret = close(priv->handle);
if (ret < 0)
return (-1);
+
return (0);
}
int
xenHypervisorGetVersion(virConnectPtr conn, unsigned long *hvVer)
{
- if ((conn == NULL) || (conn->handle < 0) || (hvVer == NULL))
+ xenUnifiedPrivatePtr priv;
+
+ if (conn == NULL)
+ return -1;
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->handle < 0 || hvVer == NULL)
return (-1);
*hvVer = (hv_version >> 16) * 1000000 + (hv_version & 0xFFFF) * 1000;
return(0);
int ret, nbids;
static int last_maxids = 2;
int maxids = last_maxids;
+ xenUnifiedPrivatePtr priv;
- if ((conn == NULL) || (conn->handle < 0))
+ if (conn == NULL)
+ return -1;
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->handle < 0)
return (-1);
retry:
XEN_GETDOMAININFOLIST_CLEAR(dominfos, maxids);
- ret = virXen_getdomaininfolist(conn->handle, 0, maxids, &dominfos);
+ ret = virXen_getdomaininfolist(priv->handle, 0, maxids, &dominfos);
XEN_GETDOMAININFOLIST_FREE(dominfos);
{
xen_getdomaininfolist dominfos;
int ret, nbids, i;
+ xenUnifiedPrivatePtr priv;
+
+ if (conn == NULL)
+ return -1;
- if ((conn == NULL) || (conn->handle < 0) ||
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->handle < 0 ||
(ids == NULL) || (maxids < 1))
return (-1);
XEN_GETDOMAININFOLIST_CLEAR(dominfos, maxids);
memset(ids, 0, maxids * sizeof(int));
- ret = virXen_getdomaininfolist(conn->handle, 0, maxids, &dominfos);
+ ret = virXen_getdomaininfolist(priv->handle, 0, maxids, &dominfos);
if (ret < 0) {
XEN_GETDOMAININFOLIST_FREE(dominfos);
}
/**
- * xenHypervisorNumOfMaxVcpus:
+ * xenHypervisorGetMaxVcpus:
*
* Returns the maximum of CPU defined by Xen.
*/
int
-xenHypervisorNumOfMaxVcpus(virConnectPtr conn)
+xenHypervisorGetMaxVcpus(virConnectPtr conn,
+ const char *type ATTRIBUTE_UNUSED)
{
- if ((conn == NULL) || (conn->handle < 0))
+ xenUnifiedPrivatePtr priv;
+
+ if (conn == NULL)
+ return -1;
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->handle < 0)
return (-1);
return MAX_VIRT_CPUS;
unsigned long
xenHypervisorGetDomMaxMemory(virConnectPtr conn, int id)
{
+ xenUnifiedPrivatePtr priv;
xen_getdomaininfo dominfo;
int ret;
- if ((conn == NULL) || (conn->handle < 0))
- return (0);
+ if (conn == NULL)
+ return 0;
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->handle < 0)
+ return 0;
if (kb_per_pages == 0) {
kb_per_pages = sysconf(_SC_PAGESIZE) / 1024;
XEN_GETDOMAININFO_CLEAR(dominfo);
- ret = virXen_getdomaininfo(conn->handle, id, &dominfo);
+ ret = virXen_getdomaininfo(priv->handle, id, &dominfo);
if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != id))
return (0);
static unsigned long
xenHypervisorGetMaxMemory(virDomainPtr domain)
{
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0))
+ xenUnifiedPrivatePtr priv;
+
+ if ((domain == NULL) || (domain->conn == NULL))
+ return 0;
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || domain->id < 0)
return (0);
return(xenHypervisorGetDomMaxMemory(domain->conn, domain->id));
int
xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info)
{
+ xenUnifiedPrivatePtr priv;
xen_getdomaininfo dominfo;
int ret;
uint32_t domain_flags, domain_state, domain_shutdown_cause;
kb_per_pages = 4;
}
- if ((conn == NULL) || (conn->handle < 0) || (info == NULL))
+ if (conn == NULL)
+ return -1;
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->handle < 0 || info == NULL)
return (-1);
memset(info, 0, sizeof(virDomainInfo));
XEN_GETDOMAININFO_CLEAR(dominfo);
- ret = virXen_getdomaininfo(conn->handle, id, &dominfo);
+ ret = virXen_getdomaininfo(priv->handle, id, &dominfo);
if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != id))
return (-1);
int
xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
{
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (info == NULL) ||
+ xenUnifiedPrivatePtr priv;
+
+ if ((domain == NULL) || (domain->conn == NULL))
+ return -1;
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || info == NULL ||
(domain->id < 0))
return (-1);
xenHypervisorPauseDomain(virDomainPtr domain)
{
int ret;
+ xenUnifiedPrivatePtr priv;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0))
+ if ((domain == NULL) || (domain->conn == NULL))
+ return -1;
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || domain->id < 0)
return (-1);
- ret = virXen_pausedomain(domain->conn->handle, domain->id);
+ ret = virXen_pausedomain(priv->handle, domain->id);
if (ret < 0)
return (-1);
return (0);
xenHypervisorResumeDomain(virDomainPtr domain)
{
int ret;
+ xenUnifiedPrivatePtr priv;
+
+ if ((domain == NULL) || (domain->conn == NULL))
+ return -1;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0))
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || domain->id < 0)
return (-1);
- ret = virXen_unpausedomain(domain->conn->handle, domain->id);
+ ret = virXen_unpausedomain(priv->handle, domain->id);
if (ret < 0)
return (-1);
return (0);
xenHypervisorDestroyDomain(virDomainPtr domain)
{
int ret;
+ xenUnifiedPrivatePtr priv;
+
+ if (domain == NULL || domain->conn == NULL)
+ return -1;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0))
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || domain->id < 0)
return (-1);
- ret = virXen_destroydomain(domain->conn->handle, domain->id);
+ ret = virXen_destroydomain(priv->handle, domain->id);
if (ret < 0)
return (-1);
return (0);
xenHypervisorSetMaxMemory(virDomainPtr domain, unsigned long memory)
{
int ret;
+ xenUnifiedPrivatePtr priv;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0))
+ if (domain == NULL || domain->conn == NULL)
+ return -1;
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || domain->id < 0)
return (-1);
- ret = virXen_setmaxmem(domain->conn->handle, domain->id, memory);
+ ret = virXen_setmaxmem(priv->handle, domain->id, memory);
if (ret < 0)
return (-1);
return (0);
xenHypervisorSetVcpus(virDomainPtr domain, unsigned int nvcpus)
{
int ret;
+ xenUnifiedPrivatePtr priv;
+
+ if (domain == NULL || domain->conn == NULL)
+ return -1;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0) ||
- (nvcpus < 1))
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || domain->id < 0 || nvcpus < 1)
return (-1);
- ret = virXen_setmaxvcpus(domain->conn->handle, domain->id, nvcpus);
+ ret = virXen_setmaxvcpus(priv->handle, domain->id, nvcpus);
if (ret < 0)
return (-1);
return (0);
unsigned char *cpumap, int maplen)
{
int ret;
+ xenUnifiedPrivatePtr priv;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0) ||
+ if (domain == NULL || domain->conn == NULL)
+ return -1;
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || (domain->id < 0) ||
(cpumap == NULL) || (maplen < 1))
return (-1);
- ret = virXen_setvcpumap(domain->conn->handle, domain->id, vcpu,
+ ret = virXen_setvcpumap(priv->handle, domain->id, vcpu,
cpumap, maplen);
if (ret < 0)
return (-1);
{
xen_getdomaininfo dominfo;
int ret;
-
+ xenUnifiedPrivatePtr priv;
virVcpuInfoPtr ipt;
int nbinfo, i;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0) || (domain->id < 0) ||
+ if (domain == NULL || domain->conn == NULL)
+ return -1;
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0 || (domain->id < 0) ||
(info == NULL) || (maxinfo < 1) ||
(sizeof(cpumap_t) & 7))
return (-1);
/* first get the number of virtual CPUs in this domain */
XEN_GETDOMAININFO_CLEAR(dominfo);
- ret = virXen_getdomaininfo(domain->conn->handle, domain->id,
+ ret = virXen_getdomaininfo(priv->handle, domain->id,
&dominfo);
if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != domain->id))
for (i = 0, ipt = info; i < nbinfo; i++, ipt++) {
if ((cpumaps != NULL) && (i < maxinfo)) {
- ret = virXen_getvcpusinfo(domain->conn->handle, domain->id, i,
+ ret = virXen_getvcpusinfo(priv->handle, domain->id, i,
ipt,
(unsigned char *)VIR_GET_CPUMAP(cpumaps, maplen, i),
maplen);
if (ret < 0)
return(-1);
} else {
- ret = virXen_getvcpusinfo(domain->conn->handle, domain->id, i,
+ ret = virXen_getvcpusinfo(priv->handle, domain->id, i,
ipt, NULL, 0);
if (ret < 0)
return(-1);
xen_getdomaininfo dominfo;
int ret;
int maxcpu;
+ xenUnifiedPrivatePtr priv;
+
+ if (domain == NULL || domain->conn == NULL)
+ return -1;
- if ((domain == NULL) || (domain->conn == NULL) ||
- (domain->conn->handle < 0))
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->handle < 0)
return (-1);
/* inactive domain */
maxcpu = MAX_VIRT_CPUS;
} else {
XEN_GETDOMAININFO_CLEAR(dominfo);
- ret = virXen_getdomaininfo(domain->conn->handle, domain->id,
+ ret = virXen_getdomaininfo(priv->handle, domain->id,
&dominfo);
if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != domain->id))
extern "C" {
#endif
-void xenHypervisorRegister (void);
+extern virDriver xenHypervisorDriver;
+int xenHypervisorInit (void);
+
+/* The following calls are made directly by the Xen proxy: */
+
int xenHypervisorOpen (virConnectPtr conn,
const char *name,
int flags);
int xenHypervisorListDomains (virConnectPtr conn,
int *ids,
int maxids);
-int xenHypervisorNumOfMaxVcpus (virConnectPtr conn);
+ int xenHypervisorGetMaxVcpus (virConnectPtr conn, const char *type);
int xenHypervisorDestroyDomain (virDomainPtr domain);
int xenHypervisorResumeDomain (virDomainPtr domain);
int xenHypervisorPauseDomain (virDomainPtr domain);
--- /dev/null
+/*
+ * xen_unified.c: Unified Xen driver.
+ *
+ * Copyright (C) 2007 Red Hat, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Richard W.M. Jones <rjones@redhat.com>
+ */
+
+#ifdef WITH_XEN
+
+/* Note:
+ *
+ * This driver provides a unified interface to the five
+ * separate underlying Xen drivers (xen_internal, proxy_internal,
+ * xend_internal, xs_internal and xm_internal). Historically
+ * the body of libvirt.c handled the five Xen drivers,
+ * and contained Xen-specific code.
+ *
+ * The interface between Xen drivers and xen_unified is
+ * the same as for "ordinary" libvirt drivers (ie. virDriverPtr),
+ * however this is just for convenience and may be changed
+ * in future. Libvirt.c should no longer call directly
+ * to the five underlying Xen drivers.
+ */
+
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <xen/dom0_ops.h>
+
+#include "internal.h"
+
+#include "xen_unified.h"
+
+#include "xen_internal.h"
+#include "proxy_internal.h"
+#include "xend_internal.h"
+#include "xs_internal.h"
+#include "xm_internal.h"
+
+/* The five Xen drivers below us. */
+static virDriverPtr drivers[] = {
+ &xenHypervisorDriver,
+ &xenProxyDriver,
+ &xenDaemonDriver,
+ &xenStoreDriver,
+ &xenXMDriver
+};
+static const int nb_drivers = sizeof drivers / sizeof drivers[0];
+static const int hypervisor_offset = 0;
+static const int proxy_offset = 1;
+
+/**
+ * xenUnifiedError:
+ * @conn: the connection
+ * @error: the error number
+ * @info: extra information string
+ *
+ * Handle an error at the xend daemon interface
+ */
+static void
+xenUnifiedError (virConnectPtr conn, virErrorNumber error, const char *info)
+{
+ const char *errmsg;
+
+ errmsg = __virErrorMsg (error, info);
+ __virRaiseError (conn, NULL, NULL, VIR_FROM_XEN, error, VIR_ERR_ERROR,
+ errmsg, info, NULL, 0, 0, errmsg, info);
+}
+
+/*----- Dispatch functions. -----*/
+
+/* These dispatch functions follow the model used historically
+ * by libvirt.c -- trying each low-level Xen driver in turn
+ * until one succeeds. However since we know what low-level
+ * drivers can perform which functions, it is probably better
+ * in future to optimise these dispatch functions to just call
+ * the single function (or small number of appropriate functions)
+ * in the low level drivers directly.
+ */
+
+static int
+xenUnifiedOpen (virConnectPtr conn, const char *name, int flags)
+{
+ int i, j;
+ xenUnifiedPrivatePtr priv;
+
+ /* If name == NULL, name == "", or begins with "xen", then it's for us. */
+ if (!name || name[0] == '\0')
+ name = "xen";
+ if (strncasecmp (name, "xen", 3) != 0)
+ return VIR_DRV_OPEN_DECLINED;
+
+ /* Allocate per-connection private data. */
+ priv = malloc (sizeof *priv);
+ if (!priv) {
+ xenUnifiedError (conn, VIR_ERR_NO_MEMORY, "allocating private data");
+ return VIR_DRV_OPEN_ERROR;
+ }
+ conn->privateData = priv;
+
+ priv->handle = -1;
+ priv->xendConfigVersion = -1;
+ priv->type = -1;
+ priv->len = -1;
+ priv->addr = NULL;
+ priv->xshandle = NULL;
+ priv->proxy = -1;
+
+ for (i = 0; i < nb_drivers; ++i) {
+ int failed_to_open = 1;
+
+ /* Ignore proxy for root */
+ if (i == proxy_offset && getuid() == 0)
+ continue;
+
+ if (drivers[i]->open &&
+ drivers[i]->open (conn, name, flags) == VIR_DRV_OPEN_SUCCESS)
+ failed_to_open = 0;
+
+ /* If as root, then all drivers must succeed.
+ If non-root, then only proxy must succeed */
+ if (failed_to_open && (getuid() == 0 || i == proxy_offset)) {
+ for (j = 0; j < i; ++j)
+ drivers[j]->close (conn);
+ return VIR_DRV_OPEN_ERROR;
+ }
+ }
+
+ return VIR_DRV_OPEN_SUCCESS;
+}
+
+static int
+xenUnifiedClose (virConnectPtr conn)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->close)
+ (void) drivers[i]->close (conn);
+
+ free (conn->privateData);
+ conn->privateData = NULL;
+
+ return 0;
+}
+
+static const char *
+xenUnifiedType (virConnectPtr conn)
+{
+ int i;
+ const char *ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->type) {
+ ret = drivers[i]->type (conn);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static int
+xenUnifiedVersion (virConnectPtr conn, unsigned long *hvVer)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->version &&
+ drivers[i]->version (conn, hvVer) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type)
+{
+ int i;
+
+ if (!type)
+ type = "Xen";
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (strcmp (drivers[i]->name, type) == 0)
+ return drivers[i]->getMaxVcpus (conn, type);
+
+ return -1;
+}
+
+static int
+xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->nodeGetInfo &&
+ drivers[i]->nodeGetInfo (conn, info) == 0)
+ return 0;
+
+ return -1;
+}
+
+static char *
+xenUnifiedGetCapabilities (virConnectPtr conn)
+{
+ int i;
+ char *ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->getCapabilities) {
+ ret = drivers[i]->getCapabilities (conn);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static int
+xenUnifiedListDomains (virConnectPtr conn, int *ids, int maxids)
+{
+ int i, ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->listDomains) {
+ ret = drivers[i]->listDomains (conn, ids, maxids);
+ if (ret >= 0) return ret;
+ }
+
+ return -1;
+}
+
+static int
+xenUnifiedNumOfDomains (virConnectPtr conn)
+{
+ int i, ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->numOfDomains) {
+ ret = drivers[i]->numOfDomains (conn);
+ if (ret >= 0) return ret;
+ }
+
+ return -1;
+}
+
+static virDomainPtr
+xenUnifiedDomainCreateLinux (virConnectPtr conn,
+ const char *xmlDesc, unsigned int flags)
+{
+ int i;
+ virDomainPtr ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainCreateLinux) {
+ ret = drivers[i]->domainCreateLinux (conn, xmlDesc, flags);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static virDomainPtr
+xenUnifiedDomainLookupByID (virConnectPtr conn, int id)
+{
+ int i;
+ virDomainPtr ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainLookupByID) {
+ ret = drivers[i]->domainLookupByID (conn, id);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static virDomainPtr
+xenUnifiedDomainLookupByUUID (virConnectPtr conn,
+ const unsigned char *uuid)
+{
+ int i;
+ virDomainPtr ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainLookupByUUID) {
+ ret = drivers[i]->domainLookupByUUID (conn, uuid);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static virDomainPtr
+xenUnifiedDomainLookupByName (virConnectPtr conn,
+ const char *name)
+{
+ int i;
+ virDomainPtr ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainLookupByName) {
+ ret = drivers[i]->domainLookupByName (conn, name);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static int
+xenUnifiedDomainSuspend (virDomainPtr dom)
+{
+ int i;
+
+ /* Try non-hypervisor methods first, then hypervisor direct method
+ * as a last resort.
+ */
+ for (i = 0; i < nb_drivers; ++i)
+ if (i != hypervisor_offset &&
+ drivers[i]->domainSuspend &&
+ drivers[i]->domainSuspend (dom) == 0)
+ return 0;
+
+ if (drivers[hypervisor_offset]->domainSuspend &&
+ drivers[hypervisor_offset]->domainSuspend (dom) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainResume (virDomainPtr dom)
+{
+ int i;
+
+ /* Try non-hypervisor methods first, then hypervisor direct method
+ * as a last resort.
+ */
+ for (i = 0; i < nb_drivers; ++i)
+ if (i != hypervisor_offset &&
+ drivers[i]->domainResume &&
+ drivers[i]->domainResume (dom) == 0)
+ return 0;
+
+ if (drivers[hypervisor_offset]->domainResume &&
+ drivers[hypervisor_offset]->domainResume (dom) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainShutdown (virDomainPtr dom)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainShutdown &&
+ drivers[i]->domainShutdown (dom) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainReboot (virDomainPtr dom, unsigned int flags)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainReboot &&
+ drivers[i]->domainReboot (dom, flags) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainDestroy (virDomainPtr dom)
+{
+ int i;
+
+ /* Try non-hypervisor methods first, then hypervisor direct method
+ * as a last resort.
+ */
+ for (i = 0; i < nb_drivers; ++i)
+ if (i != hypervisor_offset &&
+ drivers[i]->domainDestroy &&
+ drivers[i]->domainDestroy (dom) == 0)
+ return 0;
+
+ if (drivers[hypervisor_offset]->domainDestroy &&
+ drivers[hypervisor_offset]->domainDestroy (dom) == 0)
+ return 0;
+
+ return -1;
+}
+
+static char *
+xenUnifiedDomainGetOSType (virDomainPtr dom)
+{
+ int i;
+ char *ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainGetOSType) {
+ ret = drivers[i]->domainGetOSType (dom);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static unsigned long
+xenUnifiedDomainGetMaxMemory (virDomainPtr dom)
+{
+ int i;
+ unsigned long ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainGetMaxMemory) {
+ ret = drivers[i]->domainGetMaxMemory (dom);
+ if (ret != 0) return ret;
+ }
+
+ return 0;
+}
+
+static int
+xenUnifiedDomainSetMaxMemory (virDomainPtr dom, unsigned long memory)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainSetMaxMemory &&
+ drivers[i]->domainSetMaxMemory (dom, memory) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainSetMemory (virDomainPtr dom, unsigned long memory)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainSetMemory &&
+ drivers[i]->domainSetMemory (dom, memory) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainGetInfo (virDomainPtr dom, virDomainInfoPtr info)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainGetInfo &&
+ drivers[i]->domainGetInfo (dom, info) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainSave (virDomainPtr dom, const char *to)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainSave &&
+ drivers[i]->domainSave (dom, to) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainRestore (virConnectPtr conn, const char *from)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainRestore &&
+ drivers[i]->domainRestore (conn, from) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainCoreDump (virDomainPtr dom, const char *to, int flags)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainCoreDump &&
+ drivers[i]->domainCoreDump (dom, to, flags) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainSetVcpus (virDomainPtr dom, unsigned int nvcpus)
+{
+ int i;
+
+ /* Try non-hypervisor methods first, then hypervisor direct method
+ * as a last resort.
+ */
+ for (i = 0; i < nb_drivers; ++i)
+ if (i != hypervisor_offset &&
+ drivers[i]->domainSetVcpus &&
+ drivers[i]->domainSetVcpus (dom, nvcpus) == 0)
+ return 0;
+
+ if (drivers[hypervisor_offset]->domainSetVcpus &&
+ drivers[hypervisor_offset]->domainSetVcpus (dom, nvcpus) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainPinVcpu (virDomainPtr dom, unsigned int vcpu,
+ unsigned char *cpumap, int maplen)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainPinVcpu &&
+ drivers[i]->domainPinVcpu (dom, vcpu, cpumap, maplen) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainGetVcpus (virDomainPtr dom,
+ virVcpuInfoPtr info, int maxinfo,
+ unsigned char *cpumaps, int maplen)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainGetVcpus &&
+ drivers[i]->domainGetVcpus (dom, info, maxinfo, cpumaps, maplen) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainGetMaxVcpus (virDomainPtr dom)
+{
+ int i, ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainGetMaxVcpus) {
+ ret = drivers[i]->domainGetMaxVcpus (dom);
+ if (ret != 0) return ret;
+ }
+
+ return -1;
+}
+
+static char *
+xenUnifiedDomainDumpXML (virDomainPtr dom, int flags)
+{
+ int i;
+ char *ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainDumpXML) {
+ ret = drivers[i]->domainDumpXML (dom, flags);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static int
+xenUnifiedListDefinedDomains (virConnectPtr conn, char **const names,
+ int maxnames)
+{
+ int i;
+ int ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->listDefinedDomains) {
+ ret = drivers[i]->listDefinedDomains (conn, names, maxnames);
+ if (ret >= 0) return ret;
+ }
+
+ return -1;
+}
+
+static int
+xenUnifiedNumOfDefinedDomains (virConnectPtr conn)
+{
+ int i;
+ int ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->numOfDefinedDomains) {
+ ret = drivers[i]->numOfDefinedDomains (conn);
+ if (ret >= 0) return ret;
+ }
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainCreate (virDomainPtr dom)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainCreate &&
+ drivers[i]->domainCreate (dom) == 0)
+ return 0;
+
+ return -1;
+}
+
+static virDomainPtr
+xenUnifiedDomainDefineXML (virConnectPtr conn, const char *xml)
+{
+ int i;
+ virDomainPtr ret;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainDefineXML) {
+ ret = drivers[i]->domainDefineXML (conn, xml);
+ if (ret) return ret;
+ }
+
+ return NULL;
+}
+
+static int
+xenUnifiedDomainUndefine (virDomainPtr dom)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainUndefine &&
+ drivers[i]->domainUndefine (dom) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainAttachDevice (virDomainPtr dom, char *xml)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainAttachDevice &&
+ drivers[i]->domainAttachDevice (dom, xml) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainDetachDevice (virDomainPtr dom, char *xml)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainDetachDevice &&
+ drivers[i]->domainDetachDevice (dom, xml) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainGetAutostart (virDomainPtr dom, int *autostart)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainGetAutostart &&
+ drivers[i]->domainGetAutostart (dom, autostart) == 0)
+ return 0;
+
+ return -1;
+}
+
+static int
+xenUnifiedDomainSetAutostart (virDomainPtr dom, int autostart)
+{
+ int i;
+
+ for (i = 0; i < nb_drivers; ++i)
+ if (drivers[i]->domainSetAutostart &&
+ drivers[i]->domainSetAutostart (dom, autostart) == 0)
+ return 0;
+
+ return -1;
+}
+
+/*----- Register with libvirt.c, and initialise Xen drivers. -----*/
+
+#define VERSION ((DOM0_INTERFACE_VERSION >> 24) * 1000000 + \
+ ((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 + \
+ (DOM0_INTERFACE_VERSION & 0xFFFF))
+
+/* The interface which we export upwards to libvirt.c. */
+static virDriver xenUnifiedDriver = {
+ .no = VIR_DRV_XEN_UNIFIED,
+ .name = "xen",
+ .ver = VERSION,
+ .open = xenUnifiedOpen,
+ .close = xenUnifiedClose,
+ .type = xenUnifiedType,
+ .version = xenUnifiedVersion,
+ .getMaxVcpus = xenUnifiedGetMaxVcpus,
+ .nodeGetInfo = xenUnifiedNodeGetInfo,
+ .getCapabilities = xenUnifiedGetCapabilities,
+ .listDomains = xenUnifiedListDomains,
+ .numOfDomains = xenUnifiedNumOfDomains,
+ .domainCreateLinux = xenUnifiedDomainCreateLinux,
+ .domainLookupByID = xenUnifiedDomainLookupByID,
+ .domainLookupByUUID = xenUnifiedDomainLookupByUUID,
+ .domainLookupByName = xenUnifiedDomainLookupByName,
+ .domainSuspend = xenUnifiedDomainSuspend,
+ .domainResume = xenUnifiedDomainResume,
+ .domainShutdown = xenUnifiedDomainShutdown,
+ .domainReboot = xenUnifiedDomainReboot,
+ .domainDestroy = xenUnifiedDomainDestroy,
+ .domainGetOSType = xenUnifiedDomainGetOSType,
+ .domainGetMaxMemory = xenUnifiedDomainGetMaxMemory,
+ .domainSetMaxMemory = xenUnifiedDomainSetMaxMemory,
+ .domainSetMemory = xenUnifiedDomainSetMemory,
+ .domainGetInfo = xenUnifiedDomainGetInfo,
+ .domainSave = xenUnifiedDomainSave,
+ .domainRestore = xenUnifiedDomainRestore,
+ .domainCoreDump = xenUnifiedDomainCoreDump,
+ .domainSetVcpus = xenUnifiedDomainSetVcpus,
+ .domainPinVcpu = xenUnifiedDomainPinVcpu,
+ .domainGetVcpus = xenUnifiedDomainGetVcpus,
+ .domainGetMaxVcpus = xenUnifiedDomainGetMaxVcpus,
+ .domainDumpXML = xenUnifiedDomainDumpXML,
+ .listDefinedDomains = xenUnifiedListDefinedDomains,
+ .numOfDefinedDomains = xenUnifiedNumOfDefinedDomains,
+ .domainCreate = xenUnifiedDomainCreate,
+ .domainDefineXML = xenUnifiedDomainDefineXML,
+ .domainUndefine = xenUnifiedDomainUndefine,
+ .domainAttachDevice = xenUnifiedDomainAttachDevice,
+ .domainDetachDevice = xenUnifiedDomainDetachDevice,
+ .domainGetAutostart = xenUnifiedDomainGetAutostart,
+ .domainSetAutostart = xenUnifiedDomainSetAutostart,
+};
+
+int
+xenUnifiedRegister (void)
+{
+ /* Ignore failures here. */
+ (void) xenHypervisorInit ();
+ (void) xenProxyInit ();
+ (void) xenDaemonInit ();
+ (void) xenStoreInit ();
+ (void) xenXMInit ();
+
+ return virRegisterDriver (&xenUnifiedDriver);
+}
+
+#endif /* WITH_XEN */
--- /dev/null
+/*
+ * xen_unified.c: Unified Xen driver.
+ *
+ * Copyright (C) 2007 Red Hat, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Richard W.M. Jones <rjones@redhat.com>
+ */
+
+#ifndef __VIR_XEN_UNIFIED_H__
+#define __VIR_XEN_UNIFIED_H__
+
+#include "internal.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int xenUnifiedRegister (void);
+
+/* xenUnifiedPrivatePtr:
+ *
+ * Per-connection private data, stored in conn->privateData. All Xen
+ * low-level drivers access parts of this structure.
+ */
+struct _xenUnifiedPrivate {
+#ifdef WITH_XEN
+ int handle; /* Xen hypervisor handle */
+
+ int xendConfigVersion; /* XenD config version */
+
+ /* XXX This code is not IPv6 aware. */
+ /* connection to xend */
+ int type; /* PF_UNIX or PF_INET */
+ int len; /* length of addr */
+ struct sockaddr *addr; /* type of address used */
+ struct sockaddr_un addr_un; /* the unix address */
+ struct sockaddr_in addr_in; /* the inet address */
+
+ struct xs_handle *xshandle; /* handle to talk to the xenstore */
+#endif /* WITH_XEN */
+
+ int proxy; /* fd of proxy. */
+};
+
+typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __VIR_XEN_UNIFIED_H__ */
#include "internal.h"
#include "sexpr.h"
#include "xml.h"
+#include "xen_unified.h"
#include "xend_internal.h"
#include "xen_internal.h" /* for DOM0_INTERFACE_VERSION */
#include "xs_internal.h" /* To extract VNC port & Serial console TTY */
#endif /* PROXY */
#ifndef PROXY
-static virDriver xenDaemonDriver = {
- VIR_DRV_XEN_DAEMON,
+virDriver xenDaemonDriver = {
+ -1,
"XenDaemon",
(DOM0_INTERFACE_VERSION >> 24) * 1000000 +
((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
};
/**
- * xenDaemonRegister:
+ * xenDaemonInit:
*
- * Registers the xenDaemon driver
+ * Initialise the xenDaemon driver.
*/
-void xenDaemonRegister(void)
+int
+xenDaemonInit (void)
{
- virRegisterDriver(&xenDaemonDriver);
+ return 0;
}
#endif /* !PROXY */
int s;
int serrno;
int no_slow_start = 1;
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) xend->privateData;
- s = socket(xend->type, SOCK_STREAM, 0);
+ s = socket(priv->type, SOCK_STREAM, 0);
if (s == -1) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
"failed to create a socket");
sizeof(no_slow_start));
- if (connect(s, xend->addr, xend->len) == -1) {
+ if (connect(s, priv->addr, priv->len) == -1) {
serrno = errno;
close(s);
errno = serrno;
xenDaemonOpen_unix(virConnectPtr conn, const char *path)
{
struct sockaddr_un *addr;
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
if ((conn == NULL) || (path == NULL))
return (-1);
- addr = &conn->addr_un;
+ addr = &priv->addr_un;
addr->sun_family = AF_UNIX;
memset(addr->sun_path, 0, sizeof(addr->sun_path));
strncpy(addr->sun_path, path, sizeof(addr->sun_path));
- conn->len = sizeof(addr->sun_family) + strlen(addr->sun_path);
- if ((unsigned int) conn->len > sizeof(addr->sun_path))
- conn->len = sizeof(addr->sun_path);
+ priv->len = sizeof(addr->sun_family) + strlen(addr->sun_path);
+ if ((unsigned int) priv->len > sizeof(addr->sun_path))
+ priv->len = sizeof(addr->sun_path);
- conn->addr = (struct sockaddr *) addr;
- conn->type = PF_UNIX;
+ priv->addr = (struct sockaddr *) addr;
+ priv->type = PF_UNIX;
return (0);
}
{
struct in_addr ip;
struct hostent *pent;
+ xenUnifiedPrivatePtr priv;
if ((conn == NULL) || (host == NULL) || (port <= 0))
return (-1);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
pent = gethostbyname(host);
if (pent == NULL) {
if (inet_aton(host, &ip) == 0) {
memcpy(&ip, pent->h_addr_list[0], sizeof(ip));
}
- conn->len = sizeof(struct sockaddr_in);
- conn->addr = (struct sockaddr *) &conn->addr_in;
- conn->type = PF_INET;
+ priv->len = sizeof(struct sockaddr_in);
+ priv->addr = (struct sockaddr *) &priv->addr_in;
+ priv->type = PF_INET;
- conn->addr_in.sin_family = AF_INET;
- conn->addr_in.sin_port = htons(port);
- memcpy(&conn->addr_in.sin_addr, &ip, sizeof(ip));
+ priv->addr_in.sin_family = AF_INET;
+ priv->addr_in.sin_port = htons(port);
+ memcpy(&priv->addr_in.sin_addr, &ip, sizeof(ip));
return (0);
}
xend_detect_config_version(virConnectPtr conn) {
struct sexpr *root;
const char *value;
+ xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
root = sexpr_get(conn, "/xend/node/");
if (root == NULL)
return (-1);
value = sexpr_node(root, "node/xend_config_format");
if (value) {
- conn->xendConfigVersion = strtol(value, NULL, 10);
+ priv->xendConfigVersion = strtol(value, NULL, 10);
} else {
/* Xen prior to 3.0.3 did not have the xend_config_format
field, and is implicitly version 1. */
- conn->xendConfigVersion = 1;
+ priv->xendConfigVersion = 1;
}
sexpr_free(root);
- return conn->xendConfigVersion;
+ return priv->xendConfigVersion;
}
/**
char uuid[VIR_UUID_BUFLEN];
const char *name;
const char *tmp;
+ xenUnifiedPrivatePtr priv;
if ((conn == NULL) || (root == NULL))
return(NULL);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
dst_uuid = (char *) &uuid[0];
if (sexpr_uuid(&dst_uuid, root, "domain/uuid") == NULL)
goto error;
/* New 3.0.4 XenD will not report a domid for inactive domains,
* so only error out for old XenD
*/
- if (!tmp && conn->xendConfigVersion < 3)
+ if (!tmp && priv->xendConfigVersion < 3)
goto error;
if (tmp)
int ret;
unsigned long version;
- if ((name == NULL) || (name[0] == 0) || (!strcasecmp(name, "xen"))) {
- /*
- * try first to open the unix socket
- */
- ret = xenDaemonOpen_unix(conn, "/var/lib/xend/xend-socket");
- if (ret < 0)
- goto try_http;
- ret = xenDaemonGetVersion(conn, &version);
- if (ret == 0)
- goto done;
-
-try_http:
+ /* If the name is just "xen" (it might originally have been NULL, see
+ * xenUnifiedOpen) then try default paths and methods to get to the
+ * xend socket.
+ */
+ if (strcasecmp (name, "xen") == 0) {
/*
- * try though http on port 8000
- */
- ret = xenDaemonOpen_tcp(conn, "localhost", 8000);
- if (ret < 0)
- goto failed;
- ret = xenDaemonGetVersion(conn, &version);
- if (ret < 0)
- goto failed;
+ * try first to open the unix socket
+ */
+ ret = xenDaemonOpen_unix(conn, "/var/lib/xend/xend-socket");
+ if (ret < 0)
+ goto try_http;
+ ret = xenDaemonGetVersion(conn, &version);
+ if (ret == 0)
+ goto done;
+
+ try_http:
+ /*
+ * try though http on port 8000
+ */
+ ret = xenDaemonOpen_tcp(conn, "localhost", 8000);
+ if (ret < 0)
+ goto failed;
+ ret = xenDaemonGetVersion(conn, &version);
+ if (ret < 0)
+ goto failed;
} else {
/*
- * We were given a connection name, expected to be an URL
- */
- uri = xmlParseURI(name);
- if (uri == NULL) {
- if (!(flags & VIR_DRV_OPEN_QUIET))
- virXendError(conn, VIR_ERR_NO_SUPPORT, name);
- goto failed;
- }
+ * We were given a connection name, expected to be an URL
+ */
+ uri = xmlParseURI(name);
+ if (uri == NULL) {
+ if (!(flags & VIR_DRV_OPEN_QUIET))
+ virXendError(conn, VIR_ERR_NO_SUPPORT, name);
+ goto failed;
+ }
- if (uri->scheme == NULL) {
- /* It should be a file access */
- if (uri->path == NULL) {
- if (!(flags & VIR_DRV_OPEN_QUIET))
- virXendError(conn, VIR_ERR_NO_SUPPORT, name);
- goto failed;
- }
- ret = xenDaemonOpen_unix(conn, uri->path);
- if (ret < 0)
- goto failed;
-
- ret = xenDaemonGetVersion(conn, &version);
- if (ret < 0)
- goto failed;
- } else if (!strcasecmp(uri->scheme, "http")) {
- ret = xenDaemonOpen_tcp(conn, uri->server, uri->port);
+ if (uri->scheme == NULL) {
+ /* It should be a file access */
+ if (uri->path == NULL) {
+ if (!(flags & VIR_DRV_OPEN_QUIET))
+ virXendError(conn, VIR_ERR_NO_SUPPORT, name);
+ goto failed;
+ }
+ ret = xenDaemonOpen_unix(conn, uri->path);
if (ret < 0)
- goto failed;
- ret = xenDaemonGetVersion(conn, &version);
- if (ret < 0)
- goto failed;
- } else {
- if (!(flags & VIR_DRV_OPEN_QUIET))
- virXendError(conn, VIR_ERR_NO_SUPPORT, name);
- goto failed;
- }
+ goto failed;
+
+ ret = xenDaemonGetVersion(conn, &version);
+ if (ret < 0)
+ goto failed;
+ } else if (!strcasecmp(uri->scheme, "http")) {
+ ret = xenDaemonOpen_tcp(conn, uri->server, uri->port);
+ if (ret < 0)
+ goto failed;
+ ret = xenDaemonGetVersion(conn, &version);
+ if (ret < 0)
+ goto failed;
+ } else {
+ if (!(flags & VIR_DRV_OPEN_QUIET))
+ virXendError(conn, VIR_ERR_NO_SUPPORT, name);
+ goto failed;
+ }
}
-done:
- /* The XenD config version is used to determine
+ done:
+ /* The XenD config version is used to determine
* which APIs / features to activate. Lookup & cache
* it now to avoid repeated HTTP calls
*/
if (xend_detect_config_version(conn) < 0) {
- virXendError(conn, VIR_ERR_INTERNAL_ERROR, "cannot determine xend config version");
+ virXendError(conn, VIR_ERR_INTERNAL_ERROR,
+ "cannot determine xend config version");
goto failed;
}
if (uri != NULL)
xmlFreeURI(uri);
return(ret);
+
failed:
if (uri != NULL)
xmlFreeURI(uri);
* initialized with xenDaemonOpen is no longer needed
* to free the associated resources.
*
- * Returns 0 in case of succes, -1 in case of error
+ * Returns 0 in case of success, -1 in case of error
*/
int
xenDaemonClose(virConnectPtr conn ATTRIBUTE_UNUSED)
{
- return(0);
+ return 0;
}
/**
{
unsigned long ret = 0;
struct sexpr *root;
+ xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
__FUNCTION__);
return(-1);
}
- if (domain->id < 0 && domain->conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (domain->id < 0 && priv->xendConfigVersion < 3)
return(-1);
/* can we ask for a subset ? worth it ? */
xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
{
char buf[1024];
+ xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
__FUNCTION__);
return(-1);
}
- if (domain->id < 0 && domain->conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (domain->id < 0 && priv->xendConfigVersion < 3)
return(-1);
snprintf(buf, sizeof(buf), "%lu", memory >> 10);
xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory)
{
char buf[1024];
+ xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
__FUNCTION__);
return(-1);
}
- if (domain->id < 0 && domain->conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (domain->id < 0 && priv->xendConfigVersion < 3)
return(-1);
snprintf(buf, sizeof(buf), "%lu", memory >> 10);
{
char *ret = NULL;
struct sexpr *root;
+ xenUnifiedPrivatePtr priv;
root = sexpr_get(conn, "/xend/domain/%d?detail=1", domid);
if (root == NULL)
return (NULL);
- ret = xend_parse_sexp_desc(conn, root, conn->xendConfigVersion);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
+ ret = xend_parse_sexp_desc(conn, root, priv->xendConfigVersion);
sexpr_free(root);
return (ret);
{
char *ret = NULL;
struct sexpr *root;
+ xenUnifiedPrivatePtr priv;
root = sexpr_get(conn, "/xend/domain/%s?detail=1", name);
if (root == NULL)
return (NULL);
- ret = xend_parse_sexp_desc(conn, root, conn->xendConfigVersion);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
+ ret = xend_parse_sexp_desc(conn, root, priv->xendConfigVersion);
sexpr_free(root);
return (ret);
char *
xenDaemonDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED)
{
+ xenUnifiedPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
__FUNCTION__);
return(NULL);
}
- if (domain->id < 0 && domain->conn->xendConfigVersion < 3)
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (domain->id < 0 && priv->xendConfigVersion < 3)
return(NULL);
if (domain->id < 0)
return xenDaemonDomainDumpXMLByName(domain->conn, domain->name);
{
struct sexpr *root;
int ret;
+ xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
(info == NULL)) {
__FUNCTION__);
return(-1);
}
- if (domain->id < 0 && domain->conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (domain->id < 0 && priv->xendConfigVersion < 3)
return(-1);
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
xenDaemonDomainSetVcpus(virDomainPtr domain, unsigned int vcpus)
{
char buf[VIR_UUID_BUFLEN];
+ xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
|| (vcpus < 1)) {
__FUNCTION__);
return (-1);
}
- if (domain->id < 0 && domain->conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (domain->id < 0 && priv->xendConfigVersion < 3)
return(-1);
snprintf(buf, sizeof(buf), "%d", vcpus);
virDomainPtr ret;
char *name = NULL;
int id = -1;
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
+
/* Old approach for xen <= 3.0.3 */
- if (conn->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < 3) {
char **names, **tmp;
unsigned char ident[VIR_UUID_BUFLEN];
names = xenDaemonListDomainsOld(conn);
char *sexpr;
char *name = NULL;
virDomainPtr dom = NULL;
+ xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
}
- sexpr = virDomainParseXMLDesc(conn, xmlDesc, &name, conn->xendConfigVersion);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
+ sexpr = virDomainParseXMLDesc(conn, xmlDesc, &name, priv->xendConfigVersion);
if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR, "domain");
if (sexpr != NULL)
{
char *sexpr, *conf;
int hvm = 0, ret;
+ xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
return (-1);
}
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
if (strcmp(virDomainGetOSType(domain), "linux"))
hvm = 1;
- sexpr = virParseXMLDevice(domain->conn, xml, hvm, domain->conn->xendConfigVersion);
+ sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion);
if (sexpr == NULL)
return (-1);
if (!memcmp(sexpr, "(device ", 8)) {
char *sexpr;
char *name = NULL;
virDomainPtr dom;
+ xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
virXendError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (NULL);
}
- if (conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
+ if (priv->xendConfigVersion < 3)
return(NULL);
- sexpr = virDomainParseXMLDesc(conn, xmlDesc, &name, conn->xendConfigVersion);
+ sexpr = virDomainParseXMLDesc(conn, xmlDesc, &name, priv->xendConfigVersion);
if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR, "domain");
if (sexpr != NULL)
free(name);
return (NULL);
}
-int xenDaemonDomainCreate(virDomainPtr domain) {
+int xenDaemonDomainCreate(virDomainPtr domain)
+{
+ xenUnifiedPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
__FUNCTION__);
return(-1);
}
- if (domain->conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (priv->xendConfigVersion < 3)
return(-1);
return xend_op(domain->conn, domain->name, "op", "start", NULL);
}
-int xenDaemonDomainUndefine(virDomainPtr domain) {
+int xenDaemonDomainUndefine(virDomainPtr domain)
+{
+ xenUnifiedPrivatePtr priv;
+
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
__FUNCTION__);
return(-1);
}
- if (domain->conn->xendConfigVersion < 3)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (priv->xendConfigVersion < 3)
return(-1);
return xend_op(domain->conn, domain->name, "op", "delete", NULL);
struct sexpr *root = NULL;
int ret = -1;
struct sexpr *_for_i, *node;
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
- if (conn->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < 3)
return(-1);
root = sexpr_get(conn, "/xend/domain?state=halted");
struct sexpr *root = NULL;
int ret = -1;
struct sexpr *_for_i, *node;
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
- if (conn->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < 3)
return(-1);
if ((names == NULL) || (maxnames <= 0))
char *xend_parse_domain_sexp(virConnectPtr conn, char *root, int xendConfigVersion);
+extern virDriver xenDaemonDriver;
+int xenDaemonInit (void);
+
/* refactored ones */
-void xenDaemonRegister(void);
int xenDaemonOpen(virConnectPtr conn, const char *name, int flags);
int xenDaemonClose(virConnectPtr conn);
int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer);
#include <libxml/xpath.h>
+#include "xen_unified.h"
#include "xm_internal.h"
#include "xend_internal.h"
#include "conf.h"
#define XEND_PCI_CONFIG_PREFIX "xend-pci-"
#define QEMU_IF_SCRIPT "qemu-ifup"
-static virDriver xenXMDriver = {
- VIR_DRV_XEN_XM,
+virDriver xenXMDriver = {
+ -1,
"XenXM",
(DOM0_INTERFACE_VERSION >> 24) * 1000000 +
((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
errmsg, info, NULL, 0, 0, errmsg, info);
}
-void xenXMRegister(void)
+int
+xenXMInit (void)
{
char *envConfigDir;
int safeMode = 0;
- virRegisterDriver(&xenXMDriver);
/* Disable use of env variable if running setuid */
if ((geteuid() != getuid()) ||
} else {
strcpy(configDir, XM_CONFIG_DIR);
}
+
+ return 0;
}
* We only support a single directory, so repeated calls
* to open all end up using the same cache of files
*/
-int xenXMOpen(virConnectPtr conn ATTRIBUTE_UNUSED, const char *name, int flags ATTRIBUTE_UNUSED) {
- if (name &&
- strcasecmp(name, "xen")) {
- return (-1);
- }
-
+int
+xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED,
+ const char *name ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED)
+{
if (nconnections == 0) {
configCache = virHashCreate(50);
if (!configCache)
const char *vnclisten = NULL;
const char *vncpasswd = NULL;
const char *keymap = NULL;
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
if (xenXMConfigGetString(conf, "name", &name) < 0)
return (NULL);
}
}
- if (hvm && conn->xendConfigVersion == 1) {
+ if (hvm && priv->xendConfigVersion == 1) {
if (xenXMConfigGetString(conf, "cdrom", &str) == 0) {
virBufferAdd(buf, " <disk type='file' device='cdrom'>\n", -1);
virBufferAdd(buf, " <driver name='file'/>\n", -1);
}
/* HVM guests, or old PV guests use this config format */
- if (hvm || conn->xendConfigVersion < 3) {
+ if (hvm || priv->xendConfigVersion < 3) {
if (xenXMConfigGetInt(conf, "vnc", &val) == 0 && val) {
vnc = 1;
if (xenXMConfigGetInt(conf, "vncunused", &vncunused) < 0)
char *sexpr;
int ret;
unsigned char uuid[VIR_UUID_BUFLEN];
+ xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
xenXMError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
if (!(xml = xenXMDomainDumpXML(domain, 0)))
return (-1);
- if (!(sexpr = virDomainParseXMLDesc(domain->conn, xml, NULL, domain->conn->xendConfigVersion))) {
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
+ if (!(sexpr = virDomainParseXMLDesc(domain->conn, xml, NULL, priv->xendConfigVersion))) {
free(xml);
return (-1);
}
xmlChar *prop = NULL;
virConfPtr conf = NULL;
int hvm = 0, i;
+ xenUnifiedPrivatePtr priv;
doc = xmlReadDoc((const xmlChar *) xml, "domain.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
hvm = 1;
xmlXPathFreeObject(obj);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+
if (hvm) {
const char *boot = "c";
if (xenXMConfigSetString(conf, "builder", "hvm") < 0)
"cannot set the apic parameter") < 0)
goto error;
- if (conn->xendConfigVersion == 1) {
+ if (priv->xendConfigVersion == 1) {
if (xenXMConfigSetStringFromXPath(conn, conf, ctxt, "cdrom", "string(/domain/devices/disk[@device='cdrom']/source/@file)", 1,
"cannot set the cdrom parameter") < 0)
goto error;
}
- if (hvm || conn->xendConfigVersion < 3) {
+ if (hvm || priv->xendConfigVersion < 3) {
if (xenXMConfigSetIntFromXPath(conn, conf, ctxt, "sdl", "string(count(/domain/devices/graphics[@type='sdl']))", 0, 0,
"cannot set the sdl parameter") < 0)
goto error;
for (i = obj->nodesetval->nodeNr -1 ; i >= 0 ; i--) {
virConfValuePtr thisDisk;
char *disk = NULL;
- if (xenXMParseXMLDisk(obj->nodesetval->nodeTab[i], hvm, conn->xendConfigVersion, &disk) < 0)
+ if (xenXMParseXMLDisk(obj->nodesetval->nodeTab[i], hvm, priv->xendConfigVersion, &disk) < 0)
goto error;
if (disk) {
if (!(thisDisk = malloc(sizeof(virConfValue)))) {
#include "libvirt/libvirt.h"
#include "conf.h"
+#include "internal.h"
#ifdef __cplusplus
extern "C" {
#endif
-void xenXMRegister(void);
+extern virDriver xenXMDriver;
+int xenXMInit (void);
+
int xenXMOpen(virConnectPtr conn, const char *name, int flags);
int xenXMClose(virConnectPtr conn);
const char *xenXMGetType(virConnectPtr conn);
#include "internal.h"
#include "driver.h"
+#include "xen_unified.h"
#include "xs_internal.h"
#include "xen_internal.h" /* for xenHypervisorCheckID */
#ifndef PROXY
static char *xenStoreDomainGetOSType(virDomainPtr domain);
-static virDriver xenStoreDriver = {
- VIR_DRV_XEN_STORE,
+virDriver xenStoreDriver = {
+ -1,
"XenStore",
(DOM0_INTERFACE_VERSION >> 24) * 1000000 +
((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
};
/**
- * xenStoreRegister:
+ * xenStoreInit:
*
- * Registers the xenStore driver
+ * Initialisation.
*/
-void xenStoreRegister(void)
+int
+xenStoreInit ()
{
- virRegisterDriver(&xenStoreDriver);
+ return 0;
}
#endif /* ! PROXY */
virConnectDoStoreList(virConnectPtr conn, const char *path,
unsigned int *nb)
{
- if ((conn == NULL) || (conn->xshandle == NULL) || (path == NULL) ||
- (nb == NULL))
+ xenUnifiedPrivatePtr priv;
+
+ if (conn == NULL)
+ return NULL;
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL || path == NULL || nb == NULL)
return (NULL);
- return xs_directory(conn->xshandle, 0, path, nb);
+ return xs_directory (priv->xshandle, 0, path, nb);
}
#endif /* ! PROXY */
{
char s[256];
unsigned int len = 0;
+ xenUnifiedPrivatePtr priv;
+
+ if (!conn)
+ return NULL;
- if (!conn || conn->xshandle == NULL)
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL)
return (NULL);
snprintf(s, 255, "/local/domain/%d/%s", domid, path);
s[255] = 0;
- return xs_read(conn->xshandle, 0, &s[0], &len);
+ return xs_read(priv->xshandle, 0, &s[0], &len);
}
#ifndef PROXY
const char *value)
{
char s[256];
-
+ xenUnifiedPrivatePtr priv;
int ret = -1;
if (!VIR_IS_CONNECTED_DOMAIN(domain))
return (-1);
- if (domain->conn->xshandle == NULL)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->xshandle == NULL)
return (-1);
if (domain->conn->flags & VIR_CONNECT_RO)
return (-1);
snprintf(s, 255, "/local/domain/%d/%s", domain->id, path);
s[255] = 0;
- if (xs_write(domain->conn->xshandle, 0, &s[0], value, strlen(value)))
+ if (xs_write(priv->xshandle, 0, &s[0], value, strlen(value)))
ret = 0;
return (ret);
char *vm;
char query[200];
unsigned int len;
+ xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECTED_DOMAIN(domain))
return (NULL);
- if (domain->conn->xshandle == NULL)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->xshandle == NULL)
return (NULL);
snprintf(query, 199, "/local/domain/%d/vm", virDomainGetID(domain));
query[199] = 0;
- vm = xs_read(domain->conn->xshandle, 0, &query[0], &len);
+ vm = xs_read(priv->xshandle, 0, &query[0], &len);
return (vm);
}
char s[256];
char *ret = NULL;
unsigned int len = 0;
+ xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECTED_DOMAIN(domain))
return (NULL);
- if (domain->conn->xshandle == NULL)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->xshandle == NULL)
return (NULL);
snprintf(s, 255, "%s/%s", vm, name);
s[255] = 0;
- ret = xs_read(domain->conn->xshandle, 0, &s[0], &len);
+ ret = xs_read(priv->xshandle, 0, &s[0], &len);
return (ret);
}
* Returns 0 or -1 in case of error.
*/
int
-xenStoreOpen(virConnectPtr conn, const char *name, int flags)
+xenStoreOpen(virConnectPtr conn,
+ const char *name ATTRIBUTE_UNUSED, int flags)
{
- if ((name != NULL) && (strcasecmp(name, "xen")))
- return(-1);
+ xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
#ifdef PROXY
- conn->xshandle = xs_daemon_open_readonly();
+ priv->xshandle = xs_daemon_open_readonly();
#else
if (flags & VIR_DRV_OPEN_RO)
- conn->xshandle = xs_daemon_open_readonly();
+ priv->xshandle = xs_daemon_open_readonly();
else
- conn->xshandle = xs_daemon_open();
+ priv->xshandle = xs_daemon_open();
#endif /* ! PROXY */
- if (conn->xshandle == NULL) {
+ if (priv->xshandle == NULL) {
if (!(flags & VIR_DRV_OPEN_QUIET))
virXenStoreError(conn, VIR_ERR_NO_XEN,
_("failed to connect to Xen Store"));
int
xenStoreClose(virConnectPtr conn)
{
+ xenUnifiedPrivatePtr priv;
+
if (conn == NULL) {
virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
- return(-1);
+ return(-1);
}
- if (conn->xshandle == NULL)
- return(-1);
- xs_daemon_close(conn->xshandle);
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL)
+ return(-1);
+
+ xs_daemon_close(priv->xshandle);
return (0);
}
char *tmp, **tmp2;
unsigned int nb_vcpus;
char request[200];
+ xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECTED_DOMAIN(domain))
return (-1);
__FUNCTION__);
return(-1);
}
- if (domain->conn->xshandle == NULL)
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+ if (priv->xshandle == NULL)
return(-1);
+
if (domain->id == -1)
return(-1);
unsigned int num;
char **idlist;
int ret = -1;
+ xenUnifiedPrivatePtr priv;
- if ((conn == NULL) || (conn->xshandle == NULL)) {
+ if (conn == NULL) {
virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
- return(-1);
+ return -1;
}
- idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL) {
+ virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ return(-1);
+ }
+ idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num);
if (idlist) {
free(idlist);
ret = num;
unsigned int num, i;
int ret;
long id;
+ xenUnifiedPrivatePtr priv;
if ((conn == NULL) || (ids == NULL)) {
virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1);
}
- if (conn->xshandle == NULL)
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL)
return(-1);
- idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
+ idlist = xs_directory (priv->xshandle, 0, "/local/domain", &num);
if (idlist == NULL)
return(-1);
char prop[200], *tmp, *path = NULL;
int found = 0;
struct xend_domain *xenddomain = NULL;
+ xenUnifiedPrivatePtr priv;
if ((conn == NULL) || (name == NULL)) {
virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(NULL);
}
- if (conn->xshandle == NULL)
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL)
return(NULL);
- idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
+ idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num);
if (idlist == NULL)
goto done;
#endif
snprintf(prop, 199, "/local/domain/%s/name", idlist[i]);
prop[199] = 0;
- tmp = xs_read(conn->xshandle, 0, prop, &len);
+ tmp = xs_read(priv->xshandle, 0, prop, &len);
if (tmp != NULL) {
found = !strcmp(name, tmp);
free(tmp);
break;
}
}
- path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
+ path = xs_get_domain_path(priv->xshandle, (unsigned int) id);
if (!found)
return(NULL);
char *vm, *str = NULL;
char query[200];
unsigned int len;
+ xenUnifiedPrivatePtr priv;
if (id < 0)
return(NULL);
-
- if (conn->xshandle == NULL)
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL)
return (NULL);
snprintf(query, 199, "/local/domain/%d/vm", id);
query[199] = 0;
- vm = xs_read(conn->xshandle, 0, &query[0], &len);
+ vm = xs_read(priv->xshandle, 0, &query[0], &len);
if (vm) {
snprintf(query, 199, "%s/image/ostype", vm);
- str = xs_read(conn->xshandle, 0, &query[0], &len);
+ str = xs_read(priv->xshandle, 0, &query[0], &len);
free(vm);
}
if (str == NULL)
char dir[80], path[128], **list = NULL, *val = NULL;
unsigned int maclen, len, i, num;
char *ret = NULL;
+ xenUnifiedPrivatePtr priv;
if (id < 0)
return(NULL);
- if (conn->xshandle == NULL)
+
+ priv = (xenUnifiedPrivatePtr) conn->privateData;
+ if (priv->xshandle == NULL)
return (NULL);
if (mac == NULL)
return (NULL);
return (NULL);
snprintf(dir, sizeof(dir), "/local/domain/0/backend/vif/%d", id);
- list = xs_directory(conn->xshandle, 0, dir, &num);
+ list = xs_directory(priv->xshandle, 0, dir, &num);
if (list == NULL)
return(NULL);
for (i = 0; i < num; i++) {
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "mac");
- val = xs_read(conn->xshandle, 0, path, &len);
+ val = xs_read(priv->xshandle, 0, path, &len);
if (val == NULL)
break;
if ((maclen != len) || memcmp(val, mac, len)) {
extern "C" {
#endif
-void xenStoreRegister (void);
+extern virDriver xenStoreDriver;
+int xenStoreInit (void);
+
int xenStoreOpen (virConnectPtr conn,
const char *name,
int flags);
#include <string.h>
#ifdef WITH_XEN
+#include "xen_unified.h"
#include "xm_internal.h"
#include "testutils.h"
#include "internal.h"
int ret = -1;
virConnectPtr conn;
int wrote = MAX_FILE;
+ void *old_priv;
+ struct _xenUnifiedPrivate priv;
conn = virConnectOpen("test:///default");
+ if (!conn) goto fail;
+ old_priv = conn->privateData;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
goto fail;
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
goto fail;
- /* Yes, a nasty hack, but this is only a test suite */
- conn->xendConfigVersion = xendConfigVersion;
+ /* Many puppies died to bring you this code. */
+ priv.xendConfigVersion = xendConfigVersion;
+ conn->privateData = &priv;
if (!(conf = xenXMParseXMLToConfig(conn, xmlPtr)))
goto fail;
if (conf)
virConfFree(conf);
- virConnectClose(conn);
+ if (conn) {
+ conn->privateData = old_priv;
+ virConnectClose(conn);
+ }
+
return ret;
}
virConfPtr conf = NULL;
int ret = -1;
virConnectPtr conn;
+ void *old_priv;
+ struct _xenUnifiedPrivate priv;
conn = virConnectOpen("test:///default");
+ if (!conn) goto fail;
+ old_priv = conn->privateData;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
goto fail;
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
goto fail;
- /* Yes, a nasty hack, but this is only a test suite */
- conn->xendConfigVersion = xendConfigVersion;
+ /* Many puppies died to bring you this code. */
+ priv.xendConfigVersion = xendConfigVersion;
+ conn->privateData = &priv;
if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr))))
goto fail;
if (gotxml)
free(gotxml);
- virConnectClose(conn);
+ if (conn) {
+ conn->privateData = old_priv;
+ virConnectClose(conn);
+ }
+
return ret;
}