Skip to content

feat(qemu): make Qemu class extensible and QemuProcess injectable#122

Open
Rahul-Sutariya wants to merge 1 commit into
eclipse-score:mainfrom
Rahul-Sutariya:rasu_extend_itf_qemu_class
Open

feat(qemu): make Qemu class extensible and QemuProcess injectable#122
Rahul-Sutariya wants to merge 1 commit into
eclipse-score:mainfrom
Rahul-Sutariya:rasu_extend_itf_qemu_class

Conversation

@Rahul-Sutariya

Copy link
Copy Markdown

Summary

Make the Qemu class and QemuProcess extensible so downstream plugins
can add custom QEMU devices (e.g. ivshmem) via inheritance/DI instead of
copy command assembly.

Changes

qemu.py

  • __method_method (all internal methods and attributes)
  • Added _extra_qemu_args() hook — called during command assembly,
    returns [] by default; subclasses override to inject flags.
  • Added _serial_args() hook — returns ["-serial", "mon:stdio"] by
    default; overridable for per-VM serial log files.

qemu_process.py

  • Added optional qemu=None keyword argument to __init__.
  • When provided, the given Qemu instance is used directly (DI);
    otherwise a default Qemu(...) is constructed as before.

Impact on existing users

None. All changes are additive/internal:

  • Public method signatures unchanged.
  • Constructor backward-compatible (new optional kwarg).
  • Single-underscore methods are "protected" — no external caller could
    have referenced the double-underscore mangled names.

Motivation

The communication repo's dual_qemu plugin needs to launch QEMU with
an ivshmem-plain shared-memory device. Without these hooks, it had to
duplicate the entire Qemu class because inheritance was
blocked by name mangling and there was no extension point for extra args.

With this change, the ivshmem launcher becomes a thin subclass
overriding _extra_qemu_args() and _serial_args().

Replace double-underscore name mangling with single-underscore
("protected") on all internal methods and attributes of the Qemu class,
enabling subclasses to override command assembly without duplicating the
entire launcher.

Add two overridable hooks:
- _extra_qemu_args(): inject additional -object/-device flags
- _serial_args(): customize serial output redirection

Add an optional `qemu` parameter to QemuProcess.__init__ for dependency
injection: when a pre-configured Qemu (or subclass) instance is passed,
it is used directly instead of constructing a default one. This allows
downstream plugins (e.g. dual_qemu with ivshmem) to provide a custom
launcher without duplicating QemuProcess.

Both changes are fully backward-compatible:
- All public APIs (start/stop/__enter__/__exit__) are unchanged.
- QemuProcess constructor signature is additive (new kwarg with default None).
- No external code could reference the mangled __names, so __ -> _ is invisible.
@lurtz

lurtz commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@Rahul-Sutariya What a coincidence. I am also working on extending the QEMU code: #123

@lurtz lurtz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look ok to me, but I am not really a code owner of ITF, thus not approving.

We should have a discussion what features the QEMU plugin should have and how its extension points look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants