From nobody Mon Feb 9 02:28:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1598623870; cv=none; d=zohomail.com; s=zohoarc; b=GaFIMCJ85Wli94OgdQXO08ejLeUZB3mcIgOcYmtXOCc94Z/eJqEEXbdDTeAtQIqQwpmjrsKiFtoMoXkYLr2y1ZkovLCaZjOCz7N8UZ/WSLL+EdvtVPdnv6vSUxhP5mmhglaBgRVd7xMRuVnN36LqARC6O8+dpil0uHVc/qD//AA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598623870; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Kna0yLSi2xgCgzHy9brlJaTF6N8ExYG7T8j+FRl1sB4=; b=F9CpJZAazzFht7rcA3eoSnePdfFtxxzfRSvnEoP3Iugyn8Zcz+hGI64XlWPVFjKsz0lNViSOdzbIEy1/5ZFILr5b3HHcoPURkM/FJ1AYH6eZyPCU6U1DnYY/UE6AOP79pxbS8Vk6E3B886Iw6ScA7PXi3c9M5PxnKMd3NLV1OeU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1598623870747758.2446312350805; Fri, 28 Aug 2020 07:11:10 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-gAIcWGvVM1qK2l0FsHZp6g-1; Fri, 28 Aug 2020 10:11:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E62C485C737; Fri, 28 Aug 2020 14:10:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4FB76716C; Fri, 28 Aug 2020 14:10:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 94F3A7986D; Fri, 28 Aug 2020 14:10:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07SEAnMe028116 for ; Fri, 28 Aug 2020 10:10:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 696122156A23; Fri, 28 Aug 2020 14:10:49 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 642832166B27 for ; Fri, 28 Aug 2020 14:10:49 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4A644852701 for ; Fri, 28 Aug 2020 14:10:49 +0000 (UTC) Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-1T0HPj1XMBOcM-F8EXODeQ-1; Fri, 28 Aug 2020 10:10:44 -0400 Received: by mail-qk1-f193.google.com with SMTP id w186so1036778qkd.1; Fri, 28 Aug 2020 07:10:44 -0700 (PDT) Received: from localhost (209-6-122-159.s2973.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [209.6.122.159]) by smtp.gmail.com with ESMTPSA id y14sm1083153qtc.84.2020.08.28.07.10.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Aug 2020 07:10:43 -0700 (PDT) X-MC-Unique: gAIcWGvVM1qK2l0FsHZp6g-1 X-MC-Unique: 1T0HPj1XMBOcM-F8EXODeQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Kna0yLSi2xgCgzHy9brlJaTF6N8ExYG7T8j+FRl1sB4=; b=DHxDd4sf85WqtBWLsjslUqnE3OXpTShz70wTp6c1Gs+ZHEdIfcce3DqdVuY46yEoBL zWt4WLg3RGJPGq2BH39QsBWQ1Liopg+C4mc3DqGbt7hpQHmc6vZK6bBTA8nBN+gzwKnN Xx/wbw1PN2tVT0n/6ChHH3uKoKhWyrZ/mEe6pMrmWHZ1jOQKx3CIGkZ2+SDCM3Hb2KiF 0kmJ0Pyn+Xe8hs2CnCgM9ZUauneTYZ0LLAiB0qtb3wekK9ELF5REM1Aio7TcTpc6oIVC Ic5CTnKlHGmTUkdyzpzliyaA3YFinuX9uiiMR6hdtxLhxygO/3FWJ93YVnxLUoqeeb+m iOWA== X-Gm-Message-State: AOAM5336ja0dG0LPnnSpbpPtCH3R1/mO/MofE44iu8Yq5tzZ8AacPpGB 9Vefb2XOkdH5ow/nNnIJEZdeub2/t6QD X-Google-Smtp-Source: ABdhPJzCO1STDJrf+OhXGHd+o6G6daOH/Twd4Cnfz2r1GXup54ebIsueIS5VWyGj4hMEtobQAnTtKA== X-Received: by 2002:a37:84f:: with SMTP id 76mr1341952qki.251.1598623843568; Fri, 28 Aug 2020 07:10:43 -0700 (PDT) From: Masayoshi Mizuma To: libvirt-list@redhat.com, Eric Blake , Peter Krempa Subject: [PATCH v2 2/7] qemu: Introduce functions to handle transient disk Date: Fri, 28 Aug 2020 10:08:31 -0400 Message-Id: <20200828140836.14266-3-msys.mizuma@gmail.com> In-Reply-To: <20200828140836.14266-1-msys.mizuma@gmail.com> References: <20200828140836.14266-1-msys.mizuma@gmail.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false; X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Masayoshi Mizuma , Masayoshi Mizuma , qemu-block@nongnu.org X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Masayoshi Mizuma Here is the implementation of transient option for qcow2 and raw format disk. This gets available directive in domain xml file like as: When the qemu command line options are built, a new qcow2 image is created with backing qcow2 by using blockdev-snapshot command. The backing image is the qcow2 file which is set as . The filename of the new qcow2 image is original-source-file.TRANSIENT. Signed-off-by: Masayoshi Mizuma --- src/qemu/qemu_snapshot.c | 134 ++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_snapshot.h | 8 +++ src/util/virstoragefile.h | 2 + 3 files changed, 144 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index d310e6ff02..5c61d19f26 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2265,3 +2265,137 @@ qemuSnapshotDelete(virDomainObjPtr vm, cleanup: return ret; } + +static int +qemuTransientDiskPrepareOne(virQEMUDriverPtr driver, + virDomainObjPtr vm, + qemuSnapshotDiskDataPtr data, + virHashTablePtr blockNamedNodeData, + int asyncJob, + virJSONValuePtr actions) +{ + int rc =3D -1; + virStorageSourcePtr dest; + virStorageSourcePtr src =3D data->disk->src; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); + + if (!strlen(src->path)) + return rc; + + if (!(dest =3D virStorageSourceNew())) + return rc; + + dest->path =3D g_strdup_printf("%s.TRANSIENT", src->path); + + if (virFileExists(dest->path)) { + virReportError(VIR_ERR_INVALID_ARG, + _("Transient disk '%s' for '%s' exists"), + dest->path, src->path); + goto cleanup; + } + + dest->type =3D VIR_STORAGE_TYPE_FILE; + dest->format =3D VIR_STORAGE_FILE_QCOW2; + data->src =3D dest; + + if (qemuSnapshotDiskPrepareOne(driver, vm, cfg, data->disk, + NULL, data, blockNamedNodeData, + false, true, asyncJob, actions) <= 0) + goto cleanup; + + rc =3D 0; + cleanup: + if (rc < 0) + g_free(dest->path); + + return rc; +} + +static int +qemuWaitTransaction(virQEMUDriverPtr driver, + virDomainObjPtr vm, + int asyncJob, + virJSONValuePtr *actions) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + return -1; + + if (qemuMonitorTransaction(priv->mon, actions) < 0) + return -1; + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + return -1; + + return 0; +} + +int +qemuTransientCreatetDisk(virQEMUDriverPtr driver, + virDomainObjPtr vm, + int asyncJob) +{ + size_t i; + int rc =3D -1; + size_t ndata =3D 0; + qemuSnapshotDiskDataPtr data =3D NULL; + g_autoptr(virJSONValue) actions =3D NULL; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + g_autoptr(virHashTable) blockNamedNodeData =3D NULL; + bool blockdev =3D virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); + + if (!blockdev) + return rc; + + if (VIR_ALLOC_N(data, vm->def->ndisks) < 0) + return rc; + + if (!(blockNamedNodeData =3D qemuBlockGetNamedNodeData(vm, asyncJob))) + goto cleanup; + + if (!(actions =3D virJSONValueNewArray())) + goto cleanup; + + for (i =3D 0; i < vm->def->ndisks; i++) { + virDomainDiskDefPtr disk =3D vm->def->disks[i]; + + if (disk->src->readonly) + continue; + + if (disk->transient) { + data[ndata].disk =3D disk; + if (qemuTransientDiskPrepareOne(driver, vm, &data[ndata], bloc= kNamedNodeData, + asyncJob, actions) < 0) + goto cleanup; + ndata++; + } + } + + if (qemuWaitTransaction(driver, vm, asyncJob, &actions) < 0) + goto cleanup; + + for (i =3D 0; i < ndata; i++) { + qemuSnapshotDiskDataPtr dd =3D &data[i]; + + qemuSnapshotDiskUpdateSource(driver, vm, dd, blockdev); + dd->disk->src->transientEstablished =3D true; + } + + VIR_FREE(data); + rc =3D 0; + cleanup: + qemuSnapshotDiskCleanup(data, vm->def->ndisks, driver, vm, asyncJob); + + return rc; +} + +void +qemuTransientRemoveDisk(virDomainDiskDefPtr disk) +{ + if (disk->src->transientEstablished) { + VIR_DEBUG("unlink transient disk: %s", disk->src->path); + unlink(disk->src->path); + } +} diff --git a/src/qemu/qemu_snapshot.h b/src/qemu/qemu_snapshot.h index 8b3ebe87b1..aecb1762d2 100644 --- a/src/qemu/qemu_snapshot.h +++ b/src/qemu/qemu_snapshot.h @@ -53,3 +53,11 @@ int qemuSnapshotDelete(virDomainObjPtr vm, virDomainSnapshotPtr snapshot, unsigned int flags); + +int +qemuTransientCreatetDisk(virQEMUDriverPtr driver, + virDomainObjPtr vm, + int asyncJob); + +void +qemuTransientRemoveDisk(virDomainDiskDefPtr disk); diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index f73b3ee005..fd42d017f3 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -383,6 +383,8 @@ struct _virStorageSource { /* these must not be used apart from formatting the output JSON in the= qemu driver */ char *ssh_user; bool ssh_host_key_check_disabled; + + bool transientEstablished; }; =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref); --=20 2.27.0