diff options
author | Joshua Watt <jpewhacker@gmail.com> | 2020-01-08 13:48:07 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-01-10 21:18:23 +0000 |
commit | 08220028e52992dcba667fc97bf3afe8be1949fb (patch) | |
tree | 50a373bfc238ba505d7f9f3c71091f8cc94a34d2 | |
parent | 1128c128ce64f5e7f5f0f0f83471d61d91d48cca (diff) | |
download | poky-08220028e52992dcba667fc97bf3afe8be1949fb.tar.gz |
runqemu: Add network bridge support
Qemu supports attaching the virtual machine to an existing network
bridge interface via the qemu-bridge-helper program (as long as the
system is correctly configured to give the user permissions). Add
support for runqemu to do this also via the "bridge=<INTERFACE>"
argument. Note that for this to work correctly, the host
qemu-bridge-helper must be used, not the one that might have been built
by qemu-native. In order for qemu to correctly find this program, a
qemu-oe-bridge-helper program has been added to qemu-helper-native, and
runqemu will use this helper as the bridge helper. The helper will look
for the host qemu-bridge-helper first by looking in the
QEMU_BRIDGE_HELPER environment variable, then by search common paths
where the helper is installed.
(From OE-Core rev: 9e7b38c61c6b84b7f137c733ac5da9414025693d)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb | 7 | ||||
-rwxr-xr-x | meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper | 25 | ||||
-rwxr-xr-x | scripts/runqemu | 13 |
3 files changed, 42 insertions, 3 deletions
diff --git a/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb b/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb index 372eebd886..2fc07669dd 100644 --- a/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb +++ b/meta/recipes-devtools/qemu/qemu-helper-native_1.0.bb | |||
@@ -5,7 +5,10 @@ PR = "r1" | |||
5 | 5 | ||
6 | LIC_FILES_CHKSUM = "file://${WORKDIR}/tunctl.c;endline=4;md5=ff3a09996bc5fff6bc5d4e0b4c28f999" | 6 | LIC_FILES_CHKSUM = "file://${WORKDIR}/tunctl.c;endline=4;md5=ff3a09996bc5fff6bc5d4e0b4c28f999" |
7 | 7 | ||
8 | SRC_URI = "file://tunctl.c" | 8 | SRC_URI = "\ |
9 | file://tunctl.c \ | ||
10 | file://qemu-oe-bridge-helper \ | ||
11 | " | ||
9 | 12 | ||
10 | S = "${WORKDIR}" | 13 | S = "${WORKDIR}" |
11 | 14 | ||
@@ -18,6 +21,8 @@ do_compile() { | |||
18 | do_install() { | 21 | do_install() { |
19 | install -d ${D}${bindir} | 22 | install -d ${D}${bindir} |
20 | install tunctl ${D}${bindir}/ | 23 | install tunctl ${D}${bindir}/ |
24 | |||
25 | install -m 755 ${WORKDIR}/qemu-oe-bridge-helper ${D}${bindir}/ | ||
21 | } | 26 | } |
22 | 27 | ||
23 | DEPENDS += "qemu-system-native" | 28 | DEPENDS += "qemu-system-native" |
diff --git a/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper b/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper new file mode 100755 index 0000000000..f057d4eef0 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper | |||
@@ -0,0 +1,25 @@ | |||
1 | #! /bin/sh | ||
2 | # Copyright 2020 Garmin Ltd. or its subsidiaries | ||
3 | # | ||
4 | # SPDX-License-Identifier: GPL-2.0 | ||
5 | # | ||
6 | # Attempts to find and exec the host qemu-bridge-helper program | ||
7 | |||
8 | # If the QEMU_BRIDGE_HELPER variable is set by the user, exec it. | ||
9 | if [ -n "$QEMU_BRIDGE_HELPER" ]; then | ||
10 | exec "$QEMU_BRIDGE_HELPER" "$@" | ||
11 | fi | ||
12 | |||
13 | # Search common paths for the helper program | ||
14 | BN="qemu-bridge-helper" | ||
15 | PATHS="/usr/libexec/ /usr/lib/qemu/" | ||
16 | |||
17 | for p in $PATHS; do | ||
18 | if [ -e "$p/$BN" ]; then | ||
19 | exec "$p/$BN" "$@" | ||
20 | fi | ||
21 | done | ||
22 | |||
23 | echo "$BN not found!" > /dev/stderr | ||
24 | exit 1 | ||
25 | |||
diff --git a/scripts/runqemu b/scripts/runqemu index c324982e8a..dd0aa4b28f 100755 --- a/scripts/runqemu +++ b/scripts/runqemu | |||
@@ -165,6 +165,7 @@ class BaseConfig(object): | |||
165 | self.kvm_enabled = False | 165 | self.kvm_enabled = False |
166 | self.vhost_enabled = False | 166 | self.vhost_enabled = False |
167 | self.slirp_enabled = False | 167 | self.slirp_enabled = False |
168 | self.net_bridge = None | ||
168 | self.nfs_instance = 0 | 169 | self.nfs_instance = 0 |
169 | self.nfs_running = False | 170 | self.nfs_running = False |
170 | self.serialconsole = False | 171 | self.serialconsole = False |
@@ -485,6 +486,8 @@ class BaseConfig(object): | |||
485 | self.vhost_enabled = True | 486 | self.vhost_enabled = True |
486 | elif arg == 'slirp': | 487 | elif arg == 'slirp': |
487 | self.slirp_enabled = True | 488 | self.slirp_enabled = True |
489 | elif arg.startswith('bridge='): | ||
490 | self.net_bridge = '%s' % arg[len('bridge='):] | ||
488 | elif arg == 'snapshot': | 491 | elif arg == 'snapshot': |
489 | self.snapshot = True | 492 | self.snapshot = True |
490 | elif arg == 'publicvnc': | 493 | elif arg == 'publicvnc': |
@@ -802,7 +805,7 @@ class BaseConfig(object): | |||
802 | def check_and_set(self): | 805 | def check_and_set(self): |
803 | """Check configs sanity and set when needed""" | 806 | """Check configs sanity and set when needed""" |
804 | self.validate_paths() | 807 | self.validate_paths() |
805 | if not self.slirp_enabled: | 808 | if not self.slirp_enabled and not self.net_bridge: |
806 | check_tun() | 809 | check_tun() |
807 | # Check audio | 810 | # Check audio |
808 | if self.audio_enabled: | 811 | if self.audio_enabled: |
@@ -1020,6 +1023,10 @@ class BaseConfig(object): | |||
1020 | 1023 | ||
1021 | self.nfs_running = True | 1024 | self.nfs_running = True |
1022 | 1025 | ||
1026 | def setup_net_bridge(self): | ||
1027 | self.set('NETWORK_CMD', '-netdev bridge,br=%s,id=net0,helper=%s -device virtio-net-pci,netdev=net0 ' % ( | ||
1028 | self.net_bridge, os.path.join(self.bindir_native, 'qemu-oe-bridge-helper'))) | ||
1029 | |||
1023 | def setup_slirp(self): | 1030 | def setup_slirp(self): |
1024 | """Setup user networking""" | 1031 | """Setup user networking""" |
1025 | 1032 | ||
@@ -1161,7 +1168,9 @@ class BaseConfig(object): | |||
1161 | if sys.stdin.isatty(): | 1168 | if sys.stdin.isatty(): |
1162 | self.saved_stty = subprocess.check_output(("stty", "-g")).decode('utf-8').strip() | 1169 | self.saved_stty = subprocess.check_output(("stty", "-g")).decode('utf-8').strip() |
1163 | self.network_device = self.get('QB_NETWORK_DEVICE') or self.network_device | 1170 | self.network_device = self.get('QB_NETWORK_DEVICE') or self.network_device |
1164 | if self.slirp_enabled: | 1171 | if self.net_bridge: |
1172 | self.setup_net_bridge() | ||
1173 | elif self.slirp_enabled: | ||
1165 | self.setup_slirp() | 1174 | self.setup_slirp() |
1166 | else: | 1175 | else: |
1167 | self.setup_tap() | 1176 | self.setup_tap() |