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
This commit is contained in:
Richard W.M. Jones 2007-04-04 14:19:49 +00:00
parent ad8bef84d1
commit 18cd1a1e57
24 changed files with 2126 additions and 1331 deletions

View File

@ -1,3 +1,9 @@
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

View File

@ -25,6 +25,7 @@
#include "xen_internal.h"
#include "xend_internal.h"
#include "xs_internal.h"
#include "xen_unified.h"
static int fdServer = -1;
static int debug = 0;
@ -58,6 +59,23 @@ static int
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) {

View File

@ -21,6 +21,7 @@ libvirt_la_SOURCES = \
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 \

View File

@ -17,13 +17,9 @@ extern "C" {
* 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;
@ -32,10 +28,24 @@ typedef enum {
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 *
@ -44,7 +54,7 @@ typedef int
(*virDrvGetVersion) (virConnectPtr conn,
unsigned long *hvVer);
typedef int
(*virDrvGetMaxVcpus) (virConnectPtr conn);
(*virDrvGetMaxVcpus) (virConnectPtr conn, const char *type);
typedef int
(*virDrvNodeGetInfo) (virConnectPtr conn,
virNodeInfoPtr info);
@ -155,6 +165,12 @@ typedef virDriver *virDriverPtr;
*
* 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 */
@ -252,6 +268,10 @@ typedef virNetworkDriver *virNetworkDriverPtr;
*
* 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;

View File

@ -665,9 +665,10 @@ virGetConnect(void) {
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;

View File

@ -114,30 +114,19 @@ struct _virConnect {
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;
/* The underlying hypervisor driver and network driver. */
virDriverPtr driver;
virNetworkDriverPtr networkDriver;
/* 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 */
/* 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;
/* 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 */
/* Per-connection error. */
virError err; /* the last error */
virErrorFunc handler; /* associated handlet */
void *userData; /* the user data */

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@
#include "internal.h"
#include "driver.h"
#include "proxy_internal.h"
#include "xen_unified.h"
#define STANDALONE
@ -42,8 +43,8 @@ static int xenProxyDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
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 */
@ -89,14 +90,16 @@ static virDriver xenProxyDriver = {
};
/**
* xenProxyRegister:
* xenProxyInit:
*
* Registers the xenHypervisor driver
* Initialise the xen proxy driver.
*/
void xenProxyRegister(void)
int
xenProxyInit (void)
{
virRegisterDriver(&xenProxyDriver);
return 0;
}
/************************************************************************
* *
* Error handling *
@ -378,12 +381,29 @@ retry:
* 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
@ -392,9 +412,22 @@ xenProxyCommand(virConnectPtr conn, virProxyPacketPtr request,
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
@ -404,14 +437,14 @@ xenProxyCommand(virConnectPtr conn, virProxyPacketPtr request,
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);
@ -432,7 +465,7 @@ retry:
}
} 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);
@ -453,7 +486,7 @@ retry:
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))) {
@ -495,25 +528,26 @@ retry:
* 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;

View File

@ -84,10 +84,9 @@ struct _virProxyFullPacket {
};
typedef struct _virProxyFullPacket virProxyFullPacket;
typedef virProxyFullPacket *virProxyFullPacketPtr;
/*
* Functions callable from libvirt library
*/
void xenProxyRegister(void);
extern virDriver xenProxyDriver;
int xenProxyInit (void);
#ifdef __cplusplus
}

View File

@ -48,7 +48,20 @@
#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,
@ -209,7 +222,8 @@ qemuForkServer(void)
* 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;
@ -217,7 +231,7 @@ qemuOpenClientUNIX(virConnectPtr conn, const char *path, int autostart) {
retry:
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
return(-1);
return VIR_DRV_OPEN_ERROR;
}
/*
@ -242,12 +256,10 @@ qemuOpenClientUNIX(virConnectPtr conn, const char *path, int autostart) {
usleep(5000 * trials * trials);
goto retry;
}
return (-1);
return VIR_DRV_OPEN_ERROR;
}
conn->qemud_fd = fd;
return (0);
return fd;
}
@ -256,9 +268,10 @@ qemuOpenClientUNIX(virConnectPtr conn, const char *path, int autostart) {
* 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;
@ -270,7 +283,7 @@ static int qemuProcessRequest(virConnectPtr conn,
/* 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;
}
@ -280,7 +293,7 @@ static int qemuProcessRequest(virConnectPtr conn,
/* 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;
}
@ -308,7 +321,7 @@ static int qemuProcessRequest(virConnectPtr conn,
/* 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;
}
@ -333,17 +346,17 @@ static int qemuOpenConnection(virConnectPtr conn, xmlURIPtr uri, int readonly) {
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")) {
@ -351,14 +364,14 @@ static int qemuOpenConnection(virConnectPtr conn, xmlURIPtr uri, int readonly) {
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;
}
@ -373,42 +386,62 @@ static int qemuOpen(virConnectPtr conn,
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;
}
conn->qemud_fd = -1;
qemuOpenConnection(conn, uri, flags & VIR_DRV_OPEN_RO ? 1 : 0);
/* 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;
}
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;
}
@ -416,11 +449,12 @@ static int qemuClose (virConnectPtr conn) {
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;
}
@ -432,11 +466,12 @@ static int qemuGetVersion(virConnectPtr conn,
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;
}
@ -457,6 +492,7 @@ qemuGetCapabilities (virConnectPtr conn)
{
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.
@ -464,7 +500,7 @@ qemuGetCapabilities (virConnectPtr conn)
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;
}
@ -481,11 +517,12 @@ qemuGetCapabilities (virConnectPtr conn)
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;
}
@ -498,11 +535,12 @@ static int qemuListDomains(virConnectPtr conn,
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;
}
@ -524,6 +562,7 @@ qemuDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
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;
@ -534,7 +573,7 @@ qemuDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
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;
}
@ -554,12 +593,13 @@ static virDomainPtr qemuLookupDomainByID(virConnectPtr conn,
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;
}
@ -579,12 +619,13 @@ static virDomainPtr qemuLookupDomainByUUID(virConnectPtr conn,
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;
}
@ -604,6 +645,7 @@ static virDomainPtr qemuLookupDomainByName(virConnectPtr conn,
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;
@ -612,7 +654,7 @@ static virDomainPtr qemuLookupDomainByName(virConnectPtr conn,
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;
}
@ -627,12 +669,13 @@ static virDomainPtr qemuLookupDomainByName(virConnectPtr conn,
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;
}
@ -643,28 +686,30 @@ static int qemuShutdownDomain(virDomainPtr domain) {
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;
}
@ -674,12 +719,13 @@ static int qemuPauseDomain(virDomainPtr domain ATTRIBUTE_UNUSED) {
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;
}
@ -710,12 +756,13 @@ static int qemuGetDomainInfo(virDomainPtr domain,
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;
}
@ -735,11 +782,12 @@ static int qemuRestoreDomain(virConnectPtr conn ATTRIBUTE_UNUSED, const char *fi
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;
}
@ -751,11 +799,12 @@ static int qemuListDefinedDomains(virConnectPtr conn,
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;
}
@ -773,12 +822,13 @@ static int qemuListDefinedDomains(virConnectPtr conn,
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;
}
@ -791,6 +841,7 @@ static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) {
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;
@ -801,7 +852,7 @@ static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) {
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;
}
@ -819,12 +870,13 @@ static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) {
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;
}
@ -839,12 +891,13 @@ static int qemuUndefine(virDomainPtr dom) {
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;
}
@ -856,13 +909,14 @@ static int qemuDomainGetAutostart(virDomainPtr dom,
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;
}
@ -870,37 +924,62 @@ static int qemuDomainSetAutostart(virDomainPtr dom,
}
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 (conn->qemud_fd != -1)
if (!(netpriv = malloc(sizeof(struct _qemuNetworkPrivate)))) {
qemuError (conn, NULL, VIR_ERR_NO_MEMORY, __FUNCTION__);
return VIR_DRV_OPEN_ERROR;
}
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;
if (name)
uri = xmlParseURI(name);
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);
if (uri)
} 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);
return ret;
if (ret < 0) {
free(netpriv);
return ret;
} else {
netpriv->qemud_fd = ret;
netpriv->shared = 0;
conn->networkPrivateData = netpriv;
return 0;
}
}
}
static int
qemuNetworkClose (virConnectPtr conn)
{
qemuNetworkPrivatePtr netpriv = (qemuNetworkPrivatePtr) conn->networkPrivateData;
if (!netpriv->shared)
close(netpriv->qemud_fd);
free(netpriv);
conn->networkPrivateData = NULL;
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;
}
@ -912,11 +991,12 @@ static int qemuListNetworks(virConnectPtr conn,
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;
}
@ -934,11 +1014,12 @@ static int qemuListNetworks(virConnectPtr conn,
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;
}
@ -950,11 +1031,12 @@ static int qemuListDefinedNetworks(virConnectPtr conn,
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;
}
@ -974,12 +1056,13 @@ static virNetworkPtr qemuNetworkLookupByUUID(virConnectPtr conn,
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;
}
@ -997,6 +1080,7 @@ static virNetworkPtr qemuNetworkLookupByName(virConnectPtr conn,
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;
@ -1005,7 +1089,7 @@ static virNetworkPtr qemuNetworkLookupByName(virConnectPtr conn,
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;
}
@ -1022,6 +1106,7 @@ static virNetworkPtr qemuNetworkCreateXML(virConnectPtr conn,
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;
@ -1032,7 +1117,7 @@ static virNetworkPtr qemuNetworkCreateXML(virConnectPtr conn,
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;
}
@ -1052,6 +1137,7 @@ static virNetworkPtr qemuNetworkDefineXML(virConnectPtr conn,
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;
@ -1062,7 +1148,7 @@ static virNetworkPtr qemuNetworkDefineXML(virConnectPtr conn,
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;
}
@ -1079,12 +1165,13 @@ static virNetworkPtr qemuNetworkDefineXML(virConnectPtr conn,
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;
}
@ -1098,12 +1185,13 @@ static int qemuNetworkUndefine(virNetworkPtr network) {
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;
}
@ -1112,12 +1200,13 @@ static int qemuNetworkCreate(virNetworkPtr network) {
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;
}
@ -1126,12 +1215,13 @@ static int qemuNetworkDestroy(virNetworkPtr network) {
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;
}
@ -1142,12 +1232,13 @@ static char * qemuNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUS
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;
}
@ -1159,12 +1250,13 @@ static char * qemuNetworkGetBridgeName(virNetworkPtr network) {
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;
}
@ -1176,13 +1268,14 @@ static int qemuNetworkGetAutostart(virNetworkPtr network,
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;
}
@ -1237,7 +1330,7 @@ static virDriver qemuDriver = {
static virNetworkDriver qemuNetworkDriver = {
qemuNetworkOpen, /* open */
qemuClose, /* close */
qemuNetworkClose, /* close */
qemuNumOfNetworks, /* numOfNetworks */
qemuListNetworks, /* listNetworks */
qemuNumOfDefinedNetworks, /* numOfDefinedNetworks */
@ -1260,9 +1353,15 @@ static virNetworkDriver qemuNetworkDriver = {
*
* 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 */

View File

@ -30,7 +30,7 @@
extern "C" {
#endif
void qemuRegister(void);
int qemuRegister(void);
#ifdef __cplusplus
}

View File

@ -134,6 +134,12 @@ static virDriver testDriver = {
NULL, /* domainSetAutostart */
};
/* Per-connection private data. */
struct _testPrivate {
int handle;
};
typedef struct _testPrivate *testPrivatePtr;
typedef struct _testDev {
char name[20];
virDeviceMode mode;
@ -244,9 +250,10 @@ static const char *testRestartFlagToString(int flag) {
*
* Registers the test driver
*/
void testRegister(void)
int
testRegister(void)
{
virRegisterDriver(&testDriver);
return virRegisterDriver(&testDriver);
}
static int testLoadDomain(virConnectPtr conn,
@ -268,6 +275,7 @@ 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"));
@ -336,9 +344,6 @@ static int testLoadDomain(virConnectPtr conn,
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)) {
@ -386,7 +391,8 @@ static int testLoadDomain(virConnectPtr conn,
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) {
@ -479,13 +485,14 @@ static int testOpenDefault(virConnectPtr conn,
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));
@ -538,10 +545,11 @@ static int testOpenFromFile(virConnectPtr conn,
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,
@ -565,7 +573,7 @@ static int testOpenFromFile(virConnectPtr conn,
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));
@ -707,7 +715,7 @@ static int testOpenFromFile(virConnectPtr conn,
xmlFreeDoc(xml);
if (fd != -1)
close(fd);
return (-1);
return VIR_DRV_OPEN_ERROR;
}
static int getNextConnection(void) {
@ -732,7 +740,9 @@ 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)
@ -751,31 +761,39 @@ int testOpen(virConnectPtr conn,
{
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);
@ -787,16 +805,34 @@ int testOpen(virConnectPtr conn,
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,
@ -809,7 +845,8 @@ 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);
}
@ -854,7 +891,8 @@ testGetCapabilities (virConnectPtr conn)
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)
@ -871,6 +909,7 @@ testDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
testCon *con;
int domid, handle = -1, i;
virDomainPtr dom;
testPrivatePtr priv;
if (!VIR_IS_CONNECT(conn)) {
testError(conn, NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
@ -884,8 +923,10 @@ testDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
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"));
@ -914,7 +955,8 @@ testDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
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;
@ -942,7 +984,8 @@ virDomainPtr testLookupDomainByID(virConnectPtr conn,
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++) {
@ -966,7 +1009,8 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
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++) {
@ -991,7 +1035,8 @@ int testListDomains (virConnectPtr conn,
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++) {
@ -1007,6 +1052,8 @@ int testDestroyDomain (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,
@ -1018,7 +1065,9 @@ int testDestroyDomain (virDomainPtr domain)
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);
}
@ -1027,6 +1076,8 @@ int testResumeDomain (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,
@ -1038,7 +1089,9 @@ int testResumeDomain (virDomainPtr domain)
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);
}
@ -1047,6 +1100,8 @@ int testPauseDomain (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,
@ -1058,7 +1113,9 @@ int testPauseDomain (virDomainPtr domain)
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);
}
@ -1072,6 +1129,8 @@ int testShutdownDomain (virDomainPtr domain)
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,
@ -1083,7 +1142,9 @@ int testShutdownDomain (virDomainPtr domain)
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"));
@ -1103,6 +1164,8 @@ int testRebootDomain (virDomainPtr domain, virDomainRestart action)
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,
@ -1114,7 +1177,8 @@ int testRebootDomain (virDomainPtr domain, virDomainRestart action)
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"));
@ -1158,6 +1222,8 @@ int testGetDomainInfo (virDomainPtr domain,
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,
@ -1165,7 +1231,8 @@ int testGetDomainInfo (virDomainPtr domain,
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"));
@ -1189,6 +1256,8 @@ char *testGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
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,
@ -1196,7 +1265,8 @@ unsigned long testGetMaxMemory(virDomainPtr domain) {
return (-1);
}
con = &node->connections[domain->conn->handle];
priv = (testPrivatePtr) domain->conn->privateData;
con = &node->connections[priv->handle];
return con->domains[domidx].info.maxMem;
}
@ -1205,6 +1275,8 @@ int testSetMaxMemory(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,
@ -1216,7 +1288,8 @@ int testSetMaxMemory(virDomainPtr domain,
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);
@ -1227,6 +1300,8 @@ int testSetMemory(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,
@ -1238,7 +1313,8 @@ int testSetMemory(virDomainPtr domain,
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__);
@ -1253,6 +1329,8 @@ int testSetVcpus(virDomainPtr domain,
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,
@ -1264,7 +1342,8 @@ int testSetVcpus(virDomainPtr domain,
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) {
@ -1283,6 +1362,8 @@ char * testDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED)
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,
@ -1290,7 +1371,8 @@ char * testDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED)
return (NULL);
}
con = &node->connections[domain->conn->handle];
priv = (testPrivatePtr) domain->conn->privateData;
con = &node->connections[priv->handle];
if (!(buf = virBufferNew(4000))) {
return (NULL);
@ -1323,7 +1405,8 @@ char * testDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED)
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)
@ -1336,7 +1419,8 @@ int testNumOfDefinedDomains(virConnectPtr conn) {
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++) {
@ -1375,6 +1459,8 @@ virDomainPtr testDomainDefineXML(virConnectPtr conn,
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,
@ -1382,7 +1468,8 @@ int testDomainCreate(virDomainPtr domain) {
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,
@ -1399,6 +1486,8 @@ int testDomainCreate(virDomainPtr domain) {
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,
@ -1406,7 +1495,8 @@ int testDomainUndefine(virDomainPtr domain) {
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,

View File

@ -30,7 +30,7 @@
extern "C" {
#endif
void testRegister(void);
int testRegister(void);
#ifdef __cplusplus
}

View File

@ -426,6 +426,7 @@ typedef struct xen_op_v2_dom xen_op_v2_dom;
#include "internal.h"
#include "driver.h"
#include "xen_unified.h"
#include "xen_internal.h"
#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd"
@ -436,8 +437,8 @@ static unsigned long xenHypervisorGetMaxMemory(virDomainPtr domain);
#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 +
@ -446,7 +447,7 @@ static virDriver xenHypervisorDriver = {
xenHypervisorClose, /* close */
xenHypervisorGetType, /* type */
xenHypervisorGetVersion, /* version */
xenHypervisorNumOfMaxVcpus, /* getMaxVcpus */
xenHypervisorGetMaxVcpus, /* getMaxVcpus */
NULL, /* nodeGetInfo */
xenHypervisorGetCapabilities, /* getCapabilities */
xenHypervisorListDomains, /* listDomains */
@ -1176,7 +1177,7 @@ virXen_getvcpusinfo(int handle, int id, unsigned int vcpu, virVcpuInfoPtr ipt,
* 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;
@ -1187,7 +1188,7 @@ xenHypervisorInit(void)
if (initialized) {
if (hypervisor_version == -1)
return(-1);
return (-1);
return(0);
}
initialized = 1;
@ -1232,7 +1233,7 @@ xenHypervisorInit(void)
ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
if (ret < 0) {
hypervisor_version = -1;
return (-1);
return(-1);
}
fd = ret;
@ -1295,7 +1296,7 @@ xenHypervisorInit(void)
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);
}
@ -1357,21 +1358,6 @@ xenHypervisorInit(void)
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
@ -1383,17 +1369,17 @@ void xenHypervisorRegister(void)
* 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 (xenHypervisorInit() == -1)
return -1;
if ((name != NULL) && (strcasecmp(name, "xen")))
return(-1);
conn->handle = -1;
priv->handle = -1;
ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
if (ret < 0) {
@ -1401,7 +1387,8 @@ xenHypervisorOpen(virConnectPtr conn, const char *name, int flags)
virXenError(VIR_ERR_NO_XEN, XEN_HYPERVISOR_SOCKET, 0);
return (-1);
}
conn->handle = ret;
priv->handle = ret;
return(0);
}
@ -1418,13 +1405,20 @@ int
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);
}
@ -1463,7 +1457,12 @@ xenHypervisorGetType(virConnectPtr conn)
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);
@ -1778,8 +1777,12 @@ xenHypervisorNumOfDomains(virConnectPtr conn)
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:
@ -1791,7 +1794,7 @@ xenHypervisorNumOfDomains(virConnectPtr conn)
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);
@ -1824,8 +1827,13 @@ xenHypervisorListDomains(virConnectPtr conn, int *ids, int maxids)
{
xen_getdomaininfolist dominfos;
int ret, nbids, i;
xenUnifiedPrivatePtr priv;
if ((conn == NULL) || (conn->handle < 0) ||
if (conn == NULL)
return -1;
priv = (xenUnifiedPrivatePtr) conn->privateData;
if (priv->handle < 0 ||
(ids == NULL) || (maxids < 1))
return (-1);
@ -1838,7 +1846,7 @@ xenHypervisorListDomains(virConnectPtr conn, int *ids, int maxids)
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);
@ -1860,14 +1868,20 @@ xenHypervisorListDomains(virConnectPtr conn, int *ids, int maxids)
}
/**
* 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;
@ -1886,11 +1900,16 @@ xenHypervisorNumOfMaxVcpus(virConnectPtr conn)
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;
@ -1900,7 +1919,7 @@ xenHypervisorGetDomMaxMemory(virConnectPtr conn, int id)
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);
@ -1922,8 +1941,13 @@ xenHypervisorGetDomMaxMemory(virConnectPtr conn, int id)
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));
@ -1943,6 +1967,7 @@ xenHypervisorGetMaxMemory(virDomainPtr domain)
int
xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info)
{
xenUnifiedPrivatePtr priv;
xen_getdomaininfo dominfo;
int ret;
uint32_t domain_flags, domain_state, domain_shutdown_cause;
@ -1953,13 +1978,17 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info)
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);
@ -2020,8 +2049,13 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info)
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);
@ -2042,12 +2076,16 @@ int
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);
@ -2065,12 +2103,16 @@ int
xenHypervisorResumeDomain(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_unpausedomain(domain->conn->handle, domain->id);
ret = virXen_unpausedomain(priv->handle, domain->id);
if (ret < 0)
return (-1);
return (0);
@ -2088,12 +2130,16 @@ int
xenHypervisorDestroyDomain(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_destroydomain(domain->conn->handle, domain->id);
ret = virXen_destroydomain(priv->handle, domain->id);
if (ret < 0)
return (-1);
return (0);
@ -2112,12 +2158,16 @@ int
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);
@ -2139,13 +2189,16 @@ int
xenHypervisorSetVcpus(virDomainPtr domain, unsigned int nvcpus)
{
int ret;
xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) ||
(domain->conn->handle < 0) || (domain->id < 0) ||
(nvcpus < 1))
if (domain == NULL || domain->conn == NULL)
return -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);
@ -2168,13 +2221,17 @@ xenHypervisorPinVcpu(virDomainPtr domain, unsigned int vcpu,
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);
@ -2208,12 +2265,15 @@ xenHypervisorGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
{
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);
@ -2222,7 +2282,7 @@ xenHypervisorGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
/* 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))
@ -2235,14 +2295,14 @@ xenHypervisorGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
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);
@ -2266,9 +2326,13 @@ xenHypervisorGetVcpuMax(virDomainPtr domain)
xen_getdomaininfo dominfo;
int ret;
int maxcpu;
xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) ||
(domain->conn->handle < 0))
if (domain == NULL || domain->conn == NULL)
return -1;
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
if (priv->handle < 0)
return (-1);
/* inactive domain */
@ -2276,7 +2340,7 @@ xenHypervisorGetVcpuMax(virDomainPtr 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))

View File

@ -15,7 +15,11 @@
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);
@ -36,7 +40,7 @@ int xenHypervisorNumOfDomains (virConnectPtr conn);
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);

778
src/xen_unified.c Normal file
View File

@ -0,0 +1,778 @@
/*
* 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 */

53
src/xen_unified.h Normal file
View File

@ -0,0 +1,53 @@
/*
* 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__ */

View File

@ -34,6 +34,7 @@
#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 */
@ -60,8 +61,8 @@ static int xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename,
#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 +
@ -109,13 +110,14 @@ static virDriver xenDaemonDriver = {
};
/**
* xenDaemonRegister:
* xenDaemonInit:
*
* Registers the xenDaemon driver
* Initialise the xenDaemon driver.
*/
void xenDaemonRegister(void)
int
xenDaemonInit (void)
{
virRegisterDriver(&xenDaemonDriver);
return 0;
}
#endif /* !PROXY */
@ -210,8 +212,9 @@ do_connect(virConnectPtr xend)
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");
@ -225,7 +228,7 @@ do_connect(virConnectPtr xend)
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;
@ -830,21 +833,22 @@ int
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);
}
@ -866,10 +870,13 @@ xenDaemonOpen_tcp(virConnectPtr conn, const char *host, int port)
{
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) {
@ -881,13 +888,13 @@ xenDaemonOpen_tcp(virConnectPtr conn, const char *host, int port)
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);
}
@ -1121,12 +1128,15 @@ static int
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);
@ -1134,14 +1144,14 @@ xend_detect_config_version(virConnectPtr conn) {
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;
}
/**
@ -1804,10 +1814,13 @@ sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
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;
@ -1824,7 +1837,7 @@ sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
/* 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)
@ -1873,79 +1886,85 @@ xenDaemonOpen(virConnectPtr conn, const char *name, int flags)
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);
@ -1961,12 +1980,12 @@ failed:
* 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;
}
/**
@ -2177,13 +2196,17 @@ xenDaemonDomainGetMaxMemory(virDomainPtr domain)
{
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 ? */
@ -2213,13 +2236,17 @@ int
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);
@ -2247,13 +2274,17 @@ int
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);
@ -2271,12 +2302,15 @@ xenDaemonDomainDumpXMLByID(virConnectPtr conn, int domid)
{
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);
@ -2287,12 +2321,15 @@ xenDaemonDomainDumpXMLByName(virConnectPtr conn, const char *name)
{
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);
@ -2312,12 +2349,16 @@ xenDaemonDomainDumpXMLByName(virConnectPtr conn, const char *name)
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);
@ -2341,6 +2382,7 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
{
struct sexpr *root;
int ret;
xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
(info == NULL)) {
@ -2348,7 +2390,10 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
__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);
@ -2625,6 +2670,7 @@ int
xenDaemonDomainSetVcpus(virDomainPtr domain, unsigned int vcpus)
{
char buf[VIR_UUID_BUFLEN];
xenUnifiedPrivatePtr priv;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
|| (vcpus < 1)) {
@ -2632,7 +2678,10 @@ xenDaemonDomainSetVcpus(virDomainPtr domain, unsigned int vcpus)
__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);
@ -2790,8 +2839,10 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
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);
@ -2871,6 +2922,7 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
char *sexpr;
char *name = NULL;
virDomainPtr dom = NULL;
xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@ -2881,7 +2933,9 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
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)
@ -2939,6 +2993,7 @@ xenDaemonAttachDevice(virDomainPtr domain, char *xml)
{
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,
@ -2946,9 +3001,11 @@ xenDaemonAttachDevice(virDomainPtr domain, char *xml)
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)) {
@ -2993,6 +3050,7 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
char *sexpr;
char *name = NULL;
virDomainPtr dom;
xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@ -3002,10 +3060,13 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
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)
@ -3034,25 +3095,37 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
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);
@ -3072,8 +3145,9 @@ xenDaemonNumOfDefinedDomains(virConnectPtr conn)
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");
@ -3099,8 +3173,9 @@ int xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxn
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))

