All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 1/8] golang/xenlight: Create stub package
@ 2017-01-23 16:43 Ronald Rojas
  2017-01-23 16:43 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Ronald Rojas
                   ` (10 more replies)
  0 siblings, 11 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Create a basic Makefile to build and install libxenlight Golang
bindings. Also add a stub package which only opens libxl context.

Include a global xenlight.Ctx variable which can be used as the
default context by the entire program if desired.

For now, return simple errors. Proper error handling will be
added in next patch.

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/Makefile                    | 17 ++++++++
 tools/golang/xenlight/Makefile    | 31 ++++++++++++++
 tools/golang/xenlight/xenlight.go | 86 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 134 insertions(+)
 create mode 100644 tools/golang/xenlight/Makefile
 create mode 100644 tools/golang/xenlight/xenlight.go

diff --git a/tools/Makefile b/tools/Makefile
index 77e0723..c1e975f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -11,6 +11,8 @@ SUBDIRS-y += xenstore
 SUBDIRS-y += misc
 SUBDIRS-y += examples
 SUBDIRS-y += hotplug
+#Uncomment line to build Golang libxl
+#SUBDIRS-y += golang/xenlight
 SUBDIRS-y += xentrace
 SUBDIRS-$(CONFIG_XCUTILS) += xcutils
 SUBDIRS-$(CONFIG_X86) += firmware
@@ -303,6 +305,21 @@ subdir-clean-qemu-xen-dir:
 		$(MAKE) -C qemu-xen-dir clean; \
 	fi
 
+subdir-clean-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight clean
+
+subdir-distclean-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight distclean
+
+subdir-install-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight install
+
+subdir-all-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight all
+
+subdir-distclean-firmware: .phony
+	$(MAKE) -C firmware distclean
+
 subdir-clean-debugger/gdbsx subdir-distclean-debugger/gdbsx: .phony
 	$(MAKE) -C debugger/gdbsx clean
 
diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
new file mode 100644
index 0000000..1c2a2b7
--- /dev/null
+++ b/tools/golang/xenlight/Makefile
@@ -0,0 +1,31 @@
+XEN_ROOT=$(CURDIR)/../../..
+GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight
+CGO_CFLAGS = -I$(DESTDIR)$(includedir)
+CGO_LDFLAGS = -L$(DESTDIR)$(libdir) -Wl,-rpath-link=$(DESTDIR)$(libdir)
+include $(XEN_ROOT)/tools/Rules.mk
+
+BINARY = xenlight.a
+GO ?= go
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build: xenlight.a
+
+.PHONY: install
+install: build
+	$(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC)
+	$(INSTALL_DATA) xenlight.go $(DESTDIR)$(GOLANG_SRC)
+
+.PHONY: clean
+clean:
+	$(RM) $(BINARY)
+
+.PHONY: distclean
+distclean: clean
+
+xenlight.a: xenlight.go
+	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o $@ $<
+
+-include $(DEPS)
diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
new file mode 100644
index 0000000..f82e14e
--- /dev/null
+++ b/tools/golang/xenlight/xenlight.go
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of the
+ * License only.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+package xenlight
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+
+/*
+ * Other flags that may be needed at some point:
+ *  -lnl-route-3 -lnl-3
+ *
+ * To get back to static linking:
+ * #cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil
+*/
+
+import (
+	"fmt"
+	"unsafe"
+)
+
+
+/*
+ * Types: Builtins
+ */
+type Context struct {
+	ctx *C.libxl_ctx
+}
+
+/*
+ * Context
+ */
+var Ctx Context
+
+func (Ctx *Context) IsOpen() bool {
+	return Ctx.ctx != nil
+}
+
+func (Ctx *Context) Open() (err error) {
+	if Ctx.ctx != nil {
+		return
+	}
+
+	ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
+
+	if ret != 0 {
+		err = Error(-ret)
+	}
+	return
+}
+
+func (Ctx *Context) Close() (err error) {
+	ret := C.libxl_ctx_free(unsafe.Pointer(Ctx.ctx))
+	Ctx.ctx = nil
+
+	if ret != 0 {
+		err = Error(-ret)
+	}
+	return
+}
+
+func (Ctx *Context) CheckOpen() (err error) {
+	if Ctx.ctx == nil {
+		err = fmt.Errorf("Context not opened")
+	}
+	return
+}
\ No newline at end of file
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
@ 2017-01-23 16:43 ` Ronald Rojas
  2017-01-27 12:22   ` George Dunlap
  2017-01-23 16:43 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Create error type Errorxl for throwing proper xenlight
errors.

Update Ctx functions to throw Errorxl errors.

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/golang/xenlight/xenlight.go | 75 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index f82e14e..eee2254 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -38,10 +38,72 @@ import (
 	"unsafe"
 )
 
+/*
+ * Errors
+ */
+
+type Error int
+
+const (
+	ErrorNonspecific                  = Error(-C.ERROR_NONSPECIFIC)
+	ErrorVersion                      = Error(-C.ERROR_VERSION)
+	ErrorFail                         = Error(-C.ERROR_FAIL)
+	ErrorNi                           = Error(-C.ERROR_NI)
+	ErrorNomem                        = Error(-C.ERROR_NOMEM)
+	ErrorInval                        = Error(-C.ERROR_INVAL)
+	ErrorBadfail                      = Error(-C.ERROR_BADFAIL)
+	ErrorGuestTimedout                = Error(-C.ERROR_GUEST_TIMEDOUT)
+	ErrorTimedout                     = Error(-C.ERROR_TIMEDOUT)
+	ErrorNoparavirt                   = Error(-C.ERROR_NOPARAVIRT)
+	ErrorNotReady                     = Error(-C.ERROR_NOT_READY)
+	ErrorOseventRegFail               = Error(-C.ERROR_OSEVENT_REG_FAIL)
+	ErrorBufferfull                   = Error(-C.ERROR_BUFFERFULL)
+	ErrorUnknownChild                 = Error(-C.ERROR_UNKNOWN_CHILD)
+	ErrorLockFail                     = Error(-C.ERROR_LOCK_FAIL)
+	ErrorJsonConfigEmpty              = Error(-C.ERROR_JSON_CONFIG_EMPTY)
+	ErrorDeviceExists                 = Error(-C.ERROR_DEVICE_EXISTS)
+	ErrorCheckpointDevopsDoesNotMatch = Error(-C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH)
+	ErrorCheckpointDeviceNotSupported = Error(-C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED)
+	ErrorVnumaConfigInvalid           = Error(-C.ERROR_VNUMA_CONFIG_INVALID)
+	ErrorDomainNotfound               = Error(-C.ERROR_DOMAIN_NOTFOUND)
+	ErrorAborted                      = Error(-C.ERROR_ABORTED)
+	ErrorNotfound                     = Error(-C.ERROR_NOTFOUND)
+	ErrorDomainDestroyed              = Error(-C.ERROR_DOMAIN_DESTROYED)
+	ErrorFeatureRemoved               = Error(-C.ERROR_FEATURE_REMOVED)
+)
+
+var errors = [...]string{
+	ErrorNonspecific: "Non-specific error",
+	ErrorVersion: "Wrong version",
+	ErrorFail: "Failed",
+	ErrorNi: "Not Implemented",
+	ErrorNomem: "No memory",
+	ErrorInval: "Invalid argument",
+	ErrorBadfail: "Bad Fail",
+	ErrorGuestTimedout: "Guest timed out",
+	ErrorTimedout: "Timed out",
+	ErrorNoparavirt: "No Paravirtualization",
+	ErrorNotReady: "Not ready",
+	ErrorOseventRegFail: "OS event registration failed",
+	ErrorBufferfull: "Buffer full",
+	ErrorUnknownChild: "Unknown child",
+	ErrorLockFail: "Lock failed",
+	ErrorJsonConfigEmpty: "JSON config empty",
+	ErrorDeviceExists: "Device exists",
+	ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match",
+	ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported",
+	ErrorVnumaConfigInvalid: "VNUMA config invalid",
+	ErrorDomainNotfound: "Domain not found",
+	ErrorAborted: "Aborted",
+	ErrorNotfound: "Not found",
+	ErrorDomainDestroyed: "Domain destroyed",
+	ErrorFeatureRemoved: "Feature removed",
+}
 
 /*
  * Types: Builtins
  */
+
 type Context struct {
 	ctx *C.libxl_ctx
 }
@@ -51,6 +113,17 @@ type Context struct {
  */
 var Ctx Context
 
+func (e Error) Error() string{
+	if 0< int(e) && int(e) < len(errors){
+		s:= errors[e]
+		if s != ""{
+			return s
+		}
+	}
+	return fmt.Sprintf("libxl error: %d", -e)
+
+}
+
 func (Ctx *Context) IsOpen() bool {
 	return Ctx.ctx != nil
 }
@@ -83,4 +156,4 @@ func (Ctx *Context) CheckOpen() (err error) {
 		err = fmt.Errorf("Context not opened")
 	}
 	return
-}
\ No newline at end of file
+}
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH RFC 3/8] golang/xenlight: Add host-related functionality
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
  2017-01-23 16:43 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Ronald Rojas
@ 2017-01-23 16:43 ` Ronald Rojas
  2017-02-01 15:53   ` George Dunlap
                     ` (2 more replies)
  2017-01-23 16:43 ` [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
                   ` (8 subsequent siblings)
  10 siblings, 3 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Add calls for the following host-related functionality:
- libxl_get_max_cpus
- libxl_get_online_cpus
- libxl_get_max_nodes
- libxl_get_free_memory
- libxl_get_physinfo
- libxl_get_version_info

Include Golang versions of the following structs:
- libxl_physinfo as Physinfo
- libxl_version_info as VersionInfo
- libxl_hwcap as Hwcap

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/golang/xenlight/xenlight.go | 186 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 186 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index eee2254..92410a8 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -108,6 +108,63 @@ type Context struct {
 	ctx *C.libxl_ctx
 }
 
+type Hwcap []C.uint32_t
+
+func (chwcap C.libxl_hwcap)CToGo() (ghwcap Hwcap) {
+	// Alloc a Go slice for the bytes
+	size := 8
+	ghwcap= make([]C.uint32_t, size)
+
+	// Make a slice pointing to the C array
+	mapslice := (*[1 << 30]C.uint32_t)(unsafe.Pointer(&chwcap[0]))[:size:size]
+
+	// And copy the C array into the Go array
+	copy(ghwcap, mapslice)
+
+	return
+}
+
+
+/*
+ * Types: IDL
+ *
+ * FIXME: Generate these automatically from the IDL
+ */
+
+type Physinfo struct {
+	ThreadsPerCore uint32
+	CoresPerSocket uint32
+	MaxCpuId uint32
+	NrCpus    uint32
+	CpuKhz    uint32
+	TotalPages         uint64
+	FreePages          uint64
+	ScrubPages         uint64
+	OutstandingPages   uint64
+	SharingFreedPages uint64
+	SharingUsedFrames uint64
+	NrNodes uint32
+	HwCap   Hwcap
+	CapHvm          bool
+	CapHvmDirectio bool
+}
+
+type VersionInfo struct {
+	XenVersionMajor int
+	XenVersionMinor int
+	XenVersionExtra string
+	Compiler          string
+	CompileBy        string
+	CompileDomain    string
+	CompileDate      string
+	Capabilities      string
+	Changeset         string
+	VirtStart        uint64
+	Pagesize          int
+	Commandline       string
+	BuildId          string
+}
+
 /*
  * Context
  */
@@ -157,3 +214,132 @@ func (Ctx *Context) CheckOpen() (err error) {
 	}
 	return
 }
+
+//int libxl_get_max_cpus(libxl_ctx *ctx);
+func (Ctx *Context) GetMaxCpus() (maxCpus int, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_get_max_cpus(Ctx.ctx)
+	if ret < 0 {
+		err = Error(-ret)
+		return
+	}
+	maxCpus = int(ret)
+	return
+}
+
+//int libxl_get_online_cpus(libxl_ctx *ctx);
+func (Ctx *Context) GetOnlineCpus() (onCpus int, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_get_online_cpus(Ctx.ctx)
+	if ret < 0 {
+		err = Error(-ret)
+		return
+	}
+	onCpus = int(ret)
+	return
+}
+
+//int libxl_get_max_nodes(libxl_ctx *ctx);
+func (Ctx *Context) GetMaxNodes() (maxNodes int, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+	ret := C.libxl_get_max_nodes(Ctx.ctx)
+	if ret < 0 {
+		err = Error(-ret)
+		return
+	}
+	maxNodes = int(ret)
+	return
+}
+
+//int libxl_get_free_memory(libxl_ctx *ctx, uint64_t *memkb);
+func (Ctx *Context) GetFreeMemory() (memkb uint64, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+	var cmem C.uint64_t
+	ret := C.libxl_get_free_memory(Ctx.ctx, &cmem)
+
+	if ret < 0 {
+		err = Error(-ret)
+		return
+	}
+
+	memkb = uint64(cmem)
+	return
+
+}
+
+//int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
+func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+	var cphys C.libxl_physinfo
+
+	ret := C.libxl_get_physinfo(Ctx.ctx, &cphys)
+
+	if ret < 0 {
+		err = Error(ret)
+		return
+	}
+	physinfo = &Physinfo{}
+	physinfo.ThreadsPerCore = uint32(cphys.threads_per_core)
+	physinfo.CoresPerSocket = uint32(cphys.cores_per_socket)
+	physinfo.MaxCpuId = uint32(cphys.max_cpu_id)
+	physinfo.NrCpus = uint32(cphys.nr_cpus)
+	physinfo.CpuKhz= uint32(cphys.cpu_khz)
+	physinfo.TotalPages = uint64(cphys.total_pages)
+	physinfo.FreePages = uint64(cphys.free_pages)
+	physinfo.ScrubPages = uint64(cphys.scrub_pages)
+	physinfo.ScrubPages = uint64(cphys.scrub_pages)
+	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.CapHvm = bool(cphys.cap_hvm)
+	physinfo.CapHvmDirectio = bool(cphys.cap_hvm_directio)
+
+	return
+}
+
+//const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx);
+func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var cinfo *C.libxl_version_info
+
+	cinfo = C.libxl_get_version_info(Ctx.ctx)
+
+	info = &VersionInfo{}
+	info.XenVersionMajor = int(cinfo.xen_version_major)
+	info.XenVersionMinor = int(cinfo.xen_version_minor)
+	info.XenVersionExtra = C.GoString(cinfo.xen_version_extra)
+	info.Compiler = C.GoString(cinfo.compiler)
+	info.CompileBy = C.GoString(cinfo.compile_by)
+	info.CompileDomain = C.GoString(cinfo.compile_domain)
+	info.CompileDate = C.GoString(cinfo.compile_date)
+	info.Capabilities = C.GoString(cinfo.capabilities)
+	info.Changeset = C.GoString(cinfo.changeset)
+	info.VirtStart = uint64(cinfo.virt_start)
+	info.Pagesize = int(cinfo.pagesize)
+	info.Commandline = C.GoString(cinfo.commandline)
+	info.BuildId = C.GoString(cinfo.build_id)
+
+	return
+}
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
  2017-01-23 16:43 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Ronald Rojas
  2017-01-23 16:43 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
