All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 01/14] golang/xenlight: Create stub package
@ 2017-03-16 19:08 Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 02/14] golang/xenlight: Add error constants and standard handling Ronald Rojas
                   ` (13 more replies)
  0 siblings, 14 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, George Dunlap, xen-devel

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:

- Added global logger variable and destroyed the logger instance
when closing the context.

- Whitespace fixes

- Commented out CONFIG_GOLANG

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/Makefile                    |  1 +
 tools/Rules.mk                    |  7 ++++
 tools/golang/Makefile             | 27 ++++++++++++
 tools/golang/xenlight/Makefile    | 49 ++++++++++++++++++++++
 tools/golang/xenlight/xenlight.go | 88 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 172 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..4edffbe 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -30,6 +30,13 @@ 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
+XEN_GOCODE_URL    = golang.xenproject.org
+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..5db665d
--- /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/$(XEN_GOCODE_URL)/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/$(XEN_GOCODE_URL)/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) $(CFLAGS_libxentoollog)" CGO_LDFLAGS="$(LDLIBS_libxenlight) $(LDLIBS_libxentoollog)-L$(XEN_XENLIGHT) -L$(XEN_LIBXENTOOLLOG)" GOPATH=$(XEN_GOPATH) $(GO) install -x $(XEN_GOCODE_URL)/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/*/$(XEN_GOCODE_URL)/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..b025961
--- /dev/null
+++ b/tools/golang/xenlight/xenlight.go
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2016 George W. Dunlap, Citrix Systems UK Ltd
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+package xenlight
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl -lxentoollog
+#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
+
+var logger *C.xentoollog_logger_stdiostream
+
+func (Ctx *Context) IsOpen() bool {
+	return Ctx.ctx != nil
+}
+
+func (Ctx *Context) Open() (err error) {
+	if Ctx.ctx != nil {
+		return
+	}
+
+	logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_ERROR, 0)
+	ret := C.libxl_ctx_alloc(&Ctx.ctx, C.LIBXL_VERSION,
+		0, unsafe.Pointer(logger))
+
+	if ret != 0 {
+		err = fmt.Errorf("Error: %d", -ret)
+	}
+	return
+}
+
+func (Ctx *Context) Close() (err error) {
+	ret := C.libxl_ctx_free(Ctx.ctx)
+	Ctx.ctx = nil
+
+	if ret != 0 {
+		err = fmt.Errorf("Error: %d", -ret)
+	}
+	C.xtl_logger_destroy(unsafe.Pointer(logger))
+	return
+}
+
+func (Ctx *Context) CheckOpen() (err error) {
+	if Ctx.ctx == nil {
+		err = fmt.Errorf("Context not opened")
+	}
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 02/14] golang/xenlight: Add error constants and standard handling
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-20 15:41   ` George Dunlap
  2017-03-16 19:08 ` [PATCH v4 03/14] golang/xenlight: Add host-related functionality Ronald Rojas
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

Create error type Errorxl for throwing proper xenlight
errors.

Update Ctx functions to throw Errorxl errors.

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 78 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 76 insertions(+), 2 deletions(-)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index b025961..a99d9d3 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -37,8 +37,71 @@ import (
 )
 
 /*
+ * 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
 }
@@ -50,6 +113,17 @@ var Ctx Context
 
 var logger *C.xentoollog_logger_stdiostream
 
+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
 }
@@ -64,7 +138,7 @@ func (Ctx *Context) Open() (err error) {
 		0, unsafe.Pointer(logger))
 
 	if ret != 0 {
-		err = fmt.Errorf("Error: %d", -ret)
+		err = Error(-ret)
 	}
 	return
 }
@@ -74,7 +148,7 @@ func (Ctx *Context) Close() (err error) {
 	Ctx.ctx = nil
 
 	if ret != 0 {
-		err = fmt.Errorf("Error: %d", -ret)
+		err = Error(-ret)
 	}
 	C.xtl_logger_destroy(unsafe.Pointer(logger))
 	return
-- 
2.7.3


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

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

* [PATCH v4 03/14] golang/xenlight: Add host-related functionality
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 02/14] golang/xenlight: Add error constants and standard handling Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-20 15:50   ` George Dunlap
  2017-03-16 19:08 ` [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

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>
---
Changes since last version

- Used defer for libxl_physinfo_dispose

- Formating fixes

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 200 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 200 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index a99d9d3..785eaaf 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -106,6 +106,103 @@ 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
+}
+
+func (cphys *C.libxl_physinfo) toGo() (physinfo *Physinfo) {
+
+	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
+}
+
+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
+}
+
+func (cinfo *C.libxl_version_info) toGo() (info *VersionInfo) {
+	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
+}
+
 /*
  * Context
  */
@@ -160,3 +257,106 @@ 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
+	C.libxl_physinfo_init(&cphys)
+
+	ret := C.libxl_get_physinfo(Ctx.ctx, &cphys)
+
+	if ret < 0 {
+		err = Error(ret)
+		return
+	}
+	physinfo = cphys.toGo()
+	C.libxl_physinfo_dispose(&cphys)
+
+	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 = cinfo.toGo()
+
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 02/14] golang/xenlight: Add error constants and standard handling Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 03/14] golang/xenlight: Add host-related functionality Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-20 15:57   ` George Dunlap
  2017-03-16 19:08 ` [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions Ronald Rojas
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, George Dunlap, xen-devel

Add calls for the following host-related functionality:
- libxl_domain_info
- libxl_domain_unpause

Include Golang version for the libxl_domain_info as
DomainInfo.

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

- Formating fixes

- used defer for libxl_dominfo_dispose

- Removed unnessary unsafe.Pointer() casts.

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com

---
---
 tools/golang/xenlight/xenlight.go | 136 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 133 insertions(+), 3 deletions(-)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 785eaaf..34c3050 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -33,6 +33,7 @@ import "C"
 
 import (
 	"fmt"
+	"time"
 	"unsafe"
 )
 
@@ -102,13 +103,19 @@ var errors = [...]string{
  * Types: Builtins
  */
 
+type Domid uint32
+
+type MemKB uint64
+
+type Uuid C.libxl_uuid
+
 type Context struct {
 	ctx *C.libxl_ctx
 }
 
 type Hwcap []C.uint32_t
 
-func (chwcap C.libxl_hwcap) CToGo() (ghwcap Hwcap) {
+func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) {
 	// Alloc a Go slice for the bytes
 	size := 8
 	ghwcap = make([]C.uint32_t, size)
@@ -161,7 +168,7 @@ func (cphys *C.libxl_physinfo) toGo() (physinfo *Physinfo) {
 	physinfo.SharingFreedPages = uint64(cphys.sharing_freed_pages)
 	physinfo.SharingUsedFrames = uint64(cphys.sharing_used_frames)
 	physinfo.NrNodes = uint32(cphys.nr_nodes)
-	physinfo.HwCap = cphys.hw_cap.CToGo()
+	physinfo.HwCap = cphys.hw_cap.toGo()
 	physinfo.CapHvm = bool(cphys.cap_hvm)
 	physinfo.CapHvmDirectio = bool(cphys.cap_hvm_directio)
 
@@ -203,6 +210,93 @@ func (cinfo *C.libxl_version_info) toGo() (info *VersionInfo) {
 	return
 }
 
+type ShutdownReason int32
+
+const (
+	ShutdownReasonUnknown   = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_UNKNOWN)
+	ShutdownReasonPoweroff  = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_POWEROFF)
+	ShutdownReasonReboot    = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_REBOOT)
+	ShutdownReasonSuspend   = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_SUSPEND)
+	ShutdownReasonCrash     = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_CRASH)
+	ShutdownReasonWatchdog  = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_WATCHDOG)
+	ShutdownReasonSoftReset = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_SOFT_RESET)
+)
+
+func (sr ShutdownReason) String() (str string) {
+	cstr := C.libxl_shutdown_reason_to_string(C.libxl_shutdown_reason(sr))
+	str = C.GoString(cstr)
+
+	return
+}
+
+type DomainType int32
+
+const (
+	DomainTypeInvalid = DomainType(C.LIBXL_DOMAIN_TYPE_INVALID)
+	DomainTypeHvm     = DomainType(C.LIBXL_DOMAIN_TYPE_HVM)
+	DomainTypePv      = DomainType(C.LIBXL_DOMAIN_TYPE_PV)
+)
+
+func (dt DomainType) String() (str string) {
+	cstr := C.libxl_domain_type_to_string(C.libxl_domain_type(dt))
+	str = C.GoString(cstr)
+
+	return
+}
+
+type Dominfo struct {
+	Uuid      Uuid
+	Domid     Domid
+	Ssidref   uint32
+	SsidLabel string
+	Running   bool
+	Blocked   bool
+	Paused    bool
+	Shutdown  bool
+	Dying     bool
+	NeverStop bool
+
+	ShutdownReason   int32
+	OutstandingMemkb MemKB
+	CurrentMemkb     MemKB
+	SharedMemkb      MemKB
+	PagedMemkb       MemKB
+	MaxMemkb         MemKB
+	CpuTime          time.Duration
+	VcpuMaxId        uint32
+	VcpuOnline       uint32
+	Cpupool          uint32
+	DomainType       int32
+}
+
+func (cdi *C.libxl_dominfo) toGo() (di *Dominfo) {
+
+	di = &Dominfo{}
+	di.Uuid = Uuid(cdi.uuid)
+	di.Domid = Domid(cdi.domid)
+	di.Ssidref = uint32(cdi.ssidref)
+	di.SsidLabel = C.GoString(cdi.ssid_label)
+	di.Running = bool(cdi.running)
+	di.Blocked = bool(cdi.blocked)
+	di.Paused = bool(cdi.paused)
+	di.Shutdown = bool(cdi.shutdown)
+	di.Dying = bool(cdi.dying)
+	di.NeverStop = bool(cdi.never_stop)
+	di.ShutdownReason = int32(cdi.shutdown_reason)
+	di.OutstandingMemkb = MemKB(cdi.outstanding_memkb)
+	di.CurrentMemkb = MemKB(cdi.current_memkb)
+	di.SharedMemkb = MemKB(cdi.shared_memkb)
+	di.PagedMemkb = MemKB(cdi.paged_memkb)
+	di.MaxMemkb = MemKB(cdi.max_memkb)
+	di.CpuTime = time.Duration(cdi.cpu_time)
+	di.VcpuMaxId = uint32(cdi.vcpu_max_id)
+	di.VcpuOnline = uint32(cdi.vcpu_online)
+	di.Cpupool = uint32(cdi.cpupool)
+	di.DomainType = int32(cdi.domain_type)
+
+	return
+}
+
 /*
  * Context
  */
@@ -332,6 +426,7 @@ func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) {
 	}
 	var cphys C.libxl_physinfo
 	C.libxl_physinfo_init(&cphys)
+	defer C.libxl_physinfo_dispose(&cphys)
 
 	ret := C.libxl_get_physinfo(Ctx.ctx, &cphys)
 
@@ -340,7 +435,6 @@ func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) {
 		return
 	}
 	physinfo = cphys.toGo()
-	C.libxl_physinfo_dispose(&cphys)
 
 	return
 }
@@ -360,3 +454,39 @@ func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) {
 
 	return
 }
+
+func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var cdi C.libxl_dominfo
+	C.libxl_dominfo_init(&cdi)
+	defer C.libxl_dominfo_dispose(&cdi)
+
+	ret := C.libxl_domain_info(Ctx.ctx, &cdi, C.uint32_t(Id))
+
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	di = cdi.toGo()
+
+	return
+}
+
+func (Ctx *Context) DomainUnpause(Id Domid) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_domain_unpause(Ctx.ctx, C.uint32_t(Id))
+
+	if ret != 0 {
+		err = Error(-ret)
+	}
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (2 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-20 17:49   ` George Dunlap
  2017-03-16 19:08 ` [PATCH v4 06/14] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, George Dunlap, xen-devel

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

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

---
changes since last version

- created CFLAGS and LDLIBS variables to build test C
files with required dependencies.

- created create_context and destroy_context function
for tests to create/destroy libxl_ctx and xenlogger

- Formating changes

- Removed stale comments

- Removed redundant error checks in Golang tests

- Negated printed error code in freememory.go
CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/test/xeninfo/Makefile       | 41 +++++++++++++++++++++++
 tools/golang/xenlight/test/xeninfo/dominfo.c      | 33 ++++++++++++++++++
 tools/golang/xenlight/test/xeninfo/dominfo.go     | 31 +++++++++++++++++
 tools/golang/xenlight/test/xeninfo/freememory.c   | 26 ++++++++++++++
 tools/golang/xenlight/test/xeninfo/freememory.go  | 25 ++++++++++++++
 tools/golang/xenlight/test/xeninfo/maxcpu.c       | 18 ++++++++++
 tools/golang/xenlight/test/xeninfo/maxcpu.go      | 24 +++++++++++++
 tools/golang/xenlight/test/xeninfo/maxnodes.c     | 15 +++++++++
 tools/golang/xenlight/test/xeninfo/maxnodes.go    | 24 +++++++++++++
 tools/golang/xenlight/test/xeninfo/onlinecpu.c    | 18 ++++++++++
 tools/golang/xenlight/test/xeninfo/onlinecpu.go   | 24 +++++++++++++
 tools/golang/xenlight/test/xeninfo/physinfo.c     | 32 ++++++++++++++++++
 tools/golang/xenlight/test/xeninfo/physinfo.go    | 32 ++++++++++++++++++
 tools/golang/xenlight/test/xeninfo/print.h        | 22 ++++++++++++
 tools/golang/xenlight/test/xeninfo/versioninfo.c  | 22 ++++++++++++
 tools/golang/xenlight/test/xeninfo/versioninfo.go | 28 ++++++++++++++++
 tools/golang/xenlight/test/xeninfo/xenlight.go    |  1 +
 17 files changed, 416 insertions(+)
 create mode 100644 tools/golang/xenlight/test/xeninfo/Makefile
 create mode 100644 tools/golang/xenlight/test/xeninfo/dominfo.c
 create mode 100644 tools/golang/xenlight/test/xeninfo/dominfo.go
 create mode 100644 tools/golang/xenlight/test/xeninfo/freememory.c
 create mode 100644 tools/golang/xenlight/test/xeninfo/freememory.go
 create mode 100644 tools/golang/xenlight/test/xeninfo/maxcpu.c
 create mode 100644 tools/golang/xenlight/test/xeninfo/maxcpu.go
 create mode 100644 tools/golang/xenlight/test/xeninfo/maxnodes.c
 create mode 100644 tools/golang/xenlight/test/xeninfo/maxnodes.go
 create mode 100644 tools/golang/xenlight/test/xeninfo/onlinecpu.c
 create mode 100644 tools/golang/xenlight/test/xeninfo/onlinecpu.go
 create mode 100644 tools/golang/xenlight/test/xeninfo/physinfo.c
 create mode 100644 tools/golang/xenlight/test/xeninfo/physinfo.go
 create mode 100644 tools/golang/xenlight/test/xeninfo/print.h
 create mode 100644 tools/golang/xenlight/test/xeninfo/versioninfo.c
 create mode 100644 tools/golang/xenlight/test/xeninfo/versioninfo.go
 create mode 120000 tools/golang/xenlight/test/xeninfo/xenlight.go

diff --git a/tools/golang/xenlight/test/xeninfo/Makefile b/tools/golang/xenlight/test/xeninfo/Makefile
new file mode 100644
index 0000000..aae5544
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/Makefile
@@ -0,0 +1,41 @@
+XEN_ROOT = $(CURDIR)/../../../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+GO ?= go
+
+TESTS = dominfo freememory maxcpu onlinecpu physinfo versioninfo
+CBINARIES = $(TESTS:%=%-c)
+GOBINARIES = $(TESTS:%=%-go)
+
+CFLAGS += -Werror
+CFLAGS += $(CFLAGS_libxentoollog)
+CFLAGS += $(CFLAGS_libxenlight)
+
+LDLIBS += $(LDLIBS_libxentoollog)
+LDLIBS += $(LDLIBS_libxenlight)
+
+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) -o $@ $< $(LDLIBS)
+
+%-go: %.go
+	GOPATH=$(XEN_ROOT)/tools/golang $(GO) build -o $@ $<
+
+clean:
+	rm -f *-c
+	rm -f *-go
+	rm -f *.output
diff --git a/tools/golang/xenlight/test/xeninfo/dominfo.c b/tools/golang/xenlight/test/xeninfo/dominfo.c
new file mode 100644
index 0000000..2c63583
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/dominfo.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+    libxl_ctx *context;
+    libxl_dominfo info;
+    int err;
+    long cpu_time;
+    context = create_context();
+    libxl_dominfo_init(&info);
+    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));
+    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);
+
+    destroy_context(context);
+
+}
diff --git a/tools/golang/xenlight/test/xeninfo/dominfo.go b/tools/golang/xenlight/test/xeninfo/dominfo.go
new file mode 100644
index 0000000..bb9257b
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/dominfo.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"xenproject.org/xenlight"
+)
+
+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)
+
+}
diff --git a/tools/golang/xenlight/test/xeninfo/freememory.c b/tools/golang/xenlight/test/xeninfo/freememory.c
new file mode 100644
index 0000000..0fcaa1f
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/freememory.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+    libxl_ctx *context;
+    uint64_t free_memory;
+    int err;
+
+    context = create_context();
+
+    err = libxl_get_free_memory(context, &free_memory);
+    if (err < 0)
+    {
+        printf("%d\n", err);
+    }
+    else
+    {
+        printf("%lu\n", free_memory);
+    }
+    destroy_context(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/xeninfo/freememory.go b/tools/golang/xenlight/test/xeninfo/freememory.go
new file mode 100644
index 0000000..2752bd3
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/freememory.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"xenproject.org/xenlight"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil {
+		os.Exit(-1)
+	}
+
+	defer ctx.Close()
+
+	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/xeninfo/maxcpu.c b/tools/golang/xenlight/test/xeninfo/maxcpu.c
new file mode 100644
index 0000000..a57bdb2
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/maxcpu.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+    libxl_ctx *context;
+    int max_cpus;
+
+    context = create_context();
+    max_cpus = libxl_get_max_cpus(context);
+    printf("%d\n", max_cpus);
+
+    destroy_context(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/xeninfo/maxcpu.go b/tools/golang/xenlight/test/xeninfo/maxcpu.go
new file mode 100644
index 0000000..92cd93d
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/maxcpu.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"xenproject.org/xenlight"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil {
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+
+	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/xeninfo/maxnodes.c b/tools/golang/xenlight/test/xeninfo/maxnodes.c
new file mode 100644
index 0000000..e072c3e
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/maxnodes.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+int main(){
+
+    libxl_ctx *context;
+    context = create_context();
+
+    int max_nodes = libxl_get_max_nodes(context);
+    printf("%d\n", max_nodes);
+
+    destroy_context(context);
+}
+
diff --git a/tools/golang/xenlight/test/xeninfo/maxnodes.go b/tools/golang/xenlight/test/xeninfo/maxnodes.go
new file mode 100644
index 0000000..da9b495
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/maxnodes.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"xenproject.org/xenlight"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil {
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+
+	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/xeninfo/onlinecpu.c b/tools/golang/xenlight/test/xeninfo/onlinecpu.c
new file mode 100644
index 0000000..46939d6
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/onlinecpu.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+    libxl_ctx *context;
+    int online_cpus;
+    context = create_context();
+
+    online_cpus = libxl_get_online_cpus(context);
+    printf("%d\n", online_cpus);
+
+    destroy_context(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/xeninfo/onlinecpu.go b/tools/golang/xenlight/test/xeninfo/onlinecpu.go
new file mode 100644
index 0000000..b6d1da7
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/onlinecpu.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"xenproject.org/xenlight"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil {
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+
+	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/xeninfo/physinfo.c b/tools/golang/xenlight/test/xeninfo/physinfo.c
new file mode 100644
index 0000000..541a730
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/physinfo.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+    libxl_ctx *context;
+    libxl_physinfo info;
+    int err;
+    int i;
+    context = create_context();
+    libxl_physinfo_init(&info);
+    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(i = 0; i < 8; i++){
+        printf("%u\n", info.hw_cap[i]);
+    }
+
+    libxl_physinfo_init(&info);
+    destroy_context(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/xeninfo/physinfo.go b/tools/golang/xenlight/test/xeninfo/physinfo.go
new file mode 100644
index 0000000..cf7bdd4
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/physinfo.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"xenproject.org/xenlight"
+)
+
+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/xeninfo/print.h b/tools/golang/xenlight/test/xeninfo/print.h
new file mode 100644
index 0000000..dd6c987
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/print.h
@@ -0,0 +1,22 @@
+xentoollog_logger_stdiostream *logger;
+
+static inline char *bool_to_string(bool a){
+    return (a ? "true" : "false");
+}
+
+static inline libxl_ctx *create_context(void){
+    libxl_ctx *context;
+    logger = xtl_createlogger_stdiostream(stderr,
+            XTL_ERROR, 0);
+    libxl_ctx_alloc(&context, LIBXL_VERSION, 0 , (xentoollog_logger*)logger);
+    return context;
+}
+
+static inline int destroy_context(libxl_ctx *context){
+    int err = libxl_ctx_free(context);
+    if (err != 0)
+        return err;
+    xtl_logger_destroy((xentoollog_logger*)logger);
+    return err;
+
+}
diff --git a/tools/golang/xenlight/test/xeninfo/versioninfo.c b/tools/golang/xenlight/test/xeninfo/versioninfo.c
new file mode 100644
index 0000000..113bcea
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/versioninfo.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+    libxl_ctx *context;
+    const libxl_version_info * info;
+    context = create_context();
+    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);
+
+    destroy_context(context);
+
+}
diff --git a/tools/golang/xenlight/test/xeninfo/versioninfo.go b/tools/golang/xenlight/test/xeninfo/versioninfo.go
new file mode 100644
index 0000000..5545472
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/versioninfo.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"xenproject.org/xenlight"
+)
+
+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)
+
+}
diff --git a/tools/golang/xenlight/test/xeninfo/xenlight.go b/tools/golang/xenlight/test/xeninfo/xenlight.go
new file mode 120000
index 0000000..693da7b
--- /dev/null
+++ b/tools/golang/xenlight/test/xeninfo/xenlight.go
@@ -0,0 +1 @@
+../../xenlight.go/usr/local/go/src/xenproject.org/xenlight/xenlight.go
\ No newline at end of file
-- 
2.7.3


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

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

* [PATCH v4 06/14] golang/xenlight: Implement libxl_bitmap and helper operations
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (3 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 08/14] golang/xenlight: Implement cpupool operations Ronald Rojas
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, George Dunlap, xen-devel

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>

---

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com

---
---
 tools/golang/xenlight/xenlight.go | 167 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 167 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 34c3050..eb2b3cf 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -129,6 +129,20 @@ func (chwcap C.libxl_hwcap) toGo() (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
  *
@@ -298,6 +312,159 @@ func (cdi *C.libxl_dominfo) toGo() (di *Dominfo) {
 }
 
 /*
+ * Bitmap operations
+ */
+
+// Return a Go bitmap which is a copy of the referred C bitmap.
+func (cbm C.libxl_bitmap) toGo() (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) toC() (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.3


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

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

* [PATCH v4 08/14] golang/xenlight: Implement cpupool operations
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (4 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 06/14] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 09/14] golang/xenlight: Implement Domain operations Ronald Rojas
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, George Dunlap, xen-devel

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>

---

Changes

- Renamed CToGo functions as toGo

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 237 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 237 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index d4a6bc1..85e4c78 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -373,6 +373,243 @@ 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) toGo() (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.toGo()
+
+	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].toGo()
+
+		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.toGo()
+
+	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.toC()
+	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.toC()
+	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.toC()
+	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.3


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

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

* [PATCH v4 09/14] golang/xenlight: Implement Domain operations
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (5 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 08/14] golang/xenlight: Implement cpupool operations Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-04-05 10:23   ` George Dunlap
  2017-03-16 19:08 ` [PATCH v4 10/14] golang/xenlight: Implement Vcpuinfo and ListVcpu Ronald Rojas
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

Add calls for the following Domain related functionality
- libxl_domain_pause
- libxl_domain_shutdown
- libxl_domain_reboot
- libxl_list_domain

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 70 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 85e4c78..5a1e273 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -956,3 +956,73 @@ func (Ctx *Context) DomainUnpause(Id Domid) (err error) {
 	}
 	return
 }
+
+//int libxl_domain_pause(libxl_ctx *ctx, uint32_t domain);
+func (Ctx *Context) DomainPause(id Domid) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_domain_pause(Ctx.ctx, C.uint32_t(id))
+
+	if ret != 0 {
+		err = Error(-ret)
+	}
+	return
+}
+
+//int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid);
+func (Ctx *Context) DomainShutdown(id Domid) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_domain_shutdown(Ctx.ctx, C.uint32_t(id))
+
+	if ret != 0 {
+		err = Error(-ret)
+	}
+	return
+}
+
+//int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid);
+func (Ctx *Context) DomainReboot(id Domid) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	ret := C.libxl_domain_reboot(Ctx.ctx, C.uint32_t(id))
+
+	if ret != 0 {
+		err = Error(-ret)
+	}
+	return
+}
+
+//libxl_dominfo * libxl_list_domain(libxl_ctx*, int *nb_domain_out);
+//void libxl_dominfo_list_free(libxl_dominfo *list, int nb_domain);
+func (Ctx *Context) ListDomain() (glist []Dominfo) {
+	err := Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var nbDomain C.int
+	clist := C.libxl_list_domain(Ctx.ctx, &nbDomain)
+	defer C.libxl_dominfo_list_free(clist, nbDomain)
+
+	if int(nbDomain) == 0 {
+		return
+	}
+
+	gslice := (*[1 << 30]C.libxl_dominfo)(unsafe.Pointer(clist))[:nbDomain:nbDomain]
+	for i := range gslice {
+		info := gslice[i].toGo()
+		glist = append(glist, *info)
+	}
+
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 10/14] golang/xenlight: Implement Vcpuinfo and ListVcpu
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (6 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 09/14] golang/xenlight: Implement Domain operations Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 11/14] golang/xenlight: Implement get console path operations Ronald Rojas
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

Include Golang version of libxl_vcpu_info
as VcpuInfo

Add a Golang call for libxl_list_vcpu as
ListVcpu

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 54 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 5a1e273..61d7f8f 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -1026,3 +1026,57 @@ func (Ctx *Context) ListDomain() (glist []Dominfo) {
 
 	return
 }
+
+type Vcpuinfo struct {
+	Vcpuid     uint32
+	Cpu        uint32
+	Online     bool
+	Blocked    bool
+	Running    bool
+	VCpuTime   time.Duration
+	Cpumap     Bitmap
+	CpumapSoft Bitmap
+}
+
+func (cvci C.libxl_vcpuinfo) toGo() (gvci Vcpuinfo) {
+	gvci.Vcpuid = uint32(cvci.vcpuid)
+	gvci.Cpu = uint32(cvci.cpu)
+	gvci.Online = bool(cvci.online)
+	gvci.Blocked = bool(cvci.blocked)
+	gvci.Running = bool(cvci.running)
+	gvci.VCpuTime = time.Duration(cvci.vcpu_time)
+	gvci.Cpumap = cvci.cpumap.toGo()
+	gvci.CpumapSoft = cvci.cpumap_soft.toGo()
+
+	return
+}
+
+//libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
+//				int *nb_vcpu, int *nr_cpus_out);
+//void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int nr_vcpus);
+func (Ctx *Context) ListVcpu(id Domid) (glist []Vcpuinfo) {
+	err := Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var nbVcpu C.int
+	var nrCpu C.int
+
+	clist := C.libxl_list_vcpu(Ctx.ctx, C.uint32_t(id), &nbVcpu, &nrCpu)
+	defer C.libxl_vcpuinfo_list_free(clist, nbVcpu)
+
+	if int(nbVcpu) == 0 {
+		return
+	}
+
+	gslice := (*[1 << 30]C.libxl_vcpuinfo)(unsafe.Pointer(clist))[:nbVcpu:nbVcpu]
+
+	for i := range gslice {
+		info := gslice[i].toGo()
+
+		glist = append(glist, info)
+	}
+
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 11/14] golang/xenlight: Implement get console path operations
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (7 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 10/14] golang/xenlight: Implement Vcpuinfo and ListVcpu Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-04-05 11:04   ` George Dunlap
  2017-03-16 19:08 ` [PATCH v4 12/14] golang/xenlight: Created boilerplate code for device related structs Ronald Rojas
                   ` (4 subsequent siblings)
  13 siblings, 1 reply; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

