[Libvir] PATCH 7/20 add a UUID module & rename funcs

Daniel P. Berrange berrange at redhat.com
Fri Jun 22 01:49:52 UTC 2007


This patch pulls the UUID parsing & generation functions out into a separate
code module, and renames them to be more general purpose.

 conf.c |    8 ++++----
 uuid.c |   16 ++++++++--------
 uuid.h |   14 ++++++++------
 3 files changed, 20 insertions(+), 18 deletions(-)

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
-------------- next part --------------
diff -r 65bc80ff404f qemud/conf.c
--- a/qemud/conf.c	Thu Jun 21 16:26:41 2007 -0400
+++ b/qemud/conf.c	Thu Jun 21 20:40:20 2007 -0400
@@ -823,12 +823,12 @@ static struct qemud_vm_def *qemudParseXM
     if ((obj == NULL) || (obj->type != XPATH_STRING) ||
         (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
         int err;
-        if ((err = qemudGenerateUUID(def->uuid))) {
+        if ((err = virUUIDGenerate(def->uuid))) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "Failed to generate UUID: %s", strerror(err));
             goto error;
         }
-    } else if (qemudParseUUID((const char *)obj->stringval, def->uuid) < 0) {
+    } else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
         goto error;
     }
@@ -1936,12 +1936,12 @@ static struct qemud_network_def *qemudPa
     if ((obj == NULL) || (obj->type != XPATH_STRING) ||
         (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
         int err;
-        if ((err = qemudGenerateUUID(def->uuid))) {
+        if ((err = virUUIDGenerate(def->uuid))) {
             qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "Failed to generate UUID: %s", strerror(err));
             goto error;
         }
-    } else if (qemudParseUUID((const char *)obj->stringval, def->uuid) < 0) {
+    } else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) {
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", "malformed uuid element");
         goto error;
     }
diff -r 65bc80ff404f qemud/uuid.c
--- a/qemud/uuid.c	Thu Jun 21 16:26:41 2007 -0400
+++ b/qemud/uuid.c	Thu Jun 21 20:42:30 2007 -0400
@@ -35,8 +35,8 @@
 #include "internal.h"
 
 static int
-qemudGenerateRandomBytes(unsigned char *buf,
-                         int buflen)
+virUUIDGenerateRandomBytes(unsigned char *buf,
+                           int buflen)
 {
     int fd;
 
@@ -63,8 +63,8 @@ qemudGenerateRandomBytes(unsigned char *
 }
 
 static int
-qemudGeneratePseudoRandomBytes(unsigned char *buf,
-                               int buflen)
+virUUIDGeneratePseudoRandomBytes(unsigned char *buf,
+                                 int buflen)
 {
     srand(time(NULL));
     while (buflen > 0) {
@@ -76,20 +76,20 @@ qemudGeneratePseudoRandomBytes(unsigned 
 }
 
 int
-qemudGenerateUUID(unsigned char *uuid)
+virUUIDGenerate(unsigned char *uuid)
 {
     int err;
 
-    if ((err = qemudGenerateRandomBytes(uuid, QEMUD_UUID_RAW_LEN)))
+    if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_RAW_LEN)))
         qemudLog(QEMUD_WARN,
                  "Falling back to pseudorandom UUID, "
                  "failed to generate random bytes: %s", strerror(err));
 
-    return qemudGeneratePseudoRandomBytes(uuid, QEMUD_UUID_RAW_LEN);
+    return virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_RAW_LEN);
 }
 
 int
-qemudParseUUID(const char *uuid, unsigned char *rawuuid) {
+virUUIDParse(const char *uuid, unsigned char *rawuuid) {
     const char *cur;
     int i;
 
diff -r 65bc80ff404f qemud/uuid.h
--- a/qemud/uuid.h	Thu Jun 21 16:26:41 2007 -0400
+++ b/qemud/uuid.h	Thu Jun 21 20:41:37 2007 -0400
@@ -19,12 +19,14 @@
  *     Mark McLoughlin <markmc at redhat.com>
  */
 
-#ifndef __QEMUD_UUID_H__
-#define __QEMUD_UUID_H__
+#ifndef __VIR_UUID_H__
+#define __VIR_UUID_H__
 
-int qemudGenerateUUID(unsigned char *uuid);
+#define VIR_UUID_RAW_LEN 16
 
-int qemudParseUUID   (const char *uuid,
-		      unsigned char *rawuuid);
+int virUUIDGenerate(unsigned char *uuid);
 
-#endif /* __QEMUD_UUID_H__ */
+int virUUIDParse(const char *uuid,
+		 unsigned char *rawuuid);
+
+#endif /* __VIR_UUID_H__ */


More information about the libvir-list mailing list