runtime.vars: add helpers for setting VM resource requirements
authorDavid Disseldorp <ddiss@suse.de>
Fri, 26 May 2017 09:24:46 +0000 (11:24 +0200)
committerDavid Disseldorp <ddiss@suse.de>
Fri, 26 May 2017 09:24:46 +0000 (11:24 +0200)
Some workloads (e.g. fstests_local) require memory resources that exceed
the default 2xCPU + 512M RAM VM. Allow Cut scripts to define their
own CPU and memory requirements by stamping a user.rapido.vm_resources
extended attribute on the initramfs image.

Signed-off-by: David Disseldorp <ddiss@suse.de>
runtime.vars
vm.sh

index 3d20e7621b3c836fc9bd8ecaa2b39f6776c3e884..f2ae0212c352d1a784c0455c7189b87d6be4855a 100644 (file)
@@ -231,3 +231,32 @@ function _rt_xattr_vm_networkless_get
 
        getfattr --only-values -n $xattr_key $img 2> /dev/null
 }
+
+function _rt_xattr_vm_resources_set
+{
+       local img="$1"
+       local cpus="$2"
+       local mem="$3"
+       local xattr_key="user.rapido.vm_resources"
+       local re='^[0-9]+$'
+
+       [ -n "$img" ] || _fail "img parameter is manditory"
+       [ -f "$img" ] || _fail "no image at $img"
+       [[ $cpus =~ $re ]] || _fail "num CPUs must be numeric"
+       re='^[0-9]+[MGmg]?$'
+       [[ $mem =~ $re ]] || _fail "invalid memory string: $mem"
+
+       setfattr -n "$xattr_key" -v "-smp cpus=${cpus} -m $mem" $img \
+               || _fail "failed to set xattr on $img"
+}
+
+function _rt_xattr_vm_resources_get
+{
+       local img="$1"
+       local xattr_key="user.rapido.vm_resources"
+
+       [ -n "$img" ] || _fail "img parameter is manditory"
+       [ -f "$img" ] || _fail "no image at $img"
+
+       getfattr --only-values -n $xattr_key $img 2> /dev/null
+}
diff --git a/vm.sh b/vm.sh
index 73e8bcea38449826f1b184d1ad821b46df7afb81..d98636fa39d88667f608c074e08af660b7327f3b 100755 (executable)
--- a/vm.sh
+++ b/vm.sh
@@ -73,11 +73,14 @@ function _vm_start
        local qemu_cut_args="$(_rt_xattr_qemu_args_get ${DRACUT_OUT})"
        local qemu_more_args="$qemu_netdev $QEMU_EXTRA_ARGS $qemu_cut_args"
 
+       local vm_resources="$(_rt_xattr_vm_resources_get ${DRACUT_OUT})"
+       [ -n "$vm_resources" ] || vm_resources="-smp cpus=2 -m 512"
+
        [ -f "$kernel_img" ] \
           || _fail "no kernel image present at ${kernel_img}. Build needed?"
 
        $QEMU_KVM_BIN \
-               -smp cpus=2 -m 512 \
+               $vm_resources \
                -kernel "$kernel_img" \
                -initrd "$DRACUT_OUT" \
                -append "ip=${kern_ip_addr} rd.systemd.unit=emergency \