[libvirt] [PATCH] Fix initialization of current vcpus in libxl driver
Eric Blake
eblake at redhat.com
Tue May 24 16:43:22 UTC 2011
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 at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110524/e3528225/attachment-0001.sig>
More information about the libvir-list
mailing list