Re: [PATCH v4 3/3] vl: Abort if multiple machines are registered as default

2020-02-08 Thread David Gibson
On Fri, Feb 07, 2020 at 05:19:48PM +0100, Philippe Mathieu-Daudé wrote:
> It would be confusing to have multiple default machines.
> Abort if this ever occurs.
> 
> Signed-off-by: Philippe Mathieu-Daudé 

Reviewed-by: David Gibson 

> ---
> v2: Use assert() instead of human friendly message (Marc-André)
> v3: Move the check to find_machine() (Michael)
> 
> Cc: Marc-André Lureau 
> Cc: Laurent Vivier 
> Cc: Michael S. Tsirkin 
> ---
>  vl.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/vl.c b/vl.c
> index 7dcb0879c4..ebc203af0d 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1184,16 +1184,18 @@ static MachineClass *find_machine(const char *name, 
> GSList *machines)
>  static MachineClass *find_default_machine(GSList *machines)
>  {
>  GSList *el;
> +MachineClass *default_machineclass = NULL;
>  
>  for (el = machines; el; el = el->next) {
>  MachineClass *mc = el->data;
>  
>  if (mc->is_default) {
> -return mc;
> +assert(default_machineclass == NULL && "Multiple default 
> machines");
> +default_machineclass = mc;
>  }
>  }
>  
> -return NULL;
> +return default_machineclass;
>  }
>  
>  static int machine_help_func(QemuOpts *opts, MachineState *machine)

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [PATCH v4 3/3] vl: Abort if multiple machines are registered as default

2020-02-07 Thread Laurent Vivier
Le 07/02/2020 à 17:19, Philippe Mathieu-Daudé a écrit :
> It would be confusing to have multiple default machines.
> Abort if this ever occurs.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
> v2: Use assert() instead of human friendly message (Marc-André)
> v3: Move the check to find_machine() (Michael)
> 
> Cc: Marc-André Lureau 
> Cc: Laurent Vivier 
> Cc: Michael S. Tsirkin 
> ---
>  vl.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/vl.c b/vl.c
> index 7dcb0879c4..ebc203af0d 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1184,16 +1184,18 @@ static MachineClass *find_machine(const char *name, 
> GSList *machines)
>  static MachineClass *find_default_machine(GSList *machines)
>  {
>  GSList *el;
> +MachineClass *default_machineclass = NULL;
>  
>  for (el = machines; el; el = el->next) {
>  MachineClass *mc = el->data;
>  
>  if (mc->is_default) {
> -return mc;
> +assert(default_machineclass == NULL && "Multiple default 
> machines");
> +default_machineclass = mc;
>  }
>  }
>  
> -return NULL;
> +return default_machineclass;
>  }
>  
>  static int machine_help_func(QemuOpts *opts, MachineState *machine)
> 

Reviewed-by: Laurent Vivier 
Tested-by: Laurent Vivier 

I've tested "make check" actually fails when we have several default
machines.

Thanks,
Laurent



Re: [PATCH v4 3/3] vl: Abort if multiple machines are registered as default

2020-02-07 Thread Marc-André Lureau
On Fri, Feb 7, 2020 at 5:21 PM Philippe Mathieu-Daudé  wrote:
>
> It would be confusing to have multiple default machines.
> Abort if this ever occurs.
>
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
> v2: Use assert() instead of human friendly message (Marc-André)
> v3: Move the check to find_machine() (Michael)
>
> Cc: Marc-André Lureau 
> Cc: Laurent Vivier 
> Cc: Michael S. Tsirkin 

Reviewed-by: Marc-André Lureau 


> ---
>  vl.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/vl.c b/vl.c
> index 7dcb0879c4..ebc203af0d 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1184,16 +1184,18 @@ static MachineClass *find_machine(const char *name, 
> GSList *machines)
>  static MachineClass *find_default_machine(GSList *machines)
>  {
>  GSList *el;
> +MachineClass *default_machineclass = NULL;
>
>  for (el = machines; el; el = el->next) {
>  MachineClass *mc = el->data;
>
>  if (mc->is_default) {
> -return mc;
> +assert(default_machineclass == NULL && "Multiple default 
> machines");
> +default_machineclass = mc;
>  }
>  }
>
> -return NULL;
> +return default_machineclass;
>  }
>
>  static int machine_help_func(QemuOpts *opts, MachineState *machine)
> --
> 2.21.1
>


-- 
Marc-André Lureau



[PATCH v4 3/3] vl: Abort if multiple machines are registered as default

2020-02-07 Thread Philippe Mathieu-Daudé
It would be confusing to have multiple default machines.
Abort if this ever occurs.

Signed-off-by: Philippe Mathieu-Daudé 
---
v2: Use assert() instead of human friendly message (Marc-André)
v3: Move the check to find_machine() (Michael)

Cc: Marc-André Lureau 
Cc: Laurent Vivier 
Cc: Michael S. Tsirkin 
---
 vl.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index 7dcb0879c4..ebc203af0d 100644
--- a/vl.c
+++ b/vl.c
@@ -1184,16 +1184,18 @@ static MachineClass *find_machine(const char *name, 
GSList *machines)
 static MachineClass *find_default_machine(GSList *machines)
 {
 GSList *el;
+MachineClass *default_machineclass = NULL;
 
 for (el = machines; el; el = el->next) {
 MachineClass *mc = el->data;
 
 if (mc->is_default) {
-return mc;
+assert(default_machineclass == NULL && "Multiple default 
machines");
+default_machineclass = mc;
 }
 }
 
-return NULL;
+return default_machineclass;
 }
 
 static int machine_help_func(QemuOpts *opts, MachineState *machine)
-- 
2.21.1