From nobody Fri May 3 07:10:04 2024 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 1531829690093805.6480722534003; Tue, 17 Jul 2018 05:14:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 605EF3082A26; Tue, 17 Jul 2018 12:14:48 +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 243DC5D70C; Tue, 17 Jul 2018 12:14:48 +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 CA6234BB78; Tue, 17 Jul 2018 12:14:47 +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 w6HCEXQh007400 for ; Tue, 17 Jul 2018 08:14:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id E216F20180EB; Tue, 17 Jul 2018 12:14:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64D1E2026D68; Tue, 17 Jul 2018 12:14:32 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:21 +0200 Message-Id: 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 01/10] qemu: hotplug: Reuse qemuHotplugPrepareDiskAccess in qemuDomainRemoveDiskDevice 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 17 Jul 2018 12:14:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qemuHotplugPrepareDiskAccess can be used to tear down disk access so we can replace the open-coded version collecting the same function calls. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 2b6633a998..ee26fb4f52 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3830,17 +3830,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, qemuDomainReleaseDeviceAddress(vm, &disk->info, src); - if (qemuSecurityRestoreDiskLabel(driver, vm, disk) < 0) - VIR_WARN("Unable to restore security label on %s", src); - - if (qemuTeardownDiskCgroup(vm, disk) < 0) - VIR_WARN("Failed to tear down cgroup for disk path %s", src); - - if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0) - VIR_WARN("Unable to release lock on %s", src); - - if (qemuDomainNamespaceTeardownDisk(vm, disk->src) < 0) - VIR_WARN("Unable to remove /dev entry for %s", src); + /* tear down disk security access */ + qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true); dev.type =3D VIR_DOMAIN_DEVICE_DISK; dev.data.disk =3D disk; --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531829679682305.60552588740666; Tue, 17 Jul 2018 05:14:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B83E587621; Tue, 17 Jul 2018 12:14:37 +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 8357F5D6B5; Tue, 17 Jul 2018 12:14:37 +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 E374124B77; Tue, 17 Jul 2018 12:14:36 +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 w6HCEXui007410 for ; Tue, 17 Jul 2018 08:14:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id A96FC20180F4; Tue, 17 Jul 2018 12:14:33 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BE3F2026D68; Tue, 17 Jul 2018 12:14:33 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:22 +0200 Message-Id: <72fee12862cb22c8421c21463a1890217d5e2710.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 02/10] qemu: hotplug: Remove pointless variable 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 17 Jul 2018 12:14:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that there's only one use of it, replace it directly by the code filling it. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ee26fb4f52..20efb01dbf 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3757,7 +3757,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, virDomainDeviceDef dev; virObjectEventPtr event; size_t i; - const char *src =3D virDomainDiskGetSource(disk); qemuDomainObjPrivatePtr priv =3D vm->privateData; char *drivestr; bool prManaged =3D priv->prDaemonRunning; @@ -3828,7 +3827,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, if (prManaged && !prUsed) qemuProcessKillManagedPRDaemon(vm); - qemuDomainReleaseDeviceAddress(vm, &disk->info, src); + qemuDomainReleaseDeviceAddress(vm, &disk->info, virDomainDiskGetSource= (disk)); /* tear down disk security access */ qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531829690097148.78002992377708; Tue, 17 Jul 2018 05:14:50 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 5786A5F727; Tue, 17 Jul 2018 12:14:48 +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 23F77100191B; Tue, 17 Jul 2018 12:14:48 +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 CD9DE24B79; Tue, 17 Jul 2018 12:14:47 +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 w6HCEY6f007418 for ; Tue, 17 Jul 2018 08:14:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7082920180F4; Tue, 17 Jul 2018 12:14:34 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id E707C2026D68; Tue, 17 Jul 2018 12:14:33 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:23 +0200 Message-Id: <16554f06cc9b3ffcae3dce31878447aa70a9e177.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 03/10] qemu: hotplug: Don't format NULL in %s in qemuHotplugPrepareDiskAccess 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 17 Jul 2018 12:14:49 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The warning messages which include the disk source could potentially format NULL using %s as virDomainDiskGetSource may return NULL for e.g. NBD disks. As most of the APIs are NOOP for remote disks the usage of the source string only should be fine for now. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 20efb01dbf..624341baa1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -126,21 +126,21 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver, rollback_cgroup: if (qemuTeardownDiskCgroup(vm, disk) < 0) VIR_WARN("Unable to tear down cgroup access on %s", - virDomainDiskGetSource(disk)); + NULLSTR(virDomainDiskGetSource(disk))); rollback_label: if (qemuSecurityRestoreDiskLabel(driver, vm, disk) < 0) VIR_WARN("Unable to restore security label on %s", - virDomainDiskGetSource(disk)); + NULLSTR(virDomainDiskGetSource(disk))); rollback_namespace: if (qemuDomainNamespaceTeardownDisk(vm, disk->src) < 0) VIR_WARN("Unable to remove /dev entry for %s", - virDomainDiskGetSource(disk)); + NULLSTR(virDomainDiskGetSource(disk))); rollback_lock: if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0) VIR_WARN("Unable to release lock on %s", - virDomainDiskGetSource(disk)); + NULLSTR(virDomainDiskGetSource(disk))); cleanup: if (origsrc) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531829695083331.8122892039804; Tue, 17 Jul 2018 05:14:55 -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 9A2E230820E6; Tue, 17 Jul 2018 12:14:53 +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 5BB68C2777; Tue, 17 Jul 2018 12:14:53 +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 055B524601; Tue, 17 Jul 2018 12:14:53 +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 w6HCEZnq007425 for ; Tue, 17 Jul 2018 08:14:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 879A520180F4; Tue, 17 Jul 2018 12:14:35 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE1A82026D68; Tue, 17 Jul 2018 12:14:34 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:24 +0200 Message-Id: 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 04/10] qemu: hotplug: Prepare for multiple backing chain member hotplug 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.47]); Tue, 17 Jul 2018 12:14:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Similarly to how we've intergrated data belonging to a single virStorageSource for purposes of attaching it to a qemu instance we will need to agregate data relevant for the whole disk. With blockdev there will be some disk-wide backing chain members such as the copy-on-read handler. Introduce qemuHotplugDiskSourceData which agregates the backing chain and other data relevant for the disk and functions which generate it and apply and rollback it. In addition to disk hotplug this will also be reused for media changing where we need to exchange the full disk backend. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 118 ++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 109 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 624341baa1..2ddcc19cc8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -350,6 +350,110 @@ qemuDomainDiskAttachManagedPR(virDomainObjPtr vm, } +struct _qemuHotplugDiskSourceData { + qemuBlockStorageSourceAttachDataPtr *backends; + size_t nbackends; +}; +typedef struct _qemuHotplugDiskSourceData qemuHotplugDiskSourceData; +typedef qemuHotplugDiskSourceData *qemuHotplugDiskSourceDataPtr; + + +static void +qemuHotplugDiskSourceDataFree(qemuHotplugDiskSourceDataPtr data) +{ + size_t i; + + if (!data) + return; + + for (i =3D 0; i < data->nbackends; i++) + qemuBlockStorageSourceAttachDataFree(data->backends[i]); + + VIR_FREE(data); +} + + +/** + * qemuHotplugDiskSourceAttachPrepare: + * @disk: disk to generate attachment data for + * @qemuCaps: capabilities of the qemu process + * + * Prepares and returns qemuHotplugDiskSourceData structure filled with al= l data + * which will fully attach the source backend of the disk to a given VM. + */ +static qemuHotplugDiskSourceDataPtr +qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk, + virQEMUCapsPtr qemuCaps) +{ + qemuBlockStorageSourceAttachDataPtr backend; + qemuHotplugDiskSourceDataPtr data; + qemuHotplugDiskSourceDataPtr ret =3D NULL; + + if (VIR_ALLOC(data) < 0) + return NULL; + + if (!(backend =3D qemuBuildStorageSourceAttachPrepareDrive(disk, qemuC= aps, false))) + goto cleanup; + + if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, backend, qemu= Caps) < 0) + 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; +} + + +/** + * qemuHotplugDiskSourceAttach: + * @mon: monitor object + * @data: disk backend data object describing what to remove + * + * Attach a disk source backend with all relevant pieces. Caller must ente= r the + * monitor context for @mon. + */ +static int +qemuHotplugDiskSoureceAttach(qemuMonitorPtr mon, + qemuHotplugDiskSourceDataPtr data) +{ + size_t i; + + for (i =3D data->nbackends; i > 0; i--) { + if (qemuBlockStorageSourceAttachApply(mon, data->backends[i - 1]) = < 0) + return -1; + } + + return 0; +} + + +/** + * qemuHotplugDiskSourceRemove: + * @mon: monitor object + * @data: disk backend data object describing what to remove + * + * Remove a disk source backend with all relevant pieces. This function + * preserves the error which was set prior to calling it. Caller must ente= r the + * monitor context for @mon. + */ +static void +qemuHotplugDiskSourceRemove(qemuMonitorPtr mon, + qemuHotplugDiskSourceDataPtr data) + +{ + size_t i; + + for (i =3D 0; i < data->nbackends; i++) + qemuBlockStorageSourceAttachRollback(mon, data->backends[i]); +} + + /** * qemuDomainAttachDiskGeneric: * @@ -362,7 +466,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, { int ret =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; - qemuBlockStorageSourceAttachDataPtr data =3D NULL; + qemuHotplugDiskSourceDataPtr diskdata =3D NULL; virErrorPtr orig_err; char *devstr =3D NULL; char *managedPrmgrAlias =3D NULL; @@ -381,11 +485,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, if (qemuDomainDiskAttachManagedPR(vm, disk, &managedPrmgrProps) < 0) goto error; - if (!(data =3D qemuBuildStorageSourceAttachPrepareDrive(disk, priv->qe= muCaps, - false))) - goto error; - - if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data, priv->q= emuCaps) < 0) + if (!(diskdata =3D qemuHotplugDiskSourceAttachPrepare(disk, priv->qemu= Caps))) goto error; if (!(devstr =3D qemuBuildDiskDeviceStr(vm->def, disk, 0, priv->qemuCa= ps))) @@ -400,7 +500,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, qemuMonitorAddObject(priv->mon, &managedPrmgrProps, &managedPrmgrA= lias) < 0) goto exit_monitor; - if (qemuBlockStorageSourceAttachApply(priv->mon, data) < 0) + if (qemuHotplugDiskSoureceAttach(priv->mon, diskdata) < 0) goto exit_monitor; if (qemuMonitorAddDevice(priv->mon, devstr) < 0) @@ -417,7 +517,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ret =3D 0; cleanup: - qemuBlockStorageSourceAttachDataFree(data); + qemuHotplugDiskSourceDataFree(diskdata); virJSONValueFree(managedPrmgrProps); qemuDomainSecretDiskDestroy(disk); VIR_FREE(managedPrmgrAlias); @@ -426,7 +526,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, return ret; exit_monitor: - qemuBlockStorageSourceAttachRollback(priv->mon, data); + qemuHotplugDiskSourceRemove(priv->mon, diskdata); virErrorPreserveLast(&orig_err); if (managedPrmgrAlias) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531829700887314.61784325675774; Tue, 17 Jul 2018 05:15:00 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A85CD308213F; Tue, 17 Jul 2018 12:14:58 +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 761E8100191B; Tue, 17 Jul 2018 12:14:58 +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 2834D14B09; Tue, 17 Jul 2018 12:14:58 +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 w6HCEa11007433 for ; Tue, 17 Jul 2018 08:14:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E6D920180F4; Tue, 17 Jul 2018 12:14:36 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C57152026D68; Tue, 17 Jul 2018 12:14:35 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:25 +0200 Message-Id: <10962a1bd06aed83157f6b612a3d98fa1b7a806f.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 05/10] qemu: hotplug: Don't leak 'disk' if VM crashes during unplug finishing 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 17 Jul 2018 12:14:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qemuDomainRemoveDiskDevice would leak the disk to be removed if the VM crashed since it was removed from the definition but not freed. Broken in commit 105bcdde76b which moved the removal from the definition earlier. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 2ddcc19cc8..f1b18fcc7d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3863,6 +3863,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, 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); @@ -3917,7 +3918,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, ignore_value(qemuMonitorDelObject(priv->mon, qemuDomainGetManagedP= RAlias())); if (qemuDomainObjExitMonitor(driver, vm) < 0) - return -1; + goto cleanup; virDomainAuditDisk(vm, disk->src, NULL, "detach", true); @@ -3937,8 +3938,11 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name)); virDomainUSBAddressRelease(priv->usbaddrs, &disk->info); + ret =3D 0; + + cleanup: virDomainDiskDefFree(disk); - return 0; + return ret; } --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 From nobody Fri May 3 07:10:04 2024 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 15318296906981000.415676510527; Tue, 17 Jul 2018 05:14:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E23C35F732; Tue, 17 Jul 2018 12:14:48 +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 AE8F75D761; Tue, 17 Jul 2018 12:14:48 +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 5CDAB1841C49; Tue, 17 Jul 2018 12:14:48 +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 w6HCEb49007458 for ; Tue, 17 Jul 2018 08:14:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id D15E720180F4; 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 535D42026D68; Tue, 17 Jul 2018 12:14:37 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:27 +0200 Message-Id: <2282ab066e47032bc7db67c393d1a54e06b95737.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 07/10] qemu: hotplug: Simplify removal of managed PR infrastructure on unplug 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 17 Jul 2018 12:14:49 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extract the (possible) removal of the PR backend and daemon into a separate helper which enters monitor on it's own. This simplifies the code and allows reuse of this function in the future e.g. for blockjobs where removing a image with PR may result into PR not being necessary. Since the PR is not used often the overhead of entering monitor again should be negligible. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 49 ++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3ee74c8e40..57ab753974 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -350,6 +350,41 @@ qemuDomainDiskAttachManagedPR(virDomainObjPtr vm, } +/** + * qemuHotplugRemoveManagedPR: + * @driver: QEMU driver object + * @vm: domain object + * @asyncJob: asynchronous job identifier + * + * Removes the managed PR object from @vm if the configuration does not re= quire + * it any more. + */ +static int +qemuHotplugRemoveManagedPR(virQEMUDriverPtr driver, + virDomainObjPtr vm, + qemuDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virErrorPtr orig_err; + virErrorPreserveLast(&orig_err); + + if (!priv->prDaemonRunning || + virDomainDefHasManagedPR(vm->def)) + return 0; + + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + return -1; + ignore_value(qemuMonitorDelObject(priv->mon, qemuDomainGetManagedPRAli= as())); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + return -1; + + qemuProcessKillManagedPRDaemon(vm); + virErrorRestore(&orig_err); + + return 0; +} + + struct _qemuHotplugDiskSourceData { qemuBlockStorageSourceAttachDataPtr *backends; size_t nbackends; @@ -3948,8 +3983,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, virObjectEventPtr event; size_t i; qemuDomainObjPrivatePtr priv =3D vm->privateData; - bool prManaged =3D priv->prDaemonRunning; - bool prUsed =3D false; int ret =3D -1; VIR_DEBUG("Removing disk %s from domain %p %s", @@ -3965,16 +3998,10 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, } } - /* check if the last disk with managed PR was just removed */ - prUsed =3D virDomainDefHasManagedPR(vm->def); - qemuDomainObjEnterMonitor(driver, vm); qemuHotplugDiskSourceRemove(priv->mon, diskbackend); - if (prManaged && !prUsed) - ignore_value(qemuMonitorDelObject(priv->mon, qemuDomainGetManagedP= RAlias())); - if (qemuDomainObjExitMonitor(driver, vm) < 0) goto cleanup; @@ -3983,9 +4010,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, event =3D virDomainEventDeviceRemovedNewFromObj(vm, disk->info.alias); virObjectEventStateQueue(driver->domainEventState, event); - if (prManaged && !prUsed) - qemuProcessKillManagedPRDaemon(vm); - qemuDomainReleaseDeviceAddress(vm, &disk->info, virDomainDiskGetSource= (disk)); /* tear down disk security access */ @@ -3996,6 +4020,9 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name)); virDomainUSBAddressRelease(priv->usbaddrs, &disk->info); + if (qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto cleanup; + ret =3D 0; cleanup: --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531829710868420.73601168417554; Tue, 17 Jul 2018 05:15:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 629BF308FBA4; Tue, 17 Jul 2018 12:15:07 +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 135873001A68; Tue, 17 Jul 2018 12:15:07 +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 9C18314B0C; Tue, 17 Jul 2018 12:15:06 +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 w6HCEcWA007468 for ; Tue, 17 Jul 2018 08:14:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 977C420180EB; Tue, 17 Jul 2018 12:14:38 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A5252026D68; Tue, 17 Jul 2018 12:14:37 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:28 +0200 Message-Id: <7002d739b4dd1ec18f171852df5c2f949cb827e2.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 08/10] qemu: hotplug: Refactor/simplify PR managed addition to VM 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 17 Jul 2018 12:15:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Similarly to qemuDomainDiskRemoveManagedPR make it enter monitor on it's own so that it can be reused. Future users will be in the snapshot code and in removable media change code. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 55 ++++++++++++++++++++++++++-------------------= ---- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 57ab753974..c751660403 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -310,29 +310,31 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr drive= r, /** - * qemuDomainMaybeStartPRDaemon: + * qemuHotplugAttachManagedPR: + * @driver: QEMU driver object * @vm: domain object - * @disk: disk to hotplug - * @retProps: properties of the managed pr-manager-helper object which nee= ds - * to be added to the running vm + * @src: new disk source to be attached to @vm + * @asyncJob: asynchronous job identifier * * Checks if it's needed to start qemu-pr-helper and add the corresponding * pr-manager-helper object. * - * Returns: 0 on success, -1 on error. If @retProps is populated the - * qemu-pr-helper daemon was started. + * Returns: 0 on success, -1 on error. */ static int -qemuDomainDiskAttachManagedPR(virDomainObjPtr vm, - virDomainDiskDefPtr disk, - virJSONValuePtr *retProps) +qemuHotplugAttachManagedPR(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virStorageSourcePtr src, + qemuDomainAsyncJob asyncJob) { qemuDomainObjPrivatePtr priv =3D vm->privateData; virJSONValuePtr props =3D NULL; + bool daemonStarted =3D false; int ret =3D -1; + int rc; if (priv->prDaemonRunning || - !virStorageSourceChainHasManagedPR(disk->src)) + !virStorageSourceChainHasManagedPR(src)) return 0; if (!(props =3D qemuBuildPRManagedManagerInfoProps(priv))) @@ -341,10 +343,21 @@ qemuDomainDiskAttachManagedPR(virDomainObjPtr vm, if (qemuProcessStartManagedPRDaemon(vm) < 0) goto cleanup; - VIR_STEAL_PTR(*retProps, props); + daemonStarted =3D true; + + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + goto cleanup; + + rc =3D qemuMonitorAddObject(priv->mon, &props, NULL); + + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + goto cleanup; + ret =3D 0; cleanup: + if (ret < 0 && daemonStarted) + qemuProcessKillManagedPRDaemon(vm); virJSONValueFree(props); return ret; } @@ -592,7 +605,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, int ret =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; qemuHotplugDiskSourceDataPtr diskdata =3D NULL; - virErrorPtr orig_err; char *devstr =3D NULL; char *managedPrmgrAlias =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); @@ -607,9 +619,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0) goto error; - if (qemuDomainDiskAttachManagedPR(vm, disk, &managedPrmgrProps) < 0) - goto error; - if (!(diskdata =3D qemuHotplugDiskSourceAttachPrepare(disk, priv->qemu= Caps))) goto error; @@ -619,11 +628,10 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0) goto error; - qemuDomainObjEnterMonitor(driver, vm); + if (qemuHotplugAttachManagedPR(driver, vm, disk->src, QEMU_ASYNC_JOB_N= ONE) < 0) + goto error; - if (managedPrmgrProps && - qemuMonitorAddObject(priv->mon, &managedPrmgrProps, &managedPrmgrA= lias) < 0) - goto exit_monitor; + qemuDomainObjEnterMonitor(driver, vm); if (qemuHotplugDiskSoureceAttach(priv->mon, diskdata) < 0) goto exit_monitor; @@ -653,20 +661,15 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, exit_monitor: qemuHotplugDiskSourceRemove(priv->mon, diskdata); - virErrorPreserveLast(&orig_err); - if (managedPrmgrAlias) - ignore_value(qemuMonitorDelObject(priv->mon, managedPrmgrAlias)); if (qemuDomainObjExitMonitor(driver, vm) < 0) ret =3D -2; - virErrorRestore(&orig_err); + if (qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + ret =3D -2; virDomainAuditDisk(vm, NULL, disk->src, "attach", false); error: ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true= )); - if (priv->prDaemonRunning && - !virDomainDefHasManagedPR(vm->def)) - qemuProcessKillManagedPRDaemon(vm); goto cleanup; } --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531829695853882.0397390253376; Tue, 17 Jul 2018 05:14:55 -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 3AC30307D85A; Tue, 17 Jul 2018 12:14:54 +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 F0425CABCD; Tue, 17 Jul 2018 12:14:53 +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 A54E2245FD; Tue, 17 Jul 2018 12:14:53 +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 w6HCEd2e007478 for ; Tue, 17 Jul 2018 08:14:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5F31020180EB; Tue, 17 Jul 2018 12:14:39 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5C532026D68; Tue, 17 Jul 2018 12:14:38 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:29 +0200 Message-Id: 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 09/10] qemu: hotplug: Extract legacy disk media changing bits 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.48]); Tue, 17 Jul 2018 12:14:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Prepare for the -blockdev implementation of ejectable media changing by splitting up the old bits. Additionally since both callers make sure that the device is a cdrom or floppy the check is no longer necessary. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 99 +++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 62 insertions(+), 37 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c751660403..1a7d8f0ca3 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -192,7 +192,7 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, /** - * qemuDomainChangeEjectableMedia: + * qemuDomainChangeMediaLegacy: * @driver: qemu driver structure * @vm: domain definition * @disk: disk definition to change the source of @@ -206,12 +206,12 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, * * Returns 0 on success, -1 on error and reports libvirt error */ -int -qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr disk, - virStorageSourcePtr newsrc, - bool force) +static int +qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr disk, + virStorageSourcePtr newsrc, + bool force) { int ret =3D -1, rc; char *driveAlias =3D NULL; @@ -231,19 +231,8 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, if (srcPriv) secinfo =3D srcPriv->secinfo; - if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && - disk->device !=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Removable media not supported for %s device"), - virDomainDiskDeviceTypeToString(disk->device)); - goto cleanup; - } - - if (qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, false) < 0) - goto cleanup; - if (!(driveAlias =3D qemuAliasDiskDriveFromDisk(disk))) - goto error; + goto cleanup; qemuDomainObjEnterMonitor(driver, vm); rc =3D qemuMonitorEjectMedia(priv->mon, driveAlias, force); @@ -255,16 +244,16 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr drive= r, virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) { rc =3D qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias); if (rc < 0) - goto error; + goto cleanup; } else { /* otherwise report possible errors from the attempt to eject the = media*/ if (rc < 0) - goto error; + goto cleanup; } if (!virStorageSourceIsEmpty(newsrc)) { if (qemuGetDriveSourceString(newsrc, secinfo, &sourcestr) < 0) - goto error; + goto cleanup; if (virStorageSourceGetActualType(newsrc) !=3D VIR_STORAGE_TYPE_DI= R) { if (newsrc->format > 0) { @@ -283,29 +272,15 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr drive= r, goto cleanup; } - virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >=3D 0); - if (rc < 0) - goto error; - - /* remove the old source from shared device list */ - ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); - ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true= )); + goto cleanup; - virStorageSourceFree(disk->src); - disk->src =3D newsrc; - newsrc =3D NULL; ret =3D 0; cleanup: VIR_FREE(driveAlias); VIR_FREE(sourcestr); return ret; - - error: - virDomainAuditDisk(vm, disk->src, newsrc, "update", false); - ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, tr= ue)); - goto cleanup; } @@ -592,6 +567,56 @@ qemuHotplugDiskSourceRemove(qemuMonitorPtr mon, } +/** + * qemuDomainChangeEjectableMedia: + * @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 + */ +int +qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr disk, + virStorageSourcePtr newsrc, + bool force) +{ + int ret =3D -1; + int rc; + + if (qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, false) < 0) + goto cleanup; + + rc =3D qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force); + + virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >=3D 0); + + if (rc < 0) { + ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc= , true)); + goto cleanup; + } + + /* remove the old source from shared device list */ + ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); + ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true= )); + + virStorageSourceFree(disk->src); + VIR_STEAL_PTR(disk->src, newsrc); + ret =3D 0; + + cleanup: + return ret; +} + + /** * qemuDomainAttachDiskGeneric: * --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531829701892629.6268398008008; Tue, 17 Jul 2018 05:15:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F9423082A49; Tue, 17 Jul 2018 12:14:59 +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 3A5FC5D76F; Tue, 17 Jul 2018 12:14:59 +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 DA16C1841C5B; Tue, 17 Jul 2018 12:14:58 +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 w6HCEedX007485 for ; Tue, 17 Jul 2018 08:14:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25AED20180EB; Tue, 17 Jul 2018 12:14:40 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CC302026D68; Tue, 17 Jul 2018 12:14:39 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 17 Jul 2018 14:14:30 +0200 Message-Id: <9aeb1a724cb7e0a9b5be90eefc63bd6427266eb3.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 10/10] qemu: hotplug: Make qemuHotplugWaitForTrayEject reusable 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 17 Jul 2018 12:15:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Remove the issue of the monitor command to the caller so that the function can be used with the modern approach. Additionally improve the error message. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_hotplug.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1a7d8f0ca3..774ee25286 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -155,10 +155,8 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver, static int -qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr disk, - const char *driveAlias) +qemuHotplugWaitForTrayEject(virDomainObjPtr vm, + virDomainDiskDefPtr disk) { unsigned long long now; int rc; @@ -174,19 +172,14 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, /* the caller called qemuMonitorEjectMedia which usually repor= ts an * error. Report the failure in an off-chance that it didn't. = */ if (virGetLastErrorCode() =3D=3D VIR_ERR_OK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("timed out waiting for disk tray status u= pdate")); + virReportError(VIR_ERR_OPERATION_FAILED, + _("timed out waiting to open tray of '%s'"), + disk->dst); } return -1; } } - /* re-issue ejection command to pop out the media */ - qemuDomainObjEnterMonitor(driver, vm); - rc =3D qemuMonitorEjectMedia(qemuDomainGetMonitor(vm), driveAlias, fal= se); - if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) - return -1; - return 0; } @@ -242,9 +235,16 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver, /* If the tray is present and tray change event is supported wait for = it to open. */ if (!force && diskPriv->tray && virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) { - rc =3D qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias); + rc =3D qemuHotplugWaitForTrayEject(vm, disk); if (rc < 0) goto cleanup; + + /* re-issue ejection command to pop out the media */ + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorEjectMedia(priv->mon, driveAlias, false); + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + goto cleanup; + } else { /* otherwise report possible errors from the attempt to eject the = media*/ if (rc < 0) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 07:10:04 2024 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 1531913836341226.28946550360365; Wed, 18 Jul 2018 04:37:16 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E3BBB30832DC; Wed, 18 Jul 2018 11:37:06 +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 F08BBAD154; Wed, 18 Jul 2018 11:37:01 +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 64B7F18037ED; Wed, 18 Jul 2018 11:37:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6IBawWb028349 for ; Wed, 18 Jul 2018 07:36:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id E1E69111CA1C; Wed, 18 Jul 2018 11:36:57 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 817F0111CA1A for ; Wed, 18 Jul 2018 11:36:55 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 18 Jul 2018 13:36:54 +0200 Message-Id: <1d806b24bb973ce90be89febc6cc62a1d65e1f1d.1531913720.git.pkrempa@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/10] qemu: hotplug: Add/remove managed PR objects on media change 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.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 18 Jul 2018 11:37:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When changing cdrom media we did not handle the managed PR objects thus we'd either have a stale PR object left behind or the media change would fail. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- Opps this one was also left behind in the blockdev-add series but belongs to this posting. src/qemu/qemu_hotplug.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f416db2c60..a1e523013d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -595,6 +595,9 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, if (qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, false) < 0) goto cleanup; + if (qemuHotplugAttachManagedPR(driver, vm, newsrc, QEMU_ASYNC_JOB_NONE= ) < 0) + goto cleanup; + rc =3D qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force); virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >=3D 0); @@ -610,6 +613,9 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, virStorageSourceFree(disk->src); VIR_STEAL_PTR(disk->src, newsrc); + + ignore_value(qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NON= E)); + ret =3D 0; cleanup: --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list