提交 6d153563 编写于 作者: M Mark McLoughlin

Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>

        * include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
        VIR_UUID_STRING_BUFLEN

        * libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
        libvirt/src/internal.h, libvirt/src/libvirt.c,
        libvirt/src/proxy_internal.c, libvirt/src/test.c,
        libvirt/src/virsh.c, libvirt/src/xend_internal.c,
        libvirt/src/xm_internal.c, libvirt/src/xml.c,
        libvirt/python/libvir.c: use them
上级 dab5d107
Mon Jan 23 14:36:18 IST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add VIR_UUID_BUFLEN and
VIR_UUID_STRING_BUFLEN
* libvirt/proxy/libvirt_proxy.c, libvirt/src/hash.c,
libvirt/src/internal.h, libvirt/src/libvirt.c,
libvirt/src/proxy_internal.c, libvirt/src/test.c,
libvirt/src/virsh.c, libvirt/src/xend_internal.c,
libvirt/src/xm_internal.c, libvirt/src/xml.c,
libvirt/python/libvir.c: use them
Mon Jan 23 12:28:42 IST 2007 Mark McLoughlin <markmc@redhat.com> Mon Jan 23 12:28:42 IST 2007 Mark McLoughlin <markmc@redhat.com>
Issues pointed out by Karel Zak <kzak@redhat.com> Issues pointed out by Karel Zak <kzak@redhat.com>
......
...@@ -187,6 +187,24 @@ struct _virNodeInfo { ...@@ -187,6 +187,24 @@ struct _virNodeInfo {
typedef virNodeInfo *virNodeInfoPtr; typedef virNodeInfo *virNodeInfoPtr;
/**
* VIR_UUID_STRING_BUFLEN:
*
* This macro provides the length of the buffer required
* for virDomainGetUUID()
*/
#define VIR_UUID_BUFLEN (16)
/**
* VIR_UUID_STRING_BUFLEN:
*
* This macro provides the length of the buffer required
* for virDomainGetUUIDString()
*/
#define VIR_UUID_STRING_BUFLEN (36+1)
/* library versionning */ /* library versionning */
/** /**
......
...@@ -462,7 +462,7 @@ retry2: ...@@ -462,7 +462,7 @@ retry2:
break; break;
case VIR_PROXY_LOOKUP_ID: { case VIR_PROXY_LOOKUP_ID: {
char *name = NULL; char *name = NULL;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
int len; int len;
if (req->len != sizeof(virProxyPacket)) if (req->len != sizeof(virProxyPacket))
...@@ -476,9 +476,9 @@ retry2: ...@@ -476,9 +476,9 @@ retry2:
len = 1000; len = 1000;
name[1000] = 0; name[1000] = 0;
} }
req->len += 16 + len + 1; req->len += VIR_UUID_BUFLEN + len + 1;
memcpy(&request.extra.str[0], uuid, 16); memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN);
strcpy(&request.extra.str[16], name); strcpy(&request.extra.str[VIR_UUID_BUFLEN], name);
} }
if (name) if (name)
free(name); free(name);
...@@ -489,9 +489,9 @@ retry2: ...@@ -489,9 +489,9 @@ retry2:
char **tmp; char **tmp;
int ident, len; int ident, len;
char *name = NULL; char *name = NULL;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
if (req->len != sizeof(virProxyPacket) + 16) if (req->len != sizeof(virProxyPacket) + VIR_UUID_BUFLEN)
goto comm_error; goto comm_error;
/* /*
...@@ -504,7 +504,7 @@ retry2: ...@@ -504,7 +504,7 @@ retry2:
if (names != NULL) { if (names != NULL) {
while (*tmp != NULL) { while (*tmp != NULL) {
ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]); ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]);
if (!memcmp(uuid, &request.extra.str[0], 16)) { if (!memcmp(uuid, &request.extra.str[0], VIR_UUID_BUFLEN)) {
name = *tmp; name = *tmp;
break; break;
} }
...@@ -530,7 +530,7 @@ retry2: ...@@ -530,7 +530,7 @@ retry2:
} }
case VIR_PROXY_LOOKUP_NAME: { case VIR_PROXY_LOOKUP_NAME: {
int ident; int ident;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
if (req->len > sizeof(virProxyPacket) + 1000) if (req->len > sizeof(virProxyPacket) + 1000)
goto comm_error; goto comm_error;
...@@ -542,8 +542,8 @@ retry2: ...@@ -542,8 +542,8 @@ retry2:
req->data.arg = -1; req->data.arg = -1;
req->len = sizeof(virProxyPacket); req->len = sizeof(virProxyPacket);
} else { } else {
req->len = sizeof(virProxyPacket) + 16; req->len = sizeof(virProxyPacket) + VIR_UUID_BUFLEN;
memcpy(&request.extra.str[0], uuid, 16); memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN);
req->data.arg = ident; req->data.arg = ident;
} }
break; break;
......
...@@ -349,7 +349,7 @@ libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { ...@@ -349,7 +349,7 @@ libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject * PyObject *
libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval; PyObject *py_retval;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
virDomainPtr domain; virDomainPtr domain;
PyObject *pyobj_domain; PyObject *pyobj_domain;
int c_retval; int c_retval;
...@@ -370,7 +370,7 @@ libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { ...@@ -370,7 +370,7 @@ libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return(Py_None); return(Py_None);
} }
py_retval = PyString_FromStringAndSize((char *) &uuid[0], 16); py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
return(py_retval); return(py_retval);
} }
...@@ -388,7 +388,7 @@ libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { ...@@ -388,7 +388,7 @@ libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
return(NULL); return(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
if ((uuid == NULL) || (len != 16)) { if ((uuid == NULL) || (len != VIR_UUID_BUFLEN)) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return(Py_None); return(Py_None);
} }
......
...@@ -759,7 +759,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) { ...@@ -759,7 +759,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
ret->conn = conn; ret->conn = conn;
ret->id = -1; ret->id = -1;
if (uuid != NULL) if (uuid != NULL)
memcpy(&(ret->uuid[0]), uuid, 16); memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->domains, name, ret) < 0) { if (virHashAddEntry(conn->domains, name, ret) < 0) {
virHashError(conn, VIR_ERR_INTERNAL_ERROR, virHashError(conn, VIR_ERR_INTERNAL_ERROR,
......
...@@ -145,15 +145,15 @@ enum { ...@@ -145,15 +145,15 @@ enum {
* Internal structure associated to a domain * Internal structure associated to a domain
*/ */
struct _virDomain { struct _virDomain {
unsigned int magic; /* specific value to check */ unsigned int magic; /* specific value to check */
int uses; /* reference count */ int uses; /* reference count */
virConnectPtr conn; /* pointer back to the connection */ virConnectPtr conn; /* pointer back to the connection */
char *name; /* the domain external name */ char *name; /* the domain external name */
char *path; /* the domain internal path */ char *path; /* the domain internal path */
int id; /* the domain ID */ int id; /* the domain ID */
int flags; /* extra flags */ int flags; /* extra flags */
unsigned char uuid[16]; /* the domain unique identifier */ unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */
char *xml; /* the XML description for defined domains */ char *xml; /* the XML description for defined domains */
}; };
/* /*
......
...@@ -645,8 +645,8 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -645,8 +645,8 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virDomainPtr virDomainPtr
virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr) virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
{ {
int raw[16], i; int raw[VIR_UUID_BUFLEN], i;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
int ret; int ret;
if (!VIR_IS_CONNECT(conn)) { if (!VIR_IS_CONNECT(conn)) {
...@@ -672,11 +672,11 @@ virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr) ...@@ -672,11 +672,11 @@ virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
raw + 8, raw + 9, raw + 10, raw + 11, raw + 8, raw + 9, raw + 10, raw + 11,
raw + 12, raw + 13, raw + 14, raw + 15); raw + 12, raw + 13, raw + 14, raw + 15);
if (ret!=16) { if (ret!=VIR_UUID_BUFLEN) {
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (NULL); return (NULL);
} }
for (i = 0; i < 16; i++) for (i = 0; i < VIR_UUID_BUFLEN; i++)
uuid[i] = raw[i] & 0xFF; uuid[i] = raw[i] & 0xFF;
return virDomainLookupByUUID(conn, &uuid[0]); return virDomainLookupByUUID(conn, &uuid[0]);
...@@ -1205,7 +1205,7 @@ virDomainGetName(virDomainPtr domain) ...@@ -1205,7 +1205,7 @@ virDomainGetName(virDomainPtr domain)
/** /**
* virDomainGetUUID: * virDomainGetUUID:
* @domain: a domain object * @domain: a domain object
* @uuid: pointer to a 16 bytes array * @uuid: pointer to a VIR_UUID_BUFLEN bytes array
* *
* Get the UUID for a domain * Get the UUID for a domain
* *
...@@ -1224,7 +1224,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) ...@@ -1224,7 +1224,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
} }
if (domain->id == 0) { if (domain->id == 0) {
memset(uuid, 0, 16); memset(uuid, 0, VIR_UUID_BUFLEN);
} else { } else {
if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) && if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) &&
(domain->uuid[2] == 0) && (domain->uuid[3] == 0) && (domain->uuid[2] == 0) && (domain->uuid[3] == 0) &&
...@@ -1236,7 +1236,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) ...@@ -1236,7 +1236,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
(domain->uuid[14] == 0) && (domain->uuid[15] == 0)) (domain->uuid[14] == 0) && (domain->uuid[15] == 0))
xenDaemonDomainLookupByName_ids(domain->conn, domain->name, xenDaemonDomainLookupByName_ids(domain->conn, domain->name,
&domain->uuid[0]); &domain->uuid[0]);
memcpy(uuid, &domain->uuid[0], 16); memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
} }
return (0); return (0);
} }
...@@ -1244,7 +1244,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) ...@@ -1244,7 +1244,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
/** /**
* virDomainGetUUIDString: * virDomainGetUUIDString:
* @domain: a domain object * @domain: a domain object
* @buf: pointer to a 37 bytes array * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
* *
* Get the UUID for a domain as string. For more information about * Get the UUID for a domain as string. For more information about
* UUID see RFC4122. * UUID see RFC4122.
...@@ -1254,7 +1254,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid) ...@@ -1254,7 +1254,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
int int
virDomainGetUUIDString(virDomainPtr domain, char *buf) virDomainGetUUIDString(virDomainPtr domain, char *buf)
{ {
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
if (!VIR_IS_DOMAIN(domain)) { if (!VIR_IS_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
...@@ -1268,7 +1268,7 @@ virDomainGetUUIDString(virDomainPtr domain, char *buf) ...@@ -1268,7 +1268,7 @@ virDomainGetUUIDString(virDomainPtr domain, char *buf)
if (virDomainGetUUID(domain, &uuid[0])) if (virDomainGetUUID(domain, &uuid[0]))
return (-1); return (-1);
snprintf(buf, 37, snprintf(buf, VIR_UUID_STRING_BUFLEN,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", "%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[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5], uuid[6], uuid[7], uuid[4], uuid[5], uuid[6], uuid[7],
......
...@@ -761,7 +761,7 @@ xenProxyLookupByID(virConnectPtr conn, int id) ...@@ -761,7 +761,7 @@ xenProxyLookupByID(virConnectPtr conn, int id)
{ {
virProxyPacket req; virProxyPacket req;
virProxyFullPacket ans; virProxyFullPacket ans;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
const char *name; const char *name;
int ret; int ret;
virDomainPtr res; virDomainPtr res;
...@@ -786,8 +786,8 @@ xenProxyLookupByID(virConnectPtr conn, int id) ...@@ -786,8 +786,8 @@ xenProxyLookupByID(virConnectPtr conn, int id)
if (ans.data.arg == -1) { if (ans.data.arg == -1) {
return(NULL); return(NULL);
} }
memcpy(uuid, &ans.extra.str[0], 16); memcpy(uuid, &ans.extra.str[0], VIR_UUID_BUFLEN);
name = &ans.extra.str[16]; name = &ans.extra.str[VIR_UUID_BUFLEN];
res = virGetDomain(conn, name, uuid); res = virGetDomain(conn, name, uuid);
if (res == NULL) if (res == NULL)
...@@ -825,7 +825,7 @@ xenProxyLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -825,7 +825,7 @@ xenProxyLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
} }
memset(&req, 0, sizeof(virProxyPacket)); memset(&req, 0, sizeof(virProxyPacket));
req.command = VIR_PROXY_LOOKUP_UUID; req.command = VIR_PROXY_LOOKUP_UUID;
req.len = sizeof(virProxyPacket) + 16; req.len = sizeof(virProxyPacket) + VIR_UUID_BUFLEN;
ret = xenProxyCommand(conn, (virProxyPacketPtr) &req, &req, 0); ret = xenProxyCommand(conn, (virProxyPacketPtr) &req, &req, 0);
if (ret < 0) { if (ret < 0) {
xenProxyClose(conn); xenProxyClose(conn);
......
...@@ -139,7 +139,7 @@ typedef struct _testDom { ...@@ -139,7 +139,7 @@ typedef struct _testDom {
int active; int active;
int id; int id;
char name[20]; char name[20];
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
virDomainKernel kernel; virDomainKernel kernel;
virDomainInfo info; virDomainInfo info;
unsigned int maxVCPUs; unsigned int maxVCPUs;
...@@ -247,7 +247,7 @@ static int testLoadDomain(virConnectPtr conn, ...@@ -247,7 +247,7 @@ static int testLoadDomain(virConnectPtr conn,
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
xmlXPathObjectPtr obj = NULL; xmlXPathObjectPtr obj = NULL;
char *name = NULL; char *name = NULL;
unsigned char rawuuid[16]; unsigned char rawuuid[VIR_UUID_BUFLEN];
char *dst_uuid; char *dst_uuid;
testCon *con; testCon *con;
struct timeval tv; struct timeval tv;
...@@ -397,7 +397,7 @@ static int testLoadDomain(virConnectPtr conn, ...@@ -397,7 +397,7 @@ static int testLoadDomain(virConnectPtr conn,
if (memory > maxMem) if (memory > maxMem)
memory = maxMem; memory = maxMem;
memmove(con->domains[handle].uuid, rawuuid, 16); memmove(con->domains[handle].uuid, rawuuid, VIR_UUID_BUFLEN);
con->domains[handle].info.maxMem = maxMem; con->domains[handle].info.maxMem = maxMem;
con->domains[handle].info.memory = memory; con->domains[handle].info.memory = memory;
con->domains[handle].info.state = domid < 0 ? VIR_DOMAIN_SHUTOFF : VIR_DOMAIN_RUNNING; con->domains[handle].info.state = domid < 0 ? VIR_DOMAIN_SHUTOFF : VIR_DOMAIN_RUNNING;
...@@ -487,7 +487,7 @@ static int testOpenDefault(virConnectPtr conn, ...@@ -487,7 +487,7 @@ static int testOpenDefault(virConnectPtr conn,
node->connections[connid].domains[0].onCrash = VIR_DOMAIN_RESTART; node->connections[connid].domains[0].onCrash = VIR_DOMAIN_RESTART;
node->connections[connid].domains[0].onPoweroff = VIR_DOMAIN_DESTROY; node->connections[connid].domains[0].onPoweroff = VIR_DOMAIN_DESTROY;
strcpy(node->connections[connid].domains[0].name, "test"); strcpy(node->connections[connid].domains[0].name, "test");
for (u = 0 ; u < 16 ; u++) { for (u = 0 ; u < VIR_UUID_BUFLEN ; u++) {
node->connections[connid].domains[0].uuid[u] = (u * 75)%255; node->connections[connid].domains[0].uuid[u] = (u * 75)%255;
} }
node->connections[connid].domains[0].info.maxMem = 8192 * 1024; node->connections[connid].domains[0].info.maxMem = 8192 * 1024;
...@@ -901,7 +901,7 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn, ...@@ -901,7 +901,7 @@ virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
int i, idx = -1; int i, idx = -1;
for (i = 0 ; i < MAX_DOMAINS ; i++) { for (i = 0 ; i < MAX_DOMAINS ; i++) {
if (con->domains[i].active && if (con->domains[i].active &&
memcmp(uuid, con->domains[i].uuid, 16) == 0) { memcmp(uuid, con->domains[i].uuid, VIR_UUID_BUFLEN) == 0) {
idx = i; idx = i;
break; break;
} }
......
...@@ -1030,7 +1030,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd) ...@@ -1030,7 +1030,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
virDomainPtr dom; virDomainPtr dom;
int ret = TRUE; int ret = TRUE;
unsigned int id; unsigned int id;
char *str, uuid[37]; char *str, uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
...@@ -1535,7 +1535,7 @@ static int ...@@ -1535,7 +1535,7 @@ static int
cmdDomuuid(vshControl * ctl, vshCmd * cmd) cmdDomuuid(vshControl * ctl, vshCmd * cmd)
{ {
virDomainPtr dom; virDomainPtr dom;
char uuid[37]; char uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
...@@ -1943,7 +1943,7 @@ vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname, ...@@ -1943,7 +1943,7 @@ vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname,
} }
} }
/* try it by UUID */ /* try it by UUID */
if (dom==NULL && (flag & VSH_DOMBYUUID) && strlen(n)==36) { if (dom==NULL && (flag & VSH_DOMBYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, 5, "%s: <%s> tring as domain UUID\n", vshDebug(ctl, 5, "%s: <%s> tring as domain UUID\n",
cmd->def->name, optname); cmd->def->name, optname);
dom = virDomainLookupByUUIDString(ctl->conn, n); dom = virDomainLookupByUUIDString(ctl->conn, n);
......
...@@ -1100,7 +1100,7 @@ xenDaemonDomainLookupByName_ids(virConnectPtr xend, const char *domname, ...@@ -1100,7 +1100,7 @@ xenDaemonDomainLookupByName_ids(virConnectPtr xend, const char *domname,
int ret = -1; int ret = -1;
if (uuid != NULL) if (uuid != NULL)
memset(uuid, 0, 16); memset(uuid, 0, VIR_UUID_BUFLEN);
root = sexpr_get(xend, "/xend/domain/%s?detail=1", domname); root = sexpr_get(xend, "/xend/domain/%s?detail=1", domname);
if (root == NULL) if (root == NULL)
goto error; goto error;
...@@ -1152,7 +1152,7 @@ xenDaemonDomainLookupByID(virConnectPtr xend, ...@@ -1152,7 +1152,7 @@ xenDaemonDomainLookupByID(virConnectPtr xend,
char *dst_uuid; char *dst_uuid;
struct sexpr *root; struct sexpr *root;
memset(uuid, 0, 16); memset(uuid, 0, VIR_UUID_BUFLEN);
root = sexpr_get(xend, "/xend/domain/%d?detail=1", id); root = sexpr_get(xend, "/xend/domain/%d?detail=1", id);
if (root == NULL) if (root == NULL)
...@@ -1939,7 +1939,7 @@ sexpr_to_domain(virConnectPtr conn, struct sexpr *root) ...@@ -1939,7 +1939,7 @@ sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
{ {
virDomainPtr ret = NULL; virDomainPtr ret = NULL;
char *dst_uuid = NULL; char *dst_uuid = NULL;
char uuid[16]; char uuid[VIR_UUID_BUFLEN];
const char *name; const char *name;
const char *tmp; const char *tmp;
...@@ -2728,7 +2728,7 @@ error: ...@@ -2728,7 +2728,7 @@ error:
static virDomainPtr static virDomainPtr
xenDaemonLookupByID(virConnectPtr conn, int id) { xenDaemonLookupByID(virConnectPtr conn, int id) {
char *name = NULL; char *name = NULL;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
virDomainPtr ret; virDomainPtr ret;
if (xenDaemonDomainLookupByID(conn, id, &name, uuid) < 0) { if (xenDaemonDomainLookupByID(conn, id, &name, uuid) < 0) {
...@@ -2762,7 +2762,7 @@ xenDaemonLookupByID(virConnectPtr conn, int id) { ...@@ -2762,7 +2762,7 @@ xenDaemonLookupByID(virConnectPtr conn, int id) {
int int
xenDaemonDomainSetVcpus(virDomainPtr domain, unsigned int vcpus) xenDaemonDomainSetVcpus(virDomainPtr domain, unsigned int vcpus)
{ {
char buf[16]; char buf[VIR_UUID_BUFLEN];
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
|| (vcpus < 1)) { || (vcpus < 1)) {
...@@ -2793,7 +2793,7 @@ int ...@@ -2793,7 +2793,7 @@ int
xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu, xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
unsigned char *cpumap, int maplen) unsigned char *cpumap, int maplen)
{ {
char buf[16], mapstr[sizeof(cpumap_t) * 64] = "["; char buf[VIR_UUID_BUFLEN], mapstr[sizeof(cpumap_t) * 64] = "[";
int i, j; int i, j;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
...@@ -2929,7 +2929,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -2929,7 +2929,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
char *name = NULL; char *name = NULL;
char **names; char **names;
char **tmp; char **tmp;
unsigned char ident[16]; unsigned char ident[VIR_UUID_BUFLEN];
int id = -1; int id = -1;
names = xenDaemonListDomainsOld(conn); names = xenDaemonListDomainsOld(conn);
...@@ -2942,7 +2942,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -2942,7 +2942,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
while (*tmp != NULL) { while (*tmp != NULL) {
id = xenDaemonDomainLookupByName_ids(conn, *tmp, &ident[0]); id = xenDaemonDomainLookupByName_ids(conn, *tmp, &ident[0]);
if (id >= 0) { if (id >= 0) {
if (!memcmp(uuid, ident, 16)) { if (!memcmp(uuid, ident, VIR_UUID_BUFLEN)) {
name = strdup(*tmp); name = strdup(*tmp);
break; break;
} }
......
...@@ -209,7 +209,7 @@ static int xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char * ...@@ -209,7 +209,7 @@ static int xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *
have one in its config */ have one in its config */
static void xenXMConfigGenerateUUID(unsigned char *uuid) { static void xenXMConfigGenerateUUID(unsigned char *uuid) {
int i; int i;
for (i = 0 ; i < 16 ; i++) { for (i = 0 ; i < VIR_UUID_BUFLEN ; i++) {
uuid[i] = (unsigned char)(1 + (int) (256.0 * (rand() / (RAND_MAX + 1.0)))); uuid[i] = (unsigned char)(1 + (int) (256.0 * (rand() / (RAND_MAX + 1.0))));
} }
} }
...@@ -217,7 +217,7 @@ static void xenXMConfigGenerateUUID(unsigned char *uuid) { ...@@ -217,7 +217,7 @@ static void xenXMConfigGenerateUUID(unsigned char *uuid) {
/* Ensure that a config object has a valid UUID in it, /* Ensure that a config object has a valid UUID in it,
if it doesn't then (re-)generate one */ if it doesn't then (re-)generate one */
static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) { static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
const char *name; const char *name;
/* Had better have a name...*/ /* Had better have a name...*/
...@@ -242,7 +242,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) { ...@@ -242,7 +242,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
/* If there is no uuid...*/ /* If there is no uuid...*/
if (xenXMConfigGetUUID(conf, "uuid", uuid) < 0) { if (xenXMConfigGetUUID(conf, "uuid", uuid) < 0) {
virConfValuePtr value; virConfValuePtr value;
char uuidstr[37]; char uuidstr[VIR_UUID_STRING_BUFLEN];
value = malloc(sizeof(virConfValue)); value = malloc(sizeof(virConfValue));
if (!value) { if (!value) {
...@@ -251,13 +251,13 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) { ...@@ -251,13 +251,13 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
/* ... then generate one */ /* ... then generate one */
xenXMConfigGenerateUUID(uuid); xenXMConfigGenerateUUID(uuid);
snprintf(uuidstr, 37, snprintf(uuidstr, VIR_UUID_STRING_BUFLEN,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n", "%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[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5], uuid[6], uuid[7], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[8], uuid[9], uuid[10], uuid[11],
uuid[12], uuid[13], uuid[14], uuid[15]); uuid[12], uuid[13], uuid[14], uuid[15]);
uuidstr[36] = '\0'; uuidstr[VIR_UUID_STRING_BUFLEN-1] = '\0';
value->type = VIR_CONF_STRING; value->type = VIR_CONF_STRING;
value->str = strdup(uuidstr); value->str = strdup(uuidstr);
...@@ -565,7 +565,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) { ...@@ -565,7 +565,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
virBufferPtr buf; virBufferPtr buf;
char *xml; char *xml;
const char *name; const char *name;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
const char *str; const char *str;
int hvm = 0; int hvm = 0;
long val; long val;
...@@ -1168,7 +1168,7 @@ virDomainPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname) { ...@@ -1168,7 +1168,7 @@ virDomainPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname) {
const char *filename; const char *filename;
xenXMConfCachePtr entry; xenXMConfCachePtr entry;
virDomainPtr ret; virDomainPtr ret;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
if (!VIR_IS_CONNECT(conn)) { if (!VIR_IS_CONNECT(conn)) {
xenXMError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__); xenXMError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL); return (NULL);
...@@ -1209,7 +1209,7 @@ virDomainPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname) { ...@@ -1209,7 +1209,7 @@ virDomainPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname) {
* Hash table iterator to search for a domain based on UUID * Hash table iterator to search for a domain based on UUID
*/ */
static int xenXMDomainSearchForUUID(const void *payload, const char *name ATTRIBUTE_UNUSED, const void *data) { static int xenXMDomainSearchForUUID(const void *payload, const char *name ATTRIBUTE_UNUSED, const void *data) {
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
const unsigned char *wantuuid = (const unsigned char *)data; const unsigned char *wantuuid = (const unsigned char *)data;
const xenXMConfCachePtr entry = (const xenXMConfCachePtr)payload; const xenXMConfCachePtr entry = (const xenXMConfCachePtr)payload;
...@@ -1217,7 +1217,7 @@ static int xenXMDomainSearchForUUID(const void *payload, const char *name ATTRIB ...@@ -1217,7 +1217,7 @@ static int xenXMDomainSearchForUUID(const void *payload, const char *name ATTRIB
return (0); return (0);
} }
if (!memcmp(uuid, wantuuid, 16)) if (!memcmp(uuid, wantuuid, VIR_UUID_BUFLEN))
return (1); return (1);
return (0); return (0);
...@@ -1271,7 +1271,7 @@ int xenXMDomainCreate(virDomainPtr domain) { ...@@ -1271,7 +1271,7 @@ int xenXMDomainCreate(virDomainPtr domain) {
char *xml; char *xml;
char *sexpr; char *sexpr;
int ret; int ret;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
xenXMError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG, xenXMError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
...@@ -2046,7 +2046,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) { ...@@ -2046,7 +2046,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) { virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
virDomainPtr ret; virDomainPtr ret;
char filename[PATH_MAX]; char filename[PATH_MAX];
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
virConfPtr conf = NULL; virConfPtr conf = NULL;
xenXMConfCachePtr entry = NULL; xenXMConfCachePtr entry = NULL;
virConfValuePtr value; virConfValuePtr value;
......
...@@ -525,7 +525,7 @@ char * ...@@ -525,7 +525,7 @@ char *
virDomainGetXMLDesc(virDomainPtr domain, int flags) virDomainGetXMLDesc(virDomainPtr domain, int flags)
{ {
char *ret = NULL; char *ret = NULL;
unsigned char uuid[16]; unsigned char uuid[VIR_UUID_BUFLEN];
virBuffer buf; virBuffer buf;
virDomainInfo info; virDomainInfo info;
...@@ -1533,7 +1533,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion) ...@@ -1533,7 +1533,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
unsigned char *virParseUUID(char **ptr, const char *uuid) { unsigned char *virParseUUID(char **ptr, const char *uuid) {
int rawuuid[16]; int rawuuid[VIR_UUID_BUFLEN];
const char *cur; const char *cur;
unsigned char *dst_uuid = NULL; unsigned char *dst_uuid = NULL;
int i; int i;
...@@ -1546,7 +1546,7 @@ unsigned char *virParseUUID(char **ptr, const char *uuid) { ...@@ -1546,7 +1546,7 @@ unsigned char *virParseUUID(char **ptr, const char *uuid) {
* pairs as long as there is 32 of them in the end. * pairs as long as there is 32 of them in the end.
*/ */
cur = uuid; cur = uuid;
for (i = 0;i < 16;) { for (i = 0;i < VIR_UUID_BUFLEN;) {
rawuuid[i] = 0; rawuuid[i] = 0;
if (*cur == 0) if (*cur == 0)
goto error; goto error;
...@@ -1581,7 +1581,7 @@ unsigned char *virParseUUID(char **ptr, const char *uuid) { ...@@ -1581,7 +1581,7 @@ unsigned char *virParseUUID(char **ptr, const char *uuid) {
dst_uuid = (unsigned char *) *ptr; dst_uuid = (unsigned char *) *ptr;
*ptr += 16; *ptr += 16;
for (i = 0; i < 16; i++) for (i = 0; i < VIR_UUID_BUFLEN; i++)
dst_uuid[i] = rawuuid[i] & 0xFF; dst_uuid[i] = rawuuid[i] & 0xFF;
error: error:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册