Fix --tcg option (it broken KVM).
[supernested.git] / run-supernested.sh.in
index 50cd47b..7e63ceb 100644 (file)
@@ -25,9 +25,13 @@ format=qcow2
 kernel=kernel
 initrd=initrd
 append="panic=1 console=ttyS0 udevtimeout=6000 no_timer_check printk.time=1 root=/dev/sda selinux=0"
+smp=
+accel=kvm
+cpu="-cpu host"
 
 TEMP=`getopt \
-        --long nested \
+        -o '' \
+        --longoptions 'help,nested,smp:,tcg' \
         -n run-supernested.sh -- "$@"`
 if [ $? != 0 ]; then
     echo "$0: problem parsing the command line arguments"
@@ -35,6 +39,15 @@ if [ $? != 0 ]; then
 fi
 eval set -- "$TEMP"
 
+usage ()
+{
+    echo "$0: Run the supernested appliance."
+    echo "  $0 [--smp=N] [--tcg]"
+    echo "Options:"
+    echo "  --smp=N    Use N virtual CPUs (at all levels)."
+    echo "  --tcg      Use TCG (at all levels) instead of KVM."
+}
+
 while true ; do
     case "$1" in
         --nested)
@@ -44,14 +57,40 @@ while true ; do
             format=raw
             kernel=/kernel
             initrd=/initrd
+           smp="$(
+                grep -Eo 'supernested.smp=[[:digit:]]+' /proc/cmdline |
+                grep -Eo '[[:digit:]]+'
+                )"
+           if [ -n "$smp" ]; then smp="-smp $smp"; fi
+           accel="$(
+                grep -Eo 'supernested.accel=tcg' /proc/cmdline
+                )"
+           if [ -n "$accel" ]; then
+               accel=tcg
+               cpu=
+           else
+               accel=kvm
+           fi
             shift
             ;;
+       --smp)
+           smp="-smp $2"
+           append="$append supernested.smp=$2"
+           shift 2
+           ;;
+       --tcg)
+           accel=tcg
+           cpu=
+           append="$append supernested.accel=tcg"
+           shift
+           ;;
         --help)
-            echo "$0: read the README file for information about this script"
-            shift
+           usage
+           exit 0
             ;;
         --)
             shift
+           break
             ;;
         *)
             echo "internal error ($1)"
@@ -85,10 +124,25 @@ level="$(
 if [ -z "$level" ]; then level=0; fi
 append="$append supernested.level=$((level+1))"
 
+echo "Running"
+echo "    qemu = $qemu"
+echo "    cpu = $cmp"
+echo "    smp = $smp"
+echo "    accel = $accel"
+echo "    memory = $memory"
+echo "    kernel = $kernel"
+echo "    initrd = $initrd"
+echo "    disk = $image"
+echo "    append = $append"
+
+# Since this could crash the machine, better to sync ...
+sync
+
 exec \
 "$qemu" \
-    -cpu host \
-    -machine accel=kvm \
+    $cpu \
+    $smp \
+    -machine accel=$accel \
     -display none \
     -m $memory \
     -no-reboot \