|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v2 4/5] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
On 02/03/17 16:07, Ronald Rojas wrote:
> 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
> - Created type and enumeration of DomainType and ShutdownReason
>
> - Created String() method for DomainType and ShutdownReason
>
> - Refactored creating DomainInfo from c type into seperate
> toGo() function
>
> - Applied libxl_domain_info_init/dispose()
>
> - whitespace fixes
>
> CC: xen-devel@xxxxxxxxxxxxx
> CC: george.dunlap@xxxxxxxxxx
> CC: ian.jackson@xxxxxxxxxxxxx
> CC: wei.liu2@xxxxxxxxxx
>
> ---
> ---
> tools/golang/xenlight/xenlight.go | 132
> ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 132 insertions(+)
>
> diff --git a/tools/golang/xenlight/xenlight.go
> b/tools/golang/xenlight/xenlight.go
> index 63cc805..18dedcb 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -34,6 +34,7 @@ import "C"
> import (
> "fmt"
> "unsafe"
> + "time"
> )
>
> /*
> @@ -102,6 +103,12 @@ var errors = [...]string{
> * Types: Builtins
> */
>
> +type Domid uint32
> +
> +type MemKB uint64
> +
> +type Uuid C.libxl_uuid
> +
> type Context struct {
> ctx *C.libxl_ctx
> }
> @@ -203,6 +210,95 @@ 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)
Looks like this could use having `go fmt` run.
> +
> +)
> +
> +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
> */
> @@ -356,3 +452,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)
As before, put the 'defer libxl_dominfo_dispose()' here.
> +
> + ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi),
> C.uint32_t(Id))
unsafe.Pointer() isn't needed here.
Other than that, looks good, thanks.
-George
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |