From patchwork Wed Apr 5 16:05:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 9664617 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 6A09A60353 for ; Wed, 5 Apr 2017 16:08:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BFD625223 for ; Wed, 5 Apr 2017 16:08:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5098F285A1; Wed, 5 Apr 2017 16:08:52 +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=-4.2 required=2.0 tests=BAYES_00, 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 AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D23242623C for ; Wed, 5 Apr 2017 16:08:51 +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 1cvnRl-0004Nk-EI; Wed, 05 Apr 2017 16:06:13 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvnRk-0004Lv-Gj for xen-devel@lists.xenproject.org; Wed, 05 Apr 2017 16:06:12 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 55/F1-06437-3F515E85; Wed, 05 Apr 2017 16:06:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeJIrShJLcpLzFFi42JxWrrBXvez6NM Ig2NbhCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owHp86wFOxRr5i9fRdLA+NmxS5GTg4JAX+J tWd+sIHYbAJ6EvOOf2XpYuTgEBFQkbi916CLkYuDWWA6o0TXpHeMIDXCAvES7x78BrNZgGrOX 1/PDmLzCrhLtO28zQQxU07i/PGfzCBzOAU8JJ7O4AUJCwGVdBz5yg5hq0osfnAUqlVQ4uTMJy wgNrOAhMTBFy+YJzDyzkKSmoUktYCRaRWjRnFqUVlqka6hmV5SUWZ6RkluYmaOrqGBsV5uanF xYnpqTmJSsV5yfu4mRmDoMADBDsZV2z0PMUpyMCmJ8ir4PIkQ4kvKT6nMSCzOiC8qzUktPsQo w8GhJMGrCgxFIcGi1PTUirTMHGAQw6QlOHiURHhlQdK8xQWJucWZ6RCpU4yKUuK8z0SAEgIgi YzSPLg2WORcYpSVEuZlBDpEiKcgtSg3swRV/hWjOAejkjCvDsh4nsy8Erjpr4AWMwEtfnLnIc jikkSElFQD44YT33eG3DjpyvCwZOOV3W+j/CxYnverM9xXmvQw4egZ7rIl325qC1rETWkIPhA tUxyews39sV2qcerDXZuKpwfOPFyeUPPtmPGxCVfV4ub7/av94rju/empRlJ/Rf+qnZz0+aOT 3PuNVRtZvp47XPm3y2HGVAHbPNHGQ2eunNs0J9CA76eccZwSS3FGoqEWc1FxIgB+fSzMlwIAA A== X-Env-Sender: prvs=261486814=George.Dunlap@citrix.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1491408369!36295155!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45491 invoked from network); 5 Apr 2017 16:06:10 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-4.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 5 Apr 2017 16:06:10 -0000 X-IronPort-AV: E=Sophos;i="5.36,279,1486425600"; d="scan'208";a="426347156" From: George Dunlap To: Date: Wed, 5 Apr 2017 17:05:48 +0100 Message-ID: <1491408354-9643-5-git-send-email-george.dunlap@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1491408354-9643-1-git-send-email-george.dunlap@citrix.com> References: <1491408354-9643-1-git-send-email-george.dunlap@citrix.com> MIME-Version: 1.0 Cc: Ronald Rojas , Wei Liu , George Dunlap , Ian Jackson Subject: [Xen-devel] [PATCH v5 04/10] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause 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 From: Ronald Rojas Add calls for the following host-related functionality: - libxl_domain_info - libxl_domain_unpause Include Golang version for the libxl_domain_info as DomainInfo. Signed-off-by: George Dunlap Signed-off-by: Ronald Rojas --- CC: Ian Jackson CC: Wei Liu tools/golang/xenlight/xenlight.go | 134 +++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 5b500f3..ebcd2ee 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -33,6 +33,7 @@ import "C" import ( "fmt" + "time" "unsafe" ) @@ -113,6 +114,12 @@ func (e Error) Error() string { * Types: Builtins */ +type Domid uint32 + +type MemKB uint64 + +type Uuid C.libxl_uuid + type Context struct { ctx *C.libxl_ctx logger *C.xentoollog_logger_stdiostream @@ -120,7 +127,7 @@ type Context struct { type Hwcap []C.uint32_t -func (chwcap C.libxl_hwcap) CToGo() (ghwcap Hwcap) { +func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) { // Alloc a Go slice for the bytes size := 8 ghwcap = make([]C.uint32_t, size) @@ -173,7 +180,7 @@ func (cphys *C.libxl_physinfo) toGo() (physinfo *Physinfo) { physinfo.SharingFreedPages = uint64(cphys.sharing_freed_pages) physinfo.SharingUsedFrames = uint64(cphys.sharing_used_frames) physinfo.NrNodes = uint32(cphys.nr_nodes) - physinfo.HwCap = cphys.hw_cap.CToGo() + physinfo.HwCap = cphys.hw_cap.toGo() physinfo.CapHvm = bool(cphys.cap_hvm) physinfo.CapHvmDirectio = bool(cphys.cap_hvm_directio) @@ -215,6 +222,93 @@ func (cinfo *C.libxl_version_info) toGo() (info *VersionInfo) { return } +type ShutdownReason int32 + +const ( + ShutdownReasonUnknown = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_UNKNOWN) + ShutdownReasonPoweroff = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_POWEROFF) + ShutdownReasonReboot = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_REBOOT) + ShutdownReasonSuspend = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_SUSPEND) + ShutdownReasonCrash = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_CRASH) + ShutdownReasonWatchdog = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_WATCHDOG) + ShutdownReasonSoftReset = ShutdownReason(C.LIBXL_SHUTDOWN_REASON_SOFT_RESET) +) + +func (sr ShutdownReason) String() (str string) { + cstr := C.libxl_shutdown_reason_to_string(C.libxl_shutdown_reason(sr)) + str = C.GoString(cstr) + + return +} + +type DomainType int32 + +const ( + DomainTypeInvalid = DomainType(C.LIBXL_DOMAIN_TYPE_INVALID) + DomainTypeHvm = DomainType(C.LIBXL_DOMAIN_TYPE_HVM) + DomainTypePv = DomainType(C.LIBXL_DOMAIN_TYPE_PV) +) + +func (dt DomainType) String() (str string) { + cstr := C.libxl_domain_type_to_string(C.libxl_domain_type(dt)) + str = C.GoString(cstr) + + return +} + +type Dominfo struct { + Uuid Uuid + Domid Domid + Ssidref uint32 + SsidLabel string + Running bool + Blocked bool + Paused bool + Shutdown bool + Dying bool + NeverStop bool + + ShutdownReason int32 + OutstandingMemkb MemKB + CurrentMemkb MemKB + SharedMemkb MemKB + PagedMemkb MemKB + MaxMemkb MemKB + CpuTime time.Duration + VcpuMaxId uint32 + VcpuOnline uint32 + Cpupool uint32 + DomainType int32 +} + +func (cdi *C.libxl_dominfo) toGo() (di *Dominfo) { + + di = &Dominfo{} + di.Uuid = Uuid(cdi.uuid) + di.Domid = Domid(cdi.domid) + di.Ssidref = uint32(cdi.ssidref) + di.SsidLabel = C.GoString(cdi.ssid_label) + di.Running = bool(cdi.running) + di.Blocked = bool(cdi.blocked) + di.Paused = bool(cdi.paused) + di.Shutdown = bool(cdi.shutdown) + di.Dying = bool(cdi.dying) + di.NeverStop = bool(cdi.never_stop) + di.ShutdownReason = int32(cdi.shutdown_reason) + di.OutstandingMemkb = MemKB(cdi.outstanding_memkb) + di.CurrentMemkb = MemKB(cdi.current_memkb) + di.SharedMemkb = MemKB(cdi.shared_memkb) + di.PagedMemkb = MemKB(cdi.paged_memkb) + di.MaxMemkb = MemKB(cdi.max_memkb) + di.CpuTime = time.Duration(cdi.cpu_time) + di.VcpuMaxId = uint32(cdi.vcpu_max_id) + di.VcpuOnline = uint32(cdi.vcpu_online) + di.Cpupool = uint32(cdi.cpupool) + di.DomainType = int32(cdi.domain_type) + + return +} + /* * Context */ @@ -364,3 +458,39 @@ func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) { return } + +func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + + var cdi C.libxl_dominfo + C.libxl_dominfo_init(&cdi) + defer C.libxl_dominfo_dispose(&cdi) + + ret := C.libxl_domain_info(Ctx.ctx, &cdi, C.uint32_t(Id)) + + if ret != 0 { + err = Error(-ret) + return + } + + di = cdi.toGo() + + return +} + +func (Ctx *Context) DomainUnpause(Id Domid) (err error) { + err = Ctx.CheckOpen() + if err != nil { + return + } + + ret := C.libxl_domain_unpause(Ctx.ctx, C.uint32_t(Id)) + + if ret != 0 { + err = Error(-ret) + } + return +}