From patchwork Tue Dec 10 15:47:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11282869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08090138C for ; Tue, 10 Dec 2019 15:49:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC7F62077B for ; Tue, 10 Dec 2019 15:49:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hiMwiCLM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC7F62077B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iehjx-0002re-6X; Tue, 10 Dec 2019 15:47:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iehjv-0002rO-Px for xen-devel@lists.xenproject.org; Tue, 10 Dec 2019 15:47:55 +0000 X-Inumbo-ID: 6c421576-1b64-11ea-b6f1-bc764e2007e4 Received: from mail-qt1-x833.google.com (unknown [2607:f8b0:4864:20::833]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6c421576-1b64-11ea-b6f1-bc764e2007e4; Tue, 10 Dec 2019 15:47:51 +0000 (UTC) Received: by mail-qt1-x833.google.com with SMTP id i12so2006253qtp.6 for ; Tue, 10 Dec 2019 07:47:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xJQbH0Nm/8lI641knvIgk1T9SXkoB93ydbAB30piTN8=; b=hiMwiCLMyfeEdX9fUWXhlKLG4wWBMC653+9gb9H6XMe6giXrIZ2yARUteHJM/IZVtU ME6Il1oWjHzACgj5KGNwW1TTWBVHpgQ0wxVquxu39LNecFxcExVYLQKY7DlNvFRQkAXG ApCHF0XeO80Vm3Dld7bG4ev44RzTAi90uY/ZRVrMCBg9Av6Bkl3/pONg/Kd2WFtDsmaW Z4Q97rG1TPZZHb/HQHmGxN8jtyyI4tY441d9nB1SIcl5djK/03Y2/rvf/ZPWhkEC977M F//zPyb9UM3HioDBGWNXfL9l82C/fgQAZeVGQwiHMEw9BhE+LwRGkOFezaD+O1n58mrk wvZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xJQbH0Nm/8lI641knvIgk1T9SXkoB93ydbAB30piTN8=; b=h/8ELqkEuC1oypg7QH4H/acM/f81PlNF9dToA0qhaLAQmEdkf1n5o8T3MaHQdJNlbL Ham5VbPl1badKo+bSu9WTzRCEcGgjdUYewokmTz5jlqvDZ6mBUs8YPB9K4GJ7laWeW0R cWgeNSgfJWWERBlClgGhzs3lEDSgACINtJ7YfXMWDximEPm3xTv5rxgKQNhcAuaUzgQc LqHt2u35eEaIfCeM15JQ4YIbI+gMsplsbOOHdKJfYu7eaWlPqSend5TSJ3TypHRAVCr4 R68Or5Lwh6kdiFPVVTIs495jguU4rbYVQ8dPietKBJWO04md1x9QC18e8koZNPC+9M6T Wk1g== X-Gm-Message-State: APjAAAUai4MwW8Xbtt7SMYGS4rvXX/EEo8ffDHFDMi9TFNDMxLQgx5yd Xs+9ypsUJtF+mzhqk2lXme++OXmE X-Google-Smtp-Source: APXvYqzkLQcGFFCj8WCuPc0UK1vZo/OqNYKunDz74jMsaH7RdBCkNP2yTQdv8EbnLzUFjmdvwndpxQ== X-Received: by 2002:aed:36e3:: with SMTP id f90mr10017101qtb.86.1575992870522; Tue, 10 Dec 2019 07:47:50 -0800 (PST) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id m29sm1247848qtf.1.2019.12.10.07.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 07:47:49 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Tue, 10 Dec 2019 10:47:16 -0500 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 01/22] golang/xenlight: generate enum types from IDL 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: Nick Rosbrook , Ian Jackson , kerriganb@ainfosec.com, George Dunlap , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Nick Rosbrook Introduce gengotypes.py to generate Go code the from IDL. As a first step, implement 'enum' type generation. As a result of the newly-generated code, remove the existing, and now conflicting definitions in xenlight.go. In the case of the Error type, rename the slice 'errors' to 'libxlErrors' so that it does not conflict with the standard library package 'errors.' And, negate the values used in 'libxlErrors' since the generated error values are negative. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- Changes in v2: - Introduce Makefile targets for code generation - Re-generate Go code (includes new libxl_passtrhough enum). - Use *.gen.go naming convention for generated Go files. --- tools/golang/xenlight/Makefile | 18 +- tools/golang/xenlight/gengotypes.py | 109 ++++++++ tools/golang/xenlight/types.gen.go | 388 ++++++++++++++++++++++++++++ tools/golang/xenlight/xenlight.go | 140 ++-------- 4 files changed, 535 insertions(+), 120 deletions(-) create mode 100644 tools/golang/xenlight/gengotypes.py create mode 100644 tools/golang/xenlight/types.gen.go diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile index 0987305224..681f32c234 100644 --- a/tools/golang/xenlight/Makefile +++ b/tools/golang/xenlight/Makefile @@ -7,20 +7,21 @@ 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) +package: $(XEN_GOPATH)$(GOXL_PKG_DIR) -$(XEN_GOPATH)/src/$(XEN_GOCODE_URL)/xenlight/$(PKGSOURCES): $(PKGSOURCES) +$(XEN_GOPATH)/src/$(XEN_GOCODE_URL)/xenlight/: %.gen.go $(INSTALL_DIR) $(XEN_GOPATH)$(GOXL_PKG_DIR) - $(INSTALL_DATA) $(PKGSOURCES) $(XEN_GOPATH)$(GOXL_PKG_DIR) + $(INSTALL_DATA) xenlight.go $(XEN_GOPATH)$(GOXL_PKG_DIR) + $(INSTALL_DATA) types.gen.go $(XEN_GOPATH)$(GOXL_PKG_DIR) + +%.gen.go: gengotypes.py $(XEN_ROOT)/tools/libxl/libxl_types.idl $(XEN_ROOT)/tools/libxl/idl.py + XEN_ROOT=$(XEN_ROOT) $(PYTHON) gengotypes.py ../../libxl/libxl_types.idl # Go will do its own dependency checking, and not actuall go through # with the build if none of the input files have changed. @@ -36,10 +37,11 @@ build: package .PHONY: install install: build $(INSTALL_DIR) $(DESTDIR)$(GOXL_INSTALL_DIR) - $(INSTALL_DATA) $(XEN_GOPATH)$(GOXL_PKG_DIR)$(PKGSOURCES) $(DESTDIR)$(GOXL_INSTALL_DIR) + $(INSTALL_DATA) $(XEN_GOPATH)$(GOXL_PKG_DIR)xenlight.go $(DESTDIR)$(GOXL_INSTALL_DIR) + $(INSTALL_DATA) $(XEN_GOPATH)$(GOXL_PKG_DIR)types.gen.go $(DESTDIR)$(GOXL_INSTALL_DIR) .PHONY: uninstall - rm -f $(addprefix $(DESTDIR)$(GOXL_INSTALL_DIR)/, $(PKGSOURCES)) + rm -rf $(DESTDIR)$(GOXL_INSTALL_DIR) .PHONY: clean clean: diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py new file mode 100644 index 0000000000..2211541547 --- /dev/null +++ b/tools/golang/xenlight/gengotypes.py @@ -0,0 +1,109 @@ +#!/usr/bin/python + +import os +import sys + +sys.path.append('{}/tools/libxl'.format(os.environ['XEN_ROOT'])) +import idl + +# Go versions of some builtin types. +# Append the libxl-defined builtins after IDL parsing. +builtin_type_names = { + idl.bool.typename: 'bool', + idl.string.typename: 'string', + idl.integer.typename: 'int', + idl.uint8.typename: 'byte', + idl.uint16.typename: 'uint16', + idl.uint32.typename: 'uint32', + idl.uint64.typename: 'uint64', +} + +def xenlight_golang_generate_types(path = None, types = None, comment = None): + """ + Generate a .go file (types.gen.go by default) + that contains a Go type for each type in types. + """ + if path is None: + path = 'types.gen.go' + + with open(path, 'w') as f: + if comment is not None: + f.write(comment) + f.write('package xenlight\n') + + for ty in types: + f.write(xenlight_golang_type_define(ty)) + f.write('\n') + + go_fmt(path) + +def xenlight_golang_type_define(ty = None): + s = '' + + if isinstance(ty, idl.Enumeration): + s += xenlight_golang_define_enum(ty) + + return s + +def xenlight_golang_define_enum(ty = None): + s = '' + typename = '' + + if ty.typename is not None: + typename = xenlight_golang_fmt_name(ty.typename) + s += 'type {} int\n'.format(typename) + + # Start const block + s += 'const(\n' + + for v in ty.values: + name = xenlight_golang_fmt_name(v.name) + s += '{} {} = {}\n'.format(name, typename, v.value) + + # End const block + s += ')\n' + + return s + +def xenlight_golang_fmt_name(name, exported = True): + """ + Take a given type name and return an + appropriate Go type name. + """ + if name in builtin_type_names.keys(): + return builtin_type_names[name] + + # Name is not a builtin, format it for Go. + words = name.split('_') + + # Remove 'libxl' prefix + if words[0].lower() == 'libxl': + words.remove(words[0]) + + if exported: + return ''.join(x.title() for x in words) + + return words[0] + ''.join(x.title() for x in words[1:]) + +def go_fmt(path): + """ Call go fmt on the given path. """ + os.system('go fmt {}'.format(path)) + +if __name__ == '__main__': + idlname = sys.argv[1] + + (builtins, types) = idl.parse(idlname) + + for b in builtins: + name = b.typename + builtin_type_names[name] = xenlight_golang_fmt_name(name) + + header_comment="""// DO NOT EDIT. + // + // This file is generated by: + // {} + // + """.format(' '.join(sys.argv)) + + xenlight_golang_generate_types(types=types, + comment=header_comment) diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/types.gen.go new file mode 100644 index 0000000000..4a52eab048 --- /dev/null +++ b/tools/golang/xenlight/types.gen.go @@ -0,0 +1,388 @@ +// DO NOT EDIT. +// +// This file is generated by: +// gengotypes.py ../../libxl/libxl_types.idl +// +package xenlight + +type Error int + +const ( + ErrorNonspecific Error = -1 + ErrorVersion Error = -2 + ErrorFail Error = -3 + ErrorNi Error = -4 + ErrorNomem Error = -5 + ErrorInval Error = -6 + ErrorBadfail Error = -7 + ErrorGuestTimedout Error = -8 + ErrorTimedout Error = -9 + ErrorNoparavirt Error = -10 + ErrorNotReady Error = -11 + ErrorOseventRegFail Error = -12 + ErrorBufferfull Error = -13 + ErrorUnknownChild Error = -14 + ErrorLockFail Error = -15 + ErrorJsonConfigEmpty Error = -16 + ErrorDeviceExists Error = -17 + ErrorCheckpointDevopsDoesNotMatch Error = -18 + ErrorCheckpointDeviceNotSupported Error = -19 + ErrorVnumaConfigInvalid Error = -20 + ErrorDomainNotfound Error = -21 + ErrorAborted Error = -22 + ErrorNotfound Error = -23 + ErrorDomainDestroyed Error = -24 + ErrorFeatureRemoved Error = -25 + ErrorProtocolErrorQmp Error = -26 + ErrorUnknownQmpError Error = -27 + ErrorQmpGenericError Error = -28 + ErrorQmpCommandNotFound Error = -29 + ErrorQmpDeviceNotActive Error = -30 + ErrorQmpDeviceNotFound Error = -31 + ErrorQemuApi Error = -32 +) + +type DomainType int + +const ( + DomainTypeInvalid DomainType = -1 + DomainTypeHvm DomainType = 1 + DomainTypePv DomainType = 2 + DomainTypePvh DomainType = 3 +) + +type RdmReserveStrategy int + +const ( + RdmReserveStrategyIgnore RdmReserveStrategy = 0 + RdmReserveStrategyHost RdmReserveStrategy = 1 +) + +type RdmReservePolicy int + +const ( + RdmReservePolicyInvalid RdmReservePolicy = -1 + RdmReservePolicyStrict RdmReservePolicy = 0 + RdmReservePolicyRelaxed RdmReservePolicy = 1 +) + +type ChannelConnection int + +const ( + ChannelConnectionUnknown ChannelConnection = 0 + ChannelConnectionPty ChannelConnection = 1 + ChannelConnectionSocket ChannelConnection = 2 +) + +type DeviceModelVersion int + +const ( + DeviceModelVersionUnknown DeviceModelVersion = 0 + DeviceModelVersionQemuXenTraditional DeviceModelVersion = 1 + DeviceModelVersionQemuXen DeviceModelVersion = 2 +) + +type ConsoleType int + +const ( + ConsoleTypeUnknown ConsoleType = 0 + ConsoleTypeSerial ConsoleType = 1 + ConsoleTypePv ConsoleType = 2 + ConsoleTypeVuart ConsoleType = 3 +) + +type DiskFormat int + +const ( + DiskFormatUnknown DiskFormat = 0 + DiskFormatQcow DiskFormat = 1 + DiskFormatQcow2 DiskFormat = 2 + DiskFormatVhd DiskFormat = 3 + DiskFormatRaw DiskFormat = 4 + DiskFormatEmpty DiskFormat = 5 + DiskFormatQed DiskFormat = 6 +) + +type DiskBackend int + +const ( + DiskBackendUnknown DiskBackend = 0 + DiskBackendPhy DiskBackend = 1 + DiskBackendTap DiskBackend = 2 + DiskBackendQdisk DiskBackend = 3 +) + +type NicType int + +const ( + NicTypeUnknown NicType = 0 + NicTypeVifIoemu NicType = 1 + NicTypeVif NicType = 2 +) + +type ActionOnShutdown int + +const ( + ActionOnShutdownDestroy ActionOnShutdown = 1 + ActionOnShutdownRestart ActionOnShutdown = 2 + ActionOnShutdownRestartRename ActionOnShutdown = 3 + ActionOnShutdownPreserve ActionOnShutdown = 4 + ActionOnShutdownCoredumpDestroy ActionOnShutdown = 5 + ActionOnShutdownCoredumpRestart ActionOnShutdown = 6 + ActionOnShutdownSoftReset ActionOnShutdown = 7 +) + +type Trigger int + +const ( + TriggerUnknown Trigger = 0 + TriggerPower Trigger = 1 + TriggerSleep Trigger = 2 + TriggerNmi Trigger = 3 + TriggerInit Trigger = 4 + TriggerReset Trigger = 5 + TriggerS3Resume Trigger = 6 +) + +type TscMode int + +const ( + TscModeDefault TscMode = 0 + TscModeAlwaysEmulate TscMode = 1 + TscModeNative TscMode = 2 + TscModeNativeParavirt TscMode = 3 +) + +type GfxPassthruKind int + +const ( + GfxPassthruKindDefault GfxPassthruKind = 0 + GfxPassthruKindIgd GfxPassthruKind = 1 +) + +type TimerMode int + +const ( + TimerModeUnknown TimerMode = -1 + TimerModeDelayForMissedTicks TimerMode = 0 + TimerModeNoDelayForMissedTicks TimerMode = 1 + TimerModeNoMissedTicksPending TimerMode = 2 + TimerModeOneMissedTickPending TimerMode = 3 +) + +type BiosType int + +const ( + BiosTypeUnknown BiosType = 0 + BiosTypeRombios BiosType = 1 + BiosTypeSeabios BiosType = 2 + BiosTypeOvmf BiosType = 3 +) + +type Scheduler int + +const ( + SchedulerUnknown Scheduler = 0 + SchedulerSedf Scheduler = 4 + SchedulerCredit Scheduler = 5 + SchedulerCredit2 Scheduler = 6 + SchedulerArinc653 Scheduler = 7 + SchedulerRtds Scheduler = 8 + SchedulerNull Scheduler = 9 +) + +type ShutdownReason int + +const ( + ShutdownReasonUnknown ShutdownReason = -1 + ShutdownReasonPoweroff ShutdownReason = 0 + ShutdownReasonReboot ShutdownReason = 1 + ShutdownReasonSuspend ShutdownReason = 2 + ShutdownReasonCrash ShutdownReason = 3 + ShutdownReasonWatchdog ShutdownReason = 4 + ShutdownReasonSoftReset ShutdownReason = 5 +) + +type VgaInterfaceType int + +const ( + VgaInterfaceTypeUnknown VgaInterfaceType = 0 + VgaInterfaceTypeCirrus VgaInterfaceType = 1 + VgaInterfaceTypeStd VgaInterfaceType = 2 + VgaInterfaceTypeNone VgaInterfaceType = 3 + VgaInterfaceTypeQxl VgaInterfaceType = 4 +) + +type VendorDevice int + +const ( + VendorDeviceNone VendorDevice = 0 + VendorDeviceXenserver VendorDevice = 1 +) + +type ViridianEnlightenment int + +const ( + ViridianEnlightenmentBase ViridianEnlightenment = 0 + ViridianEnlightenmentFreq ViridianEnlightenment = 1 + ViridianEnlightenmentTimeRefCount ViridianEnlightenment = 2 + ViridianEnlightenmentReferenceTsc ViridianEnlightenment = 3 + ViridianEnlightenmentHcallRemoteTlbFlush ViridianEnlightenment = 4 + ViridianEnlightenmentApicAssist ViridianEnlightenment = 5 + ViridianEnlightenmentCrashCtl ViridianEnlightenment = 6 + ViridianEnlightenmentSynic ViridianEnlightenment = 7 + ViridianEnlightenmentStimer ViridianEnlightenment = 8 + ViridianEnlightenmentHcallIpi ViridianEnlightenment = 9 +) + +type Hdtype int + +const ( + HdtypeIde Hdtype = 1 + HdtypeAhci Hdtype = 2 +) + +type CheckpointedStream int + +const ( + CheckpointedStreamNone CheckpointedStream = 0 + CheckpointedStreamRemus CheckpointedStream = 1 + CheckpointedStreamColo CheckpointedStream = 2 +) + +type VuartType int + +const ( + VuartTypeUnknown VuartType = 0 + VuartTypeSbsaUart VuartType = 1 +) + +type VkbBackend int + +const ( + VkbBackendUnknown VkbBackend = 0 + VkbBackendQemu VkbBackend = 1 + VkbBackendLinux VkbBackend = 2 +) + +type Passthrough int + +const ( + PassthroughDefault Passthrough = 0 + PassthroughDisabled Passthrough = 1 + PassthroughEnabled Passthrough = 2 + PassthroughSyncPt Passthrough = 3 + PassthroughSharePt Passthrough = 4 +) + +type GicVersion int + +const ( + GicVersionDefault GicVersion = 0 + GicVersionV2 GicVersion = 32 + GicVersionV3 GicVersion = 48 +) + +type TeeType int + +const ( + TeeTypeNone TeeType = 0 + TeeTypeOptee TeeType = 1 +) + +type Altp2MMode int + +const ( + Altp2MModeDisabled Altp2MMode = 0 + Altp2MModeMixed Altp2MMode = 1 + Altp2MModeExternal Altp2MMode = 2 + Altp2MModeLimited Altp2MMode = 3 +) + +type UsbctrlType int + +const ( + UsbctrlTypeAuto UsbctrlType = 0 + UsbctrlTypePv UsbctrlType = 1 + UsbctrlTypeDevicemodel UsbctrlType = 2 + UsbctrlTypeQusb UsbctrlType = 3 +) + +type UsbdevType int + +const ( + UsbdevTypeHostdev UsbdevType = 1 +) + +type VsndPcmFormat int + +const ( + VsndPcmFormatS8 VsndPcmFormat = 1 + VsndPcmFormatU8 VsndPcmFormat = 2 + VsndPcmFormatS16Le VsndPcmFormat = 3 + VsndPcmFormatS16Be VsndPcmFormat = 4 + VsndPcmFormatU16Le VsndPcmFormat = 5 + VsndPcmFormatU16Be VsndPcmFormat = 6 + VsndPcmFormatS24Le VsndPcmFormat = 7 + VsndPcmFormatS24Be VsndPcmFormat = 8 + VsndPcmFormatU24Le VsndPcmFormat = 9 + VsndPcmFormatU24Be VsndPcmFormat = 10 + VsndPcmFormatS32Le VsndPcmFormat = 11 + VsndPcmFormatS32Be VsndPcmFormat = 12 + VsndPcmFormatU32Le VsndPcmFormat = 13 + VsndPcmFormatU32Be VsndPcmFormat = 14 + VsndPcmFormatF32Le VsndPcmFormat = 15 + VsndPcmFormatF32Be VsndPcmFormat = 16 + VsndPcmFormatF64Le VsndPcmFormat = 17 + VsndPcmFormatF64Be VsndPcmFormat = 18 + VsndPcmFormatIec958SubframeLe VsndPcmFormat = 19 + VsndPcmFormatIec958SubframeBe VsndPcmFormat = 20 + VsndPcmFormatMuLaw VsndPcmFormat = 21 + VsndPcmFormatALaw VsndPcmFormat = 22 + VsndPcmFormatImaAdpcm VsndPcmFormat = 23 + VsndPcmFormatMpeg VsndPcmFormat = 24 + VsndPcmFormatGsm VsndPcmFormat = 25 +) + +type VsndStreamType int + +const ( + VsndStreamTypeP VsndStreamType = 1 + VsndStreamTypeC VsndStreamType = 2 +) + +type EventType int + +const ( + EventTypeDomainShutdown EventType = 1 + EventTypeDomainDeath EventType = 2 + EventTypeDiskEject EventType = 3 + EventTypeOperationComplete EventType = 4 + EventTypeDomainCreateConsoleAvailable EventType = 5 +) + +type PsrCmtType int + +const ( + PsrCmtTypeCacheOccupancy PsrCmtType = 1 + PsrCmtTypeTotalMemCount PsrCmtType = 2 + PsrCmtTypeLocalMemCount PsrCmtType = 3 +) + +type PsrCbmType int + +const ( + PsrCbmTypeUnknown PsrCbmType = 0 + PsrCbmTypeL3Cbm PsrCbmType = 1 + PsrCbmTypeL3CbmCode PsrCbmType = 2 + PsrCbmTypeL3CbmData PsrCbmType = 3 + PsrCbmTypeL2Cbm PsrCbmType = 4 + PsrCbmTypeMbaThrtl PsrCbmType = 5 +) + +type PsrFeatType int + +const ( + PsrFeatTypeCat PsrFeatType = 1 + PsrFeatTypeMba PsrFeatType = 2 +) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 902cbb839e..89ed439fd0 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -37,77 +37,42 @@ import ( "unsafe" ) -/* - * Errors - */ - -type Error int - -const ( - ErrorNonspecific = Error(-C.ERROR_NONSPECIFIC) - ErrorVersion = Error(-C.ERROR_VERSION) - ErrorFail = Error(-C.ERROR_FAIL) - ErrorNi = Error(-C.ERROR_NI) - ErrorNomem = Error(-C.ERROR_NOMEM) - ErrorInval = Error(-C.ERROR_INVAL) - ErrorBadfail = Error(-C.ERROR_BADFAIL) - ErrorGuestTimedout = Error(-C.ERROR_GUEST_TIMEDOUT) - ErrorTimedout = Error(-C.ERROR_TIMEDOUT) - ErrorNoparavirt = Error(-C.ERROR_NOPARAVIRT) - ErrorNotReady = Error(-C.ERROR_NOT_READY) - ErrorOseventRegFail = Error(-C.ERROR_OSEVENT_REG_FAIL) - ErrorBufferfull = Error(-C.ERROR_BUFFERFULL) - ErrorUnknownChild = Error(-C.ERROR_UNKNOWN_CHILD) - ErrorLockFail = Error(-C.ERROR_LOCK_FAIL) - ErrorJsonConfigEmpty = Error(-C.ERROR_JSON_CONFIG_EMPTY) - ErrorDeviceExists = Error(-C.ERROR_DEVICE_EXISTS) - ErrorCheckpointDevopsDoesNotMatch = Error(-C.ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH) - ErrorCheckpointDeviceNotSupported = Error(-C.ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED) - ErrorVnumaConfigInvalid = Error(-C.ERROR_VNUMA_CONFIG_INVALID) - ErrorDomainNotfound = Error(-C.ERROR_DOMAIN_NOTFOUND) - ErrorAborted = Error(-C.ERROR_ABORTED) - ErrorNotfound = Error(-C.ERROR_NOTFOUND) - ErrorDomainDestroyed = Error(-C.ERROR_DOMAIN_DESTROYED) - ErrorFeatureRemoved = Error(-C.ERROR_FEATURE_REMOVED) -) - -var errors = [...]string{ - ErrorNonspecific: "Non-specific error", - ErrorVersion: "Wrong version", - ErrorFail: "Failed", - ErrorNi: "Not Implemented", - ErrorNomem: "No memory", - ErrorInval: "Invalid argument", - ErrorBadfail: "Bad Fail", - ErrorGuestTimedout: "Guest timed out", - ErrorTimedout: "Timed out", - ErrorNoparavirt: "No Paravirtualization", - ErrorNotReady: "Not ready", - ErrorOseventRegFail: "OS event registration failed", - ErrorBufferfull: "Buffer full", - ErrorUnknownChild: "Unknown child", - ErrorLockFail: "Lock failed", - ErrorJsonConfigEmpty: "JSON config empty", - ErrorDeviceExists: "Device exists", - ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match", - ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported", - ErrorVnumaConfigInvalid: "VNUMA config invalid", - ErrorDomainNotfound: "Domain not found", - ErrorAborted: "Aborted", - ErrorNotfound: "Not found", - ErrorDomainDestroyed: "Domain destroyed", - ErrorFeatureRemoved: "Feature removed", +var libxlErrors = [...]string{ + -ErrorNonspecific: "Non-specific error", + -ErrorVersion: "Wrong version", + -ErrorFail: "Failed", + -ErrorNi: "Not Implemented", + -ErrorNomem: "No memory", + -ErrorInval: "Invalid argument", + -ErrorBadfail: "Bad Fail", + -ErrorGuestTimedout: "Guest timed out", + -ErrorTimedout: "Timed out", + -ErrorNoparavirt: "No Paravirtualization", + -ErrorNotReady: "Not ready", + -ErrorOseventRegFail: "OS event registration failed", + -ErrorBufferfull: "Buffer full", + -ErrorUnknownChild: "Unknown child", + -ErrorLockFail: "Lock failed", + -ErrorJsonConfigEmpty: "JSON config empty", + -ErrorDeviceExists: "Device exists", + -ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match", + -ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported", + -ErrorVnumaConfigInvalid: "VNUMA config invalid", + -ErrorDomainNotfound: "Domain not found", + -ErrorAborted: "Aborted", + -ErrorNotfound: "Not found", + -ErrorDomainDestroyed: "Domain destroyed", + -ErrorFeatureRemoved: "Feature removed", } func (e Error) Error() string { - if 0 < int(e) && int(e) < len(errors) { - s := errors[e] + if 0 < int(e) && int(e) < len(libxlErrors) { + s := libxlErrors[e] if s != "" { return s } } return fmt.Sprintf("libxl error: %d", -e) - } /* @@ -236,18 +201,6 @@ 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) @@ -255,14 +208,6 @@ func (sr ShutdownReason) String() (str string) { 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) @@ -323,27 +268,6 @@ func (cdi *C.libxl_dominfo) toGo() (di *Dominfo) { return } -// # Consistent with values defined in domctl.h -// # Except unknown which we have made up -// libxl_scheduler = Enumeration("scheduler", [ -// (0, "unknown"), -// (4, "sedf"), -// (5, "credit"), -// (6, "credit2"), -// (7, "arinc653"), -// (8, "rtds"), -// ]) -type Scheduler int - -var ( - SchedulerUnknown Scheduler = C.LIBXL_SCHEDULER_UNKNOWN - SchedulerSedf Scheduler = C.LIBXL_SCHEDULER_SEDF - SchedulerCredit Scheduler = C.LIBXL_SCHEDULER_CREDIT - SchedulerCredit2 Scheduler = C.LIBXL_SCHEDULER_CREDIT2 - SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653 - SchedulerRTDS Scheduler = C.LIBXL_SCHEDULER_RTDS -) - // const char *libxl_scheduler_to_string(libxl_scheduler p); func (s Scheduler) String() string { cs := C.libxl_scheduler_to_string(C.libxl_scheduler(s)) @@ -1141,14 +1065,6 @@ func (Ctx *Context) ListVcpu(id Domid) (glist []Vcpuinfo) { return } -type ConsoleType int - -const ( - ConsoleTypeUnknown = ConsoleType(C.LIBXL_CONSOLE_TYPE_UNKNOWN) - ConsoleTypeSerial = ConsoleType(C.LIBXL_CONSOLE_TYPE_SERIAL) - ConsoleTypePV = ConsoleType(C.LIBXL_CONSOLE_TYPE_PV) -) - func (ct ConsoleType) String() (str string) { cstr := C.libxl_console_type_to_string(C.libxl_console_type(ct)) str = C.GoString(cstr)