From nobody Mon Feb 9 00:56:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533652153988202.91866759135416; Tue, 7 Aug 2018 07:29:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED5A481DF7; Tue, 7 Aug 2018 14:29:11 +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 BC44FCBD7F; Tue, 7 Aug 2018 14:29:11 +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 727A24EE0E; Tue, 7 Aug 2018 14:29:11 +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 w77ENFrx010403 for ; Tue, 7 Aug 2018 10:23:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD2612166BA2; Tue, 7 Aug 2018 14:23:15 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49AD12166BA0 for ; Tue, 7 Aug 2018 14:23:15 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 7 Aug 2018 16:22:29 +0200 Message-Id: <8f693d2786975d3f28f4ccf5b15a59aea3bf883d.1533651617.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 38/55] qemu: hotplug: Implement removable media change for -blockdev 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Aug 2018 14:29:12 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the new APIs which allow to manipulate the tray and media separately and also allow using a nodename to refer to a media to implement media changing. With the new approach we don't have to call eject twice as the media is removed by calling qemuMonitorBlockdevMediumRemove. Signed-off-by: Peter Krempa --- src/qemu/qemu_hotplug.c | 93 +++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3eddb0043e..97a486f2ea 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -618,6 +618,93 @@ qemuHotplugDiskSourceRemove(qemuMonitorPtr mon, } +/** + * qemuDomainChangeMediaBlockdev: + * @driver: qemu driver structure + * @vm: domain definition + * @disk: disk definition to change the source of + * @newsrc: new disk source to change to + * @force: force the change of media + * + * Change the media in an ejectable device to the one described by + * @newsrc. This function also removes the old source from the + * shared device table if appropriate. Note that newsrc is consumed + * on success and the old source is freed on success. + * + * Returns 0 on success, -1 on error and reports libvirt error + */ +static int +qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr disk, + virStorageSourcePtr newsrc, + bool force) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); + qemuHotplugDiskSourceDataPtr newbackend =3D NULL; + qemuHotplugDiskSourceDataPtr oldbackend =3D NULL; + virStorageSourcePtr oldsrc =3D disk->src; + char *nodename =3D NULL; + int rc; + int ret =3D -1; + + if (!virStorageSourceIsEmpty(disk->src) && + !(oldbackend =3D qemuHotplugDiskSourceRemovePrepare(disk, priv->qe= muCaps))) + goto cleanup; + + disk->src =3D newsrc; + if (!virStorageSourceIsEmpty(disk->src)) { + if (!(newbackend =3D qemuHotplugDiskSourceAttachPrepare(disk, + priv->qemuCa= ps))) + goto cleanup; + + if (qemuDomainDiskGetBackendAlias(disk, priv->qemuCaps, &nodename)= < 0) + goto cleanup; + } + + if (diskPriv->tray && disk->tray_status !=3D VIR_DOMAIN_DISK_TRAY_OPEN= ) { + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorBlockdevTrayOpen(priv->mon, diskPriv->backendQom= Name, force); + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + goto cleanup; + + if (!force && qemuHotplugWaitForTrayEject(vm, disk) < 0) + goto cleanup; + } + + qemuDomainObjEnterMonitor(driver, vm); + + rc =3D qemuMonitorBlockdevMediumRemove(priv->mon, diskPriv->backendQom= Name); + + if (rc =3D=3D 0 && oldbackend) + qemuHotplugDiskSourceRemove(priv->mon, oldbackend); + + if (newbackend && nodename) { + if (rc =3D=3D 0) + rc =3D qemuHotplugDiskSourceAttach(priv->mon, newbackend); + + if (rc =3D=3D 0) + rc =3D qemuMonitorBlockdevMediumInsert(priv->mon, + diskPriv->backendQomName, + nodename); + } + + if (rc =3D=3D 0) + rc =3D qemuMonitorBlockdevTrayClose(priv->mon, diskPriv->backendQo= mName); + + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + goto cleanup; + + cleanup: + qemuHotplugDiskSourceDataFree(newbackend); + qemuHotplugDiskSourceDataFree(oldbackend); + /* caller handles correct exchange of sources */ + disk->src =3D oldsrc; + return ret; +} + + /** * qemuDomainChangeEjectableMedia: * @driver: qemu driver structure @@ -640,6 +727,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, virStorageSourcePtr newsrc, bool force) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; int ret =3D -1; int rc; @@ -649,7 +737,10 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, if (qemuHotplugAttachManagedPR(driver, vm, newsrc, QEMU_ASYNC_JOB_NONE= ) < 0) goto cleanup; - rc =3D qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force); + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) + rc =3D qemuDomainChangeMediaBlockdev(driver, vm, disk, newsrc, for= ce); + else + rc =3D qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force= ); virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >=3D 0); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list