From nobody Sun May 5 23:20:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1599392258; cv=none; d=zohomail.com; s=zohoarc; b=D3I/zUldeAuFgmdEBX3dsvIbwqjfYq4+Iv0fC8/H3fpTq0LTlzuYwDr5CYd1OZuGf5dFsALMctNuEtgpgvCW5JfZxp7USkJ9ShRzW2x/GJV6NU8WQ4lEcARU4o/slmNBM3xsQ1b1fLXRaq6cGM51rGyPrACdIroEbyWJkmR+LuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599392258; 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; bh=sihv1pT3CFbAGTOnQLHlKXnVXsQtWr0dAsaJ08tTSSE=; b=iuHCD7+9oo+PdHEr59CYSl4GdzWM6Ifgqdzpio5+/8cXFcsKdVkrTwsQHBjdzvw8ixWxVhcbq2Vv0J9TlTomtqI72dXn1gLUyCHSHEMnNax2RoTtwH7fEUM/bX96SOKkYHZkpMYCy6xgsO32mOi66iNr/bXk7sIy5D3ggufBaiA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599392258064836.6415440353106; Sun, 6 Sep 2020 04:37:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-341-m4FuBIjsPIOXvxp-LPfOWw-1; Sun, 06 Sep 2020 07:37:33 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A73B81DDE9; Sun, 6 Sep 2020 11:37:25 +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 61A7B5D9CC; Sun, 6 Sep 2020 11:37:23 +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 6148D97307; Sun, 6 Sep 2020 11:37:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 086BbFl2013858 for ; Sun, 6 Sep 2020 07:37:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13DA75D9D2; Sun, 6 Sep 2020 11:37:15 +0000 (UTC) Received: from caroline.localdomain (unknown [10.40.192.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1B8D5D9CC for ; Sun, 6 Sep 2020 11:37:11 +0000 (UTC) Received: from caroline.redhat.com (caroline.k8r.cz [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 3527022C615A for ; Sun, 6 Sep 2020 13:37:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599392255; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=sihv1pT3CFbAGTOnQLHlKXnVXsQtWr0dAsaJ08tTSSE=; b=itjgTc4r+vHexhdeQ1KloggTpVmfh7sqZle4S6n399CYnCpW0/Q+iDMlSUb9BmGhPH67dy 5ZjteTb0B8bi+uQfa1FXAnVaFMTcu2BQZZMEOrRV0kH6vKCyU+7naxiLbktjscabhR/KiS 8wnrvDZR1CFgAiWFn4F+CBRrd6dFsnc= X-MC-Unique: m4FuBIjsPIOXvxp-LPfOWw-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [PATCH] Do not report error when setting affinity is allowed to fail Date: Sun, 6 Sep 2020 13:36:06 +0200 Message-Id: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Suggested-by: J=C3=A1n Tomko Signed-off-by: Martin Kletzander Reviewed-by: J=C3=A1n Tomko --- src/lxc/lxc_controller.c | 2 +- src/qemu/qemu_driver.c | 7 ++++--- src/qemu/qemu_process.c | 10 +++++----- src/util/virprocess.c | 32 +++++++++++++++++++++++--------- src/util/virprocess.h | 2 +- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 0a496fb7886c..37a28ac2f3c1 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -775,7 +775,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCContr= ollerPtr ctrl) * so use '0' to indicate our own process ID. No threads are * running at this point */ - if (virProcessSetAffinity(0 /* Self */, cpumapToSet) < 0) { + if (virProcessSetAffinity(0 /* Self */, cpumapToSet, false) < 0) { virBitmapFree(cpumap); return -1; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ce72e1021d16..a792a1283253 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4529,7 +4529,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, goto cleanup; } =20 - if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), cpumap) = < 0) + if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), + cpumap, false) < 0) goto cleanup; } =20 @@ -4747,7 +4748,7 @@ qemuDomainPinEmulator(virDomainPtr dom, } } =20 - if (virProcessSetAffinity(vm->pid, pcpumap) < 0) + if (virProcessSetAffinity(vm->pid, pcpumap, false) < 0) goto endjob; =20 virBitmapFree(def->cputune.emulatorpin); @@ -5222,7 +5223,7 @@ qemuDomainPinIOThread(virDomainPtr dom, } } =20 - if (virProcessSetAffinity(iothrid->thread_id, pcpumap) < 0) + if (virProcessSetAffinity(iothrid->thread_id, pcpumap, false) < 0) goto endjob; =20 if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 17d083d192a5..423c60c7c85b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2573,7 +2573,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) } =20 if (cpumapToSet && - virProcessSetAffinity(vm->pid, cpumapToSet) < 0) { + virProcessSetAffinity(vm->pid, cpumapToSet, false) < 0) { /* * We only want to error out if we failed to set the affinity to * user-requested mapping. If we are just trying to reset the aff= inity @@ -2743,7 +2743,8 @@ qemuProcessSetupPid(virDomainObjPtr vm, affinity_cpumask =3D use_cpumask; =20 /* Setup legacy affinity. */ - if (affinity_cpumask && virProcessSetAffinity(pid, affinity_cpumask) <= 0) { + if (affinity_cpumask && + virProcessSetAffinity(pid, affinity_cpumask, false) < 0) { /* * We only want to error out if we failed to set the affinity to * user-requested mapping. If we are just trying to reset the aff= inity @@ -2751,9 +2752,8 @@ qemuProcessSetupPid(virDomainObjPtr vm, * 1) libvirtd does not have CAP_SYS_NICE * 2) libvirtd does not run on all CPUs * - * However since this scenario is very improbable, we rather skip - * reporting the error because it helps running libvirtd in a a sc= enario - * where pinning is handled by someone else. + * This scenario can easily occurr when libvirtd is run inside a + * container with restrictive permissions and CPU pinning. * * See also: https://bugzilla.redhat.com/1819801#c2 */ diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 9de356505104..e9df56389621 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -441,7 +441,7 @@ int virProcessKillPainfully(pid_t pid, bool force) =20 #if WITH_SCHED_GETAFFINITY =20 -int virProcessSetAffinity(pid_t pid, virBitmapPtr map) +int virProcessSetAffinity(pid_t pid, virBitmapPtr map, bool quiet) { size_t i; int numcpus =3D 1024; @@ -479,9 +479,14 @@ int virProcessSetAffinity(pid_t pid, virBitmapPtr map) numcpus =3D numcpus << 2; goto realloc; } - virReportSystemError(errno, - _("cannot set CPU affinity on process %d"), p= id); - return -1; + if (quiet) { + VIR_DEBUG("cannot set CPU affinity on process %d: %s", + pid, g_strerror(errno)); + } else { + virReportSystemError(errno, + _("cannot set CPU affinity on process %d"= ), pid); + return -1; + } } CPU_FREE(mask); =20 @@ -533,7 +538,8 @@ virProcessGetAffinity(pid_t pid) #elif defined(WITH_BSD_CPU_AFFINITY) =20 int virProcessSetAffinity(pid_t pid, - virBitmapPtr map) + virBitmapPtr map, + bool quiet) { size_t i; cpuset_t mask; @@ -546,9 +552,14 @@ int virProcessSetAffinity(pid_t pid, =20 if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(mask), &mask) !=3D 0) { - virReportSystemError(errno, - _("cannot set CPU affinity on process %d"), p= id); - return -1; + if (quiet) { + VIR_DEBUG("cannot set CPU affinity on process %d: %s", + pid, g_strerror(errno)); + } else { + virReportSystemError(errno, + _("cannot set CPU affinity on process %d"= ), pid); + return -1; + } } =20 return 0; @@ -582,8 +593,11 @@ virProcessGetAffinity(pid_t pid) #else /* WITH_SCHED_GETAFFINITY */ =20 int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED, - virBitmapPtr map G_GNUC_UNUSED) + virBitmapPtr map G_GNUC_UNUSED, + bool quiet G_GNUC_UNUSED) { + /* The @quiet parameter is ignored here, it is used only for silencing + * actual failures. */ virReportSystemError(ENOSYS, "%s", _("Process CPU affinity is not supported on this = platform")); return -1; diff --git a/src/util/virprocess.h b/src/util/virprocess.h index 437deb18305b..34210d6c9d62 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -58,7 +58,7 @@ int virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay); =20 -int virProcessSetAffinity(pid_t pid, virBitmapPtr map); +int virProcessSetAffinity(pid_t pid, virBitmapPtr map, bool quiet); =20 virBitmapPtr virProcessGetAffinity(pid_t pid); =20 --=20 2.28.0