summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/data/opt
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/qemu/data/opt')
-rwxr-xr-xcore/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env28
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README1
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc89
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc49
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc54
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc35
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc56
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc25
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include44
9 files changed, 381 insertions, 0 deletions
diff --git a/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env
new file mode 100755
index 00000000..631c159f
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/scripts/systemd-qemukvm_env
@@ -0,0 +1,28 @@
+#!/bin/ash
+# -----------------------------------------------------------------------------
+#
+# Copyright (c) 2017..2018 bwLehrpool-Projektteam
+#
+# This program/file is free software distributed under the GPL version 2.
+# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
+#
+# If you have any feedback please consult https://bwlehrpool.de and
+# send your feedback to bwlehrpool@hs-offenburg.de.
+#
+# General information about bwLehrpool can be found at https://bwlehrpool.de
+#
+# -----------------------------------------------------------------------------
+# systemd-qemukvm_env
+# - This is the preparation script for the configuration of Linux Qemu/KVM.
+################################################################################
+
+# lazy load all kvm related modules
+modprobe kvm
+modprobe kvm_amd
+modprobe kvm_intel
+
+if [ ! -e /dev/kvm ]; then
+ slxlog "qemukvm-modules" "/dev/kvm not found! Missing kvm kernel module(s)?"
+ exit 1
+fi
+
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README
new file mode 100644
index 00000000..549d0037
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/README
@@ -0,0 +1 @@
+Not tested since refactoring! (January 2017)
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc
new file mode 100644
index 00000000..dd83b587
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/determine_hardware_limitations.inc
@@ -0,0 +1,89 @@
+##################################################################
+# qemu/kvm include: determine virtual hardware based on guest OS #
+##################################################################
+
+set_vm_hw_limits() {
+ # FIXME when we have better metadata for qemu
+ if isempty VM_OS_TYPE; then
+ writelog "VM_OS_TYPE is empty! This should have been parsed from the XML file"
+ EXIT_TYPE="user" EXIT_REASON="Konnte Gastbetriebsystems der virtuellen Maschine nicht ermitteln!" cleanexit 1
+ fi
+
+ # define global hardware-related variables
+ declare -g MAXMEM="9999999"
+ declare -g MAXCORES="4"
+ declare -g SOUND_DEV="es1370"
+
+ # determine if we need a 32bit or 64bit machine
+ # FIXME depending on the guest OS for now
+ # (sadly does not support all the exotic OSs the
+ # the world has even seen like vmware plugin :<)
+ local bits=64
+ case "${VM_OS_TYPE}" in
+ beos*)
+ bits=32
+ SOUND_DEV="sb16"
+ ;;
+ win3*|win*3*|Win*3*)
+ bits=32
+ SOUND_DEV="sb16"
+ MAXMEM=32
+ ;;
+ win95*|Win*95)
+ bits=32
+ MAXMEM=96
+ ;;
+ win98)
+ bits=32
+ MAXMEM=256
+ ;;
+ winme*|windowsme*)
+ bits=32
+ SOUND_DEV="ac97"
+ MAXMEM=384
+ ;;
+ winxp*64|windowsxp*64)
+ SOUND_DEV="ac97"
+ ;;
+ windows7|windows8|windows9)
+ SOUND_DEV="ac97"
+ MAXMEM="8000"
+ MAXCORES="4"
+ ;;
+ windows7-64|windows8-64|windows9-64)
+ SOUND_DEV="ac97"
+ MAXMEM="32000"
+ MAXCORES="8"
+ ;;
+ *64)
+ MAXMEM="16000"
+ MAXCORES="4"
+ ;;
+ *)
+ bits=32
+ MAXMEM="8000"
+ MAXCORES="1"
+ ;;
+ esac
+ declare -g VIRTCMD
+ if [ "$bits" = 32 ]; then
+ declare -rg VIRTCMD="qemu-system-i386"
+ VIRTCMDOPTS+=( "-machine" "accel=tcg" ) # TODO: 32bit VMs can't use kvm!?
+ else # 64 bit
+ declare -rg VIRTCMD="qemu-system-x86_64"
+ VIRTCMDOPTS+=( "-machine" "accel=kvm" )
+ fi
+
+
+ # check for allocated cores
+ declare -g CPU_CORES="${HW_THREADS:-1}"
+ declare -rg HOST_CORE_COUNT="${CPU_CORES}"
+ [ "${CPU_CORES}" -gt "${MAXCORES}" ] && CPU_CORES="${MAXCORES}"
+
+ # check if memory set by the generic run-virt is above the threshold
+ [ "${VM_MEM}" -gt "${MAXMEM}" ] && VM_MEM="${MAXMEM}"
+ return 0
+}
+
+## MAIN ##
+call_post_source set_vm_hw_limits
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc
new file mode 100644
index 00000000..6d9df363
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/finalize_start_command.inc
@@ -0,0 +1,49 @@
+# -----------------------------------------------------------------------------
+#
+# Copyright (c) 2009..2018 bwLehrpool-Projektteam
+#
+# This program/file is free software distributed under the GPL version 2.
+# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
+#
+# If you have any feedback please consult https://bwlehrpool.de and
+# send your feedback to bwlehrpool@hs-offenburg.de.
+#
+# General information about bwLehrpool can be found at https://bwlehrpool.de
+#
+# -----------------------------------------------------------------------------
+# run-virt.include
+# - Include script for running the QEMU/Linux KVM virtual machine on an
+# OpenSLX client via the run-virt.sh or run-vmgrid.sh
+################################################################################
+
+# set options that depend on previous includes
+# and build the final start command
+finalize_start_command() {
+
+ # set cpu type
+ VIRTCMDOPTS+=( "-cpu" "host" )
+ # set cpu cores
+ VIRTCMDOPTS+=( "-smp" "${CPU_CORES}" )
+
+ # set RAM
+ VIRTCMDOPTS+=( "-m" "${VM_MEM}" )
+
+ # special feature for real and virtual floppy disks
+ isset FLOPPY_0 && VIRTCMDOPTS+=( "-fda" "${FLOPPY_0}" )
+ isset SLX_FLOPPY_IMG && VIRTCMDOPTS+=( "-fdb" "${SLX_FLOPPY_IMG}" )
+
+ # add optical drive if available
+ isset CDROM_0 && VIRTCMDOPTS+=( "-cdrom" "${CDROM_0}" )
+
+ # audio
+ isset SOUND_DEV && VIRTCMDOPTS+=( "-soundhw" "${SOUND_DEV}" )
+
+ # serial devices TODO test
+ if isset SERIAL_PORTS; then
+ for DEV in $SERIAL_PORTS; do
+ : # buggeh: VIRTCMDOPTS+=( "-serial" "${DEV}" )
+ done
+ fi
+}
+
+call_post_source finalize_start_command
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc
new file mode 100644
index 00000000..fee2cd1c
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/init_core.inc
@@ -0,0 +1,54 @@
+# -----------------------------------------------------------------------------
+#
+# Copyright (c) 2009..2018 bwLehrpool-Projektteam
+#
+# This program/file is free software distributed under the GPL version 2.
+# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
+#
+# If you have any feedback please consult https://bwlehrpool.de and
+# send your feedback to bwlehrpool@hs-offenburg.de.
+#
+# General information about bwLehrpool can be found at https://bwlehrpool.de
+#
+# -----------------------------------------------------------------------------
+# run-virt.include
+# - Include script for running the QEMU/Linux KVM virtual machine on an
+# OpenSLX client via the run-virt.sh or run-vmgrid.sh
+################################################################################
+
+# check if kvm kernel module are available
+if [ ! -c /dev/kvm ]; then
+ writelog "KVM kernel modules not loaded!"
+ EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1
+fi
+
+# check if qemu binaries are available
+if ! check_dep qemu-system-{i386,x86_64}; then
+ writelog "QEMU binaries not available!"
+ EXIT_TYPE="internal" EXIT_REASON="QEMU/KVM Virtualisierer nicht initialisiert!" cleanexit 1
+fi
+
+# set general purpose options here, mostly evaluates information
+# contained in /opt/openslx/vmchooser/config/virtualization.conf
+
+# TODO some options should come from the server, in particular
+# - disk controller type (virtio, scsi, ide...)
+# - arch to emulate (x86_64, i386, ...)
+# - graphics mode?
+# - sound dev?
+# - tbd
+
+# display name, remove blanks because of cmdline problems
+declare -rg CMD_DISPLAYNAME=$(echo ${VM_DISPLAYNAME} | sed -e "s, ,-,g;s,(,[,g;s,),],g")
+VIRTCMDOPTS+=( "-name" "${CMD_DISPLAYNAME}" )
+
+# graphical start: vga, vmware, qxl, spice?
+VIRTCMDOPTS+=( "-vga" "std" "-full-screen" )
+
+# hot keys ALT+CTRL+SHIFT (does not work properly!?)
+VIRTCMDOPTS+=( "-alt-grab" )
+
+# TODO support other types of boot? any usecase for network boot?
+# for now just boot from disk
+VIRTCMDOPTS+=( "-boot" "c" )
+
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc
new file mode 100644
index 00000000..6b4b279f
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/log_config_summary.inc
@@ -0,0 +1,35 @@
+##################################################
+# Include: Print vm config summary into log file #
+##################################################
+
+log_config_summary() {
+ writelog "Directories:"
+ writelog "\tTMPDIR:\t\t\t$TMPDIR"
+ writelog "Disk image:"
+ writelog "\tSource disk:\t\t$VM_DISKFILE_RO"
+ if [ -e "${VM_DISKFILE_RW}" ]; then
+ writelog "\tDisk mode:\t\twritable"
+ writelog "\tRW-Layer:\t\t$VM_DISKFILE_RW"
+ else
+ writelog "\tDisk mode:\t\tread-only"
+ fi
+
+ writelog "Virtual Hardware:"
+ writelog "\tvCPU cores:\t\t${CPU_CORES}"
+ writelog "\tGuest RAM:\t\t${VM_MEM} MB"
+
+ # echo nur wenn HOST_MEM_REMAINING gesetzt
+ if isset HOST_MEM_REMAINING; then
+ writelog "\tHost RAM:\t\t${HOST_MEM_REMAINING} MB"
+ fi
+ writelog "\tMAC address:\t\t${VM_MAC_ADDR}"
+ writelog "\tNetwork card:\t\t${NIC_MODEL}"
+ writelog "\tNetwork kind:\t\t${NETWORK_MODE}"
+ writelog "\tCD-ROM1:\t${CDROM_0}"
+ writelog "\tCD-ROM2:\t${CDROM_1}"
+ writelog "\tFloppy_A:\t${FLOPPY_0}"
+ writelog "\tFloppy_B:\t${SLX_FLOPPY_IMG}"
+ #writelog "\tShared Folders 'home':\t/home/${USER}"
+}
+
+call_post_source log_config_summary
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc
new file mode 100644
index 00000000..73fb2518
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_network.inc
@@ -0,0 +1,56 @@
+###################################
+# qemu/kvm include: Network setup #
+###################################
+# This now makes use of the qemu's bridge helper
+# which creates a tap device and adds it to the
+# bridge corresponding to the network type
+# TODO configurable network type
+setup_network() {
+ # list available models with:
+ # qemu-system-x86_64 -net nic,model=?
+ # e.g. as of 2.0.0:
+ # ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio
+ declare -rg NIC_MODEL="e1000"
+
+ # add MAC address and network card model
+ VIRTCMDOPTS+=( "-device" "${NIC_MODEL},mac=${VM_MAC_ADDR},netdev=guestnet0" )
+
+ # TODO support different network kinds for lectures in bwlehrpool-suite, just NAT for now
+ declare -g NETWORK_MODE="nat"
+
+ # detect if qemu's bridge helper binary is available
+ declare -g QEMU_BRIDGE_HELPER=
+ for HELPER_PATH in /usr/lib/qemu-bridge-helper /usr/local/libexec/qemu-bridge-helper; do
+ if [ -x "${HELPER_PATH}" ] && [ -u "${HELPER_PATH}" ]; then
+ QEMU_BRIDGE_HELPER="${HELPER_PATH}"
+ readonly QEMU_BRIDGE_HELPER
+ break
+ fi
+ done
+ if isempty QEMU_BRIDGE_HELPER; then
+ writelog "Could not find qemu-bridge-helper on this machine. Setting network mode to user."
+ # Even though falling back to creating tap devices ourselves, we should instead
+ # garantee the existance of qemu's helper on minilinux build time.
+ # qemu's user network mode allows tcp/udp connections in a nat-fashion and
+ # it allows access to the web which seems suffisant for a fallback.
+ NETWORK_MODE="user"
+ fi
+
+ case "${NETWORK_MODE}" in
+ nat*)
+ VIRTCMDOPTS+=( "-netdev" "bridge,br=nat1,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" )
+ ;;
+ bridge*)
+ VIRTCMDOPTS+=( "-netdev" "bridge,br=br0,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" )
+ ;;
+ host*)
+ VIRTCMDOPTS+=( "-netdev" "bridge,br=vsw2,id=guestnet0,helper=${QEMU_BRIDGE_HELPER}" )
+ ;;
+ user*|*)
+ VIRTCMDOPTS+=( "-netdev" "user,id=guestnet0" )
+ ;;
+ esac
+}
+
+## MAIN ##
+call_post_source setup_network
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc
new file mode 100644
index 00000000..32637e5d
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/setup_rw_layer.inc
@@ -0,0 +1,25 @@
+
+setup_rw_layer() {
+ if isempty VM_DISKFILE_RO; then
+ writelog "No source diskfile found! This should be specified in the given XML file. Is it valid?"
+ EXIT_TYPE="user" EXIT_REASON="Keine virtuelle Festplatte zu dieser Veranstaltung angegeben!" cleanexit 1
+ fi
+
+ # setup qcow2 backing file for that disk file
+ writelog "Creating backing file for '${VM_DISKFILE_RO}'..."
+ # TODO: WTF? This is fucked up, VM_DISKFILE_RW is set if we want to run in persistent mode,
+ # this plugin shouldn't mess around with it....
+ declare -rg VM_DISKFILE_RW="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).qcow2"
+ if qemu-img create -f qcow2 -b "${VM_DISKFILE_RO}" "${VM_DISKFILE_RW}"; then
+ # all good, use it as main disk drive
+ # TODO: determine the proper type of controller to use, ideally virtio?
+ VIRTCMDOPTS+=("-drive" "if=virtio,format=qcow2,file=${VM_DISKFILE_RW}" )
+ else
+ writelog "Error creating backing file for '${VM_DISKFILE_RO}'"
+ # TODO use -snapshot as fallback, test it!
+ # How is this supposed to even work without a disk?
+ VIRTCMDOPTS+=( "-snapshot" )
+ fi
+}
+
+call_post_source setup_rw_layer
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
new file mode 100644
index 00000000..7d1149b0
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
@@ -0,0 +1,44 @@
+# -----------------------------------------------------------------------------
+#
+# Copyright (c) 2009..2018 bwLehrpool-Projektteam
+#
+# This program/file is free software distributed under the GPL version 2.
+# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
+#
+# If you have any feedback please consult https://bwlehrpool.de and
+# send your feedback to bwlehrpool@hs-offenburg.de.
+#
+# General information about bwLehrpool can be found at https://bwlehrpool.de
+#
+# -----------------------------------------------------------------------------
+# run-virt.include
+# - qemu/kvm plugin for vmchooser run-virt
+################################################################################
+
+# BASH_SOURCE[0] contains the file being sourced, namely this one
+declare -rg QEMUKVM_PLUGIN_DIR="$(dirname "${BASH_SOURCE[0]}")"
+declare -rg QEMUKVM_INCLUDE_DIR="${QEMUKVM_PLUGIN_DIR}/includes"
+
+# TODO make this part of the metadata coming from the server
+# TBD: "firewall printer usb slxfloppy sound netshares"
+declare -rg PLUGIN_FEATURES="slxfloppy"
+
+run_plugin() {
+ # declaration of default functions and variables for vmware
+ $(safesource --exit "${QEMUKVM_INCLUDE_DIR}/init_core.inc")
+
+ # determine limitations wrt RAM and CPU count of VM
+ $(safesource "${QEMUKVM_INCLUDE_DIR}/determine_hardware_limitations.inc")
+
+ # setup networking
+ $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_network.inc")
+
+ # setup rw layer for ro image
+ $(safesource "${QEMUKVM_INCLUDE_DIR}/setup_rw_layer.inc")
+
+ # build the final start command
+ $(safesource "${QEMUKVM_INCLUDE_DIR}/finalize_start_command.inc")
+
+ # print summary - needs writelog() from vmchooser-run_virt
+ $(safesource "${QEMUKVM_INCLUDE_DIR}/log_config_summary.inc")
+}