mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2026-08-28 20:06:05 +00:00
feat: Refactor config code (#1292)
This commit is contained in:
+56
-9
@@ -2,15 +2,62 @@
|
||||
set -Eeuo pipefail
|
||||
|
||||
DEF_OPTS="-nodefaults -boot strict=on"
|
||||
RAM_OPTS=$(echo "-m ${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
MON_OPTS="-name $PROCESS,process=$PROCESS,debug-threads=on -pidfile $QEMU_PID"
|
||||
CPU_OPTS="-cpu $CPU_FLAGS -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1"
|
||||
MAC_OPTS="-machine type=$MACHINE,smm=off,usb=off,vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
|
||||
DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
|
||||
DEV_OPTS+=" -object rng-random,id=objrng0,filename=/dev/urandom"
|
||||
DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
|
||||
DEV_OPTS=""
|
||||
|
||||
ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS"
|
||||
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
||||
configureProcessor() {
|
||||
|
||||
CPU_OPTS="-cpu $CPU_FLAGS"
|
||||
CPU_OPTS+=" -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMemory() {
|
||||
|
||||
RAM_OPTS=$(echo "-m ${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMonitor() {
|
||||
|
||||
MON_OPTS="-name $PROCESS,process=$PROCESS,debug-threads=on"
|
||||
MON_OPTS+=" -pidfile $QEMU_PID"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMachine() {
|
||||
|
||||
MAC_OPTS="-machine type=$MACHINE,smm=off,usb=off"
|
||||
MAC_OPTS+=",vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureVirtioDevices() {
|
||||
|
||||
DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
|
||||
DEV_OPTS+=" -object rng-random,id=objrng0,filename=/dev/urandom"
|
||||
DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
buildArguments() {
|
||||
|
||||
ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS"
|
||||
ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ')
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
configureMemory
|
||||
configureMonitor
|
||||
configureMachine
|
||||
configureProcessor
|
||||
configureVirtioDevices
|
||||
|
||||
buildArguments
|
||||
|
||||
return 0
|
||||
|
||||
+3
-5
@@ -45,7 +45,7 @@ checkClocksource() {
|
||||
|
||||
checkSse42() {
|
||||
|
||||
if ! grep -qw "sse4_2" <<< "$flags"; then
|
||||
if ! hasFlag "sse4_2"; then
|
||||
error "Your CPU does not have the SSE4 instruction set that Virtual DSM requires!"
|
||||
! enabled "$DEBUG" && exit 88
|
||||
fi
|
||||
@@ -94,10 +94,10 @@ configureKvmCpuModel() {
|
||||
|
||||
appendKvmInvtscFeature() {
|
||||
|
||||
if grep -qw "svm" <<< "$flags"; then
|
||||
if hasFlag "svm"; then
|
||||
|
||||
# AMD processor
|
||||
if grep -qw "tsc_scale" <<< "$flags"; then
|
||||
if hasFlag "tsc_scale"; then
|
||||
CPU_FEATURES+=",+invtsc"
|
||||
fi
|
||||
|
||||
@@ -186,8 +186,6 @@ configureHostCpuName() {
|
||||
selectClocksource
|
||||
checkClocksource
|
||||
|
||||
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)
|
||||
|
||||
if ! disabled "$KVM"; then
|
||||
configureKvm
|
||||
else
|
||||
|
||||
@@ -7,6 +7,29 @@ info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "${1:-}" "\E[0m\n"; }
|
||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: ${1:-}" "\E[0m\n" >&2; }
|
||||
warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: ${1:-}" "\E[0m\n" >&2; }
|
||||
|
||||
hasFlag() {
|
||||
|
||||
# Match a whitespace-delimited token in /proc/cpuinfo
|
||||
grep -m1 '^flags[[:space:]]*:' /proc/cpuinfo | grep -Fqw -- "$1"
|
||||
|
||||
}
|
||||
|
||||
hasFeature() {
|
||||
|
||||
# Match a whitespace-delimited token in /proc/cpuinfo
|
||||
grep -m1 '^Features[[:space:]]*:' /proc/cpuinfo | grep -Fqw -- "$1"
|
||||
|
||||
}
|
||||
|
||||
isAmdCpu() {
|
||||
|
||||
local vendor
|
||||
vendor=$(lscpu | awk '/Vendor ID/{print $3}')
|
||||
|
||||
[[ "$vendor" == "AuthenticAMD" ]]
|
||||
|
||||
}
|
||||
|
||||
interactive() {
|
||||
|
||||
[ -t 1 ] &&
|
||||
|
||||
Reference in New Issue
Block a user