Re: [PATCH 2/6] nodeDeviceParseMdevctlJSON: Accept empty string

2023-08-24 Thread Kristina Hanicova
On Thu, Aug 24, 2023 at 10:57 AM Michal Privoznik 
wrote:

> It is possible for 'mdevctl' to output nothing, an empty string
> (e.g. when no mediated devices are defined on the host). What is
> weird is that when passing '--defined' then 'mdevctl' outputs an
> empty JSON array instead. Nevertheless, we should accept both and
> threat them the same, i.e. as no mediated devices.
>

*treat


> Resolves: https://gitlab.com/libvirt/libvirt/-/issues/523
> Signed-off-by: Michal Privoznik 
> ---
>  src/node_device/node_device_driver.c | 7 +++
>  1 file changed, 7 insertions(+)
>
> diff --git a/src/node_device/node_device_driver.c
> b/src/node_device/node_device_driver.c
> index 2ef9197adc..593bc64e25 100644
> --- a/src/node_device/node_device_driver.c
> +++ b/src/node_device/node_device_driver.c
> @@ -43,6 +43,7 @@
>  #include "virutil.h"
>  #include "vircommand.h"
>  #include "virlog.h"
> +#include "virstring.h"
>
>  #define VIR_FROM_THIS VIR_FROM_NODEDEV
>
> @@ -1176,6 +1177,12 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring,
>  size_t j;
>  virJSONValue *obj;
>
> +if (virStringIsEmpty(jsonstring)) {
> +VIR_DEBUG("mdevctl has no defined mediated devices");
> +*devs = NULL;
> +return 0;
> +}
> +
>  json_devicelist = virJSONValueFromString(jsonstring);
>
>  if (!json_devicelist || !virJSONValueIsArray(json_devicelist)) {
> --
> 2.41.0
>
>
Reviewed-by: Kristina Hanicova 
Kristina


[PATCH 2/6] nodeDeviceParseMdevctlJSON: Accept empty string

2023-08-24 Thread Michal Privoznik
It is possible for 'mdevctl' to output nothing, an empty string
(e.g. when no mediated devices are defined on the host). What is
weird is that when passing '--defined' then 'mdevctl' outputs an
empty JSON array instead. Nevertheless, we should accept both and
threat them the same, i.e. as no mediated devices.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/523
Signed-off-by: Michal Privoznik 
---
 src/node_device/node_device_driver.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index 2ef9197adc..593bc64e25 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -43,6 +43,7 @@
 #include "virutil.h"
 #include "vircommand.h"
 #include "virlog.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NODEDEV
 
@@ -1176,6 +1177,12 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring,
 size_t j;
 virJSONValue *obj;
 
+if (virStringIsEmpty(jsonstring)) {
+VIR_DEBUG("mdevctl has no defined mediated devices");
+*devs = NULL;
+return 0;
+}
+
 json_devicelist = virJSONValueFromString(jsonstring);
 
 if (!json_devicelist || !virJSONValueIsArray(json_devicelist)) {
-- 
2.41.0