[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] golang/xenlight: Add libxl_utils support
The Go bindings for libxl miss functions from libxl_utils, let's start with the simple libxl_domid_to_name and its counterpart libxl_name_to_domid. NB that C.GoString() will return "" if it's passed a NULL; see https://github.com/golang/go/issues/32734#issuecomment-506835432 Signed-off-by: Nicolas Belouin <nicolas.belouin@xxxxxxxxx> Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx> --- v3: - Wire into build system - Add reference to C.GoString() handling NULL to commit message Nicolas, could you test to see if this actually works for you? It would be really good also if we could get something that would do basic unit testing on a live system, and get that running in osstest. CC: Nicolas Belouin <nicolas.belouin@xxxxxxxxx> CC: Ian Jackson <ian.jackson@xxxxxxxxxx> CC: Wei Liu <wl@xxxxxxx> --- tools/golang/xenlight/Makefile | 2 +- tools/golang/xenlight/xenlight_utils.go | 55 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tools/golang/xenlight/xenlight_utils.go diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile index 0987305224..65923df59a 100644 --- a/tools/golang/xenlight/Makefile +++ b/tools/golang/xenlight/Makefile @@ -8,7 +8,7 @@ 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 +PKGSOURCES = xenlight.go xenlight_utils.go GO ?= go diff --git a/tools/golang/xenlight/xenlight_utils.go b/tools/golang/xenlight/xenlight_utils.go new file mode 100644 index 0000000000..da1636842d --- /dev/null +++ b/tools/golang/xenlight/xenlight_utils.go @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 Nicolas Belouin, Gandi SAS + * + * 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_utils.h> +*/ +import "C" + +import ( + "unsafe" +) + +//char* libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid); +func (Ctx *Context) DomidToName(id Domid) (name string) { + cDomName := C.libxl_domid_to_name(Ctx.ctx, C.uint32_t(id)) + defer C.free(unsafe.Pointer(cDomName)) + + name = C.GoString(cDomName) + return +} + +//int libxl_name_to_domid(libxl_ct *ctx, const char *name, uint32_t *domid) +func (Ctx *Context) NameToDomid(name string) (id Domid, err error) { + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + + var cDomId C.uint32_t + + ret := C.libxl_name_to_domid(Ctx.ctx, cname, &cDomId) + if ret != 0 { + err = Error(-ret) + return + } + + id = Domid(cDomId) + + return +} -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |