summaryrefslogtreecommitdiffstats
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:07:32 +0100
commit3305872894552d7d1d486ca4441b1a7c5a39bf6e (patch)
treee8cf1c20cde362f3d403207da47b5cd484a98848 /scripts
parent8a2eb1a75e3fe0020f50e348d4a2c7d49fd5f276 (diff)
downloadpoky-3305872894552d7d1d486ca4441b1a7c5a39bf6e.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. (From OE-Core rev: f3a9ff2cea88cf4c90b1037b3ca17e6a63ea33ee) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
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):
676 else: 676 else:
677 self.nfs_server = '192.168.7.1' 677 self.nfs_server = '192.168.7.1'
678 678
679 nfs_instance = int(self.nfs_instance) 679 # Figure out a new nfs_instance to allow multiple qemus running.
680 680 # CentOS 7.1's ps doesn't print full command line without "ww"
681 mountd_rpcport = 21111 + nfs_instance 681 # when invoke by subprocess.Popen().
682 nfsd_rpcport = 11111 + nfs_instance 682 cmd = "ps auxww"
683 nfsd_port = 3049 + 2 * nfs_instance 683 ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
684 mountd_port = 3048 + 2 * nfs_instance 684 pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) '
685 unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port) 685 all_instances = re.findall(pattern, ps, re.M)
686 self.unfs_opts = unfs_opts 686 if all_instances:
687 all_instances.sort(key=int)
688 self.nfs_instance = int(all_instances.pop()) + 1
689
690 mountd_rpcport = 21111 + self.nfs_instance
691 nfsd_rpcport = 11111 + self.nfs_instance
692 nfsd_port = 3049 + 2 * self.nfs_instance
693 mountd_port = 3048 + 2 * self.nfs_instance
694
695 # Export vars for runqemu-export-rootfs
696 export_dict = {
697 'NFS_INSTANCE': self.nfs_instance,
698 'MOUNTD_RPCPORT': mountd_rpcport,
699 'NFSD_RPCPORT': nfsd_rpcport,
700 'NFSD_PORT': nfsd_port,
701 'MOUNTD_PORT': mountd_port,
702 }
703 for k, v in export_dict.items():
704 # Use '%s' since they are integers
705 os.putenv(k, '%s' % v)
687 706
688 p = '%s/.runqemu-sdk/pseudo' % os.getenv('HOME') 707 self.unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port)
689 os.putenv('PSEUDO_LOCALSTATEDIR', p)
690 708
691 # Extract .tar.bz2 or .tar.bz if no self.nfs_dir 709 # Extract .tar.bz2 or .tar.bz if no self.nfs_dir
692 if not self.nfs_dir: 710 if not self.nfs_dir:
@@ -714,7 +732,7 @@ class BaseConfig(object):
714 self.nfs_dir = dest 732 self.nfs_dir = dest
715 733
716 # Start the userspace NFS server 734 # Start the userspace NFS server
717 cmd = 'runqemu-export-rootfs restart %s' % self.nfs_dir 735 cmd = 'runqemu-export-rootfs start %s' % self.nfs_dir
718 logger.info('Running %s...' % cmd) 736 logger.info('Running %s...' % cmd)
719 if subprocess.call(cmd, shell=True) != 0: 737 if subprocess.call(cmd, shell=True) != 0:
720 raise Exception('Failed to run %s' % cmd) 738 raise Exception('Failed to run %s' % cmd)
@@ -723,6 +741,8 @@ class BaseConfig(object):
723 741
724 742
725 def setup_slirp(self): 743 def setup_slirp(self):
744 """Setup user networking"""
745
726 if self.fstype == 'nfs': 746 if self.fstype == 'nfs':
727 self.setup_nfs() 747 self.setup_nfs()
728 self.kernel_cmdline_script += ' ip=dhcp' 748 self.kernel_cmdline_script += ' ip=dhcp'
@@ -790,14 +810,13 @@ class BaseConfig(object):
790 logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") 810 logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.")
791 return 1 811 return 1
792 self.tap = tap 812 self.tap = tap
793 n0 = tap[3:] 813 tapnum = int(tap[3:])
794 n1 = int(n0) * 2 + 1 814 gateway = tapnum * 2 + 1
795 n2 = n1 + 1 815 client = gateway + 1
796 self.nfs_instance = n0
797 if self.fstype == 'nfs': 816 if self.fstype == 'nfs':
798 self.setup_nfs() 817 self.setup_nfs()
799 self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (n2, n1) 818 self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (client, gateway)
800 mac = "52:54:00:12:34:%02x" % n2 819 mac = "52:54:00:12:34:%02x" % client
801 qb_tap_opt = self.get('QB_TAP_OPT') 820 qb_tap_opt = self.get('QB_TAP_OPT')
802 if qb_tap_opt: 821 if qb_tap_opt:
803 qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap).replace('@MAC@', mac) 822 qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap).replace('@MAC@', mac)
@@ -840,11 +859,11 @@ class BaseConfig(object):
840 vm_drive = '-drive if=none,id=hd,file=%s,format=%s -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd' \ 859 vm_drive = '-drive if=none,id=hd,file=%s,format=%s -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd' \
841 % (self.rootfs, rootfs_format) 860 % (self.rootfs, rootfs_format)
842 elif subprocess.call(cmd2, shell=True) == 0: 861 elif subprocess.call(cmd2, shell=True) == 0:
843 logger.info('Using scsi drive') 862 logger.info('Using ide drive')
844 vm_drive = "%s,format=%s" % (self.rootfs, rootfs_format) 863 vm_drive = "%s,format=%s" % (self.rootfs, rootfs_format)
845 else: 864 else:
846 logger.warn("Can't detect drive type %s" % self.rootfs) 865 logger.warn("Can't detect drive type %s" % self.rootfs)
847 logger.warn('Tring to use virtio block drive') 866 logger.warn('Trying to use virtio block drive')
848 vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format) 867 vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format)
849 self.rootfs_options = '%s -no-reboot' % vm_drive 868 self.rootfs_options = '%s -no-reboot' % vm_drive
850 self.kernel_cmdline = 'root=%s rw highres=off' % (self.get('QB_KERNEL_ROOT')) 869 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
78fi 78fi
79 79
80# rpc.mountd RPC port 80# rpc.mountd RPC port
81MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ] 81MOUNTD_RPCPORT=${MOUNTD_RPCPORT:=$[ 21111 + $NFS_INSTANCE ]}
82# rpc.nfsd RPC port 82# rpc.nfsd RPC port
83NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ] 83NFSD_RPCPORT=${NFSD_RPCPORT:=$[ 11111 + $NFS_INSTANCE ]}
84# NFS server port number 84# NFS server port number
85NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] 85NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]}
86# mountd port number 86# mountd port number
87MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] 87MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]}
88 88
89## For debugging you would additionally add 89## For debugging you would additionally add
90## --debug all 90## --debug all
@@ -109,7 +109,7 @@ case "$1" in
109 fi 109 fi
110 110
111 echo "Creating exports file..." 111 echo "Creating exports file..."
112 echo "$NFS_EXPORT_DIR (rw,async,no_root_squash,no_all_squash,insecure)" > $EXPORTS 112 echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS
113 113
114 echo "Starting User Mode nfsd" 114 echo "Starting User Mode nfsd"
115 echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS" 115 echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"