From nobody Wed May 1 22:28:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1583757096; cv=none; d=zohomail.com; s=zohoarc; b=Meljj+vK9S82n4Yo4+Z+2McbiSJVZa64QvHUMPNxHcSPcb9yhIM264vQlnL6Hf7OXsaDLv27kEGGHmyGIb48GFBaMtlCBp5sFqhA39FRGpcxy9KW0JvaJsxpMf3QyFs3uvc2n/uiA8YmsaUHibhuo1a0voJyp2BDMGJugU7Io0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583757096; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fsDgc+zEsu0pZjv8A/rs5U9Xla4b2ml6YciKQutsa5Q=; b=cpf2gxc8jqKhrFc1kE81z6NU4K//1E7KDYlLI0oYUhX105ug8AW+xPY9N7e/5D5n9IHhCuDNi69WVmwZDZ/YjmuoTLwNfYrl3cSsnNYevDQs/DXjG73XUrOn2L+xR5KV/5ifxjcdfWiAyCmWT9N9gwmZqHFbHBp9smRoGd3y49k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1583757096479518.2755887918272; Mon, 9 Mar 2020 05:31:36 -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-142-TrUy-UnCOpmlyjWKQ7G5kA-1; Mon, 09 Mar 2020 08:31:33 -0400 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 A56521005509; Mon, 9 Mar 2020 12:31:26 +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 3D9AA60BFB; Mon, 9 Mar 2020 12:31:26 +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 2717884493; Mon, 9 Mar 2020 12:31:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 029CVLTC011544 for ; Mon, 9 Mar 2020 08:31:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9826E62667; Mon, 9 Mar 2020 12:31:21 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C0515C13D for ; Mon, 9 Mar 2020 12:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583757095; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fsDgc+zEsu0pZjv8A/rs5U9Xla4b2ml6YciKQutsa5Q=; b=KTHCEeZdZcMlltZJh1bRb8TpO9NSp2tOgdGHGQDyuEVxHifVuBg3muDQ5g9/7Wa9Sy3dj9 gSMwufeS6PTpW/eQYI8IdtVsqrvtY0IWnJrdG0uzm94jFzz2Eh41Znf8tKGu/AlXKTe5r0 FN9rQBF+7Mn9i8fSOJuWi+7PW2FI8+0= X-MC-Unique: TrUy-UnCOpmlyjWKQ7G5kA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] virCgroupV2DevicesAvailable: Print stringified errno in the debug log Date: Mon, 9 Mar 2020 13:31:15 +0100 Message-Id: <6fff97119a6d0363ee6bb12f3651a8a6a7d3ff91.1583757029.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In the virCgroupV2DevicesAvailable() function we try to determine whether CGroups version 2 are available. We do this by opening what we believe is the CGroup mount point and issuing a BPF call. When the call fails, a debug message is printed. However, the BPF call sets errno too. Include it in the debug message to help us with debugging. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza --- src/util/vircgroupv2devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/vircgroupv2devices.c b/src/util/vircgroupv2devices.c index 445f9c53fc..d62ee12a05 100644 --- a/src/util/vircgroupv2devices.c +++ b/src/util/vircgroupv2devices.c @@ -55,7 +55,7 @@ virCgroupV2DevicesAvailable(virCgroupPtr group) } =20 if (virBPFQueryProg(cgroupfd, 0, BPF_CGROUP_DEVICE, &progCnt, NULL) < = 0) { - VIR_DEBUG("failed to query cgroup progs"); + VIR_DEBUG("failed to query cgroup progs: %s", g_strerror(errno)); return false; } =20 --=20 2.24.1 From nobody Wed May 1 22:28:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1583757103; cv=none; d=zohomail.com; s=zohoarc; b=QFiiZ+75A+0CY4lskViIJJ7SGdUigoijVmpCu7jQjcKXCKFqaOx0yTyDo3KaHpO4qQNt8z095qYdzBbfBBdf3kuIrqQs39we8PGnKcs5cdVjDwetTy6fHk5tQKGY+/btIGfw5nPJ6rlYrOkR2pZcQw1IFSWO3mGj43q2mqTwJSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583757103; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qMjen4OGmasDipE4IMsYx07DXj+6vkail/QrDG7+K58=; b=mGL/kOQSl6N0T01Cu1FUi4xUauIfW3XfuQeOu02gNtHStP5GvInNgz5981BFw11ncRtdgGwsZGRvOovLEH263W/q6a4uSzxgA+HVCyCm1RQlO8uqlYPSyGhIKcJ9GdSEQDjgHSTdeqp+bRavzYjYCllL8fw9yV/NfbiHsmjqx1Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1583757103802662.8250651470231; Mon, 9 Mar 2020 05:31:43 -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-442-oCfKBOaPOdy2ITnPpK0oFQ-1; Mon, 09 Mar 2020 08:31:40 -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 4B2F018FF669; Mon, 9 Mar 2020 12:31:35 +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 18C265D9CA; Mon, 9 Mar 2020 12:31:35 +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 BF22B182B011; Mon, 9 Mar 2020 12:31:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 029CVMOI011554 for ; Mon, 9 Mar 2020 08:31:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CCAB73868; Mon, 9 Mar 2020 12:31:22 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E66DC62667 for ; Mon, 9 Mar 2020 12:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583757102; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qMjen4OGmasDipE4IMsYx07DXj+6vkail/QrDG7+K58=; b=Q2aGdamcnY4UaCc9mkQwENrxJL33Va/HNLMJg8pnFeTS/7ftEvYVWbSqD33mYINxXbQfWp 0xlMkgFIlOZQUROT2EFh8zAy9/55lSSVdrpCDMovZqmMuDnFNihf1NdpHrbHoIvNWXnsla UEPPqjgLHuHQYXUclAqMeE8+SpgLIdg= X-MC-Unique: oCfKBOaPOdy2ITnPpK0oFQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] virbpf: Set errno instead of reporting errors Date: Mon, 9 Mar 2020 13:31:16 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The virbpf module wraps syscalls to BPF. However, if the kernel headers used at the compile time don't have support for BPF the module offers stubs which return a negative one to signal error to the caller. But there is a slight discrepancy between real functions and these stubs. While the former set errno and return -1 the latter report an error (without setting the errno) and return -1. This is not optimal because the caller might see stale errno and overwrite the error message with a less accurate one. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza --- po/POTFILES.in | 1 - src/util/virbpf.c | 39 +++++++++++++-------------------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 982f2ebc36..8af457aa36 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -227,7 +227,6 @@ @SRCDIR@/src/util/virauth.c @SRCDIR@/src/util/virauthconfig.c @SRCDIR@/src/util/virbitmap.c -@SRCDIR@/src/util/virbpf.c @SRCDIR@/src/util/vircgroup.c @SRCDIR@/src/util/vircgroupbackend.c @SRCDIR@/src/util/vircgroupbackend.h diff --git a/src/util/virbpf.c b/src/util/virbpf.c index dec8d0133a..987fc34ef4 100644 --- a/src/util/virbpf.c +++ b/src/util/virbpf.c @@ -302,8 +302,7 @@ virBPFCreateMap(unsigned int mapType G_GNUC_UNUSED, unsigned int valSize G_GNUC_UNUSED, unsigned int maxEntries G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -313,8 +312,7 @@ virBPFLoadProg(struct bpf_insn *insns G_GNUC_UNUSED, int progType G_GNUC_UNUSED, unsigned int insnCnt G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -324,8 +322,7 @@ virBPFAttachProg(int progfd G_GNUC_UNUSED, int targetfd G_GNUC_UNUSED, int attachType G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -335,8 +332,7 @@ virBPFDetachProg(int progfd G_GNUC_UNUSED, int targetfd G_GNUC_UNUSED, int attachType G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -348,8 +344,7 @@ virBPFQueryProg(int targetfd G_GNUC_UNUSED, unsigned int *progcnt G_GNUC_UNUSED, void *progids G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -357,8 +352,7 @@ virBPFQueryProg(int targetfd G_GNUC_UNUSED, int virBPFGetProg(unsigned int id G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -368,8 +362,7 @@ virBPFGetProgInfo(int progfd G_GNUC_UNUSED, struct bpf_prog_info *info G_GNUC_UNUSED, unsigned int **mapIDs G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -377,8 +370,7 @@ virBPFGetProgInfo(int progfd G_GNUC_UNUSED, int virBPFGetMap(unsigned int id G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -387,8 +379,7 @@ int virBPFGetMapInfo(int mapfd G_GNUC_UNUSED, struct bpf_map_info *info G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -398,8 +389,7 @@ virBPFLookupElem(int mapfd G_GNUC_UNUSED, void *key G_GNUC_UNUSED, void *val G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -409,8 +399,7 @@ virBPFGetNextElem(int mapfd G_GNUC_UNUSED, void *key G_GNUC_UNUSED, void *nextKey G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -420,8 +409,7 @@ virBPFUpdateElem(int mapfd G_GNUC_UNUSED, void *key G_GNUC_UNUSED, void *val G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } =20 @@ -430,8 +418,7 @@ int virBPFDeleteElem(int mapfd G_GNUC_UNUSED, void *key G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("BPF not supported with this kernel")); + errno =3D ENOSYS; return -1; } #endif /* !HAVE_SYS_SYSCALL_H || !HAVE_DECL_BPF_PROG_QUERY */ --=20 2.24.1