> Date: Fri, 22 May 2020 23:05:21 +0200
> From: Klemens Nanni <[email protected]>
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> 
> 
> kmos noted that `-n' wouldn't bark at overallocation.
> 
> Hoisting PRI reading and moving the `-n' check after constraint checking
> makes it bail on invalid configs just as expected:
> 
>       $ cat ldom.conf
>       domain guest {
>               vdisk "/dev/null"
>               vcpu 128
>               memory 1G
>       }
>       $ ldomctl init-sytem -n ldom.conf ; echo $?
>       0
>       $ ./obj/ldomctl init-sytem -n ldom.conf
>       ldomctl: not enough VCPU resources available
> 
> 
> OK?

That can't be right.  We get the number of available CPUs for example
from the PRI so pri_init() has to be called before we check.

> Index: config.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/config.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 config.c
> --- config.c  17 Mar 2020 21:24:22 -0000      1.36
> +++ config.c  22 May 2020 21:01:17 -0000
> @@ -2792,18 +2798,6 @@ build_config(const char *filename, int n
>       SIMPLEQ_INIT(&conf.domain_list);
>       if (parse_config(filename, &conf) < 0)
>               exit(1);
> -     if (noaction)
> -             exit(0);
> -
> -     pri = md_read("pri");
> -     if (pri == NULL)
> -             err(1, "unable to get PRI");
> -     hvmd = md_read("hv.md");
> -     if (hvmd == NULL)
> -             err(1, "unable to get Hypervisor MD");
> -
> -     pri_init(pri);
> -     pri_alloc_memory(hv_membase, hv_memsize);
>  
>       SIMPLEQ_FOREACH(domain, &conf.domain_list, entry) {
>               if (strcmp(domain->name, "primary") == 0) {
> @@ -2822,6 +2816,19 @@ build_config(const char *filename, int n
>               errx(1, "not enough VCPU resources available");
>       if (memory > total_memory || primary_memory == 0)
>               errx(1, "not enough memory available");
> +
> +     if (noaction)
> +             exit(0);
> +
> +     pri = md_read("pri");
> +     if (pri == NULL)
> +             err(1, "unable to get PRI");
> +     hvmd = md_read("hv.md");
> +     if (hvmd == NULL)
> +             err(1, "unable to get Hypervisor MD");
> +
> +     pri_init(pri);
> +     pri_alloc_memory(hv_membase, hv_memsize);
>  
>       hvmd_init(hvmd);
>       primary = primary_init();
> 
> 

Reply via email to