[libvirt] [PATCH V2 4/4] qemu: Ensure reported VCPU state is current in driver API

John Ferlan jferlan at redhat.com
Thu Sep 29 14:35:23 UTC 2016



On 09/20/2016 04:11 AM, Viktor Mihajlovski wrote:
> Refresh the VCPU halted states in API functions returning domain
> VCPU state information to make sure it's current. This affects
> qemuDomainGetVcpus and  qemuDomainGetStatsVcpu
> 
> Signed-off-by: Viktor Mihajlovski <mihajlov at linux.vnet.ibm.com>
> Reviewed-by: Bjoern Walk <bwalk at linux.vnet.ibm.com>
> Reviewed-by: Hao QingFeng <haoqf at linux.vnet.ibm.com>
> Signed-off-by: Boris Fiuczynski <fiuczy at linux.vnet.ibm.com>
> ---
>  src/qemu/qemu_driver.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index e29180d..7105d26 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -1478,13 +1478,17 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm,
>          virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(vm->def, i);
>          pid_t vcpupid = qemuDomainGetVcpuPid(vm, i);
>          virVcpuInfoPtr vcpuinfo = info + ncpuinfo;
> +        bool vcpuhalted = qemuDomainGetVcpuHalted(vm, i);
>  
>          if (!vcpu->online)
>              continue;
>  
>          if (info) {
>              vcpuinfo->number = i;
> -            vcpuinfo->state = VIR_VCPU_RUNNING;
> +            if (vcpuhalted)
> +                vcpuinfo->state = VIR_VCPU_HALTED;

And this causes the client to see "halted" even though the vcpu may be
running, but just not busy.

Also if (vm->def->virtType == VIR_DOMAIN_VIRT_QEMU), then we'll always
be halted since qemuDomainRefreshVcpuHalted will avoid the refetch of data.


> +            else
> +                vcpuinfo->state = VIR_VCPU_RUNNING;
>  
>              if (qemuGetProcessInfo(&vcpuinfo->cpuTime,
>                                     &vcpuinfo->cpu, NULL,
> @@ -5370,6 +5374,7 @@ qemuDomainGetVcpus(virDomainPtr dom,
>                     unsigned char *cpumaps,
>                     int maplen)
>  {

The opposite end of virDomainGetVcpus a/k/a 'virsh vcpuinfo'

> +    virQEMUDriverPtr driver = dom->conn->privateData;
>      virDomainObjPtr vm;
>      int ret = -1;
>  
> @@ -5385,6 +5390,13 @@ qemuDomainGetVcpus(virDomainPtr dom,
>          goto cleanup;
>      }
>  
> +    if (qemuDomainRefreshVcpuHalted(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       "%s",
> +                       _("could not refresh CPU states"));

This overwrites what message qemuDomainRefreshVcpuHalted should have
generated.  Besides the "%s", could be on the previous line...

> +        goto cleanup;
> +    }
> +
>      ret = qemuDomainHelperGetVcpus(vm, info, NULL, maxinfo, cpumaps, maplen);
>  
>   cleanup:
> @@ -18863,7 +18875,7 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver,
>  
>  
>  static int
> -qemuDomainGetStatsVcpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
> +qemuDomainGetStatsVcpu(virQEMUDriverPtr driver,
>                         virDomainObjPtr dom,
>                         virDomainStatsRecordPtr record,
>                         int *maxparams,
> @@ -18893,6 +18905,13 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
>          VIR_ALLOC_N(cpuwait, virDomainDefGetVcpus(dom->def)) < 0)
>          goto cleanup;
>  
> +    if (qemuDomainRefreshVcpuHalted(driver, dom, QEMU_ASYNC_JOB_NONE) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       "%s",
> +                       _("could not refresh CPU states"));

Same comment

John

> +        goto cleanup;
> +    }
> +
>      if (qemuDomainHelperGetVcpus(dom, cpuinfo, cpuwait,
>                                   virDomainDefGetVcpus(dom->def),
>                                   NULL, 0) < 0) {
> 




More information about the libvir-list mailing list