From patchwork Thu Dec 29 20:20:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 9491385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1D9762AB7 for ; Thu, 29 Dec 2016 20:23:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 820BF1FFB9 for ; Thu, 29 Dec 2016 20:23:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6510E2018E; Thu, 29 Dec 2016 20:23:50 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 548CF1FFB9 for ; Thu, 29 Dec 2016 20:23:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cMhBd-0004fb-VD; Thu, 29 Dec 2016 20:20:29 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cMhBc-0004fV-Vz for xen-devel@lists.xen.org; Thu, 29 Dec 2016 20:20:29 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 1C/22-25337-C0075685; Thu, 29 Dec 2016 20:20:28 +0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Ha55SizFGYmGWsxFxYkAV ElmpzsEAAA= X-Env-Sender: dunlapg@gmail.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1483042825!79687224!1 X-Originating-IP: [209.85.216.193] X-SpamReason: No, hits=0.3 required=7.0 tests=RCVD_BY_IP X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45642 invoked from network); 29 Dec 2016 20:20:26 -0000 Received: from mail-qt0-f193.google.com (HELO mail-qt0-f193.google.com) (209.85.216.193) by server-9.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 29 Dec 2016 20:20:26 -0000 Received: by mail-qt0-f193.google.com with SMTP id 41so22499897qtn.0 for ; Thu, 29 Dec 2016 12:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=ax3EITOCMTfuwxNjHYsMUhHgDhwtGvjN3OyEamX4Ev4=; b=IuU2ImpVH2e10xE9d5o6BK0+khs8AxF1/sS61shy3HfhUxbAOS6PRrUelGjTXcp1OK IHi4Mvb/wpLIGr0oKNpwxKcmVUNgsXPHRUgghQBM8lqoPUgIjZX7seuDtwx2nAwaIUjS zZB5kBP0x5UCGiqlMRsC+cysCiUsK9B5dLkJdMSp3iZDuF7nZIWGik1xACAy3DXpD1Jq 7iuHfFqzLCn8wr1AhJN3xwKQBdx9w3+kDmdteXdJwtUAeqkpb7POMhCTMHtISPpzZvK3 czy+3jMFcjkiEDW9I7EQdaem4c+AZw/se8FeY8HRL7Ha9ORGSwhMSwgwmBfBxIlgLF1d LbcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=ax3EITOCMTfuwxNjHYsMUhHgDhwtGvjN3OyEamX4Ev4=; b=nnH1Lk7TmXz/dEj9f1vNJUroZjSJOwRf5Atrszb9+6k/HgtPZFaR3FJUBUxfICRnIu 75VIvuMdZFbqpQNGwhiSsFd5EPnRttursyTokfK1I+PA3UtK8U0FuJ/NmHbeFbfO0Hyf 8Wvoy4NlW/L5o9PvetDQ0gviYKJnF3yiTCAY9ZVBd5V/AOxSXP/RZebl56EA17FhrfQS rdjb4JqXRvzNnuO0CP8TEEIDvus1MfHGpFhbFrraNskEQJZaDFZWIAuANzq3FNHyaaHn vDwNWMIAXoEcG9sh3piMTUKhyOmuJ0smUz4JsvccgAQQ09ShQ8EyU3bjiVjicXaEdkaH 8YMw== X-Gm-Message-State: AIkVDXJuMfvTNeTD3sqSAm/2un7FhmFhC76FAPqeMEx4Jo4OMtL+Grl/QR1TaxO9coo6ylQnuCHC/szaaUobBA== X-Received: by 10.200.38.39 with SMTP id u36mr44173662qtu.31.1483042825317; Thu, 29 Dec 2016 12:20:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.55.157.72 with HTTP; Thu, 29 Dec 2016 12:20:24 -0800 (PST) In-Reply-To: References: <1482974092-15891-1-git-send-email-ronladred@gmail.com> <1482974092-15891-59-git-send-email-ronladred@gmail.com> From: George Dunlap Date: Thu, 29 Dec 2016 20:20:24 +0000 X-Google-Sender-Auth: 2EKrtj9j7VQDSNFoogGm3tosE2c Message-ID: To: Ronald Rojas , xen-devel , Ian Jackson , Wei Liu , George Dunlap Subject: Re: [Xen-devel] [PATCH RFC 59/59] tools/xenlight: Create interface for xenlight info X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Dec 29, 2016 at 1:45 PM, George Dunlap wrote: > At a high level: I think I began by saying that this would probably all > be a single patch. But I think it would probably be easier to review > the different decisions made at each point by filling out the file bit > by bit, and explaining what's going on at each point. [snip] > I'll take a stab at breaking it down in an example order that makes some > sense to me, and then you can see what you think. Here's one way you might break down this series that would make it easier to review. I've re-ordered the file somewhat, and there's a slight bug in the build process so I can't compile it; and many of the descriptions need to be expanded. But it should give you the idea of what I'm talking about. -George From c96a7c71c69c440fd87e77b5e11f7ecdf3263e83 Mon Sep 17 00:00:00 2001 From: George Dunlap Date: Thu, 29 Dec 2016 19:22:41 +0000 Subject: [PATCH 1/7] tools/xenlight: Create stub package 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 the next patch. Signed-off-by: Ronald Rojas --- tools/Makefile | 16 ++++++++ tools/golang/Makefile | 29 ++++++++++++++ tools/golang/xenlight/xenlight.go | 80 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 tools/golang/Makefile create mode 100644 tools/golang/xenlight/xenlight.go diff --git a/tools/Makefile b/tools/Makefile index 77e0723..4c34421 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -12,6 +12,8 @@ SUBDIRS-y += misc SUBDIRS-y += examples SUBDIRS-y += hotplug SUBDIRS-y += xentrace +SUBDIRS-y += golang +#FIXME: Have golang controlled by a configure variable SUBDIRS-$(CONFIG_XCUTILS) += xcutils SUBDIRS-$(CONFIG_X86) += firmware SUBDIRS-y += console @@ -312,6 +314,20 @@ subdir-install-debugger/gdbsx: .phony subdir-all-debugger/gdbsx: .phony $(MAKE) -C debugger/gdbsx all +subdir-all-golang/xenlight: .phony + $(MAKE) -C golang all + +subdir-clean-golang/xenlight: .phony + $(MAKE) -C golang clean + +subdir-install-golang/xenlight: .phony + $(MAKE) -C golang install + +subdir-build-golang/xenlight: .phony + $(MAKE) -C golang build + +subdir-distclean-golang/xenlight: .phony + $(MAKE) -C golang distclean subdir-clean-debugger/kdd subdir-distclean-debugger/kdd: .phony $(MAKE) -C debugger/kdd clean diff --git a/tools/golang/Makefile b/tools/golang/Makefile new file mode 100644 index 0000000..96589c8 --- /dev/null +++ b/tools/golang/Makefile @@ -0,0 +1,29 @@ +XEN_ROOT=$(CURDIR)/../.. +GOLANG_SRC=$(GOPATH)/src/xenproject.org/xenlight +include $(XEN_ROOT)/tools/Rules.mk + +BINARY = xenlight.a +GO ?= go + +.PHONY: all +all: build + +.PHONY: build +build: xenlight/xenlight.a + +.PHONY: install +install: build + $(INSTALL_DIR) $(DESTDIR)$(GOLANG_SRC) + $(INSTALL_DATA) xenlight/xenlight.go $(DESTDIR)$(GOLANG_SRC) + +.PHONY: clean +clean: + $(RM) xenlight/$(BINARY) + +.PHONY: distclean +distclean: clean + +xenlight/xenlight.a: xenlight/xenlight.go + $(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..b162abb --- /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 +#include +*/ +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 +}