@ 2017-01-23 16:43 ` Ronald Rojas
  2017-02-01 16:16   ` George Dunlap
  2017-01-23 16:43 ` [PATCH RFC 5/8] golang/xenlight: Add tests host related functinality functions Ronald Rojas
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

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>
---
 tools/golang/xenlight/xenlight.go | 92 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 92410a8..dd6893c 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -36,6 +36,7 @@ import "C"
 import (
 	"fmt"
 	"unsafe"
+	"time"
 )
 
 /*
@@ -104,6 +105,12 @@ var errors = [...]string{
  * Types: Builtins
  */
 
+type Domid uint32
+
+type MemKB uint64
+
+type Uuid C.libxl_uuid
+
 type Context struct {
 	ctx *C.libxl_ctx
 }
@@ -165,6 +172,32 @@ type VersionInfo struct {
 	BuildId          string
 }
 
+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 // FIXME shutdown_reason enumeration
+	OutstandingMemkb MemKB
+	CurrentMemkb     MemKB
+	SharedMemkb      MemKB
+	PagedMemkb       MemKB
+	MaxMemkb         MemKB
+	CpuTime          time.Duration
+	VcpuMaxId       uint32
+	VcpuOnline       uint32
+	Cpupool           uint32
+	DomainType       int32 //FIXME libxl_domain_type enumeration
+
+}
+
 /*
  * Context
  */
@@ -343,3 +376,62 @@ 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
+
+	ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi), C.uint32_t(Id))
+
+	if ret != 0 {
+		err = Error(-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.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
+}
+
+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.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH RFC 5/8] golang/xenlight: Add tests host related functinality functions
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (2 preceding siblings ...)
  2017-01-23 16:43 ` [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
@ 2017-01-23 16:43 ` Ronald Rojas
  2017-02-01 17:39   ` George Dunlap
  2017-01-23 16:43 ` [PATCH RFC 6/8] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Create tests for the following functions:
- GetVersionInfo
- GetPhysinfo
- GetDominfo
- GetMaxCpus
- GetOnlineCpus
- GetMaxNodes
- GetFreeMemory

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/golang/xenlight/test/dominfo/Makefile        | 18 ++++++++
 tools/golang/xenlight/test/dominfo/dominfo.c       | 29 +++++++++++++
 tools/golang/xenlight/test/dominfo/dominfo.go      | 48 ++++++++++++++++++++++
 tools/golang/xenlight/test/freememory/Makefile     | 19 +++++++++
 tools/golang/xenlight/test/freememory/freememory.c | 25 +++++++++++
 .../golang/xenlight/test/freememory/freememory.go  | 35 ++++++++++++++++
 tools/golang/xenlight/test/maxcpu/Makefile         | 19 +++++++++
 tools/golang/xenlight/test/maxcpu/maxcpu.c         | 21 ++++++++++
 tools/golang/xenlight/test/maxcpu/maxcpu.go        | 34 +++++++++++++++
 tools/golang/xenlight/test/maxnodes/Makefile       | 19 +++++++++
 tools/golang/xenlight/test/maxnodes/maxnodes.c     | 21 ++++++++++
 tools/golang/xenlight/test/maxnodes/maxnodes.go    | 34 +++++++++++++++
 tools/golang/xenlight/test/onlinecpu/Makefile      | 19 +++++++++
 tools/golang/xenlight/test/onlinecpu/onlinecpu.c   | 21 ++++++++++
 tools/golang/xenlight/test/onlinecpu/onlinecpu.go  | 34 +++++++++++++++
 tools/golang/xenlight/test/physinfo/Makefile       | 19 +++++++++
 tools/golang/xenlight/test/physinfo/physinfo.c     | 31 ++++++++++++++
 tools/golang/xenlight/test/physinfo/physinfo.go    | 36 ++++++++++++++++
 tools/golang/xenlight/test/versioninfo/Makefile    | 18 ++++++++
 .../golang/xenlight/test/versioninfo/versioninfo.c | 18 ++++++++
 .../xenlight/test/versioninfo/versioninfo.go       | 33 +++++++++++++++
 21 files changed, 551 insertions(+)
 create mode 100644 tools/golang/xenlight/test/dominfo/Makefile
 create mode 100644 tools/golang/xenlight/test/dominfo/dominfo.c
 create mode 100644 tools/golang/xenlight/test/dominfo/dominfo.go
 create mode 100644 tools/golang/xenlight/test/freememory/Makefile
 create mode 100644 tools/golang/xenlight/test/freememory/freememory.c
 create mode 100644 tools/golang/xenlight/test/freememory/freememory.go
 create mode 100644 tools/golang/xenlight/test/maxcpu/Makefile
 create mode 100644 tools/golang/xenlight/test/maxcpu/maxcpu.c
 create mode 100644 tools/golang/xenlight/test/maxcpu/maxcpu.go
 create mode 100644 tools/golang/xenlight/test/maxnodes/Makefile
 create mode 100644 tools/golang/xenlight/test/maxnodes/maxnodes.c
 create mode 100644 tools/golang/xenlight/test/maxnodes/maxnodes.go
 create mode 100644 tools/golang/xenlight/test/onlinecpu/Makefile
 create mode 100644 tools/golang/xenlight/test/onlinecpu/onlinecpu.c
 create mode 100644 tools/golang/xenlight/test/onlinecpu/onlinecpu.go
 create mode 100644 tools/golang/xenlight/test/physinfo/Makefile
 create mode 100644 tools/golang/xenlight/test/physinfo/physinfo.c
 create mode 100644 tools/golang/xenlight/test/physinfo/physinfo.go
 create mode 100644 tools/golang/xenlight/test/versioninfo/Makefile
 create mode 100644 tools/golang/xenlight/test/versioninfo/versioninfo.c
 create mode 100644 tools/golang/xenlight/test/versioninfo/versioninfo.go

diff --git a/tools/golang/xenlight/test/dominfo/Makefile b/tools/golang/xenlight/test/dominfo/Makefile
new file mode 100644
index 0000000..a7351cf
--- /dev/null
+++ b/tools/golang/xenlight/test/dominfo/Makefile
@@ -0,0 +1,18 @@
+
+test: clean build
+	./dominfo.out >> c.output
+	go run dominfo.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetDominfo PASSED";\
+	else \
+		echo "GetDominfo FAILED";\
+	fi\
+
+build:
+	go build -o dominfo.a dominfo.go 
+	gcc dominfo.c -lxenlight -lyajl -o dominfo.out
+
+clean:
+	rm -f *.a
+	rm -f *.out
+	rm -f *.output
diff --git a/tools/golang/xenlight/test/dominfo/dominfo.c b/tools/golang/xenlight/test/dominfo/dominfo.c
new file mode 100644
index 0000000..ebe18c3
--- /dev/null
+++ b/tools/golang/xenlight/test/dominfo/dominfo.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+char * bool_to_string(bool b);
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_dominfo info;
+    int err = libxl_domain_info(context, &info, 0);
+    if(err != 0){
+        return err;
+    }
+    
+    
+	printf("%d\n%d\n", info.domid, info.ssidref);
+	printf("%s\n%s\n%s\n%s\n%s\n%s\n", bool_to_string(info.running), bool_to_string(info.blocked ), bool_to_string(info.paused ),bool_to_string(info.shutdown ),bool_to_string(info.dying), bool_to_string(info.never_stop));
+	long cpu_time = info.cpu_time/((long)1<<35);
+	printf("%d\n%lu\n%lu\n%lu\n%lu\n%lu\n%lu\n%d\n%d\n%d\n", info.shutdown_reason, info.outstanding_memkb, info.current_memkb, info.shared_memkb, info.paged_memkb, info.max_memkb, cpu_time, info.vcpu_max_id, info.vcpu_online, info.cpupool);
+	printf("%d\n", info.domain_type);
+
+
+    libxl_ctx_free(context);
+
+}
+char * bool_to_string(bool b){
+    return b ? "true": "false";
+}
diff --git a/tools/golang/xenlight/test/dominfo/dominfo.go b/tools/golang/xenlight/test/dominfo/dominfo.go
new file mode 100644
index 0000000..e6c6a64
--- /dev/null
+++ b/tools/golang/xenlight/test/dominfo/dominfo.go
@@ -0,0 +1,48 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenproject.org/xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	info, err:= ctx.DomainInfo(0)
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	fmt.Printf("%d\n%d\n", info.Domid, info.Ssidref)
+	//fmt.Printf("%s\n", info.SsidLabel)
+	fmt.Printf("%t\n%t\n%t\n%t\n%t\n%t\n", info.Running, info.Blocked, info.Paused, info.Shutdown, info.Dying, info.NeverStop)
+	cpuTime := info.CpuTime/(1<<35)
+	fmt.Printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n", info.ShutdownReason, info.OutstandingMemkb, info.CurrentMemkb, info.SharedMemkb, info.PagedMemkb, info.MaxMemkb, cpuTime, info.VcpuMaxId, info.VcpuOnline, info.Cpupool)
+	fmt.Printf("%d\n", info.DomainType)
+
+}
+
+func replaceDomainType(n int32)(ret string){
+	switch n{
+	case -1:
+		ret = "invalid"
+	case 1:
+		ret = "hvm"
+	case 2:
+		ret = "pv"
+	}
+	return
+
+}
diff --git a/tools/golang/xenlight/test/freememory/Makefile b/tools/golang/xenlight/test/freememory/Makefile
new file mode 100644
index 0000000..9548e50
--- /dev/null
+++ b/tools/golang/xenlight/test/freememory/Makefile
@@ -0,0 +1,19 @@
+
+test: clean build
+	./func.out >> c.output
+	go run func.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetFreeMemory PASSED";\
+	else \
+		echo "GetFreeMemory FAILED"; \
+	fi\
+
+build:
+	go build -o func.a func.go
+	gcc func.c -lxenlight -lyajl -o func.out
+
+clean:
+	rm -f *.a
+	rm -f *.out
+	rm -f *.output
+
diff --git a/tools/golang/xenlight/test/freememory/freememory.c b/tools/golang/xenlight/test/freememory/freememory.c
new file mode 100644
index 0000000..9ff8444
--- /dev/null
+++ b/tools/golang/xenlight/test/freememory/freememory.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_physinfo info ;
+    int err= libxl_get_physinfo(context,&info);
+    if(err != 0){
+        return err;
+    }
+
+   uint64_t free_memory;
+    err = libxl_get_free_memory(context, &free_memory);
+    if(err < 0){
+        printf("%d\n", err);
+    }else{
+        printf("%lu\n", free_memory);
+    }
+    libxl_ctx_free(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/freememory/freememory.go b/tools/golang/xenlight/test/freememory/freememory.go
new file mode 100644
index 0000000..19501e7
--- /dev/null
+++ b/tools/golang/xenlight/test/freememory/freememory.go
@@ -0,0 +1,35 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenproject.org/xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+
+	free_memory, err := ctx.GetFreeMemory()
+	if err != nil{
+		fmt.Printf("%d\n", err)
+	}else{
+		fmt.Printf("%d\n", free_memory)
+	}
+
+}
diff --git a/tools/golang/xenlight/test/maxcpu/Makefile b/tools/golang/xenlight/test/maxcpu/Makefile
new file mode 100644
index 0000000..17aa19a
--- /dev/null
+++ b/tools/golang/xenlight/test/maxcpu/Makefile
@@ -0,0 +1,19 @@
+
+test: clean build
+	./maxcpu.out >> c.output
+	go run maxcpu.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetMaxCpu PASSED";\
+	else \
+		echo "GetMaxCpu FAILED"; \
+	fi\
+
+build:
+	go build -o maxcpu.a maxcpu.go
+	gcc maxcpu.c -lxenlight -lyajl -o maxcpu.out
+
+clean:
+	rm -f *.a
+	rm -f *.out
+	rm -f *.output
+
diff --git a/tools/golang/xenlight/test/maxcpu/maxcpu.c b/tools/golang/xenlight/test/maxcpu/maxcpu.c
new file mode 100644
index 0000000..60ef7ce
--- /dev/null
+++ b/tools/golang/xenlight/test/maxcpu/maxcpu.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_physinfo info ;
+    int err= libxl_get_physinfo(context,&info);
+    if(err != 0){
+        return err;
+    }
+
+    int max_cpus = libxl_get_max_cpus(context);
+    printf("%d\n", max_cpus);
+
+    libxl_ctx_free(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/maxcpu/maxcpu.go b/tools/golang/xenlight/test/maxcpu/maxcpu.go
new file mode 100644
index 0000000..eef575f
--- /dev/null
+++ b/tools/golang/xenlight/test/maxcpu/maxcpu.go
@@ -0,0 +1,34 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenproject.org/xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	max_cpus, err := ctx.GetMaxCpus()
+	if err != nil{
+		fmt.Printf("%d\n", err )
+	}else{
+		fmt.Printf("%d\n", max_cpus)
+	}
+
+}
diff --git a/tools/golang/xenlight/test/maxnodes/Makefile b/tools/golang/xenlight/test/maxnodes/Makefile
new file mode 100644
index 0000000..7535efe
--- /dev/null
+++ b/tools/golang/xenlight/test/maxnodes/Makefile
@@ -0,0 +1,19 @@
+
+test: clean build
+	./maxnodes.out >> c.output
+	go run maxnodes.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetMaxNodes PASSED";\
+	else \
+		echo "GetMaxNodes FAILED"; \
+	fi\
+
+build:
+	go build -o maxnodes.a maxnodes.go
+	gcc maxnodes.c -lxenlight -lyajl -o maxnodes.out
+
+clean:
+	rm -f *.a
+	rm -f *.out
+	rm -f *.output
+
diff --git a/tools/golang/xenlight/test/maxnodes/maxnodes.c b/tools/golang/xenlight/test/maxnodes/maxnodes.c
new file mode 100644
index 0000000..8f7ce9c
--- /dev/null
+++ b/tools/golang/xenlight/test/maxnodes/maxnodes.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_physinfo info ;
+    int err= libxl_get_physinfo(context,&info);
+    if(err != 0){
+        return err;
+    }
+
+    int max_nodes = libxl_get_max_nodes(context);
+    printf("%d\n", max_nodes);
+
+   libxl_ctx_free(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/maxnodes/maxnodes.go b/tools/golang/xenlight/test/maxnodes/maxnodes.go
new file mode 100644
index 0000000..5f619ff
--- /dev/null
+++ b/tools/golang/xenlight/test/maxnodes/maxnodes.go
@@ -0,0 +1,34 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenproject.org/xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	max_nodes, err := ctx.GetMaxNodes()
+	if err != nil{
+		fmt.Printf("%d\n", err)
+	}else{
+		fmt.Printf("%d\n", max_nodes)
+	}
+
+}
diff --git a/tools/golang/xenlight/test/onlinecpu/Makefile b/tools/golang/xenlight/test/onlinecpu/Makefile
new file mode 100644
index 0000000..9df2256
--- /dev/null
+++ b/tools/golang/xenlight/test/onlinecpu/Makefile
@@ -0,0 +1,19 @@
+
+test: clean build
+	./onlinecpu.out >> c.output
+	go run onlinecpu.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetOnlineCpus PASSED";\
+	else \
+		echo "GetOnline FAILED"; \
+	fi\
+
+build:
+	go build -o onlinecpu.a onlinecpu.go
+	gcc onlinecpu.c -lxenlight -lyajl -o onlinecpu.out
+
+clean:
+	rm -f *.a
+	rm -f *.out
+	rm -f *.output
+
diff --git a/tools/golang/xenlight/test/onlinecpu/onlinecpu.c b/tools/golang/xenlight/test/onlinecpu/onlinecpu.c
new file mode 100644
index 0000000..a56ff71
--- /dev/null
+++ b/tools/golang/xenlight/test/onlinecpu/onlinecpu.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_physinfo info ;
+    int err= libxl_get_physinfo(context,&info);
+    if(err != 0){
+        return err;
+    }
+
+    int online_cpus = libxl_get_online_cpus(context);
+    printf("%d\n", online_cpus);
+
+    libxl_ctx_free(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/onlinecpu/onlinecpu.go b/tools/golang/xenlight/test/onlinecpu/onlinecpu.go
new file mode 100644
index 0000000..2c4968e
--- /dev/null
+++ b/tools/golang/xenlight/test/onlinecpu/onlinecpu.go
@@ -0,0 +1,34 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenproject.org/xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	online_cpus, err := ctx.GetOnlineCpus()
+	if err != nil{
+		fmt.Printf("%d\n", err)
+	}else{
+		fmt.Printf("%d\n", online_cpus)
+	}
+
+}
diff --git a/tools/golang/xenlight/test/physinfo/Makefile b/tools/golang/xenlight/test/physinfo/Makefile
new file mode 100644
index 0000000..87fd171
--- /dev/null
+++ b/tools/golang/xenlight/test/physinfo/Makefile
@@ -0,0 +1,19 @@
+
+test: clean build
+	./physinfo.out >> c.output
+	go run physinfo.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetPhysinfo PASSED";\
+	else \
+		echo "GetPhysinfo FAILED"; \
+	fi\
+
+build:
+	go build -o physinfo.a physinfo.go 
+	gcc physinfo.c -lxenlight -lyajl -o physinfo.out
+
+clean:
+	rm -f *.a
+	rm -f *.out
+	rm -f *.output
+
diff --git a/tools/golang/xenlight/test/physinfo/physinfo.c b/tools/golang/xenlight/test/physinfo/physinfo.c
new file mode 100644
index 0000000..92c8f47
--- /dev/null
+++ b/tools/golang/xenlight/test/physinfo/physinfo.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+char *bool_to_string(bool b);
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_physinfo info ;
+    int err= libxl_get_physinfo(context,&info);
+    if(err != 0){
+        return err;
+    }
+
+    printf("%d\n%d\n%d\n%d\n%d\n", info.threads_per_core, info.cores_per_socket, info.max_cpu_id, info.nr_cpus, info.cpu_khz);
+    printf("%lu\n%lu\n%lu\n%lu\n%lu\n%lu\n", info.total_pages, info.free_pages, info.scrub_pages, info.outstanding_pages, info.sharing_freed_pages, info.sharing_used_frames);
+    printf("%u\n",info.nr_nodes);
+    printf("%s\n%s\n", bool_to_string(info.cap_hvm), bool_to_string(info.cap_hvm_directio));
+
+    for(int i = 0; i < 8; i++){
+        printf("%u\n", info.hw_cap[i]);
+    }
+
+    libxl_ctx_free(context);
+
+}
+
+char * bool_to_string(bool b){
+    return b ? "true": "false";
+}
diff --git a/tools/golang/xenlight/test/physinfo/physinfo.go b/tools/golang/xenlight/test/physinfo/physinfo.go
new file mode 100644
index 0000000..039da59
--- /dev/null
+++ b/tools/golang/xenlight/test/physinfo/physinfo.go
@@ -0,0 +1,36 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenproject.org/xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	info, err:= ctx.GetPhysinfo()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	fmt.Printf("%d\n%d\n%d\n%d\n%d\n", info.ThreadsPerCore, info.CoresPerSocket, info.MaxCpuId, info.NrCpus, info.CpuKhz)
+	fmt.Printf("%d\n%d\n%d\n%d\n%d\n%d\n", info.TotalPages, info.FreePages, info.ScrubPages, info.OutstandingPages, info.SharingFreedPages, info.SharingUsedFrames)
+	fmt.Printf("%d\n",info.NrNodes)
+	fmt.Printf("%t\n%t\n", info.CapHvm, info.CapHvmDirectio)
+
+	for i := 0; i < 8; i++ {
+	fmt.Printf("%d\n", info.HwCap[i]);
+	}
+}
diff --git a/tools/golang/xenlight/test/versioninfo/Makefile b/tools/golang/xenlight/test/versioninfo/Makefile
new file mode 100644
index 0000000..0ad1527
--- /dev/null
+++ b/tools/golang/xenlight/test/versioninfo/Makefile
@@ -0,0 +1,18 @@
+
+test: clean build
+	./versioninfo.out >> c.output
+	go run versioninfo.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetVersionInfo PASSED";\
+	else \
+		echo "GetVersionInfo FAILED"; \
+	fi\
+
+build:
+	go build -o versioninfo.a versioninfo.go 
+	gcc versioninfo.c -lxenlight -lyajl -o versioninfo.out
+
+clean:
+	rm -f *.a
+	rm -f *.out
+	rm -f *.output
diff --git a/tools/golang/xenlight/test/versioninfo/versioninfo.c b/tools/golang/xenlight/test/versioninfo/versioninfo.c
new file mode 100644
index 0000000..f40495d
--- /dev/null
+++ b/tools/golang/xenlight/test/versioninfo/versioninfo.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_version_info* info = libxl_get_version_info(context);
+
+    printf("%d\n%d\n", info->xen_version_major, info->xen_version_minor);
+    printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n", info->xen_version_extra, info->compiler, info->compile_by, info->compile_domain, info->compile_date, info->capabilities, info->changeset);
+    printf("%lu\n%d\n", info->virt_start, info->pagesize);
+    printf("%s\n%s\n", info->commandline, info->build_id);
+
+    libxl_ctx_free(context);
+
+}
diff --git a/tools/golang/xenlight/test/versioninfo/versioninfo.go b/tools/golang/xenlight/test/versioninfo/versioninfo.go
new file mode 100644
index 0000000..cad8391
--- /dev/null
+++ b/tools/golang/xenlight/test/versioninfo/versioninfo.go
@@ -0,0 +1,33 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenproject.org/xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	info, err:= ctx.GetVersionInfo()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	fmt.Printf("%d\n%d\n", info.XenVersionMajor, info.XenVersionMinor);
+	fmt.Printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n", info.XenVersionExtra, info.Compiler, info.CompileBy, info.CompileDomain, info.CompileDate, info.Capabilities, info.Changeset);
+	fmt.Printf("%d\n%d\n", info.VirtStart, info.Pagesize);
+	fmt.Printf("%s\n%s\n", info.Commandline, info.BuildId);
+
+}
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH RFC 6/8] golang/xenlight: Implement libxl_bitmap and helper operations
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (3 preceding siblings ...)
  2017-01-23 16:43 ` [PATCH RFC 5/8] golang/xenlight: Add tests host related functinality functions Ronald Rojas
@ 2017-01-23 16:43 ` Ronald Rojas
  2017-02-01 17:59   ` George Dunlap
  2017-01-23 16:43 ` [PATCH RFC 7/8] golang/xenlight: Implement libxl_scheduler enumeration Ronald Rojas
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Implement Bitmap type, along with helper functions.

The Bitmap type is implemented interllay in a way which makes it
easy to copy into and out of the C libxl_bitmap type.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/golang/xenlight/xenlight.go | 166 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 166 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index dd6893c..54692fd 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -131,6 +131,19 @@ func (chwcap C.libxl_hwcap)CToGo() (ghwcap Hwcap) {
 	return
 }
 
+// typedef struct {
+//     uint32_t size;          /* number of bytes in map */
+//     uint8_t *map;
+// } libxl_bitmap;
+
+// Implement the Go bitmap type such that the underlying data can
+// easily be copied in and out.  NB that we still have to do copies
+// both directions, because cgo runtime restrictions forbid passing to
+// a C function a pointer to a Go-allocated structure which contains a
+// pointer.
+type Bitmap struct {
+	bitmap []C.uint8_t
+}
 
 /*
  * Types: IDL
@@ -199,6 +212,159 @@ type Dominfo struct {
 }
 
 /*
+ * Bitmap operations
+ */
+
+// Return a Go bitmap which is a copy of the referred C bitmap.
+func (cbm C.libxl_bitmap) CToGo() (gbm Bitmap) {
+	// Alloc a Go slice for the bytes
+	size := int(cbm.size)
+	gbm.bitmap = make([]C.uint8_t, size)
+
+	// Make a slice pointing to the C array
+	mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
+
+	// And copy the C array into the Go array
+	copy(gbm.bitmap, mapslice)
+
+	return
+}
+
+// Must be C.libxl_bitmap_dispose'd of afterwards
+func (gbm Bitmap)GoToC() (cbm C.libxl_bitmap) {
+	C.libxl_bitmap_init(&cbm)
+
+	size := len(gbm.bitmap)
+	cbm._map = (*C.uint8_t)(C.malloc(C.size_t(size)))
+	cbm.size = C.uint32_t(size)
+	if cbm._map == nil {
+		panic("C.calloc failed!")
+	}
+
+	// Make a slice pointing to the C array
+	mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
+
+	// And copy the Go array into the C array
+	copy(mapslice, gbm.bitmap)
+
+	return
+}
+
+func (bm *Bitmap) Test(bit int) bool {
+	ubit := uint(bit)
+	if bit > bm.Max() || bm.bitmap == nil {
+		return false
+	}
+
+	return (bm.bitmap[bit/8] & (1 << (ubit & 7))) != 0
+}
+
+func (bm *Bitmap) Set(bit int) {
+	ibit := bit / 8
+	if ibit+1 > len(bm.bitmap) {
+		bm.bitmap = append(bm.bitmap, make([]C.uint8_t, ibit+1-len(bm.bitmap))...)
+	}
+
+	bm.bitmap[ibit] |= 1 << (uint(bit) & 7)
+}
+
+func (bm *Bitmap) SetRange(start int, end int) {
+	for i := start; i <= end; i++ {
+		bm.Set(i)
+	}
+}
+
+func (bm *Bitmap) Clear(bit int) {
+	ubit := uint(bit)
+	if bit > bm.Max() || bm.bitmap == nil {
+		return
+	}
+
+	bm.bitmap[bit/8] &= ^(1 << (ubit & 7))
+}
+
+func (bm *Bitmap) ClearRange(start int, end int) {
+	for i := start; i <= end; i++ {
+		bm.Clear(i)
+	}
+}
+
+func (bm *Bitmap) Max() int {
+	return len(bm.bitmap)*8 - 1
+}
+
+func (bm *Bitmap) IsEmpty() bool {
+	for i := 0; i < len(bm.bitmap); i++ {
+		if bm.bitmap[i] != 0 {
+			return false
+		}
+	}
+	return true
+}
+
+func (a Bitmap) And(b Bitmap) (c Bitmap) {
+	var max, min int
+	if len(a.bitmap) > len(b.bitmap) {
+		max = len(a.bitmap)
+		min = len(b.bitmap)
+	} else {
+		max = len(b.bitmap)
+		min = len(a.bitmap)
+	}
+	c.bitmap = make([]C.uint8_t, max)
+
+	for i := 0; i < min; i++ {
+		c.bitmap[i] = a.bitmap[i] & b.bitmap[i]
+	}
+	return
+}
+
+func (bm Bitmap) String() (s string) {
+	lastOnline := false
+	crange := false
+	printed := false
+	var i int
+	/// --x-xxxxx-x -> 2,4-8,10
+	/// --x-xxxxxxx -> 2,4-10
+	for i = 0; i <= bm.Max(); i++ {
+		if bm.Test(i) {
+			if !lastOnline {
+				// Switching offline -> online, print this cpu
+				if printed {
+					s += ","
+				}
+				s += fmt.Sprintf("%d", i)
+				printed = true
+			} else if !crange {
+				// last was online, but we're not in a range; print -
+				crange = true
+				s += "-"
+			} else {
+				// last was online, we're in a range,  nothing else to do
+			}
+			lastOnline = true
+		} else {
+			if lastOnline {
+				// Switching online->offline; do we need to end a range?
+				if crange {
+					s += fmt.Sprintf("%d", i-1)
+				}
+			}
+			lastOnline = false
+			crange = false
+		}
+	}
+	if lastOnline {
+		// Switching online->offline; do we need to end a range?
+		if crange {
+			s += fmt.Sprintf("%d", i-1)
+		}
+	}
+
+	return
+}
+
+/*
  * Context
  */
 var Ctx Context
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH RFC 7/8] golang/xenlight: Implement libxl_scheduler enumeration
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (4 preceding siblings ...)
  2017-01-23 16:43 ` [PATCH RFC 6/8] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
@ 2017-01-23 16:43 ` Ronald Rojas
  2017-02-01 18:13   ` George Dunlap
  2017-01-23 16:43 ` [PATCH RFC 8/8] golang/xenlight: Implement cpupool operations Ronald Rojas
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Include both constants and a Stringification for libxl_scheduler.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/golang/xenlight/xenlight.go | 62 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 54692fd..0990f07 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -211,6 +211,68 @@ type Dominfo struct {
 
 }
 
+// # Consistent with values defined in domctl.h
+// # Except unknown which we have made up
+// libxl_scheduler = Enumeration("scheduler", [
+//     (0, "unknown"),
+//     (4, "sedf"),
+//     (5, "credit"),
+//     (6, "credit2"),
+//     (7, "arinc653"),
+//     (8, "rtds"),
+//     ])
+type Scheduler int
+
+var (
+	SchedulerUnknown  Scheduler = C.LIBXL_SCHEDULER_UNKNOWN
+	SchedulerSedf     Scheduler = C.LIBXL_SCHEDULER_SEDF
+	SchedulerCredit   Scheduler = C.LIBXL_SCHEDULER_CREDIT
+	SchedulerCredit2  Scheduler = C.LIBXL_SCHEDULER_CREDIT2
+	SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653
+	SchedulerRTDS     Scheduler = C.LIBXL_SCHEDULER_RTDS
+)
+
+// const char *libxl_scheduler_to_string(libxl_scheduler p);
+func (s Scheduler) String() string {
+	cs := C.libxl_scheduler_to_string(C.libxl_scheduler(s))
+	// No need to free const return value
+
+	return C.GoString(cs)
+}
+
+// int libxl_scheduler_from_string(const char *s, libxl_scheduler *e);
+func (s *Scheduler) FromString(gstr string) (err error) {
+	cstr := C.CString(gstr)
+	defer C.free(unsafe.Pointer(cstr))
+
+	var cs C.libxl_scheduler
+	ret := C.libxl_scheduler_from_string(cstr, &cs)
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	*s = Scheduler(cs)
+	return
+}
+
+func SchedulerFromString(name string) (s Scheduler, err error) {
+	cname := C.CString(name)
+	defer C.free(unsafe.Pointer(cname))
+
+	var cs C.libxl_scheduler
+
+	ret := C.libxl_scheduler_from_string(cname, &cs)
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	s = Scheduler(cs)
+
+	return
+}
+
 /*
  * Bitmap operations
  */
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH RFC 8/8] golang/xenlight: Implement cpupool operations
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (5 preceding siblings ...)
  2017-01-23 16:43 ` [PATCH RFC 7/8] golang/xenlight: Implement libxl_scheduler enumeration Ronald Rojas
@ 2017-01-23 16:43 ` Ronald Rojas
  2017-01-25 16:55 ` [PATCH RFC 1/8] golang/xenlight: Create stub package Wei Liu
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-23 16:43 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Include some useful "Utility" functions:
- CpupoolFindByName
- CpupoolMakeFree

Still need to implement the following functions:
- libxl_cpupool_rename
- libxl_cpupool_cpuadd_node
- libxl_cpupool_cpuremove_node
- libxl_cpupool_movedomain

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/golang/xenlight/xenlight.go | 238 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 238 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 0990f07..c856284 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -273,6 +273,244 @@ func SchedulerFromString(name string) (s Scheduler, err error) {
 	return
 }
 
+
+// libxl_cpupoolinfo = Struct("cpupoolinfo", [
+//     ("poolid",      uint32),
+//     ("pool_name",   string),
+//     ("sched",       libxl_scheduler),
+//     ("n_dom",       uint32),
+//     ("cpumap",      libxl_bitmap)
+//     ], dir=DIR_OUT)
+
+type CpupoolInfo struct {
+	Poolid      uint32
+	PoolName    string
+	Scheduler   Scheduler
+	DomainCount int
+	Cpumap      Bitmap
+}
+
+func (cci C.libxl_cpupoolinfo)CToGo ()(gci CpupoolInfo) {
+	gci.Poolid = uint32(cci.poolid)
+	gci.PoolName = C.GoString(cci.pool_name)
+	gci.Scheduler = Scheduler(cci.sched)
+	gci.DomainCount = int(cci.n_dom)
+	gci.Cpumap = cci.cpumap.CToGo()
+
+	return
+}
+
+// libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out);
+// void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool);
+func (Ctx *Context) ListCpupool() (list []CpupoolInfo) {
+	err := Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var nbPool C.int
+
+	c_cpupool_list := C.libxl_list_cpupool(Ctx.ctx, &nbPool)
+
+	defer C.libxl_cpupoolinfo_list_free(c_cpupool_list, nbPool)
+
+	if int(nbPool) == 0 {
+		return
+	}
+
+	// Magic
+	cpupoolListSlice := (*[1 << 30]C.libxl_cpupoolinfo)(unsafe.Pointer(c_cpupool_list))[:nbPool:nbPool]
+
+	for i := range cpupoolListSlice {
+		info := cpupoolListSlice[i].CToGo()
+
+		list = append(list, info)
+	}
+
+	return
+}
+
+// int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid);
+func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool CpupoolInfo) {
+	err := Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var c_cpupool C.libxl_cpupoolinfo
+
+	ret := C.libxl_cpupool_info(Ctx.ctx, &c_cpupool, C.uint32_t(Poolid))
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+	defer C.libxl_cpupoolinfo_dispose(&c_cpupool)
+
+	pool = c_cpupool.CToGo()
+
+	return
+}
+
+// int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
+//                          libxl_scheduler sched,
+//                          libxl_bitmap cpumap, libxl_uuid *uuid,
+//                          uint32_t *poolid);
+// FIXME: uuid
+// FIXME: Setting poolid
+func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitmap) (err error, Poolid uint32) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	poolid := C.uint32_t(0)
+	name := C.CString(Name)
+	defer C.free(unsafe.Pointer(name))
+
+	// For now, just do what xl does, and make a new uuid every time we create the pool
+	var uuid C.libxl_uuid
+	C.libxl_uuid_generate(&uuid)
+
+	cbm := Cpumap.GoToC()
+	defer C.libxl_bitmap_dispose(&cbm)
+
+	ret := C.libxl_cpupool_create(Ctx.ctx, name, C.libxl_scheduler(Scheduler),
+		cbm, &uuid, &poolid)
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	Poolid = uint32(poolid)
+
+	return
+}
+
+// int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid);
+func (Ctx *Context) CpupoolDestroy(Poolid uint32) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_cpupool_destroy(Ctx.ctx, C.uint32_t(Poolid))
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	return
+}
+
+// int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu);
+func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_cpupool_cpuadd(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu))
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	return
+}
+
+// int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid,
+//                                 const libxl_bitmap *cpumap);
+func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	cbm := Cpumap.GoToC()
+	defer C.libxl_bitmap_dispose(&cbm)
+
+	ret := C.libxl_cpupool_cpuadd_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm)
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	return
+}
+
+// int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu);
+func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_cpupool_cpuremove(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu))
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	return
+}
+
+// int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid,
+//                                    const libxl_bitmap *cpumap);
+func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	cbm := Cpumap.GoToC()
+	defer C.libxl_bitmap_dispose(&cbm)
+
+	ret := C.libxl_cpupool_cpuremove_cpumap(Ctx.ctx, C.uint32_t(Poolid), &cbm)
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	return
+}
+
+// int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid);
+// int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
+// int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
+// int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid);
+
+//
+// Utility functions
+//
+func (Ctx *Context) CpupoolFindByName(name string) (info CpupoolInfo, found bool) {
+	plist := Ctx.ListCpupool()
+
+	for i := range plist {
+		if plist[i].PoolName == name {
+			found = true
+			info = plist[i]
+			return
+		}
+	}
+	return
+}
+
+func (Ctx *Context) CpupoolMakeFree(Cpumap Bitmap) (err error) {
+	plist := Ctx.ListCpupool()
+
+	for i := range plist {
+		var Intersection Bitmap
+		Intersection = Cpumap.And(plist[i].Cpumap)
+		if !Intersection.IsEmpty() {
+			err = Ctx.CpupoolCpuremoveCpumap(plist[i].Poolid, Intersection)
+			if err != nil {
+				return
+			}
+		}
+	}
+	return
+}
+
 /*
  * Bitmap operations
  */
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (6 preceding siblings ...)
  2017-01-23 16:43 ` [PATCH RFC 8/8] golang/xenlight: Implement cpupool operations Ronald Rojas
@ 2017-01-25 16:55 ` Wei Liu
  2017-01-26  8:13   ` Ronald Rojas
  2017-01-25 17:16 ` George Dunlap
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Wei Liu @ 2017-01-25 16:55 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: wei.liu2, ian.jackson, george.dunlap, xen-devel

