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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]