]> xenbits.xensource.com Git - people/dwmw2/xen.git/commitdiff
go/xenlight: Fix CpuidPoliclyList conversion
authorGeorge Dunlap <george.dunlap@citrix.com>
Thu, 26 Dec 2019 17:43:17 +0000 (17:43 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 21 Jan 2020 17:48:24 +0000 (17:48 +0000)
Empty Go strings should be converted to `nil` libxl_cpuid_policy_list;
otherwise libxl_cpuid_parse_config gets confused.

Also, libxl_cpuid_policy_list returns a weird error, not a "normal"
libxl error; if it returns one of these non-standard errors, convert
it to ErrorInval.

Finally, make the fromC() method take a pointer, and set the value of
CpuidPolicyList such that it will generate a valid CpuidPolicyList in
response.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Nick Rosbrook <rosbrookn@ainfosec.com>
tools/golang/xenlight/xenlight.go

index b1587b964f3dedd3f7be9305cde4dbce490b5073..1299981713dd0f7abe97b27ad996785663f7f365 100644 (file)
@@ -306,9 +306,14 @@ func (el *EvLink) toC(cel *C.libxl_ev_link) (err error) { return }
 // empty when it is returned from libxl.
 type CpuidPolicyList string
 
-func (cpl CpuidPolicyList) fromC(ccpl *C.libxl_cpuid_policy_list) error { return nil }
+func (cpl *CpuidPolicyList) fromC(ccpl *C.libxl_cpuid_policy_list) error { *cpl = ""; return nil }
 
 func (cpl CpuidPolicyList) toC(ccpl *C.libxl_cpuid_policy_list) error {
+       if cpl == "" {
+               *ccpl = nil
+               return nil
+       }
+
        s := C.CString(string(cpl))
        defer C.free(unsafe.Pointer(s))
 
@@ -316,7 +321,8 @@ func (cpl CpuidPolicyList) toC(ccpl *C.libxl_cpuid_policy_list) error {
        if ret != 0 {
                C.libxl_cpuid_dispose(ccpl)
 
-               return Error(-ret)
+               // libxl_cpuid_parse_config doesn't return a normal libxl error.
+               return ErrorInval
        }
 
        return nil