On Mon, Jan 23, 2017 at 11:43:30AM -0500, Ronald Rojas wrote:
[...]
> +
> +subdir-distclean-firmware: .phony
> +	$(MAKE) -C firmware distclean
> +

This looks unrelated.

>  subdir-clean-debugger/gdbsx subdir-distclean-debugger/gdbsx: .phony
>  	$(MAKE) -C debugger/gdbsx clean
>  
> diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> new file mode 100644
> index 0000000..1c2a2b7
> --- /dev/null
> +++ b/tools/golang/xenlight/Makefile
> @@ -0,0 +1,31 @@
> +XEN_ROOT=$(CURDIR)/../../..
> +GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight
> +CGO_CFLAGS = -I$(DESTDIR)$(includedir)
> +CGO_LDFLAGS = -L$(DESTDIR)$(libdir) -Wl,-rpath-link=$(DESTDIR)$(libdir)
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +BINARY = xenlight.a
> +GO ?= go
> +
> +.PHONY: all
> +all: build
> +
> +.PHONY: build
> +build: xenlight.a
> +
> +.PHONY: install
> +install: build
> +	$(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC)
> +	$(INSTALL_DATA) xenlight.go $(DESTDIR)$(GOLANG_SRC)
> +
> +.PHONY: clean
> +clean:
> +	$(RM) $(BINARY)
> +
> +.PHONY: distclean
> +distclean: clean
> +
> +xenlight.a: xenlight.go
> +	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o $@ $<
> +
> +-include $(DEPS)
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> new file mode 100644
> index 0000000..f82e14e
> --- /dev/null
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -0,0 +1,86 @@
> +/*
> + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; version 2 of the
> + * License only.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */

