Skip to content

Commit e75a838

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 075a077 commit e75a838

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

boot-qemu.py

+35-6
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,42 @@ def _prepare_for_shared_folder(self):
236236
'-numa', 'node,memdev=shm',
237237
] # yapf: disable
238238

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

248277
def _prepare_initrd(self):

0 commit comments

Comments
 (0)