提交 2e5d3596 编写于 作者: D Daniel Veillard

* src/xml.c src/xs_internal.c src/xs_internal.h: cleanup for the

  dynamic device code to isolate as a separate function
  xenStoreDomainGetNetworkID() the access to the XenStore
Daniel
上级 35adcfa6
Mon Nov 20 16:51:43 CET 2006 Daniel Veillard <veillard@redhat.com>
* src/xml.c src/xs_internal.c src/xs_internal.h: cleanup for the
dynamic device code to isolate as a separate function
xenStoreDomainGetNetworkID() the access to the XenStore
Thu Nov 16 19:36:12 EST 2006 Daniel Berrange <berrange@redhat.com>
* src/xm_internal.c: Add support for device_model parameter to
......
......@@ -23,6 +23,7 @@
#include "hash.h"
#include "sexpr.h"
#include "xml.h"
#include "xs_internal.h" /* for xenStoreDomainGetNetworkID */
static void
virXMLError(virErrorNumber error, const char *info, int value)
......@@ -1561,9 +1562,8 @@ virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref)
xmlDocPtr xml = NULL;
xmlNodePtr node, cur;
xmlChar *attr = NULL;
char dir[80], path[128], **list = NULL, *mac = NULL;
char *xref;
int ret = 0;
unsigned int num, i, len;
xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
......@@ -1594,30 +1594,14 @@ virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref)
if (attr == NULL)
goto error;
/*
* TODO: this part need to be isolated as a high level routine in
* xs_internal.[ch]
*/
sprintf(dir, "/local/domain/0/backend/vif/%d", domain->handle);
list = xs_directory(domain->conn->xshandle, 0, dir, &num);
if (list == NULL)
goto error;
for (i = 0; i < num; i++) {
sprintf(path, "%s/%s/%s", dir, list[i], "mac");
mac = xs_read(domain->conn->xshandle, 0, path, &len);
if (mac == NULL)
goto error;
if ((strlen((char*)attr) != len) || memcmp(attr, mac, len)) {
free(mac);
mac = NULL;
continue;
}
strcpy(ref, list[i]);
goto cleanup;
}
/*
* end of TODO block
*/
xref = xenStoreDomainGetNetworkID(domain->conn, domain->handle,
(char *) attr);
if (xref != NULL) {
strcpy(ref, xref);
free(xref);
goto cleanup;
}
goto error;
}
}
......@@ -1628,10 +1612,6 @@ cleanup:
xmlFreeDoc(xml);
if (attr != NULL)
xmlFree(attr);
if (list != NULL)
free(list);
if (mac != NULL)
free(mac);
return ret;
}
#endif /* !PROXY */
......
......@@ -784,3 +784,52 @@ xenStoreDomainGetOSTypeID(virConnectPtr conn, int id) {
return (str);
}
#endif /* PROXY */
/*
* xenStoreDomainGetNetworkID:
* @conn: pointer to the connection.
* @id: the domain id
* @mac: the mac address
*
* Get the reference (i.e. the string number) for the device on that domain
* which uses the given mac address
*
* Returns the new string or NULL in case of error, the string must be
* freed by the caller.
*/
char *
xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) {
char dir[80], path[128], **list = NULL, *val = NULL;
unsigned int maclen, len, i, num;
char *ret = NULL;
if (id < 0)
return(NULL);
if (conn->xshandle == NULL)
return (NULL);
if (mac == NULL)
return (NULL);
maclen = strlen(mac);
if (maclen <= 0)
return (NULL);
sprintf(dir, "/local/domain/0/backend/vif/%d", id);
list = xs_directory(conn->xshandle, 0, dir, &num);
if (list == NULL)
return(NULL);
for (i = 0; i < num; i++) {
sprintf(path, "%s/%s/%s", dir, list[i], "mac");
val = xs_read(conn->xshandle, 0, path, &len);
if (val == NULL)
break;
if ((maclen != len) || memcmp(val, mac, len)) {
free(val);
} else {
ret = list[i];
free(val);
break;
}
}
free(list);
return(ret);
}
......@@ -43,6 +43,9 @@ char * xenStoreDomainGetConsolePath(virConnectPtr conn,
int domid);
char * xenStoreDomainGetOSTypeID(virConnectPtr conn,
int id);
char * xenStoreDomainGetNetworkID(virConnectPtr conn,
int id,
const char *mac);
#ifdef __cplusplus
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册