summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@chromium.org>2012-04-14 13:58:08 -0700
committerBrian Harring <ferringb@chromium.org>2012-04-14 16:47:58 -0700
commit31456f30cea2efd5246da9185cbce28e15024cd4 (patch)
tree6ec64b3f0c4ddab7e20568162d064cec92cf7539
parentreadlink -f DISKIMAGE earlier, and start better using openrc capabilties. (diff)
downloadkvm-tools-31456f30cea2efd5246da9185cbce28e15024cd4.tar.gz
kvm-tools-31456f30cea2efd5246da9185cbce28e15024cd4.tar.bz2
kvm-tools-31456f30cea2efd5246da9185cbce28e15024cd4.zip
Make networking a bit more configurable via NIC_TYPE.
This can be: None No networking at all. br bridge mode; NIC_NET_DEPS if set is the networking needed. nat Qemu user stack; NIC model is honored, but qemu itself spins up a dhcp server and nats connections out on it's own. For most users this is likely what they'll be using- thus this is now the default.
-rw-r--r--app-emulation/qemu-init-scripts/files/qemu-init-script50
1 files changed, 36 insertions, 14 deletions
diff --git a/app-emulation/qemu-init-scripts/files/qemu-init-script b/app-emulation/qemu-init-scripts/files/qemu-init-script
index 0fbfec4..23b12ef 100644
--- a/app-emulation/qemu-init-scripts/files/qemu-init-script
+++ b/app-emulation/qemu-init-scripts/files/qemu-init-script
@@ -42,7 +42,17 @@ export KVM_USER=${KVM_USER:-"root"}
extra_commands="reboot"
depend() {
- need net.br0
+ if [ "$VMNAME" = "$SVCNAME" ]; then
+ return 0
+ fi
+
+ sanity_check || return 1
+
+ case "$NIC_TYPE" in
+ br)
+ need ${NIC_NET_DEPS-net.br0}
+ ;;
+ esac
}
send_command() {
@@ -57,12 +67,14 @@ sanity_check() {
eerror " ln -s vm /etc/init.d/vm.vmname"
return 1
fi
+
DISKIMAGE=$(readlink -f "${DISKIMAGE}")
if [ ! -f "${DISKIMAGE}" -a ! -b "${DISKIMAGE}" ]; then
eerror "couldn't find \$DISKIMAGE '$DISKIMAGE'"
return 1;
fi
discern_vm_binary
+ NIC_TYPE=${NIC_TYPE:-nat}
}
start_pre() {
@@ -70,22 +82,30 @@ start_pre() {
"${MONITOR%/*}"
}
-
start() {
sanity_check || return 1
- ebegin "creating qtap ${QTAP:-(auto allocating one)}"
- 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
+ local NIC_COMMAND=( -net "nic,model=${NIC_MODEL:-virtio},macaddr=${MACADDR}" -net )
+
+ if [ "${NIC_TYPE}" = "br" ]; then
+ ebegin "creating qtap ${QTAP:-(auto allocating one)}"
+ 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
+ echo "${QTAP}" > ${QTAP_FILE}
+ eend $?
+ NIC_COMMAND[${#NIC_COMMAND[@]}]="tap,ifname=${QTAP},script=no"
+ elif [ "${NIC_TYPE}" = "none" ]; then
+ NIC_COMMAND=( -net none )
+ else
+ NIC_COMMAND[${#NIC_COMMAND[@]}]=user
fi
- echo "${QTAP}" > ${QTAP_FILE}
- eend $?
ebegin "Starting ${VM_BINARY##*/} for ${VMNAME} at VNC port${VNC}"
start-stop-daemon --start "${VM_BINARY}" \
@@ -93,13 +113,15 @@ start() {
-- -daemonize -pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait \
-runas ${DROP_USER} -name ${VMNAME} \
-drive file="$DISKIMAGE",if=${DRIVE_MODEL:-virtio},cache=${DRIVE_CACHE:-none} \
- -net nic,model=${NIC_MODEL:-virtio},macaddr=${MACADDR} -net tap,ifname=${QTAP},script=no \
+ "${NIC_COMMAND[@]}" \
${DISABLE_KVM:---enable-kvm} \
${MEMORY:+-m ${MEMORY}} ${SMP:+-smp ${SMP}} ${VNC:+-vnc ${VNC}} ${OTHER_ARGS}
ret=$?
- if [ "0" != "${ret}" ]; then
+
+ if [ "0" != "${ret}" -a -n "${QTAP}" ]; then
qtap-manipulate destroy ${QTAP}
fi
+
eend ${ret}
}