Rename buffer functions

This commit is contained in:
Daniel P. Berrange 2007-06-26 22:21:22 +00:00
parent 3d6a119de8
commit 675ba3170d
5 changed files with 129 additions and 124 deletions

View File

@ -1,4 +1,9 @@
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 * qemud/conf.c, qemud/uuid.c, qemud/uuid.h: Rename the
UUID functions to not include QEMU in name. UUID functions to not include QEMU in name.

View File

@ -1,7 +1,7 @@
/* /*
* 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 * See COPYING.LIB for the License of this software
* *
@ -17,7 +17,7 @@
#include "buf.h" #include "buf.h"
/** /**
* bufferGrow: * virBufferGrow:
* @buf: the buffer * @buf: the buffer
* @len: the minimum free size to allocate on top of existing used space * @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 * Returns the new available space or -1 in case of error
*/ */
static int static int
bufferGrow(bufferPtr buf, unsigned int len) virBufferGrow(virBufferPtr buf, unsigned int len)
{ {
int size; int size;
char *newbuf; char *newbuf;
@ -46,7 +46,7 @@ bufferGrow(bufferPtr buf, unsigned int len)
} }
/** /**
* bufferAdd: * virBufferAdd:
* @buf: the buffer to dump * @buf: the buffer to dump
* @str: the string * @str: the string
* @len: the number of bytes to add * @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. * Returns 0 successful, -1 in case of internal or API error.
*/ */
int int
bufferAdd(bufferPtr buf, const char *str, int len) virBufferAdd(virBufferPtr buf, const char *str, int len)
{ {
unsigned int needSize; unsigned int needSize;
@ -72,7 +72,7 @@ bufferAdd(bufferPtr buf, const char *str, int len)
needSize = buf->use + len + 2; needSize = buf->use + len + 2;
if (needSize > buf->size) { if (needSize > buf->size) {
if (!bufferGrow(buf, needSize - buf->use)) { if (!virBufferGrow(buf, needSize - buf->use)) {
return (-1); return (-1);
} }
} }
@ -83,10 +83,10 @@ bufferAdd(bufferPtr buf, const char *str, int len)
return (0); return (0);
} }
bufferPtr virBufferPtr
bufferNew(unsigned int size) virBufferNew(unsigned int size)
{ {
bufferPtr buf; virBufferPtr buf;
if (!(buf = malloc(sizeof(*buf)))) return NULL; if (!(buf = malloc(sizeof(*buf)))) return NULL;
if (size && (buf->content = malloc(size))==NULL) { if (size && (buf->content = malloc(size))==NULL) {
@ -100,7 +100,7 @@ bufferNew(unsigned int size)
} }
void void
bufferFree(bufferPtr buf) virBufferFree(virBufferPtr buf)
{ {
if (buf) { if (buf) {
if (buf->content) if (buf->content)
@ -110,13 +110,13 @@ bufferFree(bufferPtr buf)
} }
/** /**
* bufferContentAndFree: * virBufferContentAndFree:
* @buf: Buffer * @buf: Buffer
* *
* Return the content from the buffer and free (only) the buffer structure. * Return the content from the buffer and free (only) the buffer structure.
*/ */
char * char *
bufferContentAndFree (bufferPtr buf) virBufferContentAndFree (virBufferPtr buf)
{ {
char *content = buf->content; char *content = buf->content;
@ -125,7 +125,7 @@ bufferContentAndFree (bufferPtr buf)
} }
/** /**
* bufferVSprintf: * virBufferVSprintf:
* @buf: the buffer to dump * @buf: the buffer to dump
* @format: the format * @format: the format
* @argptr: the variable list of arguments * @argptr: the variable list of arguments
@ -135,7 +135,7 @@ bufferContentAndFree (bufferPtr buf)
* Returns 0 successful, -1 in case of internal or API error. * Returns 0 successful, -1 in case of internal or API error.
*/ */
int int
bufferVSprintf(bufferPtr buf, const char *format, ...) virBufferVSprintf(virBufferPtr buf, const char *format, ...)
{ {
int size, count; int size, count;
va_list locarg, argptr; va_list locarg, argptr;
@ -150,7 +150,7 @@ bufferVSprintf(bufferPtr buf, const char *format, ...)
locarg)) < 0) || (count >= size - 1)) { locarg)) < 0) || (count >= size - 1)) {
buf->content[buf->use] = 0; buf->content[buf->use] = 0;
va_end(locarg); va_end(locarg);
if (bufferGrow(buf, 1000) < 0) { if (virBufferGrow(buf, 1000) < 0) {
return (-1); return (-1);
} }
size = buf->size - buf->use - 1; size = buf->size - buf->use - 1;
@ -163,7 +163,7 @@ bufferVSprintf(bufferPtr buf, const char *format, ...)
} }
/** /**
* bufferStrcat: * virBufferStrcat:
* @buf: the buffer to dump * @buf: the buffer to dump
* @argptr: the variable list of strings, the last argument must be NULL * @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. * Returns 0 successful, -1 in case of internal or API error.
*/ */
int int
bufferStrcat(bufferPtr buf, ...) virBufferStrcat(virBufferPtr buf, ...)
{ {
va_list ap; va_list ap;
char *str; char *str;
@ -184,7 +184,7 @@ bufferStrcat(bufferPtr buf, ...)
unsigned int needSize = buf->use + len + 2; unsigned int needSize = buf->use + len + 2;
if (needSize > buf->size) { if (needSize > buf->size) {
if (!bufferGrow(buf, needSize - buf->use)) if (!virBufferGrow(buf, needSize - buf->use))
return -1; return -1;
} }
memcpy(&buf->content[buf->use], str, len); memcpy(&buf->content[buf->use], str, len);

View File

@ -1,37 +1,37 @@
/* /*
* 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 * See COPYING.LIB for the License of this software
* *
* Daniel Veillard <veillard@redhat.com> * Daniel Veillard <veillard@redhat.com>
*/ */
#ifndef __QEMUD_BUF_H__ #ifndef __VIR_BUFFER_H__
#define __QEMUD_BUF_H__ #define __VIR_BUFFER_H__
#include "internal.h" #include "internal.h"
/** /**
* buffer: * virBuffer:
* *
* A buffer structure. * A buffer structure.
*/ */
typedef struct _buffer buffer; typedef struct _virBuffer virBuffer;
typedef buffer *bufferPtr; typedef virBuffer *virBufferPtr;
struct _buffer { struct _virBuffer {
char *content; /* The buffer content UTF8 */ char *content; /* The buffer content UTF8 */
unsigned int use; /* The buffer size used */ unsigned int use; /* The buffer size used */
unsigned int size; /* The buffer size */ unsigned int size; /* The buffer size */
}; };
bufferPtr bufferNew(unsigned int size); virBufferPtr virBufferNew(unsigned int size);
void bufferFree(bufferPtr buf); void virBufferFree(virBufferPtr buf);
char *bufferContentAndFree(bufferPtr buf); char *virBufferContentAndFree(virBufferPtr buf);
int bufferAdd(bufferPtr buf, const char *str, int len); int virBufferAdd(virBufferPtr buf, const char *str, int len);
int bufferVSprintf(bufferPtr buf, const char *format, ...) int virBufferVSprintf(virBufferPtr buf, const char *format, ...)
ATTRIBUTE_FORMAT(printf, 2, 3); ATTRIBUTE_FORMAT(printf, 2, 3);
int bufferStrcat(bufferPtr buf, ...); int virBufferStrcat(virBufferPtr buf, ...);
#endif /* __QEMUD_BUF_H__ */ #endif /* __VIR_BUFFER_H__ */

View File

@ -2446,14 +2446,14 @@ char *qemudGenerateXML(struct qemud_driver *driver,
struct qemud_vm *vm, struct qemud_vm *vm,
struct qemud_vm_def *def, struct qemud_vm_def *def,
int live) { int live) {
bufferPtr buf = 0; virBufferPtr buf = 0;
unsigned char *uuid; unsigned char *uuid;
struct qemud_vm_disk_def *disk; struct qemud_vm_disk_def *disk;
struct qemud_vm_net_def *net; struct qemud_vm_net_def *net;
const char *type = NULL; const char *type = NULL;
int n; int n;
buf = bufferNew (QEMUD_MAX_XML_LEN); buf = virBufferNew (QEMUD_MAX_XML_LEN);
if (!buf) if (!buf)
goto no_memory; goto no_memory;
@ -2474,50 +2474,50 @@ char *qemudGenerateXML(struct qemud_driver *driver,
} }
if (qemudIsActiveVM(vm) && live) { 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; goto no_memory;
} else { } else {
if (bufferVSprintf(buf, "<domain type='%s'>\n", type) < 0) if (virBufferVSprintf(buf, "<domain type='%s'>\n", type) < 0)
goto no_memory; 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; goto no_memory;
uuid = def->uuid; 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[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5], uuid[6], uuid[7], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[8], uuid[9], uuid[10], uuid[11],
uuid[12], uuid[13], uuid[14], uuid[15]) < 0) uuid[12], uuid[13], uuid[14], uuid[15]) < 0)
goto no_memory; 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; 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; 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; goto no_memory;
if (bufferAdd(buf, " <os>\n", -1) < 0) if (virBufferAdd(buf, " <os>\n", -1) < 0)
goto no_memory; goto no_memory;
if (def->virtType == QEMUD_VIRT_QEMU) { 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) def->os.arch, def->os.machine, def->os.type) < 0)
goto no_memory; goto no_memory;
} else { } 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; goto no_memory;
} }
if (def->os.kernel[0]) 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; goto no_memory;
if (def->os.initrd[0]) 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; goto no_memory;
if (def->os.cmdline[0]) 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; goto no_memory;
for (n = 0 ; n < def->os.nBootDevs ; n++) { for (n = 0 ; n < def->os.nBootDevs ; n++) {
@ -2536,38 +2536,38 @@ char *qemudGenerateXML(struct qemud_driver *driver,
boottype = "net"; boottype = "net";
break; break;
} }
if (bufferVSprintf(buf, " <boot dev='%s'/>\n", boottype) < 0) if (virBufferVSprintf(buf, " <boot dev='%s'/>\n", boottype) < 0)
goto no_memory; goto no_memory;
} }
if (bufferAdd(buf, " </os>\n", -1) < 0) if (virBufferAdd(buf, " </os>\n", -1) < 0)
goto no_memory; goto no_memory;
if (def->features & QEMUD_FEATURE_ACPI) { if (def->features & QEMUD_FEATURE_ACPI) {
if (bufferAdd(buf, " <features>\n", -1) < 0) if (virBufferAdd(buf, " <features>\n", -1) < 0)
goto no_memory; goto no_memory;
if (bufferAdd(buf, " <acpi/>\n", -1) < 0) if (virBufferAdd(buf, " <acpi/>\n", -1) < 0)
goto no_memory; goto no_memory;
if (bufferAdd(buf, " </features>\n", -1) < 0) if (virBufferAdd(buf, " </features>\n", -1) < 0)
goto no_memory; 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; goto no_memory;
if (def->noReboot) { 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; goto no_memory;
} else { } 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; 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; goto no_memory;
if (bufferAdd(buf, " <devices>\n", -1) < 0) if (virBufferAdd(buf, " <devices>\n", -1) < 0)
goto no_memory; 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; goto no_memory;
disk = def->disks; disk = def->disks;
@ -2585,21 +2585,21 @@ char *qemudGenerateXML(struct qemud_driver *driver,
"cdrom", "cdrom",
"floppy", "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) types[disk->type], devices[disk->device]) < 0)
goto no_memory; 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; 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; goto no_memory;
if (disk->readonly) if (disk->readonly)
if (bufferAdd(buf, " <readonly/>\n", -1) < 0) if (virBufferAdd(buf, " <readonly/>\n", -1) < 0)
goto no_memory; goto no_memory;
if (bufferVSprintf(buf, " </disk>\n") < 0) if (virBufferVSprintf(buf, " </disk>\n") < 0)
goto no_memory; goto no_memory;
disk = disk->next; disk = disk->next;
@ -2616,42 +2616,42 @@ char *qemudGenerateXML(struct qemud_driver *driver,
"network", "network",
"bridge", "bridge",
}; };
if (bufferVSprintf(buf, " <interface type='%s'>\n", if (virBufferVSprintf(buf, " <interface type='%s'>\n",
types[net->type]) < 0) types[net->type]) < 0)
goto no_memory; 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[0], net->mac[1], net->mac[2],
net->mac[3], net->mac[4], net->mac[5]) < 0) net->mac[3], net->mac[4], net->mac[5]) < 0)
goto no_memory; goto no_memory;
switch (net->type) { switch (net->type) {
case QEMUD_NET_NETWORK: 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; goto no_memory;
if (net->dst.network.ifname[0] != '\0') { 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; goto no_memory;
} }
break; break;
case QEMUD_NET_ETHERNET: case QEMUD_NET_ETHERNET:
if (net->dst.ethernet.ifname[0] != '\0') { 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; goto no_memory;
} }
if (net->dst.ethernet.script[0] != '\0') { 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; goto no_memory;
} }
break; break;
case QEMUD_NET_BRIDGE: 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; goto no_memory;
if (net->dst.bridge.ifname[0] != '\0') { 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; goto no_memory;
} }
break; break;
@ -2660,17 +2660,17 @@ char *qemudGenerateXML(struct qemud_driver *driver,
case QEMUD_NET_CLIENT: case QEMUD_NET_CLIENT:
case QEMUD_NET_MCAST: case QEMUD_NET_MCAST:
if (net->dst.socket.address[0] != '\0') { 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) net->dst.socket.address, net->dst.socket.port) < 0)
goto no_memory; goto no_memory;
} else { } else {
if (bufferVSprintf(buf, " <source port='%d'/>\n", if (virBufferVSprintf(buf, " <source port='%d'/>\n",
net->dst.socket.port) < 0) net->dst.socket.port) < 0)
goto no_memory; goto no_memory;
} }
} }
if (bufferVSprintf(buf, " </interface>\n") < 0) if (virBufferVSprintf(buf, " </interface>\n") < 0)
goto no_memory; goto no_memory;
net = net->next; net = net->next;
@ -2678,20 +2678,20 @@ char *qemudGenerateXML(struct qemud_driver *driver,
switch (def->graphicsType) { switch (def->graphicsType) {
case QEMUD_GRAPHICS_VNC: case QEMUD_GRAPHICS_VNC:
if (bufferAdd(buf, " <graphics type='vnc'", -1) < 0) if (virBufferAdd(buf, " <graphics type='vnc'", -1) < 0)
goto no_memory; goto no_memory;
if (def->vncPort && if (def->vncPort &&
bufferVSprintf(buf, " port='%d'", virBufferVSprintf(buf, " port='%d'",
qemudIsActiveVM(vm) && live ? def->vncActivePort : def->vncPort) < 0) qemudIsActiveVM(vm) && live ? def->vncActivePort : def->vncPort) < 0)
goto no_memory; goto no_memory;
if (bufferAdd(buf, "/>\n", -1) < 0) if (virBufferAdd(buf, "/>\n", -1) < 0)
goto no_memory; goto no_memory;
break; break;
case QEMUD_GRAPHICS_SDL: 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; goto no_memory;
break; break;
@ -2703,19 +2703,19 @@ char *qemudGenerateXML(struct qemud_driver *driver,
if (def->graphicsType == QEMUD_GRAPHICS_VNC) { if (def->graphicsType == QEMUD_GRAPHICS_VNC) {
} }
if (bufferAdd(buf, " </devices>\n", -1) < 0) if (virBufferAdd(buf, " </devices>\n", -1) < 0)
goto no_memory; goto no_memory;
if (bufferAdd(buf, "</domain>\n", -1) < 0) if (virBufferAdd(buf, "</domain>\n", -1) < 0)
goto no_memory; goto no_memory;
return bufferContentAndFree (buf); return virBufferContentAndFree (buf);
no_memory: no_memory:
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
cleanup: cleanup:
if (buf) bufferFree (buf); if (buf) virBufferFree (buf);
return NULL; return NULL;
} }
@ -2723,21 +2723,21 @@ char *qemudGenerateXML(struct qemud_driver *driver,
char *qemudGenerateNetworkXML(struct qemud_driver *driver, char *qemudGenerateNetworkXML(struct qemud_driver *driver,
struct qemud_network *network, struct qemud_network *network,
struct qemud_network_def *def) { struct qemud_network_def *def) {
bufferPtr buf = 0; virBufferPtr buf = 0;
unsigned char *uuid; unsigned char *uuid;
buf = bufferNew (QEMUD_MAX_XML_LEN); buf = virBufferNew (QEMUD_MAX_XML_LEN);
if (!buf) if (!buf)
goto no_memory; goto no_memory;
if (bufferVSprintf(buf, "<network>\n") < 0) if (virBufferVSprintf(buf, "<network>\n") < 0)
goto no_memory; 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; goto no_memory;
uuid = def->uuid; 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[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5], uuid[6], uuid[7], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[8], uuid[9], uuid[10], uuid[11],
@ -2746,67 +2746,67 @@ char *qemudGenerateNetworkXML(struct qemud_driver *driver,
if (def->forward) { if (def->forward) {
if (def->forwardDev[0]) { if (def->forwardDev[0]) {
bufferVSprintf(buf, " <forward dev='%s'/>\n", virBufferVSprintf(buf, " <forward dev='%s'/>\n",
def->forwardDev); def->forwardDev);
} else { } else {
bufferAdd(buf, " <forward/>\n", -1); virBufferAdd(buf, " <forward/>\n", -1);
} }
} }
bufferAdd(buf, " <bridge", -1); virBufferAdd(buf, " <bridge", -1);
if (qemudIsActiveNetwork(network)) { if (qemudIsActiveNetwork(network)) {
if (bufferVSprintf(buf, " name='%s'", network->bridge) < 0) if (virBufferVSprintf(buf, " name='%s'", network->bridge) < 0)
goto no_memory; goto no_memory;
} else if (def->bridge[0]) { } else if (def->bridge[0]) {
if (bufferVSprintf(buf, " name='%s'", def->bridge) < 0) if (virBufferVSprintf(buf, " name='%s'", def->bridge) < 0)
goto no_memory; goto no_memory;
} }
if (bufferVSprintf(buf, " stp='%s' forwardDelay='%d' />\n", if (virBufferVSprintf(buf, " stp='%s' forwardDelay='%d' />\n",
def->disableSTP ? "off" : "on", def->disableSTP ? "off" : "on",
def->forwardDelay) < 0) def->forwardDelay) < 0)
goto no_memory; goto no_memory;
if (def->ipAddress[0] || def->netmask[0]) { if (def->ipAddress[0] || def->netmask[0]) {
if (bufferAdd(buf, " <ip", -1) < 0) if (virBufferAdd(buf, " <ip", -1) < 0)
goto no_memory; goto no_memory;
if (def->ipAddress[0] && if (def->ipAddress[0] &&
bufferVSprintf(buf, " address='%s'", def->ipAddress) < 0) virBufferVSprintf(buf, " address='%s'", def->ipAddress) < 0)
goto no_memory; goto no_memory;
if (def->netmask[0] && if (def->netmask[0] &&
bufferVSprintf(buf, " netmask='%s'", def->netmask) < 0) virBufferVSprintf(buf, " netmask='%s'", def->netmask) < 0)
goto no_memory; goto no_memory;
if (bufferAdd(buf, ">\n", -1) < 0) if (virBufferAdd(buf, ">\n", -1) < 0)
goto no_memory; goto no_memory;
if (def->ranges) { if (def->ranges) {
struct qemud_dhcp_range_def *range = 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; goto no_memory;
while (range) { 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) range->start, range->end) < 0)
goto no_memory; goto no_memory;
range = range->next; range = range->next;
} }
if (bufferAdd(buf, " </dhcp>\n", -1) < 0) if (virBufferAdd(buf, " </dhcp>\n", -1) < 0)
goto no_memory; goto no_memory;
} }
if (bufferAdd(buf, " </ip>\n", -1) < 0) if (virBufferAdd(buf, " </ip>\n", -1) < 0)
goto no_memory; goto no_memory;
} }
if (bufferAdd(buf, "</network>\n", -1) < 0) if (virBufferAdd(buf, "</network>\n", -1) < 0)
goto no_memory; goto no_memory;
return bufferContentAndFree (buf); return virBufferContentAndFree (buf);
no_memory: no_memory:
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
if (buf) bufferFree (buf); if (buf) virBufferFree (buf);
return NULL; return NULL;
} }

