[PATCH 0/2] Remove use of deprecated 'xmlIndentTreeOutput' variable from libxml2
The default from libxml2 is '1' which we wanted. Thus all use in separate processes is okay, and for the few exceptions (see 2/2) the resulting XML is mis-indented but valid for any app which would override it. Peter Krempa (2): virVBoxSnapshotConfSaveVboxFile: Don't modify deprecated 'xmlIndentTreeOutput' virXMLFormatMetadata: Don't modify deprecated 'xmlIndentTreeOutput' src/util/virxml.c | 10 ---------- src/vbox/vbox_snapshot_conf.c | 5 ----- 2 files changed, 15 deletions(-) -- 2.51.1
From: Peter Krempa <pkrempa@redhat.com> 'xmlIndentTreeOutput' is now deprecated by libxml2. The default value set by libxml2 is '1', and the vbox driver resides only inside the standalone daemon where the value will not be changed by us thus there's no observable change in behaviour. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/vbox/vbox_snapshot_conf.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index b424648368..ff81cd0062 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -943,9 +943,6 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, g_auto(GStrv) secondRegex = NULL; int secondRegexResult = 0; const int parseFlags = XML_PARSE_NONET | XML_PARSE_NOBLANKS; - int oldIndentTreeOutput = xmlIndentTreeOutput; - - xmlIndentTreeOutput = 1; if (machine == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1127,8 +1124,6 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine, ret = 0; cleanup: - xmlIndentTreeOutput = oldIndentTreeOutput; - VIR_FREE(currentSnapshot); VIR_FREE(timeStamp); -- 2.51.1
From: Peter Krempa <pkrempa@redhat.com> 'libxml2' deprecated the 'xmlIndentTreeOutput' thread-local variable as well as the 'xmlThrDefIndentTreeOutput' function for setting the global default, which we use in our code for formatting the metadata sub-XML. 'libxml2' also for now doesn't provide a way to set target indentation level in 'xmlSaveCtxt' which would allow us to use the modern output APIs, we can't replace our use of 'xmlDumpNode'. Since the indentation is enabled by default in libxml2 and most of our code using xmlDumpNode (notably except for the 'test' driver and embedded qemu driver uses) is in standalone processes, which didn't change the default, just removing the override will result in identical behaviour. For the two exeptions, the result of changing the default would be that the <metadata> part would be un-indented, but that is still valid XML. Thus to fix the deprecated use just stop setting 'xmlIndentTreeOutput'. Closes: https://gitlab.com/libvirt/libvirt/-/issues/816 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virxml.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 44f11accf3..77c7b5a8f4 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1920,23 +1920,14 @@ virXMLFormatMetadata(virBuffer *buf, { g_autoptr(xmlBuffer) xmlbuf = NULL; const char *xmlbufContent = NULL; - int oldIndentTreeOutput = xmlIndentTreeOutput; if (!metadata) return 0; - /* Indentation on output requires that we previously set - * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2 - * spaces per level of indentation of intermediate elements, - * but no leading indentation before the starting element. - * Thankfully, libxml maps what looks like globals into - * thread-local uses, so we are thread-safe. */ - xmlIndentTreeOutput = 1; xmlbuf = virXMLBufferCreate(); if (xmlNodeDump(xmlbuf, metadata->doc, metadata, virBufferGetIndent(buf) / 2, 1) < 0) { - xmlIndentTreeOutput = oldIndentTreeOutput; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to format metadata element")); return -1; @@ -1948,7 +1939,6 @@ virXMLFormatMetadata(virBuffer *buf, virSkipSpaces(&xmlbufContent); virBufferAsprintf(buf, "%s\n", xmlbufContent); - xmlIndentTreeOutput = oldIndentTreeOutput; return 0; } -- 2.51.1
On 11/10/25 17:20, Peter Krempa via Devel wrote:
From: Peter Krempa <pkrempa@redhat.com>
'libxml2' deprecated the 'xmlIndentTreeOutput' thread-local variable as well as the 'xmlThrDefIndentTreeOutput' function for setting the global default, which we use in our code for formatting the metadata sub-XML.
'libxml2' also for now doesn't provide a way to set target indentation level in 'xmlSaveCtxt' which would allow us to use the modern output APIs, we can't replace our use of 'xmlDumpNode'.
Here, I'd like a reference to: https://gitlab.gnome.org/GNOME/libxml2/-/issues/989
Since the indentation is enabled by default in libxml2 and most of our code using xmlDumpNode (notably except for the 'test' driver and embedded qemu driver uses) is in standalone processes, which didn't change the default, just removing the override will result in identical behaviour.
I think there are more drivers like that: ESX, VMWare, hyperv and maybe others.
For the two exeptions, the result of changing the default would be that
exceptions
the <metadata> part would be un-indented, but that is still valid XML.
Agreed. Once the aforementioned issue is fixed this can be switched to xmlSaveTree().
Thus to fix the deprecated use just stop setting 'xmlIndentTreeOutput'.
Closes: https://gitlab.com/libvirt/libvirt/-/issues/816 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virxml.c | 10 ---------- 1 file changed, 10 deletions(-)
diff --git a/src/util/virxml.c b/src/util/virxml.c index 44f11accf3..77c7b5a8f4 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1920,23 +1920,14 @@ virXMLFormatMetadata(virBuffer *buf, { g_autoptr(xmlBuffer) xmlbuf = NULL; const char *xmlbufContent = NULL; - int oldIndentTreeOutput = xmlIndentTreeOutput;
if (!metadata) return 0;
- /* Indentation on output requires that we previously set - * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2 - * spaces per level of indentation of intermediate elements, - * but no leading indentation before the starting element. - * Thankfully, libxml maps what looks like globals into - * thread-local uses, so we are thread-safe. */ - xmlIndentTreeOutput = 1; xmlbuf = virXMLBufferCreate();
if (xmlNodeDump(xmlbuf, metadata->doc, metadata, virBufferGetIndent(buf) / 2, 1) < 0) { - xmlIndentTreeOutput = oldIndentTreeOutput; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to format metadata element")); return -1; @@ -1948,7 +1939,6 @@ virXMLFormatMetadata(virBuffer *buf, virSkipSpaces(&xmlbufContent);
virBufferAsprintf(buf, "%s\n", xmlbufContent); - xmlIndentTreeOutput = oldIndentTreeOutput;
return 0; }
Michal
On Tue, Nov 11, 2025 at 09:35:59 +0100, Michal Prívozník wrote:
On 11/10/25 17:20, Peter Krempa via Devel wrote:
From: Peter Krempa <pkrempa@redhat.com>
'libxml2' deprecated the 'xmlIndentTreeOutput' thread-local variable as well as the 'xmlThrDefIndentTreeOutput' function for setting the global default, which we use in our code for formatting the metadata sub-XML.
'libxml2' also for now doesn't provide a way to set target indentation level in 'xmlSaveCtxt' which would allow us to use the modern output APIs, we can't replace our use of 'xmlDumpNode'.
Here, I'd like a reference to:
I'll add: (See https://gitlab.gnome.org/GNOME/libxml2/-/issues/989) on the next line.
Since the indentation is enabled by default in libxml2 and most of our code using xmlDumpNode (notably except for the 'test' driver and embedded qemu driver uses) is in standalone processes, which didn't change the default, just removing the override will result in identical behaviour.
I think there are more drivers like that: ESX, VMWare, hyperv and maybe others.
For the two exeptions, the result of changing the default would be that
exceptions
How about avoiding the issue by not naming anything: Since the indentation is enabled by default in libxml2 and our most commonly used code which calls xmlDumpNode lives in a standalone process, where we don't override the setting, just removing the override will result in identical behaviour. For the use cases which do live in a process we don't fully control and thus the default could have been overriden, the result would be that the <metadata> element would be un-indented, but that is still valid XML.
Agreed. Once the aforementioned issue is fixed this can be switched to xmlSaveTree().
Thus to fix the deprecated use just stop setting 'xmlIndentTreeOutput'.
Closes: https://gitlab.com/libvirt/libvirt/-/issues/816 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virxml.c | 10 ---------- 1 file changed, 10 deletions(-)
diff --git a/src/util/virxml.c b/src/util/virxml.c index 44f11accf3..77c7b5a8f4 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1920,23 +1920,14 @@ virXMLFormatMetadata(virBuffer *buf, { g_autoptr(xmlBuffer) xmlbuf = NULL; const char *xmlbufContent = NULL; - int oldIndentTreeOutput = xmlIndentTreeOutput;
if (!metadata) return 0;
- /* Indentation on output requires that we previously set - * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2 - * spaces per level of indentation of intermediate elements, - * but no leading indentation before the starting element. - * Thankfully, libxml maps what looks like globals into - * thread-local uses, so we are thread-safe. */ - xmlIndentTreeOutput = 1; xmlbuf = virXMLBufferCreate();
if (xmlNodeDump(xmlbuf, metadata->doc, metadata, virBufferGetIndent(buf) / 2, 1) < 0) { - xmlIndentTreeOutput = oldIndentTreeOutput; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to format metadata element")); return -1; @@ -1948,7 +1939,6 @@ virXMLFormatMetadata(virBuffer *buf, virSkipSpaces(&xmlbufContent);
virBufferAsprintf(buf, "%s\n", xmlbufContent); - xmlIndentTreeOutput = oldIndentTreeOutput;
return 0; }
Michal
On Tue, Nov 11, 2025 at 09:35:59AM +0100, Michal Prívozník via Devel wrote:
On 11/10/25 17:20, Peter Krempa via Devel wrote:
From: Peter Krempa <pkrempa@redhat.com>
'libxml2' deprecated the 'xmlIndentTreeOutput' thread-local variable as well as the 'xmlThrDefIndentTreeOutput' function for setting the global default, which we use in our code for formatting the metadata sub-XML.
'libxml2' also for now doesn't provide a way to set target indentation level in 'xmlSaveCtxt' which would allow us to use the modern output APIs, we can't replace our use of 'xmlDumpNode'.
Here, I'd like a reference to:
https://gitlab.gnome.org/GNOME/libxml2/-/issues/989
Since the indentation is enabled by default in libxml2 and most of our code using xmlDumpNode (notably except for the 'test' driver and embedded qemu driver uses) is in standalone processes, which didn't change the default, just removing the override will result in identical behaviour.
I think there are more drivers like that: ESX, VMWare, hyperv and maybe others.
IIUC, this problem only affects drivers which support the metadata XML, and none of those wire up the metadata support. $ git grep 'domainSetMetadata =' src/bhyve/bhyve_driver.c: .domainSetMetadata = bhyveDomainSetMetadata, /* 1.2.4 */ src/libxl/libxl_driver.c: .domainSetMetadata = libxlDomainSetMetadata, /* 5.7.0 */ src/lxc/lxc_driver.c: .domainSetMetadata = lxcDomainSetMetadata, /* 1.1.3 */ src/qemu/qemu_driver.c: .domainSetMetadata = qemuDomainSetMetadata, /* 0.9.10 */ src/remote/remote_driver.c: .domainSetMetadata = remoteDomainSetMetadata, /* 0.9.10 */ src/test/test_driver.c: .domainSetMetadata = testDomainSetMetadata, /* 1.1.3 */ With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
On 11/10/25 17:20, Peter Krempa via Devel wrote:
The default from libxml2 is '1' which we wanted. Thus all use in separate processes is okay, and for the few exceptions (see 2/2) the resulting XML is mis-indented but valid for any app which would override it.
Peter Krempa (2): virVBoxSnapshotConfSaveVboxFile: Don't modify deprecated 'xmlIndentTreeOutput' virXMLFormatMetadata: Don't modify deprecated 'xmlIndentTreeOutput'
src/util/virxml.c | 10 ---------- src/vbox/vbox_snapshot_conf.c | 5 ----- 2 files changed, 15 deletions(-)
It's a bit unfortunate that libxml2 deprecated an API without offering a replacement, but since the newest version is getting into distros and causing us compile-time warnings we have to act. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (3)
-
Daniel P. Berrangé -
Michal Prívozník -
Peter Krempa