mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
* src/driver.h src/internal.h src/libvirt.c src/xen_internal.c
src/xen_internal.h docs/apibuild.py: starting the refactoring, first the direct Xen hypervisor module. New header describing the entry points of a driver. Daniel
This commit is contained in:
parent
247cf7a3b2
commit
de5a1d1dd5
@ -1,3 +1,10 @@
|
||||
Mon Mar 20 18:43:19 CET 2006 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* src/driver.h src/internal.h src/libvirt.c src/xen_internal.c
|
||||
src/xen_internal.h docs/apibuild.py: starting the refactoring,
|
||||
first the direct Xen hypervisor module. New header describing the
|
||||
entry points of a driver.
|
||||
|
||||
Wed Mar 15 13:10:25 CET 2006 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* src/hash.c src/hash.h src/internal.h src/libvirt.c src/sexpr.c
|
||||
|
@ -22,6 +22,7 @@ ignored_files = {
|
||||
"hash.c": "internal hash table stuff",
|
||||
"hash.h": "internal hash table stuff",
|
||||
"internal.h": "internal includes and defines",
|
||||
"driver.h": "internal driver interfaces",
|
||||
"xend_internal.h": "internal includes and defines",
|
||||
"xend_internal.c": "internal code",
|
||||
"sexpr.h": "internal includes and defines",
|
||||
|
136
src/driver.h
Normal file
136
src/driver.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* driver.h: description of the set of interfaces provided by a
|
||||
* entry point to the virtualization engine
|
||||
*/
|
||||
|
||||
#ifndef __VIR_DRIVER_H__
|
||||
#define __VIR_DRIVER_H__
|
||||
|
||||
#include "libvirt.h"
|
||||
#include "virterror.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
VIR_DRV_OPEN_QUIET = 1,
|
||||
VIR_DRV_OPEN_RO = 2
|
||||
} virDrvOpenFlag;
|
||||
|
||||
typedef int
|
||||
(*virDrvInit) (void);
|
||||
typedef int
|
||||
(*virDrvOpen) (virConnectPtr conn,
|
||||
const char *name,
|
||||
int flags);
|
||||
typedef int
|
||||
(*virDrvClose) (virConnectPtr conn);
|
||||
typedef const char *
|
||||
(*virDrvGetType) (virConnectPtr conn);
|
||||
typedef int
|
||||
(*virDrvGetVersion) (void * conn,
|
||||
unsigned long *hvVer);
|
||||
typedef int
|
||||
(*virDrvListDomains) (virConnectPtr conn,
|
||||
int *ids,
|
||||
int maxids);
|
||||
typedef int
|
||||
(*virDrvNumOfDomains) (virConnectPtr conn);
|
||||
typedef virDomainPtr
|
||||
(*virDrvDomainCreateLinux) (virConnectPtr conn,
|
||||
const char *xmlDesc,
|
||||
unsigned int flags);
|
||||
typedef virDomainPtr
|
||||
(*virDrvDomainLookupByID) (virConnectPtr conn,
|
||||
int id);
|
||||
typedef virDomainPtr
|
||||
(*virDrvDomainLookupByUUID) (virConnectPtr conn,
|
||||
const unsigned char *uuid);
|
||||
typedef virDomainPtr
|
||||
(*virDrvDomainLookupByName) (virConnectPtr conn,
|
||||
const char *name);
|
||||
typedef int
|
||||
(*virDrvDomainSuspend) (virDomainPtr domain);
|
||||
typedef int
|
||||
(*virDrvDomainResume) (virDomainPtr domain);
|
||||
typedef int
|
||||
(*virDrvDomainShutdown) (virDomainPtr domain);
|
||||
typedef int
|
||||
(*virDrvDomainDestroy) (virDomainPtr domain);
|
||||
typedef int
|
||||
(*virDrvDomainFree) (virDomainPtr domain);
|
||||
typedef const char *
|
||||
(*virDrvDomainGetName) (virDomainPtr domain);
|
||||
typedef int
|
||||
(*virDrvDomainGetID) (virDomainPtr domain);
|
||||
typedef int
|
||||
(*virDrvDomainGetUUID) (virDomainPtr domain,
|
||||
unsigned char *uuid);
|
||||
typedef char *
|
||||
(*virDrvDomainGetOSType) (virDomainPtr domain);
|
||||
typedef unsigned long
|
||||
(*virDrvDomainGetMaxMemory) (virDomainPtr domain);
|
||||
typedef int
|
||||
(*virDrvDomainSetMaxMemory) (virDomainPtr domain,
|
||||
unsigned long memory);
|
||||
typedef int
|
||||
(*virDrvDomainGetInfo) (virDomainPtr domain,
|
||||
virDomainInfoPtr info);
|
||||
typedef int
|
||||
(*virDrvDomainSave) (virDomainPtr domain,
|
||||
const char *to);
|
||||
typedef int
|
||||
(*virDrvDomainRestore) (virConnectPtr conn,
|
||||
const char *from);
|
||||
|
||||
typedef struct _virDriver virDriver;
|
||||
typedef virDriver *virDriverPtr;
|
||||
|
||||
/**
|
||||
* _virDriver:
|
||||
*
|
||||
* Structure associated to a virtualization driver, defining the various
|
||||
* entry points for it.
|
||||
*/
|
||||
struct _virDriver {
|
||||
const char *name;
|
||||
virDrvInit init;
|
||||
virDrvOpen open;
|
||||
virDrvClose close;
|
||||
virDrvGetType type;
|
||||
virDrvGetVersion version;
|
||||
virDrvListDomains listDomains;
|
||||
virDrvNumOfDomains numOfDomains;
|
||||
virDrvDomainCreateLinux domainCreateLinux;
|
||||
virDrvDomainLookupByID domainLookupByID;
|
||||
virDrvDomainLookupByUUID domainLookupByUUID;
|
||||
virDrvDomainLookupByName domainLookupByName;
|
||||
virDrvDomainSuspend domainSuspend;
|
||||
virDrvDomainResume domainResume;
|
||||
virDrvDomainShutdown domainShutdown;
|
||||
virDrvDomainDestroy domainDestroy;
|
||||
virDrvDomainFree domainFree;
|
||||
virDrvDomainGetName domainGetName;
|
||||
virDrvDomainGetID domainGetID;
|
||||
virDrvDomainGetUUID domainGetUUID;
|
||||
virDrvDomainGetOSType domainGetOSType;
|
||||
virDrvDomainGetMaxMemory domainGetMaxMemory;
|
||||
virDrvDomainSetMaxMemory domainSetMaxMemory;
|
||||
virDrvDomainGetInfo domainGetInfo;
|
||||
virDrvDomainSave domainSave;
|
||||
virDrvDomainRestore domainRestore;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Registration
|
||||
* TODO: also need ways to (des)activate a given driver
|
||||
* lookup based on the URI given in a virConnectOpen(ReadOnly)
|
||||
*/
|
||||
int virRegisterDriver(virDriverPtr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __VIR_DRIVER_H__ */
|
106
src/internal.h
106
src/internal.h
@ -74,70 +74,70 @@ extern "C" {
|
||||
*
|
||||
* Internal structure associated to a connection
|
||||
*/
|
||||
struct _virConnect {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int handle; /* internal handle used for hypercall */
|
||||
struct xs_handle *xshandle; /* handle to talk to the xenstore */
|
||||
struct _virConnect {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int handle; /* internal handle used for hypercall */
|
||||
struct xs_handle *xshandle; /* handle to talk to the xenstore */
|
||||
|
||||
/* connection to xend */
|
||||
int type; /* PF_UNIX or PF_INET */
|
||||
int len; /* lenght of addr */
|
||||
struct sockaddr *addr; /* type of address used */
|
||||
struct sockaddr_un addr_un; /* the unix address */
|
||||
struct sockaddr_in addr_in; /* the inet address */
|
||||
/* connection to xend */
|
||||
int type; /* PF_UNIX or PF_INET */
|
||||
int len; /* lenght of addr */
|
||||
struct sockaddr *addr; /* type of address used */
|
||||
struct sockaddr_un addr_un; /* the unix address */
|
||||
struct sockaddr_in addr_in; /* the inet address */
|
||||
|
||||
/* error stuff */
|
||||
virError err; /* the last error */
|
||||
virErrorFunc handler; /* associated handlet */
|
||||
void *userData; /* the user data */
|
||||
/* error stuff */
|
||||
virError err; /* the last error */
|
||||
virErrorFunc handler; /* associated handlet */
|
||||
void *userData; /* the user data */
|
||||
|
||||
/* misc */
|
||||
virHashTablePtr domains; /* hash table for known domains */
|
||||
int flags; /* a set of connection flags */
|
||||
};
|
||||
/* misc */
|
||||
virHashTablePtr domains; /* hash table for known domains */
|
||||
int flags; /* a set of connection flags */
|
||||
};
|
||||
|
||||
/**
|
||||
* virDomainFlags:
|
||||
*
|
||||
* a set of special flag values associated to the domain
|
||||
*/
|
||||
* virDomainFlags:
|
||||
*
|
||||
* a set of special flag values associated to the domain
|
||||
*/
|
||||
|
||||
enum {
|
||||
DOMAIN_IS_SHUTDOWN = (1 << 0) /* the domain is being shutdown */
|
||||
} virDomainFlags;
|
||||
enum {
|
||||
DOMAIN_IS_SHUTDOWN = (1 << 0) /* the domain is being shutdown */
|
||||
} virDomainFlags;
|
||||
|
||||
/**
|
||||
* _virDomain:
|
||||
*
|
||||
* Internal structure associated to a domain
|
||||
*/
|
||||
struct _virDomain {
|
||||
unsigned int magic; /* specific value to check */
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the domain external name */
|
||||
char *path; /* the domain internal path */
|
||||
int handle; /* internal handle for the dmonain ID */
|
||||
int flags; /* extra flags */
|
||||
unsigned char uuid[16]; /* the domain unique identifier */
|
||||
};
|
||||
* _virDomain:
|
||||
*
|
||||
* Internal structure associated to a domain
|
||||
*/
|
||||
struct _virDomain {
|
||||
unsigned int magic; /* specific value to check */
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the domain external name */
|
||||
char *path; /* the domain internal path */
|
||||
int handle; /* internal handle for the domnain ID */
|
||||
int flags; /* extra flags */
|
||||
unsigned char uuid[16]; /* the domain unique identifier */
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal routines
|
||||
*/
|
||||
char *virDomainGetVM(virDomainPtr domain);
|
||||
char *virDomainGetVMInfo(virDomainPtr domain,
|
||||
const char *vm, const char *name);
|
||||
* Internal routines
|
||||
*/
|
||||
char *virDomainGetVM(virDomainPtr domain);
|
||||
char *virDomainGetVMInfo(virDomainPtr domain,
|
||||
const char *vm, const char *name);
|
||||
|
||||
void __virRaiseError(virConnectPtr conn,
|
||||
virDomainPtr dom,
|
||||
int domain,
|
||||
int code,
|
||||
virErrorLevel level,
|
||||
const char *str1,
|
||||
const char *str2,
|
||||
const char *str3,
|
||||
int int1, int int2, const char *msg, ...);
|
||||
const char *__virErrorMsg(virErrorNumber error, const char *info);
|
||||
void __virRaiseError(virConnectPtr conn,
|
||||
virDomainPtr dom,
|
||||
int domain,
|
||||
int code,
|
||||
virErrorLevel level,
|
||||
const char *str1,
|
||||
const char *str2,
|
||||
const char *str3,
|
||||
int int1, int int2, const char *msg, ...);
|
||||
const char *__virErrorMsg(virErrorNumber error, const char *info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <unistd.h>
|
||||
#include <xs.h>
|
||||
#include "internal.h"
|
||||
#include "driver.h"
|
||||
#include "xen_internal.h"
|
||||
#include "xend_internal.h"
|
||||
#include "hash.h"
|
||||
@ -137,7 +138,7 @@ virConnectPtr
|
||||
virConnectOpen(const char *name)
|
||||
{
|
||||
virConnectPtr ret = NULL;
|
||||
int handle = -1;
|
||||
int res;
|
||||
struct xs_handle *xshandle = NULL;
|
||||
|
||||
/* we can only talk to the local Xen supervisor ATM */
|
||||
@ -146,16 +147,6 @@ virConnectOpen(const char *name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
handle = xenHypervisorOpen(0);
|
||||
if (handle == -1) {
|
||||
goto failed;
|
||||
}
|
||||
xshandle = xs_daemon_open();
|
||||
if (xshandle == NULL) {
|
||||
virLibConnError(NULL, VIR_ERR_NO_CONNECT, "XenStore");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
ret = (virConnectPtr) malloc(sizeof(virConnect));
|
||||
if (ret == NULL) {
|
||||
virLibConnError(NULL, VIR_ERR_NO_MEMORY, "Allocating connection");
|
||||
@ -163,7 +154,17 @@ virConnectOpen(const char *name)
|
||||
}
|
||||
memset(ret, 0, sizeof(virConnect));
|
||||
ret->magic = VIR_CONNECT_MAGIC;
|
||||
ret->handle = handle;
|
||||
|
||||
res = xenHypervisorOpen(ret, name, 0);
|
||||
if (res < 0) {
|
||||
goto failed;
|
||||
}
|
||||
xshandle = xs_daemon_open();
|
||||
if (xshandle == NULL) {
|
||||
virLibConnError(NULL, VIR_ERR_NO_CONNECT, "XenStore");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
ret->xshandle = xshandle;
|
||||
if (xend_setup(ret) < 0)
|
||||
goto failed;
|
||||
@ -174,8 +175,7 @@ virConnectOpen(const char *name)
|
||||
|
||||
return (ret);
|
||||
failed:
|
||||
if (handle >= 0)
|
||||
xenHypervisorClose(handle);
|
||||
xenHypervisorClose(ret);
|
||||
if (xshandle != NULL)
|
||||
xs_daemon_close(xshandle);
|
||||
if (ret != NULL)
|
||||
@ -197,7 +197,7 @@ virConnectPtr
|
||||
virConnectOpenReadOnly(const char *name)
|
||||
{
|
||||
int method = 0;
|
||||
int handle;
|
||||
int res;
|
||||
virConnectPtr ret = NULL;
|
||||
struct xs_handle *xshandle = NULL;
|
||||
|
||||
@ -207,16 +207,6 @@ virConnectOpenReadOnly(const char *name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
handle = xenHypervisorOpen(1);
|
||||
if (handle >= 0)
|
||||
method++;
|
||||
else
|
||||
handle = -1;
|
||||
|
||||
xshandle = xs_daemon_open_readonly();
|
||||
if (xshandle != NULL)
|
||||
method++;
|
||||
|
||||
ret = (virConnectPtr) malloc(sizeof(virConnect));
|
||||
if (ret == NULL) {
|
||||
virLibConnError(NULL, VIR_ERR_NO_MEMORY, "Allocating connection");
|
||||
@ -224,7 +214,15 @@ virConnectOpenReadOnly(const char *name)
|
||||
}
|
||||
memset(ret, 0, sizeof(virConnect));
|
||||
ret->magic = VIR_CONNECT_MAGIC;
|
||||
ret->handle = handle;
|
||||
|
||||
res = xenHypervisorOpen(ret, name, VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO);
|
||||
if (res >= 0)
|
||||
method++;
|
||||
|
||||
xshandle = xs_daemon_open_readonly();
|
||||
if (xshandle != NULL)
|
||||
method++;
|
||||
|
||||
ret->xshandle = xshandle;
|
||||
if (xend_setup(ret) == 0)
|
||||
method++;
|
||||
@ -240,8 +238,7 @@ virConnectOpenReadOnly(const char *name)
|
||||
|
||||
return (ret);
|
||||
failed:
|
||||
if (handle >= 0)
|
||||
xenHypervisorClose(handle);
|
||||
xenHypervisorClose(ret);
|
||||
if (xshandle != NULL)
|
||||
xs_daemon_close(xshandle);
|
||||
if (ret != NULL) {
|
||||
@ -266,6 +263,8 @@ static int
|
||||
virConnectCheckStoreID(virConnectPtr conn, int id)
|
||||
{
|
||||
if (conn->handle >= 0) {
|
||||
TODO
|
||||
/*
|
||||
dom0_getdomaininfo_t dominfo;
|
||||
int tmp;
|
||||
|
||||
@ -273,6 +272,7 @@ virConnectCheckStoreID(virConnectPtr conn, int id)
|
||||
tmp = xenHypervisorGetDomainInfo(conn->handle, id, &dominfo);
|
||||
if (tmp < 0)
|
||||
return (-1);
|
||||
*/
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@ -313,8 +313,7 @@ virConnectClose(virConnectPtr conn)
|
||||
if (conn->xshandle != NULL)
|
||||
xs_daemon_close(conn->xshandle);
|
||||
conn->xshandle = NULL;
|
||||
if (conn->handle != -1)
|
||||
xenHypervisorClose(conn->handle);
|
||||
xenHypervisorClose(conn);
|
||||
conn->handle = -1;
|
||||
free(conn);
|
||||
return (0);
|
||||
@ -373,8 +372,7 @@ virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
|
||||
return (0);
|
||||
}
|
||||
|
||||
ver = xenHypervisorGetVersion(conn->handle);
|
||||
*hvVer = (ver >> 16) * 1000000 + (ver & 0xFFFF) * 1000;
|
||||
ver = xenHypervisorGetVersion(conn, hvVer);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -961,7 +959,7 @@ virDomainDestroy(virDomainPtr domain)
|
||||
return (0);
|
||||
}
|
||||
|
||||
ret = xenHypervisorDestroyDomain(domain->conn->handle, domain->handle);
|
||||
ret = xenHypervisorDestroyDomain(domain);
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
|
||||
@ -1023,8 +1021,7 @@ virDomainSuspend(virDomainPtr domain)
|
||||
return (0);
|
||||
|
||||
/* then try a direct hypervisor access */
|
||||
return (xenHypervisorPauseDomain
|
||||
(domain->conn->handle, domain->handle));
|
||||
return (xenHypervisorPauseDomain(domain));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1053,8 +1050,7 @@ virDomainResume(virDomainPtr domain)
|
||||
return (0);
|
||||
|
||||
/* then try a direct hypervisor access */
|
||||
return (xenHypervisorResumeDomain
|
||||
(domain->conn->handle, domain->handle));
|
||||
return (xenHypervisorResumeDomain(domain));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1278,7 +1274,8 @@ virDomainGetID(virDomainPtr domain)
|
||||
*
|
||||
* Get the type of domain operation system.
|
||||
*
|
||||
* Returns the new string or NULL in case of error
|
||||
* Returns the new string or NULL in case of error, the string must be
|
||||
* freed by the caller.
|
||||
*/
|
||||
char *
|
||||
virDomainGetOSType(virDomainPtr domain)
|
||||
@ -1330,15 +1327,12 @@ virDomainGetMaxMemory(virDomainPtr domain)
|
||||
free(tmp);
|
||||
}
|
||||
} else {
|
||||
dom0_getdomaininfo_t dominfo;
|
||||
virDomainInfo dominfo;
|
||||
int tmp;
|
||||
|
||||
dominfo.domain = domain->handle;
|
||||
tmp =
|
||||
xenHypervisorGetDomainInfo(domain->conn->handle,
|
||||
domain->handle, &dominfo);
|
||||
tmp = xenHypervisorGetDomainInfo(domain, &dominfo);
|
||||
if (tmp >= 0)
|
||||
ret = dominfo.max_pages * 4;
|
||||
ret = dominfo.maxMem;
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
@ -1373,8 +1367,7 @@ virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
|
||||
return (-1);
|
||||
if (domain->conn->xshandle == NULL)
|
||||
return (-1);
|
||||
ret = xenHypervisorSetMaxMemory(domain->conn->handle, domain->handle,
|
||||
memory);
|
||||
ret = xenHypervisorSetMaxMemory(domain, memory);
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
|
||||
@ -1429,12 +1422,15 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
|
||||
* if we have direct access though the hypervisor do a direct call
|
||||
*/
|
||||
if (domain->conn->handle >= 0) {
|
||||
ret = xenHypervisorGetDomainInfo(domain, info);
|
||||
if (ret < 0)
|
||||
goto xend_info;
|
||||
return (0);
|
||||
/*
|
||||
dom0_getdomaininfo_t dominfo;
|
||||
|
||||
dominfo.domain = domain->handle;
|
||||
ret =
|
||||
xenHypervisorGetDomainInfo(domain->conn->handle,
|
||||
domain->handle, &dominfo);
|
||||
ret = xenHypervisorGetDomainInfo(domain, &dominfo);
|
||||
if (ret < 0)
|
||||
goto xend_info;
|
||||
|
||||
@ -1458,16 +1454,15 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
|
||||
info->state = VIR_DOMAIN_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* the API brings back the cpu time in nanoseconds,
|
||||
* convert to microseconds, same thing convert to
|
||||
* kilobytes from page counts
|
||||
*/
|
||||
info->cpuTime = dominfo.cpu_time;
|
||||
info->memory = dominfo.tot_pages * 4;
|
||||
info->maxMem = dominfo.max_pages * 4;
|
||||
info->nrVirtCpu = dominfo.nr_online_vcpus;
|
||||
return (0);
|
||||
*/
|
||||
}
|
||||
|
||||
xend_info:
|
||||
|
@ -31,6 +31,7 @@ typedef struct hypercall_struct {
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include "driver.h"
|
||||
#include "xen_internal.h"
|
||||
|
||||
#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd"
|
||||
@ -58,44 +59,52 @@ virXenError(virErrorNumber error, const char *info, int value)
|
||||
|
||||
/**
|
||||
* xenHypervisorOpen:
|
||||
* @quiet: don'r raise an error on failure if set
|
||||
* @conn: pointer to the connection block
|
||||
* @name: URL for the target, NULL for local
|
||||
* @flags: combination of virDrvOpenFlag(s)
|
||||
*
|
||||
* Connects to the Xen hypervisor.
|
||||
*
|
||||
* Returns the handle or -1 in case of error.
|
||||
* Returns 0 or -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorOpen(int quiet)
|
||||
xenHypervisorOpen(virConnectPtr conn, const char *name, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((name != NULL) && (strcmp(name, "xen")))
|
||||
return(-1);
|
||||
|
||||
conn->handle = -1;
|
||||
|
||||
ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
|
||||
if (ret < 0) {
|
||||
if (!quiet)
|
||||
if (!(flags & VIR_DRV_OPEN_QUIET))
|
||||
virXenError(VIR_ERR_NO_XEN, XEN_HYPERVISOR_SOCKET, 0);
|
||||
return (-1);
|
||||
}
|
||||
conn->handle = ret;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenHypervisorClose:
|
||||
* @handle: the handle to the Xen hypervisor
|
||||
* @conn: pointer to the connection block
|
||||
*
|
||||
* Close the connection to the Xen hypervisor.
|
||||
*
|
||||
* Returns 0 in case of success or -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorClose(int handle)
|
||||
xenHypervisorClose(virConnectPtr conn)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (handle < 0)
|
||||
if ((conn == NULL) || (conn->handle < 0))
|
||||
return (-1);
|
||||
|
||||
ret = close(handle);
|
||||
ret = close(conn->handle);
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
@ -145,41 +154,42 @@ xenHypervisorDoOp(int handle, dom0_op_t * op)
|
||||
|
||||
/**
|
||||
* xenHypervisorGetVersion:
|
||||
* @handle: the handle to the Xen hypervisor
|
||||
* @conn: pointer to the connection block
|
||||
* @hvVer: where to store the version
|
||||
*
|
||||
* Call the hypervisor to extracts his own internal API version
|
||||
*
|
||||
* Returns the hypervisor running version or 0 in case of error.
|
||||
* Returns 0 in case of success, -1 in case of error
|
||||
*/
|
||||
unsigned long
|
||||
xenHypervisorGetVersion(int handle)
|
||||
int
|
||||
xenHypervisorGetVersion(virConnectPtr conn, unsigned long *hvVer)
|
||||
{
|
||||
int ret;
|
||||
unsigned int cmd;
|
||||
hypercall_t hc;
|
||||
|
||||
if ((conn == NULL) || (conn->handle < 0) || (hvVer == NULL))
|
||||
return (-1);
|
||||
*hvVer = 0;
|
||||
|
||||
hc.op = __HYPERVISOR_xen_version;
|
||||
hc.arg[0] = (unsigned long) XENVER_version;
|
||||
hc.arg[1] = 0;
|
||||
|
||||
cmd = _IOC(_IOC_NONE, 'P', 0, sizeof(hc));
|
||||
ret = ioctl(handle, cmd, (unsigned long) &hc);
|
||||
ret = ioctl(conn->handle, cmd, (unsigned long) &hc);
|
||||
|
||||
if (ret < 0) {
|
||||
virXenError(VIR_ERR_XEN_CALL, " getting version ", XENVER_version);
|
||||
return (0);
|
||||
return (-1);
|
||||
}
|
||||
/*
|
||||
* use unsigned long in case the version grows behind expectations
|
||||
* allowed by int
|
||||
*/
|
||||
return ((unsigned long) ret);
|
||||
*hvVer = (ret >> 16) * 1000000 + (ret & 0xFFFF) * 1000;
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenHypervisorGetDomainInfo:
|
||||
* @handle: the handle to the Xen hypervisor
|
||||
* @domain: the domain ID
|
||||
* @domain: pointer to the domain block
|
||||
* @info: the place where informations should be stored
|
||||
*
|
||||
* Do an hypervisor call to get the related set of domain informations.
|
||||
@ -187,16 +197,18 @@ xenHypervisorGetVersion(int handle)
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorGetDomainInfo(int handle, int domain,
|
||||
dom0_getdomaininfo_t * info)
|
||||
xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
|
||||
{
|
||||
dom0_op_t op;
|
||||
dom0_getdomaininfo_t dominfo;
|
||||
int ret;
|
||||
|
||||
if (info == NULL)
|
||||
if ((domain == NULL) || (domain->conn == NULL) ||
|
||||
(domain->conn->handle < 0) || (info == NULL))
|
||||
return (-1);
|
||||
|
||||
memset(info, 0, sizeof(dom0_getdomaininfo_t));
|
||||
memset(info, 0, sizeof(virDomainInfo));
|
||||
memset(&dominfo, 0, sizeof(dom0_getdomaininfo_t));
|
||||
|
||||
if (mlock(info, sizeof(dom0_getdomaininfo_t)) < 0) {
|
||||
virXenError(VIR_ERR_XEN_CALL, " locking",
|
||||
@ -205,13 +217,13 @@ xenHypervisorGetDomainInfo(int handle, int domain,
|
||||
}
|
||||
|
||||
op.cmd = DOM0_GETDOMAININFOLIST;
|
||||
op.u.getdomaininfolist.first_domain = (domid_t) domain;
|
||||
op.u.getdomaininfolist.first_domain = (domid_t) domain->handle;
|
||||
op.u.getdomaininfolist.max_domains = 1;
|
||||
op.u.getdomaininfolist.buffer = info;
|
||||
op.u.getdomaininfolist.buffer = &dominfo;
|
||||
op.u.getdomaininfolist.num_domains = 1;
|
||||
info->domain = domain;
|
||||
dominfo.domain = domain->handle;
|
||||
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
ret = xenHypervisorDoOp(domain->conn->handle, &op);
|
||||
|
||||
if (munlock(info, sizeof(dom0_getdomaininfo_t)) < 0) {
|
||||
virXenError(VIR_ERR_XEN_CALL, " release",
|
||||
@ -221,28 +233,61 @@ xenHypervisorGetDomainInfo(int handle, int domain,
|
||||
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
|
||||
switch (dominfo.flags & 0xFF) {
|
||||
case DOMFLAGS_DYING:
|
||||
info->state = VIR_DOMAIN_SHUTDOWN;
|
||||
break;
|
||||
case DOMFLAGS_SHUTDOWN:
|
||||
info->state = VIR_DOMAIN_SHUTOFF;
|
||||
break;
|
||||
case DOMFLAGS_PAUSED:
|
||||
info->state = VIR_DOMAIN_PAUSED;
|
||||
break;
|
||||
case DOMFLAGS_BLOCKED:
|
||||
info->state = VIR_DOMAIN_BLOCKED;
|
||||
break;
|
||||
case DOMFLAGS_RUNNING:
|
||||
info->state = VIR_DOMAIN_RUNNING;
|
||||
break;
|
||||
default:
|
||||
info->state = VIR_DOMAIN_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* the API brings back the cpu time in nanoseconds,
|
||||
* convert to microseconds, same thing convert to
|
||||
* kilobytes from page counts
|
||||
*/
|
||||
info->cpuTime = dominfo.cpu_time;
|
||||
info->memory = dominfo.tot_pages * 4;
|
||||
info->maxMem = dominfo.max_pages * 4;
|
||||
info->nrVirtCpu = dominfo.nr_online_vcpus;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* xenHypervisorPauseDomain:
|
||||
* @handle: the handle to the Xen hypervisor
|
||||
* @domain: the domain ID
|
||||
* @domain: pointer to the domain block
|
||||
*
|
||||
* Do an hypervisor call to pause the given domain
|
||||
*
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorPauseDomain(int handle, int domain)
|
||||
xenHypervisorPauseDomain(virDomainPtr domain)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
op.cmd = DOM0_PAUSEDOMAIN;
|
||||
op.u.pausedomain.domain = (domid_t) domain;
|
||||
if ((domain == NULL) || (domain->conn == NULL) ||
|
||||
(domain->conn->handle < 0))
|
||||
return (-1);
|
||||
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
op.cmd = DOM0_PAUSEDOMAIN;
|
||||
op.u.pausedomain.domain = (domid_t) domain->handle;
|
||||
|
||||
ret = xenHypervisorDoOp(domain->conn->handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
@ -251,23 +296,26 @@ xenHypervisorPauseDomain(int handle, int domain)
|
||||
|
||||
/**
|
||||
* xenHypervisorResumeDomain:
|
||||
* @handle: the handle to the Xen hypervisor
|
||||
* @domain: the domain ID
|
||||
* @domain: pointer to the domain block
|
||||
*
|
||||
* Do an hypervisor call to resume the given domain
|
||||
*
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorResumeDomain(int handle, int domain)
|
||||
xenHypervisorResumeDomain(virDomainPtr domain)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
op.cmd = DOM0_UNPAUSEDOMAIN;
|
||||
op.u.unpausedomain.domain = (domid_t) domain;
|
||||
if ((domain == NULL) || (domain->conn == NULL) ||
|
||||
(domain->conn->handle < 0))
|
||||
return (-1);
|
||||
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
op.cmd = DOM0_UNPAUSEDOMAIN;
|
||||
op.u.unpausedomain.domain = (domid_t) domain->handle;
|
||||
|
||||
ret = xenHypervisorDoOp(domain->conn->handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
@ -276,23 +324,26 @@ xenHypervisorResumeDomain(int handle, int domain)
|
||||
|
||||
/**
|
||||
* xenHypervisorDestroyDomain:
|
||||
* @handle: the handle to the Xen hypervisor
|
||||
* @domain: the domain ID
|
||||
* @domain: pointer to the domain block
|
||||
*
|
||||
* Do an hypervisor call to destroy the given domain
|
||||
*
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorDestroyDomain(int handle, int domain)
|
||||
xenHypervisorDestroyDomain(virDomainPtr domain)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
op.cmd = DOM0_DESTROYDOMAIN;
|
||||
op.u.destroydomain.domain = (domid_t) domain;
|
||||
if ((domain == NULL) || (domain->conn == NULL) ||
|
||||
(domain->conn->handle < 0))
|
||||
return (-1);
|
||||
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
op.cmd = DOM0_DESTROYDOMAIN;
|
||||
op.u.destroydomain.domain = (domid_t) domain->handle;
|
||||
|
||||
ret = xenHypervisorDoOp(domain->conn->handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
@ -301,8 +352,7 @@ xenHypervisorDestroyDomain(int handle, int domain)
|
||||
|
||||
/**
|
||||
* xenHypervisorSetMaxMemory:
|
||||
* @handle: the handle to the Xen hypervisor
|
||||
* @domain: the domain ID
|
||||
* @domain: pointer to the domain block
|
||||
* @memory: the max memory size in kilobytes.
|
||||
*
|
||||
* Do an hypervisor call to change the maximum amount of memory used
|
||||
@ -310,16 +360,20 @@ xenHypervisorDestroyDomain(int handle, int domain)
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorSetMaxMemory(int handle, int domain, unsigned long memory)
|
||||
xenHypervisorSetMaxMemory(virDomainPtr domain, unsigned long memory)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
if ((domain == NULL) || (domain->conn == NULL) ||
|
||||
(domain->conn->handle < 0))
|
||||
return (-1);
|
||||
|
||||
op.cmd = DOM0_SETDOMAINMAXMEM;
|
||||
op.u.setdomainmaxmem.domain = (domid_t) domain;
|
||||
op.u.setdomainmaxmem.domain = (domid_t) domain->handle;
|
||||
op.u.setdomainmaxmem.max_memkb = memory;
|
||||
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
ret = xenHypervisorDoOp(domain->conn->handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return (-1);
|
||||
|
@ -21,17 +21,19 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int xenHypervisorOpen(int quiet);
|
||||
int xenHypervisorClose(int handle);
|
||||
unsigned long xenHypervisorGetVersion(int handle);
|
||||
int xenHypervisorDestroyDomain(int handle, int domain);
|
||||
int xenHypervisorResumeDomain(int handle, int domain);
|
||||
int xenHypervisorPauseDomain(int handle, int domain);
|
||||
int xenHypervisorGetDomainInfo(int handle,
|
||||
int domain,
|
||||
dom0_getdomaininfo_t * info);
|
||||
int xenHypervisorSetMaxMemory(int handle,
|
||||
int domain, unsigned long memory);
|
||||
int xenHypervisorOpen (virConnectPtr conn,
|
||||
const char *name,
|
||||
int flags);
|
||||
int xenHypervisorClose (virConnectPtr conn);
|
||||
int xenHypervisorGetVersion (virConnectPtr conn,
|
||||
unsigned long *hvVer);
|
||||
int xenHypervisorDestroyDomain (virDomainPtr domain);
|
||||
int xenHypervisorResumeDomain (virDomainPtr domain);
|
||||
int xenHypervisorPauseDomain (virDomainPtr domain);
|
||||
int xenHypervisorGetDomainInfo (virDomainPtr domain,
|
||||
virDomainInfoPtr info);
|
||||
int xenHypervisorSetMaxMemory (virDomainPtr domain,
|
||||
unsigned long memory);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user