All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd
@ 2016-12-06  8:55 Robert Yang
  2016-12-06  8:55 ` [PATCH V2 1/6] scripts/runqemu: fix checking for <file>.cpio.gz Robert Yang
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Robert Yang @ 2016-12-06  8:55 UTC (permalink / raw)
  To: openembedded-core

* 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(-)

-- 
2.9.0



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH V2 1/6] scripts/runqemu: fix checking for <file>.cpio.gz
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
@ 2016-12-06  8:55 ` Robert Yang
  2016-12-06  8:55 ` [PATCH V2 2/6] qemuboot.bbclass: use IMGDEPLOYDIR Robert Yang
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Robert Yang @ 2016-12-06  8:55 UTC (permalink / raw)
  To: openembedded-core

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.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 scripts/runqemu | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/scripts/runqemu b/scripts/runqemu
index af25423..c737eb2 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -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)
-- 
2.9.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH V2 2/6] qemuboot.bbclass: use IMGDEPLOYDIR
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
  2016-12-06  8:55 ` [PATCH V2 1/6] scripts/runqemu: fix checking for <file>.cpio.gz Robert Yang
@ 2016-12-06  8:55 ` Robert Yang
  2016-12-06  8:55 ` [PATCH V2 3/6] runqemu-export-rootfs: fix inconsistent var names Robert Yang
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Robert Yang @ 2016-12-06  8:55 UTC (permalink / raw)
  To: openembedded-core

So that "bitbake <image> -ccleansstate" can remove qemuboot.conf

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 meta/classes/qemuboot.bbclass | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/meta/classes/qemuboot.bbclass b/meta/classes/qemuboot.bbclass
index 8b1d4d0..1f78a98 100644
--- a/meta/classes/qemuboot.bbclass
+++ b/meta/classes/qemuboot.bbclass
@@ -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):
-- 
2.9.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH V2 3/6] runqemu-export-rootfs: fix inconsistent var names
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
  2016-12-06  8:55 ` [PATCH V2 1/6] scripts/runqemu: fix checking for <file>.cpio.gz Robert Yang
  2016-12-06  8:55 ` [PATCH V2 2/6] qemuboot.bbclass: use IMGDEPLOYDIR Robert Yang
@ 2016-12-06  8:55 ` Robert Yang
  2016-12-06  8:55 ` [PATCH V2 4/6] runqemu: support mutiple qemus running when nfs Robert Yang
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Robert Yang @ 2016-12-06  8:55 UTC (permalink / raw)
  To: openembedded-core

Fixed:
$ 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]

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 scripts/runqemu-export-rootfs | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/scripts/runqemu-export-rootfs b/scripts/runqemu-export-rootfs
index 3dee131..0dd3eba 100755
--- a/scripts/runqemu-export-rootfs
+++ b/scripts/runqemu-export-rootfs
@@ -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
-- 
2.9.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH V2 4/6] runqemu: support mutiple qemus running when nfs
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
                   ` (2 preceding siblings ...)
  2016-12-06  8:55 ` [PATCH V2 3/6] runqemu-export-rootfs: fix inconsistent var names Robert Yang
@ 2016-12-06  8:55 ` Robert Yang
  2016-12-14  9:45   ` Robert Yang
  2016-12-06  8:55 ` [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd Robert Yang
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Robert Yang @ 2016-12-06  8:55 UTC (permalink / raw)
  To: openembedded-core

Fixed:
* 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.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 scripts/runqemu               | 55 ++++++++++++++++++++++++++++---------------
 scripts/runqemu-export-rootfs | 10 ++++----
 2 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/scripts/runqemu b/scripts/runqemu
index c737eb2..a10270c 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -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'))
diff --git a/scripts/runqemu-export-rootfs b/scripts/runqemu-export-rootfs
index 0dd3eba..7ebc071 100755
--- a/scripts/runqemu-export-rootfs
+++ b/scripts/runqemu-export-rootfs
@@ -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"
-- 
2.9.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
                   ` (3 preceding siblings ...)
  2016-12-06  8:55 ` [PATCH V2 4/6] runqemu: support mutiple qemus running when nfs Robert Yang
@ 2016-12-06  8:55 ` Robert Yang
  2016-12-07 17:58   ` Randy Witt
  2016-12-06  8:55 ` [PATCH V2 6/6] qemuboot.bbclass: add blank lines in comments Robert Yang
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Robert Yang @ 2016-12-06  8:55 UTC (permalink / raw)
  To: openembedded-core

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: 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]

