Gentoo Archives: gentoo-commits

From: Brian Harring <ferringb@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/kvm-tools:master commit in: app-emulation/qemu-init-scripts/files/
Date: Fri, 24 Aug 2012 04:19:25
Message-Id: 1334447278.31456f30cea2efd5246da9185cbce28e15024cd4.ferringb@gentoo
1 commit: 31456f30cea2efd5246da9185cbce28e15024cd4
2 Author: Brian Harring <ferringb <AT> chromium <DOT> org>
3 AuthorDate: Sat Apr 14 20:58:08 2012 +0000
4 Commit: Brian Harring <ferringb <AT> gentoo <DOT> org>
5 CommitDate: Sat Apr 14 23:47:58 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/kvm-tools.git;a=commit;h=31456f30
7
8 Make networking a bit more configurable via NIC_TYPE.
9
10 This can be:
11
12 None
13 No networking at all.
14
15 br
16 bridge mode; NIC_NET_DEPS if set is the networking needed.
17
18 nat
19 Qemu user stack; NIC model is honored, but qemu itself spins up
20 a dhcp server and nats connections out on it's own. For most users
21 this is likely what they'll be using- thus this is now the default.
22
23 ---
24 .../qemu-init-scripts/files/qemu-init-script | 50 ++++++++++++++------
25 1 files changed, 36 insertions(+), 14 deletions(-)
26
27 diff --git a/app-emulation/qemu-init-scripts/files/qemu-init-script b/app-emulation/qemu-init-scripts/files/qemu-init-script
28 index 0fbfec4..23b12ef 100644
29 --- a/app-emulation/qemu-init-scripts/files/qemu-init-script
30 +++ b/app-emulation/qemu-init-scripts/files/qemu-init-script
31 @@ -42,7 +42,17 @@ export KVM_USER=${KVM_USER:-"root"}
32 extra_commands="reboot"
33
34 depend() {
35 - need net.br0
36 + if [ "$VMNAME" = "$SVCNAME" ]; then
37 + return 0
38 + fi
39 +
40 + sanity_check || return 1
41 +
42 + case "$NIC_TYPE" in
43 + br)
44 + need ${NIC_NET_DEPS-net.br0}
45 + ;;
46 + esac
47 }
48
49 send_command() {
50 @@ -57,12 +67,14 @@ sanity_check() {
51 eerror " ln -s vm /etc/init.d/vm.vmname"
52 return 1
53 fi
54 +
55 DISKIMAGE=$(readlink -f "${DISKIMAGE}")
56 if [ ! -f "${DISKIMAGE}" -a ! -b "${DISKIMAGE}" ]; then
57 eerror "couldn't find \$DISKIMAGE '$DISKIMAGE'"
58 return 1;
59 fi
60 discern_vm_binary
61 + NIC_TYPE=${NIC_TYPE:-nat}
62 }
63
64 start_pre() {
65 @@ -70,22 +82,30 @@ start_pre() {
66 "${MONITOR%/*}"
67 }
68
69 -
70 start() {
71 sanity_check || return 1
72
73 - ebegin "creating qtap ${QTAP:-(auto allocating one)}"
74 - if [ -n "$QTAP" ]; then
75 - qtap-manipulate create_specific "${QTAP}" -u "${DROP_USER}"
76 - else
77 - QTAP=$(qtap-manipulate create -u "${DROP_USER}")
78 - if [ 0 != $? ]; then
79 - eerror "failed to create qtap interface"
80 - return 1
81 + local NIC_COMMAND=( -net "nic,model=${NIC_MODEL:-virtio},macaddr=${MACADDR}" -net )
82 +
83 + if [ "${NIC_TYPE}" = "br" ]; then
84 + ebegin "creating qtap ${QTAP:-(auto allocating one)}"
85 + if [ -n "$QTAP" ]; then
86 + qtap-manipulate create_specific "${QTAP}" -u "${DROP_USER}"
87 + else
88 + QTAP=$(qtap-manipulate create -u "${DROP_USER}")
89 + if [ 0 != $? ]; then
90 + eerror "failed to create qtap interface"
91 + return 1
92 + fi
93 fi
94 + echo "${QTAP}" > ${QTAP_FILE}
95 + eend $?
96 + NIC_COMMAND[${#NIC_COMMAND[@]}]="tap,ifname=${QTAP},script=no"
97 + elif [ "${NIC_TYPE}" = "none" ]; then
98 + NIC_COMMAND=( -net none )
99 + else
100 + NIC_COMMAND[${#NIC_COMMAND[@]}]=user
101 fi
102 - echo "${QTAP}" > ${QTAP_FILE}
103 - eend $?
104
105 ebegin "Starting ${VM_BINARY##*/} for ${VMNAME} at VNC port${VNC}"
106 start-stop-daemon --start "${VM_BINARY}" \
107 @@ -93,13 +113,15 @@ start() {
108 -- -daemonize -pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait \
109 -runas ${DROP_USER} -name ${VMNAME} \
110 -drive file="$DISKIMAGE",if=${DRIVE_MODEL:-virtio},cache=${DRIVE_CACHE:-none} \
111 - -net nic,model=${NIC_MODEL:-virtio},macaddr=${MACADDR} -net tap,ifname=${QTAP},script=no \
112 + "${NIC_COMMAND[@]}" \
113 ${DISABLE_KVM:---enable-kvm} \
114 ${MEMORY:+-m ${MEMORY}} ${SMP:+-smp ${SMP}} ${VNC:+-vnc ${VNC}} ${OTHER_ARGS}
115 ret=$?
116 - if [ "0" != "${ret}" ]; then
117 +
118 + if [ "0" != "${ret}" -a -n "${QTAP}" ]; then
119 qtap-manipulate destroy ${QTAP}
120 fi
121 +
122 eend ${ret}
123 }