View File

@ -1431,7 +1431,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
int i, j, r; int i, j, r;
int have_kqemu = 0; int have_kqemu = 0;
int have_kvm = 0; int have_kvm = 0;
bufferPtr xml; virBufferPtr xml;
/* Really, this never fails - look at the man-page. */ /* Really, this never fails - look at the man-page. */
uname (&utsname); uname (&utsname);
@ -1440,13 +1440,13 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
have_kvm = access ("/dev/kvm", F_OK) == 0; have_kvm = access ("/dev/kvm", F_OK) == 0;
/* Construct the XML. */ /* Construct the XML. */
xml = bufferNew (1024); xml = virBufferNew (1024);
if (!xml) { if (!xml) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL; return NULL;
} }
r = bufferVSprintf (xml, r = virBufferVSprintf (xml,
"\ "\
<capabilities>\n\ <capabilities>\n\
<host>\n\ <host>\n\
@ -1457,7 +1457,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
utsname.machine); utsname.machine);
if (r == -1) { if (r == -1) {
vir_buffer_failed: vir_buffer_failed:
bufferFree (xml); virBufferFree (xml);
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return 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; else if (strcmp (utsname.machine, "x86_64") == 0) i = 1;
if (i >= 0) { if (i >= 0) {
/* For the default (PC-like) guest, qemudArchs[0] or [1]. */ /* For the default (PC-like) guest, qemudArchs[0] or [1]. */
r = bufferVSprintf (xml, r = virBufferVSprintf (xml,
"\ "\
\n\ \n\
<guest>\n\ <guest>\n\
@ -1482,7 +1482,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
for (j = 0; qemudArchs[i].machines[j]; ++j) { for (j = 0; qemudArchs[i].machines[j]; ++j) {
r = bufferVSprintf (xml, r = virBufferVSprintf (xml,
"\ "\
<machine>%s</machine>\n", <machine>%s</machine>\n",
qemudArchs[i].machines[j]); qemudArchs[i].machines[j]);
@ -1490,20 +1490,20 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
} }
if (have_kqemu) { if (have_kqemu) {
r = bufferAdd (xml, r = virBufferAdd (xml,
"\ "\
<domain type=\"kqemu\"/>\n", -1); <domain type=\"kqemu\"/>\n", -1);
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
} }
if (have_kvm) { if (have_kvm) {
r = bufferAdd (xml, r = virBufferAdd (xml,
"\ "\
<domain type=\"kvm\">\n\ <domain type=\"kvm\">\n\
<emulator>/usr/bin/qemu-kvm</emulator>\n\ <emulator>/usr/bin/qemu-kvm</emulator>\n\
</domain>\n", -1); </domain>\n", -1);
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
} }
r = bufferAdd (xml, r = virBufferAdd (xml,
"\ "\
</arch>\n\ </arch>\n\
</guest>\n", -1); </guest>\n", -1);
@ -1511,7 +1511,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
/* The "other" PC architecture needs emulation. */ /* The "other" PC architecture needs emulation. */
i = i ^ 1; i = i ^ 1;
r = bufferVSprintf (xml, r = virBufferVSprintf (xml,
"\ "\
\n\ \n\
<guest>\n\ <guest>\n\
@ -1525,13 +1525,13 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
qemudArchs[i].binary); qemudArchs[i].binary);
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
for (j = 0; qemudArchs[i].machines[j]; ++j) { for (j = 0; qemudArchs[i].machines[j]; ++j) {
r = bufferVSprintf (xml, r = virBufferVSprintf (xml,
"\ "\
<machine>%s</machine>\n", <machine>%s</machine>\n",
qemudArchs[i].machines[j]); qemudArchs[i].machines[j]);
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
} }
r = bufferAdd (xml, r = virBufferAdd (xml,
"\ "\
</arch>\n\ </arch>\n\
</guest>\n", -1); </guest>\n", -1);
@ -1540,7 +1540,7 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
/* The non-PC architectures, qemudArchs[>=2]. */ /* The non-PC architectures, qemudArchs[>=2]. */
for (i = 2; qemudArchs[i].arch; ++i) { for (i = 2; qemudArchs[i].arch; ++i) {
r = bufferVSprintf (xml, r = virBufferVSprintf (xml,
"\ "\
\n\ \n\
<guest>\n\ <guest>\n\
@ -1554,13 +1554,13 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
qemudArchs[i].binary); qemudArchs[i].binary);
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
for (j = 0; qemudArchs[i].machines[j]; ++j) { for (j = 0; qemudArchs[i].machines[j]; ++j) {
r = bufferVSprintf (xml, r = virBufferVSprintf (xml,
"\ "\
<machine>%s</machine>\n", <machine>%s</machine>\n",
qemudArchs[i].machines[j]); qemudArchs[i].machines[j]);
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
} }
r = bufferAdd (xml, r = virBufferAdd (xml,
"\ "\
</arch>\n\ </arch>\n\
</guest>\n", -1); </guest>\n", -1);
@ -1568,12 +1568,12 @@ char *qemudGetCapabilities(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
} }
/* Finish off. */ /* Finish off. */
r = bufferAdd (xml, r = virBufferAdd (xml,
"\ "\
</capabilities>\n", -1); </capabilities>\n", -1);
if (r == -1) goto vir_buffer_failed; if (r == -1) goto vir_buffer_failed;
return bufferContentAndFree(xml); return virBufferContentAndFree(xml);
} }