From nobody Fri Apr 26 01:38:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=yadro.com ARC-Seal: i=1; a=rsa-sha256; t=1565609629; cv=none; d=zoho.com; s=zohoarc; b=aNBS0jnoffO5n8GfZ2/OEudOPR79pkPLERcagwWIOrJRYR9qCw+COiQzMq5JN7nu6sSgrdKJ1XYGFggWco4aE6eDT8CSMTiaRNq9GF6c3LOvxEQpbl6icFnFDJDX8tAbILK3E68ph3OJg8uMCfwt81eslrbBNEOABu7ysTUauAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565609629; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=sCw5tw5VLMcTuQOJAjrfTUZRkHF2r1TB3m9SPGftAVo=; b=kkpJB0P4bOLTdFJUFXKimY+lYMbqagF6jATlL6BsQUyzIipJjMlY5/aN69ZRXOEakeyIHGRFZSVCIh40+DdGH+04nzlbahejOR7RctC2xvoMuc8C+KTU+HrpU0bp9t29lYgJQWqsOMKGDfZD+ayaqCtv/xctbBB11GBGxue6dec= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565609629020995.9562342666213; Mon, 12 Aug 2019 04:33:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C2106909C; Mon, 12 Aug 2019 11:33:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E195646A4; Mon, 12 Aug 2019 11:33:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 821DE180B536; Mon, 12 Aug 2019 11:33:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7CBXhLC015597 for ; Mon, 12 Aug 2019 07:33:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id A564019C4F; Mon, 12 Aug 2019 11:33:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A03AC19C70 for ; Mon, 12 Aug 2019 11:33:41 +0000 (UTC) Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40EA18DA5B for ; Mon, 12 Aug 2019 11:33:40 +0000 (UTC) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 500D4412D6; Mon, 12 Aug 2019 11:33:38 +0000 (UTC) Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X1Jj0A_hJDvM; Mon, 12 Aug 2019 14:33:37 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 5F8DF412D0; Mon, 12 Aug 2019 14:33:36 +0300 (MSK) Received: from localhost (172.17.128.60) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Mon, 12 Aug 2019 14:33:35 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :x-mailer:message-id:date:date:subject:subject:from:from :received:received:received; s=mta-01; t=1565609617; x= 1567424018; bh=P8pH2iIAowHQwZXbfBfYDdFQjk7ZBH6B0KLqHv1SqEk=; b=N eQiRxJLyVvmcX2KlJvSGX9IgyE5aLiU4pw6bbL0GJPAcPwJb9pfS7ep9m9COsI5Z RJrBlRZBVqFjd/9KrPqI4aFbv0FRSANjIuXYRAEd6S99R3rbhLrcZeS4aIcTdIaZ YvUX+xRnF0L9Iyr06TpasUtMnleqSqgm9M4kfBKuMg= X-Virus-Scanned: amavisd-new at yadro.com From: Roman Bolshakov To: Date: Mon, 12 Aug 2019 14:15:57 +0300 Message-ID: <20190812111556.50439-1-r.bolshakov@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.128.60] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 12 Aug 2019 11:33:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 12 Aug 2019 11:33:40 +0000 (UTC) for IP:'89.207.88.252' DOMAIN:'mta-02.yadro.com' HELO:'mta-01.yadro.com' FROM:'r.bolshakov@yadro.com' RCPT:'' X-RedHat-Spam-Score: -0.1 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS) 89.207.88.252 mta-02.yadro.com 89.207.88.252 mta-02.yadro.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Roman Bolshakov , Daniel Henrique Barboza , nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2] tools: console: Relax stream EOF handling X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 12 Aug 2019 11:33:48 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Regular VM shutdown triggers the error for existing session of virsh console and it returns with non-zero exit code: error: internal error: console stream EOF The message and status code are misleading because there's no real error. virStreamRecv returns 0 when the end of the stream is reached. In that case, virStreamFinish should be used to get confirmation of stream completion. virSteramAbort is used otherwise to terminate the stream early before an EOF. Fixes: 29f2b5248c6 ("tools: console: pass stream/fd errors to user") Signed-off-by: Roman Bolshakov --- Changes since v1: - Added needAbort parameter to virConsoleShutdown to specify if finish or abort is needed - Use it (needAbort =3D false) to finish stream after EOF from virStreamRecv - Print internal error if virStreamFinish or virStreamAbort do not succeed tools/virsh-console.c | 44 ++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tools/virsh-console.c b/tools/virsh-console.c index e16f841e57..ad514a99a7 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -97,7 +97,7 @@ virConsoleHandleSignal(int sig ATTRIBUTE_UNUSED) =20 =20 static void -virConsoleShutdown(virConsolePtr con) +virConsoleShutdown(virConsolePtr con, bool needAbort) { virErrorPtr err =3D virGetLastError(); =20 @@ -105,8 +105,15 @@ virConsoleShutdown(virConsolePtr con) virCopyLastError(&con->error); =20 if (con->st) { + int termError; virStreamEventRemoveCallback(con->st); - virStreamAbort(con->st); + if (needAbort) + termError =3D virStreamAbort(con->st); + else + termError =3D virStreamFinish(con->st); + if (termError < 0) + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot terminate console stream")); virStreamFree(con->st); con->st =3D NULL; } @@ -158,7 +165,7 @@ virConsoleEventOnStream(virStreamPtr st, if (avail < 1024) { if (VIR_REALLOC_N(con->streamToTerminal.data, con->streamToTerminal.length + 1024) < 0) { - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } con->streamToTerminal.length +=3D 1024; @@ -172,11 +179,10 @@ virConsoleEventOnStream(virStreamPtr st, if (got =3D=3D -2) goto cleanup; /* blocking */ if (got <=3D 0) { + bool needAbort =3D true; if (got =3D=3D 0) - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("console stream EOF")); - - virConsoleShutdown(con); + needAbort =3D false; + virConsoleShutdown(con, needAbort); goto cleanup; } con->streamToTerminal.offset +=3D got; @@ -195,7 +201,7 @@ virConsoleEventOnStream(virStreamPtr st, if (done =3D=3D -2) goto cleanup; /* blocking */ if (done < 0) { - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } memmove(con->terminalToStream.data, @@ -216,7 +222,7 @@ virConsoleEventOnStream(virStreamPtr st, =20 if (events & VIR_STREAM_EVENT_ERROR || events & VIR_STREAM_EVENT_HANGUP) { - virConsoleShutdown(con); + virConsoleShutdown(con, true); } =20 cleanup: @@ -246,7 +252,7 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, if (avail < 1024) { if (VIR_REALLOC_N(con->terminalToStream.data, con->terminalToStream.length + 1024) < 0) { - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } con->terminalToStream.length +=3D 1024; @@ -260,17 +266,17 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, if (got < 0) { if (errno !=3D EAGAIN) { virReportSystemError(errno, "%s", _("cannot read from stdi= n")); - virConsoleShutdown(con); + virConsoleShutdown(con, true); } goto cleanup; } if (got =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdin")= ); - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } if (con->terminalToStream.data[con->terminalToStream.offset] =3D= =3D con->escapeChar) { - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } =20 @@ -283,13 +289,13 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, =20 if (events & VIR_EVENT_HANDLE_ERROR) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("IO error on stdin"= )); - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } =20 if (events & VIR_EVENT_HANDLE_HANGUP) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdin")); - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } =20 @@ -322,7 +328,7 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED, if (done < 0) { if (errno !=3D EAGAIN) { virReportSystemError(errno, "%s", _("cannot write to stdou= t")); - virConsoleShutdown(con); + virConsoleShutdown(con, true); } goto cleanup; } @@ -344,13 +350,13 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED, =20 if (events & VIR_EVENT_HANDLE_ERROR) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("IO error stdout")); - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } =20 if (events & VIR_EVENT_HANDLE_HANGUP) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdout")); - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } =20 @@ -489,7 +495,7 @@ virshRunConsole(vshControl *ctl, ret =3D 0; =20 cleanup: - virConsoleShutdown(con); + virConsoleShutdown(con, true); =20 if (ret < 0) { vshResetLibvirtError(); --=20 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list