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

Re: [libvirt] [PATCH] Fix initialization of current vcpus in libxl driver



On 05/24/2011 10:33 AM, Jim Fehlig wrote:
> This works in the libxl driver since cur_vcpus is an int.  But
> vcpu_avail is a long in xenxs/xen_sxpr.c and I'm hoping there is
> something better than the following approach
> 
> diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
> index 4cebb21..dc000a8 100644
> --- a/src/xenxs/xen_sxpr.c
> +++ b/src/xenxs/xen_sxpr.c
> @@ -2006,9 +2006,14 @@ xenFormatSxpr(virConnectPtr conn,
>      virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
>      /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
>         either 32, or 64 on a platform where long is big enough.  */
> -    if (def->vcpus < def->maxvcpus)
> -        virBufferAsprintf(&buf, "(vcpu_avail %lu)",
> -                          def->vcpus == 32 ? 1 << 31 : (1UL <<
> def->vcpus) - 1);


> +    if (def->vcpus < def->maxvcpus) {

If def->maxvcpus is 32, then:

> +        if (sizeof(long) == 4 && def->vcpus == 32)

this conditional will never be reached (def->vcpus is less than
def->maxvcpus).

So the existing ((1UL << def->vcpus) -1) never calls the non-portable
1UL<<32 (or 1UL<<64); so it never overflows.

-- 
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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