Jim Meyering <jim(a)meyering.net> wrote:
"Daniel P. Berrange" <berrange(a)redhat.com> wrote:
...
> Some parts of qemu supply it, many other parts do not since they
> have no access to the virDomainPtr object. This is one of the
> reasons for deprecating this field - it was impossible to reliably
> provide it when raising errors.
>
> In this particular test case error, we are better off supplying the
> domain name in the format string - it'll improve the error message
> to have it placed in context of the description
>
> eg, instead of
>
> libvir: Test error test: internal error Domain is still running
>
>
> We'd have
>
> libvir: Test error: internal error Domain 'test' is still running
>
> Which could be done by changing
>
> if (privdom->state != VIR_DOMAIN_SHUTOFF) {
> testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
> _("Domain is still running"));
>
>
> to be
>
> if (privdom->state != VIR_DOMAIN_SHUTOFF) {
> testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
> _("Domain '%s' is still running"),
domain->name);
Yep. I began doing that about 15 minutes ago ;-)
Here's the change to adjust src/test.c.
Two change sets:
- Fix the "make check" failure by adjusting uses of testError,
including domain->name (and a few net->name) strings via format.
- Remove now-ignored dom and net parameters.
From e6e5387e1e8f8ea7f60bf8666c188b1ee9852700 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 10 Oct 2008 14:45:42 +0200
Subject: [PATCH] change testError format strings to explicitly include domain and network
names
* src/test.c (testResumeDomain, testPauseDomain): Likewise.
(testShutdownDomain, testGetDomainInfo, testDomainSave): Likewise.
(testSetMemory, testSetVcpus, testDomainCreate, testDomainUndefine)
(testDomainGetSchedulerType, testDomainGetSchedulerParams): Likewise.
(testDomainSetSchedulerParams, testNetworkUndefine): Likewise.
(testNetworkStart, testNetworkGetBridgeName): Likewise.
(testDomainCoreDump): Likewise.
Name the file we failed to open or write.
Use strerror(errno) in diagnostics.
* tests/undefine: Adjust expected output.
---
src/test.c | 87 ++++++++++++++++++++++++++++++-------------------------
tests/undefine | 2 +-
2 files changed, 48 insertions(+), 41 deletions(-)
diff --git a/src/test.c b/src/test.c
index ad51736..7ca50eb 100644
--- a/src/test.c
+++ b/src/test.c
@@ -776,8 +776,9 @@ static int testResumeDomain (virDomainPtr domain)
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_PAUSED) {
- testError(domain->conn, domain, NULL,
- VIR_ERR_INTERNAL_ERROR, _("domain not paused"));
+ testError(domain->conn, NULL, NULL,
+ VIR_ERR_INTERNAL_ERROR, _("%s: domain not paused"),
+ domain->name);
return -1;
}
@@ -791,8 +792,9 @@ static int testPauseDomain (virDomainPtr domain)
if (privdom->state == VIR_DOMAIN_SHUTOFF ||
privdom->state == VIR_DOMAIN_PAUSED) {
- testError(domain->conn, domain, NULL,
- VIR_ERR_INTERNAL_ERROR, _("domain not running"));
+ testError(domain->conn, NULL, NULL,
+ VIR_ERR_INTERNAL_ERROR, _("%s: domain not running"),
+ domain->name);
return -1;
}
@@ -805,7 +807,8 @@ static int testShutdownDomain (virDomainPtr domain)
GET_DOMAIN(domain, -1);
if (privdom->state == VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR, "domain not
running");
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("%s: domain not running"), domain->name);
return -1;
}
@@ -861,7 +864,8 @@ static int testGetDomainInfo (virDomainPtr domain,
GET_DOMAIN(domain, -1);
if (gettimeofday(&tv, NULL) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR, _("getting
time of day"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("getting time of day"));
return (-1);
}
@@ -886,40 +890,40 @@ static int testDomainSave(virDomainPtr domain,
xml = testDomainDumpXML(domain, 0);
if (xml == NULL) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot allocate space for metadata"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("%s: cannot allocate space for metadata"),
domain->name);
return (-1);
}
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("%s: cannot save domain"), domain->name);
return (-1);
}
len = strlen(xml);
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write header"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("%s: cannot write header"), domain->name);
close(fd);
return (-1);
}
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write metadata length"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("%s: cannot write metadata length"), domain->name);
close(fd);
return (-1);
}
if (safewrite(fd, xml, len) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write metadata"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("%s: cannot write metadata"), domain->name);
VIR_FREE(xml);
close(fd);
return (-1);
}
VIR_FREE(xml);
if (close(fd) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain data"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("%s: cannot save domain data"), domain->name);
close(fd);
return (-1);
}
@@ -1007,19 +1011,22 @@ static int testDomainCoreDump(virDomainPtr domain,
GET_DOMAIN(domain, -1);
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain core"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("domain '%s' coredump: failed to open %s: %s"),
+ domain->name, to, strerror (errno));
return (-1);
}
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot write header"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("domain '%s' coredump: failed to write header to %s:
%s"),
+ domain->name, to, strerror (errno));
close(fd);
return (-1);
}
if (close(fd) < 0) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot save domain data"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("domain '%s' coredump: write failed: %s: %s"),
+ domain->name, to, strerror (errno));
close(fd);
return (-1);
}
@@ -1060,7 +1067,7 @@ static int testSetMemory(virDomainPtr domain,
GET_DOMAIN(domain, -1);
if (memory > privdom->def->maxmem) {
- testError(domain->conn, domain, NULL,
+ testError(domain->conn, NULL, NULL,
VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
@@ -1075,7 +1082,7 @@ static int testSetVcpus(virDomainPtr domain,
/* We allow more cpus in guest than host */
if (nrCpus > 32) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
@@ -1186,8 +1193,8 @@ static int testDomainCreate(virDomainPtr domain) {
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Domain is already running"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Domain '%s' is already running"),
domain->name);
return (-1);
}
@@ -1201,8 +1208,8 @@ static int testDomainUndefine(virDomainPtr domain) {
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
- _("Domain is still running"));
+ testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Domain '%s' is still running"), domain->name);
return (-1);
}
@@ -1237,7 +1244,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain,
*nparams = 1;
type = strdup("fair");
if (!type) {
- testError(domain->conn, domain, NULL, VIR_ERR_NO_MEMORY,
"schedular");
+ testError(domain->conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"schedular");
return (NULL);
}
return type;
@@ -1249,7 +1256,7 @@ static int testDomainGetSchedulerParams(virDomainPtr domain,
{
GET_DOMAIN(domain, -1);
if (*nparams != 1) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG,
"nparams");
+ testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG,
"nparams");
return (-1);
}
strcpy(params[0].field, "weight");
@@ -1267,15 +1274,15 @@ static int testDomainSetSchedulerParams(virDomainPtr domain,
{
GET_DOMAIN(domain, -1);
if (nparams != 1) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG,
"nparams");
+ testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG,
"nparams");
return (-1);
}
if (STRNEQ(params[0].field, "weight")) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG,
"field");
+ testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG, "field");
return (-1);
}
if (params[0].type != VIR_DOMAIN_SCHED_FIELD_UINT) {
- testError(domain->conn, domain, NULL, VIR_ERR_INVALID_ARG, "type");
+ testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG, "type");
return (-1);
}
/* XXX */
@@ -1441,8 +1448,8 @@ static int testNetworkUndefine(virNetworkPtr network) {
GET_NETWORK(network, -1);
if (virNetworkIsActive(privnet)) {
- testError(network->conn, NULL, network, VIR_ERR_INTERNAL_ERROR,
- _("Network is still running"));
+ testError(network->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Network '%s' is still running"),
network->name);
return (-1);
}
@@ -1456,8 +1463,8 @@ static int testNetworkStart(virNetworkPtr network) {
GET_NETWORK(network, -1);
if (virNetworkIsActive(privnet)) {
- testError(network->conn, NULL, network, VIR_ERR_INTERNAL_ERROR,
- _("Network is already running"));
+ testError(network->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Network '%s' is already running"),
network->name);
return (-1);
}
@@ -1488,7 +1495,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) {
GET_NETWORK(network, NULL);
if (privnet->def->bridge &&
!(bridge = strdup(privnet->def->bridge))) {
- testError(network->conn, NULL, network, VIR_ERR_NO_MEMORY,
"network");
+ testError(network->conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network");
return NULL;
}
return bridge;
diff --git a/tests/undefine b/tests/undefine
index 3936e22..d745241 100755
--- a/tests/undefine
+++ b/tests/undefine
@@ -29,7 +29,7 @@ fail=0
virsh -q -c test:///default undefine test > out 2>&1
test $? = 1 || fail=1
cat <<\EOF > exp || fail=1
-libvir: Test error test: internal error Domain is still running
+libvir: Test error : internal error Domain 'test' is still running
error: Failed to undefine domain test
EOF
compare out exp || fail=1
--
1.6.0.2.307.gc4275
From 6e10cf8adc031e11adfdaf10553dc3a6b38ed0ab Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 10 Oct 2008 15:10:35 +0200
Subject: [PATCH] test.c (testError): Remove now-ignored dom and net parameters.
This is a sytnax-only change: removing the two unused parameters
and updating all callers:
* src/test.c (GET_DOMAIN, GET_NETWORK, testError)
(testBuildCapabilities, testOpenDefault, testOpenFromFile)
(testOpen, testGetHostname, testGetURI, testGetCapabilities)
(testLookupDomainByID, testLookupDomainByUUID)
(testLookupDomainByName, testResumeDomain, testPauseDomain)
(testShutdownDomain, testGetDomainInfo, testDomainSave)
(testDomainRestore, testDomainCoreDump, testGetOSType)
(testSetMemory, testSetVcpus, testListDefinedDomains)
(testNodeGetCellsFreeMemory, testDomainCreate)
(testDomainUndefine, testDomainGetSchedulerType)
(testDomainGetSchedulerParams, testDomainSetSchedulerParams)
(testLookupNetworkByUUID, testLookupNetworkByName)
(testListNetworks, testListDefinedNetworks, testNetworkUndefine)
(testNetworkStart, testNetworkGetBridgeName): Update callers.
---
src/test.c | 142 +++++++++++++++++++++++++++++------------------------------
1 files changed, 70 insertions(+), 72 deletions(-)
diff --git a/src/test.c b/src/test.c
index 7ca50eb..00d5541 100644
--- a/src/test.c
+++ b/src/test.c
@@ -88,8 +88,7 @@ static const virNodeInfo defaultNodeInfo = {
do { \
if ((privdom = virDomainFindByName(privconn->domains, \
(dom)->name)) == NULL) { \
- testError((dom)->conn, (dom), NULL, VIR_ERR_INVALID_ARG, \
- __FUNCTION__); \
+ testError((dom)->conn, VIR_ERR_INVALID_ARG, __FUNCTION__); \
return (ret); \
} \
} while (0)
@@ -102,8 +101,7 @@ static const virNodeInfo defaultNodeInfo = {
do { \
if ((privnet = virNetworkFindByName(privconn->networks, \
(net)->name)) == NULL) { \
- testError((net)->conn, NULL, (net), VIR_ERR_INVALID_ARG, \
- __FUNCTION__); \
+ testError((net)->conn, VIR_ERR_INVALID_ARG, __FUNCTION__); \
return (ret); \
} \
} while (0)
@@ -114,8 +112,8 @@ static const virNodeInfo defaultNodeInfo = {
privconn = (testConnPtr)conn->privateData;
-#define testError(conn, dom, net, code, fmt...) \
- __virReportErrorHelper(conn, VIR_FROM_TEST, code, __FILE__, \
+#define testError(conn, code, fmt...) \
+ __virReportErrorHelper(conn, VIR_FROM_TEST, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
static virCapsPtr
@@ -168,7 +166,7 @@ testBuildCapabilities(virConnectPtr conn) {
return caps;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
virCapabilitiesFree(caps);
return NULL;
}
@@ -209,13 +207,13 @@ static int testOpenDefault(virConnectPtr conn) {
virNetworkObjPtr netobj = NULL;
if (VIR_ALLOC(privconn) < 0) {
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
+ testError(conn, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
}
conn->privateData = privconn;
if (gettimeofday(&tv, NULL) < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of
day"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("getting time of day"));
goto error;
}
@@ -304,7 +302,7 @@ static int testOpenFromFile(virConnectPtr conn,
virDomainObjPtr dom;
testConnPtr privconn;
if (VIR_ALLOC(privconn) < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
+ testError(NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
}
conn->privateData = privconn;
@@ -313,14 +311,14 @@ static int testOpenFromFile(virConnectPtr conn,
goto error;
if ((fd = open(file, O_RDONLY)) < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("loading host
definition file"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("loading host definition
file"));
goto error;
}
if (!(xml = xmlReadFd(fd, file, NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("host"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("host"));
goto error;
}
close(fd);
@@ -328,13 +326,13 @@ static int testOpenFromFile(virConnectPtr conn,
root = xmlDocGetRootElement(xml);
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "node"))) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node"));
goto error;
}
ctxt = xmlXPathNewContext(xml);
if (ctxt == NULL) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("creating xpath
context"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("creating xpath context"));
goto error;
}
@@ -349,7 +347,7 @@ static int testOpenFromFile(virConnectPtr conn,
if (ret == 0) {
nodeInfo->nodes = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu numa
nodes"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu numa nodes"));
goto error;
}
@@ -357,7 +355,7 @@ static int testOpenFromFile(virConnectPtr conn,
if (ret == 0) {
nodeInfo->sockets = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu sockets"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu sockets"));
goto error;
}
@@ -365,7 +363,7 @@ static int testOpenFromFile(virConnectPtr conn,
if (ret == 0) {
nodeInfo->cores = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu cores"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu cores"));
goto error;
}
@@ -373,7 +371,7 @@ static int testOpenFromFile(virConnectPtr conn,
if (ret == 0) {
nodeInfo->threads = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu threads"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu threads"));
goto error;
}
@@ -384,14 +382,14 @@ static int testOpenFromFile(virConnectPtr conn,
nodeInfo->cpus = l;
}
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node active cpu"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node active cpu"));
goto error;
}
ret = virXPathLong(conn, "string(/node/cpu/mhz[1])", ctxt, &l);
if (ret == 0) {
nodeInfo->mhz = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node cpu mhz"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node cpu mhz"));
goto error;
}
@@ -406,13 +404,13 @@ static int testOpenFromFile(virConnectPtr conn,
if (ret == 0) {
nodeInfo->memory = l;
} else if (ret == -2) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node memory"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node memory"));
goto error;
}
ret = virXPathNodeSet(conn, "/node/domain", ctxt, &domains);
if (ret < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node domain list"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node domain list"));
goto error;
}
@@ -423,7 +421,7 @@ static int testOpenFromFile(virConnectPtr conn,
char *absFile = testBuildFilename(file, relFile);
VIR_FREE(relFile);
if (!absFile) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving
domain filename"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("resolving domain
filename"));
goto error;
}
def = virDomainDefParseFile(conn, privconn->caps, absFile);
@@ -449,7 +447,7 @@ static int testOpenFromFile(virConnectPtr conn,
ret = virXPathNodeSet(conn, "/node/network", ctxt, &networks);
if (ret < 0) {
- testError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, _("node network
list"));
+ testError(NULL, VIR_ERR_XML_ERROR, _("node network list"));
goto error;
}
for (i = 0 ; i < ret ; i++) {
@@ -459,7 +457,7 @@ static int testOpenFromFile(virConnectPtr conn,
char *absFile = testBuildFilename(file, relFile);
VIR_FREE(relFile);
if (!absFile) {
- testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving
network filename"));
+ testError(NULL, VIR_ERR_INTERNAL_ERROR, _("resolving network
filename"));
goto error;
}
@@ -536,7 +534,7 @@ static int testOpen(virConnectPtr conn,
if (!uri->path
|| uri->path[0] == '\0'
|| (uri->path[0] == '/' && uri->path[1] == '\0'))
{
- testError (NULL, NULL, NULL, VIR_ERR_INVALID_ARG,
+ testError (NULL, VIR_ERR_INVALID_ARG,
_("testOpen: supply a path or use test:///default"));
return VIR_DRV_OPEN_ERROR;
}
@@ -587,13 +585,13 @@ static char *testGetHostname (virConnectPtr conn)
r = gethostname (hostname, HOST_NAME_MAX+1);
if (r == -1) {
- testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s",
+ testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
strerror (errno));
return NULL;
}
str = strdup (hostname);
if (str == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s",
+ testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
strerror (errno));
return NULL;
}
@@ -606,7 +604,7 @@ static char * testGetURI (virConnectPtr conn)
GET_CONNECTION(conn);
if (asprintf (&uri, "test://%s", privconn->path) == -1) {
- testError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR, "%s",
+ testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
strerror (errno));
return NULL;
}
@@ -633,7 +631,7 @@ static char *testGetCapabilities (virConnectPtr conn)
GET_CONNECTION(conn);
if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) {
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
@@ -691,7 +689,7 @@ static virDomainPtr testLookupDomainByID(virConnectPtr conn,
GET_CONNECTION(conn);
if ((dom = virDomainFindByID(privconn->domains, id)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
+ testError (conn, VIR_ERR_NO_DOMAIN, NULL);
return NULL;
}
@@ -710,7 +708,7 @@ static virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
GET_CONNECTION(conn);
if ((dom = virDomainFindByUUID(privconn->domains, uuid)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
+ testError (conn, VIR_ERR_NO_DOMAIN, NULL);
return NULL;
}
@@ -729,7 +727,7 @@ static virDomainPtr testLookupDomainByName(virConnectPtr conn,
GET_CONNECTION(conn);
if ((dom = virDomainFindByName(privconn->domains, name)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
+ testError (conn, VIR_ERR_NO_DOMAIN, NULL);
return NULL;
}
@@ -776,7 +774,7 @@ static int testResumeDomain (virDomainPtr domain)
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_PAUSED) {
- testError(domain->conn, NULL, NULL,
+ testError(domain->conn,
VIR_ERR_INTERNAL_ERROR, _("%s: domain not paused"),
domain->name);
return -1;
@@ -792,7 +790,7 @@ static int testPauseDomain (virDomainPtr domain)
if (privdom->state == VIR_DOMAIN_SHUTOFF ||
privdom->state == VIR_DOMAIN_PAUSED) {
- testError(domain->conn, NULL, NULL,
+ testError(domain->conn,
VIR_ERR_INTERNAL_ERROR, _("%s: domain not running"),
domain->name);
return -1;
@@ -807,7 +805,7 @@ static int testShutdownDomain (virDomainPtr domain)
GET_DOMAIN(domain, -1);
if (privdom->state == VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("%s: domain not running"), domain->name);
return -1;
}
@@ -864,7 +862,7 @@ static int testGetDomainInfo (virDomainPtr domain,
GET_DOMAIN(domain, -1);
if (gettimeofday(&tv, NULL) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("getting time of day"));
return (-1);
}
@@ -890,31 +888,31 @@ static int testDomainSave(virDomainPtr domain,
xml = testDomainDumpXML(domain, 0);
if (xml == NULL) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("%s: cannot allocate space for metadata"),
domain->name);
return (-1);
}
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("%s: cannot save domain"), domain->name);
return (-1);
}
len = strlen(xml);
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("%s: cannot write header"), domain->name);
close(fd);
return (-1);
}
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("%s: cannot write metadata length"), domain->name);
close(fd);
return (-1);
}
if (safewrite(fd, xml, len) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("%s: cannot write metadata"), domain->name);
VIR_FREE(xml);
close(fd);
@@ -922,7 +920,7 @@ static int testDomainSave(virDomainPtr domain,
}
VIR_FREE(xml);
if (close(fd) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("%s: cannot save domain data"), domain->name);
close(fd);
return (-1);
@@ -946,41 +944,41 @@ static int testDomainRestore(virConnectPtr conn,
GET_CONNECTION(conn);
if ((fd = open(path, O_RDONLY)) < 0) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("cannot read domain image"));
return (-1);
}
if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("incomplete save header"));
close(fd);
return (-1);
}
if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("mismatched header magic"));
close(fd);
return (-1);
}
if (read(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to read metadata length"));
close(fd);
return (-1);
}
if (len < 1 || len > 8192) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("length of metadata out of range"));
close(fd);
return (-1);
}
if (VIR_ALLOC_N(xml, len+1) < 0) {
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
+ testError(conn, VIR_ERR_NO_MEMORY, "xml");
close(fd);
return (-1);
}
if (read(fd, xml, len) != len) {
- testError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(conn, VIR_ERR_INTERNAL_ERROR,
_("incomplete metdata"));
close(fd);
return (-1);
@@ -1011,20 +1009,20 @@ static int testDomainCoreDump(virDomainPtr domain,
GET_DOMAIN(domain, -1);
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("domain '%s' coredump: failed to open %s: %s"),
domain->name, to, strerror (errno));
return (-1);
}
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("domain '%s' coredump: failed to write header to %s:
%s"),
domain->name, to, strerror (errno));
close(fd);
return (-1);
}
if (close(fd) < 0) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("domain '%s' coredump: write failed: %s: %s"),
domain->name, to, strerror (errno));
close(fd);
@@ -1041,7 +1039,7 @@ static int testDomainCoreDump(virDomainPtr domain,
static char *testGetOSType(virDomainPtr dom) {
char *ret = strdup("linux");
if (!ret)
- testError(dom->conn, dom, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
return ret;
}
@@ -1067,7 +1065,7 @@ static int testSetMemory(virDomainPtr domain,
GET_DOMAIN(domain, -1);
if (memory > privdom->def->maxmem) {
- testError(domain->conn, NULL, NULL,
+ testError(domain->conn,
VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
@@ -1082,7 +1080,7 @@ static int testSetVcpus(virDomainPtr domain,
/* We allow more cpus in guest than host */
if (nrCpus > 32) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return (-1);
}
@@ -1135,7 +1133,7 @@ static int testListDefinedDomains(virConnectPtr conn,
return n;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
for (n = 0 ; n < maxnames ; n++)
VIR_FREE(names[n]);
return -1;
@@ -1174,7 +1172,7 @@ static int testNodeGetCellsFreeMemory(virConnectPtr conn,
GET_CONNECTION(conn);
if (startCell > privconn->numCells) {
- testError(conn, NULL, NULL, VIR_ERR_INVALID_ARG,
+ testError(conn, VIR_ERR_INVALID_ARG,
_("Range exceeds available cells"));
return -1;
}
@@ -1193,7 +1191,7 @@ static int testDomainCreate(virDomainPtr domain) {
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("Domain '%s' is already running"),
domain->name);
return (-1);
}
@@ -1208,7 +1206,7 @@ static int testDomainUndefine(virDomainPtr domain) {
GET_DOMAIN(domain, -1);
if (privdom->state != VIR_DOMAIN_SHUTOFF) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
_("Domain '%s' is still running"), domain->name);
return (-1);
}
@@ -1244,7 +1242,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain,
*nparams = 1;
type = strdup("fair");
if (!type) {
- testError(domain->conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"schedular");
+ testError(domain->conn, VIR_ERR_NO_MEMORY, "schedular");
return (NULL);
}
return type;
@@ -1256,7 +1254,7 @@ static int testDomainGetSchedulerParams(virDomainPtr domain,
{
GET_DOMAIN(domain, -1);
if (*nparams != 1) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG,
"nparams");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "nparams");
return (-1);
}
strcpy(params[0].field, "weight");
@@ -1274,15 +1272,15 @@ static int testDomainSetSchedulerParams(virDomainPtr domain,
{
GET_DOMAIN(domain, -1);
if (nparams != 1) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG,
"nparams");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "nparams");
return (-1);
}
if (STRNEQ(params[0].field, "weight")) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG, "field");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "field");
return (-1);
}
if (params[0].type != VIR_DOMAIN_SCHED_FIELD_UINT) {
- testError(domain->conn, NULL, NULL, VIR_ERR_INVALID_ARG, "type");
+ testError(domain->conn, VIR_ERR_INVALID_ARG, "type");
return (-1);
}
/* XXX */
@@ -1314,7 +1312,7 @@ static virNetworkPtr testLookupNetworkByUUID(virConnectPtr conn,
GET_CONNECTION(conn);
if ((net = virNetworkFindByUUID(privconn->networks, uuid)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL);
+ testError (conn, VIR_ERR_NO_NETWORK, NULL);
return NULL;
}
@@ -1328,7 +1326,7 @@ static virNetworkPtr testLookupNetworkByName(virConnectPtr conn,
GET_CONNECTION(conn);
if ((net = virNetworkFindByName(privconn->networks, name)) == NULL) {
- testError (conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL);
+ testError (conn, VIR_ERR_NO_NETWORK, NULL);
return NULL;
}
@@ -1366,7 +1364,7 @@ static int testListNetworks(virConnectPtr conn, char **const names,
int nnames)
return n;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
return (-1);
@@ -1402,7 +1400,7 @@ static int testListDefinedNetworks(virConnectPtr conn, char **const
names, int n
return n;
no_memory:
- testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
+ testError(conn, VIR_ERR_NO_MEMORY, NULL);
for (n = 0 ; n < nnames ; n++)
VIR_FREE(names[n]);
return (-1);
@@ -1448,7 +1446,7 @@ static int testNetworkUndefine(virNetworkPtr network) {
GET_NETWORK(network, -1);
if (virNetworkIsActive(privnet)) {
- testError(network->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(network->conn, VIR_ERR_INTERNAL_ERROR,
_("Network '%s' is still running"),
network->name);
return (-1);
}
@@ -1463,7 +1461,7 @@ static int testNetworkStart(virNetworkPtr network) {
GET_NETWORK(network, -1);
if (virNetworkIsActive(privnet)) {
- testError(network->conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ testError(network->conn, VIR_ERR_INTERNAL_ERROR,
_("Network '%s' is already running"),
network->name);
return (-1);
}
@@ -1495,7 +1493,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) {
GET_NETWORK(network, NULL);
if (privnet->def->bridge &&
!(bridge = strdup(privnet->def->bridge))) {
- testError(network->conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network");
+ testError(network->conn, VIR_ERR_NO_MEMORY, "network");
return NULL;
}
return bridge;
--
1.6.0.2.307.gc4275