From nobody Sat May 18 05:34:56 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=1661974505; cv=none; d=zohomail.com; s=zohoarc; b=MtKUtb+Jyip0j6HuKEcNdwRec1IFcanrNEyMJ6MOflI1E2LbnOaNcC6C3elsPQxhNW9IQr43t1Ykc/CfHUmbNR8BoRQCqaWt3TaACHllrXfzfMh2iUnhm93T21ga80oCV3xgtw81nMHRI68PD4rK2jqWRXhYXCCMVkaIjrNRJuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974505; 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=+nah2Vhcq6Nd47SfqcLVZAnjH3rW7/PZeIduqj8ISQo=; b=KCdX3sfYWVr96CPYzyURg9Zy4dRBUS4nREDumG6OBPNFE6wWaXcanSuipe5TiY2J2/HVQifmFghmRnKV4iIKt+xLwwX8xU73vvtD35XmrHy1Ap5ylSzGq4v7ZoQvH3bb8rI62YQodB6BQNOf2PP9i8XKqyuNarPHe7b1Vso7RW8= 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 1661974505969170.64654826793299; Wed, 31 Aug 2022 12:35: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-478-UprkluvnOhGs8lnYRn2GYg-1; Wed, 31 Aug 2022 15:33:51 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 298CB1857F19; Wed, 31 Aug 2022 19:33:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 776851415117; Wed, 31 Aug 2022 19:33:48 +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 103571946A4A; Wed, 31 Aug 2022 19:33:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 365331946A40 for ; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2A2472166B2A; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F41052166B26; Wed, 31 Aug 2022 18:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974505; 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=+nah2Vhcq6Nd47SfqcLVZAnjH3rW7/PZeIduqj8ISQo=; b=f5HLm1G/lTwaAojGGD6eU+WBoci80xccViAy7aq++U2KmksYK2L9s3n1m7sAW2j0IskNW3 cxQjEs+Z0wQgXx3xR1TRJCsFMFx6MPMUmq8o0WMl8tBrS+oUtOsr+fAiiPmu2qb3JBhD93 IW7k6v1LrHPVikhQ0rZQFhWODmXDGGg= X-MC-Unique: UprkluvnOhGs8lnYRn2GYg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 01/16] schema: allow 'ssh' as a protocol for network disks Date: Wed, 31 Aug 2022 13:40:46 -0500 Message-Id: <20220831184101.716362-2-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 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: 1661974507069100001 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 and mention it in the documentation. Signed-off-by: Jonathon Jongsma --- docs/formatdomain.rst | 2 +- src/conf/schemas/domaincommon.rng | 1 + .../disk-network-ssh.x86_64-latest.args | 36 +++++++++++++++++++ tests/qemuxml2argvdata/disk-network-ssh.xml | 31 ++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 5 files changed, 70 insertions(+), 1 deletion(-) 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/docs/formatdomain.rst b/docs/formatdomain.rst index 34e4906eb4..4222605ede 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2709,7 +2709,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. diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index bb6b1058e6..b3836b2f61 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2132,6 +2132,7 @@ sheepdog tftp + ssh 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..045474724b --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh.x86_64-latest.args @@ -0,0 +1,36 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/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":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram \ +-accel kvm \ +-cpu qemu64 \ +-m 214 \ +-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 \ +-no-acpi \ +-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 32f1e8ce3b..9ed7152544 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1365,6 +1365,7 @@ 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("disk-network-ssh"); driver.config->vxhsTLS =3D 0; VIR_FREE(driver.config->vxhsTLSx509certdir); DO_TEST_CAPS_LATEST("disk-no-boot"); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661974784; cv=none; d=zohomail.com; s=zohoarc; b=THpgAuzhhtVCci8U61x1vqt/TdhrecVo1M35gKX3ImMESF2OK+omTlZoWPIkvL8LO7dOs4sAaZHNkSqpbfSw/2baLAWT9gjFYwPfImsd+gf4+Khm2QJHsXut9IlehpmlvXgW7Zs1eTtamYCh+J4zvgiHQ4pVIhu0t8MUG26eqCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974784; 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=hK4ArMZPUAkxQvpij617uB4Y9xT61Tbv8KtbwnWMVIc=; b=Jj0p3VtLfQ9wsdMTgAzVmpbyidgBFMywPBsqeOSRH/r0oidc/+oS6tenb8QSTrXdrP73/fdy6/+NG43kQUjkbgRYJiqwnaFajsYJM92NYdKo0rncpIQnGDLxCa9OkGrc34oOqbMWvdDpHmPhMVqtZEM9uh58DB/apbVSiN7MLQ0= 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 1661974784497951.9652623965204; Wed, 31 Aug 2022 12:39:44 -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-66-ogLvtfDtOdOf6eZQe1jGsQ-1; Wed, 31 Aug 2022 15:39:40 -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 3A85218188AD; Wed, 31 Aug 2022 19:39:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26456C15BBA; Wed, 31 Aug 2022 19:39:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id ACB681946A4B; Wed, 31 Aug 2022 19:39:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 816F71946A40 for ; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 739492166B2A; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 428382166B26; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974783; 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=hK4ArMZPUAkxQvpij617uB4Y9xT61Tbv8KtbwnWMVIc=; b=QCC63NE0kcr5HyTFqg8Ka96LGAXpPnYHhsBM1ymogNUXRy3gvlpAUR7wWZZ+Pnj1yJ+Ng+ Xpncfk/vxqdOBebiySwHezr808teFqpeWIbceYeMZAJvugetaZKC1oS6Q0Wc4Ozy6kR5VA n3UPoL6LWlenXPFwRg4/zs0WK/a7tO0= X-MC-Unique: ogLvtfDtOdOf6eZQe1jGsQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 02/16] qemu: Add qemuNbdkitCaps to qemu driver Date: Wed, 31 Aug 2022 13:40:47 -0500 Message-Id: <20220831184101.716362-3-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 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: 1661974784776100002 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. These capabilities are stored in the qemu driver. Signed-off-by: Jonathon Jongsma --- po/POTFILES | 1 + src/qemu/meson.build | 1 + src/qemu/qemu_conf.h | 3 + src/qemu/qemu_driver.c | 3 + src/qemu/qemu_nbdkit.c | 226 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 51 ++++++++++ 6 files changed, 285 insertions(+) create mode 100644 src/qemu/qemu_nbdkit.c create mode 100644 src/qemu/qemu_nbdkit.h diff --git a/po/POTFILES b/po/POTFILES index d32105f7d5..1fd92256d4 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -179,6 +179,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_process.c src/qemu/qemu_qapi.c src/qemu/qemu_saveimage.c diff --git a/src/qemu/meson.build b/src/qemu/meson.build index 96952cc52d..101cf3591f 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_process.c', 'qemu_qapi.c', 'qemu_saveimage.c', diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index c40c452f58..d05c715400 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" @@ -306,6 +307,8 @@ struct _virQEMUDriver { =20 /* Immutable pointer, self-locking APIs */ virHashAtomic *migrationErrors; + + qemuNbdkitCaps *nbdkitCaps; }; =20 virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 707f4cc1bb..943fa8621d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -832,6 +832,9 @@ qemuStateInitialize(bool privileged, defsecmodel))) goto error; =20 + /* find whether nbdkit is available and query its capabilities */ + qemu_driver->nbdkitCaps =3D qemuQueryNbdkitCaps(); + /* 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. */ diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c new file mode 100644 index 0000000000..f55f68299f --- /dev/null +++ b/src/qemu/qemu_nbdkit.c @@ -0,0 +1,226 @@ +/* + * qemu_nbdkit.c: helpers for using nbdkit + * + * 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 + * . + * + */ + +#include +#include + +#include "vircommand.h" +#include "virerror.h" +#include "virlog.h" +#include "virpidfile.h" +#include "virsecureerase.h" +#include "virutil.h" +#include "qemu_block.h" +#include "qemu_conf.h" +#include "qemu_domain.h" +#include "qemu_driver.h" +#include "qemu_extdevice.h" +#include "qemu_nbdkit.h" +#include "qemu_security.h" + +#include + +#define VIR_FROM_THIS VIR_FROM_QEMU + +VIR_LOG_INIT("qemu.nbdkit"); + +VIR_ENUM_IMPL(qemuNbdkitCaps, + QEMU_NBDKIT_CAPS_LAST, + /* 0 */ + "plugin-curl", /* QEMU_NBDKIT_CAPS_PLUGIN_CURL */ + "plugin-ssh", /* QEMU_NBDKIT_CAPS_PLUGIN_SSH */ + "filter-readahead", /* QEMU_NBDKIT_CAPS_FILTER_READAHEAD */ +); + +struct _qemuNbdkitCaps { + GObject parent; + + char *path; + char *version; + + virBitmap *flags; +}; +G_DEFINE_TYPE(qemuNbdkitCaps, qemu_nbdkit_caps, G_TYPE_OBJECT); + + +static void +qemuNbdkitCheckCommandCap(qemuNbdkitCaps *nbdkit, + virCommand *cmd, + qemuNbdkitCapsFlags cap) +{ + if (virCommandRun(cmd, NULL) !=3D 0) + return; + + VIR_DEBUG("Setting nbdkit capability %i", cap); + ignore_value(virBitmapSetBit(nbdkit->flags, cap)); +} + + +static void +qemuNbdkitQueryFilter(qemuNbdkitCaps *nbdkit, + const char *filter, + qemuNbdkitCapsFlags cap) +{ + g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, + "--version", + NULL); + + virCommandAddArgPair(cmd, "--filter", filter); + + /* use null plugin to check for filter */ + virCommandAddArg(cmd, "null"); + + qemuNbdkitCheckCommandCap(nbdkit, cmd, cap); +} + + +static void +qemuNbdkitQueryPlugin(qemuNbdkitCaps *nbdkit, + const char *plugin, + qemuNbdkitCapsFlags cap) +{ + g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, + plugin, + "--version", + NULL); + + qemuNbdkitCheckCommandCap(nbdkit, cmd, cap); +} + + +static void +qemuNbdkitCapsQueryPlugins(qemuNbdkitCaps *nbdkit) +{ + qemuNbdkitQueryPlugin(nbdkit, "curl", QEMU_NBDKIT_CAPS_PLUGIN_CURL); + qemuNbdkitQueryPlugin(nbdkit, "ssh", QEMU_NBDKIT_CAPS_PLUGIN_SSH); +} + + +static void +qemuNbdkitCapsQueryFilters(qemuNbdkitCaps *nbdkit) +{ + qemuNbdkitQueryFilter(nbdkit, "readahead", + QEMU_NBDKIT_CAPS_FILTER_READAHEAD); +} + + +static int +qemuNbdkitCapsQueryVersion(qemuNbdkitCaps *nbdkit) +{ + g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, + "--version", + NULL); + + virCommandSetOutputBuffer(cmd, &nbdkit->version); + + if (virCommandRun(cmd, NULL) !=3D 0) + return -1; + + VIR_DEBUG("Got nbdkit version %s", nbdkit->version); + return 0; +} + + +static void qemuNbdkitCapsFinalize(GObject *object) +{ + qemuNbdkitCaps *nbdkit =3D QEMU_NBDKIT_CAPS(object); + + g_clear_pointer(&nbdkit->path, g_free); + g_clear_pointer(&nbdkit->version, g_free); + g_clear_pointer(&nbdkit->flags, virBitmapFree); + + G_OBJECT_CLASS(qemu_nbdkit_caps_parent_class)->finalize(object); +} + + +void qemu_nbdkit_caps_init(qemuNbdkitCaps *caps) +{ + caps->flags =3D virBitmapNew(QEMU_NBDKIT_CAPS_LAST); + caps->version =3D NULL; +} + + +static void +qemu_nbdkit_caps_class_init(qemuNbdkitCapsClass *klass) +{ + GObjectClass *obj =3D G_OBJECT_CLASS(klass); + + obj->finalize =3D qemuNbdkitCapsFinalize; +} + + +qemuNbdkitCaps * +qemuNbdkitCapsNew(const char *path) +{ + qemuNbdkitCaps *caps =3D g_object_new(QEMU_TYPE_NBDKIT_CAPS, NULL); + caps->path =3D g_strdup(path); + + return caps; +} + + +static void +qemuNbdkitCapsQuery(qemuNbdkitCaps *caps) +{ + qemuNbdkitCapsQueryPlugins(caps); + qemuNbdkitCapsQueryFilters(caps); + qemuNbdkitCapsQueryVersion(caps); +} + + +qemuNbdkitCaps * +qemuQueryNbdkitCaps(void) +{ + qemuNbdkitCaps *caps =3D NULL; + g_autofree char *path =3D virFindFileInPath("nbdkit"); + + if (!path) + return NULL; + + if (!virFileIsExecutable(path)) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("nbdkit '%s' is not execu= table"), + path); + return NULL; + } + + VIR_DEBUG("found nbdkit executable '%s'", path); + + caps =3D qemuNbdkitCapsNew(path); + qemuNbdkitCapsQuery(caps); + + return 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..4baf4d4d31 --- /dev/null +++ b/src/qemu/qemu_nbdkit.h @@ -0,0 +1,51 @@ +/* + * qemu_nbdkit.h: helpers for using nbdkit + * + * 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 + * . + * + */ + +#pragma once + +#include "internal.h" +#include "virbitmap.h" +#include "vircgroup.h" +#include "vircommand.h" +#include "virstorageobj.h" +#include "viruri.h" + +typedef struct _qemuNbdkitCaps qemuNbdkitCaps; + +typedef enum { + 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* qemuQueryNbdkitCaps(void); + +qemuNbdkitCaps* qemuNbdkitCapsNew(const char *path); + +bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags fla= g); + +void qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags fla= g); + +#define QEMU_TYPE_NBDKIT_CAPS qemu_nbdkit_caps_get_type() +G_DECLARE_FINAL_TYPE(qemuNbdkitCaps, qemu_nbdkit_caps, QEMU, NBDKIT_CAPS, = GObject); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661976606; cv=none; d=zohomail.com; s=zohoarc; b=IKom7fe/6Q3pTOmYoMOd0CZhpOhI1a5qgqnPhT4AEiQoy6rrFFUmAHMCUWsEEq4WZPUwXr+X/CL+VC/QV0pqa3XZqQF/LDPNwGVbK2SVhyjxMsVeCXRD5Yicbjhi+XjgPf4gp0Ju1M7bd/llsFeIkNwBZovKhcV3GP6MD4I4AXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661976606; 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=PJZOnoKBkND2y2hwFxBWOLfBNha1nxaxBSatsUzsPCM=; b=aM0Bp9hV8S3Hjo5trkdRmeD1zX5gSVv5IHRkFZCPBqhhDH/cGpOFi/J5yN+KGqycxjB9+agaUmVSl3B1Q/DMarIHhpwOIXozTo35JwLGsTdX4u0OOuX7wZ90b9g7RtC1HUR4h8QWdfnEQgIS7GNaOuWg0iWIRIzeazY3fPk4YyY= 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 1661976606227524.6936593685172; Wed, 31 Aug 2022 13:10:06 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-50-Lqfzl0WgPWmFtQJVFu1IDA-1; Wed, 31 Aug 2022 16:10:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81DFF3804539; Wed, 31 Aug 2022 20:09:59 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E130A4C819; Wed, 31 Aug 2022 20:09:58 +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 BE0CF1946A45; Wed, 31 Aug 2022 20:09:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C906D1946A40 for ; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AE6892166B2B; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86A152166B26; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661976605; 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=PJZOnoKBkND2y2hwFxBWOLfBNha1nxaxBSatsUzsPCM=; b=Vx2VwKPWftj53MH/Q17gE/BU/pJOvpcbpd4qIRjRGVm8wlau5u3xH8iAF+DbZIj+87LWoJ DGA5YFLDM85OlD+ifIux5vCu6/NutntNcOfXFQp+EK4UyF3TAhDMc4O6P3Qf1Ak2IX9UdD 2HrkCrDtnRM610DNHVxcaO7j2IvYMa8= X-MC-Unique: Lqfzl0WgPWmFtQJVFu1IDA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/16] qemu: expand nbdkit capabilities Date: Wed, 31 Aug 2022 13:40:48 -0500 Message-Id: <20220831184101.716362-4-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661976607885100001 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 --- meson.build | 6 ++++++ meson_options.txt | 1 + src/qemu/qemu_nbdkit.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/meson.build b/meson.build index 0b3187ad88..2b0425f1f6 100644 --- a/meson.build +++ b/meson.build @@ -1744,6 +1744,12 @@ if not get_option('driver_qemu').disabled() qemu_dbus_daemon_path =3D '/usr/bin/dbus-daemon' endif conf.set_quoted('QEMU_DBUS_DAEMON', qemu_dbus_daemon_path) + + nbdkit_moddir =3D get_option('nbdkit_moddir') + if nbdkit_moddir =3D=3D '' + nbdkit_moddir =3D libdir / 'nbdkit' + endif + conf.set_quoted('NBDKIT_MODDIR', nbdkit_moddir) endif endif =20 diff --git a/meson_options.txt b/meson_options.txt index 5b43cdbd6b..382174bc03 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -71,6 +71,7 @@ option('driver_vbox', type: 'feature', value: 'auto', des= cription: 'VirtualBox X option('vbox_xpcomc_dir', type: 'string', value: '', description: 'Locatio= n of directory containing VirtualBox XPCOMC library') option('driver_vmware', type: 'feature', value: 'auto', description: 'VMwa= re driver') option('driver_vz', type: 'feature', value: 'auto', description: 'Virtuozz= o driver') +option('nbdkit_moddir', type: 'string', value: '', description: 'set the d= irectory where nbdkit modules are located') =20 option('secdriver_apparmor', type: 'feature', value: 'auto', description: = 'use AppArmor security driver') option('apparmor_profiles', type: 'feature', value: 'auto', description: '= install apparmor profiles') diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index f55f68299f..0ea1b754cd 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -42,6 +42,9 @@ =20 VIR_LOG_INIT("qemu.nbdkit"); =20 +#define NBDKIT_PLUGINDIR NBDKIT_MODDIR "/plugins" +#define NBDKIT_FILTERDIR NBDKIT_MODDIR "/filters" + VIR_ENUM_IMPL(qemuNbdkitCaps, QEMU_NBDKIT_CAPS_LAST, /* 0 */ @@ -55,6 +58,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; }; @@ -177,9 +185,40 @@ qemuNbdkitCapsNew(const char *path) } =20 =20 +static time_t +getDirMtime(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; +} + + 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; + } else { + caps->ctime =3D st.st_ctime; + } + caps->filterDirMtime =3D getDirMtime(NBDKIT_FILTERDIR); + caps->pluginDirMtime =3D getDirMtime(NBDKIT_PLUGINDIR); + caps->libvirtCtime =3D virGetSelfLastChanged(); + caps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; + qemuNbdkitCapsQueryPlugins(caps); qemuNbdkitCapsQueryFilters(caps); qemuNbdkitCapsQueryVersion(caps); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661976156; cv=none; d=zohomail.com; s=zohoarc; b=VEeRWQvpJSLJO52OgB2It0Cs8eySTruqxQorRb7dXvEZxH53Sbw4ZY0IcZs1qzI+L4ACEVPxlfM7CqouaoTkkxDxXY46r4Yt8sxQvi6jGL86jhFl13BpPSo/SJpUj+kVxvAiOWlRBJyy7aSW2FrM9VnPurFJjYB1IkgHA1ph9PA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661976156; 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=iyq8Zm+UnEnUZXB6QHk7CUbjYTeqgCRPdADewRkpPsc=; b=OrpJz8313qAATzTmUSbg8Omsxd73RADesA7Gid2fpCZ/xXjowWB+LmQiyq/PJmODJP20NlBxzmukPDxE4JjMQ3y3O9poSMHrnuzc1nrYtDIDFgoqrMpytfxFqwJVZZ+khMVOflv9X0B9Bv6DltVK70BTwVyU4zjxC6xt81p9Cos= 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 1661976156014982.4117542128479; Wed, 31 Aug 2022 13:02: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-393-_TBMVu8iPGSEzGp2EXoz0w-1; Wed, 31 Aug 2022 16:02:31 -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 3212A8E48E4; Wed, 31 Aug 2022 20:02:28 +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 1FABD40D282E; Wed, 31 Aug 2022 20:02:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 901CB1946A59; Wed, 31 Aug 2022 20:02:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0536B1946A40 for ; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EA20A2166B2B; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C38A92166B26; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661976155; 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=iyq8Zm+UnEnUZXB6QHk7CUbjYTeqgCRPdADewRkpPsc=; b=YGFlL8/pPHXGytGlR9ovHOPziC3HVi1AcLd13fa1xuEuAglSmIvDgKaZi9aVS8gEdG+vZe v+PSsEbfmZu0d4FNDHi32odFR22jmQr16q7jC+Z+3H5dDNkVtJ1aKcGZRzJ7E/PfDXNZqX /oeJYZmG7dA2LrFG1aex0WgtLPrQP0E= X-MC-Unique: _TBMVu8iPGSEzGp2EXoz0w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/16] util: Allow virFileCache data to be any GObject Date: Wed, 31 Aug 2022 13:40:49 -0500 Message-Id: <20220831184101.716362-5-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 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: 1661976157825100005 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 --- src/util/virfilecache.c | 15 +++++++++------ src/util/virfilecache.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index bad37c9f00..e37008990d 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -170,7 +170,8 @@ virFileCacheLoad(virFileCache *cache, *data =3D g_steal_pointer(&loadData); =20 cleanup: - virObjectUnref(loadData); + if (loadData) + g_object_unref(loadData); return ret; } =20 @@ -207,7 +208,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 +240,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 +271,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 +301,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 +333,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 81be8feef5..f0d220cc86 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.37.1 From nobody Sat May 18 05:34:56 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=1661974572; cv=none; d=zohomail.com; s=zohoarc; b=jfDMoPvyR2Tb8zEU3EqG4U4xm/q599M/jAKPmIGn/XFkinjt+HhUrFtgSyVPISTZvv7dYBM46JrOWRlbbTrfQxt/Pn8N8HjV0KX/h0n3/81xsISThq6kIb2dTr2deuE/XriyAUx3ydyJvNpbze3P1sAb4X62/uOrNPLgg3GnD5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974572; 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=ZKg+24C2ikKmV45YMk5z0xxLlWbzj5gaZDxRXLPdp+4=; b=XZZxdxPu46QEnLDnk2oes7ga2g0mvjc2Yp73vJOh551EvqyVa3r6HRL6h6EDpMjW5dXPgId0aONGJtIxe5QeMnmbORRpaKmZ0zX6cn+REsKQzlmktueZZRn4qQky8Y6Ff5zC+oQuyBLhE19wIy+uoy2BDM+/kqbGrTMtHsDh1xo= 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 1661974572174638.6868050235779; Wed, 31 Aug 2022 12:36:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-634-r7fnM39FPresQDaO9B-LkA-1; Wed, 31 Aug 2022 15:36:06 -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 ACB923C0ED40; Wed, 31 Aug 2022 19:36:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97DD22166B26; Wed, 31 Aug 2022 19:36:04 +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 5F6411946A4A; Wed, 31 Aug 2022 19:36:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3C27B1946A40 for ; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2F9482166B2B; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0915C2166B26; Wed, 31 Aug 2022 18:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974571; 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=ZKg+24C2ikKmV45YMk5z0xxLlWbzj5gaZDxRXLPdp+4=; b=a13XBFaDM2s+KAOhkBQc6EuBAkNq1bL/5eJd9cInTdvvKzK4DPAoLasDkkNblYIgk/Cqv9 yeHPcg7ce//vWcLtX4GevntdN1aNKkn+HUGkANYykEdGGO6zvBqFdHFqEp8ivl8Nyy+Nr/ NsX6IiZtv4cUFKJRB19Wq3Aax56Mwg8= X-MC-Unique: r7fnM39FPresQDaO9B-LkA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 05/16] qemu: implement basic virFileCache for nbdkit caps Date: Wed, 31 Aug 2022 13:40:50 -0500 Message-Id: <20220831184101.716362-6-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 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: 1661974573574100001 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 --- src/qemu/qemu_nbdkit.c | 91 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 3 ++ 2 files changed, 94 insertions(+) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 0ea1b754cd..3faa16674a 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -263,3 +263,94 @@ qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, { ignore_value(virBitmapSetBit(nbdkitCaps->flags, flag)); } + + +static bool +virNbkditCapsCheckModdir(const char *moddir, + time_t expectedMtime) +{ + time_t mtime =3D getDirMtime(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 vs %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 4baf4d4d31..b65e76895b 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -25,6 +25,7 @@ #include "virbitmap.h" #include "vircgroup.h" #include "vircommand.h" +#include "virfilecache.h" #include "virstorageobj.h" #include "viruri.h" =20 @@ -43,6 +44,8 @@ qemuNbdkitCaps* qemuQueryNbdkitCaps(void); =20 qemuNbdkitCaps* qemuNbdkitCapsNew(const char *path); =20 +virFileCache* qemuNbdkitCapsCacheNew(const char *cachedir); + bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags fla= g); =20 void qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags fla= g); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661975035; cv=none; d=zohomail.com; s=zohoarc; b=GJbONpeiC24EH9ArAN7Vai8RwHJmkm+smZt+oJP5G4d3APHXva0pXlOs1g3t2kJpSyFm7/7UU1zUAHKHboArUzy96ZQVrMe0iWIZKrLBh/bsuFTgEt/95RkRi+wEVVPNQw2RKAN7o7ZL/EYD0/MjOB9vvSlOOWNN9vYFTMrT+90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661975035; 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=/kWIybfAI/q+Ah5zP3tV7HZsHixGUeyCxv9YaWixRn4=; b=nlc7SMGqY+5zoJuKpOlusyaZBXRPlZeLuJy7CBmBnocxkxz2fvytbuvlM/IBUR9O6VLoK6joSTsKI/307FA29alUxk2TgF93MdvtwrrDaGu3PHJX8ctAfwUnwL/sugUUVA91jSdNJ9N20ETjg8UL6WXZYOxPX+pYQ6OPg5Cvwys= 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 1661975035657662.5390867944027; Wed, 31 Aug 2022 12:43:55 -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-EKerT9PZMG-XYqBpEpUXzg-1; Wed, 31 Aug 2022 15:43:51 -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 1E62310119EE; Wed, 31 Aug 2022 19:43:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01683C15BB3; Wed, 31 Aug 2022 19:43:49 +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 8D84B1946A45; Wed, 31 Aug 2022 19:43:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8D4641946A40 for ; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6FB412166B2A; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44AF92166B26; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661975034; 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=/kWIybfAI/q+Ah5zP3tV7HZsHixGUeyCxv9YaWixRn4=; b=NaE1VisDAHhmkCOExYaFIzFCOla5Ijf6Tt7ye16xGJuV+fndF5D/VB9S3u8l2+OU/IEmGY e150r+Ja5fur08mIUPWXs2ZG+jKtCpJYvod7PJqPJDjD3vKqMv1Qcs0bpSZdDV8wYRyfRG 4Y4stQC/1UmRUCiMH/mmeG5WnV4oAro= X-MC-Unique: EKerT9PZMG-XYqBpEpUXzg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 06/16] qemu: implement persistent file cache for nbdkit caps Date: Wed, 31 Aug 2022 13:40:51 -0500 Message-Id: <20220831184101.716362-7-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 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: 1661975036374100003 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 --- src/qemu/qemu_nbdkit.c | 253 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 251 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 3faa16674a..ac498b948c 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -339,11 +339,260 @@ 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 '%s' but saw '%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++) { + g_autofree char *str =3D NULL; + int flag; + + if (!(str =3D virXMLPropString(nodes[i], "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing flag name in QEMU capabilities cache= ")); + return -1; + } + + flag =3D qemuNbdkitCapsTypeFromString(str); + if (flag < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown nbdkit capabilities flag %s"), str); + 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; + unsigned long lu; + + if (!(doc =3D virXMLParseFile(filename))) + return -1; + + if (!(ctxt =3D virXMLXPathContextNew(doc))) + return -1; + + ctxt->node =3D xmlDocGetRootElement(doc); + + if (STRNEQ((const char*)ctxt->node->name, "nbdkitCaps")) { + virReportError(VIR_ERR_XML_ERROR, + _("unexpected root element <%s>, " + "expecting "), + ctxt->node->name); + return -1; + } + + if (virXPathLongLong("string(./selfctime)", ctxt, &l) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing selfctime in nbdkit capabilities XML")); + return -1; + } + nbdkitCaps->libvirtCtime =3D (time_t)l; + + nbdkitCaps->libvirtVersion =3D 0; + if (virXPathULong("string(./selfvers)", ctxt, &lu) =3D=3D 0) + nbdkitCaps->libvirtVersion =3D lu; + + 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) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing nbdkitctime in nbdkit capabilities XML")= ); + return -1; + } + nbdkitCaps->ctime =3D (time_t)l; + + if (virXPathLongLong("string(./plugindirmtime)", ctxt, &l) =3D=3D 0) + nbdkitCaps->pluginDirMtime =3D (time_t)l; + + if (virXPathLongLong("string(./filterdirmtime)", ctxt, &l) =3D=3D 0) + nbdkitCaps->filterDirMtime =3D (time_t)l; + + if (qemuNbdkitCapsParseFlags(nbdkitCaps, ctxt) < 0) + return -1; + + if ((nbdkitCaps->version =3D virXPathString("string(./version)", ctxt)= ) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("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, "%llu\n", + (long long)nbdkitCaps->ctime); + if (nbdkitCaps->pluginDirMtime > 0) { + virBufferAsprintf(&buf, "%llu\n", + (long long)nbdkitCaps->pluginDirMtime); + } + if (nbdkitCaps->filterDirMtime > 0) { + virBufferAsprintf(&buf, "%llu\n", + (long long)nbdkitCaps->filterDirMtime); + } + virBufferAsprintf(&buf, "%llu\n", + (long long)nbdkitCaps->libvirtCtime); + virBufferAsprintf(&buf, "%lu\n", + (unsigned long)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 '%s' for '%s'"), + filename, nbdkitCaps->path); + return -1; + } + + VIR_DEBUG("Saved caps '%s' for '%s' with (%lld, %lld)", + filename, nbdkitCaps->path, + (long long)nbdkitCaps->ctime, + (long long)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.37.1 From nobody Sat May 18 05:34:56 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=1661974437; cv=none; d=zohomail.com; s=zohoarc; b=n/zuSg5t0Ga6moC84noD54wNcermHuHJ1sC+jQy/ojjpTViQgXZl35WlamLE1OCl0Qxkh1uGYofqEWErBHmgpc/309TOHG2VSCSy/AMM1UNqcRP+RjfS+SQV/PZiuILmwgwGUbTomt8BRk9EDaWpXfWfQQqsjgyRGN7+1NB/PXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974437; 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=N53T9nkyG6BC/qdsDJ+m/1Ahw3SaGzy6eDnMB5Lfwf4=; b=fhTjbrJDBNfmb7ultlLbav4lGu79p1gA3b6P5tVcNtZxTz86ialKc6SWP46xc4bxJX3tT6tZIgmO4ScgRfeagw4WxC3mNaiOVEvOsjU/oIYS3wuRTV2CoOQNp8VPkG8rNCcQTfu7Jfswg+5K/dC/fKRKrW9YcC8KmSbbTrSYnjU= 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 1661974437144907.1189299506708; Wed, 31 Aug 2022 12:33:57 -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-259-G2fLDWnMOvWdlk0hMQBb8w-1; Wed, 31 Aug 2022 15:33:52 -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 73FF38039BB; Wed, 31 Aug 2022 19:33:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 591D1141512E; Wed, 31 Aug 2022 19:33:49 +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 B4E731946A62; Wed, 31 Aug 2022 19:33:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CBC601946A40 for ; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B097E2166B2B; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 863FA2166B26; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974436; 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=N53T9nkyG6BC/qdsDJ+m/1Ahw3SaGzy6eDnMB5Lfwf4=; b=WUJO8OSQhkK3Pt5QhlDO+OXpNS1NTgViAo+0hcXyhD5OgN5DO8f879cPr/DdF/Fu+4424J KIaLY2f0NGxGaH1gR339k8E2tR4HQCtCaV2n8IYJjRmhEjCop9iLSGSRACH6XXcrffa3N+ /0TLxn4nmx4ZnFLhn/mS6iL2JzuhyHU= X-MC-Unique: G2fLDWnMOvWdlk0hMQBb8w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 07/16] qemu: use file cache for nbdkit caps Date: Wed, 31 Aug 2022 13:40:52 -0500 Message-Id: <20220831184101.716362-8-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 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: 1661974437721100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Switch to using the virFileCache implementation for nbdkit capabilities so that we have persistent caching and re-load capabilities whenever something changes. Signed-off-by: Jonathon Jongsma --- src/qemu/qemu_conf.h | 2 +- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_nbdkit.c | 24 ------------------------ src/qemu/qemu_nbdkit.h | 2 -- 4 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index d05c715400..414bcfb8a2 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -308,7 +308,7 @@ struct _virQEMUDriver { /* Immutable pointer, self-locking APIs */ virHashAtomic *migrationErrors; =20 - qemuNbdkitCaps *nbdkitCaps; + virFileCache *nbdkitCapsCache; }; =20 virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 943fa8621d..dce3ba1a32 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -833,7 +833,7 @@ qemuStateInitialize(bool privileged, goto error; =20 /* find whether nbdkit is available and query its capabilities */ - qemu_driver->nbdkitCaps =3D qemuQueryNbdkitCaps(); + qemu_driver->nbdkitCapsCache =3D qemuNbdkitCapsCacheNew(cfg->cacheDir); =20 /* 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 diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index ac498b948c..fc83f80f1f 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -225,30 +225,6 @@ qemuNbdkitCapsQuery(qemuNbdkitCaps *caps) } =20 =20 -qemuNbdkitCaps * -qemuQueryNbdkitCaps(void) -{ - qemuNbdkitCaps *caps =3D NULL; - g_autofree char *path =3D virFindFileInPath("nbdkit"); - - if (!path) - return NULL; - - if (!virFileIsExecutable(path)) { - virReportError(VIR_ERR_INTERNAL_ERROR, _("nbdkit '%s' is not execu= table"), - path); - return NULL; - } - - VIR_DEBUG("found nbdkit executable '%s'", path); - - caps =3D qemuNbdkitCapsNew(path); - qemuNbdkitCapsQuery(caps); - - return caps; -} - - bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags flag) diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index b65e76895b..3e34403d90 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -40,8 +40,6 @@ typedef enum { =20 VIR_ENUM_DECL(qemuNbdkitCaps); =20 -qemuNbdkitCaps* qemuQueryNbdkitCaps(void); - qemuNbdkitCaps* qemuNbdkitCapsNew(const char *path); =20 virFileCache* qemuNbdkitCapsCacheNew(const char *cachedir); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661974511; cv=none; d=zohomail.com; s=zohoarc; b=SkAKnHla6ZnpgBSY9ZRTXtRYkfMArYV6jx34m3xOTnbHR4VniljwOpH7qg74urkC+7R5hiula8LddMBr2cqx9etmL1TjmDo9qSvESZnKIp2JQKyflfr/reGLwrR/K7YMgw6L/0+lvIgEoGwC3/G+HkY9KVmL/ujmc4FEWODgS04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974511; 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=bAfxUhag97xI4s8m2rrCMLPzAm3M9RxVwHVy2QqV/LE=; b=bZ5KqpM/N82rmr4Bq3vpLe7DyfAfOrvlPyPK38Unr8g+wlqVCJpN+GM6mKdWISIZdry5B3Fp3mYO+Fxg9njaNOb/Y7CirI6X0+wQkvZnXf7t5Rg3SjzhmlE7Um1xP5A502AlfIbC7Q2kxSCLinhI6Nd3c/QxQ3CIISPse4v27Jc= 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 1661974511386722.5006082381547; Wed, 31 Aug 2022 12:35:11 -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-81-pr95NPQGNZGwWbI0HM-wKw-1; Wed, 31 Aug 2022 15:33:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52296964092; Wed, 31 Aug 2022 19:33:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CF042026D64; Wed, 31 Aug 2022 19:33:49 +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 90D481946A5A; Wed, 31 Aug 2022 19:33:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 136F11946A40 for ; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EC2C82166B2B; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3D7E2166B26; Wed, 31 Aug 2022 18:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974510; 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=bAfxUhag97xI4s8m2rrCMLPzAm3M9RxVwHVy2QqV/LE=; b=Eb8dNHqta+8MKdMv/3y+P0iAhw/1jaDx1Wa/+lGf8SglrAzL8iAnrBy/3yZ1CQTOA21uLb Et1d2UFEWDjgqCHyx6jNC2s3/Js/gAtoTtHBJ9fD3W5eOD72S0Mv8OlSkDa1D5N0imfetn IgzrNa54WT8h3Aq291uUSOuezh2TNoI= X-MC-Unique: pr95NPQGNZGwWbI0HM-wKw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/16] qemu: Add qemuNbdkitProcess Date: Wed, 31 Aug 2022 13:40:53 -0500 Message-Id: <20220831184101.716362-9-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 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: 1661974513156100001 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 --- src/qemu/qemu_conf.c | 22 ++++++++++++ src/qemu/qemu_conf.h | 3 ++ src/qemu/qemu_domain.c | 29 +++++++++++++++ src/qemu/qemu_domain.h | 4 +++ src/qemu/qemu_nbdkit.c | 82 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 24 +++++++++++++ 6 files changed, 164 insertions(+) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 3b75cdeb95..b5f451a8f9 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1571,3 +1571,25 @@ qemuGetMemoryBackingPath(virQEMUDriver *driver, *memPath =3D g_strdup_printf("%s/%s", domainPath, alias); 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) +{ + if (!driver->nbdkitBinary) + driver->nbdkitBinary =3D virFindFileInPath("nbdkit"); + + if (driver->nbdkitBinary) + return virFileCacheLookup(driver->nbdkitCapsCache, driver->nbdkitB= inary); + + return NULL; +} diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 414bcfb8a2..91212d6608 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -309,6 +309,7 @@ struct _virQEMUDriver { virHashAtomic *migrationErrors; =20 virFileCache *nbdkitCapsCache; + char *nbdkitBinary; }; =20 virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, @@ -362,3 +363,5 @@ int qemuGetMemoryBackingPath(virQEMUDriver *driver, const virDomainDef *def, const char *alias, char **memPath); + +qemuNbdkitCaps* qemuGetNbdkitCaps(virQEMUDriver *driver); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fe3ce023a4..5b3b2d3e9c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -819,6 +819,7 @@ qemuDomainStorageSourcePrivateDispose(void *obj) g_clear_pointer(&priv->encinfo, qemuDomainSecretInfoFree); g_clear_pointer(&priv->httpcookie, qemuDomainSecretInfoFree); g_clear_pointer(&priv->tlsKeySecret, qemuDomainSecretInfoFree); + g_clear_pointer(&priv->nbdkitProcess, qemuNbdkitProcessFree); } =20 =20 @@ -10013,6 +10014,32 @@ 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 qemuGetNbdkitCaps(priv->driver); + if (!nbdkit) + return false; + + if (virStorageSourceGetActualType(src) !=3D VIR_STORAGE_TYPE_NETWORK) + return false; + + return qemuNbdkitInitStorageSource(nbdkit, src, priv->libDir, + alias, cfg->user, cfg->group); +} + + /* qemuProcessPrepareStorageSourceTLS: * @source: source for a disk * @cfg: driver configuration @@ -10787,6 +10814,8 @@ qemuDomainPrepareStorageSourceBlockdevNodename(virD= omainDiskDef *disk, if (qemuDomainPrepareStorageSourceNFS(src) < 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 592ee9805b..563b0aa925 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" @@ -293,6 +294,9 @@ struct _qemuDomainStorageSourcePrivate { =20 /* key for decrypting TLS certificate */ qemuDomainSecretInfo *tlsKeySecret; + + /* 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 fc83f80f1f..4df8957196 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -579,3 +579,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(qemuNbdkitCaps *caps, + virStorageSource *source, + char *statedir, + const char *alias, + uid_t user, + gid_t group) +{ + qemuNbdkitProcess *proc =3D g_new0(qemuNbdkitProcess, 1); + g_autofree char *pidfile =3D g_strdup_printf("nbdkit-%s.pid", alias); + g_autofree char *socketfile =3D g_strdup_printf("nbdkit-%s.socket", al= ias); + + proc->caps =3D g_object_ref(caps); + /* weak reference -- source owns this object, so it will always outliv= e us */ + proc->source =3D source; + proc->user =3D user; + proc->group =3D group; + proc->pidfile =3D g_build_filename(statedir, pidfile, NULL); + proc->socketfile =3D g_build_filename(statedir, socketfile, NULL); + + return proc; +} + + +bool +qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, + virStorageSource *source, + char *statedir, + const char *alias, + uid_t user, + gid_t group) +{ + qemuDomainStorageSourcePrivate *srcPriv =3D qemuDomainStorageSourcePri= vateFetch(source); + + 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; + } + srcPriv->nbdkitProcess =3D qemuNbdkitProcessNew(caps, source, statedir= , alias, user, group); + + return true; +} + + +void +qemuNbdkitProcessFree(qemuNbdkitProcess *proc) +{ + if (virProcessKillPainfully(proc->pid, true) < 0) + VIR_WARN("Unable to kill nbdkit process"); + + unlink(proc->pidfile); + g_clear_pointer(&proc->pidfile, g_free); + unlink(proc->socketfile); + 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 3e34403d90..24762cce8f 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -30,6 +30,7 @@ #include "viruri.h" =20 typedef struct _qemuNbdkitCaps qemuNbdkitCaps; +typedef struct _qemuNbdkitProcess qemuNbdkitProcess; =20 typedef enum { QEMU_NBDKIT_CAPS_PLUGIN_CURL, @@ -44,9 +45,32 @@ qemuNbdkitCaps* qemuNbdkitCapsNew(const char *path); =20 virFileCache* qemuNbdkitCapsCacheNew(const char *cachedir); =20 +bool qemuNbdkitInitStorageSource(qemuNbdkitCaps *nbdkitCaps, + virStorageSource *source, + char *statedir, + const char *alias, + uid_t user, + gid_t group + /*, char *selinux_label*/); + bool qemuNbdkitCapsGet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags fla= g); =20 void qemuNbdkitCapsSet(qemuNbdkitCaps *nbdkitCaps, qemuNbdkitCapsFlags fla= g); =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.37.1 From nobody Sat May 18 05:34:56 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=1661974718; cv=none; d=zohomail.com; s=zohoarc; b=InKwH/eN3tnBsiOVvYiYSPXzsxCxlRIgF7bmamuFhAuE3O9tnwgdSdFfyfus+CLTCmlDmVvlMUpU6dFmYpBbX2KukbvGrPx/67Q8JvkbksL2k5dVh1F+fzvR/emc6giqg4PiGzxn5IoQjNbfGTJqR+Z4fgCsVw5oKY1AaxlaJ70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974718; 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=A8t4dJX4sckRDSJbJEhLb88QK8+tX6g2SSpmOT5ccBk=; b=JTp/v/ryQ8d5/TlueeVu48aPW9y3wQcRjOUpo0fLdGARHmUrifmkWGOc7U84e4NHZb14XJuL7g3eTQH5EGj8oYD9f6Ha48yEHbtpZX/UEYQfkQ3L3cT5yuqg9ohaq9qufKCs5jj+YMEMtFGwzl5/UGff5s13Y5q8wZDcAPJvkhA= 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 1661974718179344.84522881125827; Wed, 31 Aug 2022 12:38:38 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-621-gjebnNVtM56TbJzzX91Ltw-1; Wed, 31 Aug 2022 15:38:33 -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 EE87D3C0E22A; Wed, 31 Aug 2022 19:38:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA41BC15BB3; Wed, 31 Aug 2022 19:38:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 996BA1946A53; Wed, 31 Aug 2022 19:38:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4D32B1946A40 for ; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4233E2166B2B; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DEE02166B26; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974717; 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=A8t4dJX4sckRDSJbJEhLb88QK8+tX6g2SSpmOT5ccBk=; b=d/FSFjO18Xe8549fPlmTxuCb+4zsA/oDDr3RfEmqBrxGI3OtMZ1jnpLehd/g86OAz0++58 PgZvIfUAmTO83hOD6LPN+JUI1SIgIcnTCtY0HwiS5XhTrLJcBHTkgQpFpPYLs+xfAfol9T uPNxP9zI5bxJlGxtWOGQkgL+5VHa3j4= X-MC-Unique: gjebnNVtM56TbJzzX91Ltw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/16] qemu: add functions to start and stop nbdkit Date: Wed, 31 Aug 2022 13:40:54 -0500 Message-Id: <20220831184101.716362-10-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 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: 1661974720017100001 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 --- src/qemu/qemu_nbdkit.c | 208 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.h | 8 ++ 2 files changed, 216 insertions(+) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 4df8957196..e8f9acc17c 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -648,6 +648,156 @@ 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"); + virCommandAddArgPair(cmd, "protocols", + virStorageNetProtocolTypeToString(proc->source->p= rotocol)); + 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; + + 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 %s"), + proc->source->auth->secrettype); + return -1; + } + + if (virSecretGetSecretString(conn, + &proc->source->auth->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); + + virCommandAddArgPair(cmd, "password", password); + + virSecureErase(secret, secretlen); + virSecureErase(password, secretlen); + } + + if (proc->source->ncookies > 0) + virCommandAddArgPair(cmd, "cookie", + qemuBlockStorageSourceGetCookieString(proc->s= ource)); + + 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, + "--exit-with-parent", + "--unix", + proc->socketfile, + "--foreground", + //"--selinux-label", + //selinux_label, + 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 '%s' is not supported by nbdkit"), + virStorageNetProtocolTypeToString(proc->source-= >protocol)); + return NULL; + } + + virCommandDaemonize(cmd); + + return g_steal_pointer(&cmd); +} + + void qemuNbdkitProcessFree(qemuNbdkitProcess *proc) { @@ -661,3 +811,61 @@ 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; + int cmdret =3D 0; + int errfd =3D -1; + + if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc))) + return -1; + + virCommandSetErrorFD(cmd, &errfd); + virCommandSetPidFile(cmd, proc->pidfile); + + if (qemuExtDeviceLogCommand(driver, vm, cmd, "nbdkit") < 0) + goto error; + + if (qemuSecurityCommandRun(driver, vm, cmd, proc->user, proc->group, &= exitstatus, &cmdret) < 0) + goto error; + + if (cmdret < 0 || exitstatus !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not start 'nbdkit'. exitstatus: %d"), exit= status); + goto error; + } + + if ((rc =3D virPidFileReadPath(proc->pidfile, &proc->pid)) < 0) { + virReportSystemError(-rc, + _("Failed to read pidfile %s"), + proc->pidfile); + goto error; + } + + return 0; + + error: + if (errfd > 0) { + char errbuf[1024] =3D { 0 }; + if (read(errfd, errbuf, sizeof(errbuf) - 1) > 0) + VIR_WARN("nbdkit failed to start: %s", errbuf); + } + if (proc->pid) + virProcessKillPainfully(proc->pid, true); + unlink(proc->pidfile); + return -1; +} + + +int +qemuNbdkitProcessStop(qemuNbdkitProcess *proc) +{ + return virProcessKillPainfully(proc->pid, true); +} diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 24762cce8f..07ae0eead4 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -71,6 +71,14 @@ struct _qemuNbdkitProcess { pid_t pid; }; =20 +typedef struct _virQEMUDriver virQEMUDriver; + +int qemuNbdkitProcessStart(qemuNbdkitProcess *proc, + virDomainObj *vm, + virQEMUDriver *driver); + +int qemuNbdkitProcessStop(qemuNbdkitProcess *proc); + void qemuNbdkitProcessFree(qemuNbdkitProcess *proc); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuNbdkitProcess, qemuNbdkitProcessFree); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661974782; cv=none; d=zohomail.com; s=zohoarc; b=J93NB6dBEZ3VWySg3ASvoPOUkJx3bicj55F16woAzW5ffBThJlTQC07HXTEII7elmIRY/aiRsJy23CQvOOfTzGybcO6cOweLpjEeQuEV7WeJU7ykc4llRIGJsalsUlM7g4StaYRqr9r7zs1iaohMmuBnQFOBe1bgV2NbM62DnY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974782; 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=l703vMBfV5ZMCl+ymPjPsk2/zucwaT6+rHnAA/8gzcQ=; b=ZzXBJTmTOQ6Xw2o4vOkP0kcGG4RUFZFpL8KQLEUcDhipS2lgtk4e579N1hJW2AXNqPL0wkmrT+RoR0xAJ6gcg31m8Xu6r7ag37cZJpWA4SKTdTMAsidKTpcJPeLx3YuGXmr27/UEmWw6DcjGzn5CaYABU6Zu2yjRVBkyQSqyvoQ= 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 1661974782632714.6969740872329; Wed, 31 Aug 2022 12:39:42 -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-498-rF-hYl12M-GsFkDi7ATd0g-1; Wed, 31 Aug 2022 15:39:39 -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 3B921964093; Wed, 31 Aug 2022 19:39:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CED681415117; Wed, 31 Aug 2022 19:39:36 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8F7931946A4B; Wed, 31 Aug 2022 19:39:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9F1971946A40 for ; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 932482166B2A; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CB462166B26; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974781; 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=l703vMBfV5ZMCl+ymPjPsk2/zucwaT6+rHnAA/8gzcQ=; b=YQo1K5TSltbrDT+jEjcivsZRdcBNeK7xU94WwJ6CzxNxKpEZ4w/yt5OE2YB2m6Ka0ihGvD Fxc4NpQodvcWfuuf4GsrLkHPoFbWfCU8PsFu3uRLc3JOLDlzNy9jE/q8eUG046CA+arJK7 Mzxo/QeXfTsZTPVsCH5NLjuRyNHXinI= X-MC-Unique: rF-hYl12M-GsFkDi7ATd0g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/16] tests: add ability to test various nbdkit capabilities Date: Wed, 31 Aug 2022 13:40:55 -0500 Message-Id: <20220831184101.716362-11-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 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: 1661974784752100001 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 --- src/qemu/qemu_nbdkit.c | 20 +++++++++++++++++--- tests/qemuxml2argvtest.c | 11 +++++++++++ tests/testutilsqemu.c | 27 +++++++++++++++++++++++++++ tests/testutilsqemu.h | 5 +++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index e8f9acc17c..df3a691bff 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -260,10 +260,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; @@ -306,9 +312,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 9ed7152544..4890c3b01b 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -705,6 +705,14 @@ testCompareXMLToArgv(const void *data) if (rc < 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))) @@ -963,6 +971,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 6d3decdc16..386042aa79 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -131,6 +131,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 @@ -422,6 +426,7 @@ void qemuTestDriverFree(virQEMUDriver *driver) virObjectUnref(driver->caps); virObjectUnref(driver->config); virObjectUnref(driver->securityManager); + g_clear_object(&driver->nbdkitCapsCache); =20 virCPUDefFree(cpuDefault); virCPUDefFree(cpuHaswell); @@ -665,6 +670,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; @@ -885,6 +896,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info, =20 info->conf =3D conf; info->args.newargs =3D true; + info->args.fakeNbdkitCaps =3D qemuNbdkitCapsNew(TEST_NBDKIT_PATH); =20 va_start(argptr, conf); while ((argname =3D va_arg(argptr, testQemuInfoArgName)) !=3D ARG_END)= { @@ -896,6 +908,13 @@ testQemuInfoSetArgs(struct testQemuInfo *info, virQEMUCapsSet(info->args.fakeCaps, flag); break; =20 + case ARG_NBDKIT_CAPS: + info->args.fakeNbdkitCapsUsed =3D true; + + while ((flag =3D va_arg(argptr, int)) < QEMU_NBDKIT_CAPS_LAST) + qemuNbdkitCapsSet(info->args.fakeNbdkitCaps, flag); + break; + case ARG_GIC: info->args.gic =3D va_arg(argptr, int); break; @@ -1020,6 +1039,12 @@ testQemuInfoInitArgs(struct testQemuInfo *info) info->qemuCaps =3D g_steal_pointer(&info->args.fakeCaps); } =20 + if (info->args.fakeNbdkitCapsUsed) + info->nbdkitCaps =3D g_steal_pointer(&info->args.fakeNbdkitCaps); + else + /* empty caps */ + info->nbdkitCaps =3D qemuNbdkitCapsNew(TEST_NBDKIT_PATH); + if (info->args.gic !=3D GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, info->args.gic) < 0) return -1; @@ -1037,6 +1062,8 @@ testQemuInfoClear(struct testQemuInfo *info) VIR_FREE(info->errfile); virObjectUnref(info->qemuCaps); g_clear_pointer(&info->args.fakeCaps, virObjectUnref); + g_clear_object(&info->nbdkitCaps); + g_clear_object(&info->args.fakeNbdkitCaps); } =20 =20 diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 943958d02a..618837559c 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 "/usr/bin/nbdkit" =20 enum { GIC_NONE =3D 0, @@ -52,6 +53,7 @@ typedef enum { ARG_CAPS_VER, ARG_CAPS_HOST_CPU_MODEL, ARG_HOST_OS, + ARG_NBDKIT_CAPS, ARG_END, } testQemuInfoArgName; =20 @@ -82,6 +84,8 @@ struct testQemuArgs { bool newargs; virQEMUCaps *fakeCaps; bool fakeCapsUsed; + qemuNbdkitCaps *fakeNbdkitCaps; + bool fakeNbdkitCapsUsed; char *capsver; char *capsarch; qemuTestCPUDef capsHostCPUModel; @@ -96,6 +100,7 @@ struct testQemuInfo { char *outfile; char *errfile; virQEMUCaps *qemuCaps; + qemuNbdkitCaps *nbdkitCaps; const char *migrateFrom; int migrateFd; unsigned int flags; --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661976153; cv=none; d=zohomail.com; s=zohoarc; b=Oeoe93LSECTYpHyW8jk9Y+ZphEWImqyBF3LG7cYG4c/9PRw9alEHsU/t04xfquUDyFMeJ595k7Cs3JhQJp7bAMLDwA9vKJ1uKLz8yISMyYdihiZd4TTNnYYAyXFXl42zvKUm72I6Fh6jr1bZkIC2lO2sLeRrWGcNnt4L7NdIa8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661976153; 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=V1Gx9rzZQtT8AhgscUjaAwDzPACCkuWMWPnEZiAhBzM=; b=YFXJ8ALOL4+5U6Mkb0lb1L5/5Lvs6KZ+D+hI+YwNL6Z0FE05g15HTDPjF75tGKd2D+uk2wfVhUfNNaqHFT0RhWi2cR1VrTe5uD3g/b4Q71eE+IvAGw1WuU4JCcvGiapoua/BfuVN7dxYP8xSRBNvic3wxJGgBryIX8fKWZAWgVI= 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 1661976153482803.717851699966; Wed, 31 Aug 2022 13:02: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-553-CDTdh_HdOAaeyVRpAKoCTQ-1; Wed, 31 Aug 2022 16:02:31 -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 C728F85A589; Wed, 31 Aug 2022 20:02:27 +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 B97282166B26; Wed, 31 Aug 2022 20:02: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 5F7511946A4C; Wed, 31 Aug 2022 20:02:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F3AED1946A40 for ; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E42032166B2A; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFF582166B26; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661976152; 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=V1Gx9rzZQtT8AhgscUjaAwDzPACCkuWMWPnEZiAhBzM=; b=dgETVnvszCR20i6pYEofhCP9NAAT+Zd9oQN0soZz3mmshGifjhw63ldSZZuwwC1/6BH6vX /DOqA9UIvxrA21WtIIWGrWo2n9eHLE9vbeX+QxM2qyrBPtJBmg9wMjZ3tIluypa1+UZLRW IvEqpLZUWNa+oj/Z2gdYE5m9jzXEKJc= X-MC-Unique: CDTdh_HdOAaeyVRpAKoCTQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 11/16] qemu: split qemuDomainSecretStorageSourcePrepare Date: Wed, 31 Aug 2022 13:40:56 -0500 Message-Id: <20220831184101.716362-12-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 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: 1661976153832100001 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 | 83 ++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5b3b2d3e9c..1fd1db2f11 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1267,24 +1267,19 @@ 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; @@ -1292,13 +1287,43 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjP= rivate *priv, if (virStorageSourceIsEmpty(src)) return 0; =20 - if (!src->auth && !hasEnc && src->ncookies =3D=3D 0) + if (!hasEnc) return 0; =20 - if (!(src->privateData =3D qemuDomainStorageSourcePrivateNew())) + srcPriv =3D qemuDomainStorageSourcePrivateFetch(src); + + if (!(srcPriv->encinfo =3D qemuDomainSecretInfoSetupFromSecret(priv, a= lias, + "encrypti= on", + VIR_SECRE= T_USAGE_TYPE_VOLUME, + NULL, + &src->enc= ryption->secrets[0]->seclookupdef))) return -1; =20 - srcPriv =3D QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); + 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; + + srcPriv =3D qemuDomainStorageSourcePrivateFetch(src); =20 if (src->auth) { virSecretUsageType usageType =3D VIR_SECRET_USAGE_TYPE_ISCSI; @@ -1306,7 +1331,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= ", usage= Type, src->= auth->username, @@ -1314,19 +1339,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjP= rivate *priv, return -1; } =20 - if (hasEnc) { - if (!(srcPriv->encinfo =3D qemuDomainSecretInfoSetupFromSecret(pri= v, aliasformat, - "encr= yption", - VIR_S= ECRET_USAGE_TYPE_VOLUME, - NULL, - &src-= >encryption->secrets[0]->seclookupdef))) - return -1; - } - if (src->ncookies && !(srcPriv->httpcookie =3D qemuDomainSecretStorageSourcePrepareCook= ies(priv, = src, - = aliasprotocol))) + = alias))) return -1; =20 return 0; @@ -10761,9 +10777,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) @@ -10799,9 +10818,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.37.1 From nobody Sat May 18 05:34:56 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=1661974571; cv=none; d=zohomail.com; s=zohoarc; b=X0nhYta4Pw4P1gQjhO/oyLFQY0drrzzMh8BlAUPUDptECMErN7nhWmFwJEZYQE/990yrV0rOtO98Q3zrb0k3DnIWRQKFANltQMGxXxc/5s8ZOM3ZUPSw44iq1qr0JXvk/8pylLaPUVYj9XCrGoWwW+eaiez9ByWfz23QTTlwxBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974571; 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=1VeMqj5GU9k/Oni8WHvhGgCaales65ES4UzDSPfKILg=; b=HS54GJLjQOh9cDL/lRLOXZ8wHSCkqU893U6rAHCygVeIfW715fr7g9xJS0VBrHKiDlvzaHoJo9Tc4EgL4cIatwsDue9BRBb2fiqvKIva1YUSYV/P3a3/Tm3l6PmFCSnlasuh1kSo8axPv2ZiLN8+EqMSBswQQ7mhd9Td0/8FpWo= 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 1661974571560351.1094715174157; Wed, 31 Aug 2022 12:36:11 -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-395-MJ0HS0HmOrKQl5Sf6dt3sw-1; Wed, 31 Aug 2022 15:36:08 -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 4D8808E48EA; Wed, 31 Aug 2022 19:36:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34E3C2026D4C; Wed, 31 Aug 2022 19:36:05 +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 AA6761946A45; Wed, 31 Aug 2022 19:36:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 69B2B1946A40 for ; Wed, 31 Aug 2022 18:41:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5DD7D2166B2B; Wed, 31 Aug 2022 18:41:06 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 072012166B26; Wed, 31 Aug 2022 18:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974570; 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=1VeMqj5GU9k/Oni8WHvhGgCaales65ES4UzDSPfKILg=; b=WpUvC+8r/sl/g0qkmtmqzMCrpbru2JOt3yj+d0oJ/KW3v4ySGAokvbtYTfhw8xRQBVKTNt 1C19cU8f37HW0AdQe+eeSk5rHm9+4Ry/hfj8tSOxHod/zI82xltYOM/rphNcevl+2j1wsb srpf+hKKBiRT4+w2fji6fQ/tt5+MOc0= X-MC-Unique: MJ0HS0HmOrKQl5Sf6dt3sw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/16] qemu: use nbdkit to serve network disks if available Date: Wed, 31 Aug 2022 13:40:57 -0500 Message-Id: <20220831184101.716362-13-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 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: 1661974573633100003 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 --- src/qemu/qemu_block.c | 168 +++++++++++------- src/qemu/qemu_command.c | 4 +- src/qemu/qemu_domain.c | 21 ++- src/qemu/qemu_extdevice.c | 84 +++++++++ src/qemu/qemu_nbdkit.c | 9 + src/qemu/qemu_nbdkit.h | 2 + ...sk-cdrom-network-nbdkit.x86_64-latest.args | 42 +++++ .../disk-cdrom-network-nbdkit.xml | 1 + ...isk-network-http-nbdkit.x86_64-latest.args | 45 +++++ .../disk-network-http-nbdkit.xml | 1 + ...rce-curl-nbdkit-backing.x86_64-latest.args | 38 ++++ ...isk-network-source-curl-nbdkit-backing.xml | 45 +++++ ...work-source-curl-nbdkit.x86_64-latest.args | 50 ++++++ .../disk-network-source-curl-nbdkit.xml | 1 + ...isk-network-source-curl.x86_64-latest.args | 53 ++++++ .../disk-network-source-curl.xml | 71 ++++++++ ...disk-network-ssh-nbdkit.x86_64-latest.args | 36 ++++ .../disk-network-ssh-nbdkit.xml | 1 + tests/qemuxml2argvtest.c | 6 + 19 files changed, 605 insertions(+), 73 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 b82e3311e1..4849d68039 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -439,6 +439,33 @@ 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.transport =3D VIR_STORAGE_NET_HOST_TRANS_UNIX; + 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) @@ -851,69 +878,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; } @@ -1799,6 +1832,8 @@ qemuBlockGetBackingStoreString(virStorageSource *src, virJSONValue *props =3D NULL; g_autoptr(virURI) uri =3D NULL; g_autofree char *backingJSON =3D NULL; + qemuDomainStorageSourcePrivate *srcPriv =3D QEMU_DOMAIN_STORAGE_SOURCE= _PRIVATE(src); + bool useNbdkit =3D srcPriv && srcPriv->nbdkitProcess; =20 if (!src->sliceStorage) { if (virStorageSourceIsLocalStorage(src)) { @@ -1817,7 +1852,8 @@ qemuBlockGetBackingStoreString(virStorageSource *src, src->ncookies =3D=3D 0 && src->sslverify =3D=3D VIR_TRISTATE_BOOL_ABSENT && src->timeout =3D=3D 0 && - src->readahead =3D=3D 0) { + src->readahead =3D=3D 0 && + !useNbdkit) { =20 switch ((virStorageNetProtocol) src->protocol) { case VIR_STORAGE_NET_PROTOCOL_NBD: @@ -2196,6 +2232,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: @@ -2224,6 +2261,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_command.c b/src/qemu/qemu_command.c index a31b8ee438..b941f0b3ac 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10372,7 +10372,7 @@ qemuBuildStorageSourceAttachPrepareCommon(virStorag= eSource *src, return -1; =20 if (srcpriv) { - if (srcpriv->secinfo && + if (!srcpriv->nbdkitProcess && srcpriv->secinfo && qemuBuildSecretInfoProps(srcpriv->secinfo, &data->authsecretPr= ops) < 0) return -1; =20 @@ -10380,7 +10380,7 @@ qemuBuildStorageSourceAttachPrepareCommon(virStorag= eSource *src, qemuBuildSecretInfoProps(srcpriv->encinfo, &data->encryptsecre= tProps) < 0) return -1; =20 - if (srcpriv->httpcookie && + if (!srcpriv->nbdkitProcess && srcpriv->httpcookie && qemuBuildSecretInfoProps(srcpriv->httpcookie, &data->httpcooki= esecretProps) < 0) return -1; =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1fd1db2f11..f69cfee0cf 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10821,21 +10821,24 @@ qemuDomainPrepareStorageSourceBlockdevNodename(vi= rDomainDiskDef *disk, 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) return -1; =20 - if (qemuDomainPrepareStorageSourceTLS(src, cfg, src->nodestorage, - priv) < 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 (qemuDomainPrepareStorageSourceNFS(src) < 0) - return -1; + if (qemuDomainPrepareStorageSourceTLS(src, cfg, src->nodestorage, + priv) < 0) + return -1; =20 - qemuDomainPrepareStorageSourceNbdkit(src, cfg, src->nodestorage, priv); + if (qemuDomainPrepareStorageSourceNFS(src) < 0) + return -1; + } =20 return 0; } diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index b8e3c1000a..ffab7d048b 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -164,6 +164,25 @@ qemuExtDevicesCleanupHost(virQEMUDriver *driver, } =20 =20 +/* recursively start nbdkit for backing chain of src */ +static int qemuExtDevicesStartNbdkit(virQEMUDriver *driver, + virDomainObj *vm, + virStorageSource *src) +{ + qemuDomainStorageSourcePrivate *priv =3D QEMU_DOMAIN_STORAGE_SOURCE_PR= IVATE(src); + + if (src->backingStore) + if (qemuExtDevicesStartNbdkit(driver, vm, src->backingStore) < 0) + return -1; + + if (priv && priv->nbdkitProcess && + qemuNbdkitProcessStart(priv->nbdkitProcess, vm, driver) < 0) + return -1; + + return 0; +} + + int qemuExtDevicesStart(virQEMUDriver *driver, virDomainObj *vm, @@ -218,6 +237,34 @@ qemuExtDevicesStart(virQEMUDriver *driver, return -1; } =20 + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + if (qemuExtDevicesStartNbdkit(driver, vm, disk->src) < 0) + return -1; + } + + if (def->os.loader && def->os.loader->nvram) { + if (qemuExtDevicesStartNbdkit(driver, vm, def->os.loader->nvram) <= 0) + return -1; + } + + return 0; +} + + +/* recursively stop nbdkit processes for backing chain of src */ +static int qemuExtDevicesStopNbdkit(virStorageSource *src) +{ + qemuDomainStorageSourcePrivate *priv =3D QEMU_DOMAIN_STORAGE_SOURCE_PR= IVATE(src); + + if (src->backingStore) + if (qemuExtDevicesStopNbdkit(src->backingStore) < 0) + return -1; + + if (priv && priv->nbdkitProcess && + qemuNbdkitProcessStop(priv->nbdkitProcess) < 0) + return -1; + return 0; } =20 @@ -262,6 +309,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]; + qemuExtDevicesStopNbdkit(disk->src); + } + + if (def->os.loader && def->os.loader->nvram) + qemuExtDevicesStopNbdkit(def->os.loader->nvram); } =20 =20 @@ -291,6 +346,24 @@ qemuExtDevicesHasDevice(virDomainDef *def) } =20 =20 +/* recursively setup nbdkit cgroups for backing chain of src */ +static int qemuExtDevicesSetupCgroupNbdkit(virStorageSource *src, + virCgroup *cgroup) +{ + qemuDomainStorageSourcePrivate *priv =3D QEMU_DOMAIN_STORAGE_SOURC= E_PRIVATE(src); + + if (src->backingStore) + if (qemuExtDevicesSetupCgroupNbdkit(src->backingStore, cgroup)= < 0) + return -1; + + if (priv && priv->nbdkitProcess && + qemuNbdkitProcessSetupCgroup(priv->nbdkitProcess, cgroup) < 0) + return -1; + + return 0; +} + + int qemuExtDevicesSetupCgroup(virQEMUDriver *driver, virDomainObj *vm, @@ -324,6 +397,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_nbdkit.c b/src/qemu/qemu_nbdkit.c index df3a691bff..46d4a8a7ac 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -827,6 +827,15 @@ qemuNbdkitProcessFree(qemuNbdkitProcess *proc) } =20 =20 +int +qemuNbdkitProcessSetupCgroup(qemuNbdkitProcess *proc, + virCgroup *cgroup) +{ + return virCgroupAddProcess(cgroup, proc->pid); +} + + +/* FIXME: selinux permissions errors */ int qemuNbdkitProcessStart(qemuNbdkitProcess *proc, virDomainObj *vm, diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 07ae0eead4..4fda5113a2 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -81,4 +81,6 @@ int qemuNbdkitProcessStop(qemuNbdkitProcess *proc); =20 void qemuNbdkitProcessFree(qemuNbdkitProcess *proc); =20 +int qemuNbdkitProcessSetupCgroup(qemuNbdkitProcess *proc, virCgroup *cgrou= p); + 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..eec7ef2af7 --- /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/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/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":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram \ +-accel kvm \ +-cpu qemu64 \ +-m 1024 \ +-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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-3-storage.socket"},"node-name":"libvirt-3-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"libvirt-2-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"libvirt-1-sto= rage","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..25d476d3ce --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-http-nbdkit.x86_64-latest.args @@ -0,0 +1,45 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/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":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram \ +-accel kvm \ +-cpu qemu64 \ +-m 214 \ +-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 \ +-no-acpi \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-4-storage.socket"},"node-name":"libvirt-4-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-3-storage.socket"},"node-name":"libvirt-3-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"libvirt-2-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"libvirt-1-sto= rage","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..98cfcd219a --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit-backing.x86_64= -latest.args @@ -0,0 +1,38 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/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":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram \ +-accel tcg \ +-cpu qemu64 \ +-m 214 \ +-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 \ +-no-acpi \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"libvirt-2-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"libvirt-1-sto= rage","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..ec193bb10a --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl-nbdkit.x86_64-latest.= args @@ -0,0 +1,50 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/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":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram \ +-accel tcg \ +-cpu qemu64 \ +-m 214 \ +-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 \ +-no-acpi \ +-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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-5-storage.socket"},"node-name":"libvirt-5-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-4-storage.socket"},"node-name":"libvirt-4-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-3-storage.socket"},"node-name":"libvirt-3-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-2-storage.socket"},"node-name":"libvirt-2-sto= rage","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":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"libvirt-1-sto= rage","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..ec6dd13f6c --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args @@ -0,0 +1,53 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/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":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram \ +-accel tcg \ +-cpu qemu64 \ +-m 214 \ +-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 \ +-no-acpi \ +-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-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"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"}'= \ +-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..e22ba095b1 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-ssh-nbdkit.x86_64-latest.args @@ -0,0 +1,36 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/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":"/tm= p/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram \ +-accel kvm \ +-cpu qemu64 \ +-m 214 \ +-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 \ +-no-acpi \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"nbd","server":{"type":"unix","path":"/tmp/lib/domain= --1-QEMUGuest1/nbdkit-libvirt-1-storage.socket"},"node-name":"libvirt-1-sto= rage","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 4890c3b01b..afbc35b08b 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1326,6 +1326,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"); @@ -1366,6 +1367,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"); @@ -1376,7 +1380,9 @@ 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); DO_TEST_CAPS_LATEST("disk-network-ssh"); + DO_TEST_CAPS_LATEST_NBDKIT("disk-network-ssh-nbdkit", QEMU_NBDKIT_CAPS= _PLUGIN_SSH); driver.config->vxhsTLS =3D 0; VIR_FREE(driver.config->vxhsTLSx509certdir); DO_TEST_CAPS_LATEST("disk-no-boot"); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661974445; cv=none; d=zohomail.com; s=zohoarc; b=mHylFveOEypYN4H+E2mWtFOC+k1/lA0gdbPmQwN0Lxmk/JWO02IfjV943RvK0w0p0p9+RNvep1a7eQsljHQsVPgHMt5x940Lzcumn4QwEBqZbPzeRaHvMdbWI3X3T+qI/FEhO0UkkuMa45ri0rZxPzx95BmH4RfVsANb7t3iDAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974445; 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=dEkZCIZPpUac0p0uyDaOROrDQmno3wDSJBFpz7t3bYU=; b=E4cR8ZYu0PK8qOpQwhFxSEuRtDP88lRf15ICUXj6r2YWBfGiwxqO0++YPrgZ/3A7IwNbJqd5dNovTWu3W3QbFwtHB2cOvHOF4+W2XoGIfWALDjG7bfTyusmKG95P/BBsJP5o8c9OyKqAwzN/4uPWOTJTwJHCuX1BKn2g2Pe7+Kc= 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 1661974445820385.8607440681551; Wed, 31 Aug 2022 12:34: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-9-loD8K4LtNiGLB1gqH6rI0g-1; Wed, 31 Aug 2022 15:33:52 -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 30CB18E4901; Wed, 31 Aug 2022 19:33:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04CFF14152E4; Wed, 31 Aug 2022 19:33:50 +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 2D9501946A74; Wed, 31 Aug 2022 19:33:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BAFC81946A40 for ; Wed, 31 Aug 2022 18:41:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B01492166B2B; Wed, 31 Aug 2022 18:41:06 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82A482166B26; Wed, 31 Aug 2022 18:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974444; 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=dEkZCIZPpUac0p0uyDaOROrDQmno3wDSJBFpz7t3bYU=; b=Pe2l/0gY8fx5PBU5QkXBnHa608YCLcL0vhzat1ru1ogGof/0FmhqALqSCp3XvIGiUipTdc OG2f+toLPhf+ymX/cW+w9tz1pQQw6nLu7D87bBMfTz9o3zeaBdYGZo99jFL7G8VSoGJ4yv LlUiRJsHw/5PG2XORSWgKOg3N7PwTHs= X-MC-Unique: loD8K4LtNiGLB1gqH6rI0g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 13/16] qemu: include nbdkit state in private xml Date: Wed, 31 Aug 2022 13:40:58 -0500 Message-Id: <20220831184101.716362-14-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 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: 1661974447784100001 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 --- src/qemu/qemu_domain.c | 51 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_nbdkit.c | 21 +++++++++++++++++ src/qemu/qemu_nbdkit.h | 4 ++++ 3 files changed, 76 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f69cfee0cf..cfc030cc9c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -21,6 +21,7 @@ =20 #include =20 +#include "qemu_conf.h" #include "qemu_domain.h" #include "qemu_alias.h" #include "qemu_block.h" @@ -1816,6 +1817,31 @@ qemuStorageSourcePrivateDataAssignSecinfo(qemuDomain= SecretInfo **secinfo, } =20 =20 +static int +qemuStorageSourcePrivateDataParseNbdkit(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStorageSource *src) +{ + qemuDomainStorageSourcePrivate *srcpriv =3D qemuDomainStorageSourcePri= vateFetch(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))) + return -1; + + if (!(socketfile =3D virXPathString("string(./socketfile)", ctxt))) + return -1; + + if (!srcpriv->nbdkitProcess) + srcpriv->nbdkitProcess =3D qemuNbdkitProcessLoad(src, pidfile, soc= ketfile); + + return 0; +} + + static int qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt, virStorageSource *src) @@ -1826,6 +1852,7 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr = ctxt, g_autofree char *httpcookiealias =3D NULL; g_autofree char *tlskeyalias =3D NULL; g_autofree char *thresholdEventWithIndex =3D NULL; + 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); @@ -1869,6 +1896,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 @@ -1886,6 +1917,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) @@ -1924,6 +1972,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 46d4a8a7ac..5a0c80def8 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -595,6 +595,27 @@ qemuNbdkitCapsCacheNew(const char *cachedir) } =20 =20 +qemuNbdkitProcess * +qemuNbdkitProcessLoad(virStorageSource *source, + const char *pidfile, + const char *socketfile) +{ + int rc; + qemuNbdkitProcess *nbdkit =3D g_new0(qemuNbdkitProcess, 1); + + nbdkit->pidfile =3D g_strdup(pidfile); + nbdkit->socketfile =3D g_strdup(socketfile); + nbdkit->source =3D virObjectRef(source); + nbdkit->user =3D -1; + nbdkit->group =3D -1; + + if ((rc =3D virPidFileReadPath(nbdkit->pidfile, &nbdkit->pid)) < 0) + VIR_WARN("Failed to read pidfile %s", nbdkit->pidfile); + + return nbdkit; +} + + static qemuNbdkitProcess * qemuNbdkitProcessNew(qemuNbdkitCaps *caps, virStorageSource *source, diff --git a/src/qemu/qemu_nbdkit.h b/src/qemu/qemu_nbdkit.h index 4fda5113a2..e84fd2eacc 100644 --- a/src/qemu/qemu_nbdkit.h +++ b/src/qemu/qemu_nbdkit.h @@ -83,4 +83,8 @@ void qemuNbdkitProcessFree(qemuNbdkitProcess *proc); =20 int qemuNbdkitProcessSetupCgroup(qemuNbdkitProcess *proc, virCgroup *cgrou= p); =20 +qemuNbdkitProcess * qemuNbdkitProcessLoad(virStorageSource *source, + const char *pidfile, + const char *socketfile); + G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuNbdkitProcess, qemuNbdkitProcessFree); --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661974804; cv=none; d=zohomail.com; s=zohoarc; b=Lki91uHpAX1cb7zLHjx45SKHScq55muHdIZYWPtQSkujtoAMwfp6RoNzCcp6aNQHhxX/qjjgOKg16TIlKGqJjMifo2M68jhGKhLOpLzzsBp6MzGUPvKq87GhBpk2ozsxrycnOX3kgv/YU28lJLs+bA/XXVz2czk0B53Ty1BgRXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661974804; 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=ICpUx8Q83pNcuGQNG1+NCCGDGM/bckcAIsCI64JSzsw=; b=lTvgrgc4Ma/q9k6En5RPckDmnG9j9UcgK4UwSqYwBFO5dajbRInK2Q+21XbkAMIZNxkkIK9xmOgFdOCTffTtVaUd0yzobcuvoL1eI/YCMRKCpGB9JMG/zWjTAnkz31/zRa/Ex4dFKha0IZZAU5ufZKsDsV86RMlUwp3rftLkEzo= 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 1661974804612541.6176083399266; Wed, 31 Aug 2022 12:40:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-124-zjLLsOBNNueD9Ds2d0WNEw-1; Wed, 31 Aug 2022 15:39:40 -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 05F691C0690F; Wed, 31 Aug 2022 19:39:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3E8E4010D2A; Wed, 31 Aug 2022 19:39:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D7E8A1946A62; Wed, 31 Aug 2022 19:39:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0E5ED1946A40 for ; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0067C2166B2A; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C440E2166B26; Wed, 31 Aug 2022 18:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661974803; 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=ICpUx8Q83pNcuGQNG1+NCCGDGM/bckcAIsCI64JSzsw=; b=EYVVb6zy1QzUN7oIixB7V9GcYxXKRVDeEKQOm1sqfaAg0WGm1EjvcsD2JAE6AQra4wauYC qDvXy8WScNr3Tw+xAFxFNadv2d3bTevW/Z/b9G0r4gchY0++JrDyaLQNMS+VuUuaAePuQW Guo02tq54pAuLp9FNrCbsv89wH0KV+A= X-MC-Unique: zjLLsOBNNueD9Ds2d0WNEw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 14/16] tests: add tests for nbdkit invocation Date: Wed, 31 Aug 2022 13:40:59 -0500 Message-Id: <20220831184101.716362-15-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 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: 1661974805036100001 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 --- src/qemu/qemu_nbdkit.c | 4 +- src/qemu/qemu_nbdkitpriv.h | 31 +++ tests/meson.build | 1 + .../disk-cdrom-network.args.disk0 | 7 + .../disk-cdrom-network.args.disk1 | 9 + .../disk-cdrom-network.args.disk2 | 9 + .../disk-network-http.args.disk0 | 7 + .../disk-network-http.args.disk1 | 6 + .../disk-network-http.args.disk2 | 7 + .../disk-network-http.args.disk3 | 8 + ...work-source-curl-nbdkit-backing.args.disk0 | 8 + .../disk-network-source-curl.args.disk0 | 8 + .../disk-network-source-curl.args.disk1 | 8 + .../disk-network-source-curl.args.disk2 | 8 + .../disk-network-source-curl.args.disk3 | 7 + .../disk-network-source-curl.args.disk4 | 7 + .../disk-network-ssh.args.disk0 | 7 + tests/qemunbdkittest.c | 220 ++++++++++++++++++ 18 files changed, 361 insertions(+), 1 deletion(-) 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.disk2 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.disk3 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl-nbdkit-ba= cking.args.disk0 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk0 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk1 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk2 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/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 5a0c80def8..0ecf6c6537 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -34,6 +34,8 @@ #include "qemu_driver.h" #include "qemu_extdevice.h" #include "qemu_nbdkit.h" +#define LIBVIRT_QEMU_NBDKITPRIV_H_ALLOW +#include "qemu_nbdkitpriv.h" #include "qemu_security.h" =20 #include @@ -779,7 +781,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 d6b1bb2bf0..f1eddc2fd6 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -451,6 +451,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..5f3a795ba0 --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk0 @@ -0,0 +1,7 @@ +nbdkit \ +--exit-with-parent \ +--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..257e331db8 --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk1 @@ -0,0 +1,9 @@ +nbdkit \ +--exit-with-parent \ +--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=3Discsi-mycluster_myname-secret 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..f7879a9f24 --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk2 @@ -0,0 +1,9 @@ +nbdkit \ +--exit-with-parent \ +--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=3Discsi-mycluster_myname-secret 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..fa8ef90cd1 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk0 @@ -0,0 +1,7 @@ +nbdkit \ +--exit-with-parent \ +--unix /tmp/statedir-0/nbdkit-test-disk-0.socket \ +--foreground curl \ +protocols=3Dhttp \ +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..9bac3fe229 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk1 @@ -0,0 +1,6 @@ +nbdkit \ +--exit-with-parent \ +--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..7286b684a8 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk2 @@ -0,0 +1,7 @@ +nbdkit \ +--exit-with-parent \ +--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \ +--foreground curl \ +protocols=3Dhttp \ +url=3Dhttp://example.org:1234/test3.img \ +'cookie=3Dtest=3Dtestcookievalue; test2=3D"blurb"' 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..da177c9e6d --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk3 @@ -0,0 +1,8 @@ +nbdkit \ +--exit-with-parent \ +--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=3Dtest=3Dtestcookievalue; test2=3D"blurb"' \ +sslverify=3Dfalse 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..b13f5ed628 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.dis= k0 @@ -0,0 +1,8 @@ +nbdkit \ +--exit-with-parent \ +--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=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2' 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..6de42c626f --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0 @@ -0,0 +1,8 @@ +nbdkit \ +--exit-with-parent \ +--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=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2' 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..9abc1578dd --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 @@ -0,0 +1,8 @@ +nbdkit \ +--exit-with-parent \ +--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=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2' \ +sslverify=3Dfalse 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..1ce11ce618 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 @@ -0,0 +1,8 @@ +nbdkit \ +--exit-with-parent \ +--unix /tmp/statedir-2/nbdkit-test-disk-2.socket \ +--foreground \ +--readonly curl \ +protocols=3Dhttp \ +url=3Dhttp://http.example.org:8080/path/to/disk2.iso \ +'cookie=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2; cookie3=3Dcookie= value3' 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..bc28f04564 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk3 @@ -0,0 +1,7 @@ +nbdkit \ +--exit-with-parent \ +--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..7c3cc711ae --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk4 @@ -0,0 +1,7 @@ +nbdkit \ +--exit-with-parent \ +--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..e0020dff6a --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-ssh.args.disk0 @@ -0,0 +1,7 @@ +nbdkit \ +--exit-with-parent \ +--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..c53601dac8 --- /dev/null +++ b/tests/qemunbdkittest.c @@ -0,0 +1,220 @@ +#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" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +static virQEMUDriver driver; + + +/* Some mock implementations for testing */ +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; +} TestInfo; + + +typedef enum { + NBDKIT_ARG_CAPS, + 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_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; + + 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; + const char *actualCmdline =3D NULL; + + virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); + cmd =3D qemuNbdkitProcessBuildCommand(srcPriv->nbdkitProcess); + + if (virCommandRun(cmd, NULL) < 0) { + ret =3D -1; + continue; + } + + if (!(actualCmdline =3D virBufferContentAndReset(&buf))) { + ret =3D -1; + continue; + } + + if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < = 0) { + ret =3D -1; + continue; + } + } else { + if (virFileExists(cmdfile)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "qemuNbdkitInitStorageSource() was not expe= cted to fail"); + ret =3D -1; + } + } + } + + return ret; +} + +static int +mymain(void) +{ + int ret =3D 0; + + if (qemuTestDriverInit(&driver) < 0) + return EXIT_FAILURE; + + +#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_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); + + qemuTestDriverFree(&driver); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661975033; cv=none; d=zohomail.com; s=zohoarc; b=Li8kzXM4h82+A/xTQiuwJASsl5fTThmO3epEJaOG5DdQ5eCt1ikwOW4MYBakZyCGvo4zXSY8il5MqnZYsyAnf6XGIsdJCwugJI4gDbKbUgbdInrv7Spt+BKWk/VknBaqZwbgMg+yXz5HjWTrWUosRBAF/iNB21niNY4EGqVljt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661975033; 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=ttNrVb7qjLb4GyxgnjOQe1bgJnAofmZk8llyBBQKxN4=; b=I6sLZyfops3MvD0tzWzCsa56GzM7tb5JjeeiMmJhkuq+UKLNraGdpKLKH6Gd3mFnKDYk2vc2Y3BC4iqGvjD2+SedpgVDxzGocylB9CNC+Met05LORo43MoJd+Ux3y3oWHP6L59elDu4sS+4PyY8yccG3g3B6ekGs5M3CO1uWop8= 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 1661975033874984.7996980318484; Wed, 31 Aug 2022 12:43:53 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-665-HZNtmQJSNhyJYlbrnDd8cA-1; Wed, 31 Aug 2022 15:43:51 -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 8CAD718188A0; Wed, 31 Aug 2022 19:43:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59EA74010D2A; Wed, 31 Aug 2022 19:43:48 +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 170E51946A45; Wed, 31 Aug 2022 19:43:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4A8931946A40 for ; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3ED752166B2A; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 140C92166B26; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661975032; 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=ttNrVb7qjLb4GyxgnjOQe1bgJnAofmZk8llyBBQKxN4=; b=dLM6kni5T16yKKI5nzpvbL9YgbKBLmCObd2x6ChvGfDzDBrhPZ3DVVtW+6Cj9qu6y/q51i x0mKM6OiVk2tw0Gn0sodRrRwcWy+fcg8PGKb3PWwTjMjU/eydkyTPHtApUV5ynfIuy0HMD aZQwu1fUlgOVZX3sJhpayHBgIAX1L58= X-MC-Unique: HZNtmQJSNhyJYlbrnDd8cA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 15/16] qemu: pass sensitive data to nbdkit via pipe Date: Wed, 31 Aug 2022 13:41:00 -0500 Message-Id: <20220831184101.716362-16-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 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: 1661975034367100001 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 --- build-aux/syntax-check.mk | 4 +- src/qemu/qemu_nbdkit.c | 162 ++++++++++++++++-- src/qemu/qemu_nbdkitpriv.h | 19 +- src/util/virutil.h | 2 +- .../disk-cdrom-network.args.disk1 | 2 +- .../disk-cdrom-network.args.disk1.pipe.45 | 1 + .../disk-cdrom-network.args.disk2 | 2 +- .../disk-cdrom-network.args.disk2.pipe.47 | 1 + .../disk-network-http.args.disk2 | 2 +- .../disk-network-http.args.disk2.pipe.45 | 1 + .../disk-network-http.args.disk3 | 2 +- .../disk-network-http.args.disk3.pipe.47 | 1 + ...work-source-curl-nbdkit-backing.args.disk0 | 2 +- ...rce-curl-nbdkit-backing.args.disk0.pipe.45 | 1 + .../disk-network-source-curl.args.disk0 | 2 +- ...isk-network-source-curl.args.disk0.pipe.45 | 1 + .../disk-network-source-curl.args.disk1 | 2 +- ...isk-network-source-curl.args.disk1.pipe.47 | 1 + .../disk-network-source-curl.args.disk2 | 2 +- ...isk-network-source-curl.args.disk2.pipe.49 | 1 + tests/qemunbdkittest.c | 57 +++++- 21 files changed, 238 insertions(+), 30 deletions(-) create mode 100644 tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe= .45 create mode 100644 tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe= .47 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.= 45 create mode 100644 tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.= 47 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl-nbdkit-ba= cking.args.disk0.pipe.45 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 0.pipe.45 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 1.pipe.47 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 2.pipe.49 diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 649eb91acb..c0cf730d13 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1363,10 +1363,10 @@ exclude_file_name_regexp--sc_prohibit_strdup =3D \ ^(docs/|examples/|tests/virnetserverclientmock.c|tests/commandhelper.c|t= ools/nss/libvirt_nss_(leases|macs)\.c$$) =20 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)$$) + (\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt= -stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c|qemunbd= kittest\.c)|tools/nss/libvirt_nss_(leases|macs)\.c)$$) =20 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF =3D \ - (^tests/(nodedevmdevctl|virhostcpu|virpcitest|virstoragetest)data/|docs/= js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$) + (^tests/(nodedevmdevctl|virhostcpu|virpcitest|virstoragetest|qemunbdkit)= data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newlin= e\.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 0ecf6c6537..2b8e203d16 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -55,6 +55,76 @@ VIR_ENUM_IMPL(qemuNbdkitCaps, "filter-readahead", /* QEMU_NBDKIT_CAPS_FILTER_READAHEAD */ ); =20 + +static void +nbdkitPipeItemFree(NbdkitPipeItem *item) +{ + if (item->buf) { + virSecureErase(item->buf, item->buflen); + g_free(item->buf); + } + + if (item->fd > 0) + VIR_FORCE_CLOSE(item->fd); + + g_free(item); +} + + +void nbdkitPipeDataFree(NbdkitPipeData *self) +{ + size_t i; + + if (!self) + return; + + for (i =3D 0; i < self->nitems; i++) { + nbdkitPipeItemFree(self->items[i]); + } + + g_free(self->items); + g_free(self); +} + + +static NbdkitPipeItem* +nbdkitPipeItemNew(int fd, void *data, int datalen) +{ + NbdkitPipeItem *d; + + if (!data || datalen =3D=3D 0) + return NULL; + + d =3D g_new0(NbdkitPipeItem, 1); + d->fd =3D fd; + + if (datalen < 0) { + /* -1 indicates a null-terminated string */ + d->buf =3D g_strdup(data); + d->buflen =3D strlen(data); + } else { + d->buf =3D g_malloc(datalen); + memcpy(d->buf, data, datalen); + d->buflen =3D datalen; + } + + return d; +} + + +static int +nbdkitPipeDataWrite(NbdkitPipeItem *pipe) +{ + if (safewrite(pipe->fd, pipe->buf, pipe->buflen) < 0) { + virReportSystemError(errno, + _("failed to write data to pipe %i for nbdkit= "), + pipe->fd); + return -1; + } + return 0; +} + + struct _qemuNbdkitCaps { GObject parent; =20 @@ -71,6 +141,12 @@ struct _qemuNbdkitCaps { G_DEFINE_TYPE(qemuNbdkitCaps, qemu_nbdkit_caps, G_TYPE_OBJECT); =20 =20 +enum { + PIPE_FD_READ =3D 0, + PIPE_FD_WRITE =3D 1 +}; + + static void qemuNbdkitCheckCommandCap(qemuNbdkitCaps *nbdkit, virCommand *cmd, @@ -685,12 +761,36 @@ qemuNbdkitInitStorageSource(qemuNbdkitCaps *caps, } =20 =20 +static NbdkitPipeItem* +commandPassDataByPipe(virCommand *cmd, + const char *argName, + char *buf, + size_t buflen) +{ + int fds[2] =3D { -1, -1 }; + g_autofree char *fdfmt =3D NULL; + + if (virPipe(fds) < 0) + return NULL; + + /* 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", fds[PIPE_FD_READ]); + virCommandAddArgPair(cmd, argName, fdfmt); + virCommandPassFD(cmd, fds[PIPE_FD_READ], VIR_COMMAND_PASS_FD_CLOSE_PAR= ENT); + + return nbdkitPipeItemNew(fds[PIPE_FD_WRITE], (char*)buf, buflen); +} + static int qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *proc, - virCommand *cmd) + virCommand *cmd, + NbdkitPipeData **pipeData) { g_autoptr(virURI) uri =3D qemuBlockStorageSourceGetURI(proc->source); g_autofree char *uristring =3D virURIFormat(uri); + g_autoptr(GPtrArray) pipes =3D + g_ptr_array_new_with_free_func((GDestroyNotify)nbdkitPipeDataFree); =20 /* nbdkit plugin name */ virCommandAddArg(cmd, "curl"); @@ -702,8 +802,9 @@ 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; + NbdkitPipeItem *pipe =3D NULL; =20 virCommandAddArgPair(cmd, "user", proc->source->auth->username); @@ -716,7 +817,7 @@ qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *pr= oc, } =20 if (virSecretGetSecretString(conn, - &proc->source->auth->seclookupdef, + &authdef->seclookupdef, secrettype, &secret, &secretlen) < 0) { @@ -725,18 +826,28 @@ qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *= proc, return -1; } =20 - /* ensure that the secret is a NULL-terminated string */ - password =3D g_strndup((char*)secret, secretlen); - - virCommandAddArgPair(cmd, "password", password); + if (!(pipe =3D commandPassDataByPipe(cmd, "password", (char*)secre= t, + secretlen))) { + virSecureErase(secret, secretlen); + return -1; + } =20 virSecureErase(secret, secretlen); - virSecureErase(password, secretlen); + g_ptr_array_add(pipes, pipe); } =20 - if (proc->source->ncookies > 0) - virCommandAddArgPair(cmd, "cookie", - qemuBlockStorageSourceGetCookieString(proc->s= ource)); + /* Create a pipe to send the cookies to the nbdkit process. */ + if (proc->source->ncookies) { + NbdkitPipeItem *pipe =3D NULL; + g_autofree char *cookies =3D + qemuBlockStorageSourceGetCookieString(proc->source); + + if (!(pipe =3D commandPassDataByPipe(cmd, "cookie", cookies, -1)))= { + return -1; + } + + g_ptr_array_add(pipes, pipe); + } =20 if (proc->source->sslverify =3D=3D VIR_TRISTATE_BOOL_NO) { virCommandAddArgPair(cmd, "sslverify", "false"); @@ -747,6 +858,10 @@ qemuNbdkitProcessBuildCommandCurl(qemuNbdkitProcess *p= roc, virCommandAddArgPair(cmd, "timeout", timeout); } =20 + *pipeData =3D g_new0(NbdkitPipeData, 1); + (*pipeData)->nitems =3D pipes->len; + (*pipeData)->items =3D (NbdkitPipeItem**)g_ptr_array_free(g_steal_poin= ter(&pipes), false); + return 0; } =20 @@ -781,8 +896,17 @@ qemuNbdkitProcessBuildCommandSSH(qemuNbdkitProcess *pr= oc, } =20 =20 +/* Builds a nbdkit command for the given disk source. + * + * Some sensitive data should be not be passed to nbdkit via commandline, = so + * this command may set up one or more pipes and pass the fd of these pipe= s to + * the nbdkit command. In that case, pipeData will return information abou= t the + * pipes and the information that must be written to that pipe (via + * nbdkitPipeDataWrite()) after the command has been executed. The pipeData + * elements should be freed after writing. */ virCommand * -qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc) +qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc, + NbdkitPipeData **pipeData) { g_autoptr(virCommand) cmd =3D virCommandNewArgList(proc->caps->path, "--exit-with-parent", @@ -806,7 +930,7 @@ qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc) case VIR_STORAGE_NET_PROTOCOL_FTP: case VIR_STORAGE_NET_PROTOCOL_FTPS: case VIR_STORAGE_NET_PROTOCOL_TFTP: - if (qemuNbdkitProcessBuildCommandCurl(proc, cmd) < 0) + if (qemuNbdkitProcessBuildCommandCurl(proc, cmd, pipeData) < 0) return NULL; break; case VIR_STORAGE_NET_PROTOCOL_SSH: @@ -869,8 +993,10 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, int exitstatus =3D 0; int cmdret =3D 0; int errfd =3D -1; + g_autoptr(NbdkitPipeData) pipes =3D NULL; + size_t i; =20 - if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc))) + if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc, &pipes))) return -1; =20 virCommandSetErrorFD(cmd, &errfd); @@ -888,6 +1014,14 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, goto error; } =20 + if (pipes) { + for (i =3D 0; i < pipes->nitems; i++) { + NbdkitPipeItem *pipe =3D pipes->items[i]; + if (nbdkitPipeDataWrite(pipe) < 0) + goto error; + } + } + if ((rc =3D virPidFileReadPath(proc->pidfile, &proc->pid)) < 0) { virReportSystemError(-rc, _("Failed to read pidfile %s"), diff --git a/src/qemu/qemu_nbdkitpriv.h b/src/qemu/qemu_nbdkitpriv.h index 64f9bb99d8..a4cc61bb2c 100644 --- a/src/qemu/qemu_nbdkitpriv.h +++ b/src/qemu/qemu_nbdkitpriv.h @@ -27,5 +27,20 @@ =20 #include "qemu_nbdkit.h" =20 -virCommand * -qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc); +typedef struct { + int fd; + void *buf; + size_t buflen; +} NbdkitPipeItem; + +typedef struct { + size_t nitems; + NbdkitPipeItem **items; +} NbdkitPipeData; + +void nbdkitPipeDataFree(NbdkitPipeData *pipedata); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(NbdkitPipeData, nbdkitPipeDataFree); + +virCommand* qemuNbdkitProcessBuildCommand(qemuNbdkitProcess *proc, + NbdkitPipeData **pipeData); diff --git a/src/util/virutil.h b/src/util/virutil.h index ab8511bf8d..094b399859 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -186,7 +186,7 @@ char *virGetPassword(void); * * Returns: -1 on error, 0 on success */ -int virPipe(int fds[2]); +int virPipe(int fds[2]) G_NO_INLINE; =20 /* * virPipeQuiet: diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk1 b/tests/qem= unbdkitdata/disk-cdrom-network.args.disk1 index 257e331db8..da9e507f1b 100644 --- a/tests/qemunbdkitdata/disk-cdrom-network.args.disk1 +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk1 @@ -6,4 +6,4 @@ nbdkit \ protocols=3Dftps \ url=3Dftps://host.name:990/url/path/file.iso \ user=3Dtestuser \ -password=3Discsi-mycluster_myname-secret +password=3D-44 diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.45 b/t= ests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.45 new file mode 100644 index 0000000000..ccdd4033fc --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk1.pipe.45 @@ -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 index f7879a9f24..0742b29853 100644 --- a/tests/qemunbdkitdata/disk-cdrom-network.args.disk2 +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk2 @@ -6,4 +6,4 @@ nbdkit \ protocols=3Dhttps \ 'url=3Dhttps://host.name:443/url/path/file.iso?test=3Dval' \ user=3Dtestuser \ -password=3Discsi-mycluster_myname-secret +password=3D-46 diff --git a/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.47 b/t= ests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.47 new file mode 100644 index 0000000000..ccdd4033fc --- /dev/null +++ b/tests/qemunbdkitdata/disk-cdrom-network.args.disk2.pipe.47 @@ -0,0 +1 @@ +iscsi-mycluster_myname-secret \ No newline at end of file diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk2 b/tests/qemu= nbdkitdata/disk-network-http.args.disk2 index 7286b684a8..767ea881d8 100644 --- a/tests/qemunbdkitdata/disk-network-http.args.disk2 +++ b/tests/qemunbdkitdata/disk-network-http.args.disk2 @@ -4,4 +4,4 @@ nbdkit \ --foreground curl \ protocols=3Dhttp \ url=3Dhttp://example.org:1234/test3.img \ -'cookie=3Dtest=3Dtestcookievalue; test2=3D"blurb"' +cookie=3D-44 diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.45 b/te= sts/qemunbdkitdata/disk-network-http.args.disk2.pipe.45 new file mode 100644 index 0000000000..2c42c95930 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk2.pipe.45 @@ -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 index da177c9e6d..30dfd15861 100644 --- a/tests/qemunbdkitdata/disk-network-http.args.disk3 +++ b/tests/qemunbdkitdata/disk-network-http.args.disk3 @@ -4,5 +4,5 @@ nbdkit \ --foreground curl \ protocols=3Dhttps \ 'url=3Dhttps://example.org:1234/test4.img?par=3Dval&other=3Dble' \ -'cookie=3Dtest=3Dtestcookievalue; test2=3D"blurb"' \ +cookie=3D-46 \ sslverify=3Dfalse diff --git a/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.47 b/te= sts/qemunbdkitdata/disk-network-http.args.disk3.pipe.47 new file mode 100644 index 0000000000..2c42c95930 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-http.args.disk3.pipe.47 @@ -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 index b13f5ed628..d5ad545cdc 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.dis= k0 +++ b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.dis= k0 @@ -5,4 +5,4 @@ nbdkit \ --readonly curl \ protocols=3Dhttps \ url=3Dhttps://https.example.org:8443/path/to/disk1.qcow2 \ -'cookie=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2' +cookie=3D-44 diff --git a/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.a= rgs.disk0.pipe.45 b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-ba= cking.args.disk0.pipe.45 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl-nbdkit-backing.args.dis= k0.pipe.45 @@ -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 index 6de42c626f..3ea686e14f 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk0 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0 @@ -5,4 +5,4 @@ nbdkit \ --readonly curl \ protocols=3Dhttps \ url=3Dhttps://https.example.org:8443/path/to/disk1.iso \ -'cookie=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2' +cookie=3D-44 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.= 45 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.45 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk0.pipe.45 @@ -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 index 9abc1578dd..fb77794b56 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 @@ -4,5 +4,5 @@ nbdkit \ --foreground curl \ protocols=3Dhttps \ 'url=3Dhttps://https.example.org:8443/path/to/disk5.iso?foo=3Dbar' \ -'cookie=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2' \ +cookie=3D-46 \ sslverify=3Dfalse diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.= 47 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.47 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.47 @@ -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 1ce11ce618..eab66746ef 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 @@ -5,4 +5,4 @@ nbdkit \ --readonly curl \ protocols=3Dhttp \ url=3Dhttp://http.example.org:8080/path/to/disk2.iso \ -'cookie=3Dcookie1=3Dcookievalue1; cookie2=3Dcookievalue2; cookie3=3Dcookie= value3' +cookie=3D-48 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.= 49 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.49 new file mode 100644 index 0000000000..5c035e84c5 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.49 @@ -0,0 +1 @@ +cookie1=3Dcookievalue1; cookie2=3Dcookievalue2; cookie3=3Dcookievalue3 \ No newline at end of file diff --git a/tests/qemunbdkittest.c b/tests/qemunbdkittest.c index c53601dac8..a18567e9b4 100644 --- a/tests/qemunbdkittest.c +++ b/tests/qemunbdkittest.c @@ -13,6 +13,7 @@ #include "virutil.h" #include "virsecret.h" #include "datatypes.h" +#include "virmock.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -20,6 +21,41 @@ static virQEMUDriver driver; =20 =20 /* Some mock implementations for testing */ +#define PIPE_FD_START 44 +static int mockpipefd =3D PIPE_FD_START; +int +virPipe(int fds[2]) +{ + fds[0] =3D mockpipefd++; + fds[1] =3D mockpipefd++; + + return 0; +} + +static int (*real_close)(int fd); +static void +init_syms(void) +{ + VIR_MOCK_REAL_INIT(close); +} + +int +close(int fd) +{ + int ret; + + init_syms(); + + if (fd >=3D PIPE_FD_START) + ret =3D 0; + else + ret =3D real_close(fd); + + return ret; +} + + + int virSecretGetSecretString(virConnectPtr conn G_GNUC_UNUSED, virSecretLookupTypeDef *seclookupdef, @@ -124,6 +160,9 @@ testNbdkit(const void *data) size_t i; int ret =3D 0; =20 + /* 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); @@ -149,9 +188,11 @@ testNbdkit(const void *data) g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDry= RunTokenNew(); g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; const char *actualCmdline =3D NULL; + g_autoptr(NbdkitPipeData) pipes =3D NULL; + size_t j; =20 virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); - cmd =3D qemuNbdkitProcessBuildCommand(srcPriv->nbdkitProcess); + cmd =3D qemuNbdkitProcessBuildCommand(srcPriv->nbdkitProcess, = &pipes); =20 if (virCommandRun(cmd, NULL) < 0) { ret =3D -1; @@ -163,9 +204,19 @@ testNbdkit(const void *data) continue; } =20 - if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < = 0) { + if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < = 0) ret =3D -1; - continue; + + if (pipes) { + for (j =3D 0; j < pipes->nitems; j++) { + NbdkitPipeItem *item =3D pipes->items[j]; + g_autofree char *pipefile =3D g_strdup_printf("%s.pipe= .%i", + cmdfile, + item->fd); + + if (virTestCompareToFile(item->buf, pipefile) < 0) + ret =3D -1; + } } } else { if (virFileExists(cmdfile)) { --=20 2.37.1 From nobody Sat May 18 05:34:56 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=1661976154; cv=none; d=zohomail.com; s=zohoarc; b=TwB99cmi4nCrszJXlntwKm9Zpp5k/bnQPzlLeUyNCaM7txxpw9UdozOA9bH6ng7maaUiHAA3/V78KQiEnjkiFK8JQa7wWY9PQBxQ8J26HrxlOrwH/ZIV/BXLeRrbiKOHcNrnWS8WzO1NRWcAJS3JbIOoMSUA5u7qmWbJc7MsudQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661976154; 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=llFAGmI5nQk7vWnDaL49ipKoYAuruczKkJqtXpTZMxU=; b=imNEmfdcMARonLjB+BW9D/EO8j9zzYUvLuVTZq6CY2CJCFqyvbXjnLh1hyLdVyr8s/rdzSMpGQnpB96YWcvBTMYmUgu7BCgIn8OHq8OGG+ioGb3r7Bqx5Z7fBqnr81eDr5OFm3t9++W21xIRPqxh1iUFLXfGZlovB6jyK78y7vY= 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 1661976154454584.8370906585479; Wed, 31 Aug 2022 13:02:34 -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-136-ln4d-4XEMlGlGIp60o267w-1; Wed, 31 Aug 2022 16:02:32 -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 767DD8E48F0; Wed, 31 Aug 2022 20:02:28 +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 5E89F40D2832; Wed, 31 Aug 2022 20:02:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CC6911946A68; Wed, 31 Aug 2022 20:02:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 98E101946A40 for ; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7DB662166B2B; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.10.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53CF52166B26; Wed, 31 Aug 2022 18:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661976153; 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=llFAGmI5nQk7vWnDaL49ipKoYAuruczKkJqtXpTZMxU=; b=hmyLWx9xufvD5VuLeb+ng8CvnbnZTgZfIHxu3NhOWdXJCXPr/W8IKOngBHqIaJlZbMnHT/ Q3QU880mn8pzz6cHi+ReGciOsMOfrkDTt0VdnCmF2maWXlBp6fTbfTUuTJznGxBPsgB224 KeVDZ5ukPtlpkqUOJzwVXh0kwEWQZZE= X-MC-Unique: ln4d-4XEMlGlGIp60o267w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 16/16] qemu: add test for authenticating a https network disk Date: Wed, 31 Aug 2022 13:41:01 -0500 Message-Id: <20220831184101.716362-17-jjongsma@redhat.com> In-Reply-To: <20220831184101.716362-1-jjongsma@redhat.com> References: <20220831184101.716362-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: pkrempa@redhat.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 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: 1661976155853100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Jonathon Jongsma --- tests/qemunbdkitdata/disk-network-source-curl.args.1.pipe.1 | 1 + tests/qemunbdkitdata/disk-network-source-curl.args.disk1 | 4 +++- .../disk-network-source-curl.args.disk1.pipe.47 | 2 +- .../disk-network-source-curl.args.disk1.pipe.49 | 1 + tests/qemunbdkitdata/disk-network-source-curl.args.disk2 | 2 +- .../disk-network-source-curl.args.disk2.pipe.51 | 1 + .../disk-network-source-curl.x86_64-latest.args | 3 ++- tests/qemuxml2argvdata/disk-network-source-curl.xml | 3 +++ 8 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.1.pi= pe.1 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 1.pipe.49 create mode 100644 tests/qemunbdkitdata/disk-network-source-curl.args.disk= 2.pipe.51 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.1.pipe.1 b/= tests/qemunbdkitdata/disk-network-source-curl.args.1.pipe.1 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.1.pipe.1 @@ -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 index fb77794b56..7a5ebee46e 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1 @@ -4,5 +4,7 @@ nbdkit \ --foreground curl \ protocols=3Dhttps \ 'url=3Dhttps://https.example.org:8443/path/to/disk5.iso?foo=3Dbar' \ -cookie=3D-46 \ +user=3Dmyname \ +password=3D-46 \ +cookie=3D-48 \ sslverify=3Dfalse diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.= 47 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.47 index 20af4ae383..ccdd4033fc 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.47 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.47 @@ -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.= 49 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.49 new file mode 100644 index 0000000000..20af4ae383 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk1.pipe.49 @@ -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 eab66746ef..00151a10b0 100644 --- a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2 @@ -5,4 +5,4 @@ nbdkit \ --readonly curl \ protocols=3Dhttp \ url=3Dhttp://http.example.org:8080/path/to/disk2.iso \ -cookie=3D-48 +cookie=3D-50 diff --git a/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.= 51 b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.51 new file mode 100644 index 0000000000..5c035e84c5 --- /dev/null +++ b/tests/qemunbdkitdata/disk-network-source-curl.args.disk2.pipe.51 @@ -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 ec6dd13f6c..7f09e84227 100644 --- a/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-network-source-curl.x86_64-latest.args @@ -33,9 +33,10 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.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-format-encryption-secret0","= data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","k= eyid":"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"}'= \ --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.37.1