2005-11-02 12:50:21 +00:00
|
|
|
/*
|
2006-02-09 17:45:11 +00:00
|
|
|
* libvirt.c: Main interfaces for the libvirt library to handle virtualization
|
2005-11-02 12:50:21 +00:00
|
|
|
* domains from a process running in domain 0
|
|
|
|
*
|
2006-02-09 17:45:11 +00:00
|
|
|
* Copyright (C) 2005,2006 Red Hat, Inc.
|
2005-11-02 12:50:21 +00:00
|
|
|
*
|
|
|
|
* See COPYING.LIB for the License of this software
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2006-06-26 15:02:18 +00:00
|
|
|
#include "libvirt/libvirt.h"
|
2005-11-02 12:50:21 +00:00
|
|
|
|
2005-11-02 13:19:10 +00:00
|
|
|
#include <stdio.h>
|
2005-11-30 13:20:53 +00:00
|
|
|
#include <stdlib.h>
|
2005-12-06 13:47:40 +00:00
|
|
|
#include <string.h>
|
2006-01-18 10:37:08 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-04-28 18:29:26 +00:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/xpath.h>
|
|
|
|
|
2005-11-30 13:20:53 +00:00
|
|
|
#include <xs.h>
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2005-11-02 12:50:21 +00:00
|
|
|
#include "internal.h"
|
2006-03-20 17:49:28 +00:00
|
|
|
#include "driver.h"
|
2006-01-23 22:55:41 +00:00
|
|
|
#include "xen_internal.h"
|
2006-01-17 16:56:17 +00:00
|
|
|
#include "xend_internal.h"
|
2006-03-23 15:42:10 +00:00
|
|
|
#include "xs_internal.h"
|
2006-11-16 19:06:13 +00:00
|
|
|
#include "xm_internal.h"
|
2006-06-29 22:12:47 +00:00
|
|
|
#include "proxy_internal.h"
|
2006-02-16 22:50:52 +00:00
|
|
|
#include "xml.h"
|
2006-06-06 03:32:51 +00:00
|
|
|
#include "test.h"
|
2007-02-14 01:40:09 +00:00
|
|
|
#include "qemu_internal.h"
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2005-11-02 12:50:21 +00:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* - use lock to protect against concurrent accesses ?
|
|
|
|
* - use reference counting to garantee coherent pointer state ?
|
2005-11-10 16:12:31 +00:00
|
|
|
* - memory wrappers for malloc/free ?
|
2005-11-02 12:50:21 +00:00
|
|
|
*/
|
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
static virDriverPtr virDriverTab[MAX_DRIVERS];
|
2007-02-14 15:37:18 +00:00
|
|
|
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
|
2006-03-27 15:24:36 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInitialize:
|
|
|
|
*
|
|
|
|
* Initialize the library. It's better to call this routine at startup
|
|
|
|
* in multithreaded applications to avoid potential race when initializing
|
|
|
|
* the library.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virInitialize(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (initialized)
|
|
|
|
return(0);
|
2006-03-28 14:41:04 +00:00
|
|
|
initialized = 1;
|
2006-03-27 15:24:36 +00:00
|
|
|
|
2006-09-21 15:24:37 +00:00
|
|
|
if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR))
|
|
|
|
return (-1);
|
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
/*
|
|
|
|
* should not be needed but...
|
|
|
|
*/
|
2007-02-14 15:37:18 +00:00
|
|
|
for (i = 0;i < MAX_DRIVERS;i++) {
|
2006-03-27 15:24:36 +00:00
|
|
|
virDriverTab[i] = NULL;
|
2007-02-14 15:37:18 +00:00
|
|
|
virNetworkDriverTab[i] = NULL;
|
|
|
|
}
|
2006-03-27 15:24:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the order is important the first ones have a higher priority
|
|
|
|
*/
|
|
|
|
xenHypervisorRegister();
|
2006-06-29 22:12:47 +00:00
|
|
|
xenProxyRegister();
|
2006-03-27 15:24:36 +00:00
|
|
|
xenDaemonRegister();
|
|
|
|
xenStoreRegister();
|
2006-11-16 19:06:13 +00:00
|
|
|
xenXMRegister();
|
2006-06-06 03:32:51 +00:00
|
|
|
testRegister();
|
2007-02-14 01:40:09 +00:00
|
|
|
qemuRegister();
|
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
/**
|
|
|
|
* virLibConnError:
|
|
|
|
* @conn: the connection if available
|
|
|
|
* @error: the error noumber
|
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the connection level
|
|
|
|
*/
|
|
|
|
static void
|
2006-03-15 12:13:25 +00:00
|
|
|
virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info)
|
|
|
|
{
|
2006-02-27 16:27:18 +00:00
|
|
|
const char *errmsg;
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (error == VIR_ERR_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
errmsg = __virErrorMsg(error, info);
|
Tue Feb 14 15:37:17 EST 2007 Mark McLoughlin <markmc@redhat.com>
Note: potential ABI break here, but people should
only really be using virError structs returned from
libvirt itself.
* include/libvirt/virterror.h: add virNetwork
to virError
* src/internal.h, src/virterror.c: add network param
to __virRaiseError()
* src/conf.c, src/hash.c, src/libvirt.c, src/proxy_internal.c,
src/qemu_internal.c, src/sexpr.c, src/test.c, src/xen_internal.c,
src/xend_internal.c, src/xm_internal.c, src/xml.c, src/xmlrpc.c,
src/xs_internal.c: update.
2007-02-14 15:40:53 +00:00
|
|
|
__virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR,
|
2006-02-27 16:27:18 +00:00
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLibConnError:
|
|
|
|
* @conn: the connection if available
|
|
|
|
* @error: the error noumber
|
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the connection level
|
|
|
|
*/
|
|
|
|
static void
|
2006-03-15 12:13:25 +00:00
|
|
|
virLibDomainError(virDomainPtr domain, virErrorNumber error,
|
|
|
|
const char *info)
|
|
|
|
{
|
2006-02-27 16:27:18 +00:00
|
|
|
virConnectPtr conn = NULL;
|
|
|
|
const char *errmsg;
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (error == VIR_ERR_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
errmsg = __virErrorMsg(error, info);
|
|
|
|
if (error != VIR_ERR_INVALID_DOMAIN) {
|
|
|
|
conn = domain->conn;
|
|
|
|
}
|
Tue Feb 14 15:37:17 EST 2007 Mark McLoughlin <markmc@redhat.com>
Note: potential ABI break here, but people should
only really be using virError structs returned from
libvirt itself.
* include/libvirt/virterror.h: add virNetwork
to virError
* src/internal.h, src/virterror.c: add network param
to __virRaiseError()
* src/conf.c, src/hash.c, src/libvirt.c, src/proxy_internal.c,
src/qemu_internal.c, src/sexpr.c, src/test.c, src/xen_internal.c,
src/xend_internal.c, src/xm_internal.c, src/xml.c, src/xmlrpc.c,
src/xs_internal.c: update.
2007-02-14 15:40:53 +00:00
|
|
|
__virRaiseError(conn, domain, NULL, VIR_FROM_DOM, error, VIR_ERR_ERROR,
|
2006-02-27 16:27:18 +00:00
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
|
|
|
}
|
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
/**
|
2007-02-14 15:37:18 +00:00
|
|
|
* virLibNetworkError:
|
|
|
|
* @conn: the connection if available
|
|
|
|
* @error: the error noumber
|
|
|
|
* @info: extra information string
|
2006-03-27 15:24:36 +00:00
|
|
|
*
|
2007-02-14 15:37:18 +00:00
|
|
|
* Handle an error at the connection level
|
2006-03-27 15:24:36 +00:00
|
|
|
*/
|
2007-02-14 15:37:18 +00:00
|
|
|
static void
|
|
|
|
virLibNetworkError(virNetworkPtr network, virErrorNumber error,
|
|
|
|
const char *info)
|
|
|
|
{
|
|
|
|
virConnectPtr conn = NULL;
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
|
|
if (error == VIR_ERR_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
errmsg = __virErrorMsg(error, info);
|
|
|
|
if (error != VIR_ERR_INVALID_NETWORK) {
|
|
|
|
conn = network->conn;
|
|
|
|
}
|
Tue Feb 14 15:37:17 EST 2007 Mark McLoughlin <markmc@redhat.com>
Note: potential ABI break here, but people should
only really be using virError structs returned from
libvirt itself.
* include/libvirt/virterror.h: add virNetwork
to virError
* src/internal.h, src/virterror.c: add network param
to __virRaiseError()
* src/conf.c, src/hash.c, src/libvirt.c, src/proxy_internal.c,
src/qemu_internal.c, src/sexpr.c, src/test.c, src/xen_internal.c,
src/xend_internal.c, src/xm_internal.c, src/xml.c, src/xmlrpc.c,
src/xs_internal.c: update.
2007-02-14 15:40:53 +00:00
|
|
|
__virRaiseError(conn, NULL, network, VIR_FROM_NET, error, VIR_ERR_ERROR,
|
2007-02-14 15:37:18 +00:00
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_virRegisterDriver(void *driver, int isNetwork)
|
2006-03-27 15:24:36 +00:00
|
|
|
{
|
2007-02-14 15:37:18 +00:00
|
|
|
void **drivers;
|
2006-03-27 15:24:36 +00:00
|
|
|
int i;
|
|
|
|
|
2006-03-28 14:41:04 +00:00
|
|
|
if (!initialized)
|
2006-09-21 15:24:37 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
2006-03-28 14:41:04 +00:00
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
drivers = isNetwork ? (void **) virNetworkDriverTab : (void **) virDriverTab;
|
2006-03-27 15:24:36 +00:00
|
|
|
for (i = 0;i < MAX_DRIVERS;i++) {
|
2007-02-14 15:37:18 +00:00
|
|
|
if (drivers[i] == driver)
|
2006-03-27 15:24:36 +00:00
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
for (i = 0;i < MAX_DRIVERS;i++) {
|
2007-02-14 15:37:18 +00:00
|
|
|
if (drivers[i] == NULL) {
|
|
|
|
drivers[i] = driver;
|
2006-03-27 15:24:36 +00:00
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
/**
|
|
|
|
* virRegisterNetworkDriver:
|
|
|
|
* @driver: pointer to a network driver block
|
|
|
|
*
|
|
|
|
* Register a network virtualization driver
|
|
|
|
*
|
|
|
|
* Returns the driver priority or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virRegisterNetworkDriver(virNetworkDriverPtr driver)
|
|
|
|
{
|
|
|
|
return _virRegisterDriver(driver, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virRegisterDriver:
|
|
|
|
* @driver: pointer to a driver block
|
|
|
|
*
|
|
|
|
* Register a virtualization driver
|
|
|
|
*
|
|
|
|
* Returns the driver priority or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virRegisterDriver(virDriverPtr driver)
|
|
|
|
{
|
|
|
|
return _virRegisterDriver(driver, 0);
|
|
|
|
}
|
|
|
|
|
2005-12-08 15:08:46 +00:00
|
|
|
/**
|
|
|
|
* virGetVersion:
|
|
|
|
* @libVer: return value for the library version (OUT)
|
2006-06-13 16:31:44 +00:00
|
|
|
* @type: the type of connection/driver looked at
|
2005-12-08 15:08:46 +00:00
|
|
|
* @typeVer: return value for the version of the hypervisor (OUT)
|
|
|
|
*
|
|
|
|
* Provides two information back, @libVer is the version of the library
|
|
|
|
* while @typeVer will be the version of the hypervisor type @type against
|
|
|
|
* which the library was compiled. If @type is NULL, "Xen" is assumed, if
|
|
|
|
* @type is unknown or not availble, an error code will be returned and
|
|
|
|
* @typeVer will be 0.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of failure, 0 otherwise, and values for @libVer and
|
|
|
|
* @typeVer have the format major * 1,000,000 + minor * 1,000 + release.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virGetVersion(unsigned long *libVer, const char *type,
|
|
|
|
unsigned long *typeVer)
|
|
|
|
{
|
2006-06-13 16:31:44 +00:00
|
|
|
int i;
|
|
|
|
|
2006-03-28 14:41:04 +00:00
|
|
|
if (!initialized)
|
2006-09-21 15:24:37 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
2006-03-28 14:41:04 +00:00
|
|
|
|
2005-12-08 15:08:46 +00:00
|
|
|
if (libVer == NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2005-12-08 15:08:46 +00:00
|
|
|
*libVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
|
|
|
|
if (typeVer != NULL) {
|
2006-06-13 16:31:44 +00:00
|
|
|
if (type == NULL)
|
|
|
|
type = "Xen";
|
|
|
|
for (i = 0;i < MAX_DRIVERS;i++) {
|
|
|
|
if ((virDriverTab[i] != NULL) &&
|
|
|
|
(!strcmp(virDriverTab[i]->name, type))) {
|
|
|
|
*typeVer = virDriverTab[i]->ver;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= MAX_DRIVERS) {
|
2006-03-15 12:13:25 +00:00
|
|
|
*typeVer = 0;
|
2006-06-13 16:31:44 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_NO_SUPPORT, type);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
2005-12-08 15:08:46 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 12:50:21 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virConnectOpen:
|
2005-11-02 12:50:21 +00:00
|
|
|
* @name: optional argument currently unused, pass NULL
|
|
|
|
*
|
|
|
|
* This function should be called first to get a connection to the
|
2005-11-23 07:47:13 +00:00
|
|
|
* Hypervisor and xen store
|
2005-11-02 12:50:21 +00:00
|
|
|
*
|
|
|
|
* Returns a pointer to the hypervisor connection or NULL in case of error
|
|
|
|
*/
|
2005-12-05 11:16:07 +00:00
|
|
|
virConnectPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectOpen(const char *name)
|
|
|
|
{
|
2006-06-13 18:29:42 +00:00
|
|
|
int i, res, for_xen = 0;
|
2005-12-05 11:16:07 +00:00
|
|
|
virConnectPtr ret = NULL;
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2006-03-28 14:41:04 +00:00
|
|
|
if (!initialized)
|
2006-09-21 15:24:37 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return NULL;
|
2006-03-28 14:41:04 +00:00
|
|
|
|
2006-06-13 18:29:42 +00:00
|
|
|
if (name == NULL) {
|
|
|
|
name = "Xen";
|
|
|
|
for_xen = 1;
|
2006-06-14 13:03:04 +00:00
|
|
|
} else if (!strncasecmp(name, "xen", 3)) {
|
2006-06-13 18:29:42 +00:00
|
|
|
for_xen = 1;
|
|
|
|
}
|
|
|
|
|
2006-04-09 13:11:22 +00:00
|
|
|
ret = virGetConnect();
|
2006-03-20 17:49:28 +00:00
|
|
|
if (ret == NULL) {
|
2006-09-21 15:24:37 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
|
2006-03-20 17:49:28 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2006-03-29 12:46:03 +00:00
|
|
|
for (i = 0;i < MAX_DRIVERS;i++) {
|
|
|
|
if ((virDriverTab[i] != NULL) && (virDriverTab[i]->open != NULL)) {
|
2006-08-16 16:29:46 +00:00
|
|
|
res = virDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET);
|
2006-03-29 12:46:03 +00:00
|
|
|
/*
|
|
|
|
* For a default connect to Xen make sure we manage to contact
|
|
|
|
* all related drivers.
|
|
|
|
*/
|
2006-06-13 18:29:42 +00:00
|
|
|
if ((res < 0) && (for_xen) &&
|
2006-06-29 22:12:47 +00:00
|
|
|
(!strncasecmp(virDriverTab[i]->name, "xen", 3)) &&
|
|
|
|
(virDriverTab[i]->no != VIR_DRV_XEN_PROXY))
|
2006-03-29 12:46:03 +00:00
|
|
|
goto failed;
|
|
|
|
if (res == 0)
|
|
|
|
ret->drivers[ret->nb_drivers++] = virDriverTab[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
for (i = 0;i < MAX_DRIVERS;i++) {
|
|
|
|
if ((virNetworkDriverTab[i] != NULL) && (virNetworkDriverTab[i]->open != NULL) &&
|
|
|
|
(res = virNetworkDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET)) == 0) {
|
|
|
|
ret->networkDrivers[ret->nb_network_drivers++] = virNetworkDriverTab[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret->nb_drivers == 0 || ret->nb_network_drivers == 0) {
|
2006-03-29 12:46:03 +00:00
|
|
|
/* we failed to find an adequate driver */
|
|
|
|
virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
|
|
|
|
goto failed;
|
|
|
|
}
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
return (ret);
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
failed:
|
|
|
|
if (ret != NULL) {
|
2006-03-29 12:46:03 +00:00
|
|
|
for (i = 0;i < ret->nb_drivers;i++) {
|
|
|
|
if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
|
|
|
|
ret->drivers[i]->close(ret);
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
for (i = 0;i < ret->nb_network_drivers;i++) {
|
|
|
|
if ((ret->networkDrivers[i] != NULL) && (ret->networkDrivers[i]->close != NULL))
|
|
|
|
ret->networkDrivers[i]->close(ret);
|
|
|
|
}
|
2006-04-09 13:11:22 +00:00
|
|
|
virFreeConnect(ret);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2005-12-01 16:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virConnectOpenReadOnly:
|
2005-12-01 16:35:42 +00:00
|
|
|
* @name: optional argument currently unused, pass NULL
|
|
|
|
*
|
2006-01-19 10:23:15 +00:00
|
|
|
* This function should be called first to get a restricted connection to the
|
|
|
|
* libbrary functionalities. The set of APIs usable are then restricted
|
|
|
|
* on the available methods to control the domains.
|
2005-12-01 16:35:42 +00:00
|
|
|
*
|
|
|
|
* Returns a pointer to the hypervisor connection or NULL in case of error
|
|
|
|
*/
|
2005-12-05 11:16:07 +00:00
|
|
|
virConnectPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectOpenReadOnly(const char *name)
|
|
|
|
{
|
2006-03-29 12:46:03 +00:00
|
|
|
int i, res;
|
2005-12-05 11:16:07 +00:00
|
|
|
virConnectPtr ret = NULL;
|
2005-12-01 16:35:42 +00:00
|
|
|
|
2006-03-28 14:41:04 +00:00
|
|
|
if (!initialized)
|
2006-09-21 15:24:37 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return NULL;
|
2006-03-28 14:41:04 +00:00
|
|
|
|
2006-06-13 18:29:42 +00:00
|
|
|
if (name == NULL)
|
|
|
|
name = "Xen";
|
|
|
|
|
2006-04-09 13:11:22 +00:00
|
|
|
ret = virGetConnect();
|
2006-02-27 16:27:18 +00:00
|
|
|
if (ret == NULL) {
|
2006-09-21 15:24:37 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
|
2005-12-01 16:35:42 +00:00
|
|
|
goto failed;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-20 17:49:28 +00:00
|
|
|
|
2006-03-29 12:46:03 +00:00
|
|
|
for (i = 0;i < MAX_DRIVERS;i++) {
|
|
|
|
if ((virDriverTab[i] != NULL) && (virDriverTab[i]->open != NULL)) {
|
|
|
|
res = virDriverTab[i]->open(ret, name,
|
|
|
|
VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO);
|
|
|
|
if (res == 0)
|
|
|
|
ret->drivers[ret->nb_drivers++] = virDriverTab[i];
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2006-03-29 12:46:03 +00:00
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
if ((virNetworkDriverTab[i] != NULL) && (virNetworkDriverTab[i]->open != NULL) &&
|
|
|
|
(res = virNetworkDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET)) == 0) {
|
|
|
|
ret->networkDrivers[ret->nb_network_drivers++] = virNetworkDriverTab[i];
|
|
|
|
}
|
2006-03-29 12:46:03 +00:00
|
|
|
}
|
|
|
|
if (ret->nb_drivers == 0) {
|
|
|
|
if (name == NULL)
|
|
|
|
virLibConnError(NULL, VIR_ERR_NO_CONNECT,
|
2006-09-21 15:24:37 +00:00
|
|
|
_("Xen Daemon or Xen Store"));
|
2006-03-29 12:46:03 +00:00
|
|
|
else
|
|
|
|
/* we failed to find an adequate driver */
|
|
|
|
virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
|
|
|
|
goto failed;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-23 15:42:10 +00:00
|
|
|
ret->flags = VIR_CONNECT_RO;
|
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
return (ret);
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
failed:
|
2006-01-19 10:23:15 +00:00
|
|
|
if (ret != NULL) {
|
2006-03-29 12:46:03 +00:00
|
|
|
for (i = 0;i < ret->nb_drivers;i++) {
|
|
|
|
if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
|
|
|
|
ret->drivers[i]->close(ret);
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
for (i = 0;i < ret->nb_network_drivers;i++) {
|
|
|
|
if ((ret->networkDrivers[i] != NULL) && (ret->networkDrivers[i]->close != NULL))
|
|
|
|
ret->networkDrivers[i]->close(ret);
|
|
|
|
}
|
2006-04-09 13:11:22 +00:00
|
|
|
virFreeConnect(ret);
|
2006-01-19 10:23:15 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2005-11-02 12:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virConnectClose:
|
2005-11-02 12:50:21 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* This function closes the connection to the Hypervisor. This should
|
|
|
|
* not be called if further interaction with the Hypervisor are needed
|
|
|
|
* especially if there is running domain which need further monitoring by
|
|
|
|
* the application.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectClose(virConnectPtr conn)
|
|
|
|
{
|
2006-06-14 15:44:14 +00:00
|
|
|
int i;
|
|
|
|
|
2005-12-16 18:41:46 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn))
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-06-14 15:44:14 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) && (conn->drivers[i]->close != NULL))
|
|
|
|
conn->drivers[i]->close(conn);
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
for (i = 0;i < conn->nb_network_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) && (conn->networkDrivers[i]->close != NULL))
|
|
|
|
conn->networkDrivers[i]->close(conn);
|
|
|
|
}
|
2006-04-09 13:11:22 +00:00
|
|
|
if (virFreeConnect(conn) < 0)
|
|
|
|
return (-1);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (0);
|
2005-11-02 12:50:21 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 13:26:52 +00:00
|
|
|
/**
|
|
|
|
* virConnectGetType:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Get the name of the Hypervisor software used.
|
|
|
|
*
|
|
|
|
* Returns NULL in case of error, a static zero terminated string otherwise.
|
|
|
|
*/
|
|
|
|
const char *
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectGetType(virConnectPtr conn)
|
|
|
|
{
|
2006-06-13 16:31:44 +00:00
|
|
|
int i;
|
2006-06-13 18:29:42 +00:00
|
|
|
const char *ret;
|
2006-06-13 16:31:44 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2006-03-29 12:46:03 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-06-13 18:29:42 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->type != NULL)) {
|
|
|
|
ret = conn->drivers[i]->type(conn);
|
|
|
|
if (ret != NULL)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
2006-06-13 16:31:44 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->name != NULL)) {
|
|
|
|
return(conn->drivers[i]->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(NULL);
|
2005-12-08 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 12:50:21 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virConnectGetVersion:
|
2005-11-02 12:50:21 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2005-12-08 15:08:46 +00:00
|
|
|
* @hvVer: return value for the version of the running hypervisor (OUT)
|
2005-11-02 12:50:21 +00:00
|
|
|
*
|
2005-12-08 13:26:52 +00:00
|
|
|
* Get the version level of the Hypervisor running. This may work only with
|
|
|
|
* hypervisor call, i.e. with priviledged access to the hypervisor, not
|
|
|
|
* with a Read-Only connection.
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
2005-12-08 15:08:46 +00:00
|
|
|
* Returns -1 in case of error, 0 otherwise. if the version can't be
|
|
|
|
* extracted by lack of capacities returns 0 and @hvVer is 0, otherwise
|
|
|
|
* @hvVer value is major * 1,000,000 + minor * 1,000 + release
|
2005-11-07 17:16:18 +00:00
|
|
|
*/
|
2005-12-08 15:08:46 +00:00
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
|
|
|
|
{
|
2006-06-13 16:31:44 +00:00
|
|
|
int ret, i;
|
2005-12-08 13:26:52 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (hvVer == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-06-13 16:31:44 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->version != NULL)) {
|
|
|
|
ret = conn->drivers[i]->version(conn, hvVer);
|
|
|
|
if (ret == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
2007-02-14 01:40:09 +00:00
|
|
|
|
2006-06-13 16:31:44 +00:00
|
|
|
return (-1);
|
2005-12-02 14:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virConnectListDomains:
|
2005-12-02 14:16:21 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @ids: array to collect the list of IDs of active domains
|
|
|
|
* @maxids: size of @ids
|
|
|
|
*
|
|
|
|
* Collect the list of active domains, and store their ID in @maxids
|
|
|
|
*
|
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
|
|
|
|
{
|
2005-12-02 14:16:21 +00:00
|
|
|
int ret = -1;
|
2006-04-24 18:21:29 +00:00
|
|
|
int i;
|
2005-12-02 14:16:21 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if ((ids == NULL) || (maxids <= 0)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-04-24 18:21:29 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->listDomains != NULL)) {
|
|
|
|
ret = conn->drivers[i]->listDomains(conn, ids, maxids);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-14 15:44:14 +00:00
|
|
|
return (-1);
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2005-12-07 11:03:24 +00:00
|
|
|
/**
|
|
|
|
* virConnectNumOfDomains:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
2005-12-08 16:42:56 +00:00
|
|
|
* Provides the number of active domains.
|
|
|
|
*
|
2005-12-07 11:03:24 +00:00
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectNumOfDomains(virConnectPtr conn)
|
|
|
|
{
|
2005-12-07 11:03:24 +00:00
|
|
|
int ret = -1;
|
2006-04-24 18:21:29 +00:00
|
|
|
int i;
|
2005-12-07 11:03:24 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2005-12-16 18:41:46 +00:00
|
|
|
|
2006-04-24 18:21:29 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->numOfDomains != NULL)) {
|
|
|
|
ret = conn->drivers[i]->numOfDomains(conn);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-14 15:44:14 +00:00
|
|
|
return(-1);
|
2005-12-07 11:03:24 +00:00
|
|
|
}
|
|
|
|
|
2005-11-07 17:16:18 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainCreateLinux:
|
2005-11-07 17:16:18 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-02-16 22:50:52 +00:00
|
|
|
* @xmlDesc: an XML description of the domain
|
2005-12-05 11:16:07 +00:00
|
|
|
* @flags: an optional set of virDomainFlags
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
2006-02-20 23:08:47 +00:00
|
|
|
* Launch a new Linux guest domain, based on an XML description similar
|
|
|
|
* to the one returned by virDomainGetXMLDesc()
|
|
|
|
* This function may requires priviledged access to the hypervisor.
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
|
|
|
* Returns a new domain object or NULL in case of failure
|
|
|
|
*/
|
2005-12-05 11:16:07 +00:00
|
|
|
virDomainPtr
|
2006-06-16 12:36:40 +00:00
|
|
|
virDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
|
|
|
|
unsigned int flags)
|
2006-03-15 12:13:25 +00:00
|
|
|
{
|
2006-06-16 12:36:40 +00:00
|
|
|
virDomainPtr ret;
|
|
|
|
int i;
|
2005-12-16 18:41:46 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
if (xmlDesc == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
|
2006-06-16 12:36:40 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainCreateLinux != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainCreateLinux(conn, xmlDesc, flags);
|
|
|
|
if (ret != NULL)
|
|
|
|
return(ret);
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
2006-06-16 12:36:40 +00:00
|
|
|
return(NULL);
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2005-12-16 00:51:27 +00:00
|
|
|
|
2005-11-30 13:20:53 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainLookupByID:
|
2005-11-30 13:20:53 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @id: the domain ID number
|
|
|
|
*
|
|
|
|
* Try to find a domain based on the hypervisor ID number
|
|
|
|
*
|
|
|
|
* Returns a new domain object or NULL in case of failure
|
|
|
|
*/
|
2005-12-05 11:16:07 +00:00
|
|
|
virDomainPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainLookupByID(virConnectPtr conn, int id)
|
|
|
|
{
|
2005-12-05 11:16:07 +00:00
|
|
|
virDomainPtr ret;
|
2006-05-29 18:03:27 +00:00
|
|
|
int i;
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
if (id < 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2006-05-29 18:03:27 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainLookupByID != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainLookupByID(conn, id);
|
|
|
|
if (ret)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-23 10:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainLookupByUUID:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-05-22 14:38:33 +00:00
|
|
|
* @uuid: the raw UUID for the domain
|
2006-02-23 10:13:55 +00:00
|
|
|
*
|
|
|
|
* Try to lookup a domain on the given hypervisor based on its UUID.
|
|
|
|
*
|
|
|
|
* Returns a new domain object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|
|
|
{
|
2006-02-23 10:13:55 +00:00
|
|
|
virDomainPtr ret;
|
2006-05-29 18:03:27 +00:00
|
|
|
int i;
|
2006-02-23 10:13:55 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-05-29 18:03:27 +00:00
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainLookupByUUID != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainLookupByUUID(conn, uuid);
|
|
|
|
if (ret)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-15 14:50:48 +00:00
|
|
|
return (NULL);
|
2005-11-30 13:20:53 +00:00
|
|
|
}
|
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
/**
|
|
|
|
* virDomainLookupByUUIDString:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @uuidstr: the string UUID for the domain
|
|
|
|
*
|
|
|
|
* Try to lookup a domain on the given hypervisor based on its UUID.
|
|
|
|
*
|
|
|
|
* Returns a new domain object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
|
|
|
virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
|
|
|
|
{
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
int raw[VIR_UUID_BUFLEN], i;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
2006-05-22 14:38:33 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuidstr == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
/* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
|
|
|
|
* We needn't it here. Right?
|
|
|
|
*/
|
|
|
|
ret = sscanf(uuidstr,
|
|
|
|
"%02x%02x%02x%02x-"
|
|
|
|
"%02x%02x-"
|
|
|
|
"%02x%02x-"
|
|
|
|
"%02x%02x-"
|
|
|
|
"%02x%02x%02x%02x%02x%02x",
|
|
|
|
raw + 0, raw + 1, raw + 2, raw + 3,
|
|
|
|
raw + 4, raw + 5, raw + 6, raw + 7,
|
|
|
|
raw + 8, raw + 9, raw + 10, raw + 11,
|
|
|
|
raw + 12, raw + 13, raw + 14, raw + 15);
|
|
|
|
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
if (ret!=VIR_UUID_BUFLEN) {
|
2006-05-22 14:38:33 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
for (i = 0; i < VIR_UUID_BUFLEN; i++)
|
2006-05-22 14:38:33 +00:00
|
|
|
uuid[i] = raw[i] & 0xFF;
|
|
|
|
|
|
|
|
return virDomainLookupByUUID(conn, &uuid[0]);
|
|
|
|
}
|
|
|
|
|
2005-12-12 13:22:20 +00:00
|
|
|
/**
|
|
|
|
* virDomainLookupByName:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @name: name for the domain
|
|
|
|
*
|
2005-12-13 16:22:05 +00:00
|
|
|
* Try to lookup a domain on the given hypervisor based on its name.
|
2005-12-12 13:22:20 +00:00
|
|
|
*
|
|
|
|
* Returns a new domain object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
2005-12-12 13:22:20 +00:00
|
|
|
virDomainPtr ret = NULL;
|
2006-05-29 18:03:27 +00:00
|
|
|
int i;
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-05-29 18:03:27 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainLookupByName != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainLookupByName(conn, name);
|
|
|
|
if (ret)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 14:50:48 +00:00
|
|
|
return (NULL);
|
2005-12-12 13:22:20 +00:00
|
|
|
}
|
|
|
|
|
2005-11-07 17:16:18 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainDestroy:
|
2005-11-07 17:16:18 +00:00
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Destroy the domain object. The running instance is shutdown if not down
|
|
|
|
* already and all resources used by it are given back to the hypervisor.
|
2005-12-08 16:42:56 +00:00
|
|
|
* The data structure is freed and should not be used thereafter if the
|
|
|
|
* call does not return an error.
|
2006-01-18 10:37:08 +00:00
|
|
|
* This function may requires priviledged access
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
2005-11-02 13:19:10 +00:00
|
|
|
*/
|
2005-11-07 17:16:18 +00:00
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainDestroy(virDomainPtr domain)
|
|
|
|
{
|
2006-08-11 14:40:04 +00:00
|
|
|
int i;
|
2006-06-14 17:07:00 +00:00
|
|
|
virConnectPtr conn;
|
2005-12-08 17:16:24 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
2006-08-16 16:14:53 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2006-06-21 12:56:19 +00:00
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points but use the
|
|
|
|
* XEN_HYPERVISOR directly only as a last mechanism
|
|
|
|
*/
|
2006-06-14 17:07:00 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
2006-06-21 12:56:19 +00:00
|
|
|
(conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
|
|
|
|
(conn->drivers[i]->domainDestroy != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainDestroy(domain) == 0)
|
2006-08-11 14:40:04 +00:00
|
|
|
return (0);
|
2006-06-21 12:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
|
2006-06-14 17:07:00 +00:00
|
|
|
(conn->drivers[i]->domainDestroy != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainDestroy(domain) == 0)
|
2006-08-11 14:40:04 +00:00
|
|
|
return (0);
|
2006-06-14 17:07:00 +00:00
|
|
|
}
|
2006-01-18 10:37:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
2006-08-11 14:40:04 +00:00
|
|
|
return (-1);
|
2005-12-08 16:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainFree:
|
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Free the domain object. The running instance is kept alive.
|
|
|
|
* The data structure is freed and should not be used thereafter.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainFree(virDomainPtr domain)
|
|
|
|
{
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-04-09 13:11:22 +00:00
|
|
|
if (virFreeDomain(domain->conn, domain) < 0)
|
|
|
|
return (-1);
|
|
|
|
return(0);
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainSuspend:
|
2005-11-07 17:16:18 +00:00
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Suspends an active domain, the process is frozen without further access
|
|
|
|
* to CPU resources and I/O but the memory used by the domain at the
|
2005-12-05 11:16:07 +00:00
|
|
|
* hypervisor level will stay allocated. Use virDomainResume() to reactivate
|
2005-11-07 17:16:18 +00:00
|
|
|
* the domain.
|
2006-01-18 10:37:08 +00:00
|
|
|
* This function may requires priviledged access.
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainSuspend(virDomainPtr domain)
|
|
|
|
{
|
2006-08-11 14:40:04 +00:00
|
|
|
int i;
|
2006-06-14 17:07:00 +00:00
|
|
|
virConnectPtr conn;
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2006-06-21 12:56:19 +00:00
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points but use the
|
|
|
|
* XEN_HYPERVISOR directly only as a last mechanism
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
|
|
|
|
(conn->drivers[i]->domainSuspend != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainSuspend(domain) == 0)
|
2006-08-11 14:40:04 +00:00
|
|
|
return (0);
|
2006-06-21 12:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
2006-06-21 12:56:19 +00:00
|
|
|
(conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
|
2006-06-14 17:07:00 +00:00
|
|
|
(conn->drivers[i]->domainSuspend != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainSuspend(domain) == 0)
|
2006-08-11 14:40:04 +00:00
|
|
|
return (0);
|
2006-06-14 17:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
2006-08-11 14:40:04 +00:00
|
|
|
return (-1);
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainResume:
|
2005-11-07 17:16:18 +00:00
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Resume an suspended domain, the process is restarted from the state where
|
2005-12-05 11:16:07 +00:00
|
|
|
* it was frozen by calling virSuspendDomain().
|
2006-01-18 10:37:08 +00:00
|
|
|
* This function may requires priviledged access
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainResume(virDomainPtr domain)
|
|
|
|
{
|
2006-06-16 12:36:40 +00:00
|
|
|
int i;
|
2006-06-14 17:07:00 +00:00
|
|
|
virConnectPtr conn;
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2006-06-21 12:56:19 +00:00
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points but use the
|
|
|
|
* XEN_HYPERVISOR directly only as a last mechanism
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
|
|
|
|
(conn->drivers[i]->domainResume != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainResume(domain) == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
2006-06-21 12:56:19 +00:00
|
|
|
(conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
|
2006-06-14 17:07:00 +00:00
|
|
|
(conn->drivers[i]->domainResume != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainResume(domain) == 0)
|
2006-06-16 12:36:40 +00:00
|
|
|
return(0);
|
2006-06-14 17:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 12:36:40 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2006-01-18 10:37:08 +00:00
|
|
|
/**
|
|
|
|
* virDomainSave:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @to: path for the output file
|
|
|
|
*
|
|
|
|
* This method will suspend a domain and save its memory contents to
|
2006-01-20 10:00:08 +00:00
|
|
|
* a file on disk. After the call, if successful, the domain is not
|
|
|
|
* listed as running anymore (this may be a problem).
|
|
|
|
* Use virDomainRestore() to restore a domain after saving.
|
2006-01-18 10:37:08 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainSave(virDomainPtr domain, const char *to)
|
|
|
|
{
|
2006-06-16 12:36:40 +00:00
|
|
|
int ret, i;
|
2006-01-20 10:00:08 +00:00
|
|
|
char filepath[4096];
|
2006-06-16 12:36:40 +00:00
|
|
|
virConnectPtr conn;
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-06-16 12:36:40 +00:00
|
|
|
conn = domain->conn;
|
2006-02-27 16:27:18 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-01-20 10:00:08 +00:00
|
|
|
/*
|
|
|
|
* We must absolutize the file path as the save is done out of process
|
|
|
|
* TODO: check for URI when libxml2 is linked in.
|
|
|
|
*/
|
|
|
|
if (to[0] != '/') {
|
2006-03-15 12:13:25 +00:00
|
|
|
unsigned int len, t;
|
2006-01-20 10:00:08 +00:00
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
t = strlen(to);
|
|
|
|
if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
|
|
|
|
return (-1);
|
|
|
|
len = strlen(filepath);
|
|
|
|
/* that should be covered by getcwd() semantic, but be 100% sure */
|
|
|
|
if (len > sizeof(filepath) - (t + 3))
|
|
|
|
return (-1);
|
|
|
|
filepath[len] = '/';
|
|
|
|
strcpy(&filepath[len + 1], to);
|
|
|
|
to = &filepath[0];
|
2006-01-20 10:00:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-06-16 12:36:40 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainSave != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainSave(domain, to);
|
|
|
|
if (ret == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
2006-01-18 10:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainRestore:
|
2006-01-20 10:00:08 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-01-18 10:37:08 +00:00
|
|
|
* @from: path to the
|
|
|
|
*
|
|
|
|
* This method will restore a domain saved to disk by virDomainSave().
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainRestore(virConnectPtr conn, const char *from)
|
|
|
|
{
|
2006-06-16 12:36:40 +00:00
|
|
|
int ret, i;
|
2006-01-20 10:00:08 +00:00
|
|
|
char filepath[4096];
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
if (from == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 10:00:08 +00:00
|
|
|
/*
|
|
|
|
* We must absolutize the file path as the restore is done out of process
|
|
|
|
* TODO: check for URI when libxml2 is linked in.
|
|
|
|
*/
|
|
|
|
if (from[0] != '/') {
|
2006-03-15 12:13:25 +00:00
|
|
|
unsigned int len, t;
|
|
|
|
|
|
|
|
t = strlen(from);
|
|
|
|
if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
|
|
|
|
return (-1);
|
|
|
|
len = strlen(filepath);
|
|
|
|
/* that should be covered by getcwd() semantic, but be 100% sure */
|
|
|
|
if (len > sizeof(filepath) - (t + 3))
|
|
|
|
return (-1);
|
|
|
|
filepath[len] = '/';
|
|
|
|
strcpy(&filepath[len + 1], from);
|
|
|
|
from = &filepath[0];
|
|
|
|
}
|
|
|
|
|
2006-06-16 12:36:40 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainSave != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainRestore(conn, from);
|
|
|
|
if (ret == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
2006-11-22 17:48:29 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainCoreDump:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @to: path for the core file
|
|
|
|
* @flags: extra flags, currently unused
|
|
|
|
*
|
|
|
|
* This method will dump the core of a domain on a given file for analysis.
|
|
|
|
* Note that for remote Xen Daemon the file path will be interpreted in
|
|
|
|
* the remote host.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainCoreDump(virDomainPtr domain, const char *to, int flags)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
char filepath[4096];
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
if (to == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must absolutize the file path as the save is done out of process
|
|
|
|
* TODO: check for URI when libxml2 is linked in.
|
|
|
|
*/
|
|
|
|
if (to[0] != '/') {
|
|
|
|
unsigned int len, t;
|
|
|
|
|
|
|
|
t = strlen(to);
|
|
|
|
if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
|
|
|
|
return (-1);
|
|
|
|
len = strlen(filepath);
|
|
|
|
/* that should be covered by getcwd() semantic, but be 100% sure */
|
|
|
|
if (len > sizeof(filepath) - (t + 3))
|
|
|
|
return (-1);
|
|
|
|
filepath[len] = '/';
|
|
|
|
strcpy(&filepath[len + 1], to);
|
|
|
|
to = &filepath[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainCoreDump != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainCoreDump(domain, to, flags);
|
|
|
|
if (ret == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
2006-06-16 12:36:40 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
2006-01-18 10:37:08 +00:00
|
|
|
}
|
|
|
|
|
2005-12-16 12:16:41 +00:00
|
|
|
/**
|
|
|
|
* virDomainShutdown:
|
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Shutdown a domain, the domain object is still usable there after but
|
2006-01-18 10:37:08 +00:00
|
|
|
* the domain OS is being stopped. Note that the guest OS may ignore the
|
|
|
|
* request.
|
2005-12-16 12:16:41 +00:00
|
|
|
*
|
|
|
|
* TODO: should we add an option for reboot, knowing it may not be doable
|
|
|
|
* in the general case ?
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainShutdown(virDomainPtr domain)
|
|
|
|
{
|
2006-06-14 17:07:00 +00:00
|
|
|
int ret = -1, i;
|
|
|
|
virConnectPtr conn;
|
2005-12-16 12:16:41 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainShutdown != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainShutdown(domain) == 0)
|
|
|
|
ret = 0;
|
|
|
|
}
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2006-01-18 18:58:35 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (ret);
|
2005-12-16 12:16:41 +00:00
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
return (ret);
|
2005-12-16 12:16:41 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 13:46:43 +00:00
|
|
|
/**
|
|
|
|
* virDomainReboot:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @flags: extra flags for the reboot operation, not used yet
|
|
|
|
*
|
|
|
|
* Reboot a domain, the domain object is still usable there after but
|
|
|
|
* the domain OS is being stopped for a restart.
|
|
|
|
* Note that the guest OS may ignore the request.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainReboot(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
2006-06-14 17:07:00 +00:00
|
|
|
int ret = -1, i;
|
|
|
|
virConnectPtr conn;
|
2006-04-03 13:46:43 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-04-03 13:46:43 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainReboot != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainReboot(domain, flags) == 0)
|
|
|
|
ret = 0;
|
|
|
|
}
|
2006-04-03 13:46:43 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (ret);
|
2006-04-03 13:46:43 +00:00
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2006-04-03 13:46:43 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2005-11-23 07:47:13 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainGetName:
|
2005-11-23 07:47:13 +00:00
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Get the public name for that domain
|
|
|
|
*
|
|
|
|
* Returns a pointer to the name or NULL, the string need not be deallocated
|
|
|
|
* its lifetime will be the same as the domain object.
|
|
|
|
*/
|
|
|
|
const char *
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainGetName(virDomainPtr domain)
|
|
|
|
{
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
return (domain->name);
|
2005-11-30 13:20:53 +00:00
|
|
|
}
|
|
|
|
|
2006-02-23 10:13:55 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetUUID:
|
|
|
|
* @domain: a domain object
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
* @uuid: pointer to a VIR_UUID_BUFLEN bytes array
|
2006-02-23 10:13:55 +00:00
|
|
|
*
|
|
|
|
* Get the UUID for a domain
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
|
|
|
|
{
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 16:25:27 +00:00
|
|
|
if (domain->id == 0) {
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
2006-02-27 16:27:18 +00:00
|
|
|
} else {
|
2006-03-15 12:13:25 +00:00
|
|
|
if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) &&
|
|
|
|
(domain->uuid[2] == 0) && (domain->uuid[3] == 0) &&
|
|
|
|
(domain->uuid[4] == 0) && (domain->uuid[5] == 0) &&
|
|
|
|
(domain->uuid[6] == 0) && (domain->uuid[7] == 0) &&
|
|
|
|
(domain->uuid[8] == 0) && (domain->uuid[9] == 0) &&
|
|
|
|
(domain->uuid[10] == 0) && (domain->uuid[11] == 0) &&
|
|
|
|
(domain->uuid[12] == 0) && (domain->uuid[13] == 0) &&
|
|
|
|
(domain->uuid[14] == 0) && (domain->uuid[15] == 0))
|
2006-03-22 13:44:01 +00:00
|
|
|
xenDaemonDomainLookupByName_ids(domain->conn, domain->name,
|
2006-03-15 12:13:25 +00:00
|
|
|
&domain->uuid[0]);
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
|
2006-03-15 12:13:25 +00:00
|
|
|
}
|
|
|
|
return (0);
|
2006-02-23 10:13:55 +00:00
|
|
|
}
|
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetUUIDString:
|
|
|
|
* @domain: a domain object
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
* @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
|
2006-05-22 14:38:33 +00:00
|
|
|
*
|
|
|
|
* Get the UUID for a domain as string. For more information about
|
|
|
|
* UUID see RFC4122.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainGetUUIDString(virDomainPtr domain, char *buf)
|
|
|
|
{
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
2006-08-16 16:29:46 +00:00
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (buf == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDomainGetUUID(domain, &uuid[0]))
|
|
|
|
return (-1);
|
|
|
|
|
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
2007-01-23 14:39:45 +00:00
|
|
|
snprintf(buf, VIR_UUID_STRING_BUFLEN,
|
2006-05-22 14:38:33 +00:00
|
|
|
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
|
|
uuid[0], uuid[1], uuid[2], uuid[3],
|
|
|
|
uuid[4], uuid[5], uuid[6], uuid[7],
|
|
|
|
uuid[8], uuid[9], uuid[10], uuid[11],
|
|
|
|
uuid[12], uuid[13], uuid[14], uuid[15]);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-11-30 13:20:53 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainGetID:
|
2005-11-30 13:20:53 +00:00
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Get the hypervisor ID number for the domain
|
|
|
|
*
|
|
|
|
* Returns the domain ID number or (unsigned int) -1 in case of error
|
|
|
|
*/
|
|
|
|
unsigned int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainGetID(virDomainPtr domain)
|
|
|
|
{
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return ((unsigned int) -1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2007-01-22 16:25:27 +00:00
|
|
|
return (domain->id);
|
2005-11-23 07:47:13 +00:00
|
|
|
}
|
|
|
|
|
2005-12-16 00:51:27 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetOSType:
|
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Get the type of domain operation system.
|
|
|
|
*
|
2006-03-20 17:49:28 +00:00
|
|
|
* Returns the new string or NULL in case of error, the string must be
|
|
|
|
* freed by the caller.
|
2005-12-16 00:51:27 +00:00
|
|
|
*/
|
|
|
|
char *
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainGetOSType(virDomainPtr domain)
|
|
|
|
{
|
2006-11-07 16:28:16 +00:00
|
|
|
char *str = NULL;
|
|
|
|
int i;
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-11-07 16:28:16 +00:00
|
|
|
for (i = 0;i < domain->conn->nb_drivers;i++) {
|
|
|
|
if ((domain->conn->drivers[i] != NULL) &&
|
|
|
|
(domain->conn->drivers[i]->domainGetOSType != NULL)) {
|
|
|
|
str = domain->conn->drivers[i]->domainGetOSType(domain);
|
|
|
|
if (str != NULL)
|
|
|
|
break;
|
|
|
|
}
|
2005-12-16 00:51:27 +00:00
|
|
|
}
|
2006-11-07 16:28:16 +00:00
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
return (str);
|
2005-12-16 00:51:27 +00:00
|
|
|
}
|
|
|
|
|
2005-11-23 07:47:13 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainGetMaxMemory:
|
2005-11-23 07:47:13 +00:00
|
|
|
* @domain: a domain object or NULL
|
|
|
|
*
|
|
|
|
* Retrieve the maximum amount of physical memory allocated to a
|
|
|
|
* domain. If domain is NULL, then this get the amount of memory reserved
|
|
|
|
* to Domain0 i.e. the domain where the application runs.
|
|
|
|
*
|
|
|
|
* Returns the memory size in kilobytes or 0 in case of error.
|
|
|
|
*/
|
|
|
|
unsigned long
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainGetMaxMemory(virDomainPtr domain)
|
|
|
|
{
|
2005-12-12 13:22:20 +00:00
|
|
|
unsigned long ret = 0;
|
2006-06-16 12:36:40 +00:00
|
|
|
virConnectPtr conn;
|
|
|
|
int i;
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (0);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-06-16 12:36:40 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2006-03-23 15:42:10 +00:00
|
|
|
/*
|
2006-06-16 12:36:40 +00:00
|
|
|
* in that case instead of trying only though one method try all availble.
|
|
|
|
* If needed that can be changed back if it's a performcance problem.
|
2006-03-23 15:42:10 +00:00
|
|
|
*/
|
2006-06-16 12:36:40 +00:00
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainGetMaxMemory != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainGetMaxMemory(domain);
|
|
|
|
if (ret != 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
2005-11-23 07:47:13 +00:00
|
|
|
}
|
|
|
|
|
2005-11-07 17:16:18 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainSetMaxMemory:
|
2005-11-07 17:16:18 +00:00
|
|
|
* @domain: a domain object or NULL
|
|
|
|
* @memory: the memory size in kilobytes
|
|
|
|
*
|
|
|
|
* Dynamically change the maximum amount of physical memory allocated to a
|
|
|
|
* domain. If domain is NULL, then this change the amount of memory reserved
|
|
|
|
* to Domain0 i.e. the domain where the application runs.
|
2005-12-15 14:51:18 +00:00
|
|
|
* This function requires priviledged access to the hypervisor.
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
|
|
|
|
{
|
2006-04-13 17:18:49 +00:00
|
|
|
int ret = -1 , i;
|
|
|
|
virConnectPtr conn;
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-03-22 13:44:01 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-03-22 13:44:01 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (memory < 4096) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-04-13 17:18:49 +00:00
|
|
|
conn = domain->conn;
|
2006-03-22 13:44:01 +00:00
|
|
|
|
2006-04-13 17:18:49 +00:00
|
|
|
/*
|
|
|
|
* in that case instead of trying only though one method try all availble.
|
|
|
|
* If needed that can be changed back if it's a performcance problem.
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainSetMaxMemory != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainSetMaxMemory(domain, memory) == 0)
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret != 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-04-13 17:18:49 +00:00
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-04-13 17:18:49 +00:00
|
|
|
/**
|
|
|
|
* virDomainSetMemory:
|
|
|
|
* @domain: a domain object or NULL
|
|
|
|
* @memory: the memory size in kilobytes
|
|
|
|
*
|
|
|
|
* Dynamically change the target amount of physical memory allocated to a
|
|
|
|
* domain. If domain is NULL, then this change the amount of memory reserved
|
|
|
|
* to Domain0 i.e. the domain where the application runs.
|
|
|
|
* This function may requires priviledged access to the hypervisor.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainSetMemory(virDomainPtr domain, unsigned long memory)
|
|
|
|
{
|
|
|
|
int ret = -1 , i;
|
|
|
|
virConnectPtr conn;
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-04-13 17:18:49 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
2006-03-22 13:44:01 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (memory < 4096) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-04-13 17:18:49 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn = domain->conn;
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-04-13 17:18:49 +00:00
|
|
|
/*
|
|
|
|
* in that case instead of trying only though one method try all availble.
|
|
|
|
* If needed that can be changed back if it's a performcance problem.
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainSetMemory != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainSetMemory(domain, memory) == 0)
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret != 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
return (ret);
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2005-12-05 18:14:37 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetInfo:
|
2005-12-13 16:22:05 +00:00
|
|
|
* @domain: a domain object
|
2005-12-05 18:14:37 +00:00
|
|
|
* @info: pointer to a virDomainInfo structure allocated by the user
|
|
|
|
*
|
|
|
|
* Extract information about a domain. Note that if the connection
|
2006-07-19 22:24:37 +00:00
|
|
|
* used to get the domain is limited only a partial set of the information
|
2005-12-05 18:14:37 +00:00
|
|
|
* can be extracted.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
|
|
|
|
{
|
2006-05-29 18:03:27 +00:00
|
|
|
int i;
|
2005-12-05 18:14:37 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
if (info == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2005-12-06 13:47:40 +00:00
|
|
|
memset(info, 0, sizeof(virDomainInfo));
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-05-29 18:03:27 +00:00
|
|
|
for (i = 0;i < domain->conn->nb_drivers;i++) {
|
|
|
|
if ((domain->conn->drivers[i] != NULL) &&
|
|
|
|
(domain->conn->drivers[i]->domainGetInfo != NULL)) {
|
|
|
|
if (domain->conn->drivers[i]->domainGetInfo(domain, info) == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-23 15:42:10 +00:00
|
|
|
return (-1);
|
2005-12-05 18:14:37 +00:00
|
|
|
}
|
2005-12-13 16:22:05 +00:00
|
|
|
|
2006-02-20 23:08:47 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetXMLDesc:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @flags: and OR'ed set of extraction flags, not used yet
|
|
|
|
*
|
|
|
|
* Provide an XML description of the domain. The description may be reused
|
|
|
|
* later to relaunch the domain with virDomainCreateLinux().
|
|
|
|
*
|
|
|
|
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainGetXMLDesc(virDomainPtr domain, int flags)
|
|
|
|
{
|
2006-08-09 15:21:16 +00:00
|
|
|
int i;
|
|
|
|
char *ret = NULL;
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-02-20 23:08:47 +00:00
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
for (i = 0;i < domain->conn->nb_drivers;i++) {
|
|
|
|
if ((domain->conn->drivers[i] != NULL) &&
|
|
|
|
(domain->conn->drivers[i]->domainDumpXML != NULL)) {
|
|
|
|
ret = domain->conn->drivers[i]->domainDumpXML(domain, flags);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret) {
|
|
|
|
virLibConnError(domain->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return(ret);
|
2006-02-20 23:08:47 +00:00
|
|
|
}
|
2006-03-29 12:46:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeGetInfo:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @info: pointer to a virNodeInfo structure allocated by the user
|
|
|
|
*
|
|
|
|
* Extract hardware information about the node.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) {
|
|
|
|
int i;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (info == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->nodeGetInfo != NULL)) {
|
|
|
|
ret = conn->drivers[i]->nodeGetInfo(conn, info);
|
|
|
|
if (ret == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret != 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Handling of defined but not running domains *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainDefineXML:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @xml: the XML description for the domain, preferably in UTF-8
|
|
|
|
*
|
|
|
|
* define a domain, but does not start it
|
|
|
|
*
|
|
|
|
* Returns NULL in case of error, a pointer to the domain otherwise
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
|
|
|
virDomainDefineXML(virConnectPtr conn, const char *xml) {
|
|
|
|
virDomainPtr ret = NULL;
|
2006-08-30 14:21:03 +00:00
|
|
|
int i;
|
2006-04-28 18:29:26 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2006-08-30 14:21:03 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainDefineXML != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainDefineXML(conn, xml);
|
|
|
|
if (ret)
|
|
|
|
return(ret);
|
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainUndefine:
|
|
|
|
* @domain: pointer to a defined domain
|
|
|
|
*
|
|
|
|
* undefine a domain but does not stop it if it is running
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainUndefine(virDomainPtr domain) {
|
2006-08-30 14:21:03 +00:00
|
|
|
int ret, i;
|
|
|
|
virConnectPtr conn;
|
2006-04-28 18:29:26 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-30 14:21:03 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
2006-08-16 16:14:53 +00:00
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2006-08-30 14:21:03 +00:00
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainUndefine != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainUndefine(domain);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
|
2006-08-30 14:21:03 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfDefinedDomains:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides the number of active domains.
|
|
|
|
*
|
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->numOfDefinedDomains != NULL)) {
|
|
|
|
ret = conn->drivers[i]->numOfDefinedDomains(conn);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(-1);
|
2006-04-28 18:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListDefinedDomains:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @names: pointer to an array to store the names
|
|
|
|
* @maxnames: size of the array
|
|
|
|
*
|
|
|
|
* list the defined domains, stores the pointers to the names in @names
|
|
|
|
*
|
|
|
|
* Returns the number of names provided in the array or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListDefinedDomains(virConnectPtr conn, const char **names,
|
|
|
|
int maxnames) {
|
2006-08-30 14:21:03 +00:00
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((names == NULL) || (maxnames <= 0)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->listDefinedDomains != NULL)) {
|
|
|
|
ret = conn->drivers[i]->listDefinedDomains(conn, names, maxnames);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
2006-04-28 18:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainCreate:
|
|
|
|
* @domain: pointer to a defined domain
|
|
|
|
*
|
|
|
|
* launch a defined domain. If the call succeed the domain moves from the
|
|
|
|
* defined to the running domains pools.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainCreate(virDomainPtr domain) {
|
2006-08-30 14:21:03 +00:00
|
|
|
int i, ret = -1;
|
|
|
|
virConnectPtr conn;
|
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-30 14:21:03 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
2006-08-16 16:14:53 +00:00
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-30 14:21:03 +00:00
|
|
|
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainCreate != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainCreate(domain);
|
|
|
|
if (ret == 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(ret);
|
2006-04-28 18:29:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-04 10:41:05 +00:00
|
|
|
/**
|
|
|
|
* virDomainSetVcpus:
|
|
|
|
* @domain: pointer to domain object, or NULL for Domain0
|
|
|
|
* @nvcpus: the new number of virtual CPUs for this domain
|
|
|
|
*
|
|
|
|
* Dynamically change the number of virtual CPUs used by the domain.
|
|
|
|
* Note that this call may fail if the underlying virtualization hypervisor
|
|
|
|
* does not support it or if growing the number is arbitrary limited.
|
|
|
|
* This function requires priviledged access to the hypervisor.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
virDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
|
|
|
|
{
|
2006-08-08 22:22:55 +00:00
|
|
|
int i;
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
2006-08-04 10:41:05 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:29:46 +00:00
|
|
|
|
2006-08-04 10:41:05 +00:00
|
|
|
if (nvcpus < 1) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
2006-08-04 10:41:05 +00:00
|
|
|
|
2006-08-08 22:22:55 +00:00
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points but use the
|
|
|
|
* XEN_HYPERVISOR directly only as a last mechanism
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
|
|
|
|
(conn->drivers[i]->domainSetVcpus != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainSetVcpus(domain, nvcpus) == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
|
|
|
|
(conn->drivers[i]->domainSetVcpus != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainSetVcpus(domain, nvcpus) == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainPinVcpu:
|
|
|
|
* @domain: pointer to domain object, or NULL for Domain0
|
|
|
|
* @vcpu: virtual CPU number
|
|
|
|
* @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
|
|
|
|
* Each bit set to 1 means that corresponding CPU is usable.
|
|
|
|
* Bytes are stored in little-endian order: CPU0-7, 8-15...
|
|
|
|
* In each byte, lowest CPU number is least significant bit.
|
|
|
|
* @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
|
|
|
|
* underlying virtualization system (Xen...).
|
|
|
|
* If maplen < size, missing bytes are set to zero.
|
|
|
|
* If maplen > size, failure code is returned.
|
|
|
|
*
|
|
|
|
* Dynamically change the real CPUs which can be allocated to a virtual CPU.
|
|
|
|
* This function requires priviledged access to the hypervisor.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
|
|
|
|
unsigned char *cpumap, int maplen)
|
|
|
|
{
|
2006-08-08 22:22:55 +00:00
|
|
|
int i;
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
2006-08-04 10:41:05 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:29:46 +00:00
|
|
|
|
2006-08-08 22:22:55 +00:00
|
|
|
if ((vcpu > 32000) || (cpumap == NULL) || (maplen < 1)) {
|
2006-08-04 10:41:05 +00:00
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainPinVcpu != NULL)) {
|
|
|
|
if (conn->drivers[i]->domainPinVcpu(domain, vcpu,
|
|
|
|
cpumap, maplen) == 0)
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainGetVcpus:
|
|
|
|
* @domain: pointer to domain object, or NULL for Domain0
|
|
|
|
* @info: pointer to an array of virVcpuInfo structures (OUT)
|
|
|
|
* @maxinfo: number of structures in info array
|
|
|
|
* @cpumaps: pointer to an bit map of real CPUs for all vcpus of this
|
|
|
|
* domain (in 8-bit bytes) (OUT)
|
|
|
|
* If cpumaps is NULL, then no cupmap information is returned by the API.
|
|
|
|
* It's assumed there is <maxinfo> cpumap in cpumaps array.
|
|
|
|
* The memory allocated to cpumaps must be (maxinfo * maplen) bytes
|
|
|
|
* (ie: calloc(maxinfo, maplen)).
|
|
|
|
* One cpumap inside cpumaps has the format described in
|
|
|
|
* virDomainPinVcpu() API.
|
|
|
|
* @maplen: number of bytes in one cpumap, from 1 up to size of CPU map in
|
|
|
|
* underlying virtualization system (Xen...).
|
|
|
|
*
|
|
|
|
* Extract information about virtual CPUs of domain, store it in info array
|
|
|
|
* and also in cpumaps if this pointer is'nt NULL.
|
|
|
|
*
|
|
|
|
* Returns the number of info filled in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
|
|
|
|
unsigned char *cpumaps, int maplen)
|
|
|
|
{
|
|
|
|
int ret;
|
2006-08-08 22:22:55 +00:00
|
|
|
int i;
|
|
|
|
virConnectPtr conn;
|
2006-08-04 10:41:05 +00:00
|
|
|
|
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if ((info == NULL) || (maxinfo < 1)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (cpumaps != NULL && maplen < 1) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainGetVcpus != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainGetVcpus(domain, info, maxinfo,
|
|
|
|
cpumaps, maplen);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
2006-11-16 18:11:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainAttachDevice:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @xml: pointer to XML description of one device
|
|
|
|
*
|
|
|
|
* Create a virtual device attachment to backend.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainAttachDevice(virDomainPtr domain, char *xml)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainAttachDevice != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainAttachDevice(domain, xml);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainDetachDevice:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @xml: pointer to XML description of one device
|
|
|
|
*
|
|
|
|
* Destroy a virtual device attachment to backend.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainDetachDevice(virDomainPtr domain, char *xml)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->drivers[i] != NULL) &&
|
|
|
|
(conn->drivers[i]->domainDetachDevice != NULL)) {
|
|
|
|
ret = conn->drivers[i]->domainDetachDevice(domain, xml);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfNetworks:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides the number of active networks.
|
|
|
|
*
|
|
|
|
* Returns the number of network found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfNetworks(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_network_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->numOfNetworks != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->numOfNetworks(conn);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListNetworks:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @names: array to collect the list of names of active networks
|
|
|
|
* @maxnames: size of @names
|
|
|
|
*
|
|
|
|
* Collect the list of active networks, and store their names in @names
|
|
|
|
*
|
|
|
|
* Returns the number of networks found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListNetworks(virConnectPtr conn, const char **names, int maxnames)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((names == NULL) || (maxnames <= 0)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->listNetworks != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->listNetworks(conn, names, maxnames);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfDefinedNetworks:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides the number of inactive networks.
|
|
|
|
*
|
|
|
|
* Returns the number of networks found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfDefinedNetworks(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->numOfDefinedNetworks != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->numOfDefinedNetworks(conn);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListDefinedNetworks:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @names: pointer to an array to store the names
|
|
|
|
* @maxnames: size of the array
|
|
|
|
*
|
|
|
|
* list the inactive networks, stores the pointers to the names in @names
|
|
|
|
*
|
|
|
|
* Returns the number of names provided in the array or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListDefinedNetworks(virConnectPtr conn, const char **names,
|
|
|
|
int maxnames) {
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((names == NULL) || (maxnames <= 0)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->listDefinedNetworks != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->listDefinedNetworks(conn, names, maxnames);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkLookupByName:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @name: name for the network
|
|
|
|
*
|
|
|
|
* Try to lookup a network on the given hypervisor based on its name.
|
|
|
|
*
|
|
|
|
* Returns a new network object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
|
|
|
virNetworkPtr ret = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->networkLookupByName != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->networkLookupByName(conn, name);
|
|
|
|
if (ret)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkLookupByUUID:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @uuid: the raw UUID for the network
|
|
|
|
*
|
|
|
|
* Try to lookup a network on the given hypervisor based on its UUID.
|
|
|
|
*
|
|
|
|
* Returns a new network object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|
|
|
{
|
|
|
|
virNetworkPtr ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->networkLookupByUUID != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->networkLookupByUUID(conn, uuid);
|
|
|
|
if (ret)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkLookupByUUIDString:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @uuidstr: the string UUID for the network
|
|
|
|
*
|
|
|
|
* Try to lookup a network on the given hypervisor based on its UUID.
|
|
|
|
*
|
|
|
|
* Returns a new network object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
|
|
|
|
{
|
|
|
|
int raw[VIR_UUID_BUFLEN], i;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuidstr == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
|
|
|
|
* We needn't it here. Right?
|
|
|
|
*/
|
|
|
|
ret = sscanf(uuidstr,
|
|
|
|
"%02x%02x%02x%02x-"
|
|
|
|
"%02x%02x-"
|
|
|
|
"%02x%02x-"
|
|
|
|
"%02x%02x-"
|
|
|
|
"%02x%02x%02x%02x%02x%02x",
|
|
|
|
raw + 0, raw + 1, raw + 2, raw + 3,
|
|
|
|
raw + 4, raw + 5, raw + 6, raw + 7,
|
|
|
|
raw + 8, raw + 9, raw + 10, raw + 11,
|
|
|
|
raw + 12, raw + 13, raw + 14, raw + 15);
|
|
|
|
|
|
|
|
if (ret!=VIR_UUID_BUFLEN) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
for (i = 0; i < VIR_UUID_BUFLEN; i++)
|
|
|
|
uuid[i] = raw[i] & 0xFF;
|
|
|
|
|
|
|
|
return virNetworkLookupByUUID(conn, &uuid[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkCreateXML:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @xmlDesc: an XML description of the network
|
|
|
|
*
|
|
|
|
* Create and start a new virtual network, based on an XML description
|
|
|
|
* similar to the one returned by virNetworkGetXMLDesc()
|
|
|
|
*
|
|
|
|
* Returns a new network object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkCreateXML(virConnectPtr conn, const char *xmlDesc)
|
|
|
|
{
|
|
|
|
virNetworkPtr ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (xmlDesc == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->networkCreateXML != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->networkCreateXML(conn, xmlDesc);
|
|
|
|
if (ret != NULL)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkDefineXML:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @xml: the XML description for the network, preferably in UTF-8
|
|
|
|
*
|
|
|
|
* Define a network, but does not create it
|
|
|
|
*
|
|
|
|
* Returns NULL in case of error, a pointer to the network otherwise
|
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkDefineXML(virConnectPtr conn, const char *xml) {
|
|
|
|
virNetworkPtr ret = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->networkDefineXML != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->networkDefineXML(conn, xml);
|
|
|
|
if (ret)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkUndefine:
|
|
|
|
* @network: pointer to a defined network
|
|
|
|
*
|
|
|
|
* Undefine a network but does not stop it if it is running
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkUndefine(virNetworkPtr network) {
|
|
|
|
int ret, i;
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = network->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go though the driver registered entry points */
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->networkUndefine != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->networkUndefine(network);
|
|
|
|
if (ret >= 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkCreate:
|
|
|
|
* @network: pointer to a defined network
|
|
|
|
*
|
|
|
|
* Create and start a defined network. If the call succeed the network
|
|
|
|
* moves from the defined to the running networks pools.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkCreate(virNetworkPtr network) {
|
|
|
|
int i, ret = -1;
|
|
|
|
virConnectPtr conn;
|
|
|
|
if (network == NULL) {
|
|
|
|
TODO
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = network->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->networkCreate != NULL)) {
|
|
|
|
ret = conn->networkDrivers[i]->networkCreate(network);
|
|
|
|
if (ret == 0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkDestroy:
|
|
|
|
* @network: a network object
|
|
|
|
*
|
|
|
|
* Destroy the network object. The running instance is shutdown if not down
|
|
|
|
* already and all resources used by it are given back to the hypervisor.
|
|
|
|
* The data structure is freed and should not be used thereafter if the
|
|
|
|
* call does not return an error.
|
|
|
|
* This function may requires priviledged access
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkDestroy(virNetworkPtr network)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = network->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go though the driver registered entry points
|
|
|
|
*/
|
|
|
|
for (i = 0;i < conn->nb_drivers;i++) {
|
|
|
|
if ((conn->networkDrivers[i] != NULL) &&
|
|
|
|
(conn->networkDrivers[i]->networkDestroy != NULL)) {
|
|
|
|
if (conn->networkDrivers[i]->networkDestroy(network) == 0)
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkFree:
|
|
|
|
* @network: a network object
|
|
|
|
*
|
|
|
|
* Free the network object. The running instance is kept alive.
|
|
|
|
* The data structure is freed and should not be used thereafter.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkFree(virNetworkPtr network)
|
|
|
|
{
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (virFreeNetwork(network->conn, network) < 0)
|
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkGetName:
|
|
|
|
* @network: a network object
|
|
|
|
*
|
|
|
|
* Get the public name for that network
|
|
|
|
*
|
|
|
|
* Returns a pointer to the name or NULL, the string need not be deallocated
|
|
|
|
* its lifetime will be the same as the network object.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
virNetworkGetName(virNetworkPtr network)
|
|
|
|
{
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (network->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkGetUUID:
|
|
|
|
* @network: a network object
|
|
|
|
* @uuid: pointer to a VIR_UUID_BUFLEN bytes array
|
|
|
|
*
|
|
|
|
* Get the UUID for a network
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkGetUUID(virNetworkPtr network, unsigned char *uuid)
|
|
|
|
{
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(uuid, &network->uuid[0], VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkGetUUIDString:
|
|
|
|
* @network: a network object
|
|
|
|
* @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
|
|
|
|
*
|
|
|
|
* Get the UUID for a network as string. For more information about
|
|
|
|
* UUID see RFC4122.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkGetUUIDString(virNetworkPtr network, char *buf)
|
|
|
|
{
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (buf == NULL) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virNetworkGetUUID(network, &uuid[0]))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
snprintf(buf, VIR_UUID_STRING_BUFLEN,
|
|
|
|
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
|
|
uuid[0], uuid[1], uuid[2], uuid[3],
|
|
|
|
uuid[4], uuid[5], uuid[6], uuid[7],
|
|
|
|
uuid[8], uuid[9], uuid[10], uuid[11],
|
|
|
|
uuid[12], uuid[13], uuid[14], uuid[15]);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkGetXMLDesc:
|
|
|
|
* @network: a network object
|
|
|
|
* @flags: and OR'ed set of extraction flags, not used yet
|
|
|
|
*
|
|
|
|
* Provide an XML description of the network. The description may be reused
|
|
|
|
* later to relaunch the network with virNetworkCreateXML().
|
|
|
|
*
|
|
|
|
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virNetworkGetXMLDesc(virNetworkPtr network, int flags)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *ret = NULL;
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0;i < network->conn->nb_network_drivers;i++) {
|
|
|
|
if ((network->conn->networkDrivers[i] != NULL) &&
|
|
|
|
(network->conn->networkDrivers[i]->networkDumpXML != NULL)) {
|
|
|
|
ret = network->conn->networkDrivers[i]->networkDumpXML(network, flags);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret) {
|
|
|
|
virLibConnError(network->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|