+Thu Aug 9 14:27:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
+
+ * src/libvirt.c, src/openvz_conf.c, src/qemu_conf.c,
+ src/test.c, src/xm_internal.c, src/xend_internal.c: Use
+ virUUIDFormat() / virUUIDGenerate / virUUIDParse apis.
+ * qemu/internal.h: Remove unused UUID_LEN constants
+ * src/openvz_conf.h, src/qemu_conf.h: Remove duplicated
+ UUID length constants
+ * src/xml.c, src/xml.h: Remove virParseUUID api
+ * src/uuid.h, src/uuid.c: Add virUUIDFormat() api.
+ * proxy/Makefile.am: Include uuid.o
+
Tue Aug 7 16:35:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/Makefile.am: gnutls_1_0_compat.h to list of sources
libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
@top_srcdir@/src/xen_internal.c @top_srcdir@/src/virterror.c \
@top_srcdir@/src/sexpr.c @top_srcdir@/src/xml.c \
- @top_srcdir@/src/xs_internal.c @top_srcdir@/src/buf.c
+ @top_srcdir@/src/xs_internal.c @top_srcdir@/src/buf.c @top_srcdir@/src/uuid.c
libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
libvirt_proxy_DEPENDENCIES =
libvirt_proxy_LDADD =
#define ATTRIBUTE_FORMAT(...)
#endif
-#define UUID_LEN 16
-
typedef enum {
QEMUD_ERR,
QEMUD_WARN,
#include "internal.h"
#include "driver.h"
-#include "xml.h"
+#include "uuid.h"
#include "test.h"
#include "xen_unified.h"
#include "remote_internal.h"
if (domain->id == 0) {
memset(uuid, 0, VIR_UUID_BUFLEN);
} else {
-#if 0
- /* Probably legacy code: It appears that we always fill in
- * the UUID when creating the virDomain structure, so this
- * shouldn't be necessary.
- */
- 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))
- xenDaemonDomainLookupByName_ids(domain->conn, domain->name,
- &domain->uuid[0]);
-#endif
memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
}
return (0);
if (virDomainGetUUID(domain, &uuid[0]))
return (-1);
- snprintf(buf, VIR_UUID_STRING_BUFLEN,
- "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
+ virUUIDFormat(uuid, buf);
return (0);
}
}
if (virNetworkGetUUID(network, &uuid[0]))
- return (-1);
+ return (-1);
- snprintf(buf, VIR_UUID_STRING_BUFLEN,
- "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
+ virUUIDFormat(uuid, buf);
return (0);
}
struct openvz_vm *vm = driver->vms;
while (vm) {
- if (!memcmp(vm->vmdef->uuid, uuid, OPENVZ_UUID_MAX))
+ if (!memcmp(vm->vmdef->uuid, uuid, VIR_UUID_BUFLEN))
return vm;
vm = vm->next;
}
openvzSetUUID(int vpsid)
{
char conf_file[PATH_MAX];
- char uuid[VIR_UUID_STRING_BUFLEN];
- unsigned char new_uuid[VIR_UUID_BUFLEN];
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ unsigned char uuid[VIR_UUID_BUFLEN];
char *conf_dir;
int fd, ret, i;
return -1;
if(uuid[0] == (int)NULL) {
- virUUIDGenerate(new_uuid);
- bzero(uuid, VIR_UUID_STRING_BUFLEN);
- for(i = 0; i < VIR_UUID_BUFLEN; i ++)
- sprintf(uuid + (i * 2), "%02x", (unsigned char)new_uuid[i]);
-
+ virUUIDGenerate(uuid);
+ virUUIDFormat(uuid, uuidstr);
+
lseek(fd, 0, SEEK_END);
write(fd, "\n#UUID: ", 8);
write(fd, uuid, strlen(uuid));
#include "openvz_driver.h"
#define OPENVZ_NAME_MAX 8
-#define OPENVZ_UUID_MAX 16
#define OPENVZ_TMPL_MAX 256
#define OPENVZ_UNAME_MAX 32
#define OPENVZ_IP_MAX 16
struct openvz_vm_def {
char name[OPENVZ_NAME_MAX];
- unsigned char uuid[OPENVZ_UUID_MAX];
+ unsigned char uuid[VIR_UUID_BUFLEN];
char profile[OPENVZ_PROFILE_MAX];
struct openvz_fs_def fs;
struct openvz_net_def net;
struct qemud_vm *vm = driver->vms;
while (vm) {
- if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
+ if (!memcmp(vm->def->uuid, uuid, VIR_UUID_BUFLEN))
return vm;
vm = vm->next;
}
struct qemud_network *network = driver->networks;
while (network) {
- if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
+ if (!memcmp(network->def->uuid, uuid, VIR_UUID_BUFLEN))
return network;
network = network->next;
}
int live) {
virBufferPtr buf = 0;
unsigned char *uuid;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
struct qemud_vm_disk_def *disk;
struct qemud_vm_net_def *net;
struct qemud_vm_input_def *input;
goto no_memory;
uuid = def->uuid;
- if (virBufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]) < 0)
+ virUUIDFormat(uuid, uuidstr);
+ if (virBufferVSprintf(buf, " <uuid>%s</uuid>\n", uuidstr) < 0)
goto no_memory;
if (virBufferVSprintf(buf, " <memory>%d</memory>\n", def->maxmem) < 0)
goto no_memory;
struct qemud_network_def *def) {
virBufferPtr buf = 0;
unsigned char *uuid;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
buf = virBufferNew (QEMUD_MAX_XML_LEN);
if (!buf)
goto no_memory;
uuid = def->uuid;
- if (virBufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]) < 0)
+ virUUIDFormat(uuid, uuidstr);
+ if (virBufferVSprintf(buf, " <uuid>%s</uuid>\n", uuidstr) < 0)
goto no_memory;
if (def->forward) {
QEMUD_NET_BRIDGE,
};
-#define QEMUD_UUID_RAW_LEN 16
#define QEMUD_MAX_NAME_LEN 50
#define QEMUD_MAX_XML_LEN 4096
#define QEMUD_MAX_ERROR_LEN 1024
/* Guest VM main configuration */
struct qemud_vm_def {
int virtType;
- unsigned char uuid[QEMUD_UUID_RAW_LEN];
+ unsigned char uuid[VIR_UUID_BUFLEN];
char name[QEMUD_MAX_NAME_LEN];
int memory;
/* Virtual Network main configuration */
struct qemud_network_def {
- unsigned char uuid[QEMUD_UUID_RAW_LEN];
+ unsigned char uuid[VIR_UUID_BUFLEN];
char name[QEMUD_MAX_NAME_LEN];
char bridge[BR_IFNAME_MAXLEN];
#include "test.h"
#include "xml.h"
#include "buf.h"
-
+#include "uuid.h"
struct _testDev {
char name[20];
xmlNodePtr root = NULL;
xmlXPathContextPtr ctxt = NULL;
char *name = NULL;
- unsigned char rawuuid[VIR_UUID_BUFLEN];
- char *dst_uuid;
+ unsigned char uuid[VIR_UUID_BUFLEN];
struct timeval tv;
unsigned long memory = 0;
unsigned long maxMem = 0;
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain uuid"));
goto error;
}
- dst_uuid = (char *) &rawuuid[0];
- if (!(virParseUUID((char **)&dst_uuid, str))) {
+ if (virUUIDParse(str, uuid) < 0) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain uuid"));
goto error;
}
if (memory > maxMem)
memory = maxMem;
- memmove(privconn->domains[handle].uuid, rawuuid, VIR_UUID_BUFLEN);
+ memmove(privconn->domains[handle].uuid, uuid, VIR_UUID_BUFLEN);
privconn->domains[handle].info.maxMem = maxMem;
privconn->domains[handle].info.memory = memory;
privconn->domains[handle].info.state = domid < 0 ? VIR_DOMAIN_SHUTOFF : VIR_DOMAIN_RUNNING;
xmlNodePtr root = NULL;
xmlXPathContextPtr ctxt = NULL;
char *name = NULL, *bridge = NULL;
- unsigned char rawuuid[VIR_UUID_BUFLEN];
- char *dst_uuid;
+ unsigned char uuid[VIR_UUID_BUFLEN];
char *str;
char *ipaddress = NULL, *ipnetmask = NULL, *dhcpstart = NULL, *dhcpend = NULL;
int forward;
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("network uuid"));
goto error;
}
- dst_uuid = (char *) &rawuuid[0];
- if (!(virParseUUID((char **)&dst_uuid, str))) {
+ if (virUUIDParse(str, uuid) < 0) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("network uuid"));
goto error;
}
bridge = NULL;
}
- memmove(privconn->networks[handle].uuid, rawuuid, VIR_UUID_BUFLEN);
+ memmove(privconn->networks[handle].uuid, uuid, VIR_UUID_BUFLEN);
privconn->networks[handle].forward = forward;
if (forwardDev) {
strncpy(privconn->networks[handle].forwardDev, forwardDev, sizeof(privconn->networks[handle].forwardDev)-1);
char *str;
xmlDocPtr xml = NULL;
xmlNodePtr root = NULL;
- xmlNodePtr *domains, *networks;
+ xmlNodePtr *domains, *networks = NULL;
xmlXPathContextPtr ctxt = NULL;
virNodeInfoPtr nodeInfo;
testConnPtr privconn = malloc(sizeof(testConn));
virBufferPtr buf;
char *xml;
unsigned char *uuid;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
GET_DOMAIN(domain, NULL);
if (!(buf = virBufferNew(4000))) {
virBufferVSprintf(buf, "<domain type='test' id='%d'>\n", domain->id);
virBufferVSprintf(buf, " <name>%s</name>\n", domain->name);
uuid = domain->uuid;
- virBufferVSprintf(buf,
- " <uuid>%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x</uuid>\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
-
+ virUUIDFormat(uuid, uuidstr);
+ virBufferVSprintf(buf, " <uuid>%s</uuid>\n", uuidstr);
virBufferVSprintf(buf, " <memory>%lu</memory>\n", privdom->info.maxMem);
virBufferVSprintf(buf, " <vcpu>%d</vcpu>\n", privdom->info.nrVirtCpu);
virBufferVSprintf(buf, " <on_reboot>%s</on_reboot>\n", testRestartFlagToString(privdom->onReboot));
virBufferPtr buf;
char *xml;
unsigned char *uuid;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
GET_NETWORK(network, NULL);
if (!(buf = virBufferNew(4000))) {
virBufferAdd(buf, "<network>\n", -1);
virBufferVSprintf(buf, " <name>%s</name>\n", network->name);
uuid = network->uuid;
- virBufferVSprintf(buf,
- " <uuid>%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x</uuid>\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
-
+ virUUIDFormat(uuid, uuidstr);
+ virBufferVSprintf(buf, " <uuid>%s</uuid>\n", uuidstr);
virBufferVSprintf(buf, " <bridge name='%s'/>\n", privnet->bridge);
if (privnet->forward) {
if (privnet->forwardDev[0])
/**
* virUUIDGenerate:
- * @uuid: array of VIR_UUID_RAW_LEN bytes to store the new UUID
+ * @uuid: array of VIR_UUID_BUFLEN bytes to store the new UUID
*
* Generates a randomized unique identifier.
*
if (uuid == NULL)
return(-1);
- if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_RAW_LEN)))
+ if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_BUFLEN)))
qemudLog(QEMUD_WARN,
"Falling back to pseudorandom UUID, "
"failed to generate random bytes: %s", strerror(err));
- return virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_RAW_LEN);
+ return virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_BUFLEN);
}
/**
* virUUIDParse:
- * @uuid: zero terminated string representation of the UUID
- * @rawuuid: array of VIR_UUID_RAW_LEN bytes to store the raw UUID
+ * @uuidstr: zero terminated string representation of the UUID
+ * @uuid: array of VIR_UUID_BUFLEN bytes to store the raw UUID
*
* Parses the external string representation, allowing spaces and '-'
* character in the sequence, and storing the result as a raw UUID
* Returns 0 in case of success and -1 in case of error.
*/
int
-virUUIDParse(const char *uuid, unsigned char *rawuuid) {
+virUUIDParse(const char *uuidstr, unsigned char *uuid) {
const char *cur;
int i;
- if ((uuid == NULL) || (rawuuid == NULL))
+ if ((uuidstr == NULL) || (uuid == NULL))
return(-1);
/*
* do a liberal scan allowing '-' and ' ' anywhere between character
* pairs as long as there is 32 of them in the end.
*/
- cur = uuid;
- for (i = 0;i < 16;) {
- rawuuid[i] = 0;
+ cur = uuidstr;
+ for (i = 0;i < VIR_UUID_BUFLEN;) {
+ uuid[i] = 0;
if (*cur == 0)
goto error;
if ((*cur == '-') || (*cur == ' ')) {
continue;
}
if ((*cur >= '0') && (*cur <= '9'))
- rawuuid[i] = *cur - '0';
+ uuid[i] = *cur - '0';
else if ((*cur >= 'a') && (*cur <= 'f'))
- rawuuid[i] = *cur - 'a' + 10;
+ uuid[i] = *cur - 'a' + 10;
else if ((*cur >= 'A') && (*cur <= 'F'))
- rawuuid[i] = *cur - 'A' + 10;
+ uuid[i] = *cur - 'A' + 10;
else
goto error;
- rawuuid[i] *= 16;
+ uuid[i] *= 16;
cur++;
if (*cur == 0)
goto error;
if ((*cur >= '0') && (*cur <= '9'))
- rawuuid[i] += *cur - '0';
+ uuid[i] += *cur - '0';
else if ((*cur >= 'a') && (*cur <= 'f'))
- rawuuid[i] += *cur - 'a' + 10;
+ uuid[i] += *cur - 'a' + 10;
else if ((*cur >= 'A') && (*cur <= 'F'))
- rawuuid[i] += *cur - 'A' + 10;
+ uuid[i] += *cur - 'A' + 10;
else
goto error;
i++;
return -1;
}
+/**
+ * virUUIDFormat:
+ * @uuid: array of VIR_UUID_RAW_LEN bytes to store the raw UUID
+ * @uuidstr: array of VIR_UUID_STRING_BUFLEN bytes to store the
+ * string representation of the UUID in. The resulting string
+ * will be NULL terminated.
+ *
+ * Converts the raw UUID into printable format, with embedded '-'
+ *
+ * Returns 0 in case of success and -1 in case of error.
+ */
+void virUUIDFormat(const unsigned char *uuid, char *uuidstr)
+{
+ snprintf(uuidstr, VIR_UUID_STRING_BUFLEN,
+ "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ uuid[0], uuid[1], uuid[2], uuid[3],
+ uuid[4], uuid[5], uuid[6], uuid[7],
+ uuid[8], uuid[9], uuid[10], uuid[11],
+ uuid[12], uuid[13], uuid[14], uuid[15]);
+ uuidstr[VIR_UUID_STRING_BUFLEN-1] = '\0';
+}
+
+
/*
* Local variables:
* indent-tabs-mode: nil
#ifndef __VIR_UUID_H__
#define __VIR_UUID_H__
-/**
- * VIR_UUID_RAW_LEN:
- * number of bytes used by an UUID in raw form
- */
-#define VIR_UUID_RAW_LEN 16
-
int virUUIDGenerate(unsigned char *uuid);
-int virUUIDParse(const char *uuid,
- unsigned char *rawuuid);
+int virUUIDParse(const char *uuidstr,
+ unsigned char *uuid);
+
+void virUUIDFormat(const unsigned char *uuid,
+ char *uuidstr);
#endif /* __VIR_UUID_H__ */
#include "sexpr.h"
#include "xml.h"
#include "buf.h"
+#include "uuid.h"
#include "xen_unified.h"
#include "xend_internal.h"
#include "xen_internal.h" /* for DOM0_INTERFACE_VERSION */
*
* convenience function to lookup an UUID value from the S-Expression
*
- * Returns a pointer to the stored UUID or NULL in case of error.
+ * Returns a -1 on error, 0 on success
*/
-static unsigned char *
-sexpr_uuid(char **ptr, struct sexpr *node, const char *path)
+static int
+sexpr_uuid(unsigned char *ptr, struct sexpr *node, const char *path)
{
const char *r = sexpr_node(node, path);
- return virParseUUID(ptr, r);
+ if (!r)
+ return -1;
+ return virUUIDParse(r, ptr);
}
_("domain information incorrect domid not numeric"));
ret = -1;
} else if (uuid != NULL) {
- char *uuid_c = (char *) uuid;
- char **ptr = &uuid_c;
-
- if (sexpr_uuid(ptr, root, "domain/uuid") == NULL) {
+ if (sexpr_uuid(uuid, root, "domain/uuid") < 0) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
_("domain information incomplete, missing uuid"));
}
unsigned char *uuid)
{
const char *name = NULL;
- char *dst_uuid;
struct sexpr *root;
memset(uuid, 0, VIR_UUID_BUFLEN);
if (domname)
*domname = strdup(name);
- dst_uuid = (char *)&uuid[0];
- if (sexpr_uuid(&dst_uuid, root, "domain/uuid") == NULL) {
+ if (sexpr_uuid(uuid, root, "domain/uuid") < 0) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
_("domain information incomplete, missing uuid"));
goto error;
int hvm = 0, bootloader = 0;
int domid = -1;
int max_mem, cur_mem;
+ unsigned char uuid[VIR_UUID_BUFLEN];
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
if (root == NULL) {
/* ERROR */
}
virBufferVSprintf(&buf, " <name>%s</name>\n", tmp);
tmp = sexpr_node(root, "domain/uuid");
- if (tmp != NULL) {
- char compact[33];
- int i, j;
- for (i = 0, j = 0;(i < 32) && (tmp[j] != 0);j++) {
- if (((tmp[j] >= '0') && (tmp[j] <= '9')) ||
- ((tmp[j] >= 'a') && (tmp[j] <= 'f'))) {
- compact[i++] = tmp[j];
- } else if ((tmp[j] >= 'A') && (tmp[j] <= 'F')) {
- compact[i++] = tmp[j] + 'a' - 'A';
- }
- }
- compact[i] = 0;
- if (i > 0)
- virBufferVSprintf(&buf, " <uuid>%s</uuid>\n", compact);
+ if (tmp == NULL) {
+ virXendError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("domain information incomplete, missing name"));
+ goto error;
}
+ virUUIDParse(tmp, uuid);
+ virUUIDFormat(uuid, uuidstr);
+ virBufferVSprintf(&buf, " <uuid>%s</uuid>\n", uuidstr);
+
tmp = sexpr_node(root, "domain/bootloader");
if (tmp != NULL) {
bootloader = 1;
sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
{
virDomainPtr ret = NULL;
- char *dst_uuid = NULL;
- char uuid[VIR_UUID_BUFLEN];
+ unsigned char uuid[VIR_UUID_BUFLEN];
const char *name;
const char *tmp;
xenUnifiedPrivatePtr priv;
priv = (xenUnifiedPrivatePtr) conn->privateData;
- dst_uuid = (char *) &uuid[0];
- if (sexpr_uuid(&dst_uuid, root, "domain/uuid") == NULL)
+ if (sexpr_uuid(uuid, root, "domain/uuid") < 0)
goto error;
name = sexpr_node(root, "domain/name");
if (name == NULL)
goto error;
- ret = virGetDomain(conn, name, (const unsigned char *) &uuid[0]);
+ ret = virGetDomain(conn, name, uuid);
if (ret == NULL) return NULL;
tmp = sexpr_node(root, "domain/domid");
char uuidstr[VIR_UUID_STRING_BUFLEN];
struct sexpr *root = NULL;
- memset(uuidstr, '\0', VIR_UUID_STRING_BUFLEN);
-
- snprintf(uuidstr, VIR_UUID_STRING_BUFLEN,
- "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
-
+ virUUIDFormat(uuid, uuidstr);
root = sexpr_get(conn, "/xend/domain/%s?detail=1", uuidstr);
if (root == NULL)
return (NULL);
#include "internal.h"
#include "xml.h"
#include "buf.h"
+#include "uuid.h"
typedef struct xenXMConfCache *xenXMConfCachePtr;
typedef struct xenXMConfCache {
/* Convenience method to grab a string UUID from the config file object */
static int xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) {
virConfValuePtr val;
- char *rawuuid = (char *)uuid;
if (!uuid || !name || !conf)
return (-1);
if (!(val = virConfGetValue(conf, name))) {
if (!val->str)
return (-1);
- if (!virParseUUID(&rawuuid, val->str))
+ if (virUUIDParse(val->str, uuid) < 0)
return (-1);
return (0);
}
-/* Generate a rnadom UUID - used if domain doesn't already
- have one in its config */
-static void xenXMConfigGenerateUUID(unsigned char *uuid) {
- int i;
- for (i = 0 ; i < VIR_UUID_BUFLEN ; i++) {
- uuid[i] = (unsigned char)(1 + (int) (256.0 * (rand() / (RAND_MAX + 1.0))));
- }
-}
/* Ensure that a config object has a valid UUID in it,
if it doesn't then (re-)generate one */
}
/* ... then generate one */
- xenXMConfigGenerateUUID(uuid);
- snprintf(uuidstr, VIR_UUID_STRING_BUFLEN,
- "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
- uuidstr[VIR_UUID_STRING_BUFLEN-1] = '\0';
+ virUUIDGenerate(uuid);
+ virUUIDFormat(uuid, uuidstr);
value->type = VIR_CONF_STRING;
value->str = strdup(uuidstr);
char *xml;
const char *name;
unsigned char uuid[VIR_UUID_BUFLEN];
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
const char *str;
int hvm = 0;
long val;
virBufferAdd(buf, "<domain type='xen'>\n", -1);
virBufferVSprintf(buf, " <name>%s</name>\n", name);
- virBufferVSprintf(buf,
- " <uuid>%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x</uuid>\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
+ virUUIDFormat(uuid, uuidstr);
+ virBufferVSprintf(buf, " <uuid>%s</uuid>\n", uuidstr);
if ((xenXMConfigGetString(conf, "builder", &str) == 0) &&
!strcmp(str, "hvm"))
return (NULL);
}
-#endif /* !PROXY */
-
-
-
-unsigned char *virParseUUID(char **ptr, const char *uuid) {
- int rawuuid[VIR_UUID_BUFLEN];
- const char *cur;
- unsigned char *dst_uuid = NULL;
- int i;
-
- if (uuid == NULL)
- goto error;
-
- /*
- * do a liberal scan allowing '-' and ' ' anywhere between character
- * pairs as long as there is 32 of them in the end.
- */
- cur = uuid;
- for (i = 0;i < VIR_UUID_BUFLEN;) {
- rawuuid[i] = 0;
- if (*cur == 0)
- goto error;
- if ((*cur == '-') || (*cur == ' ')) {
- cur++;
- continue;
- }
- if ((*cur >= '0') && (*cur <= '9'))
- rawuuid[i] = *cur - '0';
- else if ((*cur >= 'a') && (*cur <= 'f'))
- rawuuid[i] = *cur - 'a' + 10;
- else if ((*cur >= 'A') && (*cur <= 'F'))
- rawuuid[i] = *cur - 'A' + 10;
- else
- goto error;
- rawuuid[i] *= 16;
- cur++;
- if (*cur == 0)
- goto error;
- if ((*cur >= '0') && (*cur <= '9'))
- rawuuid[i] += *cur - '0';
- else if ((*cur >= 'a') && (*cur <= 'f'))
- rawuuid[i] += *cur - 'a' + 10;
- else if ((*cur >= 'A') && (*cur <= 'F'))
- rawuuid[i] += *cur - 'A' + 10;
- else
- goto error;
- i++;
- cur++;
- }
-
- dst_uuid = (unsigned char *) *ptr;
- *ptr += 16;
-
- for (i = 0; i < VIR_UUID_BUFLEN; i++)
- dst_uuid[i] = rawuuid[i] & 0xFF;
-
- error:
- return(dst_uuid);
-}
-
-#ifndef PROXY
/**
* virParseXMLDevice:
* @conn: pointer to the hypervisor connection
xmlNodePtr **list);
char *virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name, int xendConfigVersion);
-unsigned char *virParseUUID(char **ptr, const char *uuid);
char *virParseXMLDevice(virConnectPtr conn, char *xmldesc, int hvm, int xendConfigVersion);
int virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref);
<domain type='xen' id='5'>
<name>rhel5</name>
- <uuid>4f77abd2301958e83bab6fbf2118f880</uuid>
+ <uuid>4f77abd2-3019-58e8-3bab-6fbf2118f880</uuid>
<bootloader>/usr/bin/pygrub</bootloader>
<os>
<type>linux</type>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='3'>
<name>fvtest</name>
- <uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
+ <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen' id='3'>
<name>fvtest</name>
- <uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
+ <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen' id='3'>
<name>fvtest</name>
- <uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
+ <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen' id='3'>
<name>fvtest</name>
- <uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
+ <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen' id='3'>
<name>fvtest</name>
- <uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
+ <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen' id='3'>
<name>fvtest</name>
- <uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
+ <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='6'>
<name>test</name>
- <uuid>cc2315e7d26a307a438c6d188ec4c09c</uuid>
+ <uuid>cc2315e7-d26a-307a-438c-6d188ec4c09c</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<bootloader>/usr/bin/pypxeboot</bootloader>
<bootloader_args>mac=AA:00:86:e2:35:72</bootloader_args>
<memory>430080</memory>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<domain type='xen' id='6'>
<name>pvtest</name>
- <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
name = "XenGuest2"
-uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest2</name>
- <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
name = "XenGuest2"
-uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest2</name>
- <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
name = "XenGuest2"
-uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest2</name>
- <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
name = "XenGuest2"
-uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest2</name>
- <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<domain type='xen'>
<name>XenGuest2</name>
- <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
name = "XenGuest2"
-uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest2</name>
- <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
name = "XenGuest2"
-uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest2</name>
- <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
name = "XenGuest1"
-uuid = "c7a5fdb0cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest1</name>
- <uuid>c7a5fdb0cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb0-cdaf-9455-926a-d65c16db1809</uuid>
<bootloader>/usr/bin/pygrub</bootloader>
<currentMemory>403456</currentMemory>
<memory>592896</memory>
name = "XenGuest1"
-uuid = "c7a5fdb0cdaf9455926ad65c16db1809"
+uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
<domain type='xen'>
<name>XenGuest1</name>
- <uuid>c7a5fdb0cdaf9455926ad65c16db1809</uuid>
+ <uuid>c7a5fdb0-cdaf-9455-926a-d65c16db1809</uuid>
<bootloader>/usr/bin/pygrub</bootloader>
<currentMemory>403456</currentMemory>
<memory>592896</memory>