diff options
author | Alexander Kanavin <alex.kanavin@gmail.com> | 2023-06-14 15:00:47 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-15 08:00:41 +0100 |
commit | 66b7727577f864d1725e14f5e953be114360fea3 (patch) | |
tree | 228d51b96873d5a7146793b528e16d7ecfeca90d /scripts/runqemu | |
parent | 5776d07bddc051ce3e9e73ace26af924f426b51f (diff) | |
download | poky-66b7727577f864d1725e14f5e953be114360fea3.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: dee96e82fb04ea99ecd6c25513c7bd368df3bd37)
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/runqemu')
-rwxr-xr-x | scripts/runqemu | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index cef5b8d4a4..7c6f1cb964 100755 --- a/scripts/runqemu +++ b/scripts/runqemu | |||
@@ -1015,17 +1015,14 @@ to your build configuration. | |||
1015 | else: | 1015 | else: |
1016 | self.nfs_server = '192.168.7.@GATEWAY@' | 1016 | self.nfs_server = '192.168.7.@GATEWAY@' |
1017 | 1017 | ||
1018 | # Figure out a new nfs_instance to allow multiple qemus running. | 1018 | nfsd_port = 3048 + self.nfs_instance |
1019 | ps = subprocess.check_output(("ps", "auxww")).decode('utf-8') | 1019 | lockdir = "/tmp/qemu-port-locks" |
1020 | pattern = '/bin/unfsd .* -i .*\.pid -e .*/exports([0-9]+) ' | 1020 | self.make_lock_dir(lockdir) |
1021 | all_instances = re.findall(pattern, ps, re.M) | 1021 | while not self.check_free_port('localhost', nfsd_port, lockdir): |
1022 | if all_instances: | 1022 | self.nfs_instance += 1 |
1023 | all_instances.sort(key=int) | 1023 | nfsd_port += 1 |
1024 | self.nfs_instance = int(all_instances.pop()) + 1 | ||
1025 | |||
1026 | nfsd_port = 3049 + 2 * self.nfs_instance | ||
1027 | mountd_port = 3048 + 2 * self.nfs_instance | ||
1028 | 1024 | ||
1025 | mountd_port = nfsd_port | ||
1029 | # Export vars for runqemu-export-rootfs | 1026 | # Export vars for runqemu-export-rootfs |
1030 | export_dict = { | 1027 | export_dict = { |
1031 | 'NFS_INSTANCE': self.nfs_instance, | 1028 | 'NFS_INSTANCE': self.nfs_instance, |
@@ -1600,13 +1597,13 @@ to your build configuration. | |||
1600 | logger.debug('Running %s' % str(cmd)) | 1597 | logger.debug('Running %s' % str(cmd)) |
1601 | subprocess.check_call(cmd) | 1598 | subprocess.check_call(cmd) |
1602 | self.release_taplock() | 1599 | self.release_taplock() |
1603 | self.release_portlock() | ||
1604 | 1600 | ||
1605 | if self.nfs_running: | 1601 | if self.nfs_running: |
1606 | logger.info("Shutting down the userspace NFS server...") | 1602 | logger.info("Shutting down the userspace NFS server...") |
1607 | cmd = ("runqemu-export-rootfs", "stop", self.rootfs) | 1603 | cmd = ("runqemu-export-rootfs", "stop", self.rootfs) |
1608 | logger.debug('Running %s' % str(cmd)) | 1604 | logger.debug('Running %s' % str(cmd)) |
1609 | subprocess.check_call(cmd) | 1605 | subprocess.check_call(cmd) |
1606 | self.release_portlock() | ||
1610 | 1607 | ||
1611 | if self.saved_stty: | 1608 | if self.saved_stty: |
1612 | subprocess.check_call(("stty", self.saved_stty)) | 1609 | subprocess.check_call(("stty", self.saved_stty)) |