CC: Nathan Rossi <nathan@nathanrossi.com>
CC: Randy Witt <randy.e.witt@linux.intel.com>
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 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::2222-: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 tmp/deploy/images/qemux86/.qemuboot.conf
+  runqemu tmp/deploy/images/qemux86/<qemuboot.conf>
   runqemu qemux86-64 core-image-sato ext4
   runqemu qemux86-64 wic-image-minimal wic
   runqemu path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial
@@ -147,6 +147,19 @@ def get_first_file(cmds):
                     return f
     return ''
 
+def check_free_port(host, port):
+    """ Check whether the port is free or not """
+    import socket
+    from contextlib import closing
+
+    with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
+        if sock.connect_ex((host, port)) == 0:
+            # Port is open, so not free
+            return False
+        else:
+            # Port is not open, so free
+            return True
+
 class BaseConfig(object):
     def __init__(self):
         # Vars can be merged with .qemuboot.conf, use a dict to manage them.
@@ -186,6 +199,15 @@ class BaseConfig(object):
         self.snapshot = False
         self.fstypes = ('ext2', 'ext3', 'ext4', 'jffs2', 'nfs', 'btrfs', 'cpio.gz', 'cpio', 'ramfs')
         self.vmtypes = ('hddimg', 'hdddirect', 'wic', 'vmdk', 'qcow2', 'vdi', 'iso')
+        self.network_device = "-device e1000,netdev=net0,mac=@MAC@"
+        # Use different mac section for tap and slirp to avoid
+        # conflicts, e.g., when one is running with tap, the other is
+        # running with slirp.
+        # The last section is dynamic, which is for avoiding conflicts,
+        # when multiple qemus are running, e.g., when multiple tap or
+        # slirp qemus are running.
+        self.mac_tap = "52:54:00:12:34:"
+        self.mac_slirp = "52:54:00:12:35:"
 
     def acquire_lock(self):
         logger.info("Acquiring lockfile %s..." % self.lock)
@@ -751,14 +773,35 @@ class BaseConfig(object):
 
         self.nfs_running = True
 
-
     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::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
+            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))
+        mac = "%s%02x" % (self.mac_slirp, mac)
+        self.set('NETWORK_CMD', '%s %s' % (self.network_device.replace('@MAC@', mac), qb_slirp_opt))
 
     def setup_tap(self):
         """Setup tap"""
@@ -828,21 +871,22 @@ class BaseConfig(object):
         if self.fstype == 'nfs':
             self.setup_nfs()
         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
+        mac = "%s%02x" % (self.mac_tap, 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)
+            qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap)
         else:
-            qemu_tap_opt = "-device virtio-net-pci,netdev=net0,mac=%s -netdev tap,id=net0,ifname=%s,script=no,downscript=no" % (mac, self.tap)
+            qemu_tap_opt = "-netdev tap,id=net0,ifname=%s,script=no,downscript=no" % (self.tap)
 
         if self.vhost_enabled:
             qemu_tap_opt += ',vhost=on'
 
-        self.set('NETWORK_CMD', qemu_tap_opt)
+        self.set('NETWORK_CMD', '%s %s' % (self.network_device.replace('@MAC@', mac), qemu_tap_opt))
 
     def setup_network(self):
         cmd = "stty -g"
         self.saved_stty = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
+        self.network_device = self.get('QB_NETWORK_DEVICE') or self.network_device
         if self.slirp_enabled:
             self.setup_slirp()
         else:
