[libvirt] [PATCH 3/3] qemu/qemu_migration_params: use virStringParseYesNo helper

Mao Zhongyi posted 3 patches 6 years, 3 months ago
There is a newer version of this series
[libvirt] [PATCH 3/3] qemu/qemu_migration_params: use virStringParseYesNo helper
Posted by Mao Zhongyi 6 years, 3 months ago
A function virStringParseYesNo was added to convert
string 'yes' to true and 'no' to false, so use this
helper to replace 'STREQ(.*, \"yes\")' and
'STREQ(.*, \"no\")' as it allows us to drop several
repetitive if-then-else string->bool conversion blocks.

Cc: jdenemar@redhat.com
Cc: g.sho1500@gmail.com
Cc: crobinso@redhat.com

Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
---
 src/qemu/qemu_migration_params.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 85fa8f8de5..acd42042fe 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -1326,11 +1326,7 @@ qemuMigrationParamsParse(xmlXPathContextPtr ctxt,
             break;
 
         case QEMU_MIGRATION_PARAM_TYPE_BOOL:
-            if (STREQ(value, "yes"))
-                pv->value.b = true;
-            else if (STREQ(value, "no"))
-                pv->value.b = false;
-            else
+            if (virStringParseYesNo(value, &pv->value.b) < 0)
                 rc = -1;
             break;
 
-- 
2.17.1



--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] qemu/qemu_migration_params: use virStringParseYesNo helper
Posted by Michal Privoznik 6 years, 3 months ago
On 10/16/19 4:39 AM, Mao Zhongyi wrote:
> A function virStringParseYesNo was added to convert
> string 'yes' to true and 'no' to false, so use this
> helper to replace 'STREQ(.*, \"yes\")' and
> 'STREQ(.*, \"no\")' as it allows us to drop several
> repetitive if-then-else string->bool conversion blocks.
> 
> Cc: jdenemar@redhat.com
> Cc: g.sho1500@gmail.com
> Cc: crobinso@redhat.com
> 
> Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
> ---
>   src/qemu/qemu_migration_params.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
> index 85fa8f8de5..acd42042fe 100644
> --- a/src/qemu/qemu_migration_params.c
> +++ b/src/qemu/qemu_migration_params.c
> @@ -1326,11 +1326,7 @@ qemuMigrationParamsParse(xmlXPathContextPtr ctxt,
>               break;
>   
>           case QEMU_MIGRATION_PARAM_TYPE_BOOL:
> -            if (STREQ(value, "yes"))
> -                pv->value.b = true;
> -            else if (STREQ(value, "no"))
> -                pv->value.b = false;
> -            else
> +            if (virStringParseYesNo(value, &pv->value.b) < 0)
>                   rc = -1;
>               break;
>   
> 

Or simply rc = virStringParseYesNo(...), but your change is good too.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list