* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-03-17 20:44 Richard Yao
0 siblings, 0 replies; 8+ messages in thread
From: Richard Yao @ 2012-03-17 20:44 UTC (permalink / raw
To: gentoo-commits
commit: 5ebde255c7e4bb851c88c3f2f55152878f9d19ff
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:40:57 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=5ebde255
Major 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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-03-17 20:46 Richard Yao
0 siblings, 0 replies; 8+ messages in thread
From: Richard Yao @ 2012-03-17 20:46 UTC (permalink / raw
To: gentoo-commits
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-04-14 4:47 Richard Yao
0 siblings, 0 replies; 8+ messages in thread
From: Richard Yao @ 2012-04-14 4:47 UTC (permalink / raw
To: gentoo-commits
commit: aa49399a69f165abd2ada35b37f5945aeec22689
Author: Richard Yao <ryao <AT> cs <DOT> stonybrook <DOT> edu>
AuthorDate: Sat Apr 14 04:46:35 2012 +0000
Commit: Richard Yao <ryao <AT> cs <DOT> stonybrook <DOT> edu>
CommitDate: Sat Apr 14 04:46:35 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=aa49399a
Minor fixes for residual issues
---
kvm-init-script | 9 +++++----
qtap-manipulate | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/kvm-init-script b/kvm-init-script
index 87d5a48..cec0ed6 100644
--- a/kvm-init-script
+++ b/kvm-init-script
@@ -13,8 +13,9 @@ DROP_USER=${DROP_USER:-nobody}
MEMORY=${MEMORY:-512M}
TIMEOUT=${TIMEOUT:-300}
SMP=${SMP:-1}
+export KVM_USER=${KVM_USER:-"root"}
-opts="reboot"
+extra_commands="reboot"
depend() {
need net.br0
@@ -22,16 +23,16 @@ depend() {
send_command() {
local command="socat -u - UNIX-CONNECT:${MONITOR}"
- which nc6 2>&1 > /dev/null && command="nc6 -U ${MONITOR} --send-only"
+ which nc6 2> /dev/null > /dev/null && command="nc6 -U ${MONITOR} --send-only"
echo "$@" | ${command} >/dev/null 2>&1
}
sanity_check() {
- 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
- elif [ ! -f "${DISKIMAGE}" ]; then
+ elif [ ! -f "${DISKIMAGE}" -a ! -b "${DISKIMAGE}" ]; then
eerror "couldn't find \$DISKIMAGE '$DISKIMAGE'"
return 1;
fi
diff --git a/qtap-manipulate b/qtap-manipulate
index b75c5ef..0c92633 100755
--- a/qtap-manipulate
+++ b/qtap-manipulate
@@ -1,7 +1,7 @@
#!/bin/sh
[ -z "$1" ] || ( [ "$1" != "create" ] && [ -z "$2" ] ) && { echo "invalid usage, require create [device] || |destroy device"; exit 1; }
-#KVM_USER="kvm-envs"
+KVM_USER=${KVM_USER:-"root"}
has() {
local desired=$1 x
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-04-14 6:26 Brian Harring
0 siblings, 0 replies; 8+ messages in thread
From: Brian Harring @ 2012-04-14 6:26 UTC (permalink / raw
To: gentoo-commits
commit: cada3da04eb8f483cb382262307cae63e6e511f5
Author: Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Sat Apr 14 02:38:36 2012 +0000
Commit: Brian Harring <ferringb <AT> gentoo <DOT> org>
CommitDate: Sat Apr 14 06:19:03 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=cada3da0
Properly fix user/group breakage in qtap-manipulate induced in eb70edb7.
In the process, add a create_specific command. Additionally,
update kvm.init to work w/ the new qtap-manipulate options.
---
kvm-init-script | 2 +-
qtap-manipulate | 103 +++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 82 insertions(+), 23 deletions(-)
diff --git a/kvm-init-script b/kvm-init-script
index e71c687..e618ad9 100644
--- a/kvm-init-script
+++ b/kvm-init-script
@@ -49,7 +49,7 @@ start() {
mkdir -p $(dirname ${PIDFILE}) $(dirname ${MONITOR})
ebegin "creating qtap ${QTAP:-(auto allocating one)}"
- QTAP_RET=$(qtap-manipulate create ${QTAP});
+ QTAP_RET=$(qtap-manipulate create ${QTAP} -u "${DROP_USER}");
if [ 0 != $? ]; then
eerror "failed to create qtap interface"
return 1
diff --git a/qtap-manipulate b/qtap-manipulate
index 0c92633..7e1ec53 100755
--- a/qtap-manipulate
+++ b/qtap-manipulate
@@ -1,7 +1,4 @@
#!/bin/sh
-[ -z "$1" ] || ( [ "$1" != "create" ] && [ -z "$2" ] ) && { echo "invalid usage, require create [device] || |destroy device"; exit 1; }
-
-KVM_USER=${KVM_USER:-"root"}
has() {
local desired=$1 x
@@ -12,7 +9,7 @@ has() {
return 1
}
-find_node() {
+find_available_node() {
local val=$(ifconfig -a | grep -i ^qtap | cut -d ' ' -f1)
local pos=0
while has qtap${pos} $val; do
@@ -22,9 +19,11 @@ find_node() {
}
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; }
+ local qtap="$1"
+ shift
+ tunctl -b -t "${qtap}" "$@" > /dev/null || die "tunctl failed"
+ brctl addif br0 "${qtap}" || die "brctl failed"
+ ifconfig "${qtap}" up 0.0.0.0 promisc || die "ifconfig failed"
}
destroy_node() {
@@ -32,24 +31,84 @@ destroy_node() {
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 ))
+ [ -n "${issue}" ] && exit $(( $issue ))
}
-command=$1
-qtap=$2
+die() {
+ echo "$@" >&2
+ exit 1
+}
-if [ -z "$qtap" ]; then
- qtap=$(find_node)
-fi
+usage() {
+ echo "commands available:"
+ echo "create-specific qtap-name [ -u user ] [ -g group ]"
+ echo "create [ -u user ] [ -g group ]"
+ echo "destroy qtap-name"
+ echo
+}
-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
+usage_die() {
+ usage
+ die "$@"
+}
+
+create_user=
+create_group=
+
+parse_create_options() {
+ while [ $# -ne 0 ]; do
+ local x="$1"
+ case "$x" in
+ -u=*)
+ shift
+ set -- "-u" "${x#-u=}" "$@"
+ ;&
+ -u)
+ shift
+ [ -z "$1" ] && die "-u requires an argument"
+ create_user="$1"
+ shift
+ ;;
+ -g=*)
+ shift
+ set -- "-g" "${x#-u=}" "$@"
+ ;&
+ -g)
+ shift
+ [ -z "$1" ] && die "-g requires an argument"
+ create_group="$2"
+ shift
+ ;;
+ *)
+ die "unknown option $1"
+ esac
+ done
+}
+output_qtap=false
+case "$1" in
+ destroy)
+ shift
+ [ $# -eq 0 ] && usage_die "destroy requires a second argument"
+ [ $# -gt 1 ] && usage_die "no idea what to do with args: $@"
+ destroy_node "$1"
+ ;;
+ create)
+ output_qtap=true
+ qtap=$(find_available_node)
+ [ -z "$qtap" ] && die "failed to find a qtap node to use"
+ shift
+ set -- create_specific "${qtap}" "$@"
+ ;&
+ create_specific)
+ shift
+ qtap="$1"; shift
+ parse_create_options "$@"
+ create_node "$qtap"
+ $output_qtap && echo "$qtap"
+ ;;
+ *)
+ usage_die "Unknown command $1"
+ ;;
+esac
exit 0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-04-14 6:26 Brian Harring
0 siblings, 0 replies; 8+ messages in thread
From: Brian Harring @ 2012-04-14 6:26 UTC (permalink / raw
To: gentoo-commits
commit: 9288932a7fc62147a018b20beddf313cd08068d2
Author: Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Sat Apr 14 02:29:33 2012 +0000
Commit: Brian Harring <ferringb <AT> gentoo <DOT> org>
CommitDate: Sat Apr 14 06:18:34 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=9288932a
Fix indentation issues induced in eb70edb7.
---
kvm-init-script | 32 ++++++++++++++++----------------
1 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/kvm-init-script b/kvm-init-script
index 0be5046..e71c687 100644
--- a/kvm-init-script
+++ b/kvm-init-script
@@ -35,7 +35,7 @@ sanity_check() {
elif [ ! -f "${DISKIMAGE}" -a ! -b "${DISKIMAGE}" ]; then
eerror "couldn't find \$DISKIMAGE '$DISKIMAGE'"
return 1;
- fi
+ fi
}
start() {
@@ -46,7 +46,7 @@ start() {
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});
@@ -60,13 +60,13 @@ start() {
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},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}
+ --pidfile ${PIDFILE} \
+ -- -daemonize -pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait \
+ -runas ${DROP_USER} -name ${VMNAME} \
+ -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}
@@ -76,11 +76,11 @@ start() {
reboot() {
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
+ 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 $?
@@ -103,9 +103,9 @@ stop() {
ebegin "Stopping ${VMSOFTWARE-qemu} for ${VMNAME}"
start-stop-daemon --stop /usr/bin/${VMSOFTWARE-qemu} \
- --user ${DROP_USER} \
- --pidfile ${PIDFILE} \
- --quiet
+ --user ${DROP_USER} \
+ --pidfile ${PIDFILE} \
+ --quiet
eend $?
QTAP=$(cat ${QTAP_FILE})
ebegin "destroying qtap ${QTAP}"
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-04-14 6:26 Brian Harring
0 siblings, 0 replies; 8+ messages in thread
From: Brian Harring @ 2012-04-14 6:26 UTC (permalink / raw
To: gentoo-commits
commit: cbda1b878235f6551f263e351cf527c1e30ea559
Author: Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Sat Apr 14 06:17:28 2012 +0000
Commit: Brian Harring <ferringb <AT> gentoo <DOT> org>
CommitDate: Sat Apr 14 06:18:26 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=cbda1b87
Fix breakage sanity_check breakage induced in aa49399a.
---
kvm-init-script | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kvm-init-script b/kvm-init-script
index cec0ed6..0be5046 100644
--- a/kvm-init-script
+++ b/kvm-init-script
@@ -28,7 +28,7 @@ send_command() {
}
sanity_check() {
- 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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-04-14 6:26 Brian Harring
0 siblings, 0 replies; 8+ messages in thread
From: Brian Harring @ 2012-04-14 6:26 UTC (permalink / raw
To: gentoo-commits
commit: 80a64bd925e3d97e22f185545a8a8cc650339955
Author: Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Sat Apr 14 03:49:16 2012 +0000
Commit: Brian Harring <ferringb <AT> gentoo <DOT> org>
CommitDate: Sat Apr 14 06:19:46 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=80a64bd9
kvm-init-script: Fix breakages induced in eb70edb7, up the error checking, cleanup.
---
kvm-init-script | 74 +++++++++++++++++++++++++++++++++++-------------------
1 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/kvm-init-script b/kvm-init-script
index e618ad9..7bfeb9d 100644
--- a/kvm-init-script
+++ b/kvm-init-script
@@ -7,8 +7,12 @@ PIDFILE=/var/run/vm/${VMNAME}.pid
MONITOR=/var/run/vm/${VMNAME}.monitor
QTAP_FILE=/var/run/vm/${VMNAME}.qtap
-# modify this
-VMSOFTWARE=${VMSOFTWARE:-qemu-kvm}
+# Default to qemu-kvm in the absense of a setting, failing back
+# to kvm if no binary is found, finally, back to qemu.
+[ -z "$VMSOFTWARE" ] && VMSOFTWARE=$(type -p qemu-kvm)
+[ -z "$VMSOFTWARE" ] && VMSOFTWARE=$(type -p kvm)
+[ -z "$VMSOFTWARE" ] && VMSOFTWARE=$(type -p qemu)
+
DROP_USER=${DROP_USER:-nobody}
MEMORY=${MEMORY:-512M}
TIMEOUT=${TIMEOUT:-300}
@@ -23,8 +27,8 @@ depend() {
send_command() {
local command="socat -u - UNIX-CONNECT:${MONITOR}"
- which nc6 2> /dev/null > /dev/null && command="nc6 -U ${MONITOR} --send-only"
- echo "$@" | ${command} >/dev/null 2>&1
+ type -p nc6 > /dev/null && command="nc6 -U ${MONITOR} --send-only"
+ echo "$@" | ${command} > /dev/null 2>&1
}
sanity_check() {
@@ -47,19 +51,22 @@ start() {
return 1;
}
- mkdir -p $(dirname ${PIDFILE}) $(dirname ${MONITOR})
+ mkdir -p "${PIDFILE%/*}" "${MONITOR%/*}"
ebegin "creating qtap ${QTAP:-(auto allocating one)}"
- QTAP_RET=$(qtap-manipulate create ${QTAP} -u "${DROP_USER}");
- if [ 0 != $? ]; then
- eerror "failed to create qtap interface"
- return 1
+ if [ -n "$QTAP" ]; then
+ qtap-manipulate create_specific "${QTAP}" -u "${DROP_USER}"
+ else
+ QTAP=$(qtap-manipulate create -u "${DROP_USER}")
+ if [ 0 != $? ]; then
+ eerror "failed to create qtap interface"
+ return 1
+ fi
fi
- 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##*/} for ${VMNAME} at VNC port${VNC}"
+ start-stop-daemon --start "${VMSOFTWARE}" \
--pidfile ${PIDFILE} \
-- -daemonize -pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait \
-runas ${DROP_USER} -name ${VMNAME} \
@@ -94,21 +101,36 @@ stop() {
eend $?
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}
+ local pid
+ [ -s "${PIDFILE}" ] && pid=$(cat "${PIDFILE}")
+ if [ -z "$pid" ]; then
+ eerror "Couldn't find stored pid at '$PIDFILE'; user will have to manually kill kvm"
+ eerror "Will attempt to destroy qtap despite."
+ eend 1
+ else
+ local ret=1
+ for x in $(seq 0 ${TIMEOUT:-60}); do
+ if kill -0 "${pid}" > /dev/null 2>&1; then
+ sleep 1s
+ continue
+ fi
+ ret=0
+ break
+ done
+ eend $ret
+ fi
- ebegin "Stopping ${VMSOFTWARE-qemu} for ${VMNAME}"
- start-stop-daemon --stop /usr/bin/${VMSOFTWARE-qemu} \
- --user ${DROP_USER} \
- --pidfile ${PIDFILE} \
+ ebegin "Stopping ${VMSOFTWARE##*/} for ${VMNAME}"
+ start-stop-daemon --stop "${VMSOFTWARE}" \
+ --user "${DROP_USER}" \
+ --pidfile "${PIDFILE}" \
--quiet
eend $?
- QTAP=$(cat ${QTAP_FILE})
- ebegin "destroying qtap ${QTAP}"
- qtap-manipulate destroy ${QTAP}
- eend $?
+ local qtap
+ [ -s "${QTAP_FILE}" ] && qtap=$(cat "${QTAP_FILE}")
+ if [ -n "$qtap" ]; then
+ ebegin "destroying qtap ${qtap}"
+ qtap-manipulate destroy ${qtap}
+ eend $?
+ fi
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [gentoo-commits] proj/kvm-tools:master commit in: /
@ 2012-04-14 6:26 Brian Harring
0 siblings, 0 replies; 8+ messages in thread
From: Brian Harring @ 2012-04-14 6:26 UTC (permalink / raw
To: gentoo-commits
commit: b303558ddc795624f3dabc9639e76465ea0d43dd
Author: Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Sat Apr 14 04:33:05 2012 +0000
Commit: Brian Harring <ferringb <AT> gentoo <DOT> org>
CommitDate: Sat Apr 14 06:19:50 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=b303558d
qtap-manipulate: Handle ifconfig appending of ':' to the iface name.
---
qtap-manipulate | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/qtap-manipulate b/qtap-manipulate
index 7e1ec53..09727ec 100755
--- a/qtap-manipulate
+++ b/qtap-manipulate
@@ -11,6 +11,8 @@ has() {
find_available_node() {
local val=$(ifconfig -a | grep -i ^qtap | cut -d ' ' -f1)
+ # Strip off ifconfig appended ':'
+ val="${val%:}"
local pos=0
while has qtap${pos} $val; do
pos=$(( $pos + 1 ))
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-04-14 6:27 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-14 6:26 [gentoo-commits] proj/kvm-tools:master commit in: / Brian Harring
-- strict thread matches above, loose matches on Subject: below --
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:46 Richard Yao
2012-03-17 20:44 Richard Yao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox