From nobody Mon Feb 9 05:20:57 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 1531829684125986.9481152661615; Tue, 17 Jul 2018 05:14:44 -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 8FF7385363; Tue, 17 Jul 2018 12:14:42 +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 4A6A0CB1A6; Tue, 17 Jul 2018 12:14:42 +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 E85201841C4B; Tue, 17 Jul 2018 12:14:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6HCEbIx007448 for ; Tue, 17 Jul 2018 08:14:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1577920180F4; Tue, 17 Jul 2018 12:14:37 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C3BF2026D68; Tue, 17 Jul 2018 12:14:36 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:26 +0200 Message-Id: <67e062f57683e986283d4b72db5a8b1b645640c5.1531829580.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 06/10] qemu: hotplug: Reuse qemuHotplugDiskSourceRemove for disk backend removal 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, 17 Jul 2018 12:14:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add code which will convert a disk definition into qemuHotplugDiskSourceData and then reuse qemuHotplugDiskSourceRemove to remove all the backend related objects. This unifies the detach code as much as possible with the already existing helpers and will allow reuse this infrastructure when changing removable disk media. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 129 +++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 94 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f1b18fcc7d..3ee74c8e40 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -373,6 +373,96 @@ qemuHotplugDiskSourceDataFree(qemuHotplugDiskSourceDat= aPtr data) } +/** + * qemuDomainRemoveDiskStorageSourcePrepareData: + * @src: disk source structure + * @driveAlias: Alias of the -drive backend, the pointer is always consumed + * + * Prepare qemuBlockStorageSourceAttachDataPtr for detaching a single sour= ce + * from a VM. If @driveAlias is NULL -blockdev is assumed. + */ +static qemuBlockStorageSourceAttachDataPtr +qemuHotplugRemoveStorageSourcePrepareData(virStorageSourcePtr src, + char *driveAlias) + +{ + qemuDomainStorageSourcePrivatePtr srcpriv =3D QEMU_DOMAIN_STORAGE_SOUR= CE_PRIVATE(src); + qemuBlockStorageSourceAttachDataPtr data; + qemuBlockStorageSourceAttachDataPtr ret =3D NULL; + + if (VIR_ALLOC(data) < 0) + goto cleanup; + + if (driveAlias) { + VIR_STEAL_PTR(data->driveAlias, driveAlias); + data->driveAdded =3D true; + } else { + data->formatNodeName =3D src->nodeformat; + data->formatAttached =3D true; + data->storageNodeName =3D src->nodestorage; + data->storageAttached =3D true; + } + + if (src->pr && + !virStoragePRDefIsManaged(src->pr) && + VIR_STRDUP(data->prmgrAlias, src->pr->mgralias) < 0) + goto cleanup; + + if (VIR_STRDUP(data->tlsAlias, src->tlsAlias) < 0) + goto cleanup; + + if (srcpriv) { + if (srcpriv->secinfo && + srcpriv->secinfo->type =3D=3D VIR_DOMAIN_SECRET_INFO_TYPE_AES = && + VIR_STRDUP(data->authsecretAlias, srcpriv->secinfo->s.aes.alia= s) < 0) + goto cleanup; + + if (srcpriv->encinfo && + srcpriv->encinfo->type =3D=3D VIR_DOMAIN_SECRET_INFO_TYPE_AES = && + VIR_STRDUP(data->encryptsecretAlias, srcpriv->encinfo->s.aes.a= lias) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, data); + + cleanup: + VIR_FREE(driveAlias); + qemuBlockStorageSourceAttachDataFree(data); + return ret; +} + + +static qemuHotplugDiskSourceDataPtr +qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk, + virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSE= D) +{ + qemuBlockStorageSourceAttachDataPtr backend; + qemuHotplugDiskSourceDataPtr data; + qemuHotplugDiskSourceDataPtr ret =3D NULL; + char *drivealias =3D NULL; + + if (VIR_ALLOC(data) < 0) + return NULL; + + if (!(drivealias =3D qemuAliasDiskDriveFromDisk(disk))) + goto cleanup; + + if (!(backend =3D qemuHotplugRemoveStorageSourcePrepareData(disk->src, + drivealias))) + goto cleanup; + + if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0) + goto cleanup; + + VIR_STEAL_PTR(ret, data); + + cleanup: + qemuBlockStorageSourceAttachDataFree(backend); + qemuHotplugDiskSourceDataFree(data); + return ret; +} + + /** * qemuHotplugDiskSourceAttachPrepare: * @disk: disk to generate attachment data for @@ -3853,36 +3943,21 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDiskDefPtr disk) { - qemuDomainStorageSourcePrivatePtr diskPriv =3D QEMU_DOMAIN_STORAGE_SOU= RCE_PRIVATE(disk->src); + qemuHotplugDiskSourceDataPtr diskbackend =3D NULL; virDomainDeviceDef dev; virObjectEventPtr event; size_t i; qemuDomainObjPrivatePtr priv =3D vm->privateData; - char *drivestr; bool prManaged =3D priv->prDaemonRunning; bool prUsed =3D false; - const char *authAlias =3D NULL; - const char *encAlias =3D NULL; int ret =3D -1; VIR_DEBUG("Removing disk %s from domain %p %s", disk->info.alias, vm, vm->def->name); - /* build the actual drive id string as the disk->info.alias doesn't - * contain the QEMU_DRIVE_HOST_PREFIX that is passed to qemu */ - if (!(drivestr =3D qemuAliasDiskDriveFromDisk(disk))) + if (!(diskbackend =3D qemuHotplugDiskSourceRemovePrepare(disk, priv->q= emuCaps))) return -1; - if (diskPriv) { - if (diskPriv->secinfo && - diskPriv->secinfo->type =3D=3D VIR_DOMAIN_SECRET_INFO_TYPE_AES) - authAlias =3D diskPriv->secinfo->s.aes.alias; - - if (diskPriv->encinfo && - diskPriv->encinfo->type =3D=3D VIR_DOMAIN_SECRET_INFO_TYPE_AES) - encAlias =3D diskPriv->encinfo->s.aes.alias; - } - for (i =3D 0; i < vm->def->ndisks; i++) { if (vm->def->disks[i] =3D=3D disk) { virDomainDiskRemove(vm->def, i); @@ -3895,24 +3970,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, qemuDomainObjEnterMonitor(driver, vm); - qemuMonitorDriveDel(priv->mon, drivestr); - VIR_FREE(drivestr); - - /* If it fails, then so be it - it was a best shot */ - if (authAlias) - ignore_value(qemuMonitorDelObject(priv->mon, authAlias)); - - /* If it fails, then so be it - it was a best shot */ - if (encAlias) - ignore_value(qemuMonitorDelObject(priv->mon, encAlias)); - - /* If it fails, then so be it - it was a best shot */ - if (disk->src->pr && - !virStoragePRDefIsManaged(disk->src->pr)) - ignore_value(qemuMonitorDelObject(priv->mon, disk->src->pr->mgrali= as)); - - if (disk->src->tlsAlias) - ignore_value(qemuMonitorDelObject(priv->mon, disk->src->tlsAlias)); + qemuHotplugDiskSourceRemove(priv->mon, diskbackend); if (prManaged && !prUsed) ignore_value(qemuMonitorDelObject(priv->mon, qemuDomainGetManagedP= RAlias())); @@ -3941,6 +3999,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, ret =3D 0; cleanup: + qemuHotplugDiskSourceDataFree(diskbackend); virDomainDiskDefFree(disk); return ret; } --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list