My impression is that we prefer LGPL for libraries -- but of course it
is up to the author to decide what license to use. :-)

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (7 preceding siblings ...)
  2017-01-25 16:55 ` [PATCH RFC 1/8] golang/xenlight: Create stub package Wei Liu
@ 2017-01-25 17:16 ` George Dunlap
  2017-01-26  8:26   ` Ronald Rojas
  2017-01-26 10:44   ` Ian Jackson
  2017-01-27 11:43 ` George Dunlap
  2017-01-27 19:40 ` George Dunlap
  10 siblings, 2 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-25 17:16 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Wei Liu, Ian Jackson, xen-devel

On Mon, Jan 23, 2017 at 4:43 PM, Ronald Rojas <ronladred@gmail.com> wrote:

> +func (Ctx *Context) Open() (err error) {
> +       if Ctx.ctx != nil {
> +               return
> +       }
> +
> +       ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)

Just discovered there's a bug here (in code that I wrote obviously) --
you can't pass the last argument as nil; you have to include a logger.
Otherwise if you ever get an error you'll get a NULL dereference. :-)

I think the fastest thing to do to begin with would be to create a
"null" logger that just throws away all the data.  Then at some point
(possibly not in your internship) someone can think about what a
proper logging interface looks like.

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-25 16:55 ` [PATCH RFC 1/8] golang/xenlight: Create stub package Wei Liu
@ 2017-01-26  8:13   ` Ronald Rojas
  0 siblings, 0 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-26  8:13 UTC (permalink / raw)
  To: Wei Liu; +Cc: ian.jackson, george.dunlap, xen-devel

On Wed, Jan 25, 2017 at 04:55:38PM +0000, Wei Liu wrote:
> On Mon, Jan 23, 2017 at 11:43:30AM -0500, Ronald Rojas wrote:
> [...]
> > +
> > +subdir-distclean-firmware: .phony
> > +	$(MAKE) -C firmware distclean
> > +
> 
> This looks unrelated.

You're correct. Thanks for catching the mistake.
> 
> >  subdir-clean-debugger/gdbsx subdir-distclean-debugger/gdbsx: .phony
> >  	$(MAKE) -C debugger/gdbsx clean
> >  
> > diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> > new file mode 100644
> > index 0000000..1c2a2b7
> > --- /dev/null
> > +++ b/tools/golang/xenlight/Makefile
> > @@ -0,0 +1,31 @@
> > +XEN_ROOT=$(CURDIR)/../../..
> > +GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight
> > +CGO_CFLAGS = -I$(DESTDIR)$(includedir)
> > +CGO_LDFLAGS = -L$(DESTDIR)$(libdir) -Wl,-rpath-link=$(DESTDIR)$(libdir)
> > +include $(XEN_ROOT)/tools/Rules.mk
> > +
> > +BINARY = xenlight.a
> > +GO ?= go
> > +
> > +.PHONY: all
> > +all: build
> > +
> > +.PHONY: build
> > +build: xenlight.a
> > +
> > +.PHONY: install
> > +install: build
> > +	$(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC)
> > +	$(INSTALL_DATA) xenlight.go $(DESTDIR)$(GOLANG_SRC)
> > +
> > +.PHONY: clean
> > +clean:
> > +	$(RM) $(BINARY)
> > +
> > +.PHONY: distclean
> > +distclean: clean
> > +
> > +xenlight.a: xenlight.go
> > +	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o $@ $<
> > +
> > +-include $(DEPS)
> > diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> > new file mode 100644
> > index 0000000..f82e14e
> > --- /dev/null
> > +++ b/tools/golang/xenlight/xenlight.go
> > @@ -0,0 +1,86 @@
> > +/*
> > + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License as
> > + * published by the Free Software Foundation; version 2 of the
> > + * License only.
> > + *
> > + * This program is distributed in the hope that it will be useful, but
> > + * WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> > + * 02110-1301, USA.
> > + */
> 
> My impression is that we prefer LGPL for libraries -- but of course it
> is up to the author to decide what license to use. :-)

Why the preferance for LGPL? I'm not too familiar with the differences
between the two. 
> 
> Wei.

Thanks, 
Ronald

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-25 17:16 ` George Dunlap
@ 2017-01-26  8:26   ` Ronald Rojas
  2017-01-26 10:44   ` Ian Jackson
  1 sibling, 0 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-26  8:26 UTC (permalink / raw)
  To: George Dunlap; +Cc: Wei Liu, Ian Jackson, xen-devel

On Wed, Jan 25, 2017 at 05:16:47PM +0000, George Dunlap wrote:
> On Mon, Jan 23, 2017 at 4:43 PM, Ronald Rojas <ronladred@gmail.com> wrote:
> 
> > +func (Ctx *Context) Open() (err error) {
> > +       if Ctx.ctx != nil {
> > +               return
> > +       }
> > +
> > +       ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
> 
> Just discovered there's a bug here (in code that I wrote obviously) --
> you can't pass the last argument as nil; you have to include a logger.
> Otherwise if you ever get an error you'll get a NULL dereference. :-)
> 
> I think the fastest thing to do to begin with would be to create a
> "null" logger that just throws away all the data.  Then at some point
> (possibly not in your internship) someone can think about what a
> proper logging interface looks like.

Makes sense. I can modify the code so that it creates an instance of 
the xenlogger and prints it to /dev/null. I will add this in the next
version of the patch.
> 
>  -George

Thanks,
Ronald

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-25 17:16 ` George Dunlap
  2017-01-26  8:26   ` Ronald Rojas
@ 2017-01-26 10:44   ` Ian Jackson
  2017-01-26 11:26     ` George Dunlap
  1 sibling, 1 reply; 32+ messages in thread
From: Ian Jackson @ 2017-01-26 10:44 UTC (permalink / raw)
  To: George Dunlap; +Cc: Ronald Rojas, Wei Liu, xen-devel

George Dunlap writes ("Re: [Xen-devel] [PATCH RFC 1/8] golang/xenlight: Create stub package"):
> I think the fastest thing to do to begin with would be to create a
> "null" logger that just throws away all the data.  Then at some point
> (possibly not in your internship) someone can think about what a
> proper logging interface looks like.

Please don't just throw away all the messages.  For now, have your C
code make the stdiostream logger to send the messages to stderr.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-26 10:44   ` Ian Jackson
@ 2017-01-26 11:26     ` George Dunlap
  0 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-26 11:26 UTC (permalink / raw)
  To: Ian Jackson; +Cc: Ronald Rojas, Wei Liu, xen-devel

On 26/01/17 10:44, Ian Jackson wrote:
> George Dunlap writes ("Re: [Xen-devel] [PATCH RFC 1/8] golang/xenlight: Create stub package"):
>> I think the fastest thing to do to begin with would be to create a
>> "null" logger that just throws away all the data.  Then at some point
>> (possibly not in your internship) someone can think about what a
>> proper logging interface looks like.
> 
> Please don't just throw away all the messages.  For now, have your C
> code make the stdiostream logger to send the messages to stderr.

After I wrote this I also came to the conclusion that it would be pretty
important to have the messages available for debugging purposes.

My main concern here was that I wasn't sure how glibc's stdiostream
would interact with Go's iostream: They might have different sets of
buffers, for instance, which would cause garbled output.  But it looks
like Go by default doesn't buffer stdout/stderr; and the stdiostream
logger flushes output  after each message as well.  So using stdiostream
sounds like a good starting point (although it will need to be replaced
before we consider the library production-ready).

Ronald, you can look in tools/libxl/xl.c to see an example of how to
make an stdiostream logger to pass to libxl_ctx_alloc().

 -George



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (8 preceding siblings ...)
  2017-01-25 17:16 ` George Dunlap
@ 2017-01-27 11:43 ` George Dunlap
  2017-01-27 19:40 ` George Dunlap
  10 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-27 11:43 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, Ronald Rojas wrote:
> Create a basic Makefile to build and install libxenlight Golang
> bindings. Also add a stub package which only opens libxl context.
> 
> Include a global xenlight.Ctx variable which can be used as the
> default context by the entire program if desired.
> 
> For now, return simple errors. Proper error handling will be
> added in next patch.

So this is not true at the moment; and as a result the patch doesn't build.

As I said in response to Dario's suggestion, I think in this
chicken-and-egg situation it makes sense to just use fmt.Errorf() for
this patch, and then change them to Error(-ret) in the next patch.

> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/Makefile                    | 17 ++++++++
>  tools/golang/xenlight/Makefile    | 31 ++++++++++++++
>  tools/golang/xenlight/xenlight.go | 86 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 134 insertions(+)
>  create mode 100644 tools/golang/xenlight/Makefile
>  create mode 100644 tools/golang/xenlight/xenlight.go
> 
> diff --git a/tools/Makefile b/tools/Makefile
> index 77e0723..c1e975f 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -11,6 +11,8 @@ SUBDIRS-y += xenstore
>  SUBDIRS-y += misc
>  SUBDIRS-y += examples
>  SUBDIRS-y += hotplug
> +#Uncomment line to build Golang libxl
> +#SUBDIRS-y += golang/xenlight

This won't build from a clean tree, because at this point libxl hasn't
been built yet; and if you modify libxl and re-build, it will use the
old version of libxl rather than the new one you just modified.  It
needs to go a bit further down, under "SUBDIRS-y += libxl".

(Actually this whole list could use some reordering, but that's not your
problem.)

>  SUBDIRS-y += xentrace
>  SUBDIRS-$(CONFIG_XCUTILS) += xcutils
>  SUBDIRS-$(CONFIG_X86) += firmware
> @@ -303,6 +305,21 @@ subdir-clean-qemu-xen-dir:
>  		$(MAKE) -C qemu-xen-dir clean; \
>  	fi
>  
> +subdir-clean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight clean
> +
> +subdir-distclean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight distclean
> +
> +subdir-install-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight install
> +
> +subdir-all-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight all
> +
> +subdir-distclean-firmware: .phony
> +	$(MAKE) -C firmware distclean
> +
>  subdir-clean-debugger/gdbsx subdir-distclean-debugger/gdbsx: .phony
>  	$(MAKE) -C debugger/gdbsx clean
>  
> diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> new file mode 100644
> index 0000000..1c2a2b7
> --- /dev/null
> +++ b/tools/golang/xenlight/Makefile
> @@ -0,0 +1,31 @@
> +XEN_ROOT=$(CURDIR)/../../..
> +GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight

So GOPATH is actually like the PATH variable: you can have several
directories in it.

I think this should probably be:

GOCODEDIR ?= $(prefix)/share/cogode
GOLANG_SRC = $(GOCODEDIR)/src/xenproject.org/xenlight

Other than that, looks good -- I think with those three changes, this
patch should be ready to go in. :-)

 -George

> +CGO_CFLAGS = -I$(DESTDIR)$(includedir)
> +CGO_LDFLAGS = -L$(DESTDIR)$(libdir) -Wl,-rpath-link=$(DESTDIR)$(libdir)
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +BINARY = xenlight.a
> +GO ?= go
> +
> +.PHONY: all
> +all: build
> +
> +.PHONY: build
> +build: xenlight.a
> +
> +.PHONY: install
> +install: build
> +	$(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC)
> +	$(INSTALL_DATA) xenlight.go $(DESTDIR)$(GOLANG_SRC)
> +
> +.PHONY: clean
> +clean:
> +	$(RM) $(BINARY)
> +
> +.PHONY: distclean
> +distclean: clean
> +
> +xenlight.a: xenlight.go
> +	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o $@ $<
> +
> +-include $(DEPS)
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> new file mode 100644
> index 0000000..f82e14e
> --- /dev/null
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -0,0 +1,86 @@
> +/*
> + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; version 2 of the
> + * License only.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +package xenlight
> +
> +/*
> +#cgo LDFLAGS: -lxenlight -lyajl
> +#include <stdlib.h>
> +#include <libxl.h>
> +*/
> +import "C"
> +
> +/*
> + * Other flags that may be needed at some point:
> + *  -lnl-route-3 -lnl-3
> + *
> + * To get back to static linking:
> + * #cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil
> +*/
> +
> +import (
> +	"fmt"
> +	"unsafe"
> +)
> +
> +
> +/*
> + * Types: Builtins
> + */
> +type Context struct {
> +	ctx *C.libxl_ctx
> +}
> +
> +/*
> + * Context
> + */
> +var Ctx Context
> +
> +func (Ctx *Context) IsOpen() bool {
> +	return Ctx.ctx != nil
> +}
> +
> +func (Ctx *Context) Open() (err error) {
> +	if Ctx.ctx != nil {
> +		return
> +	}
> +
> +	ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
> +
> +	if ret != 0 {
> +		err = Error(-ret)
> +	}
> +	return
> +}
> +
> +func (Ctx *Context) Close() (err error) {
> +	ret := C.libxl_ctx_free(unsafe.Pointer(Ctx.ctx))
> +	Ctx.ctx = nil
> +
> +	if ret != 0 {
> +		err = Error(-ret)
> +	}
> +	return
> +}
> +
> +func (Ctx *Context) CheckOpen() (err error) {
> +	if Ctx.ctx == nil {
> +		err = fmt.Errorf("Context not opened")
> +	}
> +	return
> +}
> \ No newline at end of file
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling
  2017-01-23 16:43 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Ronald Rojas
