+Fri Jul 25 15:21:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
+
+ * src/xml.c, src/xml.h: Take a virConnectPtr object as param
+ for all methods to allow proper error reporting.
+ * src/lxc_conf.c, src/domain_conf.c, src/network_conf.c,
+ src/storage_conf.c, src/test.c: Pass virConnect object
+ to XML routines
+
Fri Jul 25 15:03:27 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/xend_internal.c, src/xend_internal.h: Expose the
int *val,
int defaultVal)
{
- char *tmp = virXPathString(xpath, ctxt);
+ char *tmp = virXPathString(conn, xpath, ctxt);
if (tmp == NULL) {
*val = defaultVal;
} else {
def->id = -1;
/* Find out what type of QEMU virtualization to use */
- if (!(tmp = virXPathString("string(./@type)", ctxt))) {
+ if (!(tmp = virXPathString(conn, "string(./@type)", ctxt))) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing domain type attribute"));
goto error;
VIR_FREE(tmp);
/* Extract domain name */
- if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
+ if (!(def->name = virXPathString(conn, "string(./name[1])", ctxt))) {
virDomainReportError(conn, VIR_ERR_NO_NAME, NULL);
goto error;
}
/* Extract domain uuid */
- tmp = virXPathString("string(./uuid[1])", ctxt);
+ tmp = virXPathString(conn, "string(./uuid[1])", ctxt);
if (!tmp) {
int err;
if ((err = virUUIDGenerate(def->uuid))) {
}
/* Extract domain memory */
- if (virXPathULong("string(./memory[1])", ctxt, &def->maxmem) < 0) {
+ if (virXPathULong(conn, "string(./memory[1])", ctxt, &def->maxmem) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("missing memory element"));
goto error;
}
- if (virXPathULong("string(./currentMemory[1])", ctxt, &def->memory) < 0)
+ if (virXPathULong(conn, "string(./currentMemory[1])", ctxt, &def->memory) < 0)
def->memory = def->maxmem;
- if (virXPathULong("string(./vcpu[1])", ctxt, &def->vcpus) < 0)
+ if (virXPathULong(conn, "string(./vcpu[1])", ctxt, &def->vcpus) < 0)
def->vcpus = 1;
- tmp = virXPathString("string(./vcpu[1]/@cpuset)", ctxt);
+ tmp = virXPathString(conn, "string(./vcpu[1]/@cpuset)", ctxt);
if (tmp) {
char *set = tmp;
def->cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
VIR_FREE(tmp);
}
- if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) > 0) {
+ if ((n = virXPathNodeSet(conn, "./features/*", ctxt, &nodes)) > 0) {
for (i = 0 ; i < n ; i++) {
int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
if (val < 0) {
goto error;
- tmp = virXPathString("string(./clock/@offset)", ctxt);
+ tmp = virXPathString(conn, "string(./clock/@offset)", ctxt);
if (tmp && STREQ(tmp, "localtime"))
def->localtime = 1;
VIR_FREE(tmp);
- def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
- def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt);
+ def->os.bootloader = virXPathString(conn, "string(./bootloader)", ctxt);
+ def->os.bootloaderArgs = virXPathString(conn, "string(./bootloader_args)", ctxt);
- def->os.type = virXPathString("string(./os/type[1])", ctxt);
+ def->os.type = virXPathString(conn, "string(./os/type[1])", ctxt);
if (!def->os.type) {
if (def->os.bootloader) {
def->os.type = strdup("xen");
goto error;
}
- def->os.arch = virXPathString("string(./os/type[1]/@arch)", ctxt);
+ def->os.arch = virXPathString(conn, "string(./os/type[1]/@arch)", ctxt);
if (!def->os.arch) {
const char *defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type);
if (defaultArch == NULL) {
}
}
- def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt);
+ def->os.machine = virXPathString(conn, "string(./os/type[1]/@machine)", ctxt);
if (!def->os.machine) {
const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
def->os.type,
}
if (!def->os.bootloader) {
- def->os.kernel = virXPathString("string(./os/kernel[1])", ctxt);
- def->os.initrd = virXPathString("string(./os/initrd[1])", ctxt);
- def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
- def->os.root = virXPathString("string(./os/root[1])", ctxt);
- def->os.loader = virXPathString("string(./os/loader[1])", ctxt);
+ def->os.kernel = virXPathString(conn, "string(./os/kernel[1])", ctxt);
+ def->os.initrd = virXPathString(conn, "string(./os/initrd[1])", ctxt);
+ def->os.cmdline = virXPathString(conn, "string(./os/cmdline[1])", ctxt);
+ def->os.root = virXPathString(conn, "string(./os/root[1])", ctxt);
+ def->os.loader = virXPathString(conn, "string(./os/loader[1])", ctxt);
/* analysis of the boot devices */
- if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./os/boot", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract boot device"));
goto error;
VIR_FREE(nodes);
}
- def->emulator = virXPathString("string(./devices/emulator[1])", ctxt);
+ def->emulator = virXPathString(conn, "string(./devices/emulator[1])", ctxt);
if (!def->emulator) {
const char *type = virDomainVirtTypeToString(def->virtType);
if (!type) {
}
/* analysis of the disk devices */
- if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/disk", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract disk devices"));
goto error;
VIR_FREE(nodes);
/* analysis of the network devices */
- if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/interface", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract network devices"));
goto error;
/* analysis of the character devices */
- if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/parallel", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract parallel devices"));
goto error;
}
VIR_FREE(nodes);
- if ((n = virXPathNodeSet("./devices/serial", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/serial", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract serial devices"));
goto error;
* devices which is the legacy syntax for the same thing
*/
if (def->serials == NULL) {
- if ((node = virXPathNode("./devices/console[1]", ctxt)) != NULL) {
+ if ((node = virXPathNode(conn, "./devices/console[1]", ctxt)) != NULL) {
virDomainChrDefPtr chr = virDomainChrDefParseXML(conn,
node);
if (!chr)
/* analysis of the input devices */
- if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/input", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract input devices"));
goto error;
VIR_FREE(nodes);
/* analysis of the input devices */
- if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/graphics", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract graphics devices"));
goto error;
/* analysis of the sound devices */
- if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet(conn, "./devices/sound", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot extract sound devices"));
goto error;
DEBUG0("parsing nets");
- res = virXPathNodeSet("/domain/devices/interface", contextPtr, &list);
+ res = virXPathNodeSet(conn, "/domain/devices/interface", contextPtr, &list);
if (res > 0) {
for (i = 0; i < res; ++i) {
netDef = calloc(1, sizeof(lxc_net_def_t));
{
char *res;
- res = virXPathString("string(/domain/name[1])", contextPtr);
+ res = virXPathString(conn, "string(/domain/name[1])", contextPtr);
if (res == NULL) {
lxcError(conn, NULL, VIR_ERR_NO_NAME, NULL);
return(-1);
{
char *res;
- res = virXPathString("string(/domain/uuid[1])", contextPtr);
+ res = virXPathString(conn, "string(/domain/uuid[1])", contextPtr);
if (res == NULL) {
if (virUUIDGenerate(uuid)) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
xmlNodePtr *list;
int res;
- res = virXPathNodeSet("/domain/devices/filesystem", contextPtr, &list);
+ res = virXPathNodeSet(conn, "/domain/devices/filesystem", contextPtr, &list);
if (res > 0) {
for (i = 0; i < res; ++i) {
if (VIR_ALLOC(mountObj) < 0) {
{
char *res;
- res = virXPathString("string(/domain/os/init[1])", contextPtr);
+ res = virXPathString(conn, "string(/domain/os/init[1])", contextPtr);
if (res == NULL) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
_("invalid or missing init element"));
{
char *res;
- res = virXPathString("string(/domain/devices/console[1]/@tty)", contextPtr);
+ res = virXPathString(conn, "string(/domain/devices/console[1]/@tty)", contextPtr);
if (res == NULL) {
/* make sure the tty string is empty */
*tty = strdup("");
long res;
int rc;
- rc = virXPathLong("string(/domain/memory[1])", contextPtr, &res);
+ rc = virXPathLong(conn, "string(/domain/memory[1])", contextPtr, &res);
if ((rc == -2) || ((rc == 0) && (res <= 0))) {
*memory = -1;
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
}
/* Extract network name */
- def->name = virXPathString("string(./name[1])", ctxt);
+ def->name = virXPathString(conn, "string(./name[1])", ctxt);
if (!def->name) {
virNetworkReportError(conn, VIR_ERR_NO_NAME, NULL);
goto error;
}
/* Extract network uuid */
- tmp = virXPathString("string(./uuid[1])", ctxt);
+ tmp = virXPathString(conn, "string(./uuid[1])", ctxt);
if (!tmp) {
int err;
if ((err = virUUIDGenerate(def->uuid))) {
}
/* Parse bridge information */
- def->bridge = virXPathString("string(./bridge[1]/@name)", ctxt);
- tmp = virXPathString("string(./bridge[1]/@stp)", ctxt);
+ def->bridge = virXPathString(conn, "string(./bridge[1]/@name)", ctxt);
+ tmp = virXPathString(conn, "string(./bridge[1]/@stp)", ctxt);
def->stp = (tmp && STREQ(tmp, "off")) ? 0 : 1;
VIR_FREE(tmp);
- if (virXPathULong("string(./bridge[1]/@delay)", ctxt, &def->delay) < 0)
+ if (virXPathULong(conn, "string(./bridge[1]/@delay)", ctxt, &def->delay) < 0)
def->delay = 0;
- def->ipAddress = virXPathString("string(./ip[1]/@address)", ctxt);
- def->netmask = virXPathString("string(./ip[1]/@netmask)", ctxt);
+ def->ipAddress = virXPathString(conn, "string(./ip[1]/@address)", ctxt);
+ def->netmask = virXPathString(conn, "string(./ip[1]/@netmask)", ctxt);
if (def->ipAddress &&
def->netmask) {
/* XXX someday we want IPv6 too, so inet_aton won't work there */
goto error;
}
- if ((dhcp = virXPathNode("./ip[1]/dhcp[1]", ctxt)) &&
+ if ((dhcp = virXPathNode(conn, "./ip[1]/dhcp[1]", ctxt)) &&
virNetworkDHCPRangeDefParseXML(conn, def, dhcp) < 0)
goto error;
}
/* IPv4 forwarding setup */
- if (virXPathBoolean("count(./forward) > 0", ctxt)) {
+ if (virXPathBoolean(conn, "count(./forward) > 0", ctxt)) {
if (!def->ipAddress ||
!def->netmask) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
goto error;
}
- tmp = virXPathString("string(./forward[1]/@mode)", ctxt);
+ tmp = virXPathString(conn, "string(./forward[1]/@mode)", ctxt);
if (tmp) {
if ((def->forwardType = virNetworkForwardTypeFromString(tmp)) < 0) {
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
}
- def->forwardDev = virXPathString("string(./forward[1]/@dev)", ctxt);
+ def->forwardDev = virXPathString(conn, "string(./forward[1]/@dev)", ctxt);
} else {
def->forwardType = VIR_NETWORK_FORWARD_NONE;
}
virStoragePoolDefParseAuthChap(virConnectPtr conn,
xmlXPathContextPtr ctxt,
virStoragePoolAuthChapPtr auth) {
- auth->login = virXPathString("string(/pool/source/auth/@login)", ctxt);
+ auth->login = virXPathString(conn, "string(/pool/source/auth/@login)", ctxt);
if (auth->login == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing auth host attribute"));
return -1;
}
- auth->passwd = virXPathString("string(/pool/source/auth/@passwd)", ctxt);
+ auth->passwd = virXPathString(conn, "string(/pool/source/auth/@passwd)", ctxt);
if (auth->passwd == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing auth passwd attribute"));
char *mode;
long v;
- mode = virXPathString("string(/pool/permissions/mode)", ctxt);
+ mode = virXPathString(conn, "string(/pool/permissions/mode)", ctxt);
if (!mode) {
perms->mode = 0700;
} else {
}
}
- if (virXPathNode("/pool/permissions/owner", ctxt) == NULL) {
+ if (virXPathNode(conn, "/pool/permissions/owner", ctxt) == NULL) {
perms->uid = getuid();
} else {
- if (virXPathLong("number(/pool/permissions/owner)", ctxt, &v) < 0) {
+ if (virXPathLong(conn, "number(/pool/permissions/owner)", ctxt, &v) < 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("malformed owner element"));
return -1;
perms->uid = (int)v;
}
- if (virXPathNode("/pool/permissions/group", ctxt) == NULL) {
+ if (virXPathNode(conn, "/pool/permissions/group", ctxt) == NULL) {
perms->uid = getgid();
} else {
- if (virXPathLong("number(/pool/permissions/group)", ctxt, &v) < 0) {
+ if (virXPathLong(conn, "number(/pool/permissions/group)", ctxt, &v) < 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("malformed group element"));
return -1;
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
- perms->label = virXPathString("string(/pool/permissions/label)", ctxt);
+ perms->label = virXPathString(conn, "string(/pool/permissions/label)", ctxt);
return 0;
}
goto cleanup;
}
- if ((ret->name = virXPathString("string(/pool/name)", ctxt)) == NULL) {
+ if ((ret->name = virXPathString(conn, "string(/pool/name)", ctxt)) == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing name element"));
goto cleanup;
}
- uuid = virXPathString("string(/pool/uuid)", ctxt);
+ uuid = virXPathString(conn, "string(/pool/uuid)", ctxt);
if (uuid == NULL) {
if (virUUIDGenerate(ret->uuid) < 0) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
}
if (options->formatFromString) {
- char *format = virXPathString("string(/pool/source/format/@type)", ctxt);
+ char *format = virXPathString(conn, "string(/pool/source/format/@type)", ctxt);
if ((ret->source.format = (options->formatFromString)(conn, format)) < 0) {
VIR_FREE(format);
goto cleanup;
}
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) {
- if ((ret->source.host.name = virXPathString("string(/pool/source/host/@name)", ctxt)) == NULL) {
+ if ((ret->source.host.name = virXPathString(conn, "string(/pool/source/host/@name)", ctxt)) == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing source host name"));
goto cleanup;
xmlNodePtr *nodeset = NULL;
int nsource, i;
- if ((nsource = virXPathNodeSet("/pool/source/device", ctxt, &nodeset)) <= 0) {
+ if ((nsource = virXPathNodeSet(conn, "/pool/source/device", ctxt, &nodeset)) <= 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("cannot extract source devices"));
goto cleanup;
ret->source.ndevice = nsource;
}
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) {
- if ((ret->source.dir = virXPathString("string(/pool/source/dir/@path)", ctxt)) == NULL) {
+ if ((ret->source.dir = virXPathString(conn, "string(/pool/source/dir/@path)", ctxt)) == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing source path"));
goto cleanup;
}
- authType = virXPathString("string(/pool/source/auth/@type)", ctxt);
+ authType = virXPathString(conn, "string(/pool/source/auth/@type)", ctxt);
if (authType == NULL) {
ret->source.authType = VIR_STORAGE_POOL_AUTH_NONE;
} else {
goto cleanup;
}
- if ((ret->target.path = virXPathString("string(/pool/target/path)", ctxt)) == NULL) {
+ if ((ret->target.path = virXPathString(conn, "string(/pool/target/path)", ctxt)) == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing target path"));
goto cleanup;
char *mode;
long v;
- mode = virXPathString("string(/volume/permissions/mode)", ctxt);
+ mode = virXPathString(conn, "string(/volume/permissions/mode)", ctxt);
if (!mode) {
perms->mode = 0600;
} else {
}
}
- if (virXPathNode("/volume/permissions/owner", ctxt) == NULL) {
+ if (virXPathNode(conn, "/volume/permissions/owner", ctxt) == NULL) {
perms->uid = getuid();
} else {
- if (virXPathLong("number(/volume/permissions/owner)", ctxt, &v) < 0) {
+ if (virXPathLong(conn, "number(/volume/permissions/owner)", ctxt, &v) < 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing owner element"));
return -1;
}
perms->uid = (int)v;
}
- if (virXPathNode("/volume/permissions/group", ctxt) == NULL) {
+ if (virXPathNode(conn, "/volume/permissions/group", ctxt) == NULL) {
perms->gid = getgid();
} else {
- if (virXPathLong("number(/volume/permissions/group)", ctxt, &v) < 0) {
+ if (virXPathLong(conn, "number(/volume/permissions/group)", ctxt, &v) < 0) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing owner element"));
return -1;
}
/* NB, we're ignoring missing labels here - they'll simply inherit */
- perms->label = virXPathString("string(/volume/permissions/label)", ctxt);
+ perms->label = virXPathString(conn, "string(/volume/permissions/label)", ctxt);
return 0;
}
goto cleanup;
}
- ret->name = virXPathString("string(/volume/name)", ctxt);
+ ret->name = virXPathString(conn, "string(/volume/name)", ctxt);
if (ret->name == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing name element"));
}
/* Auto-generated so deliberately ignore */
- /*ret->key = virXPathString("string(/volume/key)", ctxt);*/
+ /*ret->key = virXPathString(conn, "string(/volume/key)", ctxt);*/
- capacity = virXPathString("string(/volume/capacity)", ctxt);
- unit = virXPathString("string(/volume/capacity/@unit)", ctxt);
+ capacity = virXPathString(conn, "string(/volume/capacity)", ctxt);
+ unit = virXPathString(conn, "string(/volume/capacity/@unit)", ctxt);
if (capacity == NULL) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing capacity element"));
VIR_FREE(capacity);
VIR_FREE(unit);
- allocation = virXPathString("string(/volume/allocation)", ctxt);
+ allocation = virXPathString(conn, "string(/volume/allocation)", ctxt);
if (allocation) {
- unit = virXPathString("string(/volume/allocation/@unit)", ctxt);
+ unit = virXPathString(conn, "string(/volume/allocation/@unit)", ctxt);
if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
goto cleanup;
VIR_FREE(allocation);
ret->allocation = ret->capacity;
}
- ret->target.path = virXPathString("string(/volume/target/path)", ctxt);
+ ret->target.path = virXPathString(conn, "string(/volume/target/path)", ctxt);
if (options->formatFromString) {
- char *format = virXPathString("string(/volume/target/format/@type)", ctxt);
+ char *format = virXPathString(conn, "string(/volume/target/format/@type)", ctxt);
if ((ret->target.format = (options->formatFromString)(conn, format)) < 0) {
VIR_FREE(format);
goto cleanup;
memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
nodeInfo = &privconn->nodeInfo;
- ret = virXPathLong("string(/node/cpu/nodes[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/nodes[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->nodes = l;
} else if (ret == -2) {
goto error;
}
- ret = virXPathLong("string(/node/cpu/sockets[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/sockets[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->sockets = l;
} else if (ret == -2) {
goto error;
}
- ret = virXPathLong("string(/node/cpu/cores[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/cores[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->cores = l;
} else if (ret == -2) {
goto error;
}
- ret = virXPathLong("string(/node/cpu/threads[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/threads[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->threads = l;
} else if (ret == -2) {
}
nodeInfo->cpus = nodeInfo->cores * nodeInfo->threads * nodeInfo->sockets * nodeInfo->nodes;
- ret = virXPathLong("string(/node/cpu/active[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/active[1])", ctxt, &l);
if (ret == 0) {
if (l < nodeInfo->cpus) {
nodeInfo->cpus = l;
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node active cpu"));
goto error;
}
- ret = virXPathLong("string(/node/cpu/mhz[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/cpu/mhz[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->mhz = l;
} else if (ret == -2) {
goto error;
}
- str = virXPathString("string(/node/cpu/model[1])", ctxt);
+ str = virXPathString(conn, "string(/node/cpu/model[1])", ctxt);
if (str != NULL) {
strncpy(nodeInfo->model, str, sizeof(nodeInfo->model)-1);
nodeInfo->model[sizeof(nodeInfo->model)-1] = '\0';
VIR_FREE(str);
}
- ret = virXPathLong("string(/node/memory[1])", ctxt, &l);
+ ret = virXPathLong(conn, "string(/node/memory[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->memory = l;
} else if (ret == -2) {
goto error;
}
- ret = virXPathNodeSet("/node/domain", ctxt, &domains);
+ ret = virXPathNodeSet(conn, "/node/domain", ctxt, &domains);
if (ret < 0) {
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node domain list"));
goto error;
if (domains != NULL)
VIR_FREE(domains);
- ret = virXPathNodeSet("/node/network", ctxt, &networks);
+ ret = virXPathNodeSet(conn, "/node/network", ctxt, &networks);
if (ret < 0) {
testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node network list"));
goto error;
#include "buf.h"
#include "util.h"
#include "memory.h"
-#include "xend_internal.h" /* for is_sound_* functions */
-
/**
* virXMLError:
* if the evaluation failed.
*/
char *
-virXPathString(const char *xpath, xmlXPathContextPtr ctxt)
+virXPathString(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
char *ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathString()"), 0);
return (NULL);
}
ret = strdup((char *) obj->stringval);
xmlXPathFreeObject(obj);
if (ret == NULL) {
- virXMLError(NULL, VIR_ERR_NO_MEMORY, _("strdup failed"), 0);
+ virXMLError(conn, VIR_ERR_NO_MEMORY, _("strdup failed"), 0);
}
ctxt->node = relnode;
return (ret);
* or -1 if the evaluation failed.
*/
int
-virXPathNumber(const char *xpath, xmlXPathContextPtr ctxt, double *value)
+virXPathNumber(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ double *value)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0);
return (-1);
}
* value doesn't have a long format.
*/
int
-virXPathLong(const char *xpath, xmlXPathContextPtr ctxt, long *value)
+virXPathLong(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ long *value)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0);
return (-1);
}
* value doesn't have a long format.
*/
int
-virXPathULong(const char *xpath, xmlXPathContextPtr ctxt, unsigned long *value)
+virXPathULong(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ unsigned long *value)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret = 0;
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNumber()"), 0);
return (-1);
}
* Returns 0 if false, 1 if true, or -1 if the evaluation failed.
*/
int
-virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt)
+virXPathBoolean(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathBoolean()"), 0);
return (-1);
}
* Returns a pointer to the node or NULL if the evaluation failed.
*/
xmlNodePtr
-virXPathNode(const char *xpath, xmlXPathContextPtr ctxt)
+virXPathNode(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
xmlNodePtr ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNode()"), 0);
return (NULL);
}
* must be freed) or -1 if the evaluation failed.
*/
int
-virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
- xmlNodePtr ** list)
+virXPathNodeSet(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr **list)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
- virXMLError(NULL, VIR_ERR_INTERNAL_ERROR,
+ virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
_("Invalid parameter to virXPathNodeSet()"), 0);
return (-1);
}
ret = obj->nodesetval->nodeNr;
if (list != NULL && ret) {
if (VIR_ALLOC_N(*list, ret) < 0) {
- virXMLError(NULL, VIR_ERR_NO_MEMORY,
+ virXMLError(conn, VIR_ERR_NO_MEMORY,
_("allocate string array"),
ret * sizeof(**list));
ret = -1;
#include <libxml/tree.h>
#include <libxml/xpath.h>
-int virXPathBoolean (const char *xpath,
+int virXPathBoolean (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt);
-char * virXPathString (const char *xpath,
+char * virXPathString (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt);
-int virXPathNumber (const char *xpath,
+int virXPathNumber (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
double *value);
-int virXPathInt (const char *xpath,
+int virXPathInt (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
int *value);
-int virXPathUInt (const char *xpath,
+int virXPathUInt (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
unsigned int *value);
-int virXPathLong (const char *xpath,
+int virXPathLong (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
long *value);
-int virXPathULong (const char *xpath,
+int virXPathULong (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
unsigned long *value);
-xmlNodePtr virXPathNode (const char *xpath,
+xmlNodePtr virXPathNode (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt);
-int virXPathNodeSet (const char *xpath,
+int virXPathNodeSet (virConnectPtr conn,
+ const char *xpath,
xmlXPathContextPtr ctxt,
xmlNodePtr **list);