Straight forward diff to allow calling disks names:

        $ cat ldom.conf
        domain guest {
                vcpu 4
                memory 8G
                vnet
                vdisk "/var/ldom/guest.img"
                vdisk "/var/ldom/miniroot.fs" devalias=miniroot
        }
        $ doas ldomctl start -c guest
        {ok} devalias
        ...
        miniroot                 /virtual-devices@100/channel-devices@200/disk@1
        disk1                    /virtual-devices@100/channel-devices@200/disk@1
        disk0                    /virtual-devices@100/channel-devices@200/disk@0
        disk                     /virtual-devices@100/channel-devices@200/disk@0
        ...
        {ok} boot miniroot
        Boot device: /virtual-devices@100/channel-devices@200/disk@1  File and 
args:
        OpenBSD IEEE 1275 Bootblock 1.4
        ...

This helps me to navigate inside guests as I no longer have to remember
in which order I specified the `vdisk' lines in ldom.conf(5).


parse.y code is simply copied from existing vnet code and adapted with
s/vnet/vdisk/.

It would need the previously sent ldom.conf.5 vnet, although for
correctness and consistency only.

Feedback? OK?


Index: config.c
===================================================================
RCS file: /cvs/src/usr.sbin/ldomctl/config.c,v
retrieving revision 1.32
diff -u -p -r1.32 config.c
--- config.c    22 Jan 2020 07:52:38 -0000      1.32
+++ config.c    5 Feb 2020 20:24:12 -0000
@@ -2557,7 +2557,8 @@ guest_add_memory(struct guest *guest, ui
 }
 
 void
-guest_add_vdisk(struct guest *guest, uint64_t id, const char *path)
+guest_add_vdisk(struct guest *guest, uint64_t id, const char *path,
+    const char *user_devalias)
 {
        struct guest *primary;
        struct ldc_channel *lc;
@@ -2577,6 +2578,8 @@ guest_add_vdisk(struct guest *guest, uin
        if (id == 0)
                guest_add_devalias(guest, "disk", devpath);
        guest_add_devalias(guest, devalias, devpath);
+       if (user_devalias != NULL)
+               guest_add_devalias(guest, user_devalias, devpath);
        free(devalias);
        free(devpath);
 }
@@ -2849,7 +2852,8 @@ build_config(const char *filename, int n
                guest_add_memory(guest, -1, domain->memory);
                i = 0;
                SIMPLEQ_FOREACH(vdisk, &domain->vdisk_list, entry)
-                       guest_add_vdisk(guest, i++, vdisk->path);
+                       guest_add_vdisk(guest, i++, vdisk->path,
+                           vdisk->devalias);
                i = 0;
                SIMPLEQ_FOREACH(vnet, &domain->vnet_list, entry)
                        guest_add_vnetwork(guest, i++, vnet->mac_addr,
Index: ldom.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/ldomctl/ldom.conf.5,v
retrieving revision 1.10
diff -u -p -r1.10 ldom.conf.5
--- ldom.conf.5 13 Jan 2020 09:29:41 -0000      1.10
+++ ldom.conf.5 5 Feb 2020 20:20:21 -0000
@@ -56,7 +56,7 @@ See
 .Xr eeprom 8
 for a list of OpenPROM variables.
 This keyword can be used multiple times.
-.It Ic vdisk Ar file
+.It Ic vdisk Ar file Op Ar keyword Ns = Ns Ar value ...
 The specified file is used to back a virtual disk of the guest
 domain.
 .Ar file
@@ -64,6 +64,12 @@ can be a block device node or a disk ima
 .Cm create-vdisk
 command.
 This keyword can be used multiple times.
+Valid options are:
+.Bl -tag -width Ds
+.It Ic devalias Ns = Ns Ar name
+Alias the virtual disk as
+.Ar name .
+.El
 .It Ic vnet Op Brq Ar keyword Ns = Ns Ar value ...
 Assign a
 .Xr vnet 4
Index: ldomctl.h
===================================================================
RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.h,v
retrieving revision 1.12
diff -u -p -r1.12 ldomctl.h
--- ldomctl.h   4 Jan 2020 15:45:46 -0000       1.12
+++ ldomctl.h   5 Feb 2020 20:18:43 -0000
@@ -158,6 +158,7 @@ extern uint64_t hv_memsize;
 struct vdisk {
        SIMPLEQ_ENTRY(vdisk)    entry;
        const char              *path;
+       const char              *devalias;
 };
 
 struct vnet {
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ldomctl/parse.y,v
retrieving revision 1.15
diff -u -p -r1.15 parse.y
--- parse.y     9 Jan 2020 22:06:23 -0000       1.15
+++ parse.y     5 Feb 2020 20:18:48 -0000
@@ -70,12 +70,17 @@ struct vcpu_opts {
        uint64_t        stride;
 } vcpu_opts;
 
+struct vdisk_opts {
+       const char      *devalias;
+} vdisk_opts;
+
 struct vnet_opts {
        uint64_t        mac_addr;
        uint64_t        mtu;
 } vnet_opts;
 
 void           vcput_opts_default(void);
+void           vdisk_opts_default(void);
 void           vnet_opts_default(void);
 
 typedef struct {
@@ -83,6 +88,7 @@ typedef struct {
                int64_t                  number;
                char                    *string;
                struct vcpu_opts         vcpu_opts;
+               struct vdisk_opts        vdisk_opts;
                struct vnet_opts         vnet_opts;
        } v;
        int lineno;
@@ -91,13 +97,15 @@ typedef struct {
 %}
 
 %token DOMAIN
-%token VCPU MEMORY VDISK VNET VARIABLE IODEVICE
+%token VCPU MEMORY VDISK DEVALIAS VNET VARIABLE IODEVICE
 %token MAC_ADDR MTU
 %token ERROR
 %token <v.string>              STRING
 %token <v.number>              NUMBER
 %type  <v.number>              memory
 %type  <v.vcpu_opts>           vcpu
+%type  <v.vdisk_opts>          vdisk_opts vdisk_opts_l vdisk_opt
+%type  <v.vdisk_opts>          devalias
 %type  <v.vnet_opts>           vnet_opts vnet_opts_l vnet_opt
 %type  <v.vnet_opts>           mac_addr
 %type  <v.vnet_opts>           mtu
@@ -162,7 +170,7 @@ domainopts  : VCPU vcpu {
                | MEMORY memory {
                        domain->memory = $2;
                }
-               | VDISK STRING {
+               | VDISK STRING vdisk_opts {
                        struct vdisk *vdisk = xmalloc(sizeof(struct vdisk));
                        vdisk->path = $2;
                        SIMPLEQ_INSERT_TAIL(&domain->vdisk_list, vdisk, entry);
@@ -186,6 +194,22 @@ domainopts : VCPU vcpu {
                    }
                ;
 
+vdisk_opts     :       { vdisk_opts_default(); }
+                 vdisk_opts_l
+                       { $$ = vdisk_opts; }
+               |       { vdisk_opts_default(); $$ = vdisk_opts; }
+               ;
+vdisk_opts_l   : vdisk_opts_l vdisk_opt
+               | vdisk_opt
+               ;
+vdisk_opt      : devalias
+               ;
+
+devalias       : DEVALIAS '=' STRING {
+                       vdisk_opts.devalias = $3;
+               }
+               ;
+
 vnet_opts      :       { vnet_opts_default(); }
                  vnet_opts_l
                        { $$ = vnet_opts; }
@@ -279,6 +303,12 @@ vcpu_opts_default(void)
 }
 
 void
+vdisk_opts_default(void)
+{
+       vdisk_opts.devalias = NULL;
+}
+
+void
 vnet_opts_default(void)
 {
        vnet_opts.mac_addr = -1;
@@ -315,6 +345,7 @@ lookup(char *s)
 {
        /* this has to be sorted always */
        static const struct keywords keywords[] = {
+               { "devalias",           DEVALIAS},
                { "domain",             DOMAIN},
                { "iodevice",           IODEVICE},
                { "mac-addr",           MAC_ADDR},

Reply via email to