public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Richard Yao" <ryao@cs.stonybrook.edu>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/kvm-tools:master commit in: /
Date: Sat, 17 Mar 2012 20:46:47 +0000 (UTC)	[thread overview]
Message-ID: <1332017084.eb70edb705d8456c43ebf52a5eae2d91b6b61ecd.ryao@gentoo> (raw)

commit:     eb70edb705d8456c43ebf52a5eae2d91b6b61ecd
Author:     Richard Yao <ryao <AT> cs <DOT> stonybrook <DOT> edu>
AuthorDate: Sat Mar 17 20:40:57 2012 +0000
Commit:     Richard Yao <ryao <AT> cs <DOT> stonybrook <DOT> edu>
CommitDate: Sat Mar 17 20:44:44 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=eb70edb7

Many small changes

	Eliminate bashisms
	Include missing qtap-manipulate script
	Make indentation use tabs to match other scripts in Gentoo
	Eliminate boot=on flag being removed from upstream QEMU
	Switch from default binary from kvm to qemu-kvm

---
 kvm-init-script |  120 +++++++++++++++++++++++++++---------------------------
 qtap-manipulate |   55 +++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 60 deletions(-)

diff --git a/kvm-init-script b/kvm-init-script
index 155e7c6..87d5a48 100644
--- a/kvm-init-script
+++ b/kvm-init-script
@@ -8,9 +8,9 @@ MONITOR=/var/run/vm/${VMNAME}.monitor
 QTAP_FILE=/var/run/vm/${VMNAME}.qtap
 
 # modify this
-VMSOFTWARE=${VMSOFTWARE:-kvm}
+VMSOFTWARE=${VMSOFTWARE:-qemu-kvm}
 DROP_USER=${DROP_USER:-nobody}
-MEMORY=${MEMORY:-500M}
+MEMORY=${MEMORY:-512M}
 TIMEOUT=${TIMEOUT:-300}
 SMP=${SMP:-1}
 
@@ -21,93 +21,93 @@ depend() {
 }
 
 send_command() {
-    local command="socat -u - UNIX-CONNECT:${MONITOR}"
-    which nc6 &> /dev/null && command="nc6 -U ${MONITOR} --send-only"
-    echo "$@" | ${command} >/dev/null 2>&1
+	local command="socat -u - UNIX-CONNECT:${MONITOR}"
+	which nc6 2>&1 > /dev/null && command="nc6 -U ${MONITOR} --send-only"
+	echo "$@" | ${command} >/dev/null 2>&1
 }
 
 sanity_check() {
-    if [ ${VMNAME} = ${SVCNAME} ]; then
-        eerror "You have to create an init script for each vm:"
-        eerror " ln -s vm /etc/init.d/vm.vmname"
-        return 1
-    elif [ ! -f "${DISKIMAGE}" ]; then
-    	eerror "couldn't find \$DISKIMAGE '$DISKIMAGE'"
-    	return 1;
+	if [ "${VMNAME}" = "${SVCNAME}" ]; then
+		eerror "You have to create an init script for each vm:"
+		eerror " ln -s vm /etc/init.d/vm.vmname"
+		return 1
+	elif [ ! -f "${DISKIMAGE}" ]; then
+		eerror "couldn't find \$DISKIMAGE '$DISKIMAGE'"
+		return 1;
    	fi
 }
 
 start() {
-    sanity_check
+	sanity_check
 
-    img=$(readlink -f "${DISKIMAGE}")
-    [ -z "$img" ] && {
-        eerror "couldn't find ${DISKIMAGE}"
-        return 1;
-    }
-    
-    mkdir -p $(dirname ${PIDFILE}) $(dirname ${MONITOR})
-    ebegin "creating qtap ${QTAP:-(auto allocating one)}"
-    QTAP_RET=$(qtap-manipulate create ${QTAP});
-    if [ 0 != $? ]; then
-        eerror "failed to create qtap interface"
-        return 1
+	img=$(readlink -f "${DISKIMAGE}")
+	[ -z "$img" ] && {
+		eerror "couldn't find ${DISKIMAGE}"
+		return 1;
+	}
+	
+	mkdir -p $(dirname ${PIDFILE}) $(dirname ${MONITOR})
+	ebegin "creating qtap ${QTAP:-(auto allocating one)}"
+	QTAP_RET=$(qtap-manipulate create ${QTAP});
+	if [ 0 != $? ]; then
+		eerror "failed to create qtap interface"
+		return 1
 	fi
-    QTAP=${QTAP:-${QTAP_RET}}
-    echo "${QTAP}" > ${QTAP_FILE}
-    eend $?
+	QTAP=${QTAP:-${QTAP_RET}}
+	echo "${QTAP}" > ${QTAP_FILE}
+	eend $?
 
-    ebegin "Starting ${VMSOFTWARE-qemu} for ${VMNAME} at VNC port${VNC}"
-    start-stop-daemon --start /usr/bin/${VMSOFTWARE-qemu} \
+	ebegin "Starting ${VMSOFTWARE-qemu} for ${VMNAME} at VNC port${VNC}"
+	start-stop-daemon --start /usr/bin/${VMSOFTWARE-qemu} \
 	--pidfile ${PIDFILE} \
 	-- -daemonize -pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait \
 	-runas ${DROP_USER} -name ${VMNAME} \
-	-drive file="$img",if=${DRIVE_MODEL:-virtio},boot=on \
+	-drive file="$img",if=${DRIVE_MODEL:-virtio},cache=${DRIVE_CACHE:-none} \
 	-net nic,model=${NIC_MODEL:-virtio},macaddr=${MACADDR} -net tap,ifname=${QTAP},script=no \
 	${DISABLE_KVM:---enable-kvm}  \
 	${MEMORY:+-m ${MEMORY}} ${SMP:+-smp ${SMP}} ${VNC:+-vnc ${VNC}} ${OTHER_ARGS}
-    ret=$?
-    if [ "0" != "${ret}" ]; then
-        qtap-manipulate destroy ${QTAP}
-    fi
-    eend ${ret}
+	ret=$?
+	if [ "0" != "${ret}" ]; then
+		qtap-manipulate destroy ${QTAP}
+	fi
+	eend ${ret}
 }
 
 reboot() {
-    if [ ${VMNAME} = ${SVCNAME} ]; then
+	if [ ${VMNAME} = ${SVCNAME} ]; then
 	eerror "You have to create an init script for each vm:"
 	eerror " ln -s vm /etc/init.d/vm.vmname"
 	return 1
-    fi
-    
-    ebegin "Rebooting ${VMNAME}"
-    send_command system_reset
-    eend $?
+	fi
+	
+	ebegin "Rebooting ${VMNAME}"
+	send_command system_reset
+	eend $?
 }
 
 stop() {
-    sanity_check
+	sanity_check
 
-    ebegin "Powering off ${VMNAME}"
-    send_command system_powerdown
-    eend $?
+	ebegin "Powering off ${VMNAME}"
+	send_command system_powerdown
+	eend $?
 
-    ebegin "waiting up to ${TIMEOUT:-60} seconds for it to die"
-    ret=1
-    for x in $(seq 0 ${TIMEOUT:-60}); do
-    	kill -0 $(<$PIDFILE) &> /dev/null || { ret=0; break; }
-    	sleep 1s
-    done
-    eend ${ret}
+	ebegin "waiting up to ${TIMEOUT:-60} seconds for it to die"
+	ret=1
+	for x in $(seq 0 ${TIMEOUT:-60}); do
+		kill -0 $(cat $PIDFILE) 2>&1 > /dev/null || { ret=0; break; }
+		sleep 1s
+	done
+	eend ${ret}
 
-    ebegin "Stopping ${VMSOFTWARE-qemu} for ${VMNAME}"
-    start-stop-daemon --stop /usr/bin/${VMSOFTWARE-qemu} \
+	ebegin "Stopping ${VMSOFTWARE-qemu} for ${VMNAME}"
+	start-stop-daemon --stop /usr/bin/${VMSOFTWARE-qemu} \
 	--user ${DROP_USER} \
 	--pidfile ${PIDFILE} \
 	--quiet
-    eend $?
-	QTAP=$(<${QTAP_FILE})
-    ebegin "destroying qtap ${QTAP}"
-    qtap-manipulate destroy ${QTAP}
-    eend $?
+	eend $?
+	QTAP=$(cat ${QTAP_FILE})
+	ebegin "destroying qtap ${QTAP}"
+	qtap-manipulate destroy ${QTAP}
+	eend $?
 }

