Re: [PATCH 06/25] qemu: blockjob: Register new and running blockjobs in the global table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi guys,

Em sex, 12 de jul de 2019 às 13:06, Peter Krempa <pkrempa@xxxxxxxxxx> escreveu:
>
> Add the job structure to the table when instantiating a new job and
> remove it when it terminates/fails.
>
> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> ---
>  src/qemu/qemu_blockjob.c  | 29 ++++++++++++++++++++++-------
>  src/qemu/qemu_blockjob.h  |  6 ++++--
>  src/qemu/qemu_driver.c    | 16 ++++++++--------
>  src/qemu/qemu_migration.c |  4 ++--
>  src/qemu/qemu_process.c   |  6 +++---
>  5 files changed, 39 insertions(+), 22 deletions(-)
>
> diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
> index c102417e43..8cbfc556b3 100644
> --- a/src/qemu/qemu_blockjob.c
> +++ b/src/qemu/qemu_blockjob.c
> @@ -94,8 +94,16 @@ qemuBlockJobDataNew(qemuBlockJobType type,
>
>  static int
>  qemuBlockJobRegister(qemuBlockJobDataPtr job,
> +                     virDomainObjPtr vm,
>                       virDomainDiskDefPtr disk)
>  {
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
> +
> +    if (virHashAddEntry(priv->blockjobs, job->name, virObjectRef(job)) < 0) {
> +        virObjectUnref(job);
> +        return -1;
> +    }
> +
>      if (disk) {
>          job->disk = disk;
>          QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = virObjectRef(job);
> @@ -106,8 +114,10 @@ qemuBlockJobRegister(qemuBlockJobDataPtr job,
>
>
>  static void
> -qemuBlockJobUnregister(qemuBlockJobDataPtr job)
> +qemuBlockJobUnregister(qemuBlockJobDataPtr job,
> +                       virDomainObjPtr vm)
>  {
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
>      qemuDomainDiskPrivatePtr diskPriv;
>
>      if (job->disk) {
> @@ -120,6 +130,9 @@ qemuBlockJobUnregister(qemuBlockJobDataPtr job)
>
>          job->disk = NULL;
>      }
> +
> +    /* this may remove the last reference of 'job' */
> +    virHashRemoveEntry(priv->blockjobs, job->name);
>  }
>
>
> @@ -132,7 +145,8 @@ qemuBlockJobUnregister(qemuBlockJobDataPtr job)
>   * Returns 0 on success and -1 on failure.
>   */
>  qemuBlockJobDataPtr
> -qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
> +qemuBlockJobDiskNew(virDomainObjPtr vm,
> +                    virDomainDiskDefPtr disk,
>                      qemuBlockJobType type,
>                      const char *jobname)
>  {
> @@ -141,7 +155,7 @@ qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
>      if (!(job = qemuBlockJobDataNew(type, jobname)))
>          return NULL;
>
> -    if (qemuBlockJobRegister(job, disk) < 0)
> +    if (qemuBlockJobRegister(job, vm, disk) < 0)
>          return NULL;
>
>      VIR_RETURN_PTR(job);
> @@ -189,13 +203,14 @@ qemuBlockJobStarted(qemuBlockJobDataPtr job)
>   * to @job if it was started.
>   */
>  void
> -qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job)
> +qemuBlockJobStartupFinalize(virDomainObjPtr vm,
> +                            qemuBlockJobDataPtr job)
>  {
>      if (!job)
>          return;
>
>      if (job->state == QEMU_BLOCKJOB_STATE_NEW)
> -        qemuBlockJobUnregister(job);
> +        qemuBlockJobUnregister(job, vm);
>
>      virObjectUnref(job);
>  }
> @@ -314,7 +329,7 @@ qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver,
>      virStorageSourceBackingStoreClear(disk->src);
>      ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk, NULL, true));
>      ignore_value(qemuBlockNodeNamesDetect(driver, vm, asyncJob));
> -    qemuBlockJobUnregister(job);
> +    qemuBlockJobUnregister(job, vm);
>  }
>
>
> @@ -369,7 +384,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
>          }
>          disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
>          disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
> -        qemuBlockJobUnregister(job);
> +        qemuBlockJobUnregister(job, vm);
>          break;
>
>      case VIR_DOMAIN_BLOCK_JOB_LAST:
> diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
> index da529090ad..b7aaa86f4d 100644
> --- a/src/qemu/qemu_blockjob.h
> +++ b/src/qemu/qemu_blockjob.h
> @@ -80,7 +80,8 @@ struct _qemuBlockJobData {
>
>
>  qemuBlockJobDataPtr
> -qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
> +qemuBlockJobDiskNew(virDomainObjPtr vm,
> +                    virDomainDiskDefPtr disk,
>                      qemuBlockJobType type,
>                      const char *jobname)
>      ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);

I think this patch is missing an attribute shift... Compilation is failing:

diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index d07ab75c8b..b0d17963fd 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -106,7 +106,7 @@ qemuBlockJobDiskNew(virDomainObjPtr vm,
                     virDomainDiskDefPtr disk,
                     qemuBlockJobType type,
                     const char *jobname)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);

 qemuBlockJobDataPtr
 qemuBlockJobDiskGetJob(virDomainDiskDefPtr disk)

