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>
This commit is contained in:
parent
603a3bad4b
commit
bd4c0ef409
@ -158,17 +158,13 @@ class QEMUMachine:
|
|||||||
self._qmp_timer = qmp_timer
|
self._qmp_timer = qmp_timer
|
||||||
|
|
||||||
self._name = name or f"{id(self):x}"
|
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._temp_dir: Optional[str] = None
|
||||||
self._base_temp_dir = base_temp_dir
|
self._base_temp_dir = base_temp_dir
|
||||||
self._sock_dir = sock_dir
|
self._sock_dir = sock_dir
|
||||||
self._log_dir = log_dir
|
self._log_dir = log_dir
|
||||||
|
|
||||||
if monitor_address is not None:
|
self._monitor_address = monitor_address
|
||||||
self._monitor_address = monitor_address
|
|
||||||
else:
|
|
||||||
self._monitor_address = os.path.join(
|
|
||||||
self.sock_dir, f"{self._name}.qmp"
|
|
||||||
)
|
|
||||||
|
|
||||||
self._console_log_path = console_log
|
self._console_log_path = console_log
|
||||||
if self._console_log_path:
|
if self._console_log_path:
|
||||||
@ -303,7 +299,11 @@ class QEMUMachine:
|
|||||||
args = ['-display', 'none', '-vga', 'none']
|
args = ['-display', 'none', '-vga', 'none']
|
||||||
|
|
||||||
if self._qmp_set:
|
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(
|
moncdev = "socket,id=mon,host={},port={}".format(
|
||||||
*self._monitor_address
|
*self._monitor_address
|
||||||
)
|
)
|
||||||
@ -337,10 +337,17 @@ class QEMUMachine:
|
|||||||
self._remove_files.append(self._console_address)
|
self._remove_files.append(self._console_address)
|
||||||
|
|
||||||
if self._qmp_set:
|
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):
|
if isinstance(self._monitor_address, str):
|
||||||
self._remove_files.append(self._monitor_address)
|
self._remove_files.append(self._monitor_address)
|
||||||
|
monitor_address = self._monitor_address
|
||||||
self._qmp_connection = QEMUMonitorProtocol(
|
self._qmp_connection = QEMUMonitorProtocol(
|
||||||
self._monitor_address,
|
address=monitor_address,
|
||||||
|
sock=sock,
|
||||||
server=True,
|
server=True,
|
||||||
nickname=self._name
|
nickname=self._name
|
||||||
)
|
)
|
||||||
@ -360,6 +367,8 @@ class QEMUMachine:
|
|||||||
))
|
))
|
||||||
|
|
||||||
def _post_launch(self) -> None:
|
def _post_launch(self) -> None:
|
||||||
|
if self._sock_pair:
|
||||||
|
self._sock_pair[0].close()
|
||||||
if self._qmp_connection:
|
if self._qmp_connection:
|
||||||
self._qmp.accept(self._qmp_timer)
|
self._qmp.accept(self._qmp_timer)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user