From patchwork Thu Jul 18 21:54:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11049585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80D8513B1 for ; Thu, 18 Jul 2019 21:56:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F57028897 for ; Thu, 18 Jul 2019 21:56:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63A8E2889E; Thu, 18 Jul 2019 21:56:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7F1228897 for ; Thu, 18 Jul 2019 21:56:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hoEMJ-0008K3-1P; Thu, 18 Jul 2019 21:54:39 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hoEMI-0008Jy-3g for xen-devel@lists.xenproject.org; Thu, 18 Jul 2019 21:54:38 +0000 X-Inumbo-ID: a17fa1f0-a9a6-11e9-8980-bc764e045a96 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id a17fa1f0-a9a6-11e9-8980-bc764e045a96; Thu, 18 Jul 2019 21:54:35 +0000 (UTC) Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: X4+k/xRpuHGq9R5P3GnSsVj10d3uaWof1fBoA9t5/QeSDKOfbmMk7KzBCPp34mslop5XHzYmc+ /z5ebsnZc+5HLtRjq8w7n3WgXUdmjvPP9OJo7kjcT2cJHDYsbZKMMWeOckBAuKyM4h6TZxue0j QWPFLpUuax+vgV8yebA48AaeGi9gMMNNCQF3TSBF6i3ZNGebtTAZg/hv/u1pcLEOo2qmrAksSG wu1o2TfdNql9lhbflwIKHdwlaO528Iwqy0Wrxjut3aHfoMdGZoLnyojR0p7kapoYjWR19jj+cY lDI= X-SBRS: 2.7 X-MesageID: 3241739 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,279,1559534400"; d="scan'208";a="3241739" From: George Dunlap To: Date: Thu, 18 Jul 2019 22:54:28 +0100 Message-ID: <20190718215428.6727-1-george.dunlap@citrix.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] golang/xenlight: Add libxl_utils support X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Nicolas Belouin , George Dunlap , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: George Dunlap --- 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 CC: Ian Jackson CC: Wei Liu --- 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 . + */ +package xenlight + +/* +#cgo LDFLAGS: -lxenlight -lyajl -lxentoollog +#include +#include +*/ +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 +}