When set sysinfo element without sub-elements,
libvirt will format it as:
<sysinfo type='smbios'>
</sysinfo>
After improve the format:
<sysinfo type='smbios'/>
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/util/virsysinfo.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 8bb17f0..f87376f 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -1041,31 +1041,42 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def)
int
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
{
+ virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
const char *type = virSysinfoTypeToString(def->type);
+ int indent = virBufferGetIndent(buf, false);
+ int ret = -1;
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sysinfo type model %d"),
def->type);
virBufferFreeAndReset(buf);
- return -1;
+ goto cleanup;
}
- virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type);
- virBufferAdjustIndent(buf, 2);
+ virBufferAdjustIndent(&childrenBuf, indent + 2);
- virSysinfoBIOSFormat(buf, def);
- virSysinfoSystemFormat(buf, def);
- virSysinfoProcessorFormat(buf, def);
- virSysinfoMemoryFormat(buf, def);
+ virSysinfoBIOSFormat(&childrenBuf, def);
+ virSysinfoSystemFormat(&childrenBuf, def);
+ virSysinfoProcessorFormat(&childrenBuf, def);
+ virSysinfoMemoryFormat(&childrenBuf, def);
- virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "</sysinfo>\n");
+ virBufferAsprintf(buf, "<sysinfo type='%s'", type);
+ if (virBufferUse(&childrenBuf)) {
+ virBufferAddLit(buf, ">\n");
+ virBufferAddBuffer(buf, &childrenBuf);
+ virBufferAddLit(buf, "</sysinfo>\n");
+ } else {
+ virBufferAddLit(buf, "/>\n");
+ }
if (virBufferCheckError(buf) < 0)
- return -1;
+ goto cleanup;
- return 0;
+ ret = 0;
+ cleanup:
+ virBufferFreeAndReset(&childrenBuf);
+ return ret;
}
bool virSysinfoIsEqual(virSysinfoDefPtr src,
--
1.8.3.1
Show replies by date
When set a redirfilter element without sub-element, libvirt will
format it like this:
<redirfilter>
</redirfilter>
Just drop this element if it do not have any sub-element.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/conf/domain_conf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bfdc94e..1034466 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20596,6 +20596,10 @@ virDomainRedirFilterDefFormat(virBufferPtr buf,
{
size_t i;
+ /* no need format an empty redirfilter */
+ if (filter->nusbdevs == 0)
+ return 0;
+
virBufferAddLit(buf, "<redirfilter>\n");
virBufferAdjustIndent(buf, 2);
for (i = 0; i < filter->nusbdevs; i++) {
--
1.8.3.1
On 05/22/2015 05:26 AM, Luyao Huang wrote:
When set a redirfilter element without sub-element, libvirt will
format it like this:
<redirfilter>
</redirfilter>
Just drop this element if it do not have any sub-element.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/conf/domain_conf.c | 4 ++++
1 file changed, 4 insertions(+)
ACK - I'll slightly adjust commit message before pushing
John
On 05/27/2015 08:00 AM, John Ferlan wrote:
On 05/22/2015 05:26 AM, Luyao Huang wrote:
> When set a redirfilter element without sub-element, libvirt will
> format it like this:
>
> <redirfilter>
> </redirfilter>
>
> Just drop this element if it do not have any sub-element.
>
> Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
> ---
> src/conf/domain_conf.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
ACK - I'll slightly adjust commit message before pushing
Thank you John :)
John
Luyao
On 05/22/2015 05:26 AM, Luyao Huang wrote:
When set sysinfo element without sub-elements,
libvirt will format it as:
<sysinfo type='smbios'>
</sysinfo>
After improve the format:
<sysinfo type='smbios'/>
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/util/virsysinfo.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
ACK - I'll slightly adjust commit message before pushing
John
On 05/27/2015 07:59 AM, John Ferlan wrote:
On 05/22/2015 05:26 AM, Luyao Huang wrote:
> When set sysinfo element without sub-elements,
> libvirt will format it as:
>
> <sysinfo type='smbios'>
> </sysinfo>
>
> After improve the format:
>
> <sysinfo type='smbios'/>
>
> Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
> ---
> src/util/virsysinfo.c | 33 ++++++++++++++++++++++-----------
> 1 file changed, 22 insertions(+), 11 deletions(-)
>
ACK - I'll slightly adjust commit message before pushing
Thanks for your quick review
John
Luyao