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:11:38 -1000
commitbb2ce4dcf6a5c549a6ef29a5a1be0fb224e68477 (patch)
tree9650c6c416fef1d7e5da286a16f05ef54be1483b /scripts
parente69c311ed68e3f44f3e55f01f6f54b978d76e0d1 (diff)
downloadpoky-bb2ce4dcf6a5c549a6ef29a5a1be0fb224e68477.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: 343510b33650c88367f95e8d8322fae92ae901ca) 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 f275cf7813..729b067a9f 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1001,17 +1001,14 @@ class BaseConfig(object):
1001 else: 1001 else:
1002 self.nfs_server = '192.168.7.1' 1002 self.nfs_server = '192.168.7.1'
1003 1003
1004 # Figure out a new nfs_instance to allow multiple qemus running. 1004 nfsd_port = 3048 + self.nfs_instance
1005 ps = subprocess.check_output(("ps", "auxww")).decode('utf-8') 1005 lockdir = "/tmp/qemu-port-locks"
1006 pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) ' 1006 self.make_lock_dir(lockdir)
1007 all_instances = re.findall(pattern, ps, re.M) 1007 while not self.check_free_port('localhost', nfsd_port, lockdir):
1008 if all_instances: 1008 self.nfs_instance += 1
1009 all_instances.sort(key=int) 1009 nfsd_port += 1
1010 self.nfs_instance = int(all_instances.pop()) + 1
1011
1012 nfsd_port = 3049 + 2 * self.nfs_instance
1013 mountd_port = 3048 + 2 * self.nfs_instance
1014 1010
1011 mountd_port = nfsd_port
1015 # Export vars for runqemu-export-rootfs 1012 # Export vars for runqemu-export-rootfs
1016 export_dict = { 1013 export_dict = {
1017 'NFS_INSTANCE': self.nfs_instance, 1014 'NFS_INSTANCE': self.nfs_instance,
@@ -1542,13 +1539,13 @@ class BaseConfig(object):
1542 logger.debug('Running %s' % str(cmd)) 1539 logger.debug('Running %s' % str(cmd))
1543 subprocess.check_call(cmd) 1540 subprocess.check_call(cmd)
1544 self.release_taplock() 1541 self.release_taplock()
1545 self.release_portlock()
1546 1542
1547 if self.nfs_running: 1543 if self.nfs_running:
1548 logger.info("Shutting down the userspace NFS server...") 1544 logger.info("Shutting down the userspace NFS server...")
1549 cmd = ("runqemu-export-rootfs", "stop", self.rootfs) 1545 cmd = ("runqemu-export-rootfs", "stop", self.rootfs)
1550 logger.debug('Running %s' % str(cmd)) 1546 logger.debug('Running %s' % str(cmd))
1551 subprocess.check_call(cmd) 1547 subprocess.check_call(cmd)
1548 self.release_portlock()
1552 1549
1553 if self.saved_stty: 1550 if self.saved_stty:
1554 subprocess.check_call(("stty", self.saved_stty)) 1551 subprocess.check_call(("stty", self.saved_stty))