Skip to content

Commit

Permalink
boot-qemu.py: Handle difference in arguments between C and Rust imple…
Browse files Browse the repository at this point in the history
…mentations 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]>
  • Loading branch information
nathanchance committed Jun 17, 2024
1 parent 075a077 commit e75a838
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions boot-qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e75a838

Please sign in to comment.