diff options
| author | Robert Yang <liezhi.yang@windriver.com> | 2016-11-23 00:57:39 -0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-01-23 12:05:22 +0000 |
| commit | 5ea3627dbb61ab065be8737c46007d7d8d7f3501 (patch) | |
| tree | f62d9a42995de48e02fa940e14a7e2e917b7a49f | |
| parent | c32720422e81f3965c57e80579892a0740453bbf (diff) | |
| download | poky-5ea3627dbb61ab065be8737c46007d7d8d7f3501.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: 84b2281595bbdb497daa42640e3ee4658bf0bed8)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rwxr-xr-x | scripts/runqemu | 57 | ||||
| -rwxr-xr-x | scripts/runqemu-export-rootfs | 10 |
2 files changed, 43 insertions, 24 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index 434b1c2ec7..b176e20845 100755 --- a/scripts/runqemu +++ b/scripts/runqemu | |||
| @@ -694,17 +694,35 @@ class BaseConfig(object): | |||
| 694 | else: | 694 | else: |
| 695 | self.nfs_server = '192.168.7.1' | 695 | self.nfs_server = '192.168.7.1' |
| 696 | 696 | ||
| 697 | nfs_instance = int(self.nfs_instance) | 697 | # Figure out a new nfs_instance to allow multiple qemus running. |
| 698 | 698 | # CentOS 7.1's ps doesn't print full command line without "ww" | |
| 699 | mountd_rpcport = 21111 + nfs_instance | 699 | # when invoke by subprocess.Popen(). |
| 700 | nfsd_rpcport = 11111 + nfs_instance | 700 | cmd = "ps auxww" |
| 701 | nfsd_port = 3049 + 2 * nfs_instance | 701 | ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8') |
| 702 | mountd_port = 3048 + 2 * nfs_instance | 702 | pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) ' |
| 703 | unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port) | 703 | all_instances = re.findall(pattern, ps, re.M) |
| 704 | self.unfs_opts = unfs_opts | 704 | if all_instances: |
| 705 | all_instances.sort(key=int) | ||
| 706 | self.nfs_instance = int(all_instances.pop()) + 1 | ||
| 707 | |||
| 708 | mountd_rpcport = 21111 + self.nfs_instance | ||
| 709 | nfsd_rpcport = 11111 + self.nfs_instance | ||
| 710 | nfsd_port = 3049 + 2 * self.nfs_instance | ||
| 711 | mountd_port = 3048 + 2 * self.nfs_instance | ||
| 712 | |||
| 713 | # Export vars for runqemu-export-rootfs | ||
| 714 | export_dict = { | ||
| 715 | 'NFS_INSTANCE': self.nfs_instance, | ||
| 716 | 'MOUNTD_RPCPORT': mountd_rpcport, | ||
| 717 | 'NFSD_RPCPORT': nfsd_rpcport, | ||
| 718 | 'NFSD_PORT': nfsd_port, | ||
| 719 | 'MOUNTD_PORT': mountd_port, | ||
| 720 | } | ||
| 721 | for k, v in export_dict.items(): | ||
| 722 | # Use '%s' since they are integers | ||
| 723 | os.putenv(k, '%s' % v) | ||
| 705 | 724 | ||
| 706 | p = '%s/.runqemu-sdk/pseudo' % os.getenv('HOME') | 725 | self.unfs_opts="nfsvers=3,port=%s,mountprog=%s,nfsprog=%s,udp,mountport=%s" % (nfsd_port, mountd_rpcport, nfsd_rpcport, mountd_port) |
| 707 | os.putenv('PSEUDO_LOCALSTATEDIR', p) | ||
| 708 | 726 | ||
| 709 | # Extract .tar.bz2 or .tar.bz if no self.nfs_dir | 727 | # Extract .tar.bz2 or .tar.bz if no self.nfs_dir |
| 710 | if not self.nfs_dir: | 728 | if not self.nfs_dir: |
| @@ -732,7 +750,7 @@ class BaseConfig(object): | |||
| 732 | self.nfs_dir = dest | 750 | self.nfs_dir = dest |
| 733 | 751 | ||
| 734 | # Start the userspace NFS server | 752 | # Start the userspace NFS server |
| 735 | cmd = 'runqemu-export-rootfs restart %s' % self.nfs_dir | 753 | cmd = 'runqemu-export-rootfs start %s' % self.nfs_dir |
| 736 | logger.info('Running %s...' % cmd) | 754 | logger.info('Running %s...' % cmd) |
| 737 | if subprocess.call(cmd, shell=True) != 0: | 755 | if subprocess.call(cmd, shell=True) != 0: |
| 738 | raise Exception('Failed to run %s' % cmd) | 756 | raise Exception('Failed to run %s' % cmd) |
| @@ -741,6 +759,8 @@ class BaseConfig(object): | |||
| 741 | 759 | ||
| 742 | 760 | ||
| 743 | def setup_slirp(self): | 761 | def setup_slirp(self): |
| 762 | """Setup user networking""" | ||
| 763 | |||
| 744 | if self.fstype == 'nfs': | 764 | if self.fstype == 'nfs': |
| 745 | self.setup_nfs() | 765 | self.setup_nfs() |
| 746 | self.kernel_cmdline_script += ' ip=dhcp' | 766 | self.kernel_cmdline_script += ' ip=dhcp' |
| @@ -808,14 +828,13 @@ class BaseConfig(object): | |||
| 808 | logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") | 828 | logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") |
| 809 | return 1 | 829 | return 1 |
| 810 | self.tap = tap | 830 | self.tap = tap |
| 811 | n0 = tap[3:] | 831 | tapnum = int(tap[3:]) |
| 812 | n1 = int(n0) * 2 + 1 | 832 | gateway = tapnum * 2 + 1 |
| 813 | n2 = n1 + 1 | 833 | client = gateway + 1 |
| 814 | self.nfs_instance = n0 | ||
| 815 | if self.fstype == 'nfs': | 834 | if self.fstype == 'nfs': |
| 816 | self.setup_nfs() | 835 | self.setup_nfs() |
| 817 | self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (n2, n1) | 836 | self.kernel_cmdline_script += " ip=192.168.7.%s::192.168.7.%s:255.255.255.0" % (client, gateway) |
| 818 | mac = "52:54:00:12:34:%02x" % n2 | 837 | mac = "52:54:00:12:34:%02x" % client |
| 819 | qb_tap_opt = self.get('QB_TAP_OPT') | 838 | qb_tap_opt = self.get('QB_TAP_OPT') |
| 820 | if qb_tap_opt: | 839 | if qb_tap_opt: |
| 821 | qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap).replace('@MAC@', mac) | 840 | qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap).replace('@MAC@', mac) |
| @@ -858,11 +877,11 @@ class BaseConfig(object): | |||
| 858 | vm_drive = '-drive if=none,id=hd,file=%s,format=%s -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd' \ | 877 | vm_drive = '-drive if=none,id=hd,file=%s,format=%s -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd' \ |
| 859 | % (self.rootfs, rootfs_format) | 878 | % (self.rootfs, rootfs_format) |
| 860 | elif subprocess.call(cmd2, shell=True) == 0: | 879 | elif subprocess.call(cmd2, shell=True) == 0: |
| 861 | logger.info('Using scsi drive') | 880 | logger.info('Using ide drive') |
| 862 | vm_drive = "%s,format=%s" % (self.rootfs, rootfs_format) | 881 | vm_drive = "%s,format=%s" % (self.rootfs, rootfs_format) |
| 863 | else: | 882 | else: |
| 864 | logger.warn("Can't detect drive type %s" % self.rootfs) | 883 | logger.warn("Can't detect drive type %s" % self.rootfs) |
| 865 | logger.warn('Tring to use virtio block drive') | 884 | logger.warn('Trying to use virtio block drive') |
| 866 | vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format) | 885 | vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format) |
| 867 | self.rootfs_options = '%s -no-reboot' % vm_drive | 886 | self.rootfs_options = '%s -no-reboot' % vm_drive |
| 868 | self.kernel_cmdline = 'root=%s rw highres=off' % (self.get('QB_KERNEL_ROOT')) | 887 | 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 | |||
| 78 | fi | 78 | fi |
| 79 | 79 | ||
| 80 | # rpc.mountd RPC port | 80 | # rpc.mountd RPC port |
| 81 | MOUNTD_RPCPORT=$[ 21111 + $NFS_INSTANCE ] | 81 | MOUNTD_RPCPORT=${MOUNTD_RPCPORT:=$[ 21111 + $NFS_INSTANCE ]} |
| 82 | # rpc.nfsd RPC port | 82 | # rpc.nfsd RPC port |
| 83 | NFSD_RPCPORT=$[ 11111 + $NFS_INSTANCE ] | 83 | NFSD_RPCPORT=${NFSD_RPCPORT:=$[ 11111 + $NFS_INSTANCE ]} |
| 84 | # NFS server port number | 84 | # NFS server port number |
| 85 | NFSD_PORT=$[ 3049 + 2 * $NFS_INSTANCE ] | 85 | NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]} |
| 86 | # mountd port number | 86 | # mountd port number |
| 87 | MOUNTD_PORT=$[ 3048 + 2 * $NFS_INSTANCE ] | 87 | MOUNTD_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" |
