From nobody Tue May 7 23:53:39 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566567226; cv=none; d=zoho.com; s=zohoarc; b=egcYZTJNJhzk7BxNLbMdu2kkdkbcZobkcBRlNOMI2CH2FpPI91Y36UnGj6oMkEBQOzWuaNsSlJHh905GJYkwbBXtVw82HcrNrTrUXYB67Rrr44tVcVdkDYwU4Z7HVEgF0ppau4+nqvbWEH4QvO5T3HCv/3LnL/AxAH8piNOJtQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566567226; h=Content-Type:Content-Transfer-Encoding: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=iVee2hz7VC2z46DToO4pQmln74onDdXeMNPhMJvSijA=; b=LzWI0WKL5+eUkVamdbe4/pqudbS4KbODdqEu7KLsJRj+AMiTi3ImFWYMJ0NeuCNvYrZ2cJ6DKLg4tbG7OJ9bxHe+KPQ9JmUWR6Sn6p3ulT7cVLyQnSgVLIJNRhxDIzmIGs0LD+4etHK6fEOZlHx5MgmjDlltqyo8F23nHkRo4fg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass 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 1566567226146195.01630352446261; Fri, 23 Aug 2019 06:33:46 -0700 (PDT) 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 166FD8980FD; Fri, 23 Aug 2019 13:33:45 +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 E62566CE7A; Fri, 23 Aug 2019 13:33:44 +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 AB7BF180B536; Fri, 23 Aug 2019 13:33:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7NDXg7e000316 for ; Fri, 23 Aug 2019 09:33:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id C082B60933; Fri, 23 Aug 2019 13:33:42 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49F87608C2 for ; Fri, 23 Aug 2019 13:33:37 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 23 Aug 2019 15:33:36 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: Allow graceful console shutdown 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Fri, 23 Aug 2019 13:33:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Currently, whenever there's a regular EOF on the console stream or an error the virStreamAbort() is called regardless. While this may not actually break anything, we should call virStreamFinish() to let the daemon know we've successfully received all the data and are shutting down the stream gracefully. Signed-off-by: Michal Privoznik Reviewed-by: Roman Bolshakov --- tools/virsh-console.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tools/virsh-console.c b/tools/virsh-console.c index a235a9a283..900faa5087 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -97,7 +97,8 @@ virConsoleHandleSignal(int sig ATTRIBUTE_UNUSED) =20 =20 static void -virConsoleShutdown(virConsolePtr con) +virConsoleShutdown(virConsolePtr con, + bool graceful) { virErrorPtr err =3D virGetLastError(); =20 @@ -105,10 +106,18 @@ virConsoleShutdown(virConsolePtr con) virCopyLastError(&con->error); =20 if (con->st) { + int rc; + virStreamEventRemoveCallback(con->st); - if (virStreamAbort(con->st) < 0) + if (graceful) + rc =3D virStreamFinish(con->st); + else + rc =3D virStreamAbort(con->st); + + if (rc < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot terminate console stream")); + } virStreamFree(con->st); con->st =3D NULL; } @@ -160,7 +169,7 @@ virConsoleEventOnStream(virStreamPtr st, if (avail < 1024) { if (VIR_REALLOC_N(con->streamToTerminal.data, con->streamToTerminal.length + 1024) < 0) { - virConsoleShutdown(con); + virConsoleShutdown(con, false); goto cleanup; } con->streamToTerminal.length +=3D 1024; @@ -174,7 +183,7 @@ virConsoleEventOnStream(virStreamPtr st, if (got =3D=3D -2) goto cleanup; /* blocking */ if (got <=3D 0) { - virConsoleShutdown(con); + virConsoleShutdown(con, got =3D=3D 0); goto cleanup; } con->streamToTerminal.offset +=3D got; @@ -193,7 +202,7 @@ virConsoleEventOnStream(virStreamPtr st, if (done =3D=3D -2) goto cleanup; /* blocking */ if (done < 0) { - virConsoleShutdown(con); + virConsoleShutdown(con, done =3D=3D 0); goto cleanup; } memmove(con->terminalToStream.data, @@ -214,7 +223,7 @@ virConsoleEventOnStream(virStreamPtr st, =20 if (events & VIR_STREAM_EVENT_ERROR || events & VIR_STREAM_EVENT_HANGUP) { - virConsoleShutdown(con); + virConsoleShutdown(con, false); } =20 cleanup: @@ -244,7 +253,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, false); goto cleanup; } con->terminalToStream.length +=3D 1024; @@ -258,17 +267,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, false); } goto cleanup; } if (got =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdin")= ); - virConsoleShutdown(con); + virConsoleShutdown(con, false); goto cleanup; } if (con->terminalToStream.data[con->terminalToStream.offset] =3D= =3D con->escapeChar) { - virConsoleShutdown(con); + virConsoleShutdown(con, true); goto cleanup; } =20 @@ -281,13 +290,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, false); goto cleanup; } =20 if (events & VIR_EVENT_HANDLE_HANGUP) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdin")); - virConsoleShutdown(con); + virConsoleShutdown(con, false); goto cleanup; } =20 @@ -320,7 +329,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, false); } goto cleanup; } @@ -342,13 +351,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, false); goto cleanup; } =20 if (events & VIR_EVENT_HANDLE_HANGUP) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("EOF on stdout")); - virConsoleShutdown(con); + virConsoleShutdown(con, false); goto cleanup; } =20 @@ -487,7 +496,7 @@ virshRunConsole(vshControl *ctl, ret =3D 0; =20 cleanup: - virConsoleShutdown(con); + virConsoleShutdown(con, ret =3D=3D 0); =20 if (ret < 0) { vshResetLibvirtError(); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list