Skip to content

Commit 9c27060

Browse files
committed
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 <compat-options>... 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 <[email protected]>
1 parent eac0333 commit 9c27060

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

boot-qemu.py

+39-6
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,46 @@ def _prepare_for_shared_folder(self):
235235
'-numa', 'node,memdev=shm',
236236
] # yapf: disable
237237

238+
# recent versions of the rust implementation of virtiofsd have
239+
# deprecated the '-o' syntax for options. Check for the '-o' syntax in
240+
# the help text of virtiofsd and use that if present or the new syntax
241+
# if not.
242+
base_virtiofsd_cmd = [sudo, virtiofsd]
243+
virtiofsd_version_text = subprocess.run(
244+
[*base_virtiofsd_cmd, '--version'],
245+
capture_output=True,
246+
check=True,
247+
text=True).stdout
248+
# C / QEMU / Reference implementation (deprecated)
249+
if 'virtiofsd version' in virtiofsd_version_text:
250+
virtiofsd_args = [
251+
f"--socket-group={grp.getgrgid(os.getgid()).gr_name}",
252+
f"--socket-path={self._vfsd_conf['files']['sock']}",
253+
'-o', 'cache=always',
254+
'-o', f"source={SHARED_FOLDER}",
255+
] # yapf: disable
256+
# Rust implementation
257+
# The some of the above options are parsed as legacy compatibility
258+
# options and as of at least 1.7.1, they are documented as deprecated.
259+
# To guard against a release where those options are no longer parsed
260+
# properly or at all, use the new option format. Once the Rust
261+
# implementation is more widely available in distributions, support for
262+
# the deprecated C implementation can be dropped.
263+
elif 'virtiofsd backend' in virtiofsd_version_text:
264+
virtiofsd_args = [
265+
'--cache', 'always',
266+
'--shared-dir', SHARED_FOLDER,
267+
'--socket-group', grp.getgrgid(os.getgid()).gr_name,
268+
'--socket-path', self._vfsd_conf['files']['sock'],
269+
] # yapf: disable
270+
else:
271+
raise RuntimeError(
272+
f"Could not determine virtiofsd implementation details from version string ('{virtiofsd_version_text}')?"
273+
)
274+
238275
self._vfsd_conf['cmd'] = [
239-
sudo,
240-
virtiofsd,
241-
f"--socket-group={grp.getgrgid(os.getgid()).gr_name}",
242-
f"--socket-path={self._vfsd_conf['files']['sock']}",
243-
'-o', f"source={SHARED_FOLDER}",
244-
'-o', 'cache=always',
276+
*base_virtiofsd_cmd,
277+
*virtiofsd_args
245278
] # yapf: disable
246279

247280
def _prepare_initrd(self):

0 commit comments

Comments
 (0)