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
|
|
|
|
*
|
2008-02-04 19:31:30 +00:00
|
|
|
* Copyright (C) 2005,2006,2008 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>
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
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>
|
2007-08-21 09:31:12 +00:00
|
|
|
#include <assert.h>
|
2008-03-11 14:49:04 +00:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-04-28 18:29:26 +00:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/xpath.h>
|
2007-11-14 11:40:57 +00:00
|
|
|
#include <libxml/uri.h>
|
2007-12-07 14:56:37 +00:00
|
|
|
#include "getpass.h"
|
|
|
|
|
2008-01-05 16:06:36 +00:00
|
|
|
#ifdef HAVE_WINSOCK2_H
|
2007-12-07 14:56:37 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
2006-04-28 18:29:26 +00:00
|
|
|
|
2005-11-02 12:50:21 +00:00
|
|
|
#include "internal.h"
|
2006-03-20 17:49:28 +00:00
|
|
|
#include "driver.h"
|
2007-03-15 07:43:16 +00:00
|
|
|
|
2007-08-09 20:19:12 +00:00
|
|
|
#include "uuid.h"
|
2008-02-20 16:54:35 +00:00
|
|
|
#include "util.h"
|
2006-06-06 03:32:51 +00:00
|
|
|
#include "test.h"
|
2007-04-04 14:19:49 +00:00
|
|
|
#include "xen_unified.h"
|
2007-06-11 11:43:41 +00:00
|
|
|
#include "remote_internal.h"
|
2007-06-27 00:12:29 +00:00
|
|
|
#include "qemu_driver.h"
|
2008-02-20 15:34:52 +00:00
|
|
|
#include "storage_driver.h"
|
2007-07-17 14:40:26 +00:00
|
|
|
#ifdef WITH_OPENVZ
|
|
|
|
#include "openvz_driver.h"
|
|
|
|
#endif
|
2008-03-21 15:03:37 +00:00
|
|
|
#ifdef WITH_LXC
|
|
|
|
#include "lxc_driver.h"
|
|
|
|
#endif
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2005-11-02 12:50:21 +00:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* - use lock to protect against concurrent accesses ?
|
2008-04-04 07:58:29 +00:00
|
|
|
* - use reference counting to guarantee coherent pointer state ?
|
2005-11-02 12:50:21 +00:00
|
|
|
*/
|
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
static virDriverPtr virDriverTab[MAX_DRIVERS];
|
2007-03-08 14:53:41 +00:00
|
|
|
static int virDriverTabCount = 0;
|
2007-02-14 15:37:18 +00:00
|
|
|
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
|
2007-03-08 14:53:41 +00:00
|
|
|
static int virNetworkDriverTabCount = 0;
|
2008-02-20 15:06:53 +00:00
|
|
|
static virStorageDriverPtr virStorageDriverTab[MAX_DRIVERS];
|
|
|
|
static int virStorageDriverTabCount = 0;
|
2007-06-26 22:56:14 +00:00
|
|
|
static virStateDriverPtr virStateDriverTab[MAX_DRIVERS];
|
|
|
|
static int virStateDriverTabCount = 0;
|
2006-03-27 15:24:36 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
|
2008-01-19 18:36:01 +00:00
|
|
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
|
|
|
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
|
|
|
|
2007-07-12 08:34:51 +00:00
|
|
|
#ifdef ENABLE_DEBUG
|
2008-01-19 18:36:01 +00:00
|
|
|
int debugFlag = 0;
|
|
|
|
#endif
|
2007-07-12 08:34:51 +00:00
|
|
|
|
2008-03-11 14:49:04 +00:00
|
|
|
#if defined(POLKIT_AUTH)
|
|
|
|
static int virConnectAuthGainPolkit(const char *privilege) {
|
|
|
|
const char *const args[] = {
|
|
|
|
POLKIT_AUTH, "--obtain", privilege, NULL
|
|
|
|
};
|
|
|
|
int childpid, status, ret;
|
|
|
|
|
|
|
|
/* Root has all rights */
|
|
|
|
if (getuid() == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((childpid = fork()) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!childpid) {
|
|
|
|
execvp(args[0], (char **)args);
|
|
|
|
_exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ret = waitpid(childpid, &status, 0) == -1) && errno == EINTR);
|
|
|
|
if (ret == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WIFEXITED(status) ||
|
|
|
|
(WEXITSTATUS(status) != 0 && WEXITSTATUS(status) != 1)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-05 18:55:04 +00:00
|
|
|
static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred,
|
|
|
|
unsigned int ncred,
|
|
|
|
void *cbdata ATTRIBUTE_UNUSED) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < ncred ; i++) {
|
|
|
|
char buf[1024];
|
|
|
|
char *bufptr = buf;
|
2008-01-21 14:09:51 +00:00
|
|
|
size_t len;
|
2007-12-05 18:55:04 +00:00
|
|
|
|
|
|
|
switch (cred[i].type) {
|
2008-02-20 16:54:35 +00:00
|
|
|
case VIR_CRED_EXTERNAL: {
|
|
|
|
if (STRNEQ(cred[i].challenge, "PolicyKit"))
|
|
|
|
return -1;
|
|
|
|
|
2008-04-04 15:09:19 +00:00
|
|
|
#if defined(POLKIT_AUTH)
|
2008-03-11 14:49:04 +00:00
|
|
|
if (virConnectAuthGainPolkit(cred[i].prompt) < 0)
|
2008-02-20 16:54:35 +00:00
|
|
|
return -1;
|
2008-04-04 15:09:19 +00:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Ignore & carry on. Although we can't auth
|
|
|
|
* directly, the user may have authenticated
|
|
|
|
* themselves already outside context of libvirt
|
|
|
|
*/
|
|
|
|
#endif
|
2008-02-20 16:54:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-04-04 15:09:19 +00:00
|
|
|
|
2007-12-05 18:55:04 +00:00
|
|
|
case VIR_CRED_USERNAME:
|
|
|
|
case VIR_CRED_AUTHNAME:
|
|
|
|
case VIR_CRED_ECHOPROMPT:
|
|
|
|
case VIR_CRED_REALM:
|
2008-02-20 16:54:35 +00:00
|
|
|
if (printf("%s:", cred[i].prompt) < 0)
|
|
|
|
return -1;
|
|
|
|
if (fflush(stdout) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2007-12-05 18:55:04 +00:00
|
|
|
if (!fgets(buf, sizeof(buf), stdin)) {
|
|
|
|
if (feof(stdin)) { /* Treat EOF as "" */
|
|
|
|
buf[0] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2008-01-21 14:09:51 +00:00
|
|
|
len = strlen(buf);
|
|
|
|
if (len != 0 && buf[len-1] == '\n')
|
|
|
|
buf[len-1] = '\0';
|
2007-12-05 18:55:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_CRED_PASSPHRASE:
|
|
|
|
case VIR_CRED_NOECHOPROMPT:
|
2008-02-20 16:54:35 +00:00
|
|
|
if (printf("%s:", cred[i].prompt) < 0)
|
|
|
|
return -1;
|
|
|
|
if (fflush(stdout) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2007-12-05 18:55:04 +00:00
|
|
|
bufptr = getpass("");
|
|
|
|
if (!bufptr)
|
|
|
|
return -1;
|
|
|
|
break;
|
2007-12-15 17:15:12 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
2007-12-05 18:55:04 +00:00
|
|
|
}
|
|
|
|
|
2008-05-22 15:12:25 +00:00
|
|
|
if (cred[i].type != VIR_CRED_EXTERNAL) {
|
|
|
|
if (STREQ(bufptr, "") && cred[i].defresult)
|
|
|
|
cred[i].result = strdup(cred[i].defresult);
|
|
|
|
else
|
|
|
|
cred[i].result = strdup(bufptr);
|
|
|
|
if (!cred[i].result)
|
|
|
|
return -1;
|
|
|
|
cred[i].resultlen = strlen(cred[i].result);
|
|
|
|
}
|
2007-12-05 18:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't typically want VIR_CRED_USERNAME. It enables you to authenticate
|
|
|
|
* as one user, and act as another. It just results in annoying
|
|
|
|
* prompts for the username twice & is very rarely what you want
|
|
|
|
*/
|
|
|
|
static int virConnectCredTypeDefault[] = {
|
|
|
|
VIR_CRED_AUTHNAME,
|
|
|
|
VIR_CRED_ECHOPROMPT,
|
|
|
|
VIR_CRED_REALM,
|
|
|
|
VIR_CRED_PASSPHRASE,
|
|
|
|
VIR_CRED_NOECHOPROMPT,
|
2008-02-20 16:54:35 +00:00
|
|
|
VIR_CRED_EXTERNAL,
|
2007-12-05 18:55:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static virConnectAuth virConnectAuthDefault = {
|
|
|
|
virConnectCredTypeDefault,
|
|
|
|
sizeof(virConnectCredTypeDefault)/sizeof(int),
|
|
|
|
virConnectAuthCallbackDefault,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* virConnectAuthPtrDefault
|
|
|
|
*
|
|
|
|
* A default implementation of the authentication callbacks. This
|
|
|
|
* implementation is suitable for command line based tools. It will
|
|
|
|
* prompt for username, passwords, realm and one time keys as needed.
|
|
|
|
* It will print on STDOUT, and read from STDIN. If this is not
|
|
|
|
* suitable for the application's needs an alternative implementation
|
|
|
|
* should be provided.
|
|
|
|
*/
|
|
|
|
virConnectAuthPtr virConnectAuthPtrDefault = &virConnectAuthDefault;
|
|
|
|
|
2007-12-07 14:56:37 +00:00
|
|
|
#if HAVE_WINSOCK2_H
|
|
|
|
static int
|
|
|
|
winsock_init (void)
|
|
|
|
{
|
|
|
|
WORD winsock_version, err;
|
|
|
|
WSADATA winsock_data;
|
|
|
|
|
|
|
|
/* http://msdn2.microsoft.com/en-us/library/ms742213.aspx */
|
|
|
|
winsock_version = MAKEWORD (2, 2);
|
|
|
|
err = WSAStartup (winsock_version, &winsock_data);
|
|
|
|
if (err != 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2008-01-19 18:36:01 +00:00
|
|
|
#ifdef ENABLE_DEBUG
|
|
|
|
char *debugEnv;
|
|
|
|
#endif
|
2006-03-27 15:24:36 +00:00
|
|
|
if (initialized)
|
|
|
|
return(0);
|
2006-03-28 14:41:04 +00:00
|
|
|
initialized = 1;
|
2006-03-27 15:24:36 +00:00
|
|
|
|
2008-01-19 18:36:01 +00:00
|
|
|
#ifdef ENABLE_DEBUG
|
|
|
|
debugEnv = getenv("LIBVIRT_DEBUG");
|
|
|
|
if (debugEnv && *debugEnv && *debugEnv != '0')
|
|
|
|
debugFlag = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DEBUG0("register drivers");
|
|
|
|
|
2007-12-07 14:56:37 +00:00
|
|
|
#if HAVE_WINSOCK2_H
|
|
|
|
if (winsock_init () == -1) return -1;
|
|
|
|
#endif
|
|
|
|
|
2006-09-21 15:24:37 +00:00
|
|
|
if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR))
|
|
|
|
return (-1);
|
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
/*
|
2007-04-04 14:19:49 +00:00
|
|
|
* Note that the order is important: the first ones have a higher
|
|
|
|
* priority when calling virConnectOpen.
|
2006-03-27 15:24:36 +00:00
|
|
|
*/
|
2007-03-15 07:43:16 +00:00
|
|
|
#ifdef WITH_TEST
|
2007-04-04 14:19:49 +00:00
|
|
|
if (testRegister() == -1) return -1;
|
2007-03-15 07:43:16 +00:00
|
|
|
#endif
|
2008-02-05 19:27:37 +00:00
|
|
|
#ifdef WITH_QEMU
|
2007-06-26 23:48:46 +00:00
|
|
|
if (qemudRegister() == -1) return -1;
|
2007-03-15 07:43:16 +00:00
|
|
|
#endif
|
2007-04-18 10:14:07 +00:00
|
|
|
#ifdef WITH_XEN
|
|
|
|
if (xenUnifiedRegister () == -1) return -1;
|
2007-06-20 10:01:14 +00:00
|
|
|
#endif
|
2007-07-17 13:27:26 +00:00
|
|
|
#ifdef WITH_OPENVZ
|
|
|
|
if (openvzRegister() == -1) return -1;
|
2008-03-21 15:03:37 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_LXC
|
|
|
|
if (lxcRegister() == -1) return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
#endif
|
2008-02-20 15:34:52 +00:00
|
|
|
if (storageRegister() == -1) return -1;
|
2007-06-20 10:01:14 +00:00
|
|
|
#ifdef WITH_REMOTE
|
|
|
|
if (remoteRegister () == -1) return -1;
|
2007-04-18 10:14:07 +00:00
|
|
|
#endif
|
2007-02-14 01:40:09 +00:00
|
|
|
|
2006-03-27 15:24:36 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
/**
|
|
|
|
* virLibConnError:
|
|
|
|
* @conn: the connection if available
|
2007-06-07 13:05:00 +00:00
|
|
|
* @error: the error number
|
2006-02-27 16:27:18 +00:00
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-07 13:05:00 +00:00
|
|
|
* virLibConnWarning:
|
2006-02-27 16:27:18 +00:00
|
|
|
* @conn: the connection if available
|
2007-06-07 13:05:00 +00:00
|
|
|
* @error: the error number
|
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the connection level
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virLibConnWarning(virConnectPtr conn, virErrorNumber error, const char *info)
|
|
|
|
{
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
|
|
if (error == VIR_ERR_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
errmsg = __virErrorMsg(error, info);
|
|
|
|
__virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_WARNING,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLibDomainError:
|
|
|
|
* @domain: the domain if available
|
|
|
|
* @error: the error number
|
2006-02-27 16:27:18 +00:00
|
|
|
* @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
|
2008-04-04 07:58:29 +00:00
|
|
|
* @error: the error number
|
2007-02-14 15:37:18 +00:00
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
/**
|
|
|
|
* virLibStoragePoolError:
|
|
|
|
* @conn: the connection if available
|
2008-04-04 07:58:29 +00:00
|
|
|
* @error: the error number
|
2008-02-20 15:06:53 +00:00
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the connection level
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virLibStoragePoolError(virStoragePoolPtr pool, 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_STORAGE_POOL)
|
|
|
|
conn = pool->conn;
|
|
|
|
|
|
|
|
__virRaiseError(conn, NULL, NULL, VIR_FROM_STORAGE, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLibStorageVolError:
|
|
|
|
* @conn: the connection if available
|
2008-04-04 07:58:29 +00:00
|
|
|
* @error: the error number
|
2008-02-20 15:06:53 +00:00
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the connection level
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virLibStorageVolError(virStorageVolPtr vol, 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_STORAGE_VOL)
|
|
|
|
conn = vol->conn;
|
|
|
|
|
|
|
|
__virRaiseError(conn, NULL, NULL, VIR_FROM_STORAGE, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2007-03-08 14:53:41 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return(-1);
|
2007-03-08 14:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virNetworkDriverTabCount >= MAX_DRIVERS) {
|
2008-04-10 16:54:54 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
2007-03-08 14:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virNetworkDriverTab[virNetworkDriverTabCount] = driver;
|
|
|
|
return virNetworkDriverTabCount++;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
/**
|
|
|
|
* virRegisterStorageDriver:
|
|
|
|
* @driver: pointer to a storage driver block
|
|
|
|
*
|
|
|
|
* Register a storage virtualization driver
|
|
|
|
*
|
|
|
|
* Returns the driver priority or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virRegisterStorageDriver(virStorageDriverPtr driver)
|
|
|
|
{
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStorageDriverTabCount >= MAX_DRIVERS) {
|
2008-04-10 16:54:54 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-02-20 15:06:53 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
virStorageDriverTab[virStorageDriverTabCount] = driver;
|
|
|
|
return virStorageDriverTabCount++;
|
|
|
|
}
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2007-03-08 14:53:41 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return(-1);
|
2007-03-08 14:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virDriverTabCount >= MAX_DRIVERS) {
|
2008-04-10 16:54:54 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
2007-03-08 14:53:41 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (driver->no < 0) {
|
2008-04-10 16:54:54 +00:00
|
|
|
virLibConnError
|
2007-04-04 14:19:49 +00:00
|
|
|
(NULL, VIR_ERR_INVALID_ARG,
|
|
|
|
"virRegisterDriver: tried to register an internal Xen driver");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-03-08 14:53:41 +00:00
|
|
|
virDriverTab[virDriverTabCount] = driver;
|
|
|
|
return virDriverTabCount++;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-26 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* virRegisterStateDriver:
|
|
|
|
* @driver: pointer to a driver block
|
|
|
|
*
|
|
|
|
* Register a virtualization driver
|
|
|
|
*
|
|
|
|
* Returns the driver priority or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virRegisterStateDriver(virStateDriverPtr driver)
|
|
|
|
{
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStateDriverTabCount >= MAX_DRIVERS) {
|
2008-04-10 16:54:54 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2007-06-26 22:56:14 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
virStateDriverTab[virStateDriverTabCount] = driver;
|
|
|
|
return virStateDriverTabCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __virStateInitialize(void) {
|
|
|
|
int i, ret = 0;
|
|
|
|
|
2007-06-26 23:48:46 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
2007-06-26 22:56:14 +00:00
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0 ; i < virStateDriverTabCount ; i++) {
|
2007-10-27 01:23:28 +00:00
|
|
|
if (virStateDriverTab[i]->initialize &&
|
|
|
|
virStateDriverTab[i]->initialize() < 0)
|
2007-06-26 22:56:14 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __virStateCleanup(void) {
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < virStateDriverTabCount ; i++) {
|
2007-10-27 01:23:28 +00:00
|
|
|
if (virStateDriverTab[i]->cleanup &&
|
|
|
|
virStateDriverTab[i]->cleanup() < 0)
|
2007-06-26 22:56:14 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __virStateReload(void) {
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < virStateDriverTabCount ; i++) {
|
2007-10-27 01:23:28 +00:00
|
|
|
if (virStateDriverTab[i]->reload &&
|
|
|
|
virStateDriverTab[i]->reload() < 0)
|
2007-06-26 22:56:14 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __virStateActive(void) {
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < virStateDriverTabCount ; i++) {
|
2007-10-27 01:23:28 +00:00
|
|
|
if (virStateDriverTab[i]->active &&
|
|
|
|
virStateDriverTab[i]->active())
|
2007-06-26 22:56:14 +00:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-13 06:30:58 +00:00
|
|
|
int __virStateSigDispatcher(siginfo_t *siginfo) {
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < virStateDriverTabCount ; i++) {
|
|
|
|
if (virStateDriverTab[i]->sigHandler &&
|
|
|
|
virStateDriverTab[i]->sigHandler(siginfo))
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-26 22:56:14 +00:00
|
|
|
|
|
|
|
|
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
|
2008-04-04 07:58:29 +00:00
|
|
|
* @type is unknown or not available, an error code will be returned and
|
2005-12-08 15:08:46 +00:00
|
|
|
* @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;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("libVir=%p, type=%s, typeVer=%p", libVer, type, typeVer);
|
2006-06-13 16:31:44 +00:00
|
|
|
|
2006-03-28 14:41:04 +00:00
|
|
|
if (!initialized)
|
2006-09-21 15:24:37 +00:00
|
|
|
if (virInitialize() < 0)
|
2008-04-10 16:54:54 +00:00
|
|
|
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)
|
2008-04-10 16:54:54 +00:00
|
|
|
type = "Xen";
|
|
|
|
for (i = 0;i < virDriverTabCount;i++) {
|
|
|
|
if ((virDriverTab[i] != NULL) &&
|
2008-05-14 19:51:24 +00:00
|
|
|
(STRCASEEQ(virDriverTab[i]->name, type))) {
|
2008-04-10 16:54:54 +00:00
|
|
|
*typeVer = virDriverTab[i]->ver;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-08 14:53:41 +00:00
|
|
|
if (i >= virDriverTabCount) {
|
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
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
static virConnectPtr
|
2007-12-05 18:28:05 +00:00
|
|
|
do_open (const char *name,
|
|
|
|
virConnectAuthPtr auth,
|
|
|
|
int flags)
|
2006-03-15 12:13:25 +00:00
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
int i, res;
|
2005-12-05 11:16:07 +00:00
|
|
|
virConnectPtr ret = NULL;
|
2007-11-14 11:40:57 +00:00
|
|
|
xmlURIPtr uri;
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2008-02-26 07:05:18 +00:00
|
|
|
/*
|
|
|
|
* If no URI is passed, then check for an environment string if not
|
|
|
|
* available probe the compiled in drivers to find a default hypervisor
|
|
|
|
* if detectable.
|
|
|
|
*/
|
|
|
|
if (!name || name[0] == '\0') {
|
|
|
|
char *defname = getenv("LIBVIRT_DEFAULT_URI");
|
|
|
|
if (defname && *defname) {
|
2008-04-10 16:54:54 +00:00
|
|
|
DEBUG("Using LIBVIRT_DEFAULT_URI %s", defname);
|
2008-02-26 07:05:18 +00:00
|
|
|
name = defname;
|
|
|
|
} else {
|
2008-04-10 16:54:54 +00:00
|
|
|
const char *use = NULL;
|
|
|
|
const char *latest;
|
|
|
|
int probes = 0;
|
|
|
|
for (i = 0; i < virNetworkDriverTabCount; i++) {
|
|
|
|
if ((virDriverTab[i]->probe != NULL) &&
|
|
|
|
((latest = virDriverTab[i]->probe()) != NULL)) {
|
|
|
|
probes++;
|
|
|
|
|
|
|
|
DEBUG("Probed %s", latest);
|
|
|
|
/*
|
|
|
|
* if running a xen kernel, give it priority over
|
|
|
|
* QEmu emulation
|
|
|
|
*/
|
|
|
|
if (STREQ(latest, "xen:///"))
|
|
|
|
use = latest;
|
|
|
|
else if (use == NULL)
|
|
|
|
use = latest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (use == NULL) {
|
|
|
|
name = "xen:///";
|
|
|
|
DEBUG("Could not probe any hypervisor defaulting to %s",
|
|
|
|
name);
|
|
|
|
} else {
|
|
|
|
name = use;
|
|
|
|
DEBUG("Using %s as default URI, %d hypervisor found",
|
|
|
|
use, probes);
|
|
|
|
}
|
|
|
|
}
|
2008-02-26 07:05:18 +00:00
|
|
|
}
|
2007-07-05 13:49:17 +00:00
|
|
|
|
|
|
|
/* Convert xen -> xen:/// for back compat */
|
2008-05-14 19:51:24 +00:00
|
|
|
if (STRCASEEQ(name, "xen"))
|
2007-07-05 13:49:17 +00:00
|
|
|
name = "xen:///";
|
|
|
|
|
2007-11-14 11:40:57 +00:00
|
|
|
/* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
|
|
|
|
* former. This allows URIs such as xen://localhost to work.
|
|
|
|
*/
|
|
|
|
if (STREQ (name, "xen://"))
|
|
|
|
name = "xen:///";
|
|
|
|
|
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"));
|
2007-11-14 11:40:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uri = xmlParseURI (name);
|
|
|
|
if (!uri) {
|
|
|
|
virLibConnError (ret, VIR_ERR_INVALID_ARG,
|
|
|
|
_("could not parse connection URI"));
|
2006-03-20 17:49:28 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2008-01-19 18:36:01 +00:00
|
|
|
DEBUG("name \"%s\" to URI components:\n"
|
|
|
|
" scheme %s\n"
|
|
|
|
" opaque %s\n"
|
|
|
|
" authority %s\n"
|
|
|
|
" server %s\n"
|
|
|
|
" user %s\n"
|
|
|
|
" port %d\n"
|
|
|
|
" path %s\n",
|
|
|
|
name,
|
|
|
|
uri->scheme, uri->opaque, uri->authority, uri->server,
|
|
|
|
uri->user, uri->port, uri->path);
|
2007-07-12 08:34:51 +00:00
|
|
|
|
2007-11-14 11:40:57 +00:00
|
|
|
ret->name = strdup (name);
|
|
|
|
if (!ret->name) {
|
2008-02-04 19:31:30 +00:00
|
|
|
virLibConnError (ret, VIR_ERR_NO_MEMORY, _("allocating conn->name"));
|
2007-11-14 11:40:57 +00:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2008-02-20 16:54:35 +00:00
|
|
|
/* Cleansing flags */
|
|
|
|
ret->flags = flags & VIR_CONNECT_RO;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
for (i = 0; i < virDriverTabCount; i++) {
|
2008-01-19 18:36:01 +00:00
|
|
|
DEBUG("trying driver %d (%s) ...",
|
|
|
|
i, virDriverTab[i]->name);
|
2007-12-05 18:28:05 +00:00
|
|
|
res = virDriverTab[i]->open (ret, uri, auth, flags);
|
2008-01-19 18:36:01 +00:00
|
|
|
DEBUG("driver %d %s returned %s",
|
|
|
|
i, virDriverTab[i]->name,
|
|
|
|
res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
|
|
|
|
(res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
|
|
|
|
(res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
|
2007-04-04 14:19:49 +00:00
|
|
|
if (res == VIR_DRV_OPEN_ERROR) goto failed;
|
|
|
|
else if (res == VIR_DRV_OPEN_SUCCESS) {
|
|
|
|
ret->driver = virDriverTab[i];
|
|
|
|
break;
|
|
|
|
}
|
2006-03-29 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (!ret->driver) {
|
2007-06-20 17:25:39 +00:00
|
|
|
/* If we reach here, then all drivers declined the connection. */
|
|
|
|
virLibConnError (NULL, VIR_ERR_NO_CONNECT, name);
|
2007-04-04 14:19:49 +00:00
|
|
|
goto failed;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
for (i = 0; i < virNetworkDriverTabCount; i++) {
|
2007-12-05 18:28:05 +00:00
|
|
|
res = virNetworkDriverTab[i]->open (ret, uri, auth, flags);
|
2008-01-19 18:36:01 +00:00
|
|
|
DEBUG("network driver %d %s returned %s",
|
|
|
|
i, virNetworkDriverTab[i]->name,
|
|
|
|
res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
|
|
|
|
(res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
|
|
|
|
(res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
|
2007-06-07 13:05:00 +00:00
|
|
|
if (res == VIR_DRV_OPEN_ERROR) {
|
2007-07-27 23:23:00 +00:00
|
|
|
if (STREQ(virNetworkDriverTab[i]->name, "remote")) {
|
2008-02-05 19:27:37 +00:00
|
|
|
virLibConnWarning (NULL, VIR_WAR_NO_NETWORK,
|
2007-07-27 23:23:00 +00:00
|
|
|
"Is the daemon running ?");
|
|
|
|
}
|
2007-06-07 13:05:00 +00:00
|
|
|
break;
|
|
|
|
} else if (res == VIR_DRV_OPEN_SUCCESS) {
|
2007-04-04 14:19:49 +00:00
|
|
|
ret->networkDriver = virNetworkDriverTab[i];
|
|
|
|
break;
|
|
|
|
}
|
2006-03-29 12:46:03 +00:00
|
|
|
}
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
/* Secondary driver for storage. Optional */
|
|
|
|
for (i = 0; i < virStorageDriverTabCount; i++) {
|
|
|
|
res = virStorageDriverTab[i]->open (ret, uri, auth, flags);
|
|
|
|
#ifdef ENABLE_DEBUG
|
|
|
|
DEBUG("storage driver %d %s returned %s",
|
|
|
|
i, virStorageDriverTab[i]->name,
|
|
|
|
res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
|
|
|
|
(res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
|
|
|
|
(res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
|
|
|
|
#endif
|
|
|
|
if (res == VIR_DRV_OPEN_ERROR) {
|
|
|
|
if (0 && STREQ(virStorageDriverTab[i]->name, "remote")) {
|
|
|
|
virLibConnWarning (NULL, VIR_WAR_NO_STORAGE,
|
|
|
|
"Is the daemon running ?");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else if (res == VIR_DRV_OPEN_SUCCESS) {
|
|
|
|
ret->storageDriver = virStorageDriverTab[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 11:40:57 +00:00
|
|
|
xmlFreeURI (uri);
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
return ret;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
failed:
|
2007-04-04 14:19:49 +00:00
|
|
|
if (ret->driver) ret->driver->close (ret);
|
2007-11-14 11:40:57 +00:00
|
|
|
if (uri) xmlFreeURI(uri);
|
2008-04-10 16:54:54 +00:00
|
|
|
virUnrefConnect(ret);
|
2007-11-14 11:40:57 +00:00
|
|
|
return NULL;
|
2005-12-01 16:35:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
/**
|
|
|
|
* virConnectOpen:
|
2007-06-20 17:25:39 +00:00
|
|
|
* @name: URI of the hypervisor
|
2007-04-04 14:19:49 +00:00
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* This function should be called first to get a connection to the
|
2007-04-04 14:19:49 +00:00
|
|
|
* Hypervisor and xen store
|
|
|
|
*
|
|
|
|
* Returns a pointer to the hypervisor connection or NULL in case of error
|
2007-06-20 17:25:39 +00:00
|
|
|
*
|
|
|
|
* URIs are documented at http://libvirt.org/uri.html
|
2007-04-04 14:19:49 +00:00
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virConnectOpen (const char *name)
|
|
|
|
{
|
2008-02-20 16:54:35 +00:00
|
|
|
if (!initialized)
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("name=%s", name);
|
2007-12-05 18:28:05 +00:00
|
|
|
return do_open (name, NULL, 0);
|
2007-04-04 14:19:49 +00:00
|
|
|
}
|
|
|
|
|
2005-12-01 16:35:42 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virConnectOpenReadOnly:
|
2007-06-20 17:25:39 +00:00
|
|
|
* @name: URI of the hypervisor
|
2005-12-01 16:35:42 +00:00
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* This function should be called first to get a restricted connection to the
|
2008-04-04 07:58:29 +00:00
|
|
|
* library functionalities. The set of APIs usable are then restricted
|
2006-01-19 10:23:15 +00:00
|
|
|
* 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
|
2007-06-20 17:25:39 +00:00
|
|
|
*
|
|
|
|
* URIs are documented at http://libvirt.org/uri.html
|
2005-12-01 16:35:42 +00:00
|
|
|
*/
|
2005-12-05 11:16:07 +00:00
|
|
|
virConnectPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectOpenReadOnly(const char *name)
|
|
|
|
{
|
2008-02-20 16:54:35 +00:00
|
|
|
if (!initialized)
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("name=%s", name);
|
2007-12-05 18:28:05 +00:00
|
|
|
return do_open (name, NULL, VIR_CONNECT_RO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectOpenAuth:
|
|
|
|
* @name: URI of the hypervisor
|
|
|
|
* @auth: Authenticate callback parameters
|
|
|
|
* @flags: Open flags
|
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* This function should be called first to get a connection to the
|
2008-03-17 10:27:31 +00:00
|
|
|
* Hypervisor. If necessary, authentication will be performed fetching
|
2007-12-05 18:28:05 +00:00
|
|
|
* credentials via the callback
|
|
|
|
*
|
|
|
|
* Returns a pointer to the hypervisor connection or NULL in case of error
|
|
|
|
*
|
|
|
|
* URIs are documented at http://libvirt.org/uri.html
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virConnectOpenAuth(const char *name,
|
|
|
|
virConnectAuthPtr auth,
|
|
|
|
int flags)
|
|
|
|
{
|
2008-02-20 16:54:35 +00:00
|
|
|
if (!initialized)
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
DEBUG("name=%s, auth=%p, flags=%d", name, auth, flags);
|
2007-12-05 18:28:05 +00:00
|
|
|
return do_open (name, auth, flags);
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2005-12-16 18:41:46 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn))
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
if (conn->networkDriver)
|
|
|
|
conn->networkDriver->close (conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
if (conn->storageDriver)
|
|
|
|
conn->storageDriver->close (conn);
|
2007-06-26 23:48:46 +00:00
|
|
|
conn->driver->close (conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2008-01-21 16:29:10 +00:00
|
|
|
if (virUnrefConnect(conn) < 0)
|
2006-04-09 13:11:22 +00:00
|
|
|
return (-1);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (0);
|
2005-11-02 12:50:21 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 09:03:55 +00:00
|
|
|
/* Not for public use. This function is part of the internal
|
|
|
|
* implementation of driver features in the remote case.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__virDrvSupportsFeature (virConnectPtr conn, int feature)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, feature=%d", conn, feature);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return VIR_DRV_SUPPORTS_FEATURE (conn->driver, conn, feature);
|
|
|
|
}
|
|
|
|
|
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.
|
2007-06-11 11:43:41 +00:00
|
|
|
*
|
|
|
|
* See also:
|
|
|
|
* http://www.redhat.com/archives/libvir-list/2007-February/msg00096.html
|
2005-12-08 13:26:52 +00:00
|
|
|
*/
|
|
|
|
const char *
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectGetType(virConnectPtr conn)
|
|
|
|
{
|
2006-06-13 18:29:42 +00:00
|
|
|
const char *ret;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
2006-06-13 16:31:44 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
if (conn->driver->type) {
|
|
|
|
ret = conn->driver->type (conn);
|
|
|
|
if (ret) return ret;
|
2006-06-13 16:31:44 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
return conn->driver->name;
|
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
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* Get the version level of the Hypervisor running. This may work only with
|
2008-03-17 10:27:31 +00:00
|
|
|
* hypervisor call, i.e. with privileged access to the hypervisor, not
|
2005-12-08 13:26:52 +00:00
|
|
|
* 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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, hvVer=%p", conn, hvVer);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->version)
|
|
|
|
return conn->driver->version (conn, hvVer);
|
2007-02-14 01:40:09 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
2005-12-02 14:16:21 +00:00
|
|
|
}
|
|
|
|
|
2007-06-26 11:42:46 +00:00
|
|
|
/**
|
|
|
|
* virConnectGetHostname:
|
|
|
|
* @conn: pointer to a hypervisor connection
|
|
|
|
*
|
|
|
|
* This returns the system hostname on which the hypervisor is
|
|
|
|
* running (the result of the gethostname(2) system call). If
|
|
|
|
* we are connected to a remote system, then this returns the
|
|
|
|
* hostname of the remote system.
|
|
|
|
*
|
|
|
|
* Returns the hostname which must be freed by the caller, or
|
|
|
|
* NULL if there was an error.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virConnectGetHostname (virConnectPtr conn)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2007-06-26 11:42:46 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-06-26 11:42:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->driver->getHostname)
|
|
|
|
return conn->driver->getHostname (conn);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectGetURI:
|
|
|
|
* @conn: pointer to a hypervisor connection
|
|
|
|
*
|
|
|
|
* This returns the URI (name) of the hypervisor connection.
|
|
|
|
* Normally this is the same as or similar to the string passed
|
|
|
|
* to the virConnectOpen/virConnectOpenReadOnly call, but
|
|
|
|
* the driver may make the URI canonical. If name == NULL
|
|
|
|
* was passed to virConnectOpen, then the driver will return
|
|
|
|
* a non-NULL URI which can be used to connect to the same
|
|
|
|
* hypervisor later.
|
|
|
|
*
|
|
|
|
* Returns the URI string which must be freed by the caller, or
|
|
|
|
* NULL if there was an error.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virConnectGetURI (virConnectPtr conn)
|
|
|
|
{
|
2007-11-14 11:40:57 +00:00
|
|
|
char *name;
|
|
|
|
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2007-06-26 11:42:46 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-06-26 11:42:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-14 11:40:57 +00:00
|
|
|
/* Drivers may override getURI, but if they don't then
|
|
|
|
* we provide a default implementation.
|
|
|
|
*/
|
2007-06-26 11:42:46 +00:00
|
|
|
if (conn->driver->getURI)
|
|
|
|
return conn->driver->getURI (conn);
|
|
|
|
|
2007-11-14 11:40:57 +00:00
|
|
|
name = strdup (conn->name);
|
|
|
|
if (!name) {
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return name;
|
2007-06-26 11:42:46 +00:00
|
|
|
}
|
|
|
|
|
2007-03-08 08:31:07 +00:00
|
|
|
/**
|
|
|
|
* virConnectGetMaxVcpus:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @type: value of the 'type' attribute in the <domain> element
|
|
|
|
*
|
2007-03-15 17:24:56 +00:00
|
|
|
* Provides the maximum number of virtual CPUs supported for a guest VM of a
|
2007-03-08 08:31:07 +00:00
|
|
|
* specific type. The 'type' parameter here corresponds to the 'type'
|
|
|
|
* attribute in the <domain> element of the XML.
|
|
|
|
*
|
|
|
|
* Returns the maximum of virtual CPU or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectGetMaxVcpus(virConnectPtr conn,
|
|
|
|
const char *type)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, type=%s", conn, type);
|
|
|
|
|
2007-03-08 08:31:07 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-03-08 08:31:07 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->getMaxVcpus)
|
|
|
|
return conn->driver->getMaxVcpus (conn, type);
|
2007-03-08 08:31:07 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
2007-03-08 08:31:07 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, ids=%p, maxids=%d", conn, ids, maxids);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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
|
|
|
|
2007-06-25 08:23:10 +00:00
|
|
|
if ((ids == NULL) || (maxids < 0)) {
|
2006-02-27 16:27:18 +00:00
|
|
|
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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->listDomains)
|
|
|
|
return conn->driver->listDomains (conn, ids, maxids);
|
2006-04-24 18:21:29 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->numOfDomains)
|
|
|
|
return conn->driver->numOfDomains (conn);
|
2006-04-24 18:21:29 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
2005-12-07 11:03:24 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 15:56:18 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetConnect:
|
|
|
|
* @dom: pointer to a domain
|
|
|
|
*
|
2007-06-29 13:23:13 +00:00
|
|
|
* Provides the connection pointer associated with a domain. The
|
2007-06-25 15:56:18 +00:00
|
|
|
* reference counter on the connection is not increased by this
|
|
|
|
* call.
|
|
|
|
*
|
2007-07-24 15:32:55 +00:00
|
|
|
* WARNING: When writing libvirt bindings in other languages, do
|
|
|
|
* not use this function. Instead, store the connection and
|
|
|
|
* the domain object together.
|
|
|
|
*
|
2007-06-25 15:56:18 +00:00
|
|
|
* Returns the virConnectPtr or NULL in case of failure.
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virDomainGetConnect (virDomainPtr dom)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("dom=%p", dom);
|
|
|
|
|
2007-06-25 15:56:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN (dom)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-06-25 15:56:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return dom->conn;
|
|
|
|
}
|
|
|
|
|
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
|
2008-03-21 15:03:37 +00:00
|
|
|
* @xmlDesc: string containing 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()
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function may requires privileged access to the hypervisor.
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
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
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, xmlDesc=%s, flags=%d", conn, xmlDesc, flags);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (NULL);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainCreateLinux)
|
|
|
|
return conn->driver->domainCreateLinux (conn, xmlDesc, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
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
|
|
|
|
*
|
2007-07-06 14:56:15 +00:00
|
|
|
* Returns a new domain object or NULL in case of failure. If the
|
|
|
|
* domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
|
2005-11-30 13:20:53 +00:00
|
|
|
*/
|
2005-12-05 11:16:07 +00:00
|
|
|
virDomainPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainLookupByID(virConnectPtr conn, int id)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, id=%d", conn, id);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainLookupByID)
|
|
|
|
return conn->driver->domainLookupByID (conn, id);
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
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.
|
|
|
|
*
|
2007-07-06 14:56:15 +00:00
|
|
|
* Returns a new domain object or NULL in case of failure. If the
|
|
|
|
* domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
|
2006-02-23 10:13:55 +00:00
|
|
|
*/
|
|
|
|
virDomainPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, uuid=%s", conn, uuid);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainLookupByUUID)
|
|
|
|
return conn->driver->domainLookupByUUID (conn, uuid);
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
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.
|
|
|
|
*
|
2007-07-06 14:56:15 +00:00
|
|
|
* Returns a new domain object or NULL in case of failure. If the
|
|
|
|
* domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
|
2006-05-22 14:38:33 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
|
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-05-22 14:38:33 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuidstr == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
/* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
|
|
|
|
* We needn't it here. Right?
|
2006-05-22 14:38:33 +00:00
|
|
|
*/
|
|
|
|
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);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
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) {
|
2008-04-10 16:54:54 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
2006-05-22 14:38:33 +00:00
|
|
|
}
|
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;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
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
|
|
|
*
|
2007-07-06 14:56:15 +00:00
|
|
|
* Returns a new domain object or NULL in case of failure. If the
|
|
|
|
* domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
|
2005-12-12 13:22:20 +00:00
|
|
|
*/
|
|
|
|
virDomainPtr
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, name=%s", conn, name);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainLookupByName)
|
|
|
|
return conn->driver->domainLookupByName (conn, name);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
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
|
2008-05-21 20:53:30 +00:00
|
|
|
* already and all resources used by it are given back to the hypervisor. This
|
|
|
|
* does not free the associated virDomainPtr object.
|
|
|
|
* This function may require privileged 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-06-14 17:07:00 +00:00
|
|
|
virConnectPtr conn;
|
2005-12-08 17:16:24 +00:00
|
|
|
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainDestroy)
|
|
|
|
return conn->driver->domainDestroy (domain);
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2008-01-21 16:29:10 +00:00
|
|
|
if (virUnrefDomain(domain) < 0)
|
2006-04-09 13:11:22 +00:00
|
|
|
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
|
2008-02-05 19:27:37 +00:00
|
|
|
* 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.
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function may requires privileged 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-06-14 17:07:00 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainSuspend)
|
|
|
|
return conn->driver->domainSuspend (domain);
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
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().
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function may requires privileged 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-14 17:07:00 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainResume)
|
|
|
|
return conn->driver->domainResume (domain);
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __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-01-20 10:00:08 +00:00
|
|
|
char filepath[4096];
|
2006-06-16 12:36:40 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, to=%s", domain, to);
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainSave)
|
|
|
|
return conn->driver->domainSave (domain, to);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
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
|
2008-02-05 19:27:37 +00:00
|
|
|
* @from: path to the
|
2006-01-18 10:37:08 +00:00
|
|
|
*
|
|
|
|
* 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-01-20 10:00:08 +00:00
|
|
|
char filepath[4096];
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, from=%s", conn, from);
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
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];
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainRestore)
|
|
|
|
return conn->driver->domainRestore (conn, from);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-11-22 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
char filepath[4096];
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, to=%s, flags=%d", domain, to, flags);
|
2006-11-22 17:48:29 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-11-22 17:48:29 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-11-22 17:48:29 +00:00
|
|
|
}
|
|
|
|
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];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainCoreDump)
|
|
|
|
return conn->driver->domainCoreDump (domain, to, flags);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
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
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2005-12-16 12:16:41 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainShutdown)
|
|
|
|
return conn->driver->domainShutdown (domain);
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
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
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, flags=%u", domain, flags);
|
2006-04-03 13:46:43 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-04-03 13:46:43 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-04-03 13:46:43 +00:00
|
|
|
|
2006-06-14 17:07:00 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainReboot)
|
|
|
|
return conn->driver->domainReboot (domain, flags);
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-04-03 13:46:43 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, uuid=%p", domain, uuid);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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
|
|
|
}
|
|
|
|
|
2008-04-09 14:03:01 +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
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* Get the UUID for a domain as string. For more information about
|
2006-05-22 14:38:33 +00:00
|
|
|
* 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];
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, buf=%p", domain, buf);
|
2006-08-16 16:29:46 +00:00
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-05-22 14:38:33 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (buf == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
if (virDomainGetUUID(domain, &uuid[0]))
|
2007-04-04 14:19:49 +00:00
|
|
|
return (-1);
|
2006-05-22 14:38:33 +00:00
|
|
|
|
2007-08-09 20:19:12 +00:00
|
|
|
virUUIDFormat(uuid, buf);
|
2006-05-22 14:38:33 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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)
|
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainGetOSType)
|
|
|
|
return conn->driver->domainGetOSType (domain);
|
2006-11-07 16:28:16 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
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
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2005-11-23 07:47:13 +00:00
|
|
|
* 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)
|
|
|
|
{
|
2006-06-16 12:36:40 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainGetMaxMemory)
|
|
|
|
return conn->driver->domainGetMaxMemory (domain);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return 0;
|
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
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2005-11-07 17:16:18 +00:00
|
|
|
* 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.
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function requires privileged 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
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, memory=%lu", domain, memory);
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-03-22 13:44:01 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-03-22 13:44:01 +00:00
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainSetMaxMemory)
|
|
|
|
return conn->driver->domainSetMaxMemory (domain, memory);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-04-13 17:18:49 +00:00
|
|
|
}
|
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
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2006-04-13 17:18:49 +00:00
|
|
|
* 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.
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function may requires privileged access to the hypervisor.
|
2006-04-13 17:18:49 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainSetMemory(virDomainPtr domain, unsigned long memory)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, memory=%lu", domain, memory);
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2006-04-13 17:18:49 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-04-13 17:18:49 +00:00
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-04-13 17:18:49 +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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainSetMemory)
|
|
|
|
return conn->driver->domainSetMemory (domain, memory);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
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
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2005-12-05 18:14:37 +00:00
|
|
|
* 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)
|
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, info=%p", domain, info);
|
2005-12-05 18:14:37 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, 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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainGetInfo)
|
|
|
|
return conn->driver->domainGetInfo (domain, info);
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +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
|
2007-09-30 13:09:07 +00:00
|
|
|
* @flags: an OR'ed set of virDomainXMLFlags
|
2006-02-20 23:08:47 +00:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, flags=%d", domain, flags);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2006-02-27 16:27:18 +00:00
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainDumpXML)
|
|
|
|
return conn->driver->domainDumpXML (domain, flags);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2006-02-20 23:08:47 +00:00
|
|
|
}
|
2006-03-29 12:46:03 +00:00
|
|
|
|
2007-08-21 09:31:12 +00:00
|
|
|
/**
|
|
|
|
* virDomainMigrate:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @dconn: destination host (a connection object)
|
|
|
|
* @flags: flags
|
|
|
|
* @dname: (optional) rename domain to this at destination
|
|
|
|
* @uri: (optional) dest hostname/URI as seen from the source host
|
|
|
|
* @bandwidth: (optional) specify migration bandwidth limit in Mbps
|
|
|
|
*
|
|
|
|
* Migrate the domain object from its current host to the destination
|
|
|
|
* host given by dconn (a connection to the destination host).
|
|
|
|
*
|
|
|
|
* Flags may be one of more of the following:
|
|
|
|
* VIR_MIGRATE_LIVE Attempt a live migration.
|
|
|
|
*
|
|
|
|
* If a hypervisor supports renaming domains during migration,
|
|
|
|
* then you may set the dname parameter to the new name (otherwise
|
|
|
|
* it keeps the same name). If this is not supported by the
|
|
|
|
* hypervisor, dname must be NULL or else you will get an error.
|
|
|
|
*
|
|
|
|
* Since typically the two hypervisors connect directly to each
|
|
|
|
* other in order to perform the migration, you may need to specify
|
|
|
|
* a path from the source to the destination. This is the purpose
|
|
|
|
* of the uri parameter. If uri is NULL, then libvirt will try to
|
|
|
|
* find the best method. Uri may specify the hostname or IP address
|
|
|
|
* of the destination host as seen from the source. Or uri may be
|
|
|
|
* a URI giving transport, hostname, user, port, etc. in the usual
|
|
|
|
* form. Refer to driver documentation for the particular URIs
|
|
|
|
* supported.
|
|
|
|
*
|
|
|
|
* The maximum bandwidth (in Mbps) that will be used to do migration
|
|
|
|
* can be specified with the bandwidth parameter. If set to 0,
|
|
|
|
* libvirt will choose a suitable default. Some hypervisors do
|
|
|
|
* not support this feature and will return an error if bandwidth
|
|
|
|
* is not 0.
|
|
|
|
*
|
|
|
|
* To see which features are supported by the current hypervisor,
|
|
|
|
* see virConnectGetCapabilities, /capabilities/host/migration_features.
|
|
|
|
*
|
|
|
|
* There are many limitations on migration imposed by the underlying
|
|
|
|
* technology - for example it may not be possible to migrate between
|
|
|
|
* different processors even with the same architecture, or between
|
|
|
|
* different types of hypervisor.
|
|
|
|
*
|
|
|
|
* Returns the new domain object if the migration was successful,
|
|
|
|
* or NULL in case of error. Note that the new domain object
|
|
|
|
* exists in the scope of the destination connection (dconn).
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
|
|
|
virDomainMigrate (virDomainPtr domain,
|
|
|
|
virConnectPtr dconn,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
virDomainPtr ddomain = NULL;
|
|
|
|
char *uri_out = NULL;
|
|
|
|
char *cookie = NULL;
|
|
|
|
int cookielen = 0, ret;
|
|
|
|
DEBUG("domain=%p, dconn=%p, flags=%lu, dname=%s, uri=%s, bandwidth=%lu",
|
|
|
|
domain, dconn, flags, dname, uri, bandwidth);
|
|
|
|
|
|
|
|
if (!VIR_IS_DOMAIN (domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-08-21 09:31:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
conn = domain->conn; /* Source connection. */
|
|
|
|
if (!VIR_IS_CONNECT (dconn)) {
|
|
|
|
virLibConnError (conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that migration is supported by both drivers. */
|
|
|
|
if (!VIR_DRV_SUPPORTS_FEATURE (conn->driver, conn,
|
|
|
|
VIR_DRV_FEATURE_MIGRATION_V1) ||
|
|
|
|
!VIR_DRV_SUPPORTS_FEATURE (dconn->driver, dconn,
|
|
|
|
VIR_DRV_FEATURE_MIGRATION_V1)) {
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare the migration.
|
|
|
|
*
|
|
|
|
* The destination host may return a cookie, or leave cookie as
|
|
|
|
* NULL.
|
|
|
|
*
|
|
|
|
* The destination host MUST set uri_out if uri_in is NULL.
|
|
|
|
*
|
|
|
|
* If uri_in is non-NULL, then the destination host may modify
|
|
|
|
* the URI by setting uri_out. If it does not wish to modify
|
|
|
|
* the URI, it should leave uri_out as NULL.
|
|
|
|
*/
|
|
|
|
ret = dconn->driver->domainMigratePrepare
|
|
|
|
(dconn, &cookie, &cookielen, uri, &uri_out, flags, dname, bandwidth);
|
|
|
|
if (ret == -1) goto done;
|
|
|
|
if (uri == NULL && uri_out == NULL) {
|
|
|
|
virLibConnError (conn, VIR_ERR_INTERNAL_ERROR,
|
2008-02-04 19:31:30 +00:00
|
|
|
_("domainMigratePrepare did not set uri"));
|
2007-08-21 09:31:12 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (uri_out) uri = uri_out; /* Did domainMigratePrepare change URI? */
|
|
|
|
|
|
|
|
assert (uri != NULL);
|
|
|
|
|
|
|
|
/* Perform the migration. The driver isn't supposed to return
|
|
|
|
* until the migration is complete.
|
|
|
|
*/
|
|
|
|
ret = conn->driver->domainMigratePerform
|
|
|
|
(domain, cookie, cookielen, uri, flags, dname, bandwidth);
|
|
|
|
|
|
|
|
if (ret == -1) goto done;
|
|
|
|
|
|
|
|
/* Get the destination domain and return it or error.
|
|
|
|
* 'domain' no longer actually exists at this point (or so we hope), but
|
|
|
|
* we still use the object in memory in order to get the name.
|
|
|
|
*/
|
|
|
|
dname = dname ? dname : domain->name;
|
|
|
|
if (dconn->driver->domainMigrateFinish)
|
|
|
|
ddomain = dconn->driver->domainMigrateFinish
|
|
|
|
(dconn, dname, cookie, cookielen, uri, flags);
|
|
|
|
else
|
|
|
|
ddomain = virDomainLookupByName (dconn, dname);
|
|
|
|
|
|
|
|
done:
|
2008-01-29 17:41:07 +00:00
|
|
|
free (uri_out);
|
|
|
|
free (cookie);
|
2007-08-21 09:31:12 +00:00
|
|
|
return ddomain;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not for public use. This function is part of the internal
|
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__virDomainMigratePrepare (virConnectPtr dconn,
|
|
|
|
char **cookie,
|
|
|
|
int *cookielen,
|
|
|
|
const char *uri_in,
|
|
|
|
char **uri_out,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
|
|
|
DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p, flags=%lu, dname=%s, bandwidth=%lu", dconn, cookie, cookielen, uri_in, uri_out, flags, dname, bandwidth);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT (dconn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-08-21 09:31:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dconn->driver->domainMigratePrepare)
|
|
|
|
return dconn->driver->domainMigratePrepare (dconn, cookie, cookielen,
|
|
|
|
uri_in, uri_out,
|
|
|
|
flags, dname, bandwidth);
|
|
|
|
|
|
|
|
virLibConnError (dconn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not for public use. This function is part of the internal
|
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__virDomainMigratePerform (virDomainPtr domain,
|
|
|
|
const char *cookie,
|
|
|
|
int cookielen,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("domain=%p, cookie=%p, cookielen=%d, uri=%s, flags=%lu, dname=%s, bandwidth=%lu", domain, cookie, cookielen, uri, flags, dname, bandwidth);
|
|
|
|
|
|
|
|
if (!VIR_IS_DOMAIN (domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-08-21 09:31:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainMigratePerform)
|
|
|
|
return conn->driver->domainMigratePerform (domain, cookie, cookielen,
|
|
|
|
uri,
|
|
|
|
flags, dname, bandwidth);
|
|
|
|
|
|
|
|
virLibDomainError (domain, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not for public use. This function is part of the internal
|
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
|
|
|
__virDomainMigrateFinish (virConnectPtr dconn,
|
|
|
|
const char *dname,
|
|
|
|
const char *cookie,
|
|
|
|
int cookielen,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, flags=%lu", dconn, dname, cookie, cookielen, uri, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT (dconn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-08-21 09:31:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dconn->driver->domainMigrateFinish)
|
|
|
|
return dconn->driver->domainMigrateFinish (dconn, dname,
|
|
|
|
cookie, cookielen,
|
|
|
|
uri, flags);
|
|
|
|
|
|
|
|
virLibConnError (dconn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2006-03-29 12:46:03 +00:00
|
|
|
* Extract hardware information about the node.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2007-04-04 14:19:49 +00:00
|
|
|
virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, info=%p", conn, info);
|
|
|
|
|
2006-03-29 12:46:03 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-29 12:46:03 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (info == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->nodeGetInfo)
|
|
|
|
return conn->driver->nodeGetInfo (conn, info);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-03-29 12:46:03 +00:00
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
|
2007-03-15 17:24:56 +00:00
|
|
|
/**
|
|
|
|
* virConnectGetCapabilities:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides capabilities of the hypervisor / driver.
|
|
|
|
*
|
2007-09-10 09:37:10 +00:00
|
|
|
* Returns NULL in case of error, or an XML string
|
|
|
|
* defining the capabilities.
|
2007-03-15 17:24:56 +00:00
|
|
|
* The client must free the returned string after use.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virConnectGetCapabilities (virConnectPtr conn)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2007-03-15 17:24:56 +00:00
|
|
|
if (!VIR_IS_CONNECT (conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-03-15 17:24:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->getCapabilities)
|
|
|
|
return conn->driver->getCapabilities (conn);
|
2007-03-15 17:24:56 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-03-15 17:24:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-30 13:09:07 +00:00
|
|
|
/**
|
|
|
|
* virNodeGetFreeMemory:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2008-04-04 07:58:29 +00:00
|
|
|
* provides the free memory available on the Node
|
2007-09-30 13:09:07 +00:00
|
|
|
*
|
|
|
|
* Returns the available free memory in kilobytes or 0 in case of error
|
|
|
|
*/
|
|
|
|
unsigned long long
|
|
|
|
virNodeGetFreeMemory(virConnectPtr conn)
|
|
|
|
{
|
2007-11-15 17:44:06 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2007-09-30 13:09:07 +00:00
|
|
|
if (!VIR_IS_CONNECT (conn)) {
|
|
|
|
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->driver->getFreeMemory)
|
|
|
|
return conn->driver->getFreeMemory (conn);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:06:08 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetSchedulerType:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @nparams: number of scheduler parameters(return value)
|
|
|
|
*
|
|
|
|
* Get the scheduler type.
|
|
|
|
*
|
|
|
|
* Returns NULL in case of error. The caller must free the returned string.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virDomainGetSchedulerType(virDomainPtr domain, int *nparams)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
char *schedtype;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, nparams=%p", domain, nparams);
|
2007-06-05 12:06:08 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-06-05 12:06:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainGetSchedulerType){
|
|
|
|
schedtype = conn->driver->domainGetSchedulerType (domain, nparams);
|
|
|
|
return schedtype;
|
|
|
|
}
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-06-05 12:06:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainGetSchedulerParameters:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @params: pointer to scheduler parameter object
|
|
|
|
* (return value)
|
|
|
|
* @nparams: pointer to number of scheduler parameter
|
|
|
|
* (this value should be same than the returned value
|
|
|
|
* nparams of virDomainGetSchedulerType)
|
|
|
|
*
|
|
|
|
* Get the scheduler parameters, the @params array will be filled with the
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainGetSchedulerParameters(virDomainPtr domain,
|
2008-04-10 16:54:54 +00:00
|
|
|
virSchedParameterPtr params, int *nparams)
|
2007-06-05 12:06:08 +00:00
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, params=%p, nparams=%p", domain, params, nparams);
|
2007-06-05 12:06:08 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-06-05 12:06:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainGetSchedulerParameters)
|
|
|
|
return conn->driver->domainGetSchedulerParameters (domain, params, nparams);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-06-05 12:06:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainSetSchedulerParameters:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @params: pointer to scheduler parameter objects
|
|
|
|
* @nparams: number of scheduler parameter
|
|
|
|
* (this value should be same or less than the returned value
|
|
|
|
* nparams of virDomainGetSchedulerType)
|
|
|
|
*
|
|
|
|
* Change the scheduler parameters
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success.
|
|
|
|
*/
|
|
|
|
int
|
2008-02-05 19:27:37 +00:00
|
|
|
virDomainSetSchedulerParameters(virDomainPtr domain,
|
2008-04-10 16:54:54 +00:00
|
|
|
virSchedParameterPtr params, int nparams)
|
2007-06-05 12:06:08 +00:00
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, params=%p, nparams=%d", domain, params, nparams);
|
2007-06-05 12:06:08 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-06-05 12:06:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-03-13 09:27:46 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-06-05 12:06:08 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainSetSchedulerParameters)
|
|
|
|
return conn->driver->domainSetSchedulerParameters (domain, params, nparams);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-06-05 12:06:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-21 10:08:12 +00:00
|
|
|
/**
|
2007-08-21 14:59:47 +00:00
|
|
|
* virDomainBlockStats:
|
2007-08-21 10:08:12 +00:00
|
|
|
* @dom: pointer to the domain object
|
|
|
|
* @path: path to the block device
|
|
|
|
* @stats: block device stats (returned)
|
|
|
|
* @size: size of stats structure
|
|
|
|
*
|
|
|
|
* This function returns block device (disk) stats for block
|
|
|
|
* devices attached to the domain.
|
|
|
|
*
|
|
|
|
* The path parameter is the name of the block device. Get this
|
|
|
|
* by calling virDomainGetXMLDesc and finding the <target dev='...'>
|
|
|
|
* attribute within //domain/devices/disk. (For example, "xvda").
|
|
|
|
*
|
|
|
|
* Domains may have more than one block device. To get stats for
|
|
|
|
* each you should make multiple calls to this function.
|
|
|
|
*
|
|
|
|
* Individual fields within the stats structure may be returned
|
|
|
|
* as -1, which indicates that the hypervisor does not support
|
|
|
|
* that particular statistic.
|
|
|
|
*
|
|
|
|
* Returns: 0 in case of success or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainBlockStats (virDomainPtr dom, const char *path,
|
|
|
|
virDomainBlockStatsPtr stats, size_t size)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
struct _virDomainBlockStats stats2 = { -1, -1, -1, -1, -1 };
|
|
|
|
DEBUG("domain=%p, path=%s, stats=%p, size=%zi", dom, path, stats, size);
|
|
|
|
|
|
|
|
if (!stats || size > sizeof stats2) {
|
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-08-21 10:08:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = dom->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainBlockStats) {
|
|
|
|
if (conn->driver->domainBlockStats (dom, path, &stats2) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memcpy (stats, &stats2, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-08-21 14:59:47 +00:00
|
|
|
* virDomainInterfaceStats:
|
2007-08-21 10:08:12 +00:00
|
|
|
* @dom: pointer to the domain object
|
|
|
|
* @path: path to the interface
|
|
|
|
* @stats: network interface stats (returned)
|
|
|
|
* @size: size of stats structure
|
|
|
|
*
|
|
|
|
* This function returns network interface stats for interfaces
|
|
|
|
* attached to the domain.
|
|
|
|
*
|
|
|
|
* The path parameter is the name of the network interface.
|
|
|
|
*
|
|
|
|
* Domains may have more than network interface. To get stats for
|
|
|
|
* each you should make multiple calls to this function.
|
|
|
|
*
|
|
|
|
* Individual fields within the stats structure may be returned
|
|
|
|
* as -1, which indicates that the hypervisor does not support
|
|
|
|
* that particular statistic.
|
|
|
|
*
|
|
|
|
* Returns: 0 in case of success or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainInterfaceStats (virDomainPtr dom, const char *path,
|
|
|
|
virDomainInterfaceStatsPtr stats, size_t size)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
struct _virDomainInterfaceStats stats2 = { -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1 };
|
|
|
|
DEBUG("domain=%p, path=%s, stats=%p, size=%zi", dom, path, stats, size);
|
|
|
|
|
|
|
|
if (!stats || size > sizeof stats2) {
|
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-08-21 10:08:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = dom->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainInterfaceStats) {
|
|
|
|
if (conn->driver->domainInterfaceStats (dom, path, &stats2) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memcpy (stats, &stats2, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-06-05 12:06:08 +00:00
|
|
|
|
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) {
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, xml=%s", conn, xml);
|
|
|
|
|
2006-04-28 18:29:26 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-04-28 18:29:26 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (NULL);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainDefineXML)
|
|
|
|
return conn->driver->domainDefineXML (conn, xml);
|
2006-04-28 18:29:26 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2006-04-28 18:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2006-04-28 18:29:26 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-04-28 18:29:26 +00:00
|
|
|
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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainUndefine)
|
|
|
|
return conn->driver->domainUndefine (domain);
|
2006-04-28 18:29:26 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-08-30 14:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfDefinedDomains:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
2008-03-17 16:43:54 +00:00
|
|
|
* Provides the number of defined but inactive domains.
|
2006-08-30 14:21:03 +00:00
|
|
|
*
|
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2006-08-30 14:21:03 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-08-30 14:21:03 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->numOfDefinedDomains)
|
|
|
|
return conn->driver->numOfDefinedDomains (conn);
|
2006-08-30 14:21:03 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
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
|
|
|
|
*
|
2008-03-17 16:43:54 +00:00
|
|
|
* list the defined but inactive domains, stores the pointers to the names
|
|
|
|
* in @names
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2006-04-28 18:29:26 +00:00
|
|
|
* Returns the number of names provided in the array or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
2007-03-06 21:55:44 +00:00
|
|
|
virConnectListDefinedDomains(virConnectPtr conn, char **const names,
|
2006-04-28 18:29:26 +00:00
|
|
|
int maxnames) {
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
|
|
|
|
|
2006-08-30 14:21:03 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-08-30 14:21:03 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:23:10 +00:00
|
|
|
if ((names == NULL) || (maxnames < 0)) {
|
2006-08-30 14:21:03 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->listDefinedDomains)
|
|
|
|
return conn->driver->listDefinedDomains (conn, names, maxnames);
|
2006-08-30 14:21:03 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
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
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2006-08-30 14:21:03 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-30 14:21:03 +00:00
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-08-16 16:14:53 +00:00
|
|
|
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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-08-30 14:21:03 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainCreate)
|
|
|
|
return conn->driver->domainCreate (domain);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-04-28 18:29:26 +00:00
|
|
|
}
|
|
|
|
|
2007-02-23 08:51:30 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetAutostart:
|
|
|
|
* @domain: a domain object
|
2007-03-15 17:24:56 +00:00
|
|
|
* @autostart: the value returned
|
2007-02-23 08:51:30 +00:00
|
|
|
*
|
2007-03-15 17:24:56 +00:00
|
|
|
* Provides a boolean value indicating whether the domain
|
2007-02-23 08:51:30 +00:00
|
|
|
* configured to be automatically started when the host
|
|
|
|
* machine boots.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainGetAutostart(virDomainPtr domain,
|
2007-04-04 14:19:49 +00:00
|
|
|
int *autostart)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, autostart=%p", domain, autostart);
|
2007-02-23 08:51:30 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-02-23 08:51:30 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!autostart) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainGetAutostart)
|
|
|
|
return conn->driver->domainGetAutostart (domain, autostart);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-23 08:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainSetAutostart:
|
|
|
|
* @domain: a domain object
|
2007-03-15 17:24:56 +00:00
|
|
|
* @autostart: whether the domain should be automatically started 0 or 1
|
2007-02-23 08:51:30 +00:00
|
|
|
*
|
|
|
|
* Configure the domain to be automatically started
|
|
|
|
* when the host machine boots.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainSetAutostart(virDomainPtr domain,
|
2007-04-04 14:19:49 +00:00
|
|
|
int autostart)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, autostart=%d", domain, autostart);
|
2007-02-23 08:51:30 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-02-23 08:51:30 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainSetAutostart)
|
|
|
|
return conn->driver->domainSetAutostart (domain, autostart);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-23 08:51:30 +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.
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function requires privileged access to the hypervisor.
|
2006-08-04 10:41:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, nvcpus=%u", domain, nvcpus);
|
2006-08-08 22:22:55 +00:00
|
|
|
|
2006-08-04 10:41:05 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-08-04 10:41:05 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
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
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainSetVcpus)
|
|
|
|
return conn->driver->domainSetVcpus (domain, nvcpus);
|
2006-08-08 22:22:55 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
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.
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2006-08-04 10:41:05 +00:00
|
|
|
* Dynamically change the real CPUs which can be allocated to a virtual CPU.
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function requires privileged access to the hypervisor.
|
2006-08-04 10:41:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, vcpu=%u, cpumap=%p, maplen=%d", domain, vcpu, cpumap, maplen);
|
2006-08-08 22:22:55 +00:00
|
|
|
|
2006-08-04 10:41:05 +00:00
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-08-04 10:41:05 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2006-08-16 16:14:53 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainPinVcpu)
|
|
|
|
return conn->driver->domainPinVcpu (domain, vcpu, cpumap, maplen);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
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)
|
2008-04-04 07:58:29 +00:00
|
|
|
* If cpumaps is NULL, then no cpumap information is returned by the API.
|
2006-08-04 10:41:05 +00:00
|
|
|
* 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...).
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2006-08-04 10:41:05 +00:00
|
|
|
* Extract information about virtual CPUs of domain, store it in info array
|
2008-04-04 07:58:29 +00:00
|
|
|
* and also in cpumaps if this pointer isn't NULL.
|
2006-08-04 10:41:05 +00:00
|
|
|
*
|
|
|
|
* Returns the number of info filled in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
|
2008-04-10 16:54:54 +00:00
|
|
|
unsigned char *cpumaps, int maplen)
|
2006-08-04 10:41:05 +00:00
|
|
|
{
|
2006-08-08 22:22:55 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, info=%p, maxinfo=%d, cpumaps=%p, maplen=%d", domain, info, maxinfo, cpumaps, maplen);
|
2006-08-04 10:41:05 +00:00
|
|
|
|
|
|
|
if (domain == NULL) {
|
|
|
|
TODO
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-08-04 10:41:05 +00:00
|
|
|
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);
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainGetVcpus)
|
|
|
|
return conn->driver->domainGetVcpus (domain, info, maxinfo,
|
|
|
|
cpumaps, maplen);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
2006-11-16 18:11:28 +00:00
|
|
|
|
2007-03-08 08:31:07 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetMaxVcpus:
|
|
|
|
* @domain: pointer to domain object
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2007-03-15 17:24:56 +00:00
|
|
|
* Provides the maximum number of virtual CPUs supported for
|
|
|
|
* the guest VM. If the guest is inactive, this is basically
|
|
|
|
* the same as virConnectGetMaxVcpus. If the guest is running
|
|
|
|
* this will reflect the maximum number of virtual CPUs the
|
|
|
|
* guest was booted with.
|
2007-03-08 08:31:07 +00:00
|
|
|
*
|
|
|
|
* Returns the maximum of virtual CPU or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
2007-04-04 14:19:49 +00:00
|
|
|
virDomainGetMaxVcpus(virDomainPtr domain)
|
|
|
|
{
|
2007-03-08 08:31:07 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
2007-03-08 08:31:07 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2007-03-08 08:31:07 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainGetMaxVcpus)
|
|
|
|
return conn->driver->domainGetMaxVcpus (domain);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-03-08 08:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-16 18:11:28 +00:00
|
|
|
/**
|
|
|
|
* virDomainAttachDevice:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @xml: pointer to XML description of one device
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2006-11-16 18:11:28 +00:00
|
|
|
* Create a virtual device attachment to backend.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2007-10-15 21:38:56 +00:00
|
|
|
virDomainAttachDevice(virDomainPtr domain, const char *xml)
|
2006-11-16 18:11:28 +00:00
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, xml=%s", domain, xml);
|
2006-11-16 18:11:28 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-11-16 18:11:28 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-11-16 18:11:28 +00:00
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainAttachDevice)
|
|
|
|
return conn->driver->domainAttachDevice (domain, xml);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-11-16 18:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainDetachDevice:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @xml: pointer to XML description of one device
|
2008-02-05 19:27:37 +00:00
|
|
|
*
|
2006-11-16 18:11:28 +00:00
|
|
|
* Destroy a virtual device attachment to backend.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2007-10-15 21:38:56 +00:00
|
|
|
virDomainDetachDevice(virDomainPtr domain, const char *xml)
|
2006-11-16 18:11:28 +00:00
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p, xml=%s", domain, xml);
|
2006-11-16 18:11:28 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
2006-11-16 18:11:28 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2006-11-16 18:11:28 +00:00
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->driver->domainDetachDevice)
|
|
|
|
return conn->driver->domainDetachDevice (domain, xml);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-11-16 18:11:28 +00:00
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-09-28 14:28:12 +00:00
|
|
|
/**
|
|
|
|
* virNodeGetCellsFreeMemory:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @freeMems: pointer to the array of unsigned long long
|
|
|
|
* @startCell: index of first cell to return freeMems info on.
|
|
|
|
* @maxCells: Maximum number of cells for which freeMems information can
|
|
|
|
* be returned.
|
|
|
|
*
|
|
|
|
* This call returns the amount of free memory in one or more NUMA cells.
|
|
|
|
* The @freeMems array must be allocated by the caller and will be filled
|
|
|
|
* with the amount of free memory in kilobytes for each cell requested,
|
|
|
|
* starting with startCell (in freeMems[0]), up to either
|
|
|
|
* (startCell + maxCells), or the number of additional cells in the node,
|
|
|
|
* whichever is smaller.
|
|
|
|
*
|
|
|
|
* Returns the number of entries filled in freeMems, or -1 in case of error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
virNodeGetCellsFreeMemory(virConnectPtr conn, unsigned long long *freeMems,
|
|
|
|
int startCell, int maxCells)
|
|
|
|
{
|
2007-11-15 17:44:06 +00:00
|
|
|
DEBUG("conn=%p, freeMems=%p, startCell=%d, maxCells=%d",
|
|
|
|
conn, freeMems, startCell, maxCells);
|
|
|
|
|
2007-09-28 14:28:12 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-09-30 13:17:45 +00:00
|
|
|
if ((freeMems == NULL) || (maxCells <= 0) || (startCell < 0)) {
|
2007-09-28 14:28:12 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->driver->nodeGetCellsFreeMemory)
|
|
|
|
return conn->driver->nodeGetCellsFreeMemory (conn, freeMems, startCell, maxCells);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-06-25 15:56:18 +00:00
|
|
|
/**
|
|
|
|
* virNetworkGetConnect:
|
|
|
|
* @net: pointer to a network
|
|
|
|
*
|
2007-06-29 13:23:13 +00:00
|
|
|
* Provides the connection pointer associated with a network. The
|
2007-06-25 15:56:18 +00:00
|
|
|
* reference counter on the connection is not increased by this
|
|
|
|
* call.
|
|
|
|
*
|
2007-07-24 15:32:55 +00:00
|
|
|
* WARNING: When writing libvirt bindings in other languages, do
|
|
|
|
* not use this function. Instead, store the connection and
|
|
|
|
* the network object together.
|
|
|
|
*
|
2007-06-25 15:56:18 +00:00
|
|
|
* Returns the virConnectPtr or NULL in case of failure.
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virNetworkGetConnect (virNetworkPtr net)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("net=%p", net);
|
|
|
|
|
2007-06-25 15:56:18 +00:00
|
|
|
if (!VIR_IS_NETWORK (net)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-06-25 15:56:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return net->conn;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->numOfNetworks)
|
|
|
|
return conn->networkDriver->numOfNetworks (conn);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2007-03-06 21:55:44 +00:00
|
|
|
virConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
|
2007-02-14 15:37:18 +00:00
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:23:10 +00:00
|
|
|
if ((names == NULL) || (maxnames < 0)) {
|
2007-02-14 15:37:18 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->listNetworks)
|
|
|
|
return conn->networkDriver->listNetworks (conn, names, maxnames);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->numOfDefinedNetworks)
|
|
|
|
return conn->networkDriver->numOfDefinedNetworks (conn);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2007-03-06 21:55:44 +00:00
|
|
|
virConnectListDefinedNetworks(virConnectPtr conn, char **const names,
|
2007-04-04 14:19:49 +00:00
|
|
|
int maxnames)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:23:10 +00:00
|
|
|
if ((names == NULL) || (maxnames < 0)) {
|
2007-02-14 15:37:18 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->listDefinedNetworks)
|
|
|
|
return conn->networkDriver->listDefinedNetworks (conn,
|
|
|
|
names, maxnames);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2007-07-06 15:20:38 +00:00
|
|
|
* Returns a new network object or NULL in case of failure. If the
|
|
|
|
* network cannot be found, then VIR_ERR_NO_NETWORK error is raised.
|
2007-02-14 15:37:18 +00:00
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, name=%s", conn, name);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkLookupByName)
|
|
|
|
return conn->networkDriver->networkLookupByName (conn, name);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2007-07-06 15:20:38 +00:00
|
|
|
* Returns a new network object or NULL in case of failure. If the
|
|
|
|
* network cannot be found, then VIR_ERR_NO_NETWORK error is raised.
|
2007-02-14 15:37:18 +00:00
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, uuid=%s", conn, uuid);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkLookupByUUID)
|
|
|
|
return conn->networkDriver->networkLookupByUUID (conn, uuid);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2007-07-06 15:20:38 +00:00
|
|
|
* Returns a new network object or NULL in case of failure. If the
|
|
|
|
* network cannot be found, then VIR_ERR_NO_NETWORK error is raised.
|
2007-02-14 15:37:18 +00:00
|
|
|
*/
|
|
|
|
virNetworkPtr
|
|
|
|
virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
|
|
|
|
{
|
|
|
|
int raw[VIR_UUID_BUFLEN], i;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
int ret;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
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) {
|
2008-04-10 16:54:54 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, xmlDesc=%s", conn, xmlDesc);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
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__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (NULL);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkCreateXML)
|
|
|
|
return conn->networkDriver->networkCreateXML (conn, xmlDesc);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2007-04-04 14:19:49 +00:00
|
|
|
virNetworkDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p, xml=%s", conn, xml);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (NULL);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkDefineXML)
|
|
|
|
return conn->networkDriver->networkDefineXML (conn, xml);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p", network);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = network->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkUndefine)
|
|
|
|
return conn->networkDriver->networkUndefine (network);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2007-04-04 14:19:49 +00:00
|
|
|
virNetworkCreate(virNetworkPtr network)
|
|
|
|
{
|
2007-02-14 15:37:18 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p", network);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (network == NULL) {
|
|
|
|
TODO
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = network->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkCreate)
|
|
|
|
return conn->networkDriver->networkCreate (network);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkDestroy:
|
|
|
|
* @network: a network object
|
|
|
|
*
|
|
|
|
* Destroy the network object. The running instance is shutdown if not down
|
2008-05-21 20:53:30 +00:00
|
|
|
* already and all resources used by it are given back to the hypervisor. This
|
|
|
|
* does not free the associated virNetworkPtr object.
|
|
|
|
* This function may require privileged access
|
2007-02-14 15:37:18 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkDestroy(virNetworkPtr network)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p", network);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = network->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return (-1);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkDestroy)
|
|
|
|
return conn->networkDriver->networkDestroy (network);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p", network);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2008-01-21 16:29:10 +00:00
|
|
|
if (virUnrefNetwork(network) < 0)
|
2007-02-14 15:37:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p", network);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p, uuid=%p", network, uuid);
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
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];
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p, buf=%p", network, buf);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (buf == NULL) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virNetworkGetUUID(network, &uuid[0]))
|
2007-08-09 20:19:12 +00:00
|
|
|
return (-1);
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-08-09 20:19:12 +00:00
|
|
|
virUUIDFormat(uuid, buf);
|
2007-02-14 15:37:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p, flags=%d", network, flags);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 15:37:18 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = network->conn;
|
|
|
|
|
|
|
|
if (conn->networkDriver && conn->networkDriver->networkDumpXML)
|
|
|
|
return conn->networkDriver->networkDumpXML (network, flags);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
2007-02-14 16:20:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkGetBridgeName:
|
|
|
|
* @network: a network object
|
|
|
|
*
|
2007-03-15 17:24:56 +00:00
|
|
|
* Provides a bridge interface name to which a domain may connect
|
2007-02-14 16:20:38 +00:00
|
|
|
* a network interface in order to join the network.
|
|
|
|
*
|
|
|
|
* Returns a 0 terminated interface name, or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virNetworkGetBridgeName(virNetworkPtr network)
|
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p", network);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-02-14 16:20:38 +00:00
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-14 16:20:38 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = network->conn;
|
|
|
|
|
|
|
|
if (conn->networkDriver && conn->networkDriver->networkGetBridgeName)
|
|
|
|
return conn->networkDriver->networkGetBridgeName (network);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2007-02-14 16:20:38 +00:00
|
|
|
}
|
2007-02-23 08:51:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkGetAutostart:
|
|
|
|
* @network: a network object
|
2007-03-15 17:24:56 +00:00
|
|
|
* @autostart: the value returned
|
2007-02-23 08:51:30 +00:00
|
|
|
*
|
2007-03-15 17:24:56 +00:00
|
|
|
* Provides a boolean value indicating whether the network
|
2007-02-23 08:51:30 +00:00
|
|
|
* configured to be automatically started when the host
|
|
|
|
* machine boots.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkGetAutostart(virNetworkPtr network,
|
2007-04-04 14:19:49 +00:00
|
|
|
int *autostart)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p, autostart=%p", network, autostart);
|
2007-02-23 08:51:30 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-23 08:51:30 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!autostart) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = network->conn;
|
|
|
|
|
|
|
|
if (conn->networkDriver && conn->networkDriver->networkGetAutostart)
|
|
|
|
return conn->networkDriver->networkGetAutostart (network, autostart);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-23 08:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkSetAutostart:
|
|
|
|
* @network: a network object
|
2007-03-15 17:24:56 +00:00
|
|
|
* @autostart: whether the network should be automatically started 0 or 1
|
2007-02-23 08:51:30 +00:00
|
|
|
*
|
|
|
|
* Configure the network to be automatically started
|
|
|
|
* when the host machine boots.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error, 0 in case of success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkSetAutostart(virNetworkPtr network,
|
2007-04-04 14:19:49 +00:00
|
|
|
int autostart)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("network=%p, autostart=%d", network, autostart);
|
2007-02-23 08:51:30 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_NETWORK(network)) {
|
2007-09-20 12:04:57 +00:00
|
|
|
virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
2007-02-23 08:51:30 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = network->conn;
|
|
|
|
|
|
|
|
if (conn->networkDriver && conn->networkDriver->networkSetAutostart)
|
|
|
|
return conn->networkDriver->networkSetAutostart (network, autostart);
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-02-23 08:51:30 +00:00
|
|
|
}
|
2007-03-15 17:24:56 +00:00
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolGetConnect:
|
2008-03-17 10:27:31 +00:00
|
|
|
* @pool: pointer to a pool
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Provides the connection pointer associated with a storage pool. The
|
|
|
|
* reference counter on the connection is not increased by this
|
|
|
|
* call.
|
|
|
|
*
|
|
|
|
* WARNING: When writing libvirt bindings in other languages, do
|
|
|
|
* not use this function. Instead, store the connection and
|
|
|
|
* the pool object together.
|
|
|
|
*
|
|
|
|
* Returns the virConnectPtr or NULL in case of failure.
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virStoragePoolGetConnect (virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL (pool)) {
|
|
|
|
virLibStoragePoolError (NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return pool->conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfStoragePools:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides the number of active storage pools
|
|
|
|
*
|
|
|
|
* Returns the number of pools found, or -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfStoragePools (virConnectPtr conn)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->numOfPools)
|
|
|
|
return conn->storageDriver->numOfPools (conn);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListStoragePools:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @names: array of char * to fill with pool names (allocated by caller)
|
|
|
|
* @maxnames: size of the names array
|
|
|
|
*
|
|
|
|
* Provides the list of names of active storage pools
|
|
|
|
* upto maxnames. If there are more than maxnames, the
|
|
|
|
* remaining names will be silently ignored.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListStoragePools (virConnectPtr conn,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((names == NULL) || (maxnames < 0)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->listPools)
|
|
|
|
return conn->storageDriver->listPools (conn, names, maxnames);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfDefinedStoragePools:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides the number of inactive storage pools
|
|
|
|
*
|
|
|
|
* Returns the number of pools found, or -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->numOfDefinedPools)
|
|
|
|
return conn->storageDriver->numOfDefinedPools (conn);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListDefinedStoragePools:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @names: array of char * to fill with pool names (allocated by caller)
|
|
|
|
* @maxnames: size of the names array
|
|
|
|
*
|
|
|
|
* Provides the list of names of inactive storage pools
|
|
|
|
* upto maxnames. If there are more than maxnames, the
|
|
|
|
* remaining names will be silently ignored.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListDefinedStoragePools(virConnectPtr conn,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((names == NULL) || (maxnames < 0)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->listDefinedPools)
|
|
|
|
return conn->storageDriver->listDefinedPools (conn, names, maxnames);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolLookupByName:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @name: name of pool to fetch
|
|
|
|
*
|
|
|
|
* Fetch a storage pool based on its unique name
|
|
|
|
*
|
|
|
|
* Returns a virStoragePoolPtr object, or NULL if no matching pool is found
|
|
|
|
*/
|
|
|
|
virStoragePoolPtr
|
|
|
|
virStoragePoolLookupByName(virConnectPtr conn,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, name=%s", conn, name);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolLookupByName)
|
|
|
|
return conn->storageDriver->poolLookupByName (conn, name);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolLookupByUUID:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @uuid: globally unique id of pool to fetch
|
|
|
|
*
|
|
|
|
* Fetch a storage pool based on its globally unique id
|
|
|
|
*
|
|
|
|
* Returns a virStoragePoolPtr object, or NULL if no matching pool is found
|
|
|
|
*/
|
|
|
|
virStoragePoolPtr
|
|
|
|
virStoragePoolLookupByUUID(virConnectPtr conn,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, uuid=%s", conn, uuid);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolLookupByUUID)
|
|
|
|
return conn->storageDriver->poolLookupByUUID (conn, uuid);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolLookupByUUIDString:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @uuidstr: globally unique id of pool to fetch
|
|
|
|
*
|
|
|
|
* Fetch a storage pool based on its globally unique id
|
|
|
|
*
|
|
|
|
* Returns a virStoragePoolPtr object, or NULL if no matching pool is found
|
|
|
|
*/
|
|
|
|
virStoragePoolPtr
|
|
|
|
virStoragePoolLookupByUUIDString(virConnectPtr conn,
|
2008-04-10 16:54:54 +00:00
|
|
|
const char *uuidstr)
|
2008-02-20 15:06:53 +00:00
|
|
|
{
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuidstr == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virUUIDParse(uuidstr, uuid) < 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return virStoragePoolLookupByUUID(conn, uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolLookupByVolume:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
*
|
|
|
|
* Fetch a storage pool which contains a particular volume
|
|
|
|
*
|
|
|
|
* Returns a virStoragePoolPtr object, or NULL if no matching pool is found
|
|
|
|
*/
|
|
|
|
virStoragePoolPtr
|
|
|
|
virStoragePoolLookupByVolume(virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
DEBUG("vol=%p", vol);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol->conn->storageDriver && vol->conn->storageDriver->poolLookupByVolume)
|
|
|
|
return vol->conn->storageDriver->poolLookupByVolume (vol);
|
|
|
|
|
|
|
|
virLibConnError (vol->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolCreateXML:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @xmlDesc: XML description for new pool
|
2008-03-17 10:48:02 +00:00
|
|
|
* @flags: future flags, use 0 for now
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Create a new storage based on its XML description. The
|
2008-04-04 07:58:29 +00:00
|
|
|
* pool is not persistent, so its definition will disappear
|
2008-02-20 15:06:53 +00:00
|
|
|
* when it is destroyed, or if the host is restarted
|
|
|
|
*
|
|
|
|
* Returns a virStoragePoolPtr object, or NULL if creation failed
|
|
|
|
*/
|
|
|
|
virStoragePoolPtr
|
|
|
|
virStoragePoolCreateXML(virConnectPtr conn,
|
|
|
|
const char *xmlDesc,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, xmlDesc=%s", conn, xmlDesc);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolCreateXML)
|
|
|
|
return conn->storageDriver->poolCreateXML (conn, xmlDesc, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolDefineXML:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @xml: XML description for new pool
|
2008-03-17 10:48:02 +00:00
|
|
|
* @flags: future flags, use 0 for now
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Define a new inactive storage pool based on its XML description. The
|
2008-04-04 07:58:29 +00:00
|
|
|
* pool is persistent, until explicitly undefined.
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Returns a virStoragePoolPtr object, or NULL if creation failed
|
|
|
|
*/
|
|
|
|
virStoragePoolPtr
|
|
|
|
virStoragePoolDefineXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, xml=%s", conn, xml);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolDefineXML)
|
|
|
|
return conn->storageDriver->poolDefineXML (conn, xml, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolBuild:
|
|
|
|
* @pool: pointer to storage pool
|
2008-03-17 10:48:02 +00:00
|
|
|
* @flags: future flags, use 0 for now
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Build the underlying storage pool
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 upon failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolBuild(virStoragePoolPtr pool,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p, flags=%u", pool, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = pool->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolBuild)
|
|
|
|
return conn->storageDriver->poolBuild (pool, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolUndefine:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
*
|
|
|
|
* Undefine an inactive storage pool
|
|
|
|
*
|
|
|
|
* Returns a virStoragePoolPtr object, or NULL if creation failed
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolUndefine(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = pool->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolUndefine)
|
|
|
|
return conn->storageDriver->poolUndefine (pool);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolCreate:
|
|
|
|
* @pool: pointer to storage pool
|
2008-03-17 10:48:02 +00:00
|
|
|
* @flags: future flags, use 0 for now
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Starts an inactive storage pool
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 if it could not be started
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolCreate(virStoragePoolPtr pool,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
|
|
|
if (pool == NULL) {
|
|
|
|
TODO;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
conn = pool->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolCreate)
|
|
|
|
return conn->storageDriver->poolCreate (pool, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolDestroy:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
*
|
|
|
|
* Destroy an active storage pool. This will deactivate the
|
|
|
|
* pool on the host, but keep any persistent config associated
|
|
|
|
* with it. If it has a persistent config it can later be
|
|
|
|
* restarted with virStoragePoolCreate(). This does not free
|
|
|
|
* the associated virStoragePoolPtr object.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 if it could not be destroyed
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolDestroy(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolDestroy)
|
|
|
|
return conn->storageDriver->poolDestroy (pool);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolDelete:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @flags: flags for obliteration process
|
|
|
|
*
|
|
|
|
* Delete the underlying pool resources. This is
|
|
|
|
* a non-recoverable operation. The virStoragePoolPtr object
|
|
|
|
* itself is not free'd.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 if it could not be obliterate
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolDelete(virStoragePoolPtr pool,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p, flags=%u", pool, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolDelete)
|
|
|
|
return conn->storageDriver->poolDelete (pool, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolFree:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
*
|
|
|
|
* Free a storage pool object, releasing all memory associated with
|
|
|
|
* it. Does not change the state of the pool on the host.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -1 if it could not be free'd.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolFree(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (virUnrefStoragePool(pool) < 0)
|
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolRefresh:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @flags: flags to control refresh behaviour (currently unused, use 0)
|
|
|
|
*
|
|
|
|
* Request that the pool refresh its list of volumes. This may
|
|
|
|
* involve communicating with a remote server, and/or initializing
|
|
|
|
* new devices at the OS layer
|
|
|
|
*
|
|
|
|
* Return 0 if the volume list was refreshed, -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolRefresh(virStoragePoolPtr pool,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p flags=%u", pool, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolRefresh)
|
|
|
|
return conn->storageDriver->poolRefresh (pool, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolGetName:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
*
|
|
|
|
* Fetch the locally unique name of the storage pool
|
|
|
|
*
|
|
|
|
* Return the name of the pool, or NULL on error
|
|
|
|
*/
|
|
|
|
const char*
|
|
|
|
virStoragePoolGetName(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (pool->name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolGetUUID:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @uuid: buffer of VIR_UUID_BUFLEN bytes in size
|
|
|
|
*
|
|
|
|
* Fetch the globally unique ID of the storage pool
|
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on error;
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolGetUUID(virStoragePoolPtr pool,
|
|
|
|
unsigned char *uuid)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p, uuid=%p", pool, uuid);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(uuid, &pool->uuid[0], VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolGetUUIDString:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @buf: buffer of VIR_UUID_STRING_BUFLEN bytes in size
|
|
|
|
*
|
|
|
|
* Fetch the globally unique ID of the storage pool as a string
|
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on error;
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolGetUUIDString(virStoragePoolPtr pool,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
DEBUG("pool=%p, buf=%p", pool, buf);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (buf == NULL) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStoragePoolGetUUID(pool, &uuid[0]))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
virUUIDFormat(uuid, buf);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolGetInfo:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @info: pointer at which to store info
|
|
|
|
*
|
|
|
|
* Get volatile information about the storage pool
|
|
|
|
* such as free space / usage summary
|
|
|
|
*
|
|
|
|
* returns 0 on success, or -1 on failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolGetInfo(virStoragePoolPtr pool,
|
|
|
|
virStoragePoolInfoPtr info)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p, info=%p", pool, info);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (info == NULL) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(info, 0, sizeof(virStoragePoolInfo));
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
|
|
|
|
if (conn->storageDriver->poolGetInfo)
|
|
|
|
return conn->storageDriver->poolGetInfo (pool, info);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolGetXMLDesc:
|
|
|
|
* @pool: pointer to storage pool
|
2008-03-17 10:48:02 +00:00
|
|
|
* @flags: flags for XML format options (set of virDomainXMLFlags)
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Fetch an XML document describing all aspects of the
|
|
|
|
* storage pool. This is suitable for later feeding back
|
|
|
|
* into the virStoragePoolCreateXML method.
|
|
|
|
*
|
|
|
|
* returns a XML document, or NULL on error
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virStoragePoolGetXMLDesc(virStoragePoolPtr pool,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p, flags=%u", pool, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolGetXMLDesc)
|
|
|
|
return conn->storageDriver->poolGetXMLDesc (pool, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolGetAutostart:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @autostart: location in which to store autostart flag
|
|
|
|
*
|
|
|
|
* Fetches the value of the autostart flag, which determines
|
|
|
|
* whether the pool is automatically started at boot time
|
|
|
|
*
|
|
|
|
* return 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolGetAutostart(virStoragePoolPtr pool,
|
|
|
|
int *autostart)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p, autostart=%p", pool, autostart);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!autostart) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolGetAutostart)
|
|
|
|
return conn->storageDriver->poolGetAutostart (pool, autostart);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolSetAutostart:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @autostart: new flag setting
|
|
|
|
*
|
|
|
|
* Sets the autostart flag
|
|
|
|
*
|
|
|
|
* returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolSetAutostart(virStoragePoolPtr pool,
|
|
|
|
int autostart)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p, autostart=%d", pool, autostart);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->poolSetAutostart)
|
|
|
|
return conn->storageDriver->poolSetAutostart (pool, autostart);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolNumOfVolumes:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
*
|
|
|
|
* Fetch the number of storage volumes within a pool
|
|
|
|
*
|
|
|
|
* Returns the number of storage pools, or -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolNumOfVolumes(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->poolNumOfVolumes)
|
|
|
|
return pool->conn->storageDriver->poolNumOfVolumes (pool);
|
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolListVolumes:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @names: array in which to storage volume names
|
|
|
|
* @maxnames: size of names array
|
|
|
|
*
|
|
|
|
* Fetch list of storage volume names, limiting to
|
|
|
|
* at most maxnames.
|
|
|
|
*
|
|
|
|
* Returns the number of names fetched, or -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolListVolumes(virStoragePoolPtr pool,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p, names=%p, maxnames=%d", pool, names, maxnames);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((names == NULL) || (maxnames < 0)) {
|
|
|
|
virLibConnError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->poolListVolumes)
|
|
|
|
return pool->conn->storageDriver->poolListVolumes (pool, names, maxnames);
|
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolGetConnect:
|
2008-03-17 10:27:31 +00:00
|
|
|
* @vol: pointer to a pool
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Provides the connection pointer associated with a storage volume. The
|
|
|
|
* reference counter on the connection is not increased by this
|
|
|
|
* call.
|
|
|
|
*
|
|
|
|
* WARNING: When writing libvirt bindings in other languages, do
|
|
|
|
* not use this function. Instead, store the connection and
|
|
|
|
* the volume object together.
|
|
|
|
*
|
|
|
|
* Returns the virConnectPtr or NULL in case of failure.
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virStorageVolGetConnect (virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
DEBUG("vol=%p", vol);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL (vol)) {
|
|
|
|
virLibStoragePoolError (NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return vol->conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolLookupByName:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @name: name of storage volume
|
|
|
|
*
|
|
|
|
* Fetch a pointer to a storage volume based on its name
|
|
|
|
* within a pool
|
|
|
|
*
|
|
|
|
* return a storage volume, or NULL if not found / error
|
|
|
|
*/
|
|
|
|
virStorageVolPtr
|
|
|
|
virStorageVolLookupByName(virStoragePoolPtr pool,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p, name=%s", pool, name);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->volLookupByName)
|
|
|
|
return pool->conn->storageDriver->volLookupByName (pool, name);
|
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolLookupByKey:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @key: globally unique key
|
|
|
|
*
|
|
|
|
* Fetch a pointer to a storage volume based on its
|
|
|
|
* globally unique key
|
|
|
|
*
|
|
|
|
* return a storage volume, or NULL if not found / error
|
|
|
|
*/
|
|
|
|
virStorageVolPtr
|
|
|
|
virStorageVolLookupByKey(virConnectPtr conn,
|
|
|
|
const char *key)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, key=%s", conn, key);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (key == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->volLookupByKey)
|
|
|
|
return conn->storageDriver->volLookupByKey (conn, key);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolLookupByPath:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @path: locally unique path
|
|
|
|
*
|
|
|
|
* Fetch a pointer to a storage volume based on its
|
|
|
|
* locally (host) unique path
|
|
|
|
*
|
|
|
|
* return a storage volume, or NULL if not found / error
|
|
|
|
*/
|
|
|
|
virStorageVolPtr
|
|
|
|
virStorageVolLookupByPath(virConnectPtr conn,
|
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, path=%s", conn, path);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (path == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->volLookupByPath)
|
|
|
|
return conn->storageDriver->volLookupByPath (conn, path);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolGetName:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
*
|
|
|
|
* Fetch the storage volume name. This is unique
|
|
|
|
* within the scope of a pool
|
|
|
|
*
|
|
|
|
* return the volume name, or NULL on error
|
|
|
|
*/
|
|
|
|
const char*
|
|
|
|
virStorageVolGetName(virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
DEBUG("vol=%p", vol);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (vol->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolGetKey:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
*
|
|
|
|
* Fetch the storage volume key. This is globally
|
2008-03-17 10:27:31 +00:00
|
|
|
* unique, so the same volume will have the same
|
2008-02-20 15:06:53 +00:00
|
|
|
* key no matter what host it is accessed from
|
|
|
|
*
|
|
|
|
* return the volume key, or NULL on error
|
|
|
|
*/
|
|
|
|
const char*
|
|
|
|
virStorageVolGetKey(virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
DEBUG("vol=%p", vol);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (vol->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolCreateXML:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
* @xmldesc: description of volume to create
|
|
|
|
* @flags: flags for creation (unused, pass 0)
|
|
|
|
*
|
|
|
|
* Create a storage volume within a pool based
|
|
|
|
* on an XML description. Not all pools support
|
|
|
|
* creation of volumes
|
|
|
|
*
|
|
|
|
* return the storage volume, or NULL on error
|
|
|
|
*/
|
|
|
|
virStorageVolPtr
|
|
|
|
virStorageVolCreateXML(virStoragePoolPtr pool,
|
|
|
|
const char *xmldesc,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p, flags=%u", pool, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(pool->conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->volCreateXML)
|
|
|
|
return pool->conn->storageDriver->volCreateXML (pool, xmldesc, flags);
|
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolDelete:
|
|
|
|
* @vol: pointer to storage volume
|
2008-03-17 10:48:02 +00:00
|
|
|
* @flags: future flags, use 0 for now
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Delete the storage volume from the pool
|
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageVolDelete(virStorageVolPtr vol,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("vol=%p, flags=%u", vol, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = vol->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStorageVolError(vol, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->volDelete)
|
|
|
|
return conn->storageDriver->volDelete (vol, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolFree:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
*
|
|
|
|
* Release the storage volume handle. The underlying
|
|
|
|
* storage volume contains to exist
|
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageVolFree(virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
DEBUG("vol=%p", vol);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (virUnrefStorageVol(vol) < 0)
|
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolGetInfo:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
* @info: pointer at which to store info
|
|
|
|
*
|
|
|
|
* Fetches volatile information about the storage
|
|
|
|
* volume such as its current allocation
|
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageVolGetInfo(virStorageVolPtr vol,
|
|
|
|
virStorageVolInfoPtr info)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("vol=%p, info=%p", vol, info);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (info == NULL) {
|
|
|
|
virLibStorageVolError(vol, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(info, 0, sizeof(virStorageVolInfo));
|
|
|
|
|
|
|
|
conn = vol->conn;
|
|
|
|
|
|
|
|
if (conn->storageDriver->volGetInfo)
|
|
|
|
return conn->storageDriver->volGetInfo (vol, info);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolGetXMLDesc:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
* @flags: flags for XML generation (unused, pass 0)
|
|
|
|
*
|
|
|
|
* Fetch an XML document describing all aspects of
|
|
|
|
* the storage volume
|
|
|
|
*
|
|
|
|
* Return the XML document, or NULL on error
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virStorageVolGetXMLDesc(virStorageVolPtr vol,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("vol=%p, flags=%u", vol, flags);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibStorageVolError(vol, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = vol->conn;
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->volGetXMLDesc)
|
|
|
|
return conn->storageDriver->volGetXMLDesc (vol, flags);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolGetPath:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
*
|
|
|
|
* Fetch the storage volume path. Depending on the pool
|
|
|
|
* configuration this is either persistent across hosts,
|
|
|
|
* or dynamically assigned at pool startup. Consult
|
|
|
|
* pool documentation for information on getting the
|
|
|
|
* persistent naming
|
|
|
|
*
|
|
|
|
* Returns the storage volume path, or NULL on error
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virStorageVolGetPath(virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("vol=%p", vol);
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = vol->conn;
|
|
|
|
|
|
|
|
if (conn->storageDriver && conn->storageDriver->volGetPath)
|
|
|
|
return conn->storageDriver->volGetPath (vol);
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|