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

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

On Tue, Feb 14, 2017 at 05:11:07PM -0500, Leonid Podolny wrote:
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(-)
Looks good, and I've applied to git master. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
participants (2)
-
Daniel P. Berrange
-
Leonid Podolny