+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>
Issues pointed out by Karel Zak <kzak@redhat.com>
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 */
/**
break;
case VIR_PROXY_LOOKUP_ID: {
char *name = NULL;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
int len;
if (req->len != sizeof(virProxyPacket))
len = 1000;
name[1000] = 0;
}
- req->len += 16 + len + 1;
- memcpy(&request.extra.str[0], uuid, 16);
- strcpy(&request.extra.str[16], name);
+ req->len += VIR_UUID_BUFLEN + len + 1;
+ memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN);
+ strcpy(&request.extra.str[VIR_UUID_BUFLEN], name);
}
if (name)
free(name);
char **tmp;
int ident, len;
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;
/*
if (names != NULL) {
while (*tmp != NULL) {
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;
break;
}
}
case VIR_PROXY_LOOKUP_NAME: {
int ident;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
if (req->len > sizeof(virProxyPacket) + 1000)
goto comm_error;
req->data.arg = -1;
req->len = sizeof(virProxyPacket);
} else {
- req->len = sizeof(virProxyPacket) + 16;
- memcpy(&request.extra.str[0], uuid, 16);
+ req->len = sizeof(virProxyPacket) + VIR_UUID_BUFLEN;
+ memcpy(&request.extra.str[0], uuid, VIR_UUID_BUFLEN);
req->data.arg = ident;
}
break;
PyObject *
libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
virDomainPtr domain;
PyObject *pyobj_domain;
int c_retval;
Py_INCREF(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(NULL);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
- if ((uuid == NULL) || (len != 16)) {
+ if ((uuid == NULL) || (len != VIR_UUID_BUFLEN)) {
Py_INCREF(Py_None);
return(Py_None);
}
ret->conn = conn;
ret->id = -1;
if (uuid != NULL)
- memcpy(&(ret->uuid[0]), uuid, 16);
+ memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->domains, name, ret) < 0) {
virHashError(conn, VIR_ERR_INTERNAL_ERROR,
* Internal structure associated to a domain
*/
struct _virDomain {
- unsigned int magic; /* specific value to check */
- int uses; /* reference count */
- virConnectPtr conn; /* pointer back to the connection */
- char *name; /* the domain external name */
- char *path; /* the domain internal path */
- int id; /* the domain ID */
- int flags; /* extra flags */
- unsigned char uuid[16]; /* the domain unique identifier */
- char *xml; /* the XML description for defined domains */
+ unsigned int magic; /* specific value to check */
+ int uses; /* reference count */
+ virConnectPtr conn; /* pointer back to the connection */
+ char *name; /* the domain external name */
+ char *path; /* the domain internal path */
+ int id; /* the domain ID */
+ int flags; /* extra flags */
+ unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */
+ char *xml; /* the XML description for defined domains */
};
/*
virDomainPtr
virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
{
- int raw[16], i;
- unsigned char uuid[16];
+ int raw[VIR_UUID_BUFLEN], i;
+ unsigned char uuid[VIR_UUID_BUFLEN];
int ret;
if (!VIR_IS_CONNECT(conn)) {
raw + 8, raw + 9, raw + 10, raw + 11,
raw + 12, raw + 13, raw + 14, raw + 15);
- if (ret!=16) {
+ if (ret!=VIR_UUID_BUFLEN) {
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (NULL);
}
- for (i = 0; i < 16; i++)
+ for (i = 0; i < VIR_UUID_BUFLEN; i++)
uuid[i] = raw[i] & 0xFF;
return virDomainLookupByUUID(conn, &uuid[0]);
/**
* virDomainGetUUID:
* @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
*
}
if (domain->id == 0) {
- memset(uuid, 0, 16);
+ memset(uuid, 0, VIR_UUID_BUFLEN);
} else {
if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) &&
(domain->uuid[2] == 0) && (domain->uuid[3] == 0) &&
(domain->uuid[14] == 0) && (domain->uuid[15] == 0))
xenDaemonDomainLookupByName_ids(domain->conn, domain->name,
&domain->uuid[0]);
- memcpy(uuid, &domain->uuid[0], 16);
+ memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
}
return (0);
}
/**
* virDomainGetUUIDString:
* @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
* UUID see RFC4122.
int
virDomainGetUUIDString(virDomainPtr domain, char *buf)
{
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
if (!VIR_IS_DOMAIN(domain)) {
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
if (virDomainGetUUID(domain, &uuid[0]))
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",
uuid[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5], uuid[6], uuid[7],
{
virProxyPacket req;
virProxyFullPacket ans;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
const char *name;
int ret;
virDomainPtr res;
if (ans.data.arg == -1) {
return(NULL);
}
- memcpy(uuid, &ans.extra.str[0], 16);
- name = &ans.extra.str[16];
+ memcpy(uuid, &ans.extra.str[0], VIR_UUID_BUFLEN);
+ name = &ans.extra.str[VIR_UUID_BUFLEN];
res = virGetDomain(conn, name, uuid);
if (res == NULL)
}
memset(&req, 0, sizeof(virProxyPacket));
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);
if (ret < 0) {
xenProxyClose(conn);
int active;
int id;
char name[20];
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
virDomainKernel kernel;
virDomainInfo info;
unsigned int maxVCPUs;
xmlXPathContextPtr ctxt = NULL;
xmlXPathObjectPtr obj = NULL;
char *name = NULL;
- unsigned char rawuuid[16];
+ unsigned char rawuuid[VIR_UUID_BUFLEN];
char *dst_uuid;
testCon *con;
struct timeval tv;
if (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.memory = memory;
con->domains[handle].info.state = domid < 0 ? VIR_DOMAIN_SHUTOFF : VIR_DOMAIN_RUNNING;
node->connections[connid].domains[0].onCrash = VIR_DOMAIN_RESTART;
node->connections[connid].domains[0].onPoweroff = VIR_DOMAIN_DESTROY;
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].info.maxMem = 8192 * 1024;
int i, idx = -1;
for (i = 0 ; i < MAX_DOMAINS ; i++) {
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;
break;
}
virDomainPtr dom;
int ret = TRUE;
unsigned int id;
- char *str, uuid[37];
+ char *str, uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
cmdDomuuid(vshControl * ctl, vshCmd * cmd)
{
virDomainPtr dom;
- char uuid[37];
+ char uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
}
}
/* 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",
cmd->def->name, optname);
dom = virDomainLookupByUUIDString(ctl->conn, n);
int ret = -1;
if (uuid != NULL)
- memset(uuid, 0, 16);
+ memset(uuid, 0, VIR_UUID_BUFLEN);
root = sexpr_get(xend, "/xend/domain/%s?detail=1", domname);
if (root == NULL)
goto error;
char *dst_uuid;
struct sexpr *root;
- memset(uuid, 0, 16);
+ memset(uuid, 0, VIR_UUID_BUFLEN);
root = sexpr_get(xend, "/xend/domain/%d?detail=1", id);
if (root == NULL)
{
virDomainPtr ret = NULL;
char *dst_uuid = NULL;
- char uuid[16];
+ char uuid[VIR_UUID_BUFLEN];
const char *name;
const char *tmp;
static virDomainPtr
xenDaemonLookupByID(virConnectPtr conn, int id) {
char *name = NULL;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
virDomainPtr ret;
if (xenDaemonDomainLookupByID(conn, id, &name, uuid) < 0) {
int
xenDaemonDomainSetVcpus(virDomainPtr domain, unsigned int vcpus)
{
- char buf[16];
+ char buf[VIR_UUID_BUFLEN];
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
|| (vcpus < 1)) {
xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
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;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
char *name = NULL;
char **names;
char **tmp;
- unsigned char ident[16];
+ unsigned char ident[VIR_UUID_BUFLEN];
int id = -1;
names = xenDaemonListDomainsOld(conn);
while (*tmp != NULL) {
id = xenDaemonDomainLookupByName_ids(conn, *tmp, &ident[0]);
if (id >= 0) {
- if (!memcmp(uuid, ident, 16)) {
+ if (!memcmp(uuid, ident, VIR_UUID_BUFLEN)) {
name = strdup(*tmp);
break;
}
have one in its config */
static void xenXMConfigGenerateUUID(unsigned char *uuid) {
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))));
}
}
/* Ensure that a config object has a valid UUID in it,
if it doesn't then (re-)generate one */
static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
const char *name;
/* Had better have a name...*/
/* If there is no uuid...*/
if (xenXMConfigGetUUID(conf, "uuid", uuid) < 0) {
virConfValuePtr value;
- char uuidstr[37];
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
value = malloc(sizeof(virConfValue));
if (!value) {
/* ... then generate one */
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",
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[36] = '\0';
+ uuidstr[VIR_UUID_STRING_BUFLEN-1] = '\0';
value->type = VIR_CONF_STRING;
value->str = strdup(uuidstr);
virBufferPtr buf;
char *xml;
const char *name;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
const char *str;
int hvm = 0;
long val;
const char *filename;
xenXMConfCachePtr entry;
virDomainPtr ret;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
if (!VIR_IS_CONNECT(conn)) {
xenXMError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (NULL);
* 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) {
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
const unsigned char *wantuuid = (const unsigned char *)data;
const xenXMConfCachePtr entry = (const xenXMConfCachePtr)payload;
return (0);
}
- if (!memcmp(uuid, wantuuid, 16))
+ if (!memcmp(uuid, wantuuid, VIR_UUID_BUFLEN))
return (1);
return (0);
char *xml;
char *sexpr;
int ret;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
xenXMError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
virDomainPtr ret;
char filename[PATH_MAX];
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
virConfPtr conf = NULL;
xenXMConfCachePtr entry = NULL;
virConfValuePtr value;
virDomainGetXMLDesc(virDomainPtr domain, int flags)
{
char *ret = NULL;
- unsigned char uuid[16];
+ unsigned char uuid[VIR_UUID_BUFLEN];
virBuffer buf;
virDomainInfo info;
unsigned char *virParseUUID(char **ptr, const char *uuid) {
- int rawuuid[16];
+ int rawuuid[VIR_UUID_BUFLEN];
const char *cur;
unsigned char *dst_uuid = NULL;
int i;
* pairs as long as there is 32 of them in the end.
*/
cur = uuid;
- for (i = 0;i < 16;) {
+ for (i = 0;i < VIR_UUID_BUFLEN;) {
rawuuid[i] = 0;
if (*cur == 0)
goto error;
dst_uuid = (unsigned char *) *ptr;
*ptr += 16;
- for (i = 0; i < 16; i++)
+ for (i = 0; i < VIR_UUID_BUFLEN; i++)
dst_uuid[i] = rawuuid[i] & 0xFF;
error: