2005-12-13 16:22:05 +00:00
|
|
|
/*
|
|
|
|
* xml.c: XML based interfaces for the libvir library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* See COPYING.LIB for the License of this software
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2006-06-26 15:02:18 +00:00
|
|
|
#include "libvirt/libvirt.h"
|
2005-12-13 16:22:05 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
2007-03-15 07:43:16 +00:00
|
|
|
#ifdef WITH_XEN
|
2005-12-13 16:22:05 +00:00
|
|
|
#include <xs.h>
|
2007-03-15 07:43:16 +00:00
|
|
|
#endif
|
2006-02-16 22:50:52 +00:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/xpath.h>
|
2006-08-10 14:26:35 +00:00
|
|
|
#include <math.h> /* for isnan() */
|
2005-12-13 16:22:05 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "hash.h"
|
2006-02-20 17:22:16 +00:00
|
|
|
#include "sexpr.h"
|
2006-02-16 22:50:52 +00:00
|
|
|
#include "xml.h"
|
2006-11-20 16:42:16 +00:00
|
|
|
#include "xs_internal.h" /* for xenStoreDomainGetNetworkID */
|
2005-12-13 16:22:05 +00:00
|
|
|
|
2006-02-27 22:32:54 +00:00
|
|
|
static void
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(virConnectPtr conn, virErrorNumber error, const char *info, int value)
|
2006-03-15 12:13:25 +00:00
|
|
|
{
|
2006-02-27 22:32:54 +00:00
|
|
|
const char *errmsg;
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-02-27 22:32:54 +00:00
|
|
|
if (error == VIR_ERR_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
errmsg = __virErrorMsg(error, info);
|
2007-02-14 16:16:13 +00:00
|
|
|
__virRaiseError(conn, NULL, NULL, VIR_FROM_XML, error, VIR_ERR_ERROR,
|
2006-03-15 12:13:25 +00:00
|
|
|
errmsg, info, NULL, value, 0, errmsg, info, value);
|
2006-02-27 22:32:54 +00:00
|
|
|
}
|
|
|
|
|
2005-12-13 16:22:05 +00:00
|
|
|
/**
|
|
|
|
* virBufferGrow:
|
|
|
|
* @buf: the buffer
|
2007-03-21 15:24:56 +00:00
|
|
|
* @len: the minimum free size to allocate on top of existing used space
|
2005-12-13 16:22:05 +00:00
|
|
|
*
|
2007-03-21 15:24:56 +00:00
|
|
|
* Grow the available space of an XML buffer to at least @len bytes.
|
2005-12-13 16:22:05 +00:00
|
|
|
*
|
|
|
|
* Returns the new available space or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int
|
2006-03-15 12:13:25 +00:00
|
|
|
virBufferGrow(virBufferPtr buf, unsigned int len)
|
|
|
|
{
|
2005-12-13 16:22:05 +00:00
|
|
|
int size;
|
|
|
|
char *newbuf;
|
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (-1);
|
|
|
|
if (len + buf->use < buf->size)
|
|
|
|
return (0);
|
2005-12-13 16:22:05 +00:00
|
|
|
|
|
|
|
size = buf->use + len + 1000;
|
|
|
|
|
|
|
|
newbuf = (char *) realloc(buf->content, size);
|
|
|
|
if (newbuf == NULL) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(NULL, VIR_ERR_NO_MEMORY, _("growing buffer"), size);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
|
|
|
buf->content = newbuf;
|
|
|
|
buf->size = size;
|
2006-03-15 12:13:25 +00:00
|
|
|
return (buf->size - buf->use);
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virBufferAdd:
|
|
|
|
* @buf: the buffer to dump
|
|
|
|
* @str: the string
|
|
|
|
* @len: the number of bytes to add
|
|
|
|
*
|
|
|
|
* Add a string range to an XML buffer. if len == -1, the length of
|
|
|
|
* str is recomputed to the full string.
|
|
|
|
*
|
|
|
|
* Returns 0 successful, -1 in case of internal or API error.
|
|
|
|
*/
|
2006-02-20 17:22:16 +00:00
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virBufferAdd(virBufferPtr buf, const char *str, int len)
|
|
|
|
{
|
2005-12-13 16:22:05 +00:00
|
|
|
unsigned int needSize;
|
|
|
|
|
|
|
|
if ((str == NULL) || (buf == NULL)) {
|
2006-03-15 12:13:25 +00:00
|
|
|
return -1;
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
2006-03-15 12:13:25 +00:00
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
2005-12-13 16:22:05 +00:00
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
len = strlen(str);
|
|
|
|
|
|
|
|
needSize = buf->use + len + 2;
|
2006-03-15 12:13:25 +00:00
|
|
|
if (needSize > buf->size) {
|
2007-03-21 15:24:56 +00:00
|
|
|
if (!virBufferGrow(buf, needSize - buf->use)) {
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-10 12:15:49 +00:00
|
|
|
/* XXX: memmove() is 2x slower than memcpy(), do we really need it? */
|
2005-12-13 16:22:05 +00:00
|
|
|
memmove(&buf->content[buf->use], str, len);
|
|
|
|
buf->use += len;
|
|
|
|
buf->content[buf->use] = 0;
|
2006-03-15 12:13:25 +00:00
|
|
|
return (0);
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 12:15:49 +00:00
|
|
|
virBufferPtr
|
|
|
|
virBufferNew(unsigned int size)
|
|
|
|
{
|
|
|
|
virBufferPtr buf;
|
|
|
|
|
|
|
|
if (!(buf = malloc(sizeof(*buf)))) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(NULL, VIR_ERR_NO_MEMORY, _("allocate new buffer"), sizeof(*buf));
|
2006-05-10 12:15:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (size && (buf->content = malloc(size))==NULL) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(NULL, VIR_ERR_NO_MEMORY, _("allocate buffer content"), size);
|
2006-05-10 12:15:49 +00:00
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
buf->size = size;
|
|
|
|
buf->use = 0;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
2007-02-07 13:50:18 +00:00
|
|
|
|
2006-05-09 15:35:46 +00:00
|
|
|
void
|
|
|
|
virBufferFree(virBufferPtr buf)
|
|
|
|
{
|
|
|
|
if (buf) {
|
2006-05-10 12:15:49 +00:00
|
|
|
if (buf->content)
|
2007-02-07 13:50:18 +00:00
|
|
|
free(buf->content);
|
|
|
|
free(buf);
|
2006-05-09 15:35:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-13 16:22:05 +00:00
|
|
|
/**
|
|
|
|
* virBufferVSprintf:
|
|
|
|
* @buf: the buffer to dump
|
|
|
|
* @format: the format
|
|
|
|
* @argptr: the variable list of arguments
|
|
|
|
*
|
|
|
|
* Do a formatted print to an XML buffer.
|
|
|
|
*
|
|
|
|
* Returns 0 successful, -1 in case of internal or API error.
|
|
|
|
*/
|
2006-02-20 17:22:16 +00:00
|
|
|
int
|
2006-03-15 12:13:25 +00:00
|
|
|
virBufferVSprintf(virBufferPtr buf, const char *format, ...)
|
|
|
|
{
|
2005-12-13 16:22:05 +00:00
|
|
|
int size, count;
|
|
|
|
va_list locarg, argptr;
|
|
|
|
|
|
|
|
if ((format == NULL) || (buf == NULL)) {
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
|
|
|
size = buf->size - buf->use - 1;
|
|
|
|
va_start(argptr, format);
|
|
|
|
va_copy(locarg, argptr);
|
|
|
|
while (((count = vsnprintf(&buf->content[buf->use], size, format,
|
|
|
|
locarg)) < 0) || (count >= size - 1)) {
|
2006-03-15 12:13:25 +00:00
|
|
|
buf->content[buf->use] = 0;
|
|
|
|
va_end(locarg);
|
|
|
|
if (virBufferGrow(buf, 1000) < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
size = buf->size - buf->use - 1;
|
|
|
|
va_copy(locarg, argptr);
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
|
|
|
va_end(locarg);
|
|
|
|
buf->use += count;
|
|
|
|
buf->content[buf->use] = 0;
|
2006-03-15 12:13:25 +00:00
|
|
|
return (0);
|
2005-12-13 16:22:05 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 12:15:49 +00:00
|
|
|
/**
|
|
|
|
* virBufferStrcat:
|
|
|
|
* @buf: the buffer to dump
|
|
|
|
* @argptr: the variable list of strings, the last argument must be NULL
|
|
|
|
*
|
|
|
|
* Concatenate strings to an XML buffer.
|
|
|
|
*
|
|
|
|
* Returns 0 successful, -1 in case of internal or API error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virBufferStrcat(virBufferPtr buf, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *str;
|
2007-02-07 13:50:18 +00:00
|
|
|
|
2006-05-10 12:15:49 +00:00
|
|
|
va_start(ap, buf);
|
2007-02-07 13:50:18 +00:00
|
|
|
|
2006-05-10 12:15:49 +00:00
|
|
|
while ((str = va_arg(ap, char *)) != NULL) {
|
|
|
|
unsigned int len = strlen(str);
|
|
|
|
unsigned int needSize = buf->use + len + 2;
|
|
|
|
|
|
|
|
if (needSize > buf->size) {
|
2007-03-21 15:24:56 +00:00
|
|
|
if (!virBufferGrow(buf, needSize - buf->use))
|
2007-02-07 13:50:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2006-05-10 12:15:49 +00:00
|
|
|
memcpy(&buf->content[buf->use], str, len);
|
|
|
|
buf->use += len;
|
|
|
|
buf->content[buf->use] = 0;
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-20 17:22:16 +00:00
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
#ifndef PROXY
|
2006-08-26 15:30:44 +00:00
|
|
|
/**
|
2006-12-13 14:08:51 +00:00
|
|
|
* virtDomainParseXMLGraphicsDescImage:
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-08-26 15:30:44 +00:00
|
|
|
* @node: node containing graphics description
|
|
|
|
* @buf: a buffer for the result S-Expr
|
2006-09-12 01:34:26 +00:00
|
|
|
* @xendConfigVersion: xend configuration file format
|
2006-08-26 15:30:44 +00:00
|
|
|
*
|
2007-02-07 13:50:18 +00:00
|
|
|
* Parse the graphics part of the XML description and add it to the S-Expr
|
|
|
|
* in buf. This is a temporary interface as the S-Expr interface will be
|
|
|
|
* replaced by XML-RPC in the future. However the XML format should stay
|
2006-08-26 15:30:44 +00:00
|
|
|
* valid over time.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
2007-02-14 16:16:13 +00:00
|
|
|
static int virDomainParseXMLGraphicsDescImage(virConnectPtr conn ATTRIBUTE_UNUSED, xmlNodePtr node, virBufferPtr buf, int xendConfigVersion)
|
2006-08-26 15:30:44 +00:00
|
|
|
{
|
|
|
|
xmlChar *graphics_type = NULL;
|
|
|
|
|
|
|
|
graphics_type = xmlGetProp(node, BAD_CAST "type");
|
|
|
|
if (graphics_type != NULL) {
|
|
|
|
if (xmlStrEqual(graphics_type, BAD_CAST "sdl")) {
|
|
|
|
virBufferAdd(buf, "(sdl 1)", 7);
|
2006-12-13 14:08:51 +00:00
|
|
|
/* TODO:
|
|
|
|
* Need to understand sdl options
|
|
|
|
*
|
|
|
|
*virBufferAdd(buf, "(display localhost:10.0)", 24);
|
|
|
|
*virBufferAdd(buf, "(xauthority /root/.Xauthority)", 30);
|
|
|
|
*/
|
2006-08-26 15:30:44 +00:00
|
|
|
}
|
2006-09-12 01:34:26 +00:00
|
|
|
else if (xmlStrEqual(graphics_type, BAD_CAST "vnc")) {
|
2006-08-26 15:30:44 +00:00
|
|
|
virBufferAdd(buf, "(vnc 1)", 7);
|
2006-09-12 01:34:26 +00:00
|
|
|
if (xendConfigVersion >= 2) {
|
2006-10-06 15:32:48 +00:00
|
|
|
xmlChar *vncport = xmlGetProp(node, BAD_CAST "port");
|
2006-12-13 14:08:51 +00:00
|
|
|
xmlChar *vnclisten = xmlGetProp(node, BAD_CAST "listen");
|
|
|
|
xmlChar *vncpasswd = xmlGetProp(node, BAD_CAST "passwd");
|
2007-03-06 20:00:17 +00:00
|
|
|
xmlChar *keymap = xmlGetProp(node, BAD_CAST "keymap");
|
2006-09-12 01:34:26 +00:00
|
|
|
if (vncport != NULL) {
|
2006-10-06 15:32:48 +00:00
|
|
|
long port = strtol((const char *)vncport, NULL, 10);
|
2006-09-12 01:34:26 +00:00
|
|
|
if (port == -1)
|
|
|
|
virBufferAdd(buf, "(vncunused 1)", 13);
|
2007-03-08 08:55:56 +00:00
|
|
|
else if (port >= 5900)
|
2007-03-16 15:03:21 +00:00
|
|
|
virBufferVSprintf(buf, "(vncdisplay %ld)", port - 5900);
|
2006-10-06 15:32:48 +00:00
|
|
|
xmlFree(vncport);
|
2006-09-12 01:34:26 +00:00
|
|
|
}
|
2006-12-13 14:08:51 +00:00
|
|
|
if (vnclisten != NULL) {
|
|
|
|
virBufferVSprintf(buf, "(vnclisten %s)", vnclisten);
|
|
|
|
xmlFree(vnclisten);
|
|
|
|
}
|
|
|
|
if (vncpasswd != NULL) {
|
|
|
|
virBufferVSprintf(buf, "(vncpasswd %s)", vncpasswd);
|
|
|
|
xmlFree(vncpasswd);
|
|
|
|
}
|
2007-03-06 20:00:17 +00:00
|
|
|
if (keymap != NULL) {
|
|
|
|
virBufferVSprintf(buf, "(keymap %s)", keymap);
|
|
|
|
xmlFree(keymap);
|
|
|
|
}
|
2006-09-12 01:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-26 15:30:44 +00:00
|
|
|
xmlFree(graphics_type);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-13 14:08:51 +00:00
|
|
|
/**
|
|
|
|
* virtDomainParseXMLGraphicsDescVFB:
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-12-13 14:08:51 +00:00
|
|
|
* @node: node containing graphics description
|
|
|
|
* @buf: a buffer for the result S-Expr
|
|
|
|
*
|
2007-02-07 13:50:18 +00:00
|
|
|
* Parse the graphics part of the XML description and add it to the S-Expr
|
|
|
|
* in buf. This is a temporary interface as the S-Expr interface will be
|
|
|
|
* replaced by XML-RPC in the future. However the XML format should stay
|
2006-12-13 14:08:51 +00:00
|
|
|
* valid over time.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error
|
|
|
|
*/
|
2007-02-14 16:16:13 +00:00
|
|
|
static int virDomainParseXMLGraphicsDescVFB(virConnectPtr conn ATTRIBUTE_UNUSED, xmlNodePtr node, virBufferPtr buf)
|
2006-12-13 14:08:51 +00:00
|
|
|
{
|
|
|
|
xmlChar *graphics_type = NULL;
|
|
|
|
|
|
|
|
graphics_type = xmlGetProp(node, BAD_CAST "type");
|
|
|
|
if (graphics_type != NULL) {
|
|
|
|
virBufferAdd(buf, "(device (vkbd))", 15);
|
|
|
|
virBufferAdd(buf, "(device (vfb ", 13);
|
|
|
|
if (xmlStrEqual(graphics_type, BAD_CAST "sdl")) {
|
|
|
|
virBufferAdd(buf, "(type sdl)", 10);
|
|
|
|
/* TODO:
|
|
|
|
* Need to understand sdl options
|
|
|
|
*
|
|
|
|
*virBufferAdd(buf, "(display localhost:10.0)", 24);
|
|
|
|
*virBufferAdd(buf, "(xauthority /root/.Xauthority)", 30);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual(graphics_type, BAD_CAST "vnc")) {
|
|
|
|
virBufferAdd(buf, "(type vnc)", 10);
|
|
|
|
xmlChar *vncport = xmlGetProp(node, BAD_CAST "port");
|
|
|
|
xmlChar *vnclisten = xmlGetProp(node, BAD_CAST "listen");
|
|
|
|
xmlChar *vncpasswd = xmlGetProp(node, BAD_CAST "passwd");
|
2007-03-06 20:00:17 +00:00
|
|
|
xmlChar *keymap = xmlGetProp(node, BAD_CAST "keymap");
|
2006-12-13 14:08:51 +00:00
|
|
|
if (vncport != NULL) {
|
|
|
|
long port = strtol((const char *)vncport, NULL, 10);
|
|
|
|
if (port == -1)
|
|
|
|
virBufferAdd(buf, "(vncunused 1)", 13);
|
2007-03-08 08:55:56 +00:00
|
|
|
else if (port >= 5900)
|
2007-03-16 15:03:21 +00:00
|
|
|
virBufferVSprintf(buf, "(vncdisplay %ld)", port - 5900);
|
2006-12-13 14:08:51 +00:00
|
|
|
xmlFree(vncport);
|
|
|
|
}
|
|
|
|
if (vnclisten != NULL) {
|
|
|
|
virBufferVSprintf(buf, "(vnclisten %s)", vnclisten);
|
|
|
|
xmlFree(vnclisten);
|
|
|
|
}
|
|
|
|
if (vncpasswd != NULL) {
|
|
|
|
virBufferVSprintf(buf, "(vncpasswd %s)", vncpasswd);
|
|
|
|
xmlFree(vncpasswd);
|
|
|
|
}
|
2007-03-06 20:00:17 +00:00
|
|
|
if (keymap != NULL) {
|
|
|
|
virBufferVSprintf(buf, "(keymap %s)", keymap);
|
|
|
|
xmlFree(keymap);
|
|
|
|
}
|
2006-12-13 14:08:51 +00:00
|
|
|
}
|
|
|
|
virBufferAdd(buf, "))", 2);
|
|
|
|
xmlFree(graphics_type);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
/**
|
2006-07-10 11:21:24 +00:00
|
|
|
* virDomainParseXMLOSDescHVM:
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-07-10 11:21:24 +00:00
|
|
|
* @node: node containing HVM OS description
|
2006-02-16 22:50:52 +00:00
|
|
|
* @buf: a buffer for the result S-Expr
|
2006-07-10 11:21:24 +00:00
|
|
|
* @ctxt: a path context representing the XML description
|
2007-02-07 13:44:22 +00:00
|
|
|
* @vcpus: number of virtual CPUs to configure
|
2006-09-12 01:16:22 +00:00
|
|
|
* @xendConfigVersion: xend configuration file format
|
2006-02-16 22:50:52 +00:00
|
|
|
*
|
2006-07-10 11:21:24 +00:00
|
|
|
* Parse the OS part of the XML description for an HVM domain and add it to
|
|
|
|
* the S-Expr in buf. This is a temporary interface as the S-Expr interface
|
2006-02-16 22:50:52 +00:00
|
|
|
* will be replaced by XML-RPC in the future. However the XML format should
|
|
|
|
* stay valid over time.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
static int
|
2007-02-14 16:16:13 +00:00
|
|
|
virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr ctxt, int vcpus, int xendConfigVersion)
|
2006-07-10 11:21:24 +00:00
|
|
|
{
|
|
|
|
xmlXPathObjectPtr obj = NULL;
|
|
|
|
xmlNodePtr cur, txt;
|
2006-10-06 15:32:48 +00:00
|
|
|
xmlChar *type = NULL;
|
|
|
|
xmlChar *loader = NULL;
|
|
|
|
xmlChar *boot_dev = NULL;
|
2006-08-26 15:30:44 +00:00
|
|
|
int res;
|
2006-07-10 11:21:24 +00:00
|
|
|
|
|
|
|
cur = node->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE) {
|
|
|
|
if ((type == NULL)
|
|
|
|
&& (xmlStrEqual(cur->name, BAD_CAST "type"))) {
|
|
|
|
txt = cur->children;
|
|
|
|
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(txt->next == NULL))
|
2006-07-10 11:21:24 +00:00
|
|
|
type = txt->content;
|
|
|
|
} else if ((loader == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "loader"))) {
|
|
|
|
txt = cur->children;
|
|
|
|
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(txt->next == NULL))
|
2006-07-10 11:21:24 +00:00
|
|
|
loader = txt->content;
|
|
|
|
} else if ((boot_dev == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "boot"))) {
|
|
|
|
boot_dev = xmlGetProp(cur, BAD_CAST "dev");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
if ((type == NULL) || (!xmlStrEqual(type, BAD_CAST "hvm"))) {
|
|
|
|
/* VIR_ERR_OS_TYPE */
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_OS_TYPE, (const char *) type, 0);
|
2006-07-10 11:21:24 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
virBufferAdd(buf, "(image (hvm ", 12);
|
|
|
|
if (loader == NULL) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_KERNEL, NULL, 0);
|
2007-02-07 13:50:18 +00:00
|
|
|
goto error;
|
2006-07-10 11:21:24 +00:00
|
|
|
} else {
|
2007-02-07 13:50:18 +00:00
|
|
|
virBufferVSprintf(buf, "(kernel '%s')", (const char *) loader);
|
2006-07-10 11:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get the device emulation model */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
|
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
|
|
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_KERNEL, NULL, 0); /* TODO: error */
|
2006-07-10 11:21:24 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virBufferVSprintf(buf, "(device_model '%s')",
|
|
|
|
(const char *) obj->stringval);
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = NULL;
|
|
|
|
|
2007-02-07 13:44:22 +00:00
|
|
|
virBufferVSprintf(buf, "(vcpus %d)", vcpus);
|
|
|
|
|
2006-07-10 11:21:24 +00:00
|
|
|
if (boot_dev) {
|
2007-02-07 13:50:18 +00:00
|
|
|
if (xmlStrEqual(boot_dev, BAD_CAST "fd")) {
|
2007-03-16 15:03:21 +00:00
|
|
|
virBufferVSprintf(buf, "(boot a)" /*, (const char *) boot_dev*/);
|
2007-02-07 13:50:18 +00:00
|
|
|
} else if (xmlStrEqual(boot_dev, BAD_CAST "cdrom")) {
|
2007-03-16 15:03:21 +00:00
|
|
|
virBufferVSprintf(buf, "(boot d)" /*, (const char *) boot_dev*/);
|
2007-02-07 13:50:18 +00:00
|
|
|
} else if (xmlStrEqual(boot_dev, BAD_CAST "hd")) {
|
2007-03-16 15:03:21 +00:00
|
|
|
virBufferVSprintf(buf, "(boot c)" /*, (const char *) boot_dev*/);
|
2007-02-07 13:50:18 +00:00
|
|
|
} else {
|
|
|
|
/* Any other type of boot dev is unsupported right now */
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_XML_ERROR, NULL, 0);
|
2007-02-07 13:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get the 1st floppy device file */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fda']/source", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
|
|
|
|
cur = obj->nodesetval->nodeTab[0];
|
|
|
|
virBufferVSprintf(buf, "(fda '%s')",
|
|
|
|
(const char *) xmlGetProp(cur, BAD_CAST "file"));
|
|
|
|
cur = NULL;
|
|
|
|
}
|
|
|
|
if (obj) {
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the 2nd floppy device file */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fdb']/source", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
|
|
|
|
xmlChar *fdfile = NULL;
|
|
|
|
cur = obj->nodesetval->nodeTab[0];
|
|
|
|
fdfile = xmlGetProp(cur, BAD_CAST "file");
|
|
|
|
virBufferVSprintf(buf, "(fdb '%s')",
|
|
|
|
(const char *) fdfile);
|
|
|
|
xmlFree(fdfile);
|
|
|
|
cur = NULL;
|
|
|
|
}
|
|
|
|
if (obj) {
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the cdrom device file */
|
|
|
|
/* Only XenD <= 3.0.2 wants cdrom config here */
|
|
|
|
if (xendConfigVersion == 1) {
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='cdrom' and target/@dev='hdc']/source", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
|
|
|
|
xmlChar *cdfile = NULL;
|
|
|
|
cur = obj->nodesetval->nodeTab[0];
|
|
|
|
cdfile = xmlGetProp(cur, BAD_CAST "file");
|
|
|
|
virBufferVSprintf(buf, "(cdrom '%s')",
|
|
|
|
(const char *)cdfile);
|
|
|
|
xmlFree(cdfile);
|
|
|
|
cur = NULL;
|
|
|
|
}
|
|
|
|
if (obj) {
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/features/acpi", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
|
|
|
|
virBufferAdd(buf, "(acpi 1)", 8);
|
|
|
|
}
|
|
|
|
if (obj)
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/features/apic", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
|
|
|
|
virBufferAdd(buf, "(apic 1)", 8);
|
|
|
|
}
|
|
|
|
if (obj)
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/features/pae", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
|
|
|
|
virBufferAdd(buf, "(pae 1)", 7);
|
|
|
|
}
|
|
|
|
if (obj)
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = NULL;
|
2006-08-11 14:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "count(domain/devices/console) > 0", ctxt);
|
|
|
|
if ((obj == NULL) || (obj->type != XPATH_BOOLEAN)) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_XML_ERROR, NULL, 0);
|
2007-02-07 13:50:18 +00:00
|
|
|
goto error;
|
2006-08-11 14:40:04 +00:00
|
|
|
}
|
|
|
|
if (obj->boolval) {
|
2007-02-07 13:50:18 +00:00
|
|
|
virBufferAdd(buf, "(serial pty)", 12);
|
2006-08-11 14:40:04 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = NULL;
|
2007-02-07 13:50:18 +00:00
|
|
|
|
2006-07-10 11:21:24 +00:00
|
|
|
/* Is a graphics device specified? */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics[1]", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
2006-08-26 15:30:44 +00:00
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
|
2007-02-14 16:16:13 +00:00
|
|
|
res = virDomainParseXMLGraphicsDescImage(conn, obj->nodesetval->nodeTab[0], buf, xendConfigVersion);
|
2006-08-26 15:30:44 +00:00
|
|
|
if (res != 0) {
|
|
|
|
goto error;
|
2006-07-10 11:21:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
virBufferAdd(buf, "))", 2);
|
|
|
|
|
2006-10-06 15:32:48 +00:00
|
|
|
if (boot_dev)
|
|
|
|
xmlFree(boot_dev);
|
|
|
|
|
2006-07-10 11:21:24 +00:00
|
|
|
return (0);
|
2007-02-07 13:50:18 +00:00
|
|
|
error:
|
2006-10-06 15:32:48 +00:00
|
|
|
if (boot_dev)
|
|
|
|
xmlFree(boot_dev);
|
2006-07-10 11:21:24 +00:00
|
|
|
if (obj != NULL)
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainParseXMLOSDescPV:
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-07-10 11:21:24 +00:00
|
|
|
* @node: node containing PV OS description
|
|
|
|
* @buf: a buffer for the result S-Expr
|
2006-08-26 15:30:44 +00:00
|
|
|
* @ctxt: a path context representing the XML description
|
2006-09-12 01:34:26 +00:00
|
|
|
* @xendConfigVersion: xend configuration file format
|
2006-07-10 11:21:24 +00:00
|
|
|
*
|
|
|
|
* Parse the OS part of the XML description for a paravirtualized domain
|
|
|
|
* and add it to the S-Expr in buf. This is a temporary interface as the
|
|
|
|
* S-Expr interface will be replaced by XML-RPC in the future. However
|
|
|
|
* the XML format should stay valid over time.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
static int
|
2007-02-14 16:16:13 +00:00
|
|
|
virDomainParseXMLOSDescPV(virConnectPtr conn, xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr ctxt, int xendConfigVersion)
|
2006-03-15 12:13:25 +00:00
|
|
|
{
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlNodePtr cur, txt;
|
2006-08-26 15:30:44 +00:00
|
|
|
xmlXPathObjectPtr obj = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
const xmlChar *type = NULL;
|
|
|
|
const xmlChar *root = NULL;
|
|
|
|
const xmlChar *kernel = NULL;
|
|
|
|
const xmlChar *initrd = NULL;
|
|
|
|
const xmlChar *cmdline = NULL;
|
2006-08-26 15:30:44 +00:00
|
|
|
int res;
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
cur = node->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE) {
|
2006-03-15 12:13:25 +00:00
|
|
|
if ((type == NULL)
|
|
|
|
&& (xmlStrEqual(cur->name, BAD_CAST "type"))) {
|
|
|
|
txt = cur->children;
|
2006-07-04 12:46:14 +00:00
|
|
|
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(txt->next == NULL))
|
2006-03-15 12:13:25 +00:00
|
|
|
type = txt->content;
|
|
|
|
} else if ((kernel == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "kernel"))) {
|
|
|
|
txt = cur->children;
|
2006-07-04 12:46:14 +00:00
|
|
|
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(txt->next == NULL))
|
2006-03-15 12:13:25 +00:00
|
|
|
kernel = txt->content;
|
|
|
|
} else if ((root == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "root"))) {
|
|
|
|
txt = cur->children;
|
2006-07-04 12:46:14 +00:00
|
|
|
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(txt->next == NULL))
|
2006-03-15 12:13:25 +00:00
|
|
|
root = txt->content;
|
|
|
|
} else if ((initrd == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "initrd"))) {
|
|
|
|
txt = cur->children;
|
2006-07-04 12:46:14 +00:00
|
|
|
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(txt->next == NULL))
|
2006-03-15 12:13:25 +00:00
|
|
|
initrd = txt->content;
|
|
|
|
} else if ((cmdline == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "cmdline"))) {
|
|
|
|
txt = cur->children;
|
2006-07-04 12:46:14 +00:00
|
|
|
if ((txt != NULL) && (txt->type == XML_TEXT_NODE) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(txt->next == NULL))
|
2006-03-15 12:13:25 +00:00
|
|
|
cmdline = txt->content;
|
|
|
|
}
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
if ((type != NULL) && (!xmlStrEqual(type, BAD_CAST "linux"))) {
|
|
|
|
/* VIR_ERR_OS_TYPE */
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_OS_TYPE, (const char *) type, 0);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
2006-07-05 17:08:40 +00:00
|
|
|
virBufferAdd(buf, "(image (linux ", 14);
|
2006-02-16 22:50:52 +00:00
|
|
|
if (kernel == NULL) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_KERNEL, NULL, 0);
|
2007-02-07 13:50:18 +00:00
|
|
|
return (-1);
|
2006-03-30 16:08:13 +00:00
|
|
|
} else {
|
2007-02-07 13:50:18 +00:00
|
|
|
virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
if (initrd != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
|
2006-04-26 07:31:16 +00:00
|
|
|
if (root != NULL)
|
2006-02-16 22:50:52 +00:00
|
|
|
virBufferVSprintf(buf, "(root '%s')", (const char *) root);
|
2006-04-26 07:31:16 +00:00
|
|
|
if (cmdline != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
virBufferVSprintf(buf, "(args '%s')", (const char *) cmdline);
|
2006-08-26 15:30:44 +00:00
|
|
|
|
|
|
|
/* Is a graphics device specified? */
|
2006-12-13 14:08:51 +00:00
|
|
|
/* Old style config before merge of PVFB */
|
|
|
|
if (xendConfigVersion < 3) {
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics[1]", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr > 0)) {
|
2007-02-14 16:16:13 +00:00
|
|
|
res = virDomainParseXMLGraphicsDescImage(conn, obj->nodesetval->nodeTab[0], buf, xendConfigVersion);
|
2006-12-13 14:08:51 +00:00
|
|
|
if (res != 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
2006-08-26 15:30:44 +00:00
|
|
|
}
|
2006-12-13 14:08:51 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
2006-08-26 15:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
2006-07-05 17:08:40 +00:00
|
|
|
virBufferAdd(buf, "))", 2);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (0);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
2006-11-08 16:55:20 +00:00
|
|
|
/**
|
|
|
|
* virCatchXMLParseError:
|
|
|
|
* @ctx: the context
|
|
|
|
* @msg: the error message
|
|
|
|
* @...: extra arguments
|
|
|
|
*
|
|
|
|
* SAX callback on parsing errors, act as a gate for libvirt own
|
|
|
|
* error reporting.
|
|
|
|
*/
|
|
|
|
static void
|
2006-11-17 00:10:51 +00:00
|
|
|
virCatchXMLParseError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
|
2006-11-08 16:55:20 +00:00
|
|
|
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
|
|
|
|
2006-11-17 00:10:51 +00:00
|
|
|
if ((ctxt != NULL) &&
|
2006-11-08 16:55:20 +00:00
|
|
|
(ctxt->lastError.level == XML_ERR_FATAL) &&
|
2006-11-17 00:10:51 +00:00
|
|
|
(ctxt->lastError.message != NULL)) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(NULL, VIR_ERR_XML_DETAIL, ctxt->lastError.message,
|
2007-02-07 13:50:18 +00:00
|
|
|
ctxt->lastError.line);
|
2006-11-08 16:55:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
/**
|
|
|
|
* virDomainParseXMLDiskDesc:
|
2006-07-10 11:21:24 +00:00
|
|
|
* @node: node containing disk description
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-02-16 22:50:52 +00:00
|
|
|
* @buf: a buffer for the result S-Expr
|
2006-09-12 01:16:22 +00:00
|
|
|
* @xendConfigVersion: xend configuration file format
|
2006-02-16 22:50:52 +00:00
|
|
|
*
|
|
|
|
* Parse the one disk in the XML description and add it to the S-Expr in buf
|
|
|
|
* This is a temporary interface as the S-Expr interface
|
|
|
|
* will be replaced by XML-RPC in the future. However the XML format should
|
|
|
|
* stay valid over time.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
static int
|
2007-02-14 16:16:13 +00:00
|
|
|
virDomainParseXMLDiskDesc(virConnectPtr conn, xmlNodePtr node, virBufferPtr buf, int hvm, int xendConfigVersion)
|
2006-03-15 12:13:25 +00:00
|
|
|
{
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlNodePtr cur;
|
|
|
|
xmlChar *type = NULL;
|
2006-08-11 14:40:04 +00:00
|
|
|
xmlChar *device = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlChar *source = NULL;
|
|
|
|
xmlChar *target = NULL;
|
2006-10-09 14:32:07 +00:00
|
|
|
xmlChar *drvName = NULL;
|
|
|
|
xmlChar *drvType = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
int ro = 0;
|
2006-11-13 17:09:31 +00:00
|
|
|
int shareable = 0;
|
2006-02-16 22:50:52 +00:00
|
|
|
int typ = 0;
|
2006-09-12 01:16:22 +00:00
|
|
|
int cdrom = 0;
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
type = xmlGetProp(node, BAD_CAST "type");
|
|
|
|
if (type != NULL) {
|
2006-03-15 12:13:25 +00:00
|
|
|
if (xmlStrEqual(type, BAD_CAST "file"))
|
|
|
|
typ = 0;
|
|
|
|
else if (xmlStrEqual(type, BAD_CAST "block"))
|
|
|
|
typ = 1;
|
|
|
|
xmlFree(type);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
2006-08-11 14:40:04 +00:00
|
|
|
device = xmlGetProp(node, BAD_CAST "device");
|
2006-10-09 14:32:07 +00:00
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
cur = node->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE) {
|
2006-03-15 12:13:25 +00:00
|
|
|
if ((source == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "source"))) {
|
|
|
|
|
|
|
|
if (typ == 0)
|
|
|
|
source = xmlGetProp(cur, BAD_CAST "file");
|
|
|
|
else
|
|
|
|
source = xmlGetProp(cur, BAD_CAST "dev");
|
|
|
|
} else if ((target == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "target"))) {
|
|
|
|
target = xmlGetProp(cur, BAD_CAST "dev");
|
2006-10-09 14:32:07 +00:00
|
|
|
} else if ((drvName == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "driver"))) {
|
|
|
|
drvName = xmlGetProp(cur, BAD_CAST "name");
|
|
|
|
if (drvName && !strcmp((const char *)drvName, "tap"))
|
|
|
|
drvType = xmlGetProp(cur, BAD_CAST "type");
|
2006-03-15 12:13:25 +00:00
|
|
|
} else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
|
|
|
|
ro = 1;
|
2006-11-13 17:09:31 +00:00
|
|
|
} else if (xmlStrEqual(cur->name, BAD_CAST "shareable")) {
|
2007-02-07 13:50:18 +00:00
|
|
|
shareable = 1;
|
2006-03-15 12:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source == NULL) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_SOURCE, (const char *) target, 0);
|
2006-03-15 12:13:25 +00:00
|
|
|
|
|
|
|
if (target != NULL)
|
|
|
|
xmlFree(target);
|
2006-10-06 15:32:48 +00:00
|
|
|
if (device != NULL)
|
|
|
|
xmlFree(device);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
if (target == NULL) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_TARGET, (const char *) source, 0);
|
2006-03-15 12:13:25 +00:00
|
|
|
if (source != NULL)
|
|
|
|
xmlFree(source);
|
2006-10-06 15:32:48 +00:00
|
|
|
if (device != NULL)
|
|
|
|
xmlFree(device);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (-1);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
2006-08-11 14:40:04 +00:00
|
|
|
|
2006-09-12 01:16:22 +00:00
|
|
|
/* Xend (all versions) put the floppy device config
|
|
|
|
* under the hvm (image (os)) block
|
2006-08-11 14:40:04 +00:00
|
|
|
*/
|
2006-10-09 14:32:07 +00:00
|
|
|
if (hvm &&
|
2006-09-14 15:34:50 +00:00
|
|
|
device &&
|
2006-09-12 01:16:22 +00:00
|
|
|
!strcmp((const char *)device, "floppy")) {
|
2006-10-06 15:32:48 +00:00
|
|
|
goto cleanup;
|
2006-09-12 01:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Xend <= 3.0.2 doesn't include cdrom config here */
|
2006-10-09 14:32:07 +00:00
|
|
|
if (hvm &&
|
2006-09-14 15:34:50 +00:00
|
|
|
device &&
|
|
|
|
!strcmp((const char *)device, "cdrom")) {
|
2006-09-12 01:16:22 +00:00
|
|
|
if (xendConfigVersion == 1)
|
2006-10-06 15:32:48 +00:00
|
|
|
goto cleanup;
|
2006-09-12 01:16:22 +00:00
|
|
|
else
|
|
|
|
cdrom = 1;
|
2006-08-11 14:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virBufferAdd(buf, "(device ", 8);
|
2006-10-09 14:32:07 +00:00
|
|
|
/* Normally disks are in a (device (vbd ...)) block
|
|
|
|
but blktap disks ended up in a differently named
|
|
|
|
(device (tap ....)) block.... */
|
|
|
|
if (drvName && !strcmp((const char *)drvName, "tap")) {
|
|
|
|
virBufferAdd(buf, "(tap ", 5);
|
|
|
|
} else {
|
|
|
|
virBufferAdd(buf, "(vbd ", 5);
|
|
|
|
}
|
2006-09-12 01:16:22 +00:00
|
|
|
|
2006-08-11 14:40:04 +00:00
|
|
|
if (hvm) {
|
|
|
|
char *tmp = (char *)target;
|
2006-09-12 01:16:22 +00:00
|
|
|
/* Just in case user mistakenly still puts ioemu: in their XML */
|
2006-08-11 14:40:04 +00:00
|
|
|
if (!strncmp((const char *) tmp, "ioemu:", 6))
|
|
|
|
tmp += 6;
|
2006-09-12 01:16:22 +00:00
|
|
|
|
|
|
|
/* Xend <= 3.0.2 wants a ioemu: prefix on devices for HVM */
|
|
|
|
if (xendConfigVersion == 1)
|
2006-10-09 14:32:07 +00:00
|
|
|
virBufferVSprintf(buf, "(dev 'ioemu:%s')", (const char *)tmp);
|
2006-09-12 01:16:22 +00:00
|
|
|
else /* But newer does not */
|
2006-10-09 14:32:07 +00:00
|
|
|
virBufferVSprintf(buf, "(dev '%s%s')", (const char *)tmp, cdrom ? ":cdrom" : ":disk");
|
2006-08-11 14:40:04 +00:00
|
|
|
} else
|
2006-10-09 14:32:07 +00:00
|
|
|
virBufferVSprintf(buf, "(dev '%s')", (const char *)target);
|
|
|
|
|
|
|
|
if (drvName) {
|
|
|
|
if (!strcmp((const char *)drvName, "tap")) {
|
|
|
|
virBufferVSprintf(buf, "(uname '%s:%s:%s')",
|
|
|
|
(const char *)drvName,
|
|
|
|
(drvType ? (const char *)drvType : "aio"),
|
|
|
|
(const char *)source);
|
|
|
|
} else {
|
|
|
|
virBufferVSprintf(buf, "(uname '%s:%s')",
|
|
|
|
(const char *)drvName,
|
|
|
|
(const char *)source);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (typ == 0)
|
|
|
|
virBufferVSprintf(buf, "(uname 'file:%s')", source);
|
|
|
|
else if (typ == 1) {
|
|
|
|
if (source[0] == '/')
|
|
|
|
virBufferVSprintf(buf, "(uname 'phy:%s')", source);
|
|
|
|
else
|
|
|
|
virBufferVSprintf(buf, "(uname 'phy:/dev/%s')", source);
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
2006-11-13 17:09:31 +00:00
|
|
|
if (ro == 1)
|
2006-02-16 22:50:52 +00:00
|
|
|
virBufferVSprintf(buf, "(mode 'r')");
|
2006-11-13 17:09:31 +00:00
|
|
|
else if (shareable == 1)
|
|
|
|
virBufferVSprintf(buf, "(mode 'w!')");
|
|
|
|
else
|
|
|
|
virBufferVSprintf(buf, "(mode 'w')");
|
2006-02-16 22:50:52 +00:00
|
|
|
|
2006-08-11 14:40:04 +00:00
|
|
|
virBufferAdd(buf, ")", 1);
|
2006-02-16 22:50:52 +00:00
|
|
|
virBufferAdd(buf, ")", 1);
|
2006-10-06 15:32:48 +00:00
|
|
|
|
|
|
|
cleanup:
|
2006-10-09 14:32:07 +00:00
|
|
|
xmlFree(drvType);
|
|
|
|
xmlFree(drvName);
|
2006-10-06 15:32:48 +00:00
|
|
|
xmlFree(device);
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlFree(target);
|
|
|
|
xmlFree(source);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (0);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainParseXMLIfDesc:
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-07-10 11:21:24 +00:00
|
|
|
* @node: node containing the interface description
|
2006-02-16 22:50:52 +00:00
|
|
|
* @buf: a buffer for the result S-Expr
|
|
|
|
*
|
|
|
|
* Parse the one interface the XML description and add it to the S-Expr in buf
|
|
|
|
* This is a temporary interface as the S-Expr interface
|
|
|
|
* will be replaced by XML-RPC in the future. However the XML format should
|
|
|
|
* stay valid over time.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
static int
|
2007-02-14 16:16:13 +00:00
|
|
|
virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED, xmlNodePtr node, virBufferPtr buf, int hvm)
|
2006-03-15 12:13:25 +00:00
|
|
|
{
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlNodePtr cur;
|
|
|
|
xmlChar *type = NULL;
|
|
|
|
xmlChar *source = NULL;
|
|
|
|
xmlChar *mac = NULL;
|
|
|
|
xmlChar *script = NULL;
|
2006-11-15 00:38:13 +00:00
|
|
|
xmlChar *ip = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
int typ = 0;
|
2007-02-14 16:22:02 +00:00
|
|
|
int ret = -1;
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
type = xmlGetProp(node, BAD_CAST "type");
|
|
|
|
if (type != NULL) {
|
2006-03-15 12:13:25 +00:00
|
|
|
if (xmlStrEqual(type, BAD_CAST "bridge"))
|
|
|
|
typ = 0;
|
|
|
|
else if (xmlStrEqual(type, BAD_CAST "ethernet"))
|
|
|
|
typ = 1;
|
2007-02-14 16:22:02 +00:00
|
|
|
else if (xmlStrEqual(type, BAD_CAST "network"))
|
|
|
|
typ = 2;
|
2006-03-15 12:13:25 +00:00
|
|
|
xmlFree(type);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
cur = node->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
if (cur->type == XML_ELEMENT_NODE) {
|
2006-03-15 12:13:25 +00:00
|
|
|
if ((source == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "source"))) {
|
|
|
|
if (typ == 0)
|
|
|
|
source = xmlGetProp(cur, BAD_CAST "bridge");
|
2007-02-14 16:22:02 +00:00
|
|
|
else if (typ == 1)
|
2006-03-15 12:13:25 +00:00
|
|
|
source = xmlGetProp(cur, BAD_CAST "dev");
|
2007-02-14 16:22:02 +00:00
|
|
|
else
|
|
|
|
source = xmlGetProp(cur, BAD_CAST "network");
|
2006-03-15 12:13:25 +00:00
|
|
|
} else if ((mac == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "mac"))) {
|
|
|
|
mac = xmlGetProp(cur, BAD_CAST "address");
|
|
|
|
} else if ((script == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "script"))) {
|
|
|
|
script = xmlGetProp(cur, BAD_CAST "path");
|
2006-11-15 00:38:13 +00:00
|
|
|
} else if ((ip == NULL) &&
|
|
|
|
(xmlStrEqual(cur->name, BAD_CAST "ip"))) {
|
|
|
|
/* XXX in future expect to need to have > 1 ip
|
|
|
|
address element - eg ipv4 & ipv6. For now
|
|
|
|
xen only supports a single address though
|
|
|
|
so lets ignore that complication */
|
|
|
|
ip = xmlGetProp(cur, BAD_CAST "address");
|
2006-03-15 12:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAdd(buf, "(vif ", 5);
|
|
|
|
if (mac != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
virBufferVSprintf(buf, "(mac '%s')", (const char *) mac);
|
2006-02-16 22:50:52 +00:00
|
|
|
if (source != NULL) {
|
2006-03-15 12:13:25 +00:00
|
|
|
if (typ == 0)
|
|
|
|
virBufferVSprintf(buf, "(bridge '%s')", (const char *) source);
|
2007-02-14 16:22:02 +00:00
|
|
|
else if (typ == 1) /* TODO does that work like that ? */
|
2006-03-15 12:13:25 +00:00
|
|
|
virBufferVSprintf(buf, "(dev '%s')", (const char *) source);
|
2007-02-14 16:22:02 +00:00
|
|
|
else {
|
|
|
|
virNetworkPtr network = virNetworkLookupByName(conn, (const char *) source);
|
|
|
|
char *bridge;
|
|
|
|
if (!network || !(bridge = virNetworkGetBridgeName(network))) {
|
|
|
|
virXMLError(conn, VIR_ERR_NO_SOURCE, (const char *) source, 0);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virBufferVSprintf(buf, "(bridge '%s')", bridge);
|
|
|
|
free(bridge);
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
if (script != NULL)
|
|
|
|
virBufferVSprintf(buf, "(script '%s')", script);
|
2006-11-15 00:38:13 +00:00
|
|
|
if (ip != NULL)
|
|
|
|
virBufferVSprintf(buf, "(ip '%s')", ip);
|
2006-08-18 20:20:50 +00:00
|
|
|
if (hvm)
|
|
|
|
virBufferAdd(buf, "(type ioemu)", 12);
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
virBufferAdd(buf, ")", 1);
|
2007-02-14 16:22:02 +00:00
|
|
|
ret = 0;
|
|
|
|
error:
|
2006-02-16 22:50:52 +00:00
|
|
|
if (mac != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
xmlFree(mac);
|
2006-02-16 22:50:52 +00:00
|
|
|
if (source != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
xmlFree(source);
|
2006-02-16 22:50:52 +00:00
|
|
|
if (script != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
xmlFree(script);
|
2006-11-15 00:38:13 +00:00
|
|
|
if (ip != NULL)
|
|
|
|
xmlFree(ip);
|
2007-02-14 16:22:02 +00:00
|
|
|
return (ret);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainParseXMLDesc:
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-02-16 22:50:52 +00:00
|
|
|
* @xmldesc: string with the XML description
|
2006-09-12 01:16:22 +00:00
|
|
|
* @xendConfigVersion: xend configuration file format
|
2006-02-16 22:50:52 +00:00
|
|
|
*
|
|
|
|
* Parse the XML description and turn it into the xend sexp needed to
|
|
|
|
* create the comain. This is a temporary interface as the S-Expr interface
|
|
|
|
* will be replaced by XML-RPC in the future. However the XML format should
|
|
|
|
* stay valid over time.
|
|
|
|
*
|
|
|
|
* Returns the 0 terminatedi S-Expr string or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *
|
2007-02-14 16:16:13 +00:00
|
|
|
virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name, int xendConfigVersion)
|
2006-03-15 12:13:25 +00:00
|
|
|
{
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlNodePtr node;
|
2006-02-27 22:32:54 +00:00
|
|
|
char *ret = NULL, *nam = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
virBuffer buf;
|
|
|
|
xmlChar *prop;
|
2006-11-08 16:55:20 +00:00
|
|
|
xmlParserCtxtPtr pctxt;
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlXPathObjectPtr obj = NULL;
|
2006-07-10 11:21:24 +00:00
|
|
|
xmlXPathObjectPtr tmpobj = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
int i, res;
|
2006-03-30 16:08:13 +00:00
|
|
|
int bootloader = 0;
|
2006-08-11 14:40:04 +00:00
|
|
|
int hvm = 0;
|
2007-02-07 13:44:22 +00:00
|
|
|
unsigned int vcpus = 1;
|
2006-11-10 11:13:01 +00:00
|
|
|
unsigned long mem = 0, max_mem = 0;
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
if (name != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
*name = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
ret = malloc(1000);
|
|
|
|
if (ret == NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-16 22:50:52 +00:00
|
|
|
buf.content = ret;
|
|
|
|
buf.size = 1000;
|
|
|
|
buf.use = 0;
|
|
|
|
|
2006-11-08 16:55:20 +00:00
|
|
|
pctxt = xmlNewParserCtxt();
|
|
|
|
if ((pctxt == NULL) || (pctxt->sax == NULL)) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2007-02-14 16:16:13 +00:00
|
|
|
/* TODO pass the connection point to the error handler:
|
|
|
|
* pctxt->userData = virConnectPtr;
|
|
|
|
*/
|
2006-11-08 16:55:20 +00:00
|
|
|
pctxt->sax->error = virCatchXMLParseError;
|
|
|
|
|
|
|
|
xml = xmlCtxtReadDoc(pctxt, (const xmlChar *) xmldesc, "domain.xml", NULL,
|
|
|
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
|
|
|
XML_PARSE_NOWARNING);
|
2006-02-16 22:50:52 +00:00
|
|
|
if (xml == NULL) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
node = xmlDocGetRootElement(xml);
|
|
|
|
if ((node == NULL) || (!xmlStrEqual(node->name, BAD_CAST "domain")))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
prop = xmlGetProp(node, BAD_CAST "type");
|
|
|
|
if (prop != NULL) {
|
|
|
|
if (!xmlStrEqual(prop, BAD_CAST "xen")) {
|
2006-03-15 12:13:25 +00:00
|
|
|
xmlFree(prop);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
xmlFree(prop);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
virBufferAdd(&buf, "(vm ", 4);
|
|
|
|
ctxt = xmlXPathNewContext(xml);
|
|
|
|
if (ctxt == NULL) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/*
|
2006-07-10 11:21:24 +00:00
|
|
|
* extract some of the basics, name, memory, cpus ...
|
2006-02-16 22:50:52 +00:00
|
|
|
*/
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
|
2006-03-15 12:13:25 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
2006-02-16 22:50:52 +00:00
|
|
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_NAME, xmldesc, 0);
|
2006-02-16 22:50:52 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virBufferVSprintf(&buf, "(name '%s')", obj->stringval);
|
2006-02-27 22:32:54 +00:00
|
|
|
nam = strdup((const char *) obj->stringval);
|
|
|
|
if (nam == NULL) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_MEMORY, "copying name", 0);
|
2006-03-15 12:13:25 +00:00
|
|
|
goto error;
|
2006-02-27 22:32:54 +00:00
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "number(/domain/memory[1])", ctxt);
|
|
|
|
if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
|
2007-03-08 14:12:06 +00:00
|
|
|
(isnan(obj->floatval)) || (obj->floatval < MIN_XEN_GUEST_SIZE * 1024)) {
|
2007-02-07 13:50:18 +00:00
|
|
|
max_mem = 128;
|
2006-02-16 22:50:52 +00:00
|
|
|
} else {
|
2006-11-10 11:13:01 +00:00
|
|
|
max_mem = (obj->floatval / 1024);
|
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
obj = xmlXPathEval(BAD_CAST "number(/domain/currentMemory[1])", ctxt);
|
|
|
|
if ((obj == NULL) || (obj->type != XPATH_NUMBER) ||
|
2007-03-08 14:12:06 +00:00
|
|
|
(isnan(obj->floatval)) || (obj->floatval < MIN_XEN_GUEST_SIZE * 1024)) {
|
2006-11-10 11:13:01 +00:00
|
|
|
mem = max_mem;
|
|
|
|
} else {
|
|
|
|
mem = (obj->floatval / 1024);
|
2007-02-07 13:50:18 +00:00
|
|
|
if (mem > max_mem) {
|
|
|
|
max_mem = mem;
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
2006-11-10 11:13:01 +00:00
|
|
|
virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)", mem, max_mem);
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "number(/domain/vcpu[1])", ctxt);
|
2007-02-07 13:44:22 +00:00
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NUMBER) &&
|
|
|
|
(!isnan(obj->floatval)) && (obj->floatval > 0)) {
|
|
|
|
vcpus = (unsigned int) obj->floatval;
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
2007-02-07 13:44:22 +00:00
|
|
|
virBufferVSprintf(&buf, "(vcpus %u)", vcpus);
|
2006-02-16 22:50:52 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
2006-07-13 22:27:31 +00:00
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/uuid[1])", ctxt);
|
2006-08-08 22:22:55 +00:00
|
|
|
if ((obj == NULL) || ((obj->type == XPATH_STRING) &&
|
2007-02-07 13:50:18 +00:00
|
|
|
(obj->stringval != NULL) && (obj->stringval[0] != 0))) {
|
2006-07-13 22:27:31 +00:00
|
|
|
virBufferVSprintf(&buf, "(uuid '%s')", obj->stringval);
|
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
2006-03-30 16:08:13 +00:00
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/bootloader[1])", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
|
|
|
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
2007-02-07 13:50:18 +00:00
|
|
|
virBufferVSprintf(&buf, "(bootloader '%s')", obj->stringval);
|
|
|
|
/*
|
|
|
|
* if using pygrub, the kernel and initrd strings are not
|
|
|
|
* significant and should be discarded
|
|
|
|
*/
|
|
|
|
if (xmlStrstr(obj->stringval, BAD_CAST "pygrub"))
|
|
|
|
bootloader = 2;
|
|
|
|
else
|
|
|
|
bootloader = 1;
|
2006-03-30 16:08:13 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
2006-04-10 08:32:34 +00:00
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/on_poweroff[1])", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
|
|
|
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
2007-02-07 13:50:18 +00:00
|
|
|
virBufferVSprintf(&buf, "(on_poweroff '%s')", obj->stringval);
|
2006-04-10 08:32:34 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/on_reboot[1])", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
|
|
|
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
2007-02-07 13:50:18 +00:00
|
|
|
virBufferVSprintf(&buf, "(on_reboot '%s')", obj->stringval);
|
2006-04-10 08:32:34 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/on_crash[1])", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
|
|
|
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
2007-02-07 13:50:18 +00:00
|
|
|
virBufferVSprintf(&buf, "(on_crash '%s')", obj->stringval);
|
2006-04-10 08:32:34 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
2006-11-27 23:16:59 +00:00
|
|
|
if (bootloader != 2) {
|
2007-02-07 13:50:18 +00:00
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
|
|
|
|
/* Analyze of the os description, based on HVM or PV. */
|
|
|
|
tmpobj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt);
|
|
|
|
if ((tmpobj != NULL) &&
|
|
|
|
((tmpobj->type != XPATH_STRING) || (tmpobj->stringval == NULL)
|
|
|
|
|| (tmpobj->stringval[0] == 0))) {
|
|
|
|
xmlXPathFreeObject(tmpobj);
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_OS_TYPE, nam, 0);
|
2007-02-07 13:50:18 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tmpobj == NULL)
|
|
|
|
|| !xmlStrEqual(tmpobj->stringval, BAD_CAST "hvm")) {
|
2007-02-14 16:16:13 +00:00
|
|
|
res = virDomainParseXMLOSDescPV(conn, obj->nodesetval->nodeTab[0],
|
2007-02-07 13:50:18 +00:00
|
|
|
&buf, ctxt, xendConfigVersion);
|
|
|
|
} else {
|
|
|
|
hvm = 1;
|
2007-02-14 16:16:13 +00:00
|
|
|
res = virDomainParseXMLOSDescHVM(conn, obj->nodesetval->nodeTab[0],
|
2007-02-07 13:50:18 +00:00
|
|
|
&buf, ctxt, vcpus, xendConfigVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlXPathFreeObject(tmpobj);
|
|
|
|
|
|
|
|
if (res != 0)
|
|
|
|
goto error;
|
|
|
|
} else if (bootloader == 0) {
|
2007-02-14 16:16:13 +00:00
|
|
|
virXMLError(conn, VIR_ERR_NO_OS, nam, 0);
|
2007-02-07 13:50:18 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* analyze of the devices */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
|
2006-07-07 14:36:27 +00:00
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
|
2007-02-07 13:50:18 +00:00
|
|
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
2007-02-14 16:16:13 +00:00
|
|
|
res = virDomainParseXMLDiskDesc(conn, obj->nodesetval->nodeTab[i], &buf, hvm, xendConfigVersion);
|
2007-02-07 13:50:18 +00:00
|
|
|
if (res != 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
2006-07-07 14:36:27 +00:00
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
|
2006-03-15 12:13:25 +00:00
|
|
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
|
|
|
virBufferAdd(&buf, "(device ", 8);
|
2007-02-14 16:16:13 +00:00
|
|
|
res = virDomainParseXMLIfDesc(conn, obj->nodesetval->nodeTab[i], &buf, hvm);
|
2006-03-15 12:13:25 +00:00
|
|
|
if (res != 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virBufferAdd(&buf, ")", 1);
|
|
|
|
}
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
2006-12-13 14:08:51 +00:00
|
|
|
/* New style PVFB config - 3.0.4 merge */
|
|
|
|
if (xendConfigVersion >= 3 && !hvm) {
|
|
|
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt);
|
|
|
|
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
|
|
|
|
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
|
|
|
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
2007-02-14 16:16:13 +00:00
|
|
|
res = virDomainParseXMLGraphicsDescVFB(conn, obj->nodesetval->nodeTab[i], &buf);
|
2006-12-13 14:08:51 +00:00
|
|
|
if (res != 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
}
|
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
|
2006-02-20 17:22:16 +00:00
|
|
|
virBufferAdd(&buf, ")", 1); /* closes (vm */
|
2006-02-16 22:50:52 +00:00
|
|
|
buf.content[buf.use] = 0;
|
|
|
|
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
xmlFreeDoc(xml);
|
2006-11-10 23:46:12 +00:00
|
|
|
xmlFreeParserCtxt(pctxt);
|
2006-02-27 22:32:54 +00:00
|
|
|
|
|
|
|
if (name != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
*name = nam;
|
2006-10-06 15:32:48 +00:00
|
|
|
else
|
|
|
|
free(nam);
|
2006-02-16 22:50:52 +00:00
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
return (ret);
|
|
|
|
|
2007-02-07 13:50:18 +00:00
|
|
|
error:
|
2006-02-27 22:32:54 +00:00
|
|
|
if (nam != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
free(nam);
|
2006-02-27 22:32:54 +00:00
|
|
|
if (name != NULL)
|
2006-03-15 12:13:25 +00:00
|
|
|
*name = NULL;
|
2006-02-16 22:50:52 +00:00
|
|
|
if (obj != NULL)
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
if (ctxt != NULL)
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
if (xml != NULL)
|
|
|
|
xmlFreeDoc(xml);
|
2006-11-10 23:46:12 +00:00
|
|
|
if (pctxt != NULL)
|
|
|
|
xmlFreeParserCtxt(pctxt);
|
2006-02-16 22:50:52 +00:00
|
|
|
if (ret != NULL)
|
|
|
|
free(ret);
|
2006-03-15 12:13:25 +00:00
|
|
|
return (NULL);
|
2006-02-16 22:50:52 +00:00
|
|
|
}
|
2006-08-09 15:21:16 +00:00
|
|
|
|
|
|
|
#endif /* !PROXY */
|
2006-08-16 16:33:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char *virParseUUID(char **ptr, const char *uuid) {
|
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
2007-01-23 14:39:45 +00:00
|
|
|
int rawuuid[VIR_UUID_BUFLEN];
|
2006-08-17 18:39:32 +00:00
|
|
|
const char *cur;
|
2006-08-16 16:33:55 +00:00
|
|
|
unsigned char *dst_uuid = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (uuid == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2006-08-17 18:39:32 +00:00
|
|
|
/*
|
|
|
|
* do a liberal scan allowing '-' and ' ' anywhere between character
|
|
|
|
* pairs as long as there is 32 of them in the end.
|
|
|
|
*/
|
|
|
|
cur = uuid;
|
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
2007-01-23 14:39:45 +00:00
|
|
|
for (i = 0;i < VIR_UUID_BUFLEN;) {
|
2006-08-17 18:39:32 +00:00
|
|
|
rawuuid[i] = 0;
|
|
|
|
if (*cur == 0)
|
2007-02-07 13:50:18 +00:00
|
|
|
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++;
|
2006-08-17 18:39:32 +00:00
|
|
|
if (*cur == 0)
|
2007-02-07 13:50:18 +00:00
|
|
|
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;
|
2006-08-17 18:39:32 +00:00
|
|
|
i++;
|
2007-02-07 13:50:18 +00:00
|
|
|
cur++;
|
2006-08-17 18:39:32 +00:00
|
|
|
}
|
2006-08-16 16:33:55 +00:00
|
|
|
|
|
|
|
dst_uuid = (unsigned char *) *ptr;
|
|
|
|
*ptr += 16;
|
|
|
|
|
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
2007-01-23 14:39:45 +00:00
|
|
|
for (i = 0; i < VIR_UUID_BUFLEN; i++)
|
2006-08-16 16:33:55 +00:00
|
|
|
dst_uuid[i] = rawuuid[i] & 0xFF;
|
|
|
|
|
2007-02-07 13:50:18 +00:00
|
|
|
error:
|
2006-08-17 18:39:32 +00:00
|
|
|
return(dst_uuid);
|
2006-08-16 16:33:55 +00:00
|
|
|
}
|
2006-09-12 01:34:26 +00:00
|
|
|
|
2006-11-16 18:11:28 +00:00
|
|
|
#ifndef PROXY
|
|
|
|
/**
|
|
|
|
* virParseXMLDevice:
|
2007-02-14 16:16:13 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
2006-11-16 18:11:28 +00:00
|
|
|
* @xmldesc: string with the XML description
|
|
|
|
* @hvm: 1 for fully virtualized guest, 0 for paravirtualized
|
|
|
|
* @xendConfigVersion: xend configuration file format
|
|
|
|
*
|
|
|
|
* Parse the XML description and turn it into the xend sexp needed to
|
|
|
|
* create the device. This is a temporary interface as the S-Expr interface
|
|
|
|
* will be replaced by XML-RPC in the future. However the XML format should
|
|
|
|
* stay valid over time.
|
|
|
|
*
|
|
|
|
* Returns the 0-terminated S-Expr string, or NULL in case of error.
|
|
|
|
* the caller must free() the returned value.
|
|
|
|
*/
|
|
|
|
char *
|
2007-02-14 16:16:13 +00:00
|
|
|
virParseXMLDevice(virConnectPtr conn, char *xmldesc, int hvm, int xendConfigVersion)
|
2006-11-16 18:11:28 +00:00
|
|
|
{
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlNodePtr node;
|
|
|
|
virBuffer buf;
|
|
|
|
|
|
|
|
buf.content = malloc(1000);
|
|
|
|
if (buf.content == NULL)
|
|
|
|
return (NULL);
|
|
|
|
buf.size = 1000;
|
|
|
|
buf.use = 0;
|
|
|
|
xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
|
|
|
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
|
|
|
XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
|
|
|
|
if (xml == NULL)
|
|
|
|
goto error;
|
|
|
|
node = xmlDocGetRootElement(xml);
|
|
|
|
if (node == NULL)
|
|
|
|
goto error;
|
|
|
|
if (xmlStrEqual(node->name, BAD_CAST "disk")) {
|
2007-02-14 16:16:13 +00:00
|
|
|
if (virDomainParseXMLDiskDesc(conn, node, &buf, hvm, xendConfigVersion) != 0)
|
2006-11-16 18:11:28 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual(node->name, BAD_CAST "interface")) {
|
2007-02-14 16:16:13 +00:00
|
|
|
if (virDomainParseXMLIfDesc(conn, node, &buf, hvm) != 0)
|
2006-11-16 18:11:28 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2007-02-07 13:50:18 +00:00
|
|
|
cleanup:
|
2006-11-16 18:11:28 +00:00
|
|
|
if (xml != NULL)
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
return buf.content;
|
2007-02-07 13:50:18 +00:00
|
|
|
error:
|
2006-11-16 18:11:28 +00:00
|
|
|
free(buf.content);
|
|
|
|
buf.content = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainXMLDevID:
|
|
|
|
* @domain: pointer to domain object
|
|
|
|
* @xmldesc: string with the XML description
|
|
|
|
* @class: Xen device class "vbd" or "vif" (OUT)
|
|
|
|
* @ref: Xen device reference (OUT)
|
|
|
|
*
|
|
|
|
* Set class according to XML root, and:
|
|
|
|
* - if disk, copy in ref the target name from description
|
|
|
|
* - if network, get MAC address from description, scan XenStore and
|
|
|
|
* copy in ref the corresponding vif number.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virDomainXMLDevID(virDomainPtr domain, char *xmldesc, char *class, char *ref)
|
|
|
|
{
|
|
|
|
xmlDocPtr xml = NULL;
|
|
|
|
xmlNodePtr node, cur;
|
|
|
|
xmlChar *attr = NULL;
|
2007-03-15 07:43:16 +00:00
|
|
|
#ifdef WITH_XEN
|
2006-11-20 16:42:16 +00:00
|
|
|
char *xref;
|
2007-03-15 07:43:16 +00:00
|
|
|
#endif /* WITH_XEN */
|
2006-11-17 00:10:51 +00:00
|
|
|
int ret = 0;
|
2006-11-16 18:11:28 +00:00
|
|
|
|
|
|
|
xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
|
|
|
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
|
|
|
XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
|
|
|
|
if (xml == NULL)
|
|
|
|
goto error;
|
|
|
|
node = xmlDocGetRootElement(xml);
|
|
|
|
if (node == NULL)
|
|
|
|
goto error;
|
|
|
|
if (xmlStrEqual(node->name, BAD_CAST "disk")) {
|
|
|
|
strcpy(class, "vbd");
|
|
|
|
for (cur = node->children; cur != NULL; cur = cur->next) {
|
|
|
|
if ((cur->type != XML_ELEMENT_NODE) ||
|
2007-02-07 13:50:18 +00:00
|
|
|
(!xmlStrEqual(cur->name, BAD_CAST "target"))) continue;
|
2006-11-16 18:11:28 +00:00
|
|
|
attr = xmlGetProp(cur, BAD_CAST "dev");
|
|
|
|
if (attr == NULL)
|
|
|
|
goto error;
|
2006-11-17 00:10:51 +00:00
|
|
|
strcpy(ref, (char *)attr);
|
2006-11-16 18:11:28 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (xmlStrEqual(node->name, BAD_CAST "interface")) {
|
|
|
|
strcpy(class, "vif");
|
|
|
|
for (cur = node->children; cur != NULL; cur = cur->next) {
|
|
|
|
if ((cur->type != XML_ELEMENT_NODE) ||
|
|
|
|
(!xmlStrEqual(cur->name, BAD_CAST "mac"))) continue;
|
|
|
|
attr = xmlGetProp(cur, BAD_CAST "address");
|
|
|
|
if (attr == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2007-03-15 07:43:16 +00:00
|
|
|
#ifdef WITH_XEN
|
2007-01-22 16:25:27 +00:00
|
|
|
xref = xenStoreDomainGetNetworkID(domain->conn, domain->id,
|
2007-02-07 13:50:18 +00:00
|
|
|
(char *) attr);
|
|
|
|
if (xref != NULL) {
|
|
|
|
strcpy(ref, xref);
|
|
|
|
free(xref);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-03-16 14:55:51 +00:00
|
|
|
#else /* without xen */
|
|
|
|
/* hack to avoid the warning that domain is unused */
|
|
|
|
if (domain->id < 0)
|
|
|
|
ret = -1;
|
2007-03-15 07:43:16 +00:00
|
|
|
#endif /* WITH_XEN */
|
2007-02-07 13:50:18 +00:00
|
|
|
|
2006-11-16 18:11:28 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2007-02-07 13:50:18 +00:00
|
|
|
error:
|
2006-11-16 18:11:28 +00:00
|
|
|
ret = -1;
|
2007-02-07 13:50:18 +00:00
|
|
|
cleanup:
|
2006-11-16 18:11:28 +00:00
|
|
|
if (xml != NULL)
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
if (attr != NULL)
|
|
|
|
xmlFree(attr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* !PROXY */
|
|
|
|
|
2006-09-12 01:34:26 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* c-indent-level: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 4
|
|
|
|
* End:
|
|
|
|
*/
|