Implement Golang enumeration of libxl_console_type
as ConsoleType

Implement the following libxl functions:
- libxl_console_get_tty
- libxl_primary_console_get_tty

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 57 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 61d7f8f..d520f74 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -1080,3 +1080,60 @@ func (Ctx *Context) ListVcpu(id Domid) (glist []Vcpuinfo) {
 
 	return
 }
+
+type ConsoleType int
+
+const (
+	ConsoleTypeUnknown = ConsoleType(C.LIBXL_CONSOLE_TYPE_UNKNOWN)
+	ConsoleTypeSerial  = ConsoleType(C.LIBXL_CONSOLE_TYPE_SERIAL)
+	ConsoleTypePV      = ConsoleType(C.LIBXL_CONSOLE_TYPE_PV)
+)
+
+func (ct ConsoleType) String() (str string) {
+	cstr := C.libxl_console_type_to_string(C.libxl_console_type(ct))
+	str = C.GoString(cstr)
+
+	return
+}
+
+//int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num,
+//libxl_console_type type, char **path);
+func (Ctx *Context) ConsoleGetTty(id Domid, consNum int, conType ConsoleType) (path string, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var cpath *C.char
+	defer C.free(cpath)
+	ret := C.libxl_console_get_tty(Ctx.ctx, C.uint32_t(id), C.int(consNum), C.libxl_console_type(conType), &cpath)
+
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	path = C.GoString(cpath)
+	return
+}
+
+//int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm,
+//					char **path);
+func (Ctx *Context) PrimaryConsoleGetTty(domid uint32) (path string, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	var cpath *C.char
+	ret := C.libxl_primary_console_get_tty(Ctx.ctx, C.uint32_t(domid), &cpath)
+	defer C.free(cpath)
+
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+
+	path = C.GoString(cpath)
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 12/14] golang/xenlight: Created boilerplate code for device related structs
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (8 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 11/14] golang/xenlight: Implement get console path operations Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-04-05 11:13   ` George Dunlap
  2017-03-16 19:08 ` [PATCH v4 13/14] golang/xenlight: Implement ActionOnShutdown and DomainConfig Ronald Rojas
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

