]> xenbits.xensource.com Git - libvirt.git/commitdiff
* src/hash.c src/hash.h src/internal.h src/libvirt.c src/sexpr.c
authorDaniel Veillard <veillard@redhat.com>
Wed, 15 Mar 2006 12:13:25 +0000 (12:13 +0000)
committerDaniel Veillard <veillard@redhat.com>
Wed, 15 Mar 2006 12:13:25 +0000 (12:13 +0000)
  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

15 files changed:
ChangeLog
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

index c43c02e5156a5abba95f2211bbec6f23db8f33b0..0fcd4ee26d353a56ab380cff0c4080342ccaa156 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 
index 5d992292e046f0c63bc76ad16682443e94326161..052f49e0fc89fbf318c33244491d2e0dfe5ea252 100644 (file)
@@ -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);
     }
 }
-
index fa1534f47e82b740ae92221ce8b1f036ccbd7942..5077580184bc7c5c093fc8540b64f9fa9de1e4ee 100644 (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,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__ */
index 1df8c388bfb4329fa50377e46fefe072875d8129..7993df006b372daa169a23bfa2fc7328ab426a51 100644 (file)
@@ -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__ */
index 0bda0b0e7d6d1da3224a5a1d3f1d03799d1a6695..236b9514d56fb179439f1d58ec7d8e4db794318b 100644 (file)
  * Handle an error at the connection level
  */
 static void
-virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info) {
+virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info)
+{
     const char *errmsg;
-    
+
     if (error == VIR_ERR_OK)
         return;
 
@@ -62,10 +63,12 @@ virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info) {
  * Handle an error at the connection level
  */
 static void
-virLibDomainError(virDomainPtr domain, virErrorNumber error, const char *info) {
+virLibDomainError(virDomainPtr domain, virErrorNumber error,
+                  const char *info)
+{
     virConnectPtr conn = NULL;
     const char *errmsg;
-    
+
     if (error == VIR_ERR_OK)
         return;
 
@@ -93,30 +96,32 @@ virLibDomainError(virDomainPtr domain, virErrorNumber error, const char *info) {
  *       @typeVer have the format major * 1,000,000 + minor * 1,000 + release.
  */
 int
-virGetVersion(unsigned long *libVer, const char *type, unsigned long *typeVer) {
+virGetVersion(unsigned long *libVer, const char *type,
+              unsigned long *typeVer)
+{
     if (libVer == NULL)
-        return(-1);
+        return (-1);
     *libVer = LIBVIR_VERSION_NUMBER;
 
     if (typeVer != NULL) {
-       if ((type == NULL) || (!strcasecmp(type, "Xen"))) {
-           if ((DOM0_INTERFACE_VERSION & 0xFFFF0000) == (0xAAAA0000)) {
-               /* one time glitch hopefully ! */
+        if ((type == NULL) || (!strcasecmp(type, "Xen"))) {
+            if ((DOM0_INTERFACE_VERSION & 0xFFFF0000) == (0xAAAA0000)) {
+                /* one time glitch hopefully ! */
                 *typeVer = 2 * 1000000 +
-                          ((DOM0_INTERFACE_VERSION >> 8) & 0xFF) * 1000 +
-                          (DOM0_INTERFACE_VERSION & 0xFF);
-           } else {
-               *typeVer = (DOM0_INTERFACE_VERSION >> 24) * 1000000 +
-                          ((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
-                          (DOM0_INTERFACE_VERSION & 0xFFFF);
-           }
-       } else {
-           *typeVer = 0;
-           virLibConnError(NULL, VIR_ERR_NO_SUPPORT, "type");
-           return(-1);
-       }
-    }
-    return(0);
+                    ((DOM0_INTERFACE_VERSION >> 8) & 0xFF) * 1000 +
+                    (DOM0_INTERFACE_VERSION & 0xFF);
+            } else {
+                *typeVer = (DOM0_INTERFACE_VERSION >> 24) * 1000000 +
+                    ((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
+                    (DOM0_INTERFACE_VERSION & 0xFFFF);
+            }
+        } else {
+            *typeVer = 0;
+            virLibConnError(NULL, VIR_ERR_NO_SUPPORT, "type");
+            return (-1);
+        }
+    }
+    return (0);
 }
 
 /**
@@ -129,15 +134,16 @@ virGetVersion(unsigned long *libVer, const char *type, unsigned long *typeVer) {
  * Returns a pointer to the hypervisor connection or NULL in case of error
  */
 virConnectPtr
-virConnectOpen(const char *name) {
+virConnectOpen(const char *name)
+{
     virConnectPtr ret = NULL;
     int handle = -1;
     struct xs_handle *xshandle = NULL;
 
     /* we can only talk to the local Xen supervisor ATM */
     if (name != NULL) {
-        virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name); 
-        return(NULL);
+        virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
+        return (NULL);
     }
 
     handle = xenHypervisorOpen(0);
@@ -146,7 +152,7 @@ virConnectOpen(const char *name) {
     }
     xshandle = xs_daemon_open();
     if (xshandle == NULL) {
-        virLibConnError(NULL, VIR_ERR_NO_CONNECT, "XenStore"); 
+        virLibConnError(NULL, VIR_ERR_NO_CONNECT, "XenStore");
         goto failed;
     }
 
@@ -166,15 +172,15 @@ virConnectOpen(const char *name) {
     if (ret->domains == NULL)
         goto failed;
 
-    return(ret);
-failed:
+    return (ret);
+  failed:
     if (handle >= 0)
         xenHypervisorClose(handle);
     if (xshandle != NULL)
         xs_daemon_close(xshandle);
     if (ret != NULL)
         free(ret);
-    return(NULL);
+    return (NULL);
 }
 
 /**
@@ -188,7 +194,8 @@ failed:
  * Returns a pointer to the hypervisor connection or NULL in case of error
  */
 virConnectPtr
-virConnectOpenReadOnly(const char *name) {
+virConnectOpenReadOnly(const char *name)
+{
     int method = 0;
     int handle;
     virConnectPtr ret = NULL;
@@ -196,8 +203,8 @@ virConnectOpenReadOnly(const char *name) {
 
     /* we can only talk to the local Xen supervisor ATM */
     if (name != NULL) {
-        virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name); 
-        return(NULL);
+        virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
+        return (NULL);
     }
 
     handle = xenHypervisorOpen(1);
@@ -227,22 +234,22 @@ virConnectOpenReadOnly(const char *name) {
     ret->flags = VIR_CONNECT_RO;
     if (method == 0) {
         virLibConnError(NULL, VIR_ERR_NO_CONNECT,
-                       "could not connect to Xen Daemon nor Xen Store");
+                        "could not connect to Xen Daemon nor Xen Store");
         goto failed;
     }
 
-    return(ret);
-failed:
+    return (ret);
+  failed:
     if (handle >= 0)
         xenHypervisorClose(handle);
     if (xshandle != NULL)
         xs_daemon_close(xshandle);
     if (ret != NULL) {
         if (ret->domains != NULL)
-           virHashFree(ret->domains, NULL);
+            virHashFree(ret->domains, NULL);
         free(ret);
     }
-    return(NULL);
+    return (NULL);
 }
 
 /**
@@ -256,17 +263,18 @@ failed:
  * Returns -1 if the check failed, 0 if successful or not possible to check
  */
 static int
-virConnectCheckStoreID(virConnectPtr conn, int id) {
+virConnectCheckStoreID(virConnectPtr conn, int id)
+{
     if (conn->handle >= 0) {
-       dom0_getdomaininfo_t dominfo;
-       int tmp;
+        dom0_getdomaininfo_t dominfo;
+        int tmp;
 
-       dominfo.domain = id;
-       tmp = xenHypervisorGetDomainInfo(conn->handle, id, &dominfo);
-       if (tmp < 0)
-           return(-1);
+        dominfo.domain = id;
+        tmp = xenHypervisorGetDomainInfo(conn->handle, id, &dominfo);
+        if (tmp < 0)
+            return (-1);
     }
-    return(0);
+    return (0);
 }
 
 /**
@@ -278,8 +286,9 @@ virConnectCheckStoreID(virConnectPtr conn, int id) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 static int
-virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
-    return(virDomainFree(domain));
+virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED)
+{
+    return (virDomainFree(domain));
 }
 
 /**
@@ -294,20 +303,21 @@ virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED) {
  * Returns 0 in case of success or -1 in case of error.
  */
 int
-virConnectClose(virConnectPtr conn) {
+virConnectClose(virConnectPtr conn)
+{
     xend_cleanup(conn);
     if (!VIR_IS_CONNECT(conn))
-        return(-1);
+        return (-1);
     virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
     conn->magic = -1;
     if (conn->xshandle != NULL)
-       xs_daemon_close(conn->xshandle);
+        xs_daemon_close(conn->xshandle);
     conn->xshandle = NULL;
     if (conn->handle != -1)
-       xenHypervisorClose(conn->handle);
+        xenHypervisorClose(conn->handle);
     conn->handle = -1;
     free(conn);
-    return(0);
+    return (0);
 }
 
 /**
@@ -319,12 +329,14 @@ virConnectClose(virConnectPtr conn) {
  * Returns NULL in case of error, a static zero terminated string otherwise.
  */
 const char *
-virConnectGetType(virConnectPtr conn) {
+virConnectGetType(virConnectPtr conn)
+{
     if (!VIR_IS_CONNECT(conn)) {
-        virLibConnError(conn, VIR_ERR_INVALID_CONN, "in virConnectGetType");
-        return(NULL);
+        virLibConnError(conn, VIR_ERR_INVALID_CONN,
+                        "in virConnectGetType");
+        return (NULL);
     }
-    return("Xen");
+    return ("Xen");
 }
 
 /**
@@ -341,28 +353,29 @@ virConnectGetType(virConnectPtr conn) {
  *    @hvVer value is major * 1,000,000 + minor * 1,000 + release
  */
 int
-virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) {
+virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
+{
     unsigned long ver;
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
-    
+
     if (hvVer == NULL) {
         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
-    
+
     /* this can't be extracted from the Xenstore */
     if (conn->handle < 0) {
         *hvVer = 0;
-        return(0);
+        return (0);
     }
 
     ver = xenHypervisorGetVersion(conn->handle);
     *hvVer = (ver >> 16) * 1000000 + (ver & 0xFFFF) * 1000;
-    return(0);
+    return (0);
 }
 
 /**
@@ -376,7 +389,8 @@ virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) {
  * Returns the number of domain found or -1 in case of error
  */
 int
-virConnectListDomains(virConnectPtr conn, int *ids, int maxids) {
+virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
+{
     int ret = -1;
     unsigned int num, i;
     long id;
@@ -384,45 +398,45 @@ virConnectListDomains(virConnectPtr conn, int *ids, int maxids) {
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
-    
+
     if ((ids == NULL) || (maxids <= 0)) {
         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
-    
+
     idlist = xend_get_domains(conn);
     if (idlist != NULL) {
-        for (ret = 0,i = 0;(idlist[i] != NULL) && (ret < maxids);i++) {
-           id = xend_get_domain_ids(conn, idlist[i], NULL);
-           if (id >= 0)
-               ids[ret++] = (int) id;
-       }
-       goto done;
+        for (ret = 0, i = 0; (idlist[i] != NULL) && (ret < maxids); i++) {
+            id = xend_get_domain_ids(conn, idlist[i], NULL);
+            if (id >= 0)
+                ids[ret++] = (int) id;
+        }
+        goto done;
     }
     if (conn->xshandle != NULL) {
-       idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
-       if (idlist == NULL)
-           goto done;
-
-       for (ret = 0,i = 0;(i < num) && (ret < maxids);i++) {
-           id = strtol(idlist[i], &endptr, 10);
-           if ((endptr == idlist[i]) || (*endptr != 0)) {
-               ret = -1;
-               goto done;
-           }
-           if (virConnectCheckStoreID(conn, (int) id) < 0)
-               continue;
-           ids[ret++] = (int) id;
-       }
-    }
-
-done:
+        idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
+        if (idlist == NULL)
+            goto done;
+
+        for (ret = 0, i = 0; (i < num) && (ret < maxids); i++) {
+            id = strtol(idlist[i], &endptr, 10);
+            if ((endptr == idlist[i]) || (*endptr != 0)) {
+                ret = -1;
+                goto done;
+            }
+            if (virConnectCheckStoreID(conn, (int) id) < 0)
+                continue;
+            ids[ret++] = (int) id;
+        }
+    }
+
+  done:
     if (idlist != NULL)
         free(idlist);
 
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -434,14 +448,15 @@ done:
  * Returns the number of domain found or -1 in case of error
  */
 int
-virConnectNumOfDomains(virConnectPtr conn) {
+virConnectNumOfDomains(virConnectPtr conn)
+{
     int ret = -1;
     unsigned int num;
     char **idlist = NULL;
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
 
     /* 
@@ -453,18 +468,18 @@ virConnectNumOfDomains(virConnectPtr conn) {
 
         ret = 0;
         while (*tmp != NULL) {
-           tmp++;
-           ret++;
-       }
-       
+            tmp++;
+            ret++;
+        }
+
     } else if (conn->xshandle != NULL) {
         idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
-       if (idlist) {
-           free(idlist);
-           ret = num;
-       }
+        if (idlist) {
+            free(idlist);
+            ret = num;
+        }
     }
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -480,9 +495,10 @@ virConnectNumOfDomains(virConnectPtr conn) {
  * Returns a new domain object or NULL in case of failure
  */
 virDomainPtr
-virDomainCreateLinux(virConnectPtr conn, 
+virDomainCreateLinux(virConnectPtr conn,
                      const char *xmlDesc,
-                    unsigned int flags ATTRIBUTE_UNUSED) {
+                     unsigned int flags ATTRIBUTE_UNUSED)
+{
     int ret;
     char *sexpr;
     char *name = NULL;
@@ -490,52 +506,52 @@ virDomainCreateLinux(virConnectPtr conn,
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
     if (xmlDesc == NULL) {
         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(NULL);
+        return (NULL);
     }
 
     sexpr = virDomainParseXMLDesc(xmlDesc, &name);
     if ((sexpr == NULL) || (name == NULL)) {
         if (sexpr != NULL)
-           free(sexpr);
+            free(sexpr);
         if (name != NULL)
-           free(name);
+            free(name);
 
-        return(NULL);
+        return (NULL);
     }
 
     ret = xend_create_sexpr(conn, sexpr);
     free(sexpr);
     if (ret != 0) {
         fprintf(stderr, "Failed to create domain %s\n", name);
-       goto error;
+        goto error;
     }
 
     ret = xend_wait_for_devices(conn, name);
     if (ret != 0) {
         fprintf(stderr, "Failed to get devices for domain %s\n", name);
-       xend_destroy(conn, name);
-       goto error;
+        xend_destroy(conn, name);
+        goto error;
     }
 
     ret = xend_unpause(conn, name);
     if (ret != 0) {
         fprintf(stderr, "Failed to resume new domain %s\n", name);
-       xend_destroy(conn, name);
-       goto error;
+        xend_destroy(conn, name);
+        goto error;
     }
 
     dom = virDomainLookupByName(conn, name);
     free(name);
 
-    return(dom);
-error:
+    return (dom);
+  error:
     if (name != NULL)
         free(name);
-    return(NULL);
+    return (NULL);
 }
 
 /**
@@ -549,10 +565,12 @@ error:
  * Returns a string which must be freed by the caller or NULL in case of error
  */
 static char **
-virConnectDoStoreList(virConnectPtr conn, const char *path, unsigned int *nb) {
+virConnectDoStoreList(virConnectPtr conn, const char *path,
+                      unsigned int *nb)
+{
     if ((conn == NULL) || (conn->xshandle == NULL) || (path == NULL) ||
         (nb == NULL))
-        return(NULL);
+        return (NULL);
 
     return xs_directory(conn->xshandle, 0, path, nb);
 }
@@ -567,14 +585,15 @@ virConnectDoStoreList(virConnectPtr conn, const char *path, unsigned int *nb) {
  * Returns a string which must be freed by the caller or NULL in case of error
  */
 static char *
-virDomainDoStoreQuery(virDomainPtr domain, const char *path) {
+virDomainDoStoreQuery(virDomainPtr domain, const char *path)
+{
     char s[256];
     unsigned int len = 0;
-    
+
     if (!VIR_IS_CONNECTED_DOMAIN(domain))
-       return(NULL);
+        return (NULL);
     if (domain->conn->xshandle == NULL)
-        return(NULL);
+        return (NULL);
 
     snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path);
     s[255] = 0;
@@ -595,17 +614,18 @@ virDomainDoStoreQuery(virDomainPtr domain, const char *path) {
  */
 static int
 virDomainDoStoreWrite(virDomainPtr domain, const char *path,
-                      const char *value) {
+                      const char *value)
+{
     char s[256];
 
     int ret = -1;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain))
-       return(-1);
+        return (-1);
     if (domain->conn->xshandle == NULL)
-        return(-1);
+        return (-1);
     if (domain->conn->flags & VIR_CONNECT_RO)
-        return(-1);
+        return (-1);
 
     snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path);
     s[255] = 0;
@@ -613,7 +633,7 @@ virDomainDoStoreWrite(virDomainPtr domain, const char *path,
     if (xs_write(domain->conn->xshandle, 0, &s[0], value, strlen(value)))
         ret = 0;
 
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -630,19 +650,18 @@ virDomainGetVM(virDomainPtr domain)
     char *vm;
     char query[200];
     unsigned int len;
-    
+
     if (!VIR_IS_CONNECTED_DOMAIN(domain))
-       return(NULL);
+        return (NULL);
     if (domain->conn->xshandle == NULL)
-        return(NULL);
-    
-    snprintf(query, 199, "/local/domain/%d/vm", 
-             virDomainGetID(domain));
+        return (NULL);
+
+    snprintf(query, 199, "/local/domain/%d/vm", virDomainGetID(domain));
     query[199] = 0;
 
     vm = xs_read(domain->conn->xshandle, 0, &query[0], &len);
 
-    return(vm);
+    return (vm);
 }
 
 /**
@@ -657,23 +676,23 @@ virDomainGetVM(virDomainPtr domain)
  * Returns the new string or NULL in case of error
  */
 char *
-virDomainGetVMInfo(virDomainPtr domain, const char *vm, 
-                   const char *name) {
+virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name)
+{
     char s[256];
     char *ret = NULL;
     unsigned int len = 0;
-    
+
     if (!VIR_IS_CONNECTED_DOMAIN(domain))
-       return(NULL);
-    if (domain->conn->xshandle==NULL)
-       return(NULL);
-    
+        return (NULL);
+    if (domain->conn->xshandle == NULL)
+        return (NULL);
+
     snprintf(s, 255, "%s/%s", vm, name);
     s[255] = 0;
 
     ret = xs_read(domain->conn->xshandle, 0, &s[0], &len);
 
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -686,7 +705,8 @@ virDomainGetVMInfo(virDomainPtr domain, const char *vm,
  * Returns a new domain object or NULL in case of failure
  */
 virDomainPtr
-virDomainLookupByID(virConnectPtr conn, int id) {
+virDomainLookupByID(virConnectPtr conn, int id)
+{
     char *path = NULL;
     virDomainPtr ret;
     char *name = NULL;
@@ -694,34 +714,34 @@ virDomainLookupByID(virConnectPtr conn, int id) {
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
     if (id < 0) {
         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(NULL);
+        return (NULL);
     }
 
     /* lookup is easier with the Xen store so try it first */
     if (conn->xshandle != NULL) {
-       path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
+        path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
     }
     /* fallback to xend API then */
     if (path == NULL) {
         char **names = xend_get_domains(conn);
-       char **tmp = names;
-       int ident;
-
-       if (names != NULL) {
-           while (*tmp != NULL) {
-               ident = xend_get_domain_ids(conn, *tmp, &uuid[0]);
-               if (ident == id) {
-                   name = strdup(*tmp);
-                   break;
-               }
-               tmp++;
-           }
-           free(names);
-       }
+        char **tmp = names;
+        int ident;
+
+        if (names != NULL) {
+            while (*tmp != NULL) {
+                ident = xend_get_domain_ids(conn, *tmp, &uuid[0]);
+                if (ident == id) {
+                    name = strdup(*tmp);
+                    break;
+                }
+                tmp++;
+            }
+            free(names);
+        }
     }
 
     ret = (virDomainPtr) malloc(sizeof(virDomain));
@@ -734,7 +754,7 @@ virDomainLookupByID(virConnectPtr conn, int id) {
     ret->handle = id;
     ret->path = path;
     if (name == NULL) {
-       ret->name = virDomainDoStoreQuery(ret, "name");
+        ret->name = virDomainDoStoreQuery(ret, "name");
     } else {
         ret->name = name;
         memcpy(&ret->uuid[0], uuid, 16);
@@ -743,15 +763,15 @@ virDomainLookupByID(virConnectPtr conn, int id) {
         goto error;
     }
 
-    return(ret);
-error:
+    return (ret);
+  error:
     if (ret != NULL)
-       free(path);
+        free(path);
     if (path != NULL)
-       free(path);
+        free(path);
     if (path != NULL)
-       free(path);
-    return(NULL);
+        free(path);
+    return (NULL);
 }
 
 /**
@@ -764,7 +784,8 @@ error:
  * Returns a new domain object or NULL in case of failure
  */
 virDomainPtr
-virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) {
+virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
+{
     virDomainPtr ret;
     char *name = NULL;
     char **names;
@@ -774,39 +795,39 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) {
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
     if (uuid == NULL) {
         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(NULL);
+        return (NULL);
     }
     names = xend_get_domains(conn);
     tmp = names;
 
     if (names == NULL) {
-        TODO /* try to fallback to xenstore lookup */
-       return(NULL);
+        TODO                    /* try to fallback to xenstore lookup */
+            return (NULL);
     }
     while (*tmp != NULL) {
-       id = xend_get_domain_ids(conn, *tmp, &ident[0]);
-       if (id >= 0) {
-           if (!memcmp(uuid, ident, 16)) {
-               name = strdup(*tmp);
-               break;
-           }
-       }
-       tmp++;
+        id = xend_get_domain_ids(conn, *tmp, &ident[0]);
+        if (id >= 0) {
+            if (!memcmp(uuid, ident, 16)) {
+                name = strdup(*tmp);
+                break;
+            }
+        }
+        tmp++;
     }
     free(names);
 
     if (name == NULL)
-        return(NULL);
+        return (NULL);
 
     ret = (virDomainPtr) malloc(sizeof(virDomain));
     if (ret == NULL) {
         if (name != NULL)
-           free(name);
-       return(NULL);
+            free(name);
+        return (NULL);
     }
     memset(ret, 0, sizeof(virDomain));
     ret->magic = VIR_DOMAIN_MAGIC;
@@ -816,7 +837,7 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) {
     ret->path = 0;
     memcpy(ret->uuid, uuid, 16);
 
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -829,7 +850,8 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) {
  * Returns a new domain object or NULL in case of failure
  */
 virDomainPtr
-virDomainLookupByName(virConnectPtr conn, const char *name) {
+virDomainLookupByName(virConnectPtr conn, const char *name)
+{
     virDomainPtr ret = NULL;
     unsigned int num, i, len;
     long id = -1;
@@ -841,20 +863,20 @@ virDomainLookupByName(virConnectPtr conn, const char *name) {
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
     if (name == NULL) {
         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(NULL);
+        return (NULL);
     }
 
     /* try first though Xend */
     xenddomain = xend_get_domain(conn, name);
     if (xenddomain != NULL) {
         id = xenddomain->live->id;
-       uuid = xenddomain->uuid;
-       found = 1;
-       goto do_found;
+        uuid = xenddomain->uuid;
+        found = 1;
+        goto do_found;
     }
 
     /* then though the XenStore */
@@ -863,49 +885,49 @@ virDomainLookupByName(virConnectPtr conn, const char *name) {
         if (idlist == NULL)
             goto done;
 
-        for (i = 0;i < num;i++) {
-             id = strtol(idlist[i], &endptr, 10);
-            if ((endptr == idlist[i]) || (*endptr != 0)) {
-                goto done;
-            }
-            if (virConnectCheckStoreID(conn, (int) id) < 0)
-                continue;
-             snprintf(prop, 199, "/local/domain/%s/name", idlist[i]);
-            prop[199] = 0;
-            tmp = xs_read(conn->xshandle, 0, prop, &len);
-            if (tmp != NULL) {
-                found = !strcmp(name, tmp);
-                free(tmp);
-                if (found)
-                    break;
-            }
+        for (i = 0; i < num; i++) {
+            id = strtol(idlist[i], &endptr, 10);
+            if ((endptr == idlist[i]) || (*endptr != 0)) {
+                goto done;
+            }
+            if (virConnectCheckStoreID(conn, (int) id) < 0)
+                continue;
+            snprintf(prop, 199, "/local/domain/%s/name", idlist[i]);
+            prop[199] = 0;
+            tmp = xs_read(conn->xshandle, 0, prop, &len);
+            if (tmp != NULL) {
+                found = !strcmp(name, tmp);
+                free(tmp);
+                if (found)
+                    break;
+            }
         }
         path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
     }
 
-do_found:
+  do_found:
 
     if (found) {
-       ret = (virDomainPtr) malloc(sizeof(virDomain));
-       if (ret == NULL)
-           goto done;
-       memset(ret, 0, sizeof(virDomain));
-       ret->magic = VIR_DOMAIN_MAGIC;
-       ret->conn = conn;
-       ret->handle = id;
-       ret->path = path;
-       if (uuid != NULL)
-           memcpy(ret->uuid, uuid, 16);
-       ret->name = strdup(name);
-    }
-
-done:
+        ret = (virDomainPtr) malloc(sizeof(virDomain));
+        if (ret == NULL)
+            goto done;
+        memset(ret, 0, sizeof(virDomain));
+        ret->magic = VIR_DOMAIN_MAGIC;
+        ret->conn = conn;
+        ret->handle = id;
+        ret->path = path;
+        if (uuid != NULL)
+            memcpy(ret->uuid, uuid, 16);
+        ret->name = strdup(name);
+    }
+
+  done:
     if (xenddomain != NULL)
-       free(xenddomain);
+        free(xenddomain);
     if (idlist != NULL)
         free(idlist);
 
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -921,12 +943,13 @@ done:
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainDestroy(virDomainPtr domain) {
+virDomainDestroy(virDomainPtr domain)
+{
     int ret;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
 
     /*
@@ -935,15 +958,15 @@ virDomainDestroy(virDomainPtr domain) {
     ret = xend_destroy(domain->conn, domain->name);
     if (ret == 0) {
         virDomainFree(domain);
-       return(0);
+        return (0);
     }
 
     ret = xenHypervisorDestroyDomain(domain->conn->handle, domain->handle);
     if (ret < 0)
-        return(-1);
-    
+        return (-1);
+
     virDomainFree(domain);
-    return(0);
+    return (0);
 }
 
 /**
@@ -956,10 +979,11 @@ virDomainDestroy(virDomainPtr domain) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainFree(virDomainPtr domain) {
+virDomainFree(virDomainPtr domain)
+{
     if (!VIR_IS_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
     domain->magic = -1;
     domain->handle = -1;
@@ -968,7 +992,7 @@ virDomainFree(virDomainPtr domain) {
     if (domain->name)
         free(domain->name);
     free(domain);
-    return(0);
+    return (0);
 }
 
 /**
@@ -984,21 +1008,23 @@ virDomainFree(virDomainPtr domain) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainSuspend(virDomainPtr domain) {
+virDomainSuspend(virDomainPtr domain)
+{
     int ret;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
 
     /* first try though the Xen daemon */
     ret = xend_pause(domain->conn, domain->name);
     if (ret == 0)
-        return(0);
+        return (0);
 
     /* then try a direct hypervisor access */
-    return(xenHypervisorPauseDomain(domain->conn->handle, domain->handle));
+    return (xenHypervisorPauseDomain
+            (domain->conn->handle, domain->handle));
 }
 
 /**
@@ -1012,21 +1038,23 @@ virDomainSuspend(virDomainPtr domain) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainResume(virDomainPtr domain) {
+virDomainResume(virDomainPtr domain)
+{
     int ret;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
 
     /* first try though the Xen daemon */
     ret = xend_unpause(domain->conn, domain->name);
     if (ret == 0)
-        return(0);
+        return (0);
 
     /* then try a direct hypervisor access */
-    return(xenHypervisorResumeDomain(domain->conn->handle, domain->handle));
+    return (xenHypervisorResumeDomain
+            (domain->conn->handle, domain->handle));
 }
 
 /**
@@ -1042,17 +1070,18 @@ virDomainResume(virDomainPtr domain) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainSave(virDomainPtr domain, const char *to) {
+virDomainSave(virDomainPtr domain, const char *to)
+{
     int ret;
     char filepath[4096];
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
     if (to == NULL) {
         virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
 
     /*
@@ -1060,23 +1089,23 @@ virDomainSave(virDomainPtr domain, const char *to) {
      * TODO: check for URI when libxml2 is linked in.
      */
     if (to[0] != '/') {
-       unsigned int len, t;
+        unsigned int len, t;
 
-       t = strlen(to);
-       if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
-           return(-1);
-       len = strlen(filepath);
-       /* that should be covered by getcwd() semantic, but be 100% sure */
-       if (len > sizeof(filepath) - (t + 3))
-           return(-1); 
-       filepath[len] = '/';
-       strcpy(&filepath[len + 1], to);
-       to = &filepath[0];
+        t = strlen(to);
+        if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
+            return (-1);
+        len = strlen(filepath);
+        /* that should be covered by getcwd() semantic, but be 100% sure */
+        if (len > sizeof(filepath) - (t + 3))
+            return (-1);
+        filepath[len] = '/';
+        strcpy(&filepath[len + 1], to);
+        to = &filepath[0];
 
     }
 
     ret = xend_save(domain->conn, domain->name, to);
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -1089,17 +1118,18 @@ virDomainSave(virDomainPtr domain, const char *to) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainRestore(virConnectPtr conn, const char *from) {
+virDomainRestore(virConnectPtr conn, const char *from)
+{
     int ret;
     char filepath[4096];
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
     if (from == NULL) {
         virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
 
     /*
@@ -1107,22 +1137,22 @@ virDomainRestore(virConnectPtr conn, const char *from) {
      * TODO: check for URI when libxml2 is linked in.
      */
     if (from[0] != '/') {
-       unsigned int len, t;
-
-       t = strlen(from);
-       if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
-           return(-1);
-       len = strlen(filepath);
-       /* that should be covered by getcwd() semantic, but be 100% sure */
-       if (len > sizeof(filepath) - (t + 3))
-           return(-1); 
-       filepath[len] = '/';
-       strcpy(&filepath[len + 1], from);
-       from = &filepath[0];
-    }
-    
+        unsigned int len, t;
+
+        t = strlen(from);
+        if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
+            return (-1);
+        len = strlen(filepath);
+        /* that should be covered by getcwd() semantic, but be 100% sure */
+        if (len > sizeof(filepath) - (t + 3))
+            return (-1);
+        filepath[len] = '/';
+        strcpy(&filepath[len + 1], from);
+        from = &filepath[0];
+    }
+
     ret = xend_restore(conn, from);
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -1139,20 +1169,21 @@ virDomainRestore(virConnectPtr conn, const char *from) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainShutdown(virDomainPtr domain) {
+virDomainShutdown(virDomainPtr domain)
+{
     int ret;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
-    
+
     /*
      * try first with the xend daemon
      */
     ret = xend_shutdown(domain->conn, domain->name);
     if (ret == 0)
-        return(0);
+        return (0);
 
     /*
      * this is very hackish, the domU kernel probes for a special 
@@ -1162,7 +1193,7 @@ virDomainShutdown(virDomainPtr domain) {
     if (ret == 0) {
         domain->flags |= DOMAIN_IS_SHUTDOWN;
     }
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -1175,12 +1206,13 @@ virDomainShutdown(virDomainPtr domain) {
  * its lifetime will be the same as the domain object.
  */
 const char *
-virDomainGetName(virDomainPtr domain) {
+virDomainGetName(virDomainPtr domain)
+{
     if (!VIR_IS_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
-    return(domain->name);
+    return (domain->name);
 }
 
 /**
@@ -1193,31 +1225,33 @@ virDomainGetName(virDomainPtr domain) {
  * Returns -1 in case of error, 0 in case of success
  */
 int
-virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) {
+virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
+{
     if (!VIR_IS_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
     if (uuid == NULL) {
         virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
 
     if (domain->handle == 0) {
         memset(uuid, 0, 16);
     } else {
-       if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) &&
-           (domain->uuid[2] == 0) && (domain->uuid[3] == 0) &&
-           (domain->uuid[4] == 0) && (domain->uuid[5] == 0) &&
-           (domain->uuid[6] == 0) && (domain->uuid[7] == 0) &&
-           (domain->uuid[8] == 0) && (domain->uuid[9] == 0) &&
-           (domain->uuid[10] == 0) && (domain->uuid[11] == 0) &&
-           (domain->uuid[12] == 0) && (domain->uuid[13] == 0) &&
-           (domain->uuid[14] == 0) && (domain->uuid[15] == 0))
-           xend_get_domain_ids(domain->conn, domain->name, &domain->uuid[0]);
-       memcpy(uuid, &domain->uuid[0], 16);
-    }
-    return(0);
+        if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) &&
+            (domain->uuid[2] == 0) && (domain->uuid[3] == 0) &&
+            (domain->uuid[4] == 0) && (domain->uuid[5] == 0) &&
+            (domain->uuid[6] == 0) && (domain->uuid[7] == 0) &&
+            (domain->uuid[8] == 0) && (domain->uuid[9] == 0) &&
+            (domain->uuid[10] == 0) && (domain->uuid[11] == 0) &&
+            (domain->uuid[12] == 0) && (domain->uuid[13] == 0) &&
+            (domain->uuid[14] == 0) && (domain->uuid[15] == 0))
+            xend_get_domain_ids(domain->conn, domain->name,
+                                &domain->uuid[0]);
+        memcpy(uuid, &domain->uuid[0], 16);
+    }
+    return (0);
 }
 
 /**
@@ -1229,12 +1263,13 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) {
  * Returns the domain ID number or (unsigned int) -1 in case of error
  */
 unsigned int
-virDomainGetID(virDomainPtr domain) {
+virDomainGetID(virDomainPtr domain)
+{
     if (!VIR_IS_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return((unsigned int) -1);
+        return ((unsigned int) -1);
     }
-    return(domain->handle);
+    return (domain->handle);
 }
 
 /**
@@ -1246,23 +1281,24 @@ virDomainGetID(virDomainPtr domain) {
  * Returns the new string or NULL in case of error
  */
 char *
-virDomainGetOSType(virDomainPtr domain) {
+virDomainGetOSType(virDomainPtr domain)
+{
     char *vm, *str = NULL;
-    
+
     if (!VIR_IS_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
-    
+
     vm = virDomainGetVM(domain);
     if (vm) {
-       str = virDomainGetVMInfo(domain, vm, "image/ostype");
-       free(vm);
+        str = virDomainGetVMInfo(domain, vm, "image/ostype");
+        free(vm);
     }
     if (str == NULL)
         str = strdup("linux");
 
-    return(str);
+    return (str);
 }
 
 /**
@@ -1276,33 +1312,35 @@ virDomainGetOSType(virDomainPtr domain) {
  * Returns the memory size in kilobytes or 0 in case of error.
  */
 unsigned long
-virDomainGetMaxMemory(virDomainPtr domain) {
+virDomainGetMaxMemory(virDomainPtr domain)
+{
     unsigned long ret = 0;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(0);
+        return (0);
     }
-    
+
     if (domain->conn->flags & VIR_CONNECT_RO) {
         char *tmp;
 
-       tmp = virDomainDoStoreQuery(domain, "memory/target");
-       if (tmp != NULL) {
-           ret = (unsigned long) atol(tmp);
-           free(tmp);
-       }
+        tmp = virDomainDoStoreQuery(domain, "memory/target");
+        if (tmp != NULL) {
+            ret = (unsigned long) atol(tmp);
+            free(tmp);
+        }
     } else {
         dom0_getdomaininfo_t dominfo;
-       int tmp;
+        int tmp;
 
-       dominfo.domain = domain->handle;
-        tmp = xenHypervisorGetDomainInfo(domain->conn->handle, domain->handle,
-                                        &dominfo);
-       if (tmp >= 0)
-           ret = dominfo.max_pages * 4;
+        dominfo.domain = domain->handle;
+        tmp =
+            xenHypervisorGetDomainInfo(domain->conn->handle,
+                                       domain->handle, &dominfo);
+        if (tmp >= 0)
+            ret = dominfo.max_pages * 4;
     }
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -1318,26 +1356,27 @@ virDomainGetMaxMemory(virDomainPtr domain) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
+virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
+{
     int ret;
     char s[256], v[30];
-    
+
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
     if (memory < 4096) {
         virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
     if (domain->conn->flags & VIR_CONNECT_RO)
-        return(-1);
-    if (domain->conn->xshandle==NULL)
-       return(-1);
+        return (-1);
+    if (domain->conn->xshandle == NULL)
+        return (-1);
     ret = xenHypervisorSetMaxMemory(domain->conn->handle, domain->handle,
                                     memory);
     if (ret < 0)
-        return(-1);
+        return (-1);
 
     /*
      * try to update at the Xenstore level too
@@ -1352,7 +1391,7 @@ virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
     if (!xs_write(domain->conn->xshandle, 0, &s[0], &v[0], strlen(v)))
         ret = -1;
 
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -1367,7 +1406,8 @@ virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
  * Returns 0 in case of success and -1 in case of failure.
  */
 int
-virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
+virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
+{
     int ret;
     char *tmp, **tmp2;
     unsigned int nb_vcpus;
@@ -1376,65 +1416,66 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
     if (info == NULL) {
         virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
-       return(-1);
+        return (-1);
     }
-    
+
     memset(info, 0, sizeof(virDomainInfo));
-    
+
     /*
      * if we have direct access though the hypervisor do a direct call
      */
     if (domain->conn->handle >= 0) {
         dom0_getdomaininfo_t dominfo;
 
-       dominfo.domain = domain->handle;
-        ret = xenHypervisorGetDomainInfo(domain->conn->handle, domain->handle,
-                                        &dominfo);
+        dominfo.domain = domain->handle;
+        ret =
+            xenHypervisorGetDomainInfo(domain->conn->handle,
+                                       domain->handle, &dominfo);
         if (ret < 0)
-           goto xend_info;
-
-       switch (dominfo.flags & 0xFF) {
-           case DOMFLAGS_DYING:
-               info->state = VIR_DOMAIN_SHUTDOWN;
-               break;
-           case DOMFLAGS_SHUTDOWN:
-               info->state = VIR_DOMAIN_SHUTOFF;
-               break;
-           case DOMFLAGS_PAUSED:
-               info->state = VIR_DOMAIN_PAUSED;
-               break;
-           case DOMFLAGS_BLOCKED:
-               info->state = VIR_DOMAIN_BLOCKED;
-               break;
-           case DOMFLAGS_RUNNING:
-               info->state = VIR_DOMAIN_RUNNING;
-               break;
-           default:
-               info->state = VIR_DOMAIN_NONE;
-       }
-
-       /*
-        * the API brings back the cpu time in nanoseconds,
-        * convert to microseconds, same thing convert to
+            goto xend_info;
+
+        switch (dominfo.flags & 0xFF) {
+            case DOMFLAGS_DYING:
+                info->state = VIR_DOMAIN_SHUTDOWN;
+                break;
+            case DOMFLAGS_SHUTDOWN:
+                info->state = VIR_DOMAIN_SHUTOFF;
+                break;
+            case DOMFLAGS_PAUSED:
+                info->state = VIR_DOMAIN_PAUSED;
+                break;
+            case DOMFLAGS_BLOCKED:
+                info->state = VIR_DOMAIN_BLOCKED;
+                break;
+            case DOMFLAGS_RUNNING:
+                info->state = VIR_DOMAIN_RUNNING;
+                break;
+            default:
+                info->state = VIR_DOMAIN_NONE;
+        }
+
+        /*
+         * the API brings back the cpu time in nanoseconds,
+         * convert to microseconds, same thing convert to
          * kilobytes from page counts
-        */
-       info->cpuTime = dominfo.cpu_time;
-       info->memory = dominfo.tot_pages * 4;
-       info->maxMem = dominfo.max_pages * 4;
-       info->nrVirtCpu = dominfo.nr_online_vcpus;
-       return(0);
+         */
+        info->cpuTime = dominfo.cpu_time;
+        info->memory = dominfo.tot_pages * 4;
+        info->maxMem = dominfo.max_pages * 4;
+        info->nrVirtCpu = dominfo.nr_online_vcpus;
+        return (0);
     }
 
-xend_info:
+  xend_info:
     /*
      * try to extract the informations though access to the Xen Daemon
      */
     if (xend_get_domain_info(domain, info) == 0)
-        return(0);
+        return (0);
 
     /*
      * last fallback, try to get the inforamtions from the Xen store
@@ -1442,39 +1483,39 @@ xend_info:
 
     tmp = virDomainDoStoreQuery(domain, "running");
     if (tmp != NULL) {
-       if (tmp[0] == '1')
-           info->state = VIR_DOMAIN_RUNNING;
-       free(tmp);
+        if (tmp[0] == '1')
+            info->state = VIR_DOMAIN_RUNNING;
+        free(tmp);
     } else {
-       info->state = VIR_DOMAIN_NONE;
+        info->state = VIR_DOMAIN_NONE;
     }
     tmp = virDomainDoStoreQuery(domain, "memory/target");
     if (tmp != NULL) {
-       info->memory = atol(tmp);
-       info->maxMem = atol(tmp);
-       free(tmp);
+        info->memory = atol(tmp);
+        info->maxMem = atol(tmp);
+        free(tmp);
     } else {
-       info->memory = 0;
-       info->maxMem = 0;
+        info->memory = 0;
+        info->maxMem = 0;
     }
 #if 0
     /* doesn't seems to work */
     tmp = virDomainDoStoreQuery(domain, "cpu_time");
     if (tmp != NULL) {
-       info->cpuTime = atol(tmp);
-       free(tmp);
+        info->cpuTime = atol(tmp);
+        free(tmp);
     } else {
-       info->cpuTime = 0;
+        info->cpuTime = 0;
     }
 #endif
     snprintf(request, 199, "/local/domain/%d/cpu", domain->handle);
     request[199] = 0;
     tmp2 = virConnectDoStoreList(domain->conn, request, &nb_vcpus);
     if (tmp2 != NULL) {
-       info->nrVirtCpu = nb_vcpus;
-       free(tmp2);
+        info->nrVirtCpu = nb_vcpus;
+        free(tmp2);
     }
-    return(0);
+    return (0);
 }
 
 /**
@@ -1489,15 +1530,16 @@ xend_info:
  *         the caller must free() the returned value.
  */
 char *
-virDomainGetXMLDesc(virDomainPtr domain, int flags) {
+virDomainGetXMLDesc(virDomainPtr domain, int flags)
+{
     if (!VIR_IS_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
     if (flags != 0) {
         virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
 
-    return(xend_get_domain_xml(domain));
+    return (xend_get_domain_xml(domain));
 }
index 105ed3ec5cc46a85429ce303fde968605e3c5c6f..baf034142c5c126d19a81f247d33015508c7a249 100644 (file)
  * 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) {
index c776b2e5dfd551a9fed6f8e003671f6b524a61d8..3026ee54fb34d4127db154d81bfd850263d1e3e6 100644 (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
index faeb4d7e52227edc1145d16ed8b643cf5a010fde..785f544d7ace6ddfe92ca9580fd28aec49474f52 100644 (file)
@@ -11,7 +11,7 @@
  * $Id$
  */
 
-#define _GNU_SOURCE    /* isblank() */
+#define _GNU_SOURCE             /* isblank() */
 
 #include "libvirt.h"
 #include "virterror.h"
@@ -47,10 +47,10 @@ static char *progname;
           ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
 
 typedef enum {
-    VSH_MESG,        /* standard output */
-    VSH_HEADER,      /* header for standard output */
-    VSH_FOOTER,      /* timing, last command state, or whatever */
-    VSH_DEBUG1,      /* debugN where 'N' = level */
+    VSH_MESG,                   /* standard output */
+    VSH_HEADER,                 /* header for standard output */
+    VSH_FOOTER,                 /* timing, last command state, or whatever */
+    VSH_DEBUG1,                 /* debugN where 'N' = level */
     VSH_DEBUG2,
     VSH_DEBUG3,
     VSH_DEBUG4,
@@ -61,7 +61,8 @@ typedef enum {
  * The error handler for virtsh
  */
 static void
-virshErrorHandler(void *unused, virErrorPtr error) {
+virshErrorHandler(void *unused, virErrorPtr error)
+{
     if ((unused != NULL) || (error == NULL))
         return;
 
@@ -94,20 +95,20 @@ virshErrorHandler(void *unused, virErrorPtr error) {
 
 /*
  * vshCmdOptType - command option type 
- */   
+ */
 typedef enum {
-    VSH_OT_NONE = 0,   /* none */
-    VSH_OT_BOOL,       /* boolean option */
-    VSH_OT_STRING,     /* string option */
-    VSH_OT_INT,        /* int option */
-    VSH_OT_DATA        /* string data (as non-option) */
+    VSH_OT_NONE = 0,            /* none */
+    VSH_OT_BOOL,                /* boolean option */
+    VSH_OT_STRING,              /* string option */
+    VSH_OT_INT,                 /* int option */
+    VSH_OT_DATA                 /* string data (as non-option) */
 } vshCmdOptType;
 
 /*
  * Command Option Flags
  */
-#define VSH_OFLAG_NONE    0        /* without flags */
-#define VSH_OFLAG_REQ    (1 << 1)    /* option required */
+#define VSH_OFLAG_NONE    0     /* without flags */
+#define VSH_OFLAG_REQ    (1 << 1)       /* option required */
 
 /* dummy */
 typedef struct __vshControl vshControl;
@@ -116,89 +117,94 @@ typedef struct __vshCmd vshCmd;
 /*
  * vshCmdInfo -- information about command
  */
-typedef struct  {
-    const char    *name;     /* name of information */
-    const char    *data;     /* information */
+typedef struct {
+    const char *name;           /* name of information */
+    const char *data;           /* information */
 } vshCmdInfo;
 
 /*
  * vshCmdOptDef - command option definition
  */
-typedef struct  {
-    const char       *name;     /* the name of option */
-    vshCmdOptType    type;      /* option type */
-    int              flag;      /* flags */
-    const char       *help;     /* help string */
+typedef struct {
+    const char *name;           /* the name of option */
+    vshCmdOptType type;         /* option type */
+    int flag;                   /* flags */
+    const char *help;           /* help string */
 } vshCmdOptDef;
 
 /*
  * vshCmdOpt - command options
  */
 typedef struct vshCmdOpt {
-    vshCmdOptDef     *def;      /* pointer to relevant option */
-    char             *data;     /* allocated data */
-    struct vshCmdOpt *next;    
+    vshCmdOptDef *def;          /* pointer to relevant option */
+    char *data;                 /* allocated data */
+    struct vshCmdOpt *next;
 } vshCmdOpt;
 
 /*
  * vshCmdDef - command definition
  */
-typedef struct  {
-    const char       *name;
-    int              (*handler)(vshControl *, vshCmd *);    /* command handler */
-    vshCmdOptDef     *opts;     /* definition of command options */
-    vshCmdInfo       *info;     /* details about command */
+typedef struct {
+    const char *name;
+    int (*handler) (vshControl *, vshCmd *);    /* command handler */
+    vshCmdOptDef *opts;         /* definition of command options */
+    vshCmdInfo *info;           /* details about command */
 } vshCmdDef;
 
 /*
  * vshCmd - parsed command
  */
 typedef struct __vshCmd {
-    vshCmdDef        *def;      /* command definition */
-    vshCmdOpt        *opts;     /* list of command arguments */
-    struct __vshCmd  *next;     /* next command */
+    vshCmdDef *def;             /* command definition */
+    vshCmdOpt *opts;            /* list of command arguments */
+    struct __vshCmd *next;      /* next command */
 } __vshCmd;
 
 /*
  * vshControl
  */
 typedef struct __vshControl {
-    virConnectPtr   conn;       /* connection to hypervisor */
-    vshCmd          *cmd;       /* the current command */
-    char            *cmdstr;    /* string with command */
-    uid_t           uid;        /* process owner */
-    int             imode;      /* interactive mode? */
-    int             quiet;      /* quiet mode */
-    int             debug;      /* print debug messages? */
-    int             timing;     /* print timing info? */
+    virConnectPtr conn;         /* connection to hypervisor */
+    vshCmd *cmd;                /* the current command */
+    char *cmdstr;               /* string with command */
+    uid_t uid;                  /* process owner */
+    int imode;                  /* interactive mode? */
+    int quiet;                  /* quiet mode */
+    int debug;                  /* print debug messages? */
+    int timing;                 /* print timing info? */
 } __vshControl;
 
 
 static vshCmdDef commands[];
 
-static void vshError(vshControl *ctl, int doexit, const char *format, ...);
-static int vshInit(vshControl *ctl);
-static int vshDeinit(vshControl *ctl);
-static void vshUsage(vshControl *ctl, const char *cmdname);
+static void vshError(vshControl * ctl, int doexit, const char *format,
+                     ...);
+static int vshInit(vshControl * ctl);
+static int vshDeinit(vshControl * ctl);
+static void vshUsage(vshControl * ctl, const char *cmdname);
 
-static int vshParseArgv(vshControl *ctl, int argc, char **argv);
+static int vshParseArgv(vshControl * ctl, int argc, char **argv);
 
-static const char *vshCmddefGetInfo(vshCmdDef *cmd, const char *info);
+static const char *vshCmddefGetInfo(vshCmdDef * cmd, const char *info);
 static vshCmdDef *vshCmddefSearch(const char *cmdname);
-static int vshCmddefHelp(vshControl *ctl, const char *name, int withprog);
+static int vshCmddefHelp(vshControl * ctl, const char *name, int withprog);
 
-static vshCmdOpt *vshCommandOpt(vshCmd *cmd, const char *name);
-static int vshCommandOptInt(vshCmd *cmd, const char *name, int *found);
-static char *vshCommandOptString(vshCmd *cmd, const char *name, int *found);
-static int vshCommandOptBool(vshCmd *cmd, const char *name);
-static virDomainPtr vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **name);
+static vshCmdOpt *vshCommandOpt(vshCmd * cmd, const char *name);
+static int vshCommandOptInt(vshCmd * cmd, const char *name, int *found);
+static char *vshCommandOptString(vshCmd * cmd, const char *name,
+                                 int *found);
+static int vshCommandOptBool(vshCmd * cmd, const char *name);
+static virDomainPtr vshCommandOptDomain(vshControl * ctl, vshCmd * cmd,
+                                        const char *optname, char **name);
 
 
-static void vshPrint(vshControl *ctl, vshOutType out, const char *format, ...);
+static void vshPrint(vshControl * ctl, vshOutType out, const char *format,
+                     ...);
 
 
 static const char *vshDomainStateToString(int state);
-static int vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror);
+static int vshConnectionUsability(vshControl * ctl, virConnectPtr conn,
+                                  int showerror);
 
 /* ---------------
  * Commands
@@ -209,29 +215,30 @@ static int vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showe
  * "help" command 
  */
 static vshCmdInfo info_help[] = {
-    { "syntax",   "help [<command>]" },
-    { "help",     "print help" },
-    { "desc",     "Prints global help or command specific help." },
-    { "version",  "Prints versionning informations." },
-    { NULL, NULL }
+    {"syntax", "help [<command>]"},
+    {"help", "print help"},
+    {"desc", "Prints global help or command specific help."},
+    {"version", "Prints versionning informations."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_help[] = {
-    { "command", VSH_OT_DATA, 0, "name of command" },
-        { NULL, 0, 0, NULL }
+    {"command", VSH_OT_DATA, 0, "name of command"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdHelp(vshControl *ctl, vshCmd *cmd) {
+cmdHelp(vshControl * ctl, vshCmd * cmd)
+{
     const char *cmdname = vshCommandOptString(cmd, "command", NULL);
 
     if (!cmdname) {
         vshCmdDef *def;
-        
+
         vshPrint(ctl, VSH_HEADER, "Commands:\n\n");
-        for(def = commands; def->name; def++)
-            vshPrint(ctl, VSH_MESG, "    %-15s %s\n", def->name, 
-                    vshCmddefGetInfo(def, "help"));
+        for (def = commands; def->name; def++)
+            vshPrint(ctl, VSH_MESG, "    %-15s %s\n", def->name,
+                     vshCmddefGetInfo(def, "help"));
         return TRUE;
     }
     return vshCmddefHelp(ctl, cmdname, FALSE);
@@ -241,24 +248,27 @@ cmdHelp(vshControl *ctl, vshCmd *cmd) {
  * "connect" command 
  */
 static vshCmdInfo info_connect[] = {
-    { "syntax",   "connect [--readonly]" },
-    { "help",     "(re)connect to hypervisor" },
-    { "desc",     "Connect to local hypervisor. This is build-in command after shell start up." },
-    { NULL, NULL }
+    {"syntax", "connect [--readonly]"},
+    {"help", "(re)connect to hypervisor"},
+    {"desc",
+     "Connect to local hypervisor. This is build-in command after shell start up."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_connect[] = {
-    { "readonly", VSH_OT_BOOL, 0, "read-only connection" },
-        { NULL, 0, 0, NULL }
+    {"readonly", VSH_OT_BOOL, 0, "read-only connection"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdConnect(vshControl *ctl, vshCmd *cmd) {
+cmdConnect(vshControl * ctl, vshCmd * cmd)
+{
     int ro = vshCommandOptBool(cmd, "readonly");
-    
+
     if (ctl->conn) {
-        if (virConnectClose(ctl->conn)!=0) {
-            vshError(ctl, FALSE, "failed to disconnect from the hypervisor");
+        if (virConnectClose(ctl->conn) != 0) {
+            vshError(ctl, FALSE,
+                     "failed to disconnect from the hypervisor");
             return FALSE;
         }
         ctl->conn = NULL;
@@ -270,7 +280,7 @@ cmdConnect(vshControl *ctl, vshCmd *cmd) {
 
     if (!ctl->conn)
         vshError(ctl, FALSE, "failed to connect to the hypervisor");
-    
+
     return ctl->conn ? TRUE : FALSE;
 }
 
@@ -278,21 +288,22 @@ cmdConnect(vshControl *ctl, vshCmd *cmd) {
  * "list" command
  */
 static vshCmdInfo info_list[] = {
-    { "syntax",   "list" },
-    { "help",     "list domains" },
-    { "desc",     "Returns list of domains." },
-    { NULL, NULL }
+    {"syntax", "list"},
+    {"help", "list domains"},
+    {"desc", "Returns list of domains."},
+    {NULL, NULL}
 };
 
 
 
 static int
-cmdList(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
+cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+{
     int *ids, maxid, i;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
-    
+
     maxid = virConnectNumOfDomains(ctl->conn);
     if (maxid <= 0) {
         /* strange, there should be at least dom0... */
@@ -301,24 +312,25 @@ cmdList(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
     }
     ids = malloc(sizeof(int) * maxid);
     virConnectListDomains(ctl->conn, &ids[0], maxid);
-    
+
     vshPrint(ctl, VSH_HEADER, "%3s %-20s %s\n", "Id", "Name", "State");
     vshPrint(ctl, VSH_HEADER, "----------------------------------\n");
-    
-    for(i=0; i < maxid; i++) {
+
+    for (i = 0; i < maxid; i++) {
         int ret;
         virDomainInfo info;
         virDomainPtr dom = virDomainLookupByID(ctl->conn, ids[i]);
-        
-         /* this kind of work with domains is not atomic operation */
+
+        /* this kind of work with domains is not atomic operation */
         if (!dom)
             continue;
         ret = virDomainGetInfo(dom, &info);
-        
-        vshPrint(ctl, VSH_MESG, "%3d %-20s %s\n", 
-                virDomainGetID(dom), 
-                virDomainGetName(dom),
-                ret < 0 ? "no state" : vshDomainStateToString(info.state));
+
+        vshPrint(ctl, VSH_MESG, "%3d %-20s %s\n",
+                 virDomainGetID(dom),
+                 virDomainGetName(dom),
+                 ret <
+                 0 ? "no state" : vshDomainStateToString(info.state));
         virDomainFree(dom);
     }
     free(ids);
@@ -329,34 +341,36 @@ cmdList(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
  * "dstate" command
  */
 static vshCmdInfo info_dstate[] = {
-    { "syntax",  "dstate <domain>" },
-    { "help",    "domain state" },
-    { "desc",    "Returns state about a running domain." },
-    { NULL, NULL }
+    {"syntax", "dstate <domain>"},
+    {"help", "domain state"},
+    {"desc", "Returns state about a running domain."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_dstate[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdDstate(vshControl *ctl, vshCmd *cmd) {
+cmdDstate(vshControl * ctl, vshCmd * cmd)
+{
     virDomainInfo info;
     virDomainPtr dom;
     int ret = TRUE;
-   
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
         return FALSE;
-    
-    if (virDomainGetInfo(dom, &info)==0)
-        vshPrint(ctl, VSH_MESG, "%s\n", vshDomainStateToString(info.state));
+
+    if (virDomainGetInfo(dom, &info) == 0)
+        vshPrint(ctl, VSH_MESG, "%s\n",
+                 vshDomainStateToString(info.state));
     else
         ret = FALSE;
-        
+
     virDomainFree(dom);
     return ret;
 }
@@ -365,36 +379,37 @@ cmdDstate(vshControl *ctl, vshCmd *cmd) {
  * "suspend" command
  */
 static vshCmdInfo info_suspend[] = {
-    { "syntax",  "suspend <domain>" },
-    { "help",    "suspend a domain" },
-    { "desc",    "Suspend a running domain." },
-    { NULL, NULL }
+    {"syntax", "suspend <domain>"},
+    {"help", "suspend a domain"},
+    {"desc", "Suspend a running domain."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_suspend[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdSuspend(vshControl *ctl, vshCmd *cmd) {
+cmdSuspend(vshControl * ctl, vshCmd * cmd)
+{
     virDomainPtr dom;
     char *name;
     int ret = TRUE;
-    
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
         return FALSE;
-    
-    if (virDomainSuspend(dom)==0) {
+
+    if (virDomainSuspend(dom) == 0) {
         vshPrint(ctl, VSH_MESG, "Domain %s suspended\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to suspend domain\n");
         ret = FALSE;
     }
-        
+
     virDomainFree(dom);
     return ret;
 }
@@ -403,41 +418,42 @@ cmdSuspend(vshControl *ctl, vshCmd *cmd) {
  * "save" command
  */
 static vshCmdInfo info_save[] = {
-    { "syntax",  "save <domain> <file>" },
-    { "help",    "save a domain state to a file" },
-    { "desc",    "Save a running domain." },
-    { NULL, NULL }
+    {"syntax", "save <domain> <file>"},
+    {"help", "save a domain state to a file"},
+    {"desc", "Save a running domain."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_save[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { "file",    VSH_OT_DATA, VSH_OFLAG_REQ, "where to save the data" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {"file", VSH_OT_DATA, VSH_OFLAG_REQ, "where to save the data"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdSave(vshControl *ctl, vshCmd *cmd) {
+cmdSave(vshControl * ctl, vshCmd * cmd)
+{
     virDomainPtr dom;
     char *name;
     char *to;
     int ret = TRUE;
-    
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(to = vshCommandOptString(cmd, "file", NULL)))
         return FALSE;
-    
+
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
         return FALSE;
-    
-    if (virDomainSave(dom, to)==0) {
+
+    if (virDomainSave(dom, to) == 0) {
         vshPrint(ctl, VSH_MESG, "Domain %s saved\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to save domain\n");
         ret = FALSE;
     }
-        
+
     virDomainFree(dom);
     return ret;
 }
@@ -446,31 +462,32 @@ cmdSave(vshControl *ctl, vshCmd *cmd) {
  * "restore" command
  */
 static vshCmdInfo info_restore[] = {
-    { "syntax",  "restore a domain from <file>" },
-    { "help",    "restore a domain from a saved state in a file" },
-    { "desc",    "Restore a domain." },
-    { NULL, NULL }
+    {"syntax", "restore a domain from <file>"},
+    {"help", "restore a domain from a saved state in a file"},
+    {"desc", "Restore a domain."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_restore[] = {
-    { "file",  VSH_OT_DATA, VSH_OFLAG_REQ, "the state to restore" },
-    { NULL, 0, 0, NULL }
+    {"file", VSH_OT_DATA, VSH_OFLAG_REQ, "the state to restore"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdRestore(vshControl *ctl, vshCmd *cmd) {
+cmdRestore(vshControl * ctl, vshCmd * cmd)
+{
     char *from;
     int found;
     int ret = TRUE;
-    
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     from = vshCommandOptString(cmd, "file", &found);
     if (!found)
         return FALSE;
-    
-    if (virDomainRestore(ctl->conn, from)==0) {
+
+    if (virDomainRestore(ctl->conn, from) == 0) {
         vshPrint(ctl, VSH_MESG, "Domain restored from %s\n", from);
     } else {
         vshError(ctl, FALSE, "Failed to restore domain\n");
@@ -483,36 +500,37 @@ cmdRestore(vshControl *ctl, vshCmd *cmd) {
  * "resume" command
  */
 static vshCmdInfo info_resume[] = {
-    { "syntax",  "resume <domain>" },
-    { "help",    "resume a domain" },
-    { "desc",    "Resume a previously suspended domain." },
-    { NULL, NULL }
+    {"syntax", "resume <domain>"},
+    {"help", "resume a domain"},
+    {"desc", "Resume a previously suspended domain."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_resume[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdResume(vshControl *ctl, vshCmd *cmd) {
+cmdResume(vshControl * ctl, vshCmd * cmd)
+{
     virDomainPtr dom;
     int ret = TRUE;
     char *name;
-    
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
         return FALSE;
-    
-    if (virDomainResume(dom)==0) {
+
+    if (virDomainResume(dom) == 0) {
         vshPrint(ctl, VSH_MESG, "Domain %s resumed\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to resume domain\n");
         ret = FALSE;
     }
-        
+
     virDomainFree(dom);
     return ret;
 }
@@ -521,36 +539,37 @@ cmdResume(vshControl *ctl, vshCmd *cmd) {
  * "shutdown" command
  */
 static vshCmdInfo info_shutdown[] = {
-    { "syntax",  "shutdown <domain>" },
-    { "help",    "gracefully shutdown a domain" },
-    { "desc",    "Run shutdown in the targetted domain" },
-    { NULL, NULL }
+    {"syntax", "shutdown <domain>"},
+    {"help", "gracefully shutdown a domain"},
+    {"desc", "Run shutdown in the targetted domain"},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_shutdown[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdShutdown(vshControl *ctl, vshCmd *cmd) {
+cmdShutdown(vshControl * ctl, vshCmd * cmd)
+{
     virDomainPtr dom;
     int ret = TRUE;
     char *name;
-    
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
         return FALSE;
-    
-    if (virDomainShutdown(dom)==0) {
+
+    if (virDomainShutdown(dom) == 0) {
         vshPrint(ctl, VSH_MESG, "Domain %s is being shutdown\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to shutdown domain\n");
         ret = FALSE;
     }
-        
+
     virDomainFree(dom);
     return ret;
 }
@@ -559,37 +578,38 @@ cmdShutdown(vshControl *ctl, vshCmd *cmd) {
  * "destroy" command
  */
 static vshCmdInfo info_destroy[] = {
-    { "syntax",  "destroy <domain>" },
-    { "help",    "destroy a domain" },
-    { "desc",    "Destroy a given domain." },
-    { NULL, NULL }
+    {"syntax", "destroy <domain>"},
+    {"help", "destroy a domain"},
+    {"desc", "Destroy a given domain."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_destroy[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdDestroy(vshControl *ctl, vshCmd *cmd) {
+cmdDestroy(vshControl * ctl, vshCmd * cmd)
+{
     virDomainPtr dom;
     int ret = TRUE;
     char *name;
-   
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
         return FALSE;
-    
-    if (virDomainDestroy(dom)==0) {
+
+    if (virDomainDestroy(dom) == 0) {
         vshPrint(ctl, VSH_MESG, "Domain %s destroyed\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to destroy domain\n");
         ret = FALSE;
         virDomainFree(dom);
     }
-        
+
     return ret;
 }
 
@@ -597,64 +617,62 @@ cmdDestroy(vshControl *ctl, vshCmd *cmd) {
  * "dinfo" command
  */
 static vshCmdInfo info_dinfo[] = {
-    { "syntax",   "dinfo <domain>" },
-    { "help",     "domain information" },
-    { "desc",     "Returns basic information about the domain." },
-    { NULL, NULL }
+    {"syntax", "dinfo <domain>"},
+    {"help", "domain information"},
+    {"desc", "Returns basic information about the domain."},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_dinfo[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdDinfo(vshControl *ctl, vshCmd *cmd) {
+cmdDinfo(vshControl * ctl, vshCmd * cmd)
+{
     virDomainInfo info;
     virDomainPtr dom;
     int ret = TRUE;
     char *str;
-   
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
         return FALSE;
-    
-     vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:", 
-            virDomainGetID(dom));
-     vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:", 
-            virDomainGetName(dom));
-     
-     if ((str=virDomainGetOSType(dom))) {
-         vshPrint(ctl, VSH_MESG, "%-15s %s\n", "OS Type:", str);
-         free(str);
-     }
-
-    if (virDomainGetInfo(dom, &info)==0) {
-        vshPrint(ctl, VSH_MESG, "%-15s %s\n", "State:",    
-                vshDomainStateToString(info.state));
-        
-        vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):",
-                info.nrVirtCpu);
-        
-        if (info.cpuTime != 0) 
-        {
+
+    vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:", virDomainGetID(dom));
+    vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:", virDomainGetName(dom));
+
+    if ((str = virDomainGetOSType(dom))) {
+        vshPrint(ctl, VSH_MESG, "%-15s %s\n", "OS Type:", str);
+        free(str);
+    }
+
+    if (virDomainGetInfo(dom, &info) == 0) {
+        vshPrint(ctl, VSH_MESG, "%-15s %s\n", "State:",
+                 vshDomainStateToString(info.state));
+
+        vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):", info.nrVirtCpu);
+
+        if (info.cpuTime != 0) {
             float cpuUsed = info.cpuTime;
+
             cpuUsed /= 1000000000;
-            
+
             vshPrint(ctl, VSH_MESG, "%-15s %.1fs\n", "CPU time:", cpuUsed);
         }
-           
+
         vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Max memory:",
-                info.maxMem);
+                 info.maxMem);
         vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Used memory:",
-                info.memory);
-        
+                 info.memory);
+
     } else {
         ret = FALSE;
     }
-        
+
     virDomainFree(dom);
     return ret;
 }
@@ -663,29 +681,30 @@ cmdDinfo(vshControl *ctl, vshCmd *cmd) {
  * "dumpxml" command
  */
 static vshCmdInfo info_dumpxml[] = {
-    { "syntax",   "dumpxml <name>" },
-    { "help",     "domain information in XML" },
-    { "desc",     "Ouput the domain informations as an XML dump to stdout" },
-    { NULL, NULL }
+    {"syntax", "dumpxml <name>"},
+    {"help", "domain information in XML"},
+    {"desc", "Ouput the domain informations as an XML dump to stdout"},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_dumpxml[] = {
-    { "domain",  VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id" },
-    { NULL, 0, 0, NULL }
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdDumpXML(vshControl *ctl, vshCmd *cmd) {
+cmdDumpXML(vshControl * ctl, vshCmd * cmd)
+{
     virDomainPtr dom;
     int ret = TRUE;
     char *dump;
-    
+
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
         return FALSE;
-    
+
     dump = virDomainGetXMLDesc(dom, 0);
     if (dump != NULL) {
         printf("%s", dump);
@@ -693,7 +712,7 @@ cmdDumpXML(vshControl *ctl, vshCmd *cmd) {
     } else {
         ret = FALSE;
     }
-        
+
     virDomainFree(dom);
     return ret;
 }
@@ -702,18 +721,19 @@ cmdDumpXML(vshControl *ctl, vshCmd *cmd) {
  * "nameof" command
  */
 static vshCmdInfo info_nameof[] = {
-    { "syntax",   "nameof <id>" },
-    { "help",     "convert a domain Id to domain name" },
-    { NULL, NULL }
+    {"syntax", "nameof <id>"},
+    {"help", "convert a domain Id to domain name"},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_nameof[] = {
-    { "id",        VSH_OT_DATA,  VSH_OFLAG_REQ, "domain Id" },
-    { NULL, 0, 0, NULL }
+    {"id", VSH_OT_DATA, VSH_OFLAG_REQ, "domain Id"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdNameof(vshControl *ctl, vshCmd *cmd) {
+cmdNameof(vshControl * ctl, vshCmd * cmd)
+{
     int found;
     int id = vshCommandOptInt(cmd, "id", &found);
     virDomainPtr dom;
@@ -722,7 +742,7 @@ cmdNameof(vshControl *ctl, vshCmd *cmd) {
         return FALSE;
     if (!found)
         return FALSE;
-    
+
     dom = virDomainLookupByID(ctl->conn, id);
     if (dom) {
         vshPrint(ctl, VSH_MESG, "%s\n", virDomainGetName(dom));
@@ -738,18 +758,19 @@ cmdNameof(vshControl *ctl, vshCmd *cmd) {
  * "idof" command
  */
 static vshCmdInfo info_idof[] = {
-    { "syntax",   "idof <name>" },
-    { "help",     "convert a domain name to domain Id" },
-    { NULL, NULL }
+    {"syntax", "idof <name>"},
+    {"help", "convert a domain name to domain Id"},
+    {NULL, NULL}
 };
 
 static vshCmdOptDef opts_idof[] = {
-    { "name",     VSH_OT_DATA, VSH_OFLAG_REQ, "domain name" },
-        { NULL, 0, 0, NULL }
+    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name"},
+    {NULL, 0, 0, NULL}
 };
 
 static int
-cmdIdof(vshControl *ctl, vshCmd *cmd) {
+cmdIdof(vshControl * ctl, vshCmd * cmd)
+{
     char *name = vshCommandOptString(cmd, "name", NULL);
     virDomainPtr dom;
 
@@ -757,7 +778,7 @@ cmdIdof(vshControl *ctl, vshCmd *cmd) {
         return FALSE;
     if (!name)
         return FALSE;
-    
+
     dom = virDomainLookupByName(ctl->conn, name);
     if (dom) {
         vshPrint(ctl, VSH_MESG, "%d\n", virDomainGetID(dom));
@@ -773,15 +794,16 @@ cmdIdof(vshControl *ctl, vshCmd *cmd) {
  * "version" command
  */
 static vshCmdInfo info_version[] = {
-    { "syntax",   "version" },
-    { "help",     "show versions" },
-    { "desc",     "Display the version informations available" },
-    { NULL, NULL }
+    {"syntax", "version"},
+    {"help", "show versions"},
+    {"desc", "Display the version informations available"},
+    {NULL, NULL}
 };
 
 
 static int
-cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
+cmdVersion(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+{
     unsigned long hvVersion;
     const char *hvType;
     unsigned long libVersion;
@@ -794,7 +816,7 @@ cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
-    
+
     hvType = virConnectGetType(ctl->conn);
     if (hvType == NULL) {
         vshError(ctl, FALSE, "failed to get hypervisor type\n");
@@ -820,7 +842,7 @@ cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
     rel = libVersion % 1000;
     vshPrint(ctl, VSH_MESG, "Using library: libvir %d.%d.%d\n",
              major, minor, rel);
-    
+
     major = apiVersion / 1000000;
     apiVersion %= 1000000;
     minor = apiVersion / 1000;
@@ -828,23 +850,22 @@ cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
     vshPrint(ctl, VSH_MESG, "Using API: %s %d.%d.%d\n", hvType,
              major, minor, rel);
 
-    ret =  virConnectGetVersion(ctl->conn, &hvVersion);
+    ret = virConnectGetVersion(ctl->conn, &hvVersion);
     if (ret < 0) {
         vshError(ctl, FALSE, "failed to get the hypervisor version");
         return FALSE;
     }
     if (hvVersion == 0) {
         vshPrint(ctl, VSH_MESG,
-                 "cannot extract running %s hypervisor version\n",
-                 hvType);
+                 "cannot extract running %s hypervisor version\n", hvType);
     } else {
         major = hvVersion / 1000000;
         hvVersion %= 1000000;
         minor = hvVersion / 1000;
         rel = hvVersion % 1000;
 
-        vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n", hvType,
-                 major, minor, rel);
+        vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n",
+                 hvType, major, minor, rel);
     }
     return TRUE;
 }
@@ -853,13 +874,14 @@ cmdVersion(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
  * "quit" command
  */
 static vshCmdInfo info_quit[] = {
-    { "syntax",   "quit" },
-    { "help",     "quit this interactive terminal" },
-    { NULL, NULL }
+    {"syntax", "quit"},
+    {"help", "quit this interactive terminal"},
+    {NULL, NULL}
 };
 
 static int
-cmdQuit(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
+cmdQuit(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+{
     ctl->imode = FALSE;
     return TRUE;
 }
@@ -868,23 +890,23 @@ cmdQuit(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
  * Commands
  */
 static vshCmdDef commands[] = {
-    { "connect",    cmdConnect,    opts_connect,   info_connect },
-    { "dinfo",      cmdDinfo,      opts_dinfo,     info_dinfo },
-    { "dumpxml",    cmdDumpXML,    opts_dumpxml,   info_dumpxml },
-    { "dstate",     cmdDstate,     opts_dstate,    info_dstate },
-    { "suspend",    cmdSuspend,    opts_suspend,   info_suspend },
-    { "resume",     cmdResume,     opts_resume,    info_resume },
-    { "save",       cmdSave,       opts_save,      info_save },
-    { "restore",    cmdRestore,    opts_restore,   info_restore },
-    { "shutdown",   cmdShutdown,   opts_shutdown,  info_shutdown },
-    { "destroy",    cmdDestroy,    opts_destroy,   info_destroy },
-    { "help",       cmdHelp,       opts_help,      info_help },
-    { "idof",       cmdIdof,       opts_idof,      info_idof },
-    { "list",       cmdList,       NULL,           info_list },
-    { "nameof",     cmdNameof,     opts_nameof,    info_nameof },
-    { "version",    cmdVersion,    NULL,           info_version },
-    { "quit",       cmdQuit,       NULL,           info_quit },
-    { NULL, NULL, NULL, NULL }
+    {"connect", cmdConnect, opts_connect, info_connect},
+    {"dinfo", cmdDinfo, opts_dinfo, info_dinfo},
+    {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml},
+    {"dstate", cmdDstate, opts_dstate, info_dstate},
+    {"suspend", cmdSuspend, opts_suspend, info_suspend},
+    {"resume", cmdResume, opts_resume, info_resume},
+    {"save", cmdSave, opts_save, info_save},
+    {"restore", cmdRestore, opts_restore, info_restore},
+    {"shutdown", cmdShutdown, opts_shutdown, info_shutdown},
+    {"destroy", cmdDestroy, opts_destroy, info_destroy},
+    {"help", cmdHelp, opts_help, info_help},
+    {"idof", cmdIdof, opts_idof, info_idof},
+    {"list", cmdList, NULL, info_list},
+    {"nameof", cmdNameof, opts_nameof, info_nameof},
+    {"version", cmdVersion, NULL, info_version},
+    {"quit", cmdQuit, NULL, info_quit},
+    {NULL, NULL, NULL, NULL}
 };
 
 /* ---------------
@@ -892,33 +914,36 @@ static vshCmdDef commands[] = {
  * ---------------
  */
 static const char *
-vshCmddefGetInfo(vshCmdDef *cmd, const char *name) {
+vshCmddefGetInfo(vshCmdDef * cmd, const char *name)
+{
     vshCmdInfo *info;
-    
+
     for (info = cmd->info; info && info->name; info++) {
-        if (strcmp(info->name, name)==0)
+        if (strcmp(info->name, name) == 0)
             return info->data;
     }
     return NULL;
 }
 
 static vshCmdOptDef *
-vshCmddefGetOption(vshCmdDef *cmd, const char *name) {
+vshCmddefGetOption(vshCmdDef * cmd, const char *name)
+{
     vshCmdOptDef *opt;
-    
+
     for (opt = cmd->opts; opt && opt->name; opt++)
-        if (strcmp(opt->name, name)==0)
+        if (strcmp(opt->name, name) == 0)
             return opt;
     return NULL;
 }
 
 static vshCmdOptDef *
-vshCmddefGetData(vshCmdDef *cmd, int data_ct) {
+vshCmddefGetData(vshCmdDef * cmd, int data_ct)
+{
     vshCmdOptDef *opt;
 
     for (opt = cmd->opts; opt && opt->name; opt++) {
-        if (opt->type==VSH_OT_DATA) {
-            if (data_ct==0)
+        if (opt->type == VSH_OT_DATA) {
+            if (data_ct == 0)
                 return opt;
             else
                 data_ct--;
@@ -930,63 +955,65 @@ vshCmddefGetData(vshCmdDef *cmd, int data_ct) {
 /*
  * Checks for required options
  */
-static int 
-vshCommandCheckOpts(vshControl *ctl, vshCmd *cmd)
+static int
+vshCommandCheckOpts(vshControl * ctl, vshCmd * cmd)
 {
     vshCmdDef *def = cmd->def;
     vshCmdOptDef *d;
-    int err=0;
+    int err = 0;
 
     for (d = def->opts; d && d->name; d++) {
         if (d->flag & VSH_OFLAG_REQ) {
             vshCmdOpt *o = cmd->opts;
-            int ok=0;
-        
-            while(o && ok==0) {
+            int ok = 0;
+
+            while (o && ok == 0) {
                 if (o->def == d)
-                    ok=1;
+                    ok = 1;
                 o = o->next;
             }
             if (!ok) {
-                vshError(ctl, FALSE, 
-                        d->type == VSH_OT_DATA ?
-                            "command '%s' requires <%s> option" :
-                            "command '%s' requires --%s option",
-                              def->name, d->name);
+                vshError(ctl, FALSE,
+                         d->type == VSH_OT_DATA ?
+                         "command '%s' requires <%s> option" :
+                         "command '%s' requires --%s option",
+                         def->name, d->name);
                 err = 1;
             }
-            
+
         }
     }
     return !err;
 }
 
 static vshCmdDef *
-vshCmddefSearch(const char *cmdname) {
+vshCmddefSearch(const char *cmdname)
+{
     vshCmdDef *c;
-    
+
     for (c = commands; c->name; c++)
-        if (strcmp(c->name, cmdname)==0)
+        if (strcmp(c->name, cmdname) == 0)
             return c;
     return NULL;
 }
 
 static int
-vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog) {
+vshCmddefHelp(vshControl * ctl, const char *cmdname, int withprog)
+{
     vshCmdDef *def = vshCmddefSearch(cmdname);
-    
+
     if (!def) {
-         vshError(ctl, FALSE, "command '%s' doesn't exist", cmdname);
-         return FALSE;
-    } else {    
+        vshError(ctl, FALSE, "command '%s' doesn't exist", cmdname);
+        return FALSE;
+    } else {
         vshCmdOptDef *opt;
         const char *desc = vshCmddefGetInfo(def, "desc");
         const char *help = vshCmddefGetInfo(def, "help");
         const char *syntax = vshCmddefGetInfo(def, "syntax");
 
         fputs("  NAME\n", stdout);
-        fprintf(stdout, "    %s - %s\n", def->name,  help);
-        
+        fprintf(stdout, "    %s - %s\n", def->name, help);
+
         if (syntax) {
             fputs("\n  SYNOPSIS\n", stdout);
             if (!withprog)
@@ -1000,20 +1027,20 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog) {
         }
         if (def->opts) {
             fputs("\n  OPTIONS\n", stdout);
-            for (opt=def->opts; opt->name; opt++) {
+            for (opt = def->opts; opt->name; opt++) {
                 char buf[256];
-                
-                if (opt->type==VSH_OT_BOOL)
+
+                if (opt->type == VSH_OT_BOOL)
                     snprintf(buf, sizeof(buf), "--%s", opt->name);
-                else if (opt->type==VSH_OT_INT)
+                else if (opt->type == VSH_OT_INT)
                     snprintf(buf, sizeof(buf), "--%s <number>", opt->name);
-                else if (opt->type==VSH_OT_STRING)
+                else if (opt->type == VSH_OT_STRING)
                     snprintf(buf, sizeof(buf), "--%s <string>", opt->name);
-                else if (opt->type==VSH_OT_DATA)
+                else if (opt->type == VSH_OT_DATA)
                     snprintf(buf, sizeof(buf), "<%s>", opt->name);
-                
+
                 fprintf(stdout, "    %-15s  %s\n", buf, opt->help);
-            }    
+            }
         }
         fputc('\n', stdout);
     }
@@ -1024,12 +1051,14 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog) {
  * Utils for work with runtime commands data
  * ---------------
  */
-static void     
-vshCommandOptFree(vshCmdOpt *arg) {
+static void
+vshCommandOptFree(vshCmdOpt * arg)
+{
     vshCmdOpt *a = arg;
 
-    while(a) {
+    while (a) {
         vshCmdOpt *tmp = a;
+
         a = a->next;
 
         if (tmp->data)
@@ -1039,11 +1068,13 @@ vshCommandOptFree(vshCmdOpt *arg) {
 }
 
 static void
-vshCommandFree(vshCmd *cmd) {
+vshCommandFree(vshCmd * cmd)
+{
     vshCmd *c = cmd;
 
-    while(c) {
+    while (c) {
         vshCmd *tmp = c;
+
         c = c->next;
 
         if (tmp->opts)
@@ -1056,11 +1087,12 @@ vshCommandFree(vshCmd *cmd) {
  * Returns option by name
  */
 static vshCmdOpt *
-vshCommandOpt(vshCmd *cmd, const char *name) {
+vshCommandOpt(vshCmd * cmd, const char *name)
+{
     vshCmdOpt *opt = cmd->opts;
-    
-    while(opt) {
-        if (opt->def && strcmp(opt->def->name, name)==0)
+
+    while (opt) {
+        if (opt->def && strcmp(opt->def->name, name) == 0)
             return opt;
         opt = opt->next;
     }
@@ -1071,10 +1103,11 @@ vshCommandOpt(vshCmd *cmd, const char *name) {
  * Returns option as INT
  */
 static int
-vshCommandOptInt(vshCmd *cmd, const char *name, int *found) {
+vshCommandOptInt(vshCmd * cmd, const char *name, int *found)
+{
     vshCmdOpt *arg = vshCommandOpt(cmd, name);
     int res = 0;
-    
+
     if (arg)
         res = atoi(arg->data);
     if (found)
@@ -1086,8 +1119,10 @@ vshCommandOptInt(vshCmd *cmd, const char *name, int *found) {
  * Returns option as STRING
  */
 static char *
-vshCommandOptString(vshCmd *cmd, const char *name, int *found) {
+vshCommandOptString(vshCmd * cmd, const char *name, int *found)
+{
     vshCmdOpt *arg = vshCommandOpt(cmd, name);
+
     if (found)
         *found = arg ? TRUE : FALSE;
 
@@ -1098,42 +1133,48 @@ vshCommandOptString(vshCmd *cmd, const char *name, int *found) {
  * Returns TRUE/FALSE if the option exists
  */
 static int
-vshCommandOptBool(vshCmd *cmd, const char *name) {
+vshCommandOptBool(vshCmd * cmd, const char *name)
+{
     return vshCommandOpt(cmd, name) ? TRUE : FALSE;
 }
 
 
 static virDomainPtr
-vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **name) {
+vshCommandOptDomain(vshControl * ctl, vshCmd * cmd, const char *optname,
+                    char **name)
+{
     virDomainPtr dom = NULL;
     char *n, *end = NULL;
     int id;
-    
+
     if (!(n = vshCommandOptString(cmd, optname, NULL))) {
         vshError(ctl, FALSE, "undefined domain name or id");
-        return NULL; 
+        return NULL;
     }
-    
-    vshPrint(ctl, VSH_DEBUG5, "%s: found option <%s>: %s\n", cmd->def->name, optname, n);
-    
+
+    vshPrint(ctl, VSH_DEBUG5, "%s: found option <%s>: %s\n",
+             cmd->def->name, optname, n);
+
     if (name)
         *name = n;
-    
+
     /* try it by ID */
     id = (int) strtol(n, &end, 10);
-    if (id >= 0 && end && *end=='\0') {
-        vshPrint(ctl, VSH_DEBUG5, "%s: <%s> seems like domain ID\n", cmd->def->name, optname);
+    if (id >= 0 && end && *end == '\0') {
+        vshPrint(ctl, VSH_DEBUG5, "%s: <%s> seems like domain ID\n",
+                 cmd->def->name, optname);
         dom = virDomainLookupByID(ctl->conn, id);
     }
-    
+
     /* try it by NAME */
     if (!dom) {
-        vshPrint(ctl, VSH_DEBUG5, "%s: <%s> tring as domain NAME\n", cmd->def->name, optname);
+        vshPrint(ctl, VSH_DEBUG5, "%s: <%s> tring as domain NAME\n",
+                 cmd->def->name, optname);
         dom = virDomainLookupByName(ctl->conn, n);
     }
-    if (!dom) 
+    if (!dom)
         vshError(ctl, FALSE, "failed to get domain '%s'", n);
-        
+
     return dom;
 }
 
@@ -1141,26 +1182,28 @@ vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **na
  * Executes command(s) and returns return code from last command
  */
 static int
-vshCommandRun(vshControl *ctl, vshCmd *cmd) {
+vshCommandRun(vshControl * ctl, vshCmd * cmd)
+{
     int ret = TRUE;
-    
-    while(cmd) {
+
+    while (cmd) {
         struct timeval before, after;
-        
+
         if (ctl->timing)
             GETTIMEOFDAY(&before);
-        
+
         ret = cmd->def->handler(ctl, cmd);
 
         if (ctl->timing)
             GETTIMEOFDAY(&after);
-        
-        if (strcmp(cmd->def->name, "quit")==0) /* hack ... */
+
+        if (strcmp(cmd->def->name, "quit") == 0)        /* hack ... */
             return ret;
 
         if (ctl->timing)
-            vshPrint(ctl, VSH_MESG, "\n(Time: %.3f ms)\n\n", DIFF_MSEC(&after, &before));
-        else     
+            vshPrint(ctl, VSH_MESG, "\n(Time: %.3f ms)\n\n",
+                     DIFF_MSEC(&after, &before));
+        else
             vshPrint(ctl, VSH_FOOTER, "\n");
         cmd = cmd->next;
     }
@@ -1177,54 +1220,56 @@ vshCommandRun(vshControl *ctl, vshCmd *cmd) {
 #define VSH_TK_DATA    2
 #define VSH_TK_END    3
 
-static int 
-vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res) {
+static int
+vshCommandGetToken(vshControl * ctl, char *str, char **end, char **res)
+{
     int tk = VSH_TK_NONE;
     int quote = FALSE;
     int sz = 0;
     char *p = str;
     char *tkstr = NULL;
-    
+
     *end = NULL;
-    
-    while(p && *p && isblank((unsigned char) *p)) 
+
+    while (p && *p && isblank((unsigned char) *p))
         p++;
-    
-    if (p==NULL || *p=='\0')
+
+    if (p == NULL || *p == '\0')
         return VSH_TK_END;
-     if (*p==';') {
-        *end = ++p;        /* = \0 or begi of next command */
+    if (*p == ';') {
+        *end = ++p;             /* = \0 or begi of next command */
         return VSH_TK_END;
     }
-    while(*p) {
+    while (*p) {
         /* end of token is blank space or ';' */
-        if ((quote==FALSE && isblank((unsigned char) *p)) || *p==';')
+        if ((quote == FALSE && isblank((unsigned char) *p)) || *p == ';')
             break;
-    
+
         /* end of option name could be '=' */
-        if (tk==VSH_TK_OPTION && *p=='=') {
-            p++;    /* skip '=' */
+        if (tk == VSH_TK_OPTION && *p == '=') {
+            p++;                /* skip '=' */
             break;
         }
-        
-        if (tk==VSH_TK_NONE) {
-            if (*p=='-' && *(p+1)=='-' && *(p+2) && isalnum((unsigned char) *(p+2))) {
+
+        if (tk == VSH_TK_NONE) {
+            if (*p == '-' && *(p + 1) == '-' && *(p + 2)
+                && isalnum((unsigned char) *(p + 2))) {
                 tk = VSH_TK_OPTION;
-                p+=2;
+                p += 2;
             } else {
                 tk = VSH_TK_DATA;
-                if (*p=='"') {
-                           quote = TRUE;
+                if (*p == '"') {
+                    quote = TRUE;
                     p++;
                 } else {
                     quote = FALSE;
                 }
             }
-            tkstr = p;    /* begin of token */
-        } else if (quote && *p=='"') {
+            tkstr = p;          /* begin of token */
+        } else if (quote && *p == '"') {
             quote = FALSE;
             p++;
-            break;        /* end of "..." token */
+            break;              /* end of "..." token */
         }
         p++;
         sz++;
@@ -1233,141 +1278,140 @@ vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res) {
         vshError(ctl, FALSE, "missing \"");
         return VSH_TK_ERROR;
     }
-    if (tkstr==NULL || *tkstr=='\0' || p==NULL)
+    if (tkstr == NULL || *tkstr == '\0' || p == NULL)
         return VSH_TK_END;
-    if (sz==0)
+    if (sz == 0)
         return VSH_TK_END;
-    
-    *res = malloc(sz+1);
+
+    *res = malloc(sz + 1);
     memcpy(*res, tkstr, sz);
-    *(*res+sz) = '\0';
+    *(*res + sz) = '\0';
 
     *end = p;
     return tk;
 }
 
 static int
-vshCommandParse(vshControl *ctl, char *cmdstr) {
+vshCommandParse(vshControl * ctl, char *cmdstr)
+{
     char *str;
     char *tkdata = NULL;
     vshCmd *clast = NULL;
     vshCmdOpt *first = NULL;
-    
+
     if (ctl->cmd) {
         vshCommandFree(ctl->cmd);
         ctl->cmd = NULL;
     }
-    
-    if (cmdstr==NULL || *cmdstr=='\0')
+
+    if (cmdstr == NULL || *cmdstr == '\0')
         return FALSE;
-    
+
     str = cmdstr;
-    while(str && *str) 
-    {
+    while (str && *str) {
         vshCmdOpt *last = NULL;
         vshCmdDef *cmd = NULL;
         int tk = VSH_TK_NONE;
         int data_ct = 0;
-        
+
         first = NULL;
-        
-        while (tk!=VSH_TK_END) {
+
+        while (tk != VSH_TK_END) {
             char *end = NULL;
             vshCmdOptDef *opt = NULL;
-    
+
             tkdata = NULL;
-            
+
             /* get token */
             tk = vshCommandGetToken(ctl, str, &end, &tkdata);
-            
+
             str = end;
-            
-            if (tk==VSH_TK_END)
+
+            if (tk == VSH_TK_END)
                 break;
-            if (tk==VSH_TK_ERROR)
+            if (tk == VSH_TK_ERROR)
                 goto syntaxError;
-            
-            if (cmd==NULL) {
+
+            if (cmd == NULL) {
                 /* first token must be command name */
-                if (tk!=VSH_TK_DATA) {
-                    vshError(ctl, FALSE, 
-                        "unexpected token (command name): '%s'", 
-                        tkdata);
+                if (tk != VSH_TK_DATA) {
+                    vshError(ctl, FALSE,
+                             "unexpected token (command name): '%s'",
+                             tkdata);
                     goto syntaxError;
                 }
                 if (!(cmd = vshCmddefSearch(tkdata))) {
-                    vshError(ctl, FALSE,
-                        "unknown command: '%s'", tkdata);
-                    goto syntaxError;  /* ... or ignore this command only? */
+                    vshError(ctl, FALSE, "unknown command: '%s'", tkdata);
+                    goto syntaxError;   /* ... or ignore this command only? */
                 }
                 free(tkdata);
-            } else if (tk==VSH_TK_OPTION) {
+            } else if (tk == VSH_TK_OPTION) {
                 if (!(opt = vshCmddefGetOption(cmd, tkdata))) {
                     vshError(ctl, FALSE,
-                        "command '%s' doesn't support option --%s",
-                        cmd->name, tkdata);
+                             "command '%s' doesn't support option --%s",
+                             cmd->name, tkdata);
                     goto syntaxError;
                 }
-                free(tkdata);        /* option name */
+                free(tkdata);   /* option name */
                 tkdata = NULL;
 
                 if (opt->type != VSH_OT_BOOL) {
                     /* option data */
                     tk = vshCommandGetToken(ctl, str, &end, &tkdata);
-                    str = end;    
-                    if (tk==VSH_TK_ERROR)
+                    str = end;
+                    if (tk == VSH_TK_ERROR)
                         goto syntaxError;
-                    if (tk!=VSH_TK_DATA) {
+                    if (tk != VSH_TK_DATA) {
                         vshError(ctl, FALSE,
-                            "expected syntax: --%s <%s>", 
-                            opt->name, 
-                            opt->type==VSH_OT_INT ? "number" : "string");
+                                 "expected syntax: --%s <%s>",
+                                 opt->name,
+                                 opt->type ==
+                                 VSH_OT_INT ? "number" : "string");
                         goto syntaxError;
                     }
                 }
-            } else if (tk==VSH_TK_DATA) {
+            } else if (tk == VSH_TK_DATA) {
                 if (!(opt = vshCmddefGetData(cmd, data_ct++))) {
-                    vshError(ctl, FALSE,
-                        "unexpected data '%s'",
-                               tkdata);
+                    vshError(ctl, FALSE, "unexpected data '%s'", tkdata);
                     goto syntaxError;
                 }
             }
             if (opt) {
                 /* save option */
                 vshCmdOpt *arg = malloc(sizeof(vshCmdOpt));
-                
+
                 arg->def = opt;
                 arg->data = tkdata;
                 arg->next = NULL;
                 tkdata = NULL;
-                
+
                 if (!first)
                     first = arg;
                 if (last)
                     last->next = arg;
                 last = arg;
-                
+
                 vshPrint(ctl, VSH_DEBUG4, "%s: %s(%s): %s\n",
-                    cmd->name,
-                    opt->name,
-                    tk==VSH_TK_OPTION ? "OPTION" : "DATA",
-                    arg->data);
+                         cmd->name,
+                         opt->name,
+                         tk == VSH_TK_OPTION ? "OPTION" : "DATA",
+                         arg->data);
             }
             if (!str)
                 break;
         }
-        
+
         /* commad parsed -- allocate new struct for the command */
         if (cmd) {
-            vshCmd *c = malloc(sizeof(vshCmd));    
+            vshCmd *c = malloc(sizeof(vshCmd));
+
             c->opts = first;
             c->def = cmd;
             c->next = NULL;
 
             if (!vshCommandCheckOpts(ctl, c))
                 goto syntaxError;
-            
+
             if (!ctl->cmd)
                 ctl->cmd = c;
             if (clast)
@@ -1375,17 +1419,17 @@ vshCommandParse(vshControl *ctl, char *cmdstr) {
             clast = c;
         }
     }
-    
+
     return TRUE;
 
-syntaxError:
+  syntaxError:
     if (ctl->cmd)
         vshCommandFree(ctl->cmd);
     if (first)
         vshCommandOptFree(first);
     if (tkdata)
         free(tkdata);
-    return FALSE;    
+    return FALSE;
 }
 
 
@@ -1394,10 +1438,11 @@ syntaxError:
  * ---------------
  */
 static const char *
-vshDomainStateToString(int state) {
+vshDomainStateToString(int state)
+{
     switch (state) {
         case VIR_DOMAIN_RUNNING:
-                return "running ";
+            return "running ";
         case VIR_DOMAIN_BLOCKED:
             return "blocked ";
         case VIR_DOMAIN_PAUSED:
@@ -1407,13 +1452,14 @@ vshDomainStateToString(int state) {
         case VIR_DOMAIN_SHUTOFF:
             return "shut off";
         default:
-            return "no state";    /* = dom0 state */
+            return "no state";  /* = dom0 state */
     }
     return NULL;
 }
 
 static int
-vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror) {
+vshConnectionUsability(vshControl * ctl, virConnectPtr conn, int showerror)
+{
     /* TODO: use something like virConnectionState() to 
      *       check usability of the connection 
      */
@@ -1426,8 +1472,9 @@ vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror) {
 }
 
 static int
-vshWantedDebug(vshOutType type, int mode) {
-    switch(type) {
+vshWantedDebug(vshOutType type, int mode)
+{
+    switch (type) {
         case VSH_DEBUG5:
             if (mode < 5)
                 return FALSE;
@@ -1456,35 +1503,37 @@ vshWantedDebug(vshOutType type, int mode) {
 }
 
 static void
-vshPrint(vshControl *ctl, vshOutType type, const char *format, ...) {
+vshPrint(vshControl * ctl, vshOutType type, const char *format, ...)
+{
     va_list ap;
-    
-    if (ctl->quiet==TRUE && (type==VSH_HEADER || type==VSH_FOOTER))
+
+    if (ctl->quiet == TRUE && (type == VSH_HEADER || type == VSH_FOOTER))
         return;
 
     if (!vshWantedDebug(type, ctl->debug))
         return;
-    
+
     va_start(ap, format);
     vfprintf(stderr, format, ap);
     va_end(ap);
 }
 
 static void
-vshError(vshControl *ctl, int doexit, const char *format, ...) {
+vshError(vshControl * ctl, int doexit, const char *format, ...)
+{
     va_list ap;
-    
+
     if (doexit)
         fprintf(stderr, "%s: error: ", progname);
     else
         fputs("error: ", stderr);
-    
+
     va_start(ap, format);
     vfprintf(stderr, format, ap);
     va_end(ap);
 
     fputc('\n', stderr);
-    
+
     if (doexit) {
         vshDeinit(ctl);
         exit(EXIT_FAILURE);
@@ -1495,21 +1544,22 @@ vshError(vshControl *ctl, int doexit, const char *format, ...) {
  * Initialize vistsh
  */
 static int
-vshInit(vshControl *ctl) {
+vshInit(vshControl * ctl)
+{
     if (ctl->conn)
         return FALSE;
 
     ctl->uid = getuid();
-    
+
     /* set up the library error handler */
     virSetErrorFunc(NULL, virshErrorHandler);
-    
+
     /* basic connection to hypervisor */
     if (ctl->uid == 0)
         ctl->conn = virConnectOpen(NULL);
     else
         ctl->conn = virConnectOpenReadOnly(NULL);
-    
+
     if (!ctl->conn)
         vshError(ctl, TRUE, "failed to connect to the hypervisor");
 
@@ -1527,7 +1577,8 @@ vshInit(vshControl *ctl) {
  * (i.e. STATE == 0), then we start at the top of the list. 
  */
 static char *
-vshReadlineCommandGenerator(const char *text, int state) {
+vshReadlineCommandGenerator(const char *text, int state)
+{
     static int list_index, len;
     const char *name;
 
@@ -1537,7 +1588,7 @@ vshReadlineCommandGenerator(const char *text, int state) {
      */
     if (!state) {
         list_index = 0;
-        len = strlen (text);
+        len = strlen(text);
     }
 
     /* Return the next name which partially matches from the
@@ -1545,7 +1596,7 @@ vshReadlineCommandGenerator(const char *text, int state) {
      */
     while ((name = commands[list_index].name)) {
         list_index++;
-        if (strncmp (name, text, len) == 0)
+        if (strncmp(name, text, len) == 0)
             return strdup(name);
     }
 
@@ -1554,7 +1605,8 @@ vshReadlineCommandGenerator(const char *text, int state) {
 }
 
 static char *
-vshReadlineOptionsGenerator(const char *text, int state) {
+vshReadlineOptionsGenerator(const char *text, int state)
+{
     static int list_index, len;
     static vshCmdDef *cmd = NULL;
     const char *name;
@@ -1567,32 +1619,33 @@ vshReadlineOptionsGenerator(const char *text, int state) {
         if (!(p = strchr(rl_line_buffer, ' ')))
             return NULL;
 
-        cmdname = calloc((p - rl_line_buffer)+ 1, 1);
-        memcpy(cmdname, rl_line_buffer, p-rl_line_buffer);
+        cmdname = calloc((p - rl_line_buffer) + 1, 1);
+        memcpy(cmdname, rl_line_buffer, p - rl_line_buffer);
 
         cmd = vshCmddefSearch(cmdname);
         list_index = 0;
-        len = strlen (text);
+        len = strlen(text);
         free(cmdname);
     }
 
     if (!cmd)
         return NULL;
-    
+
     while ((name = cmd->opts[list_index].name)) {
         vshCmdOptDef *opt = &cmd->opts[list_index];
         char *res;
+
         list_index++;
-       
+
         if (opt->type == VSH_OT_DATA)
             /* ignore non --option */
             continue;
-        
+
         if (len > 2) {
-            if (strncmp (name, text+2, len-2))
+            if (strncmp(name, text + 2, len - 2))
                 continue;
         }
-        res = malloc(strlen(name)+3);
+        res = malloc(strlen(name) + 3);
         sprintf(res, "--%s", name);
         return res;
     }
@@ -1602,21 +1655,24 @@ vshReadlineOptionsGenerator(const char *text, int state) {
 }
 
 static char **
-vshReadlineCompletion(const char *text, int start, int end ATTRIBUTE_UNUSED) {
+vshReadlineCompletion(const char *text, int start,
+                      int end ATTRIBUTE_UNUSED)
+{
     char **matches = (char **) NULL;
 
-    if (start==0)
+    if (start == 0)
         /* command name generator */
-        matches = rl_completion_matches (text, vshReadlineCommandGenerator);
+        matches = rl_completion_matches(text, vshReadlineCommandGenerator);
     else
         /* commands options */
-        matches = rl_completion_matches (text, vshReadlineOptionsGenerator);
+        matches = rl_completion_matches(text, vshReadlineOptionsGenerator);
     return matches;
 }
 
 
 static void
-vshReadlineInit(void) {
+vshReadlineInit(void)
+{
     /* Allow conditional parsing of the ~/.inputrc file. */
     rl_readline_name = "virsh";
 
@@ -1628,23 +1684,26 @@ vshReadlineInit(void) {
  * Deinitliaze virsh
  */
 static int
-vshDeinit(vshControl *ctl) {
+vshDeinit(vshControl * ctl)
+{
     if (ctl->conn) {
-        if (virConnectClose(ctl->conn)!=0) {
-            ctl->conn = NULL; /* prevent recursive call from vshError() */
-            vshError(ctl, TRUE, "failed to disconnect from the hypervisor");
+        if (virConnectClose(ctl->conn) != 0) {
+            ctl->conn = NULL;   /* prevent recursive call from vshError() */
+            vshError(ctl, TRUE,
+                     "failed to disconnect from the hypervisor");
         }
     }
     return TRUE;
 }
-    
+
 /*
  * Print usage
  */
 static void
-vshUsage(vshControl *ctl, const char *cmdname) {
+vshUsage(vshControl * ctl, const char *cmdname)
+{
     vshCmdDef *cmd;
-    
+
     /* global help */
     if (!cmdname) {
         fprintf(stdout, "\n%s [options] [commands]\n\n"
@@ -1655,12 +1714,14 @@ vshUsage(vshControl *ctl, const char *cmdname) {
                 "    -t | --timing           print timing information\n"
                 "    -v | --version          program version\n\n"
                 "  commands (non interactive mode):\n", progname);
-    
-        for(cmd = commands; cmd->name; cmd++)
-            fprintf(stdout, 
-                "    %-15s %s\n", cmd->name, vshCmddefGetInfo(cmd, "help"));
-        
-        fprintf(stdout, "\n  (specify --help <command> for details about the command)\n\n");
+
+        for (cmd = commands; cmd->name; cmd++)
+            fprintf(stdout,
+                    "    %-15s %s\n", cmd->name, vshCmddefGetInfo(cmd,
+                                                                  "help"));
+
+        fprintf(stdout,
+                "\n  (specify --help <command> for details about the command)\n\n");
         return;
     }
     if (!vshCmddefHelp(ctl, cmdname, TRUE))
@@ -1672,42 +1733,43 @@ vshUsage(vshControl *ctl, const char *cmdname) {
  *
  */
 static int
-vshParseArgv(vshControl *ctl, int argc, char **argv) {
+vshParseArgv(vshControl * ctl, int argc, char **argv)
+{
     char *last = NULL;
     int i, end = 0, help = 0;
-    int arg, idx=0;
+    int arg, idx = 0;
     struct option opt[] = {
-        { "debug",    1, 0, 'd' },
-        { "help",     0, 0, 'h' },
-        { "quiet",    0, 0, 'q' },
-        { "timing",   0, 0, 't' },
-        { "version",  0, 0, 'v' },
+        {"debug", 1, 0, 'd'},
+        {"help", 0, 0, 'h'},
+        {"quiet", 0, 0, 'q'},
+        {"timing", 0, 0, 't'},
+        {"version", 0, 0, 'v'},
         {0, 0, 0, 0}
-    };         
+    };
+
 
-    
     if (argc < 2)
         return TRUE;
-    
+
     /* look for begin of the command, for example:
      *   ./virsh --debug 5 -q command --cmdoption
      *                  <--- ^ --->
      *        getopt() stuff | command suff
      */
-    for(i=1; i < argc; i++) {
+    for (i = 1; i < argc; i++) {
         if (*argv[i] != '-') {
             int valid = FALSE;
-            
+
             /* non "--option" argv, is it command? */
             if (last) {
                 struct option *o;
                 int sz = strlen(last);
-                
-                for(o=opt; o->name; o++) {
-                    if (sz==2 && *(last+1)==o->val)
+
+                for (o = opt; o->name; o++) {
+                    if (sz == 2 && *(last + 1) == o->val)
                         /* valid virsh short option */
                         valid = TRUE;
-                    else if (sz > 2 && strcmp(o->name, last+2)==0)
+                    else if (sz > 2 && strcmp(o->name, last + 2) == 0)
                         /* valid virsh long option */
                         valid = TRUE;
                 }
@@ -1720,10 +1782,10 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) {
         last = argv[i];
     }
     end = end ? : argc;
-    
+
     /* standard (non-command) options */
-    while((arg = getopt_long(end, argv, "d:hqtv", opt, &idx)) != -1) {
-        switch(arg) {
+    while ((arg = getopt_long(end, argv, "d:hqtv", opt, &idx)) != -1) {
+        switch (arg) {
             case 'd':
                 ctl->debug = atoi(optarg);
                 break;
@@ -1740,7 +1802,8 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) {
                 fprintf(stdout, "%s\n", VERSION);
                 exit(EXIT_SUCCESS);
             default:
-                vshError(ctl, TRUE, "unsupported option '-%c'. See --help.", arg);
+                vshError(ctl, TRUE,
+                  "unsupported option '-%c'. See --help.", arg);
                 break;
         }
     }
@@ -1749,68 +1812,72 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) {
         /* global or command specific help */
         vshUsage(ctl, argc > end ? argv[end] : NULL);
         exit(EXIT_SUCCESS);
-    }    
-    
+    }
+
     if (argc > end) {
         /* parse command */
         char *cmdstr;
-        int sz=0, ret;
-        
+        int sz = 0, ret;
+
         ctl->imode = FALSE;
-        
-        for (i=end; i < argc; i++)
-            sz += strlen(argv[i]) + 1;     /* +1 is for blank space between items */
 
-        cmdstr = calloc(sz+1, 1);
-        
-        for (i=end; i < argc; i++) {
+        for (i = end; i < argc; i++)
+            sz += strlen(argv[i]) + 1;  /* +1 is for blank space between items */
+
+        cmdstr = calloc(sz + 1, 1);
+
+        for (i = end; i < argc; i++) {
             strncat(cmdstr, argv[i], sz);
             sz -= strlen(argv[i]);
             strncat(cmdstr, " ", sz--);
         }
         vshPrint(ctl, VSH_DEBUG2, "command: \"%s\"\n", cmdstr);
         ret = vshCommandParse(ctl, cmdstr);
-        
+
         free(cmdstr);
         return ret;
     }
     return TRUE;
 }
 
-int 
-main(int argc, char **argv) {
-    vshControl _ctl, *ctl=&_ctl;
+int
+main(int argc, char **argv)
+{
+    vshControl _ctl, *ctl = &_ctl;
     int ret = TRUE;
 
-    if (!(progname=strrchr(argv[0], '/')))
+    if (!(progname = strrchr(argv[0], '/')))
         progname = argv[0];
     else
         progname++;
-    
+
     memset(ctl, 0, sizeof(vshControl));
-    ctl->imode = TRUE;    /* default is interactive mode */
+    ctl->imode = TRUE;          /* default is interactive mode */
 
     if (!vshParseArgv(ctl, argc, argv))
         exit(EXIT_FAILURE);
-        
+
     if (!vshInit(ctl))
         exit(EXIT_FAILURE);
-    
+
     if (!ctl->imode) {
-        ret = vshCommandRun(ctl, ctl->cmd);    
+        ret = vshCommandRun(ctl, ctl->cmd);
     } else {
         /* interactive mode */
         if (!ctl->quiet) {
-            vshPrint(ctl, VSH_MESG, "Welcome to %s, the virtualization interactive terminal.\n\n", 
-                        progname);
-            vshPrint(ctl, VSH_MESG, "Type:  'help' for help with commands\n"
-                                    "       'quit' to quit\n\n");
+            vshPrint(ctl, VSH_MESG,
+                     "Welcome to %s, the virtualization interactive terminal.\n\n",
+                     progname);
+            vshPrint(ctl, VSH_MESG,
+                     "Type:  'help' for help with commands\n"
+                     "       'quit' to quit\n\n");
         }
         vshReadlineInit();
         do {
-            ctl->cmdstr = readline(ctl->uid==0 ? VSH_PROMPT_RW : VSH_PROMPT_RO);
-            if (ctl->cmdstr==NULL)
-                break;                /* EOF */
+            ctl->cmdstr =
+                readline(ctl->uid == 0 ? VSH_PROMPT_RW : VSH_PROMPT_RO);
+            if (ctl->cmdstr == NULL)
+                break;          /* EOF */
             if (*ctl->cmdstr) {
                 add_history(ctl->cmdstr);
                 if (vshCommandParse(ctl, ctl->cmdstr))
@@ -1818,12 +1885,12 @@ main(int argc, char **argv) {
             }
             free(ctl->cmdstr);
             ctl->cmdstr = NULL;
-        } while(ctl->imode);    
+        } while (ctl->imode);
 
-        if (ctl->cmdstr==NULL)
-            fputc('\n', stdout);    /* line break after alone prompt */
+        if (ctl->cmdstr == NULL)
+            fputc('\n', stdout);        /* line break after alone prompt */
     }
-    
+
     vshDeinit(ctl);
     exit(ret ? EXIT_SUCCESS : EXIT_FAILURE);
 }
@@ -1833,4 +1900,3 @@ main(int argc, char **argv) {
  * vim: set shiftwidth=4:
  * vim: set expandtab:
  */
-
index c3510bcc0d8f942fff53699c2b309d5ccfa025b6..552cb7964488f3c0270a7b68ea9273b0bae792b8 100644 (file)
 #include "virterror.h"
 #include "internal.h"
 
-static virError     lastErr =          /* the last error */
-{ 0, 0, NULL, VIR_ERR_NONE, NULL, NULL, NULL, NULL, NULL, 0, 0};
-static virErrorFunc virErrorHandler = NULL;/* global error handlet */
-static void        *virUserData = NULL;        /* associated data */
+static virError lastErr =       /* the last error */
+{ 0, 0, NULL, VIR_ERR_NONE, NULL, NULL, NULL, NULL, NULL, 0, 0 };
+static virErrorFunc virErrorHandler = NULL;     /* global error handlet */
+static void *virUserData = NULL;        /* associated data */
 
 /*
  * Macro used to format the message as a string in __virRaiseError
@@ -68,10 +68,11 @@ static void        *virUserData = NULL;     /* associated data */
  * Returns a pointer to the last error or NULL if none occured.
  */
 virErrorPtr
-virGetLastError(void) {
+virGetLastError(void)
+{
     if (lastErr.code == VIR_ERR_OK)
-        return(NULL);
-    return(&lastErr);
+        return (NULL);
+    return (&lastErr);
 }
 
 /*
@@ -85,13 +86,14 @@ virGetLastError(void) {
  *         of parameter error.
  */
 int
-virCopyLastError(virErrorPtr to) {
+virCopyLastError(virErrorPtr to)
+{
     if (to == NULL)
-        return(-1);
+        return (-1);
     if (lastErr.code == VIR_ERR_OK)
-        return(0);
+        return (0);
     memcpy(to, &lastErr, sizeof(virError));
-    return(lastErr.code);
+    return (lastErr.code);
 }
 
 /**
@@ -101,7 +103,8 @@ virCopyLastError(virErrorPtr to) {
  * Reset the error being pointed to
  */
 void
-virResetError(virErrorPtr err) {
+virResetError(virErrorPtr err)
+{
     if (err == NULL)
         return;
     if (err->message != NULL)
@@ -121,7 +124,8 @@ virResetError(virErrorPtr err) {
  * Reset the last error caught at the library level.
  */
 void
-virResetLastError(void) {
+virResetLastError(void)
+{
     virResetError(&lastErr);
 }
 
@@ -136,10 +140,11 @@ virResetLastError(void) {
  * Returns a pointer to the last error or NULL if none occured.
  */
 virErrorPtr
-virConnGetLastError(virConnectPtr conn) {
+virConnGetLastError(virConnectPtr conn)
+{
     if (conn == NULL)
-       return(NULL);
-    return(&conn->err);
+        return (NULL);
+    return (&conn->err);
 }
 
 /**
@@ -154,15 +159,16 @@ virConnGetLastError(virConnectPtr conn) {
  *         of parameter error.
  */
 int
-virConnCopyLastError(virConnectPtr conn, virErrorPtr to) {
+virConnCopyLastError(virConnectPtr conn, virErrorPtr to)
+{
     if (conn == NULL)
-       return(-1);
+        return (-1);
     if (to == NULL)
-        return(-1);
+        return (-1);
     if (conn->err.code == VIR_ERR_OK)
-        return(0);
+        return (0);
     memcpy(to, &conn->err, sizeof(virError));
-    return(conn->err.code);
+    return (conn->err.code);
 }
 
 /**
@@ -172,7 +178,8 @@ virConnCopyLastError(virConnectPtr conn, virErrorPtr to) {
  * Reset the last error caught on that connection
  */
 void
-virConnResetLastError(virConnectPtr conn) {
+virConnResetLastError(virConnectPtr conn)
+{
     if (conn == NULL)
         return;
     virResetError(&conn->err);
@@ -188,7 +195,8 @@ virConnResetLastError(virConnectPtr conn) {
  * are those for which no handler at the connection level could caught.
  */
 void
-virSetErrorFunc(void *userData, virErrorFunc handler) {
+virSetErrorFunc(void *userData, virErrorFunc handler)
+{
     virErrorHandler = handler;
     virUserData = userData;
 }
@@ -204,7 +212,9 @@ virSetErrorFunc(void *userData, virErrorFunc handler) {
  * library handler.
  */
 void
-virConnSetErrorFunc(virConnectPtr conn, void *userData, virErrorFunc handler) {
+virConnSetErrorFunc(virConnectPtr conn, void *userData,
+                    virErrorFunc handler)
+{
     if (conn == NULL)
         return;
     conn->handler = handler;
@@ -218,7 +228,8 @@ virConnSetErrorFunc(virConnectPtr conn, void *userData, virErrorFunc handler) {
  * Default routine reporting an error to stderr.
  */
 void
-virDefaultErrorFunc(virErrorPtr err) {
+virDefaultErrorFunc(virErrorPtr err)
+{
     const char *lvl = "", *dom = "", *domain = "";
     int len;
 
@@ -226,39 +237,39 @@ virDefaultErrorFunc(virErrorPtr err) {
         return;
     switch (err->level) {
         case VIR_ERR_NONE:
-           lvl = "";
-           break;
+            lvl = "";
+            break;
         case VIR_ERR_WARNING:
-           lvl = "warning";
-           break;
+            lvl = "warning";
+            break;
         case VIR_ERR_ERROR:
-           lvl = "error";
-           break;
-    } 
+            lvl = "error";
+            break;
+    }
     switch (err->domain) {
         case VIR_FROM_NONE:
-           dom = "";
-           break;
+            dom = "";
+            break;
         case VIR_FROM_XEN:
-           dom = "Xen ";
-           break;
+            dom = "Xen ";
+            break;
         case VIR_FROM_XEND:
-           dom = "Xen Daemon ";
-           break;
+            dom = "Xen Daemon ";
+            break;
         case VIR_FROM_DOM:
-           dom = "Domain ";
-           break;
+            dom = "Domain ";
+            break;
     }
     if ((err->dom != NULL) && (err->code != VIR_ERR_INVALID_DOMAIN)) {
         domain = err->dom->name;
     }
     len = strlen(err->message);
     if ((len == 0) || (err->message[len - 1] != '\n'))
-       fprintf(stderr, "libvir: %s%s %s: %s\n",
-               dom, lvl, domain, err->message);
-    else 
-       fprintf(stderr, "libvir: %s%s %s: %s",
-               dom, lvl, domain, err->message);
+        fprintf(stderr, "libvir: %s%s %s: %s\n",
+                dom, lvl, domain, err->message);
+    else
+        fprintf(stderr, "libvir: %s%s %s: %s",
+                dom, lvl, domain, err->message);
 }
 
 /**
@@ -283,24 +294,25 @@ void
 __virRaiseError(virConnectPtr conn, virDomainPtr dom,
                 int domain, int code, virErrorLevel level,
                 const char *str1, const char *str2, const char *str3,
-               int int1, int int2, const char *msg, ...) {
+                int int1, int int2, const char *msg, ...)
+{
     virErrorPtr to = &lastErr;
     void *userData = virUserData;
     virErrorFunc handler = virErrorHandler;
     char *str;
 
     if (code == VIR_ERR_OK)
-       return;
+        return;
 
     /*
      * try to find the best place to save and report the error
      */
     if (conn != NULL) {
         to = &conn->err;
-       if (conn->handler != NULL) {
-           handler = conn->handler;
-           userData = conn->userData;
-       }
+        if (conn->handler != NULL) {
+            handler = conn->handler;
+            userData = conn->userData;
+        }
     }
 
     /*
@@ -352,124 +364,124 @@ __virRaiseError(virConnectPtr conn, virDomainPtr dom,
  * Returns the constant string associated to @error
  */
 const char *
-__virErrorMsg(virErrorNumber error, const char *info) {
+__virErrorMsg(virErrorNumber error, const char *info)
+{
     const char *errmsg = NULL;
 
     switch (error) {
         case VIR_ERR_OK:
-           return(NULL);
-       case VIR_ERR_INTERNAL_ERROR:
-           if (info != NULL)
-               errmsg = "internal error %s";
-           else
-               errmsg = "internal error";
-           break;
-       case VIR_ERR_NO_MEMORY:
-           errmsg = "out of memory";
-           break;
-       case VIR_ERR_NO_SUPPORT:
-           errmsg = "no support for hypervisor %s";
-           break;
-       case VIR_ERR_NO_CONNECT:
-           if (info == NULL)
-               errmsg = "could not connect to hypervisor";
-           else
-               errmsg = "could not connect to %s";
-           break;
-       case VIR_ERR_INVALID_CONN:
-           errmsg = "invalid connection pointer in";
-           break;
-       case VIR_ERR_INVALID_DOMAIN:
-           errmsg = "invalid domain pointer in";
-           break;
-       case VIR_ERR_INVALID_ARG:
-           errmsg = "invalid domain pointer in";
-           break;
-       case VIR_ERR_OPERATION_FAILED:
-           if (info != NULL)
-               errmsg = "operation failed: %s";
-           else
-               errmsg = "operation failed";
-           break;
-       case VIR_ERR_GET_FAILED:
-           if (info != NULL)
-               errmsg = "GET operation failed: %s";
-           else
-               errmsg = "GET operation failed";
-           break;
-       case VIR_ERR_POST_FAILED:
-           if (info != NULL)
-               errmsg = "POST operation failed: %s";
-           else
-               errmsg = "POST operation failed";
-           break;
-       case VIR_ERR_HTTP_ERROR:
-           errmsg = "got unknown HTTP error code %d";
-           break;
-       case VIR_ERR_UNKNOWN_HOST:
-           errmsg = "unknown host %s";
-           break;
-       case VIR_ERR_SEXPR_SERIAL:
-           if (info != NULL)
-               errmsg = "failed to serialize S-Expr: %s";
-           else
-               errmsg = "failed to serialize S-Expr";
-           break;
-       case VIR_ERR_NO_XEN:
-           if (info == NULL)
-               errmsg = "could not use Xen hypervisor entry";
-           else
-               errmsg = "could not use Xen hypervisor entry %s";
-           break;
-       case VIR_ERR_XEN_CALL:
-           errmsg = "failed Xen syscall %s %d";
-           break;
-       case VIR_ERR_OS_TYPE:
-           if (info == NULL)
-               errmsg = "unknown OS type";
-           else
-               errmsg = "unknown OS type %s";
-           break;
-       case VIR_ERR_NO_KERNEL:
-           errmsg = "missing kernel informations";
-           break;
-       case VIR_ERR_NO_ROOT:
-           if (info == NULL)
-               errmsg = "missing root device informations";
-           else
-               errmsg = "missing root device informations in %s";
-           break;
-       case VIR_ERR_NO_SOURCE:
-           if (info == NULL)
-               errmsg = "missing source informations for device";
-           else
-               errmsg = "missing source informations for device %s";
-           break;
-       case VIR_ERR_NO_TARGET:
-           if (info == NULL)
-               errmsg = "missing target informations for device";
-           else
-               errmsg = "missing target informations for device %s";
-           break;
-       case VIR_ERR_NO_NAME:
-           if (info == NULL)
-               errmsg = "missing domain name informations";
-           else
-               errmsg = "missing domain name informations in %s";
-           break;
-       case VIR_ERR_NO_OS:
-           if (info == NULL)
-               errmsg = "missing operating system informations";
-           else
-               errmsg = "missing operating system informations for %s";
-           break;
-       case VIR_ERR_NO_DEVICE:
-           if (info == NULL)
-               errmsg = "missing devices informations";
-           else
-               errmsg = "missing devices informations for %s";
-           break;
+            return (NULL);
+        case VIR_ERR_INTERNAL_ERROR:
+            if (info != NULL)
+                errmsg = "internal error %s";
+            else
+                errmsg = "internal error";
+            break;
+        case VIR_ERR_NO_MEMORY:
+            errmsg = "out of memory";
+            break;
+        case VIR_ERR_NO_SUPPORT:
+            errmsg = "no support for hypervisor %s";
+            break;
+        case VIR_ERR_NO_CONNECT:
+            if (info == NULL)
+                errmsg = "could not connect to hypervisor";
+            else
+                errmsg = "could not connect to %s";
+            break;
+        case VIR_ERR_INVALID_CONN:
+            errmsg = "invalid connection pointer in";
+            break;
+        case VIR_ERR_INVALID_DOMAIN:
+            errmsg = "invalid domain pointer in";
+            break;
+        case VIR_ERR_INVALID_ARG:
+            errmsg = "invalid domain pointer in";
+            break;
+        case VIR_ERR_OPERATION_FAILED:
+            if (info != NULL)
+                errmsg = "operation failed: %s";
+            else
+                errmsg = "operation failed";
+            break;
+        case VIR_ERR_GET_FAILED:
+            if (info != NULL)
+                errmsg = "GET operation failed: %s";
+            else
+                errmsg = "GET operation failed";
+            break;
+        case VIR_ERR_POST_FAILED:
+            if (info != NULL)
+                errmsg = "POST operation failed: %s";
+            else
+                errmsg = "POST operation failed";
+            break;
+        case VIR_ERR_HTTP_ERROR:
+            errmsg = "got unknown HTTP error code %d";
+            break;
+        case VIR_ERR_UNKNOWN_HOST:
+            errmsg = "unknown host %s";
+            break;
+        case VIR_ERR_SEXPR_SERIAL:
+            if (info != NULL)
+                errmsg = "failed to serialize S-Expr: %s";
+            else
+                errmsg = "failed to serialize S-Expr";
+            break;
+        case VIR_ERR_NO_XEN:
+            if (info == NULL)
+                errmsg = "could not use Xen hypervisor entry";
+            else
+                errmsg = "could not use Xen hypervisor entry %s";
+            break;
+        case VIR_ERR_XEN_CALL:
+            errmsg = "failed Xen syscall %s %d";
+            break;
+        case VIR_ERR_OS_TYPE:
+            if (info == NULL)
+                errmsg = "unknown OS type";
+            else
+                errmsg = "unknown OS type %s";
+            break;
+        case VIR_ERR_NO_KERNEL:
+            errmsg = "missing kernel informations";
+            break;
+        case VIR_ERR_NO_ROOT:
+            if (info == NULL)
+                errmsg = "missing root device informations";
+            else
+                errmsg = "missing root device informations in %s";
+            break;
+        case VIR_ERR_NO_SOURCE:
+            if (info == NULL)
+                errmsg = "missing source informations for device";
+            else
+                errmsg = "missing source informations for device %s";
+            break;
+        case VIR_ERR_NO_TARGET:
+            if (info == NULL)
+                errmsg = "missing target informations for device";
+            else
+                errmsg = "missing target informations for device %s";
+            break;
+        case VIR_ERR_NO_NAME:
+            if (info == NULL)
+                errmsg = "missing domain name informations";
+            else
+                errmsg = "missing domain name informations in %s";
+            break;
+        case VIR_ERR_NO_OS:
+            if (info == NULL)
+                errmsg = "missing operating system informations";
+            else
+                errmsg = "missing operating system informations for %s";
+            break;
+        case VIR_ERR_NO_DEVICE:
+            if (info == NULL)
+                errmsg = "missing devices informations";
+            else
+                errmsg = "missing devices informations for %s";
+            break;
     }
-    return(errmsg);
+    return (errmsg);
 }
-
index 98a6dbd7c37b7f9858bb48c6822c65d05d405c90..30d94feb3ee0e7260c5cfa6e5ce0ca302c129399 100644 (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,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);
 }
index a819b441489b22ae0097e7c20f9e09b5b2f5c7a6..6ff7d29e022d93c8315a690fa49d2ab77a6f7c41 100644 (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>
 
 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__ */
index 1d94e772b0e7c166213c832e94fca01cd0924e43..7c3bc9966bf9e916db3e709712cb32963c701db0 100644 (file)
@@ -67,9 +67,10 @@ struct xend {
  * Handle an error at the xend daemon interface
  */
 static void
-virXendError(virConnectPtr conn, virErrorNumber error, const char *info) {
+virXendError(virConnectPtr conn, virErrorNumber error, const char *info)
+{
     const char *errmsg;
-    
+
     if (error == VIR_ERR_OK)
         return;
 
@@ -87,10 +88,10 @@ virXendError(virConnectPtr conn, virErrorNumber error, const char *info) {
  * Handle an error at the xend daemon interface
  */
 static void
-virXendErrorInt(virConnectPtr conn, virErrorNumber error,
-                int val) {
+virXendErrorInt(virConnectPtr conn, virErrorNumber error, int val)
+{
     const char *errmsg;
-    
+
     if (error == VIR_ERR_OK)
         return;
 
@@ -126,7 +127,7 @@ do_connect(virConnectPtr xend)
     s = socket(xend->type, SOCK_STREAM, 0);
     if (s == -1) {
         virXendError(xend, VIR_ERR_INTERNAL_ERROR,
-                    "failed to create a socket");
+                     "failed to create a socket");
         return -1;
     }
 
@@ -161,9 +162,9 @@ wr_sync(int fd, void *buffer, size_t size, int do_read)
         ssize_t len;
 
         if (do_read) {
-            len = read(fd, ((char *)buffer) + offset, size - offset);
+            len = read(fd, ((char *) buffer) + offset, size - offset);
         } else {
-            len = write(fd, ((char *)buffer) + offset, size - offset);
+            len = write(fd, ((char *) buffer) + offset, size - offset);
         }
 
         /* recoverable error, retry  */
@@ -178,14 +179,14 @@ wr_sync(int fd, void *buffer, size_t size, int do_read)
 
         /* unrecoverable error */
         if (len == -1) {
-           if (do_read)
-               virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
-                            "faid to read from Xen Daemon");
-           else
-               virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
-                            "faid to read from Xen Daemon");
-               
-            return(-1);
+            if (do_read)
+                virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
+                             "faid to read from Xen Daemon");
+            else
+                virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
+                             "faid to read from Xen Daemon");
+
+            return (-1);
         }
 
         offset += len;
@@ -257,7 +258,7 @@ sreads(int fd, char *buffer, size_t n_buffer)
     size_t offset;
 
     if (n_buffer < 1)
-        return(-1);
+        return (-1);
 
     for (offset = 0; offset < (n_buffer - 1); offset++) {
         ssize_t ret;
@@ -364,7 +365,7 @@ xend_get(virConnectPtr xend, const char *path,
     close(s);
 
     if ((ret < 0) || (ret >= 300)) {
-       virXendError(NULL, VIR_ERR_GET_FAILED, content);
+        virXendError(NULL, VIR_ERR_GET_FAILED, content);
     }
 
     return ret;
@@ -412,7 +413,7 @@ xend_post(virConnectPtr xend, const char *path, const char *ops,
     close(s);
 
     if ((ret < 0) || (ret >= 300)) {
-       virXendError(NULL, VIR_ERR_POST_FAILED, content);
+        virXendError(NULL, VIR_ERR_POST_FAILED, content);
     }
 
     return ret;
@@ -440,7 +441,7 @@ http2unix(int ret)
             errno = ESRCH;
             break;
         default:
-            virXendErrorInt(NULL, VIR_ERR_HTTP_ERROR,  ret);
+            virXendErrorInt(NULL, VIR_ERR_HTTP_ERROR, ret);
             errno = EINVAL;
             break;
     }
@@ -935,7 +936,7 @@ urlencode(const char *string)
     size_t i;
 
     if (buffer == NULL)
-        return(NULL);
+        return (NULL);
     for (i = 0; i < len; i++) {
         switch (string[i]) {
             case ' ':
@@ -1027,7 +1028,7 @@ xend_setup_unix(virConnectPtr xend, const char *path)
     struct sockaddr_un *addr;
 
     if ((xend == NULL) || (path == NULL))
-        return(-1);
+        return (-1);
 
     addr = &xend->addr_un;
     addr->sun_family = AF_UNIX;
@@ -1041,7 +1042,7 @@ xend_setup_unix(virConnectPtr xend, const char *path)
     xend->addr = (struct sockaddr *) addr;
     xend->type = PF_UNIX;
 
-    return(0);
+    return (0);
 }
 
 /**
@@ -1062,14 +1063,14 @@ xend_setup_tcp(virConnectPtr xend, const char *host, int port)
     struct hostent *pent;
 
     if ((xend == NULL) || (host == NULL) || (port <= 0))
-        return(-1);
+        return (-1);
 
     pent = gethostbyname(host);
     if (pent == NULL) {
         if (inet_aton(host, &ip) == 0) {
-           virXendError(xend, VIR_ERR_UNKNOWN_HOST, host);
+            virXendError(xend, VIR_ERR_UNKNOWN_HOST, host);
             errno = ESRCH;
-            return(-1);
+            return (-1);
         }
     } else {
         memcpy(&ip, pent->h_addr_list[0], sizeof(ip));
@@ -1083,7 +1084,7 @@ xend_setup_tcp(virConnectPtr xend, const char *host, int port)
     xend->addr_in.sin_port = htons(port);
     memcpy(&xend->addr_in.sin_addr, &ip, sizeof(ip));
 
-    return(0);
+    return (0);
 }
 
 /**
@@ -1098,7 +1099,8 @@ xend_setup_tcp(virConnectPtr xend, const char *host, int port)
 int
 xend_setup(virConnectPtr conn)
 {
-    return(xend_setup_tcp(conn, "localhost", 8000));
+    return (xend_setup_tcp(conn, "localhost", 8000));
+
 /*    return(xend_setup_unix(conn, "/var/lib/xend/xend-socket")); */
 }
 
@@ -1173,9 +1175,9 @@ int
 xend_rename(virConnectPtr xend, const char *old, const char *new)
 {
     if ((xend == NULL) || (old == NULL) || (new == NULL)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
     return xend_op(xend, old, "op", "rename", "name", new, NULL);
 }
@@ -1193,9 +1195,9 @@ int
 xend_reboot(virConnectPtr xend, const char *name)
 {
     if ((xend == NULL) || (name == NULL)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
     return xend_op(xend, name, "op", "shutdown", "reason", "reboot", NULL);
 }
@@ -1214,12 +1216,11 @@ int
 xend_shutdown(virConnectPtr xend, const char *name)
 {
     if ((xend == NULL) || (name == NULL)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
-    return xend_op(xend, name,
-                   "op", "shutdown", "reason", "halt", NULL);
+    return xend_op(xend, name, "op", "shutdown", "reason", "halt", NULL);
 }
 
 /**
@@ -1236,9 +1237,9 @@ int
 xend_sysrq(virConnectPtr xend, const char *name, const char *key)
 {
     if ((xend == NULL) || (name == NULL) || (key == NULL)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
     return xend_op(xend, name, "op", "sysrq", "key", key, NULL);
 }
@@ -1258,9 +1259,9 @@ int
 xend_destroy(virConnectPtr xend, const char *name)
 {
     if ((xend == NULL) || (name == NULL)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
     return xend_op(xend, name, "op", "destroy", NULL);
 }
@@ -1283,9 +1284,9 @@ int
 xend_save(virConnectPtr xend, const char *name, const char *filename)
 {
     if ((xend == NULL) || (filename == NULL)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
     return xend_op(xend, name, "op", "save", "file", filename, NULL);
 }
@@ -1305,9 +1306,9 @@ int
 xend_restore(virConnectPtr xend, const char *filename)
 {
     if ((xend == NULL) || (filename == NULL)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return(-1);
+        return (-1);
     }
     return xend_op(xend, "", "op", "restore", "file", filename, NULL);
 }
@@ -1390,7 +1391,7 @@ xend_domain_to_sexpr(const struct xend_domain *domain)
     size_t i;
 
     if (domain == NULL)
-        return(NULL);
+        return (NULL);
 
     lst = sexpr_append(lst, sexpr_string("vm", -1));
     lst = sexpr_append_str(lst, "name", domain->name);
@@ -1505,10 +1506,10 @@ xend_create_sexpr(virConnectPtr xend, const char *sexpr)
 
     ptr = urlencode(sexpr);
     if (ptr == NULL) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(xend, VIR_ERR_INTERNAL_ERROR,
-                    "Failed to urlencode the create S-Expr");
-       return(-1);
+                     "Failed to urlencode the create S-Expr");
+        return (-1);
     }
 
     ret = xend_op(xend, "", "op", "create", "config", ptr, NULL);
@@ -1750,21 +1751,21 @@ sexpr_to_xend_domain_size(struct sexpr *root, int *n_vbds, int *n_vifs)
 
     for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
          _for_i = _for_i->cdr, node = _for_i->car) {
-       if (sexpr_lookup(node, "device/vbd")) {
-           size += sexpr_strlen(node, "device/vbd/dev");
-           size += sexpr_strlen(node, "device/vbd/uname");
-           (*n_vbds)++;
-       }
+        if (sexpr_lookup(node, "device/vbd")) {
+            size += sexpr_strlen(node, "device/vbd/dev");
+            size += sexpr_strlen(node, "device/vbd/uname");
+            (*n_vbds)++;
+        }
     }
 
     for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
          _for_i = _for_i->cdr, node = _for_i->car) {
-       if (sexpr_lookup(node, "device/vif")) {
-           size += sexpr_strlen(node, "device/vif/bridge");
-           size += sexpr_strlen(node, "device/vif/ip");
-           size += sexpr_strlen(node, "device/vif/script");
-           size += sexpr_strlen(node, "device/vif/vifname");
-           (*n_vifs)++;
+        if (sexpr_lookup(node, "device/vif")) {
+            size += sexpr_strlen(node, "device/vif/bridge");
+            size += sexpr_strlen(node, "device/vif/ip");
+            size += sexpr_strlen(node, "device/vif/script");
+            size += sexpr_strlen(node, "device/vif/vifname");
+            (*n_vifs)++;
         }
     }
 
@@ -1795,10 +1796,10 @@ static int
 sexpr_to_xend_domain_info(struct sexpr *root, virDomainInfoPtr info)
 {
     const char *flags;
-    
+
 
     if ((root == NULL) || (info == NULL))
-        return(-1);
+        return (-1);
 
     info->memory = sexpr_u64(root, "domain/memory") << 10;
     info->maxMem = sexpr_u64(root, "domain/maxmem") << 10;
@@ -1806,23 +1807,23 @@ sexpr_to_xend_domain_info(struct sexpr *root, virDomainInfoPtr info)
 
     if (flags) {
         if (strchr(flags, 'c'))
-           info->state = VIR_DOMAIN_CRASHED;
-       else if (strchr(flags, 's'))
-           info->state = VIR_DOMAIN_SHUTDOWN;
-       else if (strchr(flags, 'd'))
-           info->state = VIR_DOMAIN_SHUTOFF;
-       else if (strchr(flags, 'p'))
-           info->state = VIR_DOMAIN_PAUSED;
-       else if (strchr(flags, 'b'))
-           info->state = VIR_DOMAIN_BLOCKED;
-       else if (strchr(flags, 'r'))
-           info->state = VIR_DOMAIN_RUNNING;
+            info->state = VIR_DOMAIN_CRASHED;
+        else if (strchr(flags, 's'))
+            info->state = VIR_DOMAIN_SHUTDOWN;
+        else if (strchr(flags, 'd'))
+            info->state = VIR_DOMAIN_SHUTOFF;
+        else if (strchr(flags, 'p'))
+            info->state = VIR_DOMAIN_PAUSED;
+        else if (strchr(flags, 'b'))
+            info->state = VIR_DOMAIN_BLOCKED;
+        else if (strchr(flags, 'r'))
+            info->state = VIR_DOMAIN_RUNNING;
     } else {
         info->state = VIR_DOMAIN_NOSTATE;
     }
     info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000;
     info->nrVirtCpu = sexpr_int(root, "domain/vcpus");
-    return(0);
+    return (0);
 }
 
 /**
@@ -1913,33 +1914,34 @@ sexpr_to_xend_domain(struct sexpr *root)
     i = 0;
     for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
          _for_i = _for_i->cdr, node = _for_i->car) {
-       if (sexpr_lookup(node, "device/vbd")) {
-           dom->vbds[i].dev = sexpr_strcpy(&ptr, node, "device/vbd/dev");
-           dom->vbds[i].uname = sexpr_strcpy(&ptr, node, "device/vbd/uname");
-           dom->vbds[i].backend = sexpr_int(node, "device/vbd/backend");
-           dom->vbds[i].mode = sexpr_mode(node, "device/vbd/mode");
-           i++;
-       }
+        if (sexpr_lookup(node, "device/vbd")) {
+            dom->vbds[i].dev = sexpr_strcpy(&ptr, node, "device/vbd/dev");
+            dom->vbds[i].uname =
+                sexpr_strcpy(&ptr, node, "device/vbd/uname");
+            dom->vbds[i].backend = sexpr_int(node, "device/vbd/backend");
+            dom->vbds[i].mode = sexpr_mode(node, "device/vbd/mode");
+            i++;
+        }
     }
 
     i = 0;
     for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
          _for_i = _for_i->cdr, node = _for_i->car) {
-       if (sexpr_lookup(node, "device/vif")) {
-           dom->vifs[i].backend = sexpr_int(node, "device/vif/backend");
-           dom->vifs[i].bridge =
-               sexpr_strcpy(&ptr, node, "device/vif/bridge");
-           dom->vifs[i].ip = sexpr_strcpy(&ptr, node, "device/vif/ip");
-           sexpr_mac(dom->vifs[i].mac, node, "device/vif/mac");
-           dom->vifs[i].script =
-               sexpr_strcpy(&ptr, node, "device/vif/script");
-           dom->vifs[i].vifname =
-               sexpr_strcpy(&ptr, node, "device/vif/vifname");
-           i++;
+        if (sexpr_lookup(node, "device/vif")) {
+            dom->vifs[i].backend = sexpr_int(node, "device/vif/backend");
+            dom->vifs[i].bridge =
+                sexpr_strcpy(&ptr, node, "device/vif/bridge");
+            dom->vifs[i].ip = sexpr_strcpy(&ptr, node, "device/vif/ip");
+            sexpr_mac(dom->vifs[i].mac, node, "device/vif/mac");
+            dom->vifs[i].script =
+                sexpr_strcpy(&ptr, node, "device/vif/script");
+            dom->vifs[i].vifname =
+                sexpr_strcpy(&ptr, node, "device/vif/vifname");
+            i++;
         }
     }
 
-error:
+  error:
     return dom;
 }
 
@@ -1960,15 +1962,16 @@ xend_get_domain_info(virDomainPtr domain, virDomainInfoPtr info)
     int ret;
 
     if ((domain == NULL) || (info == NULL))
-        return(-1);
+        return (-1);
 
-    root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
+    root =
+        sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
     if (root == NULL)
-        return(-1);
+        return (-1);
 
     ret = sexpr_to_xend_domain_info(root, info);
     sexpr_free(root);
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -2017,7 +2020,7 @@ xend_get_domain_ids(virConnectPtr xend, const char *domname,
     const char *value;
     int ret = -1;
 
-    if (uuid != NULL) 
+    if (uuid != NULL)
         memset(uuid, 0, 16);
     root = sexpr_get(xend, "/xend/domain/%s?detail=1", domname);
     if (root == NULL)
@@ -2026,25 +2029,26 @@ xend_get_domain_ids(virConnectPtr xend, const char *domname,
     value = sexpr_node(root, "domain/domid");
     if (value == NULL) {
         virXendError(xend, VIR_ERR_INTERNAL_ERROR,
-                    "domain informations incomplete, missing domid");
+                     "domain informations incomplete, missing domid");
         goto error;
     }
     ret = strtol(value, NULL, 0);
     if ((ret == 0) && (value[0] != '0')) {
         virXendError(xend, VIR_ERR_INTERNAL_ERROR,
-                    "domain informations incorrect domid not numberic");
+                     "domain informations incorrect domid not numberic");
         ret = -1;
     } else if (uuid != NULL) {
         char **ptr = (char **) &uuid;
+
         if (sexpr_uuid(ptr, root, "domain/uuid") == NULL) {
-           virXendError(xend, VIR_ERR_INTERNAL_ERROR,
-                        "domain informations incomplete, missing uuid");
-       }
+            virXendError(xend, VIR_ERR_INTERNAL_ERROR,
+                         "domain informations incomplete, missing uuid");
+        }
     }
 
-error:
+  error:
     sexpr_free(root);
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -2222,7 +2226,8 @@ xend_log(virConnectPtr xend, char *buffer, size_t n_buffer)
  *         the caller must free() the returned value.
  */
 static char *
-xend_parse_sexp_desc(struct sexpr *root) {
+xend_parse_sexp_desc(struct sexpr *root)
+{
     char *ret;
     struct sexpr *cur, *node;
     const char *tmp;
@@ -2230,11 +2235,11 @@ xend_parse_sexp_desc(struct sexpr *root) {
 
     if (root == NULL) {
         /* ERROR */
-        return(NULL);
+        return (NULL);
     }
     ret = malloc(1000);
     if (ret == NULL)
-        return(NULL);
+        return (NULL);
     buf.content = ret;
     buf.size = 1000;
     buf.use = 0;
@@ -2243,122 +2248,125 @@ xend_parse_sexp_desc(struct sexpr *root) {
                       sexpr_int(root, "domain/domid"));
     tmp = sexpr_node(root, "domain/name");
     if (tmp == NULL) {
-       virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
-                    "domain informations incomplete, missing name");
-       goto error;
+        virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
+                     "domain informations incomplete, missing name");
+        goto error;
     }
     virBufferVSprintf(&buf, "  <name>%s</name>\n", tmp);
     tmp = sexpr_node(root, "domain/image/linux/kernel");
     if (tmp == NULL) {
         /*
-        * TODO: we will need some fallback here for other guest OSes
-        */
-       virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
-                    "domain informations incomplete, missing kernel");
-       goto error;
+         * TODO: we will need some fallback here for other guest OSes
+         */
+        virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
+                     "domain informations incomplete, missing kernel");
+        goto error;
     }
     virBufferAdd(&buf, "  <os>\n", 7);
     virBufferVSprintf(&buf, "    <type>linux</type>\n");
     virBufferVSprintf(&buf, "    <kernel>%s</kernel>\n", tmp);
     tmp = sexpr_node(root, "domain/image/linux/ramdisk");
     if ((tmp != NULL) && (tmp[0] != 0))
-       virBufferVSprintf(&buf, "    <initrd>%s</initrd>\n", tmp);
+        virBufferVSprintf(&buf, "    <initrd>%s</initrd>\n", tmp);
     tmp = sexpr_node(root, "domain/image/linux/root");
     if ((tmp != NULL) && (tmp[0] != 0))
-       virBufferVSprintf(&buf, "    <root>%s</root>\n", tmp);
+        virBufferVSprintf(&buf, "    <root>%s</root>\n", tmp);
     tmp = sexpr_node(root, "domain/image/linux/args");
     if ((tmp != NULL) && (tmp[0] != 0))
-       virBufferVSprintf(&buf, "    <cmdline>%s</cmdline>\n", tmp);
+        virBufferVSprintf(&buf, "    <cmdline>%s</cmdline>\n", tmp);
     virBufferAdd(&buf, "  </os>\n", 8);
-    virBufferVSprintf(&buf, "  <memory>%d</memory>\n", 
+    virBufferVSprintf(&buf, "  <memory>%d</memory>\n",
                       (int) (sexpr_u64(root, "domain/maxmem") << 10));
-    virBufferVSprintf(&buf, "  <vcpu>%d</vcpu>\n", 
+    virBufferVSprintf(&buf, "  <vcpu>%d</vcpu>\n",
                       sexpr_int(root, "domain/vcpus"));
     virBufferAdd(&buf, "  <devices>\n", 12);
     for (cur = root; cur->kind == SEXPR_CONS; cur = cur->cdr) {
         node = cur->car;
-       if (sexpr_lookup(node, "device/vbd")) {
-           tmp = sexpr_node(node, "device/vbd/uname");
-           if (tmp == NULL)
-               continue;
-           if (!memcmp(tmp, "file:", 5)) {
-               tmp += 5;
-               virBufferVSprintf(&buf, "    <disk type='file'>\n");
-               virBufferVSprintf(&buf, "      <source file='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vbd/dev");
-               if (tmp == NULL) {
-                   virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
-                    "domain informations incomplete, vbd has no dev");
-                   goto error;
-               }
-               virBufferVSprintf(&buf, "      <target dev='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vbd/mode");
-               if ((tmp != NULL) && (!strcmp(tmp, "r")))
-                   virBufferVSprintf(&buf, "      <readonly/>\n");
-               virBufferAdd(&buf, "    </disk>\n", 12);
-           } else if (!memcmp(tmp, "phy:", 4)) {
-               tmp += 4;
-               virBufferVSprintf(&buf, "    <disk type='block'>\n");
-               virBufferVSprintf(&buf, "      <source dev='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vbd/dev");
-               if (tmp == NULL) {
-                   virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
-                    "domain informations incomplete, vbd has no dev");
-                   goto error;
-               }
-               virBufferVSprintf(&buf, "      <target dev='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vbd/mode");
-               if ((tmp != NULL) && (!strcmp(tmp, "r")))
-                   virBufferVSprintf(&buf, "      <readonly/>\n");
-               virBufferAdd(&buf, "    </disk>\n", 12);
-           } else {
-               char serial[1000];
-
-               TODO
-               sexpr2string(node, serial, 1000);
-               virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
-                                 serial);
-               TODO
-           }
-       } else if (sexpr_lookup(node, "device/vif")) {
-           tmp = sexpr_node(node, "device/vif/bridge");
-           if (tmp != NULL) {
-               virBufferVSprintf(&buf, "    <interface type='bridge'>\n");
-               virBufferVSprintf(&buf, "      <source bridge='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vif/vifname");
-               if (tmp != NULL)
-                   virBufferVSprintf(&buf, "      <target dev='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vif/mac");
-               if (tmp != NULL)
-                   virBufferVSprintf(&buf, "      <mac address='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vif/ip");
-               if (tmp != NULL)
-                   virBufferVSprintf(&buf, "      <ip address='%s'/>\n", tmp);
-               tmp = sexpr_node(node, "device/vif/script");
-               if (tmp != NULL)
-                   virBufferVSprintf(&buf, "      <script path='%s'/>\n", tmp);
-               virBufferAdd(&buf, "    </interface>\n", 17);
-           } else {
-               char serial[1000];
-
-               TODO
-               sexpr2string(node->car, serial, 1000);
-               virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
-                                 serial);
-           }
-           
-       }
+        if (sexpr_lookup(node, "device/vbd")) {
+            tmp = sexpr_node(node, "device/vbd/uname");
+            if (tmp == NULL)
+                continue;
+            if (!memcmp(tmp, "file:", 5)) {
+                tmp += 5;
+                virBufferVSprintf(&buf, "    <disk type='file'>\n");
+                virBufferVSprintf(&buf, "      <source file='%s'/>\n",
+                                  tmp);
+                tmp = sexpr_node(node, "device/vbd/dev");
+                if (tmp == NULL) {
+                    virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
+                                 "domain informations incomplete, vbd has no dev");
+                    goto error;
+                }
+                virBufferVSprintf(&buf, "      <target dev='%s'/>\n", tmp);
+                tmp = sexpr_node(node, "device/vbd/mode");
+                if ((tmp != NULL) && (!strcmp(tmp, "r")))
+                    virBufferVSprintf(&buf, "      <readonly/>\n");
+                virBufferAdd(&buf, "    </disk>\n", 12);
+            } else if (!memcmp(tmp, "phy:", 4)) {
+                tmp += 4;
+                virBufferVSprintf(&buf, "    <disk type='block'>\n");
+                virBufferVSprintf(&buf, "      <source dev='%s'/>\n", tmp);
+                tmp = sexpr_node(node, "device/vbd/dev");
+                if (tmp == NULL) {
+                    virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
+                                 "domain informations incomplete, vbd has no dev");
+                    goto error;
+                }
+                virBufferVSprintf(&buf, "      <target dev='%s'/>\n", tmp);
+                tmp = sexpr_node(node, "device/vbd/mode");
+                if ((tmp != NULL) && (!strcmp(tmp, "r")))
+                    virBufferVSprintf(&buf, "      <readonly/>\n");
+                virBufferAdd(&buf, "    </disk>\n", 12);
+            } else {
+                char serial[1000];
+
+                TODO sexpr2string(node, serial, 1000);
+                virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
+                                  serial);
+            TODO}
+        } else if (sexpr_lookup(node, "device/vif")) {
+            tmp = sexpr_node(node, "device/vif/bridge");
+            if (tmp != NULL) {
+                virBufferVSprintf(&buf, "    <interface type='bridge'>\n");
+                virBufferVSprintf(&buf, "      <source bridge='%s'/>\n",
+                                  tmp);
+                tmp = sexpr_node(node, "device/vif/vifname");
+                if (tmp != NULL)
+                    virBufferVSprintf(&buf, "      <target dev='%s'/>\n",
+                                      tmp);
+                tmp = sexpr_node(node, "device/vif/mac");
+                if (tmp != NULL)
+                    virBufferVSprintf(&buf, "      <mac address='%s'/>\n",
+                                      tmp);
+                tmp = sexpr_node(node, "device/vif/ip");
+                if (tmp != NULL)
+                    virBufferVSprintf(&buf, "      <ip address='%s'/>\n",
+                                      tmp);
+                tmp = sexpr_node(node, "device/vif/script");
+                if (tmp != NULL)
+                    virBufferVSprintf(&buf, "      <script path='%s'/>\n",
+                                      tmp);
+                virBufferAdd(&buf, "    </interface>\n", 17);
+            } else {
+                char serial[1000];
+
+                TODO sexpr2string(node->car, serial, 1000);
+                virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n",
+                                  serial);
+            }
+
+        }
     }
     virBufferAdd(&buf, "  </devices>\n", 13);
     virBufferAdd(&buf, "</domain>\n", 10);
 
     buf.content[buf.use] = 0;
-    return(ret);
+    return (ret);
 
-error:
+  error:
     if (ret != NULL)
         free(ret);
-    return(NULL);
+    return (NULL);
 }
 
 /**
@@ -2371,22 +2379,24 @@ error:
  *         the caller must free() the returned value.
  */
 char *
-xend_get_domain_xml(virDomainPtr domain) {
+xend_get_domain_xml(virDomainPtr domain)
+{
     char *ret = NULL;
     struct sexpr *root;
 
     if (!VIR_IS_DOMAIN(domain)) {
-       /* this should be caught at the interface but ... */
+        /* this should be caught at the interface but ... */
         virXendError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
-       return(NULL);
+        return (NULL);
     }
 
-    root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
+    root =
+        sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
     if (root == NULL)
-        return(NULL);
+        return (NULL);
 
     ret = xend_parse_sexp_desc(root);
     sexpr_free(root);
 
-    return(ret);
+    return (ret);
 }
index ed254f8595b567ece1c96db7d2304071e21baa81..ad8b83cf386af807d2b2a5b4455537f9d70c1ad7 100644 (file)
@@ -31,418 +31,417 @@ extern "C" {
 /**
    This structure represents a virtual block device.
 */
-struct xend_device_vbd
-{
-       /**
+    struct xend_device_vbd {
+
+        /**
           The domain ID of the backend.
 
           Required.
        */
-       int backend;
+        int backend;
 
-       /**
+        /**
           A URI representing the device.  This is typically in the form
           file:/path/to/image or phy:/dev/device
 
           Required.
        */
-       const char *uname;
+        const char *uname;
 
-       /**
+        /**
           The name (or number) of the device to expose to the frontend.
 
           Required.
        */
-       const char *dev;
+        const char *dev;
 
-       /**
+        /**
           A flag specifying the permissions to expose the device with.
 
           Required.
        */
-       virDeviceMode mode;
-};
+        virDeviceMode mode;
+    };
 
 /**
    This structure represents a range of PIO to enable for a guest.
 */
-struct xend_device_ioport
-{
-       /**
+    struct xend_device_ioport {
+
+        /**
           The beginning address of an ioport range to enable.
 
           Required.
        */
-       uint16_t from;
+        uint16_t from;
 
-       /**
+        /**
           The ending address of an ioport range to enable.
 
           Required.
        */
-       uint16_t to;
-};
+        uint16_t to;
+    };
 
 /**
    This structure represents a virtual network interface configuration.
 */
-struct xend_device_vif
-{
-       /**
+    struct xend_device_vif {
+
+        /**
           A string representing the domain that will serve as the backend for
           this device.
 
           Required.
        */
-       int backend;
+        int backend;
 
-       /**
+        /**
           The name of the bridge device to pass to the network script.
 
           Optional.
        */
-       const char *bridge;
+        const char *bridge;
 
-       /**
+        /**
           The ip address to configure the virtal network device with.
 
           Optional.
        */
-       const char *ip;
+        const char *ip;
 
-       /**
+        /**
           The mac address to use for the virtual network device.
 
           Required.
        */
-       uint8_t mac[6];
+        uint8_t mac[6];
 
-       /**
+        /**
           The path to the network script that is to be used for initializing
           the network device.
 
           Optional.
        */
-       const char *script;
+        const char *script;
 
-       /**
+        /**
           The name of the vif.  The primary use for this is to allow the user
           to operate on vifs by name.
 
           Optional.
        */
-       const char *vifname;
-};
+        const char *vifname;
+    };
+
+    struct xend_domain_live {
 
-struct xend_domain_live
-{
-       /**
+        /**
           true is domain is currently scheduled.
        */
-       bool running;
+        bool running;
 
-       /**
+        /**
           true is domain has crashed.
        */
-       bool crashed;
+        bool crashed;
 
-       /**
+        /**
           true if domain has been shutdown.
        */
-       bool poweroff;
+        bool poweroff;
 
-       /**
+        /**
           true if domain has requested a reboot.
        */
-       bool reboot;
+        bool reboot;
 
-       /**
+        /**
           true if domain has requested a suspend.
        */
-       bool suspend;
+        bool suspend;
 
-       /**
+        /**
           true if domain is blocked on IO
        */
-       bool blocked;
+        bool blocked;
 
-       /**
+        /**
           true if domain has been destroyed but resources are not
           fully deallocated.
        */
-       bool dying;
+        bool dying;
 
-       /**
+        /**
           true if domain is paused.
        */
-       bool paused;
+        bool paused;
 
-       /**
+        /**
           the amount of time the domain has been running (in seconds)
        */
-       double cpu_time;
+        double cpu_time;
 
-       /**
+        /**
           the wall clock time since the domain was created (in seconds)
        */
-       double up_time;
+        double up_time;
 
-       /**
+        /**
           the time (in seconds since epoch) the domain was created
        */
-       double start_time;
+        double start_time;
 
-       /**
+        /**
           the number of enabled VCPUs
        */
-       int online_vcpus;
+        int online_vcpus;
 
-       /**
+        /**
           the total number of available VCPUs
        */
-       int vcpu_avail;
+        int vcpu_avail;
 
-       /**
+        /**
           the domain id number
        */
-       int id;
-};
+        int id;
+    };
 
 /**
    This structure represents the configuration of a domain.  It's primary
    purpose (currently) is for domain creation.
 */
-struct xend_domain
-{
-       /**
+    struct xend_domain {
+
+        /**
           The name of the domain.
 
           Required.
        */
-       const char *name;
+        const char *name;
 
-       /**
+        /**
           The amount of memory to assign to the domain before creation.
 
           Required.
        */
-       uint64_t memory;
+        uint64_t memory;
 
-       /**
+        /**
           The maximum amount of memory that can be given to the domain
           while it's running.  Please note that a domain can increase its
           memory on its own while running up to this value.
 
           Required.
        */
-       uint64_t max_memory;
+        uint64_t max_memory;
 
-       /**
+        /**
           The uuid to use to identify the domain.  This is compatible with
           libuuid's uuid_t and should be able to be used interchangably.
 
           Optional.
        */
-       unsigned char *uuid;
+        unsigned char *uuid;
 
-       /**
+        /**
           The ssidref to assign to the domain.
 
           Optional.
        */
-       int ssidref;
+        int ssidref;
 
-       /**
+        /**
           The action to perform when the domain powers off.
 
           Optional.
        */
-       virDomainRestart on_poweroff;
+        virDomainRestart on_poweroff;
 
-       /**
+        /**
           The action to perform when the domain reboots.
 
           Optional.
        */
-       virDomainRestart on_reboot;
+        virDomainRestart on_reboot;
 
-       /**
+        /**
           The action to perform when the domain crashes.
 
           Optional.
        */
-       virDomainRestart on_crash;
+        virDomainRestart on_crash;
 
-       /**
+        /**
           The number of VCPUs to assign to the domain.
 
           Required.
        */
-       int vcpus;
+        int vcpus;
 
-       /* FIXME cpus */
+        /* FIXME cpus */
 
-       virDomainKernel image;
+        virDomainKernel image;
 
-       /**
+        /**
           The number of VBDs pointed to be vbds.
 
           Optional.
        */
-       size_t n_vbds;
-       struct xend_device_vbd *vbds;
+        size_t n_vbds;
+        struct xend_device_vbd *vbds;
 
-       /**
+        /**
           The number of IO port ranges pointed to by ioports.
 
           Optional.
        */
-       size_t n_ioports;
-       struct xend_device_ioport *ioports;
+        size_t n_ioports;
+        struct xend_device_ioport *ioports;
 
-       /**
+        /**
           The number of VIFs pointed to be vifs.
 
           Optional.
        */
-       size_t n_vifs;
-       struct xend_device_vif *vifs;
+        size_t n_vifs;
+        struct xend_device_vif *vifs;
 
-       /**
+        /**
           A pointer to run-time information about the domain.
 
           Only set by xen_get_domain().
        */
-       struct xend_domain_live *live;
-};
+        struct xend_domain_live *live;
+    };
+
+    enum xend_node_system {
+        XEND_SYSTEM_LINUX = 1,
+    };
 
-enum xend_node_system
-{
-       XEND_SYSTEM_LINUX = 1,
-};
+    struct xend_node {
 
-struct xend_node
-{
-       /**
+        /**
           An enumeration value specifying the host system.
        */
-       enum xend_node_system system;
+        enum xend_node_system system;
 
-       /**
+        /**
           The DNS host name.
        */
-       const char *host;
+        const char *host;
 
-       /**
+        /**
           The dom0 kernel release string.
        */
-       const char *release;
+        const char *release;
 
-       /**
+        /**
           The result of uname -v.
        */
-       const char *version;
+        const char *version;
 
-       /**
+        /**
           The machine type.
        */
-       const char *machine;
+        const char *machine;
 
-       /**
+        /**
           The number of physical cpus.
        */
-       int nr_cpus;
+        int nr_cpus;
 
-       /**
+        /**
           The number of NUMA nodes.
        */
-       int nr_nodes;
+        int nr_nodes;
 
-       /**
+        /**
           The number of sockets per NUMA node.
        */
-       int sockets_per_node;
+        int sockets_per_node;
 
-       /**
+        /**
           The number of cores per NUMA socket.
        */
-       int cores_per_socket;
+        int cores_per_socket;
 
-       /**
+        /**
           The number of hyperthreads per core.
        */
-       int threads_per_core;
+        int threads_per_core;
 
-       /**
+        /**
           The clock rating (in megahertz) of each core.
        */
-       int cpu_mhz;
+        int cpu_mhz;
 
-       /**
+        /**
           I honestly don't know what this is.
        */
-       const char *hw_caps;
+        const char *hw_caps;
 
-       /**
+        /**
           The total memory (in bytes).
        */
-       uint64_t total_memory;
+        uint64_t total_memory;
 
-       /**
+        /**
           The free memory (in bytes).
        */
-       uint64_t free_memory;
+        uint64_t free_memory;
 
-       /**
+        /**
           The Xen major version number.
        */
-       int xen_major;
+        int xen_major;
 
-       /**
+        /**
           The Xen minor version number.
        */
-       int xen_minor;
+        int xen_minor;
 
-       /**
+        /**
           The Xen extra version number.
        */
-       int xen_extra;
+        int xen_extra;
 
-       /**
+        /**
           A string descirbing the Xen platform.
        */
-       const char *xen_caps;
+        const char *xen_caps;
 
-       /**
+        /**
           Dunno.
        */
-       const char *platform_params;
+        const char *platform_params;
 
-       /**
+        /**
           The build changeset.
        */
-       const char *xen_changeset;
+        const char *xen_changeset;
 
-       /**
+        /**
           The compiler version.
        */
-       const char *cc_compiler;
+        const char *cc_compiler;
 
-       /**
+        /**
           The user that compiled this binary.
        */
-       const char *cc_compile_by;
+        const char *cc_compile_by;
 
-       /**
+        /**
           The system this binary was built on.
        */
-       const char *cc_compile_domain;
+        const char *cc_compile_domain;
 
-       /**
+        /**
           The date that this binary was built on.
        */
-       const char *cc_compile_date;
-};
+        const char *cc_compile_date;
+    };
 
 /**
  * \brief Setup the connection to the local Xend instance
@@ -456,7 +455,7 @@ struct xend_node
  *
  * Make sure to call xend_cleanup().
  */
-int xend_setup(virConnectPtr conn);
+    int xend_setup(virConnectPtr conn);
 
 /**
  * \brief Setup the connection to a xend instance via TCP
@@ -470,7 +469,7 @@ int xend_setup(virConnectPtr conn);
  *
  * Make sure to call xend_cleanup().
  */
-int xend_setup_tcp(virConnectPtr xend, const char *host, int port);
+    int xend_setup_tcp(virConnectPtr xend, const char *host, int port);
 
 /**
  * \brief Setup the connection to xend instance via a Unix domain socket
@@ -483,7 +482,7 @@ int xend_setup_tcp(virConnectPtr xend, const char *host, int port);
  *
  * Make sure to call xend_cleanup().
  */
-int xend_setup_unix(virConnectPtr xend, const char *path);
+    int xend_setup_unix(virConnectPtr xend, const char *path);
 
 /**
  * \brief Delete a previously allocated Xend instance
@@ -493,7 +492,7 @@ int xend_setup_unix(virConnectPtr xend, const char *path);
  * initialized with xend_setup[_{tcp, unix}] is no longer needed
  * to free the associated resources.
  */
-void xend_cleanup(virConnectPtr xend);
+    void xend_cleanup(virConnectPtr xend);
 
 /**
  * \brief Blocks until a domain's devices are initialized
@@ -507,7 +506,7 @@ void xend_cleanup(virConnectPtr xend);
  * invalid filename, the error won't occur until after this function
  * returns.
  */
-int xend_wait_for_devices(virConnectPtr xend, const char *name);
+    int xend_wait_for_devices(virConnectPtr xend, const char *name);
 
 /**
  * \brief Pause a domain
@@ -518,7 +517,7 @@ int xend_wait_for_devices(virConnectPtr xend, const char *name);
  * This method will make sure that Xen does not schedule the domain
  * anymore until after xend_unpause() has been called.
  */
-int xend_pause(virConnectPtr xend, const char *name);
+    int xend_pause(virConnectPtr xend, const char *name);
 
 /**
  * \brief Unpause a domain
@@ -529,7 +528,7 @@ int xend_pause(virConnectPtr xend, const char *name);
  * This method will allow a paused domain (the result of xen_pause())
  * to be scheduled in the future.
  */
-int xend_unpause(virConnectPtr xend, const char *name);
+    int xend_unpause(virConnectPtr xend, const char *name);
 
 /**
  * \brief Unpause a domain
@@ -540,7 +539,8 @@ int xend_unpause(virConnectPtr xend, const char *name);
  * 
  * This method allows a domain to have its name changed after creation.
  */
-int xend_rename(virConnectPtr xend, const char *oldname, const char *name);
+    int xend_rename(virConnectPtr xend, const char *oldname,
+                    const char *name);
 
 /**
  * \brief Sends a SYSRQ to a domain
@@ -551,7 +551,7 @@ int xend_rename(virConnectPtr xend, const char *oldname, const char *name);
  * 
  * This method simulates the pressing of a SYSRQ sequence.
  */
-int xend_sysrq(virConnectPtr xend, const char *name, const char *key);
+    int xend_sysrq(virConnectPtr xend, const char *name, const char *key);
 
 /**
  * \brief Request a domain to reboot
@@ -563,7 +563,7 @@ int xend_sysrq(virConnectPtr xend, const char *name, const char *key);
  * a request and the domain may ignore it.  It will return immediately
  * after queuing the request.
  */
-int xend_reboot(virConnectPtr xend, const char *name);
+    int xend_reboot(virConnectPtr xend, const char *name);
 
 /**
  * \brief Request a domain to shutdown
@@ -575,7 +575,7 @@ int xend_reboot(virConnectPtr xend, const char *name);
  * a request and the domain may ignore it.  It will return immediately
  * after queuing the request.
  */
-int xend_shutdown(virConnectPtr xend, const char *name);
+    int xend_shutdown(virConnectPtr xend, const char *name);
 
 /**
  * \brief Destroy a domain
@@ -589,7 +589,7 @@ int xend_shutdown(virConnectPtr xend, const char *name);
  * dying and will go away completely once all of the resources have been
  * unmapped (usually from the backend devices).
  */
-int xend_destroy(virConnectPtr xend, const char *name);
+    int xend_destroy(virConnectPtr xend, const char *name);
 
 /**
  * \brief Save a domain to the disk
@@ -602,7 +602,8 @@ int xend_destroy(virConnectPtr xend, const char *name);
  * a file on disk.  Use xend_restore() to restore a domain after
  * saving.
  */
-int xend_save(virConnectPtr xend, const char *name, const char *filename);
+    int xend_save(virConnectPtr xend, const char *name,
+                  const char *filename);
 
 /**
  * \brief Restore a domain from the disk
@@ -612,7 +613,7 @@ int xend_save(virConnectPtr xend, const char *name, const char *filename);
  * 
  * This method will restore a domain saved to disk by xend_save().
  */
-int xend_restore(virConnectPtr xend, const char *filename);
+    int xend_restore(virConnectPtr xend, const char *filename);
 
 /**
  * \brief Obtain a list of currently running domains
@@ -622,7 +623,7 @@ int xend_restore(virConnectPtr xend, const char *filename);
  * This method will return an array of names of currently running
  * domains.  The memory should be released will a call to free().
  */
-char **xend_get_domains(virConnectPtr xend);
+    char **xend_get_domains(virConnectPtr xend);
 
 /**
  * \brief Create a new domain
@@ -634,7 +635,7 @@ char **xend_get_domains(virConnectPtr xend);
  * domain will be paused after creation and must be unpaused with
  * xend_unpause() to begin execution.
  */
-int xend_create(virConnectPtr xend, const struct xend_domain *info);
+    int xend_create(virConnectPtr xend, const struct xend_domain *info);
 
 /**
  * \brief Create a new domain
@@ -646,7 +647,7 @@ int xend_create(virConnectPtr xend, const struct xend_domain *info);
  * domain will be paused after creation and must be unpaused with
  * xend_unpause() to begin execution.
  */
-int xend_create_sexpr(virConnectPtr xend, const char *sexpr);
+    int xend_create_sexpr(virConnectPtr xend, const char *sexpr);
 
 /**
  * \brief Set the maximum memory for a domain
@@ -660,7 +661,8 @@ int xend_create_sexpr(virConnectPtr xend, const char *sexpr);
  * on its own (although under normal circumstances, memory allocation for a
  * domain is only done through xend_set_memory()).
  */
-int xend_set_max_memory(virConnectPtr xend, const char *name, uint64_t value);
+    int xend_set_max_memory(virConnectPtr xend, const char *name,
+                            uint64_t value);
 
 /**
  * \brief Set the memory allocation for a domain
@@ -678,7 +680,8 @@ int xend_set_max_memory(virConnectPtr xend, const char *name, uint64_t value);
  * There is no safe guard for allocations that are too small so be careful
  * when using this function to reduce a domain's memory usage.
  */
-int xend_set_memory(virConnectPtr xend, const char *name, uint64_t value);
+    int xend_set_memory(virConnectPtr xend, const char *name,
+                        uint64_t value);
 
 /**
  * \brief Create a virtual block device
@@ -692,9 +695,9 @@ int xend_set_memory(virConnectPtr xend, const char *name, uint64_t value);
  * rather, one should use xend_wait_for_devices() to block until the device
  * has been successfully attached.
  */
-int xend_vbd_create(virConnectPtr xend,
-                   const char *name,
-                   const struct xend_device_vbd *vbd);
+    int xend_vbd_create(virConnectPtr xend,
+                        const char *name,
+                        const struct xend_device_vbd *vbd);
 
 /**
  * \brief Destroy a virtual block device
@@ -708,9 +711,9 @@ int xend_vbd_create(virConnectPtr xend,
  * should use xend_wait_for_devices() to block until the device has been
  * successfully detached.
  */
-int xend_vbd_destroy(virConnectPtr xend,
-                    const char *name,
-                    const struct xend_device_vbd *vbd);
+    int xend_vbd_destroy(virConnectPtr xend,
+                         const char *name,
+                         const struct xend_device_vbd *vbd);
 
 /**
  * \brief Create a virtual network device
@@ -724,9 +727,9 @@ int xend_vbd_destroy(virConnectPtr xend,
  * rather, one should use xend_wait_for_devices() to network until the device
  * has been successfully attached.
  */
-int xend_vif_create(virConnectPtr xend,
-                   const char *name,
-                   const struct xend_device_vif *vif);
+    int xend_vif_create(virConnectPtr xend,
+                        const char *name,
+                        const struct xend_device_vif *vif);
 
 /**
  * \brief Destroy a virtual network device
@@ -740,9 +743,9 @@ int xend_vif_create(virConnectPtr xend,
  * rather, one should use xend_wait_for_devices() to network until the device
  * has been successfully detached.
  */
-int xend_vif_destroy(virConnectPtr xend,
-                    const char *name,
-                    const struct xend_device_vif *vif);
+    int xend_vif_destroy(virConnectPtr xend,
+                         const char *name,
+                         const struct xend_device_vif *vif);
 
 /**
  * \brief Lookup information about a domain
@@ -754,8 +757,8 @@ int xend_vif_destroy(virConnectPtr xend,
  * it in the form of a struct xend_domain.  This should be
  * free()'d when no longer needed.
  */
-struct xend_domain *xend_get_domain(virConnectPtr xend,
-                                   const char *name);
+    struct xend_domain *xend_get_domain(virConnectPtr xend,
+                                        const char *name);
 
 /**
  * \brief Lookup the id of a domain
@@ -766,9 +769,8 @@ struct xend_domain *xend_get_domain(virConnectPtr xend,
  *
  * This method looks up the ids of a domain
  */
-int xend_get_domain_ids(virConnectPtr xend,
-                       const char *name,
-                       unsigned char *uuid);
+    int xend_get_domain_ids(virConnectPtr xend,
+                            const char *name, unsigned char *uuid);
 
 /**
  * \brief Get status informations for a domain
@@ -779,8 +781,7 @@ int xend_get_domain_ids(virConnectPtr xend,
  * This method looks up information about a domain and update the
  * information block provided.
  */
-int xend_get_domain_info(virDomainPtr domain,
-                        virDomainInfoPtr info);
+    int xend_get_domain_info(virDomainPtr domain, virDomainInfoPtr info);
 
 /**
  * \brief Lookup information about the host machine
@@ -790,7 +791,7 @@ int xend_get_domain_info(virDomainPtr domain,
  * This method returns information about the physical host
  * machine running Xen.
  */
-struct xend_node *xend_get_node(virConnectPtr xend);
+    struct xend_node *xend_get_node(virConnectPtr xend);
 
 /**
  * \brief Shutdown physical host machine
@@ -799,7 +800,7 @@ struct xend_node *xend_get_node(virConnectPtr xend);
  *
  * This method shuts down the physical machine running Xen.
  */
-int xend_node_shutdown(virConnectPtr xend);
+    int xend_node_shutdown(virConnectPtr xend);
 
 /**
  * \brief Restarts physical host machine
@@ -808,7 +809,7 @@ int xend_node_shutdown(virConnectPtr xend);
  *
  * This method restarts the physical machine running Xen.
  */
-int xend_node_restart(virConnectPtr xend);
+    int xend_node_restart(virConnectPtr xend);
 
 /**
  * \brief Return hypervisor debugging messages
@@ -820,9 +821,7 @@ int xend_node_restart(virConnectPtr xend);
  * This function will place the debugging messages from the
  * hypervisor into a buffer with a null terminator.
  */
-int xend_dmesg(virConnectPtr xend,
-              char *buffer,
-              size_t n_buffer);
+    int xend_dmesg(virConnectPtr xend, char *buffer, size_t n_buffer);
 
 /**
  * \brief Clear the hypervisor debugging messages
@@ -832,7 +831,7 @@ int xend_dmesg(virConnectPtr xend,
  * This function will clear the debugging message ring queue
  * in the hypervisor.
  */
-int xend_dmesg_clear(virConnectPtr xend);
+    int xend_dmesg_clear(virConnectPtr xend);
 
 /**
  * \brief Obtain the Xend log messages
@@ -844,9 +843,7 @@ int xend_dmesg_clear(virConnectPtr xend);
  * This function will place the Xend debugging messages into
  * a buffer with a null terminator.
  */
-int xend_log(virConnectPtr xend,
-            char *buffer,
-            size_t n_buffer);
+    int xend_log(virConnectPtr xend, char *buffer, size_t n_buffer);
 
 /**
  * \brief Provide an XML description of the domain.
@@ -856,9 +853,8 @@ int xend_log(virConnectPtr xend,
  *
  * Provide an XML description of the domain.
  */
-char *xend_get_domain_xml(virDomainPtr domain);
+    char *xend_get_domain_xml(virDomainPtr domain);
 #ifdef __cplusplus
 }
 #endif
-
 #endif
index e4577b8330e6e6564be996554bab2887a3af1d55..fdf24f8f07bfa2f4192e26759002321da10f2899 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
  * 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)
         return;
 
     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;
+        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,38 +125,41 @@ 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);
     va_copy(locarg, argptr);
     while (((count = vsnprintf(&buf->content[buf->use], size, format,
                                locarg)) < 0) || (count >= size - 1)) {
-       buf->content[buf->use] = 0;
-       va_end(locarg);
-       if (virBufferGrow(buf, 1000) < 0) {
-           return(-1);
-       }
-       size = buf->size - buf->use - 1;
-       va_copy(locarg, argptr);
+        buf->content[buf->use] = 0;
+        va_end(locarg);
+        if (virBufferGrow(buf, 1000) < 0) {
+            return (-1);
+        }
+        size = buf->size - buf->use - 1;
+        va_copy(locarg, argptr);
     }
     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
@@ -164,8 +172,9 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
  * Returns the new string or NULL in case of error
  */
 static char *
-virDomainGetXMLDeviceInfo(virDomainPtr domain, const char *sub, 
-                          long dev, const char *name) {
+virDomainGetXMLDeviceInfo(virDomainPtr domain, const char *sub,
+                          long dev, const char *name)
+{
     char s[256];
     unsigned int len = 0;
 
@@ -187,55 +196,56 @@ 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");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <source file='%s'/>\n", val);
-           free(val);
-       }
-       val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "dev");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <target dev='%s'/>\n", val);
-           free(val);
-       }
-       val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "read-only");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <readonly/>\n", val);
-           free(val);
-       }
-       virBufferAdd(buf, "    </disk>\n", 12);
+        virBufferVSprintf(buf, "    <disk type='file'>\n");
+        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "params");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <source file='%s'/>\n", val);
+            free(val);
+        }
+        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "dev");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <target dev='%s'/>\n", val);
+            free(val);
+        }
+        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "read-only");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <readonly/>\n", val);
+            free(val);
+        }
+        virBufferAdd(buf, "    </disk>\n", 12);
     } else if (!strcmp(type, "phy")) {
-       virBufferVSprintf(buf, "    <disk type='device'>\n");
-       val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "params");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <source device='%s'/>\n", val);
-           free(val);
-       }
-       val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "dev");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <target dev='%s'/>\n", val);
-           free(val);
-       }
-       val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "read-only");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <readonly/>\n", val);
-           free(val);
-       }
-       virBufferAdd(buf, "    </disk>\n", 12);
+        virBufferVSprintf(buf, "    <disk type='device'>\n");
+        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "params");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <source device='%s'/>\n", val);
+            free(val);
+        }
+        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "dev");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <target dev='%s'/>\n", val);
+            free(val);
+        }
+        val = virDomainGetXMLDeviceInfo(domain, "vbd", dev, "read-only");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <readonly/>\n", val);
+            free(val);
+        }
+        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,11 +268,11 @@ virDomainGetXMLDevices(virDomainPtr domain, virBufferPtr buf) {
     virConnectPtr conn;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain))
-       return(-1);
-    
+        return (-1);
+
     conn = domain->conn;
 
-    snprintf(backend, 199, "/local/domain/0/backend/vbd/%d", 
+    snprintf(backend, 199, "/local/domain/0/backend/vbd/%d",
              virDomainGetID(domain));
     backend[199] = 0;
     list = xs_directory(conn->xshandle, 0, backend, &num);
@@ -269,20 +280,20 @@ 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;
-           goto done;
-       }
-       virDomainGetXMLDevice(domain, buf, id);
+        if ((endptr == list[i]) || (*endptr != 0)) {
+            ret = -1;
+            goto done;
+        }
+        virDomainGetXMLDevice(domain, buf, id);
     }
 
-done:
+  done:
     if (list != NULL)
         free(list);
 
-    return(ret);
+    return (ret);
 }
 
 /**
@@ -297,41 +308,42 @@ 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");
     if (type == NULL) {
-       virBufferVSprintf(buf, "    <interface type='default'>\n");
-       val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "mac");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <mac address='%s'/>\n", val);
-           free(val);
-       }
-       val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "script");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <script path='%s'/>\n", val);
-           free(val);
-       }
-       virBufferAdd(buf, "    </interface>\n", 17);
+        virBufferVSprintf(buf, "    <interface type='default'>\n");
+        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "mac");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <mac address='%s'/>\n", val);
+            free(val);
+        }
+        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "script");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <script path='%s'/>\n", val);
+            free(val);
+        }
+        virBufferAdd(buf, "    </interface>\n", 17);
     } else {
-       virBufferVSprintf(buf, "    <interface type='bridge'>\n");
-       virBufferVSprintf(buf, "      <source bridge='%s'/>\n", type);
-       val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "mac");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <mac address='%s'/>\n", val);
-           free(val);
-       }
-       val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "script");
-       if (val != NULL) {
-           virBufferVSprintf(buf, "      <script path='%s'/>\n", val);
-           free(val);
-       }
-       virBufferAdd(buf, "    </interface>\n", 17);
+        virBufferVSprintf(buf, "    <interface type='bridge'>\n");
+        virBufferVSprintf(buf, "      <source bridge='%s'/>\n", type);
+        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "mac");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <mac address='%s'/>\n", val);
+            free(val);
+        }
+        val = virDomainGetXMLDeviceInfo(domain, "vif", dev, "script");
+        if (val != NULL) {
+            virBufferVSprintf(buf, "      <script path='%s'/>\n", val);
+            free(val);
+        }
+        virBufferAdd(buf, "    </interface>\n", 17);
     }
     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,11 +366,11 @@ virDomainGetXMLInterfaces(virDomainPtr domain, virBufferPtr buf) {
     virConnectPtr conn;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain))
-       return(-1);
-    
+        return (-1);
+
     conn = domain->conn;
 
-    snprintf(backend, 199, "/local/domain/0/backend/vif/%d", 
+    snprintf(backend, 199, "/local/domain/0/backend/vif/%d",
              virDomainGetID(domain));
     backend[199] = 0;
     list = xs_directory(conn->xshandle, 0, backend, &num);
@@ -365,20 +378,20 @@ 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;
-           goto done;
-       }
-       virDomainGetXMLInterface(domain, buf, id);
+        if ((endptr == list[i]) || (*endptr != 0)) {
+            ret = -1;
+            goto done;
+        }
+        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");
@@ -417,20 +431,20 @@ virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf) {
     }
     str = virDomainGetVMInfo(domain, vm, "image/ramdisk");
     if (str != NULL) {
-       if (str[0] != 0)
-           virBufferVSprintf(buf, "    <initrd>%s</initrd>\n", str);
+        if (str[0] != 0)
+            virBufferVSprintf(buf, "    <initrd>%s</initrd>\n", str);
         free(str);
     }
     str = virDomainGetVMInfo(domain, vm, "image/cmdline");
     if (str != NULL) {
-       if (str[0] != 0)
-           virBufferVSprintf(buf, "    <cmdline>%s</cmdline>\n", str);
+        if (str[0] != 0)
+            virBufferVSprintf(buf, "    <cmdline>%s</cmdline>\n", str);
         free(str);
     }
     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);
@@ -475,9 +491,9 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) {
     virDomainGetXMLInterfaces(domain, &buf);
     virBufferAdd(&buf, "  </devices>\n", 13);
     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,85 +523,90 @@ 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"))) {
-               txt = cur->children;
-               if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
-                   type = txt->content;
-           } else if ((kernel == NULL) &&
-                      (xmlStrEqual(cur->name, BAD_CAST "kernel"))) {
-               txt = cur->children;
-               if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
-                   kernel = txt->content;
-           } else if ((root == NULL) &&
-                      (xmlStrEqual(cur->name, BAD_CAST "root"))) {
-               txt = cur->children;
-               if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
-                   root = txt->content;
-           } else if ((initrd == NULL) &&
-                      (xmlStrEqual(cur->name, BAD_CAST "initrd"))) {
-               txt = cur->children;
-               if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
-                   initrd = txt->content;
-           } else if ((cmdline == NULL) &&
-                      (xmlStrEqual(cur->name, BAD_CAST "cmdline"))) {
-               txt = cur->children;
-               if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
-                   cmdline = txt->content;
-           }
-       }
+            if ((type == NULL)
+                && (xmlStrEqual(cur->name, BAD_CAST "type"))) {
+                txt = cur->children;
+                if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
+                    type = txt->content;
+            } else if ((kernel == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "kernel"))) {
+                txt = cur->children;
+                if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
+                    kernel = txt->content;
+            } else if ((root == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "root"))) {
+                txt = cur->children;
+                if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
+                    root = txt->content;
+            } else if ((initrd == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "initrd"))) {
+                txt = cur->children;
+                if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
+                    initrd = txt->content;
+            } else if ((cmdline == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "cmdline"))) {
+                txt = cur->children;
+                if ((txt->type == XML_TEXT_NODE) && (txt->next == NULL))
+                    cmdline = txt->content;
+            }
+        }
         cur = cur->next;
     }
     if ((type != NULL) && (!xmlStrEqual(type, BAD_CAST "linux"))) {
         /* VIR_ERR_OS_TYPE */
-       virXMLError(VIR_ERR_OS_TYPE, (const char *) type, 0);
-       return(-1);
+        virXMLError(VIR_ERR_OS_TYPE, (const char *) type, 0);
+        return (-1);
     }
     virBufferAdd(buf, "(linux ", 7);
     if (kernel == NULL) {
-       virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
-       return(-1);
+        virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
+        return (-1);
     }
     virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel);
     if (initrd != NULL)
-       virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
+        virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
     if (root == NULL) {
-       const xmlChar *base, *tmp;
+        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);
-       }
-       base = cmdline;
-       while (*base != 0) {
-           if ((base[0] == 'r') && (base[1] == 'o') && (base[2] == 'o') &&
-               (base[3] == 't')) {
-               base += 4;
-               break;
-           }
-           base++;
-       }
-       while ((*base == ' ') || (*base == '\t')) base++;
-       if (*base == '=') {
-           base++;
-           while ((*base == ' ') || (*base == '\t')) base++;
-       }
-       tmp = base;
-       while ((*tmp != 0) && (*tmp != ' ') && (*tmp != '\t')) tmp++;
-       if (tmp == base) {
-           virXMLError(VIR_ERR_NO_ROOT, (const char *) cmdline, 0);
-           return(-1);
-       }
-       root = xmlStrndup(base, tmp - base);
+        if (cmdline == NULL) {
+            virXMLError(VIR_ERR_NO_ROOT, (const char *) cmdline, 0);
+            return (-1);
+        }
+        base = cmdline;
+        while (*base != 0) {
+            if ((base[0] == 'r') && (base[1] == 'o') && (base[2] == 'o') &&
+                (base[3] == 't')) {
+                base += 4;
+                break;
+            }
+            base++;
+        }
+        while ((*base == ' ') || (*base == '\t'))
+            base++;
+        if (*base == '=') {
+            base++;
+            while ((*base == ' ') || (*base == '\t'))
+                base++;
+        }
+        tmp = base;
+        while ((*tmp != 0) && (*tmp != ' ') && (*tmp != '\t'))
+            tmp++;
+        if (tmp == base) {
+            virXMLError(VIR_ERR_NO_ROOT, (const char *) cmdline, 0);
+            return (-1);
+        }
+        root = xmlStrndup(base, tmp - base);
         virBufferVSprintf(buf, "(root '%s')", (const char *) root);
-       xmlFree((xmlChar *) root);
-       virBufferVSprintf(buf, "(args '%s')", (const char *) cmdline);
+        xmlFree((xmlChar *) root);
+        virBufferVSprintf(buf, "(args '%s')", (const char *) cmdline);
     } else {
         virBufferVSprintf(buf, "(root '%s')", (const char *) root);
-       if (cmdline != NULL)
-           virBufferVSprintf(buf, "(args '%s')", (const char *) cmdline);
+        if (cmdline != NULL)
+            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,55 +633,57 @@ 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;
-       xmlFree(type);
+        if (xmlStrEqual(type, BAD_CAST "file"))
+            typ = 0;
+        else if (xmlStrEqual(type, BAD_CAST "block"))
+            typ = 1;
+        xmlFree(type);
     }
     cur = node->children;
     while (cur != NULL) {
         if (cur->type == XML_ELEMENT_NODE) {
-           if ((source == NULL) &&
-               (xmlStrEqual(cur->name, BAD_CAST "source"))) {
-
-               if (typ == 0)
-                   source = xmlGetProp(cur, BAD_CAST "file");
-               else
-                   source = xmlGetProp(cur, BAD_CAST "dev");
-           } else if ((target == NULL) &&
-                      (xmlStrEqual(cur->name, BAD_CAST "target"))) {
-               target = xmlGetProp(cur, BAD_CAST "dev");
-           } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
-               ro = 1;
-           }
-       }
+            if ((source == NULL) &&
+                (xmlStrEqual(cur->name, BAD_CAST "source"))) {
+
+                if (typ == 0)
+                    source = xmlGetProp(cur, BAD_CAST "file");
+                else
+                    source = xmlGetProp(cur, BAD_CAST "dev");
+            } else if ((target == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "target"))) {
+                target = xmlGetProp(cur, BAD_CAST "dev");
+            } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
+                ro = 1;
+            }
+        }
         cur = cur->next;
     }
 
     if (source == NULL) {
-       virXMLError(VIR_ERR_NO_SOURCE, (const char *) target, 0);
-       
-       if (target != NULL)
-           xmlFree(target);
-       return(-1);
+        virXMLError(VIR_ERR_NO_SOURCE, (const char *) target, 0);
+
+        if (target != NULL)
+            xmlFree(target);
+        return (-1);
     }
     if (target == NULL) {
-       virXMLError(VIR_ERR_NO_TARGET, (const char *) source, 0);
-       if (source != NULL)
-           xmlFree(source);
-       return(-1);
+        virXMLError(VIR_ERR_NO_TARGET, (const char *) source, 0);
+        if (source != NULL)
+            xmlFree(source);
+        return (-1);
     }
     virBufferAdd(buf, "(vbd ", 5);
     if (target[0] == '/')
-       virBufferVSprintf(buf, "(dev '%s')", (const char *) target);
+        virBufferVSprintf(buf, "(dev '%s')", (const char *) target);
     else
-       virBufferVSprintf(buf, "(dev '/dev/%s')", (const char *) target);
+        virBufferVSprintf(buf, "(dev '/dev/%s')", (const char *) target);
     if (typ == 0)
         virBufferVSprintf(buf, "(uname 'file:%s')", source);
     else if (typ == 1) {
         if (source[0] == '/')
-           virBufferVSprintf(buf, "(uname 'phy:%s')", source);
-       else
-           virBufferVSprintf(buf, "(uname 'phy:/dev/%s')", source);
+            virBufferVSprintf(buf, "(uname 'phy:%s')", source);
+        else
+            virBufferVSprintf(buf, "(uname 'phy:/dev/%s')", source);
     }
     if (ro == 0)
         virBufferVSprintf(buf, "(mode 'w')");
@@ -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,51 +720,53 @@ 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;
-       xmlFree(type);
+        if (xmlStrEqual(type, BAD_CAST "bridge"))
+            typ = 0;
+        else if (xmlStrEqual(type, BAD_CAST "ethernet"))
+            typ = 1;
+        xmlFree(type);
     }
     cur = node->children;
     while (cur != NULL) {
         if (cur->type == XML_ELEMENT_NODE) {
-           if ((source == NULL) &&
-               (xmlStrEqual(cur->name, BAD_CAST "source"))) {
-
-               if (typ == 0)
-                   source = xmlGetProp(cur, BAD_CAST "bridge");
-               else
-                   source = xmlGetProp(cur, BAD_CAST "dev");
-           } else if ((mac == NULL) &&
-                      (xmlStrEqual(cur->name, BAD_CAST "mac"))) {
-               mac = xmlGetProp(cur, BAD_CAST "address");
-           } else if ((script == NULL) &&
-                      (xmlStrEqual(cur->name, BAD_CAST "script"))) {
-               script = xmlGetProp(cur, BAD_CAST "path");
-           }
-       }
+            if ((source == NULL) &&
+                (xmlStrEqual(cur->name, BAD_CAST "source"))) {
+
+                if (typ == 0)
+                    source = xmlGetProp(cur, BAD_CAST "bridge");
+                else
+                    source = xmlGetProp(cur, BAD_CAST "dev");
+            } else if ((mac == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "mac"))) {
+                mac = xmlGetProp(cur, BAD_CAST "address");
+            } else if ((script == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "script"))) {
+                script = xmlGetProp(cur, BAD_CAST "path");
+            }
+        }
         cur = cur->next;
     }
 
     virBufferAdd(buf, "(vif ", 5);
     if (mac != NULL)
-       virBufferVSprintf(buf, "(mac '%s')", (const char *) mac);
+        virBufferVSprintf(buf, "(mac '%s')", (const char *) mac);
     if (source != NULL) {
-       if (typ == 0)
-           virBufferVSprintf(buf, "(bridge '%s')", (const char *) source);
-       else /* TODO does that work like that ? */
-           virBufferVSprintf(buf, "(dev '%s')", (const char *) source);
+        if (typ == 0)
+            virBufferVSprintf(buf, "(bridge '%s')", (const char *) source);
+        else                    /* TODO does that work like that ? */
+            virBufferVSprintf(buf, "(dev '%s')", (const char *) source);
     }
     if (script != NULL)
         virBufferVSprintf(buf, "(script '%s')", script);
 
     virBufferAdd(buf, ")", 1);
     if (mac != NULL)
-       xmlFree(mac);
+        xmlFree(mac);
     if (source != NULL)
-       xmlFree(source);
+        xmlFree(source);
     if (script != NULL)
-       xmlFree(script);
-    return(0);
+        xmlFree(script);
+    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;
@@ -765,17 +794,17 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
     int i, res;
 
     if (name != NULL)
-       *name = NULL;
+        *name = NULL;
     ret = malloc(1000);
     if (ret == NULL)
-        return(NULL);
+        return (NULL);
     buf.content = ret;
     buf.size = 1000;
     buf.use = 0;
 
     xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
-                XML_PARSE_NOENT | XML_PARSE_NONET | 
-                XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
+                     XML_PARSE_NOENT | XML_PARSE_NONET |
+                     XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
     if (xml == NULL) {
         goto error;
     }
@@ -786,10 +815,10 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
     prop = xmlGetProp(node, BAD_CAST "type");
     if (prop != NULL) {
         if (!xmlStrEqual(prop, BAD_CAST "xen")) {
-           xmlFree(prop);
-           goto error;
-       }
-       xmlFree(prop);
+            xmlFree(prop);
+            goto error;
+        }
+        xmlFree(prop);
     }
     virBufferAdd(&buf, "(vm ", 4);
     ctxt = xmlXPathNewContext(xml);
@@ -800,25 +829,26 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
      * extract soem of the basics, name, memory, cpus ...
      */
     obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
-    if ((obj == NULL) || (obj->type != XPATH_STRING) || 
+    if ((obj == NULL) || (obj->type != XPATH_STRING) ||
         (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
-       virXMLError(VIR_ERR_NO_NAME, xmldesc, 0);
+        virXMLError(VIR_ERR_NO_NAME, xmldesc, 0);
         goto error;
     }
     virBufferVSprintf(&buf, "(name '%s')", obj->stringval);
     nam = strdup((const char *) obj->stringval);
     if (nam == NULL) {
-       virXMLError(VIR_ERR_NO_MEMORY, "copying name", 0);
-       goto error;
+        virXMLError(VIR_ERR_NO_MEMORY, "copying name", 0);
+        goto error;
     }
     xmlXPathFreeObject(obj);
 
     obj = xmlXPathEval(BAD_CAST "number(/domain/memory[1])", ctxt);
     if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
         (obj->floatval < 64000)) {
-       virBufferVSprintf(&buf, "(memory 128)(maxmem 128)");
+        virBufferVSprintf(&buf, "(memory 128)(maxmem 128)");
     } else {
         unsigned long mem = (obj->floatval / 1024);
+
         virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)", mem, mem);
     }
     xmlXPathFreeObject(obj);
@@ -826,9 +856,10 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
     obj = xmlXPathEval(BAD_CAST "number(/domain/vcpu[1])", ctxt);
     if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
         (obj->floatval <= 0)) {
-       virBufferVSprintf(&buf, "(vcpus 1)");
+        virBufferVSprintf(&buf, "(vcpus 1)");
     } else {
         unsigned int cpu = (unsigned int) obj->floatval;
+
         virBufferVSprintf(&buf, "(vcpus %u)", cpu);
     }
     xmlXPathFreeObject(obj);
@@ -837,9 +868,8 @@ 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)) {
-       virXMLError(VIR_ERR_NO_OS, nam, 0);
+        (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr != 1)) {
+        virXMLError(VIR_ERR_NO_OS, nam, 0);
         goto error;
     }
     res = virDomainParseXMLOSDesc(obj->nodesetval->nodeTab[0], &buf);
@@ -852,31 +882,31 @@ 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)) {
-       virXMLError(VIR_ERR_NO_DEVICE, nam, 0);
+        (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 1)) {
+        virXMLError(VIR_ERR_NO_DEVICE, nam, 0);
         goto error;
     }
-    for (i = 0;i < obj->nodesetval->nodeNr;i++) {
-       virBufferAdd(&buf, "(device ", 8);
-       res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf);
-       if (res != 0) {
-           goto error;
-       }
-       virBufferAdd(&buf, ")", 1);
+    for (i = 0; i < obj->nodesetval->nodeNr; i++) {
+        virBufferAdd(&buf, "(device ", 8);
+        res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf);
+        if (res != 0) {
+            goto error;
+        }
+        virBufferAdd(&buf, ")", 1);
     }
     xmlXPathFreeObject(obj);
     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++) {
-           virBufferAdd(&buf, "(device ", 8);
-           res = virDomainParseXMLIfDesc(obj->nodesetval->nodeTab[i], &buf);
-           if (res != 0) {
-               goto error;
-           }
-           virBufferAdd(&buf, ")", 1);
-       }
+        for (i = 0; i < obj->nodesetval->nodeNr; i++) {
+            virBufferAdd(&buf, "(device ", 8);
+            res =
+                virDomainParseXMLIfDesc(obj->nodesetval->nodeTab[i], &buf);
+            if (res != 0) {
+                goto error;
+            }
+            virBufferAdd(&buf, ")", 1);
+        }
     }
     xmlXPathFreeObject(obj);
 
@@ -888,15 +918,15 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) {
     xmlFreeDoc(xml);
 
     if (name != NULL)
-       *name = nam;
-    
-    return(ret);
+        *name = nam;
 
-error:
+    return (ret);
+
+  error:
     if (nam != NULL)
-       free(nam);
+        free(nam);
     if (name != NULL)
-       *name = NULL;
+        *name = NULL;
     if (obj != NULL)
         xmlXPathFreeObject(obj);
     if (ctxt != NULL)
@@ -905,6 +935,5 @@ error:
         xmlFreeDoc(xml);
     if (ret != NULL)
         free(ret);
-    return(NULL);
+    return (NULL);
 }
-
index e802be97177aacd2c7300fa130389c7aa661a9e8..2d75b007bfe026ce59d62f4e0a128c1c69821f8f 100644 (file)
--- a/src/xml.h
+++ b/src/xml.h
@@ -16,26 +16,19 @@ extern "C" {
  *
  * A buffer structure.
  */
-typedef struct _virBuffer virBuffer;
-typedef virBuffer *virBufferPtr;
-struct _virBuffer {
-    char *content;             /* The buffer content UTF8 */
-    unsigned int use;          /* The buffer size used */
-    unsigned int size;         /* The buffer size */
-};
-
-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__ */