Skip to content

Commit

Permalink
Revamp bhyve configuration.
Browse files Browse the repository at this point in the history
- Embed default values so bhyve.conf does not have to set them
- The guest might be launched without PCI pass-through configured
  • Loading branch information
pgj committed Aug 6, 2021
1 parent b966c82 commit 75ad051
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
16 changes: 8 additions & 8 deletions etc/bhyve.conf.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# These are the default values for launching the bhyve(8) guest. Please
# modify the `passthru` value to match with the slot/bus/function of the
# wireless PCI device, which can be obtained from the output of the
# pciconf(8) tool.
# These are the default values for launching the bhyve(8) guest.
# Please, at least set the `passthru` value to match with the
# slot/bus/function of the wireless PCI device, which can be obtained
# from the output of the pciconf(8) tool.

cpus=1
memory=128M
passthru=3/0/0
console=no
#cpus=1 # number of CPUs allocated for the guest
#memory=128M # amount of memory allocated for the guest
#passthru= # expected format: "s/b/f", e.g. "3/0/0"
#console=no # "yes" actives the nmdm(4) console
34 changes: 30 additions & 4 deletions sbin/wifibox
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ destroy_nmdm() {

get_ppt_device() {
check_configuration "${CONFDIR}/bhyve.conf"
passthru=

# shellcheck source=./etc/bhyve.conf.sample
. "${CONFDIR}/bhyve.conf"

${ECHO} "pci${passthru}" | ${SED} 's!/!:!g'
if [ -z "${passthru}" ]; then
${ECHO} ""
else
${ECHO} "pci${passthru}" | ${SED} 's!/!:!g'
fi
}

get_vm_pid() {
Expand All @@ -137,12 +142,19 @@ get_vm_pid() {
vm_start() {
local _nmdm_grub_bhyve
local _nmdm_bhyve
local _passthru_bhyve
local _ppt

check_configuration "${CONFDIR}/bhyve.conf"
check_configuration "${CONFDIR}/interfaces.conf"
check_configuration "${CONFDIR}/udhcpd.conf"
check_configuration "${CONFDIR}/wpa_supplicant.conf"

cpus=1
memory=128M
passthru=
console=no

# shellcheck source=./etc/bhyve.conf.sample
. "${CONFDIR}/bhyve.conf"

Expand All @@ -151,7 +163,15 @@ vm_start() {
_nmdm_bhyve="-l com1,${NMDM_A}"
fi

${DEVCTL} set driver -f "$(get_ppt_device)" ppt > /dev/null
if [ -n "${passthru}" ]; then
_passthru_bhyve="-s 6:0,passthru,${passthru}"
fi

_ppt="$(get_ppt_device)"
if [ -n "${_ppt}" ]; then
${DEVCTL} set driver -f "${_ppt}" ppt > /dev/null
fi

${GRUB_BHYVE} -S -M "${memory}" -r host \
${_nmdm_grub_bhyve} \
-m ${PREFIX}/share/wifibox/device.map \
Expand All @@ -165,7 +185,7 @@ vm_start() {
-s 4:1,virtio-9p,config=${CONFDIR},ro \
-s 4:2,virtio-9p,var=${RUNDIR}/appliance \
-s 5:0,e1000,tap-wifibox \
-s 6:0,passthru,"${passthru}" \
${_passthru_bhyve} \
wifibox > ${BHYVE_LOG} 2>&1 &
# Give some time for bhyve to launch.
${SLEEP} 1 > /dev/null
Expand All @@ -179,12 +199,18 @@ vm_start() {
}

vm_stop() {
local _ppt

${KILL} -SIGTERM "$(get_vm_pid)" > /dev/null
${SLEEP} 3 > /dev/null
${BHYVECTL} --force-poweroff --vm=wifibox >> ${BHYVE_LOG} 2>&1
${BHYVECTL} --destroy --vm=wifibox >> ${BHYVE_LOG} 2>&1
${SLEEP} 1 > /dev/null
${DEVCTL} clear driver -f "$(get_ppt_device)" > /dev/null

_ppt="$(get_ppt_device)"
if [ -n "${_ppt}" ]; then
${DEVCTL} clear driver -f "${_ppt}" > /dev/null
fi
}

assert_vm_runs() {
Expand Down

0 comments on commit 75ad051

Please sign in to comment.