Commit 871e51d2d4 changed the sign on the xenlight error types (making
the values negative, same as the C-generated constants), but failed to
flip the sign in the Error() string function. The result is that
ErrorNonspecific.String() prints "libxl error: 1" rather than the
human-readable error message.
Get rid of the whole issue by making libxlErrors a map, and mapping
actual error values to string, falling back to printing the actual
value of the Error type if it's not present.
Signed-off-by: George Dunlap
---
v2:
- Convert libxlErrors to a map.
CC: Nick Rosbrook
---
tools/golang/xenlight/xenlight.go | 62 +++
1 file changed, 30 insertions(+), 32 deletions(-)
diff --git a/tools/golang/xenlight/xenlight.go
b/tools/golang/xenlight/xenlight.go
index 1299981713..aa1e63a61a 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -36,42 +36,40 @@ import (
"unsafe"
)
-var libxlErrors = [...]string{
- -ErrorNonspecific: "Non-specific error",
- -ErrorVersion: "Wrong version",
- -ErrorFail: "Failed",
- -ErrorNi: "Not Implemented",
- -ErrorNomem:"No memory",
- -ErrorInval:"Invalid argument",
- -ErrorBadfail: "Bad Fail",
- -ErrorGuestTimedout:"Guest timed out",
- -ErrorTimedout: "Timed out",
- -ErrorNoparavirt: "No Paravirtualization",
- -ErrorNotReady: "Not ready",
- -ErrorOseventRegFail: "OS event registration failed",
- -ErrorBufferfull: "Buffer full",
- -ErrorUnknownChild: "Unknown child",
- -ErrorLockFail: "Lock failed",
- -ErrorJsonConfigEmpty: "JSON config empty",
- -ErrorDeviceExists: "Device exists",
- -ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match",
- -ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported",
- -ErrorVnumaConfigInvalid: "VNUMA config invalid",
- -ErrorDomainNotfound: "Domain not found",
- -ErrorAborted: "Aborted",
- -ErrorNotfound: "Not found",
- -ErrorDomainDestroyed: "Domain destroyed",
- -ErrorFeatureRemoved: "Feature removed",
+var libxlErrors = map[Error]string{
+ ErrorNonspecific: "Non-specific error",
+ ErrorVersion: "Wrong version",
+ ErrorFail: "Failed",
+ ErrorNi: "Not Implemented",
+ ErrorNomem:"No memory",
+ ErrorInval:"Invalid argument",
+ ErrorBadfail: "Bad Fail",
+ ErrorGuestTimedout:"Guest timed out",
+ ErrorTimedout: "Timed out",
+ ErrorNoparavirt: "No Paravirtualization",
+ ErrorNotReady: "Not ready",
+ ErrorOseventRegFail: "OS event registration failed",
+ ErrorBufferfull: "Buffer full",
+ ErrorUnknownChild: "Unknown child",
+ ErrorLockFail: "Lock failed",
+ ErrorJsonConfigEmpty: "JSON config empty",
+ ErrorDeviceExists: "Device exists",
+ ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match",
+ ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported",
+ ErrorVnumaConfigInvalid: "VNUMA config invalid",
+ ErrorDomainNotfound: "Domain not found",
+ ErrorAborted: "Aborted",
+ ErrorNotfound: "Not found",
+ ErrorDomainDestroyed: "Domain destroyed",
+ ErrorFeatureRemoved: "Feature removed",
}
func (e Error) Error() string {
- if 0 < int(e) && int(e) < len(libxlErrors) {
- s := libxlErrors[e]
- if s != "" {
- return s
- }
+ if s, ok := libxlErrors[e]; ok {
+ return s
}
- return fmt.Sprintf("libxl error: %d", -e)
+
+ return fmt.Sprintf("libxl error: %d", e)
}
// Context represents a libxl_ctx.
--
2.24.1
___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel