mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
python/qemu: Add ConsoleSocket for optional use in QEMUMachine
We add the ConsoleSocket object, which has a socket interface and which will consume all arriving characters on the socket, placing them into an in memory buffer. This will also provide those chars via recv() as would a regular socket. ConsoleSocket also has the option of dumping the console bytes to a log file. We also give QEMUMachine the option of using ConsoleSocket to drain and to use for logging console to a file. By default QEMUMachine does not use ConsoleSocket. This is added in preparation for use by basevm.py in a later commit. This is a workaround we found was needed for basevm.py since there is a known issue where QEMU will hang waiting for console characters to be consumed. Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: Cleber Rosa <crosa@redhat.com> Signed-off-by: Robert Foley <robert.foley@linaro.org> Reviewed-by: Peter Puhov <peter.puhov@linaro.org> Acked-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200601211421.1277-9-robert.foley@linaro.org> Message-Id: <20200701135652.1366-13-alex.bennee@linaro.org>
This commit is contained in:
parent
df00168039
commit
0fc8f660c5
2 changed files with 129 additions and 4 deletions
|
@ -26,6 +26,7 @@ import socket
|
|||
import tempfile
|
||||
from typing import Optional, Type
|
||||
from types import TracebackType
|
||||
from qemu.console_socket import ConsoleSocket
|
||||
|
||||
from . import qmp
|
||||
|
||||
|
@ -75,7 +76,8 @@ class QEMUMachine:
|
|||
|
||||
def __init__(self, binary, args=None, wrapper=None, name=None,
|
||||
test_dir="/var/tmp", monitor_address=None,
|
||||
socket_scm_helper=None, sock_dir=None):
|
||||
socket_scm_helper=None, sock_dir=None,
|
||||
drain_console=False, console_log=None):
|
||||
'''
|
||||
Initialize a QEMUMachine
|
||||
|
||||
|
@ -86,6 +88,9 @@ class QEMUMachine:
|
|||
@param test_dir: where to create socket and log file
|
||||
@param monitor_address: address for QMP monitor
|
||||
@param socket_scm_helper: helper program, required for send_fd_scm()
|
||||
@param sock_dir: where to create socket (overrides test_dir for sock)
|
||||
@param console_log: (optional) path to console log file
|
||||
@param drain_console: (optional) True to drain console socket to buffer
|
||||
@note: Qemu process is not started until launch() is used.
|
||||
'''
|
||||
if args is None:
|
||||
|
@ -122,6 +127,12 @@ class QEMUMachine:
|
|||
self._console_address = None
|
||||
self._console_socket = None
|
||||
self._remove_files = []
|
||||
self._console_log_path = console_log
|
||||
if self._console_log_path:
|
||||
# In order to log the console, buffering needs to be enabled.
|
||||
self._drain_console = True
|
||||
else:
|
||||
self._drain_console = drain_console
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
@ -580,7 +591,11 @@ class QEMUMachine:
|
|||
Returns a socket connected to the console
|
||||
"""
|
||||
if self._console_socket is None:
|
||||
self._console_socket = socket.socket(socket.AF_UNIX,
|
||||
socket.SOCK_STREAM)
|
||||
self._console_socket.connect(self._console_address)
|
||||
if self._drain_console:
|
||||
self._console_socket = ConsoleSocket(self._console_address,
|
||||
file=self._console_log_path)
|
||||
else:
|
||||
self._console_socket = socket.socket(socket.AF_UNIX,
|
||||
socket.SOCK_STREAM)
|
||||
self._console_socket.connect(self._console_address)
|
||||
return self._console_socket
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue