---
src/conf/domain_conf.c | 37 ++++---------------------------------
1 file changed, 4 insertions(+), 33 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d5e01a8..6073dcf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7706,53 +7706,24 @@ static int
virDomainParseMemory(const char *xpath, xmlXPathContextPtr ctxt,
unsigned long long *mem, bool required)
{
- char *xpath_full = NULL;
- char *unit = NULL;
int ret = -1;
- unsigned long long bytes;
- unsigned long long max;
+ unsigned long long bytes, max;
- *mem = 0;
- if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- ret = virXPathULongLong(xpath_full, ctxt, &bytes);
- if (ret < 0) {
- if (ret == -2)
- virDomainReportError(VIR_ERR_XML_ERROR,
- _("could not parse memory element %s"),
- xpath);
- else if (required)
- virDomainReportError(VIR_ERR_XML_ERROR,
- _("missing memory element %s"),
- xpath);
- else
- ret = 0;
- goto cleanup;
- }
- VIR_FREE(xpath_full);
-
- if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- unit = virXPathString(xpath_full, ctxt);
/* On 32-bit machines, our bound is 0xffffffff * KiB. On 64-bit
* machines, our bound is off_t (2^63). */
if (sizeof(unsigned long) < sizeof(long long))
max = 1024ull * ULONG_MAX;
else
max = LLONG_MAX;
- if (virScaleInteger(&bytes, unit, 1024, max) < 0)
+
+ ret = virDomainParseScaledValue(xpath, ctxt, &bytes, 1024, max, required);
+ if (ret < 0)
goto cleanup;
/* Yes, we really do use kibibytes for our internal sizing. */
*mem = VIR_DIV_UP(bytes, 1024);
ret = 0;
cleanup:
- VIR_FREE(xpath_full);
- VIR_FREE(unit);
return ret;
}
--
1.7.10
Show replies by date
On 05/11/2012 03:14 PM, Guido Günther wrote:
---
src/conf/domain_conf.c | 37 ++++---------------------------------
1 file changed, 4 insertions(+), 33 deletions(-)
Ah, here's what I was wondering about in patch 1/4.
I'd rebase this to happen at the same time as you create
virDomainParseScaledValue, as the first patch in the series (a straight
refactor), leaving the rest of the original patch 1 for the second patch
in the rebase (adding new content).
But the change is good.
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org