From nobody Wed Feb 11 06:14:33 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=1676394603; cv=none; d=zohomail.com; s=zohoarc; b=mnxjnPtND19REvgCvtkFzbL1Zl4Tw0Z695FA0EcEpMmfZ/RSVJujkVccW8nmGHYloJfXu75ZLyCPzsfVxtV6J+6nOHYpDJ940cn69IeegFX/0UAClhtmC3aM1T7VccZtbnvUmERLtmWZIYU6H94uq7NzpIvLZhAoqsJ0DoMqlXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676394603; 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=Vw4HnRTuSE18M3hYkYLWsUv/EvhCoCMSv9GB5JKh+ZI=; b=nCs7qEoH6QYYl3OD0KSNk9XTFSlb1MfbJYwsDYy7PsZ04I7fgYRqimVFIP4rzsn8O5Y000+Az1Crmovf48FOfhxxjgbi0PaiwaCkhB3MVyNjcoTiHZZLeqrIPMmJoHy2VFmyy9dJarh7tTOLuaediycuSrHz6Vz/k6WJGPcoK9s= 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 1676394603885878.5687219443593; Tue, 14 Feb 2023 09:10:03 -0800 (PST) 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-376-PxLb73QhPM2pUm2SZUcbrw-1; Tue, 14 Feb 2023 12:09:37 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 591BC100F916; Tue, 14 Feb 2023 17:09:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 471251121319; Tue, 14 Feb 2023 17:09:33 +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 956341946A73; Tue, 14 Feb 2023 17:08:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 18D7819465A3 for ; Tue, 14 Feb 2023 17:08:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EED7A1C55A; Tue, 14 Feb 2023 17:08:26 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD5F818EC2 for ; Tue, 14 Feb 2023 17:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676394602; 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=Vw4HnRTuSE18M3hYkYLWsUv/EvhCoCMSv9GB5JKh+ZI=; b=WQRLpq3djGpeckXalGinbjX4bx/+hxuCY2uNjrG00Wy2C0QCujLEYu6khK6LOjIOZoNxZN djU+uI1kRDz9LMzcZ4dtgKpQaP0o2BF3ucc6E1AAgAJTw+XGyKYIfv4lqtJ5AGcyd2q7BK q3seC2pDUAUl5nisdk5T88ffEsmth6k= X-MC-Unique: PxLb73QhPM2pUm2SZUcbrw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v5 26/32] qemu: try to connect to nbdkit early to detect errors Date: Tue, 14 Feb 2023 11:08:13 -0600 Message-Id: <20230214170819.3143132-27-jjongsma@redhat.com> In-Reply-To: <20230214170819.3143132-1-jjongsma@redhat.com> References: <20230214170819.3143132-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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.3 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: 1676394604899100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When using nbdkit to serve a network disk source, the nbdkit process will start and wait for an nbd connection before actually attempting to connect to the (remote) disk location. Because of this, nbdkit will not report an error until after qemu is launched and tries to read from the disk. This results in a fairly user-unfriendly error saying that qemu was unable to start because "Requested export not available". Ideally we'd like to be able to tell the user *why* the export is not available, but this sort of information is only available to nbdkit, not qemu. It could be because the url was incorrect, or because of an authentication failure, or one of many other possibilities. To make this friendlier for users and easier to detect misconfigurations, try to connect to nbdkit immediately after starting nbdkit and before we try to start qemu. This requires adding a dependency on libnbd. If an error occurs when connecting to nbdkit, read back from the nbdkit error log and provide that information in the error report from qemuNbdkitProcessStart(). User-visible change demonstrated below: Previous error: $ virsh start nbdkit-test 2023-01-18 19:47:45.778+0000: 30895: error : virNetClientProgramDispatc= hError:172 : internal error: process exited while connecting to monitor: 2023-01-18T19:47:45.= 704658Z qemu-system-x86_64: -blockdev {"driver":"nbd","server":{"type":"unix", "path":"/var/lib/libvirt/qemu/domain-1-nbdkit-test/nbdkit-libvirt-1-sto= rage.socket"}, "node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"= }: Requested export not available error: Failed to start domain 'nbdkit-test' error: internal error: process exited while connecting to monitor: 2023= -01-18T19:47:45.704658Z qemu-system-x86_64: -blockdev {"driver":"nbd","server":{"type":"unix", "path":"/var/lib/libvirt/qemu/domain-1-nbdkit-test/nbdkit-libvirt-1-sto= rage.socket"}, "node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"= }: Requested export not available After this change: $ virsh start nbdkit-test 2023-01-18 19:44:36.242+0000: 30895: error : virNetClientProgramDispatc= hError:172 : internal error: Failed to connect to nbdkit for 'http://localhost:8888/nonexiste= nt.iso': nbdkit: curl[1]: error: problem doing HEAD request to fetch size of URL [http://localhos= t:8888/nonexistent.iso]: HTTP response code said error: The requested URL returned error: 404 error: Failed to start domain 'nbdkit-test' error: internal error: Failed to connect to nbdkit for 'http://localhos= t:8888/nonexistent.iso]: error: problem doing HEAD request to fetch size of URL [http://localhos= t:8888/nonexistent.iso]: HTTP response code said error: The requested URL returned error: 404 Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- meson.build | 7 +++++++ meson_options.txt | 1 + src/qemu/meson.build | 1 + src/qemu/qemu_nbdkit.c | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/meson.build b/meson.build index 048b15ff71..83692bef22 100644 --- a/meson.build +++ b/meson.build @@ -959,6 +959,12 @@ 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) +endif + libnl_version =3D '3.0' if not get_option('libnl').disabled() and host_machine.system() =3D=3D 'li= nux' libnl_dep =3D dependency('libnl-3.0', version: '>=3D' + libnl_version, r= equired: get_option('libnl')) @@ -2200,6 +2206,7 @@ libs_summary =3D { 'glusterfs': glusterfs_dep.found(), 'libiscsi': libiscsi_dep.found(), 'libkvm': libkvm_dep.found(), + 'libnbd': libnbd_dep.found(), 'libnl': libnl_dep.found(), 'libparted': libparted_dep.found(), 'libpcap': libpcap_dep.found(), diff --git a/meson_options.txt b/meson_options.txt index 861c5577d2..2d68bd7349 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -24,6 +24,7 @@ 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') diff --git a/src/qemu/meson.build b/src/qemu/meson.build index 6d7a1bfbb0..607b597c8c 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -99,6 +99,7 @@ if conf.has('WITH_QEMU') access_dep, capng_dep, gnutls_dep, + libnbd_dep, libnl_dep, log_dep, selinux_dep, diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 74e2ceee19..b2527eff2d 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -19,6 +19,9 @@ =20 #include #include +#if WITH_LIBNBD +# include +#endif #include =20 #include "vircommand.h" @@ -27,6 +30,7 @@ #include "virlog.h" #include "virpidfile.h" #include "virsecureerase.h" +#include "virstring.h" #include "virtime.h" #include "virutil.h" #include "qemu_block.h" @@ -1157,6 +1161,9 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, g_autofree char *errmsg =3D NULL; g_autoptr(virURI) uri =3D NULL; g_autofree char *uristring =3D NULL; +#if WITH_LIBNBD + struct nbd_handle *nbd =3D NULL; +#endif =20 if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc))) return -1; @@ -1211,6 +1218,23 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, goto error; } =20 +#if WITH_LIBNBD + /* if the disk source was misconfigured, nbdkit will not produce an er= ror + * until somebody connects to the socket and tries to access the nbd + * export. This results in poor user experience because the only error= we + * would get from qemu is something like "Requested export not availab= le". + * So let's try to access it ourselves so that we can error out early = and + * provide a useful message to the user. + */ + nbd =3D nbd_create(); + if (nbd_connect_unix(nbd, proc->socketfile) < 0) { + VIR_WARN("nbd_connect_unix failed: %s", nbd_get_error()); + nbd_close(nbd); + goto error; + } + nbd_close(nbd); +#endif + if (qemuNbdkitProcessStartMonitor(proc, vm) < 0) goto error; =20 --=20 2.39.1