diff options
Diffstat (limited to 'scripts/runqemu')
-rwxr-xr-x | scripts/runqemu | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index cc87ea871a..4dfc0e2d38 100755 --- a/scripts/runqemu +++ b/scripts/runqemu | |||
@@ -764,7 +764,7 @@ class BaseConfig(object): | |||
764 | raise RunQemuError('BIOS not found: %s' % bios_match_name) | 764 | raise RunQemuError('BIOS not found: %s' % bios_match_name) |
765 | 765 | ||
766 | if not os.path.exists(self.bios): | 766 | if not os.path.exists(self.bios): |
767 | raise RunQemuError("KERNEL %s not found" % self.bios) | 767 | raise RunQemuError("BIOS %s not found" % self.bios) |
768 | 768 | ||
769 | 769 | ||
770 | def check_mem(self): | 770 | def check_mem(self): |
@@ -974,17 +974,14 @@ class BaseConfig(object): | |||
974 | else: | 974 | else: |
975 | self.nfs_server = '192.168.7.1' | 975 | self.nfs_server = '192.168.7.1' |
976 | 976 | ||
977 | # Figure out a new nfs_instance to allow multiple qemus running. | 977 | nfsd_port = 3048 + self.nfs_instance |
978 | ps = subprocess.check_output(("ps", "auxww")).decode('utf-8') | 978 | lockdir = "/tmp/qemu-port-locks" |
979 | pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) ' | 979 | self.make_lock_dir(lockdir) |
980 | all_instances = re.findall(pattern, ps, re.M) | 980 | while not self.check_free_port('localhost', nfsd_port, lockdir): |
981 | if all_instances: | 981 | self.nfs_instance += 1 |
982 | all_instances.sort(key=int) | 982 | nfsd_port += 1 |
983 | self.nfs_instance = int(all_instances.pop()) + 1 | ||
984 | |||
985 | nfsd_port = 3049 + 2 * self.nfs_instance | ||
986 | mountd_port = 3048 + 2 * self.nfs_instance | ||
987 | 983 | ||
984 | mountd_port = nfsd_port | ||
988 | # Export vars for runqemu-export-rootfs | 985 | # Export vars for runqemu-export-rootfs |
989 | export_dict = { | 986 | export_dict = { |
990 | 'NFS_INSTANCE': self.nfs_instance, | 987 | 'NFS_INSTANCE': self.nfs_instance, |
@@ -1034,6 +1031,17 @@ class BaseConfig(object): | |||
1034 | self.set('NETWORK_CMD', '-netdev bridge,br=%s,id=net0,helper=%s -device virtio-net-pci,netdev=net0 ' % ( | 1031 | self.set('NETWORK_CMD', '-netdev bridge,br=%s,id=net0,helper=%s -device virtio-net-pci,netdev=net0 ' % ( |
1035 | self.net_bridge, os.path.join(self.bindir_native, 'qemu-oe-bridge-helper'))) | 1032 | self.net_bridge, os.path.join(self.bindir_native, 'qemu-oe-bridge-helper'))) |
1036 | 1033 | ||
1034 | def make_lock_dir(self, lockdir): | ||
1035 | if not os.path.exists(lockdir): | ||
1036 | # There might be a race issue when multi runqemu processess are | ||
1037 | # running at the same time. | ||
1038 | try: | ||
1039 | os.mkdir(lockdir) | ||
1040 | os.chmod(lockdir, 0o777) | ||
1041 | except FileExistsError: | ||
1042 | pass | ||
1043 | return | ||
1044 | |||
1037 | def setup_slirp(self): | 1045 | def setup_slirp(self): |
1038 | """Setup user networking""" | 1046 | """Setup user networking""" |
1039 | 1047 | ||
@@ -1052,14 +1060,7 @@ class BaseConfig(object): | |||
1052 | mac = 2 | 1060 | mac = 2 |
1053 | 1061 | ||
1054 | lockdir = "/tmp/qemu-port-locks" | 1062 | lockdir = "/tmp/qemu-port-locks" |
1055 | if not os.path.exists(lockdir): | 1063 | self.make_lock_dir(lockdir) |
1056 | # There might be a race issue when multi runqemu processess are | ||
1057 | # running at the same time. | ||
1058 | try: | ||
1059 | os.mkdir(lockdir) | ||
1060 | os.chmod(lockdir, 0o777) | ||
1061 | except FileExistsError: | ||
1062 | pass | ||
1063 | 1064 | ||
1064 | # Find a free port to avoid conflicts | 1065 | # Find a free port to avoid conflicts |
1065 | for p in ports[:]: | 1066 | for p in ports[:]: |
@@ -1099,14 +1100,7 @@ class BaseConfig(object): | |||
1099 | logger.error("ip: %s" % ip) | 1100 | logger.error("ip: %s" % ip) |
1100 | raise OEPathError("runqemu-ifup, runqemu-ifdown or ip not found") | 1101 | raise OEPathError("runqemu-ifup, runqemu-ifdown or ip not found") |
1101 | 1102 | ||
1102 | if not os.path.exists(lockdir): | 1103 | self.make_lock_dir(lockdir) |
1103 | # There might be a race issue when multi runqemu processess are | ||
1104 | # running at the same time. | ||
1105 | try: | ||
1106 | os.mkdir(lockdir) | ||
1107 | os.chmod(lockdir, 0o777) | ||
1108 | except FileExistsError: | ||
1109 | pass | ||
1110 | 1104 | ||
1111 | cmd = (ip, 'link') | 1105 | cmd = (ip, 'link') |
1112 | logger.debug('Running %s...' % str(cmd)) | 1106 | logger.debug('Running %s...' % str(cmd)) |
@@ -1328,6 +1322,8 @@ class BaseConfig(object): | |||
1328 | 1322 | ||
1329 | for ovmf in self.ovmf_bios: | 1323 | for ovmf in self.ovmf_bios: |
1330 | format = ovmf.rsplit('.', 1)[-1] | 1324 | format = ovmf.rsplit('.', 1)[-1] |
1325 | if format == "bin": | ||
1326 | format = "raw" | ||
1331 | self.qemu_opt += ' -drive if=pflash,format=%s,file=%s' % (format, ovmf) | 1327 | self.qemu_opt += ' -drive if=pflash,format=%s,file=%s' % (format, ovmf) |
1332 | 1328 | ||
1333 | self.qemu_opt += ' ' + self.qemu_opt_script | 1329 | self.qemu_opt += ' ' + self.qemu_opt_script |
@@ -1421,13 +1417,13 @@ class BaseConfig(object): | |||
1421 | logger.debug('Running %s' % str(cmd)) | 1417 | logger.debug('Running %s' % str(cmd)) |
1422 | subprocess.check_call(cmd) | 1418 | subprocess.check_call(cmd) |
1423 | self.release_taplock() | 1419 | self.release_taplock() |
1424 | self.release_portlock() | ||
1425 | 1420 | ||
1426 | if self.nfs_running: | 1421 | if self.nfs_running: |
1427 | logger.info("Shutting down the userspace NFS server...") | 1422 | logger.info("Shutting down the userspace NFS server...") |
1428 | cmd = ("runqemu-export-rootfs", "stop", self.rootfs) | 1423 | cmd = ("runqemu-export-rootfs", "stop", self.rootfs) |
1429 | logger.debug('Running %s' % str(cmd)) | 1424 | logger.debug('Running %s' % str(cmd)) |
1430 | subprocess.check_call(cmd) | 1425 | subprocess.check_call(cmd) |
1426 | self.release_portlock() | ||
1431 | 1427 | ||
1432 | if self.saved_stty: | 1428 | if self.saved_stty: |
1433 | subprocess.check_call(("stty", self.saved_stty)) | 1429 | subprocess.check_call(("stty", self.saved_stty)) |
@@ -1514,7 +1510,8 @@ def main(): | |||
1514 | 1510 | ||
1515 | def sigterm_handler(signum, frame): | 1511 | def sigterm_handler(signum, frame): |
1516 | logger.info("SIGTERM received") | 1512 | logger.info("SIGTERM received") |
1517 | os.kill(config.qemupid, signal.SIGTERM) | 1513 | if config.qemupid: |
1514 | os.kill(config.qemupid, signal.SIGTERM) | ||
1518 | config.cleanup() | 1515 | config.cleanup() |
1519 | # Deliberately ignore the return code of 'tput smam'. | 1516 | # Deliberately ignore the return code of 'tput smam'. |
1520 | subprocess.call(["tput", "smam"]) | 1517 | subprocess.call(["tput", "smam"]) |