From nobody Sat Feb 7 07:31:38 2026 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1696497763; cv=none; d=zohomail.com; s=zohoarc; b=VOUe8qTgtJcJ7UdWlaG24L01ZDLnmlQOUKXUMVcX+Mui8bPlGgJ+zuSgxdwAg/PCb94HhRW4nl/hQxUq5Y9A372aIQo+SlPsVXvINzsK/phl1WsGNLkm1uVdsiM7AB4hgcKkq1+yMHYc2Ij/WdHZ6tfSotEgqiwA2nuLLucmpio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696497763; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=HQlNRKso0VociUtEyGXpeTIz5Pmh2v40hrxP1HVhvY4=; b=h24x+voHa/6Iufo12PhzzU4qtKJcmuYR1M9BWw5ox5O1Ko1ECDmRXKsvu+SuPbfmiZNbfMkmfPsNu1pU+9ff6dS/RnFU16q/oyD779L4CNlwqruPe/4QtoU5KYjvkEJ7Lc7f0fX8hF/1WZ0mNWikDxev9O7cgTqcQUHkNPQMabI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1696497763958306.6017670578332; Thu, 5 Oct 2023 02:22:43 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-558-oSvdJ083NfSMZGURTVexLA-1; Thu, 05 Oct 2023 05:22:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 4FBC181D7A5; Thu, 5 Oct 2023 09:22:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 067A740C2017; Thu, 5 Oct 2023 09:22:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CDA8119466E8; Thu, 5 Oct 2023 09:22:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0EF5F194658F for ; Thu, 5 Oct 2023 09:22:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E4B2240C2017; Thu, 5 Oct 2023 09:22:17 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.226.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 508D740C2015 for ; Thu, 5 Oct 2023 09:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696497763; 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=HQlNRKso0VociUtEyGXpeTIz5Pmh2v40hrxP1HVhvY4=; b=GV2rIepVupGtEg4UabJanSHFcCaTN6UJW6oVZV/UrvjDLPHFfXEGhdry+N1cHc98+826pp ha/6eQZ4DE+LeS38Ok637mgO8TD48MmBHMd2uVAkrP5dgB9XafpnkSkl6Gdlsy9wSMueW1 EMrOgs0FHs29MJPB9cfWrR2c34l/diM= X-MC-Unique: oSvdJ083NfSMZGURTVexLA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/1] meson: Improve nbdkit configurability Date: Thu, 5 Oct 2023 11:22:14 +0200 Message-ID: <20231005092214.686290-2-abologna@redhat.com> In-Reply-To: <20231005092214.686290-1-abologna@redhat.com> References: <20231005092214.686290-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1696497764682100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Currently, nbdkit support will automatically be enabled as long as the pidfd_open(2) syscall is available. Optionally, libnbd is used to generate more user-friendly error messages. In theory this is all good, since use of nbdkit is supposed to be transparent to the user. In practice, however, there is a problem: if support for it is enabled at build time and the necessary runtime components are installed, nbdkit will always be preferred, with no way for the user to opt out. This will arguably be fine in the long run, but right now none of the platforms that we target ships with a SELinux policy that allows libvirt to launch nbdkit, and the AppArmor policy that we maintain ourselves hasn't been updated either. So, in practice, as of today having nbdkit installed on the host makes network disks completely unusable unless you're willing to compromise the overall security of the system by disabling SELinux/AppArmor. In order to make the transition smoother, provide a convenient way for users and distro packagers to disable nbdkit support at compile time until SELinux and AppArmor are ready. In the process, detection is completely overhauled. libnbd is made mandatory when nbdkit support is enabled, since availability across operating systems is comparable and offering users the option to make error messages worse doesn't make a lot of sense; we also make sure that an explicit request from the user to enable/disable nbdkit support is either complied with, or results in a build failure when that's not possible. Last but not least, we avoid linking against libnbd when nbdkit support is disabled. At the RPM level, we disable the feature when building against anything older than Fedora 40, which still doesn't have the necessary SELinux bits but will hopefully gain them by the time it's released. We also allow nbdkit support to be disabled at build time the same way as other optional features, that is, by passing "--define '_without_nbdkit 1'" to rpmbuild. Finally, if nbdkit support has been disabled, installing libvirt will no longer drag it in as a (weak) dependency. Signed-off-by: Andrea Bolognani Reviewed-by: Jonathon Jongsma --- libvirt.spec.in | 28 +++++++++++++++++++++++++--- meson.build | 29 +++++++++++++++++++++-------- meson_options.txt | 2 +- src/qemu/qemu_nbdkit.c | 6 +++--- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/libvirt.spec.in b/libvirt.spec.in index f3d21ccc8f..fe54c45c5c 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -95,6 +95,7 @@ %define with_fuse 0 %define with_sanlock 0 %define with_numad 0 +%define with_nbdkit 0 %define with_firewalld_zone 0 %define with_netcf 0 %define with_libssh2 0 @@ -173,6 +174,18 @@ %endif %endif =20 +# We should only enable nbdkit support if the OS ships a SELinux policy th= at +# allows libvirt to launch it. Right now that's not the case anywhere, but +# things should be fine by the time Fedora 40 is released. +# +# TODO: add RHEL 9 once a minor release that contains the necessary SELinux +# bits exists (we only support the most recent minor release) +%if %{with_qemu} + %if 0%{?fedora} >=3D 40 + %define with_nbdkit 0%{!?_without_nbdkit:1} + %endif +%endif + %ifarch %{arches_dmidecode} %define with_dmidecode 0%{!?_without_dmidecode:1} %endif @@ -312,6 +325,9 @@ BuildRequires: util-linux BuildRequires: libacl-devel # From QEMU RPMs, used by virstoragetest BuildRequires: /usr/bin/qemu-img +%endif +# nbdkit support requires libnbd +%if %{with_nbdkit} BuildRequires: libnbd-devel %endif # For LVM drivers @@ -769,9 +785,11 @@ Requires: numad Recommends: passt Recommends: passt-selinux %endif + %if %{with_nbdkit} Recommends: nbdkit Recommends: nbdkit-curl-plugin Recommends: nbdkit-ssh-plugin + %endif =20 %description daemon-driver-qemu The qemu driver plugin for the libvirtd daemon, providing @@ -1078,10 +1096,8 @@ exit 1 =20 %if %{with_qemu} %define arg_qemu -Ddriver_qemu=3Denabled - %define arg_libnbd -Dlibnbd=3Denabled %else %define arg_qemu -Ddriver_qemu=3Ddisabled - %define arg_libnbd -Dlibnbd=3Ddisabled %endif =20 %if %{with_openvz} @@ -1158,6 +1174,12 @@ exit 1 %define arg_numad -Dnumad=3Ddisabled %endif =20 +%if %{with_nbdkit} + %define arg_nbdkit -Dnbdkit=3Denabled +%else + %define arg_nbdkit -Dnbdkit=3Ddisabled +%endif + %if %{with_fuse} %define arg_fuse -Dfuse=3Denabled %else @@ -1270,7 +1292,7 @@ export SOURCE_DATE_EPOCH=3D$(stat --printf=3D'%Y' %{_= specdir}/libvirt.spec) -Dyajl=3Denabled \ %{?arg_sanlock} \ -Dlibpcap=3Denabled \ - %{?arg_libnbd} \ + %{?arg_nbdkit} \ -Dlibnl=3Denabled \ -Daudit=3Denabled \ -Ddtrace=3Denabled \ diff --git a/meson.build b/meson.build index 6fa1f74670..de23fbda1e 100644 --- a/meson.build +++ b/meson.build @@ -1011,10 +1011,27 @@ endif libiscsi_version =3D '1.18.0' libiscsi_dep =3D dependency('libiscsi', version: '>=3D' + libiscsi_version= , required: get_option('libiscsi')) =20 -libnbd_version =3D '1.0' -libnbd_dep =3D dependency('libnbd', version: '>=3D' + libnbd_version, requ= ired: get_option('libnbd')) -if libnbd_dep.found() - conf.set('WITH_LIBNBD', 1) +if not get_option('nbdkit').disabled() + libnbd_version =3D '1.0' + libnbd_dep =3D dependency('libnbd', version: '>=3D' + libnbd_version, re= quired: false) + + nbdkit_requested =3D get_option('nbdkit').enabled() + nbdkit_syscall_ok =3D conf.has('WITH_DECL_SYS_PIDFD_OPEN') + nbdkit_libnbd_ok =3D libnbd_dep.found() + + if not nbdkit_syscall_ok and nbdkit_requested + error('nbdkit support requires pidfd_open(2)') + endif + if not nbdkit_libnbd_ok and nbdkit_requested + error('nbdkit support requires libnbd') + endif + + if nbdkit_syscall_ok and nbdkit_libnbd_ok + conf.set('WITH_NBDKIT', 1) + endif +endif +if not conf.has('WITH_NBDKIT') + libnbd_dep =3D dependency('', required: false) endif =20 libnl_version =3D '3.0' @@ -2024,10 +2041,6 @@ endif =20 conf.set_quoted('TLS_PRIORITY', get_option('tls_priority')) =20 -if conf.has('WITH_DECL_SYS_PIDFD_OPEN') - conf.set('WITH_NBDKIT', 1) -endif - # Various definitions =20 # Python3 < 3.7 treats the C locale as 7-bit only. We must force env vars = so diff --git a/meson_options.txt b/meson_options.txt index ba6e49afc5..7c428a9eb0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -25,7 +25,6 @@ option('curl', type: 'feature', value: 'auto', descriptio= n: 'curl support') option('fuse', type: 'feature', value: 'auto', description: 'fuse support') option('glusterfs', type: 'feature', value: 'auto', description: 'glusterf= s support') option('libiscsi', type: 'feature', value: 'auto', description: 'libiscsi = support') -option('libnbd', type: 'feature', value: 'auto', description: 'libnbd supp= ort') option('libnl', type: 'feature', value: 'auto', description: 'libnl suppor= t') option('libpcap', type: 'feature', value: 'auto', description: 'libpcap su= pport') option('libssh', type: 'feature', value: 'auto', description: 'libssh supp= ort') @@ -105,6 +104,7 @@ option('loader_nvram', type: 'string', value: '', descr= iption: 'Pass list of pai option('login_shell', type: 'feature', value: 'auto', description: 'build = virt-login-shell') option('nss', type: 'feature', value: 'auto', description: 'enable Name Se= rvice Switch plugin for resolving guest IP addresses') option('numad', type: 'feature', value: 'auto', description: 'use numad to= manage CPU placement dynamically') +option('nbdkit', type: 'feature', value: 'auto', description: 'use nbdkit = to access network disks') option('pm_utils', type: 'feature', value: 'auto', description: 'use pm-ut= ils for power management') option('sysctl_config', type: 'feature', value: 'auto', description: 'Whet= her to install sysctl configs') option('tls_priority', type: 'string', value: 'NORMAL', description: 'set = the default TLS session priority string') diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 17819ca992..3ad63cfaa0 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -19,7 +19,7 @@ =20 #include #include -#if WITH_LIBNBD +#if WITH_NBDKIT # include #endif #include @@ -1159,7 +1159,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, g_autofree char *basename =3D g_strdup_printf("%s-nbdkit-%i", vm->def-= >name, proc->source->id); int logfd =3D -1; g_autoptr(qemuLogContext) logContext =3D NULL; -#if WITH_LIBNBD +#if WITH_NBDKIT struct nbd_handle *nbd =3D NULL; #endif =20 @@ -1214,7 +1214,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, =20 while (virTimeBackOffWait(&timebackoff)) { if (virFileExists(proc->socketfile)) { -#if WITH_LIBNBD +#if WITH_NBDKIT /* if the disk source was misconfigured, nbdkit will not produ= ce an error * until somebody connects to the socket and tries to access t= he nbd * export. This results in poor user experience because the on= ly error we --=20 2.41.0