Re: [OE-core] [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd

2016-12-11 Thread Robert Yang



On 12/08/2016 01:58 AM, Randy Witt wrote:



 def setup_slirp(self):
 """Setup user networking"""

 if self.fstype == 'nfs':
 self.setup_nfs()
 self.kernel_cmdline_script += ' ip=dhcp'
-self.set('NETWORK_CMD', self.get('QB_SLIRP_OPT'))
+# Port mapping
+hostfwd = ",hostfwd=tcp::-: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
+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
: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::-: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 .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


command line and then check to see if anything is remapped. But that's a bit
more work.


+mac = "%s%02x" % (self.mac_slirp, mac)
+self.set('NETWORK_CMD', '%s %s' %
(self.network_device.replace('@MAC@', mac), qb_slirp_opt))




--
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


Re: [OE-core] [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd

2016-12-07 Thread Randy Witt



 def setup_slirp(self):
 """Setup user networking"""

 if self.fstype == 'nfs':
 self.setup_nfs()
 self.kernel_cmdline_script += ' ip=dhcp'
-self.set('NETWORK_CMD', self.get('QB_SLIRP_OPT'))
+# Port mapping
+hostfwd = ",hostfwd=tcp::-: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
+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 
: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.



+mac = "%s%02x" % (self.mac_slirp, mac)
+self.set('NETWORK_CMD', '%s %s' % 
(self.network_device.replace('@MAC@', mac), qb_slirp_opt))


--
___
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core


[OE-core] [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd

2016-12-06 Thread Robert Yang
Fixed:
- 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:  -> 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]

CC: Nathan Rossi 
CC: Randy Witt 
Signed-off-by: Robert Yang 
---
 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(-)

diff --git a/meta/classes/qemuboot.bbclass b/meta/classes/qemuboot.bbclass
index 1f78a98..1b94af9 100644
--- a/meta/classes/qemuboot.bbclass
+++ b/meta/classes/qemuboot.bbclass
@@ -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
diff --git a/meta/conf/machine/include/qemuboot-x86.inc 
b/meta/conf/machine/include/qemuboot-x86.inc
index 0870294..06ac983 100644
--- a/meta/conf/machine/include/qemuboot-x86.inc
+++ b/meta/conf/machine/include/qemuboot-x86.inc
@@ -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::-:22"
diff --git a/meta/conf/machine/qemuarm64.conf b/meta/conf/machine/qemuarm64.conf
index df2010c..7a5570c 100644
--- a/meta/conf/machine/qemuarm64.conf
+++ b/meta/conf/machine/qemuarm64.conf
@@ -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"
diff --git a/scripts/runqemu b/scripts/runqemu
index a10270c..629b4ed 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -84,7 +84,7 @@ of the following environment variables (in any order):
 Examples:
   runqemu qemuarm
   runqemu tmp/deploy/images/qemuarm
-  runqemu