-- 
2.9.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH V2 6/6] qemuboot.bbclass: add blank lines in comments
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
                   ` (4 preceding siblings ...)
  2016-12-06  8:55 ` [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd Robert Yang
@ 2016-12-06  8:55 ` Robert Yang
  2016-12-06  9:01 ` [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
  2016-12-21  6:24 ` Robert Yang
  7 siblings, 0 replies; 16+ messages in thread
From: Robert Yang @ 2016-12-06  8:55 UTC (permalink / raw)
  To: openembedded-core

Add blank lines in comments to make it easy for readind and updating.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 meta/classes/qemuboot.bbclass | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/meta/classes/qemuboot.bbclass b/meta/classes/qemuboot.bbclass
index 1b94af9..f953241 100644
--- a/meta/classes/qemuboot.bbclass
+++ b/meta/classes/qemuboot.bbclass
@@ -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.
-- 
2.9.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
                   ` (5 preceding siblings ...)
  2016-12-06  8:55 ` [PATCH V2 6/6] qemuboot.bbclass: add blank lines in comments Robert Yang
@ 2016-12-06  9:01 ` Robert Yang
  2016-12-07 16:50   ` Nathan Rossi
  2016-12-21  6:24 ` Robert Yang
  7 siblings, 1 reply; 16+ messages in thread
From: Robert Yang @ 2016-12-06  9:01 UTC (permalink / raw)
  To: Randy Witt, Nathan Rossi; +Cc: openembedded-core



On 12/06/2016 04:55 PM, Robert Yang wrote:
> * V2
>   - Add QB_NETWORK_DEVICE to 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

>   - 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(-)
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd
  2016-12-06  9:01 ` [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
@ 2016-12-07 16:50   ` Nathan Rossi
  0 siblings, 0 replies; 16+ messages in thread
From: Nathan Rossi @ 2016-12-07 16:50 UTC (permalink / raw)
  To: Robert Yang; +Cc: openembedded-core

On 6 December 2016 at 19:01, Robert Yang <liezhi.yang@windriver.com> wrote:
>
>
> On 12/06/2016 04:55 PM, Robert Yang wrote:
>>
>> * V2
>>   - Add QB_NETWORK_DEVICE to 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

>
> // Robert
>
>
>>   - 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(-)
>>
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd
  2016-12-06  8:55 ` [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd Robert Yang
@ 2016-12-07 17:58   ` Randy Witt
  2016-12-12  3:31     ` Robert Yang
  0 siblings, 1 reply; 16+ messages in thread
From: Randy Witt @ 2016-12-07 17:58 UTC (permalink / raw)
  To: Robert Yang, openembedded-core


>      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::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
> +            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.

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



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd
  2016-12-07 17:58   ` Randy Witt
@ 2016-12-12  3:31     ` Robert Yang
  0 siblings, 0 replies; 16+ messages in thread
From: Robert Yang @ 2016-12-12  3:31 UTC (permalink / raw)
  To: Randy Witt, openembedded-core



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::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
>> +            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

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

> 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))
>
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 4/6] runqemu: support mutiple qemus running when nfs
  2016-12-06  8:55 ` [PATCH V2 4/6] runqemu: support mutiple qemus running when nfs Robert Yang
@ 2016-12-14  9:45   ` Robert Yang
  0 siblings, 0 replies; 16+ messages in thread
From: Robert Yang @ 2016-12-14  9:45 UTC (permalink / raw)
  To: openembedded-core



On 12/06/2016 04:55 PM, Robert Yang wrote:
> Fixed:
> * 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.
>
> Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
> ---
>  scripts/runqemu               | 55 ++++++++++++++++++++++++++++---------------
>  scripts/runqemu-export-rootfs | 10 ++++----
>  2 files changed, 41 insertions(+), 24 deletions(-)
>
> diff --git a/scripts/runqemu b/scripts/runqemu
> index c737eb2..a10270c 100755
> --- a/scripts/runqemu
> +++ b/scripts/runqemu
> @@ -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"

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

> +        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'))
> diff --git a/scripts/runqemu-export-rootfs b/scripts/runqemu-export-rootfs
> index 0dd3eba..7ebc071 100755
> --- a/scripts/runqemu-export-rootfs
> +++ b/scripts/runqemu-export-rootfs
> @@ -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"
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd
  2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
                   ` (6 preceding siblings ...)
  2016-12-06  9:01 ` [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
@ 2016-12-21  6:24 ` Robert Yang
  2017-01-11  1:47   ` Robert Yang
  7 siblings, 1 reply; 16+ messages in thread
From: Robert Yang @ 2016-12-21  6:24 UTC (permalink / raw)
  To: Burton, Ross; +Cc: openembedded-core

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

On 12/06/2016 04:55 PM, Robert Yang wrote:
> * 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(-)
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd
  2016-12-21  6:24 ` Robert Yang
@ 2017-01-11  1:47   ` Robert Yang
  2017-01-17 13:14     ` Burton, Ross
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Yang @ 2017-01-11  1:47 UTC (permalink / raw)
  To: Burton, Ross; +Cc: openembedded-core

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 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
>>   - 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(-)
>>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd
  2017-01-11  1:47   ` Robert Yang
@ 2017-01-17 13:14     ` Burton, Ross
  2017-01-18  9:25       ` Robert Yang
  0 siblings, 1 reply; 16+ messages in thread
From: Burton, Ross @ 2017-01-17 13:14 UTC (permalink / raw)
  To: Robert Yang; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 2530 bytes --]

Hi Robert,

I merged these into my staging branch but then the autobuilder failed in an
interesting way:

https://autobuilder.yoctoproject.org/main/builders/nightly-ppc/builds/1053/steps/Running%20Sanity%20Tests/logs/stdio

Would that be related to your series, or is it a coincidence?

Ross

On 11 January 2017 at 01:47, Robert Yang <liezhi.yang@windriver.com> 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 rbt/runqemu
>>
>> http://cgit.openembedded.org/cgit.cgi/openembedded-core-cont
>> rib/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
>>>   - 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 11063a01d4511b2688ea7ba2d7359e
>>> 4e07328c66:
>>>
>>>   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-cont
>>> rib/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(-)
>>>
>>>

[-- Attachment #2: Type: text/html, Size: 3998 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd
  2017-01-17 13:14     ` Burton, Ross
@ 2017-01-18  9:25       ` Robert Yang
  0 siblings, 0 replies; 16+ messages in thread
From: Robert Yang @ 2017-01-18  9:25 UTC (permalink / raw)
  To: Burton, Ross; +Cc: OE-core


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

On 01/17/2017 09:14 PM, Burton, Ross wrote:
> Hi Robert,
>
> I merged these into my staging branch but then the autobuilder failed in an
> interesting way:
>
> https://autobuilder.yoctoproject.org/main/builders/nightly-ppc/builds/1053/steps/Running%20Sanity%20Tests/logs/stdio
>
> Would that be related to your series, or is it a coincidence?
>
> Ross
>
> On 11 January 2017 at 01:47, Robert Yang <liezhi.yang@windriver.com
> <mailto:liezhi.yang@windriver.com>> 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/runqemu
>
>         http://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
>               - 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
>             <http://git.openembedded.org/openembedded-core-contrib> rbt/runqemu
>
>             http://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
>
>              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(-)
>
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-01-18  9:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-06  8:55 [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
2016-12-06  8:55 ` [PATCH V2 1/6] scripts/runqemu: fix checking for <file>.cpio.gz Robert Yang
2016-12-06  8:55 ` [PATCH V2 2/6] qemuboot.bbclass: use IMGDEPLOYDIR Robert Yang
2016-12-06  8:55 ` [PATCH V2 3/6] runqemu-export-rootfs: fix inconsistent var names Robert Yang
2016-12-06  8:55 ` [PATCH V2 4/6] runqemu: support mutiple qemus running when nfs Robert Yang
2016-12-14  9:45   ` Robert Yang
2016-12-06  8:55 ` [PATCH V2 5/6] runqemu: fixes for slirp, network device and hostfwd Robert Yang
2016-12-07 17:58   ` Randy Witt
2016-12-12  3:31     ` Robert Yang
2016-12-06  8:55 ` [PATCH V2 6/6] qemuboot.bbclass: add blank lines in comments Robert Yang
2016-12-06  9:01 ` [PATCH V2 0/6] runqemu: fix for slirp, network device and hostfwd Robert Yang
2016-12-07 16:50   ` Nathan Rossi
2016-12-21  6:24 ` Robert Yang
2017-01-11  1:47   ` Robert Yang
2017-01-17 13:14     ` Burton, Ross
2017-01-18  9:25       ` Robert Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.