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-04 05:32:29 -1000
commit011e2bb251bd84f534512da2c59c69b0a8e7629f (patch)
treef887f7f4a1a099426d3f50fdb83f5696d1f370fc /scripts
parent5336ba0908d97da2410ff3eaee66c4c792038580 (diff)
downloadpoky-011e2bb251bd84f534512da2c59c69b0a8e7629f.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: 3dccfba830bfbe89554a5e3ed5c3517d13545d35) 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 50224f2784..ef24ddc6b2 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1011,17 +1011,14 @@ to your build configuration.
1011 else: 1011 else:
1012 self.nfs_server = '192.168.7.@GATEWAY@' 1012 self.nfs_server = '192.168.7.@GATEWAY@'
1013 1013
1014 # Figure out a new nfs_instance to allow multiple qemus running. 1014 nfsd_port = 3048 + self.nfs_instance
1015 ps = subprocess.check_output(("ps", "auxww")).decode('utf-8') 1015 lockdir = "/tmp/qemu-port-locks"
1016 pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) ' 1016 self.make_lock_dir(lockdir)
1017 all_instances = re.findall(pattern, ps, re.M) 1017 while not self.check_free_port('localhost', nfsd_port, lockdir):
1018 if all_instances: 1018 self.nfs_instance += 1
1019 all_instances.sort(key=int) 1019 nfsd_port += 1
1020 self.nfs_instance = int(all_instances.pop()) + 1
1021
1022 nfsd_port = 3049 + 2 * self.nfs_instance
1023 mountd_port = 3048 + 2 * self.nfs_instance
1024 1020
1021 mountd_port = nfsd_port
1025 # Export vars for runqemu-export-rootfs 1022 # Export vars for runqemu-export-rootfs
1026 export_dict = { 1023 export_dict = {
1027 'NFS_INSTANCE': self.nfs_instance, 1024 'NFS_INSTANCE': self.nfs_instance,
@@ -1595,13 +1592,13 @@ to your build configuration.
1595 logger.debug('Running %s' % str(cmd)) 1592 logger.debug('Running %s' % str(cmd))
1596 subprocess.check_call(cmd) 1593 subprocess.check_call(cmd)
1597 self.release_taplock() 1594 self.release_taplock()
1598 self.release_portlock()
1599 1595
1600 if self.nfs_running: 1596 if self.nfs_running:
1601 logger.info("Shutting down the userspace NFS server...") 1597 logger.info("Shutting down the userspace NFS server...")
1602 cmd = ("runqemu-export-rootfs", "stop", self.rootfs) 1598 cmd = ("runqemu-export-rootfs", "stop", self.rootfs)
1603 logger.debug('Running %s' % str(cmd)) 1599 logger.debug('Running %s' % str(cmd))
1604 subprocess.check_call(cmd) 1600 subprocess.check_call(cmd)
1601 self.release_portlock()
1605 1602
1606 if self.saved_stty: 1603 if self.saved_stty:
1607 subprocess.check_call(("stty", self.saved_stty)) 1604 subprocess.check_call(("stty", self.saved_stty))