Created boilerplate struct and toC methods for the
following structs:
- KeyValueList
- DomainBuildInfo
- DeviceNic
- DevicePci
- DeviceRdm
- DeviceDtdev
- DeviceVfb
- DeviceVkb
- DeviceVtpm
- DeviceChannel
- DeviceUsbctrl
- DeviceUsbdev

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
This specific patch constains mostly boilerplate code
that will be implemented in patches later down the road.

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 162 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 162 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index d520f74..8b5ca38 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -1137,3 +1137,165 @@ func (Ctx *Context) PrimaryConsoleGetTty(domid uint32) (path string, err error)
 	path = C.GoString(cpath)
 	return
 }
+
+type Defbool string
+
+type KeyValueList []string
+
+type ckeyvaluelist struct {
+	clist C.libxl_key_value_list
+}
+
+func (clist ckeyvaluelist) toGo(glist KeyValueList) {
+	return
+}
+
+type DomainCreateInfo struct {
+	Type              DomainType
+	Hap               Defbool
+	Oos               Defbool
+	ssidref           uint32
+	ssid_label        string
+	name              string
+	uuid              Uuid
+	Xsdata            KeyValueList
+	Platformdata      KeyValueList
+	Poolid            uint32
+	PoolName          string
+	RunHotplugScripts Defbool
+	Pvh               Defbool
+	DriverDomain      Defbool
+}
+
+func (dci DomainCreateInfo) toC() (cci C.libxl_domain_create_info) {
+
+	return
+}
+
+type TscMode int
+
+const (
+	TscModeDefault        = TscMode(C.LIBXL_TSC_MODE_DEFAULT)
+	TscModeAlwaysEmulate  = TscMode(C.LIBXL_TSC_MODE_ALWAYS_EMULATE)
+	TscModeNative         = TscMode(C.LIBXL_TSC_MODE_NATIVE)
+	TscModeNativeParavirt = TscMode(C.LIBXL_TSC_MODE_NATIVE_PARAVIRT)
+)
+
+func (tm TscMode) String() (str string) {
+	cstr := C.libxl_tsc_mode_to_string(C.libxl_tsc_mode(tm))
+	str = C.GoString(cstr)
+
+	return
+}
+
+type CpuidPolicy struct {
+	//FIXME: Implement struct
+}
+
+//FIXME Create toGo function for CpuidPolicy
+
+type DomainBuildInfo struct {
+	MaxVcpus         int
+	AvailVcpus       Bitmap
+	Cpumap           Bitmap
+	Nodemap          Bitmap
+	VcpuHardAffinity []Bitmap
+	VcpuSoftAffinity []Bitmap
+	NumaPlacement    Defbool
+	TscMode          TscMode
+	MaxMemkb         MemKB
+	TargetMemkb      MemKB
+	VideoMemkb       MemKB
+	ShadowMemkb      MemKB
+	RtcTimeoffset    uint32
+	ExecSsidref      uint32
+	ExecSsidLabel    string
+	localTime        Defbool
+	DisableMigrate   Defbool
+	Cpuid            []CpuidPolicy
+	blkdevStart      string
+}
+
+func (gdbi DomainBuildInfo) toC() (cdbi C.libxl_domain_build_info) {
+	return
+}
+
+type DeviceNic struct {
+	//FIXME: complete struct
+}
+
+func (gdn DeviceNic) toC() (cdn C.libxl_device_nic) {
+	return
+}
+
+type DevicePci struct {
+	//FIXME: complete struct
+}
+
+func (gdp DevicePci) toC() (cdp C.libxl_device_pci) {
+	return
+}
+
+type DeviceRdm struct {
+	//FIXME: complete struct
+}
+
+func (gdr DeviceRdm) toC() (cdr C.libxl_device_rdm) {
+	return
+}
+
+type DeviceDtdev struct {
+	//FIXME: complete struct
+}
+
+func (gdd DeviceDtdev) toC() (cdd C.libxl_device_dtdev) {
+	return
+}
+
+type DeviceVfb struct {
+	//FIXME: complete struct
+}
+
+func (gdv DeviceVfb) toC() (cdv C.libxl_device_vfb) {
+	return
+}
+
+type DeviceVkb struct {
+	//FIXME: complete struct
+}
+
+func (gdv DeviceVkb) toC() (cdv C.libxl_device_vkb) {
+	return
+}
+
+type DeviceVtpm struct {
+	//FIXME: complete struct
+}
+
+func (gdv DeviceVtpm) toC() (cdv C.libxl_device_vtpm) {
+	return
+}
+
+type DeviceChannel struct {
+	//FIXME: complete struct
+}
+
+func (gdc DeviceChannel) toC() (cdc C.libxl_device_channel) {
+	return
+}
+
+type DeviceUsbctrl struct {
+	//FIXME: complete struct
+}
+
+func (gdu DeviceUsbctrl) toC() (cdu C.libxl_device_usbctrl) {
+	return
+}
+
+type DeviceUsbdev struct {
+	//FIXME: complete struct
+}
+
+func (gdu DeviceUsbdev) toC() (cdu C.libxl_device_usbdev) {
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 13/14] golang/xenlight: Implement ActionOnShutdown and DomainConfig
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (9 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 12/14] golang/xenlight: Created boilerplate code for device related structs Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-16 19:08 ` [PATCH v4 14/14] golang/xenlight: Implement domain create/destroy operations Ronald Rojas
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

Applied enumeration and implemented toC method for ActionOnShutdown

Implemented struct and implemented toC method for DomainConfig

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---
CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 61 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 8b5ca38..ed76fec 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -1299,3 +1299,64 @@ type DeviceUsbdev struct {
 func (gdu DeviceUsbdev) toC() (cdu C.libxl_device_usbdev) {
 	return
 }
+
+type ActionOnShutdown int
+
+const (
+	ActionOnShutdownDestroy         = C.LIBXL_ACTION_ON_SHUTDOWN_DESTROY
+	ActionOnShutdownRestart         = C.LIBXL_ACTION_ON_SHUTDOWN_RESTART
+	ActionOnShutdownRestartRename   = C.LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME
+	ActionOnShutdownPreserve        = C.LIBXL_ACTION_ON_SHUTDOWN_PRESERVE
+	ActionOnShutdownCoredumpDestroy = C.LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY
+	ActionOnShutdownCoredumRestart  = C.LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART
+	ActionOnShutdownSoftReset       = C.LIBXL_ACTION_ON_SHUTDOWN_SOFT_RESET
+)
+
+func (aos ActionOnShutdown) String() (str string) {
+	cstr := C.libxl_action_on_shutdown_to_string(C.libxl_action_on_shutdown(aos))
+
+	str = C.GoString(cstr)
+
+	return
+}
+
+func (gaos ActionOnShutdown) toC() (caos C.libxl_action_on_shutdown) {
+	caos = C.libxl_action_on_shutdown(gaos)
+	return
+}
+
+type DomainConfig struct {
+	CInfo DomainCreateInfo
+	BInfo DomainBuildInfo
+
+	Disks   []DeviceNic
+	Pcidevs []DevicePci
+	Rdms    []DeviceRdm
+	Dtdevs  []DeviceDtdev
+	Vftbs   []DeviceVfb
+	Vkbs    []DeviceVkb
+	Vtpms   []DeviceVtpm
+
+	Channels []DeviceChannel
+	Usbctrls []DeviceUsbctrl
+	Usbdevs  []DeviceUsbdev
+
+	OnPoweroff  ActionOnShutdown
+	OnReboot    ActionOnShutdown
+	OnWatchdog  ActionOnShutdown
+	OnCrash     ActionOnShutdown
+	OnSoftReset ActionOnShutdown
+}
+
+func (gdc DomainConfig) toC() (cdc C.libxl_domain_config) {
+	cdc.c_info = gdc.CInfo.toC()
+	cdc.b_info = gdc.BInfo.toC()
+	//FIXME: Implement converting device information
+
+	cdc.on_poweroff = gdc.OnPoweroff.toC()
+	cdc.on_reboot = gdc.OnReboot.toC()
+	cdc.on_watchdog = gdc.OnWatchdog.toC()
+	cdc.on_crash = gdc.OnCrash.toC()
+	cdc.on_soft_reset = gdc.OnSoftReset.toC()
+	return
+}
-- 
2.7.3


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

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

* [PATCH v4 14/14] golang/xenlight: Implement domain create/destroy operations
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (10 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 13/14] golang/xenlight: Implement ActionOnShutdown and DomainConfig Ronald Rojas
@ 2017-03-16 19:08 ` Ronald Rojas
  2017-03-20 14:45 ` [PATCH v4 01/14] golang/xenlight: Create stub package George Dunlap
  2017-03-20 17:51 ` George Dunlap
  13 siblings, 0 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-16 19:08 UTC (permalink / raw)
  Cc: Ronald Rojas, wei.liu2, ian.jackson, george.dunlap, xen-devel

