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
|
|
|
|
*
|
2009-01-23 14:18:43 +00:00
|
|
|
* Copyright (C) 2005,2006,2008,2009 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>
|
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
|
2009-01-22 20:27:01 +00:00
|
|
|
#include <time.h>
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-04-28 18:29:26 +00:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/xpath.h>
|
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
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2008-11-06 16:36:07 +00:00
|
|
|
#include "logging.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
|
|
|
#include "libvirt_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"
|
2008-08-27 20:05:58 +00:00
|
|
|
#include "memory.h"
|
2008-08-20 20:48:35 +00:00
|
|
|
|
2008-11-21 12:16:08 +00:00
|
|
|
#ifndef WITH_DRIVER_MODULES
|
2008-08-20 20:48:35 +00:00
|
|
|
#ifdef WITH_TEST
|
2006-06-06 03:32:51 +00:00
|
|
|
#include "test.h"
|
2008-08-20 20:48:35 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_XEN
|
2007-04-04 14:19:49 +00:00
|
|
|
#include "xen_unified.h"
|
2008-08-20 20:48:35 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_REMOTE
|
2007-06-11 11:43:41 +00:00
|
|
|
#include "remote_internal.h"
|
2008-08-20 20:48:35 +00:00
|
|
|
#endif
|
2007-07-17 14:40:26 +00:00
|
|
|
#ifdef WITH_OPENVZ
|
|
|
|
#include "openvz_driver.h"
|
|
|
|
#endif
|
2009-07-24 14:17:06 +00:00
|
|
|
#ifdef WITH_PHYP
|
|
|
|
#include "phyp/phyp_driver.h"
|
|
|
|
#endif
|
2009-04-17 16:09:07 +00:00
|
|
|
#ifdef WITH_VBOX
|
|
|
|
#include "vbox/vbox_driver.h"
|
|
|
|
#endif
|
2009-07-23 20:21:08 +00:00
|
|
|
#ifdef WITH_ESX
|
|
|
|
#include "esx/esx_driver.h"
|
|
|
|
#endif
|
2008-11-21 12:16:08 +00:00
|
|
|
#endif
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2008-11-04 23:22:06 +00:00
|
|
|
#define MAX_DRIVERS 10
|
|
|
|
|
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;
|
2009-05-20 14:26:49 +00:00
|
|
|
static virInterfaceDriverPtr virInterfaceDriverTab[MAX_DRIVERS];
|
|
|
|
static int virInterfaceDriverTabCount = 0;
|
2008-02-20 15:06:53 +00:00
|
|
|
static virStorageDriverPtr virStorageDriverTab[MAX_DRIVERS];
|
|
|
|
static int virStorageDriverTabCount = 0;
|
2008-11-21 12:19:22 +00:00
|
|
|
static virDeviceMonitorPtr virDeviceMonitorTab[MAX_DRIVERS];
|
|
|
|
static int virDeviceMonitorTabCount = 0;
|
2009-08-14 19:42:19 +00:00
|
|
|
static virSecretDriverPtr virSecretDriverTab[MAX_DRIVERS];
|
|
|
|
static int virSecretDriverTabCount = 0;
|
2008-06-26 09:37:51 +00:00
|
|
|
#ifdef WITH_LIBVIRTD
|
2007-06-26 22:56:14 +00:00
|
|
|
static virStateDriverPtr virStateDriverTab[MAX_DRIVERS];
|
|
|
|
static int virStateDriverTabCount = 0;
|
2008-06-26 09:37:51 +00:00
|
|
|
#endif
|
2006-03-27 15:24:36 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
|
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);
|
2008-10-24 08:55:13 +00:00
|
|
|
return err == 0 ? 0 : -1;
|
2007-12-07 14:56:37 +00:00
|
|
|
}
|
|
|
|
#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)
|
|
|
|
{
|
|
|
|
if (initialized)
|
|
|
|
return(0);
|
2009-01-15 19:56:05 +00:00
|
|
|
|
2006-03-28 14:41:04 +00:00
|
|
|
initialized = 1;
|
2006-03-27 15:24:36 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (virThreadInitialize() < 0 ||
|
2009-01-22 20:27:01 +00:00
|
|
|
virErrorInitialize() < 0 ||
|
|
|
|
virRandomInitialize(time(NULL) ^ getpid()))
|
2009-01-15 19:56:05 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-08-06 13:55:07 +00:00
|
|
|
virLogSetFromEnv();
|
2008-01-19 18:36:01 +00:00
|
|
|
|
|
|
|
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
|
|
|
*/
|
2008-11-21 12:16:08 +00:00
|
|
|
#ifdef WITH_DRIVER_MODULES
|
|
|
|
/* We don't care if any of these fail, because the whole point
|
|
|
|
* is to allow users to only install modules they want to use.
|
|
|
|
* If they try to use a open a connection for a module that
|
|
|
|
* is not loaded they'll get a suitable error at that point
|
|
|
|
*/
|
|
|
|
virDriverLoadModule("test");
|
|
|
|
virDriverLoadModule("xen");
|
|
|
|
virDriverLoadModule("openvz");
|
2009-04-17 16:09:07 +00:00
|
|
|
virDriverLoadModule("vbox");
|
2009-07-23 20:21:08 +00:00
|
|
|
virDriverLoadModule("esx");
|
2008-11-21 12:16:08 +00:00
|
|
|
virDriverLoadModule("remote");
|
|
|
|
#else
|
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
|
2007-04-18 10:14:07 +00:00
|
|
|
#ifdef WITH_XEN
|
2008-11-21 12:16:08 +00:00
|
|
|
if (xenRegister () == -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
|
2009-07-24 14:17:06 +00:00
|
|
|
#ifdef WITH_PHYP
|
|
|
|
if (phypRegister() == -1) return -1;
|
|
|
|
#endif
|
2009-04-17 16:09:07 +00:00
|
|
|
#ifdef WITH_VBOX
|
|
|
|
if (vboxRegister() == -1) return -1;
|
|
|
|
#endif
|
2009-07-23 20:21:08 +00:00
|
|
|
#ifdef WITH_ESX
|
|
|
|
if (esxRegister() == -1) return -1;
|
|
|
|
#endif
|
2007-06-20 10:01:14 +00:00
|
|
|
#ifdef WITH_REMOTE
|
|
|
|
if (remoteRegister () == -1) return -1;
|
2008-11-21 12:16:08 +00:00
|
|
|
#endif
|
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);
|
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
BOOL WINAPI
|
|
|
|
DllMain (HINSTANCE instance, DWORD reason, LPVOID ignore);
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
DllMain (HINSTANCE instance ATTRIBUTE_UNUSED,
|
|
|
|
DWORD reason,
|
|
|
|
LPVOID ignore ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
switch (reason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
virInitialize();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
/* Nothing todo in libvirt yet */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
/* Release per-thread local data */
|
|
|
|
virThreadOnExit();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
/* Don't bother releasing per-thread data
|
|
|
|
since (hopefully) windows cleans up
|
|
|
|
everything on process exit */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-27 15:24:36 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
errmsg = virErrorMsg(error, info);
|
|
|
|
virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
errmsg = virErrorMsg(error, info);
|
|
|
|
virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_WARNING,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
2007-06-07 13:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
errmsg = virErrorMsg(error, info);
|
2006-02-27 16:27:18 +00:00
|
|
|
if (error != VIR_ERR_INVALID_DOMAIN) {
|
|
|
|
conn = domain->conn;
|
|
|
|
}
|
2008-11-04 22:30:33 +00:00
|
|
|
virRaiseError(conn, domain, NULL, VIR_FROM_DOM, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
errmsg = virErrorMsg(error, info);
|
2007-02-14 15:37:18 +00:00
|
|
|
if (error != VIR_ERR_INVALID_NETWORK) {
|
|
|
|
conn = network->conn;
|
|
|
|
}
|
2008-11-04 22:30:33 +00:00
|
|
|
virRaiseError(conn, NULL, network, VIR_FROM_NET, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 14:26:49 +00:00
|
|
|
/**
|
|
|
|
* virLibInterfaceError:
|
|
|
|
* @conn: the connection if available
|
|
|
|
* @error: the error number
|
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the connection level
|
|
|
|
*/
|
|
|
|
static void
|
2009-05-29 14:29:22 +00:00
|
|
|
virLibInterfaceError(virInterfacePtr iface, virErrorNumber error,
|
2009-05-20 14:26:49 +00:00
|
|
|
const char *info)
|
|
|
|
{
|
|
|
|
virConnectPtr conn = NULL;
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
|
|
if (error == VIR_ERR_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
errmsg = virErrorMsg(error, info);
|
|
|
|
if (error != VIR_ERR_INVALID_INTERFACE) {
|
2009-05-29 14:29:22 +00:00
|
|
|
conn = iface->conn;
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
virRaiseError(conn, NULL, NULL, VIR_FROM_INTERFACE, error, VIR_ERR_ERROR,
|
|
|
|
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;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
errmsg = virErrorMsg(error, info);
|
2008-02-20 15:06:53 +00:00
|
|
|
if (error != VIR_ERR_INVALID_STORAGE_POOL)
|
|
|
|
conn = pool->conn;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
virRaiseError(conn, NULL, NULL, VIR_FROM_STORAGE, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
errmsg = virErrorMsg(error, info);
|
2008-02-20 15:06:53 +00:00
|
|
|
if (error != VIR_ERR_INVALID_STORAGE_VOL)
|
|
|
|
conn = vol->conn;
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
virRaiseError(conn, NULL, NULL, VIR_FROM_STORAGE, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
/**
|
|
|
|
* virLibNodeDeviceError:
|
|
|
|
* @dev: the device if available
|
|
|
|
* @error: the error number
|
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the node device level
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virLibNodeDeviceError(virNodeDevicePtr dev, 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_NODE_DEVICE)
|
|
|
|
conn = dev->conn;
|
|
|
|
|
|
|
|
virRaiseError(conn, NULL, NULL, VIR_FROM_NODEDEV, error, VIR_ERR_ERROR,
|
|
|
|
errmsg, info, NULL, 0, 0, errmsg, info);
|
|
|
|
}
|
|
|
|
|
2009-07-28 01:25:39 +00:00
|
|
|
/**
|
|
|
|
* virLibSecretError:
|
|
|
|
* @secret: the secret if available
|
|
|
|
* @error: the error number
|
|
|
|
* @info: extra information string
|
|
|
|
*
|
|
|
|
* Handle an error at the secret level
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virLibSecretError(virSecretPtr secret, 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_SECRET)
|
|
|
|
conn = secret->conn;
|
|
|
|
|
|
|
|
virRaiseError(conn, NULL, NULL, VIR_FROM_SECRET, 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
|
|
|
}
|
|
|
|
|
2008-11-21 12:16:08 +00:00
|
|
|
DEBUG ("registering %s as network driver %d",
|
|
|
|
driver->name, virNetworkDriverTabCount);
|
|
|
|
|
2007-03-08 14:53:41 +00:00
|
|
|
virNetworkDriverTab[virNetworkDriverTabCount] = driver;
|
|
|
|
return virNetworkDriverTabCount++;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 14:26:49 +00:00
|
|
|
/**
|
|
|
|
* virRegisterInterfaceDriver:
|
2009-09-04 13:40:52 +00:00
|
|
|
* @driver: pointer to an interface driver block
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
2009-09-04 13:40:52 +00:00
|
|
|
* Register an interface virtualization driver
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Returns the driver priority or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virRegisterInterfaceDriver(virInterfaceDriverPtr driver)
|
|
|
|
{
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virInterfaceDriverTabCount >= MAX_DRIVERS) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG ("registering %s as interface driver %d",
|
|
|
|
driver->name, virInterfaceDriverTabCount);
|
|
|
|
|
|
|
|
virInterfaceDriverTab[virInterfaceDriverTabCount] = driver;
|
|
|
|
return virInterfaceDriverTabCount++;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:16:08 +00:00
|
|
|
DEBUG ("registering %s as storage driver %d",
|
|
|
|
driver->name, virStorageDriverTabCount);
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
virStorageDriverTab[virStorageDriverTabCount] = driver;
|
|
|
|
return virStorageDriverTabCount++;
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
/**
|
|
|
|
* virRegisterDeviceMonitor:
|
|
|
|
* @driver: pointer to a device monitor block
|
|
|
|
*
|
|
|
|
* Register a device monitor
|
|
|
|
*
|
|
|
|
* Returns the driver priority or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virRegisterDeviceMonitor(virDeviceMonitorPtr driver)
|
|
|
|
{
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virDeviceMonitorTabCount >= MAX_DRIVERS) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:46:39 +00:00
|
|
|
DEBUG ("registering %s as device driver %d",
|
|
|
|
driver->name, virDeviceMonitorTabCount);
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
virDeviceMonitorTab[virDeviceMonitorTabCount] = driver;
|
|
|
|
return virDeviceMonitorTabCount++;
|
|
|
|
}
|
|
|
|
|
2009-08-14 19:42:19 +00:00
|
|
|
/**
|
|
|
|
* virRegisterSecretDriver:
|
|
|
|
* @driver: pointer to a secret driver block
|
|
|
|
*
|
|
|
|
* Register a secret driver
|
|
|
|
*
|
|
|
|
* Returns the driver priority or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virRegisterSecretDriver(virSecretDriverPtr driver)
|
|
|
|
{
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (driver == NULL) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virSecretDriverTabCount >= MAX_DRIVERS) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG ("registering %s as secret driver %d",
|
|
|
|
driver->name, virSecretDriverTabCount);
|
|
|
|
|
|
|
|
virSecretDriverTab[virSecretDriverTabCount] = driver;
|
|
|
|
return virSecretDriverTabCount++;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-10-15 10:33:01 +00:00
|
|
|
DEBUG ("registering %s as driver %d",
|
|
|
|
driver->name, virDriverTabCount);
|
|
|
|
|
2007-03-08 14:53:41 +00:00
|
|
|
virDriverTab[virDriverTabCount] = driver;
|
|
|
|
return virDriverTabCount++;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 09:37:51 +00:00
|
|
|
#ifdef WITH_LIBVIRTD
|
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++;
|
|
|
|
}
|
|
|
|
|
2008-11-25 10:31:52 +00:00
|
|
|
/**
|
|
|
|
* virStateInitialize:
|
2009-07-01 13:08:17 +00:00
|
|
|
* @privileged: set to 1 if running with root priviledge, 0 otherwise
|
2008-11-25 10:31:52 +00:00
|
|
|
*
|
|
|
|
* Initialize all virtualization drivers.
|
|
|
|
*
|
|
|
|
* Return 0 if all succeed, -1 upon any failure.
|
|
|
|
*/
|
2009-06-12 13:20:13 +00:00
|
|
|
int virStateInitialize(int privileged) {
|
2007-06-26 22:56:14 +00:00
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
if (virInitialize() < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0 ; i < virStateDriverTabCount ; i++) {
|
2007-10-27 01:23:28 +00:00
|
|
|
if (virStateDriverTab[i]->initialize &&
|
2009-06-12 13:20:13 +00:00
|
|
|
virStateDriverTab[i]->initialize(privileged) < 0)
|
2007-06-26 22:56:14 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-25 10:31:52 +00:00
|
|
|
/**
|
|
|
|
* virStateCleanup:
|
|
|
|
*
|
|
|
|
* Run each virtualization driver's cleanup method.
|
|
|
|
*
|
|
|
|
* Return 0 if all succeed, -1 upon any failure.
|
|
|
|
*/
|
2008-11-17 11:03:25 +00:00
|
|
|
int virStateCleanup(void) {
|
2007-06-26 22:56:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-11-25 10:31:52 +00:00
|
|
|
/**
|
|
|
|
* virStateReload:
|
|
|
|
*
|
|
|
|
* Run each virtualization driver's reload method.
|
|
|
|
*
|
|
|
|
* Return 0 if all succeed, -1 upon any failure.
|
|
|
|
*/
|
2008-11-17 11:03:25 +00:00
|
|
|
int virStateReload(void) {
|
2007-06-26 22:56:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-11-25 10:31:52 +00:00
|
|
|
/**
|
|
|
|
* virStateActive:
|
|
|
|
*
|
|
|
|
* Run each virtualization driver's "active" method.
|
|
|
|
*
|
|
|
|
* Return 0 if none are active, 1 if at least one is.
|
|
|
|
*/
|
2008-11-17 11:03:25 +00:00
|
|
|
int virStateActive(void) {
|
2007-06-26 22:56:14 +00:00
|
|
|
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-06-26 09:37:51 +00:00
|
|
|
#endif
|
2008-05-13 06:30:58 +00:00
|
|
|
|
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)
|
|
|
|
{
|
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";
|
2009-02-17 10:33:41 +00:00
|
|
|
|
|
|
|
/* FIXME: Add _proper_ type version handling for loadable driver modules... */
|
|
|
|
#ifdef WITH_DRIVER_MODULES
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#else
|
2008-11-28 12:03:20 +00:00
|
|
|
*typeVer = 0;
|
2009-02-17 10:33:41 +00:00
|
|
|
|
2008-11-28 12:03:20 +00:00
|
|
|
#if WITH_XEN
|
|
|
|
if (STRCASEEQ(type, "Xen"))
|
|
|
|
*typeVer = xenUnifiedVersion();
|
|
|
|
#endif
|
|
|
|
#if WITH_TEST
|
|
|
|
if (STRCASEEQ(type, "Test"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
|
|
|
#if WITH_QEMU
|
|
|
|
if (STRCASEEQ(type, "QEMU"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
|
|
|
#if WITH_LXC
|
|
|
|
if (STRCASEEQ(type, "LXC"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
2009-07-24 14:17:06 +00:00
|
|
|
#if WITH_PHYP
|
|
|
|
if (STRCASEEQ(type, "phyp"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
2008-11-28 12:03:20 +00:00
|
|
|
#if WITH_OPENVZ
|
|
|
|
if (STRCASEEQ(type, "OpenVZ"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
2009-04-17 16:09:07 +00:00
|
|
|
#if WITH_VBOX
|
|
|
|
if (STRCASEEQ(type, "VBox"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
2008-11-28 12:03:20 +00:00
|
|
|
#if WITH_UML
|
|
|
|
if (STRCASEEQ(type, "UML"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
2009-05-25 11:56:00 +00:00
|
|
|
#if WITH_ONE
|
|
|
|
if (STRCASEEQ(type, "ONE"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
2009-07-23 20:21:08 +00:00
|
|
|
#if WITH_ESX
|
|
|
|
if (STRCASEEQ(type, "ESX"))
|
|
|
|
*typeVer = LIBVIR_VERSION_NUMBER;
|
|
|
|
#endif
|
2008-11-28 12:03:20 +00:00
|
|
|
#if WITH_REMOTE
|
|
|
|
if (STRCASEEQ(type, "Remote"))
|
|
|
|
*typeVer = remoteVersion();
|
|
|
|
#endif
|
|
|
|
if (*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);
|
|
|
|
}
|
2009-02-17 10:33:41 +00:00
|
|
|
#endif /* WITH_DRIVER_MODULES */
|
2006-03-15 12:13:25 +00:00
|
|
|
}
|
|
|
|
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;
|
2008-11-17 11:44:51 +00:00
|
|
|
virConnectPtr ret;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
ret = virGetConnect();
|
|
|
|
if (ret == NULL)
|
|
|
|
return NULL;
|
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-11-17 11:44:51 +00:00
|
|
|
name = NULL;
|
2008-04-10 16:54:54 +00:00
|
|
|
}
|
2008-02-26 07:05:18 +00:00
|
|
|
}
|
2007-07-05 13:49:17 +00:00
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
if (name) {
|
|
|
|
/* Convert xen -> xen:/// for back compat */
|
|
|
|
if (STRCASEEQ(name, "xen"))
|
|
|
|
name = "xen:///";
|
|
|
|
|
|
|
|
/* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
|
|
|
|
* former. This allows URIs such as xen://localhost to work.
|
|
|
|
*/
|
|
|
|
if (STREQ (name, "xen://"))
|
|
|
|
name = "xen:///";
|
|
|
|
|
|
|
|
ret->uri = xmlParseURI (name);
|
|
|
|
if (!ret->uri) {
|
|
|
|
virLibConnError (ret, VIR_ERR_INVALID_ARG,
|
|
|
|
_("could not parse connection URI"));
|
|
|
|
goto failed;
|
|
|
|
}
|
2006-03-20 17:49:28 +00:00
|
|
|
|
2008-11-17 11:44:51 +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,
|
2009-01-15 17:54:20 +00:00
|
|
|
NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->opaque),
|
|
|
|
NULLSTR(ret->uri->authority), NULLSTR(ret->uri->server),
|
|
|
|
NULLSTR(ret->uri->user), ret->uri->port,
|
|
|
|
NULLSTR(ret->uri->path));
|
2008-11-17 11:44:51 +00:00
|
|
|
} else {
|
|
|
|
DEBUG0("no name, allowing driver auto-select");
|
2007-11-14 11:40:57 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2008-11-17 11:44:51 +00:00
|
|
|
res = virDriverTab[i]->open (ret, 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++) {
|
2008-11-17 11:44:51 +00:00
|
|
|
res = virNetworkDriverTab[i]->open (ret, 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
|
|
|
|
2009-05-20 14:26:49 +00:00
|
|
|
for (i = 0; i < virInterfaceDriverTabCount; i++) {
|
|
|
|
res = virInterfaceDriverTab[i]->open (ret, auth, flags);
|
|
|
|
DEBUG("interface driver %d %s returned %s",
|
|
|
|
i, virInterfaceDriverTab[i]->name,
|
|
|
|
res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
|
|
|
|
(res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
|
|
|
|
(res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
|
|
|
|
if (res == VIR_DRV_OPEN_ERROR) {
|
|
|
|
if (STREQ(virInterfaceDriverTab[i]->name, "remote")) {
|
|
|
|
virLibConnWarning (NULL, VIR_WAR_NO_INTERFACE,
|
|
|
|
"Is the daemon running ?");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else if (res == VIR_DRV_OPEN_SUCCESS) {
|
|
|
|
ret->interfaceDriver = virInterfaceDriverTab[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
/* Secondary driver for storage. Optional */
|
|
|
|
for (i = 0; i < virStorageDriverTabCount; i++) {
|
2008-11-17 11:44:51 +00:00
|
|
|
res = virStorageDriverTab[i]->open (ret, auth, flags);
|
2008-02-20 15:06:53 +00:00
|
|
|
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")));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
/* Node driver (optional) */
|
|
|
|
for (i = 0; i < virDeviceMonitorTabCount; i++) {
|
|
|
|
res = virDeviceMonitorTab[i]->open (ret, auth, flags);
|
|
|
|
DEBUG("node driver %d %s returned %s",
|
|
|
|
i, virDeviceMonitorTab[i]->name,
|
|
|
|
res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
|
|
|
|
(res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
|
|
|
|
(res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
|
|
|
|
if (res == VIR_DRV_OPEN_ERROR) {
|
|
|
|
if (STREQ(virDeviceMonitorTab[i]->name, "remote")) {
|
|
|
|
virLibConnWarning (NULL, VIR_WAR_NO_NODE,
|
|
|
|
"Is the libvirtd daemon running ?");
|
|
|
|
} else {
|
|
|
|
char *msg;
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&msg, "Is the %s daemon running?",
|
|
|
|
virDeviceMonitorTab[i]->name) > 0) {
|
2008-11-21 12:19:22 +00:00
|
|
|
virLibConnWarning (NULL, VIR_WAR_NO_NODE, msg);
|
|
|
|
VIR_FREE(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else if (res == VIR_DRV_OPEN_SUCCESS) {
|
|
|
|
ret->deviceMonitor = virDeviceMonitorTab[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-14 19:42:19 +00:00
|
|
|
/* Secret manipulation driver. Optional */
|
|
|
|
for (i = 0; i < virSecretDriverTabCount; i++) {
|
|
|
|
res = virSecretDriverTab[i]->open (ret, auth, flags);
|
|
|
|
DEBUG("secret driver %d %s returned %s",
|
|
|
|
i, virSecretDriverTab[i]->name,
|
|
|
|
res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
|
|
|
|
(res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
|
|
|
|
(res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
|
|
|
|
if (res == VIR_DRV_OPEN_ERROR) {
|
|
|
|
if (STREQ(virSecretDriverTab[i]->name, "remote")) {
|
|
|
|
virLibConnWarning (NULL, VIR_WAR_NO_SECRET,
|
|
|
|
"Is the daemon running ?");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else if (res == VIR_DRV_OPEN_SUCCESS) {
|
|
|
|
ret->secretDriver = virSecretDriverTab[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
return ret;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
failed:
|
2009-01-20 12:01:45 +00:00
|
|
|
/* Ensure a global error is set in case driver forgot */
|
|
|
|
virSetGlobalError();
|
2008-08-21 10:12:32 +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
|
|
|
*
|
2009-07-06 17:43:21 +00:00
|
|
|
* If @name is NULL then probing will be done to determine a suitable
|
|
|
|
* default driver to activate. This involves trying each hypervisor
|
|
|
|
* in turn until one successfully opens. If the LIBVIRT_DEFAULT_URI
|
|
|
|
* environment variable is set, then it will be used in preference
|
|
|
|
* to probing for a driver.
|
|
|
|
*
|
|
|
|
* If connecting to an unprivileged hypervisor driver which requires
|
|
|
|
* the libvirtd daemon to be active, it will automatically be launched
|
|
|
|
* if not already running. This can be prevented by setting the
|
|
|
|
* environment variable LIBVIRT_AUTOSTART=0
|
|
|
|
*
|
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
|
|
|
*
|
2009-07-06 17:43:21 +00:00
|
|
|
* See virConnectOpen for notes about environment variables which can
|
|
|
|
* have an effect on opening drivers
|
|
|
|
*
|
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
|
|
|
|
*
|
2009-07-06 17:43:21 +00:00
|
|
|
* See virConnectOpen for notes about environment variables which can
|
|
|
|
* have an effect on opening drivers
|
|
|
|
*
|
2007-12-05 18:28:05 +00:00
|
|
|
* 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;
|
|
|
|
|
2009-01-15 17:54:20 +00:00
|
|
|
DEBUG("name=%s, auth=%p, flags=%d", NULLSTR(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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2009-01-20 12:01:45 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2009-08-11 13:48:59 +00:00
|
|
|
return virUnrefConnect(conn);
|
2005-11-02 12:50:21 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:14:03 +00:00
|
|
|
/**
|
|
|
|
* virConnectRef:
|
|
|
|
* @conn: the connection to hold a reference on
|
|
|
|
*
|
|
|
|
* Increment the reference count on the connection. For each
|
|
|
|
* additional call to this method, there shall be a corresponding
|
|
|
|
* call to virConnectClose to release the reference count, once
|
|
|
|
* the caller no longer needs the reference to this object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple
|
|
|
|
* threads are using a connection, and it is required that the
|
|
|
|
* connection remain open until all threads have finished using
|
|
|
|
* it. ie, each new thread using a connection would increment
|
|
|
|
* the reference count.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure
|
2009-01-20 12:14:03 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectRef(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
if ((!VIR_IS_CONNECT(conn))) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
virMutexLock(&conn->lock);
|
|
|
|
DEBUG("conn=%p refs=%d", conn, conn->refs);
|
|
|
|
conn->refs++;
|
|
|
|
virMutexUnlock(&conn->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-25 15:48:11 +00:00
|
|
|
/*
|
|
|
|
* Not for public use. This function is part of the internal
|
2007-08-21 09:03:55 +00:00
|
|
|
* implementation of driver features in the remote case.
|
|
|
|
*/
|
|
|
|
int
|
2008-11-17 11:03:25 +00:00
|
|
|
virDrvSupportsFeature (virConnectPtr conn, int feature)
|
2007-08-21 09:03:55 +00:00
|
|
|
{
|
2009-01-20 12:01:45 +00:00
|
|
|
int ret;
|
2007-08-21 09:03:55 +00:00
|
|
|
DEBUG("conn=%p, feature=%d", conn, feature);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2007-08-21 09:03:55 +00:00
|
|
|
return (-1);
|
2009-01-20 12:01:45 +00:00
|
|
|
}
|
2007-08-21 09:03:55 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
ret = VIR_DRV_SUPPORTS_FEATURE (conn->driver, conn, feature);
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return ret;
|
2007-08-21 09:03:55 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 13:26:52 +00:00
|
|
|
/**
|
|
|
|
* virConnectGetType:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Get the name of the Hypervisor software used.
|
|
|
|
*
|
|
|
|
* Returns NULL in case of error, a static zero terminated string otherwise.
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->version) {
|
|
|
|
int ret = conn->driver->version (conn, hvVer);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 01:40:09 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->getHostname) {
|
|
|
|
char *ret = conn->driver->getHostname (conn);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-06-26 11:42:46 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-06-26 11:42:46 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
name = (char *)xmlSaveUri(conn->uri);
|
2007-11-14 11:40:57 +00:00
|
|
|
if (!name) {
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError (conn);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-11-14 11:40:57 +00:00
|
|
|
}
|
|
|
|
return name;
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
return -1;
|
2007-03-08 08:31:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->getMaxVcpus) {
|
|
|
|
int ret = conn->driver->getMaxVcpus (conn, type);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-03-08 08:31:07 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->listDomains) {
|
|
|
|
int ret = conn->driver->listDomains (conn, ids, maxids);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-04-24 18:21:29 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2005-12-07 11:03:24 +00:00
|
|
|
/**
|
|
|
|
* virConnectNumOfDomains:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
2005-12-08 16:42:56 +00:00
|
|
|
* Provides the number of active domains.
|
|
|
|
*
|
2005-12-07 11:03:24 +00:00
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virConnectNumOfDomains(virConnectPtr conn)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-09-02 15:47:51 +00:00
|
|
|
return -1;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2005-12-16 18:41:46 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->numOfDomains) {
|
|
|
|
int ret = conn->driver->numOfDomains (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-04-24 18:21:29 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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
|
|
|
/**
|
2008-10-10 09:32:27 +00:00
|
|
|
* virDomainCreateXML:
|
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
|
2008-09-17 14:15:20 +00:00
|
|
|
* @flags: callers should always pass 0
|
2005-11-07 17:16:18 +00:00
|
|
|
*
|
2008-10-10 09:32:27 +00:00
|
|
|
* Launch a new guest domain, based on an XML description similar
|
2006-02-20 23:08:47 +00:00
|
|
|
* to the one returned by virDomainGetXMLDesc()
|
2008-03-17 10:27:31 +00:00
|
|
|
* This function may requires privileged access to the hypervisor.
|
2008-08-01 06:42:45 +00:00
|
|
|
* The domain is not persistent, so its definition will disappear when it
|
|
|
|
* is destroyed, or if the host is restarted (see virDomainDefineXML() to
|
|
|
|
* define persistent domains).
|
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
|
2008-10-10 09:32:27 +00:00
|
|
|
virDomainCreateXML(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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-02-27 16:27:18 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainCreateXML) {
|
|
|
|
virDomainPtr ret;
|
|
|
|
ret = conn->driver->domainCreateXML (conn, xmlDesc, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 09:32:27 +00:00
|
|
|
/**
|
|
|
|
* virDomainCreateLinux:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @xmlDesc: string containing an XML description of the domain
|
|
|
|
* @flags: callers should always pass 0
|
|
|
|
*
|
|
|
|
* Deprecated after 0.4.6.
|
|
|
|
* Renamed to virDomainCreateXML() providing identical functionality.
|
|
|
|
* This existing name will left indefinitely for API compatability.
|
|
|
|
*
|
|
|
|
* Returns a new domain object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
|
|
|
virDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return(virDomainCreateXML(conn, xmlDesc, flags));
|
|
|
|
}
|
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
|
2008-07-16 20:42:38 +00:00
|
|
|
* Note that this won't work for inactive domains which have an ID of -1,
|
|
|
|
* in that case a lookup based on the Name or UUId need to be done instead.
|
2005-11-30 13:20:53 +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-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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2005-11-30 13:20:53 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainLookupByID) {
|
|
|
|
virDomainPtr ret;
|
|
|
|
ret = conn->driver->domainLookupByID (conn, id);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2006-02-23 10:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainLookupByUUID:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-05-22 14:38:33 +00:00
|
|
|
* @uuid: the raw UUID for the domain
|
2006-02-23 10:13:55 +00:00
|
|
|
*
|
|
|
|
* Try to lookup a domain on the given hypervisor based on its UUID.
|
|
|
|
*
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainLookupByUUID) {
|
|
|
|
virDomainPtr ret;
|
|
|
|
ret = conn->driver->domainLookupByUUID (conn, uuid);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2005-11-30 13:20:53 +00:00
|
|
|
}
|
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
/**
|
|
|
|
* virDomainLookupByUUIDString:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @uuidstr: the string UUID for the domain
|
|
|
|
*
|
|
|
|
* Try to lookup a domain on the given hypervisor based on its UUID.
|
|
|
|
*
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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]);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
2006-05-22 14:38:33 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-02-27 16:27:18 +00:00
|
|
|
}
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainLookupByName) {
|
|
|
|
virDomainPtr dom;
|
|
|
|
dom = conn->driver->domainLookupByName (conn, name);
|
|
|
|
if (!dom)
|
|
|
|
goto error;
|
|
|
|
return dom;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return NULL;
|
2005-12-12 13:22:20 +00:00
|
|
|
}
|
|
|
|
|
2005-11-07 17:16:18 +00:00
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainDestroy:
|
2005-11-07 17:16:18 +00:00
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Destroy the domain object. The running instance is shutdown if not down
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainDestroy) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainDestroy (domain);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-01-18 10:37:08 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2005-12-08 16:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainFree:
|
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Free the domain object. The running instance is kept alive.
|
|
|
|
* The data structure is freed and should not be used thereafter.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virDomainFree(virDomainPtr domain)
|
|
|
|
{
|
2007-07-12 08:34:51 +00:00
|
|
|
DEBUG("domain=%p", domain);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2008-01-21 16:29:10 +00:00
|
|
|
if (virUnrefDomain(domain) < 0)
|
2009-01-20 12:01:45 +00:00
|
|
|
return -1;
|
2006-04-09 13:11:22 +00:00
|
|
|
return(0);
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:14:03 +00:00
|
|
|
/**
|
|
|
|
* virDomainRef:
|
2009-04-24 14:04:54 +00:00
|
|
|
* @domain: the domain to hold a reference on
|
2009-01-20 12:14:03 +00:00
|
|
|
*
|
|
|
|
* Increment the reference count on the domain. For each
|
|
|
|
* additional call to this method, there shall be a corresponding
|
|
|
|
* call to virDomainFree to release the reference count, once
|
|
|
|
* the caller no longer needs the reference to this object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple
|
|
|
|
* threads are using a connection, and it is required that the
|
|
|
|
* connection remain open until all threads have finished using
|
|
|
|
* it. ie, each new thread using a domain would increment
|
|
|
|
* the reference count.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
2009-01-20 12:14:03 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainRef(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
if ((!VIR_IS_CONNECTED_DOMAIN(domain))) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
virMutexLock(&domain->conn->lock);
|
|
|
|
DEBUG("domain=%p refs=%d", domain, domain->refs);
|
|
|
|
domain->refs++;
|
|
|
|
virMutexUnlock(&domain->conn->lock);
|
|
|
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainSuspend) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainSuspend (domain);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2005-11-07 17:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-05 11:16:07 +00:00
|
|
|
* virDomainResume:
|
2005-11-07 17:16:18 +00:00
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Resume an suspended domain, the process is restarted from the state where
|
2005-12-05 11:16:07 +00:00
|
|
|
* it was frozen by calling virSuspendDomain().
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainResume) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainResume (domain);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainSave) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainSave (domain, to);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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);
|
2009-01-20 12:01:45 +00:00
|
|
|
if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_SYSTEM_ERROR,
|
|
|
|
_("cannot get working directory"));
|
|
|
|
goto error;
|
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
len = strlen(filepath);
|
|
|
|
/* that should be covered by getcwd() semantic, but be 100% sure */
|
2009-01-20 12:01:45 +00:00
|
|
|
if (len > sizeof(filepath) - (t + 3)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("path too long"));
|
|
|
|
goto error;
|
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
filepath[len] = '/';
|
|
|
|
strcpy(&filepath[len + 1], from);
|
|
|
|
from = &filepath[0];
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainRestore) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainRestore (conn, from);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-11-22 17:48:29 +00:00
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
if (to == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-11-22 17:48:29 +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] != '/') {
|
|
|
|
unsigned int len, t;
|
|
|
|
|
|
|
|
t = strlen(to);
|
2009-01-20 12:01:45 +00:00
|
|
|
if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_SYSTEM_ERROR,
|
|
|
|
_("cannot get current directory"));
|
|
|
|
goto error;
|
|
|
|
}
|
2006-11-22 17:48:29 +00:00
|
|
|
len = strlen(filepath);
|
|
|
|
/* that should be covered by getcwd() semantic, but be 100% sure */
|
2009-01-20 12:01:45 +00:00
|
|
|
if (len > sizeof(filepath) - (t + 3)) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("path too long"));
|
|
|
|
goto error;
|
|
|
|
}
|
2006-11-22 17:48:29 +00:00
|
|
|
filepath[len] = '/';
|
|
|
|
strcpy(&filepath[len + 1], to);
|
|
|
|
to = &filepath[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainCoreDump) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainCoreDump (domain, to, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainShutdown) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainShutdown (domain);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainReboot) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainReboot (domain, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-06-14 17:07:00 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-05-22 14:38:33 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2006-05-22 14:38:33 +00:00
|
|
|
if (virDomainGetUUID(domain, &uuid[0]))
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
|
|
|
return -1;
|
2006-05-22 14:38:33 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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 (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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainGetOSType) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->driver->domainGetOSType (domain);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-11-07 16:28:16 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainGetMaxMemory) {
|
|
|
|
unsigned long ret;
|
|
|
|
ret = conn->driver->domainGetMaxMemory (domain);
|
|
|
|
if (ret == 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
if (memory < 4096) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-04-13 17:18:49 +00:00
|
|
|
conn = domain->conn;
|
2006-03-22 13:44:01 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainSetMaxMemory) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainSetMaxMemory (domain, memory);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
if (memory < 4096) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn = domain->conn;
|
2005-12-12 13:22:20 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainSetMemory) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainSetMemory (domain, memory);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainGetInfo) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainGetInfo (domain, info);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-05-29 18:03:27 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
2008-10-10 09:32:27 +00:00
|
|
|
* later to relaunch the domain with virDomainCreateXML().
|
2006-02-20 23:08:47 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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 (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;
|
|
|
|
|
2009-03-16 17:21:12 +00:00
|
|
|
if ((conn->flags & VIR_CONNECT_RO) && (flags & VIR_DOMAIN_XML_SECURE)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED,
|
|
|
|
_("virDomainGetXMLDesc with secure flag"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-07-17 21:08:33 +00:00
|
|
|
flags &= VIR_DOMAIN_XML_FLAGS_MASK;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainDumpXML) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->driver->domainDumpXML (domain, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-05-21 13:46:35 +00:00
|
|
|
/**
|
|
|
|
* virConnectDomainXMLFromNative:
|
|
|
|
* @conn: a connection object
|
|
|
|
* @nativeFormat: configuration format importing from
|
|
|
|
* @nativeConfig: the configuration data to import
|
|
|
|
* @flags: currently unused, pass 0
|
|
|
|
*
|
|
|
|
* Reads native configuration data describing a domain, and
|
|
|
|
* generates libvirt domain XML. The format of the native
|
|
|
|
* data is hypervisor dependant.
|
|
|
|
*
|
|
|
|
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *virConnectDomainXMLFromNative(virConnectPtr conn,
|
|
|
|
const char *nativeFormat,
|
|
|
|
const char *nativeConfig,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, format=%s config=%s flags=%u", conn, nativeFormat, nativeConfig, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nativeFormat == NULL || nativeConfig == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->driver->domainXMLFromNative) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->driver->domainXMLFromNative (conn,
|
|
|
|
nativeFormat,
|
|
|
|
nativeConfig,
|
|
|
|
flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectDomainXMLToNative:
|
|
|
|
* @conn: a connection object
|
|
|
|
* @nativeFormat: configuration format exporting to
|
|
|
|
* @domainXml: the domain configuration to export
|
|
|
|
* @flags: currently unused, pass 0
|
|
|
|
*
|
|
|
|
* Reads a domain XML configuration document, and generates
|
|
|
|
* generates a native configuration file describing the domain.
|
|
|
|
* The format of the native data is hypervisor dependant.
|
|
|
|
*
|
|
|
|
* Returns a 0 terminated UTF-8 encoded native config datafile, or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *virConnectDomainXMLToNative(virConnectPtr conn,
|
|
|
|
const char *nativeFormat,
|
|
|
|
const char *domainXml,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, format=%s xml=%s flags=%u", conn, nativeFormat, domainXml, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nativeFormat == NULL || domainXml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->driver->domainXMLToNative) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->driver->domainXMLToNative(conn,
|
|
|
|
nativeFormat,
|
|
|
|
domainXml,
|
|
|
|
flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-30 14:52:02 +00:00
|
|
|
static virDomainPtr
|
|
|
|
virDomainMigrateVersion1 (virDomainPtr domain,
|
|
|
|
virConnectPtr dconn,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
|
|
|
virDomainPtr ddomain = NULL;
|
|
|
|
char *uri_out = NULL;
|
|
|
|
char *cookie = NULL;
|
|
|
|
int cookielen = 0;
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
if (dconn->driver->domainMigratePrepare
|
|
|
|
(dconn, &cookie, &cookielen, uri, &uri_out, flags, dname,
|
|
|
|
bandwidth) == -1)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (uri == NULL && uri_out == NULL) {
|
|
|
|
virLibConnError (domain->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("domainMigratePrepare did not set uri"));
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
if (domain->conn->driver->domainMigratePerform
|
|
|
|
(domain, cookie, cookielen, uri, flags, dname, bandwidth) == -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:
|
|
|
|
VIR_FREE (uri_out);
|
|
|
|
VIR_FREE (cookie);
|
|
|
|
return ddomain;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
virDomainMigrateVersion2 (virDomainPtr domain,
|
|
|
|
virConnectPtr dconn,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
|
|
|
virDomainPtr ddomain = NULL;
|
|
|
|
char *uri_out = NULL;
|
|
|
|
char *cookie = NULL;
|
|
|
|
char *dom_xml = NULL;
|
|
|
|
int cookielen = 0, ret;
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* In version 2 of the protocol, the prepare step is slightly
|
|
|
|
* different. We fetch the domain XML of the source domain
|
|
|
|
* and pass it to Prepare2.
|
|
|
|
*/
|
|
|
|
if (!domain->conn->driver->domainDumpXML) {
|
|
|
|
virLibConnError (domain->conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
dom_xml = domain->conn->driver->domainDumpXML (domain,
|
|
|
|
VIR_DOMAIN_XML_SECURE);
|
|
|
|
if (!dom_xml)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = dconn->driver->domainMigratePrepare2
|
|
|
|
(dconn, &cookie, &cookielen, uri, &uri_out, flags, dname,
|
|
|
|
bandwidth, dom_xml);
|
|
|
|
VIR_FREE (dom_xml);
|
|
|
|
if (ret == -1)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (uri == NULL && uri_out == NULL) {
|
|
|
|
virLibConnError (domain->conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("domainMigratePrepare2 did not set uri"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (uri_out)
|
|
|
|
uri = uri_out; /* Did domainMigratePrepare2 change URI? */
|
|
|
|
assert (uri != NULL);
|
|
|
|
|
|
|
|
/* Perform the migration. The driver isn't supposed to return
|
|
|
|
* until the migration is complete.
|
|
|
|
*/
|
|
|
|
ret = domain->conn->driver->domainMigratePerform
|
|
|
|
(domain, cookie, cookielen, uri, flags, dname, bandwidth);
|
|
|
|
|
|
|
|
/* In version 2 of the migration protocol, we pass the
|
|
|
|
* status code from the sender to the destination host,
|
|
|
|
* so it can do any cleanup if the migration failed.
|
|
|
|
*/
|
|
|
|
dname = dname ? dname : domain->name;
|
|
|
|
ddomain = dconn->driver->domainMigrateFinish2
|
|
|
|
(dconn, dname, cookie, cookielen, uri, flags, ret);
|
|
|
|
|
|
|
|
done:
|
|
|
|
VIR_FREE (uri_out);
|
|
|
|
VIR_FREE (cookie);
|
|
|
|
return ddomain;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
virDomainPtr ddomain = NULL;
|
|
|
|
DEBUG("domain=%p, dconn=%p, flags=%lu, dname=%s, uri=%s, bandwidth=%lu",
|
2009-01-30 15:43:05 +00:00
|
|
|
domain, dconn, flags, NULLSTR(dname), NULLSTR(uri), bandwidth);
|
2007-08-21 09:31:12 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2009-07-30 14:52:02 +00:00
|
|
|
/* First checkout the source */
|
2009-01-20 12:01:45 +00:00
|
|
|
if (!VIR_IS_CONNECTED_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;
|
|
|
|
}
|
2009-07-30 14:52:02 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-08-21 09:31:12 +00:00
|
|
|
}
|
|
|
|
|
2009-07-30 14:52:02 +00:00
|
|
|
/* Now checkout the destination */
|
|
|
|
if (!VIR_IS_CONNECT (dconn)) {
|
|
|
|
virLibConnError (domain->conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
if (dconn->flags & VIR_CONNECT_RO) {
|
2009-07-30 14:52:02 +00:00
|
|
|
/* NB, deliberately report error against source object, not dest */
|
|
|
|
virLibDomainError (domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 09:31:12 +00:00
|
|
|
/* Check that migration is supported by both drivers. */
|
2009-07-30 14:52:02 +00:00
|
|
|
if (VIR_DRV_SUPPORTS_FEATURE (domain->conn->driver, domain->conn,
|
2008-11-14 08:42:47 +00:00
|
|
|
VIR_DRV_FEATURE_MIGRATION_V1) &&
|
|
|
|
VIR_DRV_SUPPORTS_FEATURE (dconn->driver, dconn,
|
|
|
|
VIR_DRV_FEATURE_MIGRATION_V1))
|
2009-07-30 14:52:02 +00:00
|
|
|
ddomain = virDomainMigrateVersion1 (domain, dconn, flags, dname, uri, bandwidth);
|
|
|
|
else if (VIR_DRV_SUPPORTS_FEATURE (domain->conn->driver, domain->conn,
|
2008-11-14 08:42:47 +00:00
|
|
|
VIR_DRV_FEATURE_MIGRATION_V2) &&
|
|
|
|
VIR_DRV_SUPPORTS_FEATURE (dconn->driver, dconn,
|
|
|
|
VIR_DRV_FEATURE_MIGRATION_V2))
|
2009-07-30 14:52:02 +00:00
|
|
|
ddomain = virDomainMigrateVersion2 (domain, dconn, flags, dname, uri, bandwidth);
|
2008-11-14 08:42:47 +00:00
|
|
|
else {
|
2009-07-30 14:52:02 +00:00
|
|
|
virLibConnError (domain->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-08-21 09:31:12 +00:00
|
|
|
}
|
|
|
|
|
2009-07-30 14:52:02 +00:00
|
|
|
if (ddomain == NULL)
|
|
|
|
goto error;
|
2008-11-14 08:42:47 +00:00
|
|
|
|
2007-08-21 09:31:12 +00:00
|
|
|
return ddomain;
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
|
|
|
return NULL;
|
2007-08-21 09:31:12 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 15:48:11 +00:00
|
|
|
/*
|
|
|
|
* Not for public use. This function is part of the internal
|
2007-08-21 09:31:12 +00:00
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
int
|
2008-11-17 11:03:25 +00:00
|
|
|
virDomainMigratePrepare (virConnectPtr dconn,
|
2009-07-30 14:32:44 +00:00
|
|
|
char **cookie,
|
|
|
|
int *cookielen,
|
|
|
|
const char *uri_in,
|
|
|
|
char **uri_out,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
unsigned long bandwidth)
|
2007-08-21 09:31:12 +00:00
|
|
|
{
|
2009-02-02 18:41:56 +00:00
|
|
|
VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p, "
|
|
|
|
"flags=%lu, dname=%s, bandwidth=%lu", dconn, cookie, cookielen,
|
|
|
|
NULLSTR(uri_in), uri_out, flags, NULLSTR(dname), bandwidth);
|
2007-08-21 09:31:12 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2007-08-21 09:31:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (dconn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(dconn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (dconn->driver->domainMigratePrepare) {
|
|
|
|
int ret;
|
|
|
|
ret = dconn->driver->domainMigratePrepare (dconn, cookie, cookielen,
|
|
|
|
uri_in, uri_out,
|
|
|
|
flags, dname, bandwidth);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-08-21 09:31:12 +00:00
|
|
|
|
|
|
|
virLibConnError (dconn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dconn);
|
2007-08-21 09:31:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-25 15:48:11 +00:00
|
|
|
/*
|
|
|
|
* Not for public use. This function is part of the internal
|
2007-08-21 09:31:12 +00:00
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
int
|
2008-11-17 11:03:25 +00:00
|
|
|
virDomainMigratePerform (virDomainPtr domain,
|
2007-08-21 09:31:12 +00:00
|
|
|
const char *cookie,
|
|
|
|
int cookielen,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2009-02-02 18:41:56 +00:00
|
|
|
VIR_DEBUG("domain=%p, cookie=%p, cookielen=%d, uri=%s, flags=%lu, "
|
|
|
|
"dname=%s, bandwidth=%lu", domain, cookie, cookielen, uri, flags,
|
|
|
|
NULLSTR(dname), bandwidth);
|
2007-08-21 09:31:12 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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;
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainMigratePerform) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainMigratePerform (domain, cookie, cookielen,
|
|
|
|
uri,
|
|
|
|
flags, dname, bandwidth);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-08-21 09:31:12 +00:00
|
|
|
|
|
|
|
virLibDomainError (domain, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
2007-08-21 09:31:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-25 15:48:11 +00:00
|
|
|
/*
|
|
|
|
* Not for public use. This function is part of the internal
|
2007-08-21 09:31:12 +00:00
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
2008-11-17 11:03:25 +00:00
|
|
|
virDomainMigrateFinish (virConnectPtr dconn,
|
2007-08-21 09:31:12 +00:00
|
|
|
const char *dname,
|
|
|
|
const char *cookie,
|
|
|
|
int cookielen,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
2009-02-02 18:41:56 +00:00
|
|
|
VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
|
|
|
|
"flags=%lu", dconn, NULLSTR(dname), cookie, cookielen,
|
|
|
|
uri, flags);
|
2007-08-21 09:31:12 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2007-08-21 09:31:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (dconn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(dconn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (dconn->driver->domainMigrateFinish) {
|
|
|
|
virDomainPtr ret;
|
|
|
|
ret = dconn->driver->domainMigrateFinish (dconn, dname,
|
|
|
|
cookie, cookielen,
|
|
|
|
uri, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-08-21 09:31:12 +00:00
|
|
|
|
|
|
|
virLibConnError (dconn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dconn);
|
2007-08-21 09:31:12 +00:00
|
|
|
return NULL;
|
2008-11-14 08:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 15:48:11 +00:00
|
|
|
/*
|
|
|
|
* Not for public use. This function is part of the internal
|
2008-11-14 08:42:47 +00:00
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
int
|
2008-11-17 11:03:25 +00:00
|
|
|
virDomainMigratePrepare2 (virConnectPtr dconn,
|
|
|
|
char **cookie,
|
|
|
|
int *cookielen,
|
|
|
|
const char *uri_in,
|
|
|
|
char **uri_out,
|
|
|
|
unsigned long flags,
|
|
|
|
const char *dname,
|
|
|
|
unsigned long bandwidth,
|
|
|
|
const char *dom_xml)
|
2008-11-14 08:42:47 +00:00
|
|
|
{
|
2009-02-02 18:41:56 +00:00
|
|
|
VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p,"
|
|
|
|
"flags=%lu, dname=%s, bandwidth=%lu, dom_xml=%s", dconn,
|
|
|
|
cookie, cookielen, uri_in, uri_out, flags, NULLSTR(dname),
|
|
|
|
bandwidth, dom_xml);
|
2008-11-14 08:42:47 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-14 08:42:47 +00:00
|
|
|
if (!VIR_IS_CONNECT (dconn)) {
|
|
|
|
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (dconn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(dconn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (dconn->driver->domainMigratePrepare2) {
|
|
|
|
int ret;
|
|
|
|
ret = dconn->driver->domainMigratePrepare2 (dconn, cookie, cookielen,
|
|
|
|
uri_in, uri_out,
|
|
|
|
flags, dname, bandwidth,
|
|
|
|
dom_xml);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-14 08:42:47 +00:00
|
|
|
|
|
|
|
virLibConnError (dconn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dconn);
|
2008-11-14 08:42:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-25 15:48:11 +00:00
|
|
|
/*
|
|
|
|
* Not for public use. This function is part of the internal
|
2008-11-14 08:42:47 +00:00
|
|
|
* implementation of migration in the remote case.
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
2008-11-17 11:03:25 +00:00
|
|
|
virDomainMigrateFinish2 (virConnectPtr dconn,
|
|
|
|
const char *dname,
|
|
|
|
const char *cookie,
|
|
|
|
int cookielen,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long flags,
|
|
|
|
int retcode)
|
2008-11-14 08:42:47 +00:00
|
|
|
{
|
2009-02-02 18:41:56 +00:00
|
|
|
VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
|
|
|
|
"flags=%lu, retcode=%d", dconn, NULLSTR(dname), cookie,
|
|
|
|
cookielen, uri, flags, retcode);
|
2008-11-14 08:42:47 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-14 08:42:47 +00:00
|
|
|
if (!VIR_IS_CONNECT (dconn)) {
|
|
|
|
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (dconn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(dconn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (dconn->driver->domainMigrateFinish2) {
|
|
|
|
virDomainPtr ret;
|
|
|
|
ret = dconn->driver->domainMigrateFinish2 (dconn, dname,
|
|
|
|
cookie, cookielen,
|
|
|
|
uri, flags,
|
|
|
|
retcode);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-14 08:42:47 +00:00
|
|
|
|
|
|
|
virLibConnError (dconn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dconn);
|
2008-11-14 08:42:47 +00:00
|
|
|
return NULL;
|
2007-08-21 09:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-29 12:46:03 +00:00
|
|
|
/**
|
|
|
|
* virNodeGetInfo:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @info: pointer to a virNodeInfo structure allocated by the user
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-03-29 12:46:03 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->nodeGetInfo) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->nodeGetInfo (conn, info);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->getCapabilities) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->driver->getCapabilities (conn);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-03-15 17:24:56 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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
|
2009-04-17 15:34:53 +00:00
|
|
|
* Note: most libvirt APIs provide memory sizes in kilobytes, but in this
|
|
|
|
* function the returned value is in bytes. Divide by 1024 as necessary.
|
2007-09-30 13:09:07 +00:00
|
|
|
*
|
2009-04-17 15:34:53 +00:00
|
|
|
* Returns the available free memory in bytes or 0 in case of error
|
2007-09-30 13:09:07 +00:00
|
|
|
*/
|
|
|
|
unsigned long long
|
|
|
|
virNodeGetFreeMemory(virConnectPtr conn)
|
|
|
|
{
|
2007-11-15 17:44:06 +00:00
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2007-09-30 13:09:07 +00:00
|
|
|
if (!VIR_IS_CONNECT (conn)) {
|
|
|
|
virLibConnError (NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->getFreeMemory) {
|
|
|
|
unsigned long long ret;
|
|
|
|
ret = conn->driver->getFreeMemory (conn);
|
|
|
|
if (ret == 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-09-30 13:09:07 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-09-30 13:09:07 +00:00
|
|
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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);
|
2009-01-20 12:01:45 +00:00
|
|
|
if (!schedtype)
|
|
|
|
goto error;
|
2007-06-05 12:06:08 +00:00
|
|
|
return schedtype;
|
|
|
|
}
|
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainGetSchedulerParameters) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainGetSchedulerParameters (domain, params, nparams);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-06-05 12:06:08 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-03-13 09:27:46 +00:00
|
|
|
}
|
2007-06-05 12:06:08 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainSetSchedulerParameters) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainSetSchedulerParameters (domain, params, nparams);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-06-05 12:06:08 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2007-08-21 10:08:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-07-24 15:05:28 +00:00
|
|
|
if (!path || !stats || size > sizeof stats2) {
|
2009-01-20 12:01:45 +00:00
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
2007-08-21 10:08:12 +00:00
|
|
|
conn = dom->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainBlockStats) {
|
|
|
|
if (conn->driver->domainBlockStats (dom, path, &stats2) == -1)
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-08-21 10:08:12 +00:00
|
|
|
|
|
|
|
memcpy (stats, &stats2, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dom->conn);
|
2007-08-21 10:08:12 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2007-08-21 10:08:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-07-24 15:05:28 +00:00
|
|
|
if (!path || !stats || size > sizeof stats2) {
|
2009-01-20 12:01:45 +00:00
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
2007-08-21 10:08:12 +00:00
|
|
|
conn = dom->conn;
|
|
|
|
|
|
|
|
if (conn->driver->domainInterfaceStats) {
|
|
|
|
if (conn->driver->domainInterfaceStats (dom, path, &stats2) == -1)
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-08-21 10:08:12 +00:00
|
|
|
|
|
|
|
memcpy (stats, &stats2, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dom->conn);
|
2007-08-21 10:08:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
/**
|
|
|
|
* virDomainBlockPeek:
|
|
|
|
* @dom: pointer to the domain object
|
|
|
|
* @path: path to the block device
|
|
|
|
* @offset: offset within block device
|
|
|
|
* @size: size to read
|
|
|
|
* @buffer: return buffer (must be at least size bytes)
|
|
|
|
* @flags: unused, always pass 0
|
|
|
|
*
|
|
|
|
* This function allows you to read the contents of a domain's
|
|
|
|
* disk device.
|
|
|
|
*
|
|
|
|
* Typical uses for this are to determine if the domain has
|
|
|
|
* written a Master Boot Record (indicating that the domain
|
|
|
|
* has completed installation), or to try to work out the state
|
|
|
|
* of the domain's filesystems.
|
|
|
|
*
|
|
|
|
* (Note that in the local case you might try to open the
|
|
|
|
* block device or file directly, but that won't work in the
|
|
|
|
* remote case, nor if you don't have sufficient permission.
|
|
|
|
* Hence the need for this call).
|
|
|
|
*
|
|
|
|
* 'path' must be a device or file corresponding to the domain.
|
|
|
|
* In other words it must be the precise string returned in
|
|
|
|
* a <disk><source dev='...'/></disk> from
|
|
|
|
* virDomainGetXMLDesc.
|
|
|
|
*
|
|
|
|
* 'offset' and 'size' represent an area which must lie entirely
|
|
|
|
* within the device or file. 'size' may be 0 to test if the
|
|
|
|
* call would succeed.
|
|
|
|
*
|
|
|
|
* 'buffer' is the return buffer and must be at least 'size' bytes.
|
|
|
|
*
|
2008-06-10 10:43:28 +00:00
|
|
|
* NB. The remote driver imposes a 64K byte limit on 'size'.
|
|
|
|
* For your program to be able to work reliably over a remote
|
|
|
|
* connection you should split large requests to <= 65536 bytes.
|
|
|
|
*
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
* Returns: 0 in case of success or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainBlockPeek (virDomainPtr dom,
|
|
|
|
const char *path,
|
|
|
|
unsigned long long offset /* really 64 bits */,
|
|
|
|
size_t size,
|
|
|
|
void *buffer,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("domain=%p, path=%s, offset=%lld, size=%zi, buffer=%p",
|
|
|
|
dom, path, offset, size, buffer);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
|
|
|
|
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = dom->conn;
|
2007-08-21 10:08:12 +00:00
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (dom->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(dom, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
if (!path) {
|
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
|
|
|
|
_("path is NULL"));
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
|
|
|
|
_("flags must be zero"));
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow size == 0 as an access test. */
|
|
|
|
if (size > 0 && !buffer) {
|
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
|
|
|
|
_("buffer is NULL"));
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainBlockPeek) {
|
|
|
|
int ret;
|
|
|
|
ret =conn->driver->domainBlockPeek (dom, path, offset, size,
|
|
|
|
buffer, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
|
|
|
|
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dom->conn);
|
virDomainBlockPeek call
* configure.in: Document AC_SYS_LARGEFILE.
* docs/hvsupport.html.in: Document HV support for virDomainBlockPeek.
* include/libvirt/libvirt.h.in, src/driver.h, src/libvirt.c,
src/libvirt_sym.version: Add virDomainBlockPeek infrastructure.
* src/qemu_driver.c, src/test.c: Null versions of this call.
* src/xen_unified.c, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h: Xen implementation.
* tests/sexpr2xmldata/sexpr2xml-curmem.xml,
tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml: XML output
has been reordered slightly in the Xen driver, but should be
functionally the same.
2008-06-05 13:17:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-08-21 10:08:12 +00:00
|
|
|
|
2008-06-10 10:43:28 +00:00
|
|
|
/**
|
|
|
|
* virDomainMemoryPeek:
|
|
|
|
* @dom: pointer to the domain object
|
|
|
|
* @start: start of memory to peek
|
|
|
|
* @size: size of memory to peek
|
|
|
|
* @buffer: return buffer (must be at least size bytes)
|
|
|
|
* @flags: flags, see below
|
|
|
|
*
|
|
|
|
* This function allows you to read the contents of a domain's
|
|
|
|
* memory.
|
|
|
|
*
|
|
|
|
* The memory which is read is controlled by the 'start', 'size'
|
|
|
|
* and 'flags' parameters.
|
|
|
|
*
|
|
|
|
* If 'flags' is VIR_MEMORY_VIRTUAL then the 'start' and 'size'
|
|
|
|
* parameters are interpreted as virtual memory addresses for
|
|
|
|
* whichever task happens to be running on the domain at the
|
|
|
|
* moment. Although this sounds haphazard it is in fact what
|
|
|
|
* you want in order to read Linux kernel state, because it
|
|
|
|
* ensures that pointers in the kernel image can be interpreted
|
|
|
|
* coherently.
|
|
|
|
*
|
|
|
|
* 'buffer' is the return buffer and must be at least 'size' bytes.
|
|
|
|
* 'size' may be 0 to test if the call would succeed.
|
|
|
|
*
|
|
|
|
* NB. The remote driver imposes a 64K byte limit on 'size'.
|
|
|
|
* For your program to be able to work reliably over a remote
|
|
|
|
* connection you should split large requests to <= 65536 bytes.
|
|
|
|
*
|
|
|
|
* Returns: 0 in case of success or -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainMemoryPeek (virDomainPtr dom,
|
|
|
|
unsigned long long start /* really 64 bits */,
|
|
|
|
size_t size,
|
|
|
|
void *buffer,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG ("domain=%p, start=%lld, size=%zi, buffer=%p, flags=%d",
|
|
|
|
dom, start, size, buffer, flags);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-06-10 10:43:28 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
|
|
|
|
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = dom->conn;
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (dom->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(dom, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-22 14:27:09 +00:00
|
|
|
/* Note on access to physical memory: A VIR_MEMORY_PHYSICAL flag is
|
2008-06-10 10:43:28 +00:00
|
|
|
* a possibility. However it isn't really useful unless the caller
|
|
|
|
* can also access registers, particularly CR3 on x86 in order to
|
|
|
|
* get the Page Table Directory. Since registers are different on
|
|
|
|
* every architecture, that would imply another call to get the
|
|
|
|
* machine registers.
|
|
|
|
*
|
2009-07-22 14:27:09 +00:00
|
|
|
* The QEMU driver handles VIR_MEMORY_VIRTUAL, mapping it
|
2008-06-10 10:43:28 +00:00
|
|
|
* to the qemu 'memsave' command which does the virtual to physical
|
|
|
|
* mapping inside qemu.
|
|
|
|
*
|
2009-07-22 14:27:09 +00:00
|
|
|
* The QEMU driver also handles VIR_MEMORY_PHYSICAL, mapping it
|
|
|
|
* to the qemu 'pmemsave' command.
|
|
|
|
*
|
2008-06-10 10:43:28 +00:00
|
|
|
* At time of writing there is no Xen driver. However the Xen
|
|
|
|
* hypervisor only lets you map physical pages from other domains,
|
|
|
|
* and so the Xen driver would have to do the virtual to physical
|
|
|
|
* mapping by chasing 2, 3 or 4-level page tables from the PTD.
|
|
|
|
* There is example code in libxc (xc_translate_foreign_address)
|
|
|
|
* which does this, although we cannot copy this code directly
|
|
|
|
* because of incompatible licensing.
|
|
|
|
*/
|
2009-07-22 14:27:09 +00:00
|
|
|
|
|
|
|
if (flags != VIR_MEMORY_VIRTUAL && flags != VIR_MEMORY_PHYSICAL) {
|
2008-06-10 10:43:28 +00:00
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
|
2009-07-22 14:27:09 +00:00
|
|
|
_("flags parameter must be VIR_MEMORY_VIRTUAL or VIR_MEMORY_PHYSICAL"));
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-06-10 10:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow size == 0 as an access test. */
|
|
|
|
if (size > 0 && !buffer) {
|
|
|
|
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
|
|
|
|
_("buffer is NULL but size is non-zero"));
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-06-10 10:43:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainMemoryPeek) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainMemoryPeek (dom, start, size,
|
|
|
|
buffer, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-06-10 10:43:28 +00:00
|
|
|
|
|
|
|
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dom->conn);
|
2008-06-10 10:43:28 +00:00
|
|
|
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
|
|
|
|
*
|
2008-08-01 06:42:45 +00:00
|
|
|
* Define a domain, but does not start it.
|
|
|
|
* This definition is persistent, until explicitly undefined with
|
2009-04-21 13:39:40 +00:00
|
|
|
* virDomainUndefine(). A previous definition for this domain would be
|
|
|
|
* overriden if it already exists.
|
2006-04-28 18:29:26 +00:00
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-04-28 18:29:26 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainDefineXML) {
|
|
|
|
virDomainPtr ret;
|
|
|
|
ret = conn->driver->domainDefineXML (conn, xml);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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
|
|
|
|
*
|
2008-08-01 06:42:45 +00:00
|
|
|
* Undefine a domain but does not stop it if it is running
|
2006-04-28 18:29:26 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainUndefine) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainUndefine (domain);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-04-28 18:29:26 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->numOfDefinedDomains) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->numOfDefinedDomains (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-08-30 14:21:03 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-30 14:21:03 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->listDefinedDomains) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->listDefinedDomains (conn, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-08-30 14:21:03 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-16 16:14:53 +00:00
|
|
|
}
|
2006-08-30 14:21:03 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainCreate) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainCreate (domain);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-23 08:51:30 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainGetAutostart) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainGetAutostart (domain, autostart);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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;
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainSetAutostart) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainSetAutostart (domain, autostart);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
2006-08-04 10:41:05 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainSetVcpus) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainSetVcpus (domain, nvcpus);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2006-08-08 22:22:55 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainPinVcpu) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainPinVcpu (domain, vcpu, cpumap, maplen);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
|
|
|
if (cpumaps != NULL && maplen < 1) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-08-04 10:41:05 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2006-08-08 22:22:55 +00:00
|
|
|
conn = domain->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainGetVcpus) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainGetVcpus (domain, info, maxinfo,
|
|
|
|
cpumaps, maplen);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainGetMaxVcpus) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainGetMaxVcpus (domain);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2007-03-08 08:31:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-03 09:14:28 +00:00
|
|
|
/**
|
|
|
|
* virDomainGetSecurityLabel:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @seclabel: pointer to a virSecurityLabel structure
|
|
|
|
*
|
2009-06-25 09:37:22 +00:00
|
|
|
* Extract security label of an active domain. The 'label' field
|
|
|
|
* in the @seclabel argument will be initialized to the empty
|
|
|
|
* string if the domain is not running under a security model.
|
2009-03-03 09:14:28 +00:00
|
|
|
*
|
2009-06-25 09:37:22 +00:00
|
|
|
* Returns 0 in case of success, -1 in case of failure
|
2009-03-03 09:14:28 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainGetSecurityLabel(virDomainPtr domain, virSecurityLabelPtr seclabel)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
|
|
|
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seclabel == NULL) {
|
|
|
|
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-07-15 09:36:32 +00:00
|
|
|
goto error;
|
2009-03-03 09:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn = domain->conn;
|
|
|
|
|
2009-07-15 09:36:32 +00:00
|
|
|
if (conn->driver->domainGetSecurityLabel) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainGetSecurityLabel(domain, seclabel);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-03-03 09:14:28 +00:00
|
|
|
|
2009-07-15 09:36:32 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
2009-03-03 19:33:34 +00:00
|
|
|
return -1;
|
2009-03-03 09:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeGetSecurityModel:
|
|
|
|
* @conn: a connection object
|
|
|
|
* @secmodel: pointer to a virSecurityModel structure
|
|
|
|
*
|
2009-06-25 09:37:22 +00:00
|
|
|
* Extract the security model of a hypervisor. The 'model' field
|
|
|
|
* in the @secmodel argument may be initialized to the empty
|
|
|
|
* string if the driver has not activated a security model.
|
2009-03-03 09:14:28 +00:00
|
|
|
*
|
2009-06-25 09:37:22 +00:00
|
|
|
* Returns 0 in case of success, -1 in case of failure
|
2009-03-03 09:14:28 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeGetSecurityModel(virConnectPtr conn, virSecurityModelPtr secmodel)
|
|
|
|
{
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (secmodel == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-07-15 09:36:32 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->driver->nodeGetSecurityModel) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->nodeGetSecurityModel(conn, secmodel);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
2009-03-03 09:14:28 +00:00
|
|
|
}
|
|
|
|
|
2009-07-15 09:36:32 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-03-03 09:14:28 +00:00
|
|
|
|
2009-07-15 09:36:32 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2009-03-03 19:33:34 +00:00
|
|
|
return -1;
|
2009-03-03 09:14:28 +00:00
|
|
|
}
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-11-16 18:11:28 +00:00
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainAttachDevice) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainAttachDevice (domain, xml);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2006-11-16 18:11:28 +00:00
|
|
|
}
|
|
|
|
conn = domain->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->domainDetachDevice) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainDetachDevice (domain, xml);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(domain->conn);
|
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
|
2009-08-21 12:16:13 +00:00
|
|
|
* with the amount of free memory in bytes for each cell requested,
|
2007-09-28 14:28:12 +00:00
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-09-28 14:28:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->driver->nodeGetCellsFreeMemory) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->nodeGetCellsFreeMemory (conn, freeMems, startCell, maxCells);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-09-28 14:28:12 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2007-09-28 14:28:12 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->numOfNetworks) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->numOfNetworks (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->listNetworks) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->listNetworks (conn, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->numOfDefinedNetworks) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->numOfDefinedNetworks (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->listDefinedNetworks) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->listDefinedNetworks (conn,
|
|
|
|
names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkLookupByName) {
|
|
|
|
virNetworkPtr ret;
|
|
|
|
ret = conn->networkDriver->networkLookupByName (conn, name);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkLookupByUUID){
|
|
|
|
virNetworkPtr ret;
|
|
|
|
ret = conn->networkDriver->networkLookupByUUID (conn, uuid);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
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]);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkCreateXML) {
|
|
|
|
virNetworkPtr ret;
|
|
|
|
ret = conn->networkDriver->networkCreateXML (conn, xmlDesc);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkDefineXML) {
|
|
|
|
virNetworkPtr ret;
|
|
|
|
ret = conn->networkDriver->networkDefineXML (conn, xml);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkUndefine) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->networkUndefine (network);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkCreate) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->networkCreate (network);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkDestroy) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->networkDestroy (network);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-14 15:37:18 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2008-01-21 16:29:10 +00:00
|
|
|
if (virUnrefNetwork(network) < 0)
|
2007-02-14 15:37:18 +00:00
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:14:03 +00:00
|
|
|
/**
|
|
|
|
* virNetworkRef:
|
2009-04-24 14:04:54 +00:00
|
|
|
* @network: the network to hold a reference on
|
2009-01-20 12:14:03 +00:00
|
|
|
*
|
|
|
|
* Increment the reference count on the network. For each
|
|
|
|
* additional call to this method, there shall be a corresponding
|
|
|
|
* call to virNetworkFree to release the reference count, once
|
|
|
|
* the caller no longer needs the reference to this object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple
|
|
|
|
* threads are using a connection, and it is required that the
|
|
|
|
* connection remain open until all threads have finished using
|
|
|
|
* it. ie, each new thread using a network would increment
|
|
|
|
* the reference count.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
2009-01-20 12:14:03 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNetworkRef(virNetworkPtr network)
|
|
|
|
{
|
|
|
|
if ((!VIR_IS_CONNECTED_NETWORK(network))) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
virMutexLock(&network->conn->lock);
|
|
|
|
DEBUG("network=%p refs=%d", network, network->refs);
|
|
|
|
network->refs++;
|
|
|
|
virMutexUnlock(&network->conn->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-14 15:37:18 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(uuid, &network->uuid[0], VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
return (0);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
|
|
|
return -1;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetworkGetXMLDesc:
|
|
|
|
* @network: a network object
|
2009-09-04 13:40:52 +00:00
|
|
|
* @flags: an OR'ed set of extraction flags, not used yet
|
2007-02-14 15:37:18 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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 (NULL);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-14 15:37:18 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = network->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkDumpXML) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->networkDriver->networkDumpXML (network, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkGetBridgeName) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->networkDriver->networkGetBridgeName (network);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2007-02-23 08:51:30 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = network->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkGetAutostart) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->networkGetAutostart (network, autostart);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
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
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_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);
|
|
|
|
}
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (network->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
conn = network->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->networkDriver && conn->networkDriver->networkSetAutostart) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->networkDriver->networkSetAutostart (network, autostart);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-06-20 17:25:39 +00:00
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(network->conn);
|
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
|
|
|
|
2009-05-20 14:26:49 +00:00
|
|
|
/**
|
|
|
|
* virInterfaceGetConnect:
|
2009-09-04 13:40:52 +00:00
|
|
|
* @iface: pointer to an interface
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Provides the connection pointer associated with an interface. 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 interface object together.
|
|
|
|
*
|
|
|
|
* Returns the virConnectPtr or NULL in case of failure.
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceGetConnect (virInterfacePtr iface)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p", iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_INTERFACE (iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError (NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
return iface->conn;
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfInterfaces:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
2009-07-16 15:58:15 +00:00
|
|
|
* Provides the number of active interfaces on the physical host.
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
2009-07-16 15:58:15 +00:00
|
|
|
* Returns the number of active interfaces found or -1 in case of error
|
2009-05-20 14:26:49 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfInterfaces(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->numOfInterfaces) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->interfaceDriver->numOfInterfaces (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListInterfaces:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @names: array to collect the list of names of interfaces
|
|
|
|
* @maxnames: size of @names
|
|
|
|
*
|
2009-07-16 15:58:15 +00:00
|
|
|
* Collect the list of active physical host interfaces,
|
|
|
|
* and store their names in @names
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Returns the number of interfaces found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->listInterfaces) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->interfaceDriver->listInterfaces (conn, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-16 15:58:15 +00:00
|
|
|
/**
|
|
|
|
* virConnectNumOfDefinedInterfaces:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides the number of defined (inactive) interfaces on the physical host.
|
|
|
|
*
|
|
|
|
* Returns the number of defined interface found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfDefinedInterfaces(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p", conn);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->numOfDefinedInterfaces) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->interfaceDriver->numOfDefinedInterfaces (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListDefinedInterfaces:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @names: array to collect the list of names of interfaces
|
|
|
|
* @maxnames: size of @names
|
|
|
|
*
|
|
|
|
* Collect the list of defined (inactive) physical host interfaces,
|
|
|
|
* and store their names in @names.
|
|
|
|
*
|
|
|
|
* Returns the number of interfaces found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListDefinedInterfaces(virConnectPtr conn,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->listDefinedInterfaces) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->interfaceDriver->listDefinedInterfaces (conn, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-20 14:26:49 +00:00
|
|
|
/**
|
|
|
|
* virInterfaceLookupByName:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @name: name for the interface
|
|
|
|
*
|
|
|
|
* Try to lookup an interface on the given hypervisor based on its name.
|
|
|
|
*
|
|
|
|
* Returns a new interface object or NULL in case of failure. If the
|
|
|
|
* interface cannot be found, then VIR_ERR_NO_INTERFACE error is raised.
|
|
|
|
*/
|
|
|
|
virInterfacePtr
|
|
|
|
virInterfaceLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, name=%s", conn, name);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->interfaceLookupByName) {
|
|
|
|
virInterfacePtr ret;
|
|
|
|
ret = conn->interfaceDriver->interfaceLookupByName (conn, name);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceLookupByMACString:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @macstr: the MAC for the interface (null-terminated ASCII format)
|
|
|
|
*
|
|
|
|
* Try to lookup an interface on the given hypervisor based on its MAC.
|
|
|
|
*
|
|
|
|
* Returns a new interface object or NULL in case of failure. If the
|
|
|
|
* interface cannot be found, then VIR_ERR_NO_INTERFACE error is raised.
|
|
|
|
*/
|
|
|
|
virInterfacePtr
|
|
|
|
virInterfaceLookupByMACString(virConnectPtr conn, const char *macstr)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, macstr=%s", conn, macstr);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (macstr == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->interfaceLookupByMACString) {
|
|
|
|
virInterfacePtr ret;
|
|
|
|
ret = conn->interfaceDriver->interfaceLookupByMACString (conn, macstr);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceGetName:
|
2009-09-04 13:40:52 +00:00
|
|
|
* @iface: an interface object
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Get the public name for that interface
|
|
|
|
*
|
|
|
|
* Returns a pointer to the name or NULL, the string need not be deallocated
|
|
|
|
* its lifetime will be the same as the interface object.
|
|
|
|
*/
|
|
|
|
const char *
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceGetName(virInterfacePtr iface)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p", iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_INTERFACE(iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
return (iface->name);
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceGetMACString:
|
2009-09-04 13:40:52 +00:00
|
|
|
* @iface: an interface object
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
2009-09-04 13:40:52 +00:00
|
|
|
* Get the MAC for an interface as string. For more information about
|
2009-05-20 14:26:49 +00:00
|
|
|
* MAC see RFC4122.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the MAC address (in null-terminated ASCII
|
|
|
|
* format) or NULL, the string need not be deallocated its lifetime
|
|
|
|
* will be the same as the interface object.
|
|
|
|
*/
|
|
|
|
const char *
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceGetMACString(virInterfacePtr iface)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p", iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_INTERFACE(iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
return (iface->mac);
|
2009-05-20 14:26:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceGetXMLDesc:
|
2009-09-04 13:40:52 +00:00
|
|
|
* @iface: an interface object
|
|
|
|
* @flags: an OR'ed set of extraction flags, not used yet
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Provide an XML description of the interface. The description may be reused
|
2009-09-04 13:40:52 +00:00
|
|
|
* later to redefine the interface with virInterfaceDefineXML().
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p, flags=%d", iface, flags);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
2009-05-29 14:29:22 +00:00
|
|
|
virLibInterfaceError(iface, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-05-20 14:26:49 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
conn = iface->conn;
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->interfaceGetXMLDesc) {
|
|
|
|
char *ret;
|
2009-05-29 14:29:22 +00:00
|
|
|
ret = conn->interfaceDriver->interfaceGetXMLDesc (iface, flags);
|
2009-05-20 14:26:49 +00:00
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
2009-05-29 14:29:22 +00:00
|
|
|
virSetConnError(iface->conn);
|
2009-05-20 14:26:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceDefineXML:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @xml: the XML description for the interface, preferably in UTF-8
|
|
|
|
* @flags: and OR'ed set of extraction flags, not used yet
|
|
|
|
*
|
|
|
|
* Define an interface (or modify existing interface configuration)
|
|
|
|
*
|
|
|
|
* Returns NULL in case of error, a pointer to the interface otherwise
|
|
|
|
*/
|
|
|
|
virInterfacePtr
|
|
|
|
virInterfaceDefineXML(virConnectPtr conn, const char *xml, unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, xml=%s, flags=%d", conn, xml, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->interfaceDefineXML) {
|
|
|
|
virInterfacePtr ret;
|
|
|
|
ret = conn->interfaceDriver->interfaceDefineXML (conn, xml, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceUndefine:
|
2009-05-29 14:29:22 +00:00
|
|
|
* @iface: pointer to a defined interface
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Undefine an interface, ie remove it from the config.
|
|
|
|
* This does not free the associated virInterfacePtr object.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceUndefine(virInterfacePtr iface) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virConnectPtr conn;
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p", iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
conn = iface->conn;
|
2009-05-20 14:26:49 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
2009-05-29 14:29:22 +00:00
|
|
|
virLibInterfaceError(iface, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-05-20 14:26:49 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->interfaceUndefine) {
|
|
|
|
int ret;
|
2009-05-29 14:29:22 +00:00
|
|
|
ret = conn->interfaceDriver->interfaceUndefine (iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
2009-05-29 14:29:22 +00:00
|
|
|
virSetConnError(iface->conn);
|
2009-05-20 14:26:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceCreate:
|
2009-05-29 14:29:22 +00:00
|
|
|
* @iface: pointer to a defined interface
|
2009-05-20 14:26:49 +00:00
|
|
|
* @flags: and OR'ed set of extraction flags, not used yet
|
|
|
|
*
|
|
|
|
* Activate an interface (ie call "ifup")
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceCreate(virInterfacePtr iface, unsigned int flags)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p, flags=%d", iface, flags);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
conn = iface->conn;
|
2009-05-20 14:26:49 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
2009-05-29 14:29:22 +00:00
|
|
|
virLibInterfaceError(iface, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-05-20 14:26:49 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->interfaceCreate) {
|
|
|
|
int ret;
|
2009-05-29 14:29:22 +00:00
|
|
|
ret = conn->interfaceDriver->interfaceCreate (iface, flags);
|
2009-05-20 14:26:49 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
2009-05-29 14:29:22 +00:00
|
|
|
virSetConnError(iface->conn);
|
2009-05-20 14:26:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceDestroy:
|
2009-05-29 14:29:22 +00:00
|
|
|
* @iface: an interface object
|
2009-05-20 14:26:49 +00:00
|
|
|
* @flags: and OR'ed set of extraction flags, not used yet
|
|
|
|
*
|
|
|
|
* deactivate an interface (ie call "ifdown")
|
|
|
|
* This does not remove the interface from the config, and
|
|
|
|
* does not free the associated virInterfacePtr object.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceDestroy(virInterfacePtr iface, unsigned int flags)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p, flags=%d", iface, flags);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
conn = iface->conn;
|
2009-05-20 14:26:49 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
2009-05-29 14:29:22 +00:00
|
|
|
virLibInterfaceError(iface, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-05-20 14:26:49 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->interfaceDriver && conn->interfaceDriver->interfaceDestroy) {
|
|
|
|
int ret;
|
2009-05-29 14:29:22 +00:00
|
|
|
ret = conn->interfaceDriver->interfaceDestroy (iface, flags);
|
2009-05-20 14:26:49 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
2009-05-29 14:29:22 +00:00
|
|
|
virSetConnError(iface->conn);
|
2009-05-20 14:26:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceRef:
|
2009-05-29 14:29:22 +00:00
|
|
|
* @iface: the interface to hold a reference on
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Increment the reference count on the interface. For each
|
|
|
|
* additional call to this method, there shall be a corresponding
|
|
|
|
* call to virInterfaceFree to release the reference count, once
|
|
|
|
* the caller no longer needs the reference to this object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple
|
|
|
|
* threads are using a connection, and it is required that the
|
|
|
|
* connection remain open until all threads have finished using
|
2009-09-04 13:40:52 +00:00
|
|
|
* it. ie, each new thread using an interface would increment
|
2009-05-20 14:26:49 +00:00
|
|
|
* the reference count.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceRef(virInterfacePtr iface)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
2009-05-29 14:29:22 +00:00
|
|
|
if ((!VIR_IS_CONNECTED_INTERFACE(iface))) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
virMutexLock(&iface->conn->lock);
|
|
|
|
DEBUG("iface=%p refs=%d", iface, iface->refs);
|
|
|
|
iface->refs++;
|
|
|
|
virMutexUnlock(&iface->conn->lock);
|
2009-05-20 14:26:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virInterfaceFree:
|
2009-09-04 13:40:52 +00:00
|
|
|
* @iface: an interface object
|
2009-05-20 14:26:49 +00:00
|
|
|
*
|
|
|
|
* Free the interface object. The interface itself is unaltered.
|
|
|
|
* The data structure is freed and should not be used thereafter.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
2009-05-29 14:29:22 +00:00
|
|
|
virInterfaceFree(virInterfacePtr iface)
|
2009-05-20 14:26:49 +00:00
|
|
|
{
|
2009-05-29 14:29:22 +00:00
|
|
|
DEBUG("iface=%p", iface);
|
2009-05-20 14:26:49 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2009-05-29 14:29:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
|
2009-05-20 14:26:49 +00:00
|
|
|
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
2009-05-29 14:29:22 +00:00
|
|
|
if (virUnrefInterface(iface) < 0)
|
2009-05-20 14:26:49 +00:00
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL (pool)) {
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->numOfPools) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->numOfPools (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->listPools) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->listPools (conn, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->numOfDefinedPools) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->numOfDefinedPools (conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->listDefinedPools) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->listDefinedPools (conn, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-27 20:05:58 +00:00
|
|
|
/**
|
|
|
|
* virConnectFindStoragePoolSources:
|
|
|
|
* @conn: pointer to hypervisor connection
|
|
|
|
* @type: type of storage pool sources to discover
|
|
|
|
* @srcSpec: XML document specifying discovery source
|
|
|
|
* @flags: flags for discovery (unused, pass 0)
|
|
|
|
*
|
|
|
|
* Talks to a storage backend and attempts to auto-discover the set of
|
|
|
|
* available storage pool sources. e.g. For iSCSI this would be a set of
|
|
|
|
* iSCSI targets. For NFS this would be a list of exported paths. The
|
|
|
|
* srcSpec (optional for some storage pool types, e.g. local ones) is
|
|
|
|
* an instance of the storage pool's source element specifying where
|
|
|
|
* to look for the pools.
|
|
|
|
*
|
|
|
|
* srcSpec is not required for some types (e.g., those querying
|
|
|
|
* local storage resources only)
|
|
|
|
*
|
|
|
|
* Returns an xml document consisting of a SourceList element
|
|
|
|
* containing a source document appropriate to the given pool
|
|
|
|
* type for each discovered source.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virConnectFindStoragePoolSources(virConnectPtr conn,
|
|
|
|
const char *type,
|
|
|
|
const char *srcSpec,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2009-01-20 12:01:45 +00:00
|
|
|
DEBUG("conn=%p, type=%s, src=%s, flags=%u", conn, type ? type : "", srcSpec ? srcSpec : "", flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
2008-08-27 20:05:58 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
2009-09-02 15:47:51 +00:00
|
|
|
return NULL;
|
2008-08-27 20:05:58 +00:00
|
|
|
}
|
|
|
|
if (type == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-08-27 20:05:58 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->findPoolSources) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->storageDriver->findPoolSources(conn, type, srcSpec, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-08-27 20:05:58 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-08-27 20:05:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolLookupByName) {
|
|
|
|
virStoragePoolPtr ret;
|
|
|
|
ret = conn->storageDriver->poolLookupByName (conn, name);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolLookupByUUID) {
|
|
|
|
virStoragePoolPtr ret;
|
|
|
|
ret = conn->storageDriver->poolLookupByUUID (conn, uuid);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2009-01-20 12:01:45 +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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (uuidstr == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virUUIDParse(uuidstr, uuid) < 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return virStoragePoolLookupByUUID(conn, uuid);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
|
2008-02-20 15:06:53 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (vol->conn->storageDriver && vol->conn->storageDriver->poolLookupByVolume) {
|
|
|
|
virStoragePoolPtr ret;
|
|
|
|
ret = vol->conn->storageDriver->poolLookupByVolume (vol);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (vol->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(vol->conn);
|
|
|
|
return NULL;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (xmlDesc == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolCreateXML) {
|
|
|
|
virStoragePoolPtr ret;
|
|
|
|
ret = conn->storageDriver->poolCreateXML (conn, xmlDesc, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolDefineXML) {
|
|
|
|
virStoragePoolPtr ret;
|
|
|
|
ret = conn->storageDriver->poolDefineXML (conn, xml, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolBuild) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolBuild (pool, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStoragePoolUndefine:
|
|
|
|
* @pool: pointer to storage pool
|
|
|
|
*
|
|
|
|
* Undefine an inactive storage pool
|
|
|
|
*
|
2009-07-22 06:41:40 +00:00
|
|
|
* Returns 0 on success, -1 on failure
|
2008-02-20 15:06:53 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolUndefine(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
DEBUG("pool=%p", pool);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolUndefine) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolUndefine (pool);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolCreate) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolCreate (pool, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolDestroy) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolDestroy (pool);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolDelete) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolDelete (pool, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
2008-02-20 15:06:53 +00:00
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (virUnrefStoragePool(pool) < 0)
|
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-20 12:14:03 +00:00
|
|
|
/**
|
|
|
|
* virStoragePoolRef:
|
2009-04-24 14:04:54 +00:00
|
|
|
* @pool: the pool to hold a reference on
|
2009-01-20 12:14:03 +00:00
|
|
|
*
|
|
|
|
* Increment the reference count on the pool. For each
|
|
|
|
* additional call to this method, there shall be a corresponding
|
|
|
|
* call to virStoragePoolFree to release the reference count, once
|
|
|
|
* the caller no longer needs the reference to this object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple
|
|
|
|
* threads are using a connection, and it is required that the
|
|
|
|
* connection remain open until all threads have finished using
|
|
|
|
* it. ie, each new thread using a pool would increment
|
|
|
|
* the reference count.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
2009-01-20 12:14:03 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStoragePoolRef(virStoragePoolPtr pool)
|
|
|
|
{
|
|
|
|
if ((!VIR_IS_CONNECTED_STORAGE_POOL(pool))) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
virMutexLock(&pool->conn->lock);
|
|
|
|
DEBUG("pool=%p refs=%d", pool, pool->refs);
|
|
|
|
pool->refs++;
|
|
|
|
virMutexUnlock(&pool->conn->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolRefresh) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolRefresh (pool, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(uuid, &pool->uuid[0], VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virStoragePoolGetUUID(pool, &uuid[0]))
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virUUIDFormat(uuid, buf);
|
|
|
|
return (0);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(info, 0, sizeof(virStoragePoolInfo));
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver->poolGetInfo) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolGetInfo (pool, info);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
2008-02-20 15:06:53 +00:00
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolGetXMLDesc) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->storageDriver->poolGetXMLDesc (pool, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return NULL;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
2008-02-20 15:06:53 +00:00
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (!autostart) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn = pool->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolGetAutostart) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolGetAutostart (pool, autostart);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
|
2008-02-20 15:06:53 +00:00
|
|
|
virLibStoragePoolError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
2009-09-02 15:47:51 +00:00
|
|
|
return -1;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 16:45:22 +00:00
|
|
|
if (pool->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibStoragePoolError(pool, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-12-17 16:45:22 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
conn = pool->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->poolSetAutostart) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->poolSetAutostart (pool, autostart);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->poolNumOfVolumes) {
|
|
|
|
int ret;
|
|
|
|
ret = pool->conn->storageDriver->poolNumOfVolumes (pool);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->poolListVolumes) {
|
|
|
|
int ret;
|
|
|
|
ret = pool->conn->storageDriver->poolListVolumes (pool, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->volLookupByName) {
|
|
|
|
virStorageVolPtr ret;
|
|
|
|
ret = pool->conn->storageDriver->volLookupByName (pool, name);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (key == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->volLookupByKey) {
|
|
|
|
virStorageVolPtr ret;
|
|
|
|
ret = conn->storageDriver->volLookupByKey (conn, key);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (path == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->volLookupByPath) {
|
|
|
|
virStorageVolPtr ret;
|
|
|
|
ret = conn->storageDriver->volLookupByPath (conn, path);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
2009-05-05 14:17:50 +00:00
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
2008-02-20 15:06:53 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(pool->conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (pool->conn->storageDriver && pool->conn->storageDriver->volCreateXML) {
|
|
|
|
virStorageVolPtr ret;
|
|
|
|
ret = pool->conn->storageDriver->volCreateXML (pool, xmldesc, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-12 20:10:50 +00:00
|
|
|
/**
|
|
|
|
* virStorageVolCreateXMLFrom:
|
|
|
|
* @pool: pointer to parent pool for the new volume
|
|
|
|
* @xmldesc: description of volume to create
|
|
|
|
* @clonevol: storage volume to use as input
|
|
|
|
* @flags: flags for creation (unused, pass 0)
|
|
|
|
*
|
|
|
|
* Create a storage volume in the parent pool, using the
|
|
|
|
* 'clonevol' volume as input. Information for the new
|
|
|
|
* volume (name, perms) are passed via a typical volume
|
|
|
|
* XML description.
|
|
|
|
*
|
|
|
|
* return the storage volume, or NULL on error
|
|
|
|
*/
|
|
|
|
virStorageVolPtr
|
|
|
|
virStorageVolCreateXMLFrom(virStoragePoolPtr pool,
|
|
|
|
const char *xmldesc,
|
|
|
|
virStorageVolPtr clonevol,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("pool=%p, flags=%u, clonevol=%p", pool, flags, clonevol);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_POOL(pool)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!VIR_IS_STORAGE_VOL(clonevol)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->flags & VIR_CONNECT_RO ||
|
|
|
|
clonevol->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(pool->conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->conn->storageDriver &&
|
|
|
|
pool->conn->storageDriver->volCreateXMLFrom) {
|
|
|
|
virStorageVolPtr ret;
|
|
|
|
ret = pool->conn->storageDriver->volCreateXMLFrom (pool, xmldesc,
|
|
|
|
clonevol, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(pool->conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->volDelete) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->volDelete (vol, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(vol->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virStorageVolFree:
|
|
|
|
* @vol: pointer to storage volume
|
|
|
|
*
|
|
|
|
* Release the storage volume handle. The underlying
|
2009-01-23 14:18:43 +00:00
|
|
|
* storage volume continues to exist.
|
2008-02-20 15:06:53 +00:00
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageVolFree(virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
DEBUG("vol=%p", vol);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (virUnrefStorageVol(vol) < 0)
|
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-20 12:14:03 +00:00
|
|
|
/**
|
|
|
|
* virStorageVolRef:
|
2009-04-24 14:04:54 +00:00
|
|
|
* @vol: the vol to hold a reference on
|
2009-01-20 12:14:03 +00:00
|
|
|
*
|
|
|
|
* Increment the reference count on the vol. For each
|
|
|
|
* additional call to this method, there shall be a corresponding
|
|
|
|
* call to virStorageVolFree to release the reference count, once
|
|
|
|
* the caller no longer needs the reference to this object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple
|
|
|
|
* threads are using a connection, and it is required that the
|
|
|
|
* connection remain open until all threads have finished using
|
|
|
|
* it. ie, each new thread using a vol would increment
|
|
|
|
* the reference count.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
2009-01-20 12:14:03 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virStorageVolRef(virStorageVolPtr vol)
|
|
|
|
{
|
|
|
|
if ((!VIR_IS_CONNECTED_STORAGE_VOL(vol))) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
virMutexLock(&vol->conn->lock);
|
|
|
|
DEBUG("vol=%p refs=%d", vol, vol->refs);
|
|
|
|
vol->refs++;
|
|
|
|
virMutexUnlock(&vol->conn->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(info, 0, sizeof(virStorageVolInfo));
|
|
|
|
|
|
|
|
conn = vol->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver->volGetInfo){
|
|
|
|
int ret;
|
|
|
|
ret = conn->storageDriver->volGetInfo (vol, info);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(vol->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
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__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn = vol->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->volGetXMLDesc) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->storageDriver->volGetXMLDesc (vol, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(vol->conn);
|
|
|
|
return NULL;
|
2008-02-20 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-02-20 15:06:53 +00:00
|
|
|
if (!VIR_IS_STORAGE_VOL(vol)) {
|
|
|
|
virLibStorageVolError(NULL, VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = vol->conn;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->storageDriver && conn->storageDriver->volGetPath) {
|
|
|
|
char *ret;
|
|
|
|
ret = conn->storageDriver->volGetPath (vol);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:06:53 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(vol->conn);
|
2008-02-20 15:06:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-27 20:05:58 +00:00
|
|
|
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
/**
|
|
|
|
* virNodeNumOfDevices:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @cap: capability name
|
|
|
|
* @flags: flags (unused, pass 0)
|
|
|
|
*
|
|
|
|
* Provides the number of node devices.
|
|
|
|
*
|
|
|
|
* If the optional 'cap' argument is non-NULL, then the count
|
|
|
|
* will be restricted to devices with the specified capability
|
|
|
|
*
|
|
|
|
* Returns the number of node devices or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags)
|
|
|
|
{
|
2009-01-29 17:18:24 +00:00
|
|
|
DEBUG("conn=%p, cap=%s, flags=%d", conn, NULLSTR(cap), flags);
|
2008-11-21 12:19:22 +00:00
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (flags != 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->deviceMonitor && conn->deviceMonitor->numOfDevices) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->deviceMonitor->numOfDevices (conn, cap, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-11-21 12:19:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeListDevices:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @cap: capability name
|
|
|
|
* @names: array to collect the list of node device names
|
|
|
|
* @maxnames: size of @names
|
|
|
|
* @flags: flags (unused, pass 0)
|
|
|
|
*
|
|
|
|
* Collect the list of node devices, and store their names in @names
|
|
|
|
*
|
|
|
|
* If the optional 'cap' argument is non-NULL, then the count
|
|
|
|
* will be restricted to devices with the specified capability
|
|
|
|
*
|
|
|
|
* Returns the number of node devices found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeListDevices(virConnectPtr conn,
|
|
|
|
const char *cap,
|
|
|
|
char **const names, int maxnames,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, cap=%s, names=%p, maxnames=%d, flags=%d",
|
|
|
|
conn, cap, names, maxnames, flags);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if ((flags != 0) || (names == NULL) || (maxnames < 0)) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->deviceMonitor && conn->deviceMonitor->listDevices) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->deviceMonitor->listDevices (conn, cap, names, maxnames, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-11-21 12:19:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceLookupByName:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @name: unique device name
|
|
|
|
*
|
|
|
|
* Lookup a node device by its name.
|
|
|
|
*
|
|
|
|
* Returns a virNodeDevicePtr if found, NULL otherwise.
|
|
|
|
*/
|
|
|
|
virNodeDevicePtr virNodeDeviceLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
|
|
|
DEBUG("conn=%p, name=%p", conn, name);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (conn->deviceMonitor && conn->deviceMonitor->deviceLookupByName) {
|
|
|
|
virNodeDevicePtr ret;
|
|
|
|
ret = conn->deviceMonitor->deviceLookupByName (conn, name);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-11-21 12:19:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceGetXMLDesc:
|
|
|
|
* @dev: pointer to the node device
|
|
|
|
* @flags: flags for XML generation (unused, pass 0)
|
|
|
|
*
|
|
|
|
* Fetch an XML document describing all aspects of
|
|
|
|
* the device.
|
|
|
|
*
|
|
|
|
* Return the XML document, or NULL on error
|
|
|
|
*/
|
|
|
|
char *virNodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (dev->conn->deviceMonitor && dev->conn->deviceMonitor->deviceDumpXML) {
|
|
|
|
char *ret;
|
|
|
|
ret = dev->conn->deviceMonitor->deviceDumpXML (dev, flags);
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dev->conn);
|
2008-11-21 12:19:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceGetName:
|
|
|
|
* @dev: the device
|
|
|
|
*
|
2008-11-25 15:48:11 +00:00
|
|
|
* Just return the device name
|
|
|
|
*
|
|
|
|
* Returns the device name or NULL in case of error
|
2008-11-21 12:19:22 +00:00
|
|
|
*/
|
|
|
|
const char *virNodeDeviceGetName(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dev->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceGetParent:
|
|
|
|
* @dev: the device
|
|
|
|
*
|
2008-11-25 15:48:11 +00:00
|
|
|
* Accessor for the parent of the device
|
|
|
|
*
|
2008-11-21 12:19:22 +00:00
|
|
|
* Returns the name of the device's parent, or NULL if the
|
|
|
|
* device has no parent.
|
|
|
|
*/
|
|
|
|
const char *virNodeDeviceGetParent(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:46:34 +00:00
|
|
|
if (!dev->parent) {
|
|
|
|
if (dev->conn->deviceMonitor && dev->conn->deviceMonitor->deviceGetParent) {
|
|
|
|
dev->parent = dev->conn->deviceMonitor->deviceGetParent (dev);
|
|
|
|
} else {
|
|
|
|
virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
virSetConnError(dev->conn);
|
2008-12-04 21:46:34 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dev->parent;
|
2008-11-21 12:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceNumOfCaps:
|
|
|
|
* @dev: the device
|
|
|
|
*
|
2008-11-25 15:48:11 +00:00
|
|
|
* Accessor for the number of capabilities supported by the device.
|
|
|
|
*
|
2008-11-21 12:19:22 +00:00
|
|
|
* Returns the number of capabilities supported by the device.
|
|
|
|
*/
|
|
|
|
int virNodeDeviceNumOfCaps(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (dev->conn->deviceMonitor && dev->conn->deviceMonitor->deviceNumOfCaps) {
|
|
|
|
int ret;
|
|
|
|
ret = dev->conn->deviceMonitor->deviceNumOfCaps (dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dev->conn);
|
2008-11-21 12:19:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceListCaps:
|
|
|
|
* @dev: the device
|
|
|
|
* @names: array to collect the list of capability names
|
|
|
|
* @maxnames: size of @names
|
|
|
|
*
|
|
|
|
* Lists the names of the capabilities supported by the device.
|
|
|
|
*
|
|
|
|
* Returns the number of capability names listed in @names.
|
|
|
|
*/
|
|
|
|
int virNodeDeviceListCaps(virNodeDevicePtr dev,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p, names=%p, maxnames=%d",
|
|
|
|
dev, dev ? dev->conn : NULL, names, maxnames);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if (dev->conn->deviceMonitor && dev->conn->deviceMonitor->deviceListCaps) {
|
|
|
|
int ret;
|
|
|
|
ret = dev->conn->deviceMonitor->deviceListCaps (dev, names, maxnames);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-21 12:19:22 +00:00
|
|
|
|
|
|
|
virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dev->conn);
|
2008-11-21 12:19:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceFree:
|
|
|
|
* @dev: pointer to the node device
|
|
|
|
*
|
|
|
|
* Drops a reference to the node device, freeing it if
|
|
|
|
* this was the last reference.
|
|
|
|
*
|
|
|
|
* Returns the 0 for success, -1 for error.
|
|
|
|
*/
|
|
|
|
int virNodeDeviceFree(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2008-11-21 12:19:22 +00:00
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (virUnrefNodeDevice(dev) < 0)
|
|
|
|
return (-1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-20 12:14:03 +00:00
|
|
|
/**
|
|
|
|
* virNodeDeviceRef:
|
2009-04-24 14:04:54 +00:00
|
|
|
* @dev: the dev to hold a reference on
|
2009-01-20 12:14:03 +00:00
|
|
|
*
|
|
|
|
* Increment the reference count on the dev. For each
|
|
|
|
* additional call to this method, there shall be a corresponding
|
|
|
|
* call to virNodeDeviceFree to release the reference count, once
|
|
|
|
* the caller no longer needs the reference to this object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple
|
|
|
|
* threads are using a connection, and it is required that the
|
|
|
|
* connection remain open until all threads have finished using
|
|
|
|
* it. ie, each new thread using a dev would increment
|
|
|
|
* the reference count.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
2009-01-20 12:14:03 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeDeviceRef(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
if ((!VIR_IS_CONNECTED_NODE_DEVICE(dev))) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
virMutexLock(&dev->conn->lock);
|
|
|
|
DEBUG("dev=%p refs=%d", dev, dev->refs);
|
|
|
|
dev->refs++;
|
|
|
|
virMutexUnlock(&dev->conn->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-02 16:25:13 +00:00
|
|
|
/**
|
2009-04-24 14:04:54 +00:00
|
|
|
* virNodeDeviceDettach:
|
2009-03-02 16:25:13 +00:00
|
|
|
* @dev: pointer to the node device
|
|
|
|
*
|
|
|
|
* Dettach the node device from the node itself so that it may be
|
|
|
|
* assigned to a guest domain.
|
|
|
|
*
|
|
|
|
* Depending on the hypervisor, this may involve operations such
|
|
|
|
* as unbinding any device drivers from the device, binding the
|
|
|
|
* device to a dummy device driver and resetting the device.
|
|
|
|
*
|
|
|
|
* If the device is currently in use by the node, this method may
|
|
|
|
* fail.
|
|
|
|
*
|
|
|
|
* Once the device is not assigned to any guest, it may be re-attached
|
|
|
|
* to the node using the virNodeDeviceReattach() method.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
2009-03-02 16:25:13 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeDeviceDettach(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->conn->driver->nodeDeviceDettach) {
|
|
|
|
int ret;
|
|
|
|
ret = dev->conn->driver->nodeDeviceDettach (dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError(dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dev->conn);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceReAttach:
|
|
|
|
* @dev: pointer to the node device
|
|
|
|
*
|
|
|
|
* Re-attach a previously dettached node device to the node so that it
|
|
|
|
* may be used by the node again.
|
|
|
|
*
|
|
|
|
* Depending on the hypervisor, this may involve operations such
|
|
|
|
* as resetting the device, unbinding it from a dummy device driver
|
|
|
|
* and binding it to its appropriate driver.
|
|
|
|
*
|
|
|
|
* If the device is currently in use by a guest, this method may fail.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
2009-03-02 16:25:13 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeDeviceReAttach(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->conn->driver->nodeDeviceReAttach) {
|
|
|
|
int ret;
|
|
|
|
ret = dev->conn->driver->nodeDeviceReAttach (dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError(dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dev->conn);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceReset:
|
|
|
|
* @dev: pointer to the node device
|
|
|
|
*
|
|
|
|
* Reset a previously dettached node device to the node before or
|
|
|
|
* after assigning it to a guest.
|
|
|
|
*
|
|
|
|
* The exact reset semantics depends on the hypervisor and device
|
|
|
|
* type but, for example, KVM will attempt to reset PCI devices with
|
|
|
|
* a Function Level Reset, Secondary Bus Reset or a Power Management
|
|
|
|
* D-State reset.
|
|
|
|
*
|
|
|
|
* If the reset will affect other devices which are currently in use,
|
|
|
|
* this function may fail.
|
2009-04-24 14:04:54 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
2009-03-02 16:25:13 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeDeviceReset(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->conn->driver->nodeDeviceReset) {
|
|
|
|
int ret;
|
|
|
|
ret = dev->conn->driver->nodeDeviceReset (dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError(dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dev->conn);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2009-01-20 12:14:03 +00:00
|
|
|
|
2009-04-24 13:11:23 +00:00
|
|
|
/**
|
|
|
|
* virNodeDeviceCreateXML:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @xmlDesc: string containing an XML description of the device to be created
|
|
|
|
* @flags: callers should always pass 0
|
|
|
|
*
|
|
|
|
* Create a new device on the VM host machine, for example, virtual
|
|
|
|
* HBAs created using vport_create.
|
|
|
|
*
|
|
|
|
* Returns a node device object if successful, NULL in case of failure
|
|
|
|
*/
|
|
|
|
virNodeDevicePtr
|
|
|
|
virNodeDeviceCreateXML(virConnectPtr conn,
|
|
|
|
const char *xmlDesc,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("conn=%p, xmlDesc=%s, flags=%d", conn, xmlDesc, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xmlDesc == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->deviceMonitor &&
|
|
|
|
conn->deviceMonitor->deviceCreateXML) {
|
|
|
|
virNodeDevicePtr dev = conn->deviceMonitor->deviceCreateXML(conn, xmlDesc, flags);
|
|
|
|
if (dev == NULL)
|
|
|
|
goto error;
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceDestroy:
|
|
|
|
* @dev: a device object
|
|
|
|
*
|
|
|
|
* Destroy the device object. The virtual device is removed from the host operating system.
|
|
|
|
* This function may require privileged access
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virNodeDeviceDestroy(virNodeDevicePtr dev)
|
|
|
|
{
|
|
|
|
DEBUG("dev=%p", dev);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
|
|
|
|
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibConnError(dev->conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->conn->deviceMonitor &&
|
|
|
|
dev->conn->deviceMonitor->deviceDestroy) {
|
|
|
|
int retval = dev->conn->deviceMonitor->deviceDestroy(dev);
|
|
|
|
if (retval < 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(dev->conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
/*
|
|
|
|
* Domain Event Notification
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectDomainEventRegister:
|
|
|
|
* @conn: pointer to the connection
|
|
|
|
* @cb: callback to the function handling domain events
|
|
|
|
* @opaque: opaque data to pass on to the callback
|
2008-11-25 15:48:11 +00:00
|
|
|
* @freecb: optional function to deallocate opaque when not used anymore
|
2008-10-23 13:18:18 +00:00
|
|
|
*
|
|
|
|
* Adds a Domain Event Callback.
|
|
|
|
* Registering for a domain callback will enable delivery of the events
|
|
|
|
*
|
2009-01-20 12:14:03 +00:00
|
|
|
* The virDomainPtr object handle passed into the callback upon delivery
|
|
|
|
* of an event is only valid for the duration of execution of the callback.
|
|
|
|
* If the callback wishes to keep the domain object after the callback
|
|
|
|
* returns, it shall take a reference to it, by calling virDomainRef.
|
|
|
|
* The reference can be released once the object is no longer required
|
|
|
|
* by calling virDomainFree.
|
|
|
|
*
|
2008-10-23 13:18:18 +00:00
|
|
|
* Returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectDomainEventRegister(virConnectPtr conn,
|
|
|
|
virConnectDomainEventCallback cb,
|
2008-11-19 15:25:24 +00:00
|
|
|
void *opaque,
|
|
|
|
virFreeCallback freecb)
|
2008-10-23 13:18:18 +00:00
|
|
|
{
|
2009-01-20 12:01:45 +00:00
|
|
|
DEBUG("conn=%p, cb=%p, opaque=%p, freecb=%p", conn, cb, opaque, freecb);
|
|
|
|
virResetLastError();
|
2008-10-23 13:18:18 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (cb == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
if ((conn->driver) && (conn->driver->domainEventRegister)) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainEventRegister (conn, cb, opaque, freecb);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-10-23 13:18:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectDomainEventDeregister:
|
|
|
|
* @conn: pointer to the connection
|
|
|
|
* @cb: callback to the function handling domain events
|
|
|
|
*
|
|
|
|
* Removes a Domain Event Callback.
|
|
|
|
* De-registering for a domain callback will disable
|
|
|
|
* delivery of this event type
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectDomainEventDeregister(virConnectPtr conn,
|
|
|
|
virConnectDomainEventCallback cb)
|
|
|
|
{
|
2009-01-20 12:01:45 +00:00
|
|
|
DEBUG("conn=%p, cb=%p", conn, cb);
|
|
|
|
|
|
|
|
virResetLastError();
|
2008-10-23 13:18:18 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (cb == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-20 12:01:45 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if ((conn->driver) && (conn->driver->domainEventDeregister)) {
|
|
|
|
int ret;
|
|
|
|
ret = conn->driver->domainEventDeregister (conn, cb);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
2008-10-23 13:18:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
2008-10-23 13:18:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-28 01:25:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretGetConnect:
|
|
|
|
* @secret: A virSecret secret
|
|
|
|
*
|
|
|
|
* Provides the connection pointer associated with a secret. 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 secret object together.
|
|
|
|
*
|
|
|
|
* Returns the virConnectPtr or NULL in case of failure.
|
|
|
|
*/
|
|
|
|
virConnectPtr
|
|
|
|
virSecretGetConnect (virSecretPtr secret)
|
|
|
|
{
|
|
|
|
DEBUG("secret=%p", secret);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET (secret)) {
|
|
|
|
virLibSecretError (NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return secret->conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectNumOfSecrets:
|
|
|
|
* @conn: virConnect connection
|
|
|
|
*
|
|
|
|
* Fetch number of currently defined secrets.
|
|
|
|
*
|
|
|
|
* Returns the number currently defined secrets.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectNumOfSecrets(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("conn=%p", conn);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->secretDriver != NULL &&
|
|
|
|
conn->secretDriver->numOfSecrets != NULL) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->numOfSecrets(conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virConnectListSecrets:
|
|
|
|
* @conn: virConnect connection
|
|
|
|
* @uuids: Pointer to an array to store the UUIDs
|
|
|
|
* @maxuuids: size of the array.
|
|
|
|
*
|
|
|
|
* List UUIDs of defined secrets, store pointers to names in uuids.
|
|
|
|
*
|
|
|
|
* Returns the number of UUIDs provided in the array, or -1 on failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virConnectListSecrets(virConnectPtr conn, char **uuids, int maxuuids)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("conn=%p, uuids=%p, maxuuids=%d", conn, uuids, maxuuids);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (uuids == NULL || maxuuids < 0) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->secretDriver != NULL && conn->secretDriver->listSecrets != NULL) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->listSecrets(conn, uuids, maxuuids);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretLookupByUUIDString:
|
|
|
|
* @conn: virConnect connection
|
|
|
|
* @uuid: ID of a secret
|
|
|
|
*
|
|
|
|
* Fetches a secret based on uuid.
|
|
|
|
*
|
|
|
|
* Returns the secret on success, or NULL on failure.
|
|
|
|
*/
|
|
|
|
virSecretPtr
|
|
|
|
virSecretLookupByUUIDString(virConnectPtr conn, const char *uuid)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("conn=%p, uuid=%s", conn, uuid);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECT(conn)) {
|
|
|
|
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (uuid == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->secretDriver != NULL &&
|
|
|
|
conn->secretDriver->lookupByUUIDString != NULL) {
|
|
|
|
virSecretPtr ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->lookupByUUIDString(conn, uuid);
|
|
|
|
if (ret == NULL)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretDefineXML:
|
|
|
|
* @conn: virConnect connection
|
|
|
|
* @xml: XML describing the secret.
|
|
|
|
* @flags: flags, use 0 for now
|
|
|
|
*
|
|
|
|
* If XML specifies an UUID, locates the specified secret and replaces all
|
|
|
|
* attributes of the secret specified by UUID by attributes specified in xml
|
|
|
|
* (any attributes not specified in xml are discarded).
|
|
|
|
*
|
|
|
|
* Otherwise, creates a new secret with an automatically chosen UUID, and
|
|
|
|
* initializes its attributes from xml.
|
|
|
|
*
|
|
|
|
* Returns a the secret on success, NULL on failure.
|
|
|
|
*/
|
|
|
|
virSecretPtr
|
|
|
|
virSecretDefineXML(virConnectPtr conn, const char *xml, unsigned int flags)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("conn=%p, xml=%s, flags=%u", conn, xml, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
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__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (xml == NULL) {
|
|
|
|
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->secretDriver != NULL && conn->secretDriver->defineXML != NULL) {
|
|
|
|
virSecretPtr ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->defineXML(conn, xml, flags);
|
|
|
|
if (ret == NULL)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretGetUUIDString:
|
|
|
|
* @secret: A virSecret secret
|
|
|
|
*
|
|
|
|
* Fetches the UUID of the secret.
|
|
|
|
*
|
|
|
|
* Returns ID of the secret (not necessarily in the UUID format) on success,
|
|
|
|
* NULL on failure. The caller must free() the ID.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virSecretGetUUIDString(virSecretPtr secret)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
VIR_DEBUG("secret=%p", secret);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
|
|
|
virLibSecretError(NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = strdup(secret->uuid);
|
|
|
|
if (ret != NULL)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
virReportOOMError(secret->conn);
|
|
|
|
virSetConnError(secret->conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretGetXMLDesc:
|
|
|
|
* @secret: A virSecret secret
|
|
|
|
* @flags: flags, use 0 for now
|
|
|
|
*
|
|
|
|
* Fetches an XML document describing attributes of the secret.
|
|
|
|
*
|
|
|
|
* Returns the XML document on success, NULL on failure. The caller must
|
|
|
|
* free() the XML.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virSecretGetXMLDesc(virSecretPtr secret, unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
VIR_DEBUG("secret=%p, flags=%u", secret, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
|
|
|
virLibSecretError(NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn = secret->conn;
|
|
|
|
if (conn->secretDriver != NULL && conn->secretDriver->getXMLDesc != NULL) {
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->getXMLDesc(secret, flags);
|
|
|
|
if (ret == NULL)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretSetValue:
|
|
|
|
* @secret: A virSecret secret
|
|
|
|
* @value: Value of the secret
|
|
|
|
* @value_size: Size of the value
|
|
|
|
* @flags: flags, use 0 for now
|
|
|
|
*
|
|
|
|
* Sets the value of a secret.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virSecretSetValue(virSecretPtr secret, const unsigned char *value,
|
|
|
|
size_t value_size, unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
VIR_DEBUG("secret=%p, value=%p, value_size=%zu, flags=%u", secret, value,
|
|
|
|
value_size, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
|
|
|
virLibSecretError(NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = secret->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibSecretError(secret, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (value == NULL) {
|
|
|
|
virLibSecretError(secret, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->secretDriver != NULL && conn->secretDriver->setValue != NULL) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->setValue(secret, value, value_size, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretGetValue:
|
|
|
|
* @secret: A virSecret connection
|
|
|
|
* @value_size: Place for storing size of the secret value
|
|
|
|
* @flags: flags, use 0 for now
|
|
|
|
*
|
|
|
|
* Fetches the value of a secret.
|
|
|
|
*
|
|
|
|
* Returns the secret value on success, NULL on failure. The caller must
|
|
|
|
* free() the secret value.
|
|
|
|
*/
|
|
|
|
unsigned char *
|
|
|
|
virSecretGetValue(virSecretPtr secret, size_t *value_size, unsigned int flags)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
VIR_DEBUG("secret=%p, value_size=%p, flags=%u", secret, value_size, flags);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
|
|
|
virLibSecretError(NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
conn = secret->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibSecretError(secret, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (value_size == NULL) {
|
|
|
|
virLibSecretError(secret, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->secretDriver != NULL && conn->secretDriver->getValue != NULL) {
|
|
|
|
unsigned char *ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->getValue(secret, value_size, flags);
|
|
|
|
if (ret == NULL)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretUndefine:
|
|
|
|
* @secret: A virSecret secret
|
|
|
|
*
|
|
|
|
* Deletes the specified secret. This does not free the associated
|
|
|
|
* virSecretPtr object.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virSecretUndefine(virSecretPtr secret)
|
|
|
|
{
|
|
|
|
virConnectPtr conn;
|
|
|
|
|
|
|
|
VIR_DEBUG("secret=%p", secret);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
|
|
|
virLibSecretError(NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
conn = secret->conn;
|
|
|
|
if (conn->flags & VIR_CONNECT_RO) {
|
|
|
|
virLibSecretError(secret, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->secretDriver != NULL && conn->secretDriver->undefine != NULL) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = conn->secretDriver->undefine(secret);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Copy to connection error object for back compatability */
|
|
|
|
virSetConnError(conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretRef:
|
|
|
|
* @secret: the secret to hold a reference on
|
|
|
|
*
|
|
|
|
* Increment the reference count on the secret. For each additional call to
|
|
|
|
* this method, there shall be a corresponding call to virSecretFree to release
|
|
|
|
* the reference count, once the caller no longer needs the reference to this
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* This method is typically useful for applications where multiple threads are
|
|
|
|
* using a connection, and it is required that the connection remain open until
|
|
|
|
* all threads have finished using it. ie, each new thread using a secret would
|
|
|
|
* increment the reference count.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virSecretRef(virSecretPtr secret)
|
|
|
|
{
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
|
|
|
virLibSecretError(NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
virMutexLock(&secret->conn->lock);
|
|
|
|
DEBUG("secret=%p refs=%d", secret, secret->refs);
|
|
|
|
secret->refs++;
|
|
|
|
virMutexUnlock(&secret->conn->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virSecretFree:
|
|
|
|
* @secret: pointer to a secret
|
|
|
|
*
|
|
|
|
* Release the secret handle. The underlying secret continues to exist.
|
|
|
|
*
|
|
|
|
* Return 0 on success, or -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virSecretFree(virSecretPtr secret)
|
|
|
|
{
|
|
|
|
DEBUG("secret=%p", secret);
|
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_SECRET(secret)) {
|
|
|
|
virLibSecretError(NULL, VIR_ERR_INVALID_SECRET, __FUNCTION__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (virUnrefSecret(secret) < 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|