From nobody Sun May 5 07:39:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=jfalk.de Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638473095694534.403910661708; Thu, 2 Dec 2021 11:24:55 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-JHfRsaqmP6OvNsEgitlB-Q-1; Thu, 02 Dec 2021 14:24:52 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3E9F384B9A4; Thu, 2 Dec 2021 19:24:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D837E60C05; Thu, 2 Dec 2021 19:24:43 +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 D5A474BB7C; Thu, 2 Dec 2021 19:24:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B2J5NQx023004 for ; Thu, 2 Dec 2021 14:05:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3A4B74010E8C; Thu, 2 Dec 2021 19:05:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34AE740CFD0C for ; Thu, 2 Dec 2021 19:05:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 192DB185A7B4 for ; Thu, 2 Dec 2021 19:05:23 +0000 (UTC) Received: from xanadoo.inet.jfalk.de (xanadoo.inet.jfalk.de [78.47.248.194]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-5-KT_sO4FjPdGYZN3zpiR9aA-1; Thu, 02 Dec 2021 14:05:20 -0500 X-MC-Unique: JHfRsaqmP6OvNsEgitlB-Q-1 X-MC-Unique: KT_sO4FjPdGYZN3zpiR9aA-1 X-Envelope-From: X-Envelope-From: From: joachim.falk@jfalk.de To: libvir-list@redhat.com X-Header-Checks: smtp_header_checks Subject: [PATCH] Fix reboot command for LXC containers Date: Thu, 2 Dec 2021 19:56:07 +0100 Message-Id: <20211202185607.700979-1-joachim@jfalk.de> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1B2J5NQx023004 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Thu, 02 Dec 2021 14:20:03 -0500 Cc: Joachim Falk 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1638473097776100001 Content-Type: text/plain; charset="utf-8" From: Joachim Falk The virNetDaemonQuit(dmn) command in virLXCControllerSignalChildIO triggers= an early close of all clients of lxc_controller. Here, libvirtd itself is a cl= ient of this controller, and the client connection is used to notify libvirtd if= a reboot of the container is required. However, the client connection was clo= sed before such a status could be sent to libvirtd. To fix this bug, we will immediately send the reboot or shutdown status of the container to libvirtd, and only after client disconnect will we trigger virNetDaemonQuit. Fixes: #237 Bug: https://gitlab.com/libvirt/libvirt/-/issues/237 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D991773 Signed-off-by: Joachim Falk Reviewed-by: Michal Privoznik --- src/lxc/lxc_controller.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 444f728af4..039efcd7c7 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -894,8 +894,10 @@ static void virLXCControllerClientCloseHook(virNetServ= erClient *client) virLXCController *ctrl =3D virNetServerClientGetPrivateData(client); =20 VIR_DEBUG("Client %p has closed", client); - if (ctrl->client =3D=3D client) + if (ctrl->client =3D=3D client) { ctrl->client =3D NULL; + VIR_DEBUG("Client has gone away"); + } if (ctrl->inShutdown) { VIR_DEBUG("Arm timer to quit event loop"); virEventUpdateTimeout(ctrl->timerShutdown, 0); @@ -1006,8 +1008,11 @@ static int lxcControllerClearCapabilities(void) static bool wantReboot; static virMutex lock =3D VIR_MUTEX_INITIALIZER; =20 +static int +virLXCControllerEventSendExit(virLXCController *ctrl, + int exitstatus); =20 -static void virLXCControllerSignalChildIO(virNetDaemon *dmn, +static void virLXCControllerSignalChildIO(virNetDaemon *dmn G_GNUC_UNUSED, siginfo_t *info G_GNUC_UNUSED, void *opaque) { @@ -1018,7 +1023,6 @@ static void virLXCControllerSignalChildIO(virNetDaemo= n *dmn, ret =3D waitpid(-1, &status, WNOHANG); VIR_DEBUG("Got sig child %d vs %lld", ret, (long long)ctrl->initpid); if (ret =3D=3D ctrl->initpid) { - virNetDaemonQuit(dmn); virMutexLock(&lock); if (WIFSIGNALED(status) && WTERMSIG(status) =3D=3D SIGHUP) { @@ -1026,6 +1030,7 @@ static void virLXCControllerSignalChildIO(virNetDaemo= n *dmn, wantReboot =3D true; } virMutexUnlock(&lock); + virLXCControllerEventSendExit(ctrl, wantReboot ? 1 : 0); } } =20 @@ -2276,9 +2281,10 @@ virLXCControllerEventSendExit(virLXCController *ctrl, VIR_DEBUG("Waiting for client to complete dispatch"); ctrl->inShutdown =3D true; virNetServerClientDelayedClose(ctrl->client); - virNetDaemonRun(ctrl->daemon); + } else { + VIR_DEBUG("Arm timer to quit event loop"); + virEventUpdateTimeout(ctrl->timerShutdown, 0); } - VIR_DEBUG("Client has gone away"); return 0; } =20 @@ -2430,8 +2436,6 @@ virLXCControllerRun(virLXCController *ctrl) =20 rc =3D virLXCControllerMain(ctrl); =20 - virLXCControllerEventSendExit(ctrl, rc); - cleanup: VIR_FORCE_CLOSE(control[0]); VIR_FORCE_CLOSE(control[1]); --=20 2.30.2