@ 2017-01-27 12:22   ` George Dunlap
  0 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-27 12:22 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, Ronald Rojas wrote:
> Create error type Errorxl for throwing proper xenlight
> errors.
> 
> Update Ctx functions to throw Errorxl errors.
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>

Everything here looks, good with a few nitpicks...

> ---
>  tools/golang/xenlight/xenlight.go | 75 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 74 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index f82e14e..eee2254 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -38,10 +38,72 @@ import (
>  	"unsafe"
>  )
>  
> +/*
> + * Errors
> + */
> +
> +type Error int
> +
> +const (
> +	ErrorNonspecific                  = Error(-C.ERROR_NONSPECIFIC)
> +	ErrorVersion                      = Error(-C.ERROR_VERSION)
> +	ErrorFail                         = Error(-C.ERROR_FAIL)
> +	ErrorNi                           = Error(-C.ERROR_NI)
> +	ErrorNomem                        = Error(-C.ERROR_NOMEM)
> +	ErrorInval                        = Error(-C.ERROR_INVAL)
> +	ErrorBadfail                      = Error(-C.ERROR_BADFAIL)
> +	ErrorGuestTimedout                = Error(-C.ERROR_GUEST_TIMEDOUT)
> +	ErrorTimedout                     = Error(-C.ERROR_TIMEDOUT)
> +	ErrorNoparavirt                   = Error(-C.ERROR_NOPARAVIRT)
> +	ErrorNotReady                     = Error(-C.ERROR_NOT_READY)
> +	ErrorOseventRegFail               = Error(-C.ERROR_OSEVENT_REG_FAIL)
> +	ErrorBufferfull                   = Error(-C.ERROR_BUFFERFULL)
> +	ErrorUnknownChild                 = Error(-C.ERROR_UNKNOWN_CHILD)
> +	ErrorLockFail                     = Error(-C.ERROR_LOCK_FAIL)
> +	ErrorJsonConfigEmpty              = Error(-C.ERROR_JSON_CONFIG_EMPTY)
> +	ErrorDeviceExists                 = Error(-C.ERROR_DEVICE_EXISTS)
> +	ErrorCheckpointDevopsDoesNotMatch = Error(-C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH)
> +	ErrorCheckpointDeviceNotSupported = Error(-C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED)
> +	ErrorVnumaConfigInvalid           = Error(-C.ERROR_VNUMA_CONFIG_INVALID)
> +	ErrorDomainNotfound               = Error(-C.ERROR_DOMAIN_NOTFOUND)
> +	ErrorAborted                      = Error(-C.ERROR_ABORTED)
> +	ErrorNotfound                     = Error(-C.ERROR_NOTFOUND)
> +	ErrorDomainDestroyed              = Error(-C.ERROR_DOMAIN_DESTROYED)
> +	ErrorFeatureRemoved               = Error(-C.ERROR_FEATURE_REMOVED)
> +)
> +
> +var errors = [...]string{
> +	ErrorNonspecific: "Non-specific error",
> +	ErrorVersion: "Wrong version",
> +	ErrorFail: "Failed",
> +	ErrorNi: "Not Implemented",
> +	ErrorNomem: "No memory",
> +	ErrorInval: "Invalid argument",
> +	ErrorBadfail: "Bad Fail",
> +	ErrorGuestTimedout: "Guest timed out",
> +	ErrorTimedout: "Timed out",
> +	ErrorNoparavirt: "No Paravirtualization",
> +	ErrorNotReady: "Not ready",
> +	ErrorOseventRegFail: "OS event registration failed",
> +	ErrorBufferfull: "Buffer full",
> +	ErrorUnknownChild: "Unknown child",
> +	ErrorLockFail: "Lock failed",
> +	ErrorJsonConfigEmpty: "JSON config empty",
> +	ErrorDeviceExists: "Device exists",
> +	ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match",
> +	ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported",
> +	ErrorVnumaConfigInvalid: "VNUMA config invalid",
> +	ErrorDomainNotfound: "Domain not found",
> +	ErrorAborted: "Aborted",
> +	ErrorNotfound: "Not found",
> +	ErrorDomainDestroyed: "Domain destroyed",
> +	ErrorFeatureRemoved: "Feature removed",
> +}
>  
>  /*
>   * Types: Builtins
>   */
> +
>  type Context struct {
>  	ctx *C.libxl_ctx
>  }
> @@ -51,6 +113,17 @@ type Context struct {
>   */
>  var Ctx Context
>  
> +func (e Error) Error() string{
> +	if 0< int(e) && int(e) < len(errors){
> +		s:= errors[e]
> +		if s != ""{

We tend to be picky about style; so a spaces:
 - Between 0 and <
 - between len(errors) and {
 - between "" and {

I could fix these up on check-in, but since you'll be re-sending this
anyway, I'll let you do it.

And of course you'll have to change the fmt.Errorf() to Error(-ret); but
with those changes:

Reviewed-by: George Dunlap <george.dunlap@citrix.com>



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
                   ` (9 preceding siblings ...)
  2017-01-27 11:43 ` George Dunlap
@ 2017-01-27 19:40 ` George Dunlap
  10 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-27 19:40 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

[-- Attachment #1: Type: text/plain, Size: 5650 bytes --]

On 23/01/17 16:43, Ronald Rojas wrote:
> Create a basic Makefile to build and install libxenlight Golang
> bindings. Also add a stub package which only opens libxl context.
> 
> Include a global xenlight.Ctx variable which can be used as the
> default context by the entire program if desired.
> 
> For now, return simple errors. Proper error handling will be
> added in next patch.
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>

Actually, I've done a pretty big re-work of how the makefiles work, to
make sure that we can always be using stuff that is only in-tree, and
not anything that is in our outside environment.

Attached is the result.  Once we have this, then in your test makefiles
can look like this:

dominfo-go: dominfo.go
	GOPATH=$(XEN_GOPATH) $(GO) build -o $@ $<

And that will use the current in-tree version of the xenlight package.

You can probably tell I've got some comments on your testing patch as
well, but that will have to wait until Monday. :-)

Let me know what you think.

Peace,
 -George

> ---
>  tools/Makefile                    | 17 ++++++++
>  tools/golang/xenlight/Makefile    | 31 ++++++++++++++
>  tools/golang/xenlight/xenlight.go | 86 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 134 insertions(+)
>  create mode 100644 tools/golang/xenlight/Makefile
>  create mode 100644 tools/golang/xenlight/xenlight.go
> 
> diff --git a/tools/Makefile b/tools/Makefile
> index 77e0723..c1e975f 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -11,6 +11,8 @@ SUBDIRS-y += xenstore
>  SUBDIRS-y += misc
>  SUBDIRS-y += examples
>  SUBDIRS-y += hotplug
> +#Uncomment line to build Golang libxl
> +#SUBDIRS-y += golang/xenlight
>  SUBDIRS-y += xentrace
>  SUBDIRS-$(CONFIG_XCUTILS) += xcutils
>  SUBDIRS-$(CONFIG_X86) += firmware
> @@ -303,6 +305,21 @@ subdir-clean-qemu-xen-dir:
>  		$(MAKE) -C qemu-xen-dir clean; \
>  	fi
>  
> +subdir-clean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight clean
> +
> +subdir-distclean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight distclean
> +
> +subdir-install-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight install
> +
> +subdir-all-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight all
> +
> +subdir-distclean-firmware: .phony
> +	$(MAKE) -C firmware distclean
> +
>  subdir-clean-debugger/gdbsx subdir-distclean-debugger/gdbsx: .phony
>  	$(MAKE) -C debugger/gdbsx clean
>  
> diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> new file mode 100644
> index 0000000..1c2a2b7
> --- /dev/null
> +++ b/tools/golang/xenlight/Makefile
> @@ -0,0 +1,31 @@
> +XEN_ROOT=$(CURDIR)/../../..
> +GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight
> +CGO_CFLAGS = -I$(DESTDIR)$(includedir)
> +CGO_LDFLAGS = -L$(DESTDIR)$(libdir) -Wl,-rpath-link=$(DESTDIR)$(libdir)
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +BINARY = xenlight.a
> +GO ?= go
> +
> +.PHONY: all
> +all: build
> +
> +.PHONY: build
> +build: xenlight.a
> +
> +.PHONY: install
> +install: build
> +	$(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC)
> +	$(INSTALL_DATA) xenlight.go $(DESTDIR)$(GOLANG_SRC)
> +
> +.PHONY: clean
> +clean:
> +	$(RM) $(BINARY)
> +
> +.PHONY: distclean
> +distclean: clean
> +
> +xenlight.a: xenlight.go
> +	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o $@ $<
> +
> +-include $(DEPS)
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> new file mode 100644
> index 0000000..f82e14e
> --- /dev/null
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -0,0 +1,86 @@
> +/*
> + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; version 2 of the
> + * License only.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +package xenlight
> +
> +/*
> +#cgo LDFLAGS: -lxenlight -lyajl
> +#include <stdlib.h>
> +#include <libxl.h>
> +*/
> +import "C"
> +
> +/*
> + * Other flags that may be needed at some point:
> + *  -lnl-route-3 -lnl-3
> + *
> + * To get back to static linking:
> + * #cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil
> +*/
> +
> +import (
> +	"fmt"
> +	"unsafe"
> +)
> +
> +
> +/*
> + * Types: Builtins
> + */
> +type Context struct {
> +	ctx *C.libxl_ctx
> +}
> +
> +/*
> + * Context
> + */
> +var Ctx Context
> +
> +func (Ctx *Context) IsOpen() bool {
> +	return Ctx.ctx != nil
> +}
> +
> +func (Ctx *Context) Open() (err error) {
> +	if Ctx.ctx != nil {
> +		return
> +	}
> +
> +	ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
> +
> +	if ret != 0 {
> +		err = Error(-ret)
> +	}
> +	return
> +}
> +
> +func (Ctx *Context) Close() (err error) {
> +	ret := C.libxl_ctx_free(unsafe.Pointer(Ctx.ctx))
> +	Ctx.ctx = nil
> +
> +	if ret != 0 {
> +		err = Error(-ret)
> +	}
> +	return
> +}
> +
> +func (Ctx *Context) CheckOpen() (err error) {
> +	if Ctx.ctx == nil {
> +		err = fmt.Errorf("Context not opened")
> +	}
> +	return
> +}
> \ No newline at end of file
> 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-golang-xenlight-Create-stub-package.patch --]
[-- Type: text/x-diff; name="0001-golang-xenlight-Create-stub-package.patch", Size: 7837 bytes --]

From 1756fdbdf6abf8ce9b7c83722cc4f91709e93756 Mon Sep 17 00:00:00 2001
From: Ronald Rojas <ronladred@gmail.com>
Date: Mon, 23 Jan 2017 11:43:30 -0500
Subject: [PATCH] golang/xenlight: Create stub package

Create a basic Makefile to build and install libxenlight Golang
bindings. Also add a stub package which only opens libxl context.

Include a global xenlight.Ctx variable which can be used as the
default context by the entire program if desired.

For now, return simple errors. Proper error handling will be
added in next patch.

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
---
Changes:

- Moved manual-enable config option to tools/Rules.mk, use
  CONFIG_GOLANG in tools/Makefile

- Added XEN_GOPATH, pointing to tools/golang

- Modified tools/golang/xenlight makefile to construct necessary $GOPATH

- Added tools/golang/Makefile, so we don't need special rules in tools
  to make tools/golang/xenlight; and so we have a single place to remove the
  $GOPATH build side-effects ($GOPATH/src and $GOPATH/pkg)

- Build of tools/golang/xenlight sets $GOPATH and does a 'go install'

- Use tree-provided CFLAGS_libxenlight and LDLIBS_libxenlight, rather
  than hard-coding our own

- Made a PKGSOURCES variable to track dependencies of all target files
  which need to be part of the output package (i.e., what's put in
  $GOPATH/src).  At the moment this is one file, but it will probably
  be more once we start using the IDL.
---
 tools/Makefile                    |  1 +
 tools/Rules.mk                    |  6 +++
 tools/golang/Makefile             | 27 ++++++++++++
 tools/golang/xenlight/Makefile    | 49 ++++++++++++++++++++++
 tools/golang/xenlight/xenlight.go | 86 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 169 insertions(+)
 create mode 100644 tools/golang/Makefile
 create mode 100644 tools/golang/xenlight/Makefile
 create mode 100644 tools/golang/xenlight/xenlight.go

diff --git a/tools/Makefile b/tools/Makefile
index 77e0723..df1fda1 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -31,6 +31,7 @@ endif
 
 SUBDIRS-y += xenpmd
 SUBDIRS-y += libxl
+SUBDIRS-$(CONFIG_GOLANG) += golang
 SUBDIRS-y += helpers
 SUBDIRS-$(CONFIG_X86) += xenpaging
 SUBDIRS-$(CONFIG_X86) += debugger/gdbsx
diff --git a/tools/Rules.mk b/tools/Rules.mk
index b35999b..24e5220 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -30,6 +30,12 @@ XENSTORE_XENSTORED ?= y
 debug ?= y
 debug_symbols ?= $(debug)
 
+# Uncomment to compile with Go
+CONFIG_GOLANG ?= y
+ifeq ($(CONFIG_GOLANG),y)
+XEN_GOPATH        = $(XEN_ROOT)/tools/golang
+endif
+
 ifeq ($(debug_symbols),y)
 CFLAGS += -g3
 endif
