* 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:
Daniel Veillard 2006-03-15 12:13:25 +00:00
parent cda69700a0
commit 247cf7a3b2
15 changed files with 2297 additions and 2131 deletions

View File

@ -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

View File

@ -53,14 +53,16 @@ struct _virHashTable {
* Calculate the hash key
*/
static unsigned long
virHashComputeKey(virHashTablePtr table, const char *name) {
virHashComputeKey(virHashTablePtr table, const char *name)
{
unsigned long value = 0L;
char ch;
if (name != NULL) {
value += 30 * (*name);
while ((ch = *name++) != 0) {
value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
value =
value ^ ((value << 5) + (value >> 3) + (unsigned long) ch);
}
}
return (value % table->size);
@ -75,7 +77,8 @@ virHashComputeKey(virHashTablePtr table, const char *name) {
* Returns the newly created object, or NULL if an error occured.
*/
virHashTablePtr
virHashCreate(int size) {
virHashCreate(int size)
{
virHashTablePtr table;
if (size <= 0)
@ -88,11 +91,11 @@ virHashCreate(int size) {
table->table = malloc(size * sizeof(virHashEntry));
if (table->table) {
memset(table->table, 0, size * sizeof(virHashEntry));
return(table);
return (table);
}
free(table);
}
return(NULL);
return (NULL);
}
/**
@ -105,40 +108,42 @@ 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);
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)
* a new entry needs to allocated and data copied into it from
* the main table. So instead, we run through the array twice, first
* copying all the elements in the main array (where we can't get
* conflicts) and then the rest, so we only free (and don't allocate)
*/
for (i = 0; i < oldsize; i++) {
if (oldtable[i].valid == 0)
@ -179,10 +184,11 @@ virHashGrow(virHashTablePtr table, int size) {
#ifdef DEBUG_GROW
xmlGenericError(xmlGenericErrorContext,
"virHashGrow : from %d to %d, %d elems\n", oldsize, size, nbElem);
"virHashGrow : from %d to %d, %d elems\n", oldsize,
size, nbElem);
#endif
return(0);
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;
@ -205,7 +212,7 @@ virHashFree(virHashTablePtr table, virHashDeallocator f) {
return;
if (table->table) {
nbElems = table->nbElems;
for(i = 0; (i < table->size) && (nbElems > 0); i++) {
for (i = 0; (i < table->size) && (nbElems > 0); i++) {
iter = &(table->table[i]);
if (iter->valid == 0)
continue;
@ -242,14 +249,14 @@ 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.
@ -261,11 +268,11 @@ virHashAddEntry(virHashTablePtr table, const char *name,
for (insert = &(table->table[key]); insert->next != NULL;
insert = insert->next) {
if (!strcmp(insert->name, name))
return(-1);
return (-1);
len++;
}
if (!strcmp(insert->name, name))
return(-1);
return (-1);
}
if (insert == NULL) {
@ -273,7 +280,7 @@ virHashAddEntry(virHashTablePtr table, const char *name,
} else {
entry = malloc(sizeof(virHashEntry));
if (entry == NULL)
return(-1);
return (-1);
}
entry->name = strdup(name);
@ -290,7 +297,7 @@ virHashAddEntry(virHashTablePtr table, const char *name,
if (len > MAX_HASH_LEN)
virHashGrow(table, MAX_HASH_LEN * table->size);
return(0);
return (0);
}
/**
@ -308,13 +315,14 @@ 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.
@ -329,14 +337,14 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
if (f)
f(insert->payload, insert->name);
insert->payload = userdata;
return(0);
return (0);
}
}
if (!strcmp(insert->name, name)) {
if (f)
f(insert->payload, insert->name);
insert->payload = userdata;
return(0);
return (0);
}
}
@ -345,7 +353,7 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
} else {
entry = malloc(sizeof(virHashEntry));
if (entry == NULL)
return(-1);
return (-1);
}
entry->name = strdup(name);
@ -358,7 +366,7 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
if (insert != NULL) {
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);
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,26 +429,28 @@ 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)
if (entry->name)
free(entry->name);
if(prev) {
if (prev) {
prev->next = entry->next;
free(entry);
} else {
@ -446,16 +458,16 @@ virHashRemoveEntry(virHashTablePtr table, const char *name,
entry->valid = 0;
} else {
entry = entry->next;
memcpy(&(table->table[key]), entry, sizeof(virHashEntry));
memcpy(&(table->table[key]), entry,
sizeof(virHashEntry));
free(entry);
}
}
table->nbElems--;
return(0);
return (0);
}
prev = entry;
}
return(-1);
return (-1);
}
}

View File

@ -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,39 +32,35 @@ 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,
int virHashAddEntry(virHashTablePtr table,
const char *name, void *userdata);
int virHashUpdateEntry(virHashTablePtr table,
const char *name,
void *userdata);
int virHashUpdateEntry(virHashTablePtr table,
const char *name,
void *userdata,
virHashDeallocator f);
void *userdata, virHashDeallocator f);
/*
* Remove an entry from the hash table.
*/
int virHashRemoveEntry(virHashTablePtr table,
const char *name,
virHashDeallocator f);
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
}

View File

@ -74,7 +74,7 @@ extern "C" {
*
* Internal structure associated to a connection
*/
struct _virConnect {
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 */
@ -94,7 +94,7 @@ struct _virConnect {
/* misc */
virHashTablePtr domains; /* hash table for known domains */
int flags; /* a set of connection flags */
};
};
/**
* virDomainFlags:
@ -102,16 +102,16 @@ struct _virConnect {
* a set of special flag values associated to the domain
*/
enum {
enum {
DOMAIN_IS_SHUTDOWN = (1 << 0) /* the domain is being shutdown */
} virDomainFlags;
} virDomainFlags;
/**
* _virDomain:
*
* Internal structure associated to a domain
*/
struct _virDomain {
struct _virDomain {
unsigned int magic; /* specific value to check */
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the domain external name */
@ -119,17 +119,16 @@ struct _virDomain {
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,
void __virRaiseError(virConnectPtr conn,
virDomainPtr dom,
int domain,
int code,
@ -137,15 +136,10 @@ void __virRaiseError (virConnectPtr conn,
const char *str1,
const char *str2,
const char *str3,
int int1,
int int2,
const char *msg,
...);
const char * __virErrorMsg (virErrorNumber error,
const char *info);
int int1, int int2, const char *msg, ...);
const char *__virErrorMsg(virErrorNumber error, const char *info);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __VIR_INTERNAL_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,8 @@
* Handle an error in the S-Expression code
*/
static void
virSexprError(virErrorNumber error, const char *info) {
virSexprError(virErrorNumber error, const char *info)
{
const char *errmsg;
if (error == VIR_ERR_OK)
@ -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,7 +220,7 @@ 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:
@ -237,7 +238,8 @@ sexpr2string(struct sexpr * sexpr, char *buffer, size_t n_buffer)
if (tmp == 0)
goto error;
ret += tmp;
tmp = sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
tmp =
sexpr2string(sexpr->car, buffer + ret, n_buffer - ret);
if (tmp == 0)
goto error;
ret += tmp;
@ -264,11 +266,11 @@ sexpr2string(struct sexpr * sexpr, char *buffer, size_t n_buffer)
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);
}
/**
@ -346,7 +348,8 @@ _string2sexpr(const char *buffer, size_t * end)
ret->value = strndup(start, ptr - start);
if (ret->value == NULL) {
virSexprError(VIR_ERR_NO_MEMORY, "failed to copy a string");
virSexprError(VIR_ERR_NO_MEMORY,
"failed to copy a string");
}
if (*ptr == '\'')
@ -360,7 +363,8 @@ _string2sexpr(const char *buffer, size_t * end)
ret->value = strndup(start, ptr - start);
if (ret->value == NULL) {
virSexprError(VIR_ERR_NO_MEMORY, "failed to copy a string");
virSexprError(VIR_ERR_NO_MEMORY,
"failed to copy a string");
}
}
@ -373,9 +377,9 @@ _string2sexpr(const char *buffer, size_t * end)
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) {

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -17,8 +17,8 @@
#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 */
{ 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 */
/*
@ -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;
@ -283,7 +294,8 @@ void
__virRaiseError(virConnectPtr conn, virDomainPtr dom,
int domain, int code, virErrorLevel level,
const char *str1, const char *str2, const char *str3,
int int1, int int2, const char *msg, ...) {
int int1, int int2, const char *msg, ...)
{
virErrorPtr to = &lastErr;
void *userData = virUserData;
virErrorFunc handler = virErrorHandler;
@ -352,12 +364,13 @@ __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);
return (NULL);
case VIR_ERR_INTERNAL_ERROR:
if (info != NULL)
errmsg = "internal error %s";
@ -470,6 +483,5 @@ __virErrorMsg(virErrorNumber error, const char *info) {
errmsg = "missing devices informations for %s";
break;
}
return(errmsg);
return (errmsg);
}

View File

@ -23,8 +23,7 @@
#include <xen/xen.h>
#ifndef __LINUX_PUBLIC_PRIVCMD_H__
typedef struct hypercall_struct
{
typedef struct hypercall_struct {
unsigned long op;
unsigned long arg[5];
} hypercall_t;
@ -45,7 +44,8 @@ typedef struct hypercall_struct
* Handle an error at the xend daemon interface
*/
static void
virXenError(virErrorNumber error, const char *info, int value) {
virXenError(virErrorNumber error, const char *info, int value)
{
const char *errmsg;
if (error == VIR_ERR_OK)
@ -53,8 +53,7 @@ virXenError(virErrorNumber error, const char *info, int value) {
errmsg = __virErrorMsg(error, info);
__virRaiseError(NULL, NULL, VIR_FROM_XEN, error, VIR_ERR_ERROR,
errmsg, info, NULL, value, 0, errmsg, info,
value);
errmsg, info, NULL, value, 0, errmsg, info, value);
}
/**
@ -65,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);
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 (-1);
return(0);
return (0);
}
/**
@ -148,7 +152,8 @@ xenHypervisorDoOp(int handle, dom0_op_t *op) {
* Returns the hypervisor running version or 0 in case of error.
*/
unsigned long
xenHypervisorGetVersion(int handle) {
xenHypervisorGetVersion(int handle)
{
int ret;
unsigned int cmd;
hypercall_t hc;
@ -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);
}

View File

@ -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,21 +21,17 @@
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 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);
dom0_getdomaininfo_t * info);
int xenHypervisorSetMaxMemory(int handle,
int domain, unsigned long memory);
#ifdef __cplusplus
}

View File

@ -67,7 +67,8 @@ struct xend {
* Handle an error at the xend daemon interface
*/
static void
virXendError(virConnectPtr conn, virErrorNumber error, const char *info) {
virXendError(virConnectPtr conn, virErrorNumber error, const char *info)
{
const char *errmsg;
if (error == VIR_ERR_OK)
@ -87,8 +88,8 @@ virXendError(virConnectPtr conn, virErrorNumber error, const char *info) {
* Handle an error at the xend daemon interface
*/
static void
virXendErrorInt(virConnectPtr conn, virErrorNumber error,
int val) {
virXendErrorInt(virConnectPtr conn, virErrorNumber error, int val)
{
const char *errmsg;
if (error == VIR_ERR_OK)
@ -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 */
@ -185,7 +186,7 @@ wr_sync(int fd, void *buffer, size_t size, int do_read)
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
"faid to read from Xen Daemon");
return(-1);
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;
@ -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);
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")); */
}
@ -1175,7 +1177,7 @@ 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 ... */
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1);
return (-1);
}
return xend_op(xend, old, "op", "rename", "name", new, NULL);
}
@ -1195,7 +1197,7 @@ xend_reboot(virConnectPtr xend, const char *name)
if ((xend == NULL) || (name == NULL)) {
/* 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);
}
@ -1216,10 +1218,9 @@ xend_shutdown(virConnectPtr xend, const char *name)
if ((xend == NULL) || (name == NULL)) {
/* 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);
}
/**
@ -1238,7 +1239,7 @@ 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 ... */
virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1);
return (-1);
}
return xend_op(xend, name, "op", "sysrq", "key", key, NULL);
}
@ -1260,7 +1261,7 @@ xend_destroy(virConnectPtr xend, const char *name)
if ((xend == NULL) || (name == NULL)) {
/* 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);
}
@ -1285,7 +1286,7 @@ xend_save(virConnectPtr xend, const char *name, const char *filename)
if ((xend == NULL) || (filename == NULL)) {
/* 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);
}
@ -1307,7 +1308,7 @@ xend_restore(virConnectPtr xend, const char *filename)
if ((xend == NULL) || (filename == NULL)) {
/* 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);
@ -1508,7 +1509,7 @@ xend_create_sexpr(virConnectPtr xend, const char *sexpr)
/* this should be caught at the interface but ... */
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
"Failed to urlencode the create S-Expr");
return(-1);
return (-1);
}
ret = xend_op(xend, "", "op", "create", "config", ptr, NULL);
@ -1798,7 +1799,7 @@ sexpr_to_xend_domain_info(struct sexpr *root, virDomainInfoPtr info)
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;
@ -1822,7 +1823,7 @@ sexpr_to_xend_domain_info(struct sexpr *root, virDomainInfoPtr info)
}
info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000;
info->nrVirtCpu = sexpr_int(root, "domain/vcpus");
return(0);
return (0);
}
/**
@ -1915,7 +1916,8 @@ sexpr_to_xend_domain(struct sexpr *root)
_for_i = _for_i->cdr, node = _for_i->car) {
if (sexpr_lookup(node, "device/vbd")) {
dom->vbds[i].dev = sexpr_strcpy(&ptr, node, "device/vbd/dev");
dom->vbds[i].uname = sexpr_strcpy(&ptr, node, "device/vbd/uname");
dom->vbds[i].uname =
sexpr_strcpy(&ptr, node, "device/vbd/uname");
dom->vbds[i].backend = sexpr_int(node, "device/vbd/backend");
dom->vbds[i].mode = sexpr_mode(node, "device/vbd/mode");
i++;
@ -1939,7 +1941,7 @@ sexpr_to_xend_domain(struct sexpr *root)
}
}
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);
}
/**
@ -2036,15 +2039,16 @@ xend_get_domain_ids(virConnectPtr xend, const char *domname,
ret = -1;
} else if (uuid != NULL) {
char **ptr = (char **) &uuid;
if (sexpr_uuid(ptr, root, "domain/uuid") == NULL) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
"domain informations incomplete, missing uuid");
}
}
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;
@ -2284,7 +2289,8 @@ xend_parse_sexp_desc(struct sexpr *root) {
if (!memcmp(tmp, "file:", 5)) {
tmp += 5;
virBufferVSprintf(&buf, " <disk type='file'>\n");
virBufferVSprintf(&buf, " <source file='%s'/>\n", tmp);
virBufferVSprintf(&buf, " <source file='%s'/>\n",
tmp);
tmp = sexpr_node(node, "device/vbd/dev");
if (tmp == NULL) {
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
@ -2314,35 +2320,37 @@ xend_parse_sexp_desc(struct sexpr *root) {
} else {
char serial[1000];
TODO
sexpr2string(node, serial, 1000);
TODO sexpr2string(node, serial, 1000);
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
serial);
TODO
}
TODO}
} else if (sexpr_lookup(node, "device/vif")) {
tmp = sexpr_node(node, "device/vif/bridge");
if (tmp != NULL) {
virBufferVSprintf(&buf, " <interface type='bridge'>\n");
virBufferVSprintf(&buf, " <source bridge='%s'/>\n", tmp);
virBufferVSprintf(&buf, " <source bridge='%s'/>\n",
tmp);
tmp = sexpr_node(node, "device/vif/vifname");
if (tmp != NULL)
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
virBufferVSprintf(&buf, " <target dev='%s'/>\n",
tmp);
tmp = sexpr_node(node, "device/vif/mac");
if (tmp != NULL)
virBufferVSprintf(&buf, " <mac address='%s'/>\n", tmp);
virBufferVSprintf(&buf, " <mac address='%s'/>\n",
tmp);
tmp = sexpr_node(node, "device/vif/ip");
if (tmp != NULL)
virBufferVSprintf(&buf, " <ip address='%s'/>\n", tmp);
virBufferVSprintf(&buf, " <ip address='%s'/>\n",
tmp);
tmp = sexpr_node(node, "device/vif/script");
if (tmp != NULL)
virBufferVSprintf(&buf, " <script path='%s'/>\n", tmp);
virBufferVSprintf(&buf, " <script path='%s'/>\n",
tmp);
virBufferAdd(&buf, " </interface>\n", 17);
} else {
char serial[1000];
TODO
sexpr2string(node->car, serial, 1000);
TODO sexpr2string(node->car, serial, 1000);
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
serial);
}
@ -2353,12 +2361,12 @@ xend_parse_sexp_desc(struct sexpr *root) {
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 ... */
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);
}

View File

@ -31,8 +31,8 @@ extern "C" {
/**
This structure represents a virtual block device.
*/
struct xend_device_vbd
{
struct xend_device_vbd {
/**
The domain ID of the backend.
@ -61,13 +61,13 @@ struct xend_device_vbd
Required.
*/
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.
@ -81,13 +81,13 @@ struct xend_device_ioport
Required.
*/
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.
@ -132,10 +132,10 @@ struct xend_device_vif
Optional.
*/
const char *vifname;
};
};
struct xend_domain_live {
struct xend_domain_live
{
/**
true is domain is currently scheduled.
*/
@ -206,14 +206,14 @@ struct xend_domain_live
the domain id number
*/
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.
@ -314,15 +314,14 @@ struct xend_domain
Only set by xen_get_domain().
*/
struct xend_domain_live *live;
};
};
enum xend_node_system
{
enum xend_node_system {
XEND_SYSTEM_LINUX = 1,
};
};
struct xend_node {
struct xend_node
{
/**
An enumeration value specifying the host system.
*/
@ -442,7 +441,7 @@ struct xend_node
The date that this binary was built on.
*/
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,7 +695,7 @@ 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,
int xend_vbd_create(virConnectPtr xend,
const char *name,
const struct xend_device_vbd *vbd);
@ -708,7 +711,7 @@ 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,
int xend_vbd_destroy(virConnectPtr xend,
const char *name,
const struct xend_device_vbd *vbd);
@ -724,7 +727,7 @@ 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,
int xend_vif_create(virConnectPtr xend,
const char *name,
const struct xend_device_vif *vif);
@ -740,7 +743,7 @@ 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,
int xend_vif_destroy(virConnectPtr xend,
const char *name,
const struct xend_device_vif *vif);
@ -754,7 +757,7 @@ 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,
struct xend_domain *xend_get_domain(virConnectPtr xend,
const char *name);
/**
@ -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

189
src/xml.c
View File

@ -32,7 +32,8 @@
* Handle an error at the xend daemon interface
*/
static void
virXMLError(virErrorNumber error, const char *info, int value) {
virXMLError(virErrorNumber error, const char *info, int value)
{
const char *errmsg;
if (error == VIR_ERR_OK)
@ -40,8 +41,7 @@ virXMLError(virErrorNumber error, const char *info, int value) {
errmsg = __virErrorMsg(error, info);
__virRaiseError(NULL, NULL, VIR_FROM_XML, error, VIR_ERR_ERROR,
errmsg, info, NULL, value, 0, errmsg, info,
value);
errmsg, info, NULL, value, 0, errmsg, info, value);
}
/**
@ -54,23 +54,26 @@ virXMLError(virErrorNumber error, const char *info, int value) {
* Returns the new available space or -1 in case of error
*/
static int
virBufferGrow(virBufferPtr buf, unsigned int len) {
virBufferGrow(virBufferPtr buf, unsigned int len)
{
int size;
char *newbuf;
if (buf == NULL) return(-1);
if (len + buf->use < buf->size) return(0);
if (buf == NULL)
return (-1);
if (len + buf->use < buf->size)
return (0);
size = buf->use + len + 1000;
newbuf = (char *) realloc(buf->content, size);
if (newbuf == NULL) {
virXMLError(VIR_ERR_NO_MEMORY, "growing buffer", size);
return(-1);
return (-1);
}
buf->content = newbuf;
buf->size = size;
return(buf->size - buf->use);
return (buf->size - buf->use);
}
/**
@ -85,28 +88,30 @@ virBufferGrow(virBufferPtr buf, unsigned int len) {
* Returns 0 successful, -1 in case of internal or API error.
*/
int
virBufferAdd(virBufferPtr buf, const char *str, int len) {
virBufferAdd(virBufferPtr buf, const char *str, int len)
{
unsigned int needSize;
if ((str == NULL) || (buf == NULL)) {
return -1;
}
if (len == 0) return 0;
if (len == 0)
return 0;
if (len < 0)
len = strlen(str);
needSize = buf->use + len + 2;
if (needSize > buf->size){
if (!virBufferGrow(buf, needSize)){
return(-1);
if (needSize > buf->size) {
if (!virBufferGrow(buf, needSize)) {
return (-1);
}
}
memmove(&buf->content[buf->use], str, len);
buf->use += len;
buf->content[buf->use] = 0;
return(0);
return (0);
}
/**
@ -120,12 +125,13 @@ virBufferAdd(virBufferPtr buf, const char *str, int len) {
* Returns 0 successful, -1 in case of internal or API error.
*/
int
virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
virBufferVSprintf(virBufferPtr buf, const char *format, ...)
{
int size, count;
va_list locarg, argptr;
if ((format == NULL) || (buf == NULL)) {
return(-1);
return (-1);
}
size = buf->size - buf->use - 1;
va_start(argptr, format);
@ -135,7 +141,7 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
buf->content[buf->use] = 0;
va_end(locarg);
if (virBufferGrow(buf, 1000) < 0) {
return(-1);
return (-1);
}
size = buf->size - buf->use - 1;
va_copy(locarg, argptr);
@ -143,15 +149,17 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
va_end(locarg);
buf->use += count;
buf->content[buf->use] = 0;
return(0);
return (0);
}
#if 0
/*
* This block of function are now implemented by a xend poll in
* xend_internal.c instead of querying the Xen store, code is kept
* for reference of in case Xend may not be available in the future ...
*/
/**
* virDomainGetXMLDevice:
* @domain: a domain object
@ -165,7 +173,8 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
*/
static char *
virDomainGetXMLDeviceInfo(virDomainPtr domain, const char *sub,
long dev, const char *name) {
long dev, const char *name)
{
char s[256];
unsigned int len = 0;
@ -187,12 +196,13 @@ virDomainGetXMLDeviceInfo(virDomainPtr domain, const char *sub,
* Returns 0 in case of success, -1 in case of failure
*/
static int
virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev) {
virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev)
{
char *type, *val;
type = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "type");
if (type == NULL)
return(-1);
return (-1);
if (!strcmp(type, "file")) {
virBufferVSprintf(buf, " <disk type='file'>\n");
val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "params");
@ -230,12 +240,12 @@ virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev) {
}
virBufferAdd(buf, " </disk>\n", 12);
} else {
TODO
fprintf(stderr, "Don't know how to handle device type %s\n", type);
TODO fprintf(stderr, "Don't know how to handle device type %s\n",
type);
}
free(type);
return(0);
return (0);
}
/**
@ -248,7 +258,8 @@ virDomainGetXMLDevice(virDomainPtr domain, virBufferPtr buf, long dev) {
* Returns 0 in case of success, -1 in case of failure
*/
static int
virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf) {
virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf)
{
int ret = -1;
unsigned int num, i;
long id;
@ -257,7 +268,7 @@ virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf) {
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain))
return(-1);
return (-1);
conn = domain->conn;
@ -269,7 +280,7 @@ virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf) {
if (list == NULL)
goto done;
for (i = 0;i < num;i++) {
for (i = 0; i < num; i++) {
id = strtol(list[i], &endptr, 10);
if ((endptr == list[i]) || (*endptr != 0)) {
ret = -1;
@ -278,11 +289,11 @@ virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf) {
virDomainGetXMLDevice(domain, buf, id);
}
done:
done:
if (list != NULL)
free(list);
return(ret);
return (ret);
}
/**
@ -297,7 +308,8 @@ done:
* Returns 0 in case of success, -1 in case of failure
*/
static int
virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev) {
virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev)
{
char *type, *val;
type = virDomainGetXMLDeviceInfo(domain, "vif", dev, "bridge");
@ -331,7 +343,7 @@ virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev) {
}
free(type);
return(0);
return (0);
}
/**
@ -344,7 +356,8 @@ virDomainGetXMLInterface(virDomainPtr domain, virBufferPtr buf, long dev) {
* Returns 0 in case of success, -1 in case of failure
*/
static int
virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf) {
virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf)
{
int ret = -1;
unsigned int num, i;
long id;
@ -353,7 +366,7 @@ virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf) {
virConnectPtr conn;
if (!VIR_IS_CONNECTED_DOMAIN(domain))
return(-1);
return (-1);
conn = domain->conn;
@ -365,7 +378,7 @@ virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf) {
if (list == NULL)
goto done;
for (i = 0;i < num;i++) {
for (i = 0; i < num; i++) {
id = strtol(list[i], &endptr, 10);
if ((endptr == list[i]) || (*endptr != 0)) {
ret = -1;
@ -374,11 +387,11 @@ virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf) {
virDomainGetXMLInterface(domain, buf, id);
}
done:
done:
if (list != NULL)
free(list);
return(ret);
return (ret);
}
@ -394,15 +407,16 @@ done:
* Returns 0 in case of success, -1 in case of failure
*/
static int
virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf) {
virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf)
{
char *vm, *str;
if (!VIR_IS_DOMAIN(domain))
return(-1);
return (-1);
vm = virDomainGetVM(domain);
if (vm == NULL)
return(-1);
return (-1);
virBufferAdd(buf, " <os>\n", 7);
str = virDomainGetVMInfo(domain, vm, "image/ostype");
@ -430,7 +444,7 @@ virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf) {
virBufferAdd(buf, " </os>\n", 8);
free(vm);
return(0);
return (0);
}
/**
@ -445,28 +459,30 @@ virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf) {
* the caller must free() the returned value.
*/
char *
virDomainGetXMLDesc(virDomainPtr domain, int flags) {
virDomainGetXMLDesc(virDomainPtr domain, int flags)
{
char *ret = NULL;
virBuffer buf;
virDomainInfo info;
if (!VIR_IS_DOMAIN(domain))
return(NULL);
return (NULL);
if (flags != 0)
return(NULL);
return (NULL);
if (virDomainGetInfo(domain, &info) < 0)
return(NULL);
return (NULL);
ret = malloc(1000);
if (ret == NULL)
return(NULL);
return (NULL);
buf.content = ret;
buf.size = 1000;
buf.use = 0;
virBufferVSprintf(&buf, "<domain type='xen' id='%d'>\n",
virDomainGetID(domain));
virBufferVSprintf(&buf, " <name>%s</name>\n", virDomainGetName(domain));
virBufferVSprintf(&buf, " <name>%s</name>\n",
virDomainGetName(domain));
virDomainGetXMLBoot(domain, &buf);
virBufferVSprintf(&buf, " <memory>%lu</memory>\n", info.maxMem);
virBufferVSprintf(&buf, " <vcpu>%d</vcpu>\n", (int) info.nrVirtCpu);
@ -477,7 +493,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) {
virBufferAdd(&buf, "</domain>\n", 10);
buf.content[buf.use] = 0;
return(ret);
return (ret);
}
#endif
@ -495,7 +511,8 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) {
* Returns 0 in case of success, -1 in case of error.
*/
static int
virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf)
{
xmlNodePtr cur, txt;
const xmlChar *type = NULL;
const xmlChar *root = NULL;
@ -506,7 +523,8 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
if ((type == NULL) && (xmlStrEqual(cur->name, BAD_CAST "type"))) {
if ((type == NULL)
&& (xmlStrEqual(cur->name, BAD_CAST "type"))) {
txt = cur->children;
if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
type = txt->content;
@ -537,22 +555,23 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
if ((type != NULL) && (!xmlStrEqual(type, BAD_CAST "linux"))) {
/* VIR_ERR_OS_TYPE */
virXMLError(VIR_ERR_OS_TYPE, (const char *) type, 0);
return(-1);
return (-1);
}
virBufferAdd(buf, "(linux ", 7);
if (kernel == NULL) {
virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
return(-1);
return (-1);
}
virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel);
if (initrd != NULL)
virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
if (root == NULL) {
const xmlChar *base, *tmp;
/* need to extract root info from command line */
if (cmdline == NULL) {
virXMLError(VIR_ERR_NO_ROOT, (const char *) cmdline, 0);
return(-1);
return (-1);
}
base = cmdline;
while (*base != 0) {
@ -563,16 +582,19 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
}
base++;
}
while ((*base == ' ') || (*base == '\t')) base++;
while ((*base == ' ') || (*base == '\t'))
base++;
if (*base == '=') {
base++;
while ((*base == ' ') || (*base == '\t')) base++;
while ((*base == ' ') || (*base == '\t'))
base++;
}
tmp = base;
while ((*tmp != 0) && (*tmp != ' ') && (*tmp != '\t')) tmp++;
while ((*tmp != 0) && (*tmp != ' ') && (*tmp != '\t'))
tmp++;
if (tmp == base) {
virXMLError(VIR_ERR_NO_ROOT, (const char *) cmdline, 0);
return(-1);
return (-1);
}
root = xmlStrndup(base, tmp - base);
virBufferVSprintf(buf, "(root '%s')", (const char *) root);
@ -584,7 +606,7 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
virBufferVSprintf(buf, "(args '%s')", (const char *) cmdline);
}
virBufferAdd(buf, ")", 1);
return(0);
return (0);
}
/**
@ -600,7 +622,8 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) {
* Returns 0 in case of success, -1 in case of error.
*/
static int
virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf)
{
xmlNodePtr cur;
xmlChar *type = NULL;
xmlChar *source = NULL;
@ -610,8 +633,10 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
type = xmlGetProp(node, BAD_CAST "type");
if (type != NULL) {
if (xmlStrEqual(type, BAD_CAST "file")) typ = 0;
else if (xmlStrEqual(type, BAD_CAST "block")) typ = 1;
if (xmlStrEqual(type, BAD_CAST "file"))
typ = 0;
else if (xmlStrEqual(type, BAD_CAST "block"))
typ = 1;
xmlFree(type);
}
cur = node->children;
@ -639,13 +664,13 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
if (target != NULL)
xmlFree(target);
return(-1);
return (-1);
}
if (target == NULL) {
virXMLError(VIR_ERR_NO_TARGET, (const char *) source, 0);
if (source != NULL)
xmlFree(source);
return(-1);
return (-1);
}
virBufferAdd(buf, "(vbd ", 5);
if (target[0] == '/')
@ -668,7 +693,7 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
virBufferAdd(buf, ")", 1);
xmlFree(target);
xmlFree(source);
return(0);
return (0);
}
/**
@ -684,7 +709,8 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf) {
* Returns 0 in case of success, -1 in case of error.
*/
static int
virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf) {
virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf)
{
xmlNodePtr cur;
xmlChar *type = NULL;
xmlChar *source = NULL;
@ -694,8 +720,10 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf) {
type = xmlGetProp(node, BAD_CAST "type");
if (type != NULL) {
if (xmlStrEqual(type, BAD_CAST "bridge")) typ = 0;
else if (xmlStrEqual(type, BAD_CAST "ethernet")) typ = 1;
if (xmlStrEqual(type, BAD_CAST "bridge"))
typ = 0;
else if (xmlStrEqual(type, BAD_CAST "ethernet"))
typ = 1;
xmlFree(type);
}
cur = node->children;
@ -738,7 +766,7 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf) {
xmlFree(source);
if (script != NULL)
xmlFree(script);
return(0);
return (0);
}
/**
@ -754,7 +782,8 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf) {
* the caller must free() the returned value.
*/
char *
virDomainParseXMLDesc(const char *xmldesc, char **name) {
virDomainParseXMLDesc(const char *xmldesc, char **name)
{
xmlDocPtr xml = NULL;
xmlNodePtr node;
char *ret = NULL, *nam = NULL;
@ -768,7 +797,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
*name = NULL;
ret = malloc(1000);
if (ret == NULL)
return(NULL);
return (NULL);
buf.content = ret;
buf.size = 1000;
buf.use = 0;
@ -819,6 +848,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
virBufferVSprintf(&buf, "(memory 128)(maxmem 128)");
} else {
unsigned long mem = (obj->floatval / 1024);
virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)", mem, mem);
}
xmlXPathFreeObject(obj);
@ -829,6 +859,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
virBufferVSprintf(&buf, "(vcpus 1)");
} else {
unsigned int cpu = (unsigned int) obj->floatval;
virBufferVSprintf(&buf, "(vcpus %u)", cpu);
}
xmlXPathFreeObject(obj);
@ -837,8 +868,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
virBufferAdd(&buf, "(image ", 7);
obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt);
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
(obj->nodesetval == NULL) ||
(obj->nodesetval->nodeNr != 1)) {
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr != 1)) {
virXMLError(VIR_ERR_NO_OS, nam, 0);
goto error;
}
@ -852,12 +882,11 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
/* analyze of the devices */
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
(obj->nodesetval == NULL) ||
(obj->nodesetval->nodeNr < 1)) {
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 1)) {
virXMLError(VIR_ERR_NO_DEVICE, nam, 0);
goto error;
}
for (i = 0;i < obj->nodesetval->nodeNr;i++) {
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
virBufferAdd(&buf, "(device ", 8);
res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf);
if (res != 0) {
@ -869,9 +898,10 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
for (i = 0;i < obj->nodesetval->nodeNr;i++) {
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
virBufferAdd(&buf, "(device ", 8);
res = virDomainParseXMLIfDesc(obj->nodesetval->nodeTab[i], &buf);
res =
virDomainParseXMLIfDesc(obj->nodesetval->nodeTab[i], &buf);
if (res != 0) {
goto error;
}
@ -890,9 +920,9 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
if (name != NULL)
*name = nam;
return(ret);
return (ret);
error:
error:
if (nam != NULL)
free(nam);
if (name != NULL)
@ -905,6 +935,5 @@ error:
xmlFreeDoc(xml);
if (ret != NULL)
free(ret);
return(NULL);
return (NULL);
}

View File

@ -16,26 +16,19 @@ extern "C" {
*
* A buffer structure.
*/
typedef struct _virBuffer virBuffer;
typedef virBuffer *virBufferPtr;
struct _virBuffer {
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__ */