From nobody Sat May 18 14:54:25 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=1693259128; cv=none; d=zohomail.com; s=zohoarc; b=m4uZlh0i5SHkU9PlKB6JbrOll3dPTPxcbLNkIAHy9g2iNS2S0/vB4Q2M2CEybJhL9nkSK6KREwj6meL8pX5z6SCJ1G2B37G9/tsf3hz/OubG9oul96fe7QiblL4NEqxZZhSUM34Lhnw0DDw84tPXnZqYhz8c0lkbW4yxap7IeUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259128; 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=MBvCOylgLX6nvd3+uktz1yrCsu+dZEbsvNmV/xsEfhs=; b=HIaPjnenBB8p6jDLPxTQgAkzECmWGJtdCeNfH4kFBKQk1Za9/IkC2orqSrCu8niMVsXvknTogpAB2CsGztGP4tG3WNz5cEFSKQYKfI4d6xVobVRFa5+JUFlERZtSvAspx1x4mGvRUDSW0nN4N4Pnlk8m3Acx1gRW56o4LxFFQgc= 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 1693259128717634.2933959554349; Mon, 28 Aug 2023 14:45: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-60-WvhA7aOnPWejEm8GtsrqFg-1; Mon, 28 Aug 2023 17:45:18 -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 63DCC80559D; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 183D71121318; Mon, 28 Aug 2023 21:45: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 792CA19465B9; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D579D1946588 for ; Mon, 28 Aug 2023 21:45:11 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B870D140E963; Mon, 28 Aug 2023 21:45:11 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E005140E962; Mon, 28 Aug 2023 21:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259127; 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=MBvCOylgLX6nvd3+uktz1yrCsu+dZEbsvNmV/xsEfhs=; b=gFdTOwUHky8sE5FAunTlL2TtlHotnOqdefx/u0PQx267YGwlcqAcb4C9Cif/GvcuzCiFiI JvxfcHdsAaV5i2vd2es9S8kyvYs80xKMoIb+1T5gtAnLk1znoOO9H6mClCZjW6Sjr8xMc4 GtnI+EmhVop2MbbYUAq7UqpjJeO+paU= X-MC-Unique: WvhA7aOnPWejEm8GtsrqFg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 01/35] schema: allow 'ssh' as a protocol for network disks Date: Mon, 28 Aug 2023 16:44:36 -0500 Message-ID: <20230828214510.903890-2-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259129936100001 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 de3bd1c35c..4a475f5c36 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2179,6 +2179,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 6e63f8a2eb..1b76b32812 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1254,6 +1254,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 Sat May 18 14:54:25 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=1693259174; cv=none; d=zohomail.com; s=zohoarc; b=bOp2lqQADAsBubDgWRPXPt3zkVGy5pqSGSWhMfRO5d6NM3WvUEauPtyd2RfZ4ULP+AeWEBkuejNZkp/ZDe1LrKSBlY8T7+WbwMAL9PoiTS5bCfVD96OQB3o+rAqBHxQxdiLsjRMSJ2mDA6bU3hA1H8FwkjAKiB6xspvFxTmQ6gA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259174; 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=AEXtJfliRxBd6x82cDCoOSJ/4xjRiBJ8cK5If2GDxbU=; b=QV2V44LcUNgIpM3ovIniP5imeyIWnQWQpAJOaNUYnlAI9he56Bsuy7c/Sa2d86f7/HikSyLok7fFjcqIzvadQmPzegCo/xyaYd7I3Z0mw4eq3I/WSVCFzvLIC932QXTOcp7JLXcCJ5xv1dcG9JjQUxhvv6D+CRW26JgBZFW/HdY= 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 1693259174418960.8833459778386; Mon, 28 Aug 2023 14:46:14 -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-573--svqEjvBOIuxiBkrEydgww-1; Mon, 28 Aug 2023 17:45:17 -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 07011299E74B; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 142B81121319; Mon, 28 Aug 2023 21:45:14 +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 0EEBB1946A45; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 17EE51946588 for ; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0AF1C140E963; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CBC84140E962; Mon, 28 Aug 2023 21:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259173; 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=AEXtJfliRxBd6x82cDCoOSJ/4xjRiBJ8cK5If2GDxbU=; b=Qd52BDeGNRcuKQpcMy4pomPmsqexzNQ4KnEub0u4a+D8lr6InyPFWKUgbwJPbNkaykDwxQ PVBAXR1+L4h53ICRUbV3a7eFuVGxmlKovPNEi7EJycV1vAm0JOueCn2CzXNBNAIU4D7CCP fXnQtXA9dTKfpN8ATe1+grUbThkAt7I= X-MC-Unique: -svqEjvBOIuxiBkrEydgww-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 02/35] qemu: Add functions for determining nbdkit availability Date: Mon, 28 Aug 2023 16:44:37 -0500 Message-ID: <20230828214510.903890-3-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259176113100013 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 | 200 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 50 +++++++++++ 4 files changed, 252 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..e4e8fd568e --- /dev/null +++ b/src/qemu/qemu_nbdkit.c @@ -0,0 +1,200 @@ +/* + * 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_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 Sat May 18 14:54:25 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=1693259126; cv=none; d=zohomail.com; s=zohoarc; b=lqqK+FYWDCwdsaabJ5Q0uobfHBhBZ8eFWzNbQ8RDikZhgUZbL6Ci6z+O2eeBXB5Ls3S+LfIp9drRuVwIS6RzrCXwvis0oTV/VXHT0dR8eTouzn4ybWjaAQySTeX8+1qDyNqqJChsRN9xNpxAtnFu29eyiBW+phu3oGqOFqbVWCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259126; 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=DB++S6+maEvgpSneh5etuvrkeU8xREeRsHKOjGDEvcA=; b=Tv0EP73CJ3LUMJulAEVfd/9UhySN5mCrk89cvMYQoi47uId6jlB24CT5KTfxvFmjOdHkqCUJLohPJPT/peGLdoQAPng6J6Zje6AvyutcYuSG7SUIS98cGNIg+UNGM+TrRQ8hlbHbup5fwM5nVeVGlobIl1GBCOpfF/HGNg78uEo= 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 1693259125798710.4200653178476; Mon, 28 Aug 2023 14:45:25 -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-222-mc9SXpTiPA2lXWydWM8MNw-1; Mon, 28 Aug 2023 17:45:20 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 069E8185A791; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DB30401051; Mon, 28 Aug 2023 21:45:14 +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 4B4A01946A52; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 68B7D1946A44 for ; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 499D1140E965; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EACD140E962; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259124; 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=DB++S6+maEvgpSneh5etuvrkeU8xREeRsHKOjGDEvcA=; b=Q7HLno00h0keOTV96Y6uOLR5WkbZgwBAFkWS3z2S+ujWpQh7K2nFrDo6e4tlhSrAoKMacX hZfMDGnBe+S85e3sbuqxeUlkcDKtx+OHqiR+dNWRevwmPnVSpRz3csu9sfLr2XsQVRD+ai RdJAhni/xygM8uraxLAbmMvCK8RjHy4= X-MC-Unique: mc9SXpTiPA2lXWydWM8MNw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 03/35] qemu: expand nbdkit capabilities Date: Mon, 28 Aug 2023 16:44:38 -0500 Message-ID: <20230828214510.903890-4-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.10 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: 1693259127718100001 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 e4e8fd568e..58828dd89a 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" @@ -38,6 +39,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 */ @@ -51,6 +56,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; }; @@ -175,9 +185,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 Sat May 18 14:54:25 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=1693259226; cv=none; d=zohomail.com; s=zohoarc; b=gA5KhgQMrKZFqxbxRzLWDg4aw3W8o4YfikJAe9bDu+p6QrZX2S9SMyL+je7RbZ6P/upsi75wSWnxEsKdjITINgVrIiokjgmh6Y9oRgNLETC29TZ5MknWBmt8AUQ/NdPZz8QKDe/UNJJjtCFrgc3+tsw/ibLtaVGtGN5Up7/r4U8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259226; 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=EzmYUvEpa784kWQGwL8C83AYeVYLcVWM0GfMVNeEWpLR/tSC2bwJMJwik10OXbXtx2PRh3HCtJKHl97GXEyDheDI0zzhiOgByeZ2pYwY5H6R9SswY+QmRmyWufUSlOxUXNoJ3F/qmmAzXWtdi9/Gq3fzuK7v4bulMCa8EJnr9dA= 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 1693259226942840.9705348022795; Mon, 28 Aug 2023 14:47: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-463-PtKIcQk1O1CEWd5g2PgZtA-1; Mon, 28 Aug 2023 17:45:43 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E801C1C29B0B; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2AE946A3A2; Mon, 28 Aug 2023 21:45: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 0848F1946588; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A2EC01946A44 for ; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 86378140EBD7; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5BD9F140E962; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259225; 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=Juk8jySeNz9G4/POU8nC7mNQzHlrefCAfs6A/r/UT1mRinNmcYYVAPX2Y3PxSeZwI/aD0s yRUsq5Wm4oek9EruRqSPJWinm3Kw4n6mg1pxP0A/KkABCQImgaMiaI9LoWZHV+P5HM5zot 6AE9vSmZ6FN/l2+xLFswvUMgJBoxwTo= X-MC-Unique: PtKIcQk1O1CEWd5g2PgZtA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 04/35] util: Allow virFileCache data to be any GObject Date: Mon, 28 Aug 2023 16:44:39 -0500 Message-ID: <20230828214510.903890-5-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.10 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: 1693259228962100011 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 Sat May 18 14:54:25 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=1693259143; cv=none; d=zohomail.com; s=zohoarc; b=WY41aVhDDRi9K5WrOtRx/uUKrCTwYwUkkkaK+GU1mCPc6/XjWR9/c66OsHRQm12DTWd6YBozUAeCDtbCJpQcVMrjRD3GgmpWtkeYak4Z09w7FIGOc1xpz+xdDYLpmJH0U3s+bjIDV7rUFA9gwYiYexx/grgbnM7UO95b/eLCgJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259143; 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=3zJaT8f7QR3G5uQXpwlSTpCGcMBYIFxSokjmSmAFr+4=; b=lO5zjqul45hmj4Atq0DH9/SC6WahONAv4TJbjUSo+wghcwwo1eozvz4kCK5Y1N65FaMvNskM44Qe7gICw8DvwGfoeIK5JJimdHaYsd4ES7+AiqXsABqeGEYplv657K5Cne/bDNOLr2jM9dy/d2I6fQh7jktI1VRXLkOD1Eszzbs= 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 1693259143714812.9425316315529; Mon, 28 Aug 2023 14:45:43 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-35-rFNXIENIMdSraXK2JQiyPw-1; Mon, 28 Aug 2023 17:45:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 754C285CCE8; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B0BA2166B26; Mon, 28 Aug 2023 21:45: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 C3B3A1946A7D; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DF9CD1946A44 for ; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C2B81140E963; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98A22140E962; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259142; 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=3zJaT8f7QR3G5uQXpwlSTpCGcMBYIFxSokjmSmAFr+4=; b=BVw4RBcIdzDiR8wpf/TMo52rYiVbtJLS+2vtZV7DZH9i8vUMPD6iHTa1+NvW7cx+WBSArk VF6r9cLurDqHug+dCGEppWzhGWrDWiWGu2wVWSi0diYvEZzPV/0ieiX2hPjwyW2cYcsvlC bnO+9l+m9cNlGnoD+hzqD4XFsvBSHM8= X-MC-Unique: rFNXIENIMdSraXK2JQiyPw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 05/35] qemu: implement basic virFileCache for nbdkit caps Date: Mon, 28 Aug 2023 16:44:40 -0500 Message-ID: <20230828214510.903890-6-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259145777100005 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 58828dd89a..9828f562f7 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -201,7 +201,7 @@ qemuNbdkitGetDirMtime(const char *moddir) } =20 =20 -G_GNUC_UNUSED static void +static void qemuNbdkitCapsQuery(qemuNbdkitCaps *caps) { struct stat st; @@ -240,3 +240,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 Sat May 18 14:54:25 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=1693259169; cv=none; d=zohomail.com; s=zohoarc; b=aBxUfK/RjayAlocu0yOuIGUALESodys3rE5c3X5eK8boP2/dMGtJonubF3arxw8LZO/+d35+uPWLgAhiZSbGbQOSrwqiraTLLaiW4+Eq8zUYKliux2YT7eB1QZGHVBTG0j6NbUmPcxVFkqu4sB0xRtqE+aeiEwIS2URfPiE0ELg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259169; 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=kWEmYkdBi2zPSZhhCEmTk3nn8kjz8JNfaLmwG8hWpNQ=; b=jNi63dBVAnHP21765cK8ZQUebxvBPWxe4yuo4KfA3YmrbkTc6VBaNUn9QV2pS0Mixerzulay3UhKyAcwD2tBx2Fho3HM/OrAwvyky08XdvPimF7MhQ3poBxY/URqRyP9auiKA7+wMUHsOAOcsGx48tRmlfsv0Z0i7uJfnhE9v0s= 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 1693259169826584.0172884841515; Mon, 28 Aug 2023 14:46: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-226-PQXJ2YYUN3iqvPJs-azFrg-1; Mon, 28 Aug 2023 17:45:34 -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 AE7728D40B1; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96CEC40C2071; Mon, 28 Aug 2023 21:45: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 5E58B19452D3; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1D6271946A4A for ; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0D280140E963; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6828140E962; Mon, 28 Aug 2023 21:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259167; 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=kWEmYkdBi2zPSZhhCEmTk3nn8kjz8JNfaLmwG8hWpNQ=; b=Kcgb4aCZEP5ZPfT/Ot+pBBGrEtEqgXZFIxox8yRT1OVtHFy5ylbV4X5QrZsXo4JL9j5O49 4JcpOWKZSlv7T5ENGNwQ6bVOcr5XVRsJoIHtYO3HdVBluyZuH2MpTrpBZZK/vPLinrFNDt n2+ZhbbfC90GsiPuL+mAyipeHAoPl3g= X-MC-Unique: PQXJ2YYUN3iqvPJs-azFrg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 06/35] qemu: implement persistent file cache for nbdkit caps Date: Mon, 28 Aug 2023 16:44:41 -0500 Message-ID: <20230828214510.903890-7-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259170554100003 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 9828f562f7..97612b637f 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -312,11 +312,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 Sat May 18 14:54:25 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=1693259125; cv=none; d=zohomail.com; s=zohoarc; b=jeAaZGuanHzh0g0ycsA4qmIDrmwK4S1YYbTl+u/sPtz2vrtmOLwqJeSbTOUj+J+Bnsa8PYPftb9Dr8v+KijZxlAJSyLLcQXJm4ABjDRLCcUuW8sJYPRZTW0e+OQA5I9HO6cMzu/sFiDHXN1iOCzy/nIP2CUtGZCtZQmi8iN1zxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259125; 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=34myDEo1bLOMbLqCqXB3Y1/xShfJGhBuZE4SHOf4riY=; b=cK80xhgLAy+J4pr3GejIVsVdxTKEKvpBsHqF54nUiYjeObTjpof+VXKYNy7TimnzVEVI9QUtS2nfZcLvip1HvQ2xq9u/bIeP26Z0xwiwGTSg4LTtibi/cKhMjW6EoeUtU2MFlW/qHkY6DcU9kXCYX33QTQ3H+wlyLcqlKaHP97I= 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 1693259125069792.1106342458102; Mon, 28 Aug 2023 14:45:25 -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-280-UfgTOeHjPH-0PIf5zUZT4w-1; Mon, 28 Aug 2023 17:45:19 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 636F93C0FCB2; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 491362166B2B; Mon, 28 Aug 2023 21:45: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 880F61946A40; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 68BD31946A66 for ; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4B6D2140E963; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20612140E962; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259124; 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=34myDEo1bLOMbLqCqXB3Y1/xShfJGhBuZE4SHOf4riY=; b=fslGtUW46xO/kVDNPxRfKm+5TnPQChQ7ZvER338XQoTF1SmrgNqpibNQsIpeJ/pWtXdLfg qL+XWQ3lvu4dlLKIB+Btch9QyofAwZpBmydQgoI1i5eLz0+QN5JG9EJOF1B83ZAkDRCABW 3LBqenRZn9GoZbWHF6LCdWellY16ZtM= X-MC-Unique: UfgTOeHjPH-0PIf5zUZT4w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 07/35] qemu: use file cache for nbdkit caps Date: Mon, 28 Aug 2023 16:44:42 -0500 Message-ID: <20230828214510.903890-8-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259125495100001 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 5db42f0753..ad8428948b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -845,6 +845,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. */ @@ -1078,6 +1080,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 Sat May 18 14:54:25 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=1693259129; cv=none; d=zohomail.com; s=zohoarc; b=dvEGLynOif6cm2gGDUfSRx8K82plsSRF8dL1D2/7Ti6gubL+wP7/NdzVWRISmGba+uSOcj6GOe9iCuFjDw4osxP7RvbrEKn6tM/5zrJ+pYx0eMWa9m8MdubZ2pPsoY0QcGBQQCwbupShSUXnjHdiZqkPa8mkZbmfSdw043f5Cwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259129; 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=PelqRrwRbRaECtXC2oiUjDxYzegwemWvD4n3T7ETPr8=; b=HN8jkEUUMUmgShmvV10iwr7PIbYAgHkjaQp55YMf6V+HWjsRY+bibK5tOn1oju7EPDFsJFtB4DLU6wbI0SDDMut/t7im+1mQhyS4cueM+p46lU+MfS7/aW1wAPd3mWzAlD1+8OWzbB7gW+bmCvD9ju4ort1+0pwHZqYQK1gA8HM= 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 1693259129670437.1052673570779; Mon, 28 Aug 2023 14:45: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-460-eI_EHXGcP56WSt4mi48l1A-1; Mon, 28 Aug 2023 17:45:22 -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 706643811F4F; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C759140E962; Mon, 28 Aug 2023 21:45: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 CB6E519465B3; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 96B771946A66 for ; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 88B42140E962; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E3AD140E964; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259128; 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=PelqRrwRbRaECtXC2oiUjDxYzegwemWvD4n3T7ETPr8=; b=Bci3JpnXnszI1o/aKzEhkKV0jDlzr7wMdmz9eyzhJE9hZ2HhQ4112GZ81TM2JDqYmFH5lj fLmemysznFfbd+HGWRUWPR0uDTWTp4kIAj8nMvwpfxXJDeH7kwYbEYA1w5bq85hRl3JlVh 873Y7nzujsAOWo6foB4VNOyVmRTAtYo= X-MC-Unique: eI_EHXGcP56WSt4mi48l1A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 08/35] qemu: Add qemuNbdkitProcess Date: Mon, 28 Aug 2023 16:44:43 -0500 Message-ID: <20230828214510.903890-9-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259130241100003 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 3f811d064f..a0360e8d1b 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1656,3 +1656,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 bfeddc7746..5a2eb4868a 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 @@ -10471,6 +10472,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 @@ -11300,6 +11329,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 786f239495..89edc75fcf 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 97612b637f..12c721f7f1 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -549,3 +549,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 Sat May 18 14:54:25 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=1693259133; cv=none; d=zohomail.com; s=zohoarc; b=n0jlFH9AH+iS5vRafGQ4a3ASzOtMewC5OmRzLprWSxZH727XAqgC9KWuAG18qipboPuFZcpuwulqsaQmAbv533KSzEi96KT+HiSE+bHRSq+d9Nd+ZZwdtqPZpkEIu72sp5xJgKni0ggIKNMH0bOHngZ0J29anolPWLUfinNHOyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259133; 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=hUDGyg5qinMiVjRZmXJktJLFG5QVZHuF19LeRl9tXA8=; b=OPAcNsy8p/sXj8ENCpbaM6bQWzXCeFev/DVWrrB0ShNUTGwq68tcuJBJGQqFUmwSaTojuxpDzp55dNCAw2TXo6+3GGk0SoFu15XBBe2w2TLhTb10p4C1tUc1vKscWPoI7IKWUF4KCvIW/wo6Hc4TKUKzl5WZe13UK12bkjUX3R0= 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 1693259133892590.6368792340277; Mon, 28 Aug 2023 14:45:33 -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-50-fwtFph5WPwi_qNE--SP0KA-1; Mon, 28 Aug 2023 17:45:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 563DA805BFB; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3DFB2166B26; Mon, 28 Aug 2023 21:45: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 22A7B1946A6F; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F0EB719466DF for ; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C61D1140EBD7; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C391140E965; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259132; 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=hUDGyg5qinMiVjRZmXJktJLFG5QVZHuF19LeRl9tXA8=; b=WRHVXw9tzwpVvUBhoXWV/iNoRhOxVTe2STNAcW+uQxEG/lCO1OWhL1gNb2cG09px35yOk9 iSxYkgP6HnFpK+1GQ/Dm24gb77OHThhymaaClNEf6K7qvZCo2/43BOiUtgUrE6/u2hMzmI gRHRNpKvLtfroL9hUzh/7S6g/USsXjI= X-MC-Unique: fwtFph5WPwi_qNE--SP0KA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 09/35] qemu: query nbdkit module dir from binary Date: Mon, 28 Aug 2023 16:44:44 -0500 Message-ID: <20230828214510.903890-10-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259135600100001 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 12c721f7f1..9a2a89224d 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" @@ -39,10 +38,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 */ @@ -56,6 +51,9 @@ struct _qemuNbdkitCaps { =20 char *path; char *version; + char *filterDir; + char *pluginDir; + time_t ctime; time_t libvirtCtime; time_t pluginDirMtime; @@ -129,18 +127,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 @@ -152,6 +179,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); @@ -214,15 +243,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 @@ -267,9 +296,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() || @@ -421,12 +450,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; @@ -482,8 +521,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 Sat May 18 14:54:25 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=1693259136; cv=none; d=zohomail.com; s=zohoarc; b=RzGGm1OSjAtJ7THLKFhz+Ut5nghFxSKZCpIRCL70XtQsH305uaSOtMqH/5KTcmGZ+nlaopSzhGe9udDvGFa62/imhNcm4ON47N+WtxCw0HtZNgFza6bTmIC+Z4l2SkdHgzAOe7RTi9cMn+eh/e8x1cIdLNOex+4OSkbq5IoeIiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259136; 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=djG2NMnPlcMAll/xvNzzyeLYacQvvVOZlNDD5f+wnjM=; b=Lgx9091eYr6j3wM+elIwAdDs6p38UGO40pV3ezIwQXH9iPQrXhd8t4Ritvj1Seabha4XQICoMTUuUZIEWuS94sU5PcrKMzzTkXBW2juax8pChIfx+VAjljW6fIafKOSgUo0rtKKJPAfMEkU/nqvc8DBnn+IQYWs/gF01mboi0MI= 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 1693259136218909.4696665292121; Mon, 28 Aug 2023 14:45: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-74-4sjY47Q2My-b5hbe2fXbzw-1; Mon, 28 Aug 2023 17:45:27 -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 BE6F33811F43; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A911F1121318; Mon, 28 Aug 2023 21:45: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 6DC0C19451C5; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1EE8719465BC for ; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0FFF9140E963; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9246140E962; Mon, 28 Aug 2023 21:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259135; 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=djG2NMnPlcMAll/xvNzzyeLYacQvvVOZlNDD5f+wnjM=; b=XmO3nVdKkN0SYPQ+huBPJF2dViS6rV2CpeD8vQVOWEsoEGGBZjggLSokYSbeGTYuMmwvJU sfpKhhDo89C04bzP8VEqiDuDcOlstv1gh8ye1LUthhwI84eZvyKDGTpyDF0uZZoMEH6kaf hNS1YIeK0oFNhA795Y7c4mo4WzbE9rY= X-MC-Unique: 4sjY47Q2My-b5hbe2fXbzw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 10/35] qemu: add functions to start and stop nbdkit Date: Mon, 28 Aug 2023 16:44:45 -0500 Message-ID: <20230828214510.903890-11-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259137558100004 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 9a2a89224d..6bf962d0f1 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" @@ -666,6 +668,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) { @@ -674,3 +838,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 Sat May 18 14:54:25 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=1693259169; cv=none; d=zohomail.com; s=zohoarc; b=W79ykHUM0OFzparb/5MYyOFEKqibf0HfIib0c2me5Ft1DJhzgJX8s4k1WdfjDiVlQhyoANn5zOyy3b58RFxlGlEfPxlfMTd6F8SlkD+7KTJfere+zOVp1mcNqrxWaKKpi/riyMhFNfCOPijcXl7Mt5wH9EO5rDiJACho0gf41sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259169; 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=DL5HAjcp8+pOxrXyOm7zTxHboeDXa5yYeG79LgYMEjg=; b=J/OVMPDcNUf8Puss5mtBxzR3GWSmGsi4l33FuiNBD//9tLuVcf5XqhDgw3btrBcerof3ksVtw36uGidNmk9TS9JLBdiOucekjNQyi7wc3wb3AOwsy8OtpS9eVffJg1Cdc9W4S1k6DcyqfHkqGiV2GVTUeg9v3x/n6gSRX4GBOMA= 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 1693259169783106.56126841813034; Mon, 28 Aug 2023 14:46: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-381-O76whbh9MCSInp7ou0IlMQ-1; Mon, 28 Aug 2023 17:45: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 85B0B3C100D6; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B4122026D68; Mon, 28 Aug 2023 21:45: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 C07FB19451DE; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 64C8B19465B6 for ; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 51071140E962; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22DFE140E966; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259168; 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=DL5HAjcp8+pOxrXyOm7zTxHboeDXa5yYeG79LgYMEjg=; b=A+xaZAy2H2wKfNKay0ULut+wmbF3HV5yR6FDy+zsX0SR37Jnrv4Sm7i6B/4XXTgo1hFMpL gPkttZ8Q0YoQNnW0nMM/zsP3Jy3sB/9kW3ayThka9W9cvKkvFf38efLiQ5688gZEn9+7zU BVLtAjGv3G9uzBxeZA3PYJZlpXUsc4g= X-MC-Unique: O76whbh9MCSInp7ou0IlMQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 11/35] Generalize qemuDomainLogContextNew() Date: Mon, 28 Aug 2023 16:44:46 -0500 Message-ID: <20230828214510.903890-12-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259171660100005 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 5a2eb4868a..d79f9879df 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7119,7 +7119,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)); @@ -7128,7 +7129,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 89edc75fcf..a262555c8c 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 a6ed69cfe2..e0385d11be 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7616,7 +7616,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 Sat May 18 14:54:25 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=1693259141; cv=none; d=zohomail.com; s=zohoarc; b=DzRsqTaeD4iCWp5R1Iw1m7c6DuBMUKjPrCnBv7WobbBr1hukadZhyOlwgMKpSipaqD2KWUjU03z3FNrbY91vBM6Rs87QFWGiy3b/nuKO72CWMMWQ9ZsEgIe8rojAkPg35jX3yTHwhLivw9uPFFZJtZ0ovxbEA800iPI2IZG0ry8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259141; 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=V11v4NrzyZPAYGYPEabkQnt1LAvlL+6+JF5JCk7fidM=; b=d9dSsJkRQuPz8oyxzc+qv1xtSMU9xPnq2cIZdwnXWmiTWwt3sOusMVcF/Y1s2z+bVGgCDmRRf/ZKw6g5Gfp0l+an0bTwQ+kTDfWOd4xCARQOMqSWdgxLu1cXHTB9grK2n2QU1LX5OBBMX1OV8CUZdLeAAwLI+1CJO2B8XNsTzy4= 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 1693259141822218.70573126529382; Mon, 28 Aug 2023 14:45:41 -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-510-PUdQlNbLNCi07zmNgbC-LA-1; Mon, 28 Aug 2023 17:45:24 -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 4804785D070; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29E6D40D283C; Mon, 28 Aug 2023 21:45: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 AC55919451D5; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AB6AA1946A71 for ; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 97409140E964; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 634B4140E963; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259140; 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=V11v4NrzyZPAYGYPEabkQnt1LAvlL+6+JF5JCk7fidM=; b=Xv3I+mMwuugmfu2mxfXT7OEhxgyERckBTQJ0p9OQoekni9zfbjKxgbnCa0oWp3yjqCqvtd NqD2bEt0ymAEnqs7XuT93r7EZlkIApK5ZoYsv+/U9TIVApKwb65ufFIKR3Cp3nYidMyy+C XWEWsdlzbRRy+fBOQNqAlegPG8ASQcs= X-MC-Unique: PUdQlNbLNCi07zmNgbC-LA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 12/35] qemu: Extract qemuDomainLogContext into a new file Date: Mon, 28 Aug 2023 16:44:47 -0500 Message-ID: <20230828214510.903890-13-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259143601100001 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 d79f9879df..23608f95bd 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 * @@ -6882,7 +6845,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; @@ -6935,12 +6898,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", @@ -6961,7 +6924,7 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver, void qemuDomainObjTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainTaintFlags taint, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { qemuDomainObjTaintMsg(driver, obj, taint, logCtxt, NULL); qemuDomainSaveStatus(obj); @@ -6970,7 +6933,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; @@ -6988,7 +6951,7 @@ qemuDomainObjCheckMachineTaint(virQEMUDriver *driver, static void qemuDomainObjCheckCPUTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuDomainLogContext *logCtxt, + qemuLogContext *logCtxt, bool incomingMigration) { qemuDomainObjPrivate *priv =3D obj->privateData; @@ -7020,7 +6983,7 @@ qemuDomainObjCheckCPUTaint(virQEMUDriver *driver, =20 void qemuDomainObjCheckTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuDomainLogContext *logCtxt, + qemuLogContext *logCtxt, bool incomingMigration) { size_t i; @@ -7076,7 +7039,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, @@ -7093,7 +7056,7 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriver *drive= r, void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainHostdevDef *hostdev, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { if (!virHostdevIsSCSIDevice(hostdev)) return; @@ -7106,7 +7069,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 @@ -7118,163 +7081,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: * @@ -7332,31 +7138,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 a262555c8c..ddd20e67b4 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..6ad60b7b4a --- /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 e0385d11be..e03d0d8b4d 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 @@ -2300,7 +2300,7 @@ static int qemuProcessWaitForMonitor(virQEMUDriver *driver, virDomainObj *vm, int asyncJob, - qemuDomainLogContext *logCtxt) + qemuLogContext *logCtxt) { int ret =3D -1; g_autoptr(GHashTable) info =3D NULL; @@ -4664,7 +4664,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; @@ -4678,20 +4678,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 @@ -7566,7 +7566,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; @@ -7616,11 +7616,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; @@ -7656,7 +7656,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 Sat May 18 14:54:25 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=1693259177; cv=none; d=zohomail.com; s=zohoarc; b=E9SQ1iJTmPQ58XcOaWIyYUWT4G9GANuYy8FDzh0/1973lJHFRm46vnfjvWyJmU51ffZFmfpaMmGf3UTzlsh5BiVSPAOuQTtuTPn7BUIGoovwo1Utk9/bHWeJ3iUuGAp3sLMHFvrkWRtjAwrE0+E7rGPI9p9/2oLOBvOjFx6HNoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259177; 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=m3g5XW58EaRP6oFO37vhujsxRstjvtIO7HjsLacxBgI=; b=BvYymX4MUZEk65+Z8KyzeFL4puRj35nziRtFBq+B3vSQ+UY7vLRIUw6K7b6bt08dg2M19lLJkEYV3iSZcK31+TCIdfwfqP2sNX98haWYUoIlspHZay+A64SsUXM6h4pnN+kwH750aTCzL/k6lKOPi6Yp9Ap3fb6T3UcQ72WEvYc= 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 1693259177454554.0817680649919; Mon, 28 Aug 2023 14:46:17 -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-296-SLU6-Vm9MR20rOBm4q8wjw-1; Mon, 28 Aug 2023 17:45:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A2A9823F85; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05CD62166B28; Mon, 28 Aug 2023 21:45: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 458E61946A4C; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0406619452C6 for ; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D4552140E966; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9BB1140E963; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259176; 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=m3g5XW58EaRP6oFO37vhujsxRstjvtIO7HjsLacxBgI=; b=CJHI7wsCJQ+IdvxdP6dhANo6m+olpI6y422dIkTu+iLhCfhFJ0NWd24f6YeMV7QmZMS2dv KtvoSAx8hOV7+G44GUyG3bhAj7KHIFOejuvYeASseIz8jLTcXqyg9t7ymxwsDEz/NnBh7/ mnWtwIOcBbqpJun8zeiigsumEGYJmgo= X-MC-Unique: SLU6-Vm9MR20rOBm4q8wjw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 13/35] qemu: move qemuProcessReadLog() to qemuLogContext Date: Mon, 28 Aug 2023 16:44:48 -0500 Message-ID: <20230828214510.903890-14-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259177980100015 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 6ad60b7b4a..738e908bc3 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 e03d0d8b4d..a77d2ba7de 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 Sat May 18 14:54:25 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=1693259136; cv=none; d=zohomail.com; s=zohoarc; b=KBi6JbfFuX9VjZcL0vPA7YbImO6AqwBToT/8n82vW99s/SktpPvLYxFcyLr8UZBr84mMc4LhCvsFespFLbbn7y5NUiPjj39oM4chQ6uOKCkOUvTTSQMxaQeHrmLV1sugFEluU28hAPAzAgdmhTtxGZE6iFxQJaFdcuGVmMdt+ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259136; 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=lUWg967418F7/v+phEw8WUXGn3twK60cLfdAYe2cSc0=; b=ZwACMzK8yxG4DP73ADSEbl0nHZ5oUeeCxDy5xCjQOwtNGE54A2AYN5SWIkIvsAYe7BAJic3k2EEth/6/BZvD864R0HZT+j6YveyKt13+74piU2mvJZVlyF+b9QibcmmR7u6sFQ6qV6mM6SSVhdQeJs5u1jGe6y9CdQwFhBMIqB8= 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 169325913646320.09724216603763; Mon, 28 Aug 2023 14:45: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-113-ntQIZhcnN2W0N6z5MWIQ_g-1; Mon, 28 Aug 2023 17:45:26 -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 E9B5B3C0FC95; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6BDEC15E6A; Mon, 28 Aug 2023 21:45: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 186E61946A63; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2CB3F1946588 for ; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 205AA140E968; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7DCD140E962; Mon, 28 Aug 2023 21:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259135; 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=lUWg967418F7/v+phEw8WUXGn3twK60cLfdAYe2cSc0=; b=ai6geLu80cQUqFj6E1hST9FiwEDr/G8mmB2WN60lCNPZCe7JKWcS6fG5spNTnVw+DnenQn 5HFFbcAQYPVHA3qVv2AKsaackuymed72VT3yHTI5caVpEFGZrxpUIE/ZPXIlsMaWlAfoEp VMbOmvlK/0aUs8po4IBAB3qxb4ClKKM= X-MC-Unique: ntQIZhcnN2W0N6z5MWIQ_g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 14/35] qemu: log error output from nbdkit Date: Mon, 28 Aug 2023 16:44:49 -0500 Message-ID: <20230828214510.903890-15-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259137537100003 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 6bf962d0f1..2d70e72c42 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -852,12 +852,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) @@ -899,6 +910,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 Sat May 18 14:54:25 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=1693259144; cv=none; d=zohomail.com; s=zohoarc; b=Nq4YsezWahsWSXtkImu25Ya88ceCM7LCoxv+BuR+SLaZKWXyE3nl3BXeE6ruynMmg5FB9UpkOxQXDQ3AnMhnlXjxrDjlxxoSDzeX6NR1nC3puVaU0/+H2JWL8cRxEkVozK8JKAmxZl6hSY9TKKRbaWGIeRtjz+rERmsQfJwBUwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259144; 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=/rF9WLa/rjy3okTZRJ5mIvDJSDXAMEk36UZx047tEOU=; b=iz2K+mJljIYiR3fbsgsNvkg/sKpNiYWELmiXYW+QXq7TUInO5HgLw1u8h5o1RAjTkaTxr8JP6gu40ZEW0SJC821/497KpbFNV7H4nI0rg6HAanUyoIr+4chKsv50FcTO7QDF9vzpMBC6cJ7tVhp0t9Oa4TG+Z65YDhEx1apchiQ= 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 1693259144895955.7191661740865; Mon, 28 Aug 2023 14:45:44 -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-511-GBQP_2M-N-6a1ES99-N_7A-1; Mon, 28 Aug 2023 17:45:37 -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 5176E1C05B13; Mon, 28 Aug 2023 21:45:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C37A40C2078; Mon, 28 Aug 2023 21:45: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 148B319452CD; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7CB121946588 for ; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5EC40140E963; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33CA1140E962; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259143; 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=/rF9WLa/rjy3okTZRJ5mIvDJSDXAMEk36UZx047tEOU=; b=DwJ8JZqt/5pXfebYSh01qw4Tt2Ck/Thso0wh+SpWxza51R7mj1rVOmo3NyU130LZAYEH/I ckDj6MEW9jikxVWOD1g4A7qj8nE1bL3qPRhEJMYFExdmudBJ8dEG3pFLFVOR3PI/kawHDd hQy3tRXa9U0G3MaNC60G7Zi+EPwBsb8= X-MC-Unique: GBQP_2M-N-6a1ES99-N_7A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 15/35] tests: add ability to test various nbdkit capabilities Date: Mon, 28 Aug 2023 16:44:50 -0500 Message-ID: <20230828214510.903890-16-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259146436100007 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 2d70e72c42..81861bae4a 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -290,10 +290,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; @@ -334,9 +340,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 1b76b32812..d64c21ae17 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -611,6 +611,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))) @@ -831,6 +839,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 fdbad16abe..9a607ab5a3 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -50,6 +50,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 @@ -288,6 +292,7 @@ void qemuTestDriverFree(virQEMUDriver *driver) virObjectUnref(driver->caps); virObjectUnref(driver->config); virObjectUnref(driver->securityManager); + g_clear_object(&driver->nbdkitCapsCache); =20 virCPUDefFree(cpuDefault); virCPUDefFree(cpuHaswell); @@ -487,6 +492,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; @@ -780,6 +791,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; @@ -1054,6 +1073,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; @@ -1072,6 +1096,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 7845ac7cb6..ad6874fdc3 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 @@ -80,6 +82,7 @@ struct testQemuArgs { bool newargs; virBitmap *fakeCapsAdd; virBitmap *fakeCapsDel; + virBitmap *fakeNbdkitCaps; char *capsver; char *capsarch; const char *capsvariant; @@ -95,6 +98,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 Sat May 18 14:54:25 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=1693259151; cv=none; d=zohomail.com; s=zohoarc; b=PjwzyLb/HAOkWrpkYDvQGCDdHkKThgOaPmuhvMFZaSwM5SkWcOMHYZI8zQQFq0IiO3ZFyaYJxOnMMvije/lyyXm1SJrL9Qx5omRaAo4DbhmoanTRrjAf//fs5OkjHlS2u4+GCdcTErEg0eFa/0Uf5DiY9//oZJ1vrm52ZwlJABU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259151; 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=xVczPliuCBtyATSu1LuZA0Bi/OLnlBn1EKzy+sSIhbA=; b=OkT53Gv585ShIZ91XEGx3KXn0IbL9aHwqt2+mVYluAIKdnoARxo+lSsl1VFdX3BtMeTrkuLTkzgehU20xqrdXlY0hN6yfWRPSfoLoFPNb6T5pP+bxflNc3lZJbA+JUkhEKXHCEZoaAozOamwyci2y17cyBTTA/fZA9C49SGtdj0= 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 16932591515551000.5089922517105; Mon, 28 Aug 2023 14:45:51 -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-672-DRyh4lqsN3qsUPosAkOPqQ-1; Mon, 28 Aug 2023 17:45:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E5531049BA7; Mon, 28 Aug 2023 21:45:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 203E52166B2C; Mon, 28 Aug 2023 21:45: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 3789619452D8; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id ACA761946588 for ; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9D4BF140E970; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71F8B140E962; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259150; 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=xVczPliuCBtyATSu1LuZA0Bi/OLnlBn1EKzy+sSIhbA=; b=fg9g0z0hl/jYXnDOz6TcUiSoM4OI/ioTL6tiD2egegTELbRSN/uQKWsRj0jllhIR2CMM2U 4u0IRB4c+8poLqX+A+kZ+t6MEeUxBaBPb0/FEcEjPVRsNDB9BYqpO9roLSZv768roOd4BX sCadv2uMxTw81iogNK01FuMa0kL/uHE= X-MC-Unique: DRyh4lqsN3qsUPosAkOPqQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 16/35] qemu: split qemuDomainSecretStorageSourcePrepare Date: Mon, 28 Aug 2023 16:44:51 -0500 Message-ID: <20230828214510.903890-17-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259151793100001 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 23608f95bd..951f3127d9 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; @@ -11000,9 +11016,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) @@ -11093,9 +11112,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 Sat May 18 14:54:25 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=1693259226; cv=none; d=zohomail.com; s=zohoarc; b=Gecfi0FKJMnCayo4Yr8HbFSWi/wq4kr+LHTT/dOt85qIgb4ub4bXTLL5KWJkJ8lJCxR84/MqRZqX10dKM81ILBir3/sK6FgyGHGriHodnG9MAKtE+ACeLqIict++ZUZ551QHtYk+jKIL1Z0aSCxcjy9XgRoniCarBRk3cvumgfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259226; 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=GxEDnsmy2GTMfziXOg8Pb5zKhTErMIEsglgOt/fkkKc=; b=GMWJq0AcGyCXzZUD4S4m5dDb/SsBcTKHakmFFmjfMzu82i3u48f4XxYjGEvjWJEfG9sNZ7pZX3wBAICLF19R9p+xkee6wSXWTvy/86VoRS9VaJdepKU6z8ghx9lVTy4WnFbEVBIWvB/xPMc0fDWKsLNVmngDSPjLMfoGn7Ee1Qs= 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 1693259226241721.0260317547909; Mon, 28 Aug 2023 14:47: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-596-fSif3b-yN5G-RSBt49sISw-1; Mon, 28 Aug 2023 17:45:41 -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 34FAF2834767; Mon, 28 Aug 2023 21:45:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1841940D2846; Mon, 28 Aug 2023 21:45:22 +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 D9CB719465B6; Mon, 28 Aug 2023 21:45:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E79F61946A45 for ; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DA2AC140E964; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0155140E963; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259225; 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=GxEDnsmy2GTMfziXOg8Pb5zKhTErMIEsglgOt/fkkKc=; b=KUxeaCEwlOQz94RMTXNZ0Y6CKKTEHVCYZ2flFM4+Tdhf8U+9k0QswXKrt3lZZGYWsWOpj/ cLcyvmgy0vIRJW34BHzbizUC1xucs5iEDujxanWFjPRyZnwwIvoCN2Bu4qMRn0OtIz+3lX vTGyNApgukFx+IPWRVI1rBYhxTwrfSg= X-MC-Unique: fSif3b-yN5G-RSBt49sISw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 17/35] qemu: include nbdkit state in private xml Date: Mon, 28 Aug 2023 16:44:52 -0500 Message-ID: <20230828214510.903890-18-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259228320100008 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 951f3127d9..8429ce1028 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 81861bae4a..e3923ab4f2 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -627,6 +627,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 a77d2ba7de..d90990d8a5 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8992,6 +8992,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 Sat May 18 14:54:25 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=1693259144; cv=none; d=zohomail.com; s=zohoarc; b=fq5GcZlBj+Oc9maetNIEYwyIpf2LKVdm12/q3V/JP0fNu2fiQ6NT69hAZMtStrXSwLrQBIk0UCog45zRKQcmqpoYGrQx7VA6WnxkOuKrYR/CcNrYTCblykNRoYrMw7rMuXLSZcPUiV4iAHAs6tpjKX5iF2cr+iur0OETr9C0SSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259144; 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=9QfEW9cQFX2auPwFu2TxFTQzLbiuBk9u5C1MJi14hlU=; b=f1Z6NejGoUVlnxqUwh76V5T4lBr3ePBsTvxkyXHDJYltUlz45ws5vScwljn3hathSxq1c56KEH5e/wyMyBV/vrUNaQ/qh3Q0l7bY6bkBU29LswgoU9Sm5Zix2JMkT8LWbdQlXUUXRCL+3JYbsF5hUkKdqfPz5uKtyUnIyRk7wUA= 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 1693259143929668.9235342014655; Mon, 28 Aug 2023 14:45:43 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-523-hIsdOzoiMMqrDBsrIfYejA-1; Mon, 28 Aug 2023 17:45:40 -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 85B95823E13; Mon, 28 Aug 2023 21:45:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70510112132D; Mon, 28 Aug 2023 21:45: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 71A4C19451C7; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 31E0519452C9 for ; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2292E140E964; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ECAC5140E962; Mon, 28 Aug 2023 21:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259142; 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=9QfEW9cQFX2auPwFu2TxFTQzLbiuBk9u5C1MJi14hlU=; b=iuxJh7goH7HOYiVn/sWW9k6JdRpP2kXNXVJhNniW5J2iZzE7UtrkhdqJ8/uQ8Zg/Cp6jnA yNgJQuEZk9XA0BTSQcapWpKP/bQqfI8/V9w023kzmWCzdI07WXWLuK/vEnLA6ojH6bvSZr 7wIXo/jCxuO1MhkaAH6l/rKtQ796nNE= X-MC-Unique: hIsdOzoiMMqrDBsrIfYejA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 18/35] util: secure erase virCommand send buffers Date: Mon, 28 Aug 2023 16:44:53 -0500 Message-ID: <20230828214510.903890-19-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259145572100003 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 5f094c625a..899d413dd2 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 @@ -1697,6 +1698,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 Sat May 18 14:54:25 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=1693259225; cv=none; d=zohomail.com; s=zohoarc; b=UWl2fFbQRPi1uoa8nn1hi3P7sOAJl8KgbvKDEyHjCHG/p7xcAcXOYI5a+hvpsMSe0YSDJoEOWh0ojlZtEa5i4GgHVQoWFFNOWNlKhXlaX91ZzkM5oIoF6WxiTeSalVaG/uKVWHg+VRbFJLmb1At7zHGiuK93RU0YSebR7ZHrw1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259225; 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=Ob7AvZ+ZWSTbid1+fMcqOMUPiyidD8vCKT6RXHwj/fc=; b=lP2OUlDSfjyI6HRmZRpV0o6RZp3Q4/8iHVw6F0W84yj089mQqvHUlpnx1jOBf4dwJoL5TWxNYHleg5Ou7r0yhEoOCopxX17BQtmqtjVXsbT8tRt80lDLdzc+1n27zCOa+fZlaYjjGsfkWaGerbZLWPCr1YEZ8/6iKieYhAofC6w= 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 1693259225943225.3107037259125; Mon, 28 Aug 2023 14:47: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-693-bDIt2w8SPRevUI3xnEWt_Q-1; Mon, 28 Aug 2023 17:45:43 -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 EC81118E0057; Mon, 28 Aug 2023 21:45:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94F18111F3B0; Mon, 28 Aug 2023 21:45:25 +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 5FF9519465BD; Mon, 28 Aug 2023 21:45:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6CE0419451C4 for ; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 60011140E963; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35F62140E964; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259225; 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=Ob7AvZ+ZWSTbid1+fMcqOMUPiyidD8vCKT6RXHwj/fc=; b=ZAkpViPVoIK0V5d19SW5/jZxWbgFOnfkXt26tJkRt8EulcMPzOmVSt27S72pZ/+Jz5crNT M54fVLWXFl0bqcu7yYNFnVwa7U+FmVVHUq3HU+aPY4jA3QKblVwgNhE3MkoLSZvu411d3V 9mlcGQOnmQVzWt6EkbmlPlm5VjZrHoc= X-MC-Unique: bDIt2w8SPRevUI3xnEWt_Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 19/35] qemu: pass sensitive data to nbdkit via pipe Date: Mon, 28 Aug 2023 16:44:54 -0500 Message-ID: <20230828214510.903890-20-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259226281100004 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 | 54 ++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index e3923ab4f2..22a67b0748 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -24,7 +24,6 @@ #include "virerror.h" #include "virlog.h" #include "virpidfile.h" -#include "virsecureerase.h" #include "virtime.h" #include "virutil.h" #include "qemu_block.h" @@ -753,6 +752,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) @@ -775,7 +797,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 @@ -799,26 +820,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 Sat May 18 14:54:25 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=1693259186; cv=none; d=zohomail.com; s=zohoarc; b=TGtsC9YD1UddvsXbLPTzqd5sftmwwZ4jrrFuKUrgsHrIH16w9lufUZDl5/NVfshvT7ghOEMR1tdUvUItxKDdYJLyAzqEEOb5Yvdmh0uVR0m+KDjsiAHc2MghWNg0nPwwqJc1ppUXNr22hfORLIIPdICBT2wtkjW1VOG+4e6ba1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259186; 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=JSUPy1pSJ0B7Cqr0Jc/FA8wCel+YMo6kyC3Hu7rRVTQ=; b=Gg6FYFlNbjZbB7GB+5Atv4ADWnBFhixSoEbqL2SYaaIXRILPTC0pSDwBVnXwaf5wtF9pwWRQJdpxgyugBdVOqPw/5YZCdqD9lktF7k87afCR4HkPFWo9ZobgEui8ecGfvQe09rRRQu0afkxjWwYB4vrgCUtk4TrxClgYJ9p601Q= 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 1693259186090531.1640749662611; Mon, 28 Aug 2023 14:46: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-608-FWpWsuM8MbaLqaJhhnn6OA-1; Mon, 28 Aug 2023 17:45:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 840D618A65BA; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EF242166B2B; Mon, 28 Aug 2023 21:45: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 810591946A6C; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B900B19451DB for ; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A9B78140E965; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75000140E962; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259184; 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=JSUPy1pSJ0B7Cqr0Jc/FA8wCel+YMo6kyC3Hu7rRVTQ=; b=gKB8T02RcdjpmyBNUNrEfWmTlkxjpE2TqxSg0fSE5y46G+hmfWpwBUZcOvWrk3u/R7WPWC FRC9cLH5E2mz3bxFydc3SRp3l/phZadMV9BMkTR/iHJ/quAp3dOWMnuVxjBCmbmPWto/00 Mw/IQ+JfZeoP9hrldFqaVGWESJs0lX8= X-MC-Unique: FWpWsuM8MbaLqaJhhnn6OA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 20/35] qemu: use nbdkit to serve network disks if available Date: Mon, 28 Aug 2023 16:44:55 -0500 Message-ID: <20230828214510.903890-21-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259188296100001 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 8429ce1028..46fe5a1cf4 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11167,9 +11167,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; @@ -11184,8 +11189,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 d7d1db8ecc..dc06486922 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); @@ -4491,6 +4496,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 22a67b0748..299d8824f2 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -752,6 +752,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, @@ -939,6 +973,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 d64c21ae17..0304f66f1d 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1208,6 +1208,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"); @@ -1252,6 +1253,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"); @@ -1262,10 +1266,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 Sat May 18 14:54:25 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=1693259168; cv=none; d=zohomail.com; s=zohoarc; b=Zz7Zdh89I6gF+jBwZqbebySR4tegRHHzaBhj1SQFoUlY5IUFv53HvflcAz2visdImp5dkuzElx4he1qCyFR1kQ/KZAuwN3LC0sf4Sh/q3rFm9n1iM3tOBHvqB3ssfNiE+oJAKhHUUgg7A5uhRzrJCeR0fH7sjhLv9XTofcUTpv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259168; 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=zHJh7kce0dxPq8YksDEHp0tEJPqjz3H6hXJ3wS1bLGw=; b=LoeSqYPCDCyUc+PZrGDX6UAdmxqgCTaH9Lpjld8ui54AOmBuIR0DzuTYSGZW2LWn4TWIEAEbdTTCbcFPsLo/0k9HRS2v8mkWibvBgrLAiVUE3zn5G2DLwMdnARfeJwxp0c79p2JSAsmdsCecTraZqn0c9WtsqTSczbCENoliW2o= 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 16932591683391007.4379656231936; Mon, 28 Aug 2023 14:46: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-147-WZI7OVY6OKCyadgnJIFb1A-1; Mon, 28 Aug 2023 17:45:41 -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 C003728EC101; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98346400F362; Mon, 28 Aug 2023 21:45: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 C56BE1946A79; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0292219451F0 for ; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E6A03140E963; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC902140E962; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259167; 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=zHJh7kce0dxPq8YksDEHp0tEJPqjz3H6hXJ3wS1bLGw=; b=WFVrCOOUyP343KDP0VVkrYHJ+vpVivRH2uzkvATbHdhIUqXM24Vfbkh1QIlQ9B3swB+Nvk oMlzboL0KaPo/bPMKWNDr9e5+p2QXw6lwpZ4St/LgtvOx+9M5VD8NH0Wd7j+93cyX6rusm Tud+l0mQjrXTPlqwX1PQ6exKC7+mJ/c= X-MC-Unique: WZI7OVY6OKCyadgnJIFb1A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 21/35] util: make virCommandSetSendBuffer testable Date: Mon, 28 Aug 2023 16:44:56 -0500 Message-ID: <20230828214510.903890-22-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259169654100001 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 1e3e407097..e4da5388e7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2117,6 +2117,7 @@ virCommandNewArgs; virCommandNewVAList; virCommandNonblockingFDs; virCommandPassFD; +virCommandPeekSendBuffers; virCommandRawStatus; virCommandRequireHandshake; virCommandRun; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 899d413dd2..7d7ce4297e 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 @@ -3515,3 +3507,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 Sat May 18 14:54:25 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=1693259283; cv=none; d=zohomail.com; s=zohoarc; b=mIjNS+5ucxs5nuSbZ5S6SUfstKRLD1VI0zqFBjH4Oecc372b2MThPwDwuD6waium1l91XVPevmhutAEewBOcXiZWFX5SrZ/FpQYkEufcuAhoGuPMelmwRg2K13eIPIOnJMJ2dtR9jqqCV3n29WwkgfWj2QEwVd+vw3DTWYD3XuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259283; 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=2ItDpoJR6fqqJZqWkp5+BNuRZ4BZEp+mPrdx5aJy0s0=; b=B02T6uQsEPc1lBknrMLQNrvTr+rL5ukPSMq7q4uu0ovgv3GXPSRWIVEzk8G+pNqU6eBubluRRV+Yu1A7t9K5V+lMLzTc4azM/ybJtd4s18jOzpyfrDUg+YhzCz+AyTW4e9BEf1mSyklP3mOd8N7KyoD73ck/Ua6OBYpqOr4GcFg= 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 1693259283663183.49868987733942; Mon, 28 Aug 2023 14:48:03 -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-222-catuAAIZOSqOHi53EdXctg-1; Mon, 28 Aug 2023 17:45:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 275A9107852F; Mon, 28 Aug 2023 21:45:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6CE82166B38; Mon, 28 Aug 2023 21:45:25 +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 9E1B419466DF; Mon, 28 Aug 2023 21:45:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3E11B1946A4E for ; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 31880140E964; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07C5B140E962; Mon, 28 Aug 2023 21:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259282; 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=2ItDpoJR6fqqJZqWkp5+BNuRZ4BZEp+mPrdx5aJy0s0=; b=TEpOHRDzDJatHI5CN3E3HYfI+Ns5olcVbiJvAk8IFyV2Tn521CJhLH/dp7+ds+mFTlvCAO q8XwtfoBK6mUAz4zPQTzIEZpJMTZVm5pjyHXOirgtTPJHBOnCEZu2qxM60eWLoH/lsV32H 4I6P1lrx33nK+aL3nuXhTj7Ds1sQu7c= X-MC-Unique: catuAAIZOSqOHi53EdXctg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 22/35] tests: add tests for nbdkit invocation Date: Mon, 28 Aug 2023 16:44:57 -0500 Message-ID: <20230828214510.903890-23-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259284123100001 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 299d8824f2..df638e99c0 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -31,6 +31,8 @@ #include "qemu_domain.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 @@ -912,7 +914,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 e76289da62..f05774263c 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -456,6 +456,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 Sat May 18 14:54:25 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=1693259147; cv=none; d=zohomail.com; s=zohoarc; b=XeKW08RS9NyneIQlrA19NW7bCXY40pMCyq1/9yDpU/WVlEg4nuEkzQzGCsq1fa7ISwvV6ELnPg92NsemUmTE3JebgBPhzKurkvYR5EskpT2UZ/AczhWHQgQ/pzMw25BqVESkR0JctoFrG2Ay8+emrgTy88/BeyV875GN8vwcz5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259147; 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=dLik1qCEyy6Ek7RUBKBbT4LJ6DDLhQ14NzHBvbGPN6oJ2L7NSAIi2UWGmOSoIWiHqOWeq8ItEDbpDeKhFQIvVnmSLHUIZSy1NARZ0NI6E/JZU8M3KoTH7a/ukabz9ieOafClyM5Hm/N8tThFhyB2BqBqjXjPAEvdI7rrmoZ/WkM= 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 1693259147639501.9038743670112; Mon, 28 Aug 2023 14:45: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-139-2Tt-Q55iONCdMzMJKH_OSA-1; Mon, 28 Aug 2023 17:45:43 -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 7868685CC17; Mon, 28 Aug 2023 21:45:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63368140E963; Mon, 28 Aug 2023 21:45:25 +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 294291946A4B; Mon, 28 Aug 2023 21:45:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8B78A1946588 for ; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6FDBD140E965; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45800140E964; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259146; 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=O6xAO1tApCo1U7h8m9Qo/BLGdMrmtDz7xueniS1ntmudqVkou8EbGLv0hJb3vdQTsbheiy UQ5FgcQlvXTgXWM19WrgkKZBgsfRLMAMH9xLDXb3pJosmryDH57iCGh/5HrAt1O73fI9O3 6dNEum0NklwFom663AglJy7nr/r8LEY= X-MC-Unique: 2Tt-Q55iONCdMzMJKH_OSA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 23/35] qemu: add test for authenticating a https network disk Date: Mon, 28 Aug 2023 16:44:58 -0500 Message-ID: <20230828214510.903890-24-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259148492100013 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 Sat May 18 14:54:25 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=1693259223; cv=none; d=zohomail.com; s=zohoarc; b=AnzDyQ57BZnsT1BbjkZnElSZZChvWDcA9mVcarfUInftqtqQeNcgKWj8r+Snry5hctR2NsDGT3y6QhI38YSVd0N+2Xb78KC53xi9Z2wYP++eP5BeC18p7iciHncEW3krgSlUAy+YUhz+6/OEIziScylCmV4U934k5Xvv/Vxr18k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259223; 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=JcZgHB4id0rsf6yTTXfHxcgsnfFDVVLxEATOfuvY5RQ=; b=G33jRL4PsgqoJOs0rEnrCgIZNi69t8YFYazmMS4aVvdY1HULRSK454zr7OHuzTpoQvlGxo2h7rXMJZzNOssGuLirI2L07nIDiSpVPLYY0oDywkSR0yacgZYQT+Cu0Kxx4bKsv8jLmGxwwukBr20dUZfdZ3dKaJp1BKIW92Tad/Q= 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 1693259223410105.02653562700357; Mon, 28 Aug 2023 14:47:03 -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-374-cp-1_i0cOSqGNo4H5DxVOQ-1; Mon, 28 Aug 2023 17:45:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 888288057AB; Mon, 28 Aug 2023 21:45:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CA412166B26; Mon, 28 Aug 2023 21:45:22 +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 32B811946A66; Mon, 28 Aug 2023 21:45:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C08E81946588 for ; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A45DB140E966; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 826AC140E962 for ; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259222; 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=JcZgHB4id0rsf6yTTXfHxcgsnfFDVVLxEATOfuvY5RQ=; b=MXEZZH3ancDSZI0evPZsQ/flLR/Cu+k1CN268W3vRDFnyK897dkf5xVKbDgm1my0hzuhp2 ql0AOu1bt44qiHXMzrg24Z7mTjDyQaBTcAxNHalPEtyOmVuFMWwTMkQXnm5yrk0bQKFkBm isjaDBsYAgsB90ipqZFYVErHk4JN61c= X-MC-Unique: cp-1_i0cOSqGNo4H5DxVOQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 24/35] qemu: Monitor nbdkit process for exit Date: Mon, 28 Aug 2023 16:44:59 -0500 Message-ID: <20230828214510.903890-25-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259224887100001 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_domain.c | 1 + src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 18 ++++++ src/qemu/qemu_nbdkit.c | 137 ++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_nbdkit.h | 8 ++- src/qemu/qemu_process.c | 13 +++- src/qemu/qemu_process.h | 3 + 8 files changed, 180 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index 965ada483b..8da3b59070 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_domain.c b/src/qemu/qemu_domain.c index 46fe5a1cf4..2b8ece8f19 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11511,6 +11511,7 @@ qemuProcessEventFree(struct qemuProcessEvent *event) case QEMU_PROCESS_EVENT_PR_DISCONNECT: case QEMU_PROCESS_EVENT_UNATTENDED_MIGRATION: case QEMU_PROCESS_EVENT_RESET: + case QEMU_PROCESS_EVENT_NBDKIT_EXITED: case QEMU_PROCESS_EVENT_LAST: break; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index ddd20e67b4..f018b45eb6 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -465,6 +465,7 @@ typedef enum { QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE, QEMU_PROCESS_EVENT_UNATTENDED_MIGRATION, QEMU_PROCESS_EVENT_RESET, + QEMU_PROCESS_EVENT_NBDKIT_EXITED, =20 QEMU_PROCESS_EVENT_LAST } qemuProcessEventType; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ad8428948b..46e089fe0f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4040,6 +4040,21 @@ processResetEvent(virQEMUDriver *driver, } =20 =20 + + +static void +processNbdkitExitedEvent(virDomainObj *vm, + qemuNbdkitProcess *nbdkit) +{ + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + return; + + qemuNbdkitProcessRestart(nbdkit, vm); + + virDomainObjEndJob(vm); +} + + static void qemuProcessEventHandler(void *data, void *opaque) { struct qemuProcessEvent *processEvent =3D data; @@ -4097,6 +4112,9 @@ static void qemuProcessEventHandler(void *data, void = *opaque) case QEMU_PROCESS_EVENT_RESET: processResetEvent(driver, vm); break; + case QEMU_PROCESS_EVENT_NBDKIT_EXITED: + processNbdkitExitedEvent(vm, processEvent->data); + break; case QEMU_PROCESS_EVENT_LAST: break; } diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index df638e99c0..c3fa349922 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -19,6 +19,7 @@ =20 #include #include +#include =20 #include "vircommand.h" #include "virerror.h" @@ -33,6 +34,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 @@ -611,6 +613,106 @@ qemuNbdkitCapsCacheNew(const char *cachedir) } =20 =20 +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); + /* submit an event so that it is handled in the per-vm event thread */ + qemuProcessHandleNbdkitExit(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 + /* This should not be reachable */ + 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, @@ -658,9 +760,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) @@ -671,6 +775,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); @@ -678,8 +785,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 /** @@ -692,11 +805,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 @@ -708,6 +822,11 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, uid_t user, gid_t group) { +#if !WITH_DECL_SYS_PIDFD_OPEN + /* 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; +#else 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); @@ -751,6 +870,7 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, srcPriv->nbdkitProcess =3D proc; =20 return true; +#endif /* WITH_DECL_SYS_PIDFD_OPEN */ } =20 =20 @@ -968,6 +1088,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); @@ -1037,8 +1159,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; @@ -1069,6 +1194,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..f33b049d38 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 @@ -98,6 +100,10 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, virDomainObj *vm, virQEMUDriver *driver); =20 +void +qemuNbdkitProcessRestart(qemuNbdkitProcess *proc, + virDomainObj *vm); + int qemuNbdkitProcessStop(qemuNbdkitProcess *proc); =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d90990d8a5..1020c1a161 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8993,10 +8993,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) @@ -9451,3 +9451,12 @@ qemuProcessQMPStart(qemuProcessQMP *proc) =20 return 0; } + + +void qemuProcessHandleNbdkitExit(qemuNbdkitProcess *nbdkit, + virDomainObj *vm) +{ + virObjectLock(vm); + qemuProcessEventSubmit(vm, QEMU_PROCESS_EVENT_NBDKIT_EXITED, 0, 0, nbd= kit); + virObjectUnlock(vm); +} diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index cae1b49756..86a60d29c9 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -237,3 +237,6 @@ void qemuProcessRefreshDiskProps(virDomainDiskDef *disk, struct qemuDomainDiskInfo *info); =20 int qemuProcessSetupEmulator(virDomainObj *vm); + +void qemuProcessHandleNbdkitExit(qemuNbdkitProcess *nbdkit, + virDomainObj *vm); --=20 2.41.0 From nobody Sat May 18 14:54:25 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=1693259138; cv=none; d=zohomail.com; s=zohoarc; b=dIBLGDErp9a1kVtacrmai62ZSKwiOm4HdrCST0MrPe6qgSbCbxkWzc9JvCwcPAopdv1LoxHGFSdTIW6L7K3bHlGoPfDdcqwZAnxfY+8mR6E3qGdlyCE6Cnhe+lX13IqsXr91BqLpTMRLxWS/ETCsR3SDM21QcqvK2Sit7Wn6MR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259138; 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=YAPESxsCrxqrFSNRrh9qEQO2LLnWnjX/YodnHO1h+N4=; b=EUFPiytFdweXFvy9wSCd844t7Gt2EEt0SDubbPUEbdjY9tQX+r+g61LuxnTl0uXezfiI2qgoXOkdIOGyQFNj5ak9t5LkSFZtVqwN1JZX6aoxLYrwtHhU80ZyX6EQQ2x4Udmrp+Rx7s0A50AddqepThvk3j9wobGWVFH3RTkmTGg= 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 1693259138106144.0304379334067; Mon, 28 Aug 2023 14:45:38 -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-586-2HHeLfLeNBm09nRpKNgolw-1; Mon, 28 Aug 2023 17:45:28 -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 B9E8638149D6; Mon, 28 Aug 2023 21:45:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A367C40D2842; Mon, 28 Aug 2023 21:45: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 9CE2F19451DC; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E685E1946588 for ; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D6230140E963; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5CA1140E962 for ; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259137; 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=YAPESxsCrxqrFSNRrh9qEQO2LLnWnjX/YodnHO1h+N4=; b=eri0DOcAsF20Zzg+Vtiro6ZH/RE7HtaheW1towNGRzbPwxtWd6l8smSjlpjkpqylNaxldk JiQowlqjh5/JIq00tv9vbz5xCzHjymN47sFOZll3Rk4464VaPf6z1zU91rp1MdO4bfHY5r uKJZ9PdS/DDynVoBxQLOyCYmTvzKIO8= X-MC-Unique: 2HHeLfLeNBm09nRpKNgolw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 25/35] qemu: Taint domain if nbdkit restart fails Date: Mon, 28 Aug 2023 16:45:00 -0500 Message-ID: <20230828214510.903890-26-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.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: 1693259139963100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Since the restart handler will trigger at an arbitrary time (when the nbdkit process crashes, for instance), it's difficult to provide feedback to the user if the restart is unsuccessful. Rather than just relying on a warning in the log, taint the domain so that there will be a slightly more user-visible notification. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 2 ++ src/conf/domain_conf.h | 1 + src/qemu/qemu_nbdkit.c | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bb4f1fdb94..8feaf5d055 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -87,6 +87,7 @@ VIR_ENUM_IMPL(virDomainTaint, "custom-hypervisor-feature", "deprecated-config", "custom-device", + "nbdkit-restart", ); =20 VIR_ENUM_IMPL(virDomainTaintMessage, @@ -105,6 +106,7 @@ VIR_ENUM_IMPL(virDomainTaintMessage, N_("hypervisor feature autodetection override"), N_("use of deprecated configuration settings"), N_("custom device configuration"), + N_("nbdkit restart failed"), ); =20 VIR_ENUM_IMPL(virDomainVirt, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ca195a52d2..c0729905a8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3194,6 +3194,7 @@ typedef enum { VIR_DOMAIN_TAINT_CUSTOM_HYPERVISOR_FEATURE, /* custom hypervisor featu= re control */ VIR_DOMAIN_TAINT_DEPRECATED_CONFIG, /* Configuration that is marked d= eprecated */ VIR_DOMAIN_TAINT_CUSTOM_DEVICE, /* hypervisor device config customized= */ + VIR_DOMAIN_TAINT_NBDKIT_RESTART, /* nbdkit could not be restarted */ =20 VIR_DOMAIN_TAINT_LAST } virDomainTaintFlags; diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index c3fa349922..ff5f1c0d05 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -623,8 +623,10 @@ qemuNbdkitProcessRestart(qemuNbdkitProcess *proc, /* clean up resources associated with process */ qemuNbdkitProcessStop(proc); =20 - if (qemuNbdkitProcessStart(proc, vm, driver) < 0) + if (qemuNbdkitProcessStart(proc, vm, driver) < 0) { VIR_WARN("Unable to restart nbkdit process"); + virDomainObjTaint(vm, VIR_DOMAIN_TAINT_NBDKIT_RESTART); + } } =20 =20 --=20 2.41.0 From nobody Sat May 18 14:54:25 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=1693259136; cv=none; d=zohomail.com; s=zohoarc; b=KZjyqn0ElGdU+j2jRln8yQfWDIQEy+ImAenMtqSjH9wHQ+8F9DpGWnU/mnuFZDxsy5DO0OMs+k6IRnNJ+usQoqJBb+8D4h2WXg9rcp5dCnIpa0OtIXIGLlf03Lp5aczHiYH7hIWySNhp//KLVs9mSr2pSshdejIwu6b82vPqj7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259136; 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=G1c7Z5ZuKgls9ICm053cFwp49lH25dIlbqgoeCr7Rg8=; b=Tg5nukoF85/cMoOPk6Dh5ZID1oMGUbc8hRhJ1oEr5Ybyt45+omB1pj0EZFmgIIQjcvX88uUzp2hJNvxiCUZxzXB54RKkCsdQn+RrmukzepwPttfw8U80sktNYk0DAQeEXzXFnzSg2xEg7T/Jx1P+73jvb8ES05zBnSS1443X7NQ= 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 1693259136378110.45476376210911; Mon, 28 Aug 2023 14:45:36 -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-661-mugwjIi7N5yH7Gm9_KxaaQ-1; Mon, 28 Aug 2023 17:45:32 -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 183B78057A5; Mon, 28 Aug 2023 21:45:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2F8E492C3A; Mon, 28 Aug 2023 21:45:22 +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 A01B01946A5E; Mon, 28 Aug 2023 21:45:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 27B101946A42 for ; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1EDA3140E964; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8B55140E967; Mon, 28 Aug 2023 21:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259135; 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=G1c7Z5ZuKgls9ICm053cFwp49lH25dIlbqgoeCr7Rg8=; b=BFulgOarEehnUGU1m0HXRsqhpZhYBIiZbxRf9FF/Wb4Ohc+uL5oh80K73TZRLp14RbIrl6 UfACTjqW2ATtg+StvoDfvGVREAnlHAyAj3NyII107BpOCKz4533Vpz5cJS6R95x2s6vz6G 8S0PW9Z20UkkMor3rM6GAaAO746Xa0A= X-MC-Unique: mugwjIi7N5yH7Gm9_KxaaQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 26/35] qemu: try to connect to nbdkit early to detect errors Date: Mon, 28 Aug 2023 16:45:01 -0500 Message-ID: <20230828214510.903890-27-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259137568100005 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 | 23 +++++++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/meson.build b/meson.build index 8da3b59070..a5ab94c0ba 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 ff5f1c0d05..3e82c90850 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" @@ -1122,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; @@ -1162,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 Sat May 18 14:54:25 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=1693259230; cv=none; d=zohomail.com; s=zohoarc; b=DMC330HZpO/zdv79sj8M4uJ92A885iKuRjY2x8KleN9S/S1xIWgfD473jcjhMLgzfN4Fqq3acSw6YrRrghFczOY2STCBSWa9WVgihO2v3Tcarh0tMwelRfVaapzPkNjoRxwwzTAZc3woJJt1lX6HrX5NilfjxKt33ksN4Sda/48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259230; 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=QVnwMQj4A9bInJGBWZcOJYNJbuE3qAXypiNX8smZyPI=; b=ZtFndH4oJdK3CVZ8zfOBZCbjcpM/ASczK8r+Gmui8m0gag2vqsBChJExB8EsKpUjcJzFc7xFMjb35vTMGxik1IchkdhmI7UQ+xA5CXbp82usQYlvqzl49PGuEnhGJfYfqX9sd26qy6/4Mf3fN5Ha3b28mGqBDMV4YsrtupjdVoI= 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 169325923011027.110757590238222; Mon, 28 Aug 2023 14:47:10 -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-693-con-ZTSSOXa3bGDir19HFA-1; Mon, 28 Aug 2023 17:45:39 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 626612823823; Mon, 28 Aug 2023 21:45:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47B38401051; Mon, 28 Aug 2023 21:45: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 059641946A45; Mon, 28 Aug 2023 21:45:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 741AC1946A63 for ; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5B164140E964; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 316E1140E963; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259229; 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=QVnwMQj4A9bInJGBWZcOJYNJbuE3qAXypiNX8smZyPI=; b=T47KrOWLoI/GYS9RZqyQsRjLNp1dqfJNBOS3kfBxRjK84GgdBk4lZTjkdNOtu9KKGI+RqP 6fq2ZHwYp3CBWIaaHK+dlYvGGdbJigOArHE3bqG+gab+HczUJjgk+x1a92ZX6ynWwSrvnG R/zkAVT2BgHzPwZk7NxXv5RXc+FSE1Y= X-MC-Unique: con-ZTSSOXa3bGDir19HFA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 27/35] schema: add password configuration for ssh disk Date: Mon, 28 Aug 2023 16:45:02 -0500 Message-ID: <20230828214510.903890-28-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.10 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: 1693259232327100001 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 68f54ab3ed..39d4230ec0 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2778,7 +2778,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. @@ -2930,18 +2930,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 4a475f5c36..cd838a475c 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2172,6 +2172,27 @@ =20 + + + + + + ssh + + + + + + + + + + + + + + + @@ -2179,7 +2200,6 @@ sheepdog tftp - ssh @@ -2289,6 +2309,7 @@ + --=20 2.41.0 From nobody Sat May 18 14:54:25 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=1693259285; cv=none; d=zohomail.com; s=zohoarc; b=il3vi2sNo/9vVTvfSOfvunkCjCggCGfLPxK5JEfQzy5LFvVpa4UBCirfMH1OKLOZ3V7GqN+qMKEUpyynWaoR7piyjZygBTkK847/k/v3Knu6E1JHj/ZhIk6KknuiI7OZgHNNpZ5cDfvTU3jf0jyWEtr3AAGKG6gy2glXj7wIxTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259285; 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=MmZ2bK+X+uliZEDO5NhTEpDkmKG/KDQVA3KCJEeNiwg=; b=WDqij1hcbr4w7jbrD+BBa4UhBUP9RTyAw113ful49uACHuuHJC/LT759FbPyXUAPCbECC5dB1BqyNorAVd+xql3M5bMJmmoLWJa6SCGtixH5IQRg+tdMd+mbLQQRS53P/guLA2xC6I5xmGzz0WhvghC75fwUqgspvegKCMNkWUI= 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 1693259285844854.5226145104527; Mon, 28 Aug 2023 14:48: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-120-NeQeIpv6MTa8kwBWPcyffg-1; Mon, 28 Aug 2023 17:45:35 -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 195E585CC02; Mon, 28 Aug 2023 21:45:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0487240D2839; Mon, 28 Aug 2023 21:45:25 +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 D7B3919465B3; Mon, 28 Aug 2023 21:45:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A5BC51946A73 for ; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 990BA140E964; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E025140E962; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259284; 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=MmZ2bK+X+uliZEDO5NhTEpDkmKG/KDQVA3KCJEeNiwg=; b=HCvqfQ6vEGGr5KXxQv2ohKOykKKiImp6om+duofzDZTZ9VwRrvH/dymi7dS0+WUO9TMAas FG9bfhJ2q039SIKCOaiXKAvN6onq30uH2Ypk3pFn6p9A+YlBu3xxm8iKGBVeMVy1Yu3hFd MdZypscXdEjeNQWNrNM32EfQYd2QIyU= X-MC-Unique: NeQeIpv6MTa8kwBWPcyffg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 28/35] qemu: implement password auth for ssh disks with nbdkit Date: Mon, 28 Aug 2023 16:45:03 -0500 Message-ID: <20230828214510.903890-29-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259286708100005 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 | 84 ++++++++++--------- .../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, 134 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 3e82c90850..cedeaa880b 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -936,6 +936,43 @@ 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) + 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 +991,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 +1021,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 +1031,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 0304f66f1d..6de5915175 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1272,6 +1272,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 Sat May 18 14:54:25 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=1693259171; cv=none; d=zohomail.com; s=zohoarc; b=XkKJEViF+sOQyeQsYPktINtQVuDSCJCXRosUzBNW5ufiexqf8IDu6F9zUpVWioLLbgt1J4TZ2pt2KGVrwaq5qorRbC2pRCnPQz+r6v1UBjVDNjPqcemk+GQ++6V9AkqQ4bfDue8OZWrDb03SYZV+KRQ1GF7gohMBNnJQVCfVzkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259171; 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=eMcniMDnjuXApzxe/PHU1LIEuYiSxdAjvUMZK2wFk0Q=; b=Gqohtk5yJCfujqdEo46s7C42MfqLpmvECKPFoOYhT02RKGdIrBTtZqHAvq1vPOYQU0uvUEJIFGDHsI2G6Cezst7tWCLYt409+drGsGzCLkAXf5HSLKSEcQkTG6rB97yfzh2H95CybltQdiW3KWYWk0tucKp7M2e2RqbF4ud8os0= 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 1693259171894398.9467074429115; Mon, 28 Aug 2023 14:46: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-605-Ms3iQa1JPUWSfPiho6uMTg-1; Mon, 28 Aug 2023 17:45:41 -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 33F953C13524; Mon, 28 Aug 2023 21:45:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AAF140C2075; Mon, 28 Aug 2023 21:45: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 CF78B1946A52; Mon, 28 Aug 2023 21:45:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0EAEE19452C9 for ; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D5822140E962; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB5A6140E964; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259170; 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=eMcniMDnjuXApzxe/PHU1LIEuYiSxdAjvUMZK2wFk0Q=; b=bV7lZRobKAB+2uB+CSSu64c7Xk+MRXj8OdXoXCXfScgXsdtSDhO5amnw8mr1hjdPHKIYs9 VtLW82KtWK+Iu7jTc7+Z1bpZCE8q4g074MGMhQU0Cz0bqs/tKbSb8pjHQen7Y68k0PARs0 YhwjWcYPVsphbwdmVl99ikiZboRcOnU= X-MC-Unique: Ms3iQa1JPUWSfPiho6uMTg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 29/35] schema: add configuration for host verification of ssh disks Date: Mon, 28 Aug 2023 16:45:04 -0500 Message-ID: <20230828214510.903890-30-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259173660100007 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 39d4230ec0..9230f540f4 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3021,6 +3021,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 cd838a475c..ca43586323 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2172,6 +2172,14 @@ =20 + + + + + + + + @@ -2187,6 +2195,9 @@ + + + --=20 2.41.0 From nobody Sat May 18 14:54:25 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=1693259225; cv=none; d=zohomail.com; s=zohoarc; b=XCKlfRtroSQiyp+FoSoVgtKgodyimxfU9oQtoA7VJFZr5t4x0ie3tmZZS+JVu8uaQbQIs/oPAuZdv9Qzz7JonVL3ps3AQChV1kIIZ661GzxLNC59BFUjrqhyEHsf/DHMb1V+cwsEPz10Ec0C8SwvvYQv/SreGMBJ2YIhanYSKEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259225; 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=1Tq1OxIY0wVKat0LyFx2DswwQ56bBaQe4pQYMfZ2dyI=; b=IugMGLBRN0+F4oV46xYj87EAYdtPbeEDNA2WmxfXw57IWAXcPG8uBcz8qQqVgBdpDQeYrGgx1vjOERUCnhCzqL4/QtsYv6KspnzZj/mSSidFkWcr3bPc2M5TT6DHx1xD/lVY4aYXbpEZc5ngU23COK7GmL15BJjAICEnxf/21Yc= 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 1693259225598608.7162474097672; Mon, 28 Aug 2023 14:47: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-178-KJqVe5uuOSuTUo6owc9p3w-1; Mon, 28 Aug 2023 17:45:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6110680D1A6; Mon, 28 Aug 2023 21:45:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F92E2166B26; Mon, 28 Aug 2023 21:45: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 E31F61946A4D; Mon, 28 Aug 2023 21:45:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4528E19451C4 for ; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2032E140E965; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8DB5140E964; Mon, 28 Aug 2023 21:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259224; 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=1Tq1OxIY0wVKat0LyFx2DswwQ56bBaQe4pQYMfZ2dyI=; b=imP4uqANsLUCYfSG2L8kA/6GbODX0qeacFIbfh0M1Kfl6pvQ+Oy1w4mfe52Y/LoeAeBnLN mnq0bUiqmi9LGqp6UNuiyijREnpt1sghnIIgUVdZYN4mrp4/9t8tB3tLesyZFCBlKUXpaC iY78OHoqr981GaxRu0pi0pyORqDv+Cc= X-MC-Unique: KJqVe5uuOSuTUo6owc9p3w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 30/35] qemu: implement knownHosts for ssh disks with nbdkit Date: Mon, 28 Aug 2023 16:45:05 -0500 Message-ID: <20230828214510.903890-31-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259226173100003 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 Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 8 ++++++ src/conf/storage_source_conf.c | 2 ++ 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, 46 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8feaf5d055..842b6404b5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7268,6 +7268,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; } @@ -22274,6 +22279,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..906bc36a9b 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -895,6 +895,7 @@ virStorageSourceCopy(const virStorageSource *src, /* ssh config passthrough for libguestfs */ def->ssh_host_key_check_disabled =3D src->ssh_host_key_check_disabled; def->ssh_user =3D g_strdup(src->ssh_user); + def->ssh_known_hosts_file =3D g_strdup(src->ssh_known_hosts_file); =20 def->nfs_user =3D g_strdup(src->nfs_user); def->nfs_group =3D g_strdup(src->nfs_group); @@ -1170,6 +1171,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 dc06486922..bbc5177206 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); @@ -4496,7 +4496,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 cedeaa880b..d0eca1ab89 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -624,7 +624,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); } } @@ -1041,6 +1042,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 @@ -1153,6 +1157,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 @@ -1217,16 +1225,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 f33b049d38..5403c64580 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, @@ -105,7 +106,8 @@ qemuNbdkitProcessRestart(qemuNbdkitProcess *proc, virDomainObj *vm); =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 Sat May 18 14:54:25 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=1693259233; cv=none; d=zohomail.com; s=zohoarc; b=ZML/i2yf68S1vWwcQhbgCQAFq89wR412GXMxQSJW8wC6H1TbBafJuiW19PJ3ELCXrttBVkFGJn/oOpJpvn+L2C/zfjNF114LOtw95ajl5vU4Ze+wTHyU2TpsnZ22O2A/eE+kij1OQuLU3Yp539vtp7RikyG+pp2zP+vCAwt4vLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259233; 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=pGArXqTh02OuGb4LKC5R3Fx1+QkOxCG0tGpbPCDL7wc=; b=nslpv/rsQOYmYDAL2wbmpBqDqdbLY6umPhaZ206VAw6bjz0kVBhGzj3mIi/eiBX1aI5W5MLdWsZdmTzhDBJjGLimgNFBmPT42RmLAFsgZNk7BqJcQFmFfAwWJq/MKIMpx193FIFb2RhmZCPWTJZ9TnRTuPSp7H3OCFSX+Z+PcMU= 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 1693259233155579.6522767818428; Mon, 28 Aug 2023 14:47:13 -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-609-BfyegmZQNJOdqTjrXf0YQA-1; Mon, 28 Aug 2023 17:45:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 70C803C13533; Mon, 28 Aug 2023 21:45:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 451A52166B36; Mon, 28 Aug 2023 21:45: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 20C1C19466DF; Mon, 28 Aug 2023 21:45:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7FA0019451F0 for ; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5E52B140E967; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3358E140E963; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259232; 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=pGArXqTh02OuGb4LKC5R3Fx1+QkOxCG0tGpbPCDL7wc=; b=gj60Wi3fPWBquWeIOjUREofMwSILx1FHBpXW+smTzZFzfWNLXCWal9/wx4tCgzYxIw5dP4 pQlngcJ+hV2SFXb2JdLmf4HspruRw1NLJPGGbJ5AYuR131qcHED3mn6vdha6fPyKiDieGn 8rxVgtLkVCu2vm/TUvCKIFkCndSoQRY= X-MC-Unique: BfyegmZQNJOdqTjrXf0YQA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 31/35] schema: add keyfile configuration for ssh disks Date: Mon, 28 Aug 2023 16:45:06 -0500 Message-ID: <20230828214510.903890-32-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1693259234156100003 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 9230f540f4..2ebd7bb1fc 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3005,6 +3005,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 ca43586323..47c5ee2a31 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2180,6 +2180,19 @@ =20 + + + + + + + + + + + + + @@ -2199,11 +2212,15 @@ - + + + + + --=20 2.41.0 From nobody Sat May 18 14:54:25 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=1693259283; cv=none; d=zohomail.com; s=zohoarc; b=hXFYxQM/v3O8HDUO7RlSEdxLTIIqRENXefcSICgyiNljI6O7Q0jItiXIesgsPjfp/XHL0a6h3KBDF0wSSZ3NXSTE+OqOPe272uicHm8/2/nAfNpbY6Q1DhrvjtqmkHGaGJQf5zFo+0iXGxWPThQI+dsl85dmtLC8hPhfilVpjAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259283; 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=NdhZ6u30RIJHF2YRy6vtEoLFa6RMsiPL027VV+9Yqdg=; b=adhfR6/0PYaqEERTjda1nObI+CjawBCFJW0w/O0xuxEb56EAHdrOu3fOcK8aNmmNoKY3uZxWNvOKn6F4oroEkG4JQpCExwzrer00H/X0u/E6Nq6CFmNUDDxhaxWfBDq8eWCXZbLhhdXsVdaBxpkFhkLpSTY1yni/erZq+Eo6rJI= 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 1693259283636482.0616663924866; Mon, 28 Aug 2023 14:48:03 -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-376-jX8AtdIJM5-OdIqXVjQEQg-1; Mon, 28 Aug 2023 17:45:36 -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 97F45823F87; Mon, 28 Aug 2023 21:45:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82110140E96D; Mon, 28 Aug 2023 21:45: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 4F6641946A52; Mon, 28 Aug 2023 21:45:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AAC1219451EB for ; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9DE41140E965; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70B91140E962; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259282; 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=NdhZ6u30RIJHF2YRy6vtEoLFa6RMsiPL027VV+9Yqdg=; b=WpjvA8gcRGbvs/LtDyprBHa248NGTR9Zs92WvIZe1dwvsebdvMtrNAAQYYqUSDdx3j4fgV dZj3ljQDfAhURjWlwGSHw6raZElMqtZcOWCpLhfzaXBvQHnWgxBmoYkTKxWbFBRj/Yxyhw /Ii4r4v07Ed49LR6x9szKY7TqMxj+pY= X-MC-Unique: jX8AtdIJM5-OdIqXVjQEQg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 32/35] qemu: implement keyfile auth for ssh disks with nbdkit Date: Mon, 28 Aug 2023 16:45:07 -0500 Message-ID: <20230828214510.903890-33-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259284664100003 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 Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 30 +++++++++++++---- src/conf/storage_source_conf.c | 2 ++ 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, 93 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 842b6404b5..929e115bce 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7268,10 +7268,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; @@ -22280,8 +22288,18 @@ 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_u= ser); + virBufferEscapeString(childBuf, " keyfile=3D'%s'", src->ssh_ke= yfile); + + virBufferAddLit(childBuf, "/>\n"); + } + } } =20 =20 diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 906bc36a9b..ce9c1f66c2 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -896,6 +896,7 @@ virStorageSourceCopy(const virStorageSource *src, def->ssh_host_key_check_disabled =3D src->ssh_host_key_check_disabled; def->ssh_user =3D g_strdup(src->ssh_user); def->ssh_known_hosts_file =3D g_strdup(src->ssh_known_hosts_file); + def->ssh_keyfile =3D g_strdup(src->ssh_keyfile); =20 def->nfs_user =3D g_strdup(src->nfs_user); def->nfs_group =3D g_strdup(src->nfs_group); @@ -1172,6 +1173,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 d0eca1ab89..0393850ddc 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -1035,8 +1035,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) @@ -1157,6 +1161,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; @@ -1242,6 +1250,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 Sat May 18 14:54:25 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=1693259227; cv=none; d=zohomail.com; s=zohoarc; b=i6TCEoqyvvkqUXuS3C/QDm959j9VEl6QZLkNtALEi7J6AiNgGgQlEh8ucvSK/Yr8xSJtg0mYQViUvqM92r3MvRwbHi6+TaKOzoa0bvcUQH5rrSP2ZGcZo78NZZ/bR0g4+yCoZpOlQaM91Zy6DtePGYn6a6PrcWddl576JmbF+BU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259227; 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=291vrCE/9X9H5YDh8wHK41mqKY0Xf0/0vAd02IR01e8=; b=QO08sLyETosH/o1padkRGlDMLk3elrkc9a5i7c+m9GPk8d39f6ND0i76IrAfkQFexeCfEmBqFSyjsbIi+X3625y6KJn+ZHINtkTp8uIAMEA7lUcMNkh5OQo7/nJFS7EIsGeUyLq+zM9i8UWVOSX+40qmtr1hUUvb9wzOkCY9ggk= 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 169325922705597.49527910564723; Mon, 28 Aug 2023 14:47:07 -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-501-WUOCrRVoPE-TitDdrIZY0w-1; Mon, 28 Aug 2023 17:45:45 -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 A95061C060DA; Mon, 28 Aug 2023 21:45:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FDC440D283A; Mon, 28 Aug 2023 21:45:22 +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 573791946A4B; Mon, 28 Aug 2023 21:45:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E6E041946588 for ; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D87DE140E964; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ADFCC140E962; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259226; 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=291vrCE/9X9H5YDh8wHK41mqKY0Xf0/0vAd02IR01e8=; b=SjFC5T9d007sV1e4WezOSyjNg1I53Z69YJNnbWBt4jsukXR4eDwKgiqnwjtnBcH9nbIp9h 4NsQcf5udzXz+njSBVXtzIA8Te+w0G7ECYQGd+YjUmVuDAENgb3lRmvfOr1XJG59pcfBx7 KOPDky2GVEr8V+3PM41EF1gUBOD2McI= X-MC-Unique: WUOCrRVoPE-TitDdrIZY0w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 33/35] schema: add ssh-agent configuration for ssh disks Date: Mon, 28 Aug 2023 16:45:08 -0500 Message-ID: <20230828214510.903890-34-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259228289100007 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 Reviewed-by: Peter Krempa --- 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 2ebd7bb1fc..720433617d 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3007,11 +3007,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 47c5ee2a31..d8dd1b8c69 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2186,9 +2186,14 @@ - - - + + + + + + + + --=20 2.41.0 From nobody Sat May 18 14:54:25 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=1693259146; cv=none; d=zohomail.com; s=zohoarc; b=lxaTe7jZzrCdlNeysRb6E8SkNiR6uNMxLRURqi1G+NZrRafSCq0A4XR44OIgd5NHv8SDJRCpwe3UFWRCFbckSbblNNaq7qfJmQ8T2ovkqakiKOPAGrAdjNOhyIQEwnQpzrvPmTe2f6sbQa8D4EqR2QdVF4SD70zJ9eJhrIazLcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259146; 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=AFoiRNLNRrauQJDpIQdsWRP5b1lVL39qNKL8LLmhF38=; b=fbi4RGi0y99Ob00ZlzpNQwm40extCPIQFpihVmB3GFOCCySP1kyma78ta0zYtVCI1rl800EhXWRCErYxv94OcJ3c8ZnBf7RVZEDpJmP5H19qAHH2TcJQN3SCzk1H7GwqBKCDQr0POPuW53vCVkhVsN/hNVv7JvPCtVutzj7CDao= 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 1693259146979871.82771770308; Mon, 28 Aug 2023 14:45:46 -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-44-Hl827bNFN_6H_RMLavWQhA-1; Mon, 28 Aug 2023 17:45:40 -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 9770F830D41; Mon, 28 Aug 2023 21:45:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 788BF111F3B6; Mon, 28 Aug 2023 21:45: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 4DD841946A46; Mon, 28 Aug 2023 21:45:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2F2731946588 for ; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 22D6C140E963; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB8AF140E962; Mon, 28 Aug 2023 21:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259146; 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=AFoiRNLNRrauQJDpIQdsWRP5b1lVL39qNKL8LLmhF38=; b=SKsx4bSAVbp+33pXDCWLAD9NrdOVIDSX72x71KqjL1p7+Ki/UgZ1CFqkvBBS2FmDy0rfxD hZlwM4XtmmnZVdSc/uWYD4q0rFapnBxRpd3Cd+6C4J4522sIYfz2szu4x0oJaJyrblN412 ST7iJ0ZjbDsKf7hWwq7RLrchYecFxrg= X-MC-Unique: Hl827bNFN_6H_RMLavWQhA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 34/35] qemu: implement ssh-agent auth for ssh disks with nbdkit Date: Mon, 28 Aug 2023 16:45:09 -0500 Message-ID: <20230828214510.903890-35-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1693259148000100010 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 Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 14 ++++++++++++-- src/conf/storage_source_conf.c | 2 ++ 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, 51 insertions(+), 8 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 929e115bce..398f40d2be 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7277,8 +7277,17 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, if (!(src->ssh_user =3D virXMLPropStringRequired(tmpnode, "use= rname"))) return -1; =20 - if (!(src->ssh_keyfile =3D virXMLPropStringRequired(tmpnode, "= keyfile"))) + /* 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"); + if (!src->ssh_keyfile && !src->ssh_agent) { + virReportError(VIR_ERR_XML_ERROR, + _("element '%1$s' requires either 'keyfile'= or 'agentsock' attribute"), + tmpnode->name); return -1; + } } } =20 @@ -22291,11 +22300,12 @@ 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_u= ser); virBufferEscapeString(childBuf, " keyfile=3D'%s'", src->ssh_ke= yfile); + 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 ce9c1f66c2..cafa031dfe 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -897,6 +897,7 @@ virStorageSourceCopy(const virStorageSource *src, def->ssh_user =3D g_strdup(src->ssh_user); def->ssh_known_hosts_file =3D g_strdup(src->ssh_known_hosts_file); def->ssh_keyfile =3D g_strdup(src->ssh_keyfile); + def->ssh_agent =3D g_strdup(src->ssh_agent); =20 def->nfs_user =3D g_strdup(src->nfs_user); def->nfs_group =3D g_strdup(src->nfs_group); @@ -1174,6 +1175,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 0393850ddc..a417146426 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -1043,6 +1043,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 @@ -1165,6 +1168,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; @@ -1253,6 +1260,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 Sat May 18 14:54:25 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=1693259147; cv=none; d=zohomail.com; s=zohoarc; b=DzHoLs0iwGArmnZ6GeM3ehVALOYTFxd/cNYGA5h6LKKN/aJkFN2s7lwoXz0UEefq81+Wmmao+TiDoz+BT/luR6+YJzYdPDb5S5gfJ7+NNO8hJH+WFx0XWqyEKqhAuoxL0lo/H1FjXfB508E8Nx2KD1h/q5gJbRAb9lPIMWnsGaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693259147; 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=AjLBdLGd05D8ns9fZDg8Rd+99INFaHZ9IOSgirh7YQ8=; b=dR+SLDBPuh3IAj/DVKbboOJterIq9ougoGre78JMa88+FvOLMWQ6ManP5DJmD4e0U5agRn98vEeNtqgJbOf088n9agRuAUoFst9dGReiRvD2rg7mQTn41NzXsMsBaszi4I/7eQSipUG2G0A4zNbSZuEMAYK6c6eST7HcHF5uNbc= 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 1693259147514516.8245548037698; Mon, 28 Aug 2023 14:45:47 -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-694-D0l02-bAOvWBCThJ8Z6CXA-1; Mon, 28 Aug 2023 17:45:40 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 031B61C0335B; Mon, 28 Aug 2023 21:45:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCA59402D90; Mon, 28 Aug 2023 21:45: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 9337B1946588; Mon, 28 Aug 2023 21:45:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6D1461946588 for ; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5F3DA140E967; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.17.242]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3577A140E962; Mon, 28 Aug 2023 21:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693259146; 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=AjLBdLGd05D8ns9fZDg8Rd+99INFaHZ9IOSgirh7YQ8=; b=h4uynGcE12zM9+8uS02m07vEqCutEVLNIkdp3qidm2yD89pLmTa9tARLlUewOLDZlyVw5K FJvX03MW3pE/PdkvKZw+zUFjHUNA1S+UWbYqKjpBTzwol3hDYIXHW/ySvONT2KWxDCKbTP 1Dd8z30GOiJgu2es4FxTc8ROU63+hl0= X-MC-Unique: D0l02-bAOvWBCThJ8Z6CXA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v7 35/35] rpm: update spec file for for nbdkit support Date: Mon, 28 Aug 2023 16:45:10 -0500 Message-ID: <20230828214510.903890-36-jjongsma@redhat.com> In-Reply-To: <20230828214510.903890-1-jjongsma@redhat.com> References: <20230828214510.903890-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.10 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: 1693259147965100009 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 Reviewed-by: Peter Krempa --- libvirt.spec.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libvirt.spec.in b/libvirt.spec.in index 7157cfe3b4..94cae34496 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 @@ -768,6 +769,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 @@ -1069,8 +1073,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} @@ -1259,6 +1265,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 \ @@ -1322,6 +1329,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