Implemented DomainCreateNew and DomainDestroy methods

Signed-off-by: Ronald Rojas <ronladred@gmail.com>
---

CC: xen-devel@lists.xen.org
CC: george.dunlap@citrix.com
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
---
 tools/golang/xenlight/xenlight.go | 43 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index ed76fec..c9774cf 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -1360,3 +1360,46 @@ func (gdc DomainConfig) toC() (cdc C.libxl_domain_config) {
 	cdc.on_soft_reset = gdc.OnSoftReset.toC()
 	return
 }
+
+//int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
+//				uint32_t *domid,
+//				const libxl_asyncop_how *ao_how,
+//				const libxl_asyncprogress_how *aop_console_how)
+//				LIBXL_EXTERNAL_CALLERS_ONLY;
+func (Ctx *Context) DomainCreateNew(dconfig DomainConfig) (id Domid, err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+	cconfig := dconfig.toC()
+
+	var cid C.uint32_t
+	//FIXME: create async caller
+	ret := C.libxl_domain_create_new(Ctx.ctx, &cconfig, &cid, nil, nil)
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+	id = Domid(cid)
+
+	return
+}
+
+//int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
+//			const libxl_asyncop_how *ao_how)
+//			LIBXL_EXTERNAL_CALLERS_ONLY;
+func (Ctx *Context) DomainDestroy(id Domid) (err error) {
+	err = Ctx.CheckOpen()
+	if err != nil {
+		return
+	}
+
+	//FIXME: create async caller
+	ret := C.libxl_domain_destroy(Ctx.ctx, C.uint32_t(id), nil)
+	if ret != 0 {
+		err = Error(-ret)
+		return
+	}
+	return
+
+}
-- 
2.7.3


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

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

