From 8e765095ac7ca8bea263677cfbfe4d06296db21b Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 16 Sep 2018 14:27:32 +0000 Subject: [PATCH] Add support for setting NVRAM variables. --- usr.sbin/ldomctl/config.c | 33 +++++++++++++++++++++++++++++++-- usr.sbin/ldomctl/ldomctl.8 | 8 +++++--- usr.sbin/ldomctl/ldomctl.h | 9 ++++++++- usr.sbin/ldomctl/parse.y | 12 ++++++++++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/usr.sbin/ldomctl/config.c b/usr.sbin/ldomctl/config.c index 3aad5e0f73a..b6cb9af38a3 100644 --- a/usr.sbin/ldomctl/config.c +++ b/usr.sbin/ldomctl/config.c @@ -1,7 +1,7 @@ -/* $OpenBSD: config.c,v 1.23 2018/09/16 12:17:05 kettenis Exp $ */ +/* $OpenBSD: config.c,v 1.24 2018/09/16 14:27:32 kettenis Exp $ */ /* - * Copyright (c) 2012 Mark Kettenis + * Copyright (c) 2012, 2018 Mark Kettenis * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -2206,6 +2206,25 @@ guest_add_vnetwork(struct guest *guest, uint64_t id, uint64_t mac_addr, free(devpath); } +void +guest_add_variable(struct guest *guest, const char *name, const char *str) +{ + struct md *md = guest->md; + struct md_node *parent; + struct md_node *node; + + node = md_find_node(md, "variables"); + if (node == NULL) { + parent = md_find_node(md, "root"); + assert(parent); + + node = md_add_node(md, "variables"); + md_link_node(md, parent, node); + } + + md_add_prop_str(md, node, name, str); +} + struct cpu * guest_find_cpu(struct guest *guest, uint64_t pid) { @@ -2318,6 +2337,7 @@ build_config(const char *filename) struct domain *domain; struct vdisk *vdisk; struct vnet *vnet; + struct var *var; uint64_t num_cpus, primary_num_cpus; uint64_t memory, primary_memory; @@ -2373,6 +2393,13 @@ build_config(const char *filename) guest_delete_memory(primary); guest_add_memory(primary, -1, primary_memory); + SIMPLEQ_FOREACH(domain, &conf.domain_list, entry) { + if (strcmp(domain->name, "primary") != 0) + continue; + SIMPLEQ_FOREACH(var, &domain->var_list, entry) + guest_add_variable(primary, var->name, var->str); + } + SIMPLEQ_FOREACH(domain, &conf.domain_list, entry) { if (strcmp(domain->name, "primary") == 0) continue; @@ -2387,6 +2414,8 @@ build_config(const char *filename) SIMPLEQ_FOREACH(vnet, &domain->vnet_list, entry) guest_add_vnetwork(guest, i++, vnet->mac_addr, vnet->mtu); + SIMPLEQ_FOREACH(var, &domain->var_list, entry) + guest_add_variable(guest, var->name, var->str); guest_finalize(guest); } diff --git a/usr.sbin/ldomctl/ldomctl.8 b/usr.sbin/ldomctl/ldomctl.8 index 9ad159609c7..2ed0e4a327c 100644 --- a/usr.sbin/ldomctl/ldomctl.8 +++ b/usr.sbin/ldomctl/ldomctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ldomctl.8,v 1.10 2018/04/09 10:15:15 kn Exp $ +.\" $OpenBSD: ldomctl.8,v 1.11 2018/09/16 14:27:32 kettenis Exp $ .\" .\" Copyright (c) 2012 Mark Kettenis .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 9 2018 $ +.Dd $Mdocdate: September 16 2018 $ .Dt LDOMCTL 8 sparc64 .Os .Sh NAME @@ -72,6 +72,8 @@ Declares the number of virtual CPUs assigned to a domain. Declares the amount of memory assigned to a domain, in bytes. Optionally, the units 'K', 'M', or 'G', for kilo-, mega-, and gigabytes can be used. +.It Ic variable Ar name Ic = Ar value +Sets the specified NVRAM variable for the domain. .It Ic vdisk Ar file The specified file is used to back a virtual disk of the guest domain. @@ -79,7 +81,7 @@ domain. can be a block device node or a disk image file created with .Xr dd 1 . This keyword can be used multiple times. -.It Ic vnet Op Ic \&{ Ar keyword value ... Ic \&} +.It Ic vnet Op Ic \&{ Ar keyword Ic = Ar value ... Ic \&} Assign a .Xr vnet 4 network interface to the guest domain. diff --git a/usr.sbin/ldomctl/ldomctl.h b/usr.sbin/ldomctl/ldomctl.h index ce917a69a1c..86dd62e678a 100644 --- a/usr.sbin/ldomctl/ldomctl.h +++ b/usr.sbin/ldomctl/ldomctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldomctl.h,v 1.6 2018/09/16 12:17:05 kettenis Exp $ */ +/* $OpenBSD: ldomctl.h,v 1.7 2018/09/16 14:27:32 kettenis Exp $ */ /* * Copyright (c) 2012 Mark Kettenis @@ -135,6 +135,12 @@ struct vnet { uint64_t mtu; }; +struct var { + SIMPLEQ_ENTRY(var) entry; + const char *name; + const char *str; +}; + struct domain { SIMPLEQ_ENTRY(domain) entry; const char *name; @@ -142,6 +148,7 @@ struct domain { uint64_t memory; SIMPLEQ_HEAD(, vdisk) vdisk_list; SIMPLEQ_HEAD(, vnet) vnet_list; + SIMPLEQ_HEAD(, var) var_list; } *domain; struct ldom_config { diff --git a/usr.sbin/ldomctl/parse.y b/usr.sbin/ldomctl/parse.y index edcb0869e55..359ff9a9e81 100644 --- a/usr.sbin/ldomctl/parse.y +++ b/usr.sbin/ldomctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.7 2018/07/09 12:05:11 krw Exp $ */ +/* $OpenBSD: parse.y,v 1.8 2018/09/16 14:27:32 kettenis Exp $ */ /* * Copyright (c) 2012 Mark Kettenis @@ -82,7 +82,7 @@ typedef struct { %} %token DOMAIN -%token VCPU MEMORY VDISK VNET +%token VCPU MEMORY VDISK VNET VARIABLE %token MAC_ADDR MTU %token ERROR %token STRING @@ -104,6 +104,7 @@ domain : DOMAIN STRING optnl '{' optnl { domain->name = $2; SIMPLEQ_INIT(&domain->vdisk_list); SIMPLEQ_INIT(&domain->vnet_list); + SIMPLEQ_INIT(&domain->var_list); } domainopts_l '}' { /* domain names need to be unique. */ @@ -142,6 +143,12 @@ domainopts : VCPU NUMBER { vnet->mtu = $2.mtu; SIMPLEQ_INSERT_TAIL(&domain->vnet_list, vnet, entry); } + | VARIABLE STRING '=' STRING { + struct var *var = xmalloc(sizeof(struct var)); + var->name = $2; + var->str = $4; + SIMPLEQ_INSERT_TAIL(&domain->var_list, var, entry); + } ; vnet_opts : { opts_default(); } @@ -253,6 +260,7 @@ lookup(char *s) { "mac-addr", MAC_ADDR}, { "memory", MEMORY}, { "mtu", MTU}, + { "variable", VARIABLE}, { "vcpu", VCPU}, { "vdisk", VDISK}, { "vnet", VNET} -- 2.20.1