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

[Xen-devel] [PATCH v3 4/8] golang/xenlight: Errors are negative


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: George Dunlap <george.dunlap@xxxxxxxxxx>
  • Date: Fri, 17 Jan 2020 15:57:30 +0000
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@xxxxxxxxxx; spf=Pass smtp.mailfrom=George.Dunlap@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Cc: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Fri, 17 Jan 2020 15:57:56 +0000
  • Ironport-sdr: gr6POZZBnx/sUyvQ15FK3IQNdfDc3Eu7uCDYfE+ffs8kKDDX8boNs3YS5bYSieVCYmpDm1mlNU 9U3PhCN5cCpZqlM3TyR0/iLB3UMUT3vIN/uOnMJPjDhru31grI5SpnSS3YtYgcU6QN3JJhKTr9 ahye6xg8ggOoGEyNNzhSGQUom1H9HO5ybJYasUIjQKHNfccvqngawaqUsANQRXvKMStRRv79c7 fmRn+93r3D4KeKbOCgoW4YBcu+bHhJys36+R5kQasbt8PZhUqhGp69TGM7ewLOBik7C48kSEJB A7c=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 <george.dunlap@xxxxxxxxxx>
---
v2:
- Convert libxlErrors to a map.

CC: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.