[Libvirt-cim] [PATCH 1 of 2] Add a domain_vcpu_count() function to return the number of active VCPUs for

Dan Smith danms at us.ibm.com
Tue Oct 28 15:16:50 UTC 2008


>> +        info = calloc(max, sizeof(*info));
>> +        if (info == NULL) {
>> +                CU_DEBUG("Failed to allocate %i vcpuinfo structures", max);
>> +                return -1;
>> +        }
>> +
>> +        count = virDomainGetVcpus(dom, info, max, NULL, 0);
>> +
>> +        free(info);

KR> You free info here..

>> +
>> +        for (i = 0; i < count; i++) {
>> +                if (info[i].cpu != -1)

KR> But use one of its fields in the compare here.

Yeah, that would be bad.

What happened was, I didn't realize at first that we had to actually
examine the .cpu field of the struct to get a count of *active* vcpus,
so I initially was just returning count.  Later, I added the loop to
count the active ones, and clearly added it after the free() instead
of before :)

I'll send a replacement.  Thanks!

-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms at us.ibm.com




More information about the Libvirt-cim mailing list