On Fri, May 22, 2020 at 11:35:34PM +0200, Mark Kettenis wrote:
> 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.
Yup, I fooled myself with poor testing - the commit is already reverted
with an explanation.  Didn't want to rush anything.

Here's version two that merely moves the "-n" check after the constraint
checks;  pri_init() continues to be called before using either of
`total_cpus' or `total_memory'.

        $ cat ldom.conf
        domain guest {
                vdisk "/dev/null"
                vcpu 1
                memory 1G
        }
        $ ./obj/ldomctl init-system -n ldom.conf ; echo $?
        0
        $ sed -i /memory/s,1,128, ldom.conf         
        $ ./obj/ldomctl init-system -n ldom.conf
        ldomctl: not enough memory available
        $ sed -i /cpu/s,1,128, ldom.conf         
        $ ./obj/ldomctl init-system -n ldom.conf
        ldomctl: not enough VCPU resources available


Feedback? OK?


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 22:11:59 -0000
@@ -2792,8 +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)
@@ -2822,6 +2826,9 @@ 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);
 
        hvmd_init(hvmd);
        primary = primary_init();

Reply via email to