diff options
author | kn <kn@cvs.openbsd.org> | 2020-02-20 20:38:45 +0000 |
---|---|---|
committer | kn <kn@cvs.openbsd.org> | 2020-02-20 20:38:45 +0000 |
commit | bdaa62ec963226ed1d9d98833a2a8fe50b4bc79d (patch) | |
tree | e636ea2b7ba4cf6fb4dc1f1562426e8ce465e6d9 | |
parent | 51577d51b4bd96f25484cd1b00273d5b798ef021 (diff) |
Support devaliases for vdisk
vdisk "/var/ldom/miniroot.fs" devalias=miniroot
Creates a device alias to be used in OBP:
{ok} devlias
miniroot /virutal-devices@100/...
This helps navigating inside guests without remembering
device paths or rather their order as specified in the config.
OK kettenis
-rw-r--r-- | usr.sbin/ldomctl/config.c | 10 | ||||
-rw-r--r-- | usr.sbin/ldomctl/ldom.conf.5 | 10 | ||||
-rw-r--r-- | usr.sbin/ldomctl/ldomctl.h | 3 | ||||
-rw-r--r-- | usr.sbin/ldomctl/parse.y | 37 |
4 files changed, 51 insertions, 9 deletions
diff --git a/usr.sbin/ldomctl/config.c b/usr.sbin/ldomctl/config.c index 05af736e9b6..7f6104ce3ab 100644 --- a/usr.sbin/ldomctl/config.c +++ b/usr.sbin/ldomctl/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.32 2020/01/22 07:52:38 deraadt Exp $ */ +/* $OpenBSD: config.c,v 1.33 2020/02/20 20:38:44 kn Exp $ */ /* * Copyright (c) 2012, 2018 Mark Kettenis @@ -2557,7 +2557,8 @@ guest_add_memory(struct guest *guest, uint64_t base, uint64_t size) } 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, uint64_t id, const char *path) 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 noaction) 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, diff --git a/usr.sbin/ldomctl/ldom.conf.5 b/usr.sbin/ldomctl/ldom.conf.5 index b4a1686edd9..75bf38f5de1 100644 --- a/usr.sbin/ldomctl/ldom.conf.5 +++ b/usr.sbin/ldomctl/ldom.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ldom.conf.5,v 1.11 2020/02/20 20:18:00 kn Exp $ +.\" $OpenBSD: ldom.conf.5,v 1.12 2020/02/20 20:38:44 kn Exp $ .\" .\" Copyright (c) 2012 Mark Kettenis <kettenis@openbsd.org> .\" @@ -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 image file created with the .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 Ar keyword Ns = Ns Ar value ... Assign a .Xr vnet 4 diff --git a/usr.sbin/ldomctl/ldomctl.h b/usr.sbin/ldomctl/ldomctl.h index c5e8be6721f..47545fd9786 100644 --- a/usr.sbin/ldomctl/ldomctl.h +++ b/usr.sbin/ldomctl/ldomctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldomctl.h,v 1.12 2020/01/04 15:45:46 kn Exp $ */ +/* $OpenBSD: ldomctl.h,v 1.13 2020/02/20 20:38:44 kn Exp $ */ /* * Copyright (c) 2012 Mark Kettenis @@ -158,6 +158,7 @@ extern uint64_t hv_memsize; struct vdisk { SIMPLEQ_ENTRY(vdisk) entry; const char *path; + const char *devalias; }; struct vnet { diff --git a/usr.sbin/ldomctl/parse.y b/usr.sbin/ldomctl/parse.y index 5d6ffb8c785..9fd85e995b1 100644 --- a/usr.sbin/ldomctl/parse.y +++ b/usr.sbin/ldomctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.15 2020/01/09 22:06:23 kn Exp $ */ +/* $OpenBSD: parse.y,v 1.16 2020/02/20 20:38:44 kn Exp $ */ /* * Copyright (c) 2012 Mark Kettenis <kettenis@openbsd.org> @@ -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}, |