mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
* src/hash.c src/hash.h src/internal.h src/libvirt.c src/sexpr.c
src/sexpr.h src/virsh.c src/virterror.c src/xen_internal.c src/xen_internal.h src/xend_internal.c src/xend_internal.h src/xml.c src/xml.h: applied cb/indent to homogenize the source style, as a first pass. Daniel
This commit is contained in:
parent
cda69700a0
commit
247cf7a3b2
@ -1,3 +1,11 @@
|
||||
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
|
||||
src/sexpr.h src/virsh.c src/virterror.c src/xen_internal.c
|
||||
src/xen_internal.h src/xend_internal.c src/xend_internal.h
|
||||
src/xml.c src/xml.h: applied cb/indent to homogenize the source
|
||||
style, as a first pass.
|
||||
|
||||
Fri Mar 10 11:07:58 CET 2006 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
* configure.in: applied patch for --with-xen-distdir option from
|
||||
|
50
src/hash.c
50
src/hash.c
@ -53,14 +53,16 @@ struct _virHashTable {
|
||||
* Calculate the hash key
|
||||
*/
|
||||
static unsigned long
|
||||
virHashComputeKey(virHashTablePtr table, const char *name) {
|
||||
virHashComputeKey(virHashTablePtr table, const char *name)
|
||||
{
|
||||
unsigned long value = 0L;
|
||||
char ch;
|
||||
|
||||
if (name != NULL) {
|
||||
value += 30 * (*name);
|
||||
while ((ch = *name++) != 0) {
|
||||
value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
|
||||
value =
|
||||
value ^ ((value << 5) + (value >> 3) + (unsigned long) ch);
|
||||
}
|
||||
}
|
||||
return (value % table->size);
|
||||
@ -75,7 +77,8 @@ virHashComputeKey(virHashTablePtr table, const char *name) {
|
||||
* Returns the newly created object, or NULL if an error occured.
|
||||
*/
|
||||
virHashTablePtr
|
||||
virHashCreate(int size) {
|
||||
virHashCreate(int size)
|
||||
{
|
||||
virHashTablePtr table;
|
||||
|
||||
if (size <= 0)
|
||||
@ -105,11 +108,13 @@ virHashCreate(int size) {
|
||||
* Returns 0 in case of success, -1 in case of failure
|
||||
*/
|
||||
static int
|
||||
virHashGrow(virHashTablePtr table, int size) {
|
||||
virHashGrow(virHashTablePtr table, int size)
|
||||
{
|
||||
unsigned long key;
|
||||
int oldsize, i;
|
||||
virHashEntryPtr iter, next;
|
||||
struct _virHashEntry *oldtable;
|
||||
|
||||
#ifdef DEBUG_GROW
|
||||
unsigned long nbElem = 0;
|
||||
#endif
|
||||
@ -135,10 +140,10 @@ virHashGrow(virHashTablePtr table, int size) {
|
||||
table->size = size;
|
||||
|
||||
/* If the two loops are merged, there would be situations where
|
||||
a new entry needs to allocated and data copied into it from
|
||||
the main table. So instead, we run through the array twice, first
|
||||
copying all the elements in the main array (where we can't get
|
||||
conflicts) and then the rest, so we only free (and don't allocate)
|
||||
* a new entry needs to allocated and data copied into it from
|
||||
* the main table. So instead, we run through the array twice, first
|
||||
* copying all the elements in the main array (where we can't get
|
||||
* conflicts) and then the rest, so we only free (and don't allocate)
|
||||
*/
|
||||
for (i = 0; i < oldsize; i++) {
|
||||
if (oldtable[i].valid == 0)
|
||||
@ -179,7 +184,8 @@ virHashGrow(virHashTablePtr table, int size) {
|
||||
|
||||
#ifdef DEBUG_GROW
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"virHashGrow : from %d to %d, %d elems\n", oldsize, size, nbElem);
|
||||
"virHashGrow : from %d to %d, %d elems\n", oldsize,
|
||||
size, nbElem);
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -194,7 +200,8 @@ virHashGrow(virHashTablePtr table, int size) {
|
||||
* deallocated with @f if provided.
|
||||
*/
|
||||
void
|
||||
virHashFree(virHashTablePtr table, virHashDeallocator f) {
|
||||
virHashFree(virHashTablePtr table, virHashDeallocator f)
|
||||
{
|
||||
int i;
|
||||
virHashEntryPtr iter;
|
||||
virHashEntryPtr next;
|
||||
@ -242,8 +249,8 @@ virHashFree(virHashTablePtr table, virHashDeallocator f) {
|
||||
* Returns 0 the addition succeeded and -1 in case of error.
|
||||
*/
|
||||
int
|
||||
virHashAddEntry(virHashTablePtr table, const char *name,
|
||||
void *userdata) {
|
||||
virHashAddEntry(virHashTablePtr table, const char *name, void *userdata)
|
||||
{
|
||||
unsigned long key, len = 0;
|
||||
virHashEntryPtr entry;
|
||||
virHashEntryPtr insert;
|
||||
@ -308,7 +315,8 @@ virHashAddEntry(virHashTablePtr table, const char *name,
|
||||
*/
|
||||
int
|
||||
virHashUpdateEntry(virHashTablePtr table, const char *name,
|
||||
void *userdata, virHashDeallocator f) {
|
||||
void *userdata, virHashDeallocator f)
|
||||
{
|
||||
unsigned long key;
|
||||
virHashEntryPtr entry;
|
||||
virHashEntryPtr insert;
|
||||
@ -371,7 +379,8 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
|
||||
* Returns the a pointer to the userdata
|
||||
*/
|
||||
void *
|
||||
virHashLookup(virHashTablePtr table, const char *name) {
|
||||
virHashLookup(virHashTablePtr table, const char *name)
|
||||
{
|
||||
unsigned long key;
|
||||
virHashEntryPtr entry;
|
||||
|
||||
@ -399,7 +408,8 @@ virHashLookup(virHashTablePtr table, const char *name) {
|
||||
* -1 in case of error
|
||||
*/
|
||||
int
|
||||
virHashSize(virHashTablePtr table) {
|
||||
virHashSize(virHashTablePtr table)
|
||||
{
|
||||
if (table == NULL)
|
||||
return (-1);
|
||||
return (table->nbElems);
|
||||
@ -419,7 +429,8 @@ virHashSize(virHashTablePtr table) {
|
||||
*/
|
||||
int
|
||||
virHashRemoveEntry(virHashTablePtr table, const char *name,
|
||||
virHashDeallocator f) {
|
||||
virHashDeallocator f)
|
||||
{
|
||||
unsigned long key;
|
||||
virHashEntryPtr entry;
|
||||
virHashEntryPtr prev = NULL;
|
||||
@ -431,7 +442,8 @@ virHashRemoveEntry(virHashTablePtr table, const char *name,
|
||||
if (table->table[key].valid == 0) {
|
||||
return (-1);
|
||||
} else {
|
||||
for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
|
||||
for (entry = &(table->table[key]); entry != NULL;
|
||||
entry = entry->next) {
|
||||
if (!strcmp(entry->name, name)) {
|
||||
if ((f != NULL) && (entry->payload != NULL))
|
||||
f(entry->payload, entry->name);
|
||||
@ -446,7 +458,8 @@ virHashRemoveEntry(virHashTablePtr table, const char *name,
|
||||
entry->valid = 0;
|
||||
} else {
|
||||
entry = entry->next;
|
||||
memcpy(&(table->table[key]), entry, sizeof(virHashEntry));
|
||||
memcpy(&(table->table[key]), entry,
|
||||
sizeof(virHashEntry));
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
@ -458,4 +471,3 @@ virHashRemoveEntry(virHashTablePtr table, const char *name,
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
17
src/hash.h
17
src/hash.h
@ -24,6 +24,7 @@ typedef virHashTable *virHashTablePtr;
|
||||
/*
|
||||
* function types:
|
||||
*/
|
||||
|
||||
/**
|
||||
* virHashDeallocator:
|
||||
* @payload: the data in the hash
|
||||
@ -38,32 +39,28 @@ typedef void (*virHashDeallocator)(void *payload, char *name);
|
||||
*/
|
||||
virHashTablePtr virHashCreate(int size);
|
||||
void
|
||||
virHashFree (virHashTablePtr table,
|
||||
virHashDeallocator f);
|
||||
virHashFree(virHashTablePtr table, virHashDeallocator f);
|
||||
int virHashSize(virHashTablePtr table);
|
||||
|
||||
/*
|
||||
* Add a new entry to the hash table.
|
||||
*/
|
||||
int virHashAddEntry(virHashTablePtr table,
|
||||
const char *name,
|
||||
void *userdata);
|
||||
const char *name, void *userdata);
|
||||
int virHashUpdateEntry(virHashTablePtr table,
|
||||
const char *name,
|
||||
void *userdata,
|
||||
virHashDeallocator f);
|
||||
void *userdata, virHashDeallocator f);
|
||||
|
||||
/*
|
||||
* Remove an entry from the hash table.
|
||||
*/
|
||||
int virHashRemoveEntry(virHashTablePtr table,
|
||||
const char *name,
|
||||
virHashDeallocator f);
|
||||
const char *name, virHashDeallocator f);
|
||||
|
||||
/*
|
||||
* Retrieve the userdata.
|
||||
*/
|
||||
void * virHashLookup (virHashTablePtr table,
|
||||
const char *name);
|
||||
void *virHashLookup(virHashTablePtr table, const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -126,8 +126,7 @@ struct _virDomain {
|
||||
*/
|
||||
char *virDomainGetVM(virDomainPtr domain);
|
||||
char *virDomainGetVMInfo(virDomainPtr domain,
|
||||
const char *vm,
|
||||
const char *name);
|
||||
const char *vm, const char *name);
|
||||
|
||||
void __virRaiseError(virConnectPtr conn,
|
||||
virDomainPtr dom,
|
||||
@ -137,15 +136,10 @@ void __virRaiseError (virConnectPtr conn,
|
||||
const char *str1,
|
||||
const char *str2,
|
||||
const char *str3,
|
||||
int int1,
|
||||
int int2,
|
||||
const char *msg,
|
||||
...);
|
||||
const char * __virErrorMsg (virErrorNumber error,
|
||||
const char *info);
|
||||
int int1, int int2, const char *msg, ...);
|
||||
const char *__virErrorMsg(virErrorNumber error, const char *info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __VIR_INTERNAL_H__ */
|
||||
|
134
src/libvirt.c
134
src/libvirt.c
@ -42,7 +42,8 @@
|
||||
* Handle an error at the connection level
|
||||
*/
|
||||
static void
|
||||
virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info) {
|
||||
virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info)
|
||||
{
|
||||
const char *errmsg;
|
||||
|
||||
if (error == VIR_ERR_OK)
|
||||
@ -62,7 +63,9 @@ virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info) {
|
||||
* Handle an error at the connection level
|
||||
*/
|
||||
static void
|
||||
virLibDomainError(virDomainPtr domain, virErrorNumber error, const char *info) {
|
||||
virLibDomainError(virDomainPtr domain, virErrorNumber error,
|
||||
const char *info)
|
||||
{
|
||||
virConnectPtr conn = NULL;
|
||||
const char *errmsg;
|
||||
|
||||
@ -93,7 +96,9 @@ virLibDomainError(virDomainPtr domain, virErrorNumber error, const char *info) {
|
||||
* @typeVer have the format major * 1,000,000 + minor * 1,000 + release.
|
||||
*/
|
||||
int
|
||||
virGetVersion(unsigned long *libVer, const char *type, unsigned long *typeVer) {
|
||||
virGetVersion(unsigned long *libVer, const char *type,
|
||||
unsigned long *typeVer)
|
||||
{
|
||||
if (libVer == NULL)
|
||||
return (-1);
|
||||
*libVer = LIBVIR_VERSION_NUMBER;
|
||||
@ -129,7 +134,8 @@ virGetVersion(unsigned long *libVer, const char *type, unsigned long *typeVer) {
|
||||
* Returns a pointer to the hypervisor connection or NULL in case of error
|
||||
*/
|
||||
virConnectPtr
|
||||
virConnectOpen(const char *name) {
|
||||
virConnectOpen(const char *name)
|
||||
{
|
||||
virConnectPtr ret = NULL;
|
||||
int handle = -1;
|
||||
struct xs_handle *xshandle = NULL;
|
||||
@ -188,7 +194,8 @@ failed:
|
||||
* Returns a pointer to the hypervisor connection or NULL in case of error
|
||||
*/
|
||||
virConnectPtr
|
||||
virConnectOpenReadOnly(const char *name) {
|
||||
virConnectOpenReadOnly(const char *name)
|
||||
{
|
||||
int method = 0;
|
||||
int handle;
|
||||
virConnectPtr ret = NULL;
|
||||
@ -256,7 +263,8 @@ failed:
|
||||
* Returns -1 if the check failed, 0 if successful or not possible to check
|
||||
*/
|
||||
static int
|
||||
virConnectCheckStoreID(virConnectPtr conn, int id) {
|
||||
virConnectCheckStoreID(virConnectPtr conn, int id)
|
||||
{
|
||||
if (conn->handle >= 0) {
|
||||
dom0_getdomaininfo_t dominfo;
|
||||
int tmp;
|
||||
@ -278,7 +286,8 @@ virConnectCheckStoreID(virConnectPtr conn, int id) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
static int
|
||||
virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
|
||||
virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (virDomainFree(domain));
|
||||
}
|
||||
|
||||
@ -294,7 +303,8 @@ virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
|
||||
* Returns 0 in case of success or -1 in case of error.
|
||||
*/
|
||||
int
|
||||
virConnectClose(virConnectPtr conn) {
|
||||
virConnectClose(virConnectPtr conn)
|
||||
{
|
||||
xend_cleanup(conn);
|
||||
if (!VIR_IS_CONNECT(conn))
|
||||
return (-1);
|
||||
@ -319,9 +329,11 @@ virConnectClose(virConnectPtr conn) {
|
||||
* Returns NULL in case of error, a static zero terminated string otherwise.
|
||||
*/
|
||||
const char *
|
||||
virConnectGetType(virConnectPtr conn) {
|
||||
virConnectGetType(virConnectPtr conn)
|
||||
{
|
||||
if (!VIR_IS_CONNECT(conn)) {
|
||||
virLibConnError(conn, VIR_ERR_INVALID_CONN, "in virConnectGetType");
|
||||
virLibConnError(conn, VIR_ERR_INVALID_CONN,
|
||||
"in virConnectGetType");
|
||||
return (NULL);
|
||||
}
|
||||
return ("Xen");
|
||||
@ -341,7 +353,8 @@ virConnectGetType(virConnectPtr conn) {
|
||||
* @hvVer value is major * 1,000,000 + minor * 1,000 + release
|
||||
*/
|
||||
int
|
||||
virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) {
|
||||
virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
|
||||
{
|
||||
unsigned long ver;
|
||||
|
||||
if (!VIR_IS_CONNECT(conn)) {
|
||||
@ -376,7 +389,8 @@ virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) {
|
||||
* Returns the number of domain found or -1 in case of error
|
||||
*/
|
||||
int
|
||||
virConnectListDomains(virConnectPtr conn, int *ids, int maxids) {
|
||||
virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
|
||||
{
|
||||
int ret = -1;
|
||||
unsigned int num, i;
|
||||
long id;
|
||||
@ -434,7 +448,8 @@ done:
|
||||
* Returns the number of domain found or -1 in case of error
|
||||
*/
|
||||
int
|
||||
virConnectNumOfDomains(virConnectPtr conn) {
|
||||
virConnectNumOfDomains(virConnectPtr conn)
|
||||
{
|
||||
int ret = -1;
|
||||
unsigned int num;
|
||||
char **idlist = NULL;
|
||||
@ -482,7 +497,8 @@ virConnectNumOfDomains(virConnectPtr conn) {
|
||||
virDomainPtr
|
||||
virDomainCreateLinux(virConnectPtr conn,
|
||||
const char *xmlDesc,
|
||||
unsigned int flags ATTRIBUTE_UNUSED) {
|
||||
unsigned int flags ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int ret;
|
||||
char *sexpr;
|
||||
char *name = NULL;
|
||||
@ -549,7 +565,9 @@ error:
|
||||
* Returns a string which must be freed by the caller or NULL in case of error
|
||||
*/
|
||||
static char **
|
||||
virConnectDoStoreList(virConnectPtr conn, const char *path, unsigned int *nb) {
|
||||
virConnectDoStoreList(virConnectPtr conn, const char *path,
|
||||
unsigned int *nb)
|
||||
{
|
||||
if ((conn == NULL) || (conn->xshandle == NULL) || (path == NULL) ||
|
||||
(nb == NULL))
|
||||
return (NULL);
|
||||
@ -567,7 +585,8 @@ virConnectDoStoreList(virConnectPtr conn, const char *path, unsigned int *nb) {
|
||||
* Returns a string which must be freed by the caller or NULL in case of error
|
||||
*/
|
||||
static char *
|
||||
virDomainDoStoreQuery(virDomainPtr domain, const char *path) {
|
||||
virDomainDoStoreQuery(virDomainPtr domain, const char *path)
|
||||
{
|
||||
char s[256];
|
||||
unsigned int len = 0;
|
||||
|
||||
@ -595,7 +614,8 @@ virDomainDoStoreQuery(virDomainPtr domain, const char *path) {
|
||||
*/
|
||||
static int
|
||||
virDomainDoStoreWrite(virDomainPtr domain, const char *path,
|
||||
const char *value) {
|
||||
const char *value)
|
||||
{
|
||||
char s[256];
|
||||
|
||||
int ret = -1;
|
||||
@ -636,8 +656,7 @@ virDomainGetVM(virDomainPtr domain)
|
||||
if (domain->conn->xshandle == NULL)
|
||||
return (NULL);
|
||||
|
||||
snprintf(query, 199, "/local/domain/%d/vm",
|
||||
virDomainGetID(domain));
|
||||
snprintf(query, 199, "/local/domain/%d/vm", virDomainGetID(domain));
|
||||
query[199] = 0;
|
||||
|
||||
vm = xs_read(domain->conn->xshandle, 0, &query[0], &len);
|
||||
@ -657,8 +676,8 @@ virDomainGetVM(virDomainPtr domain)
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
char *
|
||||
virDomainGetVMInfo(virDomainPtr domain, const char *vm,
|
||||
const char *name) {
|
||||
virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name)
|
||||
{
|
||||
char s[256];
|
||||
char *ret = NULL;
|
||||
unsigned int len = 0;
|
||||
@ -686,7 +705,8 @@ virDomainGetVMInfo(virDomainPtr domain, const char *vm,
|
||||
* Returns a new domain object or NULL in case of failure
|
||||
*/
|
||||
virDomainPtr
|
||||
virDomainLookupByID(virConnectPtr conn, int id) {
|
||||
virDomainLookupByID(virConnectPtr conn, int id)
|
||||
{
|
||||
char *path = NULL;
|
||||
virDomainPtr ret;
|
||||
char *name = NULL;
|
||||
@ -764,7 +784,8 @@ error:
|
||||
* Returns a new domain object or NULL in case of failure
|
||||
*/
|
||||
virDomainPtr
|
||||
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) {
|
||||
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
||||
{
|
||||
virDomainPtr ret;
|
||||
char *name = NULL;
|
||||
char **names;
|
||||
@ -829,7 +850,8 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) {
|
||||
* Returns a new domain object or NULL in case of failure
|
||||
*/
|
||||
virDomainPtr
|
||||
virDomainLookupByName(virConnectPtr conn, const char *name) {
|
||||
virDomainLookupByName(virConnectPtr conn, const char *name)
|
||||
{
|
||||
virDomainPtr ret = NULL;
|
||||
unsigned int num, i, len;
|
||||
long id = -1;
|
||||
@ -921,7 +943,8 @@ done:
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainDestroy(virDomainPtr domain) {
|
||||
virDomainDestroy(virDomainPtr domain)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
@ -956,7 +979,8 @@ virDomainDestroy(virDomainPtr domain) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainFree(virDomainPtr domain) {
|
||||
virDomainFree(virDomainPtr domain)
|
||||
{
|
||||
if (!VIR_IS_DOMAIN(domain)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
return (-1);
|
||||
@ -984,7 +1008,8 @@ virDomainFree(virDomainPtr domain) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainSuspend(virDomainPtr domain) {
|
||||
virDomainSuspend(virDomainPtr domain)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
@ -998,7 +1023,8 @@ virDomainSuspend(virDomainPtr domain) {
|
||||
return (0);
|
||||
|
||||
/* then try a direct hypervisor access */
|
||||
return(xenHypervisorPauseDomain(domain->conn->handle, domain->handle));
|
||||
return (xenHypervisorPauseDomain
|
||||
(domain->conn->handle, domain->handle));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1012,7 +1038,8 @@ virDomainSuspend(virDomainPtr domain) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainResume(virDomainPtr domain) {
|
||||
virDomainResume(virDomainPtr domain)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
@ -1026,7 +1053,8 @@ virDomainResume(virDomainPtr domain) {
|
||||
return (0);
|
||||
|
||||
/* then try a direct hypervisor access */
|
||||
return(xenHypervisorResumeDomain(domain->conn->handle, domain->handle));
|
||||
return (xenHypervisorResumeDomain
|
||||
(domain->conn->handle, domain->handle));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1042,7 +1070,8 @@ virDomainResume(virDomainPtr domain) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainSave(virDomainPtr domain, const char *to) {
|
||||
virDomainSave(virDomainPtr domain, const char *to)
|
||||
{
|
||||
int ret;
|
||||
char filepath[4096];
|
||||
|
||||
@ -1089,7 +1118,8 @@ virDomainSave(virDomainPtr domain, const char *to) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainRestore(virConnectPtr conn, const char *from) {
|
||||
virDomainRestore(virConnectPtr conn, const char *from)
|
||||
{
|
||||
int ret;
|
||||
char filepath[4096];
|
||||
|
||||
@ -1139,7 +1169,8 @@ virDomainRestore(virConnectPtr conn, const char *from) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainShutdown(virDomainPtr domain) {
|
||||
virDomainShutdown(virDomainPtr domain)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
@ -1175,7 +1206,8 @@ virDomainShutdown(virDomainPtr domain) {
|
||||
* its lifetime will be the same as the domain object.
|
||||
*/
|
||||
const char *
|
||||
virDomainGetName(virDomainPtr domain) {
|
||||
virDomainGetName(virDomainPtr domain)
|
||||
{
|
||||
if (!VIR_IS_DOMAIN(domain)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
return (NULL);
|
||||
@ -1193,7 +1225,8 @@ virDomainGetName(virDomainPtr domain) {
|
||||
* Returns -1 in case of error, 0 in case of success
|
||||
*/
|
||||
int
|
||||
virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) {
|
||||
virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
|
||||
{
|
||||
if (!VIR_IS_DOMAIN(domain)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
return (-1);
|
||||
@ -1214,7 +1247,8 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) {
|
||||
(domain->uuid[10] == 0) && (domain->uuid[11] == 0) &&
|
||||
(domain->uuid[12] == 0) && (domain->uuid[13] == 0) &&
|
||||
(domain->uuid[14] == 0) && (domain->uuid[15] == 0))
|
||||
xend_get_domain_ids(domain->conn, domain->name, &domain->uuid[0]);
|
||||
xend_get_domain_ids(domain->conn, domain->name,
|
||||
&domain->uuid[0]);
|
||||
memcpy(uuid, &domain->uuid[0], 16);
|
||||
}
|
||||
return (0);
|
||||
@ -1229,7 +1263,8 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) {
|
||||
* Returns the domain ID number or (unsigned int) -1 in case of error
|
||||
*/
|
||||
unsigned int
|
||||
virDomainGetID(virDomainPtr domain) {
|
||||
virDomainGetID(virDomainPtr domain)
|
||||
{
|
||||
if (!VIR_IS_DOMAIN(domain)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
return ((unsigned int) -1);
|
||||
@ -1246,7 +1281,8 @@ virDomainGetID(virDomainPtr domain) {
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
char *
|
||||
virDomainGetOSType(virDomainPtr domain) {
|
||||
virDomainGetOSType(virDomainPtr domain)
|
||||
{
|
||||
char *vm, *str = NULL;
|
||||
|
||||
if (!VIR_IS_DOMAIN(domain)) {
|
||||
@ -1276,7 +1312,8 @@ virDomainGetOSType(virDomainPtr domain) {
|
||||
* Returns the memory size in kilobytes or 0 in case of error.
|
||||
*/
|
||||
unsigned long
|
||||
virDomainGetMaxMemory(virDomainPtr domain) {
|
||||
virDomainGetMaxMemory(virDomainPtr domain)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
|
||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||
@ -1297,8 +1334,9 @@ virDomainGetMaxMemory(virDomainPtr domain) {
|
||||
int tmp;
|
||||
|
||||
dominfo.domain = domain->handle;
|
||||
tmp = xenHypervisorGetDomainInfo(domain->conn->handle, domain->handle,
|
||||
&dominfo);
|
||||
tmp =
|
||||
xenHypervisorGetDomainInfo(domain->conn->handle,
|
||||
domain->handle, &dominfo);
|
||||
if (tmp >= 0)
|
||||
ret = dominfo.max_pages * 4;
|
||||
}
|
||||
@ -1318,7 +1356,8 @@ virDomainGetMaxMemory(virDomainPtr domain) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
|
||||
virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
|
||||
{
|
||||
int ret;
|
||||
char s[256], v[30];
|
||||
|
||||
@ -1367,7 +1406,8 @@ virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
|
||||
virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
|
||||
{
|
||||
int ret;
|
||||
char *tmp, **tmp2;
|
||||
unsigned int nb_vcpus;
|
||||
@ -1392,8 +1432,9 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
|
||||
dom0_getdomaininfo_t dominfo;
|
||||
|
||||
dominfo.domain = domain->handle;
|
||||
ret = xenHypervisorGetDomainInfo(domain->conn->handle, domain->handle,
|
||||
&dominfo);
|
||||
ret =
|
||||
xenHypervisorGetDomainInfo(domain->conn->handle,
|
||||
domain->handle, &dominfo);
|
||||
if (ret < 0)
|
||||
goto xend_info;
|
||||
|
||||
@ -1489,7 +1530,8 @@ xend_info:
|
||||
* the caller must free() the returned value.
|
||||
*/
|
||||
char *
|
||||
virDomainGetXMLDesc(virDomainPtr domain, int flags) {
|
||||
virDomainGetXMLDesc(virDomainPtr domain, int flags)
|
||||
{
|
||||
if (!VIR_IS_DOMAIN(domain)) {
|
||||
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||
return (NULL);
|
||||
|
12
src/sexpr.c
12
src/sexpr.c
@ -30,7 +30,8 @@
|
||||
* Handle an error in the S-Expression code
|
||||
*/
|
||||
static void
|
||||
virSexprError(virErrorNumber error, const char *info) {
|
||||
virSexprError(virErrorNumber error, const char *info)
|
||||
{
|
||||
const char *errmsg;
|
||||
|
||||
if (error == VIR_ERR_OK)
|
||||
@ -237,7 +238,8 @@ sexpr2string(struct sexpr * sexpr, char *buffer, size_t n_buffer)
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
tmp = sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
|
||||
tmp =
|
||||
sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
@ -346,7 +348,8 @@ _string2sexpr(const char *buffer, size_t * end)
|
||||
|
||||
ret->value = strndup(start, ptr - start);
|
||||
if (ret->value == NULL) {
|
||||
virSexprError(VIR_ERR_NO_MEMORY, "failed to copy a string");
|
||||
virSexprError(VIR_ERR_NO_MEMORY,
|
||||
"failed to copy a string");
|
||||
}
|
||||
|
||||
if (*ptr == '\'')
|
||||
@ -360,7 +363,8 @@ _string2sexpr(const char *buffer, size_t * end)
|
||||
|
||||
ret->value = strndup(start, ptr - start);
|
||||
if (ret->value == NULL) {
|
||||
virSexprError(VIR_ERR_NO_MEMORY, "failed to copy a string");
|
||||
virSexprError(VIR_ERR_NO_MEMORY,
|
||||
"failed to copy a string");
|
||||
}
|
||||
}
|
||||
|
||||
|
19
src/sexpr.h
19
src/sexpr.h
@ -33,24 +33,17 @@ struct sexpr {
|
||||
};
|
||||
|
||||
/* conversion to/from strings */
|
||||
size_t sexpr2string (struct sexpr *sexpr,
|
||||
char *buffer,
|
||||
size_t n_buffer);
|
||||
size_t sexpr2string(struct sexpr *sexpr, char *buffer, size_t n_buffer);
|
||||
struct sexpr *string2sexpr(const char *buffer);
|
||||
|
||||
/* constructors and destructors */
|
||||
struct sexpr *sexpr_nil(void);
|
||||
struct sexpr * sexpr_string (const char *str,
|
||||
ssize_t len);
|
||||
struct sexpr * sexpr_cons (struct sexpr *car,
|
||||
struct sexpr *cdr);
|
||||
struct sexpr * sexpr_append (struct sexpr *lst,
|
||||
struct sexpr *item);
|
||||
struct sexpr *sexpr_string(const char *str, ssize_t len);
|
||||
struct sexpr *sexpr_cons(struct sexpr *car, struct sexpr *cdr);
|
||||
struct sexpr *sexpr_append(struct sexpr *lst, struct sexpr *item);
|
||||
void sexpr_free(struct sexpr *sexpr);
|
||||
|
||||
/* lookup in S-Expressions */
|
||||
const char * sexpr_node (struct sexpr *sexpr,
|
||||
const char *node);
|
||||
struct sexpr * sexpr_lookup (struct sexpr *sexpr,
|
||||
const char *node);
|
||||
const char *sexpr_node(struct sexpr *sexpr, const char *node);
|
||||
struct sexpr *sexpr_lookup(struct sexpr *sexpr, const char *node);
|
||||
#endif
|
||||
|
242
src/virsh.c
242
src/virsh.c
@ -61,7 +61,8 @@ typedef enum {
|
||||
* The error handler for virtsh
|
||||
*/
|
||||
static void
|
||||
virshErrorHandler(void *unused, virErrorPtr error) {
|
||||
virshErrorHandler(void *unused, virErrorPtr error)
|
||||
{
|
||||
if ((unused != NULL) || (error == NULL))
|
||||
return;
|
||||
|
||||
@ -176,7 +177,8 @@ typedef struct __vshControl {
|
||||
|
||||
static vshCmdDef commands[];
|
||||
|
||||
static void vshError(vshControl *ctl, int doexit, const char *format, ...);
|
||||
static void vshError(vshControl * ctl, int doexit, const char *format,
|
||||
...);
|
||||
static int vshInit(vshControl * ctl);
|
||||
static int vshDeinit(vshControl * ctl);
|
||||
static void vshUsage(vshControl * ctl, const char *cmdname);
|
||||
@ -189,16 +191,20 @@ static int vshCmddefHelp(vshControl *ctl, const char *name, int withprog);
|
||||
|
||||
static vshCmdOpt *vshCommandOpt(vshCmd * cmd, const char *name);
|
||||
static int vshCommandOptInt(vshCmd * cmd, const char *name, int *found);
|
||||
static char *vshCommandOptString(vshCmd *cmd, const char *name, int *found);
|
||||
static char *vshCommandOptString(vshCmd * cmd, const char *name,
|
||||
int *found);
|
||||
static int vshCommandOptBool(vshCmd * cmd, const char *name);
|
||||
static virDomainPtr vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **name);
|
||||
static virDomainPtr vshCommandOptDomain(vshControl * ctl, vshCmd * cmd,
|
||||
const char *optname, char **name);
|
||||
|
||||
|
||||
static void vshPrint(vshControl *ctl, vshOutType out, const char *format, ...);
|
||||
static void vshPrint(vshControl * ctl, vshOutType out, const char *format,
|
||||
...);
|
||||
|
||||
|
||||
static const char *vshDomainStateToString(int state);
|
||||
static int vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror);
|
||||
static int vshConnectionUsability(vshControl * ctl, virConnectPtr conn,
|
||||
int showerror);
|
||||
|
||||
/* ---------------
|
||||
* Commands
|
||||
@ -222,7 +228,8 @@ static vshCmdOptDef opts_help[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdHelp(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdHelp(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
const char *cmdname = vshCommandOptString(cmd, "command", NULL);
|
||||
|
||||
if (!cmdname) {
|
||||
@ -243,7 +250,8 @@ cmdHelp(vshControl *ctl, vshCmd *cmd) {
|
||||
static vshCmdInfo info_connect[] = {
|
||||
{"syntax", "connect [--readonly]"},
|
||||
{"help", "(re)connect to hypervisor"},
|
||||
{ "desc", "Connect to local hypervisor. This is build-in command after shell start up." },
|
||||
{"desc",
|
||||
"Connect to local hypervisor. This is build-in command after shell start up."},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -253,12 +261,14 @@ static vshCmdOptDef opts_connect[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdConnect(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdConnect(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
int ro = vshCommandOptBool(cmd, "readonly");
|
||||
|
||||
if (ctl->conn) {
|
||||
if (virConnectClose(ctl->conn) != 0) {
|
||||
vshError(ctl, FALSE, "failed to disconnect from the hypervisor");
|
||||
vshError(ctl, FALSE,
|
||||
"failed to disconnect from the hypervisor");
|
||||
return FALSE;
|
||||
}
|
||||
ctl->conn = NULL;
|
||||
@ -287,7 +297,8 @@ static vshCmdInfo info_list[] = {
|
||||
|
||||
|
||||
static int
|
||||
cmdList(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
|
||||
cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int *ids, maxid, i;
|
||||
|
||||
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
||||
@ -318,7 +329,8 @@ cmdList(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
|
||||
vshPrint(ctl, VSH_MESG, "%3d %-20s %s\n",
|
||||
virDomainGetID(dom),
|
||||
virDomainGetName(dom),
|
||||
ret < 0 ? "no state" : vshDomainStateToString(info.state));
|
||||
ret <
|
||||
0 ? "no state" : vshDomainStateToString(info.state));
|
||||
virDomainFree(dom);
|
||||
}
|
||||
free(ids);
|
||||
@ -341,7 +353,8 @@ static vshCmdOptDef opts_dstate[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdDstate(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdDstate(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainInfo info;
|
||||
virDomainPtr dom;
|
||||
int ret = TRUE;
|
||||
@ -353,7 +366,8 @@ cmdDstate(vshControl *ctl, vshCmd *cmd) {
|
||||
return FALSE;
|
||||
|
||||
if (virDomainGetInfo(dom, &info) == 0)
|
||||
vshPrint(ctl, VSH_MESG, "%s\n", vshDomainStateToString(info.state));
|
||||
vshPrint(ctl, VSH_MESG, "%s\n",
|
||||
vshDomainStateToString(info.state));
|
||||
else
|
||||
ret = FALSE;
|
||||
|
||||
@ -377,7 +391,8 @@ static vshCmdOptDef opts_suspend[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdSuspend(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdSuspend(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
char *name;
|
||||
int ret = TRUE;
|
||||
@ -416,7 +431,8 @@ static vshCmdOptDef opts_save[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdSave(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdSave(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
char *name;
|
||||
char *to;
|
||||
@ -458,7 +474,8 @@ static vshCmdOptDef opts_restore[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdRestore(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdRestore(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
char *from;
|
||||
int found;
|
||||
int ret = TRUE;
|
||||
@ -495,7 +512,8 @@ static vshCmdOptDef opts_resume[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdResume(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdResume(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
int ret = TRUE;
|
||||
char *name;
|
||||
@ -533,7 +551,8 @@ static vshCmdOptDef opts_shutdown[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdShutdown(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdShutdown(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
int ret = TRUE;
|
||||
char *name;
|
||||
@ -571,7 +590,8 @@ static vshCmdOptDef opts_destroy[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdDestroy(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdDestroy(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
int ret = TRUE;
|
||||
char *name;
|
||||
@ -609,7 +629,8 @@ static vshCmdOptDef opts_dinfo[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdDinfo(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdDinfo(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainInfo info;
|
||||
virDomainPtr dom;
|
||||
int ret = TRUE;
|
||||
@ -621,10 +642,8 @@ cmdDinfo(vshControl *ctl, vshCmd *cmd) {
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
|
||||
return FALSE;
|
||||
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:",
|
||||
virDomainGetID(dom));
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:",
|
||||
virDomainGetName(dom));
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:", virDomainGetID(dom));
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:", virDomainGetName(dom));
|
||||
|
||||
if ((str = virDomainGetOSType(dom))) {
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "OS Type:", str);
|
||||
@ -635,12 +654,11 @@ cmdDinfo(vshControl *ctl, vshCmd *cmd) {
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "State:",
|
||||
vshDomainStateToString(info.state));
|
||||
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):",
|
||||
info.nrVirtCpu);
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):", info.nrVirtCpu);
|
||||
|
||||
if (info.cpuTime != 0)
|
||||
{
|
||||
if (info.cpuTime != 0) {
|
||||
float cpuUsed = info.cpuTime;
|
||||
|
||||
cpuUsed /= 1000000000;
|
||||
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %.1fs\n", "CPU time:", cpuUsed);
|
||||
@ -675,7 +693,8 @@ static vshCmdOptDef opts_dumpxml[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdDumpXML(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdDumpXML(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
int ret = TRUE;
|
||||
char *dump;
|
||||
@ -713,7 +732,8 @@ static vshCmdOptDef opts_nameof[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdNameof(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdNameof(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
int found;
|
||||
int id = vshCommandOptInt(cmd, "id", &found);
|
||||
virDomainPtr dom;
|
||||
@ -749,7 +769,8 @@ static vshCmdOptDef opts_idof[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdIdof(vshControl *ctl, vshCmd *cmd) {
|
||||
cmdIdof(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
char *name = vshCommandOptString(cmd, "name", NULL);
|
||||
virDomainPtr dom;
|
||||
|
||||
@ -781,7 +802,8 @@ static vshCmdInfo info_version[] = {
|
||||
|
||||
|
||||
static int
|
||||
cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
|
||||
cmdVersion(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
||||
{
|
||||
unsigned long hvVersion;
|
||||
const char *hvType;
|
||||
unsigned long libVersion;
|
||||
@ -835,16 +857,15 @@ cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
|
||||
}
|
||||
if (hvVersion == 0) {
|
||||
vshPrint(ctl, VSH_MESG,
|
||||
"cannot extract running %s hypervisor version\n",
|
||||
hvType);
|
||||
"cannot extract running %s hypervisor version\n", hvType);
|
||||
} else {
|
||||
major = hvVersion / 1000000;
|
||||
hvVersion %= 1000000;
|
||||
minor = hvVersion / 1000;
|
||||
rel = hvVersion % 1000;
|
||||
|
||||
vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n", hvType,
|
||||
major, minor, rel);
|
||||
vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n",
|
||||
hvType, major, minor, rel);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@ -859,7 +880,8 @@ static vshCmdInfo info_quit[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
cmdQuit(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
|
||||
cmdQuit(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
||||
{
|
||||
ctl->imode = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
@ -892,7 +914,8 @@ static vshCmdDef commands[] = {
|
||||
* ---------------
|
||||
*/
|
||||
static const char *
|
||||
vshCmddefGetInfo(vshCmdDef *cmd, const char *name) {
|
||||
vshCmddefGetInfo(vshCmdDef * cmd, const char *name)
|
||||
{
|
||||
vshCmdInfo *info;
|
||||
|
||||
for (info = cmd->info; info && info->name; info++) {
|
||||
@ -903,7 +926,8 @@ vshCmddefGetInfo(vshCmdDef *cmd, const char *name) {
|
||||
}
|
||||
|
||||
static vshCmdOptDef *
|
||||
vshCmddefGetOption(vshCmdDef *cmd, const char *name) {
|
||||
vshCmddefGetOption(vshCmdDef * cmd, const char *name)
|
||||
{
|
||||
vshCmdOptDef *opt;
|
||||
|
||||
for (opt = cmd->opts; opt && opt->name; opt++)
|
||||
@ -913,7 +937,8 @@ vshCmddefGetOption(vshCmdDef *cmd, const char *name) {
|
||||
}
|
||||
|
||||
static vshCmdOptDef *
|
||||
vshCmddefGetData(vshCmdDef *cmd, int data_ct) {
|
||||
vshCmddefGetData(vshCmdDef * cmd, int data_ct)
|
||||
{
|
||||
vshCmdOptDef *opt;
|
||||
|
||||
for (opt = cmd->opts; opt && opt->name; opt++) {
|
||||
@ -962,7 +987,8 @@ vshCommandCheckOpts(vshControl *ctl, vshCmd *cmd)
|
||||
}
|
||||
|
||||
static vshCmdDef *
|
||||
vshCmddefSearch(const char *cmdname) {
|
||||
vshCmddefSearch(const char *cmdname)
|
||||
{
|
||||
vshCmdDef *c;
|
||||
|
||||
for (c = commands; c->name; c++)
|
||||
@ -972,7 +998,8 @@ vshCmddefSearch(const char *cmdname) {
|
||||
}
|
||||
|
||||
static int
|
||||
vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog) {
|
||||
vshCmddefHelp(vshControl * ctl, const char *cmdname, int withprog)
|
||||
{
|
||||
vshCmdDef *def = vshCmddefSearch(cmdname);
|
||||
|
||||
if (!def) {
|
||||
@ -1025,11 +1052,13 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog) {
|
||||
* ---------------
|
||||
*/
|
||||
static void
|
||||
vshCommandOptFree(vshCmdOpt *arg) {
|
||||
vshCommandOptFree(vshCmdOpt * arg)
|
||||
{
|
||||
vshCmdOpt *a = arg;
|
||||
|
||||
while (a) {
|
||||
vshCmdOpt *tmp = a;
|
||||
|
||||
a = a->next;
|
||||
|
||||
if (tmp->data)
|
||||
@ -1039,11 +1068,13 @@ vshCommandOptFree(vshCmdOpt *arg) {
|
||||
}
|
||||
|
||||
static void
|
||||
vshCommandFree(vshCmd *cmd) {
|
||||
vshCommandFree(vshCmd * cmd)
|
||||
{
|
||||
vshCmd *c = cmd;
|
||||
|
||||
while (c) {
|
||||
vshCmd *tmp = c;
|
||||
|
||||
c = c->next;
|
||||
|
||||
if (tmp->opts)
|
||||
@ -1056,7 +1087,8 @@ vshCommandFree(vshCmd *cmd) {
|
||||
* Returns option by name
|
||||
*/
|
||||
static vshCmdOpt *
|
||||
vshCommandOpt(vshCmd *cmd, const char *name) {
|
||||
vshCommandOpt(vshCmd * cmd, const char *name)
|
||||
{
|
||||
vshCmdOpt *opt = cmd->opts;
|
||||
|
||||
while (opt) {
|
||||
@ -1071,7 +1103,8 @@ vshCommandOpt(vshCmd *cmd, const char *name) {
|
||||
* Returns option as INT
|
||||
*/
|
||||
static int
|
||||
vshCommandOptInt(vshCmd *cmd, const char *name, int *found) {
|
||||
vshCommandOptInt(vshCmd * cmd, const char *name, int *found)
|
||||
{
|
||||
vshCmdOpt *arg = vshCommandOpt(cmd, name);
|
||||
int res = 0;
|
||||
|
||||
@ -1086,8 +1119,10 @@ vshCommandOptInt(vshCmd *cmd, const char *name, int *found) {
|
||||
* Returns option as STRING
|
||||
*/
|
||||
static char *
|
||||
vshCommandOptString(vshCmd *cmd, const char *name, int *found) {
|
||||
vshCommandOptString(vshCmd * cmd, const char *name, int *found)
|
||||
{
|
||||
vshCmdOpt *arg = vshCommandOpt(cmd, name);
|
||||
|
||||
if (found)
|
||||
*found = arg ? TRUE : FALSE;
|
||||
|
||||
@ -1098,13 +1133,16 @@ vshCommandOptString(vshCmd *cmd, const char *name, int *found) {
|
||||
* Returns TRUE/FALSE if the option exists
|
||||
*/
|
||||
static int
|
||||
vshCommandOptBool(vshCmd *cmd, const char *name) {
|
||||
vshCommandOptBool(vshCmd * cmd, const char *name)
|
||||
{
|
||||
return vshCommandOpt(cmd, name) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
static virDomainPtr
|
||||
vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **name) {
|
||||
vshCommandOptDomain(vshControl * ctl, vshCmd * cmd, const char *optname,
|
||||
char **name)
|
||||
{
|
||||
virDomainPtr dom = NULL;
|
||||
char *n, *end = NULL;
|
||||
int id;
|
||||
@ -1114,7 +1152,8 @@ vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **na
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vshPrint(ctl, VSH_DEBUG5, "%s: found option <%s>: %s\n", cmd->def->name, optname, n);
|
||||
vshPrint(ctl, VSH_DEBUG5, "%s: found option <%s>: %s\n",
|
||||
cmd->def->name, optname, n);
|
||||
|
||||
if (name)
|
||||
*name = n;
|
||||
@ -1122,13 +1161,15 @@ vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **na
|
||||
/* try it by ID */
|
||||
id = (int) strtol(n, &end, 10);
|
||||
if (id >= 0 && end && *end == '\0') {
|
||||
vshPrint(ctl, VSH_DEBUG5, "%s: <%s> seems like domain ID\n", cmd->def->name, optname);
|
||||
vshPrint(ctl, VSH_DEBUG5, "%s: <%s> seems like domain ID\n",
|
||||
cmd->def->name, optname);
|
||||
dom = virDomainLookupByID(ctl->conn, id);
|
||||
}
|
||||
|
||||
/* try it by NAME */
|
||||
if (!dom) {
|
||||
vshPrint(ctl, VSH_DEBUG5, "%s: <%s> tring as domain NAME\n", cmd->def->name, optname);
|
||||
vshPrint(ctl, VSH_DEBUG5, "%s: <%s> tring as domain NAME\n",
|
||||
cmd->def->name, optname);
|
||||
dom = virDomainLookupByName(ctl->conn, n);
|
||||
}
|
||||
if (!dom)
|
||||
@ -1141,7 +1182,8 @@ vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **na
|
||||
* Executes command(s) and returns return code from last command
|
||||
*/
|
||||
static int
|
||||
vshCommandRun(vshControl *ctl, vshCmd *cmd) {
|
||||
vshCommandRun(vshControl * ctl, vshCmd * cmd)
|
||||
{
|
||||
int ret = TRUE;
|
||||
|
||||
while (cmd) {
|
||||
@ -1159,7 +1201,8 @@ vshCommandRun(vshControl *ctl, vshCmd *cmd) {
|
||||
return ret;
|
||||
|
||||
if (ctl->timing)
|
||||
vshPrint(ctl, VSH_MESG, "\n(Time: %.3f ms)\n\n", DIFF_MSEC(&after, &before));
|
||||
vshPrint(ctl, VSH_MESG, "\n(Time: %.3f ms)\n\n",
|
||||
DIFF_MSEC(&after, &before));
|
||||
else
|
||||
vshPrint(ctl, VSH_FOOTER, "\n");
|
||||
cmd = cmd->next;
|
||||
@ -1178,7 +1221,8 @@ vshCommandRun(vshControl *ctl, vshCmd *cmd) {
|
||||
#define VSH_TK_END 3
|
||||
|
||||
static int
|
||||
vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res) {
|
||||
vshCommandGetToken(vshControl * ctl, char *str, char **end, char **res)
|
||||
{
|
||||
int tk = VSH_TK_NONE;
|
||||
int quote = FALSE;
|
||||
int sz = 0;
|
||||
@ -1208,7 +1252,8 @@ vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res) {
|
||||
}
|
||||
|
||||
if (tk == VSH_TK_NONE) {
|
||||
if (*p=='-' && *(p+1)=='-' && *(p+2) && isalnum((unsigned char) *(p+2))) {
|
||||
if (*p == '-' && *(p + 1) == '-' && *(p + 2)
|
||||
&& isalnum((unsigned char) *(p + 2))) {
|
||||
tk = VSH_TK_OPTION;
|
||||
p += 2;
|
||||
} else {
|
||||
@ -1247,7 +1292,8 @@ vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res) {
|
||||
}
|
||||
|
||||
static int
|
||||
vshCommandParse(vshControl *ctl, char *cmdstr) {
|
||||
vshCommandParse(vshControl * ctl, char *cmdstr)
|
||||
{
|
||||
char *str;
|
||||
char *tkdata = NULL;
|
||||
vshCmd *clast = NULL;
|
||||
@ -1262,8 +1308,7 @@ vshCommandParse(vshControl *ctl, char *cmdstr) {
|
||||
return FALSE;
|
||||
|
||||
str = cmdstr;
|
||||
while(str && *str)
|
||||
{
|
||||
while (str && *str) {
|
||||
vshCmdOpt *last = NULL;
|
||||
vshCmdDef *cmd = NULL;
|
||||
int tk = VSH_TK_NONE;
|
||||
@ -1296,8 +1341,7 @@ vshCommandParse(vshControl *ctl, char *cmdstr) {
|
||||
goto syntaxError;
|
||||
}
|
||||
if (!(cmd = vshCmddefSearch(tkdata))) {
|
||||
vshError(ctl, FALSE,
|
||||
"unknown command: '%s'", tkdata);
|
||||
vshError(ctl, FALSE, "unknown command: '%s'", tkdata);
|
||||
goto syntaxError; /* ... or ignore this command only? */
|
||||
}
|
||||
free(tkdata);
|
||||
@ -1321,15 +1365,14 @@ vshCommandParse(vshControl *ctl, char *cmdstr) {
|
||||
vshError(ctl, FALSE,
|
||||
"expected syntax: --%s <%s>",
|
||||
opt->name,
|
||||
opt->type==VSH_OT_INT ? "number" : "string");
|
||||
opt->type ==
|
||||
VSH_OT_INT ? "number" : "string");
|
||||
goto syntaxError;
|
||||
}
|
||||
}
|
||||
} else if (tk == VSH_TK_DATA) {
|
||||
if (!(opt = vshCmddefGetData(cmd, data_ct++))) {
|
||||
vshError(ctl, FALSE,
|
||||
"unexpected data '%s'",
|
||||
tkdata);
|
||||
vshError(ctl, FALSE, "unexpected data '%s'", tkdata);
|
||||
goto syntaxError;
|
||||
}
|
||||
}
|
||||
@ -1361,6 +1404,7 @@ vshCommandParse(vshControl *ctl, char *cmdstr) {
|
||||
/* commad parsed -- allocate new struct for the command */
|
||||
if (cmd) {
|
||||
vshCmd *c = malloc(sizeof(vshCmd));
|
||||
|
||||
c->opts = first;
|
||||
c->def = cmd;
|
||||
c->next = NULL;
|
||||
@ -1394,7 +1438,8 @@ syntaxError:
|
||||
* ---------------
|
||||
*/
|
||||
static const char *
|
||||
vshDomainStateToString(int state) {
|
||||
vshDomainStateToString(int state)
|
||||
{
|
||||
switch (state) {
|
||||
case VIR_DOMAIN_RUNNING:
|
||||
return "running ";
|
||||
@ -1413,7 +1458,8 @@ vshDomainStateToString(int state) {
|
||||
}
|
||||
|
||||
static int
|
||||
vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror) {
|
||||
vshConnectionUsability(vshControl * ctl, virConnectPtr conn, int showerror)
|
||||
{
|
||||
/* TODO: use something like virConnectionState() to
|
||||
* check usability of the connection
|
||||
*/
|
||||
@ -1426,7 +1472,8 @@ vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror) {
|
||||
}
|
||||
|
||||
static int
|
||||
vshWantedDebug(vshOutType type, int mode) {
|
||||
vshWantedDebug(vshOutType type, int mode)
|
||||
{
|
||||
switch (type) {
|
||||
case VSH_DEBUG5:
|
||||
if (mode < 5)
|
||||
@ -1456,7 +1503,8 @@ vshWantedDebug(vshOutType type, int mode) {
|
||||
}
|
||||
|
||||
static void
|
||||
vshPrint(vshControl *ctl, vshOutType type, const char *format, ...) {
|
||||
vshPrint(vshControl * ctl, vshOutType type, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (ctl->quiet == TRUE && (type == VSH_HEADER || type == VSH_FOOTER))
|
||||
@ -1471,7 +1519,8 @@ vshPrint(vshControl *ctl, vshOutType type, const char *format, ...) {
|
||||
}
|
||||
|
||||
static void
|
||||
vshError(vshControl *ctl, int doexit, const char *format, ...) {
|
||||
vshError(vshControl * ctl, int doexit, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (doexit)
|
||||
@ -1495,7 +1544,8 @@ vshError(vshControl *ctl, int doexit, const char *format, ...) {
|
||||
* Initialize vistsh
|
||||
*/
|
||||
static int
|
||||
vshInit(vshControl *ctl) {
|
||||
vshInit(vshControl * ctl)
|
||||
{
|
||||
if (ctl->conn)
|
||||
return FALSE;
|
||||
|
||||
@ -1527,7 +1577,8 @@ vshInit(vshControl *ctl) {
|
||||
* (i.e. STATE == 0), then we start at the top of the list.
|
||||
*/
|
||||
static char *
|
||||
vshReadlineCommandGenerator(const char *text, int state) {
|
||||
vshReadlineCommandGenerator(const char *text, int state)
|
||||
{
|
||||
static int list_index, len;
|
||||
const char *name;
|
||||
|
||||
@ -1554,7 +1605,8 @@ vshReadlineCommandGenerator(const char *text, int state) {
|
||||
}
|
||||
|
||||
static char *
|
||||
vshReadlineOptionsGenerator(const char *text, int state) {
|
||||
vshReadlineOptionsGenerator(const char *text, int state)
|
||||
{
|
||||
static int list_index, len;
|
||||
static vshCmdDef *cmd = NULL;
|
||||
const char *name;
|
||||
@ -1582,6 +1634,7 @@ vshReadlineOptionsGenerator(const char *text, int state) {
|
||||
while ((name = cmd->opts[list_index].name)) {
|
||||
vshCmdOptDef *opt = &cmd->opts[list_index];
|
||||
char *res;
|
||||
|
||||
list_index++;
|
||||
|
||||
if (opt->type == VSH_OT_DATA)
|
||||
@ -1602,7 +1655,9 @@ vshReadlineOptionsGenerator(const char *text, int state) {
|
||||
}
|
||||
|
||||
static char **
|
||||
vshReadlineCompletion(const char *text, int start, int end ATTRIBUTE_UNUSED) {
|
||||
vshReadlineCompletion(const char *text, int start,
|
||||
int end ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char **matches = (char **) NULL;
|
||||
|
||||
if (start == 0)
|
||||
@ -1616,7 +1671,8 @@ vshReadlineCompletion(const char *text, int start, int end ATTRIBUTE_UNUSED) {
|
||||
|
||||
|
||||
static void
|
||||
vshReadlineInit(void) {
|
||||
vshReadlineInit(void)
|
||||
{
|
||||
/* Allow conditional parsing of the ~/.inputrc file. */
|
||||
rl_readline_name = "virsh";
|
||||
|
||||
@ -1628,11 +1684,13 @@ vshReadlineInit(void) {
|
||||
* Deinitliaze virsh
|
||||
*/
|
||||
static int
|
||||
vshDeinit(vshControl *ctl) {
|
||||
vshDeinit(vshControl * ctl)
|
||||
{
|
||||
if (ctl->conn) {
|
||||
if (virConnectClose(ctl->conn) != 0) {
|
||||
ctl->conn = NULL; /* prevent recursive call from vshError() */
|
||||
vshError(ctl, TRUE, "failed to disconnect from the hypervisor");
|
||||
vshError(ctl, TRUE,
|
||||
"failed to disconnect from the hypervisor");
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
@ -1642,7 +1700,8 @@ vshDeinit(vshControl *ctl) {
|
||||
* Print usage
|
||||
*/
|
||||
static void
|
||||
vshUsage(vshControl *ctl, const char *cmdname) {
|
||||
vshUsage(vshControl * ctl, const char *cmdname)
|
||||
{
|
||||
vshCmdDef *cmd;
|
||||
|
||||
/* global help */
|
||||
@ -1658,9 +1717,11 @@ vshUsage(vshControl *ctl, const char *cmdname) {
|
||||
|
||||
for (cmd = commands; cmd->name; cmd++)
|
||||
fprintf(stdout,
|
||||
" %-15s %s\n", cmd->name, vshCmddefGetInfo(cmd, "help"));
|
||||
" %-15s %s\n", cmd->name, vshCmddefGetInfo(cmd,
|
||||
"help"));
|
||||
|
||||
fprintf(stdout, "\n (specify --help <command> for details about the command)\n\n");
|
||||
fprintf(stdout,
|
||||
"\n (specify --help <command> for details about the command)\n\n");
|
||||
return;
|
||||
}
|
||||
if (!vshCmddefHelp(ctl, cmdname, TRUE))
|
||||
@ -1672,7 +1733,8 @@ vshUsage(vshControl *ctl, const char *cmdname) {
|
||||
*
|
||||
*/
|
||||
static int
|
||||
vshParseArgv(vshControl *ctl, int argc, char **argv) {
|
||||
vshParseArgv(vshControl * ctl, int argc, char **argv)
|
||||
{
|
||||
char *last = NULL;
|
||||
int i, end = 0, help = 0;
|
||||
int arg, idx = 0;
|
||||
@ -1740,7 +1802,8 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) {
|
||||
fprintf(stdout, "%s\n", VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
default:
|
||||
vshError(ctl, TRUE, "unsupported option '-%c'. See --help.", arg);
|
||||
vshError(ctl, TRUE,
|
||||
"unsupported option '-%c'. See --help.", arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1778,7 +1841,8 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) {
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
vshControl _ctl, *ctl = &_ctl;
|
||||
int ret = TRUE;
|
||||
|
||||
@ -1801,14 +1865,17 @@ main(int argc, char **argv) {
|
||||
} else {
|
||||
/* interactive mode */
|
||||
if (!ctl->quiet) {
|
||||
vshPrint(ctl, VSH_MESG, "Welcome to %s, the virtualization interactive terminal.\n\n",
|
||||
vshPrint(ctl, VSH_MESG,
|
||||
"Welcome to %s, the virtualization interactive terminal.\n\n",
|
||||
progname);
|
||||
vshPrint(ctl, VSH_MESG, "Type: 'help' for help with commands\n"
|
||||
vshPrint(ctl, VSH_MESG,
|
||||
"Type: 'help' for help with commands\n"
|
||||
" 'quit' to quit\n\n");
|
||||
}
|
||||
vshReadlineInit();
|
||||
do {
|
||||
ctl->cmdstr = readline(ctl->uid==0 ? VSH_PROMPT_RW : VSH_PROMPT_RO);
|
||||
ctl->cmdstr =
|
||||
readline(ctl->uid == 0 ? VSH_PROMPT_RW : VSH_PROMPT_RO);
|
||||
if (ctl->cmdstr == NULL)
|
||||
break; /* EOF */
|
||||
if (*ctl->cmdstr) {
|
||||
@ -1833,4 +1900,3 @@ main(int argc, char **argv) {
|
||||
* vim: set shiftwidth=4:
|
||||
* vim: set expandtab:
|
||||
*/
|
||||
|
||||
|
@ -68,7 +68,8 @@ static void *virUserData = NULL; /* associated data */
|
||||
* Returns a pointer to the last error or NULL if none occured.
|
||||
*/
|
||||
virErrorPtr
|
||||
virGetLastError(void) {
|
||||
virGetLastError(void)
|
||||
{
|
||||
if (lastErr.code == VIR_ERR_OK)
|
||||
return (NULL);
|
||||
return (&lastErr);
|
||||
@ -85,7 +86,8 @@ virGetLastError(void) {
|
||||
* of parameter error.
|
||||
*/
|
||||
int
|
||||
virCopyLastError(virErrorPtr to) {
|
||||
virCopyLastError(virErrorPtr to)
|
||||
{
|
||||
if (to == NULL)
|
||||
return (-1);
|
||||
if (lastErr.code == VIR_ERR_OK)
|
||||
@ -101,7 +103,8 @@ virCopyLastError(virErrorPtr to) {
|
||||
* Reset the error being pointed to
|
||||
*/
|
||||
void
|
||||
virResetError(virErrorPtr err) {
|
||||
virResetError(virErrorPtr err)
|
||||
{
|
||||
if (err == NULL)
|
||||
return;
|
||||
if (err->message != NULL)
|
||||
@ -121,7 +124,8 @@ virResetError(virErrorPtr err) {
|
||||
* Reset the last error caught at the library level.
|
||||
*/
|
||||
void
|
||||
virResetLastError(void) {
|
||||
virResetLastError(void)
|
||||
{
|
||||
virResetError(&lastErr);
|
||||
}
|
||||
|
||||
@ -136,7 +140,8 @@ virResetLastError(void) {
|
||||
* Returns a pointer to the last error or NULL if none occured.
|
||||
*/
|
||||
virErrorPtr
|
||||
virConnGetLastError(virConnectPtr conn) {
|
||||
virConnGetLastError(virConnectPtr conn)
|
||||
{
|
||||
if (conn == NULL)
|
||||
return (NULL);
|
||||
return (&conn->err);
|
||||
@ -154,7 +159,8 @@ virConnGetLastError(virConnectPtr conn) {
|
||||
* of parameter error.
|
||||
*/
|
||||
int
|
||||
virConnCopyLastError(virConnectPtr conn, virErrorPtr to) {
|
||||
virConnCopyLastError(virConnectPtr conn, virErrorPtr to)
|
||||
{
|
||||
if (conn == NULL)
|
||||
return (-1);
|
||||
if (to == NULL)
|
||||
@ -172,7 +178,8 @@ virConnCopyLastError(virConnectPtr conn, virErrorPtr to) {
|
||||
* Reset the last error caught on that connection
|
||||
*/
|
||||
void
|
||||
virConnResetLastError(virConnectPtr conn) {
|
||||
virConnResetLastError(virConnectPtr conn)
|
||||
{
|
||||
if (conn == NULL)
|
||||
return;
|
||||
virResetError(&conn->err);
|
||||
@ -188,7 +195,8 @@ virConnResetLastError(virConnectPtr conn) {
|
||||
* are those for which no handler at the connection level could caught.
|
||||
*/
|
||||
void
|
||||
virSetErrorFunc(void *userData, virErrorFunc handler) {
|
||||
virSetErrorFunc(void *userData, virErrorFunc handler)
|
||||
{
|
||||
virErrorHandler = handler;
|
||||
virUserData = userData;
|
||||
}
|
||||
@ -204,7 +212,9 @@ virSetErrorFunc(void *userData, virErrorFunc handler) {
|
||||
* library handler.
|
||||
*/
|
||||
void
|
||||
virConnSetErrorFunc(virConnectPtr conn, void *userData, virErrorFunc handler) {
|
||||
virConnSetErrorFunc(virConnectPtr conn, void *userData,
|
||||
virErrorFunc handler)
|
||||
{
|
||||
if (conn == NULL)
|
||||
return;
|
||||
conn->handler = handler;
|
||||
@ -218,7 +228,8 @@ virConnSetErrorFunc(virConnectPtr conn, void *userData, virErrorFunc handler) {
|
||||
* Default routine reporting an error to stderr.
|
||||
*/
|
||||
void
|
||||
virDefaultErrorFunc(virErrorPtr err) {
|
||||
virDefaultErrorFunc(virErrorPtr err)
|
||||
{
|
||||
const char *lvl = "", *dom = "", *domain = "";
|
||||
int len;
|
||||
|
||||
@ -283,7 +294,8 @@ 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, ...) {
|
||||
int int1, int int2, const char *msg, ...)
|
||||
{
|
||||
virErrorPtr to = &lastErr;
|
||||
void *userData = virUserData;
|
||||
virErrorFunc handler = virErrorHandler;
|
||||
@ -352,7 +364,8 @@ __virRaiseError(virConnectPtr conn, virDomainPtr dom,
|
||||
* Returns the constant string associated to @error
|
||||
*/
|
||||
const char *
|
||||
__virErrorMsg(virErrorNumber error, const char *info) {
|
||||
__virErrorMsg(virErrorNumber error, const char *info)
|
||||
{
|
||||
const char *errmsg = NULL;
|
||||
|
||||
switch (error) {
|
||||
@ -472,4 +485,3 @@ __virErrorMsg(virErrorNumber error, const char *info) {
|
||||
}
|
||||
return (errmsg);
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,7 @@
|
||||
#include <xen/xen.h>
|
||||
|
||||
#ifndef __LINUX_PUBLIC_PRIVCMD_H__
|
||||
typedef struct hypercall_struct
|
||||
{
|
||||
typedef struct hypercall_struct {
|
||||
unsigned long op;
|
||||
unsigned long arg[5];
|
||||
} hypercall_t;
|
||||
@ -45,7 +44,8 @@ typedef struct hypercall_struct
|
||||
* Handle an error at the xend daemon interface
|
||||
*/
|
||||
static void
|
||||
virXenError(virErrorNumber error, const char *info, int value) {
|
||||
virXenError(virErrorNumber error, const char *info, int value)
|
||||
{
|
||||
const char *errmsg;
|
||||
|
||||
if (error == VIR_ERR_OK)
|
||||
@ -53,8 +53,7 @@ virXenError(virErrorNumber error, const char *info, int value) {
|
||||
|
||||
errmsg = __virErrorMsg(error, info);
|
||||
__virRaiseError(NULL, NULL, VIR_FROM_XEN, error, VIR_ERR_ERROR,
|
||||
errmsg, info, NULL, value, 0, errmsg, info,
|
||||
value);
|
||||
errmsg, info, NULL, value, 0, errmsg, info, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +64,9 @@ virXenError(virErrorNumber error, const char *info, int value) {
|
||||
*
|
||||
* Returns the handle or -1 in case of error.
|
||||
*/
|
||||
int xenHypervisorOpen(int quiet) {
|
||||
int
|
||||
xenHypervisorOpen(int quiet)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
|
||||
@ -86,7 +87,9 @@ int xenHypervisorOpen(int quiet) {
|
||||
*
|
||||
* Returns 0 in case of success or -1 in case of error.
|
||||
*/
|
||||
int xenHypervisorClose(int handle) {
|
||||
int
|
||||
xenHypervisorClose(int handle)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (handle < 0)
|
||||
@ -108,7 +111,8 @@ int xenHypervisorClose(int handle) {
|
||||
* Returns 0 in case of success and -1 in case of error.
|
||||
*/
|
||||
static int
|
||||
xenHypervisorDoOp(int handle, dom0_op_t *op) {
|
||||
xenHypervisorDoOp(int handle, dom0_op_t * op)
|
||||
{
|
||||
int ret;
|
||||
unsigned int cmd;
|
||||
hypercall_t hc;
|
||||
@ -148,7 +152,8 @@ xenHypervisorDoOp(int handle, dom0_op_t *op) {
|
||||
* Returns the hypervisor running version or 0 in case of error.
|
||||
*/
|
||||
unsigned long
|
||||
xenHypervisorGetVersion(int handle) {
|
||||
xenHypervisorGetVersion(int handle)
|
||||
{
|
||||
int ret;
|
||||
unsigned int cmd;
|
||||
hypercall_t hc;
|
||||
@ -182,7 +187,9 @@ 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(int handle, int domain,
|
||||
dom0_getdomaininfo_t * info)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
@ -192,7 +199,8 @@ xenHypervisorGetDomainInfo(int handle, int domain, dom0_getdomaininfo_t *info) {
|
||||
memset(info, 0, sizeof(dom0_getdomaininfo_t));
|
||||
|
||||
if (mlock(info, sizeof(dom0_getdomaininfo_t)) < 0) {
|
||||
virXenError(VIR_ERR_XEN_CALL, " locking", sizeof(dom0_getdomaininfo_t));
|
||||
virXenError(VIR_ERR_XEN_CALL, " locking",
|
||||
sizeof(dom0_getdomaininfo_t));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@ -206,7 +214,8 @@ xenHypervisorGetDomainInfo(int handle, int domain, dom0_getdomaininfo_t *info) {
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
|
||||
if (munlock(info, sizeof(dom0_getdomaininfo_t)) < 0) {
|
||||
virXenError(VIR_ERR_XEN_CALL, " release", sizeof(dom0_getdomaininfo_t));
|
||||
virXenError(VIR_ERR_XEN_CALL, " release",
|
||||
sizeof(dom0_getdomaininfo_t));
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
@ -225,7 +234,8 @@ xenHypervisorGetDomainInfo(int handle, int domain, dom0_getdomaininfo_t *info) {
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorPauseDomain(int handle, int domain) {
|
||||
xenHypervisorPauseDomain(int handle, int domain)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
@ -249,7 +259,8 @@ xenHypervisorPauseDomain(int handle, int domain) {
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorResumeDomain(int handle, int domain) {
|
||||
xenHypervisorResumeDomain(int handle, int domain)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
@ -273,7 +284,8 @@ xenHypervisorResumeDomain(int handle, int domain) {
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xenHypervisorDestroyDomain(int handle, int domain) {
|
||||
xenHypervisorDestroyDomain(int handle, int domain)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
@ -298,7 +310,8 @@ 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(int handle, int domain, unsigned long memory)
|
||||
{
|
||||
dom0_op_t op;
|
||||
int ret;
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
/* required for uint8_t, uint32_t, etc ... */
|
||||
#include <stdint.h>
|
||||
|
||||
/* required for dom0_getdomaininfo_t */
|
||||
#include <xen/dom0_ops.h>
|
||||
|
||||
@ -23,18 +24,14 @@ extern "C" {
|
||||
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 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 domain, unsigned long memory);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -67,7 +67,8 @@ struct xend {
|
||||
* Handle an error at the xend daemon interface
|
||||
*/
|
||||
static void
|
||||
virXendError(virConnectPtr conn, virErrorNumber error, const char *info) {
|
||||
virXendError(virConnectPtr conn, virErrorNumber error, const char *info)
|
||||
{
|
||||
const char *errmsg;
|
||||
|
||||
if (error == VIR_ERR_OK)
|
||||
@ -87,8 +88,8 @@ virXendError(virConnectPtr conn, virErrorNumber error, const char *info) {
|
||||
* Handle an error at the xend daemon interface
|
||||
*/
|
||||
static void
|
||||
virXendErrorInt(virConnectPtr conn, virErrorNumber error,
|
||||
int val) {
|
||||
virXendErrorInt(virConnectPtr conn, virErrorNumber error, int val)
|
||||
{
|
||||
const char *errmsg;
|
||||
|
||||
if (error == VIR_ERR_OK)
|
||||
@ -1099,6 +1100,7 @@ int
|
||||
xend_setup(virConnectPtr conn)
|
||||
{
|
||||
return (xend_setup_tcp(conn, "localhost", 8000));
|
||||
|
||||
/* return(xend_setup_unix(conn, "/var/lib/xend/xend-socket")); */
|
||||
}
|
||||
|
||||
@ -1218,8 +1220,7 @@ xend_shutdown(virConnectPtr xend, const char *name)
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, name,
|
||||
"op", "shutdown", "reason", "halt", NULL);
|
||||
return xend_op(xend, name, "op", "shutdown", "reason", "halt", NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1915,7 +1916,8 @@ sexpr_to_xend_domain(struct sexpr *root)
|
||||
_for_i = _for_i->cdr, node = _for_i->car) {
|
||||
if (sexpr_lookup(node, "device/vbd")) {
|
||||
dom->vbds[i].dev = sexpr_strcpy(&ptr, node, "device/vbd/dev");
|
||||
dom->vbds[i].uname = sexpr_strcpy(&ptr, node, "device/vbd/uname");
|
||||
dom->vbds[i].uname =
|
||||
sexpr_strcpy(&ptr, node, "device/vbd/uname");
|
||||
dom->vbds[i].backend = sexpr_int(node, "device/vbd/backend");
|
||||
dom->vbds[i].mode = sexpr_mode(node, "device/vbd/mode");
|
||||
i++;
|
||||
@ -1962,7 +1964,8 @@ xend_get_domain_info(virDomainPtr domain, virDomainInfoPtr info)
|
||||
if ((domain == NULL) || (info == NULL))
|
||||
return (-1);
|
||||
|
||||
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||
root =
|
||||
sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||
if (root == NULL)
|
||||
return (-1);
|
||||
|
||||
@ -2036,6 +2039,7 @@ xend_get_domain_ids(virConnectPtr xend, const char *domname,
|
||||
ret = -1;
|
||||
} else if (uuid != NULL) {
|
||||
char **ptr = (char **) &uuid;
|
||||
|
||||
if (sexpr_uuid(ptr, root, "domain/uuid") == NULL) {
|
||||
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, missing uuid");
|
||||
@ -2222,7 +2226,8 @@ xend_log(virConnectPtr xend, char *buffer, size_t n_buffer)
|
||||
* the caller must free() the returned value.
|
||||
*/
|
||||
static char *
|
||||
xend_parse_sexp_desc(struct sexpr *root) {
|
||||
xend_parse_sexp_desc(struct sexpr *root)
|
||||
{
|
||||
char *ret;
|
||||
struct sexpr *cur, *node;
|
||||
const char *tmp;
|
||||
@ -2284,7 +2289,8 @@ xend_parse_sexp_desc(struct sexpr *root) {
|
||||
if (!memcmp(tmp, "file:", 5)) {
|
||||
tmp += 5;
|
||||
virBufferVSprintf(&buf, " <disk type='file'>\n");
|
||||
virBufferVSprintf(&buf, " <source file='%s'/>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <source file='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/dev");
|
||||
if (tmp == NULL) {
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
@ -2314,35 +2320,37 @@ xend_parse_sexp_desc(struct sexpr *root) {
|
||||
} else {
|
||||
char serial[1000];
|
||||
|
||||
TODO
|
||||
sexpr2string(node, serial, 1000);
|
||||
TODO sexpr2string(node, serial, 1000);
|
||||
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
|
||||
serial);
|
||||
TODO
|
||||
}
|
||||
TODO}
|
||||
} else if (sexpr_lookup(node, "device/vif")) {
|
||||
tmp = sexpr_node(node, "device/vif/bridge");
|
||||
if (tmp != NULL) {
|
||||
virBufferVSprintf(&buf, " <interface type='bridge'>\n");
|
||||
virBufferVSprintf(&buf, " <source bridge='%s'/>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <source bridge='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vif/vifname");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vif/mac");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <mac address='%s'/>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <mac address='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vif/ip");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <ip address='%s'/>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <ip address='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vif/script");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <script path='%s'/>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <script path='%s'/>\n",
|
||||
tmp);
|
||||
virBufferAdd(&buf, " </interface>\n", 17);
|
||||
} else {
|
||||
char serial[1000];
|
||||
|
||||
TODO
|
||||
sexpr2string(node->car, serial, 1000);
|
||||
TODO sexpr2string(node->car, serial, 1000);
|
||||
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
|
||||
serial);
|
||||
}
|
||||
@ -2371,7 +2379,8 @@ error:
|
||||
* the caller must free() the returned value.
|
||||
*/
|
||||
char *
|
||||
xend_get_domain_xml(virDomainPtr domain) {
|
||||
xend_get_domain_xml(virDomainPtr domain)
|
||||
{
|
||||
char *ret = NULL;
|
||||
struct sexpr *root;
|
||||
|
||||
@ -2381,7 +2390,8 @@ xend_get_domain_xml(virDomainPtr domain) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||
root =
|
||||
sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||
if (root == NULL)
|
||||
return (NULL);
|
||||
|
||||
|
@ -31,8 +31,8 @@ extern "C" {
|
||||
/**
|
||||
This structure represents a virtual block device.
|
||||
*/
|
||||
struct xend_device_vbd
|
||||
{
|
||||
struct xend_device_vbd {
|
||||
|
||||
/**
|
||||
The domain ID of the backend.
|
||||
|
||||
@ -66,8 +66,8 @@ struct xend_device_vbd
|
||||
/**
|
||||
This structure represents a range of PIO to enable for a guest.
|
||||
*/
|
||||
struct xend_device_ioport
|
||||
{
|
||||
struct xend_device_ioport {
|
||||
|
||||
/**
|
||||
The beginning address of an ioport range to enable.
|
||||
|
||||
@ -86,8 +86,8 @@ struct xend_device_ioport
|
||||
/**
|
||||
This structure represents a virtual network interface configuration.
|
||||
*/
|
||||
struct xend_device_vif
|
||||
{
|
||||
struct xend_device_vif {
|
||||
|
||||
/**
|
||||
A string representing the domain that will serve as the backend for
|
||||
this device.
|
||||
@ -134,8 +134,8 @@ struct xend_device_vif
|
||||
const char *vifname;
|
||||
};
|
||||
|
||||
struct xend_domain_live
|
||||
{
|
||||
struct xend_domain_live {
|
||||
|
||||
/**
|
||||
true is domain is currently scheduled.
|
||||
*/
|
||||
@ -212,8 +212,8 @@ struct xend_domain_live
|
||||
This structure represents the configuration of a domain. It's primary
|
||||
purpose (currently) is for domain creation.
|
||||
*/
|
||||
struct xend_domain
|
||||
{
|
||||
struct xend_domain {
|
||||
|
||||
/**
|
||||
The name of the domain.
|
||||
|
||||
@ -316,13 +316,12 @@ struct xend_domain
|
||||
struct xend_domain_live *live;
|
||||
};
|
||||
|
||||
enum xend_node_system
|
||||
{
|
||||
enum xend_node_system {
|
||||
XEND_SYSTEM_LINUX = 1,
|
||||
};
|
||||
|
||||
struct xend_node
|
||||
{
|
||||
struct xend_node {
|
||||
|
||||
/**
|
||||
An enumeration value specifying the host system.
|
||||
*/
|
||||
@ -540,7 +539,8 @@ int xend_unpause(virConnectPtr xend, const char *name);
|
||||
*
|
||||
* This method allows a domain to have its name changed after creation.
|
||||
*/
|
||||
int xend_rename(virConnectPtr xend, const char *oldname, const char *name);
|
||||
int xend_rename(virConnectPtr xend, const char *oldname,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* \brief Sends a SYSRQ to a domain
|
||||
@ -602,7 +602,8 @@ int xend_destroy(virConnectPtr xend, const char *name);
|
||||
* a file on disk. Use xend_restore() to restore a domain after
|
||||
* saving.
|
||||
*/
|
||||
int xend_save(virConnectPtr xend, const char *name, const char *filename);
|
||||
int xend_save(virConnectPtr xend, const char *name,
|
||||
const char *filename);
|
||||
|
||||
/**
|
||||
* \brief Restore a domain from the disk
|
||||
@ -660,7 +661,8 @@ int xend_create_sexpr(virConnectPtr xend, const char *sexpr);
|
||||
* on its own (although under normal circumstances, memory allocation for a
|
||||
* domain is only done through xend_set_memory()).
|
||||
*/
|
||||
int xend_set_max_memory(virConnectPtr xend, const char *name, uint64_t value);
|
||||
int xend_set_max_memory(virConnectPtr xend, const char *name,
|
||||
uint64_t value);
|
||||
|
||||
/**
|
||||
* \brief Set the memory allocation for a domain
|
||||
@ -678,7 +680,8 @@ int xend_set_max_memory(virConnectPtr xend, const char *name, uint64_t value);
|
||||
* There is no safe guard for allocations that are too small so be careful
|
||||
* when using this function to reduce a domain's memory usage.
|
||||
*/
|
||||
int xend_set_memory(virConnectPtr xend, const char *name, uint64_t value);
|
||||
int xend_set_memory(virConnectPtr xend, const char *name,
|
||||
uint64_t value);
|
||||
|
||||
/**
|
||||
* \brief Create a virtual block device
|
||||
@ -767,8 +770,7 @@ struct xend_domain *xend_get_domain(virConnectPtr xend,
|
||||
* This method looks up the ids of a domain
|
||||
*/
|
||||
int xend_get_domain_ids(virConnectPtr xend,
|
||||
const char *name,
|
||||
unsigned char *uuid);
|
||||
const char *name, unsigned char *uuid);
|
||||
|
||||
/**
|
||||
* \brief Get status informations for a domain
|
||||
@ -779,8 +781,7 @@ int xend_get_domain_ids(virConnectPtr xend,
|
||||
* This method looks up information about a domain and update the
|
||||
* information block provided.
|
||||
*/
|
||||
int xend_get_domain_info(virDomainPtr domain,
|
||||
virDomainInfoPtr info);
|
||||
int xend_get_domain_info(virDomainPtr domain, virDomainInfoPtr info);
|
||||
|
||||
/**
|
||||
* \brief Lookup information about the host machine
|
||||
@ -820,9 +821,7 @@ int xend_node_restart(virConnectPtr xend);
|
||||
* This function will place the debugging messages from the
|
||||
* hypervisor into a buffer with a null terminator.
|
||||
*/
|
||||
int xend_dmesg(virConnectPtr xend,
|
||||
char *buffer,
|
||||
size_t n_buffer);
|
||||
int xend_dmesg(virConnectPtr xend, char *buffer, size_t n_buffer);
|
||||
|
||||
/**
|
||||
* \brief Clear the hypervisor debugging messages
|
||||
@ -844,9 +843,7 @@ int xend_dmesg_clear(virConnectPtr xend);
|
||||
* This function will place the Xend debugging messages into
|
||||
* a buffer with a null terminator.
|
||||
*/
|
||||
int xend_log(virConnectPtr xend,
|
||||
char *buffer,
|
||||
size_t n_buffer);
|
||||
int xend_log(virConnectPtr xend, char *buffer, size_t n_buffer);
|
||||
|
||||
/**
|
||||
* \brief Provide an XML description of the domain.
|
||||
@ -860,5 +857,4 @@ char *xend_get_domain_xml(virDomainPtr domain);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
103
src/xml.c
103
src/xml.c
@ -32,7 +32,8 @@
|
||||
* Handle an error at the xend daemon interface
|
||||
*/
|
||||
static void
|
||||
virXMLError(virErrorNumber error, const char *info, int value) {
|
||||
virXMLError(virErrorNumber error, const char *info, int value)
|
||||
{
|
||||
const char *errmsg;
|
||||
|
||||
if (error == VIR_ERR_OK)
|
||||
@ -40,8 +41,7 @@ virXMLError(virErrorNumber error, const char *info, int value) {
|
||||
|
||||
errmsg = __virErrorMsg(error, info);
|
||||
__virRaiseError(NULL, NULL, VIR_FROM_XML, error, VIR_ERR_ERROR,
|
||||
errmsg, info, NULL, value, 0, errmsg, info,
|
||||
value);
|
||||
errmsg, info, NULL, value, 0, errmsg, info, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,12 +54,15 @@ virXMLError(virErrorNumber error, const char *info, int value) {
|
||||
* Returns the new available space or -1 in case of error
|
||||
*/
|
||||
static int
|
||||
virBufferGrow(virBufferPtr buf, unsigned int len) {
|
||||
virBufferGrow(virBufferPtr buf, unsigned int len)
|
||||
{
|
||||
int size;
|
||||
char *newbuf;
|
||||
|
||||
if (buf == NULL) return(-1);
|
||||
if (len + buf->use < buf->size) return(0);
|
||||
if (buf == NULL)
|
||||
return (-1);
|
||||
if (len + buf->use < buf->size)
|
||||
return (0);
|
||||
|
||||
size = buf->use + len + 1000;
|
||||
|
||||
@ -85,13 +88,15 @@ virBufferGrow(virBufferPtr buf, unsigned int len) {
|
||||
* Returns 0 successful, -1 in case of internal or API error.
|
||||
*/
|
||||
int
|
||||
virBufferAdd(virBufferPtr buf, const char *str, int len) {
|
||||
virBufferAdd(virBufferPtr buf, const char *str, int len)
|
||||
{
|
||||
unsigned int needSize;
|
||||
|
||||
if ((str == NULL) || (buf == NULL)) {
|
||||
return -1;
|
||||
}
|
||||
if (len == 0) return 0;
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
if (len < 0)
|
||||
len = strlen(str);
|
||||
@ -120,7 +125,8 @@ virBufferAdd(virBufferPtr buf, const char *str, int len) {
|
||||
* Returns 0 successful, -1 in case of internal or API error.
|
||||
*/
|
||||
int
|
||||
virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
|
||||
virBufferVSprintf(virBufferPtr buf, const char *format, ...)
|
||||
{
|
||||
int size, count;
|
||||
va_list locarg, argptr;
|
||||
|
||||
@ -147,11 +153,13 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/*
|
||||
* This block of function are now implemented by a xend poll in
|
||||
* xend_internal.c instead of querying the Xen store, code is kept
|
||||
* for reference of in case Xend may not be available in the future ...
|
||||
*/
|
||||
|
||||
/**
|
||||
* virDomainGetXMLDevice:
|
||||
* @domain: a domain object
|
||||
@ -165,7 +173,8 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
|
||||
*/
|
||||
static char *
|
||||
virDomainGetXMLDeviceInfo(virDomainPtr domain, const char *sub,
|
||||
long dev, const char *name) {
|
||||
long dev, const char *name)
|
||||
{
|
||||
char s[256];
|
||||
unsigned int len = 0;
|
||||
|
||||
@ -187,7 +196,8 @@ virDomainGetXMLDeviceInfo(virDomainPtr domain, const char *sub,
|
||||
* Returns 0 in case of success, -1 in case of failure
|
||||
*/
|
||||
static int
|
||||
virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev) {
|
||||
virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev)
|
||||
{
|
||||
char *type, *val;
|
||||
|
||||
type = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "type");
|
||||
@ -230,8 +240,8 @@ virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev) {
|
||||
}
|
||||
virBufferAdd(buf, " </disk>\n", 12);
|
||||
} else {
|
||||
TODO
|
||||
fprintf(stderr, "Don't know how to handle device type %s\n", type);
|
||||
TODO fprintf(stderr, "Don't know how to handle device type %s\n",
|
||||
type);
|
||||
}
|
||||
free(type);
|
||||
|
||||
@ -248,7 +258,8 @@ virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev) {
|
||||
* Returns 0 in case of success, -1 in case of failure
|
||||
*/
|
||||
static int
|
||||
virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf) {
|
||||
virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf)
|
||||
{
|
||||
int ret = -1;
|
||||
unsigned int num, i;
|
||||
long id;
|
||||
@ -297,7 +308,8 @@ done:
|
||||
* Returns 0 in case of success, -1 in case of failure
|
||||
*/
|
||||
static int
|
||||
virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev) {
|
||||
virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev)
|
||||
{
|
||||
char *type, *val;
|
||||
|
||||
type = virDomainGetXMLDeviceInfo(domain, "vif", dev, "bridge");
|
||||
@ -344,7 +356,8 @@ virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev) {
|
||||
* Returns 0 in case of success, -1 in case of failure
|
||||
*/
|
||||
static int
|
||||
virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf) {
|
||||
virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf)
|
||||
{
|
||||
int ret = -1;
|
||||
unsigned int num, i;
|
||||
long id;
|
||||
@ -394,7 +407,8 @@ done:
|
||||
* Returns 0 in case of success, -1 in case of failure
|
||||
*/
|
||||
static int
|
||||
virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf) {
|
||||
virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf)
|
||||
{
|
||||
char *vm, *str;
|
||||
|
||||
if (!VIR_IS_DOMAIN(domain))
|
||||
@ -445,7 +459,8 @@ virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf) {
|
||||
* the caller must free() the returned value.
|
||||
*/
|
||||
char *
|
||||
virDomainGetXMLDesc(virDomainPtr domain, int flags) {
|
||||
virDomainGetXMLDesc(virDomainPtr domain, int flags)
|
||||
{
|
||||
char *ret = NULL;
|
||||
virBuffer buf;
|
||||
virDomainInfo info;
|
||||
@ -466,7 +481,8 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) {
|
||||
|
||||
virBufferVSprintf(&buf, "<domain type='xen' id='%d'>\n",
|
||||
virDomainGetID(domain));
|
||||
virBufferVSprintf(&buf, " <name>%s</name>\n", virDomainGetName(domain));
|
||||
virBufferVSprintf(&buf, " <name>%s</name>\n",
|
||||
virDomainGetName(domain));
|
||||
virDomainGetXMLBoot(domain, &buf);
|
||||
virBufferVSprintf(&buf, " <memory>%lu</memory>\n", info.maxMem);
|
||||
virBufferVSprintf(&buf, " <vcpu>%d</vcpu>\n", (int) info.nrVirtCpu);
|
||||
@ -495,7 +511,8 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) {
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
static int
|
||||
virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf)
|
||||
{
|
||||
xmlNodePtr cur, txt;
|
||||
const xmlChar *type = NULL;
|
||||
const xmlChar *root = NULL;
|
||||
@ -506,7 +523,8 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
cur = node->children;
|
||||
while (cur != NULL) {
|
||||
if (cur->type == XML_ELEMENT_NODE) {
|
||||
if ((type == NULL) && (xmlStrEqual(cur->name, BAD_CAST "type"))) {
|
||||
if ((type == NULL)
|
||||
&& (xmlStrEqual(cur->name, BAD_CAST "type"))) {
|
||||
txt = cur->children;
|
||||
if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
|
||||
type = txt->content;
|
||||
@ -549,6 +567,7 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
|
||||
if (root == NULL) {
|
||||
const xmlChar *base, *tmp;
|
||||
|
||||
/* need to extract root info from command line */
|
||||
if (cmdline == NULL) {
|
||||
virXMLError(VIR_ERR_NO_ROOT, (const char *) cmdline, 0);
|
||||
@ -563,13 +582,16 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
}
|
||||
base++;
|
||||
}
|
||||
while ((*base == ' ') || (*base == '\t')) base++;
|
||||
while ((*base == ' ') || (*base == '\t'))
|
||||
base++;
|
||||
if (*base == '=') {
|
||||
base++;
|
||||
while ((*base == ' ') || (*base == '\t')) base++;
|
||||
while ((*base == ' ') || (*base == '\t'))
|
||||
base++;
|
||||
}
|
||||
tmp = base;
|
||||
while ((*tmp != 0) && (*tmp != ' ') && (*tmp != '\t')) tmp++;
|
||||
while ((*tmp != 0) && (*tmp != ' ') && (*tmp != '\t'))
|
||||
tmp++;
|
||||
if (tmp == base) {
|
||||
virXMLError(VIR_ERR_NO_ROOT, (const char *) cmdline, 0);
|
||||
return (-1);
|
||||
@ -600,7 +622,8 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
static int
|
||||
virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf)
|
||||
{
|
||||
xmlNodePtr cur;
|
||||
xmlChar *type = NULL;
|
||||
xmlChar *source = NULL;
|
||||
@ -610,8 +633,10 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
|
||||
type = xmlGetProp(node, BAD_CAST "type");
|
||||
if (type != NULL) {
|
||||
if (xmlStrEqual(type, BAD_CAST "file")) typ = 0;
|
||||
else if (xmlStrEqual(type, BAD_CAST "block")) typ = 1;
|
||||
if (xmlStrEqual(type, BAD_CAST "file"))
|
||||
typ = 0;
|
||||
else if (xmlStrEqual(type, BAD_CAST "block"))
|
||||
typ = 1;
|
||||
xmlFree(type);
|
||||
}
|
||||
cur = node->children;
|
||||
@ -684,7 +709,8 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
* Returns 0 in case of success, -1 in case of error.
|
||||
*/
|
||||
static int
|
||||
virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf)
|
||||
{
|
||||
xmlNodePtr cur;
|
||||
xmlChar *type = NULL;
|
||||
xmlChar *source = NULL;
|
||||
@ -694,8 +720,10 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
|
||||
type = xmlGetProp(node, BAD_CAST "type");
|
||||
if (type != NULL) {
|
||||
if (xmlStrEqual(type, BAD_CAST "bridge")) typ = 0;
|
||||
else if (xmlStrEqual(type, BAD_CAST "ethernet")) typ = 1;
|
||||
if (xmlStrEqual(type, BAD_CAST "bridge"))
|
||||
typ = 0;
|
||||
else if (xmlStrEqual(type, BAD_CAST "ethernet"))
|
||||
typ = 1;
|
||||
xmlFree(type);
|
||||
}
|
||||
cur = node->children;
|
||||
@ -754,7 +782,8 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf) {
|
||||
* the caller must free() the returned value.
|
||||
*/
|
||||
char *
|
||||
virDomainParseXMLDesc(const char *xmldesc, char **name) {
|
||||
virDomainParseXMLDesc(const char *xmldesc, char **name)
|
||||
{
|
||||
xmlDocPtr xml = NULL;
|
||||
xmlNodePtr node;
|
||||
char *ret = NULL, *nam = NULL;
|
||||
@ -819,6 +848,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
|
||||
virBufferVSprintf(&buf, "(memory 128)(maxmem 128)");
|
||||
} else {
|
||||
unsigned long mem = (obj->floatval / 1024);
|
||||
|
||||
virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)", mem, mem);
|
||||
}
|
||||
xmlXPathFreeObject(obj);
|
||||
@ -829,6 +859,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
|
||||
virBufferVSprintf(&buf, "(vcpus 1)");
|
||||
} else {
|
||||
unsigned int cpu = (unsigned int) obj->floatval;
|
||||
|
||||
virBufferVSprintf(&buf, "(vcpus %u)", cpu);
|
||||
}
|
||||
xmlXPathFreeObject(obj);
|
||||
@ -837,8 +868,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
|
||||
virBufferAdd(&buf, "(image ", 7);
|
||||
obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt);
|
||||
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
|
||||
(obj->nodesetval == NULL) ||
|
||||
(obj->nodesetval->nodeNr != 1)) {
|
||||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr != 1)) {
|
||||
virXMLError(VIR_ERR_NO_OS, nam, 0);
|
||||
goto error;
|
||||
}
|
||||
@ -852,8 +882,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
|
||||
/* analyze of the devices */
|
||||
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
|
||||
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
|
||||
(obj->nodesetval == NULL) ||
|
||||
(obj->nodesetval->nodeNr < 1)) {
|
||||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 1)) {
|
||||
virXMLError(VIR_ERR_NO_DEVICE, nam, 0);
|
||||
goto error;
|
||||
}
|
||||
@ -871,7 +900,8 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
|
||||
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
|
||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||
virBufferAdd(&buf, "(device ", 8);
|
||||
res = virDomainParseXMLIfDesc(obj->nodesetval->nodeTab[i], &buf);
|
||||
res =
|
||||
virDomainParseXMLIfDesc(obj->nodesetval->nodeTab[i], &buf);
|
||||
if (res != 0) {
|
||||
goto error;
|
||||
}
|
||||
@ -907,4 +937,3 @@ error:
|
||||
free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
13
src/xml.h
13
src/xml.h
@ -24,18 +24,11 @@ struct _virBuffer {
|
||||
unsigned int size; /* The buffer size */
|
||||
};
|
||||
|
||||
int virBufferAdd (virBufferPtr buf,
|
||||
const char *str,
|
||||
int len);
|
||||
int virBufferVSprintf (virBufferPtr buf,
|
||||
const char *format,
|
||||
...);
|
||||
char * virDomainParseXMLDesc (const char *xmldesc,
|
||||
char **name);
|
||||
int virBufferAdd(virBufferPtr buf, const char *str, int len);
|
||||
int virBufferVSprintf(virBufferPtr buf, const char *format, ...);
|
||||
char *virDomainParseXMLDesc(const char *xmldesc, char **name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __VIR_XML_H__ */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user