diff --git a/tools/golang/Makefile b/tools/golang/Makefile
new file mode 100644
index 0000000..47a9235
--- /dev/null
+++ b/tools/golang/Makefile
@@ -0,0 +1,27 @@
+XEN_ROOT=$(CURDIR)/../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+# In order to link against a package in Go, the package must live in a
+# directory tree in the way that Go expects.  To make this possible,
+# there must be a directory such that we can set GOPATH=${dir}, and
+# the package will be under $GOPATH/src/${full-package-path}.
+
+# So we set XEN_GOPATH to $XEN_ROOT/tools/golang.  The xenlight
+# "package build" directory ($PWD/xenlight) will create the "package
+# source" directory in the proper place.  Go programs can use this
+# package by setting GOPATH=$(XEN_GOPATH).
+
+SUBDIRS-y = xenlight
+
+.PHONY: build all
+all build: subdirs-all
+
+.PHONY: install
+install: subdirs-install
+
+.PHONY: clean
+clean: subdirs-clean
+	$(RM) -r src pkg
+
+.PHONY: distclean
+distclean: clean
diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
new file mode 100644
index 0000000..5d578f3
--- /dev/null
+++ b/tools/golang/xenlight/Makefile
@@ -0,0 +1,49 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+# Standing boldly against convention, we insist on installing the
+# package source under $(prefix)/share/gocode
+GOCODE_DIR ?= $(prefix)/share/gocode/
+GOXL_PKG_DIR = /src/xenproject.org/xenlight/
+GOXL_INSTALL_DIR = $(GOCODE_DIR)$(GOXL_PKG_DIR)
+
+# PKGSOURCES: Files which comprise the distributed source package
+PKGSOURCES = xenlight.go
+
+GO ?= go
+
+.PHONY: all
+all: build
+
+.PHONY: package
+package: $(XEN_GOPATH)$(GOXL_PKG_DIR)$(PKGSOURCES)
+
+$(XEN_GOPATH)/src/xenproject.org/xenlight/$(PKGSOURCES): $(PKGSOURCES)
+	$(INSTALL_DIR) $(XEN_GOPATH)$(GOXL_PKG_DIR)
+	$(INSTALL_DATA) $(PKGSOURCES) $(XEN_GOPATH)$(GOXL_PKG_DIR)
+
+# Go will do its own dependency checking, and not actuall go through
+# with the build if none of the input files have changed.
+#
+# NB that because the users of this library need to be able to
+# recompile the library from source, it needs to include '-lxenlight'
+# in the LDFLAGS; and thus we need to add -L$(XEN_XENLIGHT) here
+# so that it can find the actual library.
+.PHONY: build
+build: package
+	CGO_CFLAGS="$(CFLAGS_libxenlight)" CGO_LDFLAGS="$(LDLIBS_libxenlight) -L$(XEN_XENLIGHT)" GOPATH=$(XEN_GOPATH) $(GO) install -x xenproject.org/xenlight
+
+.PHONY: install
+install: build
+	$(INSTALL_DIR) $(DESTDIR)$(GOXL_INSTALL_DIR)
+	$(INSTALL_DATA) $(XEN_GOPATH)$(GOXL_PKG_DIR)$(PKGSOURCES) $(DESTDIR)$(GOXL_INSTALL_DIR)
+
+.PHONY: clean
+clean:
+	$(RM) -r $(XEN_GOPATH)$(GOXL_PKG_DIR)
+	$(RM) $(XEN_GOPATH)/pkg/*/xenproject.org/xenlight.a
+
+.PHONY: distclean
+distclean: clean
+
+-include $(DEPS)
diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
new file mode 100644
index 0000000..9199e3d
--- /dev/null
+++ b/tools/golang/xenlight/xenlight.go
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of the
+ * License only.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+package xenlight
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+
+/*
+ * Other flags that may be needed at some point:
+ *  -lnl-route-3 -lnl-3
+ *
+ * To get back to static linking:
+ * #cgo LDFLAGS: -lxenlight -lyajl_s -lxengnttab -lxenstore -lxenguest -lxentoollog -lxenevtchn -lxenctrl -lblktapctl -lxenforeignmemory -lxencall -lz -luuid -lutil
+*/
+
+import (
+	"fmt"
+	"unsafe"
+)
+
+
+/*
+ * Types: Builtins
+ */
+type Context struct {
+	ctx *C.libxl_ctx
+}
+
+/*
+ * Context
+ */
+var Ctx Context
+
+func (Ctx *Context) IsOpen() bool {
+	return Ctx.ctx != nil
+}
+
+func (Ctx *Context) Open() (err error) {
+	if Ctx.ctx != nil {
+		return
+	}
+
+	ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
+
+	if ret != 0 {
+		err = fmt.Errorf("Error: %d", -ret)
+	}
+	return
+}
+
+func (Ctx *Context) Close() (err error) {
+	ret := C.libxl_ctx_free(unsafe.Pointer(Ctx.ctx))
+	Ctx.ctx = nil
+
+	if ret != 0 {
+		err = fmt.Errorf("Error: %d", -ret)
+	}
+	return
+}
+
+func (Ctx *Context) CheckOpen() (err error) {
+	if Ctx.ctx == nil {
+		err = fmt.Errorf("Context not opened")
+	}
+	return
+}
-- 
2.1.4


[-- Attachment #3: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 3/8] golang/xenlight: Add host-related functionality
  2017-01-23 16:43 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
@ 2017-02-01 15:53   ` George Dunlap
  2017-02-01 15:58   ` George Dunlap
  2017-02-01 16:05   ` George Dunlap
  2 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-02-01 15:53 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, Ronald Rojas wrote:
> Add calls for the following host-related functionality:
> - libxl_get_max_cpus
> - libxl_get_online_cpus
> - libxl_get_max_nodes
> - libxl_get_free_memory
> - libxl_get_physinfo
> - libxl_get_version_info
> 
> Include Golang versions of the following structs:
> - libxl_physinfo as Physinfo
> - libxl_version_info as VersionInfo
> - libxl_hwcap as Hwcap
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>

Mostly looks good!  One final comment:

[snip]
> +//int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
> +func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) {
> +	err = Ctx.CheckOpen()
> +	if err != nil {
> +		return
> +	}
> +	var cphys C.libxl_physinfo
> +
> +	ret := C.libxl_get_physinfo(Ctx.ctx, &cphys)

So I actually forgot that you're actually supposed to always call
"libxl_<type>_init()" on IDL-generated types before using them, and
"libxl_<type>_dispose()" when you're done with them.  As it happens in
this case, the struct contains no pointers to sub-structs; but if that
changes in the future, this would leak the memory.

Everything else is good, thanks.

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 3/8] golang/xenlight: Add host-related functionality
  2017-01-23 16:43 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
  2017-02-01 15:53   ` George Dunlap
@ 2017-02-01 15:58   ` George Dunlap
  2017-02-01 16:05   ` George Dunlap
  2 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-02-01 15:58 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, Ronald Rojas wrote:
> Add calls for the following host-related functionality:
> - libxl_get_max_cpus
> - libxl_get_online_cpus
> - libxl_get_max_nodes
> - libxl_get_free_memory
> - libxl_get_physinfo
> - libxl_get_version_info
> 
> Include Golang versions of the following structs:
> - libxl_physinfo as Physinfo
> - libxl_version_info as VersionInfo
> - libxl_hwcap as Hwcap
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>

Oh, last thing: It's probably worth running "go fmt xenlight.go" for
each patch.  That will catch little things like lack of spaces between
things, and aligning the structures nicely.

 -George


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 3/8] golang/xenlight: Add host-related functionality
  2017-01-23 16:43 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
  2017-02-01 15:53   ` George Dunlap
  2017-02-01 15:58   ` George Dunlap
