From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891628; cv=none; d=zohomail.com; s=zohoarc; b=fK13mJkf2XUA4M5cnr1c2nxJci/dZ1Azkkvl/n24RxbAR6OaoQRUfNaOI4rM48ukO/mmdlsy5T2SpgjRXSab/HbZmz2eW+i8FmsdHEK9UWn3fmPrW7NOtKbsCoe3sLWm+TBIBALBmgMKFA8qBIAH+hhOPS6tCp53wDnzhyqKaWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891628; h=Content-Type:Content-Transfer-Encoding:Cc: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=JN957JB7P/oZwDQMrWk2mEcKbbe0ZSCGMjrSHnTFEfY=; b=bZR/X5hAdJCoHMkRhyhE65ZVFHTq5fLLBFGtsZg88dpXQxz8B24uLmAvaT/yLhBuIIjT9DlhV3R1FZoSSoC+uvjssvDGpCn7lsh9galEJWjta9ziqNnmlJad9ZF3j2JUdSNtOgznGj+/CPFGapmivUKhxEt8IgbYNeQ42dT3rvw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891628284713.3897982240186; Thu, 20 Jul 2023 15:20:28 -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-137-C5MelRPzM5WbEpU27SrPUw-1; Thu, 20 Jul 2023 18:20:23 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D7618F1854; Thu, 20 Jul 2023 22:20:18 +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 75B03C5796C; Thu, 20 Jul 2023 22:20:15 +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 0A6611946A45; Thu, 20 Jul 2023 22:20:15 +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 66D5A19465BD for ; Thu, 20 Jul 2023 22:20:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A665B40C2072; Thu, 20 Jul 2023 22:20:04 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7998D40C206F; Thu, 20 Jul 2023 22:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891627; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=JN957JB7P/oZwDQMrWk2mEcKbbe0ZSCGMjrSHnTFEfY=; b=QlTFG/VVydSkHq1wbNSVAKAFqB5Qj9lPaj20q+UXUPMYbCRhv5TRFTusjjvt/h06gmV+TW 78nIAIDYOGte5yZ6elHtGwP8O82INpWKFdSEqwV9J5DiDQOI5W2u5CugGrO+EBU6e/cuzT 4cpIbw3hbwvVbFeIWjLlfpt58QdNtBg= X-MC-Unique: C5MelRPzM5WbEpU27SrPUw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 01/36] schema: allow 'ssh' as a protocol for network disks Date: Thu, 20 Jul 2023 17:19:28 -0500 Message-ID: <20230720222003.411549-2-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1689891630184100006 Content-Type: text/plain; charset="utf-8"; x-default="true" There was support in the code for parsing protocol=3D'ssh' on network disk sources, but it was not present in the xml schema. Add this to the schema. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/conf/schemas/domaincommon.rng | 1 + tests/qemublocktest.c | 2 +- ...w2-invalid.json =3D> network-ssh-qcow2.json} | 0 ...cow2-invalid.xml =3D> network-ssh-qcow2.xml} | 0 .../disk-network-ssh.x86_64-latest.args | 35 +++++++++++++++++++ tests/qemuxml2argvdata/disk-network-ssh.xml | 31 ++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 7 files changed, 69 insertions(+), 1 deletion(-) rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2-invalid.json= =3D> network-ssh-qcow2.json} (100%) rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2-invalid.xml = =3D> network-ssh-qcow2.xml} (100%) create mode 100644 tests/qemuxml2argvdata/disk-network-ssh.x86_64-latest.a= rgs create mode 100644 tests/qemuxml2argvdata/disk-network-ssh.xml diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index c2f56b0490..2284e3c949 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2194,6 +2194,7 @@ sheepdog tftp + ssh diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 9a968477d7..8bad69e7ac 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -1213,7 +1213,7 @@ mymain(void) =20 TEST_IMAGE_CREATE("network-gluster-qcow2", NULL); TEST_IMAGE_CREATE("network-rbd-qcow2", NULL); - TEST_IMAGE_CREATE("network-ssh-qcow2-invalid", NULL); + TEST_IMAGE_CREATE("network-ssh-qcow2", NULL); =20 #define TEST_BITMAP_DETECT(testname) \ do { \ diff --git a/tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.= json b/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.json similarity index 100% rename from tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.j= son rename to tests/qemublocktestdata/imagecreate/network-ssh-qcow2.json diff --git a/tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.= xml b/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml similarity index 100% rename from tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.x= ml rename to tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml diff --git a/tests/qemuxml2argvdata/disk-network-ssh.x86_64-latest.args b/t= ests/qemuxml2argvdata/disk-network-ssh.x86_64-latest.args new file mode 100644 index 0000000000..b7fd30032b --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh.x86_64-latest.args @@ -0,0 +1,35 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel kvm \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"ssh","path":"test.img","server":{"host":"example.org= ","port":"2222"},"node-name":"libvirt-1-storage","auto-read-only":true,"dis= card":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ","file":"libvirt-1-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-1-format","id":"virtio-disk0","bootindex":1}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-network-ssh.xml b/tests/qemuxml2ar= gvdata/disk-network-ssh.xml new file mode 100644 index 0000000000..355add4fea --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh.xml @@ -0,0 +1,31 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + + + + + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 534eb9e699..52d206d00f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1219,6 +1219,7 @@ mymain(void) VIR_FREE(driver.config->nbdTLSx509secretUUID); VIR_FREE(driver.config->vxhsTLSx509secretUUID); driver.config->vxhsTLS =3D 0; + DO_TEST_CAPS_LATEST("disk-network-ssh"); DO_TEST_CAPS_LATEST("disk-no-boot"); DO_TEST_CAPS_LATEST("disk-nvme"); DO_TEST_CAPS_VER("disk-vhostuser-numa", "4.2.0"); --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891728; cv=none; d=zohomail.com; s=zohoarc; b=RuVbDo+Un0+eSzWIXMDEy9gnkNbvU+SjjCSHn9KBpziAvD01nAxLHtcvxeYCf90K0hQ7peXJ699JSLgCeuL3A8ZEtBPsbsDmxTPYciSJGQtPZTaGEvPdOvjOzp1d+JT5o5eEdeCgGvY7vKZI6U1ijDkpbqM75p3rIRFWSEugxAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891728; h=Content-Type:Content-Transfer-Encoding:Cc: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=H4/Ui5/RhmGo9FTk2OKwvzxi9bilfhbcOSOkl0FLueM=; b=A4pfqbWa5BY9LfvQ8pIaILEJ+TOsyEJvHviuyUbpp6i8bALAmnrKqE08boc1A+UErKRgBymj0A1siN98trT7ZaZb5ohg8gJUK2dpmLtAh5rA/YqAv/+493xwZYE+XiwL/xa75PU3u8k7tkgoxoqnnKwM2+N2YXb/xpn8TjTRhKo= 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 1689891728901433.49971838933493; Thu, 20 Jul 2023 15:22:08 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-ln_D3FsMO9O0AB72wjvnTA-1; Thu, 20 Jul 2023 18:20:47 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B81512800EB1; Thu, 20 Jul 2023 22:20:35 +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 A2ADB40C2074; Thu, 20 Jul 2023 22:20:35 +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 3E2A71946A7A; Thu, 20 Jul 2023 22:20:24 +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 64BD919465BA for ; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id ECF0D40C2071; Thu, 20 Jul 2023 22:20:04 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B9A1540C206F; Thu, 20 Jul 2023 22:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891727; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=H4/Ui5/RhmGo9FTk2OKwvzxi9bilfhbcOSOkl0FLueM=; b=VTVAMsmarMVTDbON4BvJTqwq2P5MNxt6EhWNGGssPv0tM/1fUuaE/XxGYFmDs8E2/KPhPx iwJv1YmpmlZuMB7fXo+QbAkojBbUUa5qUAMiZhPPwoSZjk4WnusYgtI5cmbLqqeyXW4xB7 jjvALrasZDvO4i01deJuNpQXWPxDHF8= X-MC-Unique: ln_D3FsMO9O0AB72wjvnTA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 02/36] qemu: Add functions for determining nbdkit availability Date: Thu, 20 Jul 2023 17:19:29 -0500 Message-ID: <20230720222003.411549-3-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa 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: 1689891730995100013 Content-Type: text/plain; charset="utf-8"; x-default="true" In future commits, we will optionally use nbdkit to serve some remote disk sources. This patch queries to see whether nbdkit is installed on the host and queries it for capabilities. The data will be used in later commits. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/meson.build | 1 + src/qemu/qemu_conf.h | 1 + src/qemu/qemu_nbdkit.c | 201 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 50 ++++++++++ 4 files changed, 253 insertions(+) create mode 100644 src/qemu/qemu_nbdkit.c create mode 100644 src/qemu/qemu_nbdkit.h diff --git a/src/qemu/meson.build b/src/qemu/meson.build index c8806bbc36..9be6996195 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -28,6 +28,7 @@ qemu_driver_sources =3D [ 'qemu_monitor_json.c', 'qemu_monitor_text.c', 'qemu_namespace.c', + 'qemu_nbdkit.c', 'qemu_passt.c', 'qemu_process.c', 'qemu_qapi.c', diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 11c740d28f..4f610d86a1 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -36,6 +36,7 @@ #include "virthreadpool.h" #include "locking/lock_manager.h" #include "qemu_capabilities.h" +#include "qemu_nbdkit.h" #include "virclosecallbacks.h" #include "virhostdev.h" #include "virfile.h" diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c new file mode 100644 index 0000000000..9ff293698d --- /dev/null +++ b/src/qemu/qemu_nbdkit.c @@ -0,0 +1,201 @@ +/* + * qemu_nbdkit.c: helpers for using nbdkit + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#include +#include + +#include "vircommand.h" +#include "virerror.h" +#include "virlog.h" +#include "virpidfile.h" +#include "virutil.h" +#include "qemu_block.h" +#include "qemu_conf.h" +#include "qemu_domain.h" +#include "qemu_driver.h" +#include "qemu_extdevice.h" +#include "qemu_nbdkit.h" +#include "qemu_security.h" + +#include + +#define VIR_FROM_THIS VIR_FROM_QEMU + +VIR_LOG_INIT("qemu.nbdkit"); + +VIR_ENUM_IMPL(qemuNbdkitCaps, + QEMU_NBDKIT_CAPS_LAST, + /* 0 */ + "plugin-curl", /* QEMU_NBDKIT_CAPS_PLUGIN_CURL */ + "plugin-ssh", /* QEMU_NBDKIT_CAPS_PLUGIN_SSH */ + "filter-readahead", /* QEMU_NBDKIT_CAPS_FILTER_READAHEAD */ +); + +struct _qemuNbdkitCaps { + GObject parent; + + char *path; + char *version; + + virBitmap *flags; +}; +G_DEFINE_TYPE(qemuNbdkitCaps, qemu_nbdkit_caps, G_TYPE_OBJECT); + + +static void +qemuNbdkitCheckCommandCap(qemuNbdkitCaps *nbdkit, + virCommand *cmd, + qemuNbdkitCapsFlags cap) +{ + if (virCommandRun(cmd, NULL) !=3D 0) + return; + + VIR_DEBUG("Setting nbdkit capability %i", cap); + ignore_value(virBitmapSetBit(nbdkit->flags, cap)); +} + + +static void +qemuNbdkitQueryFilter(qemuNbdkitCaps *nbdkit, + const char *filter, + qemuNbdkitCapsFlags cap) +{ + g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, + "--version", + NULL); + + virCommandAddArgPair(cmd, "--filter", filter); + + /* use null plugin to check for filter */ + virCommandAddArg(cmd, "null"); + + qemuNbdkitCheckCommandCap(nbdkit, cmd, cap); +} + + +static void +qemuNbdkitQueryPlugin(qemuNbdkitCaps *nbdkit, + const char *plugin, + qemuNbdkitCapsFlags cap) +{ + g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, + plugin, + "--version", + NULL); + + qemuNbdkitCheckCommandCap(nbdkit, cmd, cap); +} + + +static void +qemuNbdkitCapsQueryPlugins(qemuNbdkitCaps *nbdkit) +{ + qemuNbdkitQueryPlugin(nbdkit, "curl", QEMU_NBDKIT_CAPS_PLUGIN_CURL); + qemuNbdkitQueryPlugin(nbdkit, "ssh", QEMU_NBDKIT_CAPS_PLUGIN_SSH); +} + + +static void +qemuNbdkitCapsQueryFilters(qemuNbdkitCaps *nbdkit) +{ + qemuNbdkitQueryFilter(nbdkit, "readahead", + QEMU_NBDKIT_CAPS_FILTER_READAHEAD); +} + + +static int +qemuNbdkitCapsQueryVersion(qemuNbdkitCaps *nbdkit) +{ + g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, + "--version", + NULL); + + virCommandSetOutputBuffer(cmd, &nbdkit->version); + + if (virCommandRun(cmd, NULL) !=3D 0) + return -1; + + VIR_DEBUG("Got nbdkit version %s", nbdkit->version); + return 0; +} + + +static void +qemuNbdkitCapsFinalize(GObject *object) +{ + qemuNbdkitCaps *nbdkit =3D QEMU_NBDKIT_CAPS(object); + + g_clear_pointer(&nbdkit->path, g_free); + g_clear_pointer(&nbdkit->version, g_free); + g_clear_pointer(&nbdkit->flags, virBitmapFree); + + G_OBJECT_CLASS(qemu_nbdkit_caps_parent_class)->finalize(object); +} + + +void +qemu_nbdkit_caps_init(qemuNbdkitCaps *caps) +{ + caps->flags =3D virBitmapNew(QEMU_NBDKIT_CAPS_LAST); + caps->version =3D NULL; +} + + +static void +qemu_nbdkit_caps_class_init(qemuNbdkitCapsClass *klass) +{ + GObjectClass *obj =3D G_OBJECT_CLASS(klass); + + obj->finalize =3D qemuNbdkitCapsFinalize; +} + + +qemuNbdkitCaps * +qemuNbdkitCapsNew(const char *path) +{ + qemuNbdkitCaps *caps =3D g_object_new(QEMU_TYPE_NBDKIT_CAPS, NULL); + caps->path =3D g_strdup(path); + + return caps; +} + + +G_GNUC_UNUSED static void +qemuNbdkitCapsQuery(qemuNbdkitCaps *caps) +{ + qemuNbdkitCapsQueryPlugins(caps); + qemuNbdkitCapsQueryFilters(caps); + qemuNbdkitCapsQueryVersion(caps); +} + + +bool +qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, + qemuNbdkitCapsFlags flag) +{ + return virBitmapIsBitSet(nbdkitCaps->flags, flag); +} + + +void +qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, + qemuNbdkitCapsFlags flag) +{ + ignore_value(virBitmapSetBit(nbdkitCaps->flags, flag)); +} diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h new file mode 100644 index 0000000000..e191e1fdb4 --- /dev/null +++ b/src/qemu/qemu_nbdkit.h @@ -0,0 +1,50 @@ +/* + * qemu_nbdkit.h: helpers for using nbdkit + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#pragma once + +#include "internal.h" +#include "virenum.h" + +typedef struct _qemuNbdkitCaps qemuNbdkitCaps; + +typedef enum { + /* 0 */ + QEMU_NBDKIT_CAPS_PLUGIN_CURL, + QEMU_NBDKIT_CAPS_PLUGIN_SSH, + QEMU_NBDKIT_CAPS_FILTER_READAHEAD, + + QEMU_NBDKIT_CAPS_LAST, +} qemuNbdkitCapsFlags; + +VIR_ENUM_DECL(qemuNbdkitCaps); + +qemuNbdkitCaps * +qemuNbdkitCapsNew(const char *path); + +bool +qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, + qemuNbdkitCapsFlags flag); + +void +qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, + qemuNbdkitCapsFlags flag); + +#define QEMU_TYPE_NBDKIT_CAPS qemu_nbdkit_caps_get_type() +G_DECLARE_FINAL_TYPE(qemuNbdkitCaps, qemu_nbdkit_caps, QEMU, NBDKIT_CAPS, = GObject); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891629; cv=none; d=zohomail.com; s=zohoarc; b=UZD6K6kd4MpN8t9FQzINQ1q8cp2Idpn0vjDpKBFPgZOkzPbdxPRjEqQiQN/Wyf7NRqVxCwEvprfdJ/VPNXRzzl7cq3H1hWdZcCDAp9jRLS+fbeYtZc0DMhnjhRS5WUdEiViGK9rnRVYqZq0MVgJiLM4ypg1iWAIYZ0VV7Y5RUuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891629; h=Content-Type:Content-Transfer-Encoding:Cc: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=qG652P2mtOZpHfwoFkmVbucMb2waM65ryO9FDThFoVI=; b=dj09KIaDkOOnQIHEOvyP1OhkxHZQQ7GJWzbGxlNYugPbD9RFmh9hh3tUHWwT/YPRMIkDD+K5nUSNlymHL4JvU2zWlqzvQ/VdaW0TEG4SyaPEHxc13/hl/MRuiQDvAUo62rUE//5G3XR+e2so4lWh/2yxX9lTJcFCa7z/jMmkD2E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891629465624.4171608828996; Thu, 20 Jul 2023 15:20:29 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-115-VTh9cFq5MWGS9d4eoY2zbw-1; Thu, 20 Jul 2023 18:20:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 828CF1C068EB; Thu, 20 Jul 2023 22:20:20 +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 66E40207B359; Thu, 20 Jul 2023 22:20: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 733FE1949739; Thu, 20 Jul 2023 22:20:16 +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 6AEF81946A49 for ; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 36F1840C2073; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C1C640C206F; Thu, 20 Jul 2023 22:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891628; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=qG652P2mtOZpHfwoFkmVbucMb2waM65ryO9FDThFoVI=; b=ISNEJwgmM2XGB5FksqzVndN0BeqTlIPS0cg/3ZlL2sDBafv16VkITfIdP5No1CMEMVScwV AsMiIV574LXoMsIv81yA6yziE1gRO2XqfAn87WIxyLfmvwlnLasn922OzsXoicBDuwb9L/ YDvX1Zfuf+33bEjijE6OvVJp+zgGL9k= X-MC-Unique: VTh9cFq5MWGS9d4eoY2zbw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 03/36] qemu: expand nbdkit capabilities Date: Thu, 20 Jul 2023 17:19:30 -0500 Message-ID: <20230720222003.411549-4-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891630150100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In order to add caching of the nbdkit capabilities, we will need to compare against file modification times, etc. So look up this information when creating the nbdkit caps. Add a nbdkit_moddir build option to allow the builder to specify the location to look for nbdkit plugins and filters. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 9ff293698d..486df8c161 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -20,6 +20,7 @@ #include #include =20 +#include "configmake.h" #include "vircommand.h" #include "virerror.h" #include "virlog.h" @@ -39,6 +40,10 @@ =20 VIR_LOG_INIT("qemu.nbdkit"); =20 +#define NBDKIT_MODDIR LIBDIR "/nbdkit" +#define NBDKIT_PLUGINDIR NBDKIT_MODDIR "/plugins" +#define NBDKIT_FILTERDIR NBDKIT_MODDIR "/filters" + VIR_ENUM_IMPL(qemuNbdkitCaps, QEMU_NBDKIT_CAPS_LAST, /* 0 */ @@ -52,6 +57,11 @@ struct _qemuNbdkitCaps { =20 char *path; char *version; + time_t ctime; + time_t libvirtCtime; + time_t pluginDirMtime; + time_t filterDirMtime; + unsigned int libvirtVersion; =20 virBitmap *flags; }; @@ -176,9 +186,41 @@ qemuNbdkitCapsNew(const char *path) } =20 =20 +static time_t +qemuNbdkitGetDirMtime(const char *moddir) +{ + struct stat st; + + if (stat(moddir, &st) < 0) { + VIR_DEBUG("Failed to stat nbdkit module directory '%s': %s", + moddir, + g_strerror(errno)); + return 0; + } + + return st.st_mtime; +} + + G_GNUC_UNUSED static void qemuNbdkitCapsQuery(qemuNbdkitCaps *caps) { + struct stat st; + + if (stat(caps->path, &st) < 0) { + VIR_DEBUG("Failed to stat nbdkit binary '%s': %s", + caps->path, + g_strerror(errno)); + caps->ctime =3D 0; + return; + } + + caps->ctime =3D st.st_ctime; + caps->filterDirMtime =3D qemuNbdkitGetDirMtime(NBDKIT_FILTERDIR); + caps->pluginDirMtime =3D qemuNbdkitGetDirMtime(NBDKIT_PLUGINDIR); + caps->libvirtCtime =3D virGetSelfLastChanged(); + caps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; + qemuNbdkitCapsQueryPlugins(caps); qemuNbdkitCapsQueryFilters(caps); qemuNbdkitCapsQueryVersion(caps); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891652; cv=none; d=zohomail.com; s=zohoarc; b=AsQ5HOPlDySMi7tjq4jEZYYN7Cu9laFdweiP+2WjkAEsWQxyKdg0jBDKRYm8O0HV+qAehJ/f3qjjDLNoWgN+e4VcrIGCC2HgvZRs6hRCfVsK1NwKiljYDODpXdLJnNmXZeBW705INUBFqofq4JuakTr7XdlRL63r2zWz8Jy5b1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891652; h=Content-Type:Content-Transfer-Encoding:Cc: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=7dWVaqdn/rRkdrOr49v+m2riQ6SW6Ns4ceGDzDHQdn0=; b=Hp2DYJBnWjag0g2GcEFJlc935qyjniwQjQaULoQuCcU8KnqfyM0Bc9TV+gVsTAD7+dllnLXdpL+CNUUI8/hXrmzKc+EtcteoP04L/K3Xfli+GLy1lqvpMsA6XQTlI38Z/p3u6QtAJY7J/zoNJJsr/hFFgx6vesFPUqIH6LWB9G4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891652413552.9280112782321; Thu, 20 Jul 2023 15:20:52 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-649-QWkUQ-VeNmWNTQyodvetdQ-1; Thu, 20 Jul 2023 18:20:44 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9033A1C0897E; Thu, 20 Jul 2023 22:20:36 +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 74ED5492CAD; Thu, 20 Jul 2023 22:20:36 +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 A120F19376C3; Thu, 20 Jul 2023 22:20:24 +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 68D891946A43 for ; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 74B8E40C2074; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A78540C206F; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891651; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=7dWVaqdn/rRkdrOr49v+m2riQ6SW6Ns4ceGDzDHQdn0=; b=fihNWmBifKOGOSP1z4Sk2KTrAHHf5iN0hPtjnwebGNeV8ojidBaf5uw9A/oLI5YYfO2V1y 8Ao40UpzQHFRnKduqlCNc1SnOg2V2JYMcBhjHW1tOSz2rm2aCffLm+KsbzIay3d21hujUZ Ms42OFv+uHaAEUSvUGzsSEIuGLe0fSQ= X-MC-Unique: QWkUQ-VeNmWNTQyodvetdQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 04/36] util: Allow virFileCache data to be any GObject Date: Thu, 20 Jul 2023 17:19:31 -0500 Message-ID: <20230720222003.411549-5-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: 1689891654234100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Since the libvirt documentation suggests to prefer GObject over virObject, and since virObject is a GObject, change virFileCache to allow GObjects as data. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/util/virfilecache.c | 14 ++++++++------ src/util/virfilecache.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index c730de066e..6f698016a1 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -170,7 +170,7 @@ virFileCacheLoad(virFileCache *cache, *data =3D g_steal_pointer(&loadData); =20 cleanup: - virObjectUnref(loadData); + g_clear_pointer(&loadData, g_object_unref); return ret; } =20 @@ -207,7 +207,7 @@ virFileCacheNewData(virFileCache *cache, return NULL; =20 if (virFileCacheSave(cache, name, data) < 0) { - g_clear_pointer(&data, virObjectUnref); + g_clear_object(&data); } } =20 @@ -239,7 +239,7 @@ virFileCacheNew(const char *dir, if (!(cache =3D virObjectNew(virFileCacheClass))) return NULL; =20 - cache->table =3D virHashNew(virObjectUnref); + cache->table =3D virHashNew(g_object_unref); =20 cache->dir =3D g_strdup(dir); =20 @@ -270,7 +270,7 @@ virFileCacheValidate(virFileCache *cache, if (*data) { VIR_DEBUG("Caching data '%p' for '%s'", *data, name); if (virHashAddEntry(cache->table, name, *data) < 0) { - g_clear_pointer(data, virObjectUnref); + g_clear_pointer(data, g_object_unref); } } } @@ -300,7 +300,8 @@ virFileCacheLookup(virFileCache *cache, data =3D virHashLookup(cache->table, name); virFileCacheValidate(cache, name, &data); =20 - virObjectRef(data); + if (data) + g_object_ref(data); virObjectUnlock(cache); =20 return data; @@ -331,7 +332,8 @@ virFileCacheLookupByFunc(virFileCache *cache, data =3D virHashSearch(cache->table, iter, iterData, &name); virFileCacheValidate(cache, name, &data); =20 - virObjectRef(data); + if (data) + g_object_ref(data); virObjectUnlock(cache); =20 return data; diff --git a/src/util/virfilecache.h b/src/util/virfilecache.h index c3bc0f529c..944741c0a7 100644 --- a/src/util/virfilecache.h +++ b/src/util/virfilecache.h @@ -48,7 +48,7 @@ typedef bool * @priv: private data created together with cache * * Creates a new data based on the @name. The returned data must be - * an instance of virObject. + * an instance of GObject. * * Returns data object or NULL on error. */ --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891725; cv=none; d=zohomail.com; s=zohoarc; b=WbHTpMxvqRkgAd5YywWAtmc9KD6BLzdmOtRib2giie5714xy/1qQjlav/eGJOX36d/KVhWlI0rbtx8vFSeLL+AG6JEcFiPgIBw9O5Hd2HxuJ/J/IjKMsedMMToJSIlDgomKlOuDHup0ROQEbn46frZ7LDT99QAdJi119KWPt+pI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891725; h=Content-Type:Content-Transfer-Encoding:Cc: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=isQQe1TpKG0Y6D6nZSM/L3QavRmA2+tgiugjaD8C454=; b=fc0775H9FTm7bCQ6aW478I1xc0c5LtUQ8uXFOuVzfmEb2Rnf2pVWEUm71P9P0/RAKWp/XRAIB9/rmkiGCCgo0lUYTClwCXkBnvuSvUlySJryo38sW9JM5w8epXd1uWjqOXZzvh+EPvTX9q7fvAIT2koYZJnOQTh16gWZgwclI9c= 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 1689891725752856.441282045316; Thu, 20 Jul 2023 15:22:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-151-GZIkLTrDNEGJ8I6Ddc_Jvw-1; Thu, 20 Jul 2023 18:20:50 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 22EB11C075B8; Thu, 20 Jul 2023 22:20: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 0E568C57969; Thu, 20 Jul 2023 22:20: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 4A90D19451F8; Thu, 20 Jul 2023 22:20:20 +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 89C671946A43 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B390B40C2075; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 888D940C206F; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891724; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=isQQe1TpKG0Y6D6nZSM/L3QavRmA2+tgiugjaD8C454=; b=NY4p2eVq1VIx+DBDFIKTFBTuVOI9tJi00dY6fqRvC0VPlTya6xul38fmSLoH70hYTTmoaF MHctjwQxU6KztstYRvqdWHnKeW3RMLdqclvD6iuhfD/mWbfYzWHQOE07ItytE/bVrUL8WF jFzmKqgK+XmHKr2FrWKUp9+whR2kIM0= X-MC-Unique: GZIkLTrDNEGJ8I6Ddc_Jvw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 05/36] qemu: implement basic virFileCache for nbdkit caps Date: Thu, 20 Jul 2023 17:19:32 -0500 Message-ID: <20230720222003.411549-6-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1689891726913100004 Content-Type: text/plain; charset="utf-8"; x-default="true" Preparatory step for caching nbdkit capabilities. This patch implements the newData and isValid virFileCacheHandlers callback functions. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 89 +++++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_nbdkit.h | 4 ++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 486df8c161..cd6fe41910 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -202,7 +202,7 @@ qemuNbdkitGetDirMtime(const char *moddir) } =20 =20 -G_GNUC_UNUSED static void +static void qemuNbdkitCapsQuery(qemuNbdkitCaps *caps) { struct stat st; @@ -241,3 +241,90 @@ qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, { ignore_value(virBitmapSetBit(nbdkitCaps->flags, flag)); } + + +static bool +virNbkditCapsCheckModdir(const char *moddir, + time_t expectedMtime) +{ + time_t mtime =3D qemuNbdkitGetDirMtime(moddir); + + if (mtime !=3D expectedMtime) { + VIR_DEBUG("Outdated capabilities for nbdkit: module directory '%s'= changed (%lld vs %lld)", + moddir, (long long)mtime, (long long)expectedMtime); + return false; + } + return true; +} + + +static bool +virNbdkitCapsIsValid(void *data, + void *privData G_GNUC_UNUSED) +{ + qemuNbdkitCaps *nbdkitCaps =3D data; + struct stat st; + + if (!nbdkitCaps->path) + return true; + + if (!virNbkditCapsCheckModdir(NBDKIT_PLUGINDIR, nbdkitCaps->pluginDirM= time)) + return false; + if (!virNbkditCapsCheckModdir(NBDKIT_FILTERDIR, nbdkitCaps->filterDirM= time)) + return false; + + if (nbdkitCaps->libvirtCtime !=3D virGetSelfLastChanged() || + nbdkitCaps->libvirtVersion !=3D LIBVIR_VERSION_NUMBER) { + VIR_DEBUG("Outdated capabilities for '%s': libvirt changed (%lld v= s %lld, %lu vs %lu)", + nbdkitCaps->path, + (long long)nbdkitCaps->libvirtCtime, + (long long)virGetSelfLastChanged(), + (unsigned long)nbdkitCaps->libvirtVersion, + (unsigned long)LIBVIR_VERSION_NUMBER); + return false; + } + + if (stat(nbdkitCaps->path, &st) < 0) { + VIR_DEBUG("Failed to stat nbdkit binary '%s': %s", + nbdkitCaps->path, + g_strerror(errno)); + return false; + } + + if (st.st_ctime !=3D nbdkitCaps->ctime) { + VIR_DEBUG("Outdated capabilities for '%s': nbdkit binary changed (= %lld vs %lld)", + nbdkitCaps->path, + (long long)st.st_ctime, (long long)nbdkitCaps->ctime); + return false; + } + + return true; +} + + +static void* +virNbdkitCapsNewData(const char *binary, + void *privData G_GNUC_UNUSED) +{ + qemuNbdkitCaps *caps =3D qemuNbdkitCapsNew(binary); + qemuNbdkitCapsQuery(caps); + + return caps; +} + + +virFileCacheHandlers nbdkitCapsCacheHandlers =3D { + .isValid =3D virNbdkitCapsIsValid, + .newData =3D virNbdkitCapsNewData, + .loadFile =3D NULL, + .saveFile =3D NULL, + .privFree =3D NULL, +}; + + +virFileCache* +qemuNbdkitCapsCacheNew(const char *cachedir) +{ + g_autofree char *dir =3D g_build_filename(cachedir, "nbdkitcapabilitie= s", NULL); + return virFileCacheNew(dir, "xml", &nbdkitCapsCacheHandlers); +} diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index e191e1fdb4..4aba7c8455 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -21,6 +21,7 @@ =20 #include "internal.h" #include "virenum.h" +#include "virfilecache.h" =20 typedef struct _qemuNbdkitCaps qemuNbdkitCaps; =20 @@ -38,6 +39,9 @@ VIR_ENUM_DECL(qemuNbdkitCaps); qemuNbdkitCaps * qemuNbdkitCapsNew(const char *path); =20 +virFileCache * +qemuNbdkitCapsCacheNew(const char *cachedir); + bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags flag); --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891628; cv=none; d=zohomail.com; s=zohoarc; b=TYrGpTgZHcJvUSsgkQ5bzOvkii8rPv66+w8HqsM5CeHxe17d3QbXq90CsrHgIIhi7OS9czpby1yAoyqje1c5w6jYjFdCcJj5NwiqcCFPUowGjMIO1VVKpknhw1uy3ntNQOH/FuzgIHecer7jfhvCngYQ0nulZnPVroOaJFeQxOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891628; h=Content-Type:Content-Transfer-Encoding:Cc: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=dPmay69nGfLfc0ZXYWJpXC3bP7qi5SCMqR8pTT1Snvw=; b=coAF0xDYpPDAOLM71V8JzGa0tCW8ab5KGOrrI3uvAs4B0DDFwhlz7k/DMmS8RtsWJT7LiJ065wqSuiWF5+QThylRpX2wqWWXyitHYe5HZy8kI+xEnxLXBArbGI/6Qfl39tv2fPqemWvhLrqROkJ4/X1JsoqJNj0o99u0kxkPsw0= 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 1689891628826948.143543238784; Thu, 20 Jul 2023 15:20:28 -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-176-zeslyyr-PauEwdYQOnA2Og-1; Thu, 20 Jul 2023 18:20:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2BCAD185A7A4; Thu, 20 Jul 2023 22:20:18 +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 B41DCF77BD; Thu, 20 Jul 2023 22:20:17 +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 9AF6B19451C1; Thu, 20 Jul 2023 22:20:15 +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 89D311946A69 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F137A40C2076; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C689940C206F; Thu, 20 Jul 2023 22:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891627; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=dPmay69nGfLfc0ZXYWJpXC3bP7qi5SCMqR8pTT1Snvw=; b=c+RU4pltkL3iiXNkKcV+N3bgI6taAMWyGWT8+QRbzqRJQ/y90f73eLyvr8k75UvfrLQouf 5gkjjdHEckUv7fTUISGdg8BvT6hNxKHzpY/9CfZYNbYvpTMD7iQLwN5s378uOqezhoC5zy Y1KCecEAvv2lOlfT7e011yy8CmlI3tE= X-MC-Unique: zeslyyr-PauEwdYQOnA2Og-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 06/36] qemu: implement persistent file cache for nbdkit caps Date: Thu, 20 Jul 2023 17:19:33 -0500 Message-ID: <20230720222003.411549-7-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1689891630162100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Implement the loadFile and saveFile virFileCacheHandlers callbacks so that nbdkit capabilities are cached perstistently across daemon restarts. The format and implementation is modeled on the qemu capabilities, but simplified slightly. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- po/POTFILES | 1 + src/qemu/qemu_nbdkit.c | 226 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 225 insertions(+), 2 deletions(-) diff --git a/po/POTFILES b/po/POTFILES index 5d6ec195b4..6167f98ac5 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -181,6 +181,7 @@ src/qemu/qemu_monitor.c src/qemu/qemu_monitor_json.c src/qemu/qemu_monitor_text.c src/qemu/qemu_namespace.c +src/qemu/qemu_nbdkit.c src/qemu/qemu_passt.c src/qemu/qemu_process.c src/qemu/qemu_qapi.c diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index cd6fe41910..033a31ce32 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -313,11 +313,233 @@ virNbdkitCapsNewData(const char *binary, } =20 =20 +static int +qemuNbdkitCapsValidateBinary(qemuNbdkitCaps *nbdkitCaps, + xmlXPathContextPtr ctxt) +{ + g_autofree char *str =3D NULL; + + if (!(str =3D virXPathString("string(./path)", ctxt))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing path in nbdkit capabilities cache")); + return -1; + } + + if (STRNEQ(str, nbdkitCaps->path)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Expected caps for '%1$s' but saw '%2$s'"), + nbdkitCaps->path, str); + return -1; + } + + return 0; +} + + +static int +qemuNbdkitCapsParseFlags(qemuNbdkitCaps *nbdkitCaps, + xmlXPathContextPtr ctxt) +{ + g_autofree xmlNodePtr *nodes =3D NULL; + size_t i; + int n; + + if ((n =3D virXPathNodeSet("./flag", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to parse qemu capabilities flags")); + return -1; + } + + VIR_DEBUG("Got flags %d", n); + for (i =3D 0; i < n; i++) { + unsigned int flag; + + if (virXMLPropEnum(nodes[i], "name", qemuNbdkitCapsTypeFromString, + VIR_XML_PROP_REQUIRED, &flag) < 0) + return -1; + + qemuNbdkitCapsSet(nbdkitCaps, flag); + } + + return 0; +} + + +/* + * Parsing a doc that looks like + * + * + * /some/path + * 234235253 + * 234235253 + * 234235253 + * 234235253 + * 1002016 + * + * + * ... + * + * + * Returns 0 on success, 1 if outdated, -1 on error + */ +static int +qemuNbdkitCapsLoadCache(qemuNbdkitCaps *nbdkitCaps, + const char *filename) +{ + g_autoptr(xmlDoc) doc =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + long long int l; + + if (!(doc =3D virXMLParse(filename, NULL, NULL, "nbdkitCaps", &ctxt, N= ULL, false))) + return -1; + + if (virXPathLongLong("string(./selfctime)", ctxt, &l) < 0) { + VIR_DEBUG("missing selfctime in nbdkit capabilities XML"); + return -1; + } + nbdkitCaps->libvirtCtime =3D (time_t)l; + + nbdkitCaps->libvirtVersion =3D 0; + virXPathUInt("string(./selfvers)", ctxt, &nbdkitCaps->libvirtVersion); + + if (nbdkitCaps->libvirtCtime !=3D virGetSelfLastChanged() || + nbdkitCaps->libvirtVersion !=3D LIBVIR_VERSION_NUMBER) { + VIR_DEBUG("Outdated capabilities in %s: libvirt changed (%lld vs %= lld, %lu vs %lu), stopping load", + nbdkitCaps->path, + (long long)nbdkitCaps->libvirtCtime, + (long long)virGetSelfLastChanged(), + (unsigned long)nbdkitCaps->libvirtVersion, + (unsigned long)LIBVIR_VERSION_NUMBER); + return 1; + } + + if (qemuNbdkitCapsValidateBinary(nbdkitCaps, ctxt) < 0) + return -1; + + if (virXPathLongLong("string(./nbdkitctime)", ctxt, &l) < 0) { + VIR_DEBUG("missing nbdkitctime in nbdkit capabilities XML"); + return -1; + } + nbdkitCaps->ctime =3D (time_t)l; + + if (virXPathLongLong("string(./plugindirmtime)", ctxt, &l) < 0) { + VIR_DEBUG("missing plugindirmtime in nbdkit capabilities XML"); + return -1; + } + nbdkitCaps->pluginDirMtime =3D (time_t)l; + + if (virXPathLongLong("string(./filterdirmtime)", ctxt, &l) < 0) { + VIR_DEBUG("missing filterdirmtime in nbdkit capabilities XML"); + return -1; + } + nbdkitCaps->filterDirMtime =3D (time_t)l; + + if (qemuNbdkitCapsParseFlags(nbdkitCaps, ctxt) < 0) + return -1; + + if ((nbdkitCaps->version =3D virXPathString("string(./version)", ctxt)= ) =3D=3D NULL) { + VIR_DEBUG("missing version in nbdkit capabilities cache"); + return -1; + } + + return 0; +} + + +static void* +virNbdkitCapsLoadFile(const char *filename, + const char *binary, + void *privData G_GNUC_UNUSED, + bool *outdated) +{ + g_autoptr(qemuNbdkitCaps) nbdkitCaps =3D qemuNbdkitCapsNew(binary); + int ret; + + if (!nbdkitCaps) + return NULL; + + ret =3D qemuNbdkitCapsLoadCache(nbdkitCaps, filename); + if (ret < 0) + return NULL; + if (ret =3D=3D 1) { + *outdated =3D true; + return NULL; + } + + return g_steal_pointer(&nbdkitCaps); +} + + +static char* +qemuNbdkitCapsFormatCache(qemuNbdkitCaps *nbdkitCaps) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + size_t i; + + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + + virBufferEscapeString(&buf, "%s\n", + nbdkitCaps->path); + virBufferAsprintf(&buf, "%lu\n", + nbdkitCaps->ctime); + virBufferAsprintf(&buf, "%lu\n", + nbdkitCaps->pluginDirMtime); + virBufferAsprintf(&buf, "%lu\n", + nbdkitCaps->filterDirMtime); + virBufferAsprintf(&buf, "%lu\n", + nbdkitCaps->libvirtCtime); + virBufferAsprintf(&buf, "%u\n", + nbdkitCaps->libvirtVersion); + + for (i =3D 0; i < QEMU_NBDKIT_CAPS_LAST; i++) { + if (qemuNbdkitCapsGet(nbdkitCaps, i)) { + virBufferAsprintf(&buf, "\n", + qemuNbdkitCapsTypeToString(i)); + } + } + + virBufferAsprintf(&buf, "%s\n", + nbdkitCaps->version); + + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + + return virBufferContentAndReset(&buf); +} + + +static int +virNbdkitCapsSaveFile(void *data, + const char *filename, + void *privData G_GNUC_UNUSED) +{ + qemuNbdkitCaps *nbdkitCaps =3D data; + g_autofree char *xml =3D NULL; + + xml =3D qemuNbdkitCapsFormatCache(nbdkitCaps); + + if (virFileWriteStr(filename, xml, 0600) < 0) { + virReportSystemError(errno, + _("Failed to save '%1$s' for '%2$s'"), + filename, nbdkitCaps->path); + return -1; + } + + VIR_DEBUG("Saved caps '%s' for '%s' with (%lu, %lu)", + filename, nbdkitCaps->path, + nbdkitCaps->ctime, + nbdkitCaps->libvirtCtime); + + return 0; +} + + virFileCacheHandlers nbdkitCapsCacheHandlers =3D { .isValid =3D virNbdkitCapsIsValid, .newData =3D virNbdkitCapsNewData, - .loadFile =3D NULL, - .saveFile =3D NULL, + .loadFile =3D virNbdkitCapsLoadFile, + .saveFile =3D virNbdkitCapsSaveFile, .privFree =3D NULL, }; =20 --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891669; cv=none; d=zohomail.com; s=zohoarc; b=QYldXjhxYcpaG1mQK/zrq26i/H4tS0efR+rYwuduNhbIwW7zi31H5C3DJAFwF7isqZ/Lu7y0MU4v1cSTJQE7A1LxiZPnyxs4IzlZZB54qEVvIydx+2l4tmcEu9C2yusibob4rS+fbggNoZpBajdkoJQksjMabz1k24t5g76Bh2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891669; h=Content-Type:Content-Transfer-Encoding:Cc: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=RyeAIXXbnnKV5Ai3ehfRV/npp0hROf5ezLBDhrgkjqw=; b=OgFml7TkHqvg6nsvk3jxq0DKNfpOPFrvSdqxX4uDtCK/H0SPgUd8u++hmvctriMofssEqRLdpdW9BokjO/XrItC+T2FI6Gy3vreTpu4b4XXbTX0takUtSHlpObmO/SIF9yUTxB8Oi22jgIZu1hBoSxKrvQiv6LflVef+yWwVmi0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891669936479.6576483243995; Thu, 20 Jul 2023 15:21:09 -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-251-JRYWlDMKPPO3RZxzTPVECw-1; Thu, 20 Jul 2023 18:20:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2704858F1E; Thu, 20 Jul 2023 22:20:23 +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 CF61C200B41D; Thu, 20 Jul 2023 22:20:23 +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 04051194037E; Thu, 20 Jul 2023 22:20:17 +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 8EA5E1946A6E for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3B15340C2077; Thu, 20 Jul 2023 22:20:06 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1029940C206F; Thu, 20 Jul 2023 22:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891668; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=RyeAIXXbnnKV5Ai3ehfRV/npp0hROf5ezLBDhrgkjqw=; b=Djq/ib3Zy3G647wqV0i9OvAyNecb4RUjfemc6i0qI3B3zMHkmGjcM7AHLc8PXah45YQEtm +F0UC0KP7uIbeaL2BF5U1+lq/m/bmwk3X+K9LoZLGZAHp7cpSzaZ8x+K0a8cqGX9VW3sLf s/YFpfN8f1WCCrRx+lpLJl4KZQxH68A= X-MC-Unique: JRYWlDMKPPO3RZxzTPVECw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 07/36] qemu: use file cache for nbdkit caps Date: Thu, 20 Jul 2023 17:19:34 -0500 Message-ID: <20230720222003.411549-8-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891671582100007 Content-Type: text/plain; charset="utf-8"; x-default="true" Add the virFileCache implementation for nbdkit capabilities to the qemu driver. This allows us to determine whether nbdkit is installed and which plugins are supported. it also has persistent caching and the capabilities are re-queried whenever something changes. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_conf.h | 3 +++ src/qemu/qemu_driver.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 4f610d86a1..a44985fb8b 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -318,6 +318,9 @@ struct _virQEMUDriver { =20 /* Immutable pointer, self-locking APIs */ virHashAtomic *migrationErrors; + + /* Immutable pointer, self-locking APIs */ + virFileCache *nbdkitCapsCache; }; =20 virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 497923ffee..1db07b3b33 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -846,6 +846,8 @@ qemuStateInitialize(bool privileged, defsecmodel))) goto error; =20 + qemu_driver->nbdkitCapsCache =3D qemuNbdkitCapsCacheNew(cfg->cacheDir); + /* If hugetlbfs is present, then we need to create a sub-directory wit= hin * it, since we can't assume the root mount point has permissions that * will let our spawned QEMU instances use it. */ @@ -1079,6 +1081,7 @@ qemuStateCleanup(void) ebtablesContextFree(qemu_driver->ebtables); VIR_FREE(qemu_driver->qemuImgBinary); virObjectUnref(qemu_driver->domains); + virObjectUnref(qemu_driver->nbdkitCapsCache); =20 if (qemu_driver->lockFD !=3D -1) virPidFileRelease(qemu_driver->config->stateDir, "driver", qemu_dr= iver->lockFD); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891629; cv=none; d=zohomail.com; s=zohoarc; b=mWg0/XcAIVNzn4HdCW6fW9t5kOKl1pPcFaxLt/qDKoVrefMOtzWlBENDnExwV8G78nmQAswbhAWhwWvLKAyrzeILYv2fUrtuStnAWgLK0Mgw2kzaSLXv5aEHMJlIhCtiKLlC+1g2uv1FORuK+zEUMr2Fmtp66djVfXVfjXIvKcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891629; h=Content-Type:Content-Transfer-Encoding:Cc: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=GBIKSQrpwhhv0zOlIJ98AoC9sUkfLqT2jKOIZjIjc2M=; b=j0dD3mCmmdb+JLO+rfvZoyZw93LyNXUCTDXUxGup/UjjCJIkAK45hqTyuNAVH7mKYW6t2ud7q0oRK9QvP5SCZh0CZhJ5R5pFQ3v6jxN3OlqTr5kjnMPq5qINMd4cAjydTy2QzqPBG38uJWFipLhGwXJVxpXVY/Bi3b88gzoYUpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891629147770.2265332905637; Thu, 20 Jul 2023 15:20:29 -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-157-AU6zJiuFNnS1ItN-24vzHA-1; Thu, 20 Jul 2023 18:20:26 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E1571064B09; Thu, 20 Jul 2023 22:20:21 +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 5335A1454143; Thu, 20 Jul 2023 22:20:21 +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 B54EE1949755; Thu, 20 Jul 2023 22:20:16 +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 89C3519465BA for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7897C40C2078; Thu, 20 Jul 2023 22:20:06 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E35440C206F; Thu, 20 Jul 2023 22:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891628; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=GBIKSQrpwhhv0zOlIJ98AoC9sUkfLqT2jKOIZjIjc2M=; b=O0iU1Wvt/KTCv1OH6/RUuDU5OywuYkJURExAlAdYo7y3Klx4Ao8aNt7VKNOR74D24X2Qsi M46LTKJ5fKkxOQonqqp3iFtR/+a9jpMqz01w64mhKfGG/TBA9epgmtuuql1R3AWOlHRSjO J0su7ld0e6ILmKi8cLdJQirBzJsmSz8= X-MC-Unique: AU6zJiuFNnS1ItN-24vzHA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 08/36] qemu: Add qemuNbdkitProcess Date: Thu, 20 Jul 2023 17:19:35 -0500 Message-ID: <20230720222003.411549-9-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1689891630150100002 Content-Type: text/plain; charset="utf-8"; x-default="true" An object for storing information about a nbdkit process that is serving a specific virStorageSource. At the moment, this information is just stored in the private data of virStorageSource and not used at all. Future commits will use this data to actually start a nbdkit process. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_conf.c | 22 ++++++++++++ src/qemu/qemu_conf.h | 2 ++ src/qemu/qemu_domain.c | 31 ++++++++++++++++ src/qemu/qemu_domain.h | 4 +++ src/qemu/qemu_nbdkit.c | 82 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 26 ++++++++++++++ 6 files changed, 167 insertions(+) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index bd984448a3..bf6c42f637 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1659,3 +1659,25 @@ qemuHugepageMakeBasedir(virQEMUDriver *driver, =20 return 0; } + + +/* + * qemuGetNbdkitCaps: + * @driver: the qemu driver + * + * Gets the capabilities for Nbdkit for the specified driver. These can be= used + * to determine whether a particular disk source can be served by nbdkit or + * not. + * + * Returns: a reference to qemuNbdkitCaps or NULL + */ +qemuNbdkitCaps* +qemuGetNbdkitCaps(virQEMUDriver *driver) +{ + char *nbdkitBinary =3D virFindFileInPath("nbdkit"); + + if (!nbdkitBinary) + return NULL; + + return virFileCacheLookup(driver->nbdkitCapsCache, nbdkitBinary); +} diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index a44985fb8b..1a3ba3a0fb 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -377,3 +377,5 @@ int qemuGetMemoryBackingPath(virQEMUDriver *driver, =20 int qemuHugepageMakeBasedir(virQEMUDriver *driver, virHugeTLBFS *hugepage); + +qemuNbdkitCaps* qemuGetNbdkitCaps(virQEMUDriver *driver); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6eea8a9fa5..a12ebc7d3f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -882,6 +882,7 @@ qemuDomainStorageSourcePrivateDispose(void *obj) g_clear_pointer(&priv->httpcookie, qemuDomainSecretInfoFree); g_clear_pointer(&priv->tlsKeySecret, qemuDomainSecretInfoFree); g_clear_pointer(&priv->fdpass, qemuFDPassFree); + g_clear_pointer(&priv->nbdkitProcess, qemuNbdkitProcessFree); } =20 =20 @@ -10420,6 +10421,34 @@ qemuDomainPrepareStorageSourceNFS(virStorageSource= *src) } =20 =20 +/* qemuPrepareStorageSourceNbdkit: + * @src: source for a disk + * + * If src is an network source that is managed by nbdkit, prepare data so = that + * nbdkit can be launched before the domain is started + * + * Returns true if nbdkit will be used for this source, + */ +static bool +qemuDomainPrepareStorageSourceNbdkit(virStorageSource *src, + virQEMUDriverConfig *cfg, + const char *alias, + qemuDomainObjPrivate *priv) +{ + g_autoptr(qemuNbdkitCaps) nbdkit =3D NULL; + + if (virStorageSourceGetActualType(src) !=3D VIR_STORAGE_TYPE_NETWORK) + return false; + + nbdkit =3D qemuGetNbdkitCaps(priv->driver); + if (!nbdkit) + return false; + + return qemuNbdkitInitStorageSource(nbdkit, src, priv->libDir, + alias, cfg->user, cfg->group); +} + + /* qemuProcessPrepareStorageSourceTLS: * @source: source for a disk * @cfg: driver configuration @@ -11249,6 +11278,8 @@ qemuDomainPrepareStorageSourceBlockdevNodename(virD= omainDiskDef *disk, if (qemuDomainPrepareStorageSourceFDs(src, priv) < 0) return -1; =20 + qemuDomainPrepareStorageSourceNbdkit(src, cfg, src->nodestorage, priv); + return 0; } =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 999190e381..572cd67856 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -33,6 +33,7 @@ #include "qemu_conf.h" #include "qemu_capabilities.h" #include "qemu_migration_params.h" +#include "qemu_nbdkit.h" #include "qemu_slirp.h" #include "qemu_fd.h" #include "virchrdev.h" @@ -308,6 +309,9 @@ struct _qemuDomainStorageSourcePrivate { =20 /* file descriptors if user asks for FDs to be passed */ qemuFDPass *fdpass; + + /* an nbdkit process for serving network storage sources */ + qemuNbdkitProcess *nbdkitProcess; }; =20 virObject *qemuDomainStorageSourcePrivateNew(void); diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 033a31ce32..2f9c5f19ef 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -550,3 +550,85 @@ qemuNbdkitCapsCacheNew(const char *cachedir) g_autofree char *dir =3D g_build_filename(cachedir, "nbdkitcapabilitie= s", NULL); return virFileCacheNew(dir, "xml", &nbdkitCapsCacheHandlers); } + + +static qemuNbdkitProcess * +qemuNbdkitProcessNew(virStorageSource *source, + const char *pidfile, + const char *socketfile) +{ + qemuNbdkitProcess *nbdkit =3D g_new0(qemuNbdkitProcess, 1); + /* weak reference -- source owns this object, so it will always outliv= e us */ + nbdkit->source =3D source; + nbdkit->user =3D -1; + nbdkit->group =3D -1; + nbdkit->pid =3D -1; + nbdkit->pidfile =3D g_strdup(pidfile); + nbdkit->socketfile =3D g_strdup(socketfile); + + return nbdkit; +} + + +bool +qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, + virStorageSource *source, + char *statedir, + const char *alias, + uid_t user, + gid_t group) +{ + qemuDomainStorageSourcePrivate *srcPriv =3D qemuDomainStorageSourcePri= vateFetch(source); + g_autofree char *pidname =3D g_strdup_printf("nbdkit-%s.pid", alias); + g_autofree char *socketname =3D g_strdup_printf("nbdkit-%s.socket", al= ias); + g_autofree char *pidfile =3D g_build_filename(statedir, pidname, NULL); + g_autofree char *socketfile =3D g_build_filename(statedir, socketname,= NULL); + qemuNbdkitProcess *proc; + + if (srcPriv->nbdkitProcess) + return false; + + switch (source->protocol) { + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + if (!virBitmapIsBitSet(caps->flags, QEMU_NBDKIT_CAPS_PLUGIN_CU= RL)) + return false; + break; + case VIR_STORAGE_NET_PROTOCOL_SSH: + if (!virBitmapIsBitSet(caps->flags, QEMU_NBDKIT_CAPS_PLUGIN_SS= H)) + return false; + break; + case VIR_STORAGE_NET_PROTOCOL_NONE: + case VIR_STORAGE_NET_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_VXHS: + case VIR_STORAGE_NET_PROTOCOL_NFS: + case VIR_STORAGE_NET_PROTOCOL_LAST: + return false; + } + + proc =3D qemuNbdkitProcessNew(source, pidfile, socketfile); + proc->caps =3D g_object_ref(caps); + proc->user =3D user; + proc->group =3D group; + + srcPriv->nbdkitProcess =3D proc; + + return true; +} + + +void +qemuNbdkitProcessFree(qemuNbdkitProcess *proc) +{ + g_clear_pointer(&proc->pidfile, g_free); + g_clear_pointer(&proc->socketfile, g_free); + g_clear_object(&proc->caps); + g_free(proc); +} diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 4aba7c8455..8844bba13c 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -20,10 +20,12 @@ #pragma once =20 #include "internal.h" +#include "storage_source_conf.h" #include "virenum.h" #include "virfilecache.h" =20 typedef struct _qemuNbdkitCaps qemuNbdkitCaps; +typedef struct _qemuNbdkitProcess qemuNbdkitProcess; =20 typedef enum { /* 0 */ @@ -42,6 +44,14 @@ qemuNbdkitCapsNew(const char *path); virFileCache * qemuNbdkitCapsCacheNew(const char *cachedir); =20 +bool +qemuNbdkitInitStorageSource(qemuNbdkitCaps *nbdkitCaps, + virStorageSource *source, + char *statedir, + const char *alias, + uid_t user, + gid_t group); + bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags flag); @@ -52,3 +62,19 @@ qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, =20 #define QEMU_TYPE_NBDKIT_CAPS qemu_nbdkit_caps_get_type() G_DECLARE_FINAL_TYPE(qemuNbdkitCaps, qemu_nbdkit_caps, QEMU, NBDKIT_CAPS, = GObject); + +struct _qemuNbdkitProcess { + qemuNbdkitCaps *caps; + virStorageSource *source; + + char *pidfile; + char *socketfile; + uid_t user; + gid_t group; + pid_t pid; +}; + +void +qemuNbdkitProcessFree(qemuNbdkitProcess *proc); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuNbdkitProcess, qemuNbdkitProcessFree); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891735; cv=none; d=zohomail.com; s=zohoarc; b=CsMUBkmSh33ZY6F0UNNxrWLVKO7Jm/3bbe21al9g6mfhkgXwOmo2FEXX7oSmO5xdqQ9Ada6RniOOZTOGIMsOHHotBJbYzA/quJIiouooaHPdmFtFVwvyYDkPuIWiJasqx2/QOkPwYD5zx5Ykm0flTkYoTBZ/APc3vAWFC96vPE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891735; h=Content-Type:Content-Transfer-Encoding:Cc: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=Fc7fhjFi55Hm3CM7ALTAQTuDwKgkKxlS9Rrz0+57Mkk=; b=hdpK+RJZOLXTXX+wfCvUZn04eMO9KEdZoAU83MGK0onYvARiaYJABPRVoSMK1AFUZqb6ermp29Y6QsJWfKrHuUoEt5VsNwEVyaReGKAqWfRlgPWpoB/9OOWq2n8pJstoZRAqGsC9USyJH89Nh1pE0UU3Tpndpy6CSL1aEfAUm8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 16898917350711012.5438245306161; Thu, 20 Jul 2023 15:22:15 -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-400-jP6mdfLfOBmkTM0wYF9ANA-1; Thu, 20 Jul 2023 18:20:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9825B185A7AC; Thu, 20 Jul 2023 22:20:19 +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 845CD4094DC1; Thu, 20 Jul 2023 22:20:19 +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 35B8119451EC; Thu, 20 Jul 2023 22:20:16 +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 8EA2C19465BD for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B64DF40C2079; Thu, 20 Jul 2023 22:20:06 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8BF0040C206F; Thu, 20 Jul 2023 22:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891733; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=Fc7fhjFi55Hm3CM7ALTAQTuDwKgkKxlS9Rrz0+57Mkk=; b=C6YB9wSa9YYXXPg2HWJpO0BNrmdBsUkBS7f5qRMSeJM6Fa5CCYRVrCrpMMU9MgQJXh60DE gevjZIHwsgdLIV/fn/vP9WJ1t0uZKhrGOSRtuY6awAKlFz5rgo6NNVyau0CV8XzO8PEH7U FDBBTbVgzwHpczKzbT+FWDRV0DAaovU= X-MC-Unique: jP6mdfLfOBmkTM0wYF9ANA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 09/36] qemu: query nbdkit module dir from binary Date: Thu, 20 Jul 2023 17:19:36 -0500 Message-ID: <20230720222003.411549-10-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 1689891736934100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Rather than hard-coding the nbdkit module directory, query the nbdkit binary for the location to these directories. nbdkit provides a --dump-config optiont that outputs this information and can be easily parsed. We can also get the version from this output rather than executing `nbdkit --version` separately. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 77 ++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 2f9c5f19ef..9e53c1893e 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -20,7 +20,6 @@ #include #include =20 -#include "configmake.h" #include "vircommand.h" #include "virerror.h" #include "virlog.h" @@ -40,10 +39,6 @@ =20 VIR_LOG_INIT("qemu.nbdkit"); =20 -#define NBDKIT_MODDIR LIBDIR "/nbdkit" -#define NBDKIT_PLUGINDIR NBDKIT_MODDIR "/plugins" -#define NBDKIT_FILTERDIR NBDKIT_MODDIR "/filters" - VIR_ENUM_IMPL(qemuNbdkitCaps, QEMU_NBDKIT_CAPS_LAST, /* 0 */ @@ -57,6 +52,9 @@ struct _qemuNbdkitCaps { =20 char *path; char *version; + char *filterDir; + char *pluginDir; + time_t ctime; time_t libvirtCtime; time_t pluginDirMtime; @@ -130,18 +128,47 @@ qemuNbdkitCapsQueryFilters(qemuNbdkitCaps *nbdkit) =20 =20 static int -qemuNbdkitCapsQueryVersion(qemuNbdkitCaps *nbdkit) +qemuNbdkitCapsQueryBuildConfig(qemuNbdkitCaps *nbdkit) { + size_t i; + g_autofree char *output =3D NULL; + g_auto(GStrv) lines =3D NULL; + const char *line; g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, - "--version", + "--dump-config", NULL); =20 - virCommandSetOutputBuffer(cmd, &nbdkit->version); + virCommandSetOutputBuffer(cmd, &output); =20 if (virCommandRun(cmd, NULL) !=3D 0) return -1; =20 - VIR_DEBUG("Got nbdkit version %s", nbdkit->version); + lines =3D g_strsplit(output, "\n", 0); + if (!lines) + return -1; + + for (i =3D 0; (line =3D lines[i]); i++) { + const char *key; + const char *val; + char *p; + + p =3D strchr(line, '=3D'); + if (!p) + continue; + + *p =3D '\0'; + key =3D line; + val =3D p + 1; + + VIR_DEBUG("Got nbdkit config value %s=3D%s", key, val); + + if (STREQ(key, "version")) + nbdkit->version =3D g_strdup(val); + else if (STREQ(key, "filterdir")) + nbdkit->filterDir =3D g_strdup(val); + else if (STREQ(key, "plugindir")) + nbdkit->pluginDir =3D g_strdup(val); + } return 0; } =20 @@ -153,6 +180,8 @@ qemuNbdkitCapsFinalize(GObject *object) =20 g_clear_pointer(&nbdkit->path, g_free); g_clear_pointer(&nbdkit->version, g_free); + g_clear_pointer(&nbdkit->filterDir, g_free); + g_clear_pointer(&nbdkit->pluginDir, g_free); g_clear_pointer(&nbdkit->flags, virBitmapFree); =20 G_OBJECT_CLASS(qemu_nbdkit_caps_parent_class)->finalize(object); @@ -215,15 +244,15 @@ qemuNbdkitCapsQuery(qemuNbdkitCaps *caps) return; } =20 + qemuNbdkitCapsQueryBuildConfig(caps); + qemuNbdkitCapsQueryPlugins(caps); + qemuNbdkitCapsQueryFilters(caps); + caps->ctime =3D st.st_ctime; - caps->filterDirMtime =3D qemuNbdkitGetDirMtime(NBDKIT_FILTERDIR); - caps->pluginDirMtime =3D qemuNbdkitGetDirMtime(NBDKIT_PLUGINDIR); + caps->filterDirMtime =3D qemuNbdkitGetDirMtime(caps->filterDir); + caps->pluginDirMtime =3D qemuNbdkitGetDirMtime(caps->pluginDir); caps->libvirtCtime =3D virGetSelfLastChanged(); caps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; - - qemuNbdkitCapsQueryPlugins(caps); - qemuNbdkitCapsQueryFilters(caps); - qemuNbdkitCapsQueryVersion(caps); } =20 =20 @@ -268,9 +297,9 @@ virNbdkitCapsIsValid(void *data, if (!nbdkitCaps->path) return true; =20 - if (!virNbkditCapsCheckModdir(NBDKIT_PLUGINDIR, nbdkitCaps->pluginDirM= time)) + if (!virNbkditCapsCheckModdir(nbdkitCaps->pluginDir, nbdkitCaps->plugi= nDirMtime)) return false; - if (!virNbkditCapsCheckModdir(NBDKIT_FILTERDIR, nbdkitCaps->filterDirM= time)) + if (!virNbkditCapsCheckModdir(nbdkitCaps->filterDir, nbdkitCaps->filte= rDirMtime)) return false; =20 if (nbdkitCaps->libvirtCtime !=3D virGetSelfLastChanged() || @@ -422,12 +451,22 @@ qemuNbdkitCapsLoadCache(qemuNbdkitCaps *nbdkitCaps, } nbdkitCaps->ctime =3D (time_t)l; =20 + if ((nbdkitCaps->pluginDir =3D virXPathString("string(./plugindir)", c= txt)) =3D=3D NULL) { + VIR_DEBUG("missing plugindir in nbdkit capabilities cache"); + return -1; + } + if (virXPathLongLong("string(./plugindirmtime)", ctxt, &l) < 0) { VIR_DEBUG("missing plugindirmtime in nbdkit capabilities XML"); return -1; } nbdkitCaps->pluginDirMtime =3D (time_t)l; =20 + if ((nbdkitCaps->filterDir =3D virXPathString("string(./filterdir)", c= txt)) =3D=3D NULL) { + VIR_DEBUG("missing filterdir in nbdkit capabilities cache"); + return -1; + } + if (virXPathLongLong("string(./filterdirmtime)", ctxt, &l) < 0) { VIR_DEBUG("missing filterdirmtime in nbdkit capabilities XML"); return -1; @@ -483,8 +522,12 @@ qemuNbdkitCapsFormatCache(qemuNbdkitCaps *nbdkitCaps) nbdkitCaps->path); virBufferAsprintf(&buf, "%lu\n", nbdkitCaps->ctime); + virBufferEscapeString(&buf, "%s\n", + nbdkitCaps->pluginDir); virBufferAsprintf(&buf, "%lu\n", nbdkitCaps->pluginDirMtime); + virBufferEscapeString(&buf, "%s\n", + nbdkitCaps->filterDir); virBufferAsprintf(&buf, "%lu\n", nbdkitCaps->filterDirMtime); virBufferAsprintf(&buf, "%lu\n", --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891669; cv=none; d=zohomail.com; s=zohoarc; b=RBkshgpixGaSOOaM+8khD3xdLl2DCkq/FQ7fS5KxCQ42HqdWpPI4YAzxluR4g08TCbCy1RUbj0rMx2WvD9HP5GmZRdl1OvXY0z8uHuGaZUicisN0UJFoLlx1BuWIDj85iw5Hsax8Oz4o1i6B5g15Kp0/7MPbv08bJU2uzTypphs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891669; h=Content-Type:Content-Transfer-Encoding:Cc: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=SiQ6vLDJ7kYjU/x4Jaw2MKOVetYXct9eUQupusPng28=; b=ktb6SoJr/xBveInVchJvtq9kpzEvXGRezq29TiiA0CrMQziaxTQjS5sKyijmuOAuazbVYzthzPjwGjWzcO98KP4HNJ1ekTxpuTnLDh0x1IHrexwkfb1E0jHXOi7LJsDZdvjiYdD0DNfhm302KGKoh4pcsCNdwe8oNpqo0s3RfiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891669615103.94403467118264; Thu, 20 Jul 2023 15:21:09 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-669-cMg2j8tsOb-FNHaRkLY8qg-1; Thu, 20 Jul 2023 18:20:23 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BDBB7380392A; Thu, 20 Jul 2023 22:20:18 +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 A9BB5492B02; Thu, 20 Jul 2023 22:20:18 +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 E687D19451D4; Thu, 20 Jul 2023 22:20:15 +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 8C75F1946A6C for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 00CA740C207A; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9DBC40C206F; Thu, 20 Jul 2023 22:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891668; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=SiQ6vLDJ7kYjU/x4Jaw2MKOVetYXct9eUQupusPng28=; b=h+i1Z/44jJrvlp80lw+9gbyzBXnRdVhVxsxi0UtL0Xf0iTXBl5g98uKU9uxtovOzrm9vX9 EIiYwKAhapL69WRjhj2yWQ9xhkdfxHzoMQroRoJCjC4k+xC44KAuGHIvxDzuuPBikhZUdl OaD7pIl72xwPLRgUwdjNK4kdrzMXP7I= X-MC-Unique: cMg2j8tsOb-FNHaRkLY8qg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 10/36] qemu: add functions to start and stop nbdkit Date: Thu, 20 Jul 2023 17:19:37 -0500 Message-ID: <20230720222003.411549-11-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: 1689891671592100008 Content-Type: text/plain; charset="utf-8"; x-default="true" Add some helper functions to build a virCommand object and run the nbdkit process for a given virStorageSource. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 250 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 10 ++ 2 files changed, 260 insertions(+) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 9e53c1893e..1acc6bf58f 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -24,6 +24,8 @@ #include "virerror.h" #include "virlog.h" #include "virpidfile.h" +#include "virsecureerase.h" +#include "virtime.h" #include "virutil.h" #include "qemu_block.h" #include "qemu_conf.h" @@ -667,6 +669,168 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, } =20 =20 +static int +qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *proc, + virCommand *cmd) +{ + g_autoptr(virURI) uri =3D qemuBlockStorageSourceGetURI(proc->source); + g_autofree char *uristring =3D virURIFormat(uri); + + /* nbdkit plugin name */ + virCommandAddArg(cmd, "curl"); + if (proc->source->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTP) { + /* allow http to be upgraded to https via e.g. redirect */ + virCommandAddArgPair(cmd, "protocols", "http,https"); + } else { + virCommandAddArgPair(cmd, "protocols", + virStorageNetProtocolTypeToString(proc->sourc= e->protocol)); + } + virCommandAddArgPair(cmd, "url", uristring); + + if (proc->source->auth) { + g_autoptr(virConnect) conn =3D virGetConnectSecret(); + g_autofree uint8_t *secret =3D NULL; + size_t secretlen =3D 0; + g_autofree char *password =3D NULL; + int secrettype; + virStorageAuthDef *authdef =3D proc->source->auth; + + virCommandAddArgPair(cmd, "user", + proc->source->auth->username); + + if ((secrettype =3D virSecretUsageTypeFromString(proc->source->aut= h->secrettype)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid secret type %1$s"), + proc->source->auth->secrettype); + return -1; + } + + if (virSecretGetSecretString(conn, + &authdef->seclookupdef, + secrettype, + &secret, + &secretlen) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to get auth secret for storage")); + return -1; + } + + /* ensure that the secret is a NULL-terminated string */ + password =3D g_strndup((char*)secret, secretlen); + virSecureErase(secret, secretlen); + + /* for now, just report an error rather than passing the password = in + * cleartext on the commandline */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Password not yet supported for nbdkit sources")); + + virSecureEraseString(password); + + return -1; + } + + if (proc->source->ncookies > 0) { + /* for now, just report an error rather than passing cookies in + * cleartext on the commandline */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cookies not yet supported for nbdkit sources")); + return -1; + } + + if (proc->source->sslverify =3D=3D VIR_TRISTATE_BOOL_NO) { + virCommandAddArgPair(cmd, "sslverify", "false"); + } + + if (proc->source->timeout > 0) { + g_autofree char *timeout =3D g_strdup_printf("%llu", proc->source-= >timeout); + virCommandAddArgPair(cmd, "timeout", timeout); + } + + return 0; +} + + +static int +qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess *proc, + virCommand *cmd) +{ + const char *user =3D NULL; + virStorageNetHostDef *host =3D &proc->source->hosts[0]; + g_autofree char *portstr =3D g_strdup_printf("%u", host->port); + + /* nbdkit plugin name */ + virCommandAddArg(cmd, "ssh"); + + virCommandAddArgPair(cmd, "host", host->name); + virCommandAddArgPair(cmd, "port", portstr); + virCommandAddArgPair(cmd, "path", proc->source->path); + + if (proc->source->auth) + user =3D proc->source->auth->username; + else if (proc->source->ssh_user) + user =3D proc->source->ssh_user; + + if (user) + virCommandAddArgPair(cmd, "user", user); + + if (proc->source->ssh_host_key_check_disabled) + virCommandAddArgPair(cmd, "verify-remote-host", "false"); + + return 0; +} + + +static virCommand * +qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc) +{ + g_autoptr(virCommand) cmd =3D virCommandNewArgList(proc->caps->path, + "--unix", + proc->socketfile, + "--foreground", + NULL); + + if (proc->source->readonly) + virCommandAddArg(cmd, "--readonly"); + + if (qemuNbdkitCapsGet(proc->caps, QEMU_NBDKIT_CAPS_FILTER_READAHEAD) && + proc->source->readahead > 0) + virCommandAddArgPair(cmd, "--filter", "readahead"); + + switch (proc->source->protocol) { + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + if (qemuNbdkitProcessBuildCommandCurl(proc, cmd) < 0) + return NULL; + break; + case VIR_STORAGE_NET_PROTOCOL_SSH: + if (qemuNbdkitProcessBuildCommandSSH(proc, cmd) < 0) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_NONE: + case VIR_STORAGE_NET_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_RBD: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_VXHS: + case VIR_STORAGE_NET_PROTOCOL_NFS: + case VIR_STORAGE_NET_PROTOCOL_LAST: + virReportError(VIR_ERR_NO_SUPPORT, + _("protocol '%1$s' is not supported by nbdkit"), + virStorageNetProtocolTypeToString(proc->source-= >protocol)); + return NULL; + } + + virCommandDaemonize(cmd); + + return g_steal_pointer(&cmd); +} + + void qemuNbdkitProcessFree(qemuNbdkitProcess *proc) { @@ -675,3 +839,89 @@ qemuNbdkitProcessFree(qemuNbdkitProcess *proc) g_clear_object(&proc->caps); g_free(proc); } + + +int +qemuNbdkitProcessStart(qemuNbdkitProcess *proc, + virDomainObj *vm, + virQEMUDriver *driver) +{ + g_autoptr(virCommand) cmd =3D NULL; + int rc; + int exitstatus =3D 0; + g_autofree char *errbuf =3D NULL; + virTimeBackOffVar timebackoff; + g_autoptr(virURI) uri =3D NULL; + g_autofree char *uristring =3D NULL; + + if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc))) + return -1; + + VIR_DEBUG("starting nbdkit process for %s", proc->source->nodestorage); + virCommandSetErrorBuffer(cmd, &errbuf); + virCommandSetPidFile(cmd, proc->pidfile); + + if (qemuExtDeviceLogCommand(driver, vm, cmd, "nbdkit") < 0) + goto error; + + if (qemuSecurityCommandRun(driver, vm, cmd, proc->user, proc->group, t= rue, &exitstatus) < 0) + goto error; + + if (exitstatus !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not start 'nbdkit'. exitstatus: %1$d"), ex= itstatus); + goto error; + } + + if ((rc =3D virPidFileReadPath(proc->pidfile, &proc->pid)) < 0) { + virReportSystemError(-rc, + _("Failed to read pidfile %1$s"), + proc->pidfile); + goto error; + } + + if (virTimeBackOffStart(&timebackoff, 1, 1000) < 0) + goto error; + + while (virTimeBackOffWait(&timebackoff)) { + if (virFileExists(proc->socketfile)) + return 0; + + if (virProcessKill(proc->pid, 0) =3D=3D 0) + continue; + + VIR_WARN("nbdkit died unexpectedly"); + goto errorlog; + } + + VIR_WARN("nbdkit socket did not show up"); + + errorlog: + if ((uri =3D qemuBlockStorageSourceGetURI(proc->source))) + uristring =3D virURIFormat(uri); + + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to connect to nbdkit for '%1$s': %2$s"), + NULLSTR(uristring), NULLSTR(errbuf)); + + error: + qemuNbdkitProcessStop(proc); + return -1; +} + + +int +qemuNbdkitProcessStop(qemuNbdkitProcess *proc) +{ + if (proc->pid < 0) + return 0; + + VIR_DEBUG("Stopping nbdkit process %i", proc->pid); + virProcessKill(proc->pid, SIGTERM); + + unlink(proc->pidfile); + unlink(proc->socketfile); + proc->pid =3D -1; + + return 0; +} diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 8844bba13c..ccd418b7d3 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -38,6 +38,8 @@ typedef enum { =20 VIR_ENUM_DECL(qemuNbdkitCaps); =20 +typedef struct _virQEMUDriver virQEMUDriver; + qemuNbdkitCaps * qemuNbdkitCapsNew(const char *path); =20 @@ -74,6 +76,14 @@ struct _qemuNbdkitProcess { pid_t pid; }; =20 +int +qemuNbdkitProcessStart(qemuNbdkitProcess *proc, + virDomainObj *vm, + virQEMUDriver *driver); + +int +qemuNbdkitProcessStop(qemuNbdkitProcess *proc); + void qemuNbdkitProcessFree(qemuNbdkitProcess *proc); =20 --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891671; cv=none; d=zohomail.com; s=zohoarc; b=L9gJfYZmH2//XmBiwS67mGzJIVwTO5gUOJFmcn/Qd+ctdI+o2xKt/RvMtvRyC/Rr7QtMfPyUfdfx73umNPXcgwKVVCdqjU+HtE0eWFsaxUCff40nH6ec/SifUGHwauomY0rpEZWvcit8O1hyEYpg4jgFhziud1Rk5iAz+7GFoo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891671; h=Content-Type:Content-Transfer-Encoding:Cc: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=IuYFRhLm/kW9qcCdKSnLc8pJ7c1BTLlLJIFgiV1brLs=; b=KO5Vv0RX4jiqnl2pF8ic7cPs2h71YCl0N34W9osCpxIsCfBlPZDlJdcvqlHWTQrKWtIy937D0PTTKApQbzUrdGGQDICJErVadfYkN/5LnKhBpEhJEMSYAeKXaBGkx1qnSwd3qQisGponCwRgW9BEdgtcWvNYtWU1UsNRZ2zg9yg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 16898916716641022.0924121466719; Thu, 20 Jul 2023 15:21:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-60-fCs-E5swMtWz2n6D65kZPg-1; Thu, 20 Jul 2023 18:20:47 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 562853815F99; Thu, 20 Jul 2023 22:20:36 +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 32DCE1454148; Thu, 20 Jul 2023 22:20:36 +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 79EEA194037F; Thu, 20 Jul 2023 22:20:24 +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 9146B1946A72 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3F43F40C207B; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 144FC40C206F; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891670; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=IuYFRhLm/kW9qcCdKSnLc8pJ7c1BTLlLJIFgiV1brLs=; b=GiiIVn2GDPgcuTvkY0qEKnnRRjXsKQuHaQHjvwrhbQuRDlxmG7EUI2S8nNf4KweF9A752p 9sIsKPR4qXf6wro8MOe6VFSiN/9uYfKRoB5JJblhCEVxa48mzRiG6Bq7F/TedzqyoBfXKH HACyOxw53Ef4Ll+gwR5THf0EkPuMcFY= X-MC-Unique: fCs-E5swMtWz2n6D65kZPg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 11/36] qemu: remove unused 'mode' param from qemuDomainLogContextNew() Date: Thu, 20 Jul 2023 17:19:38 -0500 Message-ID: <20230720222003.411549-12-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1689891672304100011 Content-Type: text/plain; charset="utf-8"; x-default="true" The only use of this function always passes QEMU_DOMAIN_LOG_CONTEXT_MODE_START. The other enum values are never used anywhere in the code. Remove them. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 26 +++++++++++--------------- src/qemu/qemu_domain.h | 9 +-------- src/qemu/qemu_process.c | 3 +-- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a12ebc7d3f..bdf6c472f2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7067,8 +7067,7 @@ void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, =20 =20 qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver, - virDomainObj *vm, - qemuDomainLogContextMode m= ode) + virDomainObj *vm) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); qemuDomainLogContext *ctxt =3D QEMU_DOMAIN_LOG_CONTEXT(g_object_new(QE= MU_TYPE_DOMAIN_LOG_CONTEXT, NULL)); @@ -7109,25 +7108,22 @@ qemuDomainLogContext *qemuDomainLogContextNew(virQE= MUDriver *driver, /* For unprivileged startup we must truncate the file since * we can't rely on logrotate. We don't use O_TRUNC since * it is better for SELinux policy if we truncate afterwards */ - if (mode =3D=3D QEMU_DOMAIN_LOG_CONTEXT_MODE_START && - !driver->privileged && + if (!driver->privileged && ftruncate(ctxt->writefd, 0) < 0) { virReportSystemError(errno, _("failed to truncate %1$s"), ctxt->path); goto error; } =20 - if (mode =3D=3D QEMU_DOMAIN_LOG_CONTEXT_MODE_START) { - if ((ctxt->readfd =3D open(ctxt->path, O_RDONLY)) < 0) { - virReportSystemError(errno, _("failed to open logfile %1$s= "), - ctxt->path); - goto error; - } - if (virSetCloseExec(ctxt->readfd) < 0) { - virReportSystemError(errno, _("failed to set close-on-exec= flag on %1$s"), - ctxt->path); - goto error; - } + if ((ctxt->readfd =3D open(ctxt->path, O_RDONLY)) < 0) { + virReportSystemError(errno, _("failed to open logfile %1$s"), + ctxt->path); + goto error; + } + if (virSetCloseExec(ctxt->readfd) < 0) { + virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), + ctxt->path); + goto error; } =20 if ((ctxt->pos =3D lseek(ctxt->writefd, 0, SEEK_END)) < 0) { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 572cd67856..b9e250402e 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -656,15 +656,8 @@ void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, virDomainNetDef *net, qemuDomainLogContext *logCtxt); =20 -typedef enum { - QEMU_DOMAIN_LOG_CONTEXT_MODE_START, - QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH, - QEMU_DOMAIN_LOG_CONTEXT_MODE_STOP, -} qemuDomainLogContextMode; - qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver, - virDomainObj *vm, - qemuDomainLogContextMode m= ode); + virDomainObj *vm); int qemuDomainLogContextWrite(qemuDomainLogContext *ctxt, const char *fmt, ...) G_GNUC_PRINTF(2, 3); ssize_t qemuDomainLogContextRead(qemuDomainLogContext *ctxt, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index db06991450..44677b08ff 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7613,8 +7613,7 @@ qemuProcessLaunch(virConnectPtr conn, hookData.cfg =3D cfg; =20 VIR_DEBUG("Creating domain log file"); - if (!(logCtxt =3D qemuDomainLogContextNew(driver, vm, - QEMU_DOMAIN_LOG_CONTEXT_MODE_S= TART))) { + if (!(logCtxt =3D qemuDomainLogContextNew(driver, vm))) { virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); goto cleanup; } --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891630; cv=none; d=zohomail.com; s=zohoarc; b=KfyZhQJzFWrJlSt9+aZzJre87K2bxhgz6pTg0LY7pssfXHgln1tlAnZUY/yjED2tnQ0pPS8Hfcdhl9MspTBZiNy8c2oKF1tUzUXswj0dEaP3bE0umYdkW2D9Ff0mf+sagP3QXQ4LyEUkEbTtC1XBFTJ0sr1Qm+BDvndfNIDD3y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891630; h=Content-Type:Content-Transfer-Encoding:Cc: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=hKcsVaRKs9jZBgHT0YlE2wOaD5HEEKWlTN86XNkkFlc=; b=WxHwCrGN+sjVmaDklz90cgFUaIK22HFUJ37r6/WMHewowSKSQ34cCsNKstVoRVyBCZvZKXDPs7SnXfBOP/B1X2h8gkEg7w/9GcjFPSoLc/n5HnHjTPyxVrYBdPE+ZICi7Nfu7p+P3mxWZkkHbW0CVdv4zzHGNvONE9R2EQpiHUk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891630844937.0613527121772; Thu, 20 Jul 2023 15:20:30 -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-671-PHCAAPavOFefcqCPZdgWcg-1; Thu, 20 Jul 2023 18:20:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C69E10504AE; Thu, 20 Jul 2023 22:20:18 +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 DCE77207B33B; Thu, 20 Jul 2023 22:20:16 +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 4CD4E19452C5; Thu, 20 Jul 2023 22:20:15 +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 89DC11946A6A for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7CB2740C207C; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5250F40C206F; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891629; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=hKcsVaRKs9jZBgHT0YlE2wOaD5HEEKWlTN86XNkkFlc=; b=HgWhyQNQWx+IdiqEjEPQk6XtOhNKOImF69y4zeCY0sZli1nySU6hWWZzoXmqQylmEm2Tqs jkVkVliSiefhERbTTiaiciPkIie5uznUEnn5/cs0Bx0iraVpvL6yYNMLwvPms628oPZIAW QLqJO4ZXStXsHE0ftGDI4tOnr57uNs4= X-MC-Unique: PHCAAPavOFefcqCPZdgWcg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 12/36] Generalize qemuDomainLogContextNew() Date: Thu, 20 Jul 2023 17:19:39 -0500 Message-ID: <20230720222003.411549-13-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891632384100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Allow to specify a basename for the log file so that qemuDomainLogContextNew() can be used to create log contexts for secondary loggers. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 5 +++-- src/qemu/qemu_domain.h | 3 ++- src/qemu/qemu_process.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index bdf6c472f2..032e366f39 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7067,7 +7067,8 @@ void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, =20 =20 qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver, - virDomainObj *vm) + virDomainObj *vm, + const char *basename) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); qemuDomainLogContext *ctxt =3D QEMU_DOMAIN_LOG_CONTEXT(g_object_new(QE= MU_TYPE_DOMAIN_LOG_CONTEXT, NULL)); @@ -7076,7 +7077,7 @@ qemuDomainLogContext *qemuDomainLogContextNew(virQEMU= Driver *driver, ctxt->writefd =3D -1; ctxt->readfd =3D -1; =20 - ctxt->path =3D g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name= ); + ctxt->path =3D g_strdup_printf("%s/%s.log", cfg->logDir, basename); =20 if (cfg->stdioLogD) { ctxt->manager =3D virLogManagerNew(driver->privileged); diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index b9e250402e..db3aa51667 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -657,7 +657,8 @@ void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, qemuDomainLogContext *logCtxt); =20 qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver, - virDomainObj *vm); + virDomainObj *vm, + const char *basename); int qemuDomainLogContextWrite(qemuDomainLogContext *ctxt, const char *fmt, ...) G_GNUC_PRINTF(2, 3); ssize_t qemuDomainLogContextRead(qemuDomainLogContext *ctxt, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 44677b08ff..33fd230426 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7613,7 +7613,7 @@ qemuProcessLaunch(virConnectPtr conn, hookData.cfg =3D cfg; =20 VIR_DEBUG("Creating domain log file"); - if (!(logCtxt =3D qemuDomainLogContextNew(driver, vm))) { + if (!(logCtxt =3D qemuDomainLogContextNew(driver, vm, vm->def->name)))= { virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); goto cleanup; } --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891727; cv=none; d=zohomail.com; s=zohoarc; b=OyDLY2WV7X6pnN+8JnUejXlwHUJxhNzM8xQFEBoqDSLY+Sn59/qevKdrg4+08Vn8JY+re0DAqGmcDT9gP0hAAeNeFIbkEU5IMJoZX0JoXBKdedFOvlUhae8zgNjpIPL8wMRGWz0m8YvmefF+6EYG4ADb0WQDjuA302B9DvF/a5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891727; h=Content-Type:Content-Transfer-Encoding:Cc: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=pLqz0Wf0UmGmmkpboLyglIL+yXI4YoyQcUN2/mqOX1k=; b=Pyv9zer9jY60g5JKvVRV1uXDqDtFNwQN+CKZx92/thcqk6bmK7mzHHrtfBkJ86IONlyiSF5MtJIFL1noqKgyQlavVFOiJ2GLGMY/4BL5S/o9+NIv6ArCg8s/xJlz3TvYynM2jChvrqGL9cvY7+rNnemH6Jf6BwnTGO/VF1vjkyU= 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 1689891727189285.1911790778089; Thu, 20 Jul 2023 15:22:07 -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-90-kn76VSeiPNiZc_n1h0bYpg-1; Thu, 20 Jul 2023 18:20:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7284B89E74E; Thu, 20 Jul 2023 22:20:38 +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 4F532207B33D; Thu, 20 Jul 2023 22:20:38 +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 7E6C2193F51A; Thu, 20 Jul 2023 22:20:25 +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 8C6371946A6B for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DC59F40C207E; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9089D40C206F; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891725; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=pLqz0Wf0UmGmmkpboLyglIL+yXI4YoyQcUN2/mqOX1k=; b=GJDYuY5lZEiqu765IGBSrf8Mm68p/Xc3iTdXQizjQge3d9d2ADDx5ZB83Onj3QlnXep0QF OoF3HQ/L5X3BHyXObBcWvRirMjf3Uydcoj7s1AGMpY8YP1Tr9rd/cFk+vpReaMn+WNt+8R Ieoqc70t+XwEJKE2QqEKsyE+JXgFmaI= X-MC-Unique: kn76VSeiPNiZc_n1h0bYpg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 13/36] qemu: Extract qemuDomainLogContext into a new file Date: Thu, 20 Jul 2023 17:19:40 -0500 Message-ID: <20230720222003.411549-14-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891728962100011 Content-Type: text/plain; charset="utf-8"; x-default="true" This will allow us to use it for nbdkit logging in upcoming commits. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- po/POTFILES | 1 + src/qemu/meson.build | 1 + src/qemu/qemu_domain.c | 247 ++-------------------------------- src/qemu/qemu_domain.h | 27 +--- src/qemu/qemu_logcontext.c | 264 +++++++++++++++++++++++++++++++++++++ src/qemu/qemu_logcontext.h | 38 ++++++ src/qemu/qemu_process.c | 44 +++---- 7 files changed, 346 insertions(+), 276 deletions(-) create mode 100644 src/qemu/qemu_logcontext.c create mode 100644 src/qemu/qemu_logcontext.h diff --git a/po/POTFILES b/po/POTFILES index 6167f98ac5..3a51aea5cb 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -174,6 +174,7 @@ src/qemu/qemu_hostdev.c src/qemu/qemu_hotplug.c src/qemu/qemu_interface.c src/qemu/qemu_interop_config.c +src/qemu/qemu_logcontext.c src/qemu/qemu_migration.c src/qemu/qemu_migration_cookie.c src/qemu/qemu_migration_params.c diff --git a/src/qemu/meson.build b/src/qemu/meson.build index 9be6996195..6d7a1bfbb0 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -21,6 +21,7 @@ qemu_driver_sources =3D [ 'qemu_hotplug.c', 'qemu_interface.c', 'qemu_interop_config.c', + 'qemu_logcontext.c', 'qemu_migration.c', 'qemu_migration_cookie.c', 'qemu_migration_params.c', diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 032e366f39..7e9203eda3 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -455,21 +455,8 @@ qemuDomainObjFromDomain(virDomainPtr domain) } =20 =20 -struct _qemuDomainLogContext { - GObject parent; - - int writefd; - int readfd; /* Only used if manager =3D=3D NULL */ - off_t pos; - ino_t inode; /* Only used if manager !=3D NULL */ - char *path; - virLogManager *manager; -}; - -G_DEFINE_TYPE(qemuDomainLogContext, qemu_domain_log_context, G_TYPE_OBJECT= ); static virClass *qemuDomainSaveCookieClass; =20 -static void qemuDomainLogContextFinalize(GObject *obj); static void qemuDomainSaveCookieDispose(void *obj); =20 =20 @@ -482,32 +469,8 @@ qemuDomainOnceInit(void) return 0; } =20 -static void qemu_domain_log_context_init(qemuDomainLogContext *logctxt G_G= NUC_UNUSED) -{ -} - -static void qemu_domain_log_context_class_init(qemuDomainLogContextClass *= klass) -{ - GObjectClass *obj =3D G_OBJECT_CLASS(klass); - - obj->finalize =3D qemuDomainLogContextFinalize; -} - VIR_ONCE_GLOBAL_INIT(qemuDomain); =20 -static void -qemuDomainLogContextFinalize(GObject *object) -{ - qemuDomainLogContext *ctxt =3D QEMU_DOMAIN_LOG_CONTEXT(object); - VIR_DEBUG("ctxt=3D%p", ctxt); - - virLogManagerFree(ctxt->manager); - VIR_FREE(ctxt->path); - VIR_FORCE_CLOSE(ctxt->writefd); - VIR_FORCE_CLOSE(ctxt->readfd); - G_OBJECT_CLASS(qemu_domain_log_context_parent_class)->finalize(object); -} - /* qemuDomainGetMasterKeyFilePath: * @libDir: Directory path to domain lib files * @@ -6830,7 +6793,7 @@ static void G_GNUC_PRINTF(5, 6) qemuDomainObjTaintMsg(virQEMUDriver *driver, virDomainObj *obj, virDomainTaintFlags taint, - qemuDomainLogContext *logCtxt, + qemuLogContext *logCtxt, const char *fmt, ...) { virErrorPtr orig_err =3D NULL; @@ -6883,12 +6846,12 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver, goto cleanup; =20 if (logCtxt) { - rc =3D qemuDomainLogContextWrite(logCtxt, - "%s: Domain id=3D%d is tainted: %s%= s%s%s\n", - timestamp, - obj->def->id, - virDomainTaintTypeToString(taint), - extraprefix, extramsg, extrasuffix); + rc =3D qemuLogContextWrite(logCtxt, + "%s: Domain id=3D%d is tainted: %s%s%s%s\= n", + timestamp, + obj->def->id, + virDomainTaintTypeToString(taint), + extraprefix, extramsg, extrasuffix); } else { rc =3D qemuDomainLogAppendMessage(driver, obj, "%s: Domain id=3D%d is tainted: %s= %s%s%s\n", @@ -6909,7 +6872,7 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver, void qemuDomainObjTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainTaintFlags taint, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { qemuDomainObjTaintMsg(driver, obj, taint, logCtxt, NULL); qemuDomainSaveStatus(obj); @@ -6918,7 +6881,7 @@ void qemuDomainObjTaint(virQEMUDriver *driver, static void qemuDomainObjCheckMachineTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { qemuDomainObjPrivate *priv =3D obj->privateData; virQEMUCaps *qemuCaps =3D priv->qemuCaps; @@ -6936,7 +6899,7 @@ qemuDomainObjCheckMachineTaint(virQEMUDriver *driver, static void qemuDomainObjCheckCPUTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuDomainLogContext *logCtxt, + qemuLogContext *logCtxt, bool incomingMigration) { qemuDomainObjPrivate *priv =3D obj->privateData; @@ -6968,7 +6931,7 @@ qemuDomainObjCheckCPUTaint(virQEMUDriver *driver, =20 void qemuDomainObjCheckTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuDomainLogContext *logCtxt, + qemuLogContext *logCtxt, bool incomingMigration) { size_t i; @@ -7024,7 +6987,7 @@ void qemuDomainObjCheckTaint(virQEMUDriver *driver, void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainDiskDef *disk, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { if (disk->rawio =3D=3D VIR_TRISTATE_BOOL_YES) qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES, @@ -7041,7 +7004,7 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriver *drive= r, void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainHostdevDef *hostdev, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { if (!virHostdevIsSCSIDevice(hostdev)) return; @@ -7054,7 +7017,7 @@ void qemuDomainObjCheckHostdevTaint(virQEMUDriver *dr= iver, void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainNetDef *net, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { /* script is only useful for NET_TYPE_ETHERNET (qemu) and * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for @@ -7066,163 +7029,6 @@ void qemuDomainObjCheckNetTaint(virQEMUDriver *driv= er, } =20 =20 -qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver, - virDomainObj *vm, - const char *basename) -{ - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - qemuDomainLogContext *ctxt =3D QEMU_DOMAIN_LOG_CONTEXT(g_object_new(QE= MU_TYPE_DOMAIN_LOG_CONTEXT, NULL)); - - VIR_DEBUG("Context new %p stdioLogD=3D%d", ctxt, cfg->stdioLogD); - ctxt->writefd =3D -1; - ctxt->readfd =3D -1; - - ctxt->path =3D g_strdup_printf("%s/%s.log", cfg->logDir, basename); - - if (cfg->stdioLogD) { - ctxt->manager =3D virLogManagerNew(driver->privileged); - if (!ctxt->manager) - goto error; - - ctxt->writefd =3D virLogManagerDomainOpenLogFile(ctxt->manager, - "qemu", - vm->def->uuid, - vm->def->name, - ctxt->path, - 0, - &ctxt->inode, - &ctxt->pos); - if (ctxt->writefd < 0) - goto error; - } else { - if ((ctxt->writefd =3D open(ctxt->path, O_WRONLY | O_CREAT | O_APP= END, S_IRUSR | S_IWUSR)) < 0) { - virReportSystemError(errno, _("failed to create logfile %1$s"), - ctxt->path); - goto error; - } - if (virSetCloseExec(ctxt->writefd) < 0) { - virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), - ctxt->path); - goto error; - } - - /* For unprivileged startup we must truncate the file since - * we can't rely on logrotate. We don't use O_TRUNC since - * it is better for SELinux policy if we truncate afterwards */ - if (!driver->privileged && - ftruncate(ctxt->writefd, 0) < 0) { - virReportSystemError(errno, _("failed to truncate %1$s"), - ctxt->path); - goto error; - } - - if ((ctxt->readfd =3D open(ctxt->path, O_RDONLY)) < 0) { - virReportSystemError(errno, _("failed to open logfile %1$s"), - ctxt->path); - goto error; - } - if (virSetCloseExec(ctxt->readfd) < 0) { - virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), - ctxt->path); - goto error; - } - - if ((ctxt->pos =3D lseek(ctxt->writefd, 0, SEEK_END)) < 0) { - virReportSystemError(errno, _("failed to seek in log file %1$s= "), - ctxt->path); - goto error; - } - } - - return ctxt; - - error: - g_clear_object(&ctxt); - return NULL; -} - - -int qemuDomainLogContextWrite(qemuDomainLogContext *ctxt, - const char *fmt, ...) -{ - va_list argptr; - g_autofree char *message =3D NULL; - int ret =3D -1; - - va_start(argptr, fmt); - - message =3D g_strdup_vprintf(fmt, argptr); - if (!ctxt->manager && - lseek(ctxt->writefd, 0, SEEK_END) < 0) { - virReportSystemError(errno, "%s", - _("Unable to seek to end of domain logfile")); - goto cleanup; - } - if (safewrite(ctxt->writefd, message, strlen(message)) < 0) { - virReportSystemError(errno, "%s", - _("Unable to write to domain logfile")); - goto cleanup; - } - - ret =3D 0; - - cleanup: - va_end(argptr); - return ret; -} - - -ssize_t qemuDomainLogContextRead(qemuDomainLogContext *ctxt, - char **msg) -{ - char *buf; - size_t buflen; - - VIR_DEBUG("Context read %p manager=3D%p inode=3D%llu pos=3D%llu", - ctxt, ctxt->manager, - (unsigned long long)ctxt->inode, - (unsigned long long)ctxt->pos); - - if (ctxt->manager) { - buf =3D virLogManagerDomainReadLogFile(ctxt->manager, - ctxt->path, - ctxt->inode, - ctxt->pos, - 1024 * 128, - 0); - if (!buf) - return -1; - buflen =3D strlen(buf); - } else { - ssize_t got; - - buflen =3D 1024 * 128; - - /* Best effort jump to start of messages */ - ignore_value(lseek(ctxt->readfd, ctxt->pos, SEEK_SET)); - - buf =3D g_new0(char, buflen); - - got =3D saferead(ctxt->readfd, buf, buflen - 1); - if (got < 0) { - VIR_FREE(buf); - virReportSystemError(errno, "%s", - _("Unable to read from log file")); - return -1; - } - - buf[got] =3D '\0'; - - buf =3D g_renew(char, buf, got + 1); - buflen =3D got; - } - - *msg =3D buf; - - return buflen; -} - - /** * qemuDomainLogAppendMessage: * @@ -7280,31 +7086,6 @@ qemuDomainLogAppendMessage(virQEMUDriver *driver, } =20 =20 -int qemuDomainLogContextGetWriteFD(qemuDomainLogContext *ctxt) -{ - return ctxt->writefd; -} - - -void qemuDomainLogContextMarkPosition(qemuDomainLogContext *ctxt) -{ - if (ctxt->manager) - virLogManagerDomainGetLogFilePosition(ctxt->manager, - ctxt->path, - 0, - &ctxt->inode, - &ctxt->pos); - else - ctxt->pos =3D lseek(ctxt->writefd, 0, SEEK_END); -} - - -virLogManager *qemuDomainLogContextGetManager(qemuDomainLogContext *ctxt) -{ - return ctxt->manager; -} - - /* Locate an appropriate 'qemu-img' binary. */ const char * qemuFindQemuImgBinary(virQEMUDriver *driver) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index db3aa51667..c3cd2e8938 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -32,13 +32,13 @@ #include "qemu_domainjob.h" #include "qemu_conf.h" #include "qemu_capabilities.h" +#include "qemu_logcontext.h" #include "qemu_migration_params.h" #include "qemu_nbdkit.h" #include "qemu_slirp.h" #include "qemu_fd.h" #include "virchrdev.h" #include "virobject.h" -#include "logging/log_manager.h" #include "virdomainmomentobjlist.h" #include "virenum.h" #include "vireventthread.h" @@ -479,9 +479,6 @@ struct qemuProcessEvent { =20 void qemuProcessEventFree(struct qemuProcessEvent *event); =20 -#define QEMU_TYPE_DOMAIN_LOG_CONTEXT qemu_domain_log_context_get_type() -G_DECLARE_FINAL_TYPE(qemuDomainLogContext, qemu_domain_log_context, QEMU, = DOMAIN_LOG_CONTEXT, GObject); - typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie; struct _qemuDomainSaveCookie { virObject parent; @@ -634,39 +631,27 @@ char *qemuDomainDefFormatLive(virQEMUDriver *driver, void qemuDomainObjTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainTaintFlags taint, - qemuDomainLogContext *logCtxt); + qemuLogContext *logCtxt); =20 char **qemuDomainObjGetTainting(virQEMUDriver *driver, virDomainObj *obj); =20 void qemuDomainObjCheckTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuDomainLogContext *logCtxt, + qemuLogContext *logCtxt, bool incomingMigration); void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainDiskDef *disk, - qemuDomainLogContext *logCtxt); + qemuLogContext *logCtxt); void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainHostdevDef *disk, - qemuDomainLogContext *logCtxt); + qemuLogContext *logCtxt); void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainNetDef *net, - qemuDomainLogContext *logCtxt); - -qemuDomainLogContext *qemuDomainLogContextNew(virQEMUDriver *driver, - virDomainObj *vm, - const char *basename); -int qemuDomainLogContextWrite(qemuDomainLogContext *ctxt, - const char *fmt, ...) G_GNUC_PRINTF(2, 3); -ssize_t qemuDomainLogContextRead(qemuDomainLogContext *ctxt, - char **msg); -int qemuDomainLogContextGetWriteFD(qemuDomainLogContext *ctxt); -void qemuDomainLogContextMarkPosition(qemuDomainLogContext *ctxt); - -virLogManager *qemuDomainLogContextGetManager(qemuDomainLogContext *ctxt); + qemuLogContext *logCtxt); =20 int qemuDomainLogAppendMessage(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/qemu/qemu_logcontext.c b/src/qemu/qemu_logcontext.c new file mode 100644 index 0000000000..0121ae5173 --- /dev/null +++ b/src/qemu/qemu_logcontext.c @@ -0,0 +1,264 @@ +/* + * qemu_logcontext.c: QEMU log context + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "qemu_logcontext.h" +#include "viralloc.h" +#include "virlog.h" +#include "virutil.h" + +#include + +#define VIR_FROM_THIS VIR_FROM_QEMU + +VIR_LOG_INIT("qemu.qemu_logcontext"); + + +struct _qemuLogContext { + GObject parent; + + int writefd; + int readfd; /* Only used if manager =3D=3D NULL */ + off_t pos; + ino_t inode; /* Only used if manager !=3D NULL */ + char *path; + virLogManager *manager; +}; + +G_DEFINE_TYPE(qemuLogContext, qemu_log_context, G_TYPE_OBJECT); + +static void +qemuLogContextFinalize(GObject *obj); + + +static void +qemu_log_context_init(qemuLogContext *logctxt G_GNUC_UNUSED) +{ +} + + +static void +qemu_log_context_class_init(qemuLogContextClass *klass) +{ + GObjectClass *obj =3D G_OBJECT_CLASS(klass); + + obj->finalize =3D qemuLogContextFinalize; +} + + +static void +qemuLogContextFinalize(GObject *object) +{ + qemuLogContext *ctxt =3D QEMU_LOG_CONTEXT(object); + VIR_DEBUG("ctxt=3D%p", ctxt); + + virLogManagerFree(ctxt->manager); + VIR_FREE(ctxt->path); + VIR_FORCE_CLOSE(ctxt->writefd); + VIR_FORCE_CLOSE(ctxt->readfd); + G_OBJECT_CLASS(qemu_log_context_parent_class)->finalize(object); +} + + +qemuLogContext * +qemuLogContextNew(virQEMUDriver *driver, + virDomainObj *vm, + const char *basename) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + qemuLogContext *ctxt =3D QEMU_LOG_CONTEXT(g_object_new(QEMU_TYPE_LOG_C= ONTEXT, NULL)); + + VIR_DEBUG("Context new %p stdioLogD=3D%d", ctxt, cfg->stdioLogD); + ctxt->writefd =3D -1; + ctxt->readfd =3D -1; + + ctxt->path =3D g_strdup_printf("%s/%s.log", cfg->logDir, basename); + + if (cfg->stdioLogD) { + ctxt->manager =3D virLogManagerNew(driver->privileged); + if (!ctxt->manager) + goto error; + + ctxt->writefd =3D virLogManagerDomainOpenLogFile(ctxt->manager, + "qemu", + vm->def->uuid, + vm->def->name, + ctxt->path, + 0, + &ctxt->inode, + &ctxt->pos); + if (ctxt->writefd < 0) + goto error; + } else { + if ((ctxt->writefd =3D open(ctxt->path, O_WRONLY | O_CREAT | O_APP= END, S_IRUSR | S_IWUSR)) < 0) { + virReportSystemError(errno, _("failed to create logfile %1$s"), + ctxt->path); + goto error; + } + if (virSetCloseExec(ctxt->writefd) < 0) { + virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), + ctxt->path); + goto error; + } + + /* For unprivileged startup we must truncate the file since + * we can't rely on logrotate. We don't use O_TRUNC since + * it is better for SELinux policy if we truncate afterwards */ + if (!driver->privileged && + ftruncate(ctxt->writefd, 0) < 0) { + virReportSystemError(errno, _("failed to truncate %1$s"), + ctxt->path); + goto error; + } + + if ((ctxt->readfd =3D open(ctxt->path, O_RDONLY)) < 0) { + virReportSystemError(errno, _("failed to open logfile %1$s"), + ctxt->path); + goto error; + } + if (virSetCloseExec(ctxt->readfd) < 0) { + virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), + ctxt->path); + goto error; + } + + if ((ctxt->pos =3D lseek(ctxt->writefd, 0, SEEK_END)) < 0) { + virReportSystemError(errno, _("failed to seek in log file %1$s= "), + ctxt->path); + goto error; + } + } + + return ctxt; + + error: + g_clear_object(&ctxt); + return NULL; +} + + +int +qemuLogContextWrite(qemuLogContext *ctxt, + const char *fmt, ...) +{ + va_list argptr; + g_autofree char *message =3D NULL; + int ret =3D -1; + + va_start(argptr, fmt); + + message =3D g_strdup_vprintf(fmt, argptr); + if (!ctxt->manager && + lseek(ctxt->writefd, 0, SEEK_END) < 0) { + virReportSystemError(errno, "%s", + _("Unable to seek to end of domain logfile")); + goto cleanup; + } + if (safewrite(ctxt->writefd, message, strlen(message)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to write to domain logfile")); + goto cleanup; + } + + ret =3D 0; + + cleanup: + va_end(argptr); + return ret; +} + + +ssize_t +qemuLogContextRead(qemuLogContext *ctxt, + char **msg) +{ + char *buf; + size_t buflen; + + VIR_DEBUG("Context read %p manager=3D%p inode=3D%llu pos=3D%llu", + ctxt, ctxt->manager, + (unsigned long long)ctxt->inode, + (unsigned long long)ctxt->pos); + + if (ctxt->manager) { + buf =3D virLogManagerDomainReadLogFile(ctxt->manager, + ctxt->path, + ctxt->inode, + ctxt->pos, + 1024 * 128, + 0); + if (!buf) + return -1; + buflen =3D strlen(buf); + } else { + ssize_t got; + + buflen =3D 1024 * 128; + + /* Best effort jump to start of messages */ + ignore_value(lseek(ctxt->readfd, ctxt->pos, SEEK_SET)); + + buf =3D g_new0(char, buflen); + + got =3D saferead(ctxt->readfd, buf, buflen - 1); + if (got < 0) { + VIR_FREE(buf); + virReportSystemError(errno, "%s", + _("Unable to read from log file")); + return -1; + } + + buf[got] =3D '\0'; + + buf =3D g_renew(char, buf, got + 1); + buflen =3D got; + } + + *msg =3D buf; + + return buflen; +} + + +int +qemuLogContextGetWriteFD(qemuLogContext *ctxt) +{ + return ctxt->writefd; +} + + +void +qemuLogContextMarkPosition(qemuLogContext *ctxt) +{ + if (ctxt->manager) + virLogManagerDomainGetLogFilePosition(ctxt->manager, + ctxt->path, + 0, + &ctxt->inode, + &ctxt->pos); + else + ctxt->pos =3D lseek(ctxt->writefd, 0, SEEK_END); +} + + +virLogManager * +qemuLogContextGetManager(qemuLogContext *ctxt) +{ + return ctxt->manager; +} diff --git a/src/qemu/qemu_logcontext.h b/src/qemu/qemu_logcontext.h new file mode 100644 index 0000000000..c6dbf3cb84 --- /dev/null +++ b/src/qemu/qemu_logcontext.h @@ -0,0 +1,38 @@ +/* + * qemu_logcontext.h: QEMU log context + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include +#include "qemu_conf.h" +#include "logging/log_manager.h" + +#define QEMU_TYPE_LOG_CONTEXT qemu_log_context_get_type() +G_DECLARE_FINAL_TYPE(qemuLogContext, qemu_log_context, QEMU, LOG_CONTEXT, = GObject); + +qemuLogContext *qemuLogContextNew(virQEMUDriver *driver, + virDomainObj *vm, + const char *basename); +int qemuLogContextWrite(qemuLogContext *ctxt, + const char *fmt, ...) G_GNUC_PRINTF(2, 3); +ssize_t qemuLogContextRead(qemuLogContext *ctxt, + char **msg); +int qemuLogContextGetWriteFD(qemuLogContext *ctxt); +void qemuLogContextMarkPosition(qemuLogContext *ctxt); + +virLogManager *qemuLogContextGetManager(qemuLogContext *ctxt); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 33fd230426..e90ca63f42 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1831,7 +1831,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon, static void qemuProcessMonitorLogFree(void *opaque) { - qemuDomainLogContext *logCtxt =3D opaque; + qemuLogContext *logCtxt =3D opaque; g_clear_object(&logCtxt); } =20 @@ -1857,7 +1857,7 @@ static int qemuConnectMonitor(virQEMUDriver *driver, virDomainObj *vm, int asyncJob, - qemuDomainLogContext *logCtxt, + qemuLogContext *logCtxt, bool reconnect) { qemuDomainObjPrivate *priv =3D vm->privateData; @@ -1921,7 +1921,7 @@ qemuConnectMonitor(virQEMUDriver *driver, * Returns 0 on success or -1 on error */ static int -qemuProcessReadLog(qemuDomainLogContext *logCtxt, +qemuProcessReadLog(qemuLogContext *logCtxt, char **msg, size_t max) { @@ -1931,7 +1931,7 @@ qemuProcessReadLog(qemuDomainLogContext *logCtxt, char *filter_next; size_t skip; =20 - if ((got =3D qemuDomainLogContextRead(logCtxt, &buf)) < 0) + if ((got =3D qemuLogContextRead(logCtxt, &buf)) < 0) return -1; =20 /* Filter out debug messages from intermediate libvirt process */ @@ -1974,7 +1974,7 @@ qemuProcessReadLog(qemuDomainLogContext *logCtxt, =20 =20 static int -qemuProcessReportLogError(qemuDomainLogContext *logCtxt, +qemuProcessReportLogError(qemuLogContext *logCtxt, const char *msgprefix) { g_autofree char *logmsg =3D NULL; @@ -1999,7 +1999,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon G_G= NUC_UNUSED, const char *msg, void *opaque) { - qemuDomainLogContext *logCtxt =3D opaque; + qemuLogContext *logCtxt =3D opaque; qemuProcessReportLogError(logCtxt, msg); } =20 @@ -2301,7 +2301,7 @@ static int qemuProcessWaitForMonitor(virQEMUDriver *driver, virDomainObj *vm, int asyncJob, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { int ret =3D -1; g_autoptr(GHashTable) info =3D NULL; @@ -4661,7 +4661,7 @@ static void qemuLogOperation(virDomainObj *vm, const char *msg, virCommand *cmd, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { g_autofree char *timestamp =3D NULL; qemuDomainObjPrivate *priv =3D vm->privateData; @@ -4675,20 +4675,20 @@ qemuLogOperation(virDomainObj *vm, if ((timestamp =3D virTimeStringNow()) =3D=3D NULL) return; =20 - if (qemuDomainLogContextWrite(logCtxt, - "%s: %s %s, qemu version: %d.%d.%d%s, ke= rnel: %s, hostname: %s\n", - timestamp, msg, VIR_LOG_VERSION_STRING, - (qemuVersion / 1000000) % 1000, - (qemuVersion / 1000) % 1000, - qemuVersion % 1000, - NULLSTR_EMPTY(package), - uts.release, - NULLSTR_EMPTY(hostname)) < 0) + if (qemuLogContextWrite(logCtxt, + "%s: %s %s, qemu version: %d.%d.%d%s, kernel: = %s, hostname: %s\n", + timestamp, msg, VIR_LOG_VERSION_STRING, + (qemuVersion / 1000000) % 1000, + (qemuVersion / 1000) % 1000, + qemuVersion % 1000, + NULLSTR_EMPTY(package), + uts.release, + NULLSTR_EMPTY(hostname)) < 0) return; =20 if (cmd) { g_autofree char *args =3D virCommandToString(cmd, true); - qemuDomainLogContextWrite(logCtxt, "%s\n", args); + qemuLogContextWrite(logCtxt, "%s\n", args); } } =20 @@ -7563,7 +7563,7 @@ qemuProcessLaunch(virConnectPtr conn, int ret =3D -1; int rv; int logfile =3D -1; - g_autoptr(qemuDomainLogContext) logCtxt =3D NULL; + g_autoptr(qemuLogContext) logCtxt =3D NULL; qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virCommand) cmd =3D NULL; struct qemuProcessHookData hookData; @@ -7613,11 +7613,11 @@ qemuProcessLaunch(virConnectPtr conn, hookData.cfg =3D cfg; =20 VIR_DEBUG("Creating domain log file"); - if (!(logCtxt =3D qemuDomainLogContextNew(driver, vm, vm->def->name)))= { + if (!(logCtxt =3D qemuLogContextNew(driver, vm, vm->def->name))) { virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); goto cleanup; } - logfile =3D qemuDomainLogContextGetWriteFD(logCtxt); + logfile =3D qemuLogContextGetWriteFD(logCtxt); =20 if (qemuProcessGenID(vm, flags) < 0) goto cleanup; @@ -7653,7 +7653,7 @@ qemuProcessLaunch(virConnectPtr conn, =20 qemuDomainObjCheckTaint(driver, vm, logCtxt, incoming !=3D NULL); =20 - qemuDomainLogContextMarkPosition(logCtxt); + qemuLogContextMarkPosition(logCtxt); =20 if (qemuProcessEnableDomainNamespaces(driver, vm) < 0) goto cleanup; --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891679; cv=none; d=zohomail.com; s=zohoarc; b=SzmWHC5Jh+XIN4gmfc2h+rM6SsKEnKwXX0FwmuHV4oZaTpSSwoEoEDWS9q9lM4a2/uhbDYBnQg8Nr2ymWdZDBBEQjz3RYfPNzavM0eYXbq0iWX7WuetxVHu/KN1/ktKXnpC9LVE0YR5yAKkHMMX+wxw++6c3O9Cmh/+GIv9f16g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891679; h=Content-Type:Content-Transfer-Encoding:Cc: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=+HpCE1Mvn0AjqgjA0wAjMTgPSZFy8LKitgmF8QYzphU=; b=Tt46QNi2gC8BVo4RP6UQSGgWSBSRcRSgvK2nTddS8OcpkkkfrbBQHVFGmxpw9ni7GkUK9Ty+VAhTMsyOlQAjOiV1MDCbKCiHCJgHk1NOevVewp57X56AeXiMqIJbHdyH9T/mWq0pV7en/fMWw4f5Soj0Kvipp0mSNQU8+SyAjDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891679150760.723516936849; Thu, 20 Jul 2023 15:21:19 -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-166-x3ZXPWtpONKxst8u3gWdiw-1; Thu, 20 Jul 2023 18:20:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1CB96830DB6; Thu, 20 Jul 2023 22:20:18 +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 ABEE9F6CDC; Thu, 20 Jul 2023 22:20:17 +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 8FC8A19452C9; Thu, 20 Jul 2023 22:20:15 +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 8EDF61946A71 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0DF0840C206F; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D796D40C207D; Thu, 20 Jul 2023 22:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891678; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=+HpCE1Mvn0AjqgjA0wAjMTgPSZFy8LKitgmF8QYzphU=; b=OaisW+UdLxv29XS5EbQrw0xMcWSY5gBGZkdqNN47RHFLCWXEqC5Rh8ex+M5BwZIyn8HZgn 4PtI2kU/Sy6ztb4Y6FynpoTV4THmpIl+egj87337Soixau5R0XYiAK4PEkRguFpKwQYqH/ wVdQeS/kCSJ2l9afDPQtNQ+2S1OWa9Q= X-MC-Unique: x3ZXPWtpONKxst8u3gWdiw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 14/36] qemu: move qemuProcessReadLog() to qemuLogContext Date: Thu, 20 Jul 2023 17:19:41 -0500 Message-ID: <20230720222003.411549-15-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1689891679607100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This code can be used by the nbdkit implementation for reading back filtered log data for error reporting. Move it to qemuLogContext so that it can be shared. Renamed to qemuLogContextReadFiltered(). Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_logcontext.c | 65 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_logcontext.h | 3 ++ src/qemu/qemu_process.c | 67 +------------------------------------- 3 files changed, 69 insertions(+), 66 deletions(-) diff --git a/src/qemu/qemu_logcontext.c b/src/qemu/qemu_logcontext.c index 0121ae5173..6e20f58bfa 100644 --- a/src/qemu/qemu_logcontext.c +++ b/src/qemu/qemu_logcontext.c @@ -21,6 +21,7 @@ #include "qemu_logcontext.h" #include "viralloc.h" #include "virlog.h" +#include "virstring.h" #include "virutil.h" =20 #include @@ -236,6 +237,70 @@ qemuLogContextRead(qemuLogContext *ctxt, } =20 =20 +/** + * qemuLogContextFilter: Read and filter log for relevant messages + * @ctxt: the domain log context + * @msg: pointer to buffer to store the read messages in + * @max: maximum length of the message returned in @msg after filtering + * + * Reads log output from @ctxt and filters it. Skips messages not produced= by + * the target executable or irrelevant messages. If @max is not zero, @buf= will + * contain at most @max characters from the end of the log and @buf will s= tart + * after a new line if possible. + */ +int +qemuLogContextReadFiltered(qemuLogContext *ctxt, + char **msg, + size_t max) +{ + char *buf; + char *eol; + char *filter_next; + size_t skip; + ssize_t got; + + if ((got =3D qemuLogContextRead(ctxt, &buf)) < 0) + return -1; + + /* Filter out debug messages from intermediate libvirt process */ + filter_next =3D buf; + while ((eol =3D strchr(filter_next, '\n'))) { + *eol =3D '\0'; + if (virLogProbablyLogMessage(filter_next) || + strstr(filter_next, "char device redirected to")) { + skip =3D (eol + 1) - filter_next; + memmove(filter_next, eol + 1, buf + got - eol); + got -=3D skip; + } else { + filter_next =3D eol + 1; + *eol =3D '\n'; + } + } + + if (got > 0 && + buf[got - 1] =3D=3D '\n') { + buf[got - 1] =3D '\0'; + got--; + } + + if (max > 0 && got > max) { + skip =3D got - max; + + if (buf[skip - 1] !=3D '\n' && + (eol =3D strchr(buf + skip, '\n')) && + !virStringIsEmpty(eol + 1)) + skip =3D eol + 1 - buf; + + memmove(buf, buf + skip, got - skip + 1); + got -=3D skip; + } + + buf =3D g_renew(char, buf, got + 1); + *msg =3D buf; + return 0; +} + + int qemuLogContextGetWriteFD(qemuLogContext *ctxt) { diff --git a/src/qemu/qemu_logcontext.h b/src/qemu/qemu_logcontext.h index c6dbf3cb84..b63a635170 100644 --- a/src/qemu/qemu_logcontext.h +++ b/src/qemu/qemu_logcontext.h @@ -32,6 +32,9 @@ int qemuLogContextWrite(qemuLogContext *ctxt, const char *fmt, ...) G_GNUC_PRINTF(2, 3); ssize_t qemuLogContextRead(qemuLogContext *ctxt, char **msg); +int qemuLogContextReadFiltered(qemuLogContext *ctxt, + char **msg, + size_t max); int qemuLogContextGetWriteFD(qemuLogContext *ctxt); void qemuLogContextMarkPosition(qemuLogContext *ctxt); =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index e90ca63f42..60a46b4b56 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1908,71 +1908,6 @@ qemuConnectMonitor(virQEMUDriver *driver, } =20 =20 -/** - * qemuProcessReadLog: Read log file of a qemu VM - * @logCtxt: the domain log context - * @msg: pointer to buffer to store the read messages in - * @max: maximum length of the message returned in @msg - * - * Reads log of a qemu VM. Skips messages not produced by qemu or irreleva= nt - * messages. If @max is not zero, @msg will contain at most @max characters - * from the end of the log and @msg will start after a new line if possibl= e. - * - * Returns 0 on success or -1 on error - */ -static int -qemuProcessReadLog(qemuLogContext *logCtxt, - char **msg, - size_t max) -{ - char *buf; - ssize_t got; - char *eol; - char *filter_next; - size_t skip; - - if ((got =3D qemuLogContextRead(logCtxt, &buf)) < 0) - return -1; - - /* Filter out debug messages from intermediate libvirt process */ - filter_next =3D buf; - while ((eol =3D strchr(filter_next, '\n'))) { - *eol =3D '\0'; - if (virLogProbablyLogMessage(filter_next) || - strstr(filter_next, "char device redirected to")) { - skip =3D (eol + 1) - filter_next; - memmove(filter_next, eol + 1, buf + got - eol); - got -=3D skip; - } else { - filter_next =3D eol + 1; - *eol =3D '\n'; - } - } - - if (got > 0 && - buf[got - 1] =3D=3D '\n') { - buf[got - 1] =3D '\0'; - got--; - } - - if (max > 0 && got > max) { - skip =3D got - max; - - if (buf[skip - 1] !=3D '\n' && - (eol =3D strchr(buf + skip, '\n')) && - !virStringIsEmpty(eol + 1)) - skip =3D eol + 1 - buf; - - memmove(buf, buf + skip, got - skip + 1); - got -=3D skip; - } - - buf =3D g_renew(char, buf, got + 1); - *msg =3D buf; - return 0; -} - - static int qemuProcessReportLogError(qemuLogContext *logCtxt, const char *msgprefix) @@ -1980,7 +1915,7 @@ qemuProcessReportLogError(qemuLogContext *logCtxt, g_autofree char *logmsg =3D NULL; =20 /* assume that 1024 chars of qemu log is the right balance */ - if (qemuProcessReadLog(logCtxt, &logmsg, 1024) < 0) + if (qemuLogContextReadFiltered(logCtxt, &logmsg, 1024) < 0) return -1; =20 virResetLastError(); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891630; cv=none; d=zohomail.com; s=zohoarc; b=nfroA2Ub/LQmLqPA7vZKuOOcfk4eHk9L1P9Cvl4LCWSmD5LFesAYl4MXfysh8HzlTkyfIi0AVv8e6kEi43XoCrwE/BMugU5TLJRwwhW1hbD6/+smDWhyI10CeB5F1kK1svyAtWxd2Zm3HJcgXoPx3+uJ/KT4J+ci13uARYGS0Hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891630; h=Content-Type:Content-Transfer-Encoding:Cc: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=/rN4tj6f6K5ymxBa3UyUlt8yAThzUjkCrgaGrTKwLgk=; b=dgtojLcYSwUs1BqyR8k5dmfERIcx2y6Tts7yukPlP+wHdDSo1N1P5LKsrokHxRcHTNNvEZwAZRrIxOu9rZwU4sCSYubokQQizL/ZvKuTo5Dddwg1ZxdMi2P7PeiHtTalMAFrO9kjP+pWEVK+pxK9s3A2MqaQN2EltS/JH/7jJiM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891630136510.716138471048; Thu, 20 Jul 2023 15:20:30 -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-357-XuVHTuXDO_q07I7Mg6WErg-1; Thu, 20 Jul 2023 18:20:25 -0400 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 7CE2288D070; Thu, 20 Jul 2023 22:20:20 +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 654F21121318; Thu, 20 Jul 2023 22:20: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 75AEC194973B; Thu, 20 Jul 2023 22:20:16 +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 91CDE1946A74 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4C51740C207F; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2154040C207D; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891629; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=/rN4tj6f6K5ymxBa3UyUlt8yAThzUjkCrgaGrTKwLgk=; b=Yz+/tmm4VLpJU0eBw93z5o60SnrAdqBkk6QSganUGkUULoLhhY/2oK7GmVzmu8Ve07P7IM +YNc1hgfLgZSE+lJXtAmh/G7ftU1ls5X31DL0QrI96XCsDpeduaocqmQ398p6qXnqWaOiA UUMhRn2BAVwSIfijCjEuA6JYIB4KVyo= X-MC-Unique: XuVHTuXDO_q07I7Mg6WErg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 15/36] qemu: log error output from nbdkit Date: Thu, 20 Jul 2023 17:19:42 -0500 Message-ID: <20230720222003.411549-16-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa 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: 1689891632363100001 Content-Type: text/plain; charset="utf-8"; x-default="true" log stderr and stdout from nbdkit into its own log so that nbdkit-related issues can be debugged more easily. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 1acc6bf58f..7275d33419 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -853,12 +853,23 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, virTimeBackOffVar timebackoff; g_autoptr(virURI) uri =3D NULL; g_autofree char *uristring =3D NULL; + 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; =20 if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc))) return -1; =20 + if (!(logContext =3D qemuLogContextNew(driver, vm, basename))) { + virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); + return -1; + } + + logfd =3D qemuLogContextGetWriteFD(logContext); + VIR_DEBUG("starting nbdkit process for %s", proc->source->nodestorage); - virCommandSetErrorBuffer(cmd, &errbuf); + virCommandSetErrorFD(cmd, &logfd); + virCommandSetOutputFD(cmd, &logfd); virCommandSetPidFile(cmd, proc->pidfile); =20 if (qemuExtDeviceLogCommand(driver, vm, cmd, "nbdkit") < 0) @@ -900,6 +911,9 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, if ((uri =3D qemuBlockStorageSourceGetURI(proc->source))) uristring =3D virURIFormat(uri); =20 + if (qemuLogContextReadFiltered(logContext, &errbuf, 1024) < 0) + VIR_WARN("Unable to read from nbdkit log"); + virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to connect to nbdkit for '%1$s': %2$s"), NULLSTR(uristring), NULLSTR(errbuf)); --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891635; cv=none; d=zohomail.com; s=zohoarc; b=bZ+J8+X7CU/rnByg7DR+/NoCPifovoWbSswandUQxy4H743d0ZxF/6yVUQTCAfMfN6aZ9NySGq2bn4x2D+KfWw5tmozhLo+KLSBkbeIeZAOfQZ3M0N5IJnlrp8mYol1VisxB43Lwycv3lcKhjnZz+5ZVOpDvf51qtrlcN/mcX4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891635; h=Content-Type:Content-Transfer-Encoding:Cc: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=IK4pQ0mzDEzDAvl7dLMR95g+pCPldo3Y2G+xKxC4nAo=; b=RDRYT/lE5ucWTgr11IHfjA1FAqGLcKEM9px7lXBpfxVHbLAVAXIBpfveAcQ13UDt2ACgQut9YgabqlwW2qWgVpcbJDSKTfjXQRiqL9W714D8gBKnKKBze6IaJrErx/8g5o5zkF+NyBz4cqhy6I7I+hRFLosl78lBybu5jaUwKug= 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 1689891635529562.0929510239574; Thu, 20 Jul 2023 15:20:35 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-362-MRGsQzijMFapWHnrxwzifA-1; Thu, 20 Jul 2023 18:20:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B43B28088A4; Thu, 20 Jul 2023 22:20:21 +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 4421DC57969; Thu, 20 Jul 2023 22:20:21 +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 B53161949754; Thu, 20 Jul 2023 22:20:16 +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 9341E1946A45 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8A82740C2005; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F2C140C2004; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891634; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=IK4pQ0mzDEzDAvl7dLMR95g+pCPldo3Y2G+xKxC4nAo=; b=gH2cpUjjh/NmoKGnIVE+6cSpVJohOMosMN49LA5f4NmYXtDkjQJXVBTYMJRbLLaNAqlSVI Af++3zTIrz/05KFhwu6+6VC/n6NJMmJngcYGGedRU8fOsw1LZFBhdMfo78+NGsbs8yAyV7 hp3gRBkBgMas06NXbrdYKf1Ios0ur98= X-MC-Unique: MRGsQzijMFapWHnrxwzifA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 16/36] tests: add ability to test various nbdkit capabilities Date: Thu, 20 Jul 2023 17:19:43 -0500 Message-ID: <20230720222003.411549-17-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1689891636156100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Add new DO_TEST_CAPS_LATEST_NBDKIT macro to test xml2argv for various nbdkit capability scenarios. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 20 +++++++++++++++++--- tests/qemuxml2argvtest.c | 11 +++++++++++ tests/testutilsqemu.c | 26 ++++++++++++++++++++++++++ tests/testutilsqemu.h | 4 ++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 7275d33419..a8988778ac 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -291,10 +291,16 @@ virNbkditCapsCheckModdir(const char *moddir, =20 static bool virNbdkitCapsIsValid(void *data, - void *privData G_GNUC_UNUSED) + void *privData) { qemuNbdkitCaps *nbdkitCaps =3D data; struct stat st; + /* when run under test, we will use privData as a signal to indicate t= hat + * we shouldn't touch the filesystem */ + bool skipValidation =3D (privData !=3D NULL); + + if (skipValidation) + return true; =20 if (!nbdkitCaps->path) return true; @@ -335,9 +341,17 @@ virNbdkitCapsIsValid(void *data, =20 static void* virNbdkitCapsNewData(const char *binary, - void *privData G_GNUC_UNUSED) + void *privData) { - qemuNbdkitCaps *caps =3D qemuNbdkitCapsNew(binary); + /* when run under test, we will use privData as a signal to indicate t= hat + * we shouldn't touch the filesystem */ + bool skipNewData =3D (privData !=3D NULL); + qemuNbdkitCaps *caps =3D NULL; + + if (skipNewData) + return NULL; + + caps =3D qemuNbdkitCapsNew(binary); qemuNbdkitCapsQuery(caps); =20 return caps; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 52d206d00f..d3dafb5bb5 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -613,6 +613,14 @@ testCompareXMLToArgv(const void *data) if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0) goto cleanup; =20 + if (info->nbdkitCaps) { + if (virFileCacheInsertData(driver.nbdkitCapsCache, TEST_NBDKIT_PAT= H, + g_object_ref(info->nbdkitCaps)) < 0) { + g_object_unref(info->nbdkitCaps); + goto cleanup; + } + } + if (info->migrateFrom && !(migrateURI =3D qemuMigrationDstGetURI(info->migrateFrom, info->migrateFd))) @@ -833,6 +841,9 @@ mymain(void) # define DO_TEST_CAPS_ARCH_VER(name, arch, ver) \ DO_TEST_CAPS_ARCH_VER_FULL(name, arch, ver, ARG_END) =20 +# define DO_TEST_CAPS_LATEST_NBDKIT(name, ...) \ + DO_TEST_CAPS_ARCH_LATEST_FULL(name, "x86_64", ARG_NBDKIT_CAPS, __VA_AR= GS__, QEMU_NBDKIT_CAPS_LAST, ARG_END) + # define DO_TEST_CAPS_LATEST(name) \ DO_TEST_CAPS_ARCH_LATEST(name, "x86_64") =20 diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 16b773a768..67923070e1 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -57,6 +57,10 @@ virFindFileInPath(const char *file) return g_strdup_printf("/usr/bin/%s", file); } =20 + if (g_str_equal(file, "nbdkit")) { + return g_strdup(TEST_NBDKIT_PATH); + } + /* Nothing in tests should be relying on real files * in host OS, so we return NULL to try to force * an error in such a case @@ -295,6 +299,7 @@ void qemuTestDriverFree(virQEMUDriver *driver) virObjectUnref(driver->caps); virObjectUnref(driver->config); virObjectUnref(driver->securityManager); + g_clear_object(&driver->nbdkitCapsCache); =20 virCPUDefFree(cpuDefault); virCPUDefFree(cpuHaswell); @@ -494,6 +499,12 @@ int qemuTestDriverInit(virQEMUDriver *driver) if (!driver->qemuCapsCache) goto error; =20 + driver->nbdkitCapsCache =3D qemuNbdkitCapsCacheNew("/dev/null"); + /* the nbdkitCapsCache just interprets the presence of a non-null priv= ate + * data pointer as a signal to skip cache validation. This prevents the + * cache from trying to validate the plugindir mtime, etc during test = */ + virFileCacheSetPriv(driver->nbdkitCapsCache, GUINT_TO_POINTER(1)); + driver->xmlopt =3D virQEMUDriverCreateXMLConf(driver, "none"); if (!driver->xmlopt) goto error; @@ -787,6 +798,14 @@ testQemuInfoSetArgs(struct testQemuInfo *info, ignore_value(virBitmapSetBit(info->args.fakeCapsDel, flag)= ); break; =20 + case ARG_NBDKIT_CAPS: + if (!(info->args.fakeNbdkitCaps)) + info->args.fakeNbdkitCaps =3D virBitmapNew(QEMU_NBDKIT_CAP= S_LAST); + + while ((flag =3D va_arg(argptr, int)) < QEMU_NBDKIT_CAPS_LAST) + ignore_value(virBitmapSetBit(info->args.fakeNbdkitCaps, fl= ag)); + break; + case ARG_GIC: info->args.gic =3D va_arg(argptr, int); break; @@ -1061,6 +1080,11 @@ testQemuInfoInitArgs(struct testQemuInfo *info) for (cap =3D -1; (cap =3D virBitmapNextSetBit(info->args.fakeCapsDel, = cap)) >=3D 0;) virQEMUCapsClear(info->qemuCaps, cap); =20 + info->nbdkitCaps =3D qemuNbdkitCapsNew(TEST_NBDKIT_PATH); + + for (cap =3D -1; (cap =3D virBitmapNextSetBit(info->args.fakeNbdkitCap= s, cap)) >=3D 0;) + qemuNbdkitCapsSet(info->nbdkitCaps, cap); + if (info->args.gic !=3D GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, info->args.gic) < 0) return -1; @@ -1079,6 +1103,8 @@ testQemuInfoClear(struct testQemuInfo *info) g_clear_pointer(&info->args.fakeCapsAdd, virBitmapFree); g_clear_pointer(&info->args.fakeCapsDel, virBitmapFree); g_clear_pointer(&info->args.fds, g_hash_table_unref); + g_clear_object(&info->nbdkitCaps); + g_clear_pointer(&info->args.fakeNbdkitCaps, virBitmapFree); } =20 =20 diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index e0d116336e..d0e0531929 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -28,6 +28,7 @@ # define TEST_TPM_ENV_VAR "VIR_TEST_MOCK_FAKE_TPM_VERSION" # define TPM_VER_1_2 "1.2" # define TPM_VER_2_0 "2.0" +# define TEST_NBDKIT_PATH "/fakebindir/nbdkit" =20 enum { GIC_NONE =3D 0, @@ -49,6 +50,7 @@ typedef enum { ARG_CAPS_VARIANT, ARG_CAPS_HOST_CPU_MODEL, ARG_FD_GROUP, /* name, nfds, fd[0], ... fd[n-1] */ + ARG_NBDKIT_CAPS, ARG_END, } testQemuInfoArgName; =20 @@ -79,6 +81,7 @@ struct testQemuArgs { bool newargs; virBitmap *fakeCapsAdd; virBitmap *fakeCapsDel; + virBitmap *fakeNbdkitCaps; char *capsver; char *capsarch; const char *capsvariant; @@ -94,6 +97,7 @@ struct testQemuInfo { char *outfile; char *errfile; virQEMUCaps *qemuCaps; + qemuNbdkitCaps *nbdkitCaps; const char *migrateFrom; int migrateFd; unsigned int flags; --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891636; cv=none; d=zohomail.com; s=zohoarc; b=M29K6PAY538RsjriGtByGaF9Hhkivnhb6qXPs2HzjbyF/FFiehvCDg0NV4SLbI/p+LrT0RSYp5pt3gmfwhcYdAECGepJnVl5pKrROhppMizhhXzjyjIMPhEn0HoZL0veyudypE/GZHKCp2AOgAD8XZ3z7fc6OcJjVjqvPEDyXjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891636; h=Content-Type:Content-Transfer-Encoding:Cc: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=h8PK7soU1rebqkM+aFUnnKAVc8njSlcfIQb1wbihIEk=; b=C9j9Y1iHNWHXZ9UwGTsMquxU+jqonkne+6cnQdqSk/MvelVP/R08rPAHm+46TUTEyRxPw7OhsU103tX++gdldGlDOGZgs9JOkLh5Z/bVGbFQZtfmHrAPgFxnYWFyjPzTjrh0OSLTpoWiiFGnJI3v0XtIdarmrRe9aV9m5C7Stek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891636016783.3228969765611; Thu, 20 Jul 2023 15:20:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-481-3HJGA8DxNfK9BUhP5LgUVQ-1; Thu, 20 Jul 2023 18:20:30 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC73A1C06937; Thu, 20 Jul 2023 22:20:26 +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 BD5D7145414A; Thu, 20 Jul 2023 22:20:26 +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 45884194E015; Thu, 20 Jul 2023 22:20:17 +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 9368D1946A75 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C874A40C2004; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D6E940C207D; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891633; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=h8PK7soU1rebqkM+aFUnnKAVc8njSlcfIQb1wbihIEk=; b=ZYLM2vUPZKyNRL0/iutRWaJ9iHJVkZiTeoWLj94Zs43Izv5X7vaRcnJ/1b5nQy4mTntpL+ eRIVGxxGD0y4HzvzLPSPwS1OImlfaSROyLB9uZS2TCv1Whk45Q3dIyypO/zlIDpS9yyw+K Lwc4X/Xzx1TX2mZ656lQ5AZjvLOdO2I= X-MC-Unique: 3HJGA8DxNfK9BUhP5LgUVQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 17/36] qemu: split qemuDomainSecretStorageSourcePrepare Date: Thu, 20 Jul 2023 17:19:44 -0500 Message-ID: <20230720222003.411549-18-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1689891636374100003 Content-Type: text/plain; charset="utf-8"; x-default="true" This prepares encryption secrets and authentication secrets. When we add nbdkit-backed network storage sources, we will not need to send authentication secrets to qemu, since they will be sent to nbdkit instead. So split this into two different functions. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 103 +++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7e9203eda3..1da33debda 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1398,38 +1398,70 @@ qemuDomainSecretStorageSourcePrepareCookies(qemuDom= ainObjPrivate *priv, =20 =20 /** - * qemuDomainSecretStorageSourcePrepare: + * qemuDomainSecretStorageSourcePrepareEncryption: * @priv: domain private object * @src: storage source struct to setup - * @authalias: prefix of the alias for secret holding authentication data - * @encalias: prefix of the alias for secret holding encryption password + * @alias: prefix of the alias for secret holding encryption password * - * Prepares data necessary for encryption and authentication of @src. The = two - * alias prefixes are provided since in the backing chain authentication b= elongs - * to the storage protocol data whereas encryption is relevant to the form= at - * driver in qemu. The two will have different node names. + * Prepares data necessary for encryption of @src. * * Returns 0 on success; -1 on error while reporting an libvirt error. */ static int -qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivate *priv, - virStorageSource *src, - const char *aliasprotocol, - const char *aliasformat) +qemuDomainSecretStorageSourcePrepareEncryption(qemuDomainObjPrivate *priv, + virStorageSource *src, + const char *alias) { qemuDomainStorageSourcePrivate *srcPriv; - bool hasEnc =3D src->encryption && src->encryption->nsecrets > 0; + size_t nsecrets =3D 0; + size_t i; =20 - if (virStorageSourceIsEmpty(src)) + if (!(src->encryption && src->encryption->nsecrets > 0)) return 0; =20 - if (!src->auth && !hasEnc && src->ncookies =3D=3D 0) + if (virStorageSourceIsEmpty(src)) return 0; =20 - if (!(src->privateData =3D qemuDomainStorageSourcePrivateNew())) - return -1; + nsecrets =3D src->encryption->nsecrets; + + srcPriv =3D qemuDomainStorageSourcePrivateFetch(src); + + srcPriv->enccount =3D nsecrets; + srcPriv->encinfo =3D g_new0(qemuDomainSecretInfo *, nsecrets); + for (i =3D 0; i < nsecrets; ++i) { + if (!(srcPriv->encinfo[i] =3D qemuDomainSecretInfoSetupFromSecret(= priv, alias, + "e= ncryption", i, + VI= R_SECRET_USAGE_TYPE_VOLUME, + NU= LL, + &s= rc->encryption->secrets[i]->seclookupdef))) + return -1; + } + + return 0; +} + + +/** + * qemuDomainSecretStorageSourcePrepareAuth: + * @priv: domain private object + * @src: storage source struct to setup + * @alias: prefix of the alias for secret holding authentication data + * + * Prepares data necessary for authentication of @src. + * + * Returns 0 on success; -1 on error while reporting an libvirt error. + */ +static int +qemuDomainSecretStorageSourcePrepareAuth(qemuDomainObjPrivate *priv, + virStorageSource *src, + const char *alias) +{ + qemuDomainStorageSourcePrivate *srcPriv; + + if (virStorageSourceIsEmpty(src)) + return 0; =20 - srcPriv =3D QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); + srcPriv =3D qemuDomainStorageSourcePrivateFetch(src); =20 if (src->auth) { virSecretUsageType usageType =3D VIR_SECRET_USAGE_TYPE_ISCSI; @@ -1437,7 +1469,7 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPri= vate *priv, if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_RBD) usageType =3D VIR_SECRET_USAGE_TYPE_CEPH; =20 - if (!(srcPriv->secinfo =3D qemuDomainSecretInfoSetupFromSecret(pri= v, aliasprotocol, + if (!(srcPriv->secinfo =3D qemuDomainSecretInfoSetupFromSecret(pri= v, alias, "auth= ", 0, usage= Type, src->= auth->username, @@ -1445,26 +1477,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjP= rivate *priv, return -1; } =20 - if (hasEnc) { - size_t nsecrets =3D src->encryption->nsecrets; - size_t i; - - srcPriv->enccount =3D nsecrets; - srcPriv->encinfo =3D g_new0(qemuDomainSecretInfo *, nsecrets); - for (i =3D 0; i < nsecrets; ++i) { - if (!(srcPriv->encinfo[i] =3D qemuDomainSecretInfoSetupFromSec= ret(priv, aliasformat, - = "encryption", i, - = VIR_SECRET_USAGE_TYPE_VOLUME, - = NULL, - = &src->encryption->secrets[i]->seclookupdef))) - return -1; - } - } - if (src->ncookies && !(srcPriv->httpcookie =3D qemuDomainSecretStorageSourcePrepareCook= ies(priv, = src, - = aliasprotocol))) + = alias))) return -1; =20 return 0; @@ -10945,9 +10961,12 @@ qemuDomainPrepareDiskSourceLegacy(virDomainDiskDef= *disk, qemuDomainPrepareStorageSourceConfig(disk->src, cfg); qemuDomainPrepareDiskSourceData(disk, disk->src); =20 - if (qemuDomainSecretStorageSourcePrepare(priv, disk->src, - disk->info.alias, - disk->info.alias) < 0) + if (qemuDomainSecretStorageSourcePrepareEncryption(priv, disk->src, + disk->info.alias) <= 0) + return -1; + + if (qemuDomainSecretStorageSourcePrepareAuth(priv, disk->src, + disk->info.alias) < 0) return -1; =20 if (qemuDomainPrepareStorageSourcePR(disk->src, priv, disk->info.alias= ) < 0) @@ -11038,9 +11057,11 @@ qemuDomainPrepareStorageSourceBlockdevNodename(vir= DomainDiskDef *disk, qemuDomainPrepareStorageSourceConfig(src, cfg); qemuDomainPrepareDiskSourceData(disk, src); =20 - if (qemuDomainSecretStorageSourcePrepare(priv, src, - src->nodestorage, - src->nodeformat) < 0) + if (qemuDomainSecretStorageSourcePrepareEncryption(priv, src, + src->nodeformat) < = 0) + return -1; + if (qemuDomainSecretStorageSourcePrepareAuth(priv, src, + src->nodestorage) < 0) return -1; =20 if (qemuDomainPrepareStorageSourcePR(src, priv, src->nodestorage) < 0) --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891656; cv=none; d=zohomail.com; s=zohoarc; b=gMYSdahaOW5jL3Z6enXI/cdyyFcwYRefOPBG9UR0w3/GsfNCLole/KT3iHVQHXQOdn2QATZzPX3G/nwADnoLPIJNSdjWneN721pQIIutfNqTY5/1cTZJlOtFQNFFRntBPIpnvChWBsPcqoeMur8ZXNI0f5jOzWpK7qetsc0jyI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891656; h=Content-Type:Content-Transfer-Encoding:Cc: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=eEad6bBFDVkfr36w5Fr8oys7GudYGDIRZPa6kaina9U=; b=VlO3AERNwq9T24j71UwQXI3sjmZaGqBtxjUiBBmTcqo/qlNG8ZbUVvlMUWgF4/fb3OvRI7EWIwZq7Au4ANCB+mjlgHF1jDBC7gK2xc7osmzvfvk6kVqJofxSGnRqszs/8ugS80KjINOfjL8W0WdDPKq4XcppTY3mrDFZBsSs6yg= 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 1689891656055216.86508811789554; Thu, 20 Jul 2023 15:20:56 -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-410-r5LrtSMVNa6B9h2UrjpXqw-1; Thu, 20 Jul 2023 18:20:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02BA1830DAC; Thu, 20 Jul 2023 22:20:32 +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 DEC6B207B315; Thu, 20 Jul 2023 22:20:31 +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 8B62C194F4AF; Thu, 20 Jul 2023 22:20:19 +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 A417C19452CC for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1286C40C2007; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DBA1340C207D; Thu, 20 Jul 2023 22:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891655; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=eEad6bBFDVkfr36w5Fr8oys7GudYGDIRZPa6kaina9U=; b=L0G2yM9op2yfOQHPYekAoAEcaxmbm5D1aQURobGC6AykZW8+sWcarghAwzCf9i7/qRptSW 4AC8ZVM4KjnUfUyv+1O0Ji8vLcuGjvEMuejhxSqfTOck1cQLwHu7ywnXb5OQ7wOfk3ciKI 5Xo76ylxFR1/clf7aqiqZfMX4s9zuGA= X-MC-Unique: r5LrtSMVNa6B9h2UrjpXqw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 18/36] qemu: include nbdkit state in private xml Date: Thu, 20 Jul 2023 17:19:45 -0500 Message-ID: <20230720222003.411549-19-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891656443100009 Content-Type: text/plain; charset="utf-8"; x-default="true" Add xml to the private data for a disk source to represent the nbdkit process so that the state can be re-created if the libvirt daemon is restarted. Format: /path/to/nbdkit.pid /path/to/nbdkit.socket Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 52 +++++++++++++++++ src/qemu/qemu_nbdkit.c | 71 +++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 8 +++ src/qemu/qemu_process.c | 6 ++ tests/qemustatusxml2xmldata/modern-in.xml | 4 ++ 5 files changed, 141 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1da33debda..d2db388622 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1958,6 +1958,33 @@ qemuStorageSourcePrivateDataAssignSecinfo(qemuDomain= SecretInfo **secinfo, } =20 =20 +static int +qemuStorageSourcePrivateDataParseNbdkit(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStorageSource *src) +{ + g_autofree char *pidfile =3D NULL; + g_autofree char *socketfile =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + + ctxt->node =3D node; + + if (!(pidfile =3D virXPathString("string(./pidfile)", ctxt))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing nbdkit pid= file")); + return -1; + } + + if (!(socketfile =3D virXPathString("string(./socketfile)", ctxt))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing nbdkit soc= ketfile")); + return -1; + } + + qemuNbdkitReconnectStorageSource(src, pidfile, socketfile); + + return 0; +} + + static int qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt, virStorageSource *src) @@ -1971,6 +1998,7 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr = ctxt, bool fdsetPresent =3D false; unsigned int fdSetID; int enccount; + xmlNodePtr nbdkitnode =3D NULL; =20 src->nodestorage =3D virXPathString("string(./nodenames/nodename[@type= =3D'storage']/@name)", ctxt); src->nodeformat =3D virXPathString("string(./nodenames/nodename[@type= =3D'format']/@name)", ctxt); @@ -2036,6 +2064,10 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr= ctxt, virTristateBoolTypeFromString(thresholdEventWithIndex) =3D=3D VIR_= TRISTATE_BOOL_YES) src->thresholdEventWithIndex =3D true; =20 + if ((nbdkitnode =3D virXPathNode("nbdkit", ctxt))) { + if (qemuStorageSourcePrivateDataParseNbdkit(nbdkitnode, ctxt, src)= < 0) + return -1; + } return 0; } =20 @@ -2053,6 +2085,23 @@ qemuStorageSourcePrivateDataFormatSecinfo(virBuffer = *buf, } =20 =20 +static void +qemuStorageSourcePrivateDataFormatNbdkit(qemuNbdkitProcess *nbdkit, + virBuffer *buf) +{ + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + + if (!nbdkit) + return; + + virBufferEscapeString(&childBuf, "%s\n", + nbdkit->pidfile); + virBufferEscapeString(&childBuf, "%s\n", + nbdkit->socketfile); + virXMLFormatElement(buf, "nbdkit", NULL, &childBuf); +} + + static int qemuStorageSourcePrivateDataFormat(virStorageSource *src, virBuffer *buf) @@ -2102,6 +2151,9 @@ qemuStorageSourcePrivateDataFormat(virStorageSource *= src, if (src->thresholdEventWithIndex) virBufferAddLit(buf, "\n"); =20 + if (srcPriv) + qemuStorageSourcePrivateDataFormatNbdkit(srcPriv->nbdkitProcess, b= uf); + return 0; } =20 diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index a8988778ac..5539b54e8c 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -628,6 +628,77 @@ qemuNbdkitProcessNew(virStorageSource *source, return nbdkit; } =20 +/** + * qemuNbdkitReconnectStorageSource: + * @source: a storage source + * @pidfile: a pidfile for an nbdkit process + * @socketfile: the socket file associated with the nbdkit process + * + * This function constructs a new qemuNbdkitProcess object with the given = values for @pidfile and + * @socketfile and stores it in @source. This is intended to be called whe= n the libvirt daemon is + * restarted and tries to reconnect to all currently-running domains. Sinc= e this function is called + * from the code that parses the current daemon state, it should not perfo= rm any filesystem + * operations, or anything else that might fail. Additional initialization= will be done later by + * calling qemuNbdkitStorageSourceManageProcess(). + */ +void +qemuNbdkitReconnectStorageSource(virStorageSource *source, + const char *pidfile, + const char *socketfile) +{ + qemuDomainStorageSourcePrivate *srcpriv =3D qemuDomainStorageSourcePri= vateFetch(source); + + if (srcpriv->nbdkitProcess) { + VIR_WARN("source already has an nbdkit process"); + return; + } + + srcpriv->nbdkitProcess =3D qemuNbdkitProcessNew(source, pidfile, socke= tfile); +} + + +static void +qemuNbdkitStorageSourceManageProcessOne(virStorageSource *source) +{ + qemuDomainStorageSourcePrivate *srcpriv =3D QEMU_DOMAIN_STORAGE_SOURCE= _PRIVATE(source); + qemuNbdkitProcess *proc; + + if (!srcpriv) + return; + + proc =3D srcpriv->nbdkitProcess; + + if (!proc) + return; + + if (proc->pid <=3D 0) { + if (virPidFileReadPath(proc->pidfile, &proc->pid) < 0) { + VIR_WARN("Unable to read pidfile '%s'", proc->pidfile); + return; + } + } + + if (virProcessKill(proc->pid, 0) < 0) + VIR_WARN("nbdkit process %i is not alive", proc->pid); +} + +/** + * qemuNbdkitStorageSourceManageProcess: + * @source: a storage source + * @vm: the vm that owns this storage source + * + * This function re-enables monitoring of any nbdkit processes associated = with the backing chain of + * @source. It is intended to be called after libvirt restarts and has loa= ded its current state from + * disk and is attempting to re-connect to active domains. + */ +void +qemuNbdkitStorageSourceManageProcess(virStorageSource *source) +{ + virStorageSource *backing; + for (backing =3D source; backing !=3D NULL; backing =3D backing->backi= ngStore) + qemuNbdkitStorageSourceManageProcessOne(backing); +} + =20 bool qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index ccd418b7d3..7e2aeed4eb 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -54,6 +54,14 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *nbdkitCaps, uid_t user, gid_t group); =20 +void +qemuNbdkitReconnectStorageSource(virStorageSource *source, + const char *pidfile, + const char *socketfile); + +void +qemuNbdkitStorageSourceManageProcess(virStorageSource *src); + bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags flag); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 60a46b4b56..83bc8252fc 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8989,6 +8989,12 @@ qemuProcessReconnect(void *opaque) } } =20 + for (i =3D 0; i < obj->def->ndisks; i++) + qemuNbdkitStorageSourceManageProcess(obj->def->disks[i]->src); + + if (obj->def->os.loader && obj->def->os.loader->nvram) + qemuNbdkitStorageSourceManageProcess(obj->def->os.loader->nvram); + /* update domain state XML with possibly updated state in virDomainObj= */ if (virDomainObjSave(obj, driver->xmlopt, cfg->stateDir) < 0) goto error; diff --git a/tests/qemustatusxml2xmldata/modern-in.xml b/tests/qemustatusxm= l2xmldata/modern-in.xml index 95fc569029..e139c8d38c 100644 --- a/tests/qemustatusxml2xmldata/modern-in.xml +++ b/tests/qemustatusxml2xmldata/modern-in.xml @@ -345,6 +345,10 @@ + + /path/to/nbdkit.pid + /path/to/nbdkit.socket + --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891667; cv=none; d=zohomail.com; s=zohoarc; b=UI8CGgPkRocQZaec+gLZ0q5VPzG5ovSclUPzA7aU7MynIyzuMphsAEsIAeus+SJgnXp+0WUIc3wj+3nVYovguaYojVWhF+gg1tcoKPj13MOGhSrLPB3PdLDStUe70qh8sXBv+aJ44yr14n2fvC8SCbiW2BtX6XZUBxANg+7S7s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891667; h=Content-Type:Content-Transfer-Encoding:Cc: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=GVUWIlrNq8dIBiortpOHAOWlBF+0YYq02TIdn7axh4M=; b=ljrTYK0hCQJGBD4ogPnSbpW/4RDanlo9Kk6CWnIYTpfsOwg8QjGvoMXA27YWAPD54+vvtFVPZ21yEmcLgHYE9MaJi0mq+8KnY91d9Vr6UZ89tL506mt3c4WHzJEPQSa+bwW3INTC/UpcR5ZJMnHe1ds/nGdSIK/U/Lcv4QOseyg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891667263364.5984415693181; Thu, 20 Jul 2023 15:21:07 -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-127-Zb-qDXxqONS0wQCiMVCgzA-1; Thu, 20 Jul 2023 18:20:26 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABF55185A7B3; Thu, 20 Jul 2023 22:20:18 +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 913C41454145; Thu, 20 Jul 2023 22:20:18 +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 DD4DD19451D1; Thu, 20 Jul 2023 22:20:15 +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 963541946A76 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5080140C2006; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2683840C207D; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891666; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=GVUWIlrNq8dIBiortpOHAOWlBF+0YYq02TIdn7axh4M=; b=JoaucMRId7IraXHZqBAJnooL/dnEZ1oLpKrK6vbMMoD34RG7mM2XBPF3gFeO9WiJ/X36HQ LyNrinGOC4Cmoj2c8AZXvTSy1EI3YDyKr9JeAjw1kBYQopxuxMYDXVkr1WPVe/cvrPomxz A2S3bKq8b18dQT5oiHIzpubqIES8yq0= X-MC-Unique: Zb-qDXxqONS0wQCiMVCgzA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 19/36] util: secure erase virCommand send buffers Date: Thu, 20 Jul 2023 17:19:46 -0500 Message-ID: <20230720222003.411549-20-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1689891668478100003 Content-Type: text/plain; charset="utf-8"; x-default="true" All users of virCommandSetSendBuffer() are using it to send sensitive data to a child process. So, since these buffers contain sensitive information, clear it with virSecureErase(). Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/util/vircommand.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 49abb53c28..154d194212 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -54,6 +54,7 @@ #include "virpidfile.h" #include "virprocess.h" #include "virbuffer.h" +#include "virsecureerase.h" #include "virthread.h" #include "virstring.h" =20 @@ -1663,6 +1664,7 @@ virCommandFreeSendBuffers(virCommand *cmd) =20 for (i =3D 0; i < virCommandGetNumSendBuffers(cmd); i++) { VIR_FORCE_CLOSE(cmd->sendBuffers[i].fd); + virSecureErase(cmd->sendBuffers[i].buffer, cmd->sendBuffers[i].buf= len); VIR_FREE(cmd->sendBuffers[i].buffer); } VIR_FREE(cmd->sendBuffers); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891643; cv=none; d=zohomail.com; s=zohoarc; b=lqCX2PlKLj5b0wClEMWrdOZGPZ3DXFme8kLyjlbW4+YglJ1mjJrZ3s8l57D91YeUWpL2as5HhysuqLrORL/DjOx4B5GGC6BxlGTsGEai62gHSA/STaK2vVFNp+0wqxxNTN02FXl7G1SMJtN/X2i/GS6E9amjS2MloV5jf75+mXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891643; h=Content-Type:Content-Transfer-Encoding:Cc: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=xIi+6VXaAZobM2oEber+TdTYmNxWZGbz2X7h2OfmHwY=; b=VxqrqnhCKjcvN+cRpoRXBITiA/N1me6NHdwEJyqPIzERr2SXHem/M87UIme++QB/Tr0Mx1lYVHhxGX7eRVDH2FX/OBiH8RH3FFvwWsZ2DQEy8XjEczi1DdMtlq2DYIUpv14siVC02N9tLtQFig6Q1Pd5BjPNGzXDp4a5AFWLpRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891643220811.9331978241945; Thu, 20 Jul 2023 15:20:43 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-93-oeCwOgF5Pl6djJVKhUxgSg-1; Thu, 20 Jul 2023 18:20:32 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0ADE53811805; Thu, 20 Jul 2023 22:20:29 +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 9FDB41454143; Thu, 20 Jul 2023 22:20:28 +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 A7C3719451C4; Thu, 20 Jul 2023 22:20: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 96D3A1946A78 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8E6B840C2008; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6470B40C207D; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891642; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=xIi+6VXaAZobM2oEber+TdTYmNxWZGbz2X7h2OfmHwY=; b=RPk7Oqtl7wu3tWIFa6RTj7cyndfEsIszXDXi3HsrkLiW3hq6BRvZghj1nDALdqSj2zWy56 W3H2zjIUzsfTWD6dZFrTYg3wmmfFZOuRrSEqg9HJALgknnGbyzB9S6wz+v7sSvciR9nmQR G2yv06xCmvNkFkidRsz7TqyZJQ3J6+Q= X-MC-Unique: oeCwOgF5Pl6djJVKhUxgSg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 20/36] qemu: pass sensitive data to nbdkit via pipe Date: Thu, 20 Jul 2023 17:19:47 -0500 Message-ID: <20230720222003.411549-21-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1689891644385100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Rather than passing passwords and cookies (which could contain passwords) to nbdkit via commandline arguments, use the alternate format that nbdkit supports where we can specify a file descriptor which nbdkit will read to get the password or cookies. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 53 +++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 5539b54e8c..b6c808caae 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -754,6 +754,29 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, } =20 =20 +static int +qemuNbdkitCommandPassDataByPipe(virCommand *cmd, + const char *argName, + unsigned char **buf, + size_t buflen) +{ + g_autofree char *fdfmt =3D NULL; + int fd =3D virCommandSetSendBuffer(cmd, buf, buflen); + + if (fd < 0) + return -1; + + /* some nbdkit arguments accept a variation where nbdkit will read the= data + * from a file descriptor, e.g. password=3D-FD */ + fdfmt =3D g_strdup_printf("-%i", fd); + virCommandAddArgPair(cmd, argName, fdfmt); + + virCommandDoAsyncIO(cmd); + + return 0; +} + + static int qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *proc, virCommand *cmd) @@ -776,7 +799,6 @@ qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *pr= oc, g_autoptr(virConnect) conn =3D virGetConnectSecret(); g_autofree uint8_t *secret =3D NULL; size_t secretlen =3D 0; - g_autofree char *password =3D NULL; int secrettype; virStorageAuthDef *authdef =3D proc->source->auth; =20 @@ -800,26 +822,19 @@ qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *= proc, return -1; } =20 - /* ensure that the secret is a NULL-terminated string */ - password =3D g_strndup((char*)secret, secretlen); - virSecureErase(secret, secretlen); - - /* for now, just report an error rather than passing the password = in - * cleartext on the commandline */ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Password not yet supported for nbdkit sources")); - - virSecureEraseString(password); - - return -1; + if (qemuNbdkitCommandPassDataByPipe(cmd, "password", + &secret, secretlen) < 0) + return -1; } =20 - if (proc->source->ncookies > 0) { - /* for now, just report an error rather than passing cookies in - * cleartext on the commandline */ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cookies not yet supported for nbdkit sources")); - return -1; + /* Create a pipe to send the cookies to the nbdkit process. */ + if (proc->source->ncookies) { + g_autofree char *cookies =3D qemuBlockStorageSourceGetCookieString= (proc->source); + + if (qemuNbdkitCommandPassDataByPipe(cmd, "cookie", + (unsigned char**)&cookies, + strlen(cookies)) < 0) + return -1; } =20 if (proc->source->sslverify =3D=3D VIR_TRISTATE_BOOL_NO) { --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891665; cv=none; d=zohomail.com; s=zohoarc; b=mHCFRSzzUZNfAV7cEI3et7Y3HGMiEVdjp7c+jbEUZdtfB7We5PpM6E2rWgtP8MQJYHygzRjhMVphFE98BOOpvzgwkNDMAT9Tk7ey3WxUFGH2kN4YNOmzBtD7TBMO9qM1g1M++3L2xyRcB1xXdc5XylAdba/iwOQBLwDyZNf8Qvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891665; h=Content-Type:Content-Transfer-Encoding:Cc: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=HImsWe/MPshtHmTAyXb6zgYE8TyS41BjBd7mNUofHmk=; b=ZHagTpcQBrAtlza8Vfwd9eu+C0iyCFr0b2sS5Dhin9EudnhBTEqkijM3D0eYnMJWaMiFoybDobNT571tkOJMsMU+SpDDRYiVryuivg0pEMuq9i/J/G+8MquzYQOEVe6bfrUui6+YSP4CLsaLbFxk091CvwowgVBf4sMKX5jm+kY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891665359937.8050892974514; Thu, 20 Jul 2023 15:21:05 -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-344-rIe8gBsKNxqfG1fXxVxtcw-1; Thu, 20 Jul 2023 18:20:46 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A85088D4E6; Thu, 20 Jul 2023 22:20: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 6D7DE145414A; Thu, 20 Jul 2023 22:20: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 8593E194973B; Thu, 20 Jul 2023 22:20:20 +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 971171946A7A for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D752C40C20F0; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A319640C207D; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891663; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=HImsWe/MPshtHmTAyXb6zgYE8TyS41BjBd7mNUofHmk=; b=VR8rIyP+9jheleQM+ckbBxJyOJWoZJ+Qsrd3ECVlQ5ryYUzn3g32IcDnYxGCX9YqJepaeP cEADRKhMKGKGTKl7vF5vE7asJ9+hs4Bt0cu+3R+grY2RxVjNX5hUsH8bedZwohlzFaAXgN P69cbq8a/VFJ3XrI+NcoGEPvS6Glxp0= X-MC-Unique: rIe8gBsKNxqfG1fXxVxtcw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 21/36] qemu: use nbdkit to serve network disks if available Date: Thu, 20 Jul 2023 17:19:48 -0500 Message-ID: <20230720222003.411549-22-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1689891667587100001 Content-Type: text/plain; charset="utf-8"; x-default="true" For virStorageSource objects that contain an nbdkitProcess, start that nbdkit process to serve that network drive and then pass the nbdkit socket to qemu rather than sending the network url to qemu directly. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_block.c | 162 +++++++++++------- src/qemu/qemu_domain.c | 13 +- src/qemu/qemu_extdevice.c | 62 +++++++ src/qemu/qemu_hotplug.c | 7 + src/qemu/qemu_nbdkit.c | 42 +++++ src/qemu/qemu_nbdkit.h | 13 ++ ...sk-cdrom-network-nbdkit.x86_64-latest.args | 42 +++++ .../disk-cdrom-network-nbdkit.xml | 1 + ...isk-network-http-nbdkit.x86_64-latest.args | 44 +++++ .../disk-network-http-nbdkit.xml | 1 + ...rce-curl-nbdkit-backing.x86_64-latest.args | 37 ++++ ...isk-network-source-curl-nbdkit-backing.xml | 45 +++++ ...work-source-curl-nbdkit.x86_64-latest.args | 49 ++++++ .../disk-network-source-curl-nbdkit.xml | 1 + ...isk-network-source-curl.x86_64-latest.args | 52 ++++++ .../disk-network-source-curl.xml | 71 ++++++++ ...disk-network-ssh-nbdkit.x86_64-latest.args | 35 ++++ .../disk-network-ssh-nbdkit.xml | 1 + tests/qemuxml2argvtest.c | 6 + 19 files changed, 618 insertions(+), 66 deletions(-) create mode 100644 tests/qemuxml2argvdata/disk-cdrom-network-nbdkit.x86_64= -latest.args create mode 120000 tests/qemuxml2argvdata/disk-cdrom-network-nbdkit.xml create mode 100644 tests/qemuxml2argvdata/disk-network-http-nbdkit.x86_64-= latest.args create mode 120000 tests/qemuxml2argvdata/disk-network-http-nbdkit.xml create mode 100644 tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-= backing.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-= backing.xml create mode 100644 tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.= x86_64-latest.args create mode 120000 tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.= xml create mode 100644 tests/qemuxml2argvdata/disk-network-source-curl.x86_64-= latest.args create mode 100644 tests/qemuxml2argvdata/disk-network-source-curl.xml create mode 100644 tests/qemuxml2argvdata/disk-network-ssh-nbdkit.x86_64-l= atest.args create mode 120000 tests/qemuxml2argvdata/disk-network-ssh-nbdkit.xml diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index dcdf883926..1a2dc8ffb4 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -438,6 +438,32 @@ qemuBlockStorageSourceGetCURLProps(virStorageSource *s= rc, } =20 =20 +static virJSONValue * +qemuBlockStorageSourceGetNbdkitProps(virStorageSource *src) +{ + qemuDomainStorageSourcePrivate *srcPriv =3D QEMU_DOMAIN_STORAGE_SOURCE= _PRIVATE(src); + virJSONValue *ret =3D NULL; + g_autoptr(virJSONValue) serverprops =3D NULL; + virStorageNetHostDef host =3D { .transport =3D VIR_STORAGE_NET_HOST_TR= ANS_UNIX }; + + /* srcPriv->nbdkitProcess will already be initialized if we can use nb= dkit + * to proxy this storage source */ + if (!(srcPriv && srcPriv->nbdkitProcess)) + return NULL; + + host.socket =3D srcPriv->nbdkitProcess->socketfile; + serverprops =3D qemuBlockStorageSourceBuildJSONSocketAddress(&host); + + if (!serverprops) + return NULL; + + if (virJSONValueObjectAdd(&ret, "a:server", &serverprops, NULL) < 0) + return NULL; + + return ret; +} + + static virJSONValue * qemuBlockStorageSourceGetISCSIProps(virStorageSource *src, bool onlytarget) @@ -890,69 +916,75 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourc= e *src, return NULL; =20 case VIR_STORAGE_TYPE_NETWORK: - switch ((virStorageNetProtocol) src->protocol) { - case VIR_STORAGE_NET_PROTOCOL_GLUSTER: - driver =3D "gluster"; - if (!(fileprops =3D qemuBlockStorageSourceGetGlusterProps(src,= onlytarget))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_VXHS: - driver =3D "vxhs"; - if (!(fileprops =3D qemuBlockStorageSourceGetVxHSProps(src, on= lytarget))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_HTTP: - case VIR_STORAGE_NET_PROTOCOL_HTTPS: - case VIR_STORAGE_NET_PROTOCOL_FTP: - case VIR_STORAGE_NET_PROTOCOL_FTPS: - case VIR_STORAGE_NET_PROTOCOL_TFTP: - driver =3D virStorageNetProtocolTypeToString(src->protocol); - if (!(fileprops =3D qemuBlockStorageSourceGetCURLProps(src, on= lytarget))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_ISCSI: - driver =3D "iscsi"; - if (!(fileprops =3D qemuBlockStorageSourceGetISCSIProps(src, o= nlytarget))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_NBD: + /* prefer using nbdkit for sources that are supported */ + if ((fileprops =3D qemuBlockStorageSourceGetNbdkitProps(src))) { driver =3D "nbd"; - if (!(fileprops =3D qemuBlockStorageSourceGetNBDProps(src, onl= ytarget))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_RBD: - driver =3D "rbd"; - if (!(fileprops =3D qemuBlockStorageSourceGetRBDProps(src, onl= ytarget))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: - driver =3D "sheepdog"; - if (!(fileprops =3D qemuBlockStorageSourceGetSheepdogProps(src= ))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_SSH: - driver =3D "ssh"; - if (!(fileprops =3D qemuBlockStorageSourceGetSshProps(src))) - return NULL; break; - - case VIR_STORAGE_NET_PROTOCOL_NFS: - driver =3D "nfs"; - if (!(fileprops =3D qemuBlockStorageSourceGetNFSProps(src))) - return NULL; - break; - - case VIR_STORAGE_NET_PROTOCOL_NONE: - case VIR_STORAGE_NET_PROTOCOL_LAST: - virReportEnumRangeError(virStorageNetProtocol, src->protocol); - return NULL; + } else { + switch ((virStorageNetProtocol) src->protocol) { + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + driver =3D "gluster"; + if (!(fileprops =3D qemuBlockStorageSourceGetGlusterPr= ops(src, onlytarget))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_VXHS: + driver =3D "vxhs"; + if (!(fileprops =3D qemuBlockStorageSourceGetVxHSProps= (src, onlytarget))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + driver =3D virStorageNetProtocolTypeToString(src->prot= ocol); + if (!(fileprops =3D qemuBlockStorageSourceGetCURLProps= (src, onlytarget))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + driver =3D "iscsi"; + if (!(fileprops =3D qemuBlockStorageSourceGetISCSIProp= s(src, onlytarget))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_NBD: + driver =3D "nbd"; + if (!(fileprops =3D qemuBlockStorageSourceGetNBDProps(= src, onlytarget))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_RBD: + driver =3D "rbd"; + if (!(fileprops =3D qemuBlockStorageSourceGetRBDProps(= src, onlytarget))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + driver =3D "sheepdog"; + if (!(fileprops =3D qemuBlockStorageSourceGetSheepdogP= rops(src))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_SSH: + driver =3D "ssh"; + if (!(fileprops =3D qemuBlockStorageSourceGetSshProps(= src))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_NFS: + driver =3D "nfs"; + if (!(fileprops =3D qemuBlockStorageSourceGetNFSProps(= src))) + return NULL; + break; + + case VIR_STORAGE_NET_PROTOCOL_NONE: + case VIR_STORAGE_NET_PROTOCOL_LAST: + virReportEnumRangeError(virStorageNetProtocol, src->pr= otocol); + return NULL; + } } break; } @@ -2261,6 +2293,7 @@ qemuBlockStorageSourceCreateGetStorageProps(virStorag= eSource *src, g_autoptr(virJSONValue) location =3D NULL; const char *driver =3D NULL; const char *filename =3D NULL; + qemuDomainStorageSourcePrivate *srcPriv =3D QEMU_DOMAIN_STORAGE_SOURCE= _PRIVATE(src); =20 switch (actualType) { case VIR_STORAGE_TYPE_FILE: @@ -2289,6 +2322,13 @@ qemuBlockStorageSourceCreateGetStorageProps(virStora= geSource *src, break; =20 case VIR_STORAGE_NET_PROTOCOL_SSH: + if (srcPriv->nbdkitProcess) { + /* disk creation not yet supported with nbdkit, and even i= f it + * was supported, it would not be done with blockdev-create + * props */ + return 0; + } + driver =3D "ssh"; if (!(location =3D qemuBlockStorageSourceGetSshProps(src))) return -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d2db388622..61fbc14c67 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11112,9 +11112,14 @@ qemuDomainPrepareStorageSourceBlockdevNodename(vir= DomainDiskDef *disk, if (qemuDomainSecretStorageSourcePrepareEncryption(priv, src, src->nodeformat) < = 0) return -1; - if (qemuDomainSecretStorageSourcePrepareAuth(priv, src, - src->nodestorage) < 0) - return -1; + + if (!qemuDomainPrepareStorageSourceNbdkit(src, cfg, src->nodestorage, = priv)) { + /* If we're using nbdkit to serve the storage source, we don't pass + * authentication secrets to qemu, but will pass them to nbdkit in= stead */ + if (qemuDomainSecretStorageSourcePrepareAuth(priv, src, + src->nodestorage) < 0) + return -1; + } =20 if (qemuDomainPrepareStorageSourcePR(src, priv, src->nodestorage) < 0) return -1; @@ -11129,8 +11134,6 @@ qemuDomainPrepareStorageSourceBlockdevNodename(virD= omainDiskDef *disk, if (qemuDomainPrepareStorageSourceFDs(src, priv) < 0) return -1; =20 - qemuDomainPrepareStorageSourceNbdkit(src, cfg, src->nodestorage, priv); - return 0; } =20 diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index bf59967eb7..42ecdf13d5 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -232,6 +232,17 @@ qemuExtDevicesStart(virQEMUDriver *driver, return -1; } =20 + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + if (qemuNbdkitStartStorageSource(driver, vm, disk->src) < 0) + return -1; + } + + if (def->os.loader && def->os.loader->nvram) { + if (qemuNbdkitStartStorageSource(driver, vm, def->os.loader->nvram= ) < 0) + return -1; + } + return 0; } =20 @@ -283,6 +294,14 @@ qemuExtDevicesStop(virQEMUDriver *driver, fs->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) qemuVirtioFSStop(driver, vm, fs); } + + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + qemuNbdkitStopStorageSource(disk->src); + } + + if (def->os.loader && def->os.loader->nvram) + qemuNbdkitStopStorageSource(def->os.loader->nvram); } =20 =20 @@ -319,10 +338,42 @@ qemuExtDevicesHasDevice(virDomainDef *def) return true; } =20 + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + virStorageSource *backing; + + for (backing =3D disk->src; backing; backing =3D backing->backingS= tore) { + qemuDomainStorageSourcePrivate* priv =3D + QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(backing); + if (priv && priv->nbdkitProcess) + return true; + } + } + + return false; } =20 =20 +/* recursively setup nbdkit cgroups for backing chain of src */ +static int +qemuExtDevicesSetupCgroupNbdkit(virStorageSource *src, + virCgroup *cgroup) +{ + virStorageSource *backing; + + for (backing =3D src; backing; backing =3D backing->backingStore) { + qemuDomainStorageSourcePrivate *priv =3D QEMU_DOMAIN_STORAGE_SOURC= E_PRIVATE(src); + + if (priv && priv->nbdkitProcess && + qemuNbdkitProcessSetupCgroup(priv->nbdkitProcess, cgroup) < 0) + return -1; + } + + return 0; +} + + int qemuExtDevicesSetupCgroup(virQEMUDriver *driver, virDomainObj *vm, @@ -365,6 +416,17 @@ qemuExtDevicesSetupCgroup(virQEMUDriver *driver, return -1; } =20 + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + if (qemuExtDevicesSetupCgroupNbdkit(disk->src, cgroup) < 0) + return -1; + } + + if (def->os.loader && def->os.loader->nvram) { + if (qemuExtDevicesSetupCgroupNbdkit(def->os.loader->nvram, cgroup)= < 0) + return -1; + } + for (i =3D 0; i < def->nfss; i++) { virDomainFSDef *fs =3D def->fss[i]; =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 2e3c99760d..e1725ab627 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1010,6 +1010,9 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver = *driver, if (qemuHotplugAttachManagedPR(vm, disk->src, VIR_ASYNC_JOB_NONE) < 0) goto cleanup; =20 + if (qemuNbdkitStartStorageSource(driver, vm, disk->src) < 0) + goto cleanup; + ret =3D qemuDomainAttachDiskGeneric(vm, disk, VIR_ASYNC_JOB_NONE); =20 virDomainAuditDisk(vm, NULL, disk->src, "attach", ret =3D=3D 0); @@ -1032,6 +1035,8 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver = *driver, =20 if (virStorageSourceChainHasManagedPR(disk->src)) ignore_value(qemuHotplugRemoveManagedPR(vm, VIR_ASYNC_JOB_NONE= )); + + qemuNbdkitStopStorageSource(disk->src); } qemuDomainSecretDiskDestroy(disk); qemuDomainCleanupStorageSourceFD(disk->src); @@ -4503,6 +4508,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriver *driver, qemuHotplugRemoveManagedPR(vm, VIR_ASYNC_JOB_NONE) < 0) goto cleanup; =20 + qemuNbdkitStopStorageSource(disk->src); + if (disk->transient) { VIR_DEBUG("Removing transient overlay '%s' of disk '%s'", disk->src->path, disk->dst); diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index b6c808caae..cb162d2ffc 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -754,6 +754,40 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, } =20 =20 +int +qemuNbdkitStartStorageSource(virQEMUDriver *driver, + virDomainObj *vm, + virStorageSource *src) +{ + virStorageSource *backing; + + for (backing =3D src; backing !=3D NULL; backing =3D backing->backingS= tore) { + qemuDomainStorageSourcePrivate *priv =3D QEMU_DOMAIN_STORAGE_SOURC= E_PRIVATE(src); + + if (priv && priv->nbdkitProcess && + qemuNbdkitProcessStart(priv->nbdkitProcess, vm, driver) < 0) + return -1; + } + + return 0; +} + + +void +qemuNbdkitStopStorageSource(virStorageSource *src) +{ + virStorageSource *backing; + + for (backing =3D src; backing !=3D NULL; backing =3D backing->backingS= tore) { + qemuDomainStorageSourcePrivate *priv =3D QEMU_DOMAIN_STORAGE_SOURC= E_PRIVATE(src); + + if (priv && priv->nbdkitProcess && + qemuNbdkitProcessStop(priv->nbdkitProcess) < 0) + VIR_WARN("Unable to stop nbdkit for storage source '%s'", src-= >nodestorage); + } +} + + static int qemuNbdkitCommandPassDataByPipe(virCommand *cmd, const char *argName, @@ -941,6 +975,14 @@ qemuNbdkitProcessFree(qemuNbdkitProcess *proc) } =20 =20 +int +qemuNbdkitProcessSetupCgroup(qemuNbdkitProcess *proc, + virCgroup *cgroup) +{ + return virCgroupAddProcess(cgroup, proc->pid); +} + + int qemuNbdkitProcessStart(qemuNbdkitProcess *proc, virDomainObj *vm, diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 7e2aeed4eb..36a2219d82 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -21,6 +21,7 @@ =20 #include "internal.h" #include "storage_source_conf.h" +#include "vircgroup.h" #include "virenum.h" #include "virfilecache.h" =20 @@ -59,6 +60,14 @@ qemuNbdkitReconnectStorageSource(virStorageSource *sourc= e, const char *pidfile, const char *socketfile); =20 +int +qemuNbdkitStartStorageSource(virQEMUDriver *driver, + virDomainObj *vm, + virStorageSource *src); + +void +qemuNbdkitStopStorageSource(virStorageSource *src); + void qemuNbdkitStorageSourceManageProcess(virStorageSource *src); =20 @@ -95,4 +104,8 @@ qemuNbdkitProcessStop(qemuNbdkitProcess *proc); void qemuNbdkitProcessFree(qemuNbdkitProcess *proc); =20 +int +qemuNbdkitProcessSetupCgroup(qemuNbdkitProcess *proc, + virCgroup *cgroup); + G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuNbdkitProcess, qemuNbdkitProcessFree); diff --git a/tests/qemuxml2argvdata/disk-cdrom-network-nbdkit.x86_64-latest= .args b/tests/qemuxml2argvdata/disk-cdrom-network-nbdkit.x86_64-latest.args new file mode 100644 index 0000000000..637f47bf2b --- /dev/null +++ b/tests/qemuxml2argvdata/disk-cdrom-network-nbdkit.x86_64-latest.args @@ -0,0 +1,42 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Don \ +-accel kvm \ +-cpu qemu64 \ +-m size=3D1048576k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":1073741824}= ' \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-3-storage.socket"},"node-name":"= libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-3-format","read-only":true,"driver":"raw"= ,"file":"libvirt-3-storage"}' \ +-device '{"driver":"ide-cd","bus":"ide.0","unit":0,"drive":"libvirt-3-form= at","id":"ide0-0-0","bootindex":1}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"= libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":true,"driver":"raw"= ,"file":"libvirt-2-storage"}' \ +-device '{"driver":"ide-cd","bus":"ide.0","unit":1,"drive":"libvirt-2-form= at","id":"ide0-0-1"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"= libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":true,"driver":"raw"= ,"file":"libvirt-1-storage"}' \ +-device '{"driver":"ide-cd","bus":"ide.1","unit":0,"drive":"libvirt-1-form= at","id":"ide0-1-0"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x2"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-cdrom-network-nbdkit.xml b/tests/q= emuxml2argvdata/disk-cdrom-network-nbdkit.xml new file mode 120000 index 0000000000..55f677546f --- /dev/null +++ b/tests/qemuxml2argvdata/disk-cdrom-network-nbdkit.xml @@ -0,0 +1 @@ +disk-cdrom-network.xml \ No newline at end of file diff --git a/tests/qemuxml2argvdata/disk-network-http-nbdkit.x86_64-latest.= args b/tests/qemuxml2argvdata/disk-network-http-nbdkit.x86_64-latest.args new file mode 100644 index 0000000000..37e46dfc20 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-http-nbdkit.x86_64-latest.args @@ -0,0 +1,44 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel kvm \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-4-storage.socket"},"node-name":"= libvirt-4-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"raw= ","file":"libvirt-4-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-4-format","id":"virtio-disk0","bootindex":1}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-3-storage.socket"},"node-name":"= libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"raw= ","file":"libvirt-3-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x3","drive":"li= bvirt-3-format","id":"virtio-disk1"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"= libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw= ","file":"libvirt-2-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"li= bvirt-2-format","id":"virtio-disk2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"= libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ","file":"libvirt-1-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x5","drive":"li= bvirt-1-format","id":"virtio-disk3"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-network-http-nbdkit.xml b/tests/qe= muxml2argvdata/disk-network-http-nbdkit.xml new file mode 120000 index 0000000000..6a05204e8a --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-http-nbdkit.xml @@ -0,0 +1 @@ +disk-network-http.xml \ No newline at end of file diff --git a/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-backing= .x86_64-latest.args b/tests/qemuxml2argvdata/disk-network-source-curl-nbdki= t-backing.x86_64-latest.args new file mode 100644 index 0000000000..25ec2513c2 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-backing.x86_64= -latest.args @@ -0,0 +1,37 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel tcg \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"= libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":true,"driver":"qcow= 2","file":"libvirt-2-storage"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"= libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":true,"driver":"qcow= 2","file":"libvirt-1-storage","backing":"libvirt-2-format"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-1-format","id":"virtio-disk0","bootindex":1}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-backing= .xml b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-backing.xml new file mode 100644 index 0000000000..37a30fcbd6 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-backing.xml @@ -0,0 +1,45 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + + cookievalue1 + cookievalue2 + + + + + + + + cookievalue3 + cookievalue4 + + + + + + + + + + + + + diff --git a/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.x86_64-= latest.args b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.x86_64= -latest.args new file mode 100644 index 0000000000..c88661f369 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.x86_64-latest.= args @@ -0,0 +1,49 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel tcg \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-device '{"driver":"ahci","id":"sata0","bus":"pci.0","addr":"0x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-5-storage.socket"},"node-name":"= libvirt-5-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-5-format","read-only":true,"driver":"raw"= ,"file":"libvirt-5-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x3","drive":"li= bvirt-5-format","id":"virtio-disk0","bootindex":1}' \ +-object '{"qom-type":"secret","id":"libvirt-4-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-4-storage.socket"},"node-name":"= libvirt-4-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"luk= s","key-secret":"libvirt-4-format-encryption-secret0","file":"libvirt-4-sto= rage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"li= bvirt-4-format","id":"virtio-disk4"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-3-storage.socket"},"node-name":"= libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-3-format","read-only":true,"driver":"raw"= ,"file":"libvirt-3-storage"}' \ +-device '{"driver":"ide-cd","bus":"sata0.1","drive":"libvirt-3-format","id= ":"sata0-0-1"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"= libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":true,"driver":"raw"= ,"file":"libvirt-2-storage"}' \ +-device '{"driver":"ide-cd","bus":"sata0.2","drive":"libvirt-2-format","id= ":"sata0-0-2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"= libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":true,"driver":"raw"= ,"file":"libvirt-1-storage"}' \ +-device '{"driver":"ide-cd","bus":"sata0.3","drive":"libvirt-1-format","id= ":"sata0-0-3"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.xml b/t= ests/qemuxml2argvdata/disk-network-source-curl-nbdkit.xml new file mode 120000 index 0000000000..4a1e40bd70 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.xml @@ -0,0 +1 @@ +disk-network-source-curl.xml \ No newline at end of file diff --git a/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.= args b/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args new file mode 100644 index 0000000000..cb0e5a92ea --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args @@ -0,0 +1,52 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel tcg \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-device '{"driver":"ahci","id":"sata0","bus":"pci.0","addr":"0x2"}' \ +-object '{"qom-type":"secret","id":"libvirt-5-storage-httpcookie-secret0",= "data":"BUU0KmnWfonHdjzhYhwVQZ5iTI1KweTJ22q8XWUVoBCVu1z70reDuczPBIabZtC3","= keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}'= \ +-blockdev '{"driver":"https","url":"https://https.example.org:8443/path/to= /disk1.iso","cookie-secret":"libvirt-5-storage-httpcookie-secret0","node-na= me":"libvirt-5-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-5-format","read-only":true,"driver":"raw"= ,"file":"libvirt-5-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x3","drive":"li= bvirt-5-format","id":"virtio-disk0","bootindex":1}' \ +-object '{"qom-type":"secret","id":"libvirt-4-storage-httpcookie-secret0",= "data":"BUU0KmnWfonHdjzhYhwVQZ5iTI1KweTJ22q8XWUVoBCVu1z70reDuczPBIabZtC3","= keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}'= \ +-object '{"qom-type":"secret","id":"libvirt-4-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ +-blockdev '{"driver":"https","url":"https://https.example.org:8443/path/to= /disk5.iso?foo=3Dbar","sslverify":false,"cookie-secret":"libvirt-4-storage-= httpcookie-secret0","node-name":"libvirt-4-storage","auto-read-only":true,"= discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"luk= s","key-secret":"libvirt-4-format-encryption-secret0","file":"libvirt-4-sto= rage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"li= bvirt-4-format","id":"virtio-disk4"}' \ +-object '{"qom-type":"secret","id":"libvirt-3-storage-httpcookie-secret0",= "data":"BUU0KmnWfonHdjzhYhwVQZ5iTI1KweTJ22q8XWUVoBBv7TuTgTkyAyOPpC2P5qLbOIy= pLoHpppjz+u5O+X8oT+jA1m7q/OJQ8dk2EFD5c0A=3D","keyid":"masterKey0","iv":"AAE= CAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ +-blockdev '{"driver":"http","url":"http://http.example.org:8080/path/to/di= sk2.iso","cookie-secret":"libvirt-3-storage-httpcookie-secret0","node-name"= :"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-3-format","read-only":true,"driver":"raw"= ,"file":"libvirt-3-storage"}' \ +-device '{"driver":"ide-cd","bus":"sata0.1","drive":"libvirt-3-format","id= ":"sata0-0-1"}' \ +-blockdev '{"driver":"ftp","url":"ftp://ftp.example.org:20/path/to/disk3.i= so","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"= }' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":true,"driver":"raw"= ,"file":"libvirt-2-storage"}' \ +-device '{"driver":"ide-cd","bus":"sata0.2","drive":"libvirt-2-format","id= ":"sata0-0-2"}' \ +-blockdev '{"driver":"ftps","url":"ftps://ftps.example.org:22/path/to/disk= 4.iso","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unm= ap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":true,"driver":"raw"= ,"file":"libvirt-1-storage"}' \ +-device '{"driver":"ide-cd","bus":"sata0.3","drive":"libvirt-1-format","id= ":"sata0-0-3"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-network-source-curl.xml b/tests/qe= muxml2argvdata/disk-network-source-curl.xml new file mode 100644 index 0000000000..1e50314abe --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl.xml @@ -0,0 +1,71 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + cookievalue1 + cookievalue2 + + + + + + + + + + cookievalue1 + cookievalue2 + cookievalue3 + + + + + + + + + + + + + + + + + + + + + + cookievalue1 + cookievalue2 + + + + + + + + + + + + + + diff --git a/tests/qemuxml2argvdata/disk-network-ssh-nbdkit.x86_64-latest.a= rgs b/tests/qemuxml2argvdata/disk-network-ssh-nbdkit.x86_64-latest.args new file mode 100644 index 0000000000..fd24e51570 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh-nbdkit.x86_64-latest.args @@ -0,0 +1,35 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel kvm \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"= libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ","file":"libvirt-1-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-1-format","id":"virtio-disk0","bootindex":1}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-network-ssh-nbdkit.xml b/tests/qem= uxml2argvdata/disk-network-ssh-nbdkit.xml new file mode 120000 index 0000000000..b0589bdfb5 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh-nbdkit.xml @@ -0,0 +1 @@ +disk-network-ssh.xml \ No newline at end of file diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index d3dafb5bb5..a516fdfa7e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1173,6 +1173,7 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-cdrom-empty-network-invalid"); DO_TEST_CAPS_LATEST("disk-cdrom-bus-other"); DO_TEST_CAPS_LATEST("disk-cdrom-network"); + DO_TEST_CAPS_LATEST_NBDKIT("disk-cdrom-network-nbdkit", QEMU_NBDKIT_CA= PS_PLUGIN_CURL); DO_TEST_CAPS_LATEST("disk-cdrom-tray"); DO_TEST_CAPS_LATEST("disk-floppy"); DO_TEST_CAPS_LATEST("disk-floppy-q35"); @@ -1217,6 +1218,9 @@ mymain(void) /* qemu-6.0 is the last qemu version supporting sheepdog */ DO_TEST_CAPS_VER("disk-network-sheepdog", "6.0.0"); DO_TEST_CAPS_LATEST("disk-network-source-auth"); + DO_TEST_CAPS_LATEST("disk-network-source-curl"); + DO_TEST_CAPS_LATEST_NBDKIT("disk-network-source-curl-nbdkit", QEMU_NBD= KIT_CAPS_PLUGIN_CURL); + DO_TEST_CAPS_LATEST_NBDKIT("disk-network-source-curl-nbdkit-backing", = QEMU_NBDKIT_CAPS_PLUGIN_CURL); DO_TEST_CAPS_LATEST("disk-network-nfs"); driver.config->vxhsTLS =3D 1; driver.config->nbdTLSx509secretUUID =3D g_strdup("6fd3f62d-9fe7-4a4e-a= 869-7acd6376d8ea"); @@ -1227,10 +1231,12 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-network-tlsx509-nbd-hostname"); DO_TEST_CAPS_VER("disk-network-tlsx509-vxhs", "5.0.0"); DO_TEST_CAPS_LATEST("disk-network-http"); + DO_TEST_CAPS_LATEST_NBDKIT("disk-network-http-nbdkit", QEMU_NBDKIT_CAP= S_PLUGIN_CURL); VIR_FREE(driver.config->nbdTLSx509secretUUID); VIR_FREE(driver.config->vxhsTLSx509secretUUID); driver.config->vxhsTLS =3D 0; DO_TEST_CAPS_LATEST("disk-network-ssh"); + DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-nbdkit", QEMU_NBDKIT_CAPS= _PLUGIN_SSH); DO_TEST_CAPS_LATEST("disk-no-boot"); DO_TEST_CAPS_LATEST("disk-nvme"); DO_TEST_CAPS_VER("disk-vhostuser-numa", "4.2.0"); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891653; cv=none; d=zohomail.com; s=zohoarc; b=MCe6dU52wzzVIO+5N/XCkEnvfSll4C2IhzeDPRaOawt5YOI0ZwplJh1XEDKt+0r5//QoXbSbazsvP1bpkXYvAJUB4GY/p9PZzeoQ7gZkzJ9JlPnbSw8BG4/1m+iCl0SBExFS80vv968WWei/ncmVdMzeCpUUw2B38d9bZlnfLvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891653; h=Content-Type:Content-Transfer-Encoding:Cc: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=G3cNDqnkeCuuzmcdqJZ6GtToUizXAhovhdXVYrel7Nw=; b=i5CO21uN3njluV5Sodxp3hTEryuLB9cH8oClpsjvSslVR10EBuSI8XNEdIdG5amQY5FFeQmFjklC7SNUBoepqyurvnmOu+jx0W+b2UcsSYN7wyYZDuavXX2sTHtcmWLCaWa5gremdLPaTX4IYWxG5b2NBJ4bXuDKBsdjWoKWcak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891653599521.9828472504263; Thu, 20 Jul 2023 15:20:53 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-533-OZMHiM2RPMKx8stUnuL1cg-1; Thu, 20 Jul 2023 18:20:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E90F28040CD; Thu, 20 Jul 2023 22:20:34 +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 644DE207B33C; Thu, 20 Jul 2023 22:20:34 +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 04C5B19543B0; Thu, 20 Jul 2023 22:20:21 +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 A3DC119452CB for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2241440C20F1; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9F2940C207D; Thu, 20 Jul 2023 22:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891652; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=G3cNDqnkeCuuzmcdqJZ6GtToUizXAhovhdXVYrel7Nw=; b=E3J44aMFbByhiRb5yG1hkBgZPJ7awcc2cctVutuYjmTHBvFAyttlLaue7xzmwQl3xp9Iwh jnE0e9/c6hu8cfXr5BgXPxMM6XkInMip/S3sLRKs4JnL3a8RwV5Qstl5FUTVFHRsANLYSM KeGtZQ3K8bhvQldUEqGn1qKMx/uHRS0= X-MC-Unique: OZMHiM2RPMKx8stUnuL1cg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 22/36] util: make virCommandSetSendBuffer testable Date: Thu, 20 Jul 2023 17:19:49 -0500 Message-ID: <20230720222003.411549-23-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891654245100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Add a private function to peek at the list of send buffers in virCommand so that it is testable Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/vircommand.c | 17 +++++++++-------- src/util/vircommand.h | 8 ++++++++ src/util/vircommandpriv.h | 4 ++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3071dec13a..a89f6047a9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2108,6 +2108,7 @@ virCommandNewArgs; virCommandNewVAList; virCommandNonblockingFDs; virCommandPassFD; +virCommandPeekSendBuffers; virCommandRawStatus; virCommandRequireHandshake; virCommandRun; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 154d194212..0e78919bab 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -78,14 +78,6 @@ struct _virCommandFD { unsigned int flags; }; =20 -typedef struct _virCommandSendBuffer virCommandSendBuffer; -struct _virCommandSendBuffer { - int fd; - unsigned char *buffer; - size_t buflen; - off_t offset; -}; - struct _virCommand { int has_error; /* 0 on success, -1 on error */ =20 @@ -3481,3 +3473,12 @@ virCommandSetRunAmong(virCommand *cmd, =20 cmd->schedCore =3D pid; } + +void +virCommandPeekSendBuffers(virCommand *cmd, + virCommandSendBuffer **buffers, + int *nbuffers) +{ + *buffers =3D cmd->sendBuffers; + *nbuffers =3D cmd->numSendBuffers; +} diff --git a/src/util/vircommand.h b/src/util/vircommand.h index d51449ac90..9bcdce35b9 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -24,6 +24,14 @@ #include "internal.h" #include "virbuffer.h" =20 +typedef struct _virCommandSendBuffer virCommandSendBuffer; +struct _virCommandSendBuffer { + int fd; + unsigned char *buffer; + size_t buflen; + off_t offset; +}; + typedef struct _virCommand virCommand; =20 /* This will execute in the context of the first child diff --git a/src/util/vircommandpriv.h b/src/util/vircommandpriv.h index ff17fa5ded..d579810bb5 100644 --- a/src/util/vircommandpriv.h +++ b/src/util/vircommandpriv.h @@ -47,3 +47,7 @@ void virCommandSetDryRun(virCommandDryRunToken *tok, bool bufCommandStripPath, virCommandDryRunCallback cb, void *opaque); + +void virCommandPeekSendBuffers(virCommand *cmd, + virCommandSendBuffer **buffers, + int *nbuffers); --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891628; cv=none; d=zohomail.com; s=zohoarc; b=GUFCie2oFnczc1hRlN7fAPyXigUaC5nsB77DfJ3T8pI1OYHef7/P5DJHnH0syQjVUWPqAwNW+cPyHTZllze7ncCkHL/+NEHAanVTNfsyPGJaguBraz7Eyr4fG+DvaolqJaGQiKYV6uHxMuWYw0mx7W0/hH66IvHbV3TR6MOm+9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891628; h=Content-Type:Content-Transfer-Encoding:Cc: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=pUIGdtbJoVQq+kSAFTNDAeoaNRtmP9WC3KB0KNxbmK0=; b=kdwO2qDTNAwZf8J0atk2na4B65jIXDgFEcg84zwLY+MorAODS1EI4IimA7vFy6PacxrRRdWQR6UQyyVCQ/4+Kb21b0meATukuk61yorMk1XXhG08IFRhKFw4ZQg/W+kxMcgu1hbrytKyfXX+ZH/7awGSWR4DNsNUkkTSyj1DoqY= 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 1689891627994888.7950748994014; Thu, 20 Jul 2023 15:20:27 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-62-KT7oTUaJNr--i3yZPeFnOA-1; Thu, 20 Jul 2023 18:20:24 -0400 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 81D443C0D183; Thu, 20 Jul 2023 22:20:19 +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 6976A1121315; Thu, 20 Jul 2023 22:20:19 +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 2BE2119451E8; Thu, 20 Jul 2023 22:20:16 +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 97F0D1946A7C for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6152640C20F2; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35FA740C207D; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891626; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=pUIGdtbJoVQq+kSAFTNDAeoaNRtmP9WC3KB0KNxbmK0=; b=EoXaWStXyUNjUP8XjBwRlSZ9O86Wt8DmHUF6Asvm6uY2ycA3+AKaCjn4pHaH47LQ0Nr5ZX qytEKkZFAl5haYwiUjYYs1qlRIonNkJ2Kg/oYFgJwzXMzCrcid1D++7J2e5L9WayhbbFa9 QIiei/orVBkLMjoovnm7qmp1wOCgpvg= X-MC-Unique: KT7oTUaJNr--i3yZPeFnOA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 23/36] tests: add tests for nbdkit invocation Date: Thu, 20 Jul 2023 17:19:50 -0500 Message-ID: <20230720222003.411549-24-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa 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: 1689891630315100009 Content-Type: text/plain; charset="utf-8"; x-default="true" We were testing the arguments that were being passed to qemu when a disk was being served by nbdkit, but the arguments used to start nbdkit itself were not testable. This adds a test to ensure that we're invoking nbdkit correctly for various disk source definitions. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- build-aux/syntax-check.mk | 2 +- src/qemu/qemu_nbdkit.c | 4 +- src/qemu/qemu_nbdkitpriv.h | 31 ++ tests/meson.build | 1 + .../disk-cdrom-network.args.disk0 | 6 + .../disk-cdrom-network.args.disk1 | 8 + .../disk-cdrom-network.args.disk1.pipe.778 | 1 + .../disk-cdrom-network.args.disk2 | 8 + .../disk-cdrom-network.args.disk2.pipe.780 | 1 + .../disk-network-http.args.disk0 | 6 + .../disk-network-http.args.disk1 | 5 + .../disk-network-http.args.disk2 | 6 + .../disk-network-http.args.disk2.pipe.778 | 1 + .../disk-network-http.args.disk3 | 7 + .../disk-network-http.args.disk3.pipe.780 | 1 + ...work-source-curl-nbdkit-backing.args.disk0 | 7 + ...ce-curl-nbdkit-backing.args.disk0.pipe.778 | 1 + .../disk-network-source-curl.args.disk0 | 7 + ...sk-network-source-curl.args.disk0.pipe.778 | 1 + .../disk-network-source-curl.args.disk1 | 7 + ...sk-network-source-curl.args.disk1.pipe.780 | 1 + .../disk-network-source-curl.args.disk2 | 7 + ...sk-network-source-curl.args.disk2.pipe.782 | 1 + .../disk-network-source-curl.args.disk3 | 6 + .../disk-network-source-curl.args.disk4 | 6 + .../disk-network-ssh.args.disk0 | 6 + tests/qemunbdkittest.c | 308 ++++++++++++++++++ 27 files changed, 444 insertions(+), 2 deletions(-) create mode 100644 src/qemu/qemu_nbdkitpriv.h create mode 100644 tests/qemunbdkitdata/disk-cdrom-network.args.disk0 create mode 100644 tests/qemunbdkitdata/disk-cdrom-network.args.disk1 create mode 100644 tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe= .778 create mode 100644 tests/qemunbdkitdata/disk-cdrom-network.args.disk2 create mode 100644 tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe= .780 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk0 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk1 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk2 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.= 778 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk3 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.= 780 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl-nbdkit-ba= cking.args.disk0 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl-nbdkit-ba= cking.args.disk0.pipe.778 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk0 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 0.pipe.778 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk1 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 1.pipe.780 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk2 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 2.pipe.782 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk3 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk4 create mode 100644 tests/qemunbdkitdata/disk-network-ssh.args.disk0 create mode 100644 tests/qemunbdkittest.c diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 64c1e2773e..ec04402133 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1370,7 +1370,7 @@ exclude_file_name_regexp--sc_prohibit_close =3D \ (\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt= -stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/= nss/libvirt_nss_(leases|macs)\.c)|tools/virt-qemu-qmp-proxy$$) =20 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF =3D \ - (^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest)dat= a/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.= conf$$) + (^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest|qem= unbdkit)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/n= o-newline\.conf$$) =20 exclude_file_name_regexp--sc_prohibit_fork_wrappers =3D \ (^(src/(util/(vircommand|virdaemon)|lxc/lxc_controller)|tests/testutils)= \.c$$) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index cb162d2ffc..c3b43ff3c0 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -33,6 +33,8 @@ #include "qemu_driver.h" #include "qemu_extdevice.h" #include "qemu_nbdkit.h" +#define LIBVIRT_QEMU_NBDKITPRIV_H_ALLOW +#include "qemu_nbdkitpriv.h" #include "qemu_security.h" =20 #include @@ -914,7 +916,7 @@ qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess *pro= c, } =20 =20 -static virCommand * +virCommand * qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc) { g_autoptr(virCommand) cmd =3D virCommandNewArgList(proc->caps->path, diff --git a/src/qemu/qemu_nbdkitpriv.h b/src/qemu/qemu_nbdkitpriv.h new file mode 100644 index 0000000000..64f9bb99d8 --- /dev/null +++ b/src/qemu/qemu_nbdkitpriv.h @@ -0,0 +1,31 @@ +/* + * qemu_nbdkitpriv.h: exposing some functions for testing + * + * Copyright (C) 2021 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#ifndef LIBVIRT_QEMU_NBDKITPRIV_H_ALLOW +# error "qemu_nbdkitpriv.h may only be included by qemu_nbdkit.c or test s= uites" +#endif /* LIBVIRT_QEMU_NBDKITPRIV_H_ALLOW */ + +#pragma once + +#include "qemu_nbdkit.h" + +virCommand * +qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc); diff --git a/tests/meson.build b/tests/meson.build index e6589ec555..234636e261 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -455,6 +455,7 @@ if conf.has('WITH_QEMU') { 'name': 'qemuvhostusertest', 'link_with': [ test_qemu_driver_lib ], = 'link_whole': [ test_file_wrapper_lib ] }, { 'name': 'qemuxml2argvtest', 'link_with': [ test_qemu_driver_lib, tes= t_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_= wrapper_lib ] }, { 'name': 'qemuxml2xmltest', 'link_with': [ test_qemu_driver_lib ], 'l= ink_whole': [ test_utils_qemu_lib, test_file_wrapper_lib ] }, + { 'name': 'qemunbdkittest', 'link_with': [ test_qemu_driver_lib ], 'li= nk_whole': [ test_utils_qemu_lib, test_file_wrapper_lib ] }, ] endif =20 diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk0 b/tests/qem= unbdkitdata/disk-cdrom-network.args.disk0 new file mode 100644 index 0000000000..b2f3be4cba --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk0 @@ -0,0 +1,6 @@ +nbdkit \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground \ +--readonly curl \ +protocols=3Dftp \ +url=3Dftp://host.name:21/url/path/file.iso diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk1 b/tests/qem= unbdkitdata/disk-cdrom-network.args.disk1 new file mode 100644 index 0000000000..a23f6573d6 --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk1 @@ -0,0 +1,8 @@ +nbdkit \ +--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \ +--foreground \ +--readonly curl \ +protocols=3Dftps \ +url=3Dftps://host.name:990/url/path/file.iso \ +user=3Dtestuser \ +password=3D-777 diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.778 b/= tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.778 new file mode 100644 index 0000000000..ccdd4033fc --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.778 @@ -0,0 +1 @@ +iscsi-mycluster_myname-secret \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk2 b/tests/qem= unbdkitdata/disk-cdrom-network.args.disk2 new file mode 100644 index 0000000000..04e918609a --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk2 @@ -0,0 +1,8 @@ +nbdkit \ +--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \ +--foreground \ +--readonly curl \ +protocols=3Dhttps \ +'url=3Dhttps://host.name:443/url/path/file.iso?test=3Dval' \ +user=3Dtestuser \ +password=3D-779 diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.780 b/= tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.780 new file mode 100644 index 0000000000..ccdd4033fc --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.780 @@ -0,0 +1 @@ +iscsi-mycluster_myname-secret \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk0 b/tests/qemu= nbdkitdata/disk-network-http.args.disk0 new file mode 100644 index 0000000000..8316f353cb --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk0 @@ -0,0 +1,6 @@ +nbdkit \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground curl \ +protocols=3Dhttp,https \ +url=3Dhttp://example.org:80/test.img \ +timeout=3D1234 diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk1 b/tests/qemu= nbdkitdata/disk-network-http.args.disk1 new file mode 100644 index 0000000000..a546a68b27 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk1 @@ -0,0 +1,5 @@ +nbdkit \ +--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \ +--foreground curl \ +protocols=3Dhttps \ +url=3Dhttps://example.org:443/test2.img diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk2 b/tests/qemu= nbdkitdata/disk-network-http.args.disk2 new file mode 100644 index 0000000000..1004547b3a --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk2 @@ -0,0 +1,6 @@ +nbdkit \ +--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \ +--foreground curl \ +protocols=3Dhttp,https \ +url=3Dhttp://example.org:1234/test3.img \ +cookie=3D-777 diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.778 b/t= ests/qemunbdkitdata/disk-network-http.args.disk2.pipe.778 new file mode 100644 index 0000000000..2c42c95930 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.778 @@ -0,0 +1 @@ +test=3Dtestcookievalue; test2=3D"blurb" \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk3 b/tests/qemu= nbdkitdata/disk-network-http.args.disk3 new file mode 100644 index 0000000000..e3c357b89a --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk3 @@ -0,0 +1,7 @@ +nbdkit \ +--unix /tmp/statedir-3/nbdkit-test-disk-3.socket \ +--foreground curl \ +protocols=3Dhttps \ +'url=3Dhttps://example.org:1234/test4.img?par=3Dval&other=3Dble' \ +cookie=3D-779 \ +sslverify=3Dfalse diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.780 b/t= ests/qemunbdkitdata/disk-network-http.args.disk3.pipe.780 new file mode 100644 index 0000000000..2c42c95930 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.780 @@ -0,0 +1 @@ +test=3Dtestcookievalue; test2=3D"blurb" \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.a= rgs.disk0 b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.ar= gs.disk0 new file mode 100644 index 0000000000..605354433b --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.dis= k0 @@ -0,0 +1,7 @@ +nbdkit \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground \ +--readonly curl \ +protocols=3Dhttps \ +url=3Dhttps://https.example.org:8443/path/to/disk1.qcow2 \ +cookie=3D-777 diff --git a/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.a= rgs.disk0.pipe.778 b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-b= acking.args.disk0.pipe.778 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.dis= k0.pipe.778 @@ -0,0 +1 @@ +cookie1=3Dcookievalue1; cookie2=3Dcookievalue2 \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk0 b/tes= ts/qemunbdkitdata/disk-network-source-curl.args.disk0 new file mode 100644 index 0000000000..948dbfbe5a --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0 @@ -0,0 +1,7 @@ +nbdkit \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground \ +--readonly curl \ +protocols=3Dhttps \ +url=3Dhttps://https.example.org:8443/path/to/disk1.iso \ +cookie=3D-777 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.= 778 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.778 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.778 @@ -0,0 +1 @@ +cookie1=3Dcookievalue1; cookie2=3Dcookievalue2 \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 b/tes= ts/qemunbdkitdata/disk-network-source-curl.args.disk1 new file mode 100644 index 0000000000..fde6a4f533 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 @@ -0,0 +1,7 @@ +nbdkit \ +--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \ +--foreground curl \ +protocols=3Dhttps \ +'url=3Dhttps://https.example.org:8443/path/to/disk5.iso?foo=3Dbar' \ +cookie=3D-779 \ +sslverify=3Dfalse diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.= 780 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780 @@ -0,0 +1 @@ +cookie1=3Dcookievalue1; cookie2=3Dcookievalue2 \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 b/tes= ts/qemunbdkitdata/disk-network-source-curl.args.disk2 new file mode 100644 index 0000000000..88c9fa35a1 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 @@ -0,0 +1,7 @@ +nbdkit \ +--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \ +--foreground \ +--readonly curl \ +protocols=3Dhttp,https \ +url=3Dhttp://http.example.org:8080/path/to/disk2.iso \ +cookie=3D-781 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.= 782 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.782 new file mode 100644 index 0000000000..5c035e84c5 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.782 @@ -0,0 +1 @@ +cookie1=3Dcookievalue1; cookie2=3Dcookievalue2; cookie3=3Dcookievalue3 \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk3 b/tes= ts/qemunbdkitdata/disk-network-source-curl.args.disk3 new file mode 100644 index 0000000000..f517baa948 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk3 @@ -0,0 +1,6 @@ +nbdkit \ +--unix /tmp/statedir-3/nbdkit-test-disk-3.socket \ +--foreground \ +--readonly curl \ +protocols=3Dftp \ +url=3Dftp://ftp.example.org:20/path/to/disk3.iso diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk4 b/tes= ts/qemunbdkitdata/disk-network-source-curl.args.disk4 new file mode 100644 index 0000000000..1df47a9d54 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk4 @@ -0,0 +1,6 @@ +nbdkit \ +--unix /tmp/statedir-4/nbdkit-test-disk-4.socket \ +--foreground \ +--readonly curl \ +protocols=3Dftps \ +url=3Dftps://ftps.example.org:22/path/to/disk4.iso diff --git a/tests/qemunbdkitdata/disk-network-ssh.args.disk0 b/tests/qemun= bdkitdata/disk-network-ssh.args.disk0 new file mode 100644 index 0000000000..c04dc8bb03 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh.args.disk0 @@ -0,0 +1,6 @@ +nbdkit \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground ssh \ +host=3Dexample.org \ +port=3D2222 \ +path=3Dtest.img diff --git a/tests/qemunbdkittest.c b/tests/qemunbdkittest.c new file mode 100644 index 0000000000..2a74f27a5a --- /dev/null +++ b/tests/qemunbdkittest.c @@ -0,0 +1,308 @@ +#include + +#include +#include "internal.h" +#include "testutils.h" +#include "testutilsqemu.h" +#include "qemu/qemu_domain.h" +#include "qemu/qemu_nbdkit.h" +#define LIBVIRT_QEMU_NBDKITPRIV_H_ALLOW +#include "qemu/qemu_nbdkitpriv.h" +#include "vircommand.h" +#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW +#include "vircommandpriv.h" +#include "virutil.h" +#include "virsecret.h" +#include "datatypes.h" +#include "virmock.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +static virQEMUDriver driver; + + +/* Some mock implementations for testing */ +#define PIPE_FD_START 777 +static int mockpipefd =3D PIPE_FD_START; + +static int (*real_virPipeQuiet)(int fds[2]); +static void +init_syms(void) +{ + VIR_MOCK_REAL_INIT(virPipeQuiet); +} + +static int +moveToStableFd(int fd) +{ + int newfd; + + /* don't overwrite an existing fd */ + if (fcntl(mockpipefd, F_GETFD) !=3D -1) + abort(); + + newfd =3D dup2(fd, mockpipefd++); + + VIR_FORCE_CLOSE(fd); + + return newfd; +} + + +int +virPipeQuiet(int fds[2]) +{ + int tempfds[2]; + + init_syms(); + + if (real_virPipeQuiet(tempfds) < 0) + return -1; + + if ((fds[0] =3D moveToStableFd(tempfds[0])) < 0 || + (fds[1] =3D moveToStableFd(tempfds[1])) < 0) + return -1; + + return 0; +} + + +int +virSecretGetSecretString(virConnectPtr conn G_GNUC_UNUSED, + virSecretLookupTypeDef *seclookupdef, + virSecretUsageType secretUsageType, + uint8_t **secret, + size_t *secret_size) +{ + char uuidstr[VIR_UUID_BUFLEN]; + const char *secretname =3D NULL; + char *tmp =3D NULL; + + switch (seclookupdef->type) { + case VIR_SECRET_LOOKUP_TYPE_UUID: + virUUIDFormat(seclookupdef->u.uuid, uuidstr); + secretname =3D uuidstr; + break; + case VIR_SECRET_LOOKUP_TYPE_USAGE: + secretname =3D seclookupdef->u.usage; + break; + case VIR_SECRET_LOOKUP_TYPE_NONE: + case VIR_SECRET_LOOKUP_TYPE_LAST: + default: + virReportEnumRangeError(virSecretLookupType, seclookupdef->typ= e); + return -1; + }; + + /* For testing, just generate a value for the secret that includes the= type + * and the id of the secret */ + tmp =3D g_strdup_printf("%s-%s-secret", virSecretUsageTypeToString(sec= retUsageType), secretname); + *secret =3D (uint8_t*)tmp; + *secret_size =3D strlen(tmp) + 1; + + return 0; +} + +virConnectPtr virGetConnectSecret(void) +{ + return virGetConnect(); +} + +/* end of mock implementations */ + + +typedef struct { + const char *name; + char* infile; + char* outtemplate; + qemuNbdkitCaps *nbdkitcaps; + bool expectFail; +} TestInfo; + + +typedef enum { + NBDKIT_ARG_CAPS, + NBDKIT_ARG_EXPECT_FAIL, + NBDKIT_ARG_END +} NbdkitArgName; + + +static void +testInfoSetPaths(TestInfo *info) +{ + info->infile =3D g_strdup_printf("%s/qemuxml2argvdata/%s.xml", + abs_srcdir, info->name); + info->outtemplate =3D g_strdup_printf("%s/qemunbdkitdata/%s", + abs_srcdir, info->name); +} + +static void +testInfoClear(TestInfo *info) +{ + g_free(info->infile); + g_free(info->outtemplate); + g_clear_object(&info->nbdkitcaps); +} + +static void +testInfoSetArgs(TestInfo *info, ...) +{ + va_list argptr; + NbdkitArgName argname; + unsigned int cap; + + va_start(argptr, info); + while ((argname =3D va_arg(argptr, NbdkitArgName)) !=3D NBDKIT_ARG_END= ) { + switch (argname) { + case NBDKIT_ARG_CAPS: + while ((cap =3D va_arg(argptr, unsigned int)) < QEMU_NBDKI= T_CAPS_LAST) + qemuNbdkitCapsSet(info->nbdkitcaps, cap); + break; + case NBDKIT_ARG_EXPECT_FAIL: + info->expectFail =3D va_arg(argptr, unsigned int); + break; + case NBDKIT_ARG_END: + default: + break; + } + } +} + + +static int +testNbdkit(const void *data) +{ + const TestInfo *info =3D data; + g_autoptr(virDomainDef) def =3D NULL; + size_t i; + int ret =3D 0; + + /* restart mock pipe fds so tests are consistent */ + mockpipefd =3D PIPE_FD_START; + + if (!virFileExists(info->infile)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Test input file '%s' is missing", info->infile); + return -1; + } + + if (!(def =3D virDomainDefParseFile(info->infile, driver.xmlopt, NULL, + VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) + return -1; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + g_autofree char *statedir =3D g_strdup_printf("/tmp/statedir-%zi",= i); + g_autofree char *alias =3D g_strdup_printf("test-disk-%zi", i); + g_autofree char *cmdfile =3D g_strdup_printf("%s.args.disk%zi", + info->outtemplate, i); + + if (qemuNbdkitInitStorageSource(info->nbdkitcaps, disk->src, state= dir, + alias, 101, 101)) { + qemuDomainStorageSourcePrivate *srcPriv =3D + qemuDomainStorageSourcePrivateFetch(disk->src); + g_autoptr(virCommand) cmd =3D NULL; + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDry= RunTokenNew(); + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_autofree char *actualCmdline =3D NULL; + virCommandSendBuffer *sendbuffers; + int nsendbuffers; + size_t j; + + virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); + cmd =3D qemuNbdkitProcessBuildCommand(srcPriv->nbdkitProcess); + + if (virCommandRun(cmd, NULL) < 0) { + ret =3D -1; + continue; + } + virCommandPeekSendBuffers(cmd, &sendbuffers, &nsendbuffers); + + if (!(actualCmdline =3D virBufferContentAndReset(&buf))) { + ret =3D -1; + continue; + } + + if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < = 0) + ret =3D -1; + + for (j =3D 0; j < nsendbuffers; j++) { + virCommandSendBuffer *buffer =3D &sendbuffers[j]; + g_autofree char *pipefile =3D g_strdup_printf("%s.pipe.%i", + cmdfile, + buffer->fd); + + if (virTestCompareToFile((const char*)buffer->buffer, pipe= file) < 0) + ret =3D -1; + } + } else { + if (virFileExists(cmdfile)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "qemuNbdkitInitStorageSource() was not expe= cted to fail"); + ret =3D -1; + } + } + } + + if (info->expectFail) { + if (ret =3D=3D 0) { + ret =3D -1; + VIR_TEST_DEBUG("Error expected but there wasn't any."); + } else { + ret =3D 0; + } + } + return ret; +} + +static int +mymain(void) +{ + g_autoptr(GHashTable) capslatest =3D testQemuGetLatestCaps(); + g_autoptr(GHashTable) capscache =3D virHashNew(virObjectUnref); + int ret =3D 0; + + if (qemuTestDriverInit(&driver) < 0) + return EXIT_FAILURE; + + if (testQemuInsertRealCaps(driver.qemuCapsCache, "x86_64", "latest", "= ", + capslatest, capscache, NULL, NULL) < 0) { + ret =3D -1; + goto cleanup; + } + +#define DO_TEST_FULL(_name, ...) \ + do { \ + TestInfo info =3D { \ + .name =3D _name, \ + .nbdkitcaps =3D qemuNbdkitCapsNew(TEST_NBDKIT_PATH), \ + }; \ + testInfoSetPaths(&info); \ + testInfoSetArgs(&info, __VA_ARGS__); \ + virTestRunLog(&ret, "nbdkit " _name, testNbdkit, &info); \ + testInfoClear(&info); \ + } while (0) + +#define DO_TEST(_name, ...) \ + DO_TEST_FULL(_name, NBDKIT_ARG_CAPS, __VA_ARGS__, QEMU_NBDKIT_CAPS_LAS= T, NBDKIT_ARG_END) + +#define DO_TEST_FAILURE(_name, ...) \ + DO_TEST_FULL(_name, \ + NBDKIT_ARG_EXPECT_FAIL, 1, \ + NBDKIT_ARG_CAPS, __VA_ARGS__, QEMU_NBDKIT_CAPS_LAST, NBDK= IT_ARG_END) + +#define DO_TEST_NOCAPS(_name) \ + DO_TEST_FULL(_name, NBDKIT_ARG_END) + + DO_TEST("disk-cdrom-network", QEMU_NBDKIT_CAPS_PLUGIN_CURL); + DO_TEST("disk-network-http", QEMU_NBDKIT_CAPS_PLUGIN_CURL); + DO_TEST("disk-network-source-curl-nbdkit-backing", QEMU_NBDKIT_CAPS_PL= UGIN_CURL); + DO_TEST("disk-network-source-curl", QEMU_NBDKIT_CAPS_PLUGIN_CURL); + DO_TEST("disk-network-ssh", QEMU_NBDKIT_CAPS_PLUGIN_SSH); + + cleanup: + qemuTestDriverFree(&driver); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891725; cv=none; d=zohomail.com; s=zohoarc; b=nJmfpe86fP35Nm3A6dH8B66lMqjWDDFFgid6xCWfs40GJsI64kqhX2wiehLw0E39Sre7ApukzTDDUgyTYurpTPlG7/Pj2c901d/W+DVnmmYl5f1V/PsQp21EVfNQ9xxnBuacPemYqyK9AUtw1bnRk8Jx4JV1ddy2vVriTVqB6qs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891725; h=Content-Type:Content-Transfer-Encoding:Cc: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=iAH2d3A/THI0HpitECc4XwX99tcfI5j1cRHEDu+pcWI=; b=NE1RwlnN48stV0i5xw3hhGLaQwVsv4/gQx8iUNhsykTdxlfOyhveLVAX8gAvnyBHcpHY0fZep+QBIZVfR2VJtvUTT3u+bpIT0I7QaD9rYMWEDxmZlHRL7bUn8u68NLFq3a1V8Zn/SHbxVmG43g9uuWdU93bIHp3gKxnLiBFF6Ik= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891725251686.0040157857607; Thu, 20 Jul 2023 15:22:05 -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-318-j9TBasDdO4yKsk3mUvoOGw-1; Thu, 20 Jul 2023 18:20:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 16CF71064AF6; Thu, 20 Jul 2023 22:20:24 +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 03C3F207B315; Thu, 20 Jul 2023 22:20:24 +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 042FD194037F; Thu, 20 Jul 2023 22:20:17 +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 98FC519459F1 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9F84F40C200F; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7510C40C207D; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891724; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=iAH2d3A/THI0HpitECc4XwX99tcfI5j1cRHEDu+pcWI=; b=cK2ncixNojN78B0hSKASUOneCWFu6cotEIHoG3qD/WFH0+uVAfRXAG5yMHUgZ44agcthqj vHpXNc8tCbPDfKtgPBVc6OJUI+HIZn+qRFD187PVckbxSQ7pRAeeDFvKZbgOfbxqZPDS+f SqOT7e5oVoewbodNbbgGSnRWOmAFiy8= X-MC-Unique: j9TBasDdO4yKsk3mUvoOGw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 24/36] qemu: add test for authenticating a https network disk Date: Thu, 20 Jul 2023 17:19:51 -0500 Message-ID: <20230720222003.411549-25-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891726889100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- tests/qemunbdkitdata/disk-network-source-curl.args.disk1 | 4 +++- .../disk-network-source-curl.args.disk1.pipe.780 | 2 +- .../disk-network-source-curl.args.disk1.pipe.782 | 1 + tests/qemunbdkitdata/disk-network-source-curl.args.disk2 | 2 +- .../disk-network-source-curl.args.disk2.pipe.784 | 1 + .../disk-network-source-curl.x86_64-latest.args | 3 ++- tests/qemuxml2argvdata/disk-network-source-curl.xml | 3 +++ 7 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 1.pipe.782 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 2.pipe.784 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 b/tes= ts/qemunbdkitdata/disk-network-source-curl.args.disk1 index fde6a4f533..d1288dd242 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 @@ -3,5 +3,7 @@ nbdkit \ --foreground curl \ protocols=3Dhttps \ 'url=3Dhttps://https.example.org:8443/path/to/disk5.iso?foo=3Dbar' \ -cookie=3D-779 \ +user=3Dmyname \ +password=3D-779 \ +cookie=3D-781 \ sslverify=3Dfalse diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.= 780 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780 index 20af4ae383..ccdd4033fc 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.780 @@ -1 +1 @@ -cookie1=3Dcookievalue1; cookie2=3Dcookievalue2 \ No newline at end of file +iscsi-mycluster_myname-secret \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.= 782 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.782 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.782 @@ -0,0 +1 @@ +cookie1=3Dcookievalue1; cookie2=3Dcookievalue2 \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 b/tes= ts/qemunbdkitdata/disk-network-source-curl.args.disk2 index 88c9fa35a1..f1d0e1929e 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 @@ -4,4 +4,4 @@ nbdkit \ --readonly curl \ protocols=3Dhttp,https \ url=3Dhttp://http.example.org:8080/path/to/disk2.iso \ -cookie=3D-781 +cookie=3D-783 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.= 784 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.784 new file mode 100644 index 0000000000..5c035e84c5 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.784 @@ -0,0 +1 @@ +cookie1=3Dcookievalue1; cookie2=3Dcookievalue2; cookie3=3Dcookievalue3 \ No newline at end of file diff --git a/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.= args b/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args index cb0e5a92ea..f6ab5532cc 100644 --- a/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args @@ -32,9 +32,10 @@ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGu= est1/.config \ -blockdev '{"driver":"https","url":"https://https.example.org:8443/path/to= /disk1.iso","cookie-secret":"libvirt-5-storage-httpcookie-secret0","node-na= me":"libvirt-5-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-5-format","read-only":true,"driver":"raw"= ,"file":"libvirt-5-storage"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x3","drive":"li= bvirt-5-format","id":"virtio-disk0","bootindex":1}' \ +-object '{"qom-type":"secret","id":"libvirt-4-storage-auth-secret0","data"= :"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","keyid"= :"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ -object '{"qom-type":"secret","id":"libvirt-4-storage-httpcookie-secret0",= "data":"BUU0KmnWfonHdjzhYhwVQZ5iTI1KweTJ22q8XWUVoBCVu1z70reDuczPBIabZtC3","= keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}'= \ -object '{"qom-type":"secret","id":"libvirt-4-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ --blockdev '{"driver":"https","url":"https://https.example.org:8443/path/to= /disk5.iso?foo=3Dbar","sslverify":false,"cookie-secret":"libvirt-4-storage-= httpcookie-secret0","node-name":"libvirt-4-storage","auto-read-only":true,"= discard":"unmap"}' \ +-blockdev '{"driver":"https","url":"https://https.example.org:8443/path/to= /disk5.iso?foo=3Dbar","username":"myname","password-secret":"libvirt-4-stor= age-auth-secret0","sslverify":false,"cookie-secret":"libvirt-4-storage-http= cookie-secret0","node-name":"libvirt-4-storage","auto-read-only":true,"disc= ard":"unmap"}' \ -blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"luk= s","key-secret":"libvirt-4-format-encryption-secret0","file":"libvirt-4-sto= rage"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"li= bvirt-4-format","id":"virtio-disk4"}' \ -object '{"qom-type":"secret","id":"libvirt-3-storage-httpcookie-secret0",= "data":"BUU0KmnWfonHdjzhYhwVQZ5iTI1KweTJ22q8XWUVoBBv7TuTgTkyAyOPpC2P5qLbOIy= pLoHpppjz+u5O+X8oT+jA1m7q/OJQ8dk2EFD5c0A=3D","keyid":"masterKey0","iv":"AAE= CAwQFBgcICQoLDA0ODw=3D=3D","format":"base64"}' \ diff --git a/tests/qemuxml2argvdata/disk-network-source-curl.xml b/tests/qe= muxml2argvdata/disk-network-source-curl.xml index 1e50314abe..8c3982cd73 100644 --- a/tests/qemuxml2argvdata/disk-network-source-curl.xml +++ b/tests/qemuxml2argvdata/disk-network-source-curl.xml @@ -59,6 +59,9 @@ + + + --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891729; cv=none; d=zohomail.com; s=zohoarc; b=j0uzrfW+bhwbKkoly3xm4AszOey74978+isKTUGZhQd8y8yUhmgMbZu8SQ0Jw5nKmGP18Y4+XcWsGgTRsCC/MgUO53RJfTm2OKQCFXNPBqlHpQKp/yFpR11FOV/ych5L3eGLkGIoAQEDvfnXM6BvQZeNDICxBIOGLWDtiu3PlkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891729; 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=iszU91I7fWAmOZwatJtp4kWXdoFiKB4o2PbLaO0ph5g=; b=RoNsRD3ozspDKGXWMKyVL4YhW8/VKMGIIZrUj7Gvqcd9+d43RpNVAd6FJiZHlfRPszy0StbDuBRY4ASAuyloeAIH4GBkjJnprzSZtpYKh2A3jopUGqg67+PV4KHW8n1lVH5lXD9cZuzYftZ6KksvaMOZn4nJ9Cd73eaFv0u9Sog= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891729415971.8313523007183; Thu, 20 Jul 2023 15:22:09 -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-460-s2Cgof8BOgWh7IAYkm4tTw-1; Thu, 20 Jul 2023 18:20:50 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4A4388D06C; Thu, 20 Jul 2023 22:20:37 +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 8FA45492B02; Thu, 20 Jul 2023 22:20:37 +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 17D161937618; Thu, 20 Jul 2023 22:20:25 +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 C28BE19452CD for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D544240C20F3; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B353640C207D for ; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891728; 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=iszU91I7fWAmOZwatJtp4kWXdoFiKB4o2PbLaO0ph5g=; b=DGjaxgcLNNnzI+DSDmf/Yc5ZFSD9QAZQGP67wIBRDej5FWjetEwyZxjNzC4/4a8cOIOiNY uE7RQ9QqAUhSjcTvKXPiXdblsdz4RjmyJPneITMFz1C24rmaRK3K29pFacXmvVovehRbBJ qDs3j4t6fTeJEKHVbF1zq/Hg2CDNFmo= X-MC-Unique: s2Cgof8BOgWh7IAYkm4tTw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 25/36] qemu: Monitor nbdkit process for exit Date: Thu, 20 Jul 2023 17:19:52 -0500 Message-ID: <20230720222003.411549-26-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.9 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: 1689891731013100014 Content-Type: text/plain; charset="utf-8"; x-default="true" Adds the ability to monitor the nbdkit process so that we can take action in case the child exits unexpectedly. When the nbdkit process exits, we pause the vm, restart nbdkit, and then resume the vm. This allows the vm to continue working in the event of a nbdkit failure. Eventually we may want to generalize this functionality since we may need something similar for e.g. qemu-storage-daemon, etc. The process is monitored with the pidfd_open() syscall if it exists (since linux 5.3). Otherwise it resorts to checking whether the process is alive once a second. The one-second time period was chosen somewhat arbitrarily. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- meson.build | 7 +++ src/qemu/qemu_nbdkit.c | 136 ++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_nbdkit.h | 4 +- src/qemu/qemu_process.c | 4 +- 4 files changed, 143 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 5fce470c6b..c6708ee37c 100644 --- a/meson.build +++ b/meson.build @@ -682,6 +682,13 @@ symbols =3D [ [ 'sched.h', 'cpu_set_t' ], ] =20 +if host_machine.system() =3D=3D 'linux' + symbols +=3D [ + # process management + [ 'sys/syscall.h', 'SYS_pidfd_open' ], + ] +endif + foreach symbol : symbols if cc.has_header_symbol(symbol[0], symbol[1], args: '-D_GNU_SOURCE', pre= fix: symbol.get(2, '')) conf.set('WITH_DECL_@0@'.format(symbol[1].to_upper()), 1) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index c3b43ff3c0..1199acd501 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -19,9 +19,11 @@ =20 #include #include +#include =20 #include "vircommand.h" #include "virerror.h" +#include "virevent.h" #include "virlog.h" #include "virpidfile.h" #include "virsecureerase.h" @@ -35,6 +37,7 @@ #include "qemu_nbdkit.h" #define LIBVIRT_QEMU_NBDKITPRIV_H_ALLOW #include "qemu_nbdkitpriv.h" +#include "qemu_process.h" #include "qemu_security.h" =20 #include @@ -613,6 +616,104 @@ qemuNbdkitCapsCacheNew(const char *cachedir) } =20 =20 +static void +qemuNbdkitProcessRestart(qemuNbdkitProcess *proc, + virDomainObj *vm) +{ + qemuDomainObjPrivate *vmpriv =3D vm->privateData; + virQEMUDriver *driver =3D vmpriv->driver; + + /* clean up resources associated with process */ + qemuNbdkitProcessStop(proc); + + if (qemuNbdkitProcessStart(proc, vm, driver) < 0) + VIR_WARN("Unable to restart nbkdit process"); +} + + +typedef struct { + qemuNbdkitProcess *proc; + virDomainObj *vm; +} qemuNbdkitProcessEventData; + + +static qemuNbdkitProcessEventData* +qemuNbdkitProcessEventDataNew(qemuNbdkitProcess *proc, + virDomainObj *vm) +{ + qemuNbdkitProcessEventData *d =3D g_new(qemuNbdkitProcessEventData, 1); + d->proc =3D proc; + d->vm =3D virObjectRef(vm); + return d; +} + + +static void +qemuNbdkitProcessEventDataFree(qemuNbdkitProcessEventData *d) +{ + virObjectUnref(d->vm); + g_free(d); +} + + +#if WITH_DECL_SYS_PIDFD_OPEN +static void +qemuNbdkitProcessPidfdCb(int watch G_GNUC_UNUSED, + int fd, + int events G_GNUC_UNUSED, + void *opaque) +{ + qemuNbdkitProcessEventData *d =3D opaque; + + VIR_FORCE_CLOSE(fd); + VIR_DEBUG("nbdkit process %i died", d->proc->pid); + qemuNbdkitProcessRestart(d->proc, d->vm); +} +#endif /* WITH_DECL_SYS_PIDFD_OPEN */ + + +static int +qemuNbdkitProcessStartMonitor(qemuNbdkitProcess *proc, + virDomainObj *vm) +{ +#if WITH_DECL_SYS_PIDFD_OPEN + int pidfd; + + pidfd =3D syscall(SYS_pidfd_open, proc->pid, 0); + if (pidfd < 0) { + virReportSystemError(errno, _("pidfd_open failed for %1$i"), proc-= >pid); + return -1; + } + + proc->eventwatch =3D virEventAddHandle(pidfd, + VIR_EVENT_HANDLE_READABLE, + qemuNbdkitProcessPidfdCb, + qemuNbdkitProcessEventDataNew(pro= c, vm), + (virFreeCallback)qemuNbdkitProces= sEventDataFree); + + VIR_DEBUG("Monitoring nbdkit process %i for exit", proc->pid); + + return 0; +#else + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("pidfd_open system call required for nbdkit support")= ); + return -1; +#endif /* WITH_DECL_SYS_PIDFD_OPEN */ +} + + +static void +qemuNbdkitProcessStopMonitor(qemuNbdkitProcess *proc) +{ +#if WITH_DECL_SYS_PIDFD_OPEN + if (proc->eventwatch > 0) { + virEventRemoveHandle(proc->eventwatch); + proc->eventwatch =3D 0; + } +#endif /* WITH_DECL_SYS_PIDFD_OPEN */ +} + + static qemuNbdkitProcess * qemuNbdkitProcessNew(virStorageSource *source, const char *pidfile, @@ -660,9 +761,11 @@ qemuNbdkitReconnectStorageSource(virStorageSource *sou= rce, =20 =20 static void -qemuNbdkitStorageSourceManageProcessOne(virStorageSource *source) +qemuNbdkitStorageSourceManageProcessOne(virStorageSource *source, + virDomainObj *vm) { qemuDomainStorageSourcePrivate *srcpriv =3D QEMU_DOMAIN_STORAGE_SOURCE= _PRIVATE(source); + qemuDomainObjPrivate *vmpriv =3D vm->privateData; qemuNbdkitProcess *proc; =20 if (!srcpriv) @@ -673,6 +776,9 @@ qemuNbdkitStorageSourceManageProcessOne(virStorageSourc= e *source) if (!proc) return; =20 + if (!proc->caps) + proc->caps =3D qemuGetNbdkitCaps(vmpriv->driver); + if (proc->pid <=3D 0) { if (virPidFileReadPath(proc->pidfile, &proc->pid) < 0) { VIR_WARN("Unable to read pidfile '%s'", proc->pidfile); @@ -680,8 +786,14 @@ qemuNbdkitStorageSourceManageProcessOne(virStorageSour= ce *source) } } =20 - if (virProcessKill(proc->pid, 0) < 0) + if (virProcessKill(proc->pid, 0) < 0) { VIR_WARN("nbdkit process %i is not alive", proc->pid); + qemuNbdkitProcessRestart(proc, vm); + return; + } + + if (qemuNbdkitProcessStartMonitor(proc, vm) < 0) + VIR_WARN("unable monitor nbdkit process"); } =20 /** @@ -694,11 +806,12 @@ qemuNbdkitStorageSourceManageProcessOne(virStorageSou= rce *source) * disk and is attempting to re-connect to active domains. */ void -qemuNbdkitStorageSourceManageProcess(virStorageSource *source) +qemuNbdkitStorageSourceManageProcess(virStorageSource *source, + virDomainObj *vm) { virStorageSource *backing; for (backing =3D source; backing !=3D NULL; backing =3D backing->backi= ngStore) - qemuNbdkitStorageSourceManageProcessOne(backing); + qemuNbdkitStorageSourceManageProcessOne(backing, vm); } =20 =20 @@ -710,6 +823,7 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, uid_t user, gid_t group) { +#if WITH_DECL_SYS_PIDFD_OPEN qemuDomainStorageSourcePrivate *srcPriv =3D qemuDomainStorageSourcePri= vateFetch(source); g_autofree char *pidname =3D g_strdup_printf("nbdkit-%s.pid", alias); g_autofree char *socketname =3D g_strdup_printf("nbdkit-%s.socket", al= ias); @@ -753,6 +867,11 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, srcPriv->nbdkitProcess =3D proc; =20 return true; +#else + /* we need pidfd_open in order to monitor the process, so don't constr= uct + * the object in this case so we'll fall back to qemu storage drivers = */ + return false; +#endif /* WITH_DECL_SYS_PIDFD_OPEN */ } =20 =20 @@ -970,6 +1089,8 @@ qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc) void qemuNbdkitProcessFree(qemuNbdkitProcess *proc) { + qemuNbdkitProcessStopMonitor(proc); + g_clear_pointer(&proc->pidfile, g_free); g_clear_pointer(&proc->socketfile, g_free); g_clear_object(&proc->caps); @@ -1039,8 +1160,11 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, goto error; =20 while (virTimeBackOffWait(&timebackoff)) { - if (virFileExists(proc->socketfile)) + if (virFileExists(proc->socketfile)) { + if (qemuNbdkitProcessStartMonitor(proc, vm) < 0) + goto error; return 0; + } =20 if (virProcessKill(proc->pid, 0) =3D=3D 0) continue; @@ -1071,6 +1195,8 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, int qemuNbdkitProcessStop(qemuNbdkitProcess *proc) { + qemuNbdkitProcessStopMonitor(proc); + if (proc->pid < 0) return 0; =20 diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 36a2219d82..326f3d5920 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -69,7 +69,8 @@ void qemuNbdkitStopStorageSource(virStorageSource *src); =20 void -qemuNbdkitStorageSourceManageProcess(virStorageSource *src); +qemuNbdkitStorageSourceManageProcess(virStorageSource *src, + virDomainObj *vm); =20 bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, @@ -91,6 +92,7 @@ struct _qemuNbdkitProcess { uid_t user; gid_t group; pid_t pid; + int eventwatch; }; =20 int diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 83bc8252fc..85e82d5ee9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8990,10 +8990,10 @@ qemuProcessReconnect(void *opaque) } =20 for (i =3D 0; i < obj->def->ndisks; i++) - qemuNbdkitStorageSourceManageProcess(obj->def->disks[i]->src); + qemuNbdkitStorageSourceManageProcess(obj->def->disks[i]->src, obj); =20 if (obj->def->os.loader && obj->def->os.loader->nvram) - qemuNbdkitStorageSourceManageProcess(obj->def->os.loader->nvram); + qemuNbdkitStorageSourceManageProcess(obj->def->os.loader->nvram, o= bj); =20 /* update domain state XML with possibly updated state in virDomainObj= */ if (virDomainObjSave(obj, driver->xmlopt, cfg->stateDir) < 0) --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891686; cv=none; d=zohomail.com; s=zohoarc; b=MVKyxr63ILueu4nlxYd8QX8AgfXVK2niaV0wBt8uDlMw3lOzB7hZrXLfrEVG5KB/DPqaamq4idnH7kPij/Vkiuhiqvp1hY8tJsTIZsqXAWfYrnM4fidC6LY4iaC0YPJvjJgsfQmBdUwPHiOxqOGbM5HmN9Aare6vK2zbpOU5GLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891686; h=Content-Type:Content-Transfer-Encoding:Cc: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=5lHzv+0l9veFJgKrVLC1XJiQ+W9mjJpVR9p4p5CVoZA=; b=BB8ld9WvXPqtrR3MaoZMHPa2jWeUYF4w3zJTiM3+ECWBpQ4oog/Cw5+fq3YShkXg5AVFSEymvqXDODQNPktUy2g51KVxJlawccKguR3v4ig/x2g5f6uoUpX/vRGJVu9OG0f+KCrKu+6bhwzL4j5+aJxkN+KpP6u5pQlbx5J0Y7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891686291427.10907546748365; Thu, 20 Jul 2023 15:21:26 -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-663-N7ATaWa4NNG4WxYbnDDRoA-1; Thu, 20 Jul 2023 18:20:48 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A35D08F1863; Thu, 20 Jul 2023 22:20:30 +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 8FC48C5796A; Thu, 20 Jul 2023 22:20:30 +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 13216194E129; Thu, 20 Jul 2023 22:20:19 +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 9AB7319452C4 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1DDBE40C20F4; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7F3A40C207D; Thu, 20 Jul 2023 22:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891685; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=5lHzv+0l9veFJgKrVLC1XJiQ+W9mjJpVR9p4p5CVoZA=; b=YCAzAyZimGimTws579ei2vyAWcAVJikS6Iao2QJWtq+kyyD8N0ECmpugN+qNyEzQeg0ElE yuwyzvFpHhwsm+nbDwnu6ETdkGazCI7PqtcRoRWo0z6TYLjNVlm97ymO6BLctl3nLSsmUf d3ZzNM4kn0s+OkQyohWpLSlvDgBhpXU= X-MC-Unique: N7ATaWa4NNG4WxYbnDDRoA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 26/36] qemu: try to connect to nbdkit early to detect errors Date: Thu, 20 Jul 2023 17:19:53 -0500 Message-ID: <20230720222003.411549-27-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1689891686598100001 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 c6708ee37c..228189bb69 100644 --- a/meson.build +++ b/meson.build @@ -1002,6 +1002,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')) @@ -2216,6 +2222,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 9174c4021c..ba6e49afc5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -25,6 +25,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 1199acd501..8bb91de994 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" @@ -1121,6 +1125,9 @@ 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 + struct nbd_handle *nbd =3D NULL; +#endif =20 if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc))) return -1; @@ -1161,6 +1168,23 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, =20 while (virTimeBackOffWait(&timebackoff)) { if (virFileExists(proc->socketfile)) { +#if WITH_LIBNBD + /* 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 + * would get from qemu is something like "Requested export not= available". + * So let's try to access it ourselves so that we can error ou= t 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 errorlog; + } + nbd_close(nbd); + +#endif if (qemuNbdkitProcessStartMonitor(proc, vm) < 0) goto error; return 0; --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891641; cv=none; d=zohomail.com; s=zohoarc; b=FriBIDwSmYiAFCrhXI1LE6tz0I/hQvVh0DuJWxr3UpB1vF/T0wD0LqHElAfJikilPXi1UZ7gCcBuvpL/96iVIhQeBh6vRiuAkNIFCoWAIvTB199IXb6vap1Bwmi6Ui1NTeOMn74WLw+dOOzqNz3NEvoBSI990HJM3xp3HXXjPIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891641; h=Content-Type:Content-Transfer-Encoding:Cc: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=vxN79/iwh58YYucoh8D1cgOTi7v6bXJOdGOUBO9ZfnU=; b=RrMJ1yerXR9WDa5WOFbDt0Euiri3DqXbYrcb+DINN6wu+ZcYIIMfhccqRYaW2iuBvJ95gzsH4juQwTKewdAhryiQlou43hjbgc7uAakXBqHj6QV0Ndg6s1bst4aIemAVNOi445F/ve2pbgUcW4znoYBAYc6+weWc3Q3i96UrBDM= 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 1689891641693246.04213919449285; Thu, 20 Jul 2023 15:20:41 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-6HHayIXKMZKJS9YrbOCntg-1; Thu, 20 Jul 2023 18:20:33 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E49D528088C0; Thu, 20 Jul 2023 22:20:27 +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 C6969145414A; Thu, 20 Jul 2023 22:20:27 +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 71F1919452C4; Thu, 20 Jul 2023 22:20: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 C1B7D1946A69 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5D3E640C20F6; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32B1340C207D; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891640; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=vxN79/iwh58YYucoh8D1cgOTi7v6bXJOdGOUBO9ZfnU=; b=KEB6GXuxhzGX1MB+8NT9nt1DWJB0hzDLSfPetoEcdI6pBxyExrvccHLNYPq+ti5UJjmEN6 od5apePDgg85u6ZgykUdllUMbvLcwyp6gjRZPUvq8SwMKjlUrD+sxs+zTsYXB3A4xAe0Ff Xw7rUDCcCVh5xQV29DFoDsn6PGJkNw4= X-MC-Unique: 6HHayIXKMZKJS9YrbOCntg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 27/36] schema: add password configuration for ssh disk Date: Thu, 20 Jul 2023 17:19:54 -0500 Message-ID: <20230720222003.411549-28-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1689891643464100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Right now, ssh network disks are not usable. There is some basic support in libvirt that is meant to support disk chains that have backing disks located at ssh urls, but there is no real way for a user to configure a ssh-based disk. This commit allows users to configure an ssh disk with password authentication. Implementation will follow. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- docs/formatdomain.rst | 27 ++++++++++++++------------- src/conf/schemas/domaincommon.rng | 23 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 4af0b82569..7a5cb1cf22 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2760,7 +2760,7 @@ paravirtualized driver is specified via the ``disk`` = element. ``network`` The ``protocol`` attribute specifies the protocol to access to the requested image. Possible values are "nbd", "iscsi", "rbd", "sheepdo= g", - "gluster", "vxhs", "nfs", "http", "https", "ftp", ftps", or "tftp". + "gluster", "vxhs", "nfs", "http", "https", "ftp", ftps", "tftp", or = "ssh". =20 For any ``protocol`` other than ``nbd`` an additional attribute ``na= me`` is mandatory to specify which volume/image will be used. @@ -2912,18 +2912,19 @@ paravirtualized driver is specified via the ``disk`= ` element. ``auth`` :since:`Since libvirt 3.9.0` , the ``auth`` element is supported for= a disk ``type`` "network" that is using a ``source`` element with the - ``protocol`` attributes "rbd" or "iscsi". If present, the ``auth`` e= lement - provides the authentication credentials needed to access the source.= It - includes a mandatory attribute ``username``, which identifies the us= ername - to use during authentication, as well as a sub-element ``secret`` wi= th - mandatory attribute ``type``, to tie back to a `libvirt secret - object `__ that holds the actual password or other - credentials (the domain XML intentionally does not expose the passwo= rd, - only the reference to the object that does manage the password). Kno= wn - secret types are "ceph" for Ceph RBD network sources and "iscsi" for= CHAP - authentication of iSCSI targets. Both will require either a ``uuid`` - attribute with the UUID of the secret object or a ``usage`` attribute - matching the key that was specified in the secret object. + ``protocol`` attributes "rbd", "iscsi", or "ssh". If present, the + ``auth`` element provides the authentication credentials needed to a= ccess + the source. It includes a mandatory attribute ``username``, which + identifies the username to use during authentication, as well as a + sub-element ``secret`` with mandatory attribute ``type``, to tie bac= k to + a `libvirt secret object `__ that holds the actual + password or other credentials (the domain XML intentionally does not + expose the password, only the reference to the object that does mana= ge + the password). Known secret types are "ceph" for Ceph RBD network so= urces + and "iscsi" for CHAP authentication of iSCSI targets. Both will requ= ire + either a ``uuid`` attribute with the UUID of the secret object or a + ``usage`` attribute matching the key that was specified in the secret + object. ``encryption`` :since:`Since libvirt 3.9.0` , the ``encryption`` can be a sub-eleme= nt of the ``source`` element for encrypted storage sources. If present, diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 2284e3c949..9fcf59268d 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2187,6 +2187,27 @@ =20 + + + + + + ssh + + + + + + + + + + + + + + + @@ -2194,7 +2215,6 @@ sheepdog tftp - ssh @@ -2304,6 +2324,7 @@ + --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891725; cv=none; d=zohomail.com; s=zohoarc; b=Y6M1IV1mEaK7ZoS9Ey+9uy675yUd7FbW1EzlyKBCuDx78frlEFq2MfoziE7bsBiK7J5pj/2bQrYB39hfBQVQtRxKoXKDKkx5A7TbrXcb/BQfvR4M+HIZO7NSJ5kM5G+HdacT5+J2QebjvATbtf3TSSEvTTvw6QrjkRf28F4y2OA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891725; 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=WkLbK7HHc2XfjhJdBUazSM/KxHSMwRg51DYrsfu/C2s=; b=f/evWfcsly7YbXW6hJZ5egqqNVi/3ynQ1w7AxtnDS8EnhHf6zTr3++rB2LO0bHtwKAFHmU3c5vVaj+ZNendO9iC3Ok5FBRYsxh1l9Utk6SommP3GQeaiKoyg+FTFvy3bg5x81inVcR/Zx7lIgRdi0O/TwK0+jM8H2m/+lWEE4UE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 168989172534732.893246431676516; Thu, 20 Jul 2023 15:22:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-464-B1PI5DThP8qnQNr5ipskNA-1; Thu, 20 Jul 2023 18:20:51 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 733853C1351C; Thu, 20 Jul 2023 22:20:37 +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 51E7F1454149; Thu, 20 Jul 2023 22:20:37 +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 F0CA619376BA; Thu, 20 Jul 2023 22:20:24 +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 9D04019452C6 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9198140C20F5; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7039340C207D for ; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891724; 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=WkLbK7HHc2XfjhJdBUazSM/KxHSMwRg51DYrsfu/C2s=; b=U7+PIXrH9ByrFJWxLMa4UkeXVLZd+unuDjSXMxqM0zaih5oJnyANfalABGfk4/dub36ckW mNPfUfLWWkdctbCxzpeyouDW9x0e9C5nlNS5KLP+8hwbFBfmPxHQuQwrUpGOxRefoYBmm0 /8N+MzMcxielTe9QjAfKx+gQJIxCaxI= X-MC-Unique: B1PI5DThP8qnQNr5ipskNA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 28/36] qemu: implement password auth for ssh disks with nbdkit Date: Thu, 20 Jul 2023 17:19:55 -0500 Message-ID: <20230720222003.411549-29-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.7 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: 1689891726929100005 Content-Type: text/plain; charset="utf-8"; x-default="true" For ssh disks that are served by nbdkit, lookup the password from the configured secret and securely pass it to the nbdkit process using fd passing. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/qemu/qemu_nbdkit.c | 87 ++++++++++--------- .../disk-network-ssh-password.args.disk0 | 8 ++ ...k-network-ssh-password.args.disk0.pipe.778 | 1 + .../disk-network-ssh.args.disk1 | 8 ++ .../disk-network-ssh.args.disk1.pipe.778 | 1 + tests/qemunbdkittest.c | 1 + ...sk-network-ssh-password.x86_64-latest.args | 35 ++++++++ .../disk-network-ssh-password.xml | 34 ++++++++ tests/qemuxml2argvtest.c | 1 + 9 files changed, 137 insertions(+), 39 deletions(-) create mode 100644 tests/qemunbdkitdata/disk-network-ssh-password.args.dis= k0 create mode 100644 tests/qemunbdkitdata/disk-network-ssh-password.args.dis= k0.pipe.778 create mode 100644 tests/qemunbdkitdata/disk-network-ssh.args.disk1 create mode 100644 tests/qemunbdkitdata/disk-network-ssh.args.disk1.pipe.7= 78 create mode 100644 tests/qemuxml2argvdata/disk-network-ssh-password.x86_64= -latest.args create mode 100644 tests/qemuxml2argvdata/disk-network-ssh-password.xml diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 8bb91de994..9dbe3af1dd 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -936,6 +936,46 @@ qemuNbdkitCommandPassDataByPipe(virCommand *cmd, } =20 =20 +static int +qemuNbdkitProcessBuildCommandAuth(virStorageAuthDef *authdef, + virCommand *cmd) +{ + g_autoptr(virConnect) conn =3D NULL; + g_autofree uint8_t *secret =3D NULL; + size_t secretlen =3D 0; + int secrettype; + + if (!authdef) + return 0; + + if ((secrettype =3D virSecretUsageTypeFromString(authdef->secrettype))= < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid secret type %1$s"), + authdef->secrettype); + return -1; + } + + conn =3D virGetConnectSecret(); + if (virSecretGetSecretString(conn, + &authdef->seclookupdef, + secrettype, + &secret, + &secretlen) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to get auth secret for storage")); + return -1; + } + + virCommandAddArgPair(cmd, "user", authdef->username); + + if (qemuNbdkitCommandPassDataByPipe(cmd, "password", + &secret, secretlen) < 0) + return -1; + + return 0; +} + + static int qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *proc, virCommand *cmd) @@ -954,37 +994,8 @@ qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *p= roc, } virCommandAddArgPair(cmd, "url", uristring); =20 - if (proc->source->auth) { - g_autoptr(virConnect) conn =3D virGetConnectSecret(); - g_autofree uint8_t *secret =3D NULL; - size_t secretlen =3D 0; - int secrettype; - virStorageAuthDef *authdef =3D proc->source->auth; - - virCommandAddArgPair(cmd, "user", - proc->source->auth->username); - - if ((secrettype =3D virSecretUsageTypeFromString(proc->source->aut= h->secrettype)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid secret type %1$s"), - proc->source->auth->secrettype); - return -1; - } - - if (virSecretGetSecretString(conn, - &authdef->seclookupdef, - secrettype, - &secret, - &secretlen) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to get auth secret for storage")); - return -1; - } - - if (qemuNbdkitCommandPassDataByPipe(cmd, "password", - &secret, secretlen) < 0) - return -1; - } + if (proc->source->auth && qemuNbdkitProcessBuildCommandAuth(proc->sour= ce->auth, cmd) < 0) + return -1; =20 /* Create a pipe to send the cookies to the nbdkit process. */ if (proc->source->ncookies) { @@ -1013,7 +1024,6 @@ static int qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess *proc, virCommand *cmd) { - const char *user =3D NULL; virStorageNetHostDef *host =3D &proc->source->hosts[0]; g_autofree char *portstr =3D g_strdup_printf("%u", host->port); =20 @@ -1024,13 +1034,12 @@ qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess = *proc, virCommandAddArgPair(cmd, "port", portstr); virCommandAddArgPair(cmd, "path", proc->source->path); =20 - if (proc->source->auth) - user =3D proc->source->auth->username; - else if (proc->source->ssh_user) - user =3D proc->source->ssh_user; - - if (user) - virCommandAddArgPair(cmd, "user", user); + if (proc->source->auth) { + if (qemuNbdkitProcessBuildCommandAuth(proc->source->auth, cmd) < 0) + return -1; + } else if (proc->source->ssh_user) { + virCommandAddArgPair(cmd, "user", proc->source->ssh_user); + } =20 if (proc->source->ssh_host_key_check_disabled) virCommandAddArgPair(cmd, "verify-remote-host", "false"); diff --git a/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0 b/te= sts/qemunbdkitdata/disk-network-ssh-password.args.disk0 new file mode 100644 index 0000000000..30711f7f07 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0 @@ -0,0 +1,8 @@ +nbdkit \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground ssh \ +host=3Dexample.org \ +port=3D2222 \ +path=3Dtest2.img \ +user=3Dtestuser \ +password=3D-777 diff --git a/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0.pipe= .778 b/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0.pipe.778 new file mode 100644 index 0000000000..ccdd4033fc --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0.pipe.778 @@ -0,0 +1 @@ +iscsi-mycluster_myname-secret \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-ssh.args.disk1 b/tests/qemun= bdkitdata/disk-network-ssh.args.disk1 new file mode 100644 index 0000000000..9a8a16c8d5 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh.args.disk1 @@ -0,0 +1,8 @@ +nbdkit \ +--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \ +--foreground ssh \ +host=3Dexample.org \ +port=3D2222 \ +path=3Dtest2.img \ +user=3Dtestuser \ +password=3D-777 diff --git a/tests/qemunbdkitdata/disk-network-ssh.args.disk1.pipe.778 b/te= sts/qemunbdkitdata/disk-network-ssh.args.disk1.pipe.778 new file mode 100644 index 0000000000..ccdd4033fc --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh.args.disk1.pipe.778 @@ -0,0 +1 @@ +iscsi-mycluster_myname-secret \ No newline at end of file diff --git a/tests/qemunbdkittest.c b/tests/qemunbdkittest.c index 2a74f27a5a..a51b287f34 100644 --- a/tests/qemunbdkittest.c +++ b/tests/qemunbdkittest.c @@ -298,6 +298,7 @@ mymain(void) DO_TEST("disk-network-source-curl-nbdkit-backing", QEMU_NBDKIT_CAPS_PL= UGIN_CURL); DO_TEST("disk-network-source-curl", QEMU_NBDKIT_CAPS_PLUGIN_CURL); DO_TEST("disk-network-ssh", QEMU_NBDKIT_CAPS_PLUGIN_SSH); + DO_TEST("disk-network-ssh-password", QEMU_NBDKIT_CAPS_PLUGIN_SSH); =20 cleanup: qemuTestDriverFree(&driver); diff --git a/tests/qemuxml2argvdata/disk-network-ssh-password.x86_64-latest= .args b/tests/qemuxml2argvdata/disk-network-ssh-password.x86_64-latest.args new file mode 100644 index 0000000000..fd24e51570 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh-password.x86_64-latest.args @@ -0,0 +1,35 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel kvm \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/var/lib/libvir= t/qemu/domain--1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"= libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ","file":"libvirt-1-storage"}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"li= bvirt-1-format","id":"virtio-disk0","bootindex":1}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-network-ssh-password.xml b/tests/q= emuxml2argvdata/disk-network-ssh-password.xml new file mode 100644 index 0000000000..266acb761f --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh-password.xml @@ -0,0 +1,34 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + + + + + + + + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index a516fdfa7e..c7d48851b8 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1237,6 +1237,7 @@ mymain(void) driver.config->vxhsTLS =3D 0; DO_TEST_CAPS_LATEST("disk-network-ssh"); DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-nbdkit", QEMU_NBDKIT_CAPS= _PLUGIN_SSH); + DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-password", QEMU_NBDKIT_CA= PS_PLUGIN_SSH); DO_TEST_CAPS_LATEST("disk-no-boot"); DO_TEST_CAPS_LATEST("disk-nvme"); DO_TEST_CAPS_VER("disk-vhostuser-numa", "4.2.0"); --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891653; cv=none; d=zohomail.com; s=zohoarc; b=LSlP3Dqu/Ne2zyBaU7StVWSBQv85JWZNLFkI6N6RMCDjmRGD/RkiXqVWGLP9ZeZjfcVtMoqQn70r4aaplA9iiN/OjfCZ+RBdaogDL00gNbVKHdeL/dn/CKZs2GpV8AJBhPUuGEExSpUIzX+LL49hibea/iNHC97eko74s4155To= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891653; h=Content-Type:Content-Transfer-Encoding:Cc: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=FLvscAittGzT0a0FiPRAmh7c1Er1JcnyTFSm898ucE0=; b=etDwD3sbiEOrSL/5zmNeUy6Uj1r8PTm1dKzKrU2hYIQ2De5fMhJg9WV2BH0m+reGinLyAvMqurgWiz9Q0R6u/oPfKv/QVq+G6/ocRDqpxp77iPOEHM5o8gVPxGTtTMiFn2FR9xP0HGRADh7+LLk2R83I3ndFrPkGh9WCNM+cuIU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1689891653475593.3889743083703; Thu, 20 Jul 2023 15:20:53 -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-577-YCZ4TbWrO46lsKlfzieZdA-1; Thu, 20 Jul 2023 18:20:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C9231064B42; Thu, 20 Jul 2023 22:20:34 +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 F16DE207B327; Thu, 20 Jul 2023 22:20: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 C0AF419451F1; Thu, 20 Jul 2023 22:20:20 +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 9C83B19452C5 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CEBAF40C20F7; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A437B40C207D; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891652; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=FLvscAittGzT0a0FiPRAmh7c1Er1JcnyTFSm898ucE0=; b=LJI6oiq0zB4bnkpSRkHFeQsb/zQhy21Wqt4b5aW6BI8nCgMCkYVSEix782r1xH9ljde7Ah i/v3EMV0KqR8BR1Bi4vVg1VF6Xa2GkveCcfTjEpzn3qY9qPMx+qfbLqBH/CtTNfSdE1odO EmNC1DF2QwPfjOfIC7Teg2zglqkcuHE= X-MC-Unique: YCZ4TbWrO46lsKlfzieZdA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 29/36] schema: add configuration for host verification of ssh disks Date: Thu, 20 Jul 2023 17:19:56 -0500 Message-ID: <20230720222003.411549-30-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891654431100006 Content-Type: text/plain; charset="utf-8"; x-default="true" In order to make ssh disks usable, we need to be able to validate a remote host. To do this, add a xml element for ssh disks to allow the user to specify a location for a file that contains known host keys. Implementation to follow. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- docs/formatdomain.rst | 8 ++++++++ src/conf/schemas/domaincommon.rng | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 7a5cb1cf22..1d30eb5016 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3003,6 +3003,14 @@ paravirtualized driver is specified via the ``disk``= element. paused and will be rerun after a successful reconnect. After that= time, any delayed requests and all future requests before a successful reco= nnect will immediately fail. If not set the default QEMU value is 0. + ``knownHosts`` + For storage accessed via the ``ssh`` protocol, this element configur= es a + path to a file that will be used to verify the remote host. This file + must contain the expected host key for the remote host or the connec= tion + will fail. The location of the file is specified via the ``path`` + attribute. + :since:`Since 9.6.0` + =20 For a "file" or "volume" disk type which represents a cdrom or floppy (= the ``device`` attribute), it is possible to define policy what to do with = the diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 9fcf59268d..aa6f39bd2d 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2187,6 +2187,14 @@ =20 + + + + + + + + @@ -2202,6 +2210,9 @@ + + + --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891670; cv=none; d=zohomail.com; s=zohoarc; b=BJ80FMyumizqtYtA9lIzMahLBhnMnz0kq9VsOgEaSMr1QDgT9qjn/jR5KJvPx1Zafnt8uw81e7DoE/YADNZKEZLIXuEgSFqeIVHHz9zxPnyrmyztZjxtGbM9fMQ9+BQydTaJGWNlrTOmODinrXxa0VpMSj36gZgbQZvQ9+NSgvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891670; 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=wnxi4UmfQZM5Le5uHtjIvfkztbL5OJ9pQ4qMXIVURuk=; b=MONjbjArBF4SeNizz8xhVOwwxGqwHQeZhxLgfPH2MyOZ26zOHH1zwqSe8vOoJoizyv06TjU/201XGrxUp9AHMo/EB22tkTrCPPU9R/fZNg1Pp2A6E10rW3wdcsYsXCtNh4wbsqRnC0Ggk2WqrNFQ22KJ5hM1Bi9mIX1VszEe3t4= 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 1689891670675822.5743501020856; Thu, 20 Jul 2023 15:21:10 -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-487-J1e5BcmtPMS3z16OCVErVw-1; Thu, 20 Jul 2023 18:20:40 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A03180123E; Thu, 20 Jul 2023 22:20:31 +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 51774200B41D; Thu, 20 Jul 2023 22:20:31 +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 527E819451DD; Thu, 20 Jul 2023 22:20:19 +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 9D84019452C7 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0EDBA40C20F8; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E1E8A40C207D for ; Thu, 20 Jul 2023 22:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891669; 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=wnxi4UmfQZM5Le5uHtjIvfkztbL5OJ9pQ4qMXIVURuk=; b=Is7jDthVk5aYzDFB7W6kQEjW1VhBKl4Yg+kGE/7Zf7QHM7g+21S0Lc+hZbnDgy2Xi1OgaJ uaG5M1x4ilOc13pyywyc1tTXfUgyN2FLiQBYrxTb85XGAZUbr1T06WgG7qSdOPZo/lCPNT kQFP7nRihQFvcbH6xcPWTkLLDSpUsv8= X-MC-Unique: J1e5BcmtPMS3z16OCVErVw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 30/36] qemu: implement knownHosts for ssh disks with nbdkit Date: Thu, 20 Jul 2023 17:19:57 -0500 Message-ID: <20230720222003.411549-31-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.4 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: 1689891672590100013 Content-Type: text/plain; charset="utf-8"; x-default="true" For ssh disks that are served by nbdkit, use the configured value for knownHosts and pass it to the nbdkit process. Signed-off-by: Jonathon Jongsma --- src/conf/domain_conf.c | 8 ++++++ src/conf/storage_source_conf.c | 1 + src/conf/storage_source_conf.h | 2 ++ src/qemu/qemu_extdevice.c | 4 +-- src/qemu/qemu_hotplug.c | 4 +-- src/qemu/qemu_nbdkit.c | 25 +++++++++++++++---- src/qemu/qemu_nbdkit.h | 6 +++-- .../disk-network-ssh-password.args.disk0 | 3 ++- .../disk-network-ssh.args.disk0 | 3 ++- .../disk-network-ssh-password.xml | 1 + tests/qemuxml2argvdata/disk-network-ssh.xml | 1 + 11 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5ac5c0b771..6420231e5c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7248,6 +7248,11 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, return -1; } } + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_SSH && + (tmpnode =3D virXPathNode("./knownHosts", ctxt))) { + if (!(src->ssh_known_hosts_file =3D virXMLPropStringRequired(tmpno= de, "path"))) + return -1; + } =20 return 0; } @@ -22158,6 +22163,9 @@ virDomainDiskSourceFormatNetwork(virBuffer *attrBuf, =20 if (src->timeout) virBufferAsprintf(childBuf, "\n", src->= timeout); + + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_SSH && src->ssh_know= n_hosts_file) + virBufferEscapeString(childBuf, "\n", src= ->ssh_known_hosts_file); } =20 =20 diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index dcac3a8ff6..3468deb760 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -1170,6 +1170,7 @@ virStorageSourceClear(virStorageSource *def) VIR_FREE(def->tlsHostname); =20 VIR_FREE(def->ssh_user); + VIR_FREE(def->ssh_known_hosts_file); =20 VIR_FREE(def->nfs_user); VIR_FREE(def->nfs_group); diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index f13e7c756a..8a9c7d07e2 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -410,6 +410,8 @@ struct _virStorageSource { /* these must not be used apart from formatting the output JSON in the= qemu driver */ char *ssh_user; bool ssh_host_key_check_disabled; + /* additional ssh variables */ + char *ssh_known_hosts_file; =20 /* nfs_user and nfs_group store the strings passed in by the user for = NFS params. * nfs_uid and nfs_gid represent the converted/looked up ID numbers wh= ich are used diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index 42ecdf13d5..3cf3867056 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -297,11 +297,11 @@ qemuExtDevicesStop(virQEMUDriver *driver, =20 for (i =3D 0; i < def->ndisks; i++) { virDomainDiskDef *disk =3D def->disks[i]; - qemuNbdkitStopStorageSource(disk->src); + qemuNbdkitStopStorageSource(disk->src, vm); } =20 if (def->os.loader && def->os.loader->nvram) - qemuNbdkitStopStorageSource(def->os.loader->nvram); + qemuNbdkitStopStorageSource(def->os.loader->nvram, vm); } =20 =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index e1725ab627..87dd32a22c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1036,7 +1036,7 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver = *driver, if (virStorageSourceChainHasManagedPR(disk->src)) ignore_value(qemuHotplugRemoveManagedPR(vm, VIR_ASYNC_JOB_NONE= )); =20 - qemuNbdkitStopStorageSource(disk->src); + qemuNbdkitStopStorageSource(disk->src, vm); } qemuDomainSecretDiskDestroy(disk); qemuDomainCleanupStorageSourceFD(disk->src); @@ -4508,7 +4508,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriver *driver, qemuHotplugRemoveManagedPR(vm, VIR_ASYNC_JOB_NONE) < 0) goto cleanup; =20 - qemuNbdkitStopStorageSource(disk->src); + qemuNbdkitStopStorageSource(disk->src, vm); =20 if (disk->transient) { VIR_DEBUG("Removing transient overlay '%s' of disk '%s'", diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 9dbe3af1dd..b4f5b2178c 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -628,7 +628,7 @@ qemuNbdkitProcessRestart(qemuNbdkitProcess *proc, virQEMUDriver *driver =3D vmpriv->driver; =20 /* clean up resources associated with process */ - qemuNbdkitProcessStop(proc); + qemuNbdkitProcessStop(proc, vm); =20 if (qemuNbdkitProcessStart(proc, vm, driver) < 0) VIR_WARN("Unable to restart nbkdit process"); @@ -899,7 +899,8 @@ qemuNbdkitStartStorageSource(virQEMUDriver *driver, =20 =20 void -qemuNbdkitStopStorageSource(virStorageSource *src) +qemuNbdkitStopStorageSource(virStorageSource *src, + virDomainObj *vm) { virStorageSource *backing; =20 @@ -907,7 +908,7 @@ qemuNbdkitStopStorageSource(virStorageSource *src) qemuDomainStorageSourcePrivate *priv =3D QEMU_DOMAIN_STORAGE_SOURC= E_PRIVATE(src); =20 if (priv && priv->nbdkitProcess && - qemuNbdkitProcessStop(priv->nbdkitProcess) < 0) + qemuNbdkitProcessStop(priv->nbdkitProcess, vm) < 0) VIR_WARN("Unable to stop nbdkit for storage source '%s'", src-= >nodestorage); } } @@ -1044,6 +1045,9 @@ qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess *p= roc, if (proc->source->ssh_host_key_check_disabled) virCommandAddArgPair(cmd, "verify-remote-host", "false"); =20 + if (proc->source->ssh_known_hosts_file) + virCommandAddArgPair(cmd, "known-hosts", proc->source->ssh_known_h= osts_file); + return 0; } =20 @@ -1156,6 +1160,10 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, if (qemuExtDeviceLogCommand(driver, vm, cmd, "nbdkit") < 0) goto error; =20 + if (proc->source->ssh_known_hosts_file && + qemuSecurityDomainSetPathLabel(driver, vm, proc->source->ssh_known= _hosts_file, false) < 0) + goto error; + if (qemuSecurityCommandRun(driver, vm, cmd, proc->user, proc->group, t= rue, &exitstatus) < 0) goto error; =20 @@ -1220,16 +1228,23 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, NULLSTR(uristring), NULLSTR(errbuf)); =20 error: - qemuNbdkitProcessStop(proc); + qemuNbdkitProcessStop(proc, vm); return -1; } =20 =20 int -qemuNbdkitProcessStop(qemuNbdkitProcess *proc) +qemuNbdkitProcessStop(qemuNbdkitProcess *proc, + virDomainObj *vm) { + qemuDomainObjPrivate *vmpriv =3D vm->privateData; + virQEMUDriver *driver =3D vmpriv->driver; + qemuNbdkitProcessStopMonitor(proc); =20 + if (proc->source->ssh_known_hosts_file) + qemuSecurityDomainRestorePathLabel(driver, vm, proc->source->ssh_k= nown_hosts_file); + if (proc->pid < 0) return 0; =20 diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 326f3d5920..cd5d6ab8db 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -66,7 +66,8 @@ qemuNbdkitStartStorageSource(virQEMUDriver *driver, virStorageSource *src); =20 void -qemuNbdkitStopStorageSource(virStorageSource *src); +qemuNbdkitStopStorageSource(virStorageSource *src, + virDomainObj *vm); =20 void qemuNbdkitStorageSourceManageProcess(virStorageSource *src, @@ -101,7 +102,8 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, virQEMUDriver *driver); =20 int -qemuNbdkitProcessStop(qemuNbdkitProcess *proc); +qemuNbdkitProcessStop(qemuNbdkitProcess *proc, + virDomainObj *vm); =20 void qemuNbdkitProcessFree(qemuNbdkitProcess *proc); diff --git a/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0 b/te= sts/qemunbdkitdata/disk-network-ssh-password.args.disk0 index 30711f7f07..ee2d7c3343 100644 --- a/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0 +++ b/tests/qemunbdkitdata/disk-network-ssh-password.args.disk0 @@ -5,4 +5,5 @@ host=3Dexample.org \ port=3D2222 \ path=3Dtest2.img \ user=3Dtestuser \ -password=3D-777 +password=3D-777 \ +known-hosts=3D/path/to/knownhosts diff --git a/tests/qemunbdkitdata/disk-network-ssh.args.disk0 b/tests/qemun= bdkitdata/disk-network-ssh.args.disk0 index c04dc8bb03..481b218936 100644 --- a/tests/qemunbdkitdata/disk-network-ssh.args.disk0 +++ b/tests/qemunbdkitdata/disk-network-ssh.args.disk0 @@ -3,4 +3,5 @@ nbdkit \ --foreground ssh \ host=3Dexample.org \ port=3D2222 \ -path=3Dtest.img +path=3Dtest.img \ +known-hosts=3D/path/to/ssh_known_hosts diff --git a/tests/qemuxml2argvdata/disk-network-ssh-password.xml b/tests/q= emuxml2argvdata/disk-network-ssh-password.xml index 266acb761f..bdb4cf6e35 100644 --- a/tests/qemuxml2argvdata/disk-network-ssh-password.xml +++ b/tests/qemuxml2argvdata/disk-network-ssh-password.xml @@ -22,6 +22,7 @@ + diff --git a/tests/qemuxml2argvdata/disk-network-ssh.xml b/tests/qemuxml2ar= gvdata/disk-network-ssh.xml index 355add4fea..a3aeca0c99 100644 --- a/tests/qemuxml2argvdata/disk-network-ssh.xml +++ b/tests/qemuxml2argvdata/disk-network-ssh.xml @@ -19,6 +19,7 @@ + --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891687; cv=none; d=zohomail.com; s=zohoarc; b=cACLR047Z82GUayvRoXF3hzhae/Oz+/e9Hv3FXgBuo5TYo7XLtl3P5AZgz2sPSsWgUBgk0hfFA2P+dMKwlxAfGEP9m81l0du4mLSfHqKEF9mBof+RU6sBQ9OgnWSgocdCwM1FAZE07J6YIw4qcsZNkB2V+C1KD1a6W6gPHt7NY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891687; h=Content-Type:Content-Transfer-Encoding:Cc: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=hHgHgWY5ubNzTTOuaS8/HmgrBJRDvK3JK6kCp/qYXbk=; b=ALPD1Q4Qp3y2WrZKu4q/Rf56PFH1N1ZMdxzZcpTWzEONqO336hL685WHGw2WjdLbiYj885TZ156LqZsEaMA2K8AYOYME0DrNozBQKz9/ep3w3u8PESjvHFg3J0i5Vfs3sHZoY+p2E/x9ScIghZ1r8B00iD1RTyCKFJjJKEcEK2E= 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 1689891687774388.41024265534224; Thu, 20 Jul 2023 15:21:27 -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-648-9VwqxpWhNVahkJy5xj07cw-1; Thu, 20 Jul 2023 18:20:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C1981064FB7; Thu, 20 Jul 2023 22:20:35 +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 292C5207B359; Thu, 20 Jul 2023 22:20:35 +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 6C7401949755; Thu, 20 Jul 2023 22:20:21 +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 C1EB51946A6A for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4BE6640CE2A7; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 218AA40C207D; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891686; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=hHgHgWY5ubNzTTOuaS8/HmgrBJRDvK3JK6kCp/qYXbk=; b=cklBwUNNnEalIy1K98QPuhpEIawmHbyphWKJyVnq815dwlwBKG//0lC8YBztIPwkta0n4F m1YShmITmFU02Fo5x9WHiwojFw2b8WNwaOOnGwhOPoOd7q161LmqxXw5fIgrytkL1o39mS TWuSxo5LmZ+NF856oowWwPU+CXDDAvU= X-MC-Unique: 9VwqxpWhNVahkJy5xj07cw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 31/36] schema: add keyfile configuration for ssh disks Date: Thu, 20 Jul 2023 17:19:58 -0500 Message-ID: <20230720222003.411549-32-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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: , Cc: Peter Krempa Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1689891688588100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Authenticating via key file to an ssh server is often preferable to logging in via password. In order to support this functionality add a new xml element for ssh disks that allows the user to specify a keyfile and username. Example configuration: ... ... Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- docs/formatdomain.rst | 7 +++++++ src/conf/schemas/domaincommon.rng | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 1d30eb5016..364fe285a3 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2987,6 +2987,13 @@ paravirtualized driver is specified via the ``disk``= element. of these attributes is omitted, then that field is assumed to be the default value for the current system. If both ``user`` and ``group`` are intended to be default, then the entire element may be omitted. + + When using an ``ssh`` protocol, this element is used to enable + authentication via ssh keys. In this configuration, the element has = two + attributes. The ``username`` attribute specifies the name of the use= r on + the remote server and the ``keyfile`` attribute specifies the path t= o the + keyfile. Note that this only works for ssh keys that are not + password-protected. ``reconnect`` For disk type ``vhostuser`` configures reconnect timeout if the conn= ection is lost. This is set with the two mandatory attributes ``enabled`` a= nd diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index aa6f39bd2d..5b90b71dff 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2195,6 +2195,19 @@ =20 + + + + + + + + + + + + + @@ -2214,11 +2227,15 @@ - + + + + + --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891725; cv=none; d=zohomail.com; s=zohoarc; b=eoQ7KFZyVg4/vex4DPLdQE618wtFfnc3BPTw6jwuCXk2IS7xnsDTgvBr8i7n8K71FdVaQZ6VyfsX/Ihgi+FBDOLQxHyJU1Gd80YNzbvSpN0CcUvguvBkISjcfvoMzYIBSKrUsREMnVocT5TZDg+geG2LmPkNlWttclyJLbMT5w4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891725; 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=28uaPjwTUq2CppdZ7Ky5AyO8KqBjQurMZdfN6figXSU=; b=GzZg3TR3K08ocXog47LEXtln+dictmxyWgmdr+i2JrJcpog9mWOWy5qoF4Wbg+9319ZUAc/e6BvxRxrJhjFiBU/PEhzjWeMxBl2D/lopxJDi9fLcMkCSqFukwalcdLHUtlrJoFusgDxCqpqqctj+le5QdPEC/BKWcxvRY7A7kCI= 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 1689891725550230.01110614102663; Thu, 20 Jul 2023 15:22:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-470-UTgbBLRaPRKGxmUqwBH0TQ-1; Thu, 20 Jul 2023 18:20:47 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CCCED3815F08; Thu, 20 Jul 2023 22:20:34 +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 AFEA41454148; Thu, 20 Jul 2023 22:20:34 +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 2F9A11949749; Thu, 20 Jul 2023 22:20:21 +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 9F62A19452C8 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7F85E40561BD; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EBF240C207D for ; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891724; 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=28uaPjwTUq2CppdZ7Ky5AyO8KqBjQurMZdfN6figXSU=; b=P9jsTOM7+YIXMUYxA32Tf1iTiZOi2CFcznT6xExULtqm93OtB9j4PAughivMLXKThdOW4D fzygfMMljR7KrUPtVzJXETztGLk6WzsW/ykqTDH2Fn8EHLzq/N9qVIjdsnR8vHNkZrjwzf iFc9omOk5vSuaRd8oVKXjWbgfLSjuIc= X-MC-Unique: UTgbBLRaPRKGxmUqwBH0TQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 32/36] qemu: implement keyfile auth for ssh disks with nbdkit Date: Thu, 20 Jul 2023 17:19:59 -0500 Message-ID: <20230720222003.411549-33-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.7 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: 1689891726875100002 Content-Type: text/plain; charset="utf-8"; x-default="true" For ssh disks that are served by nbdkit, we can support logging in with an ssh key file. Pass the path to the configured key file and the username to the nbdkit process. Signed-off-by: Jonathon Jongsma --- src/conf/domain_conf.c | 32 ++++++++++++++---- src/conf/storage_source_conf.c | 1 + src/conf/storage_source_conf.h | 5 ++- src/qemu/qemu_nbdkit.c | 15 +++++++-- .../disk-network-ssh-key.args.disk0 | 9 +++++ .../disk-network-ssh.args.disk2 | 9 +++++ tests/qemunbdkittest.c | 1 + .../qemuxml2argvdata/disk-network-ssh-key.xml | 33 +++++++++++++++++++ 8 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 tests/qemunbdkitdata/disk-network-ssh-key.args.disk0 create mode 100644 tests/qemunbdkitdata/disk-network-ssh.args.disk2 create mode 100644 tests/qemuxml2argvdata/disk-network-ssh-key.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6420231e5c..08cf1be656 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7248,10 +7248,18 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, return -1; } } - if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_SSH && - (tmpnode =3D virXPathNode("./knownHosts", ctxt))) { - if (!(src->ssh_known_hosts_file =3D virXMLPropStringRequired(tmpno= de, "path"))) - return -1; + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_SSH) { + if ((tmpnode =3D virXPathNode("./knownHosts", ctxt))) { + if (!(src->ssh_known_hosts_file =3D virXMLPropStringRequired(t= mpnode, "path"))) + return -1; + } + if ((tmpnode =3D virXPathNode("./identity", ctxt))) { + if (!(src->ssh_user =3D virXMLPropStringRequired(tmpnode, "use= rname"))) + return -1; + + if (!(src->ssh_keyfile =3D virXMLPropStringRequired(tmpnode, "= keyfile"))) + return -1; + } } =20 return 0; @@ -22164,8 +22172,20 @@ virDomainDiskSourceFormatNetwork(virBuffer *attrBu= f, if (src->timeout) virBufferAsprintf(childBuf, "\n", src->= timeout); =20 - if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_SSH && src->ssh_know= n_hosts_file) - virBufferEscapeString(childBuf, "\n", src= ->ssh_known_hosts_file); + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_SSH) { + if (src->ssh_known_hosts_file) + virBufferEscapeString(childBuf, "\n",= src->ssh_known_hosts_file); + if (src->ssh_keyfile) { + virBufferAddLit(childBuf, "ssh_user) + virBufferEscapeString(childBuf, " username=3D'%s'", src->s= sh_user); + if (src->ssh_keyfile) + virBufferEscapeString(childBuf, " keyfile=3D'%s'", src->ss= h_keyfile); + + virBufferAddLit(childBuf, "/>\n"); + } + } } =20 =20 diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 3468deb760..5074d6b219 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -1171,6 +1171,7 @@ virStorageSourceClear(virStorageSource *def) =20 VIR_FREE(def->ssh_user); VIR_FREE(def->ssh_known_hosts_file); + VIR_FREE(def->ssh_keyfile); =20 VIR_FREE(def->nfs_user); VIR_FREE(def->nfs_group); diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index 8a9c7d07e2..8c805664af 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -406,12 +406,11 @@ struct _virStorageSource { =20 bool hostcdrom; /* backing device is a cdrom */ =20 - /* passthrough variables for the ssh driver which we don't handle prop= erly */ - /* these must not be used apart from formatting the output JSON in the= qemu driver */ + /* ssh variables */ char *ssh_user; bool ssh_host_key_check_disabled; - /* additional ssh variables */ char *ssh_known_hosts_file; + char *ssh_keyfile; =20 /* nfs_user and nfs_group store the strings passed in by the user for = NFS params. * nfs_uid and nfs_gid represent the converted/looked up ID numbers wh= ich are used diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index b4f5b2178c..4bebabf799 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -1038,8 +1038,12 @@ qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess *= proc, if (proc->source->auth) { if (qemuNbdkitProcessBuildCommandAuth(proc->source->auth, cmd) < 0) return -1; - } else if (proc->source->ssh_user) { - virCommandAddArgPair(cmd, "user", proc->source->ssh_user); + } else { + if (proc->source->ssh_keyfile) + virCommandAddArgPair(cmd, "identity", proc->source->ssh_keyfil= e); + + if (proc->source->ssh_user) + virCommandAddArgPair(cmd, "user", proc->source->ssh_user); } =20 if (proc->source->ssh_host_key_check_disabled) @@ -1160,6 +1164,10 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, if (qemuExtDeviceLogCommand(driver, vm, cmd, "nbdkit") < 0) goto error; =20 + if (proc->source->ssh_keyfile && + qemuSecurityDomainSetPathLabel(driver, vm, proc->source->ssh_keyfi= le, false) < 0) + goto error; + if (proc->source->ssh_known_hosts_file && qemuSecurityDomainSetPathLabel(driver, vm, proc->source->ssh_known= _hosts_file, false) < 0) goto error; @@ -1245,6 +1253,9 @@ qemuNbdkitProcessStop(qemuNbdkitProcess *proc, if (proc->source->ssh_known_hosts_file) qemuSecurityDomainRestorePathLabel(driver, vm, proc->source->ssh_k= nown_hosts_file); =20 + if (proc->source->ssh_keyfile) + qemuSecurityDomainRestorePathLabel(driver, vm, proc->source->ssh_k= eyfile); + if (proc->pid < 0) return 0; =20 diff --git a/tests/qemunbdkitdata/disk-network-ssh-key.args.disk0 b/tests/q= emunbdkitdata/disk-network-ssh-key.args.disk0 new file mode 100644 index 0000000000..0b52bfe0fb --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh-key.args.disk0 @@ -0,0 +1,9 @@ +nbdkit \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground ssh \ +host=3Dexample.org \ +port=3D2222 \ +path=3Dtest.img \ +identity=3D/path/to/id_rsa \ +user=3Dmyuser \ +known-hosts=3D/path/to/ssh_known_hosts diff --git a/tests/qemunbdkitdata/disk-network-ssh.args.disk2 b/tests/qemun= bdkitdata/disk-network-ssh.args.disk2 new file mode 100644 index 0000000000..e269a34351 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh.args.disk2 @@ -0,0 +1,9 @@ +nbdkit \ +--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \ +--foreground ssh \ +host=3Dexample.org \ +port=3D2222 \ +path=3Dtest2.img \ +identity=3D/path/to/id_rsa \ +user=3Dmyuser \ +known-hosts=3D/path/to/ssh_known_hosts diff --git a/tests/qemunbdkittest.c b/tests/qemunbdkittest.c index a51b287f34..559196a1cd 100644 --- a/tests/qemunbdkittest.c +++ b/tests/qemunbdkittest.c @@ -299,6 +299,7 @@ mymain(void) DO_TEST("disk-network-source-curl", QEMU_NBDKIT_CAPS_PLUGIN_CURL); DO_TEST("disk-network-ssh", QEMU_NBDKIT_CAPS_PLUGIN_SSH); DO_TEST("disk-network-ssh-password", QEMU_NBDKIT_CAPS_PLUGIN_SSH); + DO_TEST("disk-network-ssh-key", QEMU_NBDKIT_CAPS_PLUGIN_SSH); =20 cleanup: qemuTestDriverFree(&driver); diff --git a/tests/qemuxml2argvdata/disk-network-ssh-key.xml b/tests/qemuxm= l2argvdata/disk-network-ssh-key.xml new file mode 100644 index 0000000000..81b92231fa --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh-key.xml @@ -0,0 +1,33 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + + + + + + + + + + + + + + + --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891668; cv=none; d=zohomail.com; s=zohoarc; b=lFLicgBXxXPp2nxWx5YxI/KEaRxiM27t7EcwLuaajdO/+Y5TYGMRZx2zJVZKrPrJ3GWsvqdWB6p8L6X1dsSvh0yd4r6eoDdM35/3VcCidUd+GFd2W6xci6izKU98aGwbyU3dOEGlcdHv4urXjuXyEvm6F/w7H4fapoLVPokvrbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891668; 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=FT1K453fcXNFNL+iEFNOxlRYe0RF3i3L/5n2FNsDjyg=; b=Bmru+gbnYPuIE+yEQZyTZ3bR2CREABT7ksd8EHidE4DFKbgRO+B1QI65IcoFmB0bWfE3cNdjuGDU2OCWHnMcSFkfQAOPZy7drcf851gU3ltrr6TOaTzTWSFMrgvp64F3SXnA5zu+nS3Un8syTPmqePd8Jy8ezLZgkFkFdsIU108= 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 1689891668704897.6466330454399; Thu, 20 Jul 2023 15:21:08 -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-164-LCVgI5vIOQquV3BII6QK2Q-1; Thu, 20 Jul 2023 18:20:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 509B587323F; Thu, 20 Jul 2023 22:20:32 +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 33480207B350; Thu, 20 Jul 2023 22:20:32 +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 C77B81946A6B; Thu, 20 Jul 2023 22:20:19 +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 C18DF19465BA for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B459D40B4CCB; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92FA340C207D for ; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891667; 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=FT1K453fcXNFNL+iEFNOxlRYe0RF3i3L/5n2FNsDjyg=; b=VJfsHr+ukSZ6sT5cXVdLsfxfHSnzQ1DiVXdxI7Ht2DUpCwKyEkHikMeGhg4vApC7LBXoP7 eZ4ci0OBoEbiqdCqKgwQsuOk8VErejee9fM6N7txSBPQHlnSME8K8oU0K7oCTRcb23NNHP I53nzA4tn3ZMAAKQ61zL/7VQirbgI2k= X-MC-Unique: LCVgI5vIOQquV3BII6QK2Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 33/36] schema: add ssh-agent configuration for ssh disks Date: Thu, 20 Jul 2023 17:20:00 -0500 Message-ID: <20230720222003.411549-34-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.4 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: 1689891670496100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Add the ability to specify a path to a ssh-agent socket in order to use the ssh-agent to authenticate to remote ssh disks. Example configuration: ... ... Signed-off-by: Jonathon Jongsma --- docs/formatdomain.rst | 13 ++++++++----- src/conf/schemas/domaincommon.rng | 11 ++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 364fe285a3..e7b14503b2 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2989,11 +2989,14 @@ paravirtualized driver is specified via the ``disk`= ` element. are intended to be default, then the entire element may be omitted. =20 When using an ``ssh`` protocol, this element is used to enable - authentication via ssh keys. In this configuration, the element has = two - attributes. The ``username`` attribute specifies the name of the use= r on - the remote server and the ``keyfile`` attribute specifies the path t= o the - keyfile. Note that this only works for ssh keys that are not - password-protected. + authentication via ssh keys. In this configuration, the element has = three + possible attributes. The ``username`` attribute is required and spec= ifies + the name of the user on the remote server. ssh keys can be specified= in + one of two ways. The first way is by adding them to an ssh-agent and + providing the path to the ssh-agent socket in the ``agentsock`` + attribute. This method works for ssh keys with or without password + protection. Alternatively, for ssh keys without a password, the ssh = key + can be specified directly by setting the ``keyfile`` attribute. ``reconnect`` For disk type ``vhostuser`` configures reconnect timeout if the conn= ection is lost. This is set with the two mandatory attributes ``enabled`` a= nd diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 5b90b71dff..91f399e057 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2201,9 +2201,14 @@ - - - + + + + + + + + --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891647; cv=none; d=zohomail.com; s=zohoarc; b=HWBTlAok+E8eBS8ETHfDXAjMoSiO34h8lY8q3jw2SkTl4ANOBWfnTrSDPc8zoGSB1jd+DjnS+36FPXGVEGSCKw8YKVeYcVXTzJViFKhGEZm0ucPfiC8JfUQnwLZOnWTPpqlmxXgK1wJSDudPZQ8t8iedVTIX1mJLCox0vdt7J38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891647; 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=6y2o8hTxvr8eCuzNrtVglencHrFSrnV9gULhp7IYmQw=; b=UFPezEp8F+6wloE8x6mUV8N3ClQ4VXdpc3btUlUNDIT7FXDh/oqaL+w0bfQySBuY58NaTJ5K7o1DX1LJGO1GipxsTjkqoJGcAep3ceCqq9qy7eOvrwle+HWZLn7rGLqDEcz7cc7ScbJrArOJZTavxEFHnXFBb1X83174FiI6tPg= 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 1689891647495327.52859874292744; Thu, 20 Jul 2023 15:20:47 -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-178-IRLlQEoCPnuaIXr_IWZdoA-1; Thu, 20 Jul 2023 18:20:37 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D7903186E125; Thu, 20 Jul 2023 22:20:29 +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 C2DFAC5796A; Thu, 20 Jul 2023 22:20:29 +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 E29B9194E11E; Thu, 20 Jul 2023 22:20: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 A173719452C9 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E871840C20F9; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C738040C207D for ; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891646; 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=6y2o8hTxvr8eCuzNrtVglencHrFSrnV9gULhp7IYmQw=; b=I2zcGK94c2ljEM8XLFy3GvS8YBH9QxX8C43CqLNKFrArnpPbXXSwvd1eDWlf/JjccmAQe+ B0i6Qzjc098Kvgeze3SCij7gsTv3nVPi/81v7mITmG2fXjEwxp55+y6jIyDFALna9ONKis meB8KdH0RJm052WumgB8GR2LLWiQquk= X-MC-Unique: IRLlQEoCPnuaIXr_IWZdoA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 34/36] qemu: implement ssh-agent auth for ssh disks with nbdkit Date: Thu, 20 Jul 2023 17:20:01 -0500 Message-ID: <20230720222003.411549-35-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.8 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: 1689891648244100001 Content-Type: text/plain; charset="utf-8"; x-default="true" It's not possible to use password-protected ssh keys directly with libvirt because libvirt doesn't have any way to prompt a user for the password. To accomodate password-protected key files, an administrator can add these keys to an ssh agent and then configure the domain with the path to the ssh-agent socket. Note that this requires an administrator or management app to configure the ssh-agent with an appropriate socket path and add the necessary keys to it. In addition, it does not currently work with selinux enabled. The ssh-agent socket would need a label that libvirt would be allowed to access rather than unconfined_t. Signed-off-by: Jonathon Jongsma --- src/conf/domain_conf.c | 11 ++++++++--- src/conf/storage_source_conf.c | 1 + src/conf/storage_source_conf.h | 1 + src/qemu/qemu_nbdkit.c | 10 ++++++++++ .../disk-network-ssh-key.args.disk0 | 6 +++--- .../disk-network-ssh-key.args.disk1 | 9 +++++++++ tests/qemuxml2argvdata/disk-network-ssh-key.xml | 17 ++++++++++++++--- 7 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 tests/qemunbdkitdata/disk-network-ssh-key.args.disk1 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 08cf1be656..a70d7bf613 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7257,8 +7257,11 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, if (!(src->ssh_user =3D virXMLPropStringRequired(tmpnode, "use= rname"))) return -1; =20 - if (!(src->ssh_keyfile =3D virXMLPropStringRequired(tmpnode, "= keyfile"))) - return -1; + /* optional path to an ssh key file */ + src->ssh_keyfile =3D virXMLPropString(tmpnode, "keyfile"); + + /* optional ssh-agent socket location */ + src->ssh_agent =3D virXMLPropString(tmpnode, "agentsock"); } } =20 @@ -22175,13 +22178,15 @@ virDomainDiskSourceFormatNetwork(virBuffer *attrB= uf, if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_SSH) { if (src->ssh_known_hosts_file) virBufferEscapeString(childBuf, "\n",= src->ssh_known_hosts_file); - if (src->ssh_keyfile) { + if (src->ssh_keyfile || src->ssh_agent) { virBufferAddLit(childBuf, "ssh_user) virBufferEscapeString(childBuf, " username=3D'%s'", src->s= sh_user); if (src->ssh_keyfile) virBufferEscapeString(childBuf, " keyfile=3D'%s'", src->ss= h_keyfile); + if (src->ssh_agent) + virBufferEscapeString(childBuf, " agentsock=3D'%s'", src->= ssh_agent); =20 virBufferAddLit(childBuf, "/>\n"); } diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 5074d6b219..efdebffd1d 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -1172,6 +1172,7 @@ virStorageSourceClear(virStorageSource *def) VIR_FREE(def->ssh_user); VIR_FREE(def->ssh_known_hosts_file); VIR_FREE(def->ssh_keyfile); + VIR_FREE(def->ssh_agent); =20 VIR_FREE(def->nfs_user); VIR_FREE(def->nfs_group); diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index 8c805664af..061faa66cb 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -411,6 +411,7 @@ struct _virStorageSource { bool ssh_host_key_check_disabled; char *ssh_known_hosts_file; char *ssh_keyfile; + char *ssh_agent; =20 /* nfs_user and nfs_group store the strings passed in by the user for = NFS params. * nfs_uid and nfs_gid represent the converted/looked up ID numbers wh= ich are used diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 4bebabf799..5e9a581169 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -1046,6 +1046,9 @@ qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess *p= roc, virCommandAddArgPair(cmd, "user", proc->source->ssh_user); } =20 + if (proc->source->ssh_agent) + virCommandAddEnvPair(cmd, "SSH_AUTH_SOCK", proc->source->ssh_agent= ); + if (proc->source->ssh_host_key_check_disabled) virCommandAddArgPair(cmd, "verify-remote-host", "false"); =20 @@ -1168,6 +1171,10 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, qemuSecurityDomainSetPathLabel(driver, vm, proc->source->ssh_keyfi= le, false) < 0) goto error; =20 + if (proc->source->ssh_agent && + qemuSecurityDomainSetPathLabel(driver, vm, proc->source->ssh_agent= , false) < 0) + goto error; + if (proc->source->ssh_known_hosts_file && qemuSecurityDomainSetPathLabel(driver, vm, proc->source->ssh_known= _hosts_file, false) < 0) goto error; @@ -1256,6 +1263,9 @@ qemuNbdkitProcessStop(qemuNbdkitProcess *proc, if (proc->source->ssh_keyfile) qemuSecurityDomainRestorePathLabel(driver, vm, proc->source->ssh_k= eyfile); =20 + if (proc->source->ssh_agent) + qemuSecurityDomainRestorePathLabel(driver, vm, proc->source->ssh_a= gent); + if (proc->pid < 0) return 0; =20 diff --git a/tests/qemunbdkitdata/disk-network-ssh-key.args.disk0 b/tests/q= emunbdkitdata/disk-network-ssh-key.args.disk0 index 0b52bfe0fb..f627700490 100644 --- a/tests/qemunbdkitdata/disk-network-ssh-key.args.disk0 +++ b/tests/qemunbdkitdata/disk-network-ssh-key.args.disk0 @@ -1,9 +1,9 @@ +SSH_AUTH_SOCK=3D/path/to/agent/socket \ nbdkit \ --unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ --foreground ssh \ host=3Dexample.org \ port=3D2222 \ -path=3Dtest.img \ -identity=3D/path/to/id_rsa \ +path=3Dtest1.img \ user=3Dmyuser \ -known-hosts=3D/path/to/ssh_known_hosts +known-hosts=3D/path/to/ssh_known_hosts1 diff --git a/tests/qemunbdkitdata/disk-network-ssh-key.args.disk1 b/tests/q= emunbdkitdata/disk-network-ssh-key.args.disk1 new file mode 100644 index 0000000000..80df9c30c6 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh-key.args.disk1 @@ -0,0 +1,9 @@ +nbdkit \ +--unix /tmp/statedir-1/nbdkit-test-disk-1.socket \ +--foreground ssh \ +host=3Dexample.org \ +port=3D2222 \ +path=3Dtest2.img \ +identity=3D/path/to/id_rsa \ +user=3Dmyuser2 \ +known-hosts=3D/path/to/ssh_known_hosts2 diff --git a/tests/qemuxml2argvdata/disk-network-ssh-key.xml b/tests/qemuxm= l2argvdata/disk-network-ssh-key.xml index 81b92231fa..fda01e7e68 100644 --- a/tests/qemuxml2argvdata/disk-network-ssh-key.xml +++ b/tests/qemuxml2argvdata/disk-network-ssh-key.xml @@ -15,12 +15,23 @@ - + - - + + + + + + + + + + + + + --=20 2.41.0 From nobody Sun May 19 15:58:45 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; 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=1689891726; cv=none; d=zohomail.com; s=zohoarc; b=ns8BTiitv4jUkxi/9l800EKFMjGg7OreYTR/VnohDOySWAHUgGo26Ftlsv3MHSGUqzO6mmZZUsLcFzOeCPFCJBCxaZ6hOKABNhkZvalrFuPkzt0O6Larjq993z8sPZQGh+Ggbhx/ukJZ4V+ISNedPhUy3QLh5PPdhOCymmS+rQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891726; 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=DaIikO9yRz9LCoD5Euoqgdygm6EkhqB6CDsZ7A970vg=; b=lqLnesyZRD6UPuO9wNNFlIS7559/x3rElnRxGkIgUMFpF5W0NC5NifReyfhxKAeuB3tzOlqVE9BNpxHVzHv7o/shqvI9WFo0Xkf4+dC8yzvYpTpOr4Yqpt67YkmtNr4nzXtcFCOnANZJB9SAxJJGBQxxmoKUGxZtcNe5/4qVI3I= 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 1689891726220470.23378323041413; Thu, 20 Jul 2023 15:22:06 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-192-wpUmwibqMwqwBLLt19Gt7Q-1; Thu, 20 Jul 2023 18:20:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B566F2807D93; Thu, 20 Jul 2023 22:20:32 +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 9E4D0207B33B; Thu, 20 Jul 2023 22:20:32 +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 11BFD19451F5; Thu, 20 Jul 2023 22:20:20 +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 A1D8B1946A49 for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 286594043CDB; Thu, 20 Jul 2023 22:20:13 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0743640C207D for ; Thu, 20 Jul 2023 22:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891725; 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=DaIikO9yRz9LCoD5Euoqgdygm6EkhqB6CDsZ7A970vg=; b=MfMv8/m/PCP9i3CAFoT6FnMDE/uNZGSPMhjr4m6RRdhmmDJO80usp1Y0dksq7Gy9NSVmxY 19ainf9sQg3zAei5Q0Z8MFvtrY6fSnNzUDLJTbbFzpbQ+Du/+yzBWb2yfgcwj1+H+BOCPr dvepc/aiEPtZ3pU+TUR3mb3C16+f/ds= X-MC-Unique: wpUmwibqMwqwBLLt19Gt7Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 35/36] run: add ability to set selinux context Date: Thu, 20 Jul 2023 17:20:02 -0500 Message-ID: <20230720222003.411549-36-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.4 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: 1689891726875100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When running libvirt from the build directory with the 'run' script, it will run as unconfined_t. This can result in unexpected behavior when selinux is enforcing due to the fact that the selinux policies are written assuming that libvirt is running with the system_u:system_r:virtd_t context. This patch adds a new --selinux option to the run script. When this option is specified, it will launch the specified binary using the 'runcon' utility to set its selinux context to the one mentioned above. Since this may require root privileges, setting the selinux context is not the default behavior and must be enabled with the command line switch. Signed-off-by: Jonathon Jongsma --- run.in | 100 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/run.in b/run.in index 80a5d2dd43..5b89b3dcd5 100644 --- a/run.in +++ b/run.in @@ -40,9 +40,11 @@ # # ---------------------------------------------------------------------- =20 +import argparse import os import os.path import random +import shutil import signal import subprocess import sys @@ -59,15 +61,20 @@ def prepend(env, varname, extradir): =20 here =3D "@abs_builddir@" =20 -if len(sys.argv) < 2: - print("syntax: %s BINARY [ARGS...]" % sys.argv[0], file=3Dsys.stderr) +parser =3D argparse.ArgumentParser(add_help=3DFalse, allow_abbrev=3DFalse) +parser.add_argument('--selinux', + action=3D'store_true', + help=3D'Run in the appropriate selinux context') + +opts, args =3D parser.parse_known_args() + +if len(args) < 1: + print("syntax: %s [--selinux] BINARY [ARGS...]" % sys.argv[0], file=3D= sys.stderr) sys.exit(1) =20 -prog =3D sys.argv[1] -args =3D sys.argv[1:] +prog =3D args[0] env =3D os.environ =20 - prepend(env, "LD_LIBRARY_PATH", os.path.join(here, "src")) prepend(env, "PKG_CONFIG_PATH", os.path.join(here, "src")) prepend(env, "PATH", os.path.join(here, "tools")) @@ -130,10 +137,25 @@ def change_unit(name, action): return ret =3D=3D 0 =20 =20 +def chcon(path, user, role, type): + print("Setting file context of {} to u=3D{}, r=3D{}, t=3D{}...".format= (progpath, + user, + role, + type)) + ret =3D subprocess.call(["chcon", "-u", user, "-r", role, "-t", type, = path]) + return ret =3D=3D 0 + + +def restorecon(path): + print("Restoring selinux context for {}...".format(path)) + ret =3D subprocess.call(["restorecon", path]) + return ret =3D=3D 0 + + try_stop_units =3D [] if is_systemd_host(): maybe_stopped_units =3D [] - for arg in sys.argv: + for arg in args: name =3D os.path.basename(arg) if is_modular_daemon(name): # Only need to stop libvirtd or this specific modular unit @@ -149,11 +171,10 @@ if is_systemd_host(): if is_unit_active(unit): try_stop_units.append(unit) =20 -if len(try_stop_units) =3D=3D 0: +if len(try_stop_units) =3D=3D 0 and not opts.selinux: # Run the program directly, replacing ourselves os.execvpe(prog, args, env) else: - print("Temporarily stopping systemd units...") stopped_units =3D [] =20 def sighandler(signum, frame): @@ -164,12 +185,48 @@ else: signal.signal(signal.SIGQUIT, sighandler) =20 try: - for unit in try_stop_units: - print(" > %s" % unit) - if not change_unit(unit, "stop"): - raise Exception("Unable to stop '%s'" % unit) - - stopped_units.append(unit) + dorestorecon =3D False + progpath =3D shutil.which(prog) + if len(try_stop_units): + print("Temporarily stopping systemd units...") + + for unit in try_stop_units: + print(" > %s" % unit) + if not change_unit(unit, "stop"): + raise Exception("Unable to stop '%s'" % unit) + + stopped_units.append(unit) + + if opts.selinux: + # if using a wrapper command like 'gdb', setting the selinux + # context won't work because the wrapper command will not be a + # valid entrypoint for the virtd_t context + if os.path.basename(prog) not in ["libvirtd", *modular_daemons= ]: + raise Exception("'{}' is not recognized as a valid daemon.= " + "Selinux process context can only be set w= hen " + "executing a daemon directly without wrapp= er " + "commands".format(prog)) + + if not progpath: + raise Exception("Can't find executable {} for selinux labe= ling" + .format(prog)) + + if not progpath.startswith(os.path.abspath(here)): + raise Exception("Refusing to change selinux context of fil= e " + "'{}' outside build directory" + .format(progpath)) + + # selinux won't allow us to transition to the virtd_t context = from + # e.g. the user_home_t context (the likely label of the local + # executable file) + if not chcon(progpath, "system_u", "object_r", "virtd_exec_t"): + raise Exception("Failed to change selinux context of binar= y") + dorestorecon =3D True + + args =3D ['runcon', + '-u', 'system_u', + '-r', 'system_r', + '-t', 'virtd_t', *args] =20 print("Running '%s'..." % str(" ".join(args))) ret =3D subprocess.call(args, env=3Denv) @@ -178,9 +235,12 @@ else: except Exception as e: print("%s" % e, file=3Dsys.stderr) finally: - print("Re-starting original systemd units...") - stopped_units.reverse() - for unit in stopped_units: - print(" > %s" % unit) - if not change_unit(unit, "start"): - print(" ! unable to restart %s" % unit, file=3Dsys.stderr) + if len(stopped_units): + print("Re-starting original systemd units...") + stopped_units.reverse() + for unit in stopped_units: + print(" > %s" % unit) + if not change_unit(unit, "start"): + print(" ! unable to restart %s" % unit, file=3Dsys.std= err) + if dorestorecon: + restorecon(progpath) --=20 2.41.0 From nobody Sun May 19 15:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1689891653; cv=none; d=zohomail.com; s=zohoarc; b=ZTa3ERfQ4qKfYLnGp9j/zx4EziSEcVhWWpdmIz6Kfa1rg3Wqmxswysq9dn3QYblifQQCcUm0HhHFcBt+QBPRx1PiSSi3vw1bneyiEtSGQU704xCz3/eDMs6S2EScvPAIUmqJzxJVuf97X4GRtMz59fkKCmYt//MvF4N18Z1q6pE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689891653; 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=MLBZ+A7qQcvcVKQ1NWNFtvL7ciKfqtO5iaLYpL5NRAc=; b=On3CBidQiAi4snOjGnCNUXj7RxezWMuFUzjq6Wg1TZGHLrlcJ7F4O3w7tKTMV5V/VJNBvNa1Juo4F5lHyY+6hcRBbCIOI1xP4oqzeLwh7jlb9f9Rkcl9h8otOjW6WgRlAk9LZSPfTO+xUc7bBsXd57raSitfW8hYcHI+ApwHpF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 168989165320549.60315443164029; Thu, 20 Jul 2023 15:20:53 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-19-9LFYx5KvPK2FaFsp65F9mw-1; Thu, 20 Jul 2023 18:20:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1E032381AE65; Thu, 20 Jul 2023 22:20:37 +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 B1B85200C0F2; Thu, 20 Jul 2023 22:20:36 +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 BF09E19376EB; Thu, 20 Jul 2023 22:20:24 +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 A394A19452CA for ; Thu, 20 Jul 2023 22:20:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5B9ED40B4CCC; Thu, 20 Jul 2023 22:20:13 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.8.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B0E140C207D for ; Thu, 20 Jul 2023 22:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689891652; 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=MLBZ+A7qQcvcVKQ1NWNFtvL7ciKfqtO5iaLYpL5NRAc=; b=R0yPYFaIdqYgnU7k2e7HUsOBb6Kk/Infk9LblSwiZFnI+NTWuf0wW7ggQE5RXMv5W81e8+ akA4h4XcXdYOd2RzfqFLnbpf9YnVi5QJfBvu/aagENHl092qag50zkAsEHlVj6ndSkiZ2s 33GWQOlg572bWQCsUSZHS9Xrn7yJmHI= X-MC-Unique: 9LFYx5KvPK2FaFsp65F9mw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 36/36] rpm: update spec file for for nbdkit support Date: Thu, 20 Jul 2023 17:20:03 -0500 Message-ID: <20230720222003.411549-37-jjongsma@redhat.com> In-Reply-To: <20230720222003.411549-1-jjongsma@redhat.com> References: <20230720222003.411549-1-jjongsma@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.4 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: 1689891654427100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Require libnbd-devel when building the qemu driver, recommend nbdkit packages. Signed-off-by: Jonathon Jongsma --- libvirt.spec.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libvirt.spec.in b/libvirt.spec.in index 1f77cd90b7..616087e849 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -312,6 +312,7 @@ BuildRequires: util-linux BuildRequires: libacl-devel # From QEMU RPMs, used by virstoragetest BuildRequires: /usr/bin/qemu-img +BuildRequires: libnbd-devel %endif # For LVM drivers BuildRequires: lvm2 @@ -767,6 +768,9 @@ Requires: numad Recommends: passt Recommends: passt-selinux %endif +Recommends: nbdkit +Recommends: nbdkit-curl-plugin +Recommends: nbdkit-ssh-plugin =20 %description daemon-driver-qemu The qemu driver plugin for the libvirtd daemon, providing @@ -1068,8 +1072,10 @@ exit 1 =20 %if %{with_qemu} %define arg_qemu -Ddriver_qemu=3Denabled + %define arg_libnbd -Dlibndb=3Denabled %else %define arg_qemu -Ddriver_qemu=3Ddisabled + %define arg_libnbd -Dlibndb=3Ddisabled %endif =20 %if %{with_openvz} @@ -1258,6 +1264,7 @@ export SOURCE_DATE_EPOCH=3D$(stat --printf=3D'%Y' %{_= specdir}/libvirt.spec) -Dyajl=3Denabled \ %{?arg_sanlock} \ -Dlibpcap=3Denabled \ + %{?arg_libnbd} \ -Dlibnl=3Denabled \ -Daudit=3Denabled \ -Ddtrace=3Denabled \ @@ -1321,6 +1328,7 @@ export SOURCE_DATE_EPOCH=3D$(stat --printf=3D'%Y' %{_= specdir}/libvirt.spec) -Dglusterfs=3Ddisabled \ -Dhost_validate=3Ddisabled \ -Dlibiscsi=3Ddisabled \ + -Dlibnbd=3Ddisabled \ -Dlibnl=3Ddisabled \ -Dlibpcap=3Ddisabled \ -Dlibssh2=3Ddisabled \ --=20 2.41.0