|
|
7548c0 |
From 0cee78aa69f5e3317b5e4853454a108e597228e5 Mon Sep 17 00:00:00 2001
|
|
|
7548c0 |
Message-Id: <0cee78aa69f5e3317b5e4853454a108e597228e5@dist-git>
|
|
|
7548c0 |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
7548c0 |
Date: Wed, 7 Oct 2020 18:45:33 +0200
|
|
|
7548c0 |
Subject: [PATCH] conf: Move and rename virDomainParseScaledValue()
|
|
|
7548c0 |
MIME-Version: 1.0
|
|
|
7548c0 |
Content-Type: text/plain; charset=UTF-8
|
|
|
7548c0 |
Content-Transfer-Encoding: 8bit
|
|
|
7548c0 |
|
|
|
7548c0 |
There is nothing domain specific about the function, thus it
|
|
|
7548c0 |
should not have virDomain prefix. Also, the fact that it is a
|
|
|
7548c0 |
static function makes it impossible to use from other files.
|
|
|
7548c0 |
Move the function to virxml.c and drop the 'Domain' infix.
|
|
|
7548c0 |
|
|
|
7548c0 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
7548c0 |
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
|
|
|
7548c0 |
(cherry picked from commit 04bd77a19f8312493151ce377da40577b1470a0b)
|
|
|
7548c0 |
|
|
|
7548c0 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1749518
|
|
|
7548c0 |
|
|
|
7548c0 |
Conflicts:
|
|
|
7548c0 |
- src/conf/domain_conf.c: Some context mismatch, and some areas
|
|
|
7548c0 |
the original commit changes don't exist in this old libvirt yet
|
|
|
7548c0 |
or the calls are in other places because of refactors.
|
|
|
7548c0 |
|
|
|
7548c0 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
7548c0 |
Message-Id: <26a847deef5941fd90f892cf5fe1443cf3fc90ca.1602087923.git.mprivozn@redhat.com>
|
|
|
7548c0 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
7548c0 |
---
|
|
|
7548c0 |
src/conf/domain_conf.c | 135 ++++++++++-----------------------------
|
|
|
7548c0 |
src/libvirt_private.syms | 1 +
|
|
|
7548c0 |
src/util/virxml.c | 72 +++++++++++++++++++++
|
|
|
7548c0 |
src/util/virxml.h | 8 +++
|
|
|
7548c0 |
4 files changed, 114 insertions(+), 102 deletions(-)
|
|
|
7548c0 |
|
|
|
7548c0 |
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
|
|
|
7548c0 |
index 306926b64c..484f3b4352 100644
|
|
|
7548c0 |
--- a/src/conf/domain_conf.c
|
|
|
7548c0 |
+++ b/src/conf/domain_conf.c
|
|
|
7548c0 |
@@ -10644,75 +10644,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|
|
7548c0 |
goto cleanup;
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
-/**
|
|
|
7548c0 |
- * virDomainParseScaledValue:
|
|
|
7548c0 |
- * @xpath: XPath to memory amount
|
|
|
7548c0 |
- * @units_xpath: XPath to units attribute
|
|
|
7548c0 |
- * @ctxt: XPath context
|
|
|
7548c0 |
- * @val: scaled value is stored here
|
|
|
7548c0 |
- * @scale: default scale for @val
|
|
|
7548c0 |
- * @max: maximal @val allowed
|
|
|
7548c0 |
- * @required: is the value required?
|
|
|
7548c0 |
- *
|
|
|
7548c0 |
- * Parse a value located at @xpath within @ctxt, and store the
|
|
|
7548c0 |
- * result into @val. The value is scaled by units located at
|
|
|
7548c0 |
- * @units_xpath (or the 'unit' attribute under @xpath if
|
|
|
7548c0 |
- * @units_xpath is NULL). If units are not present, the default
|
|
|
7548c0 |
- * @scale is used. If @required is set, then the value must
|
|
|
7548c0 |
- * exist; otherwise, the value is optional. The resulting value
|
|
|
7548c0 |
- * is in bytes.
|
|
|
7548c0 |
- *
|
|
|
7548c0 |
- * Returns 1 on success,
|
|
|
7548c0 |
- * 0 if the value was not present and !@required,
|
|
|
7548c0 |
- * -1 on failure after issuing error.
|
|
|
7548c0 |
- */
|
|
|
7548c0 |
-static int
|
|
|
7548c0 |
-virDomainParseScaledValue(const char *xpath,
|
|
|
7548c0 |
- const char *units_xpath,
|
|
|
7548c0 |
- xmlXPathContextPtr ctxt,
|
|
|
7548c0 |
- unsigned long long *val,
|
|
|
7548c0 |
- unsigned long long scale,
|
|
|
7548c0 |
- unsigned long long max,
|
|
|
7548c0 |
- bool required)
|
|
|
7548c0 |
-{
|
|
|
7548c0 |
- unsigned long long bytes;
|
|
|
7548c0 |
- g_autofree char *xpath_full = NULL;
|
|
|
7548c0 |
- g_autofree char *unit = NULL;
|
|
|
7548c0 |
- g_autofree char *bytes_str = NULL;
|
|
|
7548c0 |
-
|
|
|
7548c0 |
- *val = 0;
|
|
|
7548c0 |
- xpath_full = g_strdup_printf("string(%s)", xpath);
|
|
|
7548c0 |
-
|
|
|
7548c0 |
- bytes_str = virXPathString(xpath_full, ctxt);
|
|
|
7548c0 |
- if (!bytes_str) {
|
|
|
7548c0 |
- if (!required)
|
|
|
7548c0 |
- return 0;
|
|
|
7548c0 |
- virReportError(VIR_ERR_XML_ERROR,
|
|
|
7548c0 |
- _("missing element or attribute '%s'"),
|
|
|
7548c0 |
- xpath);
|
|
|
7548c0 |
- return -1;
|
|
|
7548c0 |
- }
|
|
|
7548c0 |
- VIR_FREE(xpath_full);
|
|
|
7548c0 |
-
|
|
|
7548c0 |
- if (virStrToLong_ullp(bytes_str, NULL, 10, &bytes) < 0) {
|
|
|
7548c0 |
- virReportError(VIR_ERR_XML_ERROR,
|
|
|
7548c0 |
- _("Invalid value '%s' for element or attribute '%s'"),
|
|
|
7548c0 |
- bytes_str, xpath);
|
|
|
7548c0 |
- return -1;
|
|
|
7548c0 |
- }
|
|
|
7548c0 |
-
|
|
|
7548c0 |
- if (units_xpath)
|
|
|
7548c0 |
- xpath_full = g_strdup_printf("string(%s)", units_xpath);
|
|
|
7548c0 |
- else
|
|
|
7548c0 |
- xpath_full = g_strdup_printf("string(%s/@unit)", xpath);
|
|
|
7548c0 |
- unit = virXPathString(xpath_full, ctxt);
|
|
|
7548c0 |
-
|
|
|
7548c0 |
- if (virScaleInteger(&bytes, unit, scale, max) < 0)
|
|
|
7548c0 |
- return -1;
|
|
|
7548c0 |
-
|
|
|
7548c0 |
- *val = bytes;
|
|
|
7548c0 |
- return 1;
|
|
|
7548c0 |
-}
|
|
|
7548c0 |
|
|
|
7548c0 |
|
|
|
7548c0 |
/**
|
|
|
7548c0 |
@@ -10749,8 +10680,8 @@ virDomainParseMemory(const char *xpath,
|
|
|
7548c0 |
|
|
|
7548c0 |
max = virMemoryMaxValue(capped);
|
|
|
7548c0 |
|
|
|
7548c0 |
- if (virDomainParseScaledValue(xpath, units_xpath, ctxt,
|
|
|
7548c0 |
- &bytes, 1024, max, required) < 0)
|
|
|
7548c0 |
+ if (virParseScaledValue(xpath, units_xpath, ctxt,
|
|
|
7548c0 |
+ &bytes, 1024, max, required) < 0)
|
|
|
7548c0 |
return -1;
|
|
|
7548c0 |
|
|
|
7548c0 |
/* Yes, we really do use kibibytes for our internal sizing. */
|
|
|
7548c0 |
@@ -10792,9 +10723,9 @@ virDomainParseMemoryLimit(const char *xpath,
|
|
|
7548c0 |
int ret;
|
|
|
7548c0 |
unsigned long long bytes;
|
|
|
7548c0 |
|
|
|
7548c0 |
- ret = virDomainParseScaledValue(xpath, units_xpath, ctxt, &bytes, 1024,
|
|
|
7548c0 |
- VIR_DOMAIN_MEMORY_PARAM_UNLIMITED << 10,
|
|
|
7548c0 |
- false);
|
|
|
7548c0 |
+ ret = virParseScaledValue(xpath, units_xpath, ctxt, &bytes, 1024,
|
|
|
7548c0 |
+ VIR_DOMAIN_MEMORY_PARAM_UNLIMITED << 10,
|
|
|
7548c0 |
+ false);
|
|
|
7548c0 |
|
|
|
7548c0 |
if (ret < 0)
|
|
|
7548c0 |
return -1;
|
|
|
7548c0 |
@@ -11125,9 +11056,9 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|
|
7548c0 |
"have an address"));
|
|
|
7548c0 |
goto error;
|
|
|
7548c0 |
}
|
|
|
7548c0 |
- if ((rc = virDomainParseScaledValue("./pcihole64", NULL,
|
|
|
7548c0 |
- ctxt, &bytes, 1024,
|
|
|
7548c0 |
- 1024ULL * ULONG_MAX, false)) < 0)
|
|
|
7548c0 |
+ if ((rc = virParseScaledValue("./pcihole64", NULL,
|
|
|
7548c0 |
+ ctxt, &bytes, 1024,
|
|
|
7548c0 |
+ 1024ULL * ULONG_MAX, false)) < 0)
|
|
|
7548c0 |
goto error;
|
|
|
7548c0 |
|
|
|
7548c0 |
if (rc == 1)
|
|
|
7548c0 |
@@ -11349,14 +11280,14 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|
|
7548c0 |
}
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
- if (virDomainParseScaledValue("./space_hard_limit[1]",
|
|
|
7548c0 |
- NULL, ctxt, &def->space_hard_limit,
|
|
|
7548c0 |
- 1, ULLONG_MAX, false) < 0)
|
|
|
7548c0 |
+ if (virParseScaledValue("./space_hard_limit[1]",
|
|
|
7548c0 |
+ NULL, ctxt, &def->space_hard_limit,
|
|
|
7548c0 |
+ 1, ULLONG_MAX, false) < 0)
|
|
|
7548c0 |
goto error;
|
|
|
7548c0 |
|
|
|
7548c0 |
- if (virDomainParseScaledValue("./space_soft_limit[1]",
|
|
|
7548c0 |
- NULL, ctxt, &def->space_soft_limit,
|
|
|
7548c0 |
- 1, ULLONG_MAX, false) < 0)
|
|
|
7548c0 |
+ if (virParseScaledValue("./space_soft_limit[1]",
|
|
|
7548c0 |
+ NULL, ctxt, &def->space_soft_limit,
|
|
|
7548c0 |
+ 1, ULLONG_MAX, false) < 0)
|
|
|
7548c0 |
goto error;
|
|
|
7548c0 |
|
|
|
7548c0 |
cur = node->children;
|
|
|
7548c0 |
@@ -15205,8 +15136,8 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|
|
7548c0 |
goto cleanup;
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
- if (virDomainParseScaledValue("./size[1]", NULL, ctxt,
|
|
|
7548c0 |
- &def->size, 1, ULLONG_MAX, false) < 0)
|
|
|
7548c0 |
+ if (virParseScaledValue("./size[1]", NULL, ctxt,
|
|
|
7548c0 |
+ &def->size, 1, ULLONG_MAX, false) < 0)
|
|
|
7548c0 |
goto cleanup;
|
|
|
7548c0 |
|
|
|
7548c0 |
if ((server = virXPathNode("./server[1]", ctxt))) {
|
|
|
7548c0 |
@@ -19603,9 +19534,9 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
|
|
|
7548c0 |
return -1;
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
- if (virDomainParseScaledValue("./@size", "./@unit",
|
|
|
7548c0 |
- ctxt, &size, 1024,
|
|
|
7548c0 |
- ULLONG_MAX, true) < 0)
|
|
|
7548c0 |
+ if (virParseScaledValue("./@size", "./@unit",
|
|
|
7548c0 |
+ ctxt, &size, 1024,
|
|
|
7548c0 |
+ ULLONG_MAX, true) < 0)
|
|
|
7548c0 |
return -1;
|
|
|
7548c0 |
|
|
|
7548c0 |
if (virResctrlAllocSetCacheSize(alloc, level, type, cache, size) < 0)
|
|
|
7548c0 |
@@ -20712,13 +20643,13 @@ virDomainDefParseXML(xmlDocPtr xml,
|
|
|
7548c0 |
VIR_FREE(tmp);
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
- if (virDomainParseScaledValue("./features/hpt/maxpagesize",
|
|
|
7548c0 |
- NULL,
|
|
|
7548c0 |
- ctxt,
|
|
|
7548c0 |
- &def->hpt_maxpagesize,
|
|
|
7548c0 |
- 1024,
|
|
|
7548c0 |
- ULLONG_MAX,
|
|
|
7548c0 |
- false) < 0) {
|
|
|
7548c0 |
+ if (virParseScaledValue("./features/hpt/maxpagesize",
|
|
|
7548c0 |
+ NULL,
|
|
|
7548c0 |
+ ctxt,
|
|
|
7548c0 |
+ &def->hpt_maxpagesize,
|
|
|
7548c0 |
+ 1024,
|
|
|
7548c0 |
+ ULLONG_MAX,
|
|
|
7548c0 |
+ false) < 0) {
|
|
|
7548c0 |
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
7548c0 |
"%s",
|
|
|
7548c0 |
_("Unable to parse HPT maxpagesize setting"));
|
|
|
7548c0 |
@@ -20944,13 +20875,13 @@ virDomainDefParseXML(xmlDocPtr xml,
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
if (def->features[VIR_DOMAIN_FEATURE_SMM] == VIR_TRISTATE_SWITCH_ON) {
|
|
|
7548c0 |
- int rv = virDomainParseScaledValue("string(./features/smm/tseg)",
|
|
|
7548c0 |
- "string(./features/smm/tseg/@unit)",
|
|
|
7548c0 |
- ctxt,
|
|
|
7548c0 |
- &def->tseg_size,
|
|
|
7548c0 |
- 1024 * 1024, /* Defaults to mebibytes */
|
|
|
7548c0 |
- ULLONG_MAX,
|
|
|
7548c0 |
- false);
|
|
|
7548c0 |
+ int rv = virParseScaledValue("string(./features/smm/tseg)",
|
|
|
7548c0 |
+ "string(./features/smm/tseg/@unit)",
|
|
|
7548c0 |
+ ctxt,
|
|
|
7548c0 |
+ &def->tseg_size,
|
|
|
7548c0 |
+ 1024 * 1024, /* Defaults to mebibytes */
|
|
|
7548c0 |
+ ULLONG_MAX,
|
|
|
7548c0 |
+ false);
|
|
|
7548c0 |
if (rv < 0)
|
|
|
7548c0 |
goto error;
|
|
|
7548c0 |
def->tseg_specified = rv;
|
|
|
7548c0 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
7548c0 |
index 130828706a..acb25eb8c8 100644
|
|
|
7548c0 |
--- a/src/libvirt_private.syms
|
|
|
7548c0 |
+++ b/src/libvirt_private.syms
|
|
|
7548c0 |
@@ -3442,6 +3442,7 @@ virVsockSetGuestCid;
|
|
|
7548c0 |
|
|
|
7548c0 |
|
|
|
7548c0 |
# util/virxml.h
|
|
|
7548c0 |
+virParseScaledValue;
|
|
|
7548c0 |
virXMLCheckIllegalChars;
|
|
|
7548c0 |
virXMLChildElementCount;
|
|
|
7548c0 |
virXMLExtractNamespaceXML;
|
|
|
7548c0 |
diff --git a/src/util/virxml.c b/src/util/virxml.c
|
|
|
7548c0 |
index 0e66d1623b..bae2e6aca5 100644
|
|
|
7548c0 |
--- a/src/util/virxml.c
|
|
|
7548c0 |
+++ b/src/util/virxml.c
|
|
|
7548c0 |
@@ -33,6 +33,7 @@
|
|
|
7548c0 |
#include "viralloc.h"
|
|
|
7548c0 |
#include "virfile.h"
|
|
|
7548c0 |
#include "virstring.h"
|
|
|
7548c0 |
+#include "virutil.h"
|
|
|
7548c0 |
|
|
|
7548c0 |
#define VIR_FROM_THIS VIR_FROM_XML
|
|
|
7548c0 |
|
|
|
7548c0 |
@@ -1433,3 +1434,74 @@ virXMLNamespaceRegister(xmlXPathContextPtr ctxt,
|
|
|
7548c0 |
|
|
|
7548c0 |
return 0;
|
|
|
7548c0 |
}
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+/**
|
|
|
7548c0 |
+ * virParseScaledValue:
|
|
|
7548c0 |
+ * @xpath: XPath to memory amount
|
|
|
7548c0 |
+ * @units_xpath: XPath to units attribute
|
|
|
7548c0 |
+ * @ctxt: XPath context
|
|
|
7548c0 |
+ * @val: scaled value is stored here
|
|
|
7548c0 |
+ * @scale: default scale for @val
|
|
|
7548c0 |
+ * @max: maximal @val allowed
|
|
|
7548c0 |
+ * @required: is the value required?
|
|
|
7548c0 |
+ *
|
|
|
7548c0 |
+ * Parse a value located at @xpath within @ctxt, and store the
|
|
|
7548c0 |
+ * result into @val. The value is scaled by units located at
|
|
|
7548c0 |
+ * @units_xpath (or the 'unit' attribute under @xpath if
|
|
|
7548c0 |
+ * @units_xpath is NULL). If units are not present, the default
|
|
|
7548c0 |
+ * @scale is used. If @required is set, then the value must
|
|
|
7548c0 |
+ * exist; otherwise, the value is optional. The resulting value
|
|
|
7548c0 |
+ * is in bytes.
|
|
|
7548c0 |
+ *
|
|
|
7548c0 |
+ * Returns 1 on success,
|
|
|
7548c0 |
+ * 0 if the value was not present and !@required,
|
|
|
7548c0 |
+ * -1 on failure after issuing error.
|
|
|
7548c0 |
+ */
|
|
|
7548c0 |
+int
|
|
|
7548c0 |
+virParseScaledValue(const char *xpath,
|
|
|
7548c0 |
+ const char *units_xpath,
|
|
|
7548c0 |
+ xmlXPathContextPtr ctxt,
|
|
|
7548c0 |
+ unsigned long long *val,
|
|
|
7548c0 |
+ unsigned long long scale,
|
|
|
7548c0 |
+ unsigned long long max,
|
|
|
7548c0 |
+ bool required)
|
|
|
7548c0 |
+{
|
|
|
7548c0 |
+ unsigned long long bytes;
|
|
|
7548c0 |
+ g_autofree char *xpath_full = NULL;
|
|
|
7548c0 |
+ g_autofree char *unit = NULL;
|
|
|
7548c0 |
+ g_autofree char *bytes_str = NULL;
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ *val = 0;
|
|
|
7548c0 |
+ xpath_full = g_strdup_printf("string(%s)", xpath);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ bytes_str = virXPathString(xpath_full, ctxt);
|
|
|
7548c0 |
+ if (!bytes_str) {
|
|
|
7548c0 |
+ if (!required)
|
|
|
7548c0 |
+ return 0;
|
|
|
7548c0 |
+ virReportError(VIR_ERR_XML_ERROR,
|
|
|
7548c0 |
+ _("missing element or attribute '%s'"),
|
|
|
7548c0 |
+ xpath);
|
|
|
7548c0 |
+ return -1;
|
|
|
7548c0 |
+ }
|
|
|
7548c0 |
+ VIR_FREE(xpath_full);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ if (virStrToLong_ullp(bytes_str, NULL, 10, &bytes) < 0) {
|
|
|
7548c0 |
+ virReportError(VIR_ERR_XML_ERROR,
|
|
|
7548c0 |
+ _("Invalid value '%s' for element or attribute '%s'"),
|
|
|
7548c0 |
+ bytes_str, xpath);
|
|
|
7548c0 |
+ return -1;
|
|
|
7548c0 |
+ }
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ if (units_xpath)
|
|
|
7548c0 |
+ xpath_full = g_strdup_printf("string(%s)", units_xpath);
|
|
|
7548c0 |
+ else
|
|
|
7548c0 |
+ xpath_full = g_strdup_printf("string(%s/@unit)", xpath);
|
|
|
7548c0 |
+ unit = virXPathString(xpath_full, ctxt);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ if (virScaleInteger(&bytes, unit, scale, max) < 0)
|
|
|
7548c0 |
+ return -1;
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ *val = bytes;
|
|
|
7548c0 |
+ return 1;
|
|
|
7548c0 |
+}
|
|
|
7548c0 |
diff --git a/src/util/virxml.h b/src/util/virxml.h
|
|
|
7548c0 |
index 26ab9f9c2d..39b261687a 100644
|
|
|
7548c0 |
--- a/src/util/virxml.h
|
|
|
7548c0 |
+++ b/src/util/virxml.h
|
|
|
7548c0 |
@@ -269,3 +269,11 @@ virXMLNamespaceFormatNS(virBufferPtr buf,
|
|
|
7548c0 |
int
|
|
|
7548c0 |
virXMLNamespaceRegister(xmlXPathContextPtr ctxt,
|
|
|
7548c0 |
virXMLNamespace const *ns);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+int virParseScaledValue(const char *xpath,
|
|
|
7548c0 |
+ const char *units_xpath,
|
|
|
7548c0 |
+ xmlXPathContextPtr ctxt,
|
|
|
7548c0 |
+ unsigned long long *val,
|
|
|
7548c0 |
+ unsigned long long scale,
|
|
|
7548c0 |
+ unsigned long long max,
|
|
|
7548c0 |
+ bool required);
|
|
|
7548c0 |
--
|
|
|
7548c0 |
2.29.2
|
|
|
7548c0 |
|