[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
Add calls for the following host-related functionality: - libxl_domain_info - libxl_domain_unpause Include Golang version for the libxl_domain_info as DomainInfo. Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx> Signed-off-by: Ronald Rojas <ronladred@xxxxxxxxx> --- Changes since last version - Formating fixes - used defer for libxl_dominfo_dispose - Removed unnessary unsafe.Pointer() casts. CC: xen-devel@xxxxxxxxxxxxx CC: george.dunlap@xxxxxxxxxx CC: ian.jackson@xxxxxxxxxxxxx CC: wei.liu2@xxxxxxxxxx --- --- tools/golang/xenlight/xenlight.go | 136 +++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 3 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 785eaaf..34c3050 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -33,6 +33,7 @@ import "C" import ( "fmt" + "time" "unsafe" ) @@ -102,13 +103,19 @@ var errors = [...]string{ * Types: Builtins */ +type Domid uint32 + +type MemKB uint64 + +type Uuid C.libxl_uuid + type Context struct { ctx *C.libxl_ctx } type Hwcap []C.uint32_t -func (chwcap C.libxl_hwcap) CToGo() (ghwcap Hwcap) { +func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) { // Alloc a Go slice for the bytes size := 8 ghwcap = make([]C.uint32_t, size) @@ -161,7 +168,7 @@ func (cphys *C.libxl_physinfo) toGo() (physinfo *Physinfo) { physinfo.SharingFreedPages = uint64(cphys.sharing_freed_pages) physinfo.SharingUsedFrames = uint64(cphys.sharing_used_frames) physinfo.NrNodes = uint32(cphys.nr_nodes) - physinfo.HwCap = cphys.hw_cap.CToGo() + physinfo.HwCap = cphys.hw_cap.toGo() physinfo.CapHvm = bool(cphys.cap_hvm) physinfo.CapHvmDirectio = bool(cphys.cap_hvm_directio) @@ -203,6 +210,93 @@ func (cinfo *C.libxl_version_info) toGo() (info *VersionInfo) { return } +type ShutdownReason int32 + +const ( + ShutdownReasonUnknown = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_UNKNOWN) + ShutdownReasonPoweroff = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_POWEROFF) + ShutdownReasonReboot = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_REBOOT) + ShutdownReasonSuspend = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_SUSPEND) + ShutdownReasonCrash = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_CRASH) + ShutdownReasonWatchdog = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_WATCHDOG) + ShutdownReasonSoftReset = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_SOFT_RESET) +) + +func (sr ShutdownReason) String() (str string) { + cstr := C.libxl_shutdown_reason_to_string(C.libxl_shutdown_reason(sr)) + str = C.GoString(cstr) + + return +} + +type DomainType int32 + +const ( + DomainTypeInvalid = DomainType(C.LIBXL_DOMAIN_TYPE_INVALID) + DomainTypeHvm = DomainType(C.LIBXL_DOMAIN_TYPE_HVM) + DomainTypePv = DomainType(C.LIBXL_DOMAIN_TYPE_PV) +) + +func (dt DomainType) String() (str string) { + cstr := C.libxl_domain_type_to_string(C.libxl_domain_type(dt)) + str = C.GoString(cstr) + + return +} + +type Dominfo struct { + Uuid Uuid + Domid Domid + Ssidref uint32 + SsidLabel string + Running bool + Blocked bool + Paused bool + Shutdown bool + Dying bool + NeverStop bool + + ShutdownReason int32 + OutstandingMemkb MemKB + CurrentMemkb MemKB + SharedMemkb MemKB + PagedMemkb MemKB + MaxMemkb MemKB + CpuTime time.Duration + VcpuMaxId uint32 + VcpuOnline uint32 + Cpupool uint32 + DomainType int32 +} + +func (cdi *C.libxl_dominfo) toGo() (di *Dominfo) { + + di = &Dominfo{} + di.Uuid = Uuid(cdi.uuid) + di.Domid = Domid(cdi.domid) + di.Ssidref = uint32(cdi.ssidref) + di.SsidLabel = C.GoString(cdi.ssid_label) + 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.NeverStop = bool(cdi.never_stop) + di.ShutdownReason = int32(cdi.shutdown_reason) + di.OutstandingMemkb = MemKB(cdi.outstanding_memkb) + di.CurrentMemkb = MemKB(cdi.current_memkb) + di.SharedMemkb = MemKB(cdi.shared_memkb) + di.PagedMemkb = MemKB(cdi.paged_memkb) + di.MaxMemkb = MemKB(cdi.max_memkb) + di.CpuTime = time.Duration(cdi.cpu_time) + di.VcpuMaxId = uint32(cdi.vcpu_max_id) + di.VcpuOnline = uint32(cdi.vcpu_online) + di.Cpupool = uint32(cdi.cpupool) + di.DomainType = int32(cdi.domain_type) + + return +} + /* * Context */ @@ -332,6 +426,7 @@ func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) { } var cphys C.libxl_physinfo C.libxl_physinfo_init(&cphys) + defer C.libxl_physinfo_dispose(&cphys) ret := C.libxl_get_physinfo(Ctx.ctx, &cphys) @@ -340,7 +435,6 @@ func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) { return } physinfo = cphys.toGo() - C.libxl_physinfo_dispose(&cphys) return } @@ -360,3 +454,39 @@ func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) { return } + +func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + + var cdi C.libxl_dominfo + C.libxl_dominfo_init(&cdi) + defer C.libxl_dominfo_dispose(&cdi) + + ret := C.libxl_domain_info(Ctx.ctx, &cdi, C.uint32_t(Id)) + + if ret != 0 { + err = Error(-ret) + return + } + + di = cdi.toGo() + + return +} + +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 { + err = Error(-ret) + } + return +} -- 2.7.3 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |