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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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