@ 2017-02-01 16:05   ` George Dunlap
  2 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-02-01 16:05 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, Ronald Rojas wrote:
> Add calls for the following host-related functionality:
> - libxl_get_max_cpus
> - libxl_get_online_cpus
> - libxl_get_max_nodes
> - libxl_get_free_memory
> - libxl_get_physinfo
> - libxl_get_version_info
> 
> Include Golang versions of the following structs:
> - libxl_physinfo as Physinfo
> - libxl_version_info as VersionInfo
> - libxl_hwcap as Hwcap
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/golang/xenlight/xenlight.go | 186 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 186 insertions(+)
> 
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index eee2254..92410a8 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -108,6 +108,63 @@ type Context struct {
>  	ctx *C.libxl_ctx
>  }
>  
> +type Hwcap []C.uint32_t
> +
> +func (chwcap C.libxl_hwcap)CToGo() (ghwcap Hwcap) {

Sorry... I'm coming back to this after a bit of time and remembering a
bunch of things as I'm going along.

I don't think we want this method to be available publicly, so this
should probably be 'cToGo' (Or perhaps just 'toGo', since it's already a
C structure.)

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
  2017-01-23 16:43 ` [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
@ 2017-02-01 16:16   ` George Dunlap
  0 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-02-01 16:16 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, 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@citrix.com>
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/golang/xenlight/xenlight.go | 92 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 92 insertions(+)
> 
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index 92410a8..dd6893c 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -36,6 +36,7 @@ import "C"
>  import (
>  	"fmt"
>  	"unsafe"
> +	"time"
>  )
>  
>  /*
> @@ -104,6 +105,12 @@ var errors = [...]string{
>   * Types: Builtins
>   */
>  
> +type Domid uint32
> +
> +type MemKB uint64
> +
> +type Uuid C.libxl_uuid
> +
>  type Context struct {
>  	ctx *C.libxl_ctx
>  }
> @@ -165,6 +172,32 @@ type VersionInfo struct {
>  	BuildId          string
>  }
>  
> +type Dominfo struct {
> +	Uuid       Uuid
> +	Domid      Domid
> +	Ssidref uint32
> +	SsidLabel string
> +	Running    bool
> +	Blocked    bool
> +	Paused     bool
> +	Shutdown   bool
> +	Dying      bool
> +	NeverStop bool

Run 'go fmt' to align these.

> +
> +	ShutdownReason   int32 // FIXME shutdown_reason enumeration
> +	OutstandingMemkb MemKB
> +	CurrentMemkb     MemKB
> +	SharedMemkb      MemKB
> +	PagedMemkb       MemKB
> +	MaxMemkb         MemKB
> +	CpuTime          time.Duration
> +	VcpuMaxId       uint32
> +	VcpuOnline       uint32
> +	Cpupool           uint32
> +	DomainType       int32 //FIXME libxl_domain_type enumeration

We need to have these enumerations actually created as consts, like we
do with the errors.

We should also make a type for these enums, and a String method that
calls the libxl_<type>_to_string() function to convert it to a string.

> +
> +}
> +
>  /*
>   * Context
>   */
> @@ -343,3 +376,62 @@ 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
> +
> +	ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi), C.uint32_t(Id))
> +
> +	if ret != 0 {
> +		err = Error(-ret)
> +		return
> +	}
> +
> +	// We could consider having this boilerplate generated by the
> +	// idl, in a function like this:
> +	//
> +	// di = translateCdomaininfoToGoDomaininfo(cdi)

Stale comment; you could remove this, or make it cdi.toGo().

> +	di = &Dominfo{}
> +	di.Uuid = Uuid(cdi.uuid)
> +	di.Domid = Domid(cdi.domid)
> +	di.Ssidref = uint32(cdi.ssidref)
> +	di.SsidLabel = C.GoString(cdi.ssid_label)

And here we'll probably leak memory if we don't call
libxl_dominfo_dispose() before returning.

Everything else looks good, thanks!

 -George


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 5/8] golang/xenlight: Add tests host related functinality functions
  2017-01-23 16:43 ` [PATCH RFC 5/8] golang/xenlight: Add tests host related functinality functions Ronald Rojas
@ 2017-02-01 17:39   ` George Dunlap
  0 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-02-01 17:39 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

[-- Attachment #1: Type: text/plain, Size: 9161 bytes --]

On 23/01/17 16:43, Ronald Rojas wrote:
> Create tests for the following functions:
> - GetVersionInfo
> - GetPhysinfo
> - GetDominfo
> - GetMaxCpus
> - GetOnlineCpus
> - GetMaxNodes
> - GetFreeMemory
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>

Hey Ronald,

Sorry this has taken a long time to get to.  I think building the test
cases has been really good for testing out the package *as a package*;
and I think the general approach is a really good one.

One big comment first: Rather than having a separate makefile for each
of these, what about putting all the tests of a similar type -- like
these, which are primarily comparing the output of the functions -- in
the same directory, and using a makefile like the attached?  (You may
have to modify the XEN_ROOT variable at the top to reflect where you end
up putting it.)

Then, as promised, a whole slew of nitpicks.

Quick heads-up: It's easy the first time you have your code nitpicked
like this to hear an angry or annoyed "tone", because the comments are
really short.  That's not what's intended; it's just to save time.

> diff --git a/tools/golang/xenlight/test/dominfo/dominfo.c b/tools/golang/xenlight/test/dominfo/dominfo.c
> new file mode 100644
> index 0000000..ebe18c3
> --- /dev/null
> +++ b/tools/golang/xenlight/test/dominfo/dominfo.c
> @@ -0,0 +1,29 @@
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <libxl.h>
> +
> +char * bool_to_string(bool b);

Need a newline here.  And I suspect you'll be using this function again
-- maybe you could put it in a .h file as a static inline?

> +int main(){
> +
> +    libxl_ctx *context;
> +    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
> +    libxl_dominfo info;
> +    int err = libxl_domain_info(context, &info, 0);

In the Xen tools style you normally declare all the variables together
at the top of the function, and then put a newline between them.  It's
probably a good idea to read tools/libxl/CODING_STYLE, particularly the
"Formating and naming" section.

Also don't forget to call libxl_dominfo_init(&info) (which will set some
defaults).

> +    if(err != 0){
> +        return err;
> +    }

The tools style says there should be spaces around the parentheses, and
that single-line blocks don't need braces; i.e.:

if (err != 0)
    return err;

> +	printf("%d\n%d\n", info.domid, info.ssidref);
> +	printf("%s\n%s\n%s\n%s\n%s\n%s\n", bool_to_string(info.running), bool_to_string(info.blocked ), bool_to_string(info.paused ),bool_to_string(info.shutdown ),bool_to_string(info.dying), bool_to_string(info.never_stop));
> +	long cpu_time = info.cpu_time/((long)1<<35);

Why are we clipping this value?

> +	printf("%d\n%lu\n%lu\n%lu\n%lu\n%lu\n%lu\n%d\n%d\n%d\n", info.shutdown_reason, info.outstanding_memkb, info.current_memkb, info.shared_memkb, info.paged_memkb, info.max_memkb, cpu_time, info.vcpu_max_id, info.vcpu_online, info.cpupool);
> +	printf("%d\n", info.domain_type);

These lines need to be wrapped to 80 columns or less.

> +
> +
> +    libxl_ctx_free(context);
> +
> +}
> +char * bool_to_string(bool b){
> +    return b ? "true": "false";
> +}
> diff --git a/tools/golang/xenlight/test/dominfo/dominfo.go b/tools/golang/xenlight/test/dominfo/dominfo.go
> new file mode 100644
> index 0000000..e6c6a64
> --- /dev/null
> +++ b/tools/golang/xenlight/test/dominfo/dominfo.go
> @@ -0,0 +1,48 @@
> +
> +package main
> +
> +/*
> +#cgo LDFLAGS: -lxenlight -lyajl
> +#include <stdlib.h>
> +#include <libxl.h>
> +*/
> +import "C"

This stanza isn't necessary -- all that should be hidden behind the
package.  (Same for all the other .go files.)

> +import (
> +	"fmt"
> +	"xenproject.org/xenlight"
> +	"os"
> +)
> +
> +func main() {
> +	ctx := xenlight.Ctx

I think this should probably be "var ctx Xenlight.Context".  Copying a
struct which has a pointer in it is usually a bad idea; if you're going
to use your own copy, you should just use your own copy. :-)  (Same for
all the other files.)

I also think we want a newline here.

> +	err := ctx.Open()
> +	if err != nil{

Run 'go fmt' to put spaces where they need to be.  (Same for all the
other files.)

> +		os.Exit(-1)
> +	}
> +	defer ctx.Close()

Newline.

> +	info, err:= ctx.DomainInfo(0)
> +	if err != nil{
> +		os.Exit(-1)
> +	}
> +
> +	fmt.Printf("%d\n%d\n", info.Domid, info.Ssidref)
> +	//fmt.Printf("%s\n", info.SsidLabel)

Why are we not printing this (both here and in the .c file)?

> +	fmt.Printf("%t\n%t\n%t\n%t\n%t\n%t\n", info.Running, info.Blocked, info.Paused, info.Shutdown, info.Dying, info.NeverStop)

These lines should be wrapped to 80 characters.

> +	cpuTime := info.CpuTime/(1<<35)
> +	fmt.Printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n", info.ShutdownReason, info.OutstandingMemkb, info.CurrentMemkb, info.SharedMemkb, info.PagedMemkb, info.MaxMemkb, cpuTime, info.VcpuMaxId, info.VcpuOnline, info.Cpupool)
> +	fmt.Printf("%d\n", info.DomainType)
> +
> +}
> +
> +func replaceDomainType(n int32)(ret string){
> +	switch n{
> +	case -1:
> +		ret = "invalid"
> +	case 1:
> +		ret = "hvm"
> +	case 2:
> +		ret = "pv"
> +	}
> +	return

You're not using this function; it should be removed.

But if you implement the xenlight.DomainType enum in the previous patch,
and the String() method which calls libxl_domain_type_to_string(), you
can use "%v" to print the value of DomainType here.  (Of course you'll
need to call libxl_domain_type_to_string() in the .c file too.)

> diff --git a/tools/golang/xenlight/test/freememory/freememory.c b/tools/golang/xenlight/test/freememory/freememory.c
> new file mode 100644
> index 0000000..9ff8444
> --- /dev/null
> +++ b/tools/golang/xenlight/test/freememory/freememory.c
> @@ -0,0 +1,25 @@
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <libxl.h>
> +
> +int main(){
> +
> +    libxl_ctx *context;
> +    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
> +    libxl_physinfo info ;
> +    int err= libxl_get_physinfo(context,&info);
> +    if(err != 0){
> +        return err;
> +    }

I don't think you actually want to call physinfo here. :-)  (Same for
the other files.)

> +
> +   uint64_t free_memory;
> +    err = libxl_get_free_memory(context, &free_memory);
> +    if(err < 0){
> +        printf("%d\n", err);
> +    }else{
> +        printf("%lu\n", free_memory);
> +    }

Indents, spaces, and unnecessary parentheses.

> +    libxl_ctx_free(context);
> +
> +}
> +
> diff --git a/tools/golang/xenlight/test/freememory/freememory.go b/tools/golang/xenlight/test/freememory/freememory.go
> new file mode 100644
> index 0000000..19501e7
> --- /dev/null
> +++ b/tools/golang/xenlight/test/freememory/freememory.go
> @@ -0,0 +1,35 @@
> +
> +package main
> +
> +/*
> +#cgo LDFLAGS: -lxenlight -lyajl
> +#include <stdlib.h>
> +#include <libxl.h>
> +*/
> +import "C"
> +import (
> +	"fmt"
> +	"xenproject.org/xenlight"
> +	"os"
> +)
> +
> +func main() {
> +	ctx := xenlight.Ctx
> +	err := ctx.Open()
> +	if err != nil{
> +		os.Exit(-1)
> +	}
> +	defer ctx.Close()
> +	if err != nil{
> +		os.Exit(-1)
> +	}

I don't think we need to check the error twice. :-)  (Same for the other
files.)

> +
> +
> +	free_memory, err := ctx.GetFreeMemory()
> +	if err != nil{
> +		fmt.Printf("%d\n", err)
> +	}else{
> +		fmt.Printf("%d\n", free_memory)
> +	}
> +
> +}

[snip]

> diff --git a/tools/golang/xenlight/test/physinfo/physinfo.c b/tools/golang/xenlight/test/physinfo/physinfo.c
> new file mode 100644
> index 0000000..92c8f47
> --- /dev/null
> +++ b/tools/golang/xenlight/test/physinfo/physinfo.c
> @@ -0,0 +1,31 @@
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <libxl.h>
> +
> +char *bool_to_string(bool b);
> +int main(){
> +
> +    libxl_ctx *context;
> +    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
> +    libxl_physinfo info ;
> +    int err= libxl_get_physinfo(context,&info);
> +    if(err != 0){
> +        return err;
> +    }
> +
> +    printf("%d\n%d\n%d\n%d\n%d\n", info.threads_per_core, info.cores_per_socket, info.max_cpu_id, info.nr_cpus, info.cpu_khz);
> +    printf("%lu\n%lu\n%lu\n%lu\n%lu\n%lu\n", info.total_pages, info.free_pages, info.scrub_pages, info.outstanding_pages, info.sharing_freed_pages, info.sharing_used_frames);
> +    printf("%u\n",info.nr_nodes);
> +    printf("%s\n%s\n", bool_to_string(info.cap_hvm), bool_to_string(info.cap_hvm_directio));
> +
> +    for(int i = 0; i < 8; i++){

So with the Xen-standard CFLAGS (which is what you'll get if you use the
makefile attached), this fails.  You should declare the int up above.

[snip]

> diff --git a/tools/golang/xenlight/test/versioninfo/versioninfo.c b/tools/golang/xenlight/test/versioninfo/versioninfo.c
> new file mode 100644
> index 0000000..f40495d
> --- /dev/null
> +++ b/tools/golang/xenlight/test/versioninfo/versioninfo.c
> @@ -0,0 +1,18 @@
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <libxl.h>
> +
> +main(){
> +
> +    libxl_ctx *context;
> +    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
> +    libxl_version_info* info = libxl_get_version_info(context);

With the Xen-supplied CFLAGS this fails because the pointer isn't
declared const.

Like I said, lots of little style points, but overall looks very good,
thanks!

 -George


[-- Attachment #2: Makefile.xenlight-tests --]
[-- Type: text/plain, Size: 698 bytes --]

XEN_ROOT = $(CURDIR)/../../../../..
include $(XEN_ROOT)/tools/Rules.mk

GO ?= go

TESTS = dominfo freememory maxcpu onlinecpu physinfo versioninfo
CBINARIES = $(TESTS:%=%-c)
GOBINARIES = $(TESTS:%=%-go)

all: build

test: clean build
	for test in $(TESTS) ; do \
		./$$test-c >> c.output ; \
	        ./$$test-go >> go.output ; \
		if cmp -s "c.output" "go.output"; then\
			echo "$$test PASSED";\
		else \
			echo "$$test FAILED";\
		fi ; \
	done

build: $(CBINARIES) $(GOBINARIES)

%-c: %.c
	gcc $(CFLAGS_libxenlight) -o $@ $< $(LDLIBS_libxenlight)

%-go: %.go
	GOPATH=$(XEN_ROOT)/tools/golang $(GO) build -o $@ $<

clean:
	rm -f *-c
	rm -f *-go
	rm -f *.output

[-- Attachment #3: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 6/8] golang/xenlight: Implement libxl_bitmap and helper operations
  2017-01-23 16:43 ` [PATCH RFC 6/8] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
@ 2017-02-01 17:59   ` George Dunlap
  0 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-02-01 17:59 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, Ronald Rojas wrote:
> Implement Bitmap type, along with helper functions.
> 
> The Bitmap type is implemented interllay in a way which makes it
> easy to copy into and out of the C libxl_bitmap type.
> 
> Signed-off-by: George Dunlap <george.dunlap@citrix.com>
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/golang/xenlight/xenlight.go | 166 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 166 insertions(+)
> 
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index dd6893c..54692fd 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -131,6 +131,19 @@ func (chwcap C.libxl_hwcap)CToGo() (ghwcap Hwcap) {
>  	return
>  }
>  
> +// typedef struct {
> +//     uint32_t size;          /* number of bytes in map */
> +//     uint8_t *map;
> +// } libxl_bitmap;
> +
> +// Implement the Go bitmap type such that the underlying data can
> +// easily be copied in and out.  NB that we still have to do copies
> +// both directions, because cgo runtime restrictions forbid passing to
> +// a C function a pointer to a Go-allocated structure which contains a
> +// pointer.
> +type Bitmap struct {
> +	bitmap []C.uint8_t
> +}
>  
>  /*
>   * Types: IDL
> @@ -199,6 +212,159 @@ type Dominfo struct {
>  }
>  
>  /*
> + * Bitmap operations
> + */
> +
> +// Return a Go bitmap which is a copy of the referred C bitmap.
> +func (cbm C.libxl_bitmap) CToGo() (gbm Bitmap) {

Probably just toGo()...

> +	// Alloc a Go slice for the bytes
> +	size := int(cbm.size)
> +	gbm.bitmap = make([]C.uint8_t, size)
> +
> +	// Make a slice pointing to the C array
> +	mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
> +
> +	// And copy the C array into the Go array
> +	copy(gbm.bitmap, mapslice)
> +
> +	return
> +}
> +
> +// Must be C.libxl_bitmap_dispose'd of afterwards
> +func (gbm Bitmap)GoToC() (cbm C.libxl_bitmap) {

...and toC (lower case so they're not visible outside the package).

Also 'go fmt'.

> +	C.libxl_bitmap_init(&cbm)
> +
> +	size := len(gbm.bitmap)
> +	cbm._map = (*C.uint8_t)(C.malloc(C.size_t(size)))
> +	cbm.size = C.uint32_t(size)
> +	if cbm._map == nil {
> +		panic("C.calloc failed!")

malloc  (This is probably my typo).

Other than that, looks good.

 -George


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 7/8] golang/xenlight: Implement libxl_scheduler enumeration
  2017-01-23 16:43 ` [PATCH RFC 7/8] golang/xenlight: Implement libxl_scheduler enumeration Ronald Rojas
@ 2017-02-01 18:13   ` George Dunlap
  0 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-02-01 18:13 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 23/01/17 16:43, Ronald Rojas wrote:
> Include both constants and a Stringification for libxl_scheduler.
> 
> Signed-off-by: George Dunlap <george.dunlap@citrix.com>
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/golang/xenlight/xenlight.go | 62 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 62 insertions(+)
> 
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index 54692fd..0990f07 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -211,6 +211,68 @@ type Dominfo struct {
>  
>  }
>  
> +// # Consistent with values defined in domctl.h
> +// # Except unknown which we have made up
> +// libxl_scheduler = Enumeration("scheduler", [
> +//     (0, "unknown"),
> +//     (4, "sedf"),
> +//     (5, "credit"),
> +//     (6, "credit2"),
> +//     (7, "arinc653"),
> +//     (8, "rtds"),
> +//     ])
> +type Scheduler int
> +
> +var (
> +	SchedulerUnknown  Scheduler = C.LIBXL_SCHEDULER_UNKNOWN
> +	SchedulerSedf     Scheduler = C.LIBXL_SCHEDULER_SEDF
> +	SchedulerCredit   Scheduler = C.LIBXL_SCHEDULER_CREDIT
> +	SchedulerCredit2  Scheduler = C.LIBXL_SCHEDULER_CREDIT2
> +	SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653
> +	SchedulerRTDS     Scheduler = C.LIBXL_SCHEDULER_RTDS
> +)
> +
> +// const char *libxl_scheduler_to_string(libxl_scheduler p);
> +func (s Scheduler) String() string {
> +	cs := C.libxl_scheduler_to_string(C.libxl_scheduler(s))
> +	// No need to free const return value
> +
> +	return C.GoString(cs)
> +}
> +
> +// int libxl_scheduler_from_string(const char *s, libxl_scheduler *e);
> +func (s *Scheduler) FromString(gstr string) (err error) {
> +	cstr := C.CString(gstr)
> +	defer C.free(unsafe.Pointer(cstr))
> +
> +	var cs C.libxl_scheduler
> +	ret := C.libxl_scheduler_from_string(cstr, &cs)
> +	if ret != 0 {
> +		err = Error(-ret)
> +		return
> +	}
> +
> +	*s = Scheduler(cs)
> +	return
> +}
> +
> +func SchedulerFromString(name string) (s Scheduler, err error) {
> +	cname := C.CString(name)
> +	defer C.free(unsafe.Pointer(cname))
> +
> +	var cs C.libxl_scheduler
> +
> +	ret := C.libxl_scheduler_from_string(cname, &cs)
> +	if ret != 0 {
> +		err = Error(-ret)
> +		return
> +	}
> +
> +	s = Scheduler(cs)
> +
> +	return
> +}

I don't think we need both of these functions.  In my code I just used
the method one (FromString).  What do you think?

BTW this file is an obvious template for the enumerations you need for
DomInfo. :-)

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-18 19:56 Ronald Rojas
                   ` (3 preceding siblings ...)
  2017-01-19 16:40 ` George Dunlap
@ 2017-01-19 16:45 ` George Dunlap
  4 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-19 16:45 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 18/01/17 19:56, Ronald Rojas wrote:
> Create a basic Makefile to build and install libxenlight Golang
> bindings. Also add a stub package which only opens libxl context.
> 
> Include a global xenlight.Ctx variable which can be used as the
> default context by the entire program if desired.
> 
> For now, return simple errors. Proper error handling will be
> added in next patch.
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/Makefile                    | 15 +++++++-
>  tools/golang/xenlight/Makefile    | 29 ++++++++++++++
>  tools/golang/xenlight/xenlight.go | 80 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 123 insertions(+), 1 deletion(-)
>  create mode 100644 tools/golang/xenlight/Makefile
>  create mode 100644 tools/golang/xenlight/xenlight.go
> 
> diff --git a/tools/Makefile b/tools/Makefile
> index 77e0723..fd49e7f 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -6,12 +6,13 @@ SUBDIRS-y += include
>  SUBDIRS-y += libs
>  SUBDIRS-y += libxc
>  SUBDIRS-y += flask
> -SUBDIRS-y += fuzz
>  SUBDIRS-y += xenstore
>  SUBDIRS-y += misc
>  SUBDIRS-y += examples
>  SUBDIRS-y += hotplug
>  SUBDIRS-y += xentrace
> +#Uncomment line to build Golang libxl
> +#SUBDIRS-y += golang/xenlight
>  SUBDIRS-$(CONFIG_XCUTILS) += xcutils
>  SUBDIRS-$(CONFIG_X86) += firmware
>  SUBDIRS-y += console
> @@ -322,6 +323,18 @@ subdir-install-debugger/kdd: .phony
>  subdir-all-debugger/kdd: .phony
>  	$(MAKE) -C debugger/kdd all
>  
> +subdir-clean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight clean
> +
> +subdir-distclean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight distclean
> +
> +subdir-install-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight install
> +
> +subdir-all-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight all
> +
>  subdir-distclean-firmware: .phony
>  	$(MAKE) -C firmware distclean
>  
> diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> new file mode 100644
> index 0000000..a45336b
> --- /dev/null
> +++ b/tools/golang/xenlight/Makefile
> @@ -0,0 +1,29 @@
> +XEN_ROOT=$(CURDIR)/../../..
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +BINARY = xenlightgo
> +GO = go
> +
> +.PHONY: all
> +all: build
> +
> +.PHONY: build
> +build: xenlight
> +
> +.PHONY: install
> +install: build
> +	! [ -f $(BINARY) ] || $(INSTALL_PROG) xenlight.go $(DESTDIR)$(bindir)
> +
> +.PHONY: clean
> +clean:
> +	$(RM) $(BINARY)
> +
> +.PHONY: distclean
> +distclean: clean
> +
> +
> +xenlight: xenlight.go
> +	$(GO) build -o $(BINARY) xenlight.go
> +
> +
> +-include $(DEPS)
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> new file mode 100644
> index 0000000..1f10e51
> --- /dev/null
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -0,0 +1,80 @@
> +/*
> + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; version 2 of the
> + * License only.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +package xenlight
> +
> +/*
> +#cgo LDFLAGS: -lxenlight -lyajl
> +#include <stdlib.h>
> +#include <libxl.h>
> +*/
> +import "C"
> +
> +import (
> +	"fmt"
> +	"time"
> +	"unsafe"
> +)

And finally -- this won't compile because we're not using the "time"
package yet.  This should be removed and added back in in the patch that
requires it.

 -George


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-18 19:56 Ronald Rojas
                   ` (2 preceding siblings ...)
  2017-01-19 16:16 ` George Dunlap
@ 2017-01-19 16:40 ` George Dunlap
  2017-01-19 16:45 ` George Dunlap
  4 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-19 16:40 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 18/01/17 19:56, Ronald Rojas wrote:
> Create a basic Makefile to build and install libxenlight Golang
> bindings. Also add a stub package which only opens libxl context.
> 
> Include a global xenlight.Ctx variable which can be used as the
> default context by the entire program if desired.
> 
> For now, return simple errors. Proper error handling will be
> added in next patch.
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/Makefile                    | 15 +++++++-
>  tools/golang/xenlight/Makefile    | 29 ++++++++++++++
>  tools/golang/xenlight/xenlight.go | 80 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 123 insertions(+), 1 deletion(-)
>  create mode 100644 tools/golang/xenlight/Makefile
>  create mode 100644 tools/golang/xenlight/xenlight.go
> 
> diff --git a/tools/Makefile b/tools/Makefile
> index 77e0723..fd49e7f 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -6,12 +6,13 @@ SUBDIRS-y += include
>  SUBDIRS-y += libs
>  SUBDIRS-y += libxc
>  SUBDIRS-y += flask
> -SUBDIRS-y += fuzz
>  SUBDIRS-y += xenstore
>  SUBDIRS-y += misc
>  SUBDIRS-y += examples
>  SUBDIRS-y += hotplug
>  SUBDIRS-y += xentrace
> +#Uncomment line to build Golang libxl
> +#SUBDIRS-y += golang/xenlight
>  SUBDIRS-$(CONFIG_XCUTILS) += xcutils
>  SUBDIRS-$(CONFIG_X86) += firmware
>  SUBDIRS-y += console
> @@ -322,6 +323,18 @@ subdir-install-debugger/kdd: .phony
>  subdir-all-debugger/kdd: .phony
>  	$(MAKE) -C debugger/kdd all
>  
> +subdir-clean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight clean
> +
> +subdir-distclean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight distclean
> +
> +subdir-install-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight install
> +
> +subdir-all-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight all
> +
>  subdir-distclean-firmware: .phony
>  	$(MAKE) -C firmware distclean
>  
> diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> new file mode 100644
> index 0000000..a45336b
> --- /dev/null
> +++ b/tools/golang/xenlight/Makefile
> @@ -0,0 +1,29 @@
> +XEN_ROOT=$(CURDIR)/../../..
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +BINARY = xenlightgo
> +GO = go
> +
> +.PHONY: all
> +all: build
> +
> +.PHONY: build
> +build: xenlight
> +
> +.PHONY: install
> +install: build
> +	! [ -f $(BINARY) ] || $(INSTALL_PROG) xenlight.go $(DESTDIR)$(bindir)
> +
> +.PHONY: clean
> +clean:
> +	$(RM) $(BINARY)
> +
> +.PHONY: distclean
> +distclean: clean
> +
> +
> +xenlight: xenlight.go
> +	$(GO) build -o $(BINARY) xenlight.go

Actually, one more thing here -- this will build using whatever version
of libxl you have installed *on the host system*, not the one you just
build as part of the build process.

You need to point the go compiler to use the version of libxl you've
just built in-tree, like this:

CGO_CFLAGS = -I$(DESTDIR)$(includedir)
CGO_LDFLAGS = -L$(DESTDIR)$(libdir) -Wl,-rpath-link=$(DESTDIR)$(libdir)
xenlight: xenlight.go
	CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -o
$(BINARY) xenlight.go


 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-18 19:56 Ronald Rojas
  2017-01-18 22:10 ` Dario Faggioli
  2017-01-19 12:03 ` Wei Liu
@ 2017-01-19 16:16 ` George Dunlap
  2017-01-19 16:40 ` George Dunlap
  2017-01-19 16:45 ` George Dunlap
  4 siblings, 0 replies; 32+ messages in thread
From: George Dunlap @ 2017-01-19 16:16 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, ian.jackson, wei.liu2

On 18/01/17 19:56, Ronald Rojas wrote:
> Create a basic Makefile to build and install libxenlight Golang
> bindings. Also add a stub package which only opens libxl context.
> 
> Include a global xenlight.Ctx variable which can be used as the
> default context by the entire program if desired.
> 
> For now, return simple errors. Proper error handling will be
> added in next patch.
> 
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
>  tools/Makefile                    | 15 +++++++-
>  tools/golang/xenlight/Makefile    | 29 ++++++++++++++
>  tools/golang/xenlight/xenlight.go | 80 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 123 insertions(+), 1 deletion(-)
>  create mode 100644 tools/golang/xenlight/Makefile
>  create mode 100644 tools/golang/xenlight/xenlight.go
> 
> diff --git a/tools/Makefile b/tools/Makefile
> index 77e0723..fd49e7f 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -6,12 +6,13 @@ SUBDIRS-y += include
>  SUBDIRS-y += libs
>  SUBDIRS-y += libxc
>  SUBDIRS-y += flask
> -SUBDIRS-y += fuzz
>  SUBDIRS-y += xenstore
>  SUBDIRS-y += misc
>  SUBDIRS-y += examples
>  SUBDIRS-y += hotplug
>  SUBDIRS-y += xentrace
> +#Uncomment line to build Golang libxl
> +#SUBDIRS-y += golang/xenlight
>  SUBDIRS-$(CONFIG_XCUTILS) += xcutils
>  SUBDIRS-$(CONFIG_X86) += firmware
>  SUBDIRS-y += console
> @@ -322,6 +323,18 @@ subdir-install-debugger/kdd: .phony
>  subdir-all-debugger/kdd: .phony
>  	$(MAKE) -C debugger/kdd all
>  
> +subdir-clean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight clean
> +
> +subdir-distclean-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight distclean
> +
> +subdir-install-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight install
> +
> +subdir-all-golang/xenlight: .phony
> +	$(MAKE) -C golang/xenlight all
> +
>  subdir-distclean-firmware: .phony
>  	$(MAKE) -C firmware distclean
>  
> diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> new file mode 100644
> index 0000000..a45336b
> --- /dev/null
> +++ b/tools/golang/xenlight/Makefile
> @@ -0,0 +1,29 @@
> +XEN_ROOT=$(CURDIR)/../../..
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +BINARY = xenlightgo
> +GO = go
> +
> +.PHONY: all
> +all: build
> +
> +.PHONY: build
> +build: xenlight
> +
> +.PHONY: install
> +install: build
> +	! [ -f $(BINARY) ] || $(INSTALL_PROG) xenlight.go $(DESTDIR)$(bindir)

This will install xenlight.go in /usr/bin.  What happened to the
GOLANG_SRC variable I had in the sample series I sent you?

> +
> +.PHONY: clean
> +clean:
> +	$(RM) $(BINARY)
> +
> +.PHONY: distclean
> +distclean: clean
> +
> +
> +xenlight: xenlight.go
> +	$(GO) build -o $(BINARY) xenlight.go
> +
> +
> +-include $(DEPS)
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> new file mode 100644
> index 0000000..1f10e51
> --- /dev/null
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -0,0 +1,80 @@
> +/*
> + * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; version 2 of the
> + * License only.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +package xenlight
> +
> +/*
> +#cgo LDFLAGS: -lxenlight -lyajl
> +#include <stdlib.h>
> +#include <libxl.h>
> +*/
> +import "C"
> +
> +import (
> +	"fmt"
> +	"time"
> +	"unsafe"
> +)
> +
> +/*
> + * Types: Builtins
> + */
> +type Context struct {
> +	ctx *C.libxl_ctx
> +}
> +
> +/*
> + * Context
> + */
> +var Ctx Context
> +
> +func (Ctx *Context) IsOpen() bool {
> +	return Ctx.ctx != nil
> +}
> +
> +func (Ctx *Context) Open() (err error) {
> +	if Ctx.ctx != nil {
> +		return
> +	}
> +
> +	ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
> +
> +	if ret != 0 {
> +		//FIXME: proper error
> +		err = createError("Allocating libxl context: ", ret)

Ah, right -- I think I see what Dario was getting at.

At the moment this won't compile, because you haven't declared
createError() anywhere.  You should try to make an effort to make each
commit in the series actually compile and have no regressions.

Since you're already including fmt, I think here I'd say:

    err = fmt.Errorf("Allocating libxl context: %d", ret)

This will compile and behave sensibly before it's replaced with the
error message.

Everything else looks good for now.  (The makefile will go through a lot
of updates once we integrate it into configure.)

 -George


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-19 12:03 ` Wei Liu
@ 2017-01-19 15:15   ` Ronald Rojas
  0 siblings, 0 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-19 15:15 UTC (permalink / raw)
  To: Wei Liu; +Cc: ian.jackson, george.dunlap, xen-devel

On Thu, Jan 19, 2017 at 12:03:22PM +0000, Wei Liu wrote:
> On Wed, Jan 18, 2017 at 02:56:39PM -0500, Ronald Rojas wrote:
>   
> > diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> > new file mode 100644
> > index 0000000..a45336b
> > --- /dev/null
> > +++ b/tools/golang/xenlight/Makefile
> > @@ -0,0 +1,29 @@
> > +XEN_ROOT=$(CURDIR)/../../..
> > +include $(XEN_ROOT)/tools/Rules.mk
> > +
> > +BINARY = xenlightgo
> > +GO = go
> 
> GO ?= go
> 
> to allow overriding this command.

Fixed. Thanks!
> 
> Other than this, I don't have further comments on the actual go code and
> will let George review your series.
> 
> Wei.

Thanks,
Ronald

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-18 19:56 Ronald Rojas
  2017-01-18 22:10 ` Dario Faggioli
@ 2017-01-19 12:03 ` Wei Liu
  2017-01-19 15:15   ` Ronald Rojas
  2017-01-19 16:16 ` George Dunlap
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 32+ messages in thread
From: Wei Liu @ 2017-01-19 12:03 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: wei.liu2, ian.jackson, george.dunlap, xen-devel

On Wed, Jan 18, 2017 at 02:56:39PM -0500, Ronald Rojas wrote:
  
> diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
> new file mode 100644
> index 0000000..a45336b
> --- /dev/null
> +++ b/tools/golang/xenlight/Makefile
> @@ -0,0 +1,29 @@
> +XEN_ROOT=$(CURDIR)/../../..
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +BINARY = xenlightgo
> +GO = go

GO ?= go

to allow overriding this command.

Other than this, I don't have further comments on the actual go code and
will let George review your series.

Wei.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-18 22:10 ` Dario Faggioli
@ 2017-01-18 22:37   ` Ronald Rojas
  0 siblings, 0 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-18 22:37 UTC (permalink / raw)
  To: Dario Faggioli; +Cc: wei.liu2, ian.jackson, george.dunlap, xen-devel

On Wed, Jan 18, 2017 at 11:10:32PM +0100, Dario Faggioli wrote:
> Hey,
> 
> I'm afraid I can't comment on nothing, as I'm not at all into go.
> 
> But there's a thing that I've noticed while skipping the patch out of
> curiosity...
> 
> On Wed, 2017-01-18 at 14:56 -0500, Ronald Rojas wrote:
> > diff --git a/tools/Makefile b/tools/Makefile
> > index 77e0723..fd49e7f 100644
> > --- a/tools/Makefile
> > +++ b/tools/Makefile
> > @@ -6,12 +6,13 @@ SUBDIRS-y += include
> >  SUBDIRS-y += libs
> >  SUBDIRS-y += libxc
> >  SUBDIRS-y += flask
> > -SUBDIRS-y += fuzz
> >
> Why does this needs to be removed?
This was a mistake and should not have been removed. I'll
fix it in the next revision.

Thanks, 
Ronald
> 
> Dario
> -- 
> <<This happens because I choose it to happen!>> (Raistlin Majere)
> -----------------------------------------------------------------
> Dario Faggioli, Ph.D, http://about.me/dario.faggioli
> Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH RFC 1/8] golang/xenlight: Create stub package
  2017-01-18 19:56 Ronald Rojas
@ 2017-01-18 22:10 ` Dario Faggioli
  2017-01-18 22:37   ` Ronald Rojas
  2017-01-19 12:03 ` Wei Liu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 32+ messages in thread
From: Dario Faggioli @ 2017-01-18 22:10 UTC (permalink / raw)
  To: Ronald Rojas, xen-devel, george.dunlap, ian.jackson, wei.liu2


[-- Attachment #1.1: Type: text/plain, Size: 790 bytes --]

Hey,

I'm afraid I can't comment on nothing, as I'm not at all into go.

But there's a thing that I've noticed while skipping the patch out of
curiosity...

On Wed, 2017-01-18 at 14:56 -0500, Ronald Rojas wrote:
> diff --git a/tools/Makefile b/tools/Makefile
> index 77e0723..fd49e7f 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -6,12 +6,13 @@ SUBDIRS-y += include
>  SUBDIRS-y += libs
>  SUBDIRS-y += libxc
>  SUBDIRS-y += flask
> -SUBDIRS-y += fuzz
>
Why does this needs to be removed?

Dario
-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH RFC 1/8] golang/xenlight: Create stub package
@ 2017-01-18 19:56 Ronald Rojas
  2017-01-18 22:10 ` Dario Faggioli
                   ` (4 more replies)
  0 siblings, 5 replies; 32+ messages in thread
From: Ronald Rojas @ 2017-01-18 19:56 UTC (permalink / raw)
  To: xen-devel, george.dunlap, ian.jackson, wei.liu2; +Cc: Ronald Rojas

Create a basic Makefile to build and install libxenlight Golang
bindings. Also add a stub package which only opens libxl context.

Include a global xenlight.Ctx variable which can be used as the
default context by the entire program if desired.

For now, return simple errors. Proper error handling will be
added in next patch.

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
 tools/Makefile                    | 15 +++++++-
 tools/golang/xenlight/Makefile    | 29 ++++++++++++++
 tools/golang/xenlight/xenlight.go | 80 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 tools/golang/xenlight/Makefile
 create mode 100644 tools/golang/xenlight/xenlight.go

diff --git a/tools/Makefile b/tools/Makefile
index 77e0723..fd49e7f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -6,12 +6,13 @@ SUBDIRS-y += include
 SUBDIRS-y += libs
 SUBDIRS-y += libxc
 SUBDIRS-y += flask
-SUBDIRS-y += fuzz
 SUBDIRS-y += xenstore
 SUBDIRS-y += misc
 SUBDIRS-y += examples
 SUBDIRS-y += hotplug
 SUBDIRS-y += xentrace
+#Uncomment line to build Golang libxl
+#SUBDIRS-y += golang/xenlight
 SUBDIRS-$(CONFIG_XCUTILS) += xcutils
 SUBDIRS-$(CONFIG_X86) += firmware
 SUBDIRS-y += console
@@ -322,6 +323,18 @@ subdir-install-debugger/kdd: .phony
 subdir-all-debugger/kdd: .phony
 	$(MAKE) -C debugger/kdd all
 
+subdir-clean-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight clean
+
+subdir-distclean-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight distclean
+
+subdir-install-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight install
+
+subdir-all-golang/xenlight: .phony
+	$(MAKE) -C golang/xenlight all
+
 subdir-distclean-firmware: .phony
 	$(MAKE) -C firmware distclean
 
diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile
new file mode 100644
index 0000000..a45336b
--- /dev/null
+++ b/tools/golang/xenlight/Makefile
@@ -0,0 +1,29 @@
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+BINARY = xenlightgo
+GO = go
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build: xenlight
+
+.PHONY: install
+install: build
+	! [ -f $(BINARY) ] || $(INSTALL_PROG) xenlight.go $(DESTDIR)$(bindir)
+
+.PHONY: clean
+clean:
+	$(RM) $(BINARY)
+
+.PHONY: distclean
+distclean: clean
+
+
+xenlight: xenlight.go
+	$(GO) build -o $(BINARY) xenlight.go
+
+
+-include $(DEPS)
diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
new file mode 100644
index 0000000..1f10e51
--- /dev/null
+++ b/tools/golang/xenlight/xenlight.go
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of the
+ * License only.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+package xenlight
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+
+import (
+	"fmt"
+	"time"
+	"unsafe"
+)
+
+/*
+ * Types: Builtins
+ */
+type Context struct {
+	ctx *C.libxl_ctx
+}
+
+/*
+ * Context
+ */
+var Ctx Context
+
+func (Ctx *Context) IsOpen() bool {
+	return Ctx.ctx != nil
+}
+
+func (Ctx *Context) Open() (err error) {
+	if Ctx.ctx != nil {
+		return
+	}
+
+	ret := C.libxl_ctx_alloc(unsafe.Pointer(&Ctx.ctx), C.LIBXL_VERSION, 0, nil)
+
+	if ret != 0 {
+		//FIXME: proper error
+		err = createError("Allocating libxl context: ", ret)
+	}
+	return
+}
+
+func (Ctx *Context) Close() (err error) {
+	ret := C.libxl_ctx_free(unsafe.Pointer(Ctx.ctx))
+	Ctx.ctx = nil
+
+	if ret != 0 {
+		//FIXME: proper error
+		err = createError("Freeing libxl context: ", ret)
+	}
+	return
+}
+
+func (Ctx *Context) CheckOpen() (err error) {
+	if Ctx.ctx == nil {
+		err = fmt.Errorf("Context not opened")
+	}
+	return
+}
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2017-02-01 18:13 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-23 16:43 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
2017-01-23 16:43 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Ronald Rojas
2017-01-27 12:22   ` George Dunlap
2017-01-23 16:43 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
2017-02-01 15:53   ` George Dunlap
2017-02-01 15:58   ` George Dunlap
2017-02-01 16:05   ` George Dunlap
2017-01-23 16:43 ` [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
2017-02-01 16:16   ` George Dunlap
2017-01-23 16:43 ` [PATCH RFC 5/8] golang/xenlight: Add tests host related functinality functions Ronald Rojas
2017-02-01 17:39   ` George Dunlap
2017-01-23 16:43 ` [PATCH RFC 6/8] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
2017-02-01 17:59   ` George Dunlap
2017-01-23 16:43 ` [PATCH RFC 7/8] golang/xenlight: Implement libxl_scheduler enumeration Ronald Rojas
2017-02-01 18:13   ` George Dunlap
2017-01-23 16:43 ` [PATCH RFC 8/8] golang/xenlight: Implement cpupool operations Ronald Rojas
2017-01-25 16:55 ` [PATCH RFC 1/8] golang/xenlight: Create stub package Wei Liu
2017-01-26  8:13   ` Ronald Rojas
2017-01-25 17:16 ` George Dunlap
2017-01-26  8:26   ` Ronald Rojas
2017-01-26 10:44   ` Ian Jackson
2017-01-26 11:26     ` George Dunlap
2017-01-27 11:43 ` George Dunlap
2017-01-27 19:40 ` George Dunlap
  -- strict thread matches above, loose matches on Subject: below --
2017-01-18 19:56 Ronald Rojas
2017-01-18 22:10 ` Dario Faggioli
2017-01-18 22:37   ` Ronald Rojas
2017-01-19 12:03 ` Wei Liu
2017-01-19 15:15   ` Ronald Rojas
2017-01-19 16:16 ` George Dunlap
2017-01-19 16:40 ` George Dunlap
2017-01-19 16:45 ` George Dunlap

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.