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

Dongsheng Yang yangds.fnst at cn.fujitsu.com
Thu May 15 09:39:51 UTC 2014


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);
 
     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




More information about the libvir-list mailing list