[libvirt] [PATCH 08/13] qemu: Simplify qemuDomainSetInterfaceParameters by using virDomainObjGetDefs

John Ferlan jferlan at redhat.com
Wed Jun 17 21:00:24 UTC 2015



On 06/15/2015 03:47 PM, Peter Krempa wrote:
> ---
>  src/qemu/qemu_driver.c | 40 ++++++++++++++++------------------------
>  1 file changed, 16 insertions(+), 24 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 2cb0215..ceadc31 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -11246,12 +11246,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
>      virQEMUDriverPtr driver = dom->conn->privateData;
>      size_t i;
>      virDomainObjPtr vm = NULL;
> -    virDomainDefPtr persistentDef = NULL;
> +    virDomainDefPtr def;
> +    virDomainDefPtr persistentDef;
>      int ret = -1;
>      virDomainNetDefPtr net = NULL, persistentNet = NULL;
>      virNetDevBandwidthPtr bandwidth = NULL, newBandwidth = NULL;
>      virQEMUDriverConfigPtr cfg = NULL;
> -    virCapsPtr caps = NULL;
>      bool inboundSpecified = false, outboundSpecified = false;
> 
>      virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> @@ -11280,31 +11280,24 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
>      if (virDomainSetInterfaceParametersEnsureACL(dom->conn, vm->def, flags) < 0)
>          goto cleanup;
> 
> -    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
> +    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
>          goto cleanup;
> 
> -    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
> +    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
>          goto cleanup;

^^ goto endjob;

NOTE:

I see this is also an existing issue for qemuDomainPinIOThread - that is
the failure to ObjGetDefs goes to cleanup after a BeginJob rather than
going to endjob.

I know - a separate issue, but it may as well be fixed in this series...

ACK with the change here...

John


> 
> -    if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
> -                                        &persistentDef) < 0)
> +    if (def &&
> +        !(net = virDomainNetFind(vm->def, device))) {
> +        virReportError(VIR_ERR_INVALID_ARG,
> +                       _("Can't find device %s"), device);
>          goto endjob;
> -
> -    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
> -        net = virDomainNetFind(vm->def, device);
> -        if (!net) {
> -            virReportError(VIR_ERR_INVALID_ARG,
> -                           _("Can't find device %s"), device);
> -            goto endjob;
> -        }
>      }
> -    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
> -        persistentNet = virDomainNetFind(persistentDef, device);
> -        if (!persistentNet) {
> -            virReportError(VIR_ERR_INVALID_ARG,
> -                           _("Can't find device %s"), device);
> -            goto endjob;
> -        }
> +
> +    if (persistentDef &&
> +        !(persistentNet = virDomainNetFind(persistentDef, device))) {
> +        virReportError(VIR_ERR_INVALID_ARG,
> +                       _("Can't find device %s"), device);
> +        goto endjob;
>      }
> 
>      if ((VIR_ALLOC(bandwidth) < 0) ||
> @@ -11340,7 +11333,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
>      if (!bandwidth->out->average)
>          VIR_FREE(bandwidth->out);
> 
> -    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
> +    if (net) {
>          if (VIR_ALLOC(newBandwidth) < 0)
>              goto endjob;
> 
> @@ -11392,7 +11385,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
>              goto endjob;
>      }
> 
> -    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
> +    if (persistentNet) {
>          if (!persistentNet->bandwidth) {
>              persistentNet->bandwidth = bandwidth;
>              bandwidth = NULL;
> @@ -11426,7 +11419,6 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
>      virNetDevBandwidthFree(bandwidth);
>      virNetDevBandwidthFree(newBandwidth);
>      virDomainObjEndAPI(&vm);
> -    virObjectUnref(caps);
>      virObjectUnref(cfg);
>      return ret;
>  }
> 




More information about the libvir-list mailing list