From nobody Wed May 8 14:05:18 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548423130304276.4997524090262; Fri, 25 Jan 2019 05:32:10 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6354BA7878; Fri, 25 Jan 2019 13:32:08 +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 27D7D166A0; Fri, 25 Jan 2019 13:32:08 +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 C1B034ED42; Fri, 25 Jan 2019 13:32:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0PDVtOC002027 for ; Fri, 25 Jan 2019 08:31:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 632E91048125; Fri, 25 Jan 2019 13:31:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF03E1048117 for ; Fri, 25 Jan 2019 13:31:54 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 25 Jan 2019 14:31:45 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] lxc: Use correct job type for destroying a domain 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 25 Jan 2019 13:32:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Not that it would matter because LXC driver doesn't differentiate the job types so far, but nevertheless the Destroy() should grab LXC_JOB_DESTROY. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/lxc/lxc_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index df15a0da50..6c0f9b57db 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1462,7 +1462,7 @@ lxcDomainDestroyFlags(virDomainPtr dom, if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) + if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_DESTROY) < 0) goto cleanup; =20 if (virDomainObjCheckActive(vm) < 0) --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 14:05:18 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548423120415709.9030844906786; Fri, 25 Jan 2019 05:32:00 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46D2137EEA; Fri, 25 Jan 2019 13:31:58 +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 B9AFB16BEC; Fri, 25 Jan 2019 13:31:57 +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 B0BD74ED28; Fri, 25 Jan 2019 13:31:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0PDVu9g002036 for ; Fri, 25 Jan 2019 08:31:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 37B731048125; Fri, 25 Jan 2019 13:31:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id B18731048117 for ; Fri, 25 Jan 2019 13:31:55 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 25 Jan 2019 14:31:46 +0100 Message-Id: <97ea112e63ecad86057639fee582217f1789bfe8.1548422575.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] vircgroup: Try harder to kill cgroup 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 25 Jan 2019 13:31:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Prior to rewrite of cgroup code we only had one backend to try. After the rewrite the virCgroupBackendGetAll() returns both backends (for v1 and v2). However, not both have to really be present on the system which results in killRecursive callback failing which in turn might mean we won't try the other backend. At the same time, this function reports no error as it should. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/util/vircgroup.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 3ebb3b0a0f..b8b56f1263 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2606,6 +2606,7 @@ virCgroupKillRecursive(virCgroupPtr group, int signum) int ret =3D 0; int rc; size_t i; + bool backendAvailable =3D false; virCgroupBackendPtr *backends =3D virCgroupBackendGetAll(); virHashTablePtr pids =3D virHashCreateFull(100, NULL, @@ -2616,13 +2617,9 @@ virCgroupKillRecursive(virCgroupPtr group, int signu= m) =20 VIR_DEBUG("group=3D%p path=3D%s signum=3D%d", group, group->path, sign= um); =20 - if (!backends) { - ret =3D -1; - goto cleanup; - } - for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { - if (backends[i]) { + if (backends && backends[i] && backends[i]->available()) { + backendAvailable =3D true; rc =3D backends[i]->killRecursive(group, signum, pids); if (rc < 0) { ret =3D -1; @@ -2633,6 +2630,12 @@ virCgroupKillRecursive(virCgroupPtr group, int signu= m) } } =20 + if (!backends || !backendAvailable) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("no cgroup backend available")); + goto cleanup; + } + cleanup: virHashFree(pids); return ret; --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 14:05:18 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548423130641555.7861711856968; Fri, 25 Jan 2019 05:32:10 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 575FCC0C274C; Fri, 25 Jan 2019 13:32:08 +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 1318F17D6B; Fri, 25 Jan 2019 13:32:08 +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 BECAD4ED41; Fri, 25 Jan 2019 13:32:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0PDVveO002041 for ; Fri, 25 Jan 2019 08:31:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0B18F1048125; Fri, 25 Jan 2019 13:31:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 865E11048117 for ; Fri, 25 Jan 2019 13:31:56 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 25 Jan 2019 14:31:47 +0100 Message-Id: <14c22d81885ca1b16de4f7b85f5f8b729b123779.1548422575.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] lxc: Restore seclabels after the container is killed 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 25 Jan 2019 13:32:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Due to a bug the seclabels are restored before any PID in the container is killed. This should be done afterwards in virLXCProcessCleanup. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/lxc/lxc_process.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 33c806630b..a3481bfa08 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -180,6 +180,17 @@ static void virLXCProcessCleanup(virLXCDriverPtr drive= r, VIR_FREE(xml); } =20 + virSecurityManagerRestoreAllLabel(driver->securityManager, + vm->def, false, false); + virSecurityManagerReleaseLabel(driver->securityManager, vm->def); + /* Clear out dynamically assigned labels */ + if (vm->def->nseclabels && + vm->def->seclabels[0]->type =3D=3D VIR_DOMAIN_SECLABEL_DYNAMIC) { + VIR_FREE(vm->def->seclabels[0]->model); + VIR_FREE(vm->def->seclabels[0]->label); + VIR_FREE(vm->def->seclabels[0]->imagelabel); + } + /* Stop autodestroy in case guest is restarted */ virCloseCallbacksUnset(driver->closeCallbacks, vm, lxcProcessAutoDestroy); @@ -836,17 +847,6 @@ int virLXCProcessStop(virLXCDriverPtr driver, =20 priv =3D vm->privateData; =20 - virSecurityManagerRestoreAllLabel(driver->securityManager, - vm->def, false, false); - virSecurityManagerReleaseLabel(driver->securityManager, vm->def); - /* Clear out dynamically assigned labels */ - if (vm->def->nseclabels && - vm->def->seclabels[0]->type =3D=3D VIR_DOMAIN_SECLABEL_DYNAMIC) { - VIR_FREE(vm->def->seclabels[0]->model); - VIR_FREE(vm->def->seclabels[0]->label); - VIR_FREE(vm->def->seclabels[0]->imagelabel); - } - /* If the LXC domain is suspended we send all processes a SIGKILL * and thaw them. Upon wakeup the process sees the pending signal * and dies immediately. It is guaranteed that priv->cgroup !=3D NULL --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 14:05:18 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548423134752344.9905753322787; Fri, 25 Jan 2019 05:32:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2EF3A7EF; Fri, 25 Jan 2019 13:32:12 +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 BDABD61533; Fri, 25 Jan 2019 13:32:12 +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 64D694ED45; Fri, 25 Jan 2019 13:32:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0PDVvR7002052 for ; Fri, 25 Jan 2019 08:31:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id D4C7D1048125; Fri, 25 Jan 2019 13:31:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AA931048117 for ; Fri, 25 Jan 2019 13:31:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 25 Jan 2019 14:31:48 +0100 Message-Id: <0269ab11be5e99c4b5a1c54774c1070c92b5ac25.1548422575.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] virinitctl: Expose fifo paths and allow caller to chose one 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 25 Jan 2019 13:32:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So far the virInitctlSetRunLevel() is fully automatic. It finds the correct fifo to use to talk to the init and it will set the desired runlevel. Well, callers (so far there is just one) will need to inspect the fifo a bit just before the runlevel is set. Therefore, expose the internal list of fifos and also allow caller to explicitly use one. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 2 +- src/util/virinitctl.c | 66 +++++++++++++++++++++++++--------------- src/util/virinitctl.h | 6 +++- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 89b8ca3b4f..af490be12c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2049,6 +2049,7 @@ virIdentitySetX509DName; =20 =20 # util/virinitctl.h +virInitctlFifos; virInitctlSetRunLevel; =20 =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 6c0f9b57db..943d199616 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3277,7 +3277,7 @@ lxcDomainInitctlCallback(pid_t pid ATTRIBUTE_UNUSED, void *opaque) { int *command =3D opaque; - return virInitctlSetRunLevel(*command); + return virInitctlSetRunLevel(NULL, *command); } =20 =20 diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index 0b06743151..8f8bbae4bc 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -101,7 +101,20 @@ struct virInitctlRequest { verify(sizeof(struct virInitctlRequest) =3D=3D 384); # endif =20 -/* + +/* List of fifos that inits are known to listen on */ +const char *virInitctlFifos[] =3D { + "/run/initctl", + "/dev/initctl", + "/etc/.initctl", +}; + + +/** + * virInitctlSetRunLevel: + * @fifo: the path to fifo that init listens on (can be NULL for autodetec= tion) + * @level: the desired runlevel + * * Send a message to init to change the runlevel. This function is * asynchronous-signal-safe (thus safe to use after fork of a * multithreaded parent) - which is good, because it should only be @@ -110,18 +123,14 @@ struct virInitctlRequest { * Returns 1 on success, 0 if initctl does not exist, -1 on error */ int -virInitctlSetRunLevel(virInitctlRunLevel level) +virInitctlSetRunLevel(const char *fifo, + virInitctlRunLevel level) { struct virInitctlRequest req; int fd =3D -1; int ret =3D -1; - const char *initctl_fifo =3D NULL; + const int open_flags =3D O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY; size_t i =3D 0; - const char *initctl_fifos[] =3D { - "/run/initctl", - "/dev/initctl", - "/etc/.initctl", - }; =20 memset(&req, 0, sizeof(req)); =20 @@ -131,31 +140,39 @@ virInitctlSetRunLevel(virInitctlRunLevel level) /* Yes it is an 'int' field, but wants a numeric character. Go figure = */ req.runlevel =3D '0' + level; =20 - for (i =3D 0; i < ARRAY_CARDINALITY(initctl_fifos); i++) { - initctl_fifo =3D initctl_fifos[i]; - - if ((fd =3D open(initctl_fifo, - O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY)) >=3D 0) - break; - - if (errno !=3D ENOENT) { + if (fifo) { + if ((fd =3D open(fifo, open_flags)) < 0) { virReportSystemError(errno, _("Cannot open init control %s"), - initctl_fifo); + fifo); goto cleanup; } - } + } else { + for (i =3D 0; i < ARRAY_CARDINALITY(virInitctlFifos); i++) { + fifo =3D virInitctlFifos[i]; =20 - /* Ensure we found a valid initctl fifo */ - if (fd < 0) { - ret =3D 0; - goto cleanup; + if ((fd =3D open(fifo, open_flags)) >=3D 0) + break; + + if (errno !=3D ENOENT) { + virReportSystemError(errno, + _("Cannot open init control %s"), + fifo); + goto cleanup; + } + } + + /* Ensure we found a valid initctl fifo */ + if (fd < 0) { + ret =3D 0; + goto cleanup; + } } =20 if (safewrite(fd, &req, sizeof(req)) !=3D sizeof(req)) { virReportSystemError(errno, _("Failed to send request to init control %s"= ), - initctl_fifo); + fifo); goto cleanup; } =20 @@ -166,7 +183,8 @@ virInitctlSetRunLevel(virInitctlRunLevel level) return ret; } #else -int virInitctlSetRunLevel(virInitctlRunLevel level ATTRIBUTE_UNUSED) +int virInitctlSetRunLevel(const char *fifo ATTRIBUTE_UNUSED, + virInitctlRunLevel level ATTRIBUTE_UNUSED) { virReportUnsupportedError(); return -1; diff --git a/src/util/virinitctl.h b/src/util/virinitctl.h index 7ac627883a..f12741c7c1 100644 --- a/src/util/virinitctl.h +++ b/src/util/virinitctl.h @@ -33,6 +33,10 @@ typedef enum { VIR_INITCTL_RUNLEVEL_LAST } virInitctlRunLevel; =20 -int virInitctlSetRunLevel(virInitctlRunLevel level); + +extern const char *virInitctlFifos[3]; + +int virInitctlSetRunLevel(const char *fifo, + virInitctlRunLevel level); =20 #endif /* LIBVIRT_VIRINITCTL_H */ --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 14:05:18 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548423135161340.1051744979925; Fri, 25 Jan 2019 05:32:15 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34D99C07EFFB; Fri, 25 Jan 2019 13:32:13 +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 EF98B166B7; Fri, 25 Jan 2019 13:32:12 +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 A627D180BAAC; Fri, 25 Jan 2019 13:32:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0PDVwgX002061 for ; Fri, 25 Jan 2019 08:31:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id A81781048125; Fri, 25 Jan 2019 13:31:58 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F4001048117 for ; Fri, 25 Jan 2019 13:31:58 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 25 Jan 2019 14:31:49 +0100 Message-Id: <9d8e4bc3595ec11a6c4360b46a1a4c48321a1a93.1548422575.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] lxc: Don't reboot host on virDomainReboot 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 25 Jan 2019 13:32:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If the container is really a simple one (init is just bash and the whole root is passed through) then virDomainReboot and virDomainShutdown will talk to the actual init within the host. Therefore, 'virsh shutdown $dom' will result in shutting down the host. True, at that point the container is shut down too but looks a bit harsh to me. The solution is to check if the init inside the container is or is not the same as the init running on the host. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/lxc/lxc_domain.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ src/lxc/lxc_domain.h | 4 +++ src/lxc/lxc_driver.c | 17 ++-------- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index b197f9dfc2..73023c0a57 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -32,6 +32,7 @@ #include "virfile.h" #include "virtime.h" #include "virsystemd.h" +#include "virinitctl.h" =20 #define VIR_FROM_THIS VIR_FROM_LXC #define LXC_NAMESPACE_HREF "http://libvirt.org/schemas/domain/lxc/1.0" @@ -416,3 +417,79 @@ virLXCDomainGetMachineName(virDomainDefPtr def, pid_t = pid) =20 return ret; } + + +typedef struct _lxcDomainInitctlCallbackData lxcDomainInitctlCallbackData; +struct _lxcDomainInitctlCallbackData { + int runlevel; + bool st_valid[ARRAY_CARDINALITY(virInitctlFifos)]; + struct stat st[ARRAY_CARDINALITY(virInitctlFifos)]; +}; + + +static int +lxcDomainInitctlCallback(pid_t pid ATTRIBUTE_UNUSED, + void *opaque) +{ + lxcDomainInitctlCallbackData *data =3D opaque; + size_t i; + + for (i =3D 0; i < ARRAY_CARDINALITY(virInitctlFifos); i++) { + const char *fifo =3D virInitctlFifos[i]; + struct stat cont_sb; + + if (stat(fifo, &cont_sb) < 0) { + if (errno =3D=3D ENOENT) + continue; + + virReportSystemError(errno, _("Unable to stat %s"), fifo); + return -1; + } + + /* Check if the init fifo is not the very one that's on + * the host. We don't want to change the host's runlevel. + */ + if (data->st_valid[i] && + data->st[i].st_dev =3D=3D cont_sb.st_dev && + data->st[i].st_ino =3D=3D cont_sb.st_ino) + continue; + + return virInitctlSetRunLevel(fifo, data->runlevel); + } + + /* If no usable fifo was found then declare success. Caller + * will try killing the domain with signal. */ + return 0; +} + + +int +virLXCDomainSetRunlevel(virDomainObjPtr vm, + int runlevel) +{ + virLXCDomainObjPrivatePtr priv =3D vm->privateData; + lxcDomainInitctlCallbackData data; + size_t i; + + memset(&data, 0, sizeof(data)); + + data.runlevel =3D runlevel; + + for (i =3D 0; i < ARRAY_CARDINALITY(virInitctlFifos); i++) { + const char *fifo =3D virInitctlFifos[i]; + + if (stat(fifo, &(data.st[i])) < 0) { + if (errno =3D=3D ENOENT) + continue; + + virReportSystemError(errno, _("Unable to stat %s"), fifo); + return -1; + } + + data.st_valid[i] =3D true; + } + + return virProcessRunInMountNamespace(priv->initpid, + lxcDomainInitctlCallback, + &data); +} diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h index 364b8e5a44..c62d6d1362 100644 --- a/src/lxc/lxc_domain.h +++ b/src/lxc/lxc_domain.h @@ -109,4 +109,8 @@ virLXCDomainObjEndJob(virLXCDriverPtr driver, char * virLXCDomainGetMachineName(virDomainDefPtr def, pid_t pid); =20 +int +virLXCDomainSetRunlevel(virDomainObjPtr vm, + int runlevel); + #endif /* LIBVIRT_LXC_DOMAIN_H */ diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 943d199616..f0d72aa569 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3272,15 +3272,6 @@ lxcConnectListAllDomains(virConnectPtr conn, } =20 =20 -static int -lxcDomainInitctlCallback(pid_t pid ATTRIBUTE_UNUSED, - void *opaque) -{ - int *command =3D opaque; - return virInitctlSetRunLevel(NULL, *command); -} - - static int lxcDomainShutdownFlags(virDomainPtr dom, unsigned int flags) @@ -3318,9 +3309,7 @@ lxcDomainShutdownFlags(virDomainPtr dom, (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) { int command =3D VIR_INITCTL_RUNLEVEL_POWEROFF; =20 - if ((rc =3D virProcessRunInMountNamespace(priv->initpid, - lxcDomainInitctlCallback, - &command)) < 0) + if ((rc =3D virLXCDomainSetRunlevel(vm, command)) < 0) goto endjob; if (rc =3D=3D 0 && flags !=3D 0 && ((flags & ~VIR_DOMAIN_SHUTDOWN_INITCTL) =3D=3D 0)) { @@ -3398,9 +3387,7 @@ lxcDomainReboot(virDomainPtr dom, (flags & VIR_DOMAIN_REBOOT_INITCTL)) { int command =3D VIR_INITCTL_RUNLEVEL_REBOOT; =20 - if ((rc =3D virProcessRunInMountNamespace(priv->initpid, - lxcDomainInitctlCallback, - &command)) < 0) + if ((rc =3D virLXCDomainSetRunlevel(vm, command)) < 0) goto endjob; if (rc =3D=3D 0 && flags !=3D 0 && ((flags & ~VIR_DOMAIN_SHUTDOWN_INITCTL) =3D=3D 0)) { --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list