提交 675ba317 编写于 作者: D Daniel P. Berrange

Rename buffer functions

上级 3d6a119d
Tue Jun 26 18:10:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
Tue Jun 26 18:21:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/conf.c, qemud/driver.c, qemud/buf.c, qemud/buf.h:
Rename the buffer functions to match those in src/ directory.
Tue Jun 26 18:18:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* qemud/conf.c, qemud/uuid.c, qemud/uuid.h: Rename the
UUID functions to not include QEMU in name.
......
/*
* buf.c: buffers for qemud
* buf.c: buffers for libvirt
*
* Copyright (C) 2005 Red Hat, Inc.
* Copyright (C) 2005-2007 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
......@@ -17,7 +17,7 @@
#include "buf.h"
/**
* bufferGrow:
* virBufferGrow:
* @buf: the buffer
* @len: the minimum free size to allocate on top of existing used space
*
......@@ -26,7 +26,7 @@
* Returns the new available space or -1 in case of error
*/
static int
bufferGrow(bufferPtr buf, unsigned int len)
virBufferGrow(virBufferPtr buf, unsigned int len)
{
int size;
char *newbuf;
......@@ -46,7 +46,7 @@ bufferGrow(bufferPtr buf, unsigned int len)
}
/**
* bufferAdd:
* virBufferAdd:
* @buf: the buffer to dump
* @str: the string
* @len: the number of bytes to add
......@@ -57,7 +57,7 @@ bufferGrow(bufferPtr buf, unsigned int len)
* Returns 0 successful, -1 in case of internal or API error.
*/
int
bufferAdd(bufferPtr buf, const char *str, int len)
virBufferAdd(virBufferPtr buf, const char *str, int len)
{
unsigned int needSize;
......@@ -72,7 +72,7 @@ bufferAdd(bufferPtr buf, const char *str, int len)
needSize = buf->use + len + 2;
if (needSize > buf->size) {
if (!bufferGrow(buf, needSize - buf->use)) {
if (!virBufferGrow(buf, needSize - buf->use)) {
return (-1);
}
}
......@@ -83,10 +83,10 @@ bufferAdd(bufferPtr buf, const char *str, int len)
return (0);
}
bufferPtr
bufferNew(unsigned int size)
virBufferPtr
virBufferNew(unsigned int size)
{
bufferPtr buf;
virBufferPtr buf;
if (!(buf = malloc(sizeof(*buf)))) return NULL;
if (size && (buf->content = malloc(size))==NULL) {
......@@ -100,7 +100,7 @@ bufferNew(unsigned int size)
}
void
bufferFree(bufferPtr buf)
virBufferFree(virBufferPtr buf)
{
if (buf) {
if (buf->content)
......@@ -110,13 +110,13 @@ bufferFree(bufferPtr buf)
}
/**
* bufferContentAndFree:
* virBufferContentAndFree:
* @buf: Buffer
*
* Return the content from the buffer and free (only) the buffer structure.
*/
char *
bufferContentAndFree (bufferPtr buf)
virBufferContentAndFree (virBufferPtr buf)
{
char *content = buf->content;
......@@ -125,7 +125,7 @@ bufferContentAndFree (bufferPtr buf)
}
/**
* bufferVSprintf:
* virBufferVSprintf:
* @buf: the buffer to dump
* @format: the format
* @argptr: the variable list of arguments
......@@ -135,7 +135,7 @@ bufferContentAndFree (bufferPtr buf)
* Returns 0 successful, -1 in case of internal or API error.
*/
int
bufferVSprintf(bufferPtr buf, const char *format, ...)
virBufferVSprintf(virBufferPtr buf, const char *format, ...)
{
int size, count;
va_list locarg, argptr;
......@@ -150,7 +150,7 @@ bufferVSprintf(bufferPtr buf, const char *format, ...)
locarg)) < 0) || (count >= size - 1)) {
buf->content[buf->use] = 0;
va_end(locarg);
if (bufferGrow(buf, 1000) < 0) {
if (virBufferGrow(buf, 1000) < 0) {
return (-1);
}
size = buf->size - buf->use - 1;
......@@ -163,7 +163,7 @@ bufferVSprintf(bufferPtr buf, const char *format, ...)
}
/**
* bufferStrcat:
* virBufferStrcat:
* @buf: the buffer to dump
* @argptr: the variable list of strings, the last argument must be NULL
*
......@@ -172,7 +172,7 @@ bufferVSprintf(bufferPtr buf, const char *format, ...)
* Returns 0 successful, -1 in case of internal or API error.
*/
int
bufferStrcat(bufferPtr buf, ...)
virBufferStrcat(virBufferPtr buf, ...)
{
va_list ap;
char *str;
......@@ -184,7 +184,7 @@ bufferStrcat(bufferPtr buf, ...)
unsigned int needSize = buf->use + len + 2;
if (needSize > buf->size) {
if (!bufferGrow(buf, needSize - buf->use))
if (!virBufferGrow(buf, needSize - buf->use))
return -1;
}
memcpy(&buf->content[buf->use], str, len);
......
/*
* buf.h: buffers for qemud
* buf.h: buffers for libvirt
*
* Copyright (C) 2005 Red Hat, Inc.
* Copyright (C) 2005-2007 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
* Daniel Veillard <veillard@redhat.com>
*/
#ifndef __QEMUD_BUF_H__
#define __QEMUD_BUF_H__
#ifndef __VIR_BUFFER_H__
#define __VIR_BUFFER_H__
#include "internal.h"
/**
* buffer:
* virBuffer:
*
* A buffer structure.
*/
typedef struct _buffer buffer;
typedef buffer *bufferPtr;
struct _buffer {
typedef struct _virBuffer virBuffer;
typedef virBuffer *virBufferPtr;
struct _virBuffer {
char *content; /* The buffer content UTF8 */
unsigned int use; /* The buffer size used */
unsigned int size; /* The buffer size */
};
bufferPtr bufferNew(unsigned int size);
void bufferFree(bufferPtr buf);
char *bufferContentAndFree(bufferPtr buf);
int bufferAdd(bufferPtr buf, const char *str, int len);
int bufferVSprintf(bufferPtr buf, const char *format, ...)
virBufferPtr virBufferNew(unsigned int size);
void virBufferFree(virBufferPtr buf);
char *virBufferContentAndFree(virBufferPtr buf);
int virBufferAdd(virBufferPtr buf, const char *str, int len);
int virBufferVSprintf(virBufferPtr buf, const char *format, ...)
ATTRIBUTE_FORMAT(printf, 2, 3);
int bufferStrcat(bufferPtr buf, ...);
int virBufferStrcat(virBufferPtr buf, ...);
#endif /* __QEMUD_BUF_H__ */
#endif /* __VIR_BUFFER_H__ */
......@@ -2446,14 +2446,14 @@ char *qemudGenerateXML(struct qemud_driver *driver,
struct qemud_vm *vm,
struct qemud_vm_def *def,
int live) {
bufferPtr buf = 0;
virBufferPtr buf = 0;
unsigned char *uuid;
struct qemud_vm_disk_def *disk;
struct qemud_vm_net_def *net;
const char *type = NULL;
int n;
buf = bufferNew (QEMUD_MAX_XML_LEN);
buf = virBufferNew (QEMUD_MAX_XML_LEN);
if (!buf)
goto no_memory;
......@@ -2474,50 +2474,50 @@ char *qemudGenerateXML(struct qemud_driver *driver,
}
if (qemudIsActiveVM(vm) && live) {
if (bufferVSprintf(buf, "<domain type='%s' id='%d'>\n", type, vm->id) < 0)
if (virBufferVSprintf(buf, "<domain type='%s' id='%d'>\n", type, vm->id) < 0)
goto no_memory;
} else {
if (bufferVSprintf(buf, "<domain type='%s'>\n", type) < 0)
if (virBufferVSprintf(buf, "<domain type='%s'>\n", type) < 0)
goto no_memory;
}
if (bufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0)
if (virBufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0)
goto no_memory;
uuid = def->uuid;
if (bufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n",
if (virBufferVSprintf(buf, " <uuid>%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]) < 0)
goto no_memory;
if (bufferVSprintf(buf, " <memory>%d</memory>\n", def->maxmem) < 0)
if (virBufferVSprintf(buf, " <memory>%d</memory>\n", def->maxmem) < 0)
goto no_memory;
if (bufferVSprintf(buf, " <currentMemory>%d</currentMemory>\n", def->memory) < 0)
if (virBufferVSprintf(buf, " <currentMemory>%d</currentMemory>\n", def->memory) < 0)
goto no_memory;
if (bufferVSprintf(buf, " <vcpu>%d</vcpu>\n", def->vcpus) < 0)
if (virBufferVSprintf(buf, " <vcpu>%d</vcpu>\n", def->vcpus) < 0)
goto no_memory;
if (bufferAdd(buf, " <os>\n", -1) < 0)
if (virBufferAdd(buf, " <os>\n", -1) < 0)
goto no_memory;
if (def->virtType == QEMUD_VIRT_QEMU) {
if (bufferVSprintf(buf, " <type arch='%s' machine='%s'>%s</type>\n",
if (virBufferVSprintf(buf, " <type arch='%s' machine='%s'>%s</type>\n",
def->os.arch, def->os.machine, def->os.type) < 0)
goto no_memory;
} else {
if (bufferVSprintf(buf, " <type>%s</type>\n", def->os.type) < 0)
if (virBufferVSprintf(buf, " <type>%s</type>\n", def->os.type) < 0)
goto no_memory;
}
if (def->os.kernel[0])
if (bufferVSprintf(buf, " <kernel>%s</kernel>\n", def->os.kernel) < 0)
if (virBufferVSprintf(buf, " <kernel>%s</kernel>\n", def->os.kernel) < 0)
goto no_memory;
if (def->os.initrd[0])
if (bufferVSprintf(buf, " <initrd>%s</initrd>\n", def->os.initrd) < 0)
if (virBufferVSprintf(buf, " <initrd>%s</initrd>\n", def->os.initrd) < 0)
goto no_memory;
if (def->os.cmdline[0])
if (bufferVSprintf(buf, " <cmdline>%s</cmdline>\n", def->os.cmdline) < 0)
if (virBufferVSprintf(buf, " <cmdline>%s</cmdline>\n", def->os.cmdline) < 0)
goto no_memory;
for (n = 0 ; n < def->os.nBootDevs ; n++) {
......@@ -2536,38 +2536,38 @@ char *qemudGenerateXML(struct qemud_driver *driver,
boottype = "net";
break;
}
if (bufferVSprintf(buf, " <boot dev='%s'/>\n", boottype) < 0)
if (virBufferVSprintf(buf, " <boot dev='%s'/>\n", boottype) < 0)
goto no_memory;
}
if (bufferAdd(buf, " </os>\n", -1) < 0)
if (virBufferAdd(buf, " </os>\n", -1) < 0)
goto no_memory;
if (def->features & QEMUD_FEATURE_ACPI) {
if (bufferAdd(buf, " <features>\n", -1) < 0)
if (virBufferAdd(buf, " <features>\n", -1) < 0)
goto no_memory;
if (bufferAdd(buf, " <acpi/>\n", -1) < 0)
if (virBufferAdd(buf, " <acpi/>\n", -1) < 0)
goto no_memory;
if (bufferAdd(buf, " </features>\n", -1) < 0)
if (virBufferAdd(buf, " </features>\n", -1) < 0)
goto no_memory;
}
if (bufferAdd(buf, " <on_poweroff>destroy</on_poweroff>\n", -1) < 0)
if (virBufferAdd(buf, " <on_poweroff>destroy</on_poweroff>\n", -1) < 0)
goto no_memory;
if (def->noReboot) {
if (bufferAdd(buf, " <on_reboot>destroy</on_reboot>\n", -1) < 0)
if (virBufferAdd(buf, " <on_reboot>destroy</on_reboot>\n", -1) < 0)
goto no_memory;
} else {
if (bufferAdd(buf, " <on_reboot>restart</on_reboot>\n", -1) < 0)
if (virBufferAdd(buf, " <on_reboot>restart</on_reboot>\n", -1) < 0)
goto no_memory;
}
if (bufferAdd(buf, " <on_crash>destroy</on_crash>\n", -1) < 0)
if (virBufferAdd(buf, " <on_crash>destroy</on_crash>\n", -1) < 0)
goto no_memory;
if (bufferAdd(buf, " <devices>\n", -1) < 0)
if (virBufferAdd(buf, " <devices>\n", -1) < 0)
goto no_memory;
if (bufferVSprintf(buf, " <emulator>%s</emulator>\n", def->os.binary) < 0)
if (virBufferVSprintf(buf, " <emulator>%s</emulator>\n", def->os.binary) < 0)
goto no_memory;
disk = def->disks;
......@@ -2585,21 +2585,21 @@ char *qemudGenerateXML(struct qemud_driver *driver,
"cdrom",
"floppy",
};
if (bufferVSprintf(buf, " <disk type='%s' device='%s'>\n",
if (virBufferVSprintf(buf, " <disk type='%s' device='%s'>\n",
types[disk->type], devices[disk->device]) < 0)
goto no_memory;
if (bufferVSprintf(buf, " <source %s='%s'/>\n", typeAttrs[disk->type], disk->src) < 0)
if (virBufferVSprintf(buf, " <source %s='%s'/>\n", typeAttrs[disk->type], disk->src) < 0)
goto no_memory;
if (bufferVSprintf(buf, " <target dev='%s'/>\n", disk->dst) < 0)
if (virBufferVSprintf(buf, " <target dev='%s'/>\n", disk->dst) < 0)
goto no_memory;
if (disk->readonly)
if (bufferAdd(buf, " <readonly/>\n", -1) < 0)
if (virBufferAdd(buf, " <readonly/>\n", -1) < 0)
goto no_memory;
if (bufferVSprintf(buf, " </disk>\n") < 0)
if (virBufferVSprintf(buf, " </disk>\n") < 0)
goto no_memory;
disk = disk->next;
......@@ -2616,42 +2616,42 @@ char *qemudGenerateXML(struct qemud_driver *driver,
"network",
"bridge",
};
if (bufferVSprintf(buf, " <interface type='%s'>\n",
if (virBufferVSprintf(buf, " <interface type='%s'>\n",
types[net->type]) < 0)
goto no_memory;
if (bufferVSprintf(buf, " <mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n",
if (virBufferVSprintf(buf, " <mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n",
net->mac[0], net->mac[1], net->mac[2],
net->mac[3], net->mac[4], net->mac[5]) < 0)
goto no_memory;
switch (net->type) {
case QEMUD_NET_NETWORK:
if (bufferVSprintf(buf, " <source network='%s'/>\n", net->dst.network.name) < 0)
if (virBufferVSprintf(buf, " <source network='%s'/>\n", net->dst.network.name) < 0)
goto no_memory;
if (net->dst.network.ifname[0] != '\0') {
if (bufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.network.ifname) < 0)
if (virBufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.network.ifname) < 0)
goto no_memory;
}
break;
case QEMUD_NET_ETHERNET:
if (net->dst.ethernet.ifname[0] != '\0') {
if (bufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.ethernet.ifname) < 0)
if (virBufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.ethernet.ifname) < 0)
goto no_memory;
}
if (net->dst.ethernet.script[0] != '\0') {
if (bufferVSprintf(buf, " <script path='%s'/>\n", net->dst.ethernet.script) < 0)
if (virBufferVSprintf(buf, " <script path='%s'/>\n", net->dst.ethernet.script) < 0)
goto no_memory;
}
break;
case QEMUD_NET_BRIDGE:
if (bufferVSprintf(buf, " <source bridge='%s'/>\n", net->dst.bridge.brname) < 0)
if (virBufferVSprintf(buf, " <source bridge='%s'/>\n", net->dst.bridge.brname) < 0)
goto no_memory;
if (net->dst.bridge.ifname[0] != '\0') {
if (bufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.bridge.ifname) < 0)
if (virBufferVSprintf(buf, " <target dev='%s'/>\n", net->dst.bridge.ifname) < 0)
goto no_memory;
}
break;
......@@ -2660,17 +2660,17 @@ char *qemudGenerateXML(struct qemud_driver *driver,
case QEMUD_NET_CLIENT:
case QEMUD_NET_MCAST:
if (net->dst.socket.address[0] != '\0') {
if (bufferVSprintf(buf, " <source address='%s' port='%d'/>\n",
if (virBufferVSprintf(buf, " <source address='%s' port='%d'/>\n",
net->dst.socket.address, net->dst.socket.port) < 0)
goto no_memory;
} else {
if (bufferVSprintf(buf, " <source port='%d'/>\n",
if (virBufferVSprintf(buf, " <source port='%d'/>\n",
net->dst.socket.port) < 0)
goto no_memory;
}
}
if (bufferVSprintf(buf, " </interface>\n") < 0)
if (virBufferVSprintf(buf, " </interface>\n") < 0)
goto no_memory;
net = net->next;
......@@ -2678,20 +2678,20 @@ char *qemudGenerateXML(struct qemud_driver *driver,
switch (def->graphicsType) {
case QEMUD_GRAPHICS_VNC:
if (bufferAdd(buf, " <graphics type='vnc'", -1) < 0)
if (virBufferAdd(buf, " <graphics type='vnc'", -1) < 0)
goto no_memory;
if (def->vncPort &&
bufferVSprintf(buf, " port='%d'",
virBufferVSprintf(buf, " port='%d'",
qemudIsActiveVM(vm) && live ? def->vncActivePort : def->vncPort) < 0)
goto no_memory;
if (bufferAdd(buf, "/>\n", -1) < 0)
if (virBufferAdd(buf, "/>\n", -1) < 0)
goto no_memory;
break;
case QEMUD_GRAPHICS_SDL:
if (bufferAdd(buf, " <graphics type='sdl'/>\n", -1) < 0)
if (virBufferAdd(buf, " <graphics type='sdl'/>\n", -1) < 0)
goto no_memory;
break;
......@@ -2703,19 +2703,19 @@ char *qemudGenerateXML(struct qemud_driver *driver,
if (def->graphicsType == QEMUD_GRAPHICS_VNC) {
}
if (bufferAdd(buf, " </devices>\n", -1) < 0)
if (virBufferAdd(buf, " </devices>\n", -1) < 0)
goto no_memory;
if (bufferAdd(buf, "</domain>\n", -1) < 0)
if (virBufferAdd(buf, "</domain>\n", -1) < 0)
goto no_memory;
return bufferContentAndFree (buf);
return virBufferContentAndFree (buf);
no_memory:
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
cleanup:
if (buf) bufferFree (buf);
if (buf) virBufferFree (buf);
return NULL;
}
......@@ -2723,21 +2723,21 @@ char *qemudGenerateXML(struct qemud_driver *driver,
char *qemudGenerateNetworkXML(struct qemud_driver *driver,
struct qemud_network *network,
struct qemud_network_def *def) {
bufferPtr buf = 0;
virBufferPtr buf = 0;
unsigned char *uuid;
buf = bufferNew (QEMUD_MAX_XML_LEN);
buf = virBufferNew (QEMUD_MAX_XML_LEN);
if (!buf)
goto no_memory;
if (bufferVSprintf(buf, "<network>\n") < 0)
if (virBufferVSprintf(buf, "<network>\n") < 0)
goto no_memory;
if (bufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0)
if (virBufferVSprintf(buf, " <name>%s</name>\n", def->name) < 0)
goto no_memory;
uuid = def->uuid;
if (bufferVSprintf(buf, " <uuid>%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x</uuid>\n",
if (virBufferVSprintf(buf, " <uuid>%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],
......@@ -2746,67 +2746,67 @@ char *qemudGenerateNetworkXML(struct qemud_driver *driver,
if (def->forward) {
if (def->forwardDev[0]) {
bufferVSprintf(buf, " <forward dev='%s'/>\n",
virBufferVSprintf(buf, " <forward dev='%s'/>\n",
def->forwardDev);
} else {
bufferAdd(buf, " <forward/>\n", -1);
virBufferAdd(buf, " <forward/>\n", -1);
}
}
bufferAdd(buf, " <bridge", -1);
virBufferAdd(buf, " <bridge", -1);
if (qemudIsActiveNetwork(network)) {
if (bufferVSprintf(buf, " name='%s'", network->bridge) < 0)
if (virBufferVSprintf(buf, " name='%s'", network->bridge) < 0)
goto no_memory;
} else if (def->bridge[0]) {
if (bufferVSprintf(buf, " name='%s'", def->bridge) < 0)
if (virBufferVSprintf(buf, " name='%s'", def->bridge) < 0)
goto no_memory;
}
if (bufferVSprintf(buf, " stp='%s' forwardDelay='%d' />\n",
if (virBufferVSprintf(buf, " stp='%s' forwardDelay='%d' />\n",
def->disableSTP ? "off" : "on",
def->forwardDelay) < 0)
goto no_memory;
if (def->ipAddress[0] || def->netmask[0]) {
if (bufferAdd(buf, " <ip", -1) < 0)
if (virBufferAdd(buf, " <ip", -1) < 0)
goto no_memory;
if (def->ipAddress[0] &&
bufferVSprintf(buf, " address='%s'", def->ipAddress) < 0)
virBufferVSprintf(buf, " address='%s'", def->ipAddress) < 0)
goto no_memory;
if (def->netmask[0] &&
bufferVSprintf(buf, " netmask='%s'", def->netmask) < 0)
virBufferVSprintf(buf, " netmask='%s'", def->netmask) < 0)
goto no_memory;
if (bufferAdd(buf, ">\n", -1) < 0)
if (virBufferAdd(buf, ">\n", -1) < 0)
goto no_memory;
if (def->ranges) {
struct qemud_dhcp_range_def *range = def->ranges;
if (bufferAdd(buf, " <dhcp>\n", -1) < 0)
if (virBufferAdd(buf, " <dhcp>\n", -1) < 0)
goto no_memory;
while (range) {
if (bufferVSprintf(buf, " <range start='%s' end='%s' />\n",
if (virBufferVSprintf(buf, " <range start='%s' end='%s' />\n",
range->start, range->end) < 0)
goto no_memory;
range = range->next;
}
if (bufferAdd(buf, " </dhcp>\n", -1) < 0)
if (virBufferAdd(buf, " </dhcp>\n", -1) < 0)
goto no_memory;
}
if (bufferAdd(buf, " </ip>\n", -1) < 0)
if (virBufferAdd(buf, " </ip>\n", -1) < 0)
goto no_memory;
}
if (bufferAdd(buf, "</network>\n", -1) < 0)
if (virBufferAdd(buf, "</network>\n", -1) < 0)
goto no_memory;
return bufferContentAndFree (buf);
return virBufferContentAndFree (buf);
no_memory:
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
if (buf) bufferFree (buf);
if (buf) virBufferFree (buf);
return NULL;
}
......
......@@ -1431,7 +1431,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
int i, j, r;
int have_kqemu = 0;
int have_kvm = 0;
bufferPtr xml;
virBufferPtr xml;
/* Really, this never fails - look at the man-page. */
uname (&utsname);
......@@ -1440,13 +1440,13 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
have_kvm = access ("/dev/kvm", F_OK) == 0;
/* Construct the XML. */
xml = bufferNew (1024);
xml = virBufferNew (1024);
if (!xml) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
r = bufferVSprintf (xml,
r = virBufferVSprintf (xml,
"\
<capabilities>\n\
<host>\n\
......@@ -1457,7 +1457,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
utsname.machine);
if (r == -1) {
vir_buffer_failed:
bufferFree (xml);
virBufferFree (xml);
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
......@@ -1467,7 +1467,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
else if (strcmp (utsname.machine, "x86_64") == 0) i = 1;
if (i >= 0) {
/* For the default (PC-like) guest, qemudArchs[0] or [1]. */
r = bufferVSprintf (xml,
r = virBufferVSprintf (xml,
"\
\n\
<guest>\n\
......@@ -1482,7 +1482,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
if (r == -1) goto vir_buffer_failed;
for (j = 0; qemudArchs[i].machines[j]; ++j) {
r = bufferVSprintf (xml,
r = virBufferVSprintf (xml,
"\
<machine>%s</machine>\n",
qemudArchs[i].machines[j]);
......@@ -1490,20 +1490,20 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
}
if (have_kqemu) {
r = bufferAdd (xml,
r = virBufferAdd (xml,
"\
<domain type=\"kqemu\"/>\n", -1);
if (r == -1) goto vir_buffer_failed;
}
if (have_kvm) {
r = bufferAdd (xml,
r = virBufferAdd (xml,
"\
<domain type=\"kvm\">\n\
<emulator>/usr/bin/qemu-kvm</emulator>\n\
</domain>\n", -1);
if (r == -1) goto vir_buffer_failed;
}
r = bufferAdd (xml,
r = virBufferAdd (xml,
"\
</arch>\n\
</guest>\n", -1);
......@@ -1511,7 +1511,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
/* The "other" PC architecture needs emulation. */
i = i ^ 1;
r = bufferVSprintf (xml,
r = virBufferVSprintf (xml,
"\
\n\
<guest>\n\
......@@ -1525,13 +1525,13 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
qemudArchs[i].binary);
if (r == -1) goto vir_buffer_failed;
for (j = 0; qemudArchs[i].machines[j]; ++j) {
r = bufferVSprintf (xml,
r = virBufferVSprintf (xml,
"\
<machine>%s</machine>\n",
qemudArchs[i].machines[j]);
if (r == -1) goto vir_buffer_failed;
}
r = bufferAdd (xml,
r = virBufferAdd (xml,
"\
</arch>\n\
</guest>\n", -1);
......@@ -1540,7 +1540,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
/* The non-PC architectures, qemudArchs[>=2]. */
for (i = 2; qemudArchs[i].arch; ++i) {
r = bufferVSprintf (xml,
r = virBufferVSprintf (xml,
"\
\n\
<guest>\n\
......@@ -1554,13 +1554,13 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
qemudArchs[i].binary);
if (r == -1) goto vir_buffer_failed;
for (j = 0; qemudArchs[i].machines[j]; ++j) {
r = bufferVSprintf (xml,
r = virBufferVSprintf (xml,
"\
<machine>%s</machine>\n",
qemudArchs[i].machines[j]);
if (r == -1) goto vir_buffer_failed;
}
r = bufferAdd (xml,
r = virBufferAdd (xml,
"\
</arch>\n\
</guest>\n", -1);
......@@ -1568,12 +1568,12 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
}
/* Finish off. */
r = bufferAdd (xml,
r = virBufferAdd (xml,
"\
</capabilities>\n", -1);
if (r == -1) goto vir_buffer_failed;
return bufferContentAndFree(xml);
return virBufferContentAndFree(xml);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册