From eec193967f7aca562f7d99eaf5d6177f08e9a99e Mon Sep 17 00:00:00 2001 From: Michael Janczyk Date: Sun, 11 Apr 2010 23:08:47 +0200 Subject: virtualization plugin, now with calculation of mem, run-vmgrid and run-virt uses it --- os-plugins/plugins/vmchooser/files/run-virt.sh | 11 ++-- .../init-hooks/80-after-plugins/virtualization.sh | 54 ++++++++++++------ os-plugins/plugins/vmgrid/XX_vmgrid.sh | 4 +- os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 6 +- os-plugins/plugins/vmgrid/files/vmgrid | 55 ++++++------------ .../init-hooks/80-after-plugins/virtualization.sh | 54 ++++++++++++------ os-plugins/plugins/vmware/files/run-virt.include | 65 ++++++++++++---------- 7 files changed, 133 insertions(+), 116 deletions(-) (limited to 'os-plugins/plugins') diff --git a/os-plugins/plugins/vmchooser/files/run-virt.sh b/os-plugins/plugins/vmchooser/files/run-virt.sh index adfc737e..771ebef4 100644 --- a/os-plugins/plugins/vmchooser/files/run-virt.sh +++ b/os-plugins/plugins/vmchooser/files/run-virt.sh @@ -121,22 +121,21 @@ cpu_cores="${cpu_cores}" # check for CPU virtualization flags -# get total amount of memory installed in your machine -totalmem=$(expr $(grep -i "memtotal" /proc/meminfo | awk '{print $2}') / 1024) +# total amount of memory defined in stage 3 permem=60 +# get a result which can be divided through 4 mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4) +[ -n "${mainvirtmem}" ] && forcemem=$(expr ${mainvirtmem} / 4 \* 4) # configuring ethernet mac address: first 3 bytes are fixed (00:50:56) # 4th byte is the VM-ID (0D) # last two bytes are taken from the bridge of the host # define one MAC per guest macguestpart="00:50:56:${VM_ID}" -machostpart=$($(which ifconfig) br0 | grep br0 | sed -e "s/ //g" | \ - awk -F ":" '{print $(NF-1)":"$NF}') +machostpart=$(echo ${machostaddr} | awk -F ":" '{print $(NF-1)":"$NF}') macaddr=$(echo "${macguestpart}:${machostpart}" | tr [a-z] [A-Z]) #TODO: remove when vmware modified -mac=$(/sbin/ifconfig eth0 | grep eth0 | sed -e "s/ //g" \ - | awk -F ":" '{print $(NF-1)":"$NF}') +mac=${machostpart} # virtual fd/cd/dvd and drive devices, floppy b: for configuration # if $floppy_0 from run-virt.include set then fdtest="TRUE" diff --git a/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh b/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh index 5fa046d9..400075cd 100644 --- a/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh +++ b/os-plugins/plugins/vmchooser/init-hooks/80-after-plugins/virtualization.sh @@ -25,9 +25,9 @@ PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization # check if plugins available active=0 [ -f ${CONFFILEVMCHOOSER} ] && . ${CONFFILEVMCHOOSER} -[ -n "${CONFFILEVMCHOOSER}" ] && active=1 +[ ${vmchooser_active} -ne 0 ] && active=1 [ -f ${CONFFILEVMGRID} ] && . ${CONFFILEVMGRID} -[ -n "${CONFFILEVMGRID}" ] && active=1 +[ ${vmgrid_active} -ne 0 ] && active=1 [ $DEBUGLEVEL -gt 0 ] \ && echo -e "Executing the virtual 'virtualization' plugin ... \c" @@ -45,27 +45,45 @@ if [ ${active} -ne 0 ] ; then totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ | awk '{print $2}') / 1024) echo "totalmem=${totalmem}" >> ${PLUGINCONFDIR}/virtualization.conf + if [ ${vmgrid_active} -ne 0 ]; then + totalmemtest=$(expr $(echo ${vmgrid_memratio} \ | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) + + # not more than 100% memory assigned if [ ${totalmemtest} -le 100 2>/dev/null ]; then - # get hostmem - freememper=$(expr 100 - $(echo ${vmgrid_memratio} \ - | awk -F ',' '{print $1" - "$2" - "$3" - "$4}')) - freemem=$(expr ${totalmem} \* ${freememper} / 100) - echo "freemem=${freemem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf - else - # more than 100% memory assigned stupid! - # vmgrid will get this as well and exit! - # so we have theoretically 100% free - echo "freemem=${totalmem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf + + # host mem + hostratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $6}') + hostmem=$(expr ${totalmem} \* ${hostratio} / 100 2>/dev/null) + if [ ${hostmem} -lt 256 2>/dev/null ]; then + # min. 256 MB for host + hostmem=256 + fi + + # main vm mem (vmchooser) + if [ ${vmchooser_active} -ne 0 ]; then + mainvirtratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $5}') + mainvirtmem=$(expr ${totalmem} \* ${mainvirtratio} / 100 2>/dev/null) + if [ ${mainvirtmem} -lt 512 2>/dev/null ]; then + # min. 512 for vmchooser + mainvirtmem=512 + fi + else + mainvirtratio=0 + mainvirtmem=0 + fi + + cat << EOF >> ${PLUGINCONFDIR}/virtualization.conf +hostratio=${hostratio} +hostmem=${hostmem} +mainvirtratio=${mainvirtratio} +mainvirtmem=${mainvirtmem} +EOF + fi - else - echo "freemem=${totalmem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf -fi + fi # cpu cores CPU_CORES=$(grep 'processor.*:' /proc/cpuinfo | wc -l) diff --git a/os-plugins/plugins/vmgrid/XX_vmgrid.sh b/os-plugins/plugins/vmgrid/XX_vmgrid.sh index 1d0c76be..f75c895d 100644 --- a/os-plugins/plugins/vmgrid/XX_vmgrid.sh +++ b/os-plugins/plugins/vmgrid/XX_vmgrid.sh @@ -30,8 +30,8 @@ if [ -f $CONFFILE ]; then # load needed variables . $CONFFILE - if [ $vmgrid_active -ne 0 ] ; then - [ $DEBUGLEVEL -gt 0 ] && echo "executing the 'vmgrid' os-plugin ..." + if [ ${vmgrid_active} -ne 0 ] ; then + [ ${DEBUGLEVEL} -gt 0 ] && echo "executing the 'vmgrid' os-plugin ..." # load general configuration . /etc/initramfs-setup diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh index 5e64b4cd..1501749e 100644 --- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -53,19 +53,19 @@ writelog () { ### Get XML file and dir ################################################################################ -# check if forcemem or graphical mode set +# check if mem or graphical mode set headless=1 while [ $# -gt 0 ]; do case "$1" in -h|--help) - echo -e "Usage: run-vmgrid.sh [-g] [--forcemem ] \c" + echo -e "Usage: run-vmgrid.sh [-g] [--mem ] \c" echo -e "[/path/]filename[.xml]" exit ;; -g) headless=0 ;; - --forcemem) + --mem) # get a result which can be divided through 4 forcemem=$2 echo $2 | grep -q '[1-9][0-9]\{2,3\}$' && forcemem=$(expr $2 / 4 \* 4) diff --git a/os-plugins/plugins/vmgrid/files/vmgrid b/os-plugins/plugins/vmgrid/files/vmgrid index ef86cb5a..d8ccd938 100644 --- a/os-plugins/plugins/vmgrid/files/vmgrid +++ b/os-plugins/plugins/vmgrid/files/vmgrid @@ -24,7 +24,7 @@ if [ -n "$1" ]; then if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then - echo -e "Usage: vmgrid [[-g] [--forcemem ] \c" + echo -e "Usage: vmgrid [[-g] [--mem ] \c" echo -e "[/path/]filename[.xml]]" exit 0 else @@ -47,9 +47,6 @@ RWSHARE=/var/opt/openslx/plugins/vmgrid/share # load general virtualization information [ -f ${PLUGINCONFROOT}/virtualization/virtualization.conf ] && \ . ${PLUGINCONFROOT}/virtualization/virtualization.conf -# get the vmchooser_active var -[ -f ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ] && \ - . ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ################################################################################ ### Functions used throughout the script @@ -69,48 +66,35 @@ writelog () { ### Configure VMs for autostart and set RAM ################################################################################ -# start to log, create shrare log dir +# start to log, create share log dir mkdir -m 1777 -p ${vmgrid_rwmnt}/logs mkdir -m 1777 -p /tmp/vmgrid mkdir -p /tmp/vmgrid/${USER} echo "Starting to log at $(date)" \ >${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log +if [ -z "${hostratio}" ]; then + writelog "There has been an error in the memory configuration in stage 3" + writelog "Please check your memory ratio settings, exiting!" + exit 1 +fi + # remove blanks -vmgrid_memratio=$(echo ${vmgrid_memratio} | sed -e "s, *,,g") vmgrid_startvms=$(echo ${vmgrid_startvms} | sed -e "s, *,,g") +vmgrid_memratio=$(echo ${vmgrid_memratio} | sed -e "s, *,,g") -# get hostmem, totalmem from stage 3 -hostratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $6}') -hostmem=$(expr ${totalmem} \* ${hostratio} / 100 2>/dev/null) -if [ ${hostmem} -lt 256 2>/dev/null ]; then - hostmem=256 - writelog "${hostmem} MB RAM reserved for host" -fi - -# get other vm mem -if [ -n "${vmchooser_active}" ]; then - othervmratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $5}') - othervmmem=$(expr ${totalmem} \* ${othervmratio} / 100 2>/dev/null) - if [ ${othervmmem} -lt 512 2>/dev/null ]; then - othervmmem=512 - writelog "${othervmmem} MB RAM reserved for other virtualization solutions" - fi -else - othervmratio=0 - othervmmem=0 -fi +# hostmem, mainvirt from virtualization plugin +# ratio minus other vms and host +restratio=$(expr 100 - ${hostratio} - ${mainvirtratio}) +# hostmem, totalmem, mainvirtmem from virtualization plugin # calculate freemem -freemem=$(expr ${totalmem} - ${hostmem} - ${othervmmem} 2>/dev/null) +freemem=$(expr ${totalmem} - ${hostmem} - ${mainvirtmem} 2>/dev/null) if [ ${freemem} -lt 512 2>/dev/null ]; then writelog "Not enough free RAM for this plugin, free: ${freemem} MB" exit 1 fi -# ratio minus other vms and host -restratio=$(expr 100 - ${hostratio} - ${othervmratio}) - # get clients mem ratio vmsumratios=0 for i in {1..4}; do @@ -123,15 +107,8 @@ for i in {1..4}; do vmsumratios=$(expr ${vmsumratios} + ${vmratio[$i]} 2>/dev/null) done -# ratio test: 100 - host - other vm + grid ratios -ratiotest=$(expr 100 - ${restratio} + ${vmsumratios} 2>/dev/null) -if [ ${ratiotest} -gt 100 ]; then - #writelog "you managed to get over 100% in ratio Einstein: ${ratiotest}%" - exit 1 -fi - for i in {1..4}; do - # calculate vms mem: mem = $freemem * $vmratio/100 * 100/$restratio + # calculate VMs mem: mem = $freemem * $vmratio/100 * 100/$restratio # multiple of 4 vmmem[$i]=$(expr ${freemem} \* ${vmratio[$i]} / ${restratio} / 4 \* 4 \ 2>/dev/null) @@ -155,7 +132,7 @@ for i in {1..4}; do writelog "${vm[$i]} already running, skipping!" else writelog "Starting ${vm[$i]} via run-vmgrid.sh with ${vmmem[$i]} MB RAM" - run-vmgrid.sh --forcemem ${vmmem[$i]} ${vm[$i]} 2>/dev/null & + run-vmgrid.sh --mem ${vmmem[$i]} ${vm[$i]} 2>/dev/null & echo $! > /tmp/vmgrid/${USER}/vmgrid.pids # wait 5 secs for the next vm to start sleep 10 diff --git a/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh index 5fa046d9..400075cd 100644 --- a/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh +++ b/os-plugins/plugins/vmgrid/init-hooks/80-after-plugins/virtualization.sh @@ -25,9 +25,9 @@ PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization # check if plugins available active=0 [ -f ${CONFFILEVMCHOOSER} ] && . ${CONFFILEVMCHOOSER} -[ -n "${CONFFILEVMCHOOSER}" ] && active=1 +[ ${vmchooser_active} -ne 0 ] && active=1 [ -f ${CONFFILEVMGRID} ] && . ${CONFFILEVMGRID} -[ -n "${CONFFILEVMGRID}" ] && active=1 +[ ${vmgrid_active} -ne 0 ] && active=1 [ $DEBUGLEVEL -gt 0 ] \ && echo -e "Executing the virtual 'virtualization' plugin ... \c" @@ -45,27 +45,45 @@ if [ ${active} -ne 0 ] ; then totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ | awk '{print $2}') / 1024) echo "totalmem=${totalmem}" >> ${PLUGINCONFDIR}/virtualization.conf + if [ ${vmgrid_active} -ne 0 ]; then + totalmemtest=$(expr $(echo ${vmgrid_memratio} \ | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) + + # not more than 100% memory assigned if [ ${totalmemtest} -le 100 2>/dev/null ]; then - # get hostmem - freememper=$(expr 100 - $(echo ${vmgrid_memratio} \ - | awk -F ',' '{print $1" - "$2" - "$3" - "$4}')) - freemem=$(expr ${totalmem} \* ${freememper} / 100) - echo "freemem=${freemem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf - else - # more than 100% memory assigned stupid! - # vmgrid will get this as well and exit! - # so we have theoretically 100% free - echo "freemem=${totalmem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf + + # host mem + hostratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $6}') + hostmem=$(expr ${totalmem} \* ${hostratio} / 100 2>/dev/null) + if [ ${hostmem} -lt 256 2>/dev/null ]; then + # min. 256 MB for host + hostmem=256 + fi + + # main vm mem (vmchooser) + if [ ${vmchooser_active} -ne 0 ]; then + mainvirtratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $5}') + mainvirtmem=$(expr ${totalmem} \* ${mainvirtratio} / 100 2>/dev/null) + if [ ${mainvirtmem} -lt 512 2>/dev/null ]; then + # min. 512 for vmchooser + mainvirtmem=512 + fi + else + mainvirtratio=0 + mainvirtmem=0 + fi + + cat << EOF >> ${PLUGINCONFDIR}/virtualization.conf +hostratio=${hostratio} +hostmem=${hostmem} +mainvirtratio=${mainvirtratio} +mainvirtmem=${mainvirtmem} +EOF + fi - else - echo "freemem=${totalmem}" \ - >> ${PLUGINCONFDIR}/virtualization.conf -fi + fi # cpu cores CPU_CORES=$(grep 'processor.*:' /proc/cpuinfo | wc -l) diff --git a/os-plugins/plugins/vmware/files/run-virt.include b/os-plugins/plugins/vmware/files/run-virt.include index dfd07a89..8b91275a 100644 --- a/os-plugins/plugins/vmware/files/run-virt.include +++ b/os-plugins/plugins/vmware/files/run-virt.include @@ -301,36 +301,40 @@ case "$parallel" in esac # adjust memory available for vmware guests -case "$vmversion" in - 2.*) - permem=30 - ;; - 3.*) - permem=25 - ;; -esac -if [ "${totalmem}" -ge "2500" ]; then - permem=40 -fi -# check if /tmp is on harddisk -if grep -qe "/dev/.* /tmp " /proc/mounts ; then - permem=60 - id44="1" - # Hack, if more than 2,5G RAM use 40% of Ram and write vmem into Ram as well - # (40% vmware | 40% confdir(vmem...) | 20% host - # VMplayer 2+ issue +if [ -n "${forcemem}" ]; then + mem="${forcemem}" +else + case "$vmversion" in + 2.*) + permem=30 + ;; + 3.*) + permem=25 + ;; + esac if [ "${totalmem}" -ge "2500" ]; then permem=40 - confdir=/dev/shm/vmware/$USER - conffile=${confdir}/run-vmware.conf - mkdir -p /dev/shm/vmware/$USER fi -fi -mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4) -if [ "${id44}" = "1" ]; then - memhost=$(expr ${totalmem} - ${mem}) -else - memhost=$(expr ${totalmem} - ${mem} - ${mem}) + # check if /tmp is on harddisk + if grep -qe "/dev/.* /tmp " /proc/mounts ; then + permem=60 + id44="1" + # Hack, if more than 2,5G RAM use 40% of Ram and write vmem into Ram as well + # (40% vmware | 40% confdir(vmem...) | 20% host + # VMplayer 2+ issue + if [ "${totalmem}" -ge "2500" ]; then + permem=40 + confdir=/dev/shm/vmware/$USER + conffile=${confdir}/run-vmware.conf + mkdir -p /dev/shm/vmware/$USER + fi + fi + mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4) + if [ "${id44}" = "1" ]; then + hostmem=$(expr ${totalmem} - ${mem}) + else + hostmem=$(expr ${totalmem} - ${mem} - ${mem}) + fi fi # check if ide/scsi and hwver of image @@ -397,8 +401,8 @@ writelog "# File created by $0 (VMversion ${vmversion})\n# on $(date)\n" writelog "Starting with non-persistent mode ...\n" # check memory range -if [ "${mem}" -lt "256" ] || [ "${memhost}" -lt "256" ]; then - writelog "\tMemory out of range: ${mem} MB (guest) / ${memhost} MB (host)!" +if [ "${mem}" -lt "256" ] || [ "${hostmem}" -lt "256" ]; then + writelog "\tMemory out of range: ${mem} MB (guest) / ${hostmem} MB (host)!" writelog "\tMin. 256 MB for host and guest!" exit 1 fi @@ -420,7 +424,8 @@ if [ -n "${network_card}" ]; then writelog "\tNet Adaptor:\t${network_card}" fi writelog "\tMem:\t\t${mem} MB" -writelog "\tHostmem:\t${memhost} MB" +# echo nur wenn hostmem gesetzt +[ -n "${hostmem}" ] && writelog "\tHostmem:\t${hostmem} MB" writelog "\tMax. res.:\t${xres}x${yres}" writelog "\tCD-ROM1:\t${cdrom0}" writelog "\tCD-ROM2:\t${cdrom1}" -- cgit v1.2.3-55-g7522