aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2023-01-11 12:01:01 +0400
committerJohn Snow <jsnow@redhat.com>2023-01-24 13:37:13 -0500
commitbd4c0ef409140bd1be393407c04005ac077d4574 (patch)
tree013be1b0b48eb4920c3bf713ded9bbcc142e734a /python
parent603a3bad4b9a95b524dc8d6a41b1be4d5c5cacdf (diff)
downloadqemu-bd4c0ef409140bd1be393407c04005ac077d4574.zip
qemu-bd4c0ef409140bd1be393407c04005ac077d4574.tar.gz
qemu-bd4c0ef409140bd1be393407c04005ac077d4574.tar.bz2
python/qemu/machine: use socketpair() for QMP by default
When no monitor address is given, establish the QMP communication through a socketpair() (API is also supported on Windows since Python 3.5) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-id: 20230111080101.969151-4-marcandre.lureau@redhat.com [Resolved conflicts, fixed typing error. --js] Signed-off-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'python')
-rw-r--r--python/qemu/machine/machine.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
index a71d87e..e57c254 100644
--- a/python/qemu/machine/machine.py
+++ b/python/qemu/machine/machine.py
@@ -158,17 +158,13 @@ class QEMUMachine:
self._qmp_timer = qmp_timer
self._name = name or f"{id(self):x}"
+ self._sock_pair: Optional[Tuple[socket.socket, socket.socket]] = None
self._temp_dir: Optional[str] = None
self._base_temp_dir = base_temp_dir
self._sock_dir = sock_dir
self._log_dir = log_dir
- if monitor_address is not None:
- self._monitor_address = monitor_address
- else:
- self._monitor_address = os.path.join(
- self.sock_dir, f"{self._name}.qmp"
- )
+ self._monitor_address = monitor_address
self._console_log_path = console_log
if self._console_log_path:
@@ -303,7 +299,11 @@ class QEMUMachine:
args = ['-display', 'none', '-vga', 'none']
if self._qmp_set:
- if isinstance(self._monitor_address, tuple):
+ if self._sock_pair:
+ fd = self._sock_pair[0].fileno()
+ os.set_inheritable(fd, True)
+ moncdev = f"socket,id=mon,fd={fd}"
+ elif isinstance(self._monitor_address, tuple):
moncdev = "socket,id=mon,host={},port={}".format(
*self._monitor_address
)
@@ -337,10 +337,17 @@ class QEMUMachine:
self._remove_files.append(self._console_address)
if self._qmp_set:
+ monitor_address = None
+ sock = None
+ if self._monitor_address is None:
+ self._sock_pair = socket.socketpair()
+ sock = self._sock_pair[1]
if isinstance(self._monitor_address, str):
self._remove_files.append(self._monitor_address)
+ monitor_address = self._monitor_address
self._qmp_connection = QEMUMonitorProtocol(
- self._monitor_address,
+ address=monitor_address,
+ sock=sock,
server=True,
nickname=self._name
)
@@ -360,6 +367,8 @@ class QEMUMachine:
))
def _post_launch(self) -> None:
+ if self._sock_pair:
+ self._sock_pair[0].close()
if self._qmp_connection:
self._qmp.accept(self._qmp_timer)