[PATCH v2 14/29] qemu: Use virXPathTristateBool()

Michal Privoznik via Devel posted 29 patches 1 week, 6 days ago
[PATCH v2 14/29] qemu: Use virXPathTristateBool()
Posted by Michal Privoznik via Devel 1 week, 6 days ago
From: Michal Privoznik <mprivozn@redhat.com>

There are two places in our code base which can use freshly
introduced virXPathTristateBool():
qemuStorageSourcePrivateDataParse() and
qemuDomainObjPrivateXMLParseBlockjobs().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b39fabfbb4..d675a5d7ee 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2073,7 +2073,7 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
     g_autofree char *authalias = NULL;
     g_autofree char *httpcookiealias = NULL;
     g_autofree char *tlskeyalias = NULL;
-    g_autofree char *thresholdEventWithIndex = NULL;
+    virTristateBool thresholdEventWithIndex;
     bool fdsetPresent = false;
     unsigned int fdSetID;
     int enccount;
@@ -2139,9 +2139,10 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
     if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
         return -1;
 
-    if ((thresholdEventWithIndex = virXPathString("string(./thresholdEvent/@indexUsed)", ctxt)) &&
-        virTristateBoolTypeFromString(thresholdEventWithIndex) == VIR_TRISTATE_BOOL_YES)
-        src->thresholdEventWithIndex = true;
+    if (virXPathTristateBool("string(./thresholdEvent/@indexUsed)",
+                             ctxt, &thresholdEventWithIndex) >= 0) {
+        virTristateBoolToBool(thresholdEventWithIndex, &src->thresholdEventWithIndex);
+    }
 
     if ((nbdkitnode = virXPathNode("nbdkit", ctxt))) {
         if (qemuStorageSourcePrivateDataParseNbdkit(nbdkitnode, ctxt, src) < 0)
@@ -3210,13 +3211,10 @@ qemuDomainObjPrivateXMLParseBlockjobs(virDomainObj *vm,
 {
     g_autofree xmlNodePtr *nodes = NULL;
     ssize_t nnodes = 0;
-    g_autofree char *active = NULL;
-    int tmp;
     size_t i;
 
-    if ((active = virXPathString("string(./blockjobs/@active)", ctxt)) &&
-        (tmp = virTristateBoolTypeFromString(active)) > 0)
-        priv->reconnectBlockjobs = tmp;
+    virXPathTristateBool("string(./blockjobs/@active)",
+                         ctxt, &priv->reconnectBlockjobs);
 
     if ((nnodes = virXPathNodeSet("./blockjobs/blockjob", ctxt, &nodes)) < 0)
         return -1;
-- 
2.49.1
Re: [PATCH v2 14/29] qemu: Use virXPathTristateBool()
Posted by Ján Tomko via Devel 1 week ago
On a Wednesday in 2025, Michal Privoznik via Devel wrote:
>From: Michal Privoznik <mprivozn@redhat.com>
>
>There are two places in our code base which can use freshly
>introduced virXPathTristateBool():
>qemuStorageSourcePrivateDataParse() and
>qemuDomainObjPrivateXMLParseBlockjobs().
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/qemu/qemu_domain.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
>diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>index b39fabfbb4..d675a5d7ee 100644
>--- a/src/qemu/qemu_domain.c
>+++ b/src/qemu/qemu_domain.c
>@@ -2073,7 +2073,7 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
>     g_autofree char *authalias = NULL;
>     g_autofree char *httpcookiealias = NULL;
>     g_autofree char *tlskeyalias = NULL;
>-    g_autofree char *thresholdEventWithIndex = NULL;
>+    virTristateBool thresholdEventWithIndex;
>     bool fdsetPresent = false;
>     unsigned int fdSetID;
>     int enccount;
>@@ -2139,9 +2139,10 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
>     if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
>         return -1;
>
>-    if ((thresholdEventWithIndex = virXPathString("string(./thresholdEvent/@indexUsed)", ctxt)) &&
>-        virTristateBoolTypeFromString(thresholdEventWithIndex) == VIR_TRISTATE_BOOL_YES)
>-        src->thresholdEventWithIndex = true;
>+    if (virXPathTristateBool("string(./thresholdEvent/@indexUsed)",
>+                             ctxt, &thresholdEventWithIndex) >= 0) {
>+        virTristateBoolToBool(thresholdEventWithIndex, &src->thresholdEventWithIndex);
>+    }
>
>     if ((nbdkitnode = virXPathNode("nbdkit", ctxt))) {
>         if (qemuStorageSourcePrivateDataParseNbdkit(nbdkitnode, ctxt, src) < 0)
>@@ -3210,13 +3211,10 @@ qemuDomainObjPrivateXMLParseBlockjobs(virDomainObj *vm,
> {
>     g_autofree xmlNodePtr *nodes = NULL;
>     ssize_t nnodes = 0;
>-    g_autofree char *active = NULL;
>-    int tmp;
>     size_t i;
>
>-    if ((active = virXPathString("string(./blockjobs/@active)", ctxt)) &&
>-        (tmp = virTristateBoolTypeFromString(active)) > 0)
>-        priv->reconnectBlockjobs = tmp;

No need to convert this, it is unused since:

commit 542d6c6bf2458bdf6296a4c50e87c67b2eb3f3ac
Author:     Peter Krempa <pkrempa@redhat.com>
CommitDate: 2022-08-11 15:12:20 +0200

     qemu: process: Remove pre-blockdev code paths

git describe: v8.6.0-149-g542d6c6bf2 contains: v8.7.0-rc1~110



Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
Re: [PATCH v2 14/29] qemu: Use virXPathTristateBool()
Posted by Michal Prívozník via Devel 6 days, 19 hours ago
On 10/15/25 03:45, Ján Tomko wrote:
> On a Wednesday in 2025, Michal Privoznik via Devel wrote:
>> From: Michal Privoznik <mprivozn@redhat.com>
>>
>> There are two places in our code base which can use freshly
>> introduced virXPathTristateBool():
>> qemuStorageSourcePrivateDataParse() and
>> qemuDomainObjPrivateXMLParseBlockjobs().
>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>> src/qemu/qemu_domain.c | 16 +++++++---------
>> 1 file changed, 7 insertions(+), 9 deletions(-)
>>
>> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>> index b39fabfbb4..d675a5d7ee 100644
>> --- a/src/qemu/qemu_domain.c
>> +++ b/src/qemu/qemu_domain.c
>> @@ -2073,7 +2073,7 @@
>> qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
>>     g_autofree char *authalias = NULL;
>>     g_autofree char *httpcookiealias = NULL;
>>     g_autofree char *tlskeyalias = NULL;
>> -    g_autofree char *thresholdEventWithIndex = NULL;
>> +    virTristateBool thresholdEventWithIndex;
>>     bool fdsetPresent = false;
>>     unsigned int fdSetID;
>>     int enccount;
>> @@ -2139,9 +2139,10 @@
>> qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
>>     if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
>>         return -1;
>>
>> -    if ((thresholdEventWithIndex = virXPathString("string(./
>> thresholdEvent/@indexUsed)", ctxt)) &&
>> -        virTristateBoolTypeFromString(thresholdEventWithIndex) ==
>> VIR_TRISTATE_BOOL_YES)
>> -        src->thresholdEventWithIndex = true;
>> +    if (virXPathTristateBool("string(./thresholdEvent/@indexUsed)",
>> +                             ctxt, &thresholdEventWithIndex) >= 0) {
>> +        virTristateBoolToBool(thresholdEventWithIndex, &src-
>> >thresholdEventWithIndex);
>> +    }
>>
>>     if ((nbdkitnode = virXPathNode("nbdkit", ctxt))) {
>>         if (qemuStorageSourcePrivateDataParseNbdkit(nbdkitnode, ctxt,
>> src) < 0)
>> @@ -3210,13 +3211,10 @@
>> qemuDomainObjPrivateXMLParseBlockjobs(virDomainObj *vm,
>> {
>>     g_autofree xmlNodePtr *nodes = NULL;
>>     ssize_t nnodes = 0;
>> -    g_autofree char *active = NULL;
>> -    int tmp;
>>     size_t i;
>>
>> -    if ((active = virXPathString("string(./blockjobs/@active)",
>> ctxt)) &&
>> -        (tmp = virTristateBoolTypeFromString(active)) > 0)
>> -        priv->reconnectBlockjobs = tmp;
> 
> No need to convert this, it is unused since:
> 
> commit 542d6c6bf2458bdf6296a4c50e87c67b2eb3f3ac
> Author:     Peter Krempa <pkrempa@redhat.com>
> CommitDate: 2022-08-11 15:12:20 +0200
> 
>     qemu: process: Remove pre-blockdev code paths
> 
> git describe: v8.6.0-149-g542d6c6bf2 contains: v8.7.0-rc1~110
> 

Why wasn't it removed then? I'll post a patch for that.

Michal