mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +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
|
||||
|
314
src/hash.c
314
src/hash.c
@ -53,15 +53,17 @@ 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 += 30 * (*name);
|
||||
while ((ch = *name++) != 0) {
|
||||
value =
|
||||
value ^ ((value << 5) + (value >> 3) + (unsigned long) ch);
|
||||
}
|
||||
}
|
||||
return (value % table->size);
|
||||
}
|
||||
@ -75,24 +77,25 @@ 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)
|
||||
size = 256;
|
||||
|
||||
|
||||
table = malloc(sizeof(virHashTable));
|
||||
if (table) {
|
||||
table->size = size;
|
||||
table->nbElems = 0;
|
||||
table->nbElems = 0;
|
||||
table->table = malloc(size * sizeof(virHashEntry));
|
||||
if (table->table) {
|
||||
memset(table->table, 0, size * sizeof(virHashEntry));
|
||||
return(table);
|
||||
memset(table->table, 0, size * sizeof(virHashEntry));
|
||||
return (table);
|
||||
}
|
||||
free(table);
|
||||
}
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,84 +108,87 @@ 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
|
||||
|
||||
|
||||
if (table == NULL)
|
||||
return(-1);
|
||||
return (-1);
|
||||
if (size < 8)
|
||||
return(-1);
|
||||
return (-1);
|
||||
if (size > 8 * 2048)
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
oldsize = table->size;
|
||||
oldtable = table->table;
|
||||
if (oldtable == NULL)
|
||||
return(-1);
|
||||
|
||||
return (-1);
|
||||
|
||||
table->table = malloc(size * sizeof(virHashEntry));
|
||||
if (table->table == NULL) {
|
||||
table->table = oldtable;
|
||||
return(-1);
|
||||
table->table = oldtable;
|
||||
return (-1);
|
||||
}
|
||||
memset(table->table, 0, size * sizeof(virHashEntry));
|
||||
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)
|
||||
*/
|
||||
/* 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)
|
||||
*/
|
||||
for (i = 0; i < oldsize; i++) {
|
||||
if (oldtable[i].valid == 0)
|
||||
continue;
|
||||
key = virHashComputeKey(table, oldtable[i].name);
|
||||
memcpy(&(table->table[key]), &(oldtable[i]), sizeof(virHashEntry));
|
||||
table->table[key].next = NULL;
|
||||
if (oldtable[i].valid == 0)
|
||||
continue;
|
||||
key = virHashComputeKey(table, oldtable[i].name);
|
||||
memcpy(&(table->table[key]), &(oldtable[i]), sizeof(virHashEntry));
|
||||
table->table[key].next = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < oldsize; i++) {
|
||||
iter = oldtable[i].next;
|
||||
while (iter) {
|
||||
next = iter->next;
|
||||
iter = oldtable[i].next;
|
||||
while (iter) {
|
||||
next = iter->next;
|
||||
|
||||
/*
|
||||
* put back the entry in the new table
|
||||
*/
|
||||
/*
|
||||
* put back the entry in the new table
|
||||
*/
|
||||
|
||||
key = virHashComputeKey(table, iter->name);
|
||||
if (table->table[key].valid == 0) {
|
||||
memcpy(&(table->table[key]), iter, sizeof(virHashEntry));
|
||||
table->table[key].next = NULL;
|
||||
free(iter);
|
||||
} else {
|
||||
iter->next = table->table[key].next;
|
||||
table->table[key].next = iter;
|
||||
}
|
||||
key = virHashComputeKey(table, iter->name);
|
||||
if (table->table[key].valid == 0) {
|
||||
memcpy(&(table->table[key]), iter, sizeof(virHashEntry));
|
||||
table->table[key].next = NULL;
|
||||
free(iter);
|
||||
} else {
|
||||
iter->next = table->table[key].next;
|
||||
table->table[key].next = iter;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_GROW
|
||||
nbElem++;
|
||||
nbElem++;
|
||||
#endif
|
||||
|
||||
iter = next;
|
||||
}
|
||||
iter = next;
|
||||
}
|
||||
}
|
||||
|
||||
free(oldtable);
|
||||
|
||||
#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);
|
||||
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;
|
||||
@ -202,30 +209,30 @@ virHashFree(virHashTablePtr table, virHashDeallocator f) {
|
||||
int nbElems;
|
||||
|
||||
if (table == NULL)
|
||||
return;
|
||||
return;
|
||||
if (table->table) {
|
||||
nbElems = table->nbElems;
|
||||
for(i = 0; (i < table->size) && (nbElems > 0); i++) {
|
||||
iter = &(table->table[i]);
|
||||
if (iter->valid == 0)
|
||||
continue;
|
||||
inside_table = 1;
|
||||
while (iter) {
|
||||
next = iter->next;
|
||||
if ((f != NULL) && (iter->payload != NULL))
|
||||
f(iter->payload, iter->name);
|
||||
if (iter->name)
|
||||
free(iter->name);
|
||||
iter->payload = NULL;
|
||||
if (!inside_table)
|
||||
free(iter);
|
||||
nbElems--;
|
||||
inside_table = 0;
|
||||
iter = next;
|
||||
}
|
||||
inside_table = 0;
|
||||
}
|
||||
free(table->table);
|
||||
nbElems = table->nbElems;
|
||||
for (i = 0; (i < table->size) && (nbElems > 0); i++) {
|
||||
iter = &(table->table[i]);
|
||||
if (iter->valid == 0)
|
||||
continue;
|
||||
inside_table = 1;
|
||||
while (iter) {
|
||||
next = iter->next;
|
||||
if ((f != NULL) && (iter->payload != NULL))
|
||||
f(iter->payload, iter->name);
|
||||
if (iter->name)
|
||||
free(iter->name);
|
||||
iter->payload = NULL;
|
||||
if (!inside_table)
|
||||
free(iter);
|
||||
nbElems--;
|
||||
inside_table = 0;
|
||||
iter = next;
|
||||
}
|
||||
inside_table = 0;
|
||||
}
|
||||
free(table->table);
|
||||
}
|
||||
free(table);
|
||||
}
|
||||
@ -242,38 +249,38 @@ 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;
|
||||
|
||||
if ((table == NULL) || (name == NULL))
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* Check for duplicate and insertion location.
|
||||
*/
|
||||
key = virHashComputeKey(table, name);
|
||||
if (table->table[key].valid == 0) {
|
||||
insert = NULL;
|
||||
insert = NULL;
|
||||
} else {
|
||||
for (insert = &(table->table[key]); insert->next != NULL;
|
||||
insert = insert->next) {
|
||||
if (!strcmp(insert->name, name))
|
||||
return(-1);
|
||||
len++;
|
||||
}
|
||||
if (!strcmp(insert->name, name))
|
||||
return(-1);
|
||||
for (insert = &(table->table[key]); insert->next != NULL;
|
||||
insert = insert->next) {
|
||||
if (!strcmp(insert->name, name))
|
||||
return (-1);
|
||||
len++;
|
||||
}
|
||||
if (!strcmp(insert->name, name))
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (insert == NULL) {
|
||||
entry = &(table->table[key]);
|
||||
entry = &(table->table[key]);
|
||||
} else {
|
||||
entry = malloc(sizeof(virHashEntry));
|
||||
if (entry == NULL)
|
||||
return(-1);
|
||||
entry = malloc(sizeof(virHashEntry));
|
||||
if (entry == NULL)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
entry->name = strdup(name);
|
||||
@ -282,15 +289,15 @@ virHashAddEntry(virHashTablePtr table, const char *name,
|
||||
entry->valid = 1;
|
||||
|
||||
|
||||
if (insert != NULL)
|
||||
insert->next = entry;
|
||||
if (insert != NULL)
|
||||
insert->next = entry;
|
||||
|
||||
table->nbElems++;
|
||||
|
||||
if (len > MAX_HASH_LEN)
|
||||
virHashGrow(table, MAX_HASH_LEN * table->size);
|
||||
virHashGrow(table, MAX_HASH_LEN * table->size);
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -308,44 +315,45 @@ 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;
|
||||
|
||||
if ((table == NULL) || name == NULL)
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* Check for duplicate and insertion location.
|
||||
*/
|
||||
key = virHashComputeKey(table, name);
|
||||
if (table->table[key].valid == 0) {
|
||||
insert = NULL;
|
||||
insert = NULL;
|
||||
} else {
|
||||
for (insert = &(table->table[key]); insert->next != NULL;
|
||||
insert = insert->next) {
|
||||
if (!strcmp(insert->name, name)) {
|
||||
if (f)
|
||||
f(insert->payload, insert->name);
|
||||
insert->payload = userdata;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
if (!strcmp(insert->name, name)) {
|
||||
if (f)
|
||||
f(insert->payload, insert->name);
|
||||
insert->payload = userdata;
|
||||
return(0);
|
||||
}
|
||||
for (insert = &(table->table[key]); insert->next != NULL;
|
||||
insert = insert->next) {
|
||||
if (!strcmp(insert->name, name)) {
|
||||
if (f)
|
||||
f(insert->payload, insert->name);
|
||||
insert->payload = userdata;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
if (!strcmp(insert->name, name)) {
|
||||
if (f)
|
||||
f(insert->payload, insert->name);
|
||||
insert->payload = userdata;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
if (insert == NULL) {
|
||||
entry = &(table->table[key]);
|
||||
entry = &(table->table[key]);
|
||||
} else {
|
||||
entry = malloc(sizeof(virHashEntry));
|
||||
if (entry == NULL)
|
||||
return(-1);
|
||||
entry = malloc(sizeof(virHashEntry));
|
||||
if (entry == NULL)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
entry->name = strdup(name);
|
||||
@ -356,9 +364,9 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
|
||||
|
||||
|
||||
if (insert != NULL) {
|
||||
insert->next = entry;
|
||||
insert->next = entry;
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -371,22 +379,23 @@ 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;
|
||||
|
||||
if (table == NULL)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
if (name == NULL)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
key = virHashComputeKey(table, name);
|
||||
if (table->table[key].valid == 0)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
|
||||
if (!strcmp(entry->name, name))
|
||||
return(entry->payload);
|
||||
if (!strcmp(entry->name, name))
|
||||
return (entry->payload);
|
||||
}
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -399,10 +408,11 @@ 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);
|
||||
return (-1);
|
||||
return (table->nbElems);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -419,43 +429,45 @@ virHashSize(virHashTablePtr table) {
|
||||
*/
|
||||
int
|
||||
virHashRemoveEntry(virHashTablePtr table, const char *name,
|
||||
virHashDeallocator f) {
|
||||
virHashDeallocator f)
|
||||
{
|
||||
unsigned long key;
|
||||
virHashEntryPtr entry;
|
||||
virHashEntryPtr prev = NULL;
|
||||
|
||||
if (table == NULL || name == NULL)
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
key = virHashComputeKey(table, name);
|
||||
if (table->table[key].valid == 0) {
|
||||
return(-1);
|
||||
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);
|
||||
entry->payload = NULL;
|
||||
if(entry->name)
|
||||
free(entry->name);
|
||||
if(prev) {
|
||||
if (entry->name)
|
||||
free(entry->name);
|
||||
if (prev) {
|
||||
prev->next = entry->next;
|
||||
free(entry);
|
||||
} else {
|
||||
if (entry->next == NULL) {
|
||||
entry->valid = 0;
|
||||
} else {
|
||||
entry = entry->next;
|
||||
memcpy(&(table->table[key]), entry, sizeof(virHashEntry));
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
free(entry);
|
||||
} else {
|
||||
if (entry->next == NULL) {
|
||||
entry->valid = 0;
|
||||
} else {
|
||||
entry = entry->next;
|
||||
memcpy(&(table->table[key]), entry,
|
||||
sizeof(virHashEntry));
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
table->nbElems--;
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
prev = entry;
|
||||
}
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
39
src/hash.h
39
src/hash.h
@ -18,12 +18,13 @@ extern "C" {
|
||||
/*
|
||||
* The hash table.
|
||||
*/
|
||||
typedef struct _virHashTable virHashTable;
|
||||
typedef virHashTable *virHashTablePtr;
|
||||
typedef struct _virHashTable virHashTable;
|
||||
typedef virHashTable *virHashTablePtr;
|
||||
|
||||
/*
|
||||
* function types:
|
||||
*/
|
||||
|
||||
/**
|
||||
* virHashDeallocator:
|
||||
* @payload: the data in the hash
|
||||
@ -31,41 +32,37 @@ typedef virHashTable *virHashTablePtr;
|
||||
*
|
||||
* Callback to free data from a hash.
|
||||
*/
|
||||
typedef void (*virHashDeallocator)(void *payload, char *name);
|
||||
typedef void (*virHashDeallocator) (void *payload, char *name);
|
||||
|
||||
/*
|
||||
* Constructor and destructor.
|
||||
*/
|
||||
virHashTablePtr virHashCreate (int size);
|
||||
void
|
||||
virHashFree (virHashTablePtr table,
|
||||
virHashDeallocator f);
|
||||
int virHashSize (virHashTablePtr table);
|
||||
virHashTablePtr virHashCreate(int size);
|
||||
void
|
||||
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);
|
||||
int virHashUpdateEntry(virHashTablePtr table,
|
||||
const char *name,
|
||||
void *userdata,
|
||||
virHashDeallocator f);
|
||||
int virHashAddEntry(virHashTablePtr table,
|
||||
const char *name, void *userdata);
|
||||
int virHashUpdateEntry(virHashTablePtr table,
|
||||
const char *name,
|
||||
void *userdata, virHashDeallocator f);
|
||||
|
||||
/*
|
||||
* Remove an entry from the hash table.
|
||||
*/
|
||||
int virHashRemoveEntry(virHashTablePtr table,
|
||||
const char *name,
|
||||
virHashDeallocator f);
|
||||
int virHashRemoveEntry(virHashTablePtr table,
|
||||
const char *name, virHashDeallocator f);
|
||||
|
||||
/*
|
||||
* Retrieve the userdata.
|
||||
*/
|
||||
void * virHashLookup (virHashTablePtr table,
|
||||
const char *name);
|
||||
void *virHashLookup(virHashTablePtr table, const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* ! __VIR_HASH_H__ */
|
||||
#endif /* ! __VIR_HASH_H__ */
|
||||
|
@ -74,27 +74,27 @@ 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:
|
||||
@ -102,50 +102,44 @@ struct _virConnect {
|
||||
* 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 */
|
||||
};
|
||||
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 */
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal routines
|
||||
*/
|
||||
char * virDomainGetVM (virDomainPtr domain);
|
||||
char * virDomainGetVMInfo (virDomainPtr domain,
|
||||
const char *vm,
|
||||
const char *name);
|
||||
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
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __VIR_INTERNAL_H__ */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __VIR_INTERNAL_H__ */
|
||||
|
804
src/libvirt.c
804
src/libvirt.c
File diff suppressed because it is too large
Load Diff
94
src/sexpr.c
94
src/sexpr.c
@ -30,9 +30,10 @@
|
||||
* 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)
|
||||
return;
|
||||
|
||||
@ -56,7 +57,7 @@ sexpr_new(void)
|
||||
ret = (struct sexpr *) malloc(sizeof(*ret));
|
||||
if (ret == NULL) {
|
||||
virSexprError(VIR_ERR_NO_MEMORY, "failed to allocate a node");
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
ret->kind = SEXPR_NIL;
|
||||
return ret;
|
||||
@ -193,11 +194,11 @@ struct sexpr *
|
||||
sexpr_append(struct sexpr *lst, struct sexpr *value)
|
||||
{
|
||||
if (lst == NULL)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
if (value == NULL)
|
||||
return(lst);
|
||||
return (lst);
|
||||
append(lst, value);
|
||||
return(lst);
|
||||
return (lst);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,33 +220,34 @@ sexpr2string(struct sexpr * sexpr, char *buffer, size_t n_buffer)
|
||||
size_t ret = 0, tmp;
|
||||
|
||||
if ((sexpr == NULL) || (buffer == NULL) || (n_buffer <= 0))
|
||||
return(0);
|
||||
return (0);
|
||||
|
||||
switch (sexpr->kind) {
|
||||
case SEXPR_CONS:
|
||||
tmp = snprintf(buffer + ret, n_buffer - ret, "(");
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
tmp = sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
tmp = sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
while (sexpr->cdr->kind != SEXPR_NIL) {
|
||||
sexpr = sexpr->cdr;
|
||||
tmp = snprintf(buffer + ret, n_buffer - ret, " ");
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
tmp = sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
tmp =
|
||||
sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
}
|
||||
tmp = snprintf(buffer + ret, n_buffer - ret, ")");
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
break;
|
||||
case SEXPR_VALUE:
|
||||
if (strchr(sexpr->value, ' '))
|
||||
@ -254,21 +256,21 @@ sexpr2string(struct sexpr * sexpr, char *buffer, size_t n_buffer)
|
||||
else
|
||||
tmp = snprintf(buffer + ret, n_buffer - ret, "%s",
|
||||
sexpr->value);
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
if (tmp == 0)
|
||||
goto error;
|
||||
ret += tmp;
|
||||
break;
|
||||
case SEXPR_NIL:
|
||||
break;
|
||||
default:
|
||||
goto error;
|
||||
default:
|
||||
goto error;
|
||||
}
|
||||
|
||||
return(ret);
|
||||
error:
|
||||
return (ret);
|
||||
error:
|
||||
buffer[n_buffer - 1] = 0;
|
||||
virSexprError(VIR_ERR_SEXPR_SERIAL, buffer);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define IS_SPACE(c) ((c == 0x20) || (c == 0x9) || (c == 0xD) || (c == 0xA))
|
||||
@ -278,7 +280,7 @@ trim(const char *string)
|
||||
{
|
||||
while (IS_SPACE(*string))
|
||||
string++;
|
||||
return(string);
|
||||
return (string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -345,9 +347,10 @@ _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");
|
||||
}
|
||||
if (ret->value == NULL) {
|
||||
virSexprError(VIR_ERR_NO_MEMORY,
|
||||
"failed to copy a string");
|
||||
}
|
||||
|
||||
if (*ptr == '\'')
|
||||
ptr++;
|
||||
@ -359,23 +362,24 @@ _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");
|
||||
}
|
||||
if (ret->value == NULL) {
|
||||
virSexprError(VIR_ERR_NO_MEMORY,
|
||||
"failed to copy a string");
|
||||
}
|
||||
}
|
||||
|
||||
ret->kind = SEXPR_VALUE;
|
||||
if (ret->value == NULL)
|
||||
goto error;
|
||||
if (ret->value == NULL)
|
||||
goto error;
|
||||
}
|
||||
|
||||
*end = ptr - buffer;
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
error:
|
||||
sexpr_free(ret);
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -415,7 +419,7 @@ sexpr_lookup(struct sexpr *sexpr, const char *node)
|
||||
char buffer[4096], *ptr, *token;
|
||||
|
||||
if ((node == NULL) || (sexpr == NULL))
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "%s", node);
|
||||
|
||||
@ -437,7 +441,7 @@ sexpr_lookup(struct sexpr *sexpr, const char *node)
|
||||
continue;
|
||||
|
||||
sexpr = sexpr->cdr;
|
||||
for (i=sexpr; i->kind != SEXPR_NIL; i=i->cdr) {
|
||||
for (i = sexpr; i->kind != SEXPR_NIL; i = i->cdr) {
|
||||
if (i->kind != SEXPR_CONS ||
|
||||
i->car->kind != SEXPR_CONS ||
|
||||
i->car->car->kind != SEXPR_VALUE) {
|
||||
|
25
src/sexpr.h
25
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);
|
||||
struct sexpr * string2sexpr (const char *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);
|
||||
void sexpr_free (struct sexpr *sexpr);
|
||||
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);
|
||||
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
|
||||
|
1104
src/virsh.c
1104
src/virsh.c
File diff suppressed because it is too large
Load Diff
344
src/virterror.c
344
src/virterror.c
@ -16,10 +16,10 @@
|
||||
#include "virterror.h"
|
||||
#include "internal.h"
|
||||
|
||||
static virError lastErr = /* the last error */
|
||||
{ 0, 0, NULL, VIR_ERR_NONE, NULL, NULL, NULL, NULL, NULL, 0, 0};
|
||||
static virErrorFunc virErrorHandler = NULL;/* global error handlet */
|
||||
static void *virUserData = NULL; /* associated data */
|
||||
static virError lastErr = /* the last error */
|
||||
{ 0, 0, NULL, VIR_ERR_NONE, NULL, NULL, NULL, NULL, NULL, 0, 0 };
|
||||
static virErrorFunc virErrorHandler = NULL; /* global error handlet */
|
||||
static void *virUserData = NULL; /* associated data */
|
||||
|
||||
/*
|
||||
* Macro used to format the message as a string in __virRaiseError
|
||||
@ -68,10 +68,11 @@ 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);
|
||||
return (NULL);
|
||||
return (&lastErr);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -85,13 +86,14 @@ virGetLastError(void) {
|
||||
* of parameter error.
|
||||
*/
|
||||
int
|
||||
virCopyLastError(virErrorPtr to) {
|
||||
virCopyLastError(virErrorPtr to)
|
||||
{
|
||||
if (to == NULL)
|
||||
return(-1);
|
||||
return (-1);
|
||||
if (lastErr.code == VIR_ERR_OK)
|
||||
return(0);
|
||||
return (0);
|
||||
memcpy(to, &lastErr, sizeof(virError));
|
||||
return(lastErr.code);
|
||||
return (lastErr.code);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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,10 +140,11 @@ 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);
|
||||
return (NULL);
|
||||
return (&conn->err);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,15 +159,16 @@ virConnGetLastError(virConnectPtr conn) {
|
||||
* of parameter error.
|
||||
*/
|
||||
int
|
||||
virConnCopyLastError(virConnectPtr conn, virErrorPtr to) {
|
||||
virConnCopyLastError(virConnectPtr conn, virErrorPtr to)
|
||||
{
|
||||
if (conn == NULL)
|
||||
return(-1);
|
||||
return (-1);
|
||||
if (to == NULL)
|
||||
return(-1);
|
||||
return (-1);
|
||||
if (conn->err.code == VIR_ERR_OK)
|
||||
return(0);
|
||||
return (0);
|
||||
memcpy(to, &conn->err, sizeof(virError));
|
||||
return(conn->err.code);
|
||||
return (conn->err.code);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
|
||||
@ -226,39 +237,39 @@ virDefaultErrorFunc(virErrorPtr err) {
|
||||
return;
|
||||
switch (err->level) {
|
||||
case VIR_ERR_NONE:
|
||||
lvl = "";
|
||||
break;
|
||||
lvl = "";
|
||||
break;
|
||||
case VIR_ERR_WARNING:
|
||||
lvl = "warning";
|
||||
break;
|
||||
lvl = "warning";
|
||||
break;
|
||||
case VIR_ERR_ERROR:
|
||||
lvl = "error";
|
||||
break;
|
||||
}
|
||||
lvl = "error";
|
||||
break;
|
||||
}
|
||||
switch (err->domain) {
|
||||
case VIR_FROM_NONE:
|
||||
dom = "";
|
||||
break;
|
||||
dom = "";
|
||||
break;
|
||||
case VIR_FROM_XEN:
|
||||
dom = "Xen ";
|
||||
break;
|
||||
dom = "Xen ";
|
||||
break;
|
||||
case VIR_FROM_XEND:
|
||||
dom = "Xen Daemon ";
|
||||
break;
|
||||
dom = "Xen Daemon ";
|
||||
break;
|
||||
case VIR_FROM_DOM:
|
||||
dom = "Domain ";
|
||||
break;
|
||||
dom = "Domain ";
|
||||
break;
|
||||
}
|
||||
if ((err->dom != NULL) && (err->code != VIR_ERR_INVALID_DOMAIN)) {
|
||||
domain = err->dom->name;
|
||||
}
|
||||
len = strlen(err->message);
|
||||
if ((len == 0) || (err->message[len - 1] != '\n'))
|
||||
fprintf(stderr, "libvir: %s%s %s: %s\n",
|
||||
dom, lvl, domain, err->message);
|
||||
else
|
||||
fprintf(stderr, "libvir: %s%s %s: %s",
|
||||
dom, lvl, domain, err->message);
|
||||
fprintf(stderr, "libvir: %s%s %s: %s\n",
|
||||
dom, lvl, domain, err->message);
|
||||
else
|
||||
fprintf(stderr, "libvir: %s%s %s: %s",
|
||||
dom, lvl, domain, err->message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -283,24 +294,25 @@ 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;
|
||||
char *str;
|
||||
|
||||
if (code == VIR_ERR_OK)
|
||||
return;
|
||||
return;
|
||||
|
||||
/*
|
||||
* try to find the best place to save and report the error
|
||||
*/
|
||||
if (conn != NULL) {
|
||||
to = &conn->err;
|
||||
if (conn->handler != NULL) {
|
||||
handler = conn->handler;
|
||||
userData = conn->userData;
|
||||
}
|
||||
if (conn->handler != NULL) {
|
||||
handler = conn->handler;
|
||||
userData = conn->userData;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -352,124 +364,124 @@ __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) {
|
||||
case VIR_ERR_OK:
|
||||
return(NULL);
|
||||
case VIR_ERR_INTERNAL_ERROR:
|
||||
if (info != NULL)
|
||||
errmsg = "internal error %s";
|
||||
else
|
||||
errmsg = "internal error";
|
||||
break;
|
||||
case VIR_ERR_NO_MEMORY:
|
||||
errmsg = "out of memory";
|
||||
break;
|
||||
case VIR_ERR_NO_SUPPORT:
|
||||
errmsg = "no support for hypervisor %s";
|
||||
break;
|
||||
case VIR_ERR_NO_CONNECT:
|
||||
if (info == NULL)
|
||||
errmsg = "could not connect to hypervisor";
|
||||
else
|
||||
errmsg = "could not connect to %s";
|
||||
break;
|
||||
case VIR_ERR_INVALID_CONN:
|
||||
errmsg = "invalid connection pointer in";
|
||||
break;
|
||||
case VIR_ERR_INVALID_DOMAIN:
|
||||
errmsg = "invalid domain pointer in";
|
||||
break;
|
||||
case VIR_ERR_INVALID_ARG:
|
||||
errmsg = "invalid domain pointer in";
|
||||
break;
|
||||
case VIR_ERR_OPERATION_FAILED:
|
||||
if (info != NULL)
|
||||
errmsg = "operation failed: %s";
|
||||
else
|
||||
errmsg = "operation failed";
|
||||
break;
|
||||
case VIR_ERR_GET_FAILED:
|
||||
if (info != NULL)
|
||||
errmsg = "GET operation failed: %s";
|
||||
else
|
||||
errmsg = "GET operation failed";
|
||||
break;
|
||||
case VIR_ERR_POST_FAILED:
|
||||
if (info != NULL)
|
||||
errmsg = "POST operation failed: %s";
|
||||
else
|
||||
errmsg = "POST operation failed";
|
||||
break;
|
||||
case VIR_ERR_HTTP_ERROR:
|
||||
errmsg = "got unknown HTTP error code %d";
|
||||
break;
|
||||
case VIR_ERR_UNKNOWN_HOST:
|
||||
errmsg = "unknown host %s";
|
||||
break;
|
||||
case VIR_ERR_SEXPR_SERIAL:
|
||||
if (info != NULL)
|
||||
errmsg = "failed to serialize S-Expr: %s";
|
||||
else
|
||||
errmsg = "failed to serialize S-Expr";
|
||||
break;
|
||||
case VIR_ERR_NO_XEN:
|
||||
if (info == NULL)
|
||||
errmsg = "could not use Xen hypervisor entry";
|
||||
else
|
||||
errmsg = "could not use Xen hypervisor entry %s";
|
||||
break;
|
||||
case VIR_ERR_XEN_CALL:
|
||||
errmsg = "failed Xen syscall %s %d";
|
||||
break;
|
||||
case VIR_ERR_OS_TYPE:
|
||||
if (info == NULL)
|
||||
errmsg = "unknown OS type";
|
||||
else
|
||||
errmsg = "unknown OS type %s";
|
||||
break;
|
||||
case VIR_ERR_NO_KERNEL:
|
||||
errmsg = "missing kernel informations";
|
||||
break;
|
||||
case VIR_ERR_NO_ROOT:
|
||||
if (info == NULL)
|
||||
errmsg = "missing root device informations";
|
||||
else
|
||||
errmsg = "missing root device informations in %s";
|
||||
break;
|
||||
case VIR_ERR_NO_SOURCE:
|
||||
if (info == NULL)
|
||||
errmsg = "missing source informations for device";
|
||||
else
|
||||
errmsg = "missing source informations for device %s";
|
||||
break;
|
||||
case VIR_ERR_NO_TARGET:
|
||||
if (info == NULL)
|
||||
errmsg = "missing target informations for device";
|
||||
else
|
||||
errmsg = "missing target informations for device %s";
|
||||
break;
|
||||
case VIR_ERR_NO_NAME:
|
||||
if (info == NULL)
|
||||
errmsg = "missing domain name informations";
|
||||
else
|
||||
errmsg = "missing domain name informations in %s";
|
||||
break;
|
||||
case VIR_ERR_NO_OS:
|
||||
if (info == NULL)
|
||||
errmsg = "missing operating system informations";
|
||||
else
|
||||
errmsg = "missing operating system informations for %s";
|
||||
break;
|
||||
case VIR_ERR_NO_DEVICE:
|
||||
if (info == NULL)
|
||||
errmsg = "missing devices informations";
|
||||
else
|
||||
errmsg = "missing devices informations for %s";
|
||||
break;
|
||||
return (NULL);
|
||||
case VIR_ERR_INTERNAL_ERROR:
|
||||
if (info != NULL)
|
||||
errmsg = "internal error %s";
|
||||
else
|
||||
errmsg = "internal error";
|
||||
break;
|
||||
case VIR_ERR_NO_MEMORY:
|
||||
errmsg = "out of memory";
|
||||
break;
|
||||
case VIR_ERR_NO_SUPPORT:
|
||||
errmsg = "no support for hypervisor %s";
|
||||
break;
|
||||
case VIR_ERR_NO_CONNECT:
|
||||
if (info == NULL)
|
||||
errmsg = "could not connect to hypervisor";
|
||||
else
|
||||
errmsg = "could not connect to %s";
|
||||
break;
|
||||
case VIR_ERR_INVALID_CONN:
|
||||
errmsg = "invalid connection pointer in";
|
||||
break;
|
||||
case VIR_ERR_INVALID_DOMAIN:
|
||||
errmsg = "invalid domain pointer in";
|
||||
break;
|
||||
case VIR_ERR_INVALID_ARG:
|
||||
errmsg = "invalid domain pointer in";
|
||||
break;
|
||||
case VIR_ERR_OPERATION_FAILED:
|
||||
if (info != NULL)
|
||||
errmsg = "operation failed: %s";
|
||||
else
|
||||
errmsg = "operation failed";
|
||||
break;
|
||||
case VIR_ERR_GET_FAILED:
|
||||
if (info != NULL)
|
||||
errmsg = "GET operation failed: %s";
|
||||
else
|
||||
errmsg = "GET operation failed";
|
||||
break;
|
||||
case VIR_ERR_POST_FAILED:
|
||||
if (info != NULL)
|
||||
errmsg = "POST operation failed: %s";
|
||||
else
|
||||
errmsg = "POST operation failed";
|
||||
break;
|
||||
case VIR_ERR_HTTP_ERROR:
|
||||
errmsg = "got unknown HTTP error code %d";
|
||||
break;
|
||||
case VIR_ERR_UNKNOWN_HOST:
|
||||
errmsg = "unknown host %s";
|
||||
break;
|
||||
case VIR_ERR_SEXPR_SERIAL:
|
||||
if (info != NULL)
|
||||
errmsg = "failed to serialize S-Expr: %s";
|
||||
else
|
||||
errmsg = "failed to serialize S-Expr";
|
||||
break;
|
||||
case VIR_ERR_NO_XEN:
|
||||
if (info == NULL)
|
||||
errmsg = "could not use Xen hypervisor entry";
|
||||
else
|
||||
errmsg = "could not use Xen hypervisor entry %s";
|
||||
break;
|
||||
case VIR_ERR_XEN_CALL:
|
||||
errmsg = "failed Xen syscall %s %d";
|
||||
break;
|
||||
case VIR_ERR_OS_TYPE:
|
||||
if (info == NULL)
|
||||
errmsg = "unknown OS type";
|
||||
else
|
||||
errmsg = "unknown OS type %s";
|
||||
break;
|
||||
case VIR_ERR_NO_KERNEL:
|
||||
errmsg = "missing kernel informations";
|
||||
break;
|
||||
case VIR_ERR_NO_ROOT:
|
||||
if (info == NULL)
|
||||
errmsg = "missing root device informations";
|
||||
else
|
||||
errmsg = "missing root device informations in %s";
|
||||
break;
|
||||
case VIR_ERR_NO_SOURCE:
|
||||
if (info == NULL)
|
||||
errmsg = "missing source informations for device";
|
||||
else
|
||||
errmsg = "missing source informations for device %s";
|
||||
break;
|
||||
case VIR_ERR_NO_TARGET:
|
||||
if (info == NULL)
|
||||
errmsg = "missing target informations for device";
|
||||
else
|
||||
errmsg = "missing target informations for device %s";
|
||||
break;
|
||||
case VIR_ERR_NO_NAME:
|
||||
if (info == NULL)
|
||||
errmsg = "missing domain name informations";
|
||||
else
|
||||
errmsg = "missing domain name informations in %s";
|
||||
break;
|
||||
case VIR_ERR_NO_OS:
|
||||
if (info == NULL)
|
||||
errmsg = "missing operating system informations";
|
||||
else
|
||||
errmsg = "missing operating system informations for %s";
|
||||
break;
|
||||
case VIR_ERR_NO_DEVICE:
|
||||
if (info == NULL)
|
||||
errmsg = "missing devices informations";
|
||||
else
|
||||
errmsg = "missing devices informations for %s";
|
||||
break;
|
||||
}
|
||||
return(errmsg);
|
||||
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,16 +44,16 @@ 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)
|
||||
return;
|
||||
|
||||
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,17 +64,19 @@ 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);
|
||||
if (ret < 0) {
|
||||
if (!quiet)
|
||||
virXenError(VIR_ERR_NO_XEN, XEN_HYPERVISOR_SOCKET, 0);
|
||||
return(-1);
|
||||
if (!quiet)
|
||||
virXenError(VIR_ERR_NO_XEN, XEN_HYPERVISOR_SOCKET, 0);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,16 +87,18 @@ 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)
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
ret = close(handle);
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,18 +111,19 @@ 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;
|
||||
|
||||
op->interface_version = DOM0_INTERFACE_VERSION;
|
||||
hc.op = __HYPERVISOR_dom0_op;
|
||||
hc.arg[0] = (unsigned long)op;
|
||||
hc.arg[0] = (unsigned long) op;
|
||||
|
||||
if (mlock(op, sizeof(dom0_op_t)) < 0) {
|
||||
virXenError(VIR_ERR_XEN_CALL, " locking", sizeof(dom0_op_t));
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
cmd = _IOC(_IOC_NONE, 'P', 0, sizeof(hc));
|
||||
@ -134,9 +138,9 @@ xenHypervisorDoOp(int handle, dom0_op_t *op) {
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
|
||||
return(0);
|
||||
return (-1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,13 +152,14 @@ 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;
|
||||
|
||||
hc.op = __HYPERVISOR_xen_version;
|
||||
hc.arg[0] = (unsigned long) XENVER_version;
|
||||
hc.arg[0] = (unsigned long) XENVER_version;
|
||||
hc.arg[1] = 0;
|
||||
|
||||
cmd = _IOC(_IOC_NONE, 'P', 0, sizeof(hc));
|
||||
@ -162,13 +167,13 @@ xenHypervisorGetVersion(int handle) {
|
||||
|
||||
if (ret < 0) {
|
||||
virXenError(VIR_ERR_XEN_CALL, " getting version ", XENVER_version);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
/*
|
||||
* use unsigned long in case the version grows behind expectations
|
||||
* allowed by int
|
||||
*/
|
||||
return((unsigned long) ret);
|
||||
return ((unsigned long) ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,18 +187,21 @@ 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;
|
||||
|
||||
if (info == NULL)
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
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));
|
||||
return(-1);
|
||||
virXenError(VIR_ERR_XEN_CALL, " locking",
|
||||
sizeof(dom0_getdomaininfo_t));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
op.cmd = DOM0_GETDOMAININFOLIST;
|
||||
@ -206,13 +214,14 @@ 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;
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
|
||||
@ -235,8 +245,8 @@ xenHypervisorPauseDomain(int handle, int domain) {
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
|
||||
@ -259,8 +270,8 @@ xenHypervisorResumeDomain(int handle, int domain) {
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
|
||||
@ -283,8 +295,8 @@ xenHypervisorDestroyDomain(int handle, int domain) {
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
|
||||
@ -309,6 +322,6 @@ xenHypervisorSetMaxMemory(int handle, int domain, unsigned long memory) {
|
||||
ret = xenHypervisorDoOp(handle, &op);
|
||||
|
||||
if (ret < 0)
|
||||
return(-1);
|
||||
return(0);
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
/* required for uint8_t, uint32_t, etc ... */
|
||||
#include <stdint.h>
|
||||
|
||||
/* required for dom0_getdomaininfo_t */
|
||||
#include <xen/dom0_ops.h>
|
||||
|
||||
@ -20,23 +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(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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __VIR_XEN_INTERNAL_H__ */
|
||||
#endif /* __VIR_XEN_INTERNAL_H__ */
|
||||
|
@ -67,9 +67,10 @@ 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)
|
||||
return;
|
||||
|
||||
@ -87,10 +88,10 @@ 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)
|
||||
return;
|
||||
|
||||
@ -126,7 +127,7 @@ do_connect(virConnectPtr xend)
|
||||
s = socket(xend->type, SOCK_STREAM, 0);
|
||||
if (s == -1) {
|
||||
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
|
||||
"failed to create a socket");
|
||||
"failed to create a socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -161,9 +162,9 @@ wr_sync(int fd, void *buffer, size_t size, int do_read)
|
||||
ssize_t len;
|
||||
|
||||
if (do_read) {
|
||||
len = read(fd, ((char *)buffer) + offset, size - offset);
|
||||
len = read(fd, ((char *) buffer) + offset, size - offset);
|
||||
} else {
|
||||
len = write(fd, ((char *)buffer) + offset, size - offset);
|
||||
len = write(fd, ((char *) buffer) + offset, size - offset);
|
||||
}
|
||||
|
||||
/* recoverable error, retry */
|
||||
@ -178,14 +179,14 @@ wr_sync(int fd, void *buffer, size_t size, int do_read)
|
||||
|
||||
/* unrecoverable error */
|
||||
if (len == -1) {
|
||||
if (do_read)
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"faid to read from Xen Daemon");
|
||||
else
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"faid to read from Xen Daemon");
|
||||
|
||||
return(-1);
|
||||
if (do_read)
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"faid to read from Xen Daemon");
|
||||
else
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"faid to read from Xen Daemon");
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
offset += len;
|
||||
@ -257,7 +258,7 @@ sreads(int fd, char *buffer, size_t n_buffer)
|
||||
size_t offset;
|
||||
|
||||
if (n_buffer < 1)
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
for (offset = 0; offset < (n_buffer - 1); offset++) {
|
||||
ssize_t ret;
|
||||
@ -364,7 +365,7 @@ xend_get(virConnectPtr xend, const char *path,
|
||||
close(s);
|
||||
|
||||
if ((ret < 0) || (ret >= 300)) {
|
||||
virXendError(NULL, VIR_ERR_GET_FAILED, content);
|
||||
virXendError(NULL, VIR_ERR_GET_FAILED, content);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -412,7 +413,7 @@ xend_post(virConnectPtr xend, const char *path, const char *ops,
|
||||
close(s);
|
||||
|
||||
if ((ret < 0) || (ret >= 300)) {
|
||||
virXendError(NULL, VIR_ERR_POST_FAILED, content);
|
||||
virXendError(NULL, VIR_ERR_POST_FAILED, content);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -440,7 +441,7 @@ http2unix(int ret)
|
||||
errno = ESRCH;
|
||||
break;
|
||||
default:
|
||||
virXendErrorInt(NULL, VIR_ERR_HTTP_ERROR, ret);
|
||||
virXendErrorInt(NULL, VIR_ERR_HTTP_ERROR, ret);
|
||||
errno = EINVAL;
|
||||
break;
|
||||
}
|
||||
@ -935,7 +936,7 @@ urlencode(const char *string)
|
||||
size_t i;
|
||||
|
||||
if (buffer == NULL)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
for (i = 0; i < len; i++) {
|
||||
switch (string[i]) {
|
||||
case ' ':
|
||||
@ -1027,7 +1028,7 @@ xend_setup_unix(virConnectPtr xend, const char *path)
|
||||
struct sockaddr_un *addr;
|
||||
|
||||
if ((xend == NULL) || (path == NULL))
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
addr = &xend->addr_un;
|
||||
addr->sun_family = AF_UNIX;
|
||||
@ -1041,7 +1042,7 @@ xend_setup_unix(virConnectPtr xend, const char *path)
|
||||
xend->addr = (struct sockaddr *) addr;
|
||||
xend->type = PF_UNIX;
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1062,14 +1063,14 @@ xend_setup_tcp(virConnectPtr xend, const char *host, int port)
|
||||
struct hostent *pent;
|
||||
|
||||
if ((xend == NULL) || (host == NULL) || (port <= 0))
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
pent = gethostbyname(host);
|
||||
if (pent == NULL) {
|
||||
if (inet_aton(host, &ip) == 0) {
|
||||
virXendError(xend, VIR_ERR_UNKNOWN_HOST, host);
|
||||
virXendError(xend, VIR_ERR_UNKNOWN_HOST, host);
|
||||
errno = ESRCH;
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
memcpy(&ip, pent->h_addr_list[0], sizeof(ip));
|
||||
@ -1083,7 +1084,7 @@ xend_setup_tcp(virConnectPtr xend, const char *host, int port)
|
||||
xend->addr_in.sin_port = htons(port);
|
||||
memcpy(&xend->addr_in.sin_addr, &ip, sizeof(ip));
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1098,7 +1099,8 @@ xend_setup_tcp(virConnectPtr xend, const char *host, int port)
|
||||
int
|
||||
xend_setup(virConnectPtr conn)
|
||||
{
|
||||
return(xend_setup_tcp(conn, "localhost", 8000));
|
||||
return (xend_setup_tcp(conn, "localhost", 8000));
|
||||
|
||||
/* return(xend_setup_unix(conn, "/var/lib/xend/xend-socket")); */
|
||||
}
|
||||
|
||||
@ -1173,9 +1175,9 @@ int
|
||||
xend_rename(virConnectPtr xend, const char *old, const char *new)
|
||||
{
|
||||
if ((xend == NULL) || (old == NULL) || (new == NULL)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, old, "op", "rename", "name", new, NULL);
|
||||
}
|
||||
@ -1193,9 +1195,9 @@ int
|
||||
xend_reboot(virConnectPtr xend, const char *name)
|
||||
{
|
||||
if ((xend == NULL) || (name == NULL)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, name, "op", "shutdown", "reason", "reboot", NULL);
|
||||
}
|
||||
@ -1214,12 +1216,11 @@ int
|
||||
xend_shutdown(virConnectPtr xend, const char *name)
|
||||
{
|
||||
if ((xend == NULL) || (name == NULL)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, name,
|
||||
"op", "shutdown", "reason", "halt", NULL);
|
||||
return xend_op(xend, name, "op", "shutdown", "reason", "halt", NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1236,9 +1237,9 @@ int
|
||||
xend_sysrq(virConnectPtr xend, const char *name, const char *key)
|
||||
{
|
||||
if ((xend == NULL) || (name == NULL) || (key == NULL)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, name, "op", "sysrq", "key", key, NULL);
|
||||
}
|
||||
@ -1258,9 +1259,9 @@ int
|
||||
xend_destroy(virConnectPtr xend, const char *name)
|
||||
{
|
||||
if ((xend == NULL) || (name == NULL)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, name, "op", "destroy", NULL);
|
||||
}
|
||||
@ -1283,9 +1284,9 @@ int
|
||||
xend_save(virConnectPtr xend, const char *name, const char *filename)
|
||||
{
|
||||
if ((xend == NULL) || (filename == NULL)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, name, "op", "save", "file", filename, NULL);
|
||||
}
|
||||
@ -1305,9 +1306,9 @@ int
|
||||
xend_restore(virConnectPtr xend, const char *filename)
|
||||
{
|
||||
if ((xend == NULL) || (filename == NULL)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
return xend_op(xend, "", "op", "restore", "file", filename, NULL);
|
||||
}
|
||||
@ -1390,7 +1391,7 @@ xend_domain_to_sexpr(const struct xend_domain *domain)
|
||||
size_t i;
|
||||
|
||||
if (domain == NULL)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
|
||||
lst = sexpr_append(lst, sexpr_string("vm", -1));
|
||||
lst = sexpr_append_str(lst, "name", domain->name);
|
||||
@ -1505,10 +1506,10 @@ xend_create_sexpr(virConnectPtr xend, const char *sexpr)
|
||||
|
||||
ptr = urlencode(sexpr);
|
||||
if (ptr == NULL) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
|
||||
"Failed to urlencode the create S-Expr");
|
||||
return(-1);
|
||||
"Failed to urlencode the create S-Expr");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ret = xend_op(xend, "", "op", "create", "config", ptr, NULL);
|
||||
@ -1750,21 +1751,21 @@ sexpr_to_xend_domain_size(struct sexpr *root, int *n_vbds, int *n_vifs)
|
||||
|
||||
for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
|
||||
_for_i = _for_i->cdr, node = _for_i->car) {
|
||||
if (sexpr_lookup(node, "device/vbd")) {
|
||||
size += sexpr_strlen(node, "device/vbd/dev");
|
||||
size += sexpr_strlen(node, "device/vbd/uname");
|
||||
(*n_vbds)++;
|
||||
}
|
||||
if (sexpr_lookup(node, "device/vbd")) {
|
||||
size += sexpr_strlen(node, "device/vbd/dev");
|
||||
size += sexpr_strlen(node, "device/vbd/uname");
|
||||
(*n_vbds)++;
|
||||
}
|
||||
}
|
||||
|
||||
for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
|
||||
_for_i = _for_i->cdr, node = _for_i->car) {
|
||||
if (sexpr_lookup(node, "device/vif")) {
|
||||
size += sexpr_strlen(node, "device/vif/bridge");
|
||||
size += sexpr_strlen(node, "device/vif/ip");
|
||||
size += sexpr_strlen(node, "device/vif/script");
|
||||
size += sexpr_strlen(node, "device/vif/vifname");
|
||||
(*n_vifs)++;
|
||||
if (sexpr_lookup(node, "device/vif")) {
|
||||
size += sexpr_strlen(node, "device/vif/bridge");
|
||||
size += sexpr_strlen(node, "device/vif/ip");
|
||||
size += sexpr_strlen(node, "device/vif/script");
|
||||
size += sexpr_strlen(node, "device/vif/vifname");
|
||||
(*n_vifs)++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1795,10 +1796,10 @@ static int
|
||||
sexpr_to_xend_domain_info(struct sexpr *root, virDomainInfoPtr info)
|
||||
{
|
||||
const char *flags;
|
||||
|
||||
|
||||
|
||||
if ((root == NULL) || (info == NULL))
|
||||
return(-1);
|
||||
return (-1);
|
||||
|
||||
info->memory = sexpr_u64(root, "domain/memory") << 10;
|
||||
info->maxMem = sexpr_u64(root, "domain/maxmem") << 10;
|
||||
@ -1806,23 +1807,23 @@ sexpr_to_xend_domain_info(struct sexpr *root, virDomainInfoPtr info)
|
||||
|
||||
if (flags) {
|
||||
if (strchr(flags, 'c'))
|
||||
info->state = VIR_DOMAIN_CRASHED;
|
||||
else if (strchr(flags, 's'))
|
||||
info->state = VIR_DOMAIN_SHUTDOWN;
|
||||
else if (strchr(flags, 'd'))
|
||||
info->state = VIR_DOMAIN_SHUTOFF;
|
||||
else if (strchr(flags, 'p'))
|
||||
info->state = VIR_DOMAIN_PAUSED;
|
||||
else if (strchr(flags, 'b'))
|
||||
info->state = VIR_DOMAIN_BLOCKED;
|
||||
else if (strchr(flags, 'r'))
|
||||
info->state = VIR_DOMAIN_RUNNING;
|
||||
info->state = VIR_DOMAIN_CRASHED;
|
||||
else if (strchr(flags, 's'))
|
||||
info->state = VIR_DOMAIN_SHUTDOWN;
|
||||
else if (strchr(flags, 'd'))
|
||||
info->state = VIR_DOMAIN_SHUTOFF;
|
||||
else if (strchr(flags, 'p'))
|
||||
info->state = VIR_DOMAIN_PAUSED;
|
||||
else if (strchr(flags, 'b'))
|
||||
info->state = VIR_DOMAIN_BLOCKED;
|
||||
else if (strchr(flags, 'r'))
|
||||
info->state = VIR_DOMAIN_RUNNING;
|
||||
} else {
|
||||
info->state = VIR_DOMAIN_NOSTATE;
|
||||
}
|
||||
info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000;
|
||||
info->nrVirtCpu = sexpr_int(root, "domain/vcpus");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1913,33 +1914,34 @@ sexpr_to_xend_domain(struct sexpr *root)
|
||||
i = 0;
|
||||
for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
|
||||
_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].backend = sexpr_int(node, "device/vbd/backend");
|
||||
dom->vbds[i].mode = sexpr_mode(node, "device/vbd/mode");
|
||||
i++;
|
||||
}
|
||||
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].backend = sexpr_int(node, "device/vbd/backend");
|
||||
dom->vbds[i].mode = sexpr_mode(node, "device/vbd/mode");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
|
||||
_for_i = _for_i->cdr, node = _for_i->car) {
|
||||
if (sexpr_lookup(node, "device/vif")) {
|
||||
dom->vifs[i].backend = sexpr_int(node, "device/vif/backend");
|
||||
dom->vifs[i].bridge =
|
||||
sexpr_strcpy(&ptr, node, "device/vif/bridge");
|
||||
dom->vifs[i].ip = sexpr_strcpy(&ptr, node, "device/vif/ip");
|
||||
sexpr_mac(dom->vifs[i].mac, node, "device/vif/mac");
|
||||
dom->vifs[i].script =
|
||||
sexpr_strcpy(&ptr, node, "device/vif/script");
|
||||
dom->vifs[i].vifname =
|
||||
sexpr_strcpy(&ptr, node, "device/vif/vifname");
|
||||
i++;
|
||||
if (sexpr_lookup(node, "device/vif")) {
|
||||
dom->vifs[i].backend = sexpr_int(node, "device/vif/backend");
|
||||
dom->vifs[i].bridge =
|
||||
sexpr_strcpy(&ptr, node, "device/vif/bridge");
|
||||
dom->vifs[i].ip = sexpr_strcpy(&ptr, node, "device/vif/ip");
|
||||
sexpr_mac(dom->vifs[i].mac, node, "device/vif/mac");
|
||||
dom->vifs[i].script =
|
||||
sexpr_strcpy(&ptr, node, "device/vif/script");
|
||||
dom->vifs[i].vifname =
|
||||
sexpr_strcpy(&ptr, node, "device/vif/vifname");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
error:
|
||||
return dom;
|
||||
}
|
||||
|
||||
@ -1960,15 +1962,16 @@ xend_get_domain_info(virDomainPtr domain, virDomainInfoPtr info)
|
||||
int ret;
|
||||
|
||||
if ((domain == NULL) || (info == NULL))
|
||||
return(-1);
|
||||
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);
|
||||
return (-1);
|
||||
|
||||
ret = sexpr_to_xend_domain_info(root, info);
|
||||
sexpr_free(root);
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2017,7 +2020,7 @@ xend_get_domain_ids(virConnectPtr xend, const char *domname,
|
||||
const char *value;
|
||||
int ret = -1;
|
||||
|
||||
if (uuid != NULL)
|
||||
if (uuid != NULL)
|
||||
memset(uuid, 0, 16);
|
||||
root = sexpr_get(xend, "/xend/domain/%s?detail=1", domname);
|
||||
if (root == NULL)
|
||||
@ -2026,25 +2029,26 @@ xend_get_domain_ids(virConnectPtr xend, const char *domname,
|
||||
value = sexpr_node(root, "domain/domid");
|
||||
if (value == NULL) {
|
||||
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, missing domid");
|
||||
"domain informations incomplete, missing domid");
|
||||
goto error;
|
||||
}
|
||||
ret = strtol(value, NULL, 0);
|
||||
if ((ret == 0) && (value[0] != '0')) {
|
||||
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incorrect domid not numberic");
|
||||
"domain informations incorrect domid not numberic");
|
||||
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");
|
||||
}
|
||||
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, missing uuid");
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
error:
|
||||
sexpr_free(root);
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
@ -2230,11 +2235,11 @@ xend_parse_sexp_desc(struct sexpr *root) {
|
||||
|
||||
if (root == NULL) {
|
||||
/* ERROR */
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
ret = malloc(1000);
|
||||
if (ret == NULL)
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
buf.content = ret;
|
||||
buf.size = 1000;
|
||||
buf.use = 0;
|
||||
@ -2243,122 +2248,125 @@ xend_parse_sexp_desc(struct sexpr *root) {
|
||||
sexpr_int(root, "domain/domid"));
|
||||
tmp = sexpr_node(root, "domain/name");
|
||||
if (tmp == NULL) {
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, missing name");
|
||||
goto error;
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, missing name");
|
||||
goto error;
|
||||
}
|
||||
virBufferVSprintf(&buf, " <name>%s</name>\n", tmp);
|
||||
tmp = sexpr_node(root, "domain/image/linux/kernel");
|
||||
if (tmp == NULL) {
|
||||
/*
|
||||
* TODO: we will need some fallback here for other guest OSes
|
||||
*/
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, missing kernel");
|
||||
goto error;
|
||||
* TODO: we will need some fallback here for other guest OSes
|
||||
*/
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, missing kernel");
|
||||
goto error;
|
||||
}
|
||||
virBufferAdd(&buf, " <os>\n", 7);
|
||||
virBufferVSprintf(&buf, " <type>linux</type>\n");
|
||||
virBufferVSprintf(&buf, " <kernel>%s</kernel>\n", tmp);
|
||||
tmp = sexpr_node(root, "domain/image/linux/ramdisk");
|
||||
if ((tmp != NULL) && (tmp[0] != 0))
|
||||
virBufferVSprintf(&buf, " <initrd>%s</initrd>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <initrd>%s</initrd>\n", tmp);
|
||||
tmp = sexpr_node(root, "domain/image/linux/root");
|
||||
if ((tmp != NULL) && (tmp[0] != 0))
|
||||
virBufferVSprintf(&buf, " <root>%s</root>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <root>%s</root>\n", tmp);
|
||||
tmp = sexpr_node(root, "domain/image/linux/args");
|
||||
if ((tmp != NULL) && (tmp[0] != 0))
|
||||
virBufferVSprintf(&buf, " <cmdline>%s</cmdline>\n", tmp);
|
||||
virBufferVSprintf(&buf, " <cmdline>%s</cmdline>\n", tmp);
|
||||
virBufferAdd(&buf, " </os>\n", 8);
|
||||
virBufferVSprintf(&buf, " <memory>%d</memory>\n",
|
||||
virBufferVSprintf(&buf, " <memory>%d</memory>\n",
|
||||
(int) (sexpr_u64(root, "domain/maxmem") << 10));
|
||||
virBufferVSprintf(&buf, " <vcpu>%d</vcpu>\n",
|
||||
virBufferVSprintf(&buf, " <vcpu>%d</vcpu>\n",
|
||||
sexpr_int(root, "domain/vcpus"));
|
||||
virBufferAdd(&buf, " <devices>\n", 12);
|
||||
for (cur = root; cur->kind == SEXPR_CONS; cur = cur->cdr) {
|
||||
node = cur->car;
|
||||
if (sexpr_lookup(node, "device/vbd")) {
|
||||
tmp = sexpr_node(node, "device/vbd/uname");
|
||||
if (tmp == NULL)
|
||||
continue;
|
||||
if (!memcmp(tmp, "file:", 5)) {
|
||||
tmp += 5;
|
||||
virBufferVSprintf(&buf, " <disk type='file'>\n");
|
||||
virBufferVSprintf(&buf, " <source file='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/dev");
|
||||
if (tmp == NULL) {
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, vbd has no dev");
|
||||
goto error;
|
||||
}
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/mode");
|
||||
if ((tmp != NULL) && (!strcmp(tmp, "r")))
|
||||
virBufferVSprintf(&buf, " <readonly/>\n");
|
||||
virBufferAdd(&buf, " </disk>\n", 12);
|
||||
} else if (!memcmp(tmp, "phy:", 4)) {
|
||||
tmp += 4;
|
||||
virBufferVSprintf(&buf, " <disk type='block'>\n");
|
||||
virBufferVSprintf(&buf, " <source dev='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/dev");
|
||||
if (tmp == NULL) {
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, vbd has no dev");
|
||||
goto error;
|
||||
}
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/mode");
|
||||
if ((tmp != NULL) && (!strcmp(tmp, "r")))
|
||||
virBufferVSprintf(&buf, " <readonly/>\n");
|
||||
virBufferAdd(&buf, " </disk>\n", 12);
|
||||
} else {
|
||||
char serial[1000];
|
||||
if (sexpr_lookup(node, "device/vbd")) {
|
||||
tmp = sexpr_node(node, "device/vbd/uname");
|
||||
if (tmp == NULL)
|
||||
continue;
|
||||
if (!memcmp(tmp, "file:", 5)) {
|
||||
tmp += 5;
|
||||
virBufferVSprintf(&buf, " <disk type='file'>\n");
|
||||
virBufferVSprintf(&buf, " <source file='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/dev");
|
||||
if (tmp == NULL) {
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, vbd has no dev");
|
||||
goto error;
|
||||
}
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/mode");
|
||||
if ((tmp != NULL) && (!strcmp(tmp, "r")))
|
||||
virBufferVSprintf(&buf, " <readonly/>\n");
|
||||
virBufferAdd(&buf, " </disk>\n", 12);
|
||||
} else if (!memcmp(tmp, "phy:", 4)) {
|
||||
tmp += 4;
|
||||
virBufferVSprintf(&buf, " <disk type='block'>\n");
|
||||
virBufferVSprintf(&buf, " <source dev='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/dev");
|
||||
if (tmp == NULL) {
|
||||
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
"domain informations incomplete, vbd has no dev");
|
||||
goto error;
|
||||
}
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vbd/mode");
|
||||
if ((tmp != NULL) && (!strcmp(tmp, "r")))
|
||||
virBufferVSprintf(&buf, " <readonly/>\n");
|
||||
virBufferAdd(&buf, " </disk>\n", 12);
|
||||
} else {
|
||||
char serial[1000];
|
||||
|
||||
TODO
|
||||
sexpr2string(node, serial, 1000);
|
||||
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
|
||||
serial);
|
||||
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);
|
||||
tmp = sexpr_node(node, "device/vif/vifname");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vif/mac");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <mac address='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vif/ip");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <ip address='%s'/>\n", tmp);
|
||||
tmp = sexpr_node(node, "device/vif/script");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <script path='%s'/>\n", tmp);
|
||||
virBufferAdd(&buf, " </interface>\n", 17);
|
||||
} else {
|
||||
char serial[1000];
|
||||
TODO sexpr2string(node, serial, 1000);
|
||||
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
|
||||
serial);
|
||||
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);
|
||||
tmp = sexpr_node(node, "device/vif/vifname");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <target dev='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vif/mac");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <mac address='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vif/ip");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <ip address='%s'/>\n",
|
||||
tmp);
|
||||
tmp = sexpr_node(node, "device/vif/script");
|
||||
if (tmp != NULL)
|
||||
virBufferVSprintf(&buf, " <script path='%s'/>\n",
|
||||
tmp);
|
||||
virBufferAdd(&buf, " </interface>\n", 17);
|
||||
} else {
|
||||
char serial[1000];
|
||||
|
||||
TODO
|
||||
sexpr2string(node->car, serial, 1000);
|
||||
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
|
||||
serial);
|
||||
}
|
||||
|
||||
}
|
||||
TODO sexpr2string(node->car, serial, 1000);
|
||||
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
|
||||
serial);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
virBufferAdd(&buf, " </devices>\n", 13);
|
||||
virBufferAdd(&buf, "</domain>\n", 10);
|
||||
|
||||
buf.content[buf.use] = 0;
|
||||
return(ret);
|
||||
return (ret);
|
||||
|
||||
error:
|
||||
error:
|
||||
if (ret != NULL)
|
||||
free(ret);
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2371,22 +2379,24 @@ 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;
|
||||
|
||||
if (!VIR_IS_DOMAIN(domain)) {
|
||||
/* this should be caught at the interface but ... */
|
||||
/* this should be caught at the interface but ... */
|
||||
virXendError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
|
||||
return(NULL);
|
||||
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);
|
||||
return (NULL);
|
||||
|
||||
ret = xend_parse_sexp_desc(root);
|
||||
sexpr_free(root);
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
@ -31,418 +31,417 @@ extern "C" {
|
||||
/**
|
||||
This structure represents a virtual block device.
|
||||
*/
|
||||
struct xend_device_vbd
|
||||
{
|
||||
/**
|
||||
struct xend_device_vbd {
|
||||
|
||||
/**
|
||||
The domain ID of the backend.
|
||||
|
||||
Required.
|
||||
*/
|
||||
int backend;
|
||||
int backend;
|
||||
|
||||
/**
|
||||
/**
|
||||
A URI representing the device. This is typically in the form
|
||||
file:/path/to/image or phy:/dev/device
|
||||
|
||||
Required.
|
||||
*/
|
||||
const char *uname;
|
||||
const char *uname;
|
||||
|
||||
/**
|
||||
/**
|
||||
The name (or number) of the device to expose to the frontend.
|
||||
|
||||
Required.
|
||||
*/
|
||||
const char *dev;
|
||||
const char *dev;
|
||||
|
||||
/**
|
||||
/**
|
||||
A flag specifying the permissions to expose the device with.
|
||||
|
||||
Required.
|
||||
*/
|
||||
virDeviceMode mode;
|
||||
};
|
||||
virDeviceMode mode;
|
||||
};
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
Required.
|
||||
*/
|
||||
uint16_t from;
|
||||
uint16_t from;
|
||||
|
||||
/**
|
||||
/**
|
||||
The ending address of an ioport range to enable.
|
||||
|
||||
Required.
|
||||
*/
|
||||
uint16_t to;
|
||||
};
|
||||
uint16_t to;
|
||||
};
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
Required.
|
||||
*/
|
||||
int backend;
|
||||
int backend;
|
||||
|
||||
/**
|
||||
/**
|
||||
The name of the bridge device to pass to the network script.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
const char *bridge;
|
||||
const char *bridge;
|
||||
|
||||
/**
|
||||
/**
|
||||
The ip address to configure the virtal network device with.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
const char *ip;
|
||||
const char *ip;
|
||||
|
||||
/**
|
||||
/**
|
||||
The mac address to use for the virtual network device.
|
||||
|
||||
Required.
|
||||
*/
|
||||
uint8_t mac[6];
|
||||
uint8_t mac[6];
|
||||
|
||||
/**
|
||||
/**
|
||||
The path to the network script that is to be used for initializing
|
||||
the network device.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
const char *script;
|
||||
const char *script;
|
||||
|
||||
/**
|
||||
/**
|
||||
The name of the vif. The primary use for this is to allow the user
|
||||
to operate on vifs by name.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
const char *vifname;
|
||||
};
|
||||
const char *vifname;
|
||||
};
|
||||
|
||||
struct xend_domain_live
|
||||
{
|
||||
/**
|
||||
struct xend_domain_live {
|
||||
|
||||
/**
|
||||
true is domain is currently scheduled.
|
||||
*/
|
||||
bool running;
|
||||
bool running;
|
||||
|
||||
/**
|
||||
/**
|
||||
true is domain has crashed.
|
||||
*/
|
||||
bool crashed;
|
||||
bool crashed;
|
||||
|
||||
/**
|
||||
/**
|
||||
true if domain has been shutdown.
|
||||
*/
|
||||
bool poweroff;
|
||||
bool poweroff;
|
||||
|
||||
/**
|
||||
/**
|
||||
true if domain has requested a reboot.
|
||||
*/
|
||||
bool reboot;
|
||||
bool reboot;
|
||||
|
||||
/**
|
||||
/**
|
||||
true if domain has requested a suspend.
|
||||
*/
|
||||
bool suspend;
|
||||
bool suspend;
|
||||
|
||||
/**
|
||||
/**
|
||||
true if domain is blocked on IO
|
||||
*/
|
||||
bool blocked;
|
||||
bool blocked;
|
||||
|
||||
/**
|
||||
/**
|
||||
true if domain has been destroyed but resources are not
|
||||
fully deallocated.
|
||||
*/
|
||||
bool dying;
|
||||
bool dying;
|
||||
|
||||
/**
|
||||
/**
|
||||
true if domain is paused.
|
||||
*/
|
||||
bool paused;
|
||||
bool paused;
|
||||
|
||||
/**
|
||||
/**
|
||||
the amount of time the domain has been running (in seconds)
|
||||
*/
|
||||
double cpu_time;
|
||||
double cpu_time;
|
||||
|
||||
/**
|
||||
/**
|
||||
the wall clock time since the domain was created (in seconds)
|
||||
*/
|
||||
double up_time;
|
||||
double up_time;
|
||||
|
||||
/**
|
||||
/**
|
||||
the time (in seconds since epoch) the domain was created
|
||||
*/
|
||||
double start_time;
|
||||
double start_time;
|
||||
|
||||
/**
|
||||
/**
|
||||
the number of enabled VCPUs
|
||||
*/
|
||||
int online_vcpus;
|
||||
int online_vcpus;
|
||||
|
||||
/**
|
||||
/**
|
||||
the total number of available VCPUs
|
||||
*/
|
||||
int vcpu_avail;
|
||||
int vcpu_avail;
|
||||
|
||||
/**
|
||||
/**
|
||||
the domain id number
|
||||
*/
|
||||
int id;
|
||||
};
|
||||
int id;
|
||||
};
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
Required.
|
||||
*/
|
||||
const char *name;
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
/**
|
||||
The amount of memory to assign to the domain before creation.
|
||||
|
||||
Required.
|
||||
*/
|
||||
uint64_t memory;
|
||||
uint64_t memory;
|
||||
|
||||
/**
|
||||
/**
|
||||
The maximum amount of memory that can be given to the domain
|
||||
while it's running. Please note that a domain can increase its
|
||||
memory on its own while running up to this value.
|
||||
|
||||
Required.
|
||||
*/
|
||||
uint64_t max_memory;
|
||||
uint64_t max_memory;
|
||||
|
||||
/**
|
||||
/**
|
||||
The uuid to use to identify the domain. This is compatible with
|
||||
libuuid's uuid_t and should be able to be used interchangably.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
unsigned char *uuid;
|
||||
unsigned char *uuid;
|
||||
|
||||
/**
|
||||
/**
|
||||
The ssidref to assign to the domain.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
int ssidref;
|
||||
int ssidref;
|
||||
|
||||
/**
|
||||
/**
|
||||
The action to perform when the domain powers off.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
virDomainRestart on_poweroff;
|
||||
virDomainRestart on_poweroff;
|
||||
|
||||
/**
|
||||
/**
|
||||
The action to perform when the domain reboots.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
virDomainRestart on_reboot;
|
||||
virDomainRestart on_reboot;
|
||||
|
||||
/**
|
||||
/**
|
||||
The action to perform when the domain crashes.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
virDomainRestart on_crash;
|
||||
virDomainRestart on_crash;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of VCPUs to assign to the domain.
|
||||
|
||||
Required.
|
||||
*/
|
||||
int vcpus;
|
||||
int vcpus;
|
||||
|
||||
/* FIXME cpus */
|
||||
/* FIXME cpus */
|
||||
|
||||
virDomainKernel image;
|
||||
virDomainKernel image;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of VBDs pointed to be vbds.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
size_t n_vbds;
|
||||
struct xend_device_vbd *vbds;
|
||||
size_t n_vbds;
|
||||
struct xend_device_vbd *vbds;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of IO port ranges pointed to by ioports.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
size_t n_ioports;
|
||||
struct xend_device_ioport *ioports;
|
||||
size_t n_ioports;
|
||||
struct xend_device_ioport *ioports;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of VIFs pointed to be vifs.
|
||||
|
||||
Optional.
|
||||
*/
|
||||
size_t n_vifs;
|
||||
struct xend_device_vif *vifs;
|
||||
size_t n_vifs;
|
||||
struct xend_device_vif *vifs;
|
||||
|
||||
/**
|
||||
/**
|
||||
A pointer to run-time information about the domain.
|
||||
|
||||
Only set by xen_get_domain().
|
||||
*/
|
||||
struct xend_domain_live *live;
|
||||
};
|
||||
struct xend_domain_live *live;
|
||||
};
|
||||
|
||||
enum xend_node_system
|
||||
{
|
||||
XEND_SYSTEM_LINUX = 1,
|
||||
};
|
||||
enum xend_node_system {
|
||||
XEND_SYSTEM_LINUX = 1,
|
||||
};
|
||||
|
||||
struct xend_node
|
||||
{
|
||||
/**
|
||||
struct xend_node {
|
||||
|
||||
/**
|
||||
An enumeration value specifying the host system.
|
||||
*/
|
||||
enum xend_node_system system;
|
||||
enum xend_node_system system;
|
||||
|
||||
/**
|
||||
/**
|
||||
The DNS host name.
|
||||
*/
|
||||
const char *host;
|
||||
const char *host;
|
||||
|
||||
/**
|
||||
/**
|
||||
The dom0 kernel release string.
|
||||
*/
|
||||
const char *release;
|
||||
const char *release;
|
||||
|
||||
/**
|
||||
/**
|
||||
The result of uname -v.
|
||||
*/
|
||||
const char *version;
|
||||
const char *version;
|
||||
|
||||
/**
|
||||
/**
|
||||
The machine type.
|
||||
*/
|
||||
const char *machine;
|
||||
const char *machine;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of physical cpus.
|
||||
*/
|
||||
int nr_cpus;
|
||||
int nr_cpus;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of NUMA nodes.
|
||||
*/
|
||||
int nr_nodes;
|
||||
int nr_nodes;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of sockets per NUMA node.
|
||||
*/
|
||||
int sockets_per_node;
|
||||
int sockets_per_node;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of cores per NUMA socket.
|
||||
*/
|
||||
int cores_per_socket;
|
||||
int cores_per_socket;
|
||||
|
||||
/**
|
||||
/**
|
||||
The number of hyperthreads per core.
|
||||
*/
|
||||
int threads_per_core;
|
||||
int threads_per_core;
|
||||
|
||||
/**
|
||||
/**
|
||||
The clock rating (in megahertz) of each core.
|
||||
*/
|
||||
int cpu_mhz;
|
||||
int cpu_mhz;
|
||||
|
||||
/**
|
||||
/**
|
||||
I honestly don't know what this is.
|
||||
*/
|
||||
const char *hw_caps;
|
||||
const char *hw_caps;
|
||||
|
||||
/**
|
||||
/**
|
||||
The total memory (in bytes).
|
||||
*/
|
||||
uint64_t total_memory;
|
||||
uint64_t total_memory;
|
||||
|
||||
/**
|
||||
/**
|
||||
The free memory (in bytes).
|
||||
*/
|
||||
uint64_t free_memory;
|
||||
uint64_t free_memory;
|
||||
|
||||
/**
|
||||
/**
|
||||
The Xen major version number.
|
||||
*/
|
||||
int xen_major;
|
||||
int xen_major;
|
||||
|
||||
/**
|
||||
/**
|
||||
The Xen minor version number.
|
||||
*/
|
||||
int xen_minor;
|
||||
int xen_minor;
|
||||
|
||||
/**
|
||||
/**
|
||||
The Xen extra version number.
|
||||
*/
|
||||
int xen_extra;
|
||||
int xen_extra;
|
||||
|
||||
/**
|
||||
/**
|
||||
A string descirbing the Xen platform.
|
||||
*/
|
||||
const char *xen_caps;
|
||||
const char *xen_caps;
|
||||
|
||||
/**
|
||||
/**
|
||||
Dunno.
|
||||
*/
|
||||
const char *platform_params;
|
||||
const char *platform_params;
|
||||
|
||||
/**
|
||||
/**
|
||||
The build changeset.
|
||||
*/
|
||||
const char *xen_changeset;
|
||||
const char *xen_changeset;
|
||||
|
||||
/**
|
||||
/**
|
||||
The compiler version.
|
||||
*/
|
||||
const char *cc_compiler;
|
||||
const char *cc_compiler;
|
||||
|
||||
/**
|
||||
/**
|
||||
The user that compiled this binary.
|
||||
*/
|
||||
const char *cc_compile_by;
|
||||
const char *cc_compile_by;
|
||||
|
||||
/**
|
||||
/**
|
||||
The system this binary was built on.
|
||||
*/
|
||||
const char *cc_compile_domain;
|
||||
const char *cc_compile_domain;
|
||||
|
||||
/**
|
||||
/**
|
||||
The date that this binary was built on.
|
||||
*/
|
||||
const char *cc_compile_date;
|
||||
};
|
||||
const char *cc_compile_date;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Setup the connection to the local Xend instance
|
||||
@ -456,7 +455,7 @@ struct xend_node
|
||||
*
|
||||
* Make sure to call xend_cleanup().
|
||||
*/
|
||||
int xend_setup(virConnectPtr conn);
|
||||
int xend_setup(virConnectPtr conn);
|
||||
|
||||
/**
|
||||
* \brief Setup the connection to a xend instance via TCP
|
||||
@ -470,7 +469,7 @@ int xend_setup(virConnectPtr conn);
|
||||
*
|
||||
* Make sure to call xend_cleanup().
|
||||
*/
|
||||
int xend_setup_tcp(virConnectPtr xend, const char *host, int port);
|
||||
int xend_setup_tcp(virConnectPtr xend, const char *host, int port);
|
||||
|
||||
/**
|
||||
* \brief Setup the connection to xend instance via a Unix domain socket
|
||||
@ -483,7 +482,7 @@ int xend_setup_tcp(virConnectPtr xend, const char *host, int port);
|
||||
*
|
||||
* Make sure to call xend_cleanup().
|
||||
*/
|
||||
int xend_setup_unix(virConnectPtr xend, const char *path);
|
||||
int xend_setup_unix(virConnectPtr xend, const char *path);
|
||||
|
||||
/**
|
||||
* \brief Delete a previously allocated Xend instance
|
||||
@ -493,7 +492,7 @@ int xend_setup_unix(virConnectPtr xend, const char *path);
|
||||
* initialized with xend_setup[_{tcp, unix}] is no longer needed
|
||||
* to free the associated resources.
|
||||
*/
|
||||
void xend_cleanup(virConnectPtr xend);
|
||||
void xend_cleanup(virConnectPtr xend);
|
||||
|
||||
/**
|
||||
* \brief Blocks until a domain's devices are initialized
|
||||
@ -507,7 +506,7 @@ void xend_cleanup(virConnectPtr xend);
|
||||
* invalid filename, the error won't occur until after this function
|
||||
* returns.
|
||||
*/
|
||||
int xend_wait_for_devices(virConnectPtr xend, const char *name);
|
||||
int xend_wait_for_devices(virConnectPtr xend, const char *name);
|
||||
|
||||
/**
|
||||
* \brief Pause a domain
|
||||
@ -518,7 +517,7 @@ int xend_wait_for_devices(virConnectPtr xend, const char *name);
|
||||
* This method will make sure that Xen does not schedule the domain
|
||||
* anymore until after xend_unpause() has been called.
|
||||
*/
|
||||
int xend_pause(virConnectPtr xend, const char *name);
|
||||
int xend_pause(virConnectPtr xend, const char *name);
|
||||
|
||||
/**
|
||||
* \brief Unpause a domain
|
||||
@ -529,7 +528,7 @@ int xend_pause(virConnectPtr xend, const char *name);
|
||||
* This method will allow a paused domain (the result of xen_pause())
|
||||
* to be scheduled in the future.
|
||||
*/
|
||||
int xend_unpause(virConnectPtr xend, const char *name);
|
||||
int xend_unpause(virConnectPtr xend, const char *name);
|
||||
|
||||
/**
|
||||
* \brief Unpause a domain
|
||||
@ -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
|
||||
@ -551,7 +551,7 @@ int xend_rename(virConnectPtr xend, const char *oldname, const char *name);
|
||||
*
|
||||
* This method simulates the pressing of a SYSRQ sequence.
|
||||
*/
|
||||
int xend_sysrq(virConnectPtr xend, const char *name, const char *key);
|
||||
int xend_sysrq(virConnectPtr xend, const char *name, const char *key);
|
||||
|
||||
/**
|
||||
* \brief Request a domain to reboot
|
||||
@ -563,7 +563,7 @@ int xend_sysrq(virConnectPtr xend, const char *name, const char *key);
|
||||
* a request and the domain may ignore it. It will return immediately
|
||||
* after queuing the request.
|
||||
*/
|
||||
int xend_reboot(virConnectPtr xend, const char *name);
|
||||
int xend_reboot(virConnectPtr xend, const char *name);
|
||||
|
||||
/**
|
||||
* \brief Request a domain to shutdown
|
||||
@ -575,7 +575,7 @@ int xend_reboot(virConnectPtr xend, const char *name);
|
||||
* a request and the domain may ignore it. It will return immediately
|
||||
* after queuing the request.
|
||||
*/
|
||||
int xend_shutdown(virConnectPtr xend, const char *name);
|
||||
int xend_shutdown(virConnectPtr xend, const char *name);
|
||||
|
||||
/**
|
||||
* \brief Destroy a domain
|
||||
@ -589,7 +589,7 @@ int xend_shutdown(virConnectPtr xend, const char *name);
|
||||
* dying and will go away completely once all of the resources have been
|
||||
* unmapped (usually from the backend devices).
|
||||
*/
|
||||
int xend_destroy(virConnectPtr xend, const char *name);
|
||||
int xend_destroy(virConnectPtr xend, const char *name);
|
||||
|
||||
/**
|
||||
* \brief Save a domain to the disk
|
||||
@ -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
|
||||
@ -612,7 +613,7 @@ int xend_save(virConnectPtr xend, const char *name, const char *filename);
|
||||
*
|
||||
* This method will restore a domain saved to disk by xend_save().
|
||||
*/
|
||||
int xend_restore(virConnectPtr xend, const char *filename);
|
||||
int xend_restore(virConnectPtr xend, const char *filename);
|
||||
|
||||
/**
|
||||
* \brief Obtain a list of currently running domains
|
||||
@ -622,7 +623,7 @@ int xend_restore(virConnectPtr xend, const char *filename);
|
||||
* This method will return an array of names of currently running
|
||||
* domains. The memory should be released will a call to free().
|
||||
*/
|
||||
char **xend_get_domains(virConnectPtr xend);
|
||||
char **xend_get_domains(virConnectPtr xend);
|
||||
|
||||
/**
|
||||
* \brief Create a new domain
|
||||
@ -634,7 +635,7 @@ char **xend_get_domains(virConnectPtr xend);
|
||||
* domain will be paused after creation and must be unpaused with
|
||||
* xend_unpause() to begin execution.
|
||||
*/
|
||||
int xend_create(virConnectPtr xend, const struct xend_domain *info);
|
||||
int xend_create(virConnectPtr xend, const struct xend_domain *info);
|
||||
|
||||
/**
|
||||
* \brief Create a new domain
|
||||
@ -646,7 +647,7 @@ int xend_create(virConnectPtr xend, const struct xend_domain *info);
|
||||
* domain will be paused after creation and must be unpaused with
|
||||
* xend_unpause() to begin execution.
|
||||
*/
|
||||
int xend_create_sexpr(virConnectPtr xend, const char *sexpr);
|
||||
int xend_create_sexpr(virConnectPtr xend, const char *sexpr);
|
||||
|
||||
/**
|
||||
* \brief Set the maximum memory for a domain
|
||||
@ -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
|
||||
@ -692,9 +695,9 @@ int xend_set_memory(virConnectPtr xend, const char *name, uint64_t value);
|
||||
* rather, one should use xend_wait_for_devices() to block until the device
|
||||
* has been successfully attached.
|
||||
*/
|
||||
int xend_vbd_create(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vbd *vbd);
|
||||
int xend_vbd_create(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vbd *vbd);
|
||||
|
||||
/**
|
||||
* \brief Destroy a virtual block device
|
||||
@ -708,9 +711,9 @@ int xend_vbd_create(virConnectPtr xend,
|
||||
* should use xend_wait_for_devices() to block until the device has been
|
||||
* successfully detached.
|
||||
*/
|
||||
int xend_vbd_destroy(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vbd *vbd);
|
||||
int xend_vbd_destroy(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vbd *vbd);
|
||||
|
||||
/**
|
||||
* \brief Create a virtual network device
|
||||
@ -724,9 +727,9 @@ int xend_vbd_destroy(virConnectPtr xend,
|
||||
* rather, one should use xend_wait_for_devices() to network until the device
|
||||
* has been successfully attached.
|
||||
*/
|
||||
int xend_vif_create(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vif *vif);
|
||||
int xend_vif_create(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vif *vif);
|
||||
|
||||
/**
|
||||
* \brief Destroy a virtual network device
|
||||
@ -740,9 +743,9 @@ int xend_vif_create(virConnectPtr xend,
|
||||
* rather, one should use xend_wait_for_devices() to network until the device
|
||||
* has been successfully detached.
|
||||
*/
|
||||
int xend_vif_destroy(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vif *vif);
|
||||
int xend_vif_destroy(virConnectPtr xend,
|
||||
const char *name,
|
||||
const struct xend_device_vif *vif);
|
||||
|
||||
/**
|
||||
* \brief Lookup information about a domain
|
||||
@ -754,8 +757,8 @@ int xend_vif_destroy(virConnectPtr xend,
|
||||
* it in the form of a struct xend_domain. This should be
|
||||
* free()'d when no longer needed.
|
||||
*/
|
||||
struct xend_domain *xend_get_domain(virConnectPtr xend,
|
||||
const char *name);
|
||||
struct xend_domain *xend_get_domain(virConnectPtr xend,
|
||||
const char *name);
|
||||
|
||||
/**
|
||||
* \brief Lookup the id of a domain
|
||||
@ -766,9 +769,8 @@ 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);
|
||||
int xend_get_domain_ids(virConnectPtr xend,
|
||||
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
|
||||
@ -790,7 +791,7 @@ int xend_get_domain_info(virDomainPtr domain,
|
||||
* This method returns information about the physical host
|
||||
* machine running Xen.
|
||||
*/
|
||||
struct xend_node *xend_get_node(virConnectPtr xend);
|
||||
struct xend_node *xend_get_node(virConnectPtr xend);
|
||||
|
||||
/**
|
||||
* \brief Shutdown physical host machine
|
||||
@ -799,7 +800,7 @@ struct xend_node *xend_get_node(virConnectPtr xend);
|
||||
*
|
||||
* This method shuts down the physical machine running Xen.
|
||||
*/
|
||||
int xend_node_shutdown(virConnectPtr xend);
|
||||
int xend_node_shutdown(virConnectPtr xend);
|
||||
|
||||
/**
|
||||
* \brief Restarts physical host machine
|
||||
@ -808,7 +809,7 @@ int xend_node_shutdown(virConnectPtr xend);
|
||||
*
|
||||
* This method restarts the physical machine running Xen.
|
||||
*/
|
||||
int xend_node_restart(virConnectPtr xend);
|
||||
int xend_node_restart(virConnectPtr xend);
|
||||
|
||||
/**
|
||||
* \brief Return hypervisor debugging messages
|
||||
@ -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
|
||||
@ -832,7 +831,7 @@ int xend_dmesg(virConnectPtr xend,
|
||||
* This function will clear the debugging message ring queue
|
||||
* in the hypervisor.
|
||||
*/
|
||||
int xend_dmesg_clear(virConnectPtr xend);
|
||||
int xend_dmesg_clear(virConnectPtr xend);
|
||||
|
||||
/**
|
||||
* \brief Obtain the Xend log 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.
|
||||
@ -856,9 +853,8 @@ int xend_log(virConnectPtr xend,
|
||||
*
|
||||
* Provide an XML description of the domain.
|
||||
*/
|
||||
char *xend_get_domain_xml(virDomainPtr domain);
|
||||
char *xend_get_domain_xml(virDomainPtr domain);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
31
src/xml.h
31
src/xml.h
@ -16,26 +16,19 @@ extern "C" {
|
||||
*
|
||||
* A buffer structure.
|
||||
*/
|
||||
typedef struct _virBuffer virBuffer;
|
||||
typedef virBuffer *virBufferPtr;
|
||||
struct _virBuffer {
|
||||
char *content; /* The buffer content UTF8 */
|
||||
unsigned int use; /* The buffer size used */
|
||||
unsigned int size; /* The buffer size */
|
||||
};
|
||||
typedef struct _virBuffer virBuffer;
|
||||
typedef virBuffer *virBufferPtr;
|
||||
struct _virBuffer {
|
||||
char *content; /* The buffer content UTF8 */
|
||||
unsigned int use; /* The buffer size used */
|
||||
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__ */
|
||||
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __VIR_XML_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user