mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
* 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
This commit is contained in:
parent
35adcfa621
commit
2e5d35966e
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Thu Nov 16 19:36:12 EST 2006 Daniel Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/xm_internal.c: Add support for device_model parameter to
|
* src/xm_internal.c: Add support for device_model parameter to
|
||||||
|
40
src/xml.c
40
src/xml.c
@ -23,6 +23,7 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "sexpr.h"
|
#include "sexpr.h"
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
|
#include "xs_internal.h" /* for xenStoreDomainGetNetworkID */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virXMLError(virErrorNumber error, const char *info, int value)
|
virXMLError(virErrorNumber error, const char *info, int value)
|
||||||
@ -1561,9 +1562,8 @@ virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref)
|
|||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlNodePtr node, cur;
|
xmlNodePtr node, cur;
|
||||||
xmlChar *attr = NULL;
|
xmlChar *attr = NULL;
|
||||||
char dir[80], path[128], **list = NULL, *mac = NULL;
|
char *xref;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned int num, i, len;
|
|
||||||
|
|
||||||
xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
|
xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
|
||||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
@ -1594,30 +1594,14 @@ virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref)
|
|||||||
if (attr == NULL)
|
if (attr == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/*
|
xref = xenStoreDomainGetNetworkID(domain->conn, domain->handle,
|
||||||
* TODO: this part need to be isolated as a high level routine in
|
(char *) attr);
|
||||||
* xs_internal.[ch]
|
if (xref != NULL) {
|
||||||
*/
|
strcpy(ref, xref);
|
||||||
sprintf(dir, "/local/domain/0/backend/vif/%d", domain->handle);
|
free(xref);
|
||||||
list = xs_directory(domain->conn->xshandle, 0, dir, &num);
|
goto cleanup;
|
||||||
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
|
|
||||||
*/
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1628,10 +1612,6 @@ cleanup:
|
|||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
if (attr != NULL)
|
if (attr != NULL)
|
||||||
xmlFree(attr);
|
xmlFree(attr);
|
||||||
if (list != NULL)
|
|
||||||
free(list);
|
|
||||||
if (mac != NULL)
|
|
||||||
free(mac);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif /* !PROXY */
|
#endif /* !PROXY */
|
||||||
|
@ -784,3 +784,52 @@ xenStoreDomainGetOSTypeID(virConnectPtr conn, int id) {
|
|||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
#endif /* PROXY */
|
#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);
|
int domid);
|
||||||
char * xenStoreDomainGetOSTypeID(virConnectPtr conn,
|
char * xenStoreDomainGetOSTypeID(virConnectPtr conn,
|
||||||
int id);
|
int id);
|
||||||
|
char * xenStoreDomainGetNetworkID(virConnectPtr conn,
|
||||||
|
int id,
|
||||||
|
const char *mac);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user