* Re: [PATCH v4 01/14] golang/xenlight: Create stub package
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (11 preceding siblings ...)
  2017-03-16 19:08 ` [PATCH v4 14/14] golang/xenlight: Implement domain create/destroy operations Ronald Rojas
@ 2017-03-20 14:45 ` George Dunlap
  2017-03-23 15:36   ` Ronald Rojas
  2017-03-20 17:51 ` George Dunlap
  13 siblings, 1 reply; 26+ messages in thread
From: George Dunlap @ 2017-03-20 14:45 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> 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>
> Signed-off-by: George Dunlap <george.dunlap@citrix.com>

Almost there.  One comment on one of the last changes...

> +/*
> + * Types: Builtins
> + */
> +type Context struct {
> +       ctx *C.libxl_ctx
> +}

The way the libxl interface here is designed, in theory a single
program could have multiple instances of libxl_ctx open at the same
time; this interface follows that lead, in the sense that you could
certainly write something like this:

var contexts [10]xenlight.Ctx

for i := range contexts {
  err = context[i].Open
  ...
}

[do stuff]

for i := range context {
  err = context[i].Close()
  ...
}

Unfortunately...

> +
> +/*
> + * Context
> + */
> +var Ctx Context
> +
> +var logger *C.xentoollog_logger_stdiostream
> +
> +func (Ctx *Context) IsOpen() bool {
> +       return Ctx.ctx != nil
> +}
> +
> +func (Ctx *Context) Open() (err error) {
> +       if Ctx.ctx != nil {
> +               return
> +       }
> +
> +       logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_ERROR, 0)

