On Mon, Jan 13, 2020 at 12:59:23PM +0100, Klemens Nanni wrote:
> On Sun, Jan 05, 2020 at 07:09:46PM +0100, Klemens Nanni wrote:
> > Domains get to define their cores and memory only once unlike the other
> > parameters of which it makes sense to have more than one.
> > 
> >     $ cat dup.conf
> >     domain primary {
> >             vcpu 2
> >             vcpu 2
> >     }
> >     $ ldomctl init-system -n dup.conf ; echo $?
> >     0
> >     $ ./obj/ldomctl init-system -n dup.conf
> >     dup.conf:3 duplicate vcpu option
> > 
> > OK?
> Now that checks for mandatory options are in, this somewhat completes
> it at the other end.
> 
> Here's the same diff with an additional check for duplicate iodevices,
> only that those must be globally unique (just like domain names).
> 
> OK?
This still is still in my tree.

It properly detects duplicate vcpu and memory lines for all domains
including the primary one;  duplicate iodevice lines are only detected
for guest domains;  preventing iodevice, vnet and vdisk lines in the
primary domain is stuff for a separate diff.

Feedback? OK?


Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ldomctl/parse.y,v
retrieving revision 1.18
diff -u -p -r1.18 parse.y
--- parse.y     21 Feb 2020 19:39:28 -0000      1.18
+++ parse.y     23 May 2020 09:23:58 -0000
@@ -166,10 +166,18 @@ domainoptsl       : domainopts nl
                ;
 
 domainopts     : VCPU vcpu {
+                       if (domain->vcpu) {
+                               yyerror("duplicate vcpu option");
+                               YYERROR;
+                       }
                        domain->vcpu = $2.count;
                        domain->vcpu_stride = $2.stride;
                }
                | MEMORY memory {
+                       if (domain->memory) {
+                               yyerror("duplicate memory option");
+                               YYERROR;
+                       }
                        domain->memory = $2;
                }
                | VDISK STRING vdisk_opts {
@@ -192,10 +200,19 @@ domainopts        : VCPU vcpu {
                        SIMPLEQ_INSERT_TAIL(&domain->var_list, var, entry);
                }
                | IODEVICE STRING {
-                       struct iodev *iodev = xmalloc(sizeof(struct iodev));
+                       struct domain *odomain;
+                       struct iodev *iodev;
+                       SIMPLEQ_FOREACH(odomain, &conf->domain_list, entry)
+                               SIMPLEQ_FOREACH(iodev, &odomain->iodev_list, 
entry)
+                                       if (strcmp(iodev->path, $2) == 0) {
+                                               yyerror("iodevice assigned"
+                                                   " twice: %s", $2);
+                                               YYERROR;
+                                       }
+                       iodev = xmalloc(sizeof(struct iodev));
                        iodev->path = $2;
                        SIMPLEQ_INSERT_TAIL(&domain->iodev_list, iodev, entry);
-                   }
+               }
                ;
 
 vdisk_opts     :       { vdisk_opts_default(); }

Reply via email to