From: Ronald Rojas <ronladred@gmail.com>
Cc: Ronald Rojas <ronladred@gmail.com>,
wei.liu2@citrix.com, ian.jackson@eu.citrix.com,
george.dunlap@citrix.com, xen-devel@lists.xen.org
Subject: [PATCH v2 2/5] golang/xenlight: Add error constants and standard handling
Date: Thu, 2 Mar 2017 11:07:14 -0500 [thread overview]
Message-ID: <1488470837-23181-2-git-send-email-ronladred@gmail.com> (raw)
In-Reply-To: <1488470837-23181-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>
---
Changes since last patch:
- Whitespace fixes
CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
tools/golang/xenlight/xenlight.go | 81 +++++++++++++++++++++++++++++++++++++--
1 file changed, 77 insertions(+), 4 deletions(-)
diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 0a0cea2..cbd3527 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -29,17 +29,79 @@ import "C"
*
* To get back to static linking:
* #cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil
-*/
+ */
import (
"fmt"
"unsafe"
)
+/*
+ * Errors
+ */
+
+type Error int
+
+const (
+ ErrorNonspecific = Error(-C.ERROR_NONSPECIFIC)
+ ErrorVersion = Error(-C.ERROR_VERSION)
+ ErrorFail = Error(-C.ERROR_FAIL)
+ ErrorNi = Error(-C.ERROR_NI)
+ ErrorNomem = Error(-C.ERROR_NOMEM)
+ ErrorInval = Error(-C.ERROR_INVAL)
+ ErrorBadfail = Error(-C.ERROR_BADFAIL)
+ ErrorGuestTimedout = Error(-C.ERROR_GUEST_TIMEDOUT)
+ ErrorTimedout = Error(-C.ERROR_TIMEDOUT)
+ ErrorNoparavirt = Error(-C.ERROR_NOPARAVIRT)
+ ErrorNotReady = Error(-C.ERROR_NOT_READY)
+ ErrorOseventRegFail = Error(-C.ERROR_OSEVENT_REG_FAIL)
+ ErrorBufferfull = Error(-C.ERROR_BUFFERFULL)
+ ErrorUnknownChild = Error(-C.ERROR_UNKNOWN_CHILD)
+ ErrorLockFail = Error(-C.ERROR_LOCK_FAIL)
+ ErrorJsonConfigEmpty = Error(-C.ERROR_JSON_CONFIG_EMPTY)
+ ErrorDeviceExists = Error(-C.ERROR_DEVICE_EXISTS)
+ ErrorCheckpointDevopsDoesNotMatch = Error(-C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH)
+ ErrorCheckpointDeviceNotSupported = Error(-C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED)
+ ErrorVnumaConfigInvalid = Error(-C.ERROR_VNUMA_CONFIG_INVALID)
+ ErrorDomainNotfound = Error(-C.ERROR_DOMAIN_NOTFOUND)
+ ErrorAborted = Error(-C.ERROR_ABORTED)
+ ErrorNotfound = Error(-C.ERROR_NOTFOUND)
+ ErrorDomainDestroyed = Error(-C.ERROR_DOMAIN_DESTROYED)
+ ErrorFeatureRemoved = Error(-C.ERROR_FEATURE_REMOVED)
+)
+
+var errors = [...]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",
+}
/*
* Types: Builtins
*/
+
type Context struct {
ctx *C.libxl_ctx
}
@@ -49,6 +111,17 @@ type Context struct {
*/
var Ctx Context
+func (e Error) Error() string {
+ if 0 < int(e) && int(e) < len(errors) {
+ s := errors[e]
+ if s != "" {
+ return s
+ }
+ }
+ return fmt.Sprintf("libxl error: %d", -e)
+
+}
+
func (Ctx *Context) IsOpen() bool {
return Ctx.ctx != nil
}
@@ -58,11 +131,11 @@ func (Ctx *Context) Open() (err error) {
return
}
- logger := C.xtl_createlogger_stdiostream(C.stderr, C.XTL_ERROR, 0);
+ logger := C.xtl_createlogger_stdiostream(C.stderr, C.XTL_ERROR, 0)
ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, unsafe.Pointer(logger))
if ret != 0 {
- err = fmt.Errorf("Error: %d", -ret)
+ err = Error(-ret)
}
return
}
@@ -72,7 +145,7 @@ func (Ctx *Context) Close() (err error) {
Ctx.ctx = nil
if ret != 0 {
- err = fmt.Errorf("Error: %d", -ret)
+ err = Error(-ret)
}
return
}
--
2.7.3
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-03-02 16:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-02 16:07 [PATCH v2 1/5] golang/xenlight: Create stub package Ronald Rojas
2017-03-02 16:07 ` Ronald Rojas [this message]
2017-03-03 14:47 ` [PATCH v2 2/5] golang/xenlight: Add error constants and standard handling George Dunlap
2017-03-02 16:07 ` [PATCH v2 3/5] golang/xenlight: Add host-related functionality Ronald Rojas
2017-03-03 14:54 ` George Dunlap
2017-03-03 18:49 ` Ronald Rojas
2017-03-02 16:07 ` [PATCH v2 4/5] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
2017-03-03 15:15 ` George Dunlap
2017-03-03 19:31 ` Ronald Rojas
2017-03-02 16:07 ` [PATCH v2 5/5] golang/xenlight: Add tests host related functionality functions Ronald Rojas
2017-03-02 17:36 ` Ian Jackson
2017-03-02 17:53 ` George Dunlap
2017-03-02 17:55 ` Ian Jackson
2017-03-02 18:01 ` George Dunlap
2017-03-03 15:02 ` Ian Jackson
2017-03-03 15:10 ` George Dunlap
2017-03-03 15:41 ` Ian Jackson
2017-03-02 18:22 ` Ronald Rojas
2017-03-03 16:20 ` George Dunlap
2017-03-03 14:42 ` [PATCH v2 1/5] golang/xenlight: Create stub package 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=1488470837-23181-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).