...this means that in the above code you'd leak 9 of the 10 loggers, and...

> +       ret := C.libxl_ctx_alloc(&Ctx.ctx, C.LIBXL_VERSION,
> +               0, unsafe.Pointer(logger))
> +
> +       if ret != 0 {
> +               err = fmt.Errorf("Error: %d", -ret)
> +       }
> +       return
> +}
> +
> +func (Ctx *Context) Close() (err error) {
> +       ret := C.libxl_ctx_free(Ctx.ctx)
> +       Ctx.ctx = nil
> +
> +       if ret != 0 {
> +               err = fmt.Errorf("Error: %d", -ret)
> +       }
> +       C.xtl_logger_destroy(unsafe.Pointer(logger))

...at this point you'd repeatedly call destroy() on that 9th pointer
value 10 times, which usually leads to not very entertaining results.

I think we want xenlight.Ctx to contain all the information needed to
open and close it; as long as we're creating a logger automatically,
we should store the pointer to the logger in the Ctx struct.

We should also set the pointer to nil after calling
xtl_logger_destroy() to prevent use-after-free bugs.

(Yay lack of garbage collection again.)

 -George

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

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

* Re: [PATCH v4 02/14] golang/xenlight: Add error constants and standard handling
  2017-03-16 19:08 ` [PATCH v4 02/14] golang/xenlight: Add error constants and standard handling Ronald Rojas
@ 2017-03-20 15:41   ` George Dunlap
  0 siblings, 0 replies; 26+ messages in thread
From: George Dunlap @ 2017-03-20 15:41 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> 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>

FYI, My response to v2 meant to indicate that once you had fixed the
`go fmt` errors (which you have now done), you could add my
Reviewed-by -- which means, putting it here under your SoB. :-)

I can also do that on check-in, but if you end up re-sending it's
normal practice to add it yourself.

 -George

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

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

* Re: [PATCH v4 03/14] golang/xenlight: Add host-related functionality
  2017-03-16 19:08 ` [PATCH v4 03/14] golang/xenlight: Add host-related functionality Ronald Rojas
@ 2017-03-20 15:50   ` George Dunlap
  0 siblings, 0 replies; 26+ messages in thread
From: George Dunlap @ 2017-03-20 15:50 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> 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>
> ---
> Changes since last version
>
> - Used defer for libxl_physinfo_dispose

You say you did this, but...

> +//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
> +       C.libxl_physinfo_init(&cphys)
> +
> +       ret := C.libxl_get_physinfo(Ctx.ctx, &cphys)
> +
> +       if ret < 0 {
> +               err = Error(ret)
> +               return
> +       }
> +       physinfo = cphys.toGo()
> +       C.libxl_physinfo_dispose(&cphys)

...the code looks the same as before.  Did you forge to / mix up a commit?

 -George

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

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

