提交 247cf7a3 编写于 作者: D Daniel Veillard

* 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
上级 cda69700
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
......
......@@ -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;
/*
* 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;
}
iter = oldtable[i].next;
while (iter) {
next = iter->next;
/*
* 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;
}
#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);
}
}
......@@ -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 */
/* 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 */
/* misc */
virHashTablePtr domains; /* hash table for known domains */
int flags; /* a set of connection flags */
};
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 */
/* 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 */
};
/**
* 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);
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);
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);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __VIR_INTERNAL_H__ */
#endif /* __cplusplus */
#endif /* __VIR_INTERNAL_H__ */
此差异已折叠。
......@@ -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) {
......
......@@ -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
此差异已折叠。
此差异已折叠。
......@@ -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__ */
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -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 */
};
int virBufferAdd (virBufferPtr buf,
const char *str,
int len);
int virBufferVSprintf (virBufferPtr buf,
const char *format,
...);
char * virDomainParseXMLDesc (const char *xmldesc,
char **name);
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);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __VIR_XML_H__ */
#endif /* __cplusplus */
#endif /* __VIR_XML_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册