Each guest needs vcpu and memory, otherwise it's invalid.
Each guest also needs at least one of vdisk, vnet or iodevice, otherwise
it has nothing to boot from.

Consider this example:

        # cat foo.conf
        domain no-boot {
                vcpu 1
                memory 32G
        }
        domain no-vcpu {
                memory 32G
        }
        domain no-memory {
                vcpu 2
        }

Current code accepts the first two guests, only the latter would fail
with bogus "ldomctl: unable to allocate guest memory".

Diff below fixes each of these cases:

        # ldomctl init-system ../foo.conf
        foo.conf:4 at least one bootable device is required: no-boot
        foo.conf:7 vcpu is required: no-vcpu
        foo.conf:10 memory is required: no-memory

Alternatively, we could make vcpu and memory default to something,
eliminating such validation checks - we only need sane default values.

For devices there is no such possible default.

Feedback? OK?


Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ldomctl/parse.y,v
retrieving revision 1.14
diff -u -p -r1.14 parse.y
--- parse.y     9 Jan 2020 09:23:57 -0000       1.14
+++ parse.y     9 Jan 2020 20:44:51 -0000
@@ -124,6 +124,25 @@ domain             : DOMAIN STRING optnl '{' optnl 
                        SIMPLEQ_INIT(&domain->iodev_list);
                }
                    domainopts_l '}' {
+                       if (strcmp(domain->name, "primary") != 0) {
+                               if (domain->vcpu == 0) {
+                                       yyerror("vcpu is required: %s",
+                                           domain->name);
+                                       YYERROR;
+                               }
+                               if ( domain->memory == 0) {
+                                       yyerror("memory is required: %s",
+                                           domain->name);
+                                       YYERROR;
+                               }
+                               if (SIMPLEQ_EMPTY(&domain->vdisk_list) &&
+                                   SIMPLEQ_EMPTY(&domain->vnet_list) &&
+                                   SIMPLEQ_EMPTY(&domain->iodev_list)) {
+                                       yyerror("at least one bootable device"
+                                           " is required: %s", domain->name);
+                                       YYERROR;
+                               }
+                       }
                        SIMPLEQ_INSERT_TAIL(&conf->domain_list, domain, entry);
                        domain = NULL;
                }

Reply via email to