* Re: [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause
  2017-03-16 19:08 ` [PATCH v4 04/14] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
@ 2017-03-20 15:57   ` George Dunlap
  0 siblings, 0 replies; 26+ messages in thread
From: George Dunlap @ 2017-03-20 15:57 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> 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>
> ---
> Changes since last version
>
> - Formating fixes
>
> - used defer for libxl_dominfo_dispose
>
> - Removed unnessary unsafe.Pointer() casts.
>
> CC: xen-devel@lists.xen.org
> CC: george.dunlap@citrix.com
> CC: ian.jackson@eu.citrix.com
> CC: wei.liu2@citrix.com
>
> ---
> ---
>  tools/golang/xenlight/xenlight.go | 136 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 133 insertions(+), 3 deletions(-)
>
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index 785eaaf..34c3050 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -33,6 +33,7 @@ import "C"
>
>  import (
>         "fmt"
> +       "time"
>         "unsafe"
>  )
>
> @@ -102,13 +103,19 @@ var errors = [...]string{
>   * Types: Builtins
>   */
>
> +type Domid uint32
> +
> +type MemKB uint64
> +
> +type Uuid C.libxl_uuid
> +
>  type Context struct {
>         ctx *C.libxl_ctx
>  }
>
>  type Hwcap []C.uint32_t
>
> -func (chwcap C.libxl_hwcap) CToGo() (ghwcap Hwcap) {
> +func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) {
>         // Alloc a Go slice for the bytes
>         size := 8
>         ghwcap = make([]C.uint32_t, size)
> @@ -161,7 +168,7 @@ func (cphys *C.libxl_physinfo) toGo() (physinfo *Physinfo) {
>         physinfo.SharingFreedPages = uint64(cphys.sharing_freed_pages)
>         physinfo.SharingUsedFrames = uint64(cphys.sharing_used_frames)
>         physinfo.NrNodes = uint32(cphys.nr_nodes)
> -       physinfo.HwCap = cphys.hw_cap.CToGo()
> +       physinfo.HwCap = cphys.hw_cap.toGo()

Oh -- looks like you accidentally added the changes intended for the
last patch to this patch.

Move this (and the defer libxl_physinfo_dispose) to the previous
patch, and you can add:

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

to both.

Thanks,
 -George

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

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

* Re: [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions
  2017-03-16 19:08 ` [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions Ronald Rojas
@ 2017-03-20 17:49   ` George Dunlap
  2017-03-20 18:15     ` Ian Jackson
  0 siblings, 1 reply; 26+ messages in thread
From: George Dunlap @ 2017-03-20 17:49 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> wrote:
> Create tests for the following functions:
> - GetVersionInfo
> - GetPhysinfo
> - GetDominfo
> - GetMaxCpus
> - GetOnlineCpus
> - GetMaxNodes
> - GetFreeMemory
>
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> Signed-off-by: George Dunlap <george.dunlap@citrix.com>
>
> ---
> changes since last version
>
> - created CFLAGS and LDLIBS variables to build test C
> files with required dependencies.
>
> - created create_context and destroy_context function
> for tests to create/destroy libxl_ctx and xenlogger
>
> - Formating changes
>
> - Removed stale comments
>
> - Removed redundant error checks in Golang tests
>
> - Negated printed error code in freememory.go

Looks a lot better, thanks!  Still some details that need to be corrected.

> diff --git a/tools/golang/xenlight/test/xeninfo/dominfo.go b/tools/golang/xenlight/test/xeninfo/dominfo.go
> new file mode 100644
> index 0000000..bb9257b
> --- /dev/null
> +++ b/tools/golang/xenlight/test/xeninfo/dominfo.go
> @@ -0,0 +1,31 @@
> +package main
> +
> +import (
> +       "fmt"
> +       "os"
> +       "xenproject.org/xenlight"

This needs to be changed to use the new name:
golang.xenproject.org/xenlight (in all the .go files).

Also, please do at least a build test for each patch before you send it.

> +)
> +
> +func main() {
> +       ctx := xenlight.Ctx
> +       err := ctx.Open()
> +       if err != nil {
> +               os.Exit(-1)
> +       }
> +       defer ctx.Close()
> +       info, err := ctx.DomainInfo(0)

Just noticed -- in this case, if DomainInfo fails, you simply exit
without printing anything (both for golang and the C versions); but in
most of the other cases, you actually print the return value.

Is there a reason not to print the error value here, but to print it
for the others?

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

Again, why is there a line here that's commented out?  (I asked this
last time and I didn't see a response.)


> diff --git a/tools/golang/xenlight/test/xeninfo/freememory.go b/tools/golang/xenlight/test/xeninfo/freememory.go
> new file mode 100644
> index 0000000..2752bd3
> --- /dev/null
> +++ b/tools/golang/xenlight/test/xeninfo/freememory.go
> @@ -0,0 +1,25 @@
> +package main
> +
> +import (
> +       "fmt"
> +       "os"
> +       "xenproject.org/xenlight"
> +)
> +
> +func main() {
> +       ctx := xenlight.Ctx
> +       err := ctx.Open()
> +       if err != nil {
> +               os.Exit(-1)
> +       }
> +
> +       defer ctx.Close()
> +
> +       free_memory, err := ctx.GetFreeMemory()
> +       if err != nil {
> +               fmt.Printf("-%d\n", err)

Hmm, so this isn't quite right.  First of all, normally you'd try to
negate the actual value, rather than just adding a '-' in front of it;
but of course you can't do that simply here because err is an
interface of type 'error'; but that shows the other way this code is a
bit fragile, in that it assumes that GetFreeMemory() will return an
error of type xenlight.Error, and not (say) some other kind of error
-- even though we actually return the results of fmt.Errorf()
occasionally (at least for some methods).

I think even for this kind of testing code, it would be better to do a
type assertion, thus:

    if err != nil {
        val, ok := err.(xenlight.Error)
        if ! ok {
            fmt.Printf("Error %v\n", err)
        } else {
            fmt.Printf("%d\n", -val)
        }
    }

Also, you need to do this for all the tests which attempt to print the
return value of the error.

Alternately, you could make all the unit tests behave like dominfo.*,
and simply exit without comment on an error.

> diff --git a/tools/golang/xenlight/test/xeninfo/print.h b/tools/golang/xenlight/test/xeninfo/print.h
> new file mode 100644
> index 0000000..dd6c987
> --- /dev/null
> +++ b/tools/golang/xenlight/test/xeninfo/print.h
> @@ -0,0 +1,22 @@
> +xentoollog_logger_stdiostream *logger;

So here you define (rather than "declare") a global variable in a
header file.  This is generally frowned upon, and usually indicates
that you need to restructure the code somewhat.

I had a chat with Ian Jackson, and we agreed that it would be better
to create a file, maybe "test-common.c", that would contain this
variable, as well as the three functions below.

Then the header ("test-common.h") would contain *declarations* of the
variable (i.e., "extern xentoollog_logger_stdiostream *logger;") and
function prototypes.

The test-common.c file is small now, but it may grow as additional
functionality is needed.

The other thing you might consider, to further reduce the boilerplate
you have in each unit test file, is to also include a libxl_ctx
pointer in test-common; and have create_context() simply return an int
(0 for success, -1 for failure).

> +
> +static inline char *bool_to_string(bool a){
> +    return (a ? "true" : "false");
> +}
> +
> +static inline libxl_ctx *create_context(void){
> +    libxl_ctx *context;
> +    logger = xtl_createlogger_stdiostream(stderr,
> +            XTL_ERROR, 0);
> +    libxl_ctx_alloc(&context, LIBXL_VERSION, 0 , (xentoollog_logger*)logger);
> +    return context;
> +}
> +
> +static inline int destroy_context(libxl_ctx *context){
> +    int err = libxl_ctx_free(context);
> +    if (err != 0)
> +        return err;
> +    xtl_logger_destroy((xentoollog_logger*)logger);
> +    return err;
> +
> +}

> diff --git a/tools/golang/xenlight/test/xeninfo/xenlight.go b/tools/golang/xenlight/test/xeninfo/xenlight.go
> new file mode 120000
> index 0000000..693da7b
> --- /dev/null
> +++ b/tools/golang/xenlight/test/xeninfo/xenlight.go
> @@ -0,0 +1 @@
> +../../xenlight.go/usr/local/go/src/xenproject.org/xenlight/xenlight.go

What's this file for?

Thanks,
 -George

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

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

* Re: [PATCH v4 01/14] golang/xenlight: Create stub package
  2017-03-16 19:08 [PATCH v4 01/14] golang/xenlight: Create stub package Ronald Rojas
                   ` (12 preceding siblings ...)
  2017-03-20 14:45 ` [PATCH v4 01/14] golang/xenlight: Create stub package George Dunlap
@ 2017-03-20 17:51 ` George Dunlap
  2017-03-23 15:37   ` Ronald Rojas
  13 siblings, 1 reply; 26+ messages in thread
From: George Dunlap @ 2017-03-20 17:51 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> 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>
> Signed-off-by: George Dunlap <george.dunlap@citrix.com>
> ---
>
> Changes:
>
> - Added global logger variable and destroyed the logger instance
> when closing the context.
>
> - Whitespace fixes
>
> - Commented out CONFIG_GOLANG

> +# 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) $(CFLAGS_libxentoollog)" CGO_LDFLAGS="$(LDLIBS_libxenlight) $(LDLIBS_libxentoollog)-L$(XEN_XENLIGHT) -L$(XEN_LIBXENTOOLLOG)" GOPATH=$(XEN_GOPATH) $(GO) install -x $(XEN_GOCODE_URL)/xenlight

Also, you're missing a space between `$(LDLIBS_libxentoollog)` and
`-L$(XEN_XENLIGHT)`.  In the future please at least compile-test your
code.

Thanks,
 -George

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

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

* Re: [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions
  2017-03-20 17:49   ` George Dunlap
@ 2017-03-20 18:15     ` Ian Jackson
  2017-04-04 16:44       ` George Dunlap
  0 siblings, 1 reply; 26+ messages in thread
From: Ian Jackson @ 2017-03-20 18:15 UTC (permalink / raw)
  To: George Dunlap; +Cc: Ronald Rojas, Wei Liu, xen-devel

George Dunlap writes ("Re: [Xen-devel] [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions"):
> I had a chat with Ian Jackson, and we agreed that it would be better
> to create a file, maybe "test-common.c", that would contain this
> variable, as well as the three functions below.
> 
> Then the header ("test-common.h") would contain *declarations* of the
> variable (i.e., "extern xentoollog_logger_stdiostream *logger;") and
> function prototypes.
> 
> The test-common.c file is small now, but it may grow as additional
> functionality is needed.

Right.

> The other thing you might consider, to further reduce the boilerplate
> you have in each unit test file, is to also include a libxl_ctx
> pointer in test-common; and have create_context() simply return an int
> (0 for success, -1 for failure).

This would be nice.

You might also consider whether create_context would better simply
exit the program if it fails.  That avoids any possibility of error
handling bugs.  And maybe it should be called test_common_setup() ?
(Names are a matter of taste, though.)

Also: in C, main needs to return a value.  I'm surprised your compiler
isn't complaining.  (Are the compiler warnings properly enabled?)  I
think I mentioned this one before...

Your test main functions should probably end with something like
  return test_common_complete();
(which would be like destroy_context but would return 0.)

Ian.

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

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

* Re: [PATCH v4 01/14] golang/xenlight: Create stub package
  2017-03-20 14:45 ` [PATCH v4 01/14] golang/xenlight: Create stub package George Dunlap
@ 2017-03-23 15:36   ` Ronald Rojas
  0 siblings, 0 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-23 15:36 UTC (permalink / raw)
  To: George Dunlap; +Cc: Ian Jackson, Wei Liu, xen-devel

On Mon, Mar 20, 2017 at 02:45:30PM +0000, George Dunlap wrote:
> On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> 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>
> > Signed-off-by: George Dunlap <george.dunlap@citrix.com>
> 
> Almost there.  One comment on one of the last changes...
> 
 
 [snip]

> I think we want xenlight.Ctx to contain all the information needed to
> open and close it; as long as we're creating a logger automatically,
> we should store the pointer to the logger in the Ctx struct.
> 
> We should also set the pointer to nil after calling
> xtl_logger_destroy() to prevent use-after-free bugs.
> 
> (Yay lack of garbage collection again.)

Makes sense. I'll put the logger inside the Ctx struct.

Ronald

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

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

* Re: [PATCH v4 01/14] golang/xenlight: Create stub package
  2017-03-20 17:51 ` George Dunlap
@ 2017-03-23 15:37   ` Ronald Rojas
  0 siblings, 0 replies; 26+ messages in thread
From: Ronald Rojas @ 2017-03-23 15:37 UTC (permalink / raw)
  To: George Dunlap; +Cc: Ian Jackson, Wei Liu, xen-devel

On Mon, Mar 20, 2017 at 05:51:03PM +0000, George Dunlap wrote:
> On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> 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>
> > Signed-off-by: George Dunlap <george.dunlap@citrix.com>
> > ---
> >
> > Changes:
> >
> > - Added global logger variable and destroyed the logger instance
> > when closing the context.
> >
> > - Whitespace fixes
> >
> > - Commented out CONFIG_GOLANG
> 
> > +# 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) $(CFLAGS_libxentoollog)" CGO_LDFLAGS="$(LDLIBS_libxenlight) $(LDLIBS_libxentoollog)-L$(XEN_XENLIGHT) -L$(XEN_LIBXENTOOLLOG)" GOPATH=$(XEN_GOPATH) $(GO) install -x $(XEN_GOCODE_URL)/xenlight
> 
> Also, you're missing a space between `$(LDLIBS_libxentoollog)` and
> `-L$(XEN_XENLIGHT)`.  In the future please at least compile-test your
> code.
> 

Sorry! I rushed this patch, I'll fix this in the next iteration.

Ronald

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

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

* Re: [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions
  2017-03-20 18:15     ` Ian Jackson
@ 2017-04-04 16:44       ` George Dunlap
  0 siblings, 0 replies; 26+ messages in thread
From: George Dunlap @ 2017-04-04 16:44 UTC (permalink / raw)
  To: Ian Jackson; +Cc: Ronald Rojas, Wei Liu, xen-devel

On Mon, Mar 20, 2017 at 6:15 PM, Ian Jackson <ian.jackson@eu.citrix.com> wrote:
> George Dunlap writes ("Re: [Xen-devel] [PATCH v4 05/14] golang/xenlight: Add tests host related functionality functions"):
>> I had a chat with Ian Jackson, and we agreed that it would be better
>> to create a file, maybe "test-common.c", that would contain this
>> variable, as well as the three functions below.
>>
>> Then the header ("test-common.h") would contain *declarations* of the
>> variable (i.e., "extern xentoollog_logger_stdiostream *logger;") and
>> function prototypes.
>>
>> The test-common.c file is small now, but it may grow as additional
>> functionality is needed.
>
> Right.
>
>> The other thing you might consider, to further reduce the boilerplate
>> you have in each unit test file, is to also include a libxl_ctx
>> pointer in test-common; and have create_context() simply return an int
>> (0 for success, -1 for failure).
>
> This would be nice.
>
> You might also consider whether create_context would better simply
> exit the program if it fails.  That avoids any possibility of error
> handling bugs.  And maybe it should be called test_common_setup() ?
> (Names are a matter of taste, though.)
>
> Also: in C, main needs to return a value.  I'm surprised your compiler
> isn't complaining.  (Are the compiler warnings properly enabled?)  I
> think I mentioned this one before...

Actually I think in C if you don't call 'return', you end up getting
whatever the last value that was calculated as a return value instead.
At least I once had a colleague show me a program and ask, "Wait, why
does this work?" when he wrote a function that did a bunch of
calculations but never called return. :-)

Better to be explicit though.

 -George

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

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

* Re: [PATCH v4 09/14] golang/xenlight: Implement Domain operations
  2017-03-16 19:08 ` [PATCH v4 09/14] golang/xenlight: Implement Domain operations Ronald Rojas
@ 2017-04-05 10:23   ` George Dunlap
  0 siblings, 0 replies; 26+ messages in thread
From: George Dunlap @ 2017-04-05 10:23 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> wrote:
> Add calls for the following Domain related functionality
> - libxl_domain_pause
> - libxl_domain_shutdown
> - libxl_domain_reboot
> - libxl_list_domain
>
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>

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] 26+ messages in thread

* Re: [PATCH v4 11/14] golang/xenlight: Implement get console path operations
  2017-03-16 19:08 ` [PATCH v4 11/14] golang/xenlight: Implement get console path operations Ronald Rojas
@ 2017-04-05 11:04   ` George Dunlap
  0 siblings, 0 replies; 26+ messages in thread
From: George Dunlap @ 2017-04-05 11:04 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> wrote:
> Implement Golang enumeration of libxl_console_type
> as ConsoleType
>
> Implement the following libxl functions:
> - libxl_console_get_tty
> - libxl_primary_console_get_tty
>
> Signed-off-by: Ronald Rojas <ronladred@gmail.com>
> ---
> CC: xen-devel@lists.xen.org
> CC: george.dunlap@citrix.com
> CC: ian.jackson@eu.citrix.com
> CC: wei.liu2@citrix.com
> ---
> ---
>  tools/golang/xenlight/xenlight.go | 57 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
>
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index 61d7f8f..d520f74 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -1080,3 +1080,60 @@ func (Ctx *Context) ListVcpu(id Domid) (glist []Vcpuinfo) {
>
>         return
>  }
> +
> +type ConsoleType int
> +
> +const (
> +       ConsoleTypeUnknown = ConsoleType(C.LIBXL_CONSOLE_TYPE_UNKNOWN)
> +       ConsoleTypeSerial  = ConsoleType(C.LIBXL_CONSOLE_TYPE_SERIAL)
> +       ConsoleTypePV      = ConsoleType(C.LIBXL_CONSOLE_TYPE_PV)
> +)
> +
> +func (ct ConsoleType) String() (str string) {
> +       cstr := C.libxl_console_type_to_string(C.libxl_console_type(ct))
> +       str = C.GoString(cstr)
> +
> +       return
> +}
> +
> +//int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num,
> +//libxl_console_type type, char **path);
> +func (Ctx *Context) ConsoleGetTty(id Domid, consNum int, conType ConsoleType) (path string, err error) {
> +       err = Ctx.CheckOpen()
> +       if err != nil {
> +               return
> +       }
> +
> +       var cpath *C.char
> +       defer C.free(cpath)
> +       ret := C.libxl_console_get_tty(Ctx.ctx, C.uint32_t(id), C.int(consNum), C.libxl_console_type(conType), &cpath)
> +
> +       if ret != 0 {
> +               err = Error(-ret)
> +               return
> +       }

You can't call `defer C.free()` until you're certain that cpath will
contain a non-NULL pointer (here and in PrimaryConsole...)

Everything else looks fine.

 -George

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

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

* Re: [PATCH v4 12/14] golang/xenlight: Created boilerplate code for device related structs
  2017-03-16 19:08 ` [PATCH v4 12/14] golang/xenlight: Created boilerplate code for device related structs Ronald Rojas
@ 2017-04-05 11:13   ` George Dunlap
  0 siblings, 0 replies; 26+ messages in thread
From: George Dunlap @ 2017-04-05 11:13 UTC (permalink / raw)
  To: Ronald Rojas; +Cc: Ian Jackson, Wei Liu, xen-devel

On Thu, Mar 16, 2017 at 7:08 PM, Ronald Rojas <ronladred@gmail.com> wrote:
> Created boilerplate struct and toC methods for the
> following structs:
> - KeyValueList
> - DomainBuildInfo
> - DeviceNic
> - DevicePci
> - DeviceRdm
> - DeviceDtdev
> - DeviceVfb
> - DeviceVkb
> - DeviceVtpm
> - DeviceChannel
> - DeviceUsbctrl
> - DeviceUsbdev

I don't think it's necessary at this point for the DomainBuildinfo and
DomainCreate structs to contain all of the elements that it will
eventually -- just the core of what's necessary to build a simple
domain, given that we can't yet create any devices.

So I think removing the boilerplate and collapsing the next three
patches into one is the best way forward here.

I'll see if I can give it a try.

 -George

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

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

end of thread, other threads:[~2017-04-05 11:13 UTC | newest]

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

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.