All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ronald Rojas <ronladred@gmail.com>
Cc: Ronald Rojas <ronladred@gmail.com>,
	wei.liu2@citrix.com, ian.jackson@eu.citrix.com,
	George Dunlap <george.dunlap@citrix.com>,
	xen-devel@lists.xen.org
Subject: [PATCH v4 01/14] golang/xenlight: Create stub package
Date: Thu, 16 Mar 2017 15:08:37 -0400	[thread overview]
Message-ID: <1489691330-17695-1-git-send-email-ronladred@gmail.com> (raw)

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

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

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 19:08 Ronald Rojas [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489691330-17695-1-git-send-email-ronladred@gmail.com \
    --to=ronladred@gmail.com \
    --cc=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.