From: Ronald Rojas <ronladred@gmail.com>
To: xen-devel@lists.xen.org, george.dunlap@citrix.com,
ian.jackson@eu.citrix.com, wei.liu2@citrix.com
Cc: Ronald Rojas <ronladred@gmail.com>
Subject: [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling
Date: Wed, 18 Jan 2017 14:56:40 -0500 [thread overview]
Message-ID: <1484769406-17416-2-git-send-email-ronladred@gmail.com> (raw)
In-Reply-To: <1484769406-17416-1-git-send-email-ronladred@gmail.com>
Create error type Errorxl for throwing proper xenlight
errors.
Update Ctx functions to throw Errorxl errors.
Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
tools/golang/xenlight/xenlight.go | 77 +++++++++++++++++++++++++++++++++++++--
1 file changed, 73 insertions(+), 4 deletions(-)
diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 1f10e51..d58f8b8 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -32,6 +32,77 @@ import (
)
/*
+ * Errors
+ */
+type Errorxl int
+
+const (
+ ErrorNonspecific = Errorxl(-C.ERROR_NONSPECIFIC)
+ ErrorVersion = Errorxl(-C.ERROR_VERSION)
+ ErrorFail = Errorxl(-C.ERROR_FAIL)
+ ErrorNi = Errorxl(-C.ERROR_NI)
+ ErrorNomem = Errorxl(-C.ERROR_NOMEM)
+ ErrorInval = Errorxl(-C.ERROR_INVAL)
+ ErrorBadfail = Errorxl(-C.ERROR_BADFAIL)
+ ErrorGuestTimedout = Errorxl(-C.ERROR_GUEST_TIMEDOUT)
+ ErrorTimedout = Errorxl(-C.ERROR_TIMEDOUT)
+ ErrorNoparavirt = Errorxl(-C.ERROR_NOPARAVIRT)
+ ErrorNotReady = Errorxl(-C.ERROR_NOT_READY)
+ ErrorOseventRegFail = Errorxl(-C.ERROR_OSEVENT_REG_FAIL)
+ ErrorBufferfull = Errorxl(-C.ERROR_BUFFERFULL)
+ ErrorUnknownChild = Errorxl(-C.ERROR_UNKNOWN_CHILD)
+ ErrorLockFail = Errorxl(-C.ERROR_LOCK_FAIL)
+ ErrorJsonConfigEmpty = Errorxl(-C.ERROR_JSON_CONFIG_EMPTY)
+ ErrorDeviceExists = Errorxl(-C.ERROR_DEVICE_EXISTS)
+ ErrorCheckpointDevopsDoesNotMatch = Errorxl(-C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH)
+ ErrorCheckpointDeviceNotSupported = Errorxl(-C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED)
+ ErrorVnumaConfigInvalid = Errorxl(-C.ERROR_VNUMA_CONFIG_INVALID)
+ ErrorDomainNotfound = Errorxl(-C.ERROR_DOMAIN_NOTFOUND)
+ ErrorAborted = Errorxl(-C.ERROR_ABORTED)
+ ErrorNotfound = Errorxl(-C.ERROR_NOTFOUND)
+ ErrorDomainDestroyed = Errorxl(-C.ERROR_DOMAIN_DESTROYED)
+ ErrorFeatureRemoved = Errorxl(-C.ERROR_FEATURE_REMOVED)
+)
+
+var errors = [...]string{
+ ErrorNonspecific: "Non-specific error",
+ ErrorVersion: "Wrong version",
+ ErrorFail: "Failed",
+ ErrorNi: "Null",
+ ErrorNomem: "No memory",
+ ErrorInval: "Invalid",
+ ErrorBadfail: "Bad Fail",
+ ErrorGuestTimedout: "Guest timed out",
+ ErrorTimedout: "Timed out",
+ ErrorNoparavirt: "No Paravirtualization",
+ ErrorNotReady: "Not ready",
+ ErrorOseventRegFail: "OS event failed",
+ ErrorBufferfull: "Buffer full",
+ ErrorUnknownChild: "Unknown child",
+ ErrorLockFail: "Lock failed",
+ ErrorJsonConfigEmpty: "JSON config empyt",
+ 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 Errorxl) Error() string {
+ if 0 <= -int(e) && -int(e) < len(errors) {
+ s := errors[-e]
+ if s != "" {
+ return s
+ }
+ }
+ return "errorxl " + strconv.Itoa(int(e))
+}
+
+/*
* Types: Builtins
*/
type Context struct {
@@ -55,8 +126,7 @@ func (Ctx *Context) Open() (err error) {
ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
if ret != 0 {
- //FIXME: proper error
- err = createError("Allocating libxl context: ", ret)
+ err = Errorxl(ret)
}
return
}
@@ -66,8 +136,7 @@ func (Ctx *Context) Close() (err error) {
Ctx.ctx = nil
if ret != 0 {
- //FIXME: proper error
- err = createError("Freeing libxl context: ", ret)
+ err = Errorxl(ret)
}
return
}
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-01-18 19:56 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-18 19:56 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
2017-01-18 19:56 ` Ronald Rojas [this message]
2017-01-18 22:16 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Dario Faggioli
2017-01-19 15:13 ` Ronald Rojas
2017-01-19 16:02 ` George Dunlap
2017-01-19 16:15 ` Wei Liu
2017-01-19 16:19 ` Dario Faggioli
2017-01-19 17:16 ` George Dunlap
2017-01-18 19:56 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
2017-01-19 17:51 ` George Dunlap
2017-01-18 19:56 ` [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 5/8] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 6/8] tools/xenlight: Implement libxl_scheduler enumeration Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 7/8] golang/xenlight: Implement cpupool operations Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 8/8] golang/xenlight: Add tests host related functinality functions Ronald Rojas
2017-01-18 22:10 ` [PATCH RFC 1/8] golang/xenlight: Create stub package Dario Faggioli
2017-01-18 22:37 ` Ronald Rojas
2017-01-19 12:03 ` Wei Liu
2017-01-19 15:15 ` Ronald Rojas
2017-01-19 16:16 ` George Dunlap
2017-01-19 16:40 ` George Dunlap
2017-01-19 16:45 ` George Dunlap
-- strict thread matches above, loose matches on Subject: below --
2017-01-23 16:43 Ronald Rojas
2017-01-23 16:43 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Ronald Rojas
2017-01-27 12:22 ` George Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1484769406-17416-2-git-send-email-ronladred@gmail.com \
--to=ronladred@gmail.com \
--cc=george.dunlap@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.