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

Martin Kletzander mkletzan at redhat.com
Thu May 15 11:37:54 UTC 2014


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.

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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140515/fdc32e52/attachment-0001.sig>


More information about the libvir-list mailing list