From nobody Tue Feb 10 06:04:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524248554170599.2836416358188; Fri, 20 Apr 2018 11:22:34 -0700 (PDT) Received: from localhost ([::1]:50151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9ag1-0005q8-Ui for importer@patchew.org; Fri, 20 Apr 2018 14:22:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9adt-0004Sg-S2 for qemu-devel@nongnu.org; Fri, 20 Apr 2018 14:20:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9ads-0004bT-M6 for qemu-devel@nongnu.org; Fri, 20 Apr 2018 14:20:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f9adr-0004Ws-Qg for qemu-devel@nongnu.org; Fri, 20 Apr 2018 14:20:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 193A17B133; Fri, 20 Apr 2018 18:20:15 +0000 (UTC) Received: from localhost (ovpn-116-52.gru2.redhat.com [10.97.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id CACE460F80; Fri, 20 Apr 2018 18:20:06 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 20 Apr 2018 15:19:28 -0300 Message-Id: <20180420181951.7252-2-ehabkost@redhat.com> In-Reply-To: <20180420181951.7252-1-ehabkost@redhat.com> References: <20180420181951.7252-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 20 Apr 2018 18:20:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 01/24] qemu.py: Introduce _create_console() method X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= , Fam Zheng , Stefan Hajnoczi , Amador Pahim , Cleber Rosa , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Amador Pahim This patch adds the QEMUMachine._create_console() method, which returns a list with the chardev console device arguments to be used in the qemu command line. Signed-off-by: Amador Pahim [ehabkost: reword commit message] Signed-off-by: Eduardo Habkost --- scripts/qemu.py | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 08a3e9af5a..9e9d502543 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -55,7 +55,7 @@ class QEMUMachine(object): =20 def __init__(self, binary, args=3DNone, wrapper=3DNone, name=3DNone, test_dir=3D"/var/tmp", monitor_address=3DNone, - socket_scm_helper=3DNone): + socket_scm_helper=3DNone, arch=3DNone): ''' Initialize a QEMUMachine =20 @@ -91,6 +91,10 @@ class QEMUMachine(object): self._test_dir =3D test_dir self._temp_dir =3D None self._launched =3D False + if arch is None: + arch =3D binary.split('-')[-1] + self._arch =3D arch + self._console_address =3D None =20 # just in case logging wasn't configured by the main script: logging.basicConfig() @@ -179,6 +183,39 @@ class QEMUMachine(object): '-mon', 'chardev=3Dmon,mode=3Dcontrol', '-display', 'none', '-vga', 'none'] =20 + def _create_console(self, console_address): + for item in self._args: + for option in ['isa-serial', 'spapr-vty', 'sclpconsole']: + if option in item: + return [] + + chardev =3D 'socket,id=3Dconsole,{address},server,nowait' + if console_address is None: + console_address =3D tempfile.mktemp() + chardev =3D chardev.format(address=3D'path=3D%s' % + console_address) + elif isinstance(console_address, tuple): + chardev =3D chardev.format(address=3D'host=3D%s,port=3D%s' % + (console_address[0], + console_address[1])) + else: + chardev =3D chardev.format(address=3D'path=3D%s' % console_add= ress) + + self._console_address =3D console_address + + device =3D '{dev_type},chardev=3Dconsole' + if '86' in self._arch: + device =3D device.format(dev_type=3D'isa-serial') + elif 'ppc' in self._arch: + device =3D device.format(dev_type=3D'spapr-vty') + elif 's390x' in self._arch: + device =3D device.format(dev_type=3D'sclpconsole') + else: + return [] + + return ['-chardev', chardev, + '-device', device] + def _pre_launch(self): self._temp_dir =3D tempfile.mkdtemp(dir=3Dself._test_dir) if self._monitor_address is not None: @@ -206,7 +243,7 @@ class QEMUMachine(object): shutil.rmtree(self._temp_dir) self._temp_dir =3D None =20 - def launch(self): + def launch(self, console_address=3DNone): """ Launch the VM and make sure we cleanup and expose the command line/output in case of exception @@ -218,7 +255,7 @@ class QEMUMachine(object): self._iolog =3D None self._qemu_full_args =3D None try: - self._launch() + self._launch(console_address) self._launched =3D True except: self.shutdown() @@ -230,12 +267,14 @@ class QEMUMachine(object): LOG.debug('Output: %r', self._iolog) raise =20 - def _launch(self): + def _launch(self, console_address): '''Launch the VM and establish a QMP connection''' devnull =3D open(os.path.devnull, 'rb') self._pre_launch() + bargs =3D self._base_args() + bargs.extend(self._create_console(console_address)) self._qemu_full_args =3D (self._wrapper + [self._binary] + - self._base_args() + self._args) + bargs + self.args) self._popen =3D subprocess.Popen(self._qemu_full_args, stdin=3Ddevnull, stdout=3Dself._qemu_log_file, --=20 2.14.3