diff --git a/qtap-manipulate b/qtap-manipulate
new file mode 100755
index 0000000..b75c5ef
--- /dev/null
+++ b/qtap-manipulate
@@ -0,0 +1,55 @@
+#!/bin/sh
+[ -z "$1" ] || ( [ "$1" != "create" ] && [ -z "$2" ] ) && { echo "invalid usage, require create [device] || |destroy device"; exit 1; }
+
+#KVM_USER="kvm-envs"
+
+has() {
+	local desired=$1 x
+	shift
+	for x in "$@"; do
+		[ "$desired" = "$x" ] && return 0;
+	done
+	return 1
+}
+
+find_node() {
+	local val=$(ifconfig -a | grep -i ^qtap | cut -d ' ' -f1)
+	local pos=0
+	while has qtap${pos} $val; do
+		pos=$(( $pos + 1 ))
+	done
+	echo qtap${pos}
+}
+
+create_node() {
+	tunctl -b -u "${KVM_USER}" -t ${1} > /dev/null || { echo "tunctl failed"; exit 2; }
+	brctl addif br0 ${1} || { echo "brctl failed"; exit 2; }
+	ifconfig ${1} up 0.0.0.0 promisc || { echo "ifconfig failed"; exit 2; }
+}
+
+destroy_node() {
+	issue=
+	ifconfig ${1} down || { echo "ifconfig failed";issue=1; }
+	brctl delif br0 ${1} || { echo "brctl failed";issue=2; }
+	tunctl -d ${1} > /dev/null || { echo "tunctl failed";issue=3;}
+	[ -n "${issue}" ] && exit -$(( $issue ))
+}
+
+command=$1
+qtap=$2
+
+if [ -z "$qtap" ]; then
+	qtap=$(find_node)
+fi
+
+if [ "$command" = "create" ]; then
+	create_node "$qtap"
+	[ "$2" != "${qtap}" ] && echo "${qtap}"
+elif [ "$command" = "destroy" ]; then
+	destroy_node "$qtap"
+else
+	echo "$command isn't a valid command; must be create or destroy";
+	exit 1
+fi
+
+exit 0



             reply	other threads:[~2012-03-17 20:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-17 20:46 Richard Yao [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-04-14  6:26 [gentoo-commits] proj/kvm-tools:master commit in: / Brian Harring
2012-04-14  6:26 Brian Harring
2012-04-14  6:26 Brian Harring
2012-04-14  6:26 Brian Harring
2012-04-14  6:26 Brian Harring
2012-04-14  4:47 Richard Yao
2012-03-17 20:44 Richard Yao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332017084.eb70edb705d8456c43ebf52a5eae2d91b6b61ecd.ryao@gentoo \
    --to=ryao@cs.stonybrook.edu \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox