From nobody Mon Feb 9 20:35:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621601425; cv=none; d=zohomail.com; s=zohoarc; b=i/jJLXsOPM1OlplPPDhJvMZOXL+5cXRRptlJYx9V09ly6tzBbX39FTyQdju87eDKWhuawjLMUToEb8z45Ctpt4arBIDbfbW9sUlZALbo7Qh/LNeNeY/BR0QGd67CSHNjU0/vbyXxaxCcdGY2x4deLnXFXJiaJlUwlcBWe2XORMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621601425; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h89YmQSYNMpMKSGJWmGzFDkDHrq7bC+i5+LyWi8INJQ=; b=MaB00/TAvhAi4Nr1/i8vfoe99Bi3llfZlirAUlV2BE1PJOcsj8POnM+A8Ka6/iwnABBCN+Th3mAjLx1H/E7AyeizopT3fXtI9rC6OmyreC0wE1KjdJ4uSSHiXQErpt6jwc5Irze5Jg/EDH2LSyMr7AEzB/0Cegog6LAjLeLoNlg= 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) header.from= 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 162160142568191.58599920094571; Fri, 21 May 2021 05:50:25 -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-547-SyxbtEsZOyi6i6jmR9QbCw-1; Fri, 21 May 2021 08:48:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BEB498A9F51; Fri, 21 May 2021 12:48:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 961D75D9D5; Fri, 21 May 2021 12:48:29 +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 2EADE1804480; Fri, 21 May 2021 12:48:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14LCmQwc031548 for ; Fri, 21 May 2021 08:48:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id C12B95945B; Fri, 21 May 2021 12:48:26 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 276AE421F for ; Fri, 21 May 2021 12:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621601424; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=h89YmQSYNMpMKSGJWmGzFDkDHrq7bC+i5+LyWi8INJQ=; b=HEtB9VerhSsNpTVB/s2alzNHmKPXvfCNNKJvAqTO1eEOSZHdwIdDQ1ddlAqzXR7cHjfFkj sudOSUTcDkbbCEQVXUoINBgs5BkV3j+LKKIsNTToH4bSMZ2PGOXpW3S9qx6ECuDx8TqFPb iMjDjLC/BTV0xbhJpJ+YLTHUzrA/h0s= X-MC-Unique: SyxbtEsZOyi6i6jmR9QbCw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 30/35] qemuDomainAttachDiskGeneric: Implement hotplug of disk Date: Fri, 21 May 2021 14:47:30 +0200 Message-Id: <9178c5c24feed0d03e79035420f44fcdbf283918.1621601161.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add code which creates the transient overlay after hotplugging the disk backend before attaching the disk frontend. The state of the topmost image is modified to be already read-only to prevent the need to open the image in read-write mode. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 52 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index e13a739ade..59832ea2b3 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -34,6 +34,7 @@ #include "qemu_process.h" #include "qemu_security.h" #include "qemu_block.h" +#include "qemu_snapshot.h" #include "domain_audit.h" #include "netdev_bandwidth_conf.h" #include "domain_nwfilter.h" @@ -685,6 +686,25 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver, } +static qemuSnapshotDiskContext * +qemuDomainAttachDiskGenericTransient(virDomainObj *vm, + virDomainDiskDef *disk, + GHashTable *blockNamedNodeData) +{ + g_autoptr(qemuSnapshotDiskContext) snapctxt =3D NULL; + g_autoptr(virDomainSnapshotDiskDef) snapdiskdef =3D NULL; + + snapdiskdef =3D qemuSnapshotGetTransientDiskDef(disk, vm->def->name); + snapctxt =3D qemuSnapshotDiskContextNew(1, vm, QEMU_ASYNC_JOB_NONE); + + if (qemuSnapshotDiskPrepareOne(snapctxt, disk, snapdiskdef, + blockNamedNodeData, false, false) < 0) + return NULL; + + return g_steal_pointer(&snapctxt); +} + + /** * qemuDomainAttachDiskGeneric: * @@ -701,6 +721,11 @@ qemuDomainAttachDiskGeneric(virQEMUDriver *driver, bool blockdev =3D virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); bool extensionDeviceAttached =3D false; int rc; + g_autoptr(qemuSnapshotDiskContext) transientDiskSnapshotCtxt =3D NULL; + bool origReadonly =3D disk->src->readonly; + + if (disk->transient) + disk->src->readonly =3D true; if (virStorageSourceGetActualType(disk->src) =3D=3D VIR_STORAGE_TYPE_V= HOST_USER) { if (!(data =3D qemuBuildStorageSourceChainAttachPrepareChardev(dis= k))) @@ -723,6 +748,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriver *driver, return -1; } + disk->src->readonly =3D origReadonly; + qemuDomainObjEnterMonitor(driver, vm); rc =3D qemuBlockStorageSourceChainAttach(priv->mon, data); @@ -733,6 +760,25 @@ qemuDomainAttachDiskGeneric(virQEMUDriver *driver, if (rc < 0) goto rollback; + if (disk->transient) { + g_autoptr(qemuBlockStorageSourceAttachData) backend =3D NULL; + g_autoptr(GHashTable) blockNamedNodeData =3D NULL; + + if (!(blockNamedNodeData =3D qemuBlockGetNamedNodeData(vm, QEMU_AS= YNC_JOB_NONE))) + goto rollback; + + if (!(transientDiskSnapshotCtxt =3D qemuDomainAttachDiskGenericTra= nsient(vm, disk, blockNamedNodeData))) + goto rollback; + + + if (qemuSnapshotDiskCreate(transientDiskSnapshotCtxt) < 0) + goto rollback; + + QEMU_DOMAIN_DISK_PRIVATE(disk)->transientOverlayCreated =3D true; + backend =3D qemuBlockStorageSourceDetachPrepare(disk->src, NULL); + ignore_value(VIR_INSERT_ELEMENT(data->srcdata, 0, data->nsrcdata, = backend)); + } + if (!(devstr =3D qemuBuildDiskDeviceStr(vm->def, disk, priv->qemuCaps)= )) goto rollback; @@ -937,12 +983,6 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *= driver, return -1; } - if (disk->transient) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("transient disk hotplug isn't supported")); - return -1; - } - if (virDomainDiskTranslateSourcePool(disk) < 0) goto cleanup; --=20 2.31.1