[libvirt] [PATCH go v2] domain.go: construct cpumaps correctly for CPU pinning verbs

Leonid Podolny leonid at podolny.net
Tue Feb 14 22:11:07 UTC 2017


In PinEmulator() and PinIOThread() there is an identical code that
converts []bool into a bitmask. It calculates the location in the
bitmask and then sets it always to 1, instead of looking at the
actual bool value.
---
 domain.go | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/domain.go b/domain.go
index 5482f1a..9ee908b 100644
--- a/domain.go
+++ b/domain.go
@@ -3967,10 +3967,12 @@ func (d *Domain) PinEmulator(cpumap []bool, flags DomainModificationImpact) erro
 	maplen := (len(cpumap) + 7) / 8
 	ccpumaps := make([]C.uchar, maplen)
 	for i := 0; i < len(cpumap); i++ {
-		byte := i / 8
-		bit := i % 8
+		if cpumap[i] {
+			byte := i / 8
+			bit := i % 8
 
-		ccpumaps[byte] |= (1 << uint(bit))
+			ccpumaps[byte] |= (1 << uint(bit))
+		}
 	}
 
 	ret := C.virDomainPinEmulator(d.ptr, &ccpumaps[0], C.int(maplen), C.uint(flags))
@@ -3989,10 +3991,12 @@ func (d *Domain) PinIOThread(iothreadid uint, cpumap []bool, flags DomainModific
 	maplen := (len(cpumap) + 7) / 8
 	ccpumaps := make([]C.uchar, maplen)
 	for i := 0; i < len(cpumap); i++ {
-		byte := i / 8
-		bit := i % 8
+		if cpumap[i] {
+			byte := i / 8
+			bit := i % 8
 
-		ccpumaps[byte] |= (1 << uint(bit))
+			ccpumaps[byte] |= (1 << uint(bit))
+		}
 	}
 
 	ret := C.virDomainPinIOThreadCompat(d.ptr, C.uint(iothreadid), &ccpumaps[0], C.int(maplen), C.uint(flags))
-- 
2.11.0




More information about the libvir-list mailing list