From e75a838c68e5cacfb16c5852055a10de559f7717 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Wed, 19 Jul 2023 12:31:06 -0700 Subject: [PATCH] boot-qemu.py: Handle difference in arguments between C and Rust implementations of virtiofsd In at least virtiofsd 1.6.1 (the Rust implementation), the '-o' options warn that they are deprecated and the '--help' text agrees: [2023-07-19T19:32:50Z WARN virtiofsd] Use of deprecated option format '-o': Please specify options without it (e.g., '--cache auto' instead of '-o cache=auto') -o ... Options in a format compatible with the legacy implementation [deprecated] To defend against a release removing the deprecated option and breaking the invocation, maintain two sets of arguments depending on what implementation is being used. This allows us to drop support for the C implementation once the Rust one is more widely available in distributions. Signed-off-by: Nathan Chancellor --- boot-qemu.py | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/boot-qemu.py b/boot-qemu.py index e998c49..abe9564 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -236,13 +236,42 @@ def _prepare_for_shared_folder(self): '-numa', 'node,memdev=shm', ] # yapf: disable + # recent versions of the rust implementation of virtiofsd have + # deprecated the '-o' syntax for options. Check for the '-o' syntax in + # the help text of virtiofsd and use that if present or the new syntax + # if not. + base_virtiofsd_cmd = [sudo, virtiofsd] + virtiofsd_version_text = subprocess.run( + [*base_virtiofsd_cmd, '--version'], + capture_output=True, + check=True, + text=True).stdout + # C / QEMU / Reference implementation (deprecated) + if 'virtiofsd version' in virtiofsd_version_text: + virtiofsd_args = [ + f"--socket-group={grp.getgrgid(os.getgid()).gr_name}", + f"--socket-path={self._vfsd_conf['files']['sock']}", + '-o', 'cache=always', + '-o', f"source={SHARED_FOLDER}", + ] # yapf: disable + # Rust implementation + # The some of the above options are parsed as legacy compatibility + # options and as of at least 1.7.1, they are documented as deprecated. + # To guard against a release where those options are no longer parsed + # properly or at all, use the new option format. Once the Rust + # implementation is more widely available in distributions, support for + # the deprecated C implementation can be dropped. + else: + virtiofsd_args = [ + '--cache', 'always', + '--shared-dir', SHARED_FOLDER, + '--socket-group', grp.getgrgid(os.getgid()).gr_name, + '--socket-path', self._vfsd_conf['files']['sock'], + ] # yapf: disable + self._vfsd_conf['cmd'] = [ - sudo, - virtiofsd, - f"--socket-group={grp.getgrgid(os.getgid()).gr_name}", - f"--socket-path={self._vfsd_conf['files']['sock']}", - '-o', f"source={SHARED_FOLDER}", - '-o', 'cache=always', + *base_virtiofsd_cmd, + *virtiofsd_args ] # yapf: disable def _prepare_initrd(self):