mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 10:31:16 +00:00
Switch XM config file driver to use new domain APIs for XML to config conversion
This commit is contained in:
parent
547bd71a4a
commit
cb29913fb1
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
Fri Jul 25 15:03:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* src/xend_internal.c, src/xend_internal.h: Expose the
|
||||
xenDaemonFormatSxprChr and xenDaemonFormatSxprSound()
|
||||
methods to the XM driver
|
||||
* src/xm_internal.c, src/xm_internal.h: Switch to use
|
||||
new domain APIs for the XML -> config formatter
|
||||
* src/xml.h, src/xml.c: Remove unused Xen specific
|
||||
APIs which now live in xend_internal.c
|
||||
* tests/xmconfigdata/test-fullvirt-usb*.cfg: Add an
|
||||
explicit 'usb=1' config setting
|
||||
|
||||
Fri Jul 25 14:48:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* src/xend_internal.c, src/xend_internal.h: Remove the
|
||||
|
@ -4936,11 +4936,10 @@ xenDaemonFormatSxprGraphicsOld(virConnectPtr conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
xenDaemonFormatSxprChr(virConnectPtr conn,
|
||||
virDomainChrDefPtr def,
|
||||
virBufferPtr buf,
|
||||
const char *name)
|
||||
virBufferPtr buf)
|
||||
{
|
||||
const char *type = virDomainChrTypeToString(def->type);
|
||||
|
||||
@ -4955,20 +4954,20 @@ xenDaemonFormatSxprChr(virConnectPtr conn,
|
||||
case VIR_DOMAIN_CHR_TYPE_STDIO:
|
||||
case VIR_DOMAIN_CHR_TYPE_VC:
|
||||
case VIR_DOMAIN_CHR_TYPE_PTY:
|
||||
virBufferVSprintf(buf, "(%s %s)", name, type);
|
||||
virBufferVSprintf(buf, "%s", type);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_FILE:
|
||||
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
||||
virBufferVSprintf(buf, "(%s %s:%s)", name, type, def->data.file.path);
|
||||
virBufferVSprintf(buf, "%s:%s", type, def->data.file.path);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_DEV:
|
||||
virBufferVSprintf(buf, "(%s %s)", name, def->data.file.path);
|
||||
virBufferVSprintf(buf, "%s", def->data.file.path);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_TCP:
|
||||
virBufferVSprintf(buf, "(%s %s:%s:%s%s)", name,
|
||||
virBufferVSprintf(buf, "%s:%s:%s%s",
|
||||
(def->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW ?
|
||||
"tcp" : "telnet"),
|
||||
(def->data.tcp.host ? def->data.tcp.host : ""),
|
||||
@ -4977,7 +4976,7 @@ xenDaemonFormatSxprChr(virConnectPtr conn,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||
virBufferVSprintf(buf, "(%s %s:%s:%s@%s:%s)", name, type,
|
||||
virBufferVSprintf(buf, "%s:%s:%s@%s:%s", type,
|
||||
(def->data.udp.connectHost ? def->data.udp.connectHost : ""),
|
||||
(def->data.udp.connectService ? def->data.udp.connectService : ""),
|
||||
(def->data.udp.bindHost ? def->data.udp.bindHost : ""),
|
||||
@ -4985,7 +4984,7 @@ xenDaemonFormatSxprChr(virConnectPtr conn,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||
virBufferVSprintf(buf, "(%s %s:%s%s)", name, type,
|
||||
virBufferVSprintf(buf, "%s:%s%s", type,
|
||||
def->data.nix.path,
|
||||
def->data.nix.listen ? ",listen" : "");
|
||||
break;
|
||||
@ -5182,17 +5181,14 @@ xenDaemonFormatSxprNet(virConnectPtr conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
xenDaemonFormatSxprSound(virConnectPtr conn,
|
||||
virDomainSoundDefPtr sound,
|
||||
virBufferPtr buf)
|
||||
{
|
||||
const char *str;
|
||||
virDomainSoundDefPtr prev = NULL;
|
||||
if (!sound)
|
||||
return 0;
|
||||
|
||||
virBufferAddLit(buf, "(soundhw '");
|
||||
while (sound) {
|
||||
if (!(str = virDomainSoundModelTypeToString(sound->model))) {
|
||||
virXendError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
@ -5204,7 +5200,6 @@ xenDaemonFormatSxprSound(virConnectPtr conn,
|
||||
sound = sound->next;
|
||||
}
|
||||
|
||||
virBufferAddLit(buf, "')");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -5396,14 +5391,18 @@ xenDaemonFormatSxpr(virConnectPtr conn,
|
||||
}
|
||||
|
||||
if (def->parallels) {
|
||||
if (xenDaemonFormatSxprChr(conn, def->parallels, &buf, "parallel") < 0)
|
||||
virBufferAddLit(&buf, "(parallel ");
|
||||
if (xenDaemonFormatSxprChr(conn, def->parallels, &buf) < 0)
|
||||
goto error;
|
||||
virBufferAddLit(&buf, ")");
|
||||
} else {
|
||||
virBufferAddLit(&buf, "(parallel none)");
|
||||
}
|
||||
if (def->serials) {
|
||||
if (xenDaemonFormatSxprChr(conn, def->serials, &buf, "serial") < 0)
|
||||
virBufferAddLit(&buf, "(serial ");
|
||||
if (xenDaemonFormatSxprChr(conn, def->serials, &buf) < 0)
|
||||
goto error;
|
||||
virBufferAddLit(&buf, ")");
|
||||
} else {
|
||||
virBufferAddLit(&buf, "(serial none)");
|
||||
}
|
||||
@ -5411,8 +5410,12 @@ xenDaemonFormatSxpr(virConnectPtr conn,
|
||||
if (def->localtime)
|
||||
virBufferAddLit(&buf, "(localtime 1)");
|
||||
|
||||
if (xenDaemonFormatSxprSound(conn, def->sounds, &buf) < 0)
|
||||
goto error;
|
||||
if (def->sounds) {
|
||||
virBufferAddLit(&buf, "(soundhw '");
|
||||
if (xenDaemonFormatSxprSound(conn, def->sounds, &buf) < 0)
|
||||
goto error;
|
||||
virBufferAddLit(&buf, "')");
|
||||
}
|
||||
}
|
||||
|
||||
/* get the device emulation model */
|
||||
|
@ -113,6 +113,15 @@ xenDaemonParseSxprChar(virConnectPtr conn,
|
||||
const char *value,
|
||||
const char *tty);
|
||||
|
||||
int
|
||||
xenDaemonFormatSxprChr(virConnectPtr conn,
|
||||
virDomainChrDefPtr def,
|
||||
virBufferPtr buf);
|
||||
int
|
||||
xenDaemonFormatSxprSound(virConnectPtr conn,
|
||||
virDomainSoundDefPtr sound,
|
||||
virBufferPtr buf);
|
||||
|
||||
char *
|
||||
xenDaemonFormatSxpr(virConnectPtr conn,
|
||||
virDomainDefPtr def,
|
||||
|
1170
src/xm_internal.c
1170
src/xm_internal.c
File diff suppressed because it is too large
Load Diff
@ -25,9 +25,8 @@
|
||||
#ifndef _LIBVIRT_XM_INTERNAL_H_
|
||||
#define _LIBVIRT_XM_INTERNAL_H_
|
||||
|
||||
#include "libvirt/libvirt.h"
|
||||
#include "conf.h"
|
||||
#include "internal.h"
|
||||
#include "conf.h"
|
||||
#include "domain_conf.h"
|
||||
|
||||
extern struct xenUnifiedDriver xenXMDriver;
|
||||
|
288
src/xml.c
288
src/xml.c
@ -368,291 +368,3 @@ virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#if WITH_XEN
|
||||
#ifndef PROXY
|
||||
/**
|
||||
* virConvertCpuSet:
|
||||
* @conn: connection
|
||||
* @str: pointer to a Xen or user provided CPU set string pointer
|
||||
* @maxcpu: number of CPUs on the node, if 0 4096 will be used
|
||||
*
|
||||
* Parse the given CPU set string and convert it to a range based
|
||||
* string.
|
||||
*
|
||||
* Returns a new string which must be freed by the caller or NULL in
|
||||
* case of error.
|
||||
*/
|
||||
char *
|
||||
virConvertCpuSet(virConnectPtr conn, const char *str, int maxcpu) {
|
||||
int ret;
|
||||
char *res, *cpuset;
|
||||
const char *cur = str;
|
||||
|
||||
if (str == NULL)
|
||||
return(NULL);
|
||||
|
||||
if (maxcpu <= 0)
|
||||
maxcpu = 4096;
|
||||
|
||||
if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
|
||||
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ret = virDomainCpuSetParse(conn, &cur, 0, cpuset, maxcpu);
|
||||
if (ret < 0) {
|
||||
VIR_FREE(cpuset);
|
||||
return(NULL);
|
||||
}
|
||||
res = virDomainCpuSetFormat(conn, cpuset, maxcpu);
|
||||
VIR_FREE(cpuset);
|
||||
return (res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virBuildSoundStringFromXML
|
||||
* @sound buffer to populate
|
||||
* @len size of preallocated buffer 'sound'
|
||||
* @ctxt xml context to pull sound info from
|
||||
*
|
||||
* Builds a string of the form m1,m2,m3 from the different sound models
|
||||
* in the xml. String must be free'd by caller.
|
||||
*
|
||||
* Returns string on success, NULL on error
|
||||
*/
|
||||
char * virBuildSoundStringFromXML(virConnectPtr conn,
|
||||
xmlXPathContextPtr ctxt) {
|
||||
|
||||
int nb_nodes, size = 256;
|
||||
char *sound;
|
||||
xmlNodePtr *nodes = NULL;
|
||||
|
||||
if (VIR_ALLOC_N(sound, size + 1) < 0) {
|
||||
virXMLError(conn, VIR_ERR_NO_MEMORY,
|
||||
_("failed to allocate sound string"), 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nb_nodes = virXPathNodeSet("/domain/devices/sound", ctxt, &nodes);
|
||||
if (nb_nodes > 0) {
|
||||
int i;
|
||||
for (i = 0; i < nb_nodes && size > 0; i++) {
|
||||
char *model = NULL;
|
||||
int collision = 0;
|
||||
|
||||
model = (char *) xmlGetProp(nodes[i], (xmlChar *) "model");
|
||||
if (!model) {
|
||||
virXMLError(conn, VIR_ERR_XML_ERROR,
|
||||
_("no model for sound device"), 0);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!is_sound_model_valid(model)) {
|
||||
virXMLError(conn, VIR_ERR_XML_ERROR,
|
||||
_("unknown sound model type"), 0);
|
||||
VIR_FREE(model);
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Check for duplicates in currently built string
|
||||
if (*sound)
|
||||
collision = is_sound_model_conflict(model, sound);
|
||||
|
||||
// If no collision, add to string
|
||||
if (!collision) {
|
||||
if (*sound && (size >= (strlen(model) + 1))) {
|
||||
strncat(sound, ",", size--);
|
||||
} else if (*sound || size < strlen(model)) {
|
||||
VIR_FREE(model);
|
||||
continue;
|
||||
}
|
||||
strncat(sound, model, size);
|
||||
size -= strlen(model);
|
||||
}
|
||||
|
||||
VIR_FREE(model);
|
||||
}
|
||||
}
|
||||
VIR_FREE(nodes);
|
||||
return sound;
|
||||
error:
|
||||
VIR_FREE(nodes);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
virDomainParseXMLOSDescHVMChar(virConnectPtr conn,
|
||||
char *buf,
|
||||
size_t buflen,
|
||||
xmlNodePtr node)
|
||||
{
|
||||
xmlChar *type = NULL;
|
||||
xmlChar *path = NULL;
|
||||
xmlChar *bindHost = NULL;
|
||||
xmlChar *bindService = NULL;
|
||||
xmlChar *connectHost = NULL;
|
||||
xmlChar *connectService = NULL;
|
||||
xmlChar *mode = NULL;
|
||||
xmlChar *protocol = NULL;
|
||||
xmlNodePtr cur;
|
||||
|
||||
type = xmlGetProp(node, BAD_CAST "type");
|
||||
|
||||
if (type != NULL) {
|
||||
cur = node->children;
|
||||
while (cur != NULL) {
|
||||
if (cur->type == XML_ELEMENT_NODE) {
|
||||
if (xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||
if (mode == NULL)
|
||||
mode = xmlGetProp(cur, BAD_CAST "mode");
|
||||
|
||||
if (STREQ((const char *)type, "dev") ||
|
||||
STREQ((const char *)type, "file") ||
|
||||
STREQ((const char *)type, "pipe") ||
|
||||
STREQ((const char *)type, "unix")) {
|
||||
if (path == NULL)
|
||||
path = xmlGetProp(cur, BAD_CAST "path");
|
||||
|
||||
} else if (STREQ((const char *)type, "udp") ||
|
||||
STREQ((const char *)type, "tcp")) {
|
||||
if (mode == NULL ||
|
||||
STREQ((const char *)mode, "connect")) {
|
||||
|
||||
if (connectHost == NULL)
|
||||
connectHost = xmlGetProp(cur, BAD_CAST "host");
|
||||
if (connectService == NULL)
|
||||
connectService = xmlGetProp(cur, BAD_CAST "service");
|
||||
} else {
|
||||
if (bindHost == NULL)
|
||||
bindHost = xmlGetProp(cur, BAD_CAST "host");
|
||||
if (bindService == NULL)
|
||||
bindService = xmlGetProp(cur, BAD_CAST "service");
|
||||
}
|
||||
|
||||
if (STREQ((const char*)type, "udp")) {
|
||||
xmlFree(mode);
|
||||
mode = NULL;
|
||||
}
|
||||
}
|
||||
} else if (xmlStrEqual(cur->name, BAD_CAST "protocol")) {
|
||||
if (protocol == NULL)
|
||||
protocol = xmlGetProp(cur, BAD_CAST "type");
|
||||
}
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == NULL ||
|
||||
STREQ((const char *)type, "pty")) {
|
||||
strncpy(buf, "pty", buflen);
|
||||
} else if (STREQ((const char *)type, "null") ||
|
||||
STREQ((const char *)type, "stdio") ||
|
||||
STREQ((const char *)type, "vc")) {
|
||||
snprintf(buf, buflen, "%s", type);
|
||||
} else if (STREQ((const char *)type, "file") ||
|
||||
STREQ((const char *)type, "dev") ||
|
||||
STREQ((const char *)type, "pipe")) {
|
||||
if (path == NULL) {
|
||||
virXMLError(conn, VIR_ERR_XML_ERROR,
|
||||
_("Missing source path attribute for char device"), 0);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (STREQ((const char *)type, "dev"))
|
||||
strncpy(buf, (const char *)path, buflen);
|
||||
else
|
||||
snprintf(buf, buflen, "%s:%s", type, path);
|
||||
} else if (STREQ((const char *)type, "tcp")) {
|
||||
int telnet = 0;
|
||||
if (protocol != NULL &&
|
||||
STREQ((const char *)protocol, "telnet"))
|
||||
telnet = 1;
|
||||
|
||||
if (mode == NULL ||
|
||||
STREQ((const char *)mode, "connect")) {
|
||||
if (connectHost == NULL) {
|
||||
virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Missing source host attribute for char device"), 0);
|
||||
goto cleanup;
|
||||
}
|
||||
if (connectService == NULL) {
|
||||
virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Missing source service attribute for char device"), 0);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snprintf(buf, buflen, "%s:%s:%s",
|
||||
(telnet ? "telnet" : "tcp"),
|
||||
connectHost, connectService);
|
||||
} else {
|
||||
if (bindHost == NULL) {
|
||||
virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Missing source host attribute for char device"), 0);
|
||||
goto cleanup;
|
||||
}
|
||||
if (bindService == NULL) {
|
||||
virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Missing source service attribute for char device"), 0);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snprintf(buf, buflen, "%s:%s:%s,listen",
|
||||
(telnet ? "telnet" : "tcp"),
|
||||
bindHost, bindService);
|
||||
}
|
||||
} else if (STREQ((const char *)type, "udp")) {
|
||||
if (connectService == NULL) {
|
||||
virXMLError(conn, VIR_ERR_XML_ERROR,
|
||||
_("Missing source service attribute for char device"), 0);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snprintf(buf, buflen, "udp:%s:%s@%s:%s",
|
||||
connectHost ? (const char *)connectHost : "",
|
||||
connectService,
|
||||
bindHost ? (const char *)bindHost : "",
|
||||
bindService ? (const char *)bindService : "");
|
||||
} else if (STREQ((const char *)type, "unix")) {
|
||||
if (path == NULL) {
|
||||
virXMLError(conn, VIR_ERR_XML_ERROR,
|
||||
_("Missing source path attribute for char device"), 0);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (mode == NULL ||
|
||||
STREQ((const char *)mode, "connect")) {
|
||||
snprintf(buf, buflen, "%s:%s", type, path);
|
||||
} else {
|
||||
snprintf(buf, buflen, "%s:%s,listen", type, path);
|
||||
}
|
||||
}
|
||||
buf[buflen-1] = '\0';
|
||||
|
||||
xmlFree(mode);
|
||||
xmlFree(protocol);
|
||||
xmlFree(type);
|
||||
xmlFree(bindHost);
|
||||
xmlFree(bindService);
|
||||
xmlFree(connectHost);
|
||||
xmlFree(connectService);
|
||||
xmlFree(path);
|
||||
|
||||
return 0;
|
||||
|
||||
cleanup:
|
||||
xmlFree(mode);
|
||||
xmlFree(protocol);
|
||||
xmlFree(type);
|
||||
xmlFree(bindHost);
|
||||
xmlFree(bindService);
|
||||
xmlFree(connectHost);
|
||||
xmlFree(connectService);
|
||||
xmlFree(path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* !PROXY */
|
||||
|
||||
#endif /* WITH_XEN */
|
||||
|
12
src/xml.h
12
src/xml.h
@ -39,16 +39,4 @@ int virXPathNodeSet (const char *xpath,
|
||||
char * virXMLPropString(xmlNodePtr node,
|
||||
const char *name);
|
||||
|
||||
char *
|
||||
virConvertCpuSet(virConnectPtr conn, const char *str, int maxcpu);
|
||||
|
||||
char * virBuildSoundStringFromXML(virConnectPtr conn,
|
||||
xmlXPathContextPtr ctxt);
|
||||
|
||||
int
|
||||
virDomainParseXMLOSDescHVMChar(virConnectPtr conn,
|
||||
char *buf,
|
||||
size_t buflen,
|
||||
xmlNodePtr node);
|
||||
|
||||
#endif /* __VIR_XML_H__ */
|
||||
|
@ -14,6 +14,7 @@ on_poweroff = "destroy"
|
||||
on_reboot = "restart"
|
||||
on_crash = "restart"
|
||||
device_model = "/usr/lib/xen/bin/qemu-dm"
|
||||
usb = 1
|
||||
usbdevice = "mouse"
|
||||
sdl = 0
|
||||
vnc = 1
|
||||
|
@ -14,6 +14,7 @@ on_poweroff = "destroy"
|
||||
on_reboot = "restart"
|
||||
on_crash = "restart"
|
||||
device_model = "/usr/lib/xen/bin/qemu-dm"
|
||||
usb = 1
|
||||
usbdevice = "tablet"
|
||||
sdl = 0
|
||||
vnc = 1
|
||||
|
Loading…
Reference in New Issue
Block a user