From: Michal Privoznik Date: Fri, 23 Jan 2026 09:09:15 +0000 (+0100) Subject: conf: Teach virDomainParseMemory() new retval X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1c6e3fef084010537b90cec5c65319134e9a3ae;p=thirdparty%2Flibvirt.git conf: Teach virDomainParseMemory() new retval So far, virDomainParseMemory() returns either 0 or -1. While this allows callers to distinguish a success case from an error it doesn't allow them to differentiate the case when no value was provided in the XML, thus nothing was parsed and nothing was required. Therefore, make virDomainParseMemory() return 1 on success, 0 in case nothing was parsed and nothing was required, and -1 on failure. Arguably, no caller needs this distinction currently, but that is about to change. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 02e23f7866..7e4de6d1f9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8729,7 +8729,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, * if @capped is true, the value must fit within an unsigned long * (only matters on 32-bit platforms). * - * Return 0 on success, -1 on failure after issuing error. + * Returns: 1 if value was parsed successfully, + * 0 if value wasn't present and @required is false, + * -1 on failure after issuing error. */ int virDomainParseMemory(const char *xpath, @@ -8740,21 +8742,27 @@ virDomainParseMemory(const char *xpath, bool capped) { unsigned long long bytes, max; + int rc; max = virMemoryMaxValue(capped); - if (virParseScaledValue(xpath, units_xpath, ctxt, - &bytes, 1024, max, required) < 0) + rc = virParseScaledValue(xpath, units_xpath, ctxt, + &bytes, 1024, max, required); + if (rc < 0) { return -1; + } else if (rc == 0) { + *mem = 0; + return 0; + } - /* Yes, we really do use kibibytes for our internal sizing. */ + /* Yes, we really do use kibibytes for our internal sizing. */ *mem = VIR_DIV_UP(bytes, 1024); if (*mem >= VIR_DIV_UP(max, 1024)) { virReportError(VIR_ERR_OVERFLOW, "%s", _("size value too large")); return -1; } - return 0; + return 1; }