> @@ -98,7 +99,8 @@ qemuBlockJobIsRunning(qemuBlockJobDataPtr job)
>      ATTRIBUTE_NONNULL(1);
>
>  void
> -qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job);
> +qemuBlockJobStartupFinalize(virDomainObjPtr vm,
> +                            qemuBlockJobDataPtr job);
>
>  int qemuBlockJobUpdate(virDomainObjPtr vm,
>                         qemuBlockJobDataPtr job,
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index e41a3001ae..879a78858b 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -4702,7 +4702,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
>      }
>
>      if (!(job = qemuBlockJobDiskGetJob(disk))) {
> -        if (!(job = qemuBlockJobDiskNew(disk, type, diskAlias)))
> +        if (!(job = qemuBlockJobDiskNew(vm, disk, type, diskAlias)))
>              goto endjob;
>          qemuBlockJobStarted(job);
>      }
> @@ -4712,7 +4712,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
>      qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
>
>   endjob:
> -    qemuBlockJobStartupFinalize(job);
> +    qemuBlockJobStartupFinalize(vm, job);
>      qemuDomainObjEndJob(driver, vm);
>  }
>
> @@ -17084,7 +17084,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
>          speed <<= 20;
>      }
>
> -    if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_PULL, device)))
> +    if (!(job = qemuBlockJobDiskNew(vm, disk, QEMU_BLOCKJOB_TYPE_PULL, device)))
>          goto endjob;
>
>      qemuDomainObjEnterMonitor(driver, vm);
> @@ -17110,7 +17110,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
>      qemuDomainObjEndJob(driver, vm);
>
>   cleanup:
> -    qemuBlockJobStartupFinalize(job);
> +    qemuBlockJobStartupFinalize(vm, job);
>      virDomainObjEndAPI(&vm);
>      return ret;
>  }
> @@ -17655,7 +17655,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
>      if (qemuDomainStorageSourceChainAccessAllow(driver, vm, mirror) < 0)
>          goto endjob;
>
> -    if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY, device)))
> +    if (!(job = qemuBlockJobDiskNew(vm, disk, QEMU_BLOCKJOB_TYPE_COPY, device)))
>          goto endjob;
>
>      disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
> @@ -17691,7 +17691,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
>          VIR_WARN("%s", _("unable to remove just-created copy target"));
>      virStorageFileDeinit(mirror);
>      qemuDomainObjEndJob(driver, vm);
> -    qemuBlockJobStartupFinalize(job);
> +    qemuBlockJobStartupFinalize(vm, job);
>
>      return ret;
>  }
> @@ -18042,7 +18042,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
>           qemuDomainStorageSourceAccessAllow(driver, vm, top_parent, false, false) < 0))
>          goto endjob;
>
> -    if (!(job = qemuBlockJobDiskNew(disk, jobtype, device)))
> +    if (!(job = qemuBlockJobDiskNew(vm, disk, jobtype, device)))
>          goto endjob;
>
>      disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
> @@ -18089,7 +18089,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
>              virFreeError(orig_err);
>          }
>      }
> -    qemuBlockJobStartupFinalize(job);
> +    qemuBlockJobStartupFinalize(vm, job);
>      qemuDomainObjEndJob(driver, vm);
>
>   cleanup:
> diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
> index 1fb88c11b6..e72553befc 100644
> --- a/src/qemu/qemu_migration.c
> +++ b/src/qemu/qemu_migration.c
> @@ -921,7 +921,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
>      if (!(diskAlias = qemuAliasDiskDriveFromDisk(disk)))
>          goto cleanup;
>
> -    if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY, diskAlias)))
> +    if (!(job = qemuBlockJobDiskNew(vm, disk, QEMU_BLOCKJOB_TYPE_COPY, diskAlias)))
>          goto cleanup;
>
>      qemuBlockJobSyncBegin(job);
> @@ -949,7 +949,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
>      ret = 0;
>
>   cleanup:
> -    qemuBlockJobStartupFinalize(job);
> +    qemuBlockJobStartupFinalize(vm, job);
>      VIR_FREE(diskAlias);
>      return ret;
>  }
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index aa09ef175a..29124ae184 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -976,7 +976,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
>      }
>
>   cleanup:
> -    qemuBlockJobStartupFinalize(job);
> +    qemuBlockJobStartupFinalize(vm, job);
>      qemuProcessEventFree(processEvent);
>      virObjectUnlock(vm);
>      return 0;
> @@ -7816,7 +7816,7 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
>          disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
>          jobtype = disk->mirrorJob;
>
> -    if (!(job = qemuBlockJobDiskNew(disk, jobtype, jobname)))
> +    if (!(job = qemuBlockJobDiskNew(vm, disk, jobtype, jobname)))
>          return -1;
>
>      qemuBlockJobStarted(job);
> @@ -7850,7 +7850,7 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
>      }
>
>   cleanup:
> -    qemuBlockJobStartupFinalize(job);
> +    qemuBlockJobStartupFinalize(vm, job);
>
>      return 0;
>  }
> --
> 2.21.0
>
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

--
Julio Faracco

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux