From nobody Tue Feb 10 07:41:06 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=1621601323; cv=none; d=zohomail.com; s=zohoarc; b=XRTZW9xmMrtnXxMytAtu8lF6FUNaMFliOVo2hSqcL7AmRHqKVNPFzuofAQ54QME70S7hN3QfonAzcK68z/fcZ+RanG75fbFvNUVDH/1RQxD+ju2NdrMJHb7kWp09cGUYM7jCNzJy9BlWgjGRpU7e73MKbaXJCv8NSi0E9NS83pY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621601323; 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=8arLAWkecMQTJ/68qjj881hIrAOGWrXTAkkC7GhUuwI=; b=ISCBi3INrRM29w3jf3Pc4FmdpNRnw6J+4W14Jx7gDljfdCog8Lawjogyaa+ijZMrlhaCI27TC0F78diiBCuTJws45Mln8TBeFFgprqdYBS8rZLTQttY/dOcI7nf90bg0qmo9UJplfU4mhzY0wVcpjP82UWQ8z0NvvTK5Rmiyj40= 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 1621601323156899.3119940177666; Fri, 21 May 2021 05:48:43 -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-518-HTUHjKkdOrG6vzoG5tFEsA-1; Fri, 21 May 2021 08:48:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D09319253C5; Fri, 21 May 2021 12:48:34 +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 2AE9110027A5; Fri, 21 May 2021 12:48:34 +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 E9F0E1801263; Fri, 21 May 2021 12:48:33 +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 14LCmUMS031648 for ; Fri, 21 May 2021 08:48:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id E866C5945B; Fri, 21 May 2021 12:48:30 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57399421F for ; Fri, 21 May 2021 12:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621601322; 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=8arLAWkecMQTJ/68qjj881hIrAOGWrXTAkkC7GhUuwI=; b=RZlklh42QtdkBI5BDOZ90e1tVXYbd3NiEGcD/OWlKXVjgs9CqHnckKQWeu1He8lO/1g3cY dkSREGcaR7NoWaTcT0AuEghSJLLHVnMz0A2LIQO1Uo4Bw7hZnyQ8fiv2e63c5QbJIs7lcY rYcczvOJbPSFUut1IWwraY49wzR0h7s= X-MC-Unique: HTUHjKkdOrG6vzoG5tFEsA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 34/35] qemu: Allow disks with images shared accross VMs Date: Fri, 21 May 2021 14:47:34 +0200 Message-Id: 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.84 on 10.5.11.22 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" Implement this behaviour by skipping the disks on traditional commandline and hotplug them before resuming CPUs. That allows to use the support for hotplugging of transient disks which inherently allows sharing of the backing image as we open it read-only. This commit implements the validation code to allow it only with buses supporting hotplug and the hotplug code while starting up the VM. When we have such disk we need to issue a system-reset so that firmware tables are regenerated to allow booting from such device. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 6 ++++++ src/qemu/qemu_process.c | 45 +++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_validate.c | 24 +++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9c32fd16b5..697324eea5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2164,6 +2164,12 @@ qemuBuildDisksCommandLine(virCommand *cmd, for (i =3D 0; i < def->ndisks; i++) { virDomainDiskDef *disk =3D def->disks[i]; + /* transient disks with shared backing image will be hotplugged af= ter + * the VM is started */ + if (disk->transient && + disk->transientShareBacking =3D=3D VIR_TRISTATE_BOOL_YES) + continue; + if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps) < 0) return -1; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9302180403..c0b4f3530f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7017,7 +7017,8 @@ qemuProcessSetupDisksTransientSnapshot(virDomainObj *= vm, virDomainDiskDef *domdisk =3D vm->def->disks[i]; g_autoptr(virDomainSnapshotDiskDef) snapdisk =3D NULL; - if (!domdisk->transient) + if (!domdisk->transient || + domdisk->transientShareBacking =3D=3D VIR_TRISTATE_BOOL_YES) continue; /* validation code makes sure that we do this only for local disks @@ -7048,6 +7049,45 @@ qemuProcessSetupDisksTransientSnapshot(virDomainObj = *vm, } +static int +qemuProcessSetupDisksTransientHotplug(virDomainObj *vm, + qemuDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + bool hasHotpluggedDisk =3D false; + size_t i; + + for (i =3D 0; i < vm->def->ndisks; i++) { + virDomainDiskDef *domdisk =3D vm->def->disks[i]; + + if (!domdisk->transient || + domdisk->transientShareBacking !=3D VIR_TRISTATE_BOOL_YES) + continue; + + if (qemuDomainAttachDiskGeneric(priv->driver, vm, domdisk, asyncJo= b) < 0) + return -1; + + hasHotpluggedDisk =3D true; + } + + /* in order to allow booting from such disks we need to issue a system= -reset + * so that the firmware tables recording bootable devices are regerate= d */ + if (hasHotpluggedDisk) { + int rc; + + if (qemuDomainObjEnterMonitorAsync(priv->driver, vm, asyncJob) < 0) + return -1; + + rc =3D qemuMonitorSystemReset(priv->mon); + + if (qemuDomainObjExitMonitor(priv->driver, vm) < 0 || rc < 0) + return -1; + } + + return 0; +} + + static int qemuProcessSetupDisksTransient(virDomainObj *vm, qemuDomainAsyncJob asyncJob) @@ -7060,6 +7100,9 @@ qemuProcessSetupDisksTransient(virDomainObj *vm, if (qemuProcessSetupDisksTransientSnapshot(vm, asyncJob) < 0) return -1; + if (qemuProcessSetupDisksTransientHotplug(vm, asyncJob) < 0) + return -1; + return 0; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 9c74092f23..6d6bca859b 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2980,6 +2980,30 @@ qemuValidateDomainDeviceDefDiskTransient(const virDo= mainDiskDef *disk, return -1; } + if (disk->transientShareBacking =3D=3D VIR_TRISTATE_BOOL_YES) { + /* sharing the backing file requires hotplug of the disk in the qe= mu driver */ + switch (disk->bus) { + case VIR_DOMAIN_DISK_BUS_USB: + case VIR_DOMAIN_DISK_BUS_VIRTIO: + case VIR_DOMAIN_DISK_BUS_SCSI: + break; + + case VIR_DOMAIN_DISK_BUS_IDE: + case VIR_DOMAIN_DISK_BUS_FDC: + case VIR_DOMAIN_DISK_BUS_XEN: + case VIR_DOMAIN_DISK_BUS_UML: + case VIR_DOMAIN_DISK_BUS_SATA: + case VIR_DOMAIN_DISK_BUS_SD: + case VIR_DOMAIN_DISK_BUS_NONE: + case VIR_DOMAIN_DISK_BUS_LAST: + default: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk bus '%s' doesn't support transiend disk= backing image sharing"), + virDomainDiskBusTypeToString(disk->bus)); + return -1; + } + } + return 0; } --=20 2.31.1