aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2016-11-23 00:57:39 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-05-18 13:04:45 +0100
commitf3a9ff2cea88cf4c90b1037b3ca17e6a63ea33ee (patch)
treecbcae8802c517dff9f2c9b51b9d1516e7973f50f /scripts
parentb572921b359010f281cdb861a73bf05317c6dacf (diff)
downloadopenembedded-core-f3a9ff2cea88cf4c90b1037b3ca17e6a63ea33ee.tar.gz
runqemu: support multiple qemus running when nfs
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> Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu57
-rwxr-xr-xscripts/runqemu-export-rootfs10
2 files changed, 43 insertions, 24 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index dbe17abfc5..1df6875111 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -676,17 +676,35 @@ 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.
+ # CentOS 7.1's ps doesn't print full command line without "ww"
+ # when invoke by subprocess.Popen().
+ cmd = "ps auxww"
+ 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:
@@ -714,7 +732,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)
@@ -723,6 +741,8 @@ class BaseConfig(object):
def setup_slirp(self):
+ """Setup user networking"""
+
if self.fstype == 'nfs':
self.setup_nfs()
self.kernel_cmdline_script += ' ip=dhcp'
@@ -790,14 +810,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)
@@ -840,11 +859,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 0dd3eba8b6..7ebc07194d 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"