Re: [libvirt] [PATCH 2/3] qemu: Extract internals of processBlockJobEvent into a helper

2015-03-30 Thread Eric Blake
On 03/30/2015 03:26 AM, Peter Krempa wrote:
> Later on I'll be adding a condition that will allow to synchronise a
> SYNC block job abort. The approach will require this code to be called
> from two different places so it has to be extracted into a helper.
> ---
>  src/qemu/qemu_driver.c | 200 
> +
>  1 file changed, 104 insertions(+), 96 deletions(-)

ACK; looks to be code motion with no immediate impact, so safe for
freeze if 3/3 is approved.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 2/3] qemu: Extract internals of processBlockJobEvent into a helper

2015-03-30 Thread Peter Krempa
Later on I'll be adding a condition that will allow to synchronise a
SYNC block job abort. The approach will require this code to be called
from two different places so it has to be extracted into a helper.
---
 src/qemu/qemu_driver.c | 200 +
 1 file changed, 104 insertions(+), 96 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f1cbc46..257dea8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4453,116 +4453,101 @@ processSerialChangedEvent(virQEMUDriverPtr driver,


 static void
-processBlockJobEvent(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- char *diskAlias,
- int type,
- int status)
+qemuBlockJobEventProcess(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDiskDefPtr disk,
+ int type,
+ int status)
 {
 virObjectEventPtr event = NULL;
 virObjectEventPtr event2 = NULL;
 const char *path;
-virDomainDiskDefPtr disk;
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 virDomainDiskDefPtr persistDisk = NULL;
 bool save = false;

-if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
-goto cleanup;
-
-if (!virDomainObjIsActive(vm)) {
-VIR_DEBUG("Domain is not running");
-goto endjob;
-}
-
-disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias);
-
-if (disk) {
-/* Have to generate two variants of the event for old vs. new
- * client callbacks */
-if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
-disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
-type = disk->mirrorJob;
-path = virDomainDiskGetSource(disk);
-event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
-event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type,
-   status);
-
-/* If we completed a block pull or commit, then update the XML
- * to match.  */
-switch ((virConnectDomainEventBlockJobStatus) status) {
-case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
-if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
-if (vm->newDef) {
-int indx = virDomainDiskIndexByName(vm->newDef, disk->dst,
-false);
-virStorageSourcePtr copy = NULL;
-
-if (indx >= 0) {
-persistDisk = vm->newDef->disks[indx];
-copy = virStorageSourceCopy(disk->mirror, false);
-if (virStorageSourceInitChainElement(copy,
- persistDisk->src,
- true) < 0) {
-VIR_WARN("Unable to update persistent definition "
- "on vm %s after block job",
- vm->def->name);
-virStorageSourceFree(copy);
-copy = NULL;
-persistDisk = NULL;
-}
-}
-if (copy) {
-virStorageSourceFree(persistDisk->src);
-persistDisk->src = copy;
+/* Have to generate two variants of the event for old vs. new
+ * client callbacks */
+if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
+disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
+type = disk->mirrorJob;
+path = virDomainDiskGetSource(disk);
+event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
+event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type, status);
+
+/* If we completed a block pull or commit, then update the XML
+ * to match.  */
+switch ((virConnectDomainEventBlockJobStatus) status) {
+case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
+if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
+if (vm->newDef) {
+int indx = virDomainDiskIndexByName(vm->newDef, disk->dst, 
false);
+virStorageSourcePtr copy = NULL;
+
+if (indx >= 0) {
+persistDisk = vm->newDef->disks[indx];
+copy = virStorageSourceCopy(disk->mirror, false);
+if (virStorageSourceInitChainElement(copy,
+ persistDisk->src,
+ true) < 0) {
+VIR_WARN("Unable to update persistent definition "
+ "on vm %s after block job",
+ vm->def->name);
+