From nobody Thu May 16 09:56:36 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 ARC-Seal: i=1; a=rsa-sha256; t=1623083360; cv=none; d=zohomail.com; s=zohoarc; b=XY2WLfSWgeT6szGol1f5iN9/9ts6IpmulgnsV6bSkE7dKMankh5lxN5Y/solOobnL2Puf1bSKwhwjEkJ5owIgRGy8AauvTvjbqqNvYLbwBb6u9aVxHCu832ocWgAWtJggUhVgM7jGSW0W/HgM6MRKoNCNQm7Gl0DfSAtGW+y+3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623083360; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=aGL8mALGbETim/FIneNht0RZ8uQYz0YVd4V4l6Zw+J4=; b=fnun9IrEbjnCtbzAB4FgmAgOkFN3z+ZOpdhDNGH7lN+WMwZmIYkhbwM4YUQ58/QeWkdENozEJtzfKzYaHD0QMzPNTEbWLL9WFasFt0YuKFCo5+hZBG1KK4UwQFfatB/X8AlJVLSqaJJ29agRsKMuPnWw8x8T0Kl7Ae9BABGCfIk= ARC-Authentication-Results: i=1; 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 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 1623083360138957.5110054629993; Mon, 7 Jun 2021 09:29:20 -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-60-HzFJEeP8NZ2ADdxtHba2cg-1; Mon, 07 Jun 2021 12:29:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60CF48049CD; Mon, 7 Jun 2021 16:29: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 ACA705C1C2; Mon, 7 Jun 2021 16:29:10 +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 DFF3944A59; Mon, 7 Jun 2021 16:29:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 157GMoMo017321 for ; Mon, 7 Jun 2021 12:22:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 50A221111A67; Mon, 7 Jun 2021 16:22:50 +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 4C5171111A5F for ; Mon, 7 Jun 2021 16:22:47 +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 99EA0182506A for ; Mon, 7 Jun 2021 16:22:47 +0000 (UTC) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219--ptEvzLJPgyL96b-wcDVXw-1; Mon, 07 Jun 2021 12:22:43 -0400 Received: by mail-wm1-f42.google.com with SMTP id l7-20020a05600c1d07b02901b0e2ebd6deso42968wms.1 for ; Mon, 07 Jun 2021 09:22:43 -0700 (PDT) Received: from quino.redhat.com ([83.240.60.216]) by smtp.googlemail.com with ESMTPSA id r4sm16543439wre.84.2021.06.07.09.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 09:22:41 -0700 (PDT) X-MC-Unique: HzFJEeP8NZ2ADdxtHba2cg-1 X-MC-Unique: -ptEvzLJPgyL96b-wcDVXw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aGL8mALGbETim/FIneNht0RZ8uQYz0YVd4V4l6Zw+J4=; b=cDNxgn/ZFt4qweV0TZYcP8GEmAamwPtNDd1j7XigRvTW48cMyay6Vtxlw6I8Xt2L27 LnuJ2lWH9cv9Daxb67WMU9zWbUe3CD/5p/cGgGrA0G0HrJdjd32osIvAkwqAbPonbhQ9 M+JPeqt7vqZdItPVv3WfykOAUTW9w2hbrLoxLhgl+eZewiwxnEea8mCu78zT8+HHK9j5 9jxttiui2Q1Yd5GHlFORLtSmsrXc4ycs5VocmSHdAS6TVZMccORoouxUE1HbsX0TBkcm aeJRCQu1Yi2d2CjNxm7RrErDFg1GZE6cs7F4O/lLq0OdsVNN+mhGWMgG7ezNlyljUR4W 7upg== X-Gm-Message-State: AOAM530035M2bsvLnDo/gWj1kKC1/w1N60d5Kt9T/rr7c6nJeuNW6phn Kv+fMqdzr2reGU6YhdXuxHjZrwXhikNqlBh5amo= X-Google-Smtp-Source: ABdhPJwOvzk3STxIBkV7TPE9UkYtP2JTI70x5rvJad0bkbXQQsuS1GDlYyVFjc/4lXcugFRPICJbhw== X-Received: by 2002:a1c:9ac5:: with SMTP id c188mr17155698wme.17.1623082962235; Mon, 07 Jun 2021 09:22:42 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Subject: [PATCH v2] tools: only fail validations if VIR_HOST_VALIDATE_FAIL is set Date: Mon, 7 Jun 2021 18:22:18 +0200 Message-Id: <20210607162218.11795-1-fabiano@fidencio.org> 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.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= 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.16 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Currently `virt-host-validate` will fail whenever one of its calls fail, regardless of virHostValidateLevel set. This behaviour is not optimal and makes it not exactly reliable as a command line tool as other tools or scripts using it would have to check its output to figure out whether something really failed or if a warning was mistakenly treated as failure. With this change, the behaviour of whether to fail or not, is defined by the caller of those functions, based on the virHostValidateLevel passed to them. https://gitlab.com/libvirt/libvirt/-/issues/175 Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: Michal Privoznik --- Changes since v1: * Replace the `goto out;` and the `out` labels by the `VIR_HOST_VALIDATE_FAILURE` macro --- tools/virt-host-validate-common.c | 30 +++++++++++++++--------------- tools/virt-host-validate-common.h | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index 6dd851f07d..9412bb7514 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -142,7 +142,7 @@ int virHostValidateDeviceExists(const char *hvname, =20 if (access(dev_name, F_OK) < 0) { virHostMsgFail(level, "%s", hint); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } =20 virHostMsgPass(); @@ -159,7 +159,7 @@ int virHostValidateDeviceAccessible(const char *hvname, =20 if (access(dev_name, R_OK|W_OK) < 0) { virHostMsgFail(level, "%s", hint); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } =20 virHostMsgPass(); @@ -180,7 +180,7 @@ int virHostValidateNamespace(const char *hvname, =20 if (access(nspath, F_OK) < 0) { virHostMsgFail(level, "%s", hint); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } =20 virHostMsgPass(); @@ -264,17 +264,17 @@ int virHostValidateLinuxKernel(const char *hvname, =20 if (STRNEQ(uts.sysname, "Linux")) { virHostMsgFail(level, "%s", hint); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } =20 if (virParseVersionString(uts.release, &thisversion, true) < 0) { virHostMsgFail(level, "%s", hint); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } =20 if (thisversion < version) { virHostMsgFail(level, "%s", hint); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } else { virHostMsgPass(); return 0; @@ -291,7 +291,7 @@ int virHostValidateCGroupControllers(const char *hvname, size_t i; =20 if (virCgroupNew("/", -1, &group) < 0) - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { int flag =3D 1 << i; @@ -303,7 +303,7 @@ int virHostValidateCGroupControllers(const char *hvname, virHostMsgCheck(hvname, "for cgroup '%s' controller support", cg_n= ame); =20 if (!virCgroupHasController(group, i)) { - ret =3D -1; + ret =3D VIR_HOST_VALIDATE_FAILURE(level); virHostMsgFail(level, "Enable '%s' in kernel Kconfig file or " "mount/enable cgroup controller in your system", cg_name); @@ -320,7 +320,7 @@ int virHostValidateCGroupControllers(const char *hvname= G_GNUC_UNUSED, virHostValidateLevel level) { virHostMsgFail(level, "%s", "This platform does not support cgroups"); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } #endif /* !__linux__ */ =20 @@ -354,7 +354,7 @@ int virHostValidateIOMMU(const char *hvname, "No ACPI DMAR table found, IOMMU either " "disabled in BIOS or not supported by this " "hardware platform"); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } } else if (isAMD) { virHostMsgCheck(hvname, "%s", _("for device assignment IOMMU suppo= rt")); @@ -366,7 +366,7 @@ int virHostValidateIOMMU(const char *hvname, "No ACPI IVRS table found, IOMMU either " "disabled in BIOS or not supported by this " "hardware platform"); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } } else if (ARCH_IS_PPC64(arch)) { /* Empty Block */ @@ -385,7 +385,7 @@ int virHostValidateIOMMU(const char *hvname, } else { virHostMsgFail(level, "Unknown if this platform has IOMMU support"); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } =20 =20 @@ -404,7 +404,7 @@ int virHostValidateIOMMU(const char *hvname, "Add %s to kernel cmdline arguments", bootarg); else virHostMsgFail(level, "IOMMU capability not compiled into kern= el."); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } virHostMsgPass(); return 0; @@ -468,7 +468,7 @@ int virHostValidateSecureGuests(const char *hvname, } =20 if (virFileReadValueString(&cmdline, "/proc/cmdline") < 0) - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); =20 /* we're prefix matching rather than equality matching here, b= ecause * kernel would treat even something like prot_virt=3D'yFOO' as @@ -516,7 +516,7 @@ int virHostValidateSecureGuests(const char *hvname, } else { virHostMsgFail(level, "Unknown if this platform has Secure Guest support"= ); - return -1; + return VIR_HOST_VALIDATE_FAILURE(level); } =20 return 0; diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-c= ommon.h index 08a9997f5f..9334fa8588 100644 --- a/tools/virt-host-validate-common.h +++ b/tools/virt-host-validate-common.h @@ -45,6 +45,20 @@ typedef enum { =20 VIR_ENUM_DECL(virHostValidateCPUFlag); =20 +/** + * VIR_HOST_VALIDATE_FAILURE + * @level: the virHostValidateLevel to be checked + * + * This macro is to be used in to return a failures based on the + * virHostValidateLevel use in the function. + * + * If the virHostValidateLevel is VIR_HOST_VALIDATE_FAIL, -1 is returned. + * 0 is returned otherwise (as the virHosValidateLevel is then either a + * Warn or a Note). + */ + +#define VIR_HOST_VALIDATE_FAILURE(level) (level =3D=3D VIR_HOST_VALIDATE_F= AIL) ? -1 : 0 + void virHostMsgSetQuiet(bool quietFlag); =20 void virHostMsgCheck(const char *prefix, --=20 2.31.1