runqemu: fix for slirp, network device and hostfwd
v2 cover runqemu: fix for slirp, network device and hostfwd
* V2
- Add QB_NETWORK_DEVICE to set network device for both slirp and tap, the idea is from Randy and Nathan.
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.
* V1
- Initial version
The following changes since commit 11063a01d4511b2688ea7ba2d7359e4e07328c66:
ruby: upgrade to 2.3.1 (2016-11-30 15:47:17 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib rbt/runqemu
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in comments
meta/classes/qemuboot.bbclass | 34 ++++++-- meta/conf/machine/include/qemuboot-x86.inc | 1 - meta/conf/machine/qemuarm64.conf | 1 - scripts/runqemu | 133 ++++++++++++++++++++++------- scripts/runqemu-export-rootfs | 21 ++--- 5 files changed, 140 insertions(+), 50 deletions(-)
Signature · 1 line
2.9.0
PATCH v2 1/6 scripts/runqemu: fix checking for <file>.cpio.gz
When "runqemu /path/to/<file>.cpio.gz", it used the last suffix "gz" as the fstype which was wrong. Check filename against self.fstypes firstly can fix the problem.
--- scripts/runqemu | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
scripts/runqemu +16 -6
@@ -269,19 +269,29 @@ class BaseConfig(object): self.kernel = p elif os.path.exists(p) and (not os.path.isdir(p)) and re.search('-image-', os.path.basename(p)): self.rootfs = p - dirpath = os.path.dirname(p) - m = re.search('(.*)\.(.*)$', p) - if m: - qb = '%s%s' % (re.sub('\.rootfs$', '', m.group(1)), '.qemuboot.conf') + # Check filename against self.fstypes can hanlde <file>.cpio.gz, + # otherwise, its type would be "gz", which is incorrect. + fst = "" + for t in self.fstypes: + if p.endswith(t): + fst = t + break + if not fst: + m = re.search('.*\.(.*)$', self.rootfs) + if m: + fst = m.group(1) + if fst: + self.check_arg_fstype(fst) + qb = re.sub('\.' + fst + "$", '', self.rootfs) + qb = '%s%s' % (re.sub('\.rootfs$', '', qb), '.qemuboot.conf') if os.path.exists(qb): self.qemuboot = qb self.qbconfload = True else: logger.warn("%s doesn't exist" % qb) - fst = m.group(2) - self.check_arg_fstype(fst) else: raise Exception("Can't find FSTYPE from: %s" % p) + elif os.path.isdir(p) or re.search(':', arg) and re.search('/', arg): if self.is_deploy_dir_image(p): logger.info('DEPLOY_DIR_IMAGE: %s' % p)
Signature · 1 line
2.9.0
PATCH v2 2/6 qemuboot.bbclass: use IMGDEPLOYDIR
In reply to Robert YangSo that "bitbake <image> -ccleansstate" can remove qemuboot.conf
--- meta/classes/qemuboot.bbclass | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
meta/classes/qemuboot.bbclass +3 -2
@@ -43,6 +43,7 @@ QB_OPT_APPEND ?= "-show-cursor" # Create qemuboot.conf addtask do_write_qemuboot_conf after do_rootfs before do_image +IMGDEPLOYDIR ?= "${WORKDIR}/deploy-${PN}-image-complete" def qemuboot_vars(d): build_vars = ['MACHINE', 'TUNE_ARCH', 'DEPLOY_DIR_IMAGE',
@@ -55,8 +56,8 @@ do_write_qemuboot_conf[vardeps] += "${@' '.join(qemuboot_vars(d))}" python do_write_qemuboot_conf() { import configparser - qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('DEPLOY_DIR_IMAGE', True), d.getVar('IMAGE_NAME', True)) - qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('DEPLOY_DIR_IMAGE', True), d.getVar('IMAGE_LINK_NAME', True)) + qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR', True), d.getVar('IMAGE_NAME', True)) + qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR', True), d.getVar('IMAGE_LINK_NAME', True)) cf = configparser.ConfigParser() cf.add_section('config_bsp') for k in qemuboot_vars(d):
Signature · 1 line
2.9.0
PATCH v2 3/6 runqemu-export-rootfs: fix inconsistent var names
In reply to Robert YangFixed:
$ runqemu nfs qemux86-64 [snip] On your target please remember to add the following options for NFS nfsroot=IP_ADDRESS:/path/to/nfsroot,nfsvers=3,port=,mountprog=,nfsprog=,udp,mountport= [snip]
Note that the values are null, this is because their var names are inconsistent.
[YOCTO #10519]
--- scripts/runqemu-export-rootfs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
scripts/runqemu-export-rootfs +9 -12
@@ -78,23 +78,17 @@ if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then fi # rpc.mountd RPC port -NFS_MOUNTPROG=$[ 21111 + $NFS_INSTANCE ] +MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ] # rpc.nfsd RPC port -NFS_NFSPROG=$[ 11111 + $NFS_INSTANCE ] -# NFS port number -NFS_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] +NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ] +# NFS server port number +NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] # mountd port number -MOUNT_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] +MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] ## For debugging you would additionally add ## --debug all -UNFSD_OPTS="-p -N -i $NFSPID -e $EXPORTS -x $NFS_NFSPROG -n $NFS_PORT -y $NFS_MOUNTPROG -m $MOUNT_PORT" - -# Setup the exports file -if [ "$1" = "start" ]; then - echo "Creating exports file..." - echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS -fi +UNFSD_OPTS="-p -N -i $NFSPID -e $EXPORTS -x $NFSD_RPCPORT -n $NFSD_PORT -y $MOUNTD_RPCPORT -m $MOUNTD_PORT" # See how we were called. case "$1" in
@@ -114,6 +108,9 @@ case "$1" in exit 1 fi + echo "Creating exports file..." + echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS + echo "Starting User Mode nfsd" echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS" $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS
Signature · 1 line
2.9.0
PATCH v2 4/6 runqemu: support mutiple qemus running when nfs
In reply to Robert YangFixed:
* In build1:
$ runqemu nfs qemux86-64 In build2: $ runqemu nfs qemux86-64
It would fail before since the port numerbs and conf files are conflicted, now make runqemu-export-rootfs work together with runqemu to fix the problem.
* And we don't need export PSEUDO_LOCALSTATEDIR in runqemu, the runqemu-export-rootfs can handle it well based on NFS_EXPORT_DIR.
* Remove "async" option from unfsd to fix warning in syslog:
Warning: unknown exports option `async' ignored
* Fixed typos
Both slirp and tap can work.
--- scripts/runqemu | 55 ++++++++++++++++++++++++++++--------------- scripts/runqemu-export-rootfs | 10 ++++---- 2 files changed, 41 insertions(+), 24 deletions(-)
scripts/runqemu +36 -19
@@ -690,17 +690,33 @@ class BaseConfig(object): else: self.nfs_server = '192.168.7.1' - nfs_instance = int(self.nfs_instance) - - mountd_rpcport = 21111 + nfs_instance - nfsd_rpcport = 11111 + nfs_instance - nfsd_port = 3049 + 2 * nfs_instance - mountd_port = 3048 + 2 * nfs_instance - unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port) - self.unfs_opts = unfs_opts + # Figure out a new nfs_instance to allow multiple qemus running. + cmd = "ps aux" + ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8') + pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) ' + all_instances = re.findall(pattern, ps, re.M) + if all_instances: + all_instances.sort(key=int) + self.nfs_instance = int(all_instances.pop()) + 1 + + mountd_rpcport = 21111 + self.nfs_instance + nfsd_rpcport = 11111 + self.nfs_instance + nfsd_port = 3049 + 2 * self.nfs_instance + mountd_port = 3048 + 2 * self.nfs_instance + + # Export vars for runqemu-export-rootfs + export_dict = { + 'NFS_INSTANCE': self.nfs_instance, + 'MOUNTD_RPCPORT': mountd_rpcport, + 'NFSD_RPCPORT': nfsd_rpcport, + 'NFSD_PORT': nfsd_port, + 'MOUNTD_PORT': mountd_port, + } + for k, v in export_dict.items(): + # Use '%s' since they are integers + os.putenv(k, '%s' % v) - p = '%s/.runqemu-sdk/pseudo' % os.getenv('HOME') - os.putenv('PSEUDO_LOCALSTATEDIR', p) + self.unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port) # Extract .tar.bz2 or .tar.bz if no self.nfs_dir if not self.nfs_dir:
@@ -728,7 +744,7 @@ class BaseConfig(object): self.nfs_dir = dest # Start the userspace NFS server - cmd = 'runqemu-export-rootfs restart %s' % self.nfs_dir + cmd = 'runqemu-export-rootfs start %s' % self.nfs_dir logger.info('Running %s...' % cmd) if subprocess.call(cmd, shell=True) != 0: raise Exception('Failed to run %s' % cmd)
@@ -737,6 +753,8 @@ class BaseConfig(object): def setup_slirp(self): + """Setup user networking""" + if self.fstype == 'nfs': self.setup_nfs() self.kernel_cmdline_script += ' ip=dhcp'
@@ -804,14 +822,13 @@ class BaseConfig(object): logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") return 1 self.tap = tap - n0 = tap[3:] - n1 = int(n0) * 2 + 1 - n2 = n1 + 1 - self.nfs_instance = n0 + tapnum = int(tap[3:]) + gateway = tapnum * 2 + 1 + client = gateway + 1 if self.fstype == 'nfs': self.setup_nfs() - self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (n2, n1) - mac = "52:54:00:12:34:%02x" % n2 + self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (client, gateway) + mac = "52:54:00:12:34:%02x" % client qb_tap_opt = self.get('QB_TAP_OPT') if qb_tap_opt: qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap).replace('@MAC@', mac)
@@ -854,11 +871,11 @@ class BaseConfig(object): vm_drive = '-drive if=none,id=hd,file=%s,format=%s -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd' \ % (self.rootfs, rootfs_format) elif subprocess.call(cmd2, shell=True) == 0: - logger.info('Using scsi drive') + logger.info('Using ide drive') vm_drive = "%s,format=%s" % (self.rootfs, rootfs_format) else: logger.warn("Can't detect drive type %s" % self.rootfs) - logger.warn('Tring to use virtio block drive') + logger.warn('Trying to use virtio block drive') vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format) self.rootfs_options = '%s -no-reboot' % vm_drive self.kernel_cmdline = 'root=%s rw highres=off' % (self.get('QB_KERNEL_ROOT'))
scripts/runqemu-export-rootfs +5 -5
@@ -78,13 +78,13 @@ if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then fi # rpc.mountd RPC port -MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ] +MOUNTD_RPCPORT=${MOUNTD_RPCPORT:=$[ 21111 + $NFS_INSTANCE ]} # rpc.nfsd RPC port -NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ] +NFSD_RPCPORT=${NFSD_RPCPORT:=$[ 11111 + $NFS_INSTANCE ]} # NFS server port number -NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] +NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]} # mountd port number -MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] +MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]} ## For debugging you would additionally add ## --debug all
@@ -109,7 +109,7 @@ case "$1" in fi echo "Creating exports file..." - echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS + echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS echo "Starting User Mode nfsd" echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
Signature · 1 line
2.9.0
Re: [PATCH V2 4/6] runqemu: support mutiple qemus running when nfs
Quoted 34 lines · Robert Yang
Fixed:
* In build1:$ runqemu nfs qemux86-64 In build2: $ runqemu nfs qemux86-64It would fail before since the port numerbs and conf files are conflicted, now make runqemu-export-rootfs work together with runqemu to fix the problem.
* And we don't need export
PSEUDO_LOCALSTATEDIRin runqemu, the runqemu-export-rootfs can handle it well based onNFS_EXPORT_DIR.* Remove "async" option from unfsd to fix warning in syslog:
Warning: unknown exports option `async' ignored* Fixed typos
Both slirp and tap can work.
Signed-off-by Robert Yang <[email protected]>--- scripts/runqemu | 55 ++++++++++++++++++++++++++++--------------- scripts/runqemu-export-rootfs | 10 ++++---- 2 files changed, 41 insertions(+), 24 deletions(-)scripts/runqemu +0
-0@@ -690,17 +690,33 @@ class BaseConfig(object): else: self.nfs_server = '192.168.7.1'
scripts/runqemu class BaseConfig(object): · line 694
Quoted 10 lines
scripts/runqemu +2
-8- nfs_instance = int(self.nfs_instance) - - mountd_rpcport = 21111 + nfs_instance - nfsd_rpcport = 11111 + nfs_instance - nfsd_port = 3049 + 2 * nfs_instance - mountd_port = 3048 + 2 * nfs_instance - unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port) - self.unfs_opts = unfs_opts + # Figure out a new nfs_instance to allow multiple qemus running. + cmd = "ps aux"
Updated here a little in the repo.
+ # Figure out a new nfs_instance to allow multiple qemus running. + # CentOS 7.1's ps doesn't print full command line without "ww" + # when invoke by subprocess.Popen(). + cmd = "ps auxww"
// Robert
Quoted 114 lines
scripts/runqemu +34
-11+ ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8') + pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) ' + all_instances = re.findall(pattern, ps, re.M) + if all_instances: + all_instances.sort(key=int) + self.nfs_instance = int(all_instances.pop()) + 1 + + mountd_rpcport = 21111 + self.nfs_instance + nfsd_rpcport = 11111 + self.nfs_instance + nfsd_port = 3049 + 2 * self.nfs_instance + mountd_port = 3048 + 2 * self.nfs_instance + + # Export vars for runqemu-export-rootfs + export_dict = { + 'NFS_INSTANCE': self.nfs_instance, + 'MOUNTD_RPCPORT': mountd_rpcport, + 'NFSD_RPCPORT': nfsd_rpcport, + 'NFSD_PORT': nfsd_port, + 'MOUNTD_PORT': mountd_port, + } + for k, v in export_dict.items(): + # Use '%s' since they are integers + os.putenv(k, '%s' % v) - p = '%s/.runqemu-sdk/pseudo' % os.getenv('HOME') - os.putenv('PSEUDO_LOCALSTATEDIR', p) + self.unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port) # Extract .tar.bz2 or .tar.bz if no self.nfs_dir if not self.nfs_dir:@@ -728,7 +744,7 @@ class BaseConfig(object): self.nfs_dir = dest # Start the userspace NFS server - cmd = 'runqemu-export-rootfs restart %s' % self.nfs_dir + cmd = 'runqemu-export-rootfs start %s' % self.nfs_dir logger.info('Running %s...' % cmd) if subprocess.call(cmd, shell=True) != 0: raise Exception('Failed to run %s' % cmd)@@ -737,6 +753,8 @@ class BaseConfig(object): def setup_slirp(self): + """Setup user networking""" + if self.fstype == 'nfs': self.setup_nfs() self.kernel_cmdline_script += ' ip=dhcp'@@ -804,14 +822,13 @@ class BaseConfig(object): logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") return 1 self.tap = tap - n0 = tap[3:] - n1 = int(n0) * 2 + 1 - n2 = n1 + 1 - self.nfs_instance = n0 + tapnum = int(tap[3:]) + gateway = tapnum * 2 + 1 + client = gateway + 1 if self.fstype == 'nfs': self.setup_nfs() - self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (n2, n1) - mac = "52:54:00:12:34:%02x" % n2 + self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (client, gateway) + mac = "52:54:00:12:34:%02x" % client qb_tap_opt = self.get('QB_TAP_OPT') if qb_tap_opt: qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap).replace('@MAC@', mac)@@ -854,11 +871,11 @@ class BaseConfig(object): vm_drive = '-drive if=none,id=hd,file=%s,format=%s -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd' \ % (self.rootfs, rootfs_format) elif subprocess.call(cmd2, shell=True) == 0: - logger.info('Using scsi drive') + logger.info('Using ide drive') vm_drive = "%s,format=%s" % (self.rootfs, rootfs_format) else: logger.warn("Can't detect drive type %s" % self.rootfs) - logger.warn('Tring to use virtio block drive') + logger.warn('Trying to use virtio block drive') vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format) self.rootfs_options = '%s -no-reboot' % vm_drive self.kernel_cmdline = 'root=%s rw highres=off' % (self.get('QB_KERNEL_ROOT'))scripts/runqemu-export-rootfs +5
-5@@ -78,13 +78,13 @@ if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then fi # rpc.mountd RPC port -MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ] +MOUNTD_RPCPORT=${MOUNTD_RPCPORT:=$[ 21111 + $NFS_INSTANCE ]} # rpc.nfsd RPC port -NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ] +NFSD_RPCPORT=${NFSD_RPCPORT:=$[ 11111 + $NFS_INSTANCE ]} # NFS server port number -NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] +NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]} # mountd port number -MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] +MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]} ## For debugging you would additionally add ## --debug all@@ -109,7 +109,7 @@ case "$1" in fi echo "Creating exports file..." - echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS + echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS echo "Starting User Mode nfsd" echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
PATCH v2 5/6 runqemu: fixes for slirp, network device and hostfwd
In reply to Robert YangFixed:
- Add QB_NETWORK_DEVICE to set network device, it will be used by both slirp and tap.
- Set QB_NETWORK_DEVICE to "-device virtio-net-pci" in qemuboot.bbclass but runqemu will default to "-device e1000" when QB_NETWORK_DEVICE is not set, this is because oe-core's qemu targets support virtio-net-pci, but the one outside of oe-core may not, "-device e1000" is more common.
- Set hostfwd by default: 2222 -> 22, 2323 -> 23, and it will choose a usable port when the one like 222 is being used. This can avoid conflicts when multilib slirp qemus are running. We can forward more ports by default if needed, and bsp.conf can custom it.
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.
[YOCTO #7887]
--- meta/classes/qemuboot.bbclass | 11 ++++-- meta/conf/machine/include/qemuboot-x86.inc | 1 - meta/conf/machine/qemuarm64.conf | 1 - scripts/runqemu | 58 ++++++++++++++++++++++++++---- 4 files changed, 59 insertions(+), 12 deletions(-)
meta/classes/qemuboot.bbclass +8 -3
@@ -18,11 +18,15 @@ # QB_AUDIO_OPT: qemu audio option, e.g., "-soundhw ac97,es1370", used # when QB_AUDIO_DRV is set. # QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda +# QB_NETWORK_DEVICE: network device, e.g., "-device virtio-net-pci,netdev=net0,mac=@MAC@", +# it needs work with QB_TAP_OPT and QB_SLIRP_OPT. +# Note, runqemu will replace @MAC@ with a predefined mac, you can set +# a custom one, but that may cause conflicts when multiple qemus are +# running on the same host. # QB_TAP_OPT: netowrk option for 'tap' mode, e.g., -# "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no -device virtio-net-device,netdev=net0" +# "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no" # Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ... -# QB_SLIRP_OPT: network option for SLIRP mode, e.g., -# "-netdev user,id=net0 -device virtio-net-device,netdev=net0" +# QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0" # QB_ROOTFS_OPT: used as rootfs, e.g., # "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0" # Note, runqemu will replace "@ROOTFS@" with the one which is used, such as core-image-minimal-qemuarm64.ext4.
@@ -40,6 +44,7 @@ QB_SERIAL_OPT ?= "-serial mon:stdio -serial null" QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}" QB_DEFAULT_FSTYPE ?= "ext4" QB_OPT_APPEND ?= "-show-cursor" +QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@" # Create qemuboot.conf addtask do_write_qemuboot_conf after do_rootfs before do_image
meta/conf/machine/include/qemuboot-x86.inc +0 -1
@@ -13,4 +13,3 @@ QB_AUDIO_OPT = "-soundhw ac97,es1370" QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=640x480-32 oprofile.timer=1 uvesafb.task_timeout=-1" # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy QB_OPT_APPEND = "-vga vmware -show-cursor -usb -usbdevice tablet -device virtio-rng-pci" -QB_SLIRP_OPT = "-net nic,model=e1000 -net user,hostfwd=tcp::2222-:22"
meta/conf/machine/qemuarm64.conf +0 -1
@@ -18,7 +18,6 @@ QB_KERNEL_CMDLINE_APPEND = "console=ttyAMA0,38400" # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy QB_OPT_APPEND = "-show-cursor -device virtio-rng-pci -monitor null" QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no -device virtio-net-device,netdev=net0,mac=@MAC@" -QB_SLIRP_OPT = "-netdev user,id=net0 -device virtio-net-device,netdev=net0" QB_ROOTFS_OPT = "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0" QB_SERIAL_OPT = "-device virtio-serial-device -chardev null,id=virtcon -device virtconsole,chardev=virtcon" QB_TCPSERIAL_OPT = " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon"
scripts/runqemu +51 -7
105 lines not on this page · raw message
Signature · 1 line
2.9.0
Re: [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd
Quoted 19 lines
def setup_slirp(self): """Setup user networking""" if self.fstype == 'nfs': self.setup_nfs() self.kernel_cmdline_script += ' ip=dhcp'scripts/runqemu +11
-1- self.set('NETWORK_CMD', self.get('QB_SLIRP_OPT')) + # Port mapping + hostfwd = ",hostfwd=tcp::2222-:22,hostfwd=tcp::2323-:23" + qb_slirp_opt_default = "-netdev user,id=net0%s" % hostfwd + qb_slirp_opt = self.get('QB_SLIRP_OPT') or qb_slirp_opt_default + # Figure out the port + ports = re.findall('hostfwd=[^-]*:([0-9]+)-[^,-]*', qb_slirp_opt) + ports = [int(i) for i in ports] + mac = 2 + # Find a free port to avoid conflicts + for p in ports[:]: + p_new = p
scripts/runqemu class BaseConfig(object): · line 802
Quoted 10 lines
scripts/runqemu +10
-0+ while not check_free_port('localhost', p_new): + p_new += 1 + mac += 1 + while p_new in ports: + p_new += 1 + mac += 1 + if p != p_new: + ports.append(p_new) + qb_slirp_opt = re.sub(':%s-' % p, ':%s-' % p_new, qb_slirp_opt) + logger.info("Port forward changed: %s -> %s" % (p, p_new))
Regardless if the port is changed or not, so that things like tests have an easier time of figuring out the port mappings, would it be good add a flag that prints out the entire list of ports used, or always do it? i.e. "Port forwarding 2222:22 2333:23.... It's not necessary of course, you can always look at the command line and then check to see if anything is remapped. But that's a bit more work.
Quoted 2 lines
scripts/runqemu +2
-0+ mac = "%s%02x" % (self.mac_slirp, mac) + self.set('NETWORK_CMD', '%s %s' % (self.network_device.replace('@MAC@', mac), qb_slirp_opt))
Re: [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd
Quoted 29 lines · Randy Witt
Quoted 19 lines
def setup_slirp(self): """Setup user networking""" if self.fstype == 'nfs': self.setup_nfs() self.kernel_cmdline_script += ' ip=dhcp'scripts/runqemu +11
-1- self.set('NETWORK_CMD', self.get('QB_SLIRP_OPT')) + # Port mapping + hostfwd = ",hostfwd=tcp::2222-:22,hostfwd=tcp::2323-:23" + qb_slirp_opt_default = "-netdev user,id=net0%s" % hostfwd + qb_slirp_opt = self.get('QB_SLIRP_OPT') or qb_slirp_opt_default + # Figure out the port + ports = re.findall('hostfwd=[^-]*:([0-9]+)-[^,-]*', qb_slirp_opt) + ports = [int(i) for i in ports] + mac = 2 + # Find a free port to avoid conflicts + for p in ports[:]: + p_new = pscripts/runqemu class BaseConfig(object): · line 802
Quoted 10 lines
scripts/runqemu +10
-0+ while not check_free_port('localhost', p_new): + p_new += 1 + mac += 1 + while p_new in ports: + p_new += 1 + mac += 1 + if p != p_new: + ports.append(p_new) + qb_slirp_opt = re.sub(':%s-' % p, ':%s-' % p_new, qb_slirp_opt) + logger.info("Port forward changed: %s -> %s" % (p, p_new))
Quoted 4 lines
Regardless if the port is changed or not, so that things like tests have an easier time of figuring out the port mappings, would it be good add a flag that prints out the entire list of ports used, or always do it? i.e. "Port forwarding 2222:22 2333:23.... It's not necessary of course, you can always look at the
Thansk, make sense, I added the following lines:
+ # Print out port foward
+ hostfwd = re.findall('(hostfwd=[^,]*)', qb_slirp_opt)
+ if hostfwd:+ logger.info('Port forward: %s' % ' '.join(hostfwd))
Now print:
runqemu - INFO - Port forward: hostfwd=tcp::2222-:22 hostfwd=tcp::2323-:23
Updated in the repo:
git://git.openembedded.org/openembedded-core-contrib rbt/runqemu
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in comments
// Robert
Quoted 8 lines
command line and then check to see if anything is remapped. But that's a bit more work.
Quoted 3 lines
(quoted diff) +2
-0+ mac = "%s%02x" % (self.mac_slirp, mac) + self.set('NETWORK_CMD', '%s %s' %(
self.network_device.replace('@MAC@', mac),qb_slirp_opt))
PATCH v2 6/6 qemuboot.bbclass: add blank lines in comments
In reply to Robert YangAdd blank lines in comments to make it easy for readind and updating.
--- meta/classes/qemuboot.bbclass | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
meta/classes/qemuboot.bbclass +18 -0
@@ -3,34 +3,52 @@ # boot by runqemu: # # QB_SYSTEM_NAME: qemu name, e.g., "qemu-system-i386" +# # QB_OPT_APPEND: options to append to qemu, e.g., "-show-cursor" +# # QB_DEFAULT_KERNEL: default kernel to boot, e.g., "bzImage" +# # QB_DEFAULT_FSTYPE: default FSTYPE to boot, e.g., "ext4" +# # QB_MEM: memory, e.g., "-m 512" +# # QB_MACHINE: qemu machine, e.g., "-machine virt" +# # QB_CPU: qemu cpu, e.g., "-cpu qemu32" +# # QB_CPU_KVM: the similar to QB_CPU, but used when kvm, e.g., '-cpu kvm64', # set it when support kvm. +# # QB_KERNEL_CMDLINE_APPEND: options to append to kernel's -append # option, e.g., "console=ttyS0 console=tty" +# # QB_DTB: qemu dtb name +# # QB_AUDIO_DRV: qemu audio driver, e.g., "alsa", set it when support audio +# # QB_AUDIO_OPT: qemu audio option, e.g., "-soundhw ac97,es1370", used # when QB_AUDIO_DRV is set. +# # QB_KERNEL_ROOT: kernel's root, e.g., /dev/vda +# # QB_NETWORK_DEVICE: network device, e.g., "-device virtio-net-pci,netdev=net0,mac=@MAC@", # it needs work with QB_TAP_OPT and QB_SLIRP_OPT. # Note, runqemu will replace @MAC@ with a predefined mac, you can set # a custom one, but that may cause conflicts when multiple qemus are # running on the same host. +# # QB_TAP_OPT: netowrk option for 'tap' mode, e.g., # "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no" # Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ... +# # QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0" +# # QB_ROOTFS_OPT: used as rootfs, e.g., # "-drive id=disk0,file=@ROOTFS@,if=none,format=raw -device virtio-blk-device,drive=disk0" # Note, runqemu will replace "@ROOTFS@" with the one which is used, such as core-image-minimal-qemuarm64.ext4. +# # QB_SERIAL_OPT: serial port, e.g., "-serial mon:stdio" +# # QB_TCPSERIAL_OPT: tcp serial port option, e.g., # " -device virtio-serial-device -chardev socket,id=virtcon,port=@PORT@,host=127.0.0.1 -device virtconsole,chardev=virtcon" # Note, runqemu will replace "@PORT@" with the port number which is used.
Signature · 1 line
2.9.0
Quoted 3 lines · Robert Yang
* V2
- AddQB_NETWORK_DEVICEto set network device for both slirp and tap, the idea is from Randy and Nathan.
Add Randy and Nathan in the loop, I had added them in git send-email, but there were not in the CC list, look strange.
// Robert
Quoted 30 lines
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.
* V1
- Initial versionThe following changes since commit
11063a01d4511b2688ea7ba2d7359e4e07328c66:ruby: upgrade to 2.3.1 (2016-11-30 15:47:17 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contribrbt/runqemu
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemuRobert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in commentsmeta/classes/qemuboot.bbclass | 34 ++++++-- meta/conf/machine/include/qemuboot-x86.inc | 1 - meta/conf/machine/qemuarm64.conf | 1 - scripts/runqemu | 133 ++++++++++++++++++++++------- scripts/runqemu-export-rootfs | 21 ++--- 5 files changed, 140 insertions(+), 50 deletions(-)
Quoted 11 lines · Robert Yang
Quoted 4 lines · Robert Yang
* V2
- AddQB_NETWORK_DEVICEto set network device for both slirp and tap, the idea is from Randy and Nathan.Add Randy and Nathan in the loop, I had added them in git send-email, but there were not in the CC list, look strange.
Hi Robert
I tested the cpio.gz and network device parts of this series with the meta-xilinx qemu machines, they work well. Will implement the QB_NETWORK_DEVICE use in meta-xilinx once this series gets applied.
Thanks,
Nathan
Quoted 38 lines
// Robert
Quoted 33 lines
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.
* V1
- Initial versionThe following changes since commit
11063a01d4511b2688ea7ba2d7359e4e07328c66:ruby: upgrade to 2.3.1 (2016-11-30 15:47:17 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contribrbt/runqemuhttp://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in commentsmeta/classes/qemuboot.bbclass | 34 ++++++-- meta/conf/machine/include/qemuboot-x86.inc | 1 - meta/conf/machine/qemuarm64.conf | 1 - scripts/runqemu | 133 ++++++++++++++++++++++------- scripts/runqemu-export-rootfs | 21 ++--- 5 files changed, 140 insertions(+), 50 deletions(-)
Hi Ross,
I rebased in the repo:
git://git.openembedded.org/openembedded-core-contrib rbt/runqemu
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in comments
// Robert
Quoted 33 lines · Robert Yang
* V2
- AddQB_NETWORK_DEVICEto set network device for both slirp and tap, the idea is from Randy and Nathan.
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.* V1
- Initial versionThe following changes since commit
11063a01d4511b2688ea7ba2d7359e4e07328c66:ruby: upgrade to 2.3.1 (2016-11-30 15:47:17 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contribrbt/runqemu
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemuRobert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in commentsmeta/classes/qemuboot.bbclass | 34 ++++++-- meta/conf/machine/include/qemuboot-x86.inc | 1 - meta/conf/machine/qemuarm64.conf | 1 - scripts/runqemu | 133 ++++++++++++++++++++++------- scripts/runqemu-export-rootfs | 21 ++--- 5 files changed, 140 insertions(+), 50 deletions(-)
ping.
// Robert
Quoted 55 lines · Robert Yang
Hi Ross,
I rebased in the repo:
git://git.openembedded.org/openembedded-core-contribrbt/runqemuhttp://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in comments// Robert
Quoted 35 lines · Robert Yang
* V2
- AddQB_NETWORK_DEVICEto set network device for both slirp and tap, the idea is from Randy and Nathan.
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.* V1
- Initial versionThe following changes since commit
11063a01d4511b2688ea7ba2d7359e4e07328c66:ruby: upgrade to 2.3.1 (2016-11-30 15:47:17 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contribrbt/runqemuhttp://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in commentsmeta/classes/qemuboot.bbclass | 34 ++++++-- meta/conf/machine/include/qemuboot-x86.inc | 1 - meta/conf/machine/qemuarm64.conf | 1 - scripts/runqemu | 133 ++++++++++++++++++++++------- scripts/runqemu-export-rootfs | 21 ++--- 5 files changed, 140 insertions(+), 50 deletions(-)
Hi Robert,
I merged these into my staging branch but then the autobuilder failed in an interesting way:
Would that be related to your series, or is it a coincidence?
Ross
Quoted 68 lines · Robert Yang
ping.
// Robert
Quoted 61 lines · Robert Yang
Hi Ross,
I rebased in the repo:
git://git.openembedded.org/openembedded-core-contribrbt/runqemuhttp://cgit.openembedded.org/cgit.cgi/openembedded-core-cont
rib/log/?h=rbt/runqemuRobert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in comments// Robert
Quoted 39 lines · Robert Yang
* V2
- AddQB_NETWORK_DEVICEto set network device for both slirp and tap, the idea is from Randy and Nathan.
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.* V1
- Initial versionThe following changes since commit
11063a01d4511b2688ea7ba2d7359e4e07328c66:ruby: upgrade to 2.3.1 (2016-11-30 15:47:17 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contribrbt/runqemuhttp://cgit.openembedded.org/cgit.cgi/openembedded-core-cont
rib/log/?h=rbt/runqemuRobert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in commentsmeta/classes/qemuboot.bbclass | 34 ++++++-- meta/conf/machine/include/qemuboot-x86.inc | 1 - meta/conf/machine/qemuarm64.conf | 1 - scripts/runqemu | 133 ++++++++++++++++++++++------- scripts/runqemu-export-rootfs | 21 ++--- 5 files changed, 140 insertions(+), 50 deletions(-)
Hi Ross,
Sorry, my fault, something was wrong with qemuppc.conf, it should not set "-device virtio-net-pci,netdev=net0,mac=@MAC@" since it is already in QB_NETWORK_DEVICE.
Fixed in the repo:
git://git.openembedded.org/openembedded-core-contrib rbt/runqemu
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in comments
// Robert
Quoted 84 lines · Ross
Hi Robert,
I merged these into my staging branch but then the autobuilder failed in an interesting way:
Would that be related to your series, or is it a coincidence?
Ross
On 11 January 2017 at 01:47, Robert Yang <[email protected] <mailto:[email protected]>> wrote:
ping.
// Robert
On 12/21/2016 02:24 PM, Robert Yang wrote:
Hi Ross,
I rebased in the repo:
git://git.openembedded.org/openembedded-core-contrib
<http://git.openembedded.org/openembedded-core-contrib> rbt/runqemuhttp://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
<http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu>Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in comments// Robert
On 12/06/2016 04:55 PM, Robert Yang wrote:
* V2
- AddQB_NETWORK_DEVICEto set network device for both slirp and tap, the idea is from Randy and Nathan.
- Use different mac sections for slirp and tap to fix conflicts when running both of them on the same host.* V1
- Initial versionThe following changes since commit
11063a01d4511b2688ea7ba2d7359e4e07328c66:ruby: upgrade to 2.3.1 (2016-11-30 15:47:17 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib
<http://git.openembedded.org/openembedded-core-contrib> rbt/runqemuhttp://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu
<http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=rbt/runqemu>Robert Yang (6):
scripts/runqemu: fix checking for <file>.cpio.gz qemuboot.bbclass: use IMGDEPLOYDIR
runqemu-export-rootfs: fix inconsistent var names
runqemu: support mutiple qemus running when nfs
runqemu: fixes for slirp, network device and hostfwd qemuboot.bbclass: add blank lines in commentsmeta/classes/qemuboot.bbclass | 34 ++++++--
meta/conf/machine/include/qemuboot-x86.inc | 1 -
meta/conf/machine/qemuarm64.conf| 1 -
scripts/runqemu| 133
++++++++++++++++++++++-------
scripts/runqemu-export-rootfs| 21 ++---
5 files changed, 140 insertions(+), 50 deletions(-)