[libvirt] [PATCH 3/3] {qemu|test}_driver: Use CLAMP macro to clamp value.

Dongsheng Yang yangds.fnst at cn.fujitsu.com
Thu May 15 10:44:22 UTC 2014


On 05/15/2014 08:37 PM, Martin Kletzander wrote:
> On Thu, May 15, 2014 at 06:39:51PM +0900, Dongsheng Yang wrote:
>> As we have CLAMP macro in util.h, we should use it to replace
>> the open implementations of it.
>>
>> Signed-off-by: Dongsheng Yang <yangds.fnst at cn.fujitsu.com>
>> ---
>> src/qemu/qemu_driver.c | 8 ++------
>> src/test/test_driver.c | 7 ++-----
>> 2 files changed, 4 insertions(+), 11 deletions(-)
>>
>> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>> index 7648865..96f325d 100644
>> --- a/src/qemu/qemu_driver.c
>> +++ b/src/qemu/qemu_driver.c
>> @@ -4547,9 +4547,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
>>     if (maxcpu > hostcpus)
>>         maxcpu = hostcpus;
>>
>> -    /* Clamp to actual number of vcpus */
>> -    if (ncpumaps > targetDef->vcpus)
>> -        ncpumaps = targetDef->vcpus;
>> +    ncpumaps = CLAMP(ncpumaps, ncpumaps, targetDef->vcpus);
>>
>
> Useless comparison to self; I'd suggest using MIN() instead.  This
> applies to the patch.

Oops, did not realize that. Just found the key word of "Clamp" in 
comment and
replaced it with CLAMP.

So it is not related with the CLAMP, and I will sent a v2 of this patch 
independently.

Thanx.
>
> Martin
>
>>     if (ncpumaps < 1) {
>>         goto cleanup;
>> @@ -4857,9 +4855,7 @@ qemuDomainGetVcpus(virDomainPtr dom,
>>     if (maxcpu > hostcpus)
>>         maxcpu = hostcpus;
>>
>> -    /* Clamp to actual number of vcpus */
>> -    if (maxinfo > priv->nvcpupids)
>> -        maxinfo = priv->nvcpupids;
>> +    maxinfo = CLAMP(maxinfo, maxinfo, priv->nvcpupids);
>>
>>     if (maxinfo >= 1) {
>>         if (info != NULL) {
>> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
>> index 37756e7..024f63d 100644
>> --- a/src/test/test_driver.c
>> +++ b/src/test/test_driver.c
>> @@ -2773,12 +2773,9 @@ static int testDomainGetVcpus(virDomainPtr 
>> domain,
>>
>>     hostcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo);
>>     maxcpu = maplen * 8;
>> -    if (maxcpu > hostcpus)
>> -        maxcpu = hostcpus;
>>
>> -    /* Clamp to actual number of vcpus */
>> -    if (maxinfo > privdom->def->vcpus)
>> -        maxinfo = privdom->def->vcpus;
>> +    maxcpu = CLAMP(maxcpu, maxcpu, hostcpus);
>> +    maxinfo = CLAMP(maxinfo, maxinfo, privdom->def->vcpus);
>>
>>     /* Populate virVcpuInfo structures */
>>     if (info != NULL) {
>> -- 
>> 1.8.2.1
>>
>> -- 
>> libvir-list mailing list
>> libvir-list at redhat.com
>> https://www.redhat.com/mailman/listinfo/libvir-list




More information about the libvir-list mailing list