From dcadedf83b219755994af123e2ee0ec49db85445 Mon Sep 17 00:00:00 2001 From: George Dunlap Date: Thu, 29 Dec 2016 19:54:10 +0000 Subject: [PATCH 4/7] golang/xenlight: Implement libxl_get_gomainfinfo and libxl_domain_unpause Signed-off-by: George Dunlap --- tools/golang/xenlight/xenlight.go | 91 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 05604c7..96a6952 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -124,6 +124,12 @@ func createError(method string, cerrNum C.int) (err error) { /* * Types: Builtins */ +type Domid uint32 + +type MemKB uint64 + +type Uuid C.libxl_uuid + type Context struct { ctx *C.libxl_ctx } @@ -189,6 +195,29 @@ type VersionInfo struct { Build_id string } +type Dominfo struct { + Uuid Uuid + Domid Domid + Running bool + Blocked bool + Paused bool + Shutdown bool + Dying bool + Never_stop bool + + Shutdown_reason int32 // FIXME shutdown_reason enumeration + Outstanding_memkb MemKB + Current_memkb MemKB + Shared_memkb MemKB + Paged_memkb MemKB + Max_memkb MemKB + Cpu_time time.Duration + Vcpu_max_id uint32 + Vcpu_online uint32 + Cpupool uint32 + Domain_type int32 //FIXME libxl_domain_type enumeration + +} /* * Context @@ -361,3 +390,65 @@ func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) { return } + +//int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r, uint32_t domid); +func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + + var cdi C.libxl_dominfo + + ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi), C.uint32_t(Id)) + + // FIXME: proper error + if ret != 0 { + err = createError("libxl_domain_info failed: ", ret) + return + } + + // We could consider having this boilerplate generated by the + // idl, in a function like this: + // + // di = translateCdomaininfoToGoDomaininfo(cdi) + di = &Dominfo{} + di.Uuid = Uuid(cdi.uuid) + di.Domid = Domid(cdi.domid) + di.Running = bool(cdi.running) + di.Blocked = bool(cdi.blocked) + di.Paused = bool(cdi.paused) + di.Shutdown = bool(cdi.shutdown) + di.Dying = bool(cdi.dying) + di.Never_stop = bool(cdi.never_stop) + di.Shutdown_reason = int32(cdi.shutdown_reason) + di.Outstanding_memkb = MemKB(cdi.outstanding_memkb) + di.Current_memkb = MemKB(cdi.current_memkb) + di.Shared_memkb = MemKB(cdi.shared_memkb) + di.Paged_memkb = MemKB(cdi.paged_memkb) + di.Max_memkb = MemKB(cdi.max_memkb) + di.Cpu_time = time.Duration(cdi.cpu_time) + di.Vcpu_max_id = uint32(cdi.vcpu_max_id) + di.Vcpu_online = uint32(cdi.vcpu_online) + di.Cpupool = uint32(cdi.cpupool) + di.Domain_type = int32(cdi.domain_type) + + return +} + +//int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid); +func (Ctx *Context) DomainUnpause(Id Domid) (err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + + ret := C.libxl_domain_unpause(Ctx.ctx, C.uint32_t(Id)) + + if ret != 0 { + //FIXME: proper error + err = createError("libxl_domain_unpause failed: ", ret) + } + return +} + -- 2.1.4