View File

@ -177,8 +177,10 @@ char *xenDaemonDomainDumpXMLByName(virConnectPtr xend,
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);

View File

@ -36,6 +36,7 @@
#include <libxml/xpath.h>
#include "xen_unified.h"
#include "xm_internal.h"
#include "xend_internal.h"
#include "conf.h"
@ -66,8 +67,8 @@ static time_t lastRefresh = 0;
#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 +
@ -127,11 +128,11 @@ xenXMError(virConnectPtr conn, virErrorNumber error, const char *info)
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()) ||
@ -145,6 +146,8 @@ void xenXMRegister(void)
} else {
strcpy(configDir, XM_CONFIG_DIR);
}
return 0;
}
@ -472,12 +475,10 @@ static int xenXMConfigCacheRefresh(void) {
* 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)
@ -584,6 +585,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
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);
@ -798,7 +800,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
}
}
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);
@ -884,7 +886,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
}
/* 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)
@ -1282,6 +1284,7 @@ int xenXMDomainCreate(virDomainPtr domain) {
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,
@ -1297,7 +1300,9 @@ int xenXMDomainCreate(virDomainPtr domain) {
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);
}
@ -1714,6 +1719,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
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 |
@ -1778,6 +1784,8 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
hvm = 1;
xmlXPathFreeObject(obj);
priv = (xenUnifiedPrivatePtr) conn->privateData;
if (hvm) {
const char *boot = "c";
if (xenXMConfigSetString(conf, "builder", "hvm") < 0)
@ -1813,7 +1821,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
"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;
@ -1854,7 +1862,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
}
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;
@ -1977,7 +1985,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
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)))) {

View File

@ -27,12 +27,15 @@
#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);

View File

@ -27,6 +27,7 @@
#include "internal.h"
#include "driver.h"
#include "xen_unified.h"
#include "xs_internal.h"
#include "xen_internal.h" /* for xenHypervisorCheckID */
@ -35,8 +36,8 @@
#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 +
@ -84,13 +85,14 @@ static virDriver xenStoreDriver = {
};
/**
* xenStoreRegister:
* xenStoreInit:
*
* Registers the xenStore driver
* Initialisation.
*/
void xenStoreRegister(void)
int
xenStoreInit ()
{
virRegisterDriver(&xenStoreDriver);
return 0;
}
#endif /* ! PROXY */
@ -135,11 +137,16 @@ static char **
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 */
@ -158,14 +165,19 @@ virDomainDoStoreQuery(virConnectPtr conn, int domid, const char *path)
{
char s[256];
unsigned int len = 0;
xenUnifiedPrivatePtr priv;
if (!conn || conn->xshandle == NULL)
if (!conn)
return 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
@ -184,12 +196,14 @@ virDomainDoStoreWrite(virDomainPtr domain, const char *path,
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);
@ -197,7 +211,7 @@ virDomainDoStoreWrite(virDomainPtr domain, const char *path,
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);
@ -217,16 +231,19 @@ virDomainGetVM(virDomainPtr domain)
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);
}
@ -248,16 +265,19 @@ virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name)
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);
}
@ -304,21 +324,21 @@ virConnectCheckStoreID(virConnectPtr conn, int id)
* 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"));
@ -338,14 +358,18 @@ xenStoreOpen(virConnectPtr conn, const char *name, int flags)
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);
}
@ -365,6 +389,7 @@ xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
char *tmp, **tmp2;
unsigned int nb_vcpus;
char request[200];
xenUnifiedPrivatePtr priv;
if (!VIR_IS_CONNECTED_DOMAIN(domain))
return (-1);
@ -374,8 +399,11 @@ xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
__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);
@ -490,12 +518,19 @@ xenStoreNumOfDomains(virConnectPtr conn)
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;
@ -520,15 +555,18 @@ xenStoreListDomains(virConnectPtr conn, int *ids, int maxids)
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);
@ -566,15 +604,18 @@ xenStoreDomainLookupByName(virConnectPtr conn, const char *name)
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;
@ -589,7 +630,7 @@ xenStoreDomainLookupByName(virConnectPtr conn, const char *name)
#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);
@ -597,7 +638,7 @@ xenStoreDomainLookupByName(virConnectPtr conn, const char *name)
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);
@ -764,22 +805,23 @@ xenStoreDomainGetOSTypeID(virConnectPtr conn, int id) {
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)
@ -807,10 +849,13 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) {
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);
@ -819,12 +864,12 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) {
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)) {

View File

@ -15,7 +15,9 @@
extern "C" {
#endif
void xenStoreRegister (void);
extern virDriver xenStoreDriver;
int xenStoreInit (void);
int xenStoreOpen (virConnectPtr conn,
const char *name,
int flags);

View File

@ -25,6 +25,7 @@
#include <string.h>
#ifdef WITH_XEN
#include "xen_unified.h"
#include "xm_internal.h"
#include "testutils.h"
#include "internal.h"
@ -45,8 +46,12 @@ static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfi
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;
@ -54,8 +59,9 @@ static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfi
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;
@ -77,7 +83,11 @@ static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfi
if (conf)
virConfFree(conf);
virConnectClose(conn);
if (conn) {
conn->privateData = old_priv;
virConnectClose(conn);
}
return ret;
}
@ -90,8 +100,12 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml, int xendConf
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;
@ -99,8 +113,9 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml, int xendConf
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;
@ -123,7 +138,11 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml, int xendConf
if (gotxml)
free(gotxml);
virConnectClose(conn);
if (conn) {
conn->privateData = old_priv;
virConnectClose(conn);
}
return ret;
}