public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Harring" <ferringb@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/kvm-tools:ferringb commit in: app-emulation/qemu-init-scripts/files/
Date: Sat, 14 Apr 2012 23:48:07 +0000 (UTC)	[thread overview]
Message-ID: <1334447278.31456f30cea2efd5246da9185cbce28e15024cd4.ferringb@gentoo> (raw)
Message-ID: <20120414234807.ImfU2oaTGQ1xQ2LrJ1Wn2qnai-4vmokMJUYR315wPXc@z> (raw)

commit:     31456f30cea2efd5246da9185cbce28e15024cd4
Author:     Brian Harring <ferringb <AT> chromium <DOT> org>
AuthorDate: Sat Apr 14 20:58:08 2012 +0000
Commit:     Brian Harring <ferringb <AT> gentoo <DOT> org>
CommitDate: Sat Apr 14 23:47:58 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=31456f30

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.

---
 .../qemu-init-scripts/files/qemu-init-script       |   50 ++++++++++++++------
 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}
 }
 



             reply	other threads:[~2012-04-14 23:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-24  4:18 Brian Harring [this message]
2012-04-14 23:48 ` [gentoo-commits] proj/kvm-tools:ferringb commit in: app-emulation/qemu-init-scripts/files/ Brian Harring
  -- strict thread matches above, loose matches on Subject: below --
2016-03-23 17:55 [gentoo-commits] proj/kvm-tools:master " Brian Dolbec
2016-03-22 23:38 Brian Dolbec
2016-03-22 23:38 Brian Dolbec
2016-03-22 23:38 Brian Dolbec
2016-03-22 23:38 Brian Dolbec
2016-03-22 23:38 Brian Dolbec
2016-03-22 23:38 Brian Dolbec
2016-02-03 22:27 Rafael Martins
2016-02-03 22:27 Rafael Martins
2013-11-16  4:21 Brian Dolbec
2013-11-16  4:21 Brian Dolbec
2013-11-16  4:21 Brian Dolbec
2013-11-16  4:21 Brian Dolbec
2012-08-24  4:18 Brian Harring
2012-08-24  4:18 Brian Harring
2012-08-24  4:18 Brian Harring
2012-08-24  4:18 Brian Harring
2012-04-14 23:48 [gentoo-commits] proj/kvm-tools:ferringb " Brian Harring
2012-08-24  4:18 ` [gentoo-commits] proj/kvm-tools:master " Brian Harring

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=1334447278.31456f30cea2efd5246da9185cbce28e15024cd4.ferringb@gentoo \
    --to=ferringb@gentoo.org \
    --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