|
|
c401cc |
From bec00335248f53fdfe7c731e4f4ff72272ca7cc1 Mon Sep 17 00:00:00 2001
|
|
|
c401cc |
Message-Id: <bec00335248f53fdfe7c731e4f4ff72272ca7cc1.1389183249.git.jdenemar@redhat.com>
|
|
|
c401cc |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
c401cc |
Date: Mon, 6 Jan 2014 17:02:25 +0100
|
|
|
c401cc |
Subject: [PATCH] virBitmapParse: Fix behavior in case of error and fix up
|
|
|
c401cc |
callers
|
|
|
c401cc |
|
|
|
c401cc |
https://bugzilla.redhat.com/show_bug.cgi?id=1047234
|
|
|
c401cc |
|
|
|
c401cc |
Re-arrange the code so that the returned bitmap is always initialized to
|
|
|
c401cc |
NULL even on early failures and return an error message as some callers
|
|
|
c401cc |
are already expecting it. Fix up the rest not to shadow the error.
|
|
|
c401cc |
|
|
|
c401cc |
(cherry picked from commit 106a2ddaa7b5ef7d69242333e48d77fda0b7ccf3)
|
|
|
c401cc |
|
|
|
c401cc |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c401cc |
---
|
|
|
c401cc |
po/POTFILES.in | 1 +
|
|
|
c401cc |
src/conf/domain_conf.c | 5 +----
|
|
|
c401cc |
src/conf/network_conf.c | 3 ---
|
|
|
c401cc |
src/nodeinfo.c | 5 +----
|
|
|
c401cc |
src/qemu/qemu_driver.c | 2 --
|
|
|
c401cc |
src/util/virbitmap.c | 18 +++++++++---------
|
|
|
c401cc |
src/xenxs/xen_sxpr.c | 5 +----
|
|
|
c401cc |
tests/cpuset | 2 +-
|
|
|
c401cc |
8 files changed, 14 insertions(+), 27 deletions(-)
|
|
|
c401cc |
|
|
|
c401cc |
diff --git a/po/POTFILES.in b/po/POTFILES.in
|
|
|
c401cc |
index 8afd015..0e4aa76 100644
|
|
|
c401cc |
--- a/po/POTFILES.in
|
|
|
c401cc |
+++ b/po/POTFILES.in
|
|
|
c401cc |
@@ -146,6 +146,7 @@ src/util/viralloc.c
|
|
|
c401cc |
src/util/viraudit.c
|
|
|
c401cc |
src/util/virauth.c
|
|
|
c401cc |
src/util/virauthconfig.c
|
|
|
c401cc |
+src/util/virbitmap.c
|
|
|
c401cc |
src/util/vircgroup.c
|
|
|
c401cc |
src/util/virclosecallbacks.c
|
|
|
c401cc |
src/util/vircommand.c
|
|
|
c401cc |
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
|
|
|
c401cc |
index d4161a5..bc53a89 100644
|
|
|
c401cc |
--- a/src/conf/domain_conf.c
|
|
|
c401cc |
+++ b/src/conf/domain_conf.c
|
|
|
c401cc |
@@ -11081,11 +11081,8 @@ virDomainDefParseXML(xmlDocPtr xml,
|
|
|
c401cc |
tmp = virXPathString("string(./vcpu[1]/@cpuset)", ctxt);
|
|
|
c401cc |
if (tmp) {
|
|
|
c401cc |
if (virBitmapParse(tmp, 0, &def->cpumask,
|
|
|
c401cc |
- VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
|
|
c401cc |
- virReportError(VIR_ERR_XML_ERROR,
|
|
|
c401cc |
- "%s", _("topology cpuset syntax error"));
|
|
|
c401cc |
+ VIR_DOMAIN_CPUMASK_LEN) < 0)
|
|
|
c401cc |
goto error;
|
|
|
c401cc |
- }
|
|
|
c401cc |
VIR_FREE(tmp);
|
|
|
c401cc |
}
|
|
|
c401cc |
}
|
|
|
c401cc |
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
|
|
|
c401cc |
index b358393..8846675 100644
|
|
|
c401cc |
--- a/src/conf/network_conf.c
|
|
|
c401cc |
+++ b/src/conf/network_conf.c
|
|
|
c401cc |
@@ -2873,9 +2873,6 @@ virNetworkLoadState(virNetworkObjListPtr nets,
|
|
|
c401cc |
if ((class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt))) {
|
|
|
c401cc |
if (virBitmapParse(class_id, 0, &class_id_map,
|
|
|
c401cc |
CLASS_ID_BITMAP_SIZE) < 0) {
|
|
|
c401cc |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c401cc |
- _("Malformed 'class_id' attribute: %s"),
|
|
|
c401cc |
- class_id);
|
|
|
c401cc |
VIR_FREE(class_id);
|
|
|
c401cc |
goto error;
|
|
|
c401cc |
}
|
|
|
c401cc |
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
|
|
|
c401cc |
index 4df4851..33a79b7 100644
|
|
|
c401cc |
--- a/src/nodeinfo.c
|
|
|
c401cc |
+++ b/src/nodeinfo.c
|
|
|
c401cc |
@@ -1547,11 +1547,8 @@ virNodeGetSiblingsList(const char *dir, int cpu_id)
|
|
|
c401cc |
if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &buf) < 0)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
|
|
|
c401cc |
- if (virBitmapParse(buf, 0, &ret, NUMA_MAX_N_CPUS) < 0) {
|
|
|
c401cc |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
c401cc |
- _("Failed to parse thread siblings"));
|
|
|
c401cc |
+ if (virBitmapParse(buf, 0, &ret, NUMA_MAX_N_CPUS) < 0)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
- }
|
|
|
c401cc |
|
|
|
c401cc |
cleanup:
|
|
|
c401cc |
VIR_FREE(buf);
|
|
|
c401cc |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
c401cc |
index d79bd02..5216e44 100644
|
|
|
c401cc |
--- a/src/qemu/qemu_driver.c
|
|
|
c401cc |
+++ b/src/qemu/qemu_driver.c
|
|
|
c401cc |
@@ -8484,8 +8484,6 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
|
|
|
c401cc |
if (virBitmapParse(params[i].value.s,
|
|
|
c401cc |
0, &nodeset,
|
|
|
c401cc |
VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
|
|
c401cc |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
c401cc |
- _("Failed to parse nodeset"));
|
|
|
c401cc |
ret = -1;
|
|
|
c401cc |
continue;
|
|
|
c401cc |
}
|
|
|
c401cc |
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
|
|
|
c401cc |
index 47c678e..870c8fe 100644
|
|
|
c401cc |
--- a/src/util/virbitmap.c
|
|
|
c401cc |
+++ b/src/util/virbitmap.c
|
|
|
c401cc |
@@ -298,23 +298,21 @@ virBitmapParse(const char *str,
|
|
|
c401cc |
size_t bitmapSize)
|
|
|
c401cc |
{
|
|
|
c401cc |
bool neg = false;
|
|
|
c401cc |
- const char *cur;
|
|
|
c401cc |
+ const char *cur = str;
|
|
|
c401cc |
char *tmp;
|
|
|
c401cc |
size_t i;
|
|
|
c401cc |
int start, last;
|
|
|
c401cc |
|
|
|
c401cc |
- if (!str)
|
|
|
c401cc |
+ if (!(*bitmap = virBitmapNew(bitmapSize)))
|
|
|
c401cc |
return -1;
|
|
|
c401cc |
|
|
|
c401cc |
- cur = str;
|
|
|
c401cc |
- virSkipSpaces(&cur);
|
|
|
c401cc |
+ if (!str)
|
|
|
c401cc |
+ goto error;
|
|
|
c401cc |
|
|
|
c401cc |
- if (*cur == 0)
|
|
|
c401cc |
- return -1;
|
|
|
c401cc |
+ virSkipSpaces(&cur);
|
|
|
c401cc |
|
|
|
c401cc |
- *bitmap = virBitmapNew(bitmapSize);
|
|
|
c401cc |
- if (!*bitmap)
|
|
|
c401cc |
- return -1;
|
|
|
c401cc |
+ if (*cur == '\0')
|
|
|
c401cc |
+ goto error;
|
|
|
c401cc |
|
|
|
c401cc |
while (*cur != 0 && *cur != terminator) {
|
|
|
c401cc |
/*
|
|
|
c401cc |
@@ -384,6 +382,8 @@ virBitmapParse(const char *str,
|
|
|
c401cc |
return virBitmapCountBits(*bitmap);
|
|
|
c401cc |
|
|
|
c401cc |
error:
|
|
|
c401cc |
+ virReportError(VIR_ERR_INVALID_ARG,
|
|
|
c401cc |
+ _("Failed to parse bitmap '%s'"), str);
|
|
|
c401cc |
virBitmapFree(*bitmap);
|
|
|
c401cc |
*bitmap = NULL;
|
|
|
c401cc |
return -1;
|
|
|
c401cc |
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
|
|
|
c401cc |
index fb01e0d..c61336c 100644
|
|
|
c401cc |
--- a/src/xenxs/xen_sxpr.c
|
|
|
c401cc |
+++ b/src/xenxs/xen_sxpr.c
|
|
|
c401cc |
@@ -1160,11 +1160,8 @@ xenParseSxpr(const struct sexpr *root,
|
|
|
c401cc |
|
|
|
c401cc |
if (cpus != NULL) {
|
|
|
c401cc |
if (virBitmapParse(cpus, 0, &def->cpumask,
|
|
|
c401cc |
- VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
|
|
c401cc |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c401cc |
- _("invalid CPU mask %s"), cpus);
|
|
|
c401cc |
+ VIR_DOMAIN_CPUMASK_LEN) < 0)
|
|
|
c401cc |
goto error;
|
|
|
c401cc |
- }
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
def->maxvcpus = sexpr_int(root, "domain/vcpus");
|
|
|
c401cc |
diff --git a/tests/cpuset b/tests/cpuset
|
|
|
c401cc |
index b617d6f..35803be 100755
|
|
|
c401cc |
--- a/tests/cpuset
|
|
|
c401cc |
+++ b/tests/cpuset
|
|
|
c401cc |
@@ -42,7 +42,7 @@ sed "s/vcpu placement='static'>/vcpu cpuset='aaa'>/" xml > xml-invalid || fail=1
|
|
|
c401cc |
$abs_top_builddir/tools/virsh --connect test:///default define xml-invalid > out 2>&1 && fail=1
|
|
|
c401cc |
cat <<\EOF > exp || fail=1
|
|
|
c401cc |
error: Failed to define domain from xml-invalid
|
|
|
c401cc |
-error: XML error: topology cpuset syntax error
|
|
|
c401cc |
+error: invalid argument: Failed to parse bitmap 'aaa'
|
|
|
c401cc |
|
|
|
c401cc |
EOF
|
|
|
c401cc |
compare exp out || fail=1
|
|
|
c401cc |
--
|
|
|
c401cc |
1.8.5.2
|
|
|
c401cc |
|