summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAlexander Kanavin <alex.kanavin@gmail.com>2023-06-14 15:00:47 +0200
committerSteve Sakoman <steve@sakoman.com>2023-07-12 05:13:59 -1000
commite146653c21d6c681acd89c37bc66aa4255d64020 (patch)
tree390a98ea12f0d3f345f4944c5e2c85832ca39ba9 /scripts
parentb30e81df2b71e7fdf23f7a4a19813fb6d512f2cd (diff)
downloadpoky-e146653c21d6c681acd89c37bc66aa4255d64020.tar.gz
scripts/runqemu: allocate unfsd ports in a way that doesn't race or clash with unrelated processes
There is already a neat check_free_port() function for finding an available port atomically, so use that and make two additional tweaks: - no need to allocate two separate ports; per unfsd documentation they can be the same - move lockfile release until after unfsd has been shut down and the port(s) used has been freed [YOCTO #15077] (From OE-Core rev: 816d12f125974fc064d17c735b7769f7a9744597) Signed-off-by: Alexander Kanavin <alex@linutronix.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit dee96e82fb04ea99ecd6c25513c7bd368df3bd37) Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu19
1 files changed, 8 insertions, 11 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index 42abda0962..4dfc0e2d38 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -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,
@@ -1420,13 +1417,13 @@ class BaseConfig(object):
1420 logger.debug('Running %s' % str(cmd)) 1417 logger.debug('Running %s' % str(cmd))
1421 subprocess.check_call(cmd) 1418 subprocess.check_call(cmd)
1422 self.release_taplock() 1419 self.release_taplock()
1423 self.release_portlock()
1424 1420
1425 if self.nfs_running: 1421 if self.nfs_running:
1426 logger.info("Shutting down the userspace NFS server...") 1422 logger.info("Shutting down the userspace NFS server...")
1427 cmd = ("runqemu-export-rootfs", "stop", self.rootfs) 1423 cmd = ("runqemu-export-rootfs", "stop", self.rootfs)
1428 logger.debug('Running %s' % str(cmd)) 1424 logger.debug('Running %s' % str(cmd))
1429 subprocess.check_call(cmd) 1425 subprocess.check_call(cmd)
1426 self.release_portlock()
1430 1427
1431 if self.saved_stty: 1428 if self.saved_stty:
1432 subprocess.check_call(("stty", self.saved_stty)) 1429 subprocess.check_call(("stty", self.saved_stty))