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 v2 4/5] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
Date: Thu,  2 Mar 2017 11:07:16 -0500	[thread overview]
Message-ID: <1488470837-23181-4-git-send-email-ronladred@gmail.com> (raw)
In-Reply-To: <1488470837-23181-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
- 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@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com

---
---
 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)
+
+)
+
+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)
+
+	ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi), C.uint32_t(Id))
+
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	di = cdi.toGo()
+	C.libxl_dominfo_dispose(&cdi)
+
+	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-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 ` [PATCH v2 2/5] golang/xenlight: Add error constants and standard handling Ronald Rojas
2017-03-03 14:47   ` 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 ` Ronald Rojas [this message]
2017-03-03 15:15   ` [PATCH v2 4/5] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause 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-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).