xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ronald Rojas <ronladred@gmail.com>
Cc: Ronald Rojas <ronladred@gmail.com>,
	wei.liu2@citrix.com, ian.jackson@eu.citrix.com,
	George Dunlap <george.dunlap@citrix.com>,
	xen-devel@lists.xen.org
Subject: [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
Date: Thu, 16 Mar 2017 15:08:40 -0400	[thread overview]
Message-ID: <1489691330-17695-4-git-send-email-ronladred@gmail.com> (raw)
In-Reply-To: <1489691330-17695-1-git-send-email-ronladred@gmail.com>

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@citrix.com>
Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
Changes since last version

- Formating fixes

- used defer for libxl_dominfo_dispose

- Removed unnessary unsafe.Pointer() casts.

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 | 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@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-03-16 19:08 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
2017-03-16 19:08 ` [PATCH v4 02/14] golang/xenlight: Add error constants and standard handling Ronald Rojas
2017-03-20 15:41   ` George Dunlap
2017-03-16 19:08 ` [PATCH v4 03/14] golang/xenlight: Add host-related functionality Ronald Rojas
2017-03-20 15:50   ` George Dunlap
2017-03-16 19:08 ` Ronald Rojas [this message]
2017-03-20 15:57   ` [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause George Dunlap
2017-03-16 19:08 ` [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions Ronald Rojas
2017-03-20 17:49   ` George Dunlap
2017-03-20 18:15     ` Ian Jackson
2017-04-04 16:44       ` George Dunlap
2017-03-16 19:08 ` [PATCH v4 06/14] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
2017-03-16 19:08 ` [PATCH v4 08/14] golang/xenlight: Implement cpupool operations Ronald Rojas
2017-03-16 19:08 ` [PATCH v4 09/14] golang/xenlight: Implement Domain operations Ronald Rojas
2017-04-05 10:23   ` George Dunlap
2017-03-16 19:08 ` [PATCH v4 10/14] golang/xenlight: Implement Vcpuinfo and ListVcpu Ronald Rojas
2017-03-16 19:08 ` [PATCH v4 11/14] golang/xenlight: Implement get console path operations Ronald Rojas
2017-04-05 11:04   ` George Dunlap
2017-03-16 19:08 ` [PATCH v4 12/14] golang/xenlight: Created boilerplate code for device related structs Ronald Rojas
2017-04-05 11:13   ` George Dunlap
2017-03-16 19:08 ` [PATCH v4 13/14] golang/xenlight: Implement ActionOnShutdown and DomainConfig Ronald Rojas
2017-03-16 19:08 ` [PATCH v4 14/14] golang/xenlight: Implement domain create/destroy operations Ronald Rojas
2017-03-20 14:45 ` [PATCH v4 01/14] golang/xenlight: Create stub package George Dunlap
2017-03-23 15:36   ` Ronald Rojas
2017-03-20 17:51 ` George Dunlap
2017-03-23 15:37   ` Ronald Rojas

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=1489691330-17695-4-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).