mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Move virDomainParseScaledValue earlier
Let virDomainControllerDefParseXML use it without a forward declaration.
This commit is contained in:
parent
796513d7cc
commit
87e3a05cba
@ -5598,6 +5598,59 @@ error:
|
||||
}
|
||||
|
||||
|
||||
/* Parse a value located at XPATH within CTXT, and store the
|
||||
* result into val. If REQUIRED, then the value must exist;
|
||||
* otherwise, the value is optional. The value is in bytes.
|
||||
* Return 1 on success, 0 if the value was not present and
|
||||
* is not REQUIRED, -1 on failure after issuing error. */
|
||||
static int
|
||||
virDomainParseScaledValue(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long long *val,
|
||||
unsigned long long scale,
|
||||
unsigned long long max,
|
||||
bool required)
|
||||
{
|
||||
char *xpath_full = NULL;
|
||||
char *unit = NULL;
|
||||
int ret = -1;
|
||||
unsigned long long bytes;
|
||||
|
||||
*val = 0;
|
||||
if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0)
|
||||
goto cleanup;
|
||||
ret = virXPathULongLong(xpath_full, ctxt, &bytes);
|
||||
if (ret < 0) {
|
||||
if (ret == -2)
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("could not parse element %s"),
|
||||
xpath);
|
||||
else if (required)
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("missing element %s"),
|
||||
xpath);
|
||||
else
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
VIR_FREE(xpath_full);
|
||||
|
||||
if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0)
|
||||
goto cleanup;
|
||||
unit = virXPathString(xpath_full, ctxt);
|
||||
|
||||
if (virScaleInteger(&bytes, unit, scale, max) < 0)
|
||||
goto cleanup;
|
||||
|
||||
*val = bytes;
|
||||
ret = 1;
|
||||
cleanup:
|
||||
VIR_FREE(xpath_full);
|
||||
VIR_FREE(unit);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainControllerModelTypeFromString(const virDomainControllerDefPtr def,
|
||||
const char *model)
|
||||
@ -5788,58 +5841,6 @@ virDomainNetGenerateMAC(virDomainXMLOptionPtr xmlopt,
|
||||
}
|
||||
|
||||
|
||||
/* Parse a value located at XPATH within CTXT, and store the
|
||||
* result into val. If REQUIRED, then the value must exist;
|
||||
* otherwise, the value is optional. The value is in bytes.
|
||||
* Return 0 on success, -1 on failure after issuing error. */
|
||||
static int
|
||||
virDomainParseScaledValue(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long long *val,
|
||||
unsigned long long scale,
|
||||
unsigned long long max,
|
||||
bool required)
|
||||
{
|
||||
char *xpath_full = NULL;
|
||||
char *unit = NULL;
|
||||
int ret = -1;
|
||||
unsigned long long bytes;
|
||||
|
||||
*val = 0;
|
||||
if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0)
|
||||
goto cleanup;
|
||||
ret = virXPathULongLong(xpath_full, ctxt, &bytes);
|
||||
if (ret < 0) {
|
||||
if (ret == -2)
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("could not parse element %s"),
|
||||
xpath);
|
||||
else if (required)
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("missing element %s"),
|
||||
xpath);
|
||||
else
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
VIR_FREE(xpath_full);
|
||||
|
||||
if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0)
|
||||
goto cleanup;
|
||||
unit = virXPathString(xpath_full, ctxt);
|
||||
|
||||
if (virScaleInteger(&bytes, unit, scale, max) < 0)
|
||||
goto cleanup;
|
||||
|
||||
*val = bytes;
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(xpath_full);
|
||||
VIR_FREE(unit);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Parse the XML definition for a disk
|
||||
* @param node XML nodeset to parse for disk definition
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user