summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu-src/data
diff options
context:
space:
mode:
authorManuel Bentele2021-09-30 14:01:50 +0200
committerManuel Bentele2021-10-12 13:12:55 +0200
commit89fa7e5a9c9b24dcaafa2a3affde56f26945030e (patch)
tree404d9b5ead2145fb3d1986ce43588d8bd8a47a65 /core/modules/qemu-src/data
parent[libvirt-src] Add module for libvirt source build (diff)
downloadmltk-89fa7e5a9c9b24dcaafa2a3affde56f26945030e.tar.gz
mltk-89fa7e5a9c9b24dcaafa2a3affde56f26945030e.tar.xz
mltk-89fa7e5a9c9b24dcaafa2a3affde56f26945030e.zip
[qemu-src] Add module for QEMU source build
Diffstat (limited to 'core/modules/qemu-src/data')
l---------core/modules/qemu-src/data/lib/systemd/system/multi-user.target.wants/qemu-kvm.service1
-rw-r--r--core/modules/qemu-src/data/lib/systemd/system/qemu-kvm.service16
-rw-r--r--core/modules/qemu-src/data/usr/share/qemu/init/qemu-kvm-init89
3 files changed, 106 insertions, 0 deletions
diff --git a/core/modules/qemu-src/data/lib/systemd/system/multi-user.target.wants/qemu-kvm.service b/core/modules/qemu-src/data/lib/systemd/system/multi-user.target.wants/qemu-kvm.service
new file mode 120000
index 00000000..cd3c10f2
--- /dev/null
+++ b/core/modules/qemu-src/data/lib/systemd/system/multi-user.target.wants/qemu-kvm.service
@@ -0,0 +1 @@
+../qemu-kvm.service \ No newline at end of file
diff --git a/core/modules/qemu-src/data/lib/systemd/system/qemu-kvm.service b/core/modules/qemu-src/data/lib/systemd/system/qemu-kvm.service
new file mode 100644
index 00000000..f35e3e98
--- /dev/null
+++ b/core/modules/qemu-src/data/lib/systemd/system/qemu-kvm.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=QEMU KVM preparation - module, ksm, hugepages
+DefaultDependencies=no
+After=local-fs.target
+Before=shutdown.target
+Conflicts=shutdown.target
+RequiresMountsFor=/usr
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/share/qemu/init/qemu-kvm-init start
+ExecReload=/usr/share/qemu/init/qemu-kvm-init start
+
+[Install]
+WantedBy=multi-user.target
diff --git a/core/modules/qemu-src/data/usr/share/qemu/init/qemu-kvm-init b/core/modules/qemu-src/data/usr/share/qemu/init/qemu-kvm-init
new file mode 100644
index 00000000..af00b718
--- /dev/null
+++ b/core/modules/qemu-src/data/usr/share/qemu/init/qemu-kvm-init
@@ -0,0 +1,89 @@
+#!/bin/sh
+
+# Detect our host arch
+arch=$(arch)
+test -z "$arch" && exit 0
+
+modlist=""
+case "$arch" in
+ x86_64 | i686)
+ kvm=/usr/bin/qemu-system-x86_64
+ if grep -qs "^flags.* vmx" /proc/cpuinfo; then
+ modlist="kvm_intel $KVM_NESTED"
+ elif grep -qs "^flags.* svm" /proc/cpuinfo; then
+ modlist="kvm_amd"
+ fi
+ ;;
+ ppc*)
+ SMT=$(/usr/sbin/ppc64_cpu --smt 2>&1 | grep "SMT=[248]")
+ if [ -n "$SMT" ]
+ then
+ if grep -q -e '^cpu\s*:\s*POWER8' /proc/cpuinfo; then
+ echo "Error: You must disable SMT if you want to run QEMU/KVM on Power8 based ppc64le architecture"
+ echo "In order to disable SMT, run: # ppc64_cpu --smt=off"
+ fi
+ fi
+ kvm=/usr/bin/qemu-system-ppc64
+ if [ "$(uname -m)" != "ppc64le" ]; then
+ exit 0
+ fi
+ if systemd-detect-virt --quiet --vm; then
+ echo "Info: second level virtualization not supported, kvm-hv load might fail"
+ fi
+ modlist="kvm-hv"
+ ;;
+esac
+
+# Silently exit if the package isn't installed anymore
+if [ -z "$kvm" -o ! -e "$kvm" ]; then
+ exit 0
+fi
+
+# shellcheck disable=SC1091
+[ -r /etc/default/qemu-kvm ] && . /etc/default/qemu-kvm
+
+start() {
+ if [ -n "$modlist" ]; then
+ modprobe -b $modlist || true
+ fi
+
+ if systemd-detect-virt --quiet --container; then
+ mknod /dev/kvm c 10 232 || true
+ chown root:kvm /dev/kvm || true
+ chmod g+rw /dev/kvm || true
+ fi
+
+ # Determine if we are running inside a VM
+ IS_VM=0
+ if command -v systemd-detect-virt >/dev/null 2>&1; then
+ systemd-detect-virt -vq && IS_VM=1
+ fi
+
+ # Enable KSM, respecting the default configuration file. If 'AUTO' is
+ # set, enable only if we aren't running inside a VM.
+ if [ "$KSM_ENABLED" = "1" ] || [ "$KSM_ENABLED" = "AUTO" ] && [ "$IS_VM" = "0" ]; then
+ # shellcheck disable=SC2015
+ [ -w /sys/kernel/mm/ksm/run ] && echo 1 > /sys/kernel/mm/ksm/run || true
+ if [ -w /sys/kernel/mm/ksm/sleep_millisecs ]; then
+ if [ -n "$SLEEP_MILLISECS" ]; then
+ echo "$SLEEP_MILLISECS" > /sys/kernel/mm/ksm/sleep_millisecs || true
+ fi
+ fi
+ else
+ # shellcheck disable=SC2015
+ [ -w /sys/kernel/mm/ksm/run ] && echo 0 > /sys/kernel/mm/ksm/run || true
+ fi
+}
+
+# See how we were called.
+case "$1" in
+ start)
+ start
+ ;;
+
+ *)
+ exit 0
+ ;;
+esac
+
+exit $?