From patchwork Mon Dec 23 15:17:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11308449 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 0D4EC138D for ; Mon, 23 Dec 2019 15:19:19 +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 D2E26206CB for ; Mon, 23 Dec 2019 15:19:18 +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="hCNfW5Rx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2E26206CB 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 1ijPSy-0006Jx-WE; Mon, 23 Dec 2019 15:17:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijPSx-0006Jo-IP for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 15:17:51 +0000 X-Inumbo-ID: 602dde54-2597-11ea-a1e1-bc764e2007e4 Received: from mail-qt1-x82a.google.com (unknown [2607:f8b0:4864:20::82a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 602dde54-2597-11ea-a1e1-bc764e2007e4; Mon, 23 Dec 2019 15:17:47 +0000 (UTC) Received: by mail-qt1-x82a.google.com with SMTP id l12so15610820qtq.12 for ; Mon, 23 Dec 2019 07:17:47 -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 :in-reply-to:references; bh=wsNbrXzTC4fbTgB0S7XOhOTybKwrAmTKHy13zlzg6dU=; b=hCNfW5Rxp00tKrKwd58mUjxr1ONqQ4ByU5C31vpw0/I993FU/kpbCxfgXIlo23qIef o0oLct4e73YsoQghYBFZJgQFUnQWqLHaqfkIKi3PI+ti9cTVZkz86HT2URuPKjCjS5FW Iz+dZMkm6J/Aw9eFa96dv5MXq29fH58LgSSAHhWPel3dDaMa/5wZhmZu2Lr3XDit0QeH sWpoSrZjKYMI2HUTiTlQK1maVkOoEmBtTJaLbnDZztGKpnjCqQjISFkImU2osVTqaxVf DspOEhTRht8y4yPwDgneXHlCgKKpDsOz0lDbAD7iRfD9ZZTucJE0FwfDPJKBkojyG7qJ bUow== 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:in-reply-to:references; bh=wsNbrXzTC4fbTgB0S7XOhOTybKwrAmTKHy13zlzg6dU=; b=IE8fEras6eRWPLRplnPO3HPtC3POLLJt3moEDvND+Z2UwTSg9/wVbm2S5uMCy+i6lA XV+anIuWhS0eNXV5gm0WetSEXJhjBQMSghY2knAI2gT/1P/grAvgGwZJZDZ2VF+n3Nwp zcc9ok4NR6Gzx4VIhVT0Ml9hG/jS32XU/426Xqg+LARHIL3p87kdK6OoxgdwJ6gwjDuS 1l0OkHhijYKIrlHoCHNMLP3A+4Az/pIEWEj2D/T0dqBWybT0gjIQlhakTFHhrEpmQv6V JyOTbfNzj6L9JN1U+MInVkWOngJ/xG1qH2coUrKoLtldyS3nl7jj64rT6EBuSUQCg7WJ Uo0g== X-Gm-Message-State: APjAAAXyW93Y50QOAglmiYObknZjgEMX8UreHd9BFwBV4xCJxGShIrdg hAZdf/N0RKXW6wUWqtN7soDZkXGE X-Google-Smtp-Source: APXvYqyesthus1zMDBZt2DD8FJFcib1HkmnRn/UtVS6to44Opf5crhRCJl3uDLeMQbL6SggCC1Bldg== X-Received: by 2002:ac8:787:: with SMTP id l7mr21833596qth.99.1577114266339; Mon, 23 Dec 2019 07:17:46 -0800 (PST) Received: from four.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id u15sm5823907qku.67.2019.12.23.07.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 07:17:45 -0800 (PST) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 23 Dec 2019 10:17:02 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 1/6] golang/xenlight: implement array C to Go marshaling 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- Changes in v4: - Call fromC using slice expression instead of creating temporary variable and assigning later. --- tools/golang/xenlight/gengotypes.py | 37 +++- tools/golang/xenlight/helpers.gen.go | 246 +++++++++++++++++++++++++++ 2 files changed, 282 insertions(+), 1 deletion(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index b68c1aa66b..8857e2e8fd 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -252,7 +252,7 @@ def xenlight_golang_define_from_C(ty = None): for f in ty.fields: if f.type.typename is not None: if isinstance(f.type, idl.Array): - # TODO + body += xenlight_golang_array_from_C(f) continue body += xenlight_golang_convert_from_C(f) @@ -399,6 +399,41 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''): return (s,extras) +def xenlight_golang_array_from_C(ty = None): + """ + Convert C array to Go slice using the method + described here: + + https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices + """ + s = '' + + gotypename = xenlight_golang_fmt_name(ty.type.elem_type.typename) + goname = xenlight_golang_fmt_name(ty.name) + ctypename = ty.type.elem_type.typename + cname = ty.name + cslice = 'c{}'.format(goname) + clenvar = ty.type.lenvar.name + golenvar = xenlight_golang_fmt_name(clenvar,exported=False) + + s += '{} := int(xc.{})\n'.format(golenvar, clenvar) + s += '{} := '.format(cslice) + s +='(*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:{}:{}]\n'.format(ctypename, cname, + golenvar, golenvar) + s += 'x.{} = make([]{}, {})\n'.format(goname, gotypename, golenvar) + s += 'for i, v := range {} {{\n'.format(cslice) + + is_enum = isinstance(ty.type.elem_type,idl.Enumeration) + if gotypename in go_builtin_types or is_enum: + s += 'x.{}[i] = {}(v)\n'.format(goname, gotypename) + else: + s += 'if err := x.{}[i].fromC(&v); err != nil {{\n'.format(goname) + s += 'return err }\n' + + s += '}\n' + + return s + def xenlight_golang_fmt_name(name, exported = True): """ Take a given type name and return an diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index e6eee234c0..25294ba292 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -263,6 +263,14 @@ func (x *SchedParams) fromC(xc *C.libxl_sched_params) error { func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { x.Sched = Scheduler(xc.sched) + numVcpus := int(xc.num_vcpus) + cVcpus := (*[1 << 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:numVcpus:numVcpus] + x.Vcpus = make([]SchedParams, numVcpus) + for i, v := range cVcpus { + if err := x.Vcpus[i].fromC(&v); err != nil { + return err + } + } return nil } @@ -282,6 +290,12 @@ func (x *DomainSchedParams) fromC(xc *C.libxl_domain_sched_params) error { func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { x.Memkb = uint64(xc.memkb) + numDistances := int(xc.num_distances) + cDistances := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.distances))[:numDistances:numDistances] + x.Distances = make([]uint32, numDistances) + for i, v := range cDistances { + x.Distances[i] = uint32(v) + } x.Pnode = uint32(xc.pnode) if err := x.Vcpus.fromC(&xc.vcpus); err != nil { return err @@ -308,6 +322,22 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { if err := x.Nodemap.fromC(&xc.nodemap); err != nil { return err } + numVcpuHardAffinity := int(xc.num_vcpu_hard_affinity) + cVcpuHardAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:numVcpuHardAffinity:numVcpuHardAffinity] + x.VcpuHardAffinity = make([]Bitmap, numVcpuHardAffinity) + for i, v := range cVcpuHardAffinity { + if err := x.VcpuHardAffinity[i].fromC(&v); err != nil { + return err + } + } + numVcpuSoftAffinity := int(xc.num_vcpu_soft_affinity) + cVcpuSoftAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:numVcpuSoftAffinity:numVcpuSoftAffinity] + x.VcpuSoftAffinity = make([]Bitmap, numVcpuSoftAffinity) + for i, v := range cVcpuSoftAffinity { + if err := x.VcpuSoftAffinity[i].fromC(&v); err != nil { + return err + } + } if err := x.NumaPlacement.fromC(&xc.numa_placement); err != nil { return err } @@ -330,6 +360,14 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { return err } x.BlkdevStart = C.GoString(xc.blkdev_start) + numVnumaNodes := int(xc.num_vnuma_nodes) + cVnumaNodes := (*[1 << 28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:numVnumaNodes:numVnumaNodes] + x.VnumaNodes = make([]VnodeInfo, numVnumaNodes) + for i, v := range cVnumaNodes { + if err := x.VnumaNodes[i].fromC(&v); err != nil { + return err + } + } x.MaxGrantFrames = uint32(xc.max_grant_frames) x.MaxMaptrackFrames = uint32(xc.max_maptrack_frames) x.DeviceModelVersion = DeviceModelVersion(xc.device_model_version) @@ -352,6 +390,28 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { if err := x.SchedParams.fromC(&xc.sched_params); err != nil { return err } + numIoports := int(xc.num_ioports) + cIoports := (*[1 << 28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:numIoports:numIoports] + x.Ioports = make([]IoportRange, numIoports) + for i, v := range cIoports { + if err := x.Ioports[i].fromC(&v); err != nil { + return err + } + } + numIrqs := int(xc.num_irqs) + cIrqs := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:numIrqs:numIrqs] + x.Irqs = make([]uint32, numIrqs) + for i, v := range cIrqs { + x.Irqs[i] = uint32(v) + } + numIomem := int(xc.num_iomem) + cIomem := (*[1 << 28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:numIomem:numIomem] + x.Iomem = make([]IomemRange, numIomem) + for i, v := range cIomem { + if err := x.Iomem[i].fromC(&v); err != nil { + return err + } + } if err := x.ClaimMode.fromC(&xc.claim_mode); err != nil { return err } @@ -831,11 +891,31 @@ func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error { x.BackendDomname = C.GoString(xc.backend_domname) x.Devid = Devid(xc.devid) x.BeAlloc = bool(xc.be_alloc) + numConnectors := int(xc.num_connectors) + cConnectors := (*[1 << 28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] + x.Connectors = make([]ConnectorParam, numConnectors) + for i, v := range cConnectors { + if err := x.Connectors[i].fromC(&v); err != nil { + return err + } + } return nil } func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error { + numSampleRates := int(xc.num_sample_rates) + cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:numSampleRates:numSampleRates] + x.SampleRates = make([]uint32, numSampleRates) + for i, v := range cSampleRates { + x.SampleRates[i] = uint32(v) + } + numSampleFormats := int(xc.num_sample_formats) + cSampleFormats := (*[1 << 28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:numSampleFormats:numSampleFormats] + x.SampleFormats = make([]VsndPcmFormat, numSampleFormats) + for i, v := range cSampleFormats { + x.SampleFormats[i] = VsndPcmFormat(v) + } x.ChannelsMin = uint32(xc.channels_min) x.ChannelsMax = uint32(xc.channels_max) x.BufferSize = uint32(xc.buffer_size) @@ -858,6 +938,14 @@ func (x *VsndPcm) fromC(xc *C.libxl_vsnd_pcm) error { if err := x.Params.fromC(&xc.params); err != nil { return err } + numVsndStreams := int(xc.num_vsnd_streams) + cStreams := (*[1 << 28]C.libxl_vsnd_stream)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] + x.Streams = make([]VsndStream, numVsndStreams) + for i, v := range cStreams { + if err := x.Streams[i].fromC(&v); err != nil { + return err + } + } return nil } @@ -871,6 +959,14 @@ func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error { if err := x.Params.fromC(&xc.params); err != nil { return err } + numVsndPcms := int(xc.num_vsnd_pcms) + cPcms := (*[1 << 28]C.libxl_vsnd_pcm)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] + x.Pcms = make([]VsndPcm, numVsndPcms) + for i, v := range cPcms { + if err := x.Pcms[i].fromC(&v); err != nil { + return err + } + } return nil } @@ -882,6 +978,126 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { if err := x.BInfo.fromC(&xc.b_info); err != nil { return err } + numDisks := int(xc.num_disks) + cDisks := (*[1 << 28]C.libxl_device_disk)(unsafe.Pointer(xc.disks))[:numDisks:numDisks] + x.Disks = make([]DeviceDisk, numDisks) + for i, v := range cDisks { + if err := x.Disks[i].fromC(&v); err != nil { + return err + } + } + numNics := int(xc.num_nics) + cNics := (*[1 << 28]C.libxl_device_nic)(unsafe.Pointer(xc.nics))[:numNics:numNics] + x.Nics = make([]DeviceNic, numNics) + for i, v := range cNics { + if err := x.Nics[i].fromC(&v); err != nil { + return err + } + } + numPcidevs := int(xc.num_pcidevs) + cPcidevs := (*[1 << 28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:numPcidevs:numPcidevs] + x.Pcidevs = make([]DevicePci, numPcidevs) + for i, v := range cPcidevs { + if err := x.Pcidevs[i].fromC(&v); err != nil { + return err + } + } + numRdms := int(xc.num_rdms) + cRdms := (*[1 << 28]C.libxl_device_rdm)(unsafe.Pointer(xc.rdms))[:numRdms:numRdms] + x.Rdms = make([]DeviceRdm, numRdms) + for i, v := range cRdms { + if err := x.Rdms[i].fromC(&v); err != nil { + return err + } + } + numDtdevs := int(xc.num_dtdevs) + cDtdevs := (*[1 << 28]C.libxl_device_dtdev)(unsafe.Pointer(xc.dtdevs))[:numDtdevs:numDtdevs] + x.Dtdevs = make([]DeviceDtdev, numDtdevs) + for i, v := range cDtdevs { + if err := x.Dtdevs[i].fromC(&v); err != nil { + return err + } + } + numVfbs := int(xc.num_vfbs) + cVfbs := (*[1 << 28]C.libxl_device_vfb)(unsafe.Pointer(xc.vfbs))[:numVfbs:numVfbs] + x.Vfbs = make([]DeviceVfb, numVfbs) + for i, v := range cVfbs { + if err := x.Vfbs[i].fromC(&v); err != nil { + return err + } + } + numVkbs := int(xc.num_vkbs) + cVkbs := (*[1 << 28]C.libxl_device_vkb)(unsafe.Pointer(xc.vkbs))[:numVkbs:numVkbs] + x.Vkbs = make([]DeviceVkb, numVkbs) + for i, v := range cVkbs { + if err := x.Vkbs[i].fromC(&v); err != nil { + return err + } + } + numVtpms := int(xc.num_vtpms) + cVtpms := (*[1 << 28]C.libxl_device_vtpm)(unsafe.Pointer(xc.vtpms))[:numVtpms:numVtpms] + x.Vtpms = make([]DeviceVtpm, numVtpms) + for i, v := range cVtpms { + if err := x.Vtpms[i].fromC(&v); err != nil { + return err + } + } + numP9S := int(xc.num_p9s) + cP9S := (*[1 << 28]C.libxl_device_p9)(unsafe.Pointer(xc.p9s))[:numP9S:numP9S] + x.P9S = make([]DeviceP9, numP9S) + for i, v := range cP9S { + if err := x.P9S[i].fromC(&v); err != nil { + return err + } + } + numPvcallsifs := int(xc.num_pvcallsifs) + cPvcallsifs := (*[1 << 28]C.libxl_device_pvcallsif)(unsafe.Pointer(xc.pvcallsifs))[:numPvcallsifs:numPvcallsifs] + x.Pvcallsifs = make([]DevicePvcallsif, numPvcallsifs) + for i, v := range cPvcallsifs { + if err := x.Pvcallsifs[i].fromC(&v); err != nil { + return err + } + } + numVdispls := int(xc.num_vdispls) + cVdispls := (*[1 << 28]C.libxl_device_vdispl)(unsafe.Pointer(xc.vdispls))[:numVdispls:numVdispls] + x.Vdispls = make([]DeviceVdispl, numVdispls) + for i, v := range cVdispls { + if err := x.Vdispls[i].fromC(&v); err != nil { + return err + } + } + numVsnds := int(xc.num_vsnds) + cVsnds := (*[1 << 28]C.libxl_device_vsnd)(unsafe.Pointer(xc.vsnds))[:numVsnds:numVsnds] + x.Vsnds = make([]DeviceVsnd, numVsnds) + for i, v := range cVsnds { + if err := x.Vsnds[i].fromC(&v); err != nil { + return err + } + } + numChannels := int(xc.num_channels) + cChannels := (*[1 << 28]C.libxl_device_channel)(unsafe.Pointer(xc.channels))[:numChannels:numChannels] + x.Channels = make([]DeviceChannel, numChannels) + for i, v := range cChannels { + if err := x.Channels[i].fromC(&v); err != nil { + return err + } + } + numUsbctrls := int(xc.num_usbctrls) + cUsbctrls := (*[1 << 28]C.libxl_device_usbctrl)(unsafe.Pointer(xc.usbctrls))[:numUsbctrls:numUsbctrls] + x.Usbctrls = make([]DeviceUsbctrl, numUsbctrls) + for i, v := range cUsbctrls { + if err := x.Usbctrls[i].fromC(&v); err != nil { + return err + } + } + numUsbdevs := int(xc.num_usbdevs) + cUsbdevs := (*[1 << 28]C.libxl_device_usbdev)(unsafe.Pointer(xc.usbdevs))[:numUsbdevs:numUsbdevs] + x.Usbdevs = make([]DeviceUsbdev, numUsbdevs) + for i, v := range cUsbdevs { + if err := x.Usbdevs[i].fromC(&v); err != nil { + return err + } + } x.OnPoweroff = ActionOnShutdown(xc.on_poweroff) x.OnReboot = ActionOnShutdown(xc.on_reboot) x.OnWatchdog = ActionOnShutdown(xc.on_watchdog) @@ -1015,6 +1231,14 @@ func (x *Vdisplinfo) fromC(xc *C.libxl_vdisplinfo) error { x.Devid = Devid(xc.devid) x.State = int(xc.state) x.BeAlloc = bool(xc.be_alloc) + numConnectors := int(xc.num_connectors) + cConnectors := (*[1 << 28]C.libxl_connectorinfo)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] + x.Connectors = make([]Connectorinfo, numConnectors) + for i, v := range cConnectors { + if err := x.Connectors[i].fromC(&v); err != nil { + return err + } + } return nil } @@ -1027,6 +1251,14 @@ func (x *Streaminfo) fromC(xc *C.libxl_streaminfo) error { } func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error { + numVsndStreams := int(xc.num_vsnd_streams) + cStreams := (*[1 << 28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] + x.Streams = make([]Streaminfo, numVsndStreams) + for i, v := range cStreams { + if err := x.Streams[i].fromC(&v); err != nil { + return err + } + } return nil } @@ -1038,6 +1270,14 @@ func (x *Vsndinfo) fromC(xc *C.libxl_vsndinfo) error { x.FrontendId = uint32(xc.frontend_id) x.Devid = Devid(xc.devid) x.State = int(xc.state) + numVsndPcms := int(xc.num_vsnd_pcms) + cPcms := (*[1 << 28]C.libxl_pcminfo)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] + x.Pcms = make([]Pcminfo, numVsndPcms) + for i, v := range cPcms { + if err := x.Pcms[i].fromC(&v); err != nil { + return err + } + } return nil } @@ -1058,6 +1298,12 @@ func (x *Vkbinfo) fromC(xc *C.libxl_vkbinfo) error { func (x *Numainfo) fromC(xc *C.libxl_numainfo) error { x.Size = uint64(xc.size) x.Free = uint64(xc.free) + numDists := int(xc.num_dists) + cDists := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.dists))[:numDists:numDists] + x.Dists = make([]uint32, numDists) + for i, v := range cDists { + x.Dists[i] = uint32(v) + } return nil } From patchwork Mon Dec 23 15:17:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11308459 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 C736113B6 for ; Mon, 23 Dec 2019 15:20:14 +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 8B5F4206CB for ; Mon, 23 Dec 2019 15:20:14 +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="n0c65eRR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B5F4206CB 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 1ijPT3-0006KH-AU; Mon, 23 Dec 2019 15:17: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 1ijPT2-0006KA-I1 for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 15:17:56 +0000 X-Inumbo-ID: 61ae7b80-2597-11ea-b6f1-bc764e2007e4 Received: from mail-qt1-x835.google.com (unknown [2607:f8b0:4864:20::835]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 61ae7b80-2597-11ea-b6f1-bc764e2007e4; Mon, 23 Dec 2019 15:17:49 +0000 (UTC) Received: by mail-qt1-x835.google.com with SMTP id j5so15624423qtq.9 for ; Mon, 23 Dec 2019 07:17:49 -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 :in-reply-to:references; bh=BdM7Aa9ODykWX2XVW3cQ+dGYhtK+6pwO9eA+HlT05yk=; b=n0c65eRRIn9A+De1j8SevSoUI5aHs41RezoU/DUwz+O7dRP5rQ0hWB37y58dBM1K9m nFppgqEQUoOy/okfEObY2Bq+oFVRICU4m1ks616c+3mAoIn3Cq/mnmoSsYkgbmlIzjXd UAYska63g7WOpw1pGCU+o5WjYKl7GiZyaDJzfuesRYEsHEqccp+ksWTFNjOsns8uKyRD tJnMy9QJBR81wOEkBf5V582+MmLutJYFNk9F7+Fxl/P6JPA4AlE1W5fCBLSslJDQSDnw pOg2Q9ePxs5KSfQR5CO60FAR0AMsPQxSIycfxey3Gi21HiXdJ9t0M7mI+Q0gXvlKcZ3Q 55Vg== 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:in-reply-to:references; bh=BdM7Aa9ODykWX2XVW3cQ+dGYhtK+6pwO9eA+HlT05yk=; b=R3ov3S6WA7WcfEe4wu3JrfAPDGEUAp4Z3WWnywVEggK9GuKsTRcgn/TMA/258W9kx+ BlDZvZWIOXCIfGMRJegXlChUKNiUn4/ZWgYQbgN2DQF1jiOJpbm1274TfzmnZCp5EdR/ GQAkAPDc/GQjDwdv7yu/BQDm+aCAQwcA4vJ2C0DzwlGp/OSwBJ9SG1w5/fbQD3QdYIka HW+I/0MyVVaLd/2+OtJRk32fisSwjYfjFxo5SBSnbF32OERprdccj5/6G7/Wg9rW6Xxv q+ssMu+OATcytLVrlrp36raRnt3ynCGiFAwMm0w9i751LQhmSaF9dyBZzLNe+njZwuwR S1JA== X-Gm-Message-State: APjAAAXnVTOzsDvqxyanxjqwIniotCDEFTJdLRH4aXcJneqw0bEc8T3h O5oaRe8VHpKvsIjbr7z7A46SW5A8 X-Google-Smtp-Source: APXvYqzRgre0HLcQgxwq8M6zlA4eshPzVIx03Lrl1/O8WiPTioiiPcpUwj4/9RAbUNmX07Yaimieyw== X-Received: by 2002:ac8:1e8e:: with SMTP id c14mr21595805qtm.330.1577114268116; Mon, 23 Dec 2019 07:17:48 -0800 (PST) Received: from four.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id u15sm5823907qku.67.2019.12.23.07.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 07:17:47 -0800 (PST) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 23 Dec 2019 10:17:03 -0500 Message-Id: <8b574d23f6abfc5356b65c958f637f3c22be5d9d.1577111872.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 2/6] golang/xenlight: begin Go to C type marshaling 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Implement conversion of basic type conversions such as strings and integer types in toC functions. Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 80 ++ tools/golang/xenlight/helpers.gen.go | 1015 ++++++++++++++++++++++++++ 2 files changed, 1095 insertions(+) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index 8857e2e8fd..9d5f8300a2 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -234,6 +234,9 @@ def xenlight_golang_generate_helpers(path = None, types = None, comment = None): f.write(extra) f.write('\n') + f.write(xenlight_golang_define_to_C(ty)) + f.write('\n') + go_fmt(path) def xenlight_golang_define_from_C(ty = None): @@ -434,6 +437,83 @@ def xenlight_golang_array_from_C(ty = None): return s +def xenlight_golang_define_to_C(ty = None, typename = None, nested = False): + s = '' + + gotypename = ctypename = '' + + if typename is not None: + gotypename = xenlight_golang_fmt_name(typename) + ctypename = typename + else: + gotypename = xenlight_golang_fmt_name(ty.typename) + ctypename = ty.typename + + if not nested: + s += 'func (x *{}) toC() (xc C.{},err error) {{\n'.format(gotypename,ctypename) + s += 'C.{}(&xc)\n'.format(ty.init_fn) + + for f in ty.fields: + if f.type.typename is not None: + if isinstance(f.type, idl.Array): + # TODO + continue + + gotypename = xenlight_golang_fmt_name(f.type.typename) + ctypename = f.type.typename + gofname = xenlight_golang_fmt_name(f.name) + cfname = f.name + + # In cgo, C names that conflict with Go keywords can be + # accessed by prepending an underscore to the name. + if cfname in go_keywords: + cfname = '_' + cfname + + # If this is nested, we need the outer name too. + if nested and typename is not None: + goname = xenlight_golang_fmt_name(typename) + goname = '{}.{}'.format(goname, gofname) + cname = '{}.{}'.format(typename, cfname) + + else: + goname = gofname + cname = cfname + + is_castable = (f.type.json_parse_type == 'JSON_INTEGER' or + isinstance(f.type, idl.Enumeration) or + gotypename in go_builtin_types) + + if is_castable: + # Use the cgo helper for converting C strings. + if gotypename == 'string': + s += 'xc.{} = C.CString(x.{})\n'.format(cname,goname) + continue + + s += 'xc.{} = C.{}(x.{})\n'.format(cname,ctypename,goname) + + else: + s += 'xc.{}, err = x.{}.toC()\n'.format(cname,goname) + s += 'if err != nil {\n' + s += 'C.{}(&xc)\n'.format(ty.dispose_fn) + s += 'return xc, err\n' + s += '}\n' + + elif isinstance(f.type, idl.Struct): + s += xenlight_golang_define_to_C(f.type, typename=f.name, nested=True) + + elif isinstance(f.type, idl.KeyedUnion): + # TODO + pass + + else: + raise Exception('type {} not supported'.format(f.type)) + + if not nested: + s += 'return xc, nil' + s += '}\n' + + return s + def xenlight_golang_fmt_name(name, exported = True): """ Take a given type name and return an diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 25294ba292..be80d6c718 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -37,6 +37,13 @@ func (x *IoportRange) fromC(xc *C.libxl_ioport_range) error { return nil } +func (x *IoportRange) toC() (xc C.libxl_ioport_range, err error) { + C.libxl_ioport_range_init(&xc) + xc.first = C.uint32_t(x.First) + xc.number = C.uint32_t(x.Number) + return xc, nil +} + func (x *IomemRange) fromC(xc *C.libxl_iomem_range) error { x.Start = uint64(xc.start) x.Number = uint64(xc.number) @@ -45,12 +52,26 @@ func (x *IomemRange) fromC(xc *C.libxl_iomem_range) error { return nil } +func (x *IomemRange) toC() (xc C.libxl_iomem_range, err error) { + C.libxl_iomem_range_init(&xc) + xc.start = C.uint64_t(x.Start) + xc.number = C.uint64_t(x.Number) + xc.gfn = C.uint64_t(x.Gfn) + return xc, nil +} + func (x *VgaInterfaceInfo) fromC(xc *C.libxl_vga_interface_info) error { x.Kind = VgaInterfaceType(xc.kind) return nil } +func (x *VgaInterfaceInfo) toC() (xc C.libxl_vga_interface_info, err error) { + C.libxl_vga_interface_info_init(&xc) + xc.kind = C.libxl_vga_interface_type(x.Kind) + return xc, nil +} + func (x *VncInfo) fromC(xc *C.libxl_vnc_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { return err @@ -65,6 +86,24 @@ func (x *VncInfo) fromC(xc *C.libxl_vnc_info) error { return nil } +func (x *VncInfo) toC() (xc C.libxl_vnc_info, err error) { + C.libxl_vnc_info_init(&xc) + xc.enable, err = x.Enable.toC() + if err != nil { + C.libxl_vnc_info_dispose(&xc) + return xc, err + } + xc.listen = C.CString(x.Listen) + xc.passwd = C.CString(x.Passwd) + xc.display = C.int(x.Display) + xc.findunused, err = x.Findunused.toC() + if err != nil { + C.libxl_vnc_info_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *SpiceInfo) fromC(xc *C.libxl_spice_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { return err @@ -92,6 +131,43 @@ func (x *SpiceInfo) fromC(xc *C.libxl_spice_info) error { return nil } +func (x *SpiceInfo) toC() (xc C.libxl_spice_info, err error) { + C.libxl_spice_info_init(&xc) + xc.enable, err = x.Enable.toC() + if err != nil { + C.libxl_spice_info_dispose(&xc) + return xc, err + } + xc.port = C.int(x.Port) + xc.tls_port = C.int(x.TlsPort) + xc.host = C.CString(x.Host) + xc.disable_ticketing, err = x.DisableTicketing.toC() + if err != nil { + C.libxl_spice_info_dispose(&xc) + return xc, err + } + xc.passwd = C.CString(x.Passwd) + xc.agent_mouse, err = x.AgentMouse.toC() + if err != nil { + C.libxl_spice_info_dispose(&xc) + return xc, err + } + xc.vdagent, err = x.Vdagent.toC() + if err != nil { + C.libxl_spice_info_dispose(&xc) + return xc, err + } + xc.clipboard_sharing, err = x.ClipboardSharing.toC() + if err != nil { + C.libxl_spice_info_dispose(&xc) + return xc, err + } + xc.usbredirection = C.int(x.Usbredirection) + xc.image_compression = C.CString(x.ImageCompression) + xc.streaming_video = C.CString(x.StreamingVideo) + return xc, nil +} + func (x *SdlInfo) fromC(xc *C.libxl_sdl_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { return err @@ -105,6 +181,23 @@ func (x *SdlInfo) fromC(xc *C.libxl_sdl_info) error { return nil } +func (x *SdlInfo) toC() (xc C.libxl_sdl_info, err error) { + C.libxl_sdl_info_init(&xc) + xc.enable, err = x.Enable.toC() + if err != nil { + C.libxl_sdl_info_dispose(&xc) + return xc, err + } + xc.opengl, err = x.Opengl.toC() + if err != nil { + C.libxl_sdl_info_dispose(&xc) + return xc, err + } + xc.display = C.CString(x.Display) + xc.xauthority = C.CString(x.Xauthority) + return xc, nil +} + func (x *Dominfo) fromC(xc *C.libxl_dominfo) error { if err := x.Uuid.fromC(&xc.uuid); err != nil { return err @@ -133,6 +226,36 @@ func (x *Dominfo) fromC(xc *C.libxl_dominfo) error { return nil } +func (x *Dominfo) toC() (xc C.libxl_dominfo, err error) { + C.libxl_dominfo_init(&xc) + xc.uuid, err = x.Uuid.toC() + if err != nil { + C.libxl_dominfo_dispose(&xc) + return xc, err + } + xc.domid = C.libxl_domid(x.Domid) + xc.ssidref = C.uint32_t(x.Ssidref) + xc.ssid_label = C.CString(x.SsidLabel) + xc.running = C.bool(x.Running) + xc.blocked = C.bool(x.Blocked) + xc.paused = C.bool(x.Paused) + xc.shutdown = C.bool(x.Shutdown) + xc.dying = C.bool(x.Dying) + xc.never_stop = C.bool(x.NeverStop) + xc.shutdown_reason = C.libxl_shutdown_reason(x.ShutdownReason) + xc.outstanding_memkb = C.uint64_t(x.OutstandingMemkb) + xc.current_memkb = C.uint64_t(x.CurrentMemkb) + xc.shared_memkb = C.uint64_t(x.SharedMemkb) + xc.paged_memkb = C.uint64_t(x.PagedMemkb) + xc.max_memkb = C.uint64_t(x.MaxMemkb) + xc.cpu_time = C.uint64_t(x.CpuTime) + xc.vcpu_max_id = C.uint32_t(x.VcpuMaxId) + xc.vcpu_online = C.uint32_t(x.VcpuOnline) + xc.cpupool = C.uint32_t(x.Cpupool) + xc.domain_type = C.libxl_domain_type(x.DomainType) + return xc, nil +} + func (x *Cpupoolinfo) fromC(xc *C.libxl_cpupoolinfo) error { x.Poolid = uint32(xc.poolid) x.PoolName = C.GoString(xc.pool_name) @@ -145,6 +268,20 @@ func (x *Cpupoolinfo) fromC(xc *C.libxl_cpupoolinfo) error { return nil } +func (x *Cpupoolinfo) toC() (xc C.libxl_cpupoolinfo, err error) { + C.libxl_cpupoolinfo_init(&xc) + xc.poolid = C.uint32_t(x.Poolid) + xc.pool_name = C.CString(x.PoolName) + xc.sched = C.libxl_scheduler(x.Sched) + xc.n_dom = C.uint32_t(x.NDom) + xc.cpumap, err = x.Cpumap.toC() + if err != nil { + C.libxl_cpupoolinfo_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *Channelinfo) fromC(xc *C.libxl_channelinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -179,6 +316,19 @@ func (x *ChannelinfoConnectionUnionPty) fromC(xc *C.libxl_channelinfo) error { return nil } +func (x *Channelinfo) toC() (xc C.libxl_channelinfo, err error) { + C.libxl_channelinfo_init(&xc) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + xc.evtch = C.int(x.Evtch) + xc.rref = C.int(x.Rref) + return xc, nil +} + func (x *Vminfo) fromC(xc *C.libxl_vminfo) error { if err := x.Uuid.fromC(&xc.uuid); err != nil { return err @@ -188,6 +338,17 @@ func (x *Vminfo) fromC(xc *C.libxl_vminfo) error { return nil } +func (x *Vminfo) toC() (xc C.libxl_vminfo, err error) { + C.libxl_vminfo_init(&xc) + xc.uuid, err = x.Uuid.toC() + if err != nil { + C.libxl_vminfo_dispose(&xc) + return xc, err + } + xc.domid = C.libxl_domid(x.Domid) + return xc, nil +} + func (x *VersionInfo) fromC(xc *C.libxl_version_info) error { x.XenVersionMajor = int(xc.xen_version_major) x.XenVersionMinor = int(xc.xen_version_minor) @@ -206,6 +367,24 @@ func (x *VersionInfo) fromC(xc *C.libxl_version_info) error { return nil } +func (x *VersionInfo) toC() (xc C.libxl_version_info, err error) { + C.libxl_version_info_init(&xc) + xc.xen_version_major = C.int(x.XenVersionMajor) + xc.xen_version_minor = C.int(x.XenVersionMinor) + xc.xen_version_extra = C.CString(x.XenVersionExtra) + xc.compiler = C.CString(x.Compiler) + xc.compile_by = C.CString(x.CompileBy) + xc.compile_domain = C.CString(x.CompileDomain) + xc.compile_date = C.CString(x.CompileDate) + xc.capabilities = C.CString(x.Capabilities) + xc.changeset = C.CString(x.Changeset) + xc.virt_start = C.uint64_t(x.VirtStart) + xc.pagesize = C.int(x.Pagesize) + xc.commandline = C.CString(x.Commandline) + xc.build_id = C.CString(x.BuildId) + return xc, nil +} + func (x *DomainCreateInfo) fromC(xc *C.libxl_domain_create_info) error { x.Type = DomainType(xc._type) if err := x.Hap.fromC(&xc.hap); err != nil { @@ -239,6 +418,53 @@ func (x *DomainCreateInfo) fromC(xc *C.libxl_domain_create_info) error { return nil } +func (x *DomainCreateInfo) toC() (xc C.libxl_domain_create_info, err error) { + C.libxl_domain_create_info_init(&xc) + xc._type = C.libxl_domain_type(x.Type) + xc.hap, err = x.Hap.toC() + if err != nil { + C.libxl_domain_create_info_dispose(&xc) + return xc, err + } + xc.oos, err = x.Oos.toC() + if err != nil { + C.libxl_domain_create_info_dispose(&xc) + return xc, err + } + xc.ssidref = C.uint32_t(x.Ssidref) + xc.ssid_label = C.CString(x.SsidLabel) + xc.name = C.CString(x.Name) + xc.uuid, err = x.Uuid.toC() + if err != nil { + C.libxl_domain_create_info_dispose(&xc) + return xc, err + } + xc.xsdata, err = x.Xsdata.toC() + if err != nil { + C.libxl_domain_create_info_dispose(&xc) + return xc, err + } + xc.platformdata, err = x.Platformdata.toC() + if err != nil { + C.libxl_domain_create_info_dispose(&xc) + return xc, err + } + xc.poolid = C.uint32_t(x.Poolid) + xc.pool_name = C.CString(x.PoolName) + xc.run_hotplug_scripts, err = x.RunHotplugScripts.toC() + if err != nil { + C.libxl_domain_create_info_dispose(&xc) + return xc, err + } + xc.driver_domain, err = x.DriverDomain.toC() + if err != nil { + C.libxl_domain_create_info_dispose(&xc) + return xc, err + } + xc.passthrough = C.libxl_passthrough(x.Passthrough) + return xc, nil +} + func (x *DomainRestoreParams) fromC(xc *C.libxl_domain_restore_params) error { x.CheckpointedStream = int(xc.checkpointed_stream) x.StreamVersion = uint32(xc.stream_version) @@ -250,6 +476,19 @@ func (x *DomainRestoreParams) fromC(xc *C.libxl_domain_restore_params) error { return nil } +func (x *DomainRestoreParams) toC() (xc C.libxl_domain_restore_params, err error) { + C.libxl_domain_restore_params_init(&xc) + xc.checkpointed_stream = C.int(x.CheckpointedStream) + xc.stream_version = C.uint32_t(x.StreamVersion) + xc.colo_proxy_script = C.CString(x.ColoProxyScript) + xc.userspace_colo_proxy, err = x.UserspaceColoProxy.toC() + if err != nil { + C.libxl_domain_restore_params_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *SchedParams) fromC(xc *C.libxl_sched_params) error { x.Vcpuid = int(xc.vcpuid) x.Weight = int(xc.weight) @@ -261,6 +500,17 @@ func (x *SchedParams) fromC(xc *C.libxl_sched_params) error { return nil } +func (x *SchedParams) toC() (xc C.libxl_sched_params, err error) { + C.libxl_sched_params_init(&xc) + xc.vcpuid = C.int(x.Vcpuid) + xc.weight = C.int(x.Weight) + xc.cap = C.int(x.Cap) + xc.period = C.int(x.Period) + xc.extratime = C.int(x.Extratime) + xc.budget = C.int(x.Budget) + return xc, nil +} + func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { x.Sched = Scheduler(xc.sched) numVcpus := int(xc.num_vcpus) @@ -275,6 +525,12 @@ func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { return nil } +func (x *VcpuSchedParams) toC() (xc C.libxl_vcpu_sched_params, err error) { + C.libxl_vcpu_sched_params_init(&xc) + xc.sched = C.libxl_scheduler(x.Sched) + return xc, nil +} + func (x *DomainSchedParams) fromC(xc *C.libxl_domain_sched_params) error { x.Sched = Scheduler(xc.sched) x.Weight = int(xc.weight) @@ -288,6 +544,19 @@ func (x *DomainSchedParams) fromC(xc *C.libxl_domain_sched_params) error { return nil } +func (x *DomainSchedParams) toC() (xc C.libxl_domain_sched_params, err error) { + C.libxl_domain_sched_params_init(&xc) + xc.sched = C.libxl_scheduler(x.Sched) + xc.weight = C.int(x.Weight) + xc.cap = C.int(x.Cap) + xc.period = C.int(x.Period) + xc.budget = C.int(x.Budget) + xc.extratime = C.int(x.Extratime) + xc.slice = C.int(x.Slice) + xc.latency = C.int(x.Latency) + return xc, nil +} + func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { x.Memkb = uint64(xc.memkb) numDistances := int(xc.num_distances) @@ -304,6 +573,18 @@ func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { return nil } +func (x *VnodeInfo) toC() (xc C.libxl_vnode_info, err error) { + C.libxl_vnode_info_init(&xc) + xc.memkb = C.uint64_t(x.Memkb) + xc.pnode = C.uint32_t(x.Pnode) + xc.vcpus, err = x.Vcpus.toC() + if err != nil { + C.libxl_vnode_info_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *RdmReserve) fromC(xc *C.libxl_rdm_reserve) error { x.Strategy = RdmReserveStrategy(xc.strategy) x.Policy = RdmReservePolicy(xc.policy) @@ -311,6 +592,13 @@ func (x *RdmReserve) fromC(xc *C.libxl_rdm_reserve) error { return nil } +func (x *RdmReserve) toC() (xc C.libxl_rdm_reserve, err error) { + C.libxl_rdm_reserve_init(&xc) + xc.strategy = C.libxl_rdm_reserve_strategy(x.Strategy) + xc.policy = C.libxl_rdm_reserve_policy(x.Policy) + return xc, nil +} + func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.MaxVcpus = int(xc.max_vcpus) if err := x.AvailVcpus.fromC(&xc.avail_vcpus); err != nil { @@ -613,6 +901,130 @@ func (x *DomainBuildInfoTypeUnionPvh) fromC(xc *C.libxl_domain_build_info) error return nil } +func (x *DomainBuildInfo) toC() (xc C.libxl_domain_build_info, err error) { + C.libxl_domain_build_info_init(&xc) + xc.max_vcpus = C.int(x.MaxVcpus) + xc.avail_vcpus, err = x.AvailVcpus.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.cpumap, err = x.Cpumap.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.nodemap, err = x.Nodemap.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.numa_placement, err = x.NumaPlacement.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.tsc_mode = C.libxl_tsc_mode(x.TscMode) + xc.max_memkb = C.uint64_t(x.MaxMemkb) + xc.target_memkb = C.uint64_t(x.TargetMemkb) + xc.video_memkb = C.uint64_t(x.VideoMemkb) + xc.shadow_memkb = C.uint64_t(x.ShadowMemkb) + xc.iommu_memkb = C.uint64_t(x.IommuMemkb) + xc.rtc_timeoffset = C.uint32_t(x.RtcTimeoffset) + xc.exec_ssidref = C.uint32_t(x.ExecSsidref) + xc.exec_ssid_label = C.CString(x.ExecSsidLabel) + xc.localtime, err = x.Localtime.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.disable_migrate, err = x.DisableMigrate.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.cpuid, err = x.Cpuid.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.blkdev_start = C.CString(x.BlkdevStart) + xc.max_grant_frames = C.uint32_t(x.MaxGrantFrames) + xc.max_maptrack_frames = C.uint32_t(x.MaxMaptrackFrames) + xc.device_model_version = C.libxl_device_model_version(x.DeviceModelVersion) + xc.device_model_stubdomain, err = x.DeviceModelStubdomain.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.device_model = C.CString(x.DeviceModel) + xc.device_model_ssidref = C.uint32_t(x.DeviceModelSsidref) + xc.device_model_ssid_label = C.CString(x.DeviceModelSsidLabel) + xc.device_model_user = C.CString(x.DeviceModelUser) + xc.extra, err = x.Extra.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.extra_pv, err = x.ExtraPv.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.extra_hvm, err = x.ExtraHvm.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.sched_params, err = x.SchedParams.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.claim_mode, err = x.ClaimMode.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.event_channels = C.uint32_t(x.EventChannels) + xc.kernel = C.CString(x.Kernel) + xc.cmdline = C.CString(x.Cmdline) + xc.ramdisk = C.CString(x.Ramdisk) + xc.device_tree = C.CString(x.DeviceTree) + xc.acpi, err = x.Acpi.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.bootloader = C.CString(x.Bootloader) + xc.bootloader_args, err = x.BootloaderArgs.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.timer_mode = C.libxl_timer_mode(x.TimerMode) + xc.nested_hvm, err = x.NestedHvm.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.apic, err = x.Apic.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.dm_restrict, err = x.DmRestrict.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + xc.tee = C.libxl_tee_type(x.Tee) + xc.arch_arm.gic_version = C.libxl_gic_version(x.ArchArm.GicVersion) + xc.arch_arm.vuart = C.libxl_vuart_type(x.ArchArm.Vuart) + xc.altp2m = C.libxl_altp2m_mode(x.Altp2M) + return xc, nil +} + func (x *DeviceVfb) fromC(xc *C.libxl_device_vfb) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -628,6 +1040,25 @@ func (x *DeviceVfb) fromC(xc *C.libxl_device_vfb) error { return nil } +func (x *DeviceVfb) toC() (xc C.libxl_device_vfb, err error) { + C.libxl_device_vfb_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + xc.vnc, err = x.Vnc.toC() + if err != nil { + C.libxl_device_vfb_dispose(&xc) + return xc, err + } + xc.sdl, err = x.Sdl.toC() + if err != nil { + C.libxl_device_vfb_dispose(&xc) + return xc, err + } + xc.keymap = C.CString(x.Keymap) + return xc, nil +} + func (x *DeviceVkb) fromC(xc *C.libxl_device_vkb) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -648,6 +1079,26 @@ func (x *DeviceVkb) fromC(xc *C.libxl_device_vkb) error { return nil } +func (x *DeviceVkb) toC() (xc C.libxl_device_vkb, err error) { + C.libxl_device_vkb_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + xc.backend_type = C.libxl_vkb_backend(x.BackendType) + xc.unique_id = C.CString(x.UniqueId) + xc.feature_disable_keyboard = C.bool(x.FeatureDisableKeyboard) + xc.feature_disable_pointer = C.bool(x.FeatureDisablePointer) + xc.feature_abs_pointer = C.bool(x.FeatureAbsPointer) + xc.feature_raw_pointer = C.bool(x.FeatureRawPointer) + xc.feature_multi_touch = C.bool(x.FeatureMultiTouch) + xc.width = C.uint32_t(x.Width) + xc.height = C.uint32_t(x.Height) + xc.multi_touch_width = C.uint32_t(x.MultiTouchWidth) + xc.multi_touch_height = C.uint32_t(x.MultiTouchHeight) + xc.multi_touch_num_contacts = C.uint32_t(x.MultiTouchNumContacts) + return xc, nil +} + func (x *DeviceDisk) fromC(xc *C.libxl_device_disk) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -678,6 +1129,42 @@ func (x *DeviceDisk) fromC(xc *C.libxl_device_disk) error { return nil } +func (x *DeviceDisk) toC() (xc C.libxl_device_disk, err error) { + C.libxl_device_disk_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.pdev_path = C.CString(x.PdevPath) + xc.vdev = C.CString(x.Vdev) + xc.backend = C.libxl_disk_backend(x.Backend) + xc.format = C.libxl_disk_format(x.Format) + xc.script = C.CString(x.Script) + xc.removable = C.int(x.Removable) + xc.readwrite = C.int(x.Readwrite) + xc.is_cdrom = C.int(x.IsCdrom) + xc.direct_io_safe = C.bool(x.DirectIoSafe) + xc.discard_enable, err = x.DiscardEnable.toC() + if err != nil { + C.libxl_device_disk_dispose(&xc) + return xc, err + } + xc.colo_enable, err = x.ColoEnable.toC() + if err != nil { + C.libxl_device_disk_dispose(&xc) + return xc, err + } + xc.colo_restore_enable, err = x.ColoRestoreEnable.toC() + if err != nil { + C.libxl_device_disk_dispose(&xc) + return xc, err + } + xc.colo_host = C.CString(x.ColoHost) + xc.colo_port = C.int(x.ColoPort) + xc.colo_export = C.CString(x.ColoExport) + xc.active_disk = C.CString(x.ActiveDisk) + xc.hidden_disk = C.CString(x.HiddenDisk) + return xc, nil +} + func (x *DeviceNic) fromC(xc *C.libxl_device_nic) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -748,6 +1235,78 @@ func (x *DeviceNic) fromC(xc *C.libxl_device_nic) error { return nil } +func (x *DeviceNic) toC() (xc C.libxl_device_nic, err error) { + C.libxl_device_nic_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + xc.mtu = C.int(x.Mtu) + xc.model = C.CString(x.Model) + xc.mac, err = x.Mac.toC() + if err != nil { + C.libxl_device_nic_dispose(&xc) + return xc, err + } + xc.ip = C.CString(x.Ip) + xc.bridge = C.CString(x.Bridge) + xc.ifname = C.CString(x.Ifname) + xc.script = C.CString(x.Script) + xc.nictype = C.libxl_nic_type(x.Nictype) + xc.rate_bytes_per_interval = C.uint64_t(x.RateBytesPerInterval) + xc.rate_interval_usecs = C.uint32_t(x.RateIntervalUsecs) + xc.gatewaydev = C.CString(x.Gatewaydev) + xc.coloft_forwarddev = C.CString(x.ColoftForwarddev) + xc.colo_sock_mirror_id = C.CString(x.ColoSockMirrorId) + xc.colo_sock_mirror_ip = C.CString(x.ColoSockMirrorIp) + xc.colo_sock_mirror_port = C.CString(x.ColoSockMirrorPort) + xc.colo_sock_compare_pri_in_id = C.CString(x.ColoSockComparePriInId) + xc.colo_sock_compare_pri_in_ip = C.CString(x.ColoSockComparePriInIp) + xc.colo_sock_compare_pri_in_port = C.CString(x.ColoSockComparePriInPort) + xc.colo_sock_compare_sec_in_id = C.CString(x.ColoSockCompareSecInId) + xc.colo_sock_compare_sec_in_ip = C.CString(x.ColoSockCompareSecInIp) + xc.colo_sock_compare_sec_in_port = C.CString(x.ColoSockCompareSecInPort) + xc.colo_sock_compare_notify_id = C.CString(x.ColoSockCompareNotifyId) + xc.colo_sock_compare_notify_ip = C.CString(x.ColoSockCompareNotifyIp) + xc.colo_sock_compare_notify_port = C.CString(x.ColoSockCompareNotifyPort) + xc.colo_sock_redirector0_id = C.CString(x.ColoSockRedirector0Id) + xc.colo_sock_redirector0_ip = C.CString(x.ColoSockRedirector0Ip) + xc.colo_sock_redirector0_port = C.CString(x.ColoSockRedirector0Port) + xc.colo_sock_redirector1_id = C.CString(x.ColoSockRedirector1Id) + xc.colo_sock_redirector1_ip = C.CString(x.ColoSockRedirector1Ip) + xc.colo_sock_redirector1_port = C.CString(x.ColoSockRedirector1Port) + xc.colo_sock_redirector2_id = C.CString(x.ColoSockRedirector2Id) + xc.colo_sock_redirector2_ip = C.CString(x.ColoSockRedirector2Ip) + xc.colo_sock_redirector2_port = C.CString(x.ColoSockRedirector2Port) + xc.colo_filter_mirror_queue = C.CString(x.ColoFilterMirrorQueue) + xc.colo_filter_mirror_outdev = C.CString(x.ColoFilterMirrorOutdev) + xc.colo_filter_redirector0_queue = C.CString(x.ColoFilterRedirector0Queue) + xc.colo_filter_redirector0_indev = C.CString(x.ColoFilterRedirector0Indev) + xc.colo_filter_redirector0_outdev = C.CString(x.ColoFilterRedirector0Outdev) + xc.colo_filter_redirector1_queue = C.CString(x.ColoFilterRedirector1Queue) + xc.colo_filter_redirector1_indev = C.CString(x.ColoFilterRedirector1Indev) + xc.colo_filter_redirector1_outdev = C.CString(x.ColoFilterRedirector1Outdev) + xc.colo_compare_pri_in = C.CString(x.ColoComparePriIn) + xc.colo_compare_sec_in = C.CString(x.ColoCompareSecIn) + xc.colo_compare_out = C.CString(x.ColoCompareOut) + xc.colo_compare_notify_dev = C.CString(x.ColoCompareNotifyDev) + xc.colo_sock_sec_redirector0_id = C.CString(x.ColoSockSecRedirector0Id) + xc.colo_sock_sec_redirector0_ip = C.CString(x.ColoSockSecRedirector0Ip) + xc.colo_sock_sec_redirector0_port = C.CString(x.ColoSockSecRedirector0Port) + xc.colo_sock_sec_redirector1_id = C.CString(x.ColoSockSecRedirector1Id) + xc.colo_sock_sec_redirector1_ip = C.CString(x.ColoSockSecRedirector1Ip) + xc.colo_sock_sec_redirector1_port = C.CString(x.ColoSockSecRedirector1Port) + xc.colo_filter_sec_redirector0_queue = C.CString(x.ColoFilterSecRedirector0Queue) + xc.colo_filter_sec_redirector0_indev = C.CString(x.ColoFilterSecRedirector0Indev) + xc.colo_filter_sec_redirector0_outdev = C.CString(x.ColoFilterSecRedirector0Outdev) + xc.colo_filter_sec_redirector1_queue = C.CString(x.ColoFilterSecRedirector1Queue) + xc.colo_filter_sec_redirector1_indev = C.CString(x.ColoFilterSecRedirector1Indev) + xc.colo_filter_sec_redirector1_outdev = C.CString(x.ColoFilterSecRedirector1Outdev) + xc.colo_filter_sec_rewriter0_queue = C.CString(x.ColoFilterSecRewriter0Queue) + xc.colo_checkpoint_host = C.CString(x.ColoCheckpointHost) + xc.colo_checkpoint_port = C.CString(x.ColoCheckpointPort) + return xc, nil +} + func (x *DevicePci) fromC(xc *C.libxl_device_pci) error { x.Func = byte(xc._func) x.Dev = byte(xc.dev) @@ -764,6 +1323,22 @@ func (x *DevicePci) fromC(xc *C.libxl_device_pci) error { return nil } +func (x *DevicePci) toC() (xc C.libxl_device_pci, err error) { + C.libxl_device_pci_init(&xc) + xc._func = C.uint8_t(x.Func) + xc.dev = C.uint8_t(x.Dev) + xc.bus = C.uint8_t(x.Bus) + xc.domain = C.int(x.Domain) + xc.vdevfn = C.uint32_t(x.Vdevfn) + xc.vfunc_mask = C.uint32_t(x.VfuncMask) + xc.msitranslate = C.bool(x.Msitranslate) + xc.power_mgmt = C.bool(x.PowerMgmt) + xc.permissive = C.bool(x.Permissive) + xc.seize = C.bool(x.Seize) + xc.rdm_policy = C.libxl_rdm_reserve_policy(x.RdmPolicy) + return xc, nil +} + func (x *DeviceRdm) fromC(xc *C.libxl_device_rdm) error { x.Start = uint64(xc.start) x.Size = uint64(xc.size) @@ -772,6 +1347,14 @@ func (x *DeviceRdm) fromC(xc *C.libxl_device_rdm) error { return nil } +func (x *DeviceRdm) toC() (xc C.libxl_device_rdm, err error) { + C.libxl_device_rdm_init(&xc) + xc.start = C.uint64_t(x.Start) + xc.size = C.uint64_t(x.Size) + xc.policy = C.libxl_rdm_reserve_policy(x.Policy) + return xc, nil +} + func (x *DeviceUsbctrl) fromC(xc *C.libxl_device_usbctrl) error { x.Type = UsbctrlType(xc._type) x.Devid = Devid(xc.devid) @@ -783,6 +1366,17 @@ func (x *DeviceUsbctrl) fromC(xc *C.libxl_device_usbctrl) error { return nil } +func (x *DeviceUsbctrl) toC() (xc C.libxl_device_usbctrl, err error) { + C.libxl_device_usbctrl_init(&xc) + xc._type = C.libxl_usbctrl_type(x.Type) + xc.devid = C.libxl_devid(x.Devid) + xc.version = C.int(x.Version) + xc.ports = C.int(x.Ports) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + return xc, nil +} + func (x *DeviceUsbdev) fromC(xc *C.libxl_device_usbdev) error { x.Ctrl = Devid(xc.ctrl) x.Port = int(xc.port) @@ -812,12 +1406,25 @@ func (x *DeviceUsbdevTypeUnionHostdev) fromC(xc *C.libxl_device_usbdev) error { return nil } +func (x *DeviceUsbdev) toC() (xc C.libxl_device_usbdev, err error) { + C.libxl_device_usbdev_init(&xc) + xc.ctrl = C.libxl_devid(x.Ctrl) + xc.port = C.int(x.Port) + return xc, nil +} + func (x *DeviceDtdev) fromC(xc *C.libxl_device_dtdev) error { x.Path = C.GoString(xc.path) return nil } +func (x *DeviceDtdev) toC() (xc C.libxl_device_dtdev, err error) { + C.libxl_device_dtdev_init(&xc) + xc.path = C.CString(x.Path) + return xc, nil +} + func (x *DeviceVtpm) fromC(xc *C.libxl_device_vtpm) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -829,6 +1436,19 @@ func (x *DeviceVtpm) fromC(xc *C.libxl_device_vtpm) error { return nil } +func (x *DeviceVtpm) toC() (xc C.libxl_device_vtpm, err error) { + C.libxl_device_vtpm_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + xc.uuid, err = x.Uuid.toC() + if err != nil { + C.libxl_device_vtpm_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *DeviceP9) fromC(xc *C.libxl_device_p9) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -840,6 +1460,17 @@ func (x *DeviceP9) fromC(xc *C.libxl_device_p9) error { return nil } +func (x *DeviceP9) toC() (xc C.libxl_device_p9, err error) { + C.libxl_device_p9_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.tag = C.CString(x.Tag) + xc.path = C.CString(x.Path) + xc.security_model = C.CString(x.SecurityModel) + xc.devid = C.libxl_devid(x.Devid) + return xc, nil +} + func (x *DevicePvcallsif) fromC(xc *C.libxl_device_pvcallsif) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -848,6 +1479,14 @@ func (x *DevicePvcallsif) fromC(xc *C.libxl_device_pvcallsif) error { return nil } +func (x *DevicePvcallsif) toC() (xc C.libxl_device_pvcallsif, err error) { + C.libxl_device_pvcallsif_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + return xc, nil +} + func (x *DeviceChannel) fromC(xc *C.libxl_device_channel) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -878,6 +1517,15 @@ func (x *DeviceChannelConnectionUnionSocket) fromC(xc *C.libxl_device_channel) e return nil } +func (x *DeviceChannel) toC() (xc C.libxl_device_channel, err error) { + C.libxl_device_channel_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + xc.name = C.CString(x.Name) + return xc, nil +} + func (x *ConnectorParam) fromC(xc *C.libxl_connector_param) error { x.UniqueId = C.GoString(xc.unique_id) x.Width = uint32(xc.width) @@ -886,6 +1534,14 @@ func (x *ConnectorParam) fromC(xc *C.libxl_connector_param) error { return nil } +func (x *ConnectorParam) toC() (xc C.libxl_connector_param, err error) { + C.libxl_connector_param_init(&xc) + xc.unique_id = C.CString(x.UniqueId) + xc.width = C.uint32_t(x.Width) + xc.height = C.uint32_t(x.Height) + return xc, nil +} + func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -903,6 +1559,15 @@ func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error { return nil } +func (x *DeviceVdispl) toC() (xc C.libxl_device_vdispl, err error) { + C.libxl_device_vdispl_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + xc.be_alloc = C.bool(x.BeAlloc) + return xc, nil +} + func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error { numSampleRates := int(xc.num_sample_rates) cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:numSampleRates:numSampleRates] @@ -923,6 +1588,14 @@ func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error { return nil } +func (x *VsndParams) toC() (xc C.libxl_vsnd_params, err error) { + C.libxl_vsnd_params_init(&xc) + xc.channels_min = C.uint32_t(x.ChannelsMin) + xc.channels_max = C.uint32_t(x.ChannelsMax) + xc.buffer_size = C.uint32_t(x.BufferSize) + return xc, nil +} + func (x *VsndStream) fromC(xc *C.libxl_vsnd_stream) error { x.UniqueId = C.GoString(xc.unique_id) x.Type = VsndStreamType(xc._type) @@ -933,6 +1606,18 @@ func (x *VsndStream) fromC(xc *C.libxl_vsnd_stream) error { return nil } +func (x *VsndStream) toC() (xc C.libxl_vsnd_stream, err error) { + C.libxl_vsnd_stream_init(&xc) + xc.unique_id = C.CString(x.UniqueId) + xc._type = C.libxl_vsnd_stream_type(x.Type) + xc.params, err = x.Params.toC() + if err != nil { + C.libxl_vsnd_stream_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *VsndPcm) fromC(xc *C.libxl_vsnd_pcm) error { x.Name = C.GoString(xc.name) if err := x.Params.fromC(&xc.params); err != nil { @@ -950,6 +1635,17 @@ func (x *VsndPcm) fromC(xc *C.libxl_vsnd_pcm) error { return nil } +func (x *VsndPcm) toC() (xc C.libxl_vsnd_pcm, err error) { + C.libxl_vsnd_pcm_init(&xc) + xc.name = C.CString(x.Name) + xc.params, err = x.Params.toC() + if err != nil { + C.libxl_vsnd_pcm_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -971,6 +1667,21 @@ func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error { return nil } +func (x *DeviceVsnd) toC() (xc C.libxl_device_vsnd, err error) { + C.libxl_device_vsnd_init(&xc) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + xc.backend_domname = C.CString(x.BackendDomname) + xc.devid = C.libxl_devid(x.Devid) + xc.short_name = C.CString(x.ShortName) + xc.long_name = C.CString(x.LongName) + xc.params, err = x.Params.toC() + if err != nil { + C.libxl_device_vsnd_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { if err := x.CInfo.fromC(&xc.c_info); err != nil { return err @@ -1107,6 +1818,26 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { return nil } +func (x *DomainConfig) toC() (xc C.libxl_domain_config, err error) { + C.libxl_domain_config_init(&xc) + xc.c_info, err = x.CInfo.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + xc.b_info, err = x.BInfo.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + xc.on_poweroff = C.libxl_action_on_shutdown(x.OnPoweroff) + xc.on_reboot = C.libxl_action_on_shutdown(x.OnReboot) + xc.on_watchdog = C.libxl_action_on_shutdown(x.OnWatchdog) + xc.on_crash = C.libxl_action_on_shutdown(x.OnCrash) + xc.on_soft_reset = C.libxl_action_on_shutdown(x.OnSoftReset) + return xc, nil +} + func (x *Diskinfo) fromC(xc *C.libxl_diskinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -1120,6 +1851,19 @@ func (x *Diskinfo) fromC(xc *C.libxl_diskinfo) error { return nil } +func (x *Diskinfo) toC() (xc C.libxl_diskinfo, err error) { + C.libxl_diskinfo_init(&xc) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + xc.evtch = C.int(x.Evtch) + xc.rref = C.int(x.Rref) + return xc, nil +} + func (x *Nicinfo) fromC(xc *C.libxl_nicinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -1134,6 +1878,20 @@ func (x *Nicinfo) fromC(xc *C.libxl_nicinfo) error { return nil } +func (x *Nicinfo) toC() (xc C.libxl_nicinfo, err error) { + C.libxl_nicinfo_init(&xc) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + xc.evtch = C.int(x.Evtch) + xc.rref_tx = C.int(x.RrefTx) + xc.rref_rx = C.int(x.RrefRx) + return xc, nil +} + func (x *Vtpminfo) fromC(xc *C.libxl_vtpminfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -1150,6 +1908,24 @@ func (x *Vtpminfo) fromC(xc *C.libxl_vtpminfo) error { return nil } +func (x *Vtpminfo) toC() (xc C.libxl_vtpminfo, err error) { + C.libxl_vtpminfo_init(&xc) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + xc.evtch = C.int(x.Evtch) + xc.rref = C.int(x.Rref) + xc.uuid, err = x.Uuid.toC() + if err != nil { + C.libxl_vtpminfo_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *Usbctrlinfo) fromC(xc *C.libxl_usbctrlinfo) error { x.Type = UsbctrlType(xc._type) x.Devid = Devid(xc.devid) @@ -1167,6 +1943,23 @@ func (x *Usbctrlinfo) fromC(xc *C.libxl_usbctrlinfo) error { return nil } +func (x *Usbctrlinfo) toC() (xc C.libxl_usbctrlinfo, err error) { + C.libxl_usbctrlinfo_init(&xc) + xc._type = C.libxl_usbctrl_type(x.Type) + xc.devid = C.libxl_devid(x.Devid) + xc.version = C.int(x.Version) + xc.ports = C.int(x.Ports) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.state = C.int(x.State) + xc.evtch = C.int(x.Evtch) + xc.ref_urb = C.int(x.RefUrb) + xc.ref_conn = C.int(x.RefConn) + return xc, nil +} + func (x *Vcpuinfo) fromC(xc *C.libxl_vcpuinfo) error { x.Vcpuid = uint32(xc.vcpuid) x.Cpu = uint32(xc.cpu) @@ -1184,6 +1977,27 @@ func (x *Vcpuinfo) fromC(xc *C.libxl_vcpuinfo) error { return nil } +func (x *Vcpuinfo) toC() (xc C.libxl_vcpuinfo, err error) { + C.libxl_vcpuinfo_init(&xc) + xc.vcpuid = C.uint32_t(x.Vcpuid) + xc.cpu = C.uint32_t(x.Cpu) + xc.online = C.bool(x.Online) + xc.blocked = C.bool(x.Blocked) + xc.running = C.bool(x.Running) + xc.vcpu_time = C.uint64_t(x.VcpuTime) + xc.cpumap, err = x.Cpumap.toC() + if err != nil { + C.libxl_vcpuinfo_dispose(&xc) + return xc, err + } + xc.cpumap_soft, err = x.CpumapSoft.toC() + if err != nil { + C.libxl_vcpuinfo_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *Physinfo) fromC(xc *C.libxl_physinfo) error { x.ThreadsPerCore = uint32(xc.threads_per_core) x.CoresPerSocket = uint32(xc.cores_per_socket) @@ -1211,6 +2025,35 @@ func (x *Physinfo) fromC(xc *C.libxl_physinfo) error { return nil } +func (x *Physinfo) toC() (xc C.libxl_physinfo, err error) { + C.libxl_physinfo_init(&xc) + xc.threads_per_core = C.uint32_t(x.ThreadsPerCore) + xc.cores_per_socket = C.uint32_t(x.CoresPerSocket) + xc.max_cpu_id = C.uint32_t(x.MaxCpuId) + xc.nr_cpus = C.uint32_t(x.NrCpus) + xc.cpu_khz = C.uint32_t(x.CpuKhz) + xc.total_pages = C.uint64_t(x.TotalPages) + xc.free_pages = C.uint64_t(x.FreePages) + xc.scrub_pages = C.uint64_t(x.ScrubPages) + xc.outstanding_pages = C.uint64_t(x.OutstandingPages) + xc.sharing_freed_pages = C.uint64_t(x.SharingFreedPages) + xc.sharing_used_frames = C.uint64_t(x.SharingUsedFrames) + xc.max_possible_mfn = C.uint64_t(x.MaxPossibleMfn) + xc.nr_nodes = C.uint32_t(x.NrNodes) + xc.hw_cap, err = x.HwCap.toC() + if err != nil { + C.libxl_physinfo_dispose(&xc) + return xc, err + } + xc.cap_hvm = C.bool(x.CapHvm) + xc.cap_pv = C.bool(x.CapPv) + xc.cap_hvm_directio = C.bool(x.CapHvmDirectio) + xc.cap_hap = C.bool(x.CapHap) + xc.cap_shadow = C.bool(x.CapShadow) + xc.cap_iommu_hap_pt_share = C.bool(x.CapIommuHapPtShare) + return xc, nil +} + func (x *Connectorinfo) fromC(xc *C.libxl_connectorinfo) error { x.UniqueId = C.GoString(xc.unique_id) x.Width = uint32(xc.width) @@ -1223,6 +2066,18 @@ func (x *Connectorinfo) fromC(xc *C.libxl_connectorinfo) error { return nil } +func (x *Connectorinfo) toC() (xc C.libxl_connectorinfo, err error) { + C.libxl_connectorinfo_init(&xc) + xc.unique_id = C.CString(x.UniqueId) + xc.width = C.uint32_t(x.Width) + xc.height = C.uint32_t(x.Height) + xc.req_evtch = C.int(x.ReqEvtch) + xc.req_rref = C.int(x.ReqRref) + xc.evt_evtch = C.int(x.EvtEvtch) + xc.evt_rref = C.int(x.EvtRref) + return xc, nil +} + func (x *Vdisplinfo) fromC(xc *C.libxl_vdisplinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -1243,6 +2098,18 @@ func (x *Vdisplinfo) fromC(xc *C.libxl_vdisplinfo) error { return nil } +func (x *Vdisplinfo) toC() (xc C.libxl_vdisplinfo, err error) { + C.libxl_vdisplinfo_init(&xc) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + xc.be_alloc = C.bool(x.BeAlloc) + return xc, nil +} + func (x *Streaminfo) fromC(xc *C.libxl_streaminfo) error { x.ReqEvtch = int(xc.req_evtch) x.ReqRref = int(xc.req_rref) @@ -1250,6 +2117,13 @@ func (x *Streaminfo) fromC(xc *C.libxl_streaminfo) error { return nil } +func (x *Streaminfo) toC() (xc C.libxl_streaminfo, err error) { + C.libxl_streaminfo_init(&xc) + xc.req_evtch = C.int(x.ReqEvtch) + xc.req_rref = C.int(x.ReqRref) + return xc, nil +} + func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error { numVsndStreams := int(xc.num_vsnd_streams) cStreams := (*[1 << 28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] @@ -1263,6 +2137,11 @@ func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error { return nil } +func (x *Pcminfo) toC() (xc C.libxl_pcminfo, err error) { + C.libxl_pcminfo_init(&xc) + return xc, nil +} + func (x *Vsndinfo) fromC(xc *C.libxl_vsndinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -1282,6 +2161,17 @@ func (x *Vsndinfo) fromC(xc *C.libxl_vsndinfo) error { return nil } +func (x *Vsndinfo) toC() (xc C.libxl_vsndinfo, err error) { + C.libxl_vsndinfo_init(&xc) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + return xc, nil +} + func (x *Vkbinfo) fromC(xc *C.libxl_vkbinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -1295,6 +2185,19 @@ func (x *Vkbinfo) fromC(xc *C.libxl_vkbinfo) error { return nil } +func (x *Vkbinfo) toC() (xc C.libxl_vkbinfo, err error) { + C.libxl_vkbinfo_init(&xc) + xc.backend = C.CString(x.Backend) + xc.backend_id = C.uint32_t(x.BackendId) + xc.frontend = C.CString(x.Frontend) + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + xc.evtch = C.int(x.Evtch) + xc.rref = C.int(x.Rref) + return xc, nil +} + func (x *Numainfo) fromC(xc *C.libxl_numainfo) error { x.Size = uint64(xc.size) x.Free = uint64(xc.free) @@ -1308,6 +2211,13 @@ func (x *Numainfo) fromC(xc *C.libxl_numainfo) error { return nil } +func (x *Numainfo) toC() (xc C.libxl_numainfo, err error) { + C.libxl_numainfo_init(&xc) + xc.size = C.uint64_t(x.Size) + xc.free = C.uint64_t(x.Free) + return xc, nil +} + func (x *Cputopology) fromC(xc *C.libxl_cputopology) error { x.Core = uint32(xc.core) x.Socket = uint32(xc.socket) @@ -1316,6 +2226,14 @@ func (x *Cputopology) fromC(xc *C.libxl_cputopology) error { return nil } +func (x *Cputopology) toC() (xc C.libxl_cputopology, err error) { + C.libxl_cputopology_init(&xc) + xc.core = C.uint32_t(x.Core) + xc.socket = C.uint32_t(x.Socket) + xc.node = C.uint32_t(x.Node) + return xc, nil +} + func (x *Pcitopology) fromC(xc *C.libxl_pcitopology) error { x.Seg = uint16(xc.seg) x.Bus = byte(xc.bus) @@ -1325,6 +2243,15 @@ func (x *Pcitopology) fromC(xc *C.libxl_pcitopology) error { return nil } +func (x *Pcitopology) toC() (xc C.libxl_pcitopology, err error) { + C.libxl_pcitopology_init(&xc) + xc.seg = C.uint16_t(x.Seg) + xc.bus = C.uint8_t(x.Bus) + xc.devfn = C.uint8_t(x.Devfn) + xc.node = C.uint32_t(x.Node) + return xc, nil +} + func (x *SchedCreditParams) fromC(xc *C.libxl_sched_credit_params) error { x.TsliceMs = int(xc.tslice_ms) x.RatelimitUs = int(xc.ratelimit_us) @@ -1333,12 +2260,26 @@ func (x *SchedCreditParams) fromC(xc *C.libxl_sched_credit_params) error { return nil } +func (x *SchedCreditParams) toC() (xc C.libxl_sched_credit_params, err error) { + C.libxl_sched_credit_params_init(&xc) + xc.tslice_ms = C.int(x.TsliceMs) + xc.ratelimit_us = C.int(x.RatelimitUs) + xc.vcpu_migr_delay_us = C.int(x.VcpuMigrDelayUs) + return xc, nil +} + func (x *SchedCredit2Params) fromC(xc *C.libxl_sched_credit2_params) error { x.RatelimitUs = int(xc.ratelimit_us) return nil } +func (x *SchedCredit2Params) toC() (xc C.libxl_sched_credit2_params, err error) { + C.libxl_sched_credit2_params_init(&xc) + xc.ratelimit_us = C.int(x.RatelimitUs) + return xc, nil +} + func (x *DomainRemusInfo) fromC(xc *C.libxl_domain_remus_info) error { x.Interval = int(xc.interval) if err := x.AllowUnsafe.fromC(&xc.allow_unsafe); err != nil { @@ -1367,6 +2308,48 @@ func (x *DomainRemusInfo) fromC(xc *C.libxl_domain_remus_info) error { return nil } +func (x *DomainRemusInfo) toC() (xc C.libxl_domain_remus_info, err error) { + C.libxl_domain_remus_info_init(&xc) + xc.interval = C.int(x.Interval) + xc.allow_unsafe, err = x.AllowUnsafe.toC() + if err != nil { + C.libxl_domain_remus_info_dispose(&xc) + return xc, err + } + xc.blackhole, err = x.Blackhole.toC() + if err != nil { + C.libxl_domain_remus_info_dispose(&xc) + return xc, err + } + xc.compression, err = x.Compression.toC() + if err != nil { + C.libxl_domain_remus_info_dispose(&xc) + return xc, err + } + xc.netbuf, err = x.Netbuf.toC() + if err != nil { + C.libxl_domain_remus_info_dispose(&xc) + return xc, err + } + xc.netbufscript = C.CString(x.Netbufscript) + xc.diskbuf, err = x.Diskbuf.toC() + if err != nil { + C.libxl_domain_remus_info_dispose(&xc) + return xc, err + } + xc.colo, err = x.Colo.toC() + if err != nil { + C.libxl_domain_remus_info_dispose(&xc) + return xc, err + } + xc.userspace_colo_proxy, err = x.UserspaceColoProxy.toC() + if err != nil { + C.libxl_domain_remus_info_dispose(&xc) + return xc, err + } + return xc, nil +} + func (x *Event) fromC(xc *C.libxl_event) error { if err := x.Link.fromC(&xc.link); err != nil { return err @@ -1436,6 +2419,23 @@ func (x *EventTypeUnionOperationComplete) fromC(xc *C.libxl_event) error { return nil } +func (x *Event) toC() (xc C.libxl_event, err error) { + C.libxl_event_init(&xc) + xc.link, err = x.Link.toC() + if err != nil { + C.libxl_event_dispose(&xc) + return xc, err + } + xc.domid = C.libxl_domid(x.Domid) + xc.domuuid, err = x.Domuuid.toC() + if err != nil { + C.libxl_event_dispose(&xc) + return xc, err + } + xc.for_user = C.uint64_t(x.ForUser) + return xc, nil +} + func (x *PsrCatInfo) fromC(xc *C.libxl_psr_cat_info) error { x.Id = uint32(xc.id) x.CosMax = uint32(xc.cos_max) @@ -1445,6 +2445,15 @@ func (x *PsrCatInfo) fromC(xc *C.libxl_psr_cat_info) error { return nil } +func (x *PsrCatInfo) toC() (xc C.libxl_psr_cat_info, err error) { + C.libxl_psr_cat_info_init(&xc) + xc.id = C.uint32_t(x.Id) + xc.cos_max = C.uint32_t(x.CosMax) + xc.cbm_len = C.uint32_t(x.CbmLen) + xc.cdp_enabled = C.bool(x.CdpEnabled) + return xc, nil +} + func (x *PsrHwInfo) fromC(xc *C.libxl_psr_hw_info) error { x.Id = uint32(xc.id) x.Type = PsrFeatType(xc._type) @@ -1491,3 +2500,9 @@ func (x *PsrHwInfoTypeUnionMba) fromC(xc *C.libxl_psr_hw_info) error { x.Linear = bool(tmp.linear) return nil } + +func (x *PsrHwInfo) toC() (xc C.libxl_psr_hw_info, err error) { + C.libxl_psr_hw_info_init(&xc) + xc.id = C.uint32_t(x.Id) + return xc, nil +} From patchwork Mon Dec 23 15:17:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11308457 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 26DFB138D for ; Mon, 23 Dec 2019 15:19:28 +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 EC50C206CB for ; Mon, 23 Dec 2019 15:19:27 +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="kzH123Yk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC50C206CB 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 1ijPT8-0006LW-Q6; Mon, 23 Dec 2019 15:18:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijPT7-0006L9-H9 for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 15:18:01 +0000 X-Inumbo-ID: 61fc91f8-2597-11ea-88e7-bc764e2007e4 Received: from mail-qk1-x735.google.com (unknown [2607:f8b0:4864:20::735]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 61fc91f8-2597-11ea-88e7-bc764e2007e4; Mon, 23 Dec 2019 15:17:50 +0000 (UTC) Received: by mail-qk1-x735.google.com with SMTP id j9so14147210qkk.1 for ; Mon, 23 Dec 2019 07:17:50 -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 :in-reply-to:references; bh=7RvqR+8RmCVrc5ss1vsqFIrpOywrRiZJTYQb8T+T+c0=; b=kzH123YkoHsccstYOcr2Dgk0pz7WpDIc+Up2PGBKnMVFwrgPHB0GY9cCnBSMQXZcSi wZ8TugaOc2zYbeG4bZ2APSnpw2IUe8jqJHI/x2QIbToMDOZ+8WI/aQ0U47Taq+HZte0B 8EcUqO/lSYBQEQkzor4PZkea0pyZfTagOxmau1i+8WFt+IW8cF8/ddEV3OeOucMnNXBt G82SxSniubkFo8Vh3a5nFNwgaCKoSOyMYGzq0T53C5tepeneacTGtVPP4/vcDBIj2OLw Xm4LR6nMchEfi+pnqiLiYXUYqrmNe9Upe679bhIm91M/77GdjbtFawZ1VsCfuzNikgKd 95ew== 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:in-reply-to:references; bh=7RvqR+8RmCVrc5ss1vsqFIrpOywrRiZJTYQb8T+T+c0=; b=bYvprpCjRJl42H5ZpUSlOfksB7o60RB7yRbD8N/fLJtG9dReL03cuYd35QQkGSkgZd IPDMvFISSiijx9zFlXruMIuDyzh9kr4ljwSRNG9lyHvAA7DnH6eGzpf+LntbzEXlne3+ yosLO4l4ttIKLEcEcOAeGV4FqGnK5xl2rjrgozyAi0nTXgOPHPoAO3XBRo8KNqzESqUD 1VVM/DJyiNXtx9Sg3xx9hUNYOUq9Wwwj7G8eg+N03dMXzVKwU/sI7PKivb7LcEz6tYcv XayBMd78+Qck3b4Kfh9V1uWnkoGn629OqxWWtmeNVVXU5E9krb/qDx2RiTgiBIrcHUiS 4aRA== X-Gm-Message-State: APjAAAWdNB6osNskwRkC9VKTpIx0L6JbsQrVzfRDTpFW4S0IPJTfT/Wv bz72LwfNX53f9KtFbWPaOGYdwURx X-Google-Smtp-Source: APXvYqyLu++Cb4wasE9eesQsafB6ZSV7hg+a8xQTFsbyRH/GzxT7GLI0qUL0wUvoAA8H/lQ5co4MCw== X-Received: by 2002:a37:9fc9:: with SMTP id i192mr25652605qke.364.1577114269449; Mon, 23 Dec 2019 07:17:49 -0800 (PST) Received: from four.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id u15sm5823907qku.67.2019.12.23.07.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 07:17:48 -0800 (PST) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 23 Dec 2019 10:17:04 -0500 Message-Id: <76a6287109680626e816c9f2d8f0a7666fef8ee9.1577111872.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 3/6] golang/xenlight: implement keyed union Go to C marshaling 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Since the C union cannot be directly populated, populate the fields of the corresponding C struct defined in the cgo preamble, and then copy that struct as bytes into the byte slice that Go uses as the union. Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 77 ++++++- tools/golang/xenlight/helpers.gen.go | 325 +++++++++++++++++++++++++++ 2 files changed, 400 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index 9d5f8300a2..b377fd9a25 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -502,8 +502,7 @@ def xenlight_golang_define_to_C(ty = None, typename = None, nested = False): s += xenlight_golang_define_to_C(f.type, typename=f.name, nested=True) elif isinstance(f.type, idl.KeyedUnion): - # TODO - pass + s += xenlight_golang_union_to_C(f.type, f.name, ty.typename, ty.dispose_fn) else: raise Exception('type {} not supported'.format(f.type)) @@ -514,6 +513,80 @@ def xenlight_golang_define_to_C(ty = None, typename = None, nested = False): return s +def xenlight_golang_union_to_C(ty = None, union_name = '', + struct_name = '', dispose_fn = ''): + keyname = ty.keyvar.name + gokeyname = xenlight_golang_fmt_name(keyname) + keytype = ty.keyvar.type.typename + gokeytype = xenlight_golang_fmt_name(keytype) + + interface_name = '{}_{}_union'.format(struct_name, keyname) + interface_name = xenlight_golang_fmt_name(interface_name, exported=False) + + cgo_keyname = keyname + if cgo_keyname in go_keywords: + cgo_keyname = '_' + cgo_keyname + + + s = 'xc.{} = C.{}(x.{})\n'.format(cgo_keyname,keytype,gokeyname) + s += 'switch x.{}{{\n'.format(gokeyname) + + # Create switch statement to determine how to populate the C union. + for f in ty.fields: + key_val = '{}_{}'.format(keytype, f.name) + key_val = xenlight_golang_fmt_name(key_val) + if f.type is None: + continue + + s += 'case {}:\n'.format(key_val) + cgotype = '{}_{}_union_{}'.format(struct_name,keyname,f.name) + gotype = xenlight_golang_fmt_name(cgotype) + goname = '{}_{}'.format(keyname,f.name) + goname = xenlight_golang_fmt_name(goname,exported=False) + + field_name = xenlight_golang_fmt_name('{}_union'.format(keyname)) + s += 'tmp, ok := x.{}.({})\n'.format(field_name,gotype) + s += 'if !ok {\n' + s += 'C.{}(&xc)\n'.format(dispose_fn) + s += 'return xc,errors.New("wrong type for union key {}")\n'.format(keyname) + s += '}\n' + + s += 'var {} C.{}\n'.format(f.name,cgotype) + for uf in f.type.fields: + gotypename = xenlight_golang_fmt_name(uf.type.typename) + ctypename = uf.type.typename + gofname = xenlight_golang_fmt_name(uf.name) + + is_castable = (uf.type.json_parse_type == 'JSON_INTEGER' or + isinstance(uf.type, idl.Enumeration) or + gotypename in go_builtin_types) + + if not is_castable: + s += '{}.{}, err = tmp.{}.toC()\n'.format(f.name,uf.name,gofname) + s += 'if err != nil {\n' + s += 'C.{}(&xc)\n'.format(dispose_fn) + s += 'return xc,err \n}\n' + + elif gotypename == 'string': + s += '{}.{} = C.CString(tmp.{})\n'.format(f.name,uf.name,gofname) + + else: + s += '{}.{} = C.{}(tmp.{})\n'.format(f.name,uf.name,ctypename,gofname) + + # The union is still represented as Go []byte. + s += '{}Bytes := C.GoBytes(unsafe.Pointer(&{}),C.sizeof_{})\n'.format(f.name, + f.name, + cgotype) + s += 'copy(xc.{}[:],{}Bytes)\n'.format(union_name,f.name) + + # End switch statement + s += 'default:\n' + err_string = '"invalid union key \'%v\'", x.{}'.format(gokeyname) + s += 'return xc, fmt.Errorf({})'.format(err_string) + s += '}\n' + + return s + def xenlight_golang_fmt_name(name, exported = True): """ Take a given type name and return an diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index be80d6c718..15548f9d6e 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -326,6 +326,21 @@ func (x *Channelinfo) toC() (xc C.libxl_channelinfo, err error) { xc.state = C.int(x.State) xc.evtch = C.int(x.Evtch) xc.rref = C.int(x.Rref) + xc.connection = C.libxl_channel_connection(x.Connection) + switch x.Connection { + case ChannelConnectionPty: + tmp, ok := x.ConnectionUnion.(ChannelinfoConnectionUnionPty) + if !ok { + C.libxl_channelinfo_dispose(&xc) + return xc, errors.New("wrong type for union key connection") + } + var pty C.libxl_channelinfo_connection_union_pty + pty.path = C.CString(tmp.Path) + ptyBytes := C.GoBytes(unsafe.Pointer(&pty), C.sizeof_libxl_channelinfo_connection_union_pty) + copy(xc.u[:], ptyBytes) + default: + return xc, fmt.Errorf("invalid union key '%v'", x.Connection) + } return xc, nil } @@ -1019,6 +1034,216 @@ func (x *DomainBuildInfo) toC() (xc C.libxl_domain_build_info, err error) { return xc, err } xc.tee = C.libxl_tee_type(x.Tee) + xc._type = C.libxl_domain_type(x.Type) + switch x.Type { + case DomainTypeHvm: + tmp, ok := x.TypeUnion.(DomainBuildInfoTypeUnionHvm) + if !ok { + C.libxl_domain_build_info_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var hvm C.libxl_domain_build_info_type_union_hvm + hvm.firmware = C.CString(tmp.Firmware) + hvm.bios = C.libxl_bios_type(tmp.Bios) + hvm.pae, err = tmp.Pae.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.apic, err = tmp.Apic.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.acpi, err = tmp.Acpi.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.acpi_s3, err = tmp.AcpiS3.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.acpi_s4, err = tmp.AcpiS4.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.acpi_laptop_slate, err = tmp.AcpiLaptopSlate.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.nx, err = tmp.Nx.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.viridian, err = tmp.Viridian.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.viridian_enable, err = tmp.ViridianEnable.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.viridian_disable, err = tmp.ViridianDisable.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.timeoffset = C.CString(tmp.Timeoffset) + hvm.hpet, err = tmp.Hpet.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.vpt_align, err = tmp.VptAlign.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.mmio_hole_memkb = C.uint64_t(tmp.MmioHoleMemkb) + hvm.timer_mode = C.libxl_timer_mode(tmp.TimerMode) + hvm.nested_hvm, err = tmp.NestedHvm.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.altp2m, err = tmp.Altp2M.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.system_firmware = C.CString(tmp.SystemFirmware) + hvm.smbios_firmware = C.CString(tmp.SmbiosFirmware) + hvm.acpi_firmware = C.CString(tmp.AcpiFirmware) + hvm.hdtype = C.libxl_hdtype(tmp.Hdtype) + hvm.nographic, err = tmp.Nographic.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.vga, err = tmp.Vga.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.vnc, err = tmp.Vnc.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.keymap = C.CString(tmp.Keymap) + hvm.sdl, err = tmp.Sdl.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.spice, err = tmp.Spice.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.gfx_passthru, err = tmp.GfxPassthru.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.gfx_passthru_kind = C.libxl_gfx_passthru_kind(tmp.GfxPassthruKind) + hvm.serial = C.CString(tmp.Serial) + hvm.boot = C.CString(tmp.Boot) + hvm.usb, err = tmp.Usb.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.usbversion = C.int(tmp.Usbversion) + hvm.usbdevice = C.CString(tmp.Usbdevice) + hvm.vkb_device, err = tmp.VkbDevice.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.soundhw = C.CString(tmp.Soundhw) + hvm.xen_platform_pci, err = tmp.XenPlatformPci.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.usbdevice_list, err = tmp.UsbdeviceList.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.vendor_device = C.libxl_vendor_device(tmp.VendorDevice) + hvm.ms_vm_genid, err = tmp.MsVmGenid.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.serial_list, err = tmp.SerialList.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.rdm, err = tmp.Rdm.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + hvm.rdm_mem_boundary_memkb = C.uint64_t(tmp.RdmMemBoundaryMemkb) + hvm.mca_caps = C.uint64_t(tmp.McaCaps) + hvmBytes := C.GoBytes(unsafe.Pointer(&hvm), C.sizeof_libxl_domain_build_info_type_union_hvm) + copy(xc.u[:], hvmBytes) + case DomainTypePv: + tmp, ok := x.TypeUnion.(DomainBuildInfoTypeUnionPv) + if !ok { + C.libxl_domain_build_info_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var pv C.libxl_domain_build_info_type_union_pv + pv.kernel = C.CString(tmp.Kernel) + pv.slack_memkb = C.uint64_t(tmp.SlackMemkb) + pv.bootloader = C.CString(tmp.Bootloader) + pv.bootloader_args, err = tmp.BootloaderArgs.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + pv.cmdline = C.CString(tmp.Cmdline) + pv.ramdisk = C.CString(tmp.Ramdisk) + pv.features = C.CString(tmp.Features) + pv.e820_host, err = tmp.E820Host.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + pvBytes := C.GoBytes(unsafe.Pointer(&pv), C.sizeof_libxl_domain_build_info_type_union_pv) + copy(xc.u[:], pvBytes) + case DomainTypePvh: + tmp, ok := x.TypeUnion.(DomainBuildInfoTypeUnionPvh) + if !ok { + C.libxl_domain_build_info_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var pvh C.libxl_domain_build_info_type_union_pvh + pvh.pvshim, err = tmp.Pvshim.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + pvh.pvshim_path = C.CString(tmp.PvshimPath) + pvh.pvshim_cmdline = C.CString(tmp.PvshimCmdline) + pvh.pvshim_extra = C.CString(tmp.PvshimExtra) + pvhBytes := C.GoBytes(unsafe.Pointer(&pvh), C.sizeof_libxl_domain_build_info_type_union_pvh) + copy(xc.u[:], pvhBytes) + default: + return xc, fmt.Errorf("invalid union key '%v'", x.Type) + } xc.arch_arm.gic_version = C.libxl_gic_version(x.ArchArm.GicVersion) xc.arch_arm.vuart = C.libxl_vuart_type(x.ArchArm.Vuart) xc.altp2m = C.libxl_altp2m_mode(x.Altp2M) @@ -1410,6 +1635,22 @@ func (x *DeviceUsbdev) toC() (xc C.libxl_device_usbdev, err error) { C.libxl_device_usbdev_init(&xc) xc.ctrl = C.libxl_devid(x.Ctrl) xc.port = C.int(x.Port) + xc._type = C.libxl_usbdev_type(x.Type) + switch x.Type { + case UsbdevTypeHostdev: + tmp, ok := x.TypeUnion.(DeviceUsbdevTypeUnionHostdev) + if !ok { + C.libxl_device_usbdev_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var hostdev C.libxl_device_usbdev_type_union_hostdev + hostdev.hostbus = C.uint8_t(tmp.Hostbus) + hostdev.hostaddr = C.uint8_t(tmp.Hostaddr) + hostdevBytes := C.GoBytes(unsafe.Pointer(&hostdev), C.sizeof_libxl_device_usbdev_type_union_hostdev) + copy(xc.u[:], hostdevBytes) + default: + return xc, fmt.Errorf("invalid union key '%v'", x.Type) + } return xc, nil } @@ -1523,6 +1764,21 @@ func (x *DeviceChannel) toC() (xc C.libxl_device_channel, err error) { xc.backend_domname = C.CString(x.BackendDomname) xc.devid = C.libxl_devid(x.Devid) xc.name = C.CString(x.Name) + xc.connection = C.libxl_channel_connection(x.Connection) + switch x.Connection { + case ChannelConnectionSocket: + tmp, ok := x.ConnectionUnion.(DeviceChannelConnectionUnionSocket) + if !ok { + C.libxl_device_channel_dispose(&xc) + return xc, errors.New("wrong type for union key connection") + } + var socket C.libxl_device_channel_connection_union_socket + socket.path = C.CString(tmp.Path) + socketBytes := C.GoBytes(unsafe.Pointer(&socket), C.sizeof_libxl_device_channel_connection_union_socket) + copy(xc.u[:], socketBytes) + default: + return xc, fmt.Errorf("invalid union key '%v'", x.Connection) + } return xc, nil } @@ -2433,6 +2689,46 @@ func (x *Event) toC() (xc C.libxl_event, err error) { return xc, err } xc.for_user = C.uint64_t(x.ForUser) + xc._type = C.libxl_event_type(x.Type) + switch x.Type { + case EventTypeDomainShutdown: + tmp, ok := x.TypeUnion.(EventTypeUnionDomainShutdown) + if !ok { + C.libxl_event_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var domain_shutdown C.libxl_event_type_union_domain_shutdown + domain_shutdown.shutdown_reason = C.uint8_t(tmp.ShutdownReason) + domain_shutdownBytes := C.GoBytes(unsafe.Pointer(&domain_shutdown), C.sizeof_libxl_event_type_union_domain_shutdown) + copy(xc.u[:], domain_shutdownBytes) + case EventTypeDiskEject: + tmp, ok := x.TypeUnion.(EventTypeUnionDiskEject) + if !ok { + C.libxl_event_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var disk_eject C.libxl_event_type_union_disk_eject + disk_eject.vdev = C.CString(tmp.Vdev) + disk_eject.disk, err = tmp.Disk.toC() + if err != nil { + C.libxl_event_dispose(&xc) + return xc, err + } + disk_ejectBytes := C.GoBytes(unsafe.Pointer(&disk_eject), C.sizeof_libxl_event_type_union_disk_eject) + copy(xc.u[:], disk_ejectBytes) + case EventTypeOperationComplete: + tmp, ok := x.TypeUnion.(EventTypeUnionOperationComplete) + if !ok { + C.libxl_event_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var operation_complete C.libxl_event_type_union_operation_complete + operation_complete.rc = C.int(tmp.Rc) + operation_completeBytes := C.GoBytes(unsafe.Pointer(&operation_complete), C.sizeof_libxl_event_type_union_operation_complete) + copy(xc.u[:], operation_completeBytes) + default: + return xc, fmt.Errorf("invalid union key '%v'", x.Type) + } return xc, nil } @@ -2504,5 +2800,34 @@ func (x *PsrHwInfoTypeUnionMba) fromC(xc *C.libxl_psr_hw_info) error { func (x *PsrHwInfo) toC() (xc C.libxl_psr_hw_info, err error) { C.libxl_psr_hw_info_init(&xc) xc.id = C.uint32_t(x.Id) + xc._type = C.libxl_psr_feat_type(x.Type) + switch x.Type { + case PsrFeatTypeCat: + tmp, ok := x.TypeUnion.(PsrHwInfoTypeUnionCat) + if !ok { + C.libxl_psr_hw_info_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var cat C.libxl_psr_hw_info_type_union_cat + cat.cos_max = C.uint32_t(tmp.CosMax) + cat.cbm_len = C.uint32_t(tmp.CbmLen) + cat.cdp_enabled = C.bool(tmp.CdpEnabled) + catBytes := C.GoBytes(unsafe.Pointer(&cat), C.sizeof_libxl_psr_hw_info_type_union_cat) + copy(xc.u[:], catBytes) + case PsrFeatTypeMba: + tmp, ok := x.TypeUnion.(PsrHwInfoTypeUnionMba) + if !ok { + C.libxl_psr_hw_info_dispose(&xc) + return xc, errors.New("wrong type for union key type") + } + var mba C.libxl_psr_hw_info_type_union_mba + mba.cos_max = C.uint32_t(tmp.CosMax) + mba.thrtl_max = C.uint32_t(tmp.ThrtlMax) + mba.linear = C.bool(tmp.Linear) + mbaBytes := C.GoBytes(unsafe.Pointer(&mba), C.sizeof_libxl_psr_hw_info_type_union_mba) + copy(xc.u[:], mbaBytes) + default: + return xc, fmt.Errorf("invalid union key '%v'", x.Type) + } return xc, nil } From patchwork Mon Dec 23 15:17:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11308455 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 8BD91138D for ; Mon, 23 Dec 2019 15:19:25 +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 5CE3D20709 for ; Mon, 23 Dec 2019 15:19:25 +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="IumXkIqV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5CE3D20709 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 1ijPTE-0006Mt-3e; Mon, 23 Dec 2019 15:18:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijPTC-0006MU-Hm for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 15:18:06 +0000 X-Inumbo-ID: 62f4c4fe-2597-11ea-88e7-bc764e2007e4 Received: from mail-qk1-x744.google.com (unknown [2607:f8b0:4864:20::744]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 62f4c4fe-2597-11ea-88e7-bc764e2007e4; Mon, 23 Dec 2019 15:17:51 +0000 (UTC) Received: by mail-qk1-x744.google.com with SMTP id x129so13753360qke.8 for ; Mon, 23 Dec 2019 07:17: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 :in-reply-to:references; bh=qIWGvbOapJP2AMLuU/QSd6YoV6wyKIPa2DBivfqk0oM=; b=IumXkIqV/+z4N/B3UxV00k4EkHHJG/8wzAL8aImJ5z23H/QJkA7+gnV54RcPqGtmkT jjrsVGYwKqDb6IHLXr8Di4bbX+OeeeCibbrqfRnu8x0ulkyffgi+VDm3yyWAMJEwW7qp 2XXOV9dVvFsBuQ3VfEbQzX4RhXX9YBpan6Wux9Hnr9od5BoLV+Ol4t+mKKisG7T6G0k+ aIuSdDKDS0ALkJ9ZpI9cdb6Arm/n7Sdq4I9HSNmsxqQPe0s5KGkajYSvotgBLmbxI6gl 2Gx/wuqJ3Lejwijz+j8Ku7CJpOqomZqsEEW8T1a3FbITMaxdurE7vsnA9qI8/R3b3PK0 zpww== 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:in-reply-to:references; bh=qIWGvbOapJP2AMLuU/QSd6YoV6wyKIPa2DBivfqk0oM=; b=bM5+/KOF1SEUeB5Oyzbq82gX8qq+5frNgMGHtNnzITzeqBbNAs50HClI8hQIOQ20P+ Eaph52ZFJlv4Xj5y7ULizrMYo4BVRxiTjQukrSlvCbH5un93kVc7tawBYowJizkIg+6B sXRZitvir/SXrOU9L8JBYxVlQ9Ycp+3EYE93sCPw5mh9gol4xTZgr9/i/v9je02gqSwc stG/VLlo9l/ehT15N+vgktWIaoG+hOkfvPWDefqLWwIJfLADvlIK7I45N6032NHeeabR +WDgQawRy6nvu53jcNZRu+x3axSQnRCANOeyIKBWZ2FEAHRfAi2eib0OYo49Nbcg53ag 4QIA== X-Gm-Message-State: APjAAAXXzU4P5gKB4c9ZleMoK1WTrx7xRCyyNxwKApPpfx7tqXz7ruSE W8bds8gKdxnpPsBIuP+YQ0wmVJn9 X-Google-Smtp-Source: APXvYqwmHOR8L9pUzbHCp0x+MPveQPT75YHeS7KxiuIKxuOmnzjZiRSxWdRXrYxNvsOtRsdP1nIfQw== X-Received: by 2002:a05:620a:b19:: with SMTP id t25mr27133610qkg.82.1577114270958; Mon, 23 Dec 2019 07:17:50 -0800 (PST) Received: from four.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id u15sm5823907qku.67.2019.12.23.07.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 07:17:50 -0800 (PST) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 23 Dec 2019 10:17:05 -0500 Message-Id: <88056982bc116611da601b2d1249bb4be4bc07e9.1577111872.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 4/6] golang/xenlight: implement array Go to C marshaling 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 44 +++- tools/golang/xenlight/helpers.gen.go | 359 +++++++++++++++++++++++++++ 2 files changed, 402 insertions(+), 1 deletion(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index b377fd9a25..a972754d36 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -456,7 +456,7 @@ def xenlight_golang_define_to_C(ty = None, typename = None, nested = False): for f in ty.fields: if f.type.typename is not None: if isinstance(f.type, idl.Array): - # TODO + s += xenlight_golang_array_to_C(f, ty.dispose_fn) continue gotypename = xenlight_golang_fmt_name(f.type.typename) @@ -587,6 +587,48 @@ def xenlight_golang_union_to_C(ty = None, union_name = '', return s +def xenlight_golang_array_to_C(ty = None, dispose_fn = ''): + s = '' + + gotypename = xenlight_golang_fmt_name(ty.type.elem_type.typename) + goname = xenlight_golang_fmt_name(ty.name) + ctypename = ty.type.elem_type.typename + cname = ty.name + clenvar = ty.type.lenvar.name + golenvar = xenlight_golang_fmt_name(clenvar,exported=False) + + is_enum = isinstance(ty.type.elem_type,idl.Enumeration) + if gotypename in go_builtin_types or is_enum: + s += '{} := len(x.{})\n'.format(golenvar,goname) + s += 'xc.{} = (*C.{})(C.malloc(C.size_t({}*{})))\n'.format(cname,ctypename, + golenvar,golenvar) + s += 'xc.{} = C.int({})\n'.format(clenvar,golenvar) + s += 'c{} := (*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:{}:{}]\n'.format(goname, + ctypename,cname, + golenvar,golenvar) + s += 'for i,v := range x.{} {{\n'.format(goname) + s += 'c{}[i] = C.{}(v)\n'.format(goname,ctypename) + s += '}\n' + + return s + + s += '{} := len(x.{})\n'.format(golenvar,goname) + s += 'xc.{} = (*C.{})(C.malloc(C.ulong({})*C.sizeof_{}))\n'.format(cname,ctypename, + golenvar,ctypename) + s += 'xc.{} = C.int({})\n'.format(clenvar,golenvar) + s += 'c{} := (*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:{}:{}]\n'.format(goname, + ctypename,cname, + golenvar,golenvar) + s += 'for i,v := range x.{} {{\n'.format(goname) + s += 'tmp, err := v.toC()\n' + s += 'if err != nil {\n' + s += 'C.{}(&xc)\n'.format(dispose_fn) + s += 'return xc,err\n}\n' + s += 'c{}[i] = tmp\n'.format(goname) + s += '}\n' + + return s + def xenlight_golang_fmt_name(name, exported = True): """ Take a given type name and return an diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 15548f9d6e..3e588dd1c2 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -543,6 +543,18 @@ func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { func (x *VcpuSchedParams) toC() (xc C.libxl_vcpu_sched_params, err error) { C.libxl_vcpu_sched_params_init(&xc) xc.sched = C.libxl_scheduler(x.Sched) + numVcpus := len(x.Vcpus) + xc.vcpus = (*C.libxl_sched_params)(C.malloc(C.ulong(numVcpus) * C.sizeof_libxl_sched_params)) + xc.num_vcpus = C.int(numVcpus) + cVcpus := (*[1 << 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:numVcpus:numVcpus] + for i, v := range x.Vcpus { + tmp, err := v.toC() + if err != nil { + C.libxl_vcpu_sched_params_dispose(&xc) + return xc, err + } + cVcpus[i] = tmp + } return xc, nil } @@ -591,6 +603,13 @@ func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { func (x *VnodeInfo) toC() (xc C.libxl_vnode_info, err error) { C.libxl_vnode_info_init(&xc) xc.memkb = C.uint64_t(x.Memkb) + numDistances := len(x.Distances) + xc.distances = (*C.uint32_t)(C.malloc(C.size_t(numDistances * numDistances))) + xc.num_distances = C.int(numDistances) + cDistances := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.distances))[:numDistances:numDistances] + for i, v := range x.Distances { + cDistances[i] = C.uint32_t(v) + } xc.pnode = C.uint32_t(x.Pnode) xc.vcpus, err = x.Vcpus.toC() if err != nil { @@ -934,6 +953,30 @@ func (x *DomainBuildInfo) toC() (xc C.libxl_domain_build_info, err error) { C.libxl_domain_build_info_dispose(&xc) return xc, err } + numVcpuHardAffinity := len(x.VcpuHardAffinity) + xc.vcpu_hard_affinity = (*C.libxl_bitmap)(C.malloc(C.ulong(numVcpuHardAffinity) * C.sizeof_libxl_bitmap)) + xc.num_vcpu_hard_affinity = C.int(numVcpuHardAffinity) + cVcpuHardAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:numVcpuHardAffinity:numVcpuHardAffinity] + for i, v := range x.VcpuHardAffinity { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + cVcpuHardAffinity[i] = tmp + } + numVcpuSoftAffinity := len(x.VcpuSoftAffinity) + xc.vcpu_soft_affinity = (*C.libxl_bitmap)(C.malloc(C.ulong(numVcpuSoftAffinity) * C.sizeof_libxl_bitmap)) + xc.num_vcpu_soft_affinity = C.int(numVcpuSoftAffinity) + cVcpuSoftAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:numVcpuSoftAffinity:numVcpuSoftAffinity] + for i, v := range x.VcpuSoftAffinity { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + cVcpuSoftAffinity[i] = tmp + } xc.numa_placement, err = x.NumaPlacement.toC() if err != nil { C.libxl_domain_build_info_dispose(&xc) @@ -964,6 +1007,18 @@ func (x *DomainBuildInfo) toC() (xc C.libxl_domain_build_info, err error) { return xc, err } xc.blkdev_start = C.CString(x.BlkdevStart) + numVnumaNodes := len(x.VnumaNodes) + xc.vnuma_nodes = (*C.libxl_vnode_info)(C.malloc(C.ulong(numVnumaNodes) * C.sizeof_libxl_vnode_info)) + xc.num_vnuma_nodes = C.int(numVnumaNodes) + cVnumaNodes := (*[1 << 28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:numVnumaNodes:numVnumaNodes] + for i, v := range x.VnumaNodes { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + cVnumaNodes[i] = tmp + } xc.max_grant_frames = C.uint32_t(x.MaxGrantFrames) xc.max_maptrack_frames = C.uint32_t(x.MaxMaptrackFrames) xc.device_model_version = C.libxl_device_model_version(x.DeviceModelVersion) @@ -996,6 +1051,37 @@ func (x *DomainBuildInfo) toC() (xc C.libxl_domain_build_info, err error) { C.libxl_domain_build_info_dispose(&xc) return xc, err } + numIoports := len(x.Ioports) + xc.ioports = (*C.libxl_ioport_range)(C.malloc(C.ulong(numIoports) * C.sizeof_libxl_ioport_range)) + xc.num_ioports = C.int(numIoports) + cIoports := (*[1 << 28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:numIoports:numIoports] + for i, v := range x.Ioports { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + cIoports[i] = tmp + } + numIrqs := len(x.Irqs) + xc.irqs = (*C.uint32_t)(C.malloc(C.size_t(numIrqs * numIrqs))) + xc.num_irqs = C.int(numIrqs) + cIrqs := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:numIrqs:numIrqs] + for i, v := range x.Irqs { + cIrqs[i] = C.uint32_t(v) + } + numIomem := len(x.Iomem) + xc.iomem = (*C.libxl_iomem_range)(C.malloc(C.ulong(numIomem) * C.sizeof_libxl_iomem_range)) + xc.num_iomem = C.int(numIomem) + cIomem := (*[1 << 28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:numIomem:numIomem] + for i, v := range x.Iomem { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_build_info_dispose(&xc) + return xc, err + } + cIomem[i] = tmp + } xc.claim_mode, err = x.ClaimMode.toC() if err != nil { C.libxl_domain_build_info_dispose(&xc) @@ -1821,6 +1907,18 @@ func (x *DeviceVdispl) toC() (xc C.libxl_device_vdispl, err error) { xc.backend_domname = C.CString(x.BackendDomname) xc.devid = C.libxl_devid(x.Devid) xc.be_alloc = C.bool(x.BeAlloc) + numConnectors := len(x.Connectors) + xc.connectors = (*C.libxl_connector_param)(C.malloc(C.ulong(numConnectors) * C.sizeof_libxl_connector_param)) + xc.num_connectors = C.int(numConnectors) + cConnectors := (*[1 << 28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] + for i, v := range x.Connectors { + tmp, err := v.toC() + if err != nil { + C.libxl_device_vdispl_dispose(&xc) + return xc, err + } + cConnectors[i] = tmp + } return xc, nil } @@ -1846,6 +1944,20 @@ func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error { func (x *VsndParams) toC() (xc C.libxl_vsnd_params, err error) { C.libxl_vsnd_params_init(&xc) + numSampleRates := len(x.SampleRates) + xc.sample_rates = (*C.uint32_t)(C.malloc(C.size_t(numSampleRates * numSampleRates))) + xc.num_sample_rates = C.int(numSampleRates) + cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:numSampleRates:numSampleRates] + for i, v := range x.SampleRates { + cSampleRates[i] = C.uint32_t(v) + } + numSampleFormats := len(x.SampleFormats) + xc.sample_formats = (*C.libxl_vsnd_pcm_format)(C.malloc(C.size_t(numSampleFormats * numSampleFormats))) + xc.num_sample_formats = C.int(numSampleFormats) + cSampleFormats := (*[1 << 28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:numSampleFormats:numSampleFormats] + for i, v := range x.SampleFormats { + cSampleFormats[i] = C.libxl_vsnd_pcm_format(v) + } xc.channels_min = C.uint32_t(x.ChannelsMin) xc.channels_max = C.uint32_t(x.ChannelsMax) xc.buffer_size = C.uint32_t(x.BufferSize) @@ -1899,6 +2011,18 @@ func (x *VsndPcm) toC() (xc C.libxl_vsnd_pcm, err error) { C.libxl_vsnd_pcm_dispose(&xc) return xc, err } + numVsndStreams := len(x.Streams) + xc.streams = (*C.libxl_vsnd_stream)(C.malloc(C.ulong(numVsndStreams) * C.sizeof_libxl_vsnd_stream)) + xc.num_vsnd_streams = C.int(numVsndStreams) + cStreams := (*[1 << 28]C.libxl_vsnd_stream)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] + for i, v := range x.Streams { + tmp, err := v.toC() + if err != nil { + C.libxl_vsnd_pcm_dispose(&xc) + return xc, err + } + cStreams[i] = tmp + } return xc, nil } @@ -1935,6 +2059,18 @@ func (x *DeviceVsnd) toC() (xc C.libxl_device_vsnd, err error) { C.libxl_device_vsnd_dispose(&xc) return xc, err } + numVsndPcms := len(x.Pcms) + xc.pcms = (*C.libxl_vsnd_pcm)(C.malloc(C.ulong(numVsndPcms) * C.sizeof_libxl_vsnd_pcm)) + xc.num_vsnd_pcms = C.int(numVsndPcms) + cPcms := (*[1 << 28]C.libxl_vsnd_pcm)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] + for i, v := range x.Pcms { + tmp, err := v.toC() + if err != nil { + C.libxl_device_vsnd_dispose(&xc) + return xc, err + } + cPcms[i] = tmp + } return xc, nil } @@ -2086,6 +2222,186 @@ func (x *DomainConfig) toC() (xc C.libxl_domain_config, err error) { C.libxl_domain_config_dispose(&xc) return xc, err } + numDisks := len(x.Disks) + xc.disks = (*C.libxl_device_disk)(C.malloc(C.ulong(numDisks) * C.sizeof_libxl_device_disk)) + xc.num_disks = C.int(numDisks) + cDisks := (*[1 << 28]C.libxl_device_disk)(unsafe.Pointer(xc.disks))[:numDisks:numDisks] + for i, v := range x.Disks { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cDisks[i] = tmp + } + numNics := len(x.Nics) + xc.nics = (*C.libxl_device_nic)(C.malloc(C.ulong(numNics) * C.sizeof_libxl_device_nic)) + xc.num_nics = C.int(numNics) + cNics := (*[1 << 28]C.libxl_device_nic)(unsafe.Pointer(xc.nics))[:numNics:numNics] + for i, v := range x.Nics { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cNics[i] = tmp + } + numPcidevs := len(x.Pcidevs) + xc.pcidevs = (*C.libxl_device_pci)(C.malloc(C.ulong(numPcidevs) * C.sizeof_libxl_device_pci)) + xc.num_pcidevs = C.int(numPcidevs) + cPcidevs := (*[1 << 28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:numPcidevs:numPcidevs] + for i, v := range x.Pcidevs { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cPcidevs[i] = tmp + } + numRdms := len(x.Rdms) + xc.rdms = (*C.libxl_device_rdm)(C.malloc(C.ulong(numRdms) * C.sizeof_libxl_device_rdm)) + xc.num_rdms = C.int(numRdms) + cRdms := (*[1 << 28]C.libxl_device_rdm)(unsafe.Pointer(xc.rdms))[:numRdms:numRdms] + for i, v := range x.Rdms { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cRdms[i] = tmp + } + numDtdevs := len(x.Dtdevs) + xc.dtdevs = (*C.libxl_device_dtdev)(C.malloc(C.ulong(numDtdevs) * C.sizeof_libxl_device_dtdev)) + xc.num_dtdevs = C.int(numDtdevs) + cDtdevs := (*[1 << 28]C.libxl_device_dtdev)(unsafe.Pointer(xc.dtdevs))[:numDtdevs:numDtdevs] + for i, v := range x.Dtdevs { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cDtdevs[i] = tmp + } + numVfbs := len(x.Vfbs) + xc.vfbs = (*C.libxl_device_vfb)(C.malloc(C.ulong(numVfbs) * C.sizeof_libxl_device_vfb)) + xc.num_vfbs = C.int(numVfbs) + cVfbs := (*[1 << 28]C.libxl_device_vfb)(unsafe.Pointer(xc.vfbs))[:numVfbs:numVfbs] + for i, v := range x.Vfbs { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cVfbs[i] = tmp + } + numVkbs := len(x.Vkbs) + xc.vkbs = (*C.libxl_device_vkb)(C.malloc(C.ulong(numVkbs) * C.sizeof_libxl_device_vkb)) + xc.num_vkbs = C.int(numVkbs) + cVkbs := (*[1 << 28]C.libxl_device_vkb)(unsafe.Pointer(xc.vkbs))[:numVkbs:numVkbs] + for i, v := range x.Vkbs { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cVkbs[i] = tmp + } + numVtpms := len(x.Vtpms) + xc.vtpms = (*C.libxl_device_vtpm)(C.malloc(C.ulong(numVtpms) * C.sizeof_libxl_device_vtpm)) + xc.num_vtpms = C.int(numVtpms) + cVtpms := (*[1 << 28]C.libxl_device_vtpm)(unsafe.Pointer(xc.vtpms))[:numVtpms:numVtpms] + for i, v := range x.Vtpms { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cVtpms[i] = tmp + } + numP9S := len(x.P9S) + xc.p9s = (*C.libxl_device_p9)(C.malloc(C.ulong(numP9S) * C.sizeof_libxl_device_p9)) + xc.num_p9s = C.int(numP9S) + cP9S := (*[1 << 28]C.libxl_device_p9)(unsafe.Pointer(xc.p9s))[:numP9S:numP9S] + for i, v := range x.P9S { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cP9S[i] = tmp + } + numPvcallsifs := len(x.Pvcallsifs) + xc.pvcallsifs = (*C.libxl_device_pvcallsif)(C.malloc(C.ulong(numPvcallsifs) * C.sizeof_libxl_device_pvcallsif)) + xc.num_pvcallsifs = C.int(numPvcallsifs) + cPvcallsifs := (*[1 << 28]C.libxl_device_pvcallsif)(unsafe.Pointer(xc.pvcallsifs))[:numPvcallsifs:numPvcallsifs] + for i, v := range x.Pvcallsifs { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cPvcallsifs[i] = tmp + } + numVdispls := len(x.Vdispls) + xc.vdispls = (*C.libxl_device_vdispl)(C.malloc(C.ulong(numVdispls) * C.sizeof_libxl_device_vdispl)) + xc.num_vdispls = C.int(numVdispls) + cVdispls := (*[1 << 28]C.libxl_device_vdispl)(unsafe.Pointer(xc.vdispls))[:numVdispls:numVdispls] + for i, v := range x.Vdispls { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cVdispls[i] = tmp + } + numVsnds := len(x.Vsnds) + xc.vsnds = (*C.libxl_device_vsnd)(C.malloc(C.ulong(numVsnds) * C.sizeof_libxl_device_vsnd)) + xc.num_vsnds = C.int(numVsnds) + cVsnds := (*[1 << 28]C.libxl_device_vsnd)(unsafe.Pointer(xc.vsnds))[:numVsnds:numVsnds] + for i, v := range x.Vsnds { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cVsnds[i] = tmp + } + numChannels := len(x.Channels) + xc.channels = (*C.libxl_device_channel)(C.malloc(C.ulong(numChannels) * C.sizeof_libxl_device_channel)) + xc.num_channels = C.int(numChannels) + cChannels := (*[1 << 28]C.libxl_device_channel)(unsafe.Pointer(xc.channels))[:numChannels:numChannels] + for i, v := range x.Channels { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cChannels[i] = tmp + } + numUsbctrls := len(x.Usbctrls) + xc.usbctrls = (*C.libxl_device_usbctrl)(C.malloc(C.ulong(numUsbctrls) * C.sizeof_libxl_device_usbctrl)) + xc.num_usbctrls = C.int(numUsbctrls) + cUsbctrls := (*[1 << 28]C.libxl_device_usbctrl)(unsafe.Pointer(xc.usbctrls))[:numUsbctrls:numUsbctrls] + for i, v := range x.Usbctrls { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cUsbctrls[i] = tmp + } + numUsbdevs := len(x.Usbdevs) + xc.usbdevs = (*C.libxl_device_usbdev)(C.malloc(C.ulong(numUsbdevs) * C.sizeof_libxl_device_usbdev)) + xc.num_usbdevs = C.int(numUsbdevs) + cUsbdevs := (*[1 << 28]C.libxl_device_usbdev)(unsafe.Pointer(xc.usbdevs))[:numUsbdevs:numUsbdevs] + for i, v := range x.Usbdevs { + tmp, err := v.toC() + if err != nil { + C.libxl_domain_config_dispose(&xc) + return xc, err + } + cUsbdevs[i] = tmp + } xc.on_poweroff = C.libxl_action_on_shutdown(x.OnPoweroff) xc.on_reboot = C.libxl_action_on_shutdown(x.OnReboot) xc.on_watchdog = C.libxl_action_on_shutdown(x.OnWatchdog) @@ -2363,6 +2679,18 @@ func (x *Vdisplinfo) toC() (xc C.libxl_vdisplinfo, err error) { xc.devid = C.libxl_devid(x.Devid) xc.state = C.int(x.State) xc.be_alloc = C.bool(x.BeAlloc) + numConnectors := len(x.Connectors) + xc.connectors = (*C.libxl_connectorinfo)(C.malloc(C.ulong(numConnectors) * C.sizeof_libxl_connectorinfo)) + xc.num_connectors = C.int(numConnectors) + cConnectors := (*[1 << 28]C.libxl_connectorinfo)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] + for i, v := range x.Connectors { + tmp, err := v.toC() + if err != nil { + C.libxl_vdisplinfo_dispose(&xc) + return xc, err + } + cConnectors[i] = tmp + } return xc, nil } @@ -2395,6 +2723,18 @@ func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error { func (x *Pcminfo) toC() (xc C.libxl_pcminfo, err error) { C.libxl_pcminfo_init(&xc) + numVsndStreams := len(x.Streams) + xc.streams = (*C.libxl_streaminfo)(C.malloc(C.ulong(numVsndStreams) * C.sizeof_libxl_streaminfo)) + xc.num_vsnd_streams = C.int(numVsndStreams) + cStreams := (*[1 << 28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] + for i, v := range x.Streams { + tmp, err := v.toC() + if err != nil { + C.libxl_pcminfo_dispose(&xc) + return xc, err + } + cStreams[i] = tmp + } return xc, nil } @@ -2425,6 +2765,18 @@ func (x *Vsndinfo) toC() (xc C.libxl_vsndinfo, err error) { xc.frontend_id = C.uint32_t(x.FrontendId) xc.devid = C.libxl_devid(x.Devid) xc.state = C.int(x.State) + numVsndPcms := len(x.Pcms) + xc.pcms = (*C.libxl_pcminfo)(C.malloc(C.ulong(numVsndPcms) * C.sizeof_libxl_pcminfo)) + xc.num_vsnd_pcms = C.int(numVsndPcms) + cPcms := (*[1 << 28]C.libxl_pcminfo)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] + for i, v := range x.Pcms { + tmp, err := v.toC() + if err != nil { + C.libxl_vsndinfo_dispose(&xc) + return xc, err + } + cPcms[i] = tmp + } return xc, nil } @@ -2471,6 +2823,13 @@ func (x *Numainfo) toC() (xc C.libxl_numainfo, err error) { C.libxl_numainfo_init(&xc) xc.size = C.uint64_t(x.Size) xc.free = C.uint64_t(x.Free) + numDists := len(x.Dists) + xc.dists = (*C.uint32_t)(C.malloc(C.size_t(numDists * numDists))) + xc.num_dists = C.int(numDists) + cDists := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.dists))[:numDists:numDists] + for i, v := range x.Dists { + cDists[i] = C.uint32_t(v) + } return xc, nil } From patchwork Mon Dec 23 15:17:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11308453 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 7FCBF13B6 for ; Mon, 23 Dec 2019 15:19:25 +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 50CCF206CB for ; Mon, 23 Dec 2019 15:19:25 +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="bhBxfm23" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50CCF206CB 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 1ijPTI-0006PJ-IV; Mon, 23 Dec 2019 15:18:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijPTH-0006OM-HT for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 15:18:11 +0000 X-Inumbo-ID: 63f59d1a-2597-11ea-88e7-bc764e2007e4 Received: from mail-qv1-xf43.google.com (unknown [2607:f8b0:4864:20::f43]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 63f59d1a-2597-11ea-88e7-bc764e2007e4; Mon, 23 Dec 2019 15:17:53 +0000 (UTC) Received: by mail-qv1-xf43.google.com with SMTP id y8so6461573qvk.6 for ; Mon, 23 Dec 2019 07:17:53 -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 :in-reply-to:references; bh=2/djd1HHcfAAC+GQCcKQ0rXC67RaS5dl0perPfCjXCU=; b=bhBxfm239b2Ew6RK6pond/R4K2nr1KUbLKlaHFO+V3os4xGMzuDKBJIDQKYduzF4FG 4F/UIpy+2Nr4mQaBWwoOkzrkcBz/t154r7hizRh3FbyvY4N714GiPI497i3nxHBbIhKj xS6zcAotA6rMgZwEl8+vDsfQ65I8nMTER0FwvlfrgmEiB2YEAadjV6woRfrEyW63hijk axQrEjnbVOm4V4eR/Hg7+NqyDCm4QbS7UTXLzNQmyICA+K2+u9h7FfYkunCbwvMbm88E 24MHRV2bznmvzalW56d9KBtbew2HjrHRR0RXRVgaXJ5rKR4PjTAdnWTOoId4OJeT9NcU iSNg== 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:in-reply-to:references; bh=2/djd1HHcfAAC+GQCcKQ0rXC67RaS5dl0perPfCjXCU=; b=s/WOri2dPD1D86ajFdnyjO4IxTuTzaDhesXfA44lowLvwUCRHv386H7zp5m2WdPMKG HgLJMSHGQfs61udMtOXIeK4d/TTZvHW0av6CXR/kZ9K4mh3vE2HSQNvvXgjTnygVoUd4 ZlcmilDGBzGj5iZu9iyWPyvR+N/Hf246vVLmqS2MVOKuKQflcDer+3CREBoVIT1D1sMH oGkv+j70cNv8ev1Vxa4gwBhJRvOuw7tWNncLxZzk+PyLJDkQJRCt7pr3QHttLCiA4mJL SmcMHRqru1+5X57QFNS5ijY6jPYg0M94oV6UH+49+mH0ru7YoIqZkec1vMfR+cKCH88v /OXg== X-Gm-Message-State: APjAAAXxWz4ror1kq8hH2zlkCWJnYqfVCHX+hONeBgZylhD0HnYxxiYB XiuV4ofPpgRL6rra5IcSksXr8m1U X-Google-Smtp-Source: APXvYqxxFYJ/XCNh4xlWiIV1s4Gj9sz/OhFaaODBGt+6tw7/k9y/iQu6iuwkCnz7FnNFKK4CKNmlnA== X-Received: by 2002:ad4:4b6d:: with SMTP id m13mr25378784qvx.240.1577114272678; Mon, 23 Dec 2019 07:17:52 -0800 (PST) Received: from four.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id u15sm5823907qku.67.2019.12.23.07.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 07:17:52 -0800 (PST) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 23 Dec 2019 10:17:06 -0500 Message-Id: <0eca74c58eb2e51cd87f48b8593a2c8065ad2996.1577111872.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 5/6] golang/xenlight: revise use of Context type 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Remove the exported global context variable, 'Ctx.' Generally, it is better to not export global variables for use through a Go package. However, there are some exceptions that can be found in the standard library. Add a NewContext function instead, and remove the Open, IsOpen, and CheckOpen functions as a result. Also, comment-out an ineffectual assignment to 'err' inside the function Context.CpupoolInfo so that compilation does not fail. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- Changes in v4: - Add line break to excessively long line in NewContext. --- tools/golang/xenlight/xenlight.go | 220 +++++------------------------- 1 file changed, 35 insertions(+), 185 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index f32eb11384..5f14cab6ce 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -74,6 +74,40 @@ func (e Error) Error() string { return fmt.Sprintf("libxl error: %d", -e) } +// Context represents a libxl_ctx. +type Context struct { + ctx *C.libxl_ctx + logger *C.xentoollog_logger_stdiostream +} + +// NewContext returns a new Context. +func NewContext() (*Context, error) { + var ctx Context + + ctx.logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_ERROR, 0) + + ret := C.libxl_ctx_alloc(&ctx.ctx, C.LIBXL_VERSION, 0, + (*C.xentoollog_logger)(unsafe.Pointer(ctx.logger))) + if ret != 0 { + return nil, Error(ret) + } + + return &ctx, nil +} + +// Close closes the Context. +func (ctx *Context) Close() error { + ret := C.libxl_ctx_free(ctx.ctx) + ctx.ctx = nil + C.xtl_logger_destroy((*C.xentoollog_logger)(unsafe.Pointer(ctx.logger))) + + if ret != 0 { + return Error(ret) + } + + return nil +} + /* * Types: Builtins */ @@ -298,11 +332,6 @@ func (cpl CpuidPolicyList) toC() (C.libxl_cpuid_policy_list, error) { return ccpl, nil } -type Context struct { - ctx *C.libxl_ctx - logger *C.xentoollog_logger_stdiostream -} - // Hwcap represents a libxl_hwcap. type Hwcap [8]uint32 @@ -453,11 +482,6 @@ func SchedulerFromString(name string) (s Scheduler, err error) { // libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out); // void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool); func (Ctx *Context) ListCpupool() (list []Cpupoolinfo) { - err := Ctx.CheckOpen() - if err != nil { - return - } - var nbPool C.int c_cpupool_list := C.libxl_list_cpupool(Ctx.ctx, &nbPool) @@ -481,16 +505,11 @@ func (Ctx *Context) ListCpupool() (list []Cpupoolinfo) { // int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid); func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool Cpupoolinfo) { - err := Ctx.CheckOpen() - if err != nil { - return - } - var c_cpupool C.libxl_cpupoolinfo ret := C.libxl_cpupool_info(Ctx.ctx, &c_cpupool, C.uint32_t(Poolid)) if ret != 0 { - err = Error(-ret) + //err = Error(-ret) return } defer C.libxl_cpupoolinfo_dispose(&c_cpupool) @@ -507,11 +526,6 @@ func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool Cpupoolinfo) { // FIXME: uuid // FIXME: Setting poolid func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitmap) (err error, Poolid uint32) { - err = Ctx.CheckOpen() - if err != nil { - return - } - poolid := C.uint32_t(C.LIBXL_CPUPOOL_POOLID_ANY) name := C.CString(Name) defer C.free(unsafe.Pointer(name)) @@ -540,11 +554,6 @@ func (Ctx *Context) CpupoolCreate(Name string, Scheduler Scheduler, Cpumap Bitma // int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); func (Ctx *Context) CpupoolDestroy(Poolid uint32) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_cpupool_destroy(Ctx.ctx, C.uint32_t(Poolid)) if ret != 0 { err = Error(-ret) @@ -556,11 +565,6 @@ func (Ctx *Context) CpupoolDestroy(Poolid uint32) (err error) { // int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu); func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_cpupool_cpuadd(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) if ret != 0 { err = Error(-ret) @@ -573,11 +577,6 @@ func (Ctx *Context) CpupoolCpuadd(Poolid uint32, Cpu int) (err error) { // int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - cbm, err := Cpumap.toC() if err != nil { return @@ -595,11 +594,6 @@ func (Ctx *Context) CpupoolCpuaddCpumap(Poolid uint32, Cpumap Bitmap) (err error // int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu); func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_cpupool_cpuremove(Ctx.ctx, C.uint32_t(Poolid), C.int(Cpu)) if ret != 0 { err = Error(-ret) @@ -612,11 +606,6 @@ func (Ctx *Context) CpupoolCpuremove(Poolid uint32, Cpu int) (err error) { // int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid, // const libxl_bitmap *cpumap); func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - cbm, err := Cpumap.toC() if err != nil { return @@ -634,11 +623,6 @@ func (Ctx *Context) CpupoolCpuremoveCpumap(Poolid uint32, Cpumap Bitmap) (err er // int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid); func (Ctx *Context) CpupoolRename(Name string, Poolid uint32) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - name := C.CString(Name) defer C.free(unsafe.Pointer(name)) @@ -653,11 +637,6 @@ func (Ctx *Context) CpupoolRename(Name string, Poolid uint32) (err error) { // int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); func (Ctx *Context) CpupoolCpuaddNode(Poolid uint32, Node int) (Cpus int, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ccpus := C.int(0) ret := C.libxl_cpupool_cpuadd_node(Ctx.ctx, C.uint32_t(Poolid), C.int(Node), &ccpus) @@ -673,11 +652,6 @@ func (Ctx *Context) CpupoolCpuaddNode(Poolid uint32, Node int) (Cpus int, err er // int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); func (Ctx *Context) CpupoolCpuremoveNode(Poolid uint32, Node int) (Cpus int, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ccpus := C.int(0) ret := C.libxl_cpupool_cpuremove_node(Ctx.ctx, C.uint32_t(Poolid), C.int(Node), &ccpus) @@ -693,11 +667,6 @@ func (Ctx *Context) CpupoolCpuremoveNode(Poolid uint32, Node int) (Cpus int, err // int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); func (Ctx *Context) CpupoolMovedomain(Poolid uint32, Id Domid) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_cpupool_movedomain(Ctx.ctx, C.uint32_t(Poolid), C.uint32_t(Id)) if ret != 0 { err = Error(-ret) @@ -857,60 +826,8 @@ func (bm Bitmap) String() (s string) { return } -/* - * Context - */ -var Ctx Context - -func (Ctx *Context) IsOpen() bool { - return Ctx.ctx != nil -} - -func (Ctx *Context) Open() (err error) { - if Ctx.ctx != nil { - return - } - - Ctx.logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_ERROR, 0) - if Ctx.logger == nil { - err = fmt.Errorf("Cannot open stdiostream") - return - } - - ret := C.libxl_ctx_alloc(&Ctx.ctx, C.LIBXL_VERSION, - 0, (*C.xentoollog_logger)(unsafe.Pointer(Ctx.logger))) - - if ret != 0 { - err = Error(-ret) - } - return -} - -func (Ctx *Context) Close() (err error) { - ret := C.libxl_ctx_free(Ctx.ctx) - Ctx.ctx = nil - - if ret != 0 { - err = Error(-ret) - } - C.xtl_logger_destroy((*C.xentoollog_logger)(unsafe.Pointer(Ctx.logger))) - return -} - -func (Ctx *Context) CheckOpen() (err error) { - if Ctx.ctx == nil { - err = fmt.Errorf("Context not opened") - } - return -} - //int libxl_get_max_cpus(libxl_ctx *ctx); func (Ctx *Context) GetMaxCpus() (maxCpus int, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_get_max_cpus(Ctx.ctx) if ret < 0 { err = Error(-ret) @@ -922,11 +839,6 @@ func (Ctx *Context) GetMaxCpus() (maxCpus int, err error) { //int libxl_get_online_cpus(libxl_ctx *ctx); func (Ctx *Context) GetOnlineCpus() (onCpus int, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_get_online_cpus(Ctx.ctx) if ret < 0 { err = Error(-ret) @@ -938,10 +850,6 @@ func (Ctx *Context) GetOnlineCpus() (onCpus int, err error) { //int libxl_get_max_nodes(libxl_ctx *ctx); func (Ctx *Context) GetMaxNodes() (maxNodes int, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } ret := C.libxl_get_max_nodes(Ctx.ctx) if ret < 0 { err = Error(-ret) @@ -953,10 +861,6 @@ func (Ctx *Context) GetMaxNodes() (maxNodes int, err error) { //int libxl_get_free_memory(libxl_ctx *ctx, uint64_t *memkb); func (Ctx *Context) GetFreeMemory() (memkb uint64, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } var cmem C.uint64_t ret := C.libxl_get_free_memory(Ctx.ctx, &cmem) @@ -972,10 +876,6 @@ func (Ctx *Context) GetFreeMemory() (memkb uint64, err error) { //int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo) func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } var cphys C.libxl_physinfo C.libxl_physinfo_init(&cphys) defer C.libxl_physinfo_dispose(&cphys) @@ -993,11 +893,6 @@ func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) { //const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx); func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - var cinfo *C.libxl_version_info cinfo = C.libxl_get_version_info(Ctx.ctx) @@ -1008,11 +903,6 @@ func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) { } 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) @@ -1030,11 +920,6 @@ func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { } 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), nil) if ret != 0 { @@ -1045,11 +930,6 @@ func (Ctx *Context) DomainUnpause(Id Domid) (err error) { //int libxl_domain_pause(libxl_ctx *ctx, uint32_t domain); func (Ctx *Context) DomainPause(id Domid) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_domain_pause(Ctx.ctx, C.uint32_t(id), nil) if ret != 0 { @@ -1060,11 +940,6 @@ func (Ctx *Context) DomainPause(id Domid) (err error) { //int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid); func (Ctx *Context) DomainShutdown(id Domid) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_domain_shutdown(Ctx.ctx, C.uint32_t(id), nil) if ret != 0 { @@ -1075,11 +950,6 @@ func (Ctx *Context) DomainShutdown(id Domid) (err error) { //int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid); func (Ctx *Context) DomainReboot(id Domid) (err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - ret := C.libxl_domain_reboot(Ctx.ctx, C.uint32_t(id), nil) if ret != 0 { @@ -1091,11 +961,6 @@ func (Ctx *Context) DomainReboot(id Domid) (err error) { //libxl_dominfo * libxl_list_domain(libxl_ctx*, int *nb_domain_out); //void libxl_dominfo_list_free(libxl_dominfo *list, int nb_domain); func (Ctx *Context) ListDomain() (glist []Dominfo) { - err := Ctx.CheckOpen() - if err != nil { - return - } - var nbDomain C.int clist := C.libxl_list_domain(Ctx.ctx, &nbDomain) defer C.libxl_dominfo_list_free(clist, nbDomain) @@ -1118,11 +983,6 @@ func (Ctx *Context) ListDomain() (glist []Dominfo) { // int *nb_vcpu, int *nr_cpus_out); //void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int nr_vcpus); func (Ctx *Context) ListVcpu(id Domid) (glist []Vcpuinfo) { - err := Ctx.CheckOpen() - if err != nil { - return - } - var nbVcpu C.int var nrCpu C.int @@ -1153,11 +1013,6 @@ func (ct ConsoleType) String() (str string) { //int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num, //libxl_console_type type, char **path); func (Ctx *Context) ConsoleGetTty(id Domid, consNum int, conType ConsoleType) (path string, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - var cpath *C.char ret := C.libxl_console_get_tty(Ctx.ctx, C.uint32_t(id), C.int(consNum), C.libxl_console_type(conType), &cpath) if ret != 0 { @@ -1173,11 +1028,6 @@ func (Ctx *Context) ConsoleGetTty(id Domid, consNum int, conType ConsoleType) (p //int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm, // char **path); func (Ctx *Context) PrimaryConsoleGetTty(domid uint32) (path string, err error) { - err = Ctx.CheckOpen() - if err != nil { - return - } - var cpath *C.char ret := C.libxl_primary_console_get_tty(Ctx.ctx, C.uint32_t(domid), &cpath) if ret != 0 { From patchwork Mon Dec 23 15:17:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11308451 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 E3A5213B6 for ; Mon, 23 Dec 2019 15:19:19 +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 C030C206CB for ; Mon, 23 Dec 2019 15:19:19 +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="pHMlx/8L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C030C206CB 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 1ijPTN-0006Rs-Re; Mon, 23 Dec 2019 15:18:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijPTM-0006RE-He for xen-devel@lists.xenproject.org; Mon, 23 Dec 2019 15:18:16 +0000 X-Inumbo-ID: 6488a966-2597-11ea-88e7-bc764e2007e4 Received: from mail-qv1-xf44.google.com (unknown [2607:f8b0:4864:20::f44]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6488a966-2597-11ea-88e7-bc764e2007e4; Mon, 23 Dec 2019 15:17:54 +0000 (UTC) Received: by mail-qv1-xf44.google.com with SMTP id f16so6465194qvi.4 for ; Mon, 23 Dec 2019 07:17:54 -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 :in-reply-to:references; bh=F/xV9O13I7GQ/UCRCjsUvyaympRarisj/rLEyIKgRFk=; b=pHMlx/8LE4XvEKQdtXEU5JugHWGVSHtPu5CB0TuFY+vwS7ud3dp6GCiMKqPWuoIc0J KeMrfC+AfndLLXMxb1XFU/WAgqW23rF/kZbi4q/eNA1VSv0W0FBUhK5irNio9wnHZdYU K3v0/jm5/q0IWBg9cQHMYRrLYeSJwgj9bRzWfefPjD30Z3TLNe/xvDCdGICKMnlGu3N8 q2O1oJD/RVEeOfQx55nRP9qKxuQeEyDWWCXT+sejzxosO1bMJ8bvxuhoSwa32D0vcCcK 0pJPq2e3lI13cUd2GrcPciO97d8HvvxxqafyfIqdYluGT1qPX0TB9Qn71dty/eCZJCzX uZyw== 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:in-reply-to:references; bh=F/xV9O13I7GQ/UCRCjsUvyaympRarisj/rLEyIKgRFk=; b=KMmxKm1iD+ddxhpK42nDdmfhnyUq1LgM+o3NSsZZpIxmCSYZDXnZldO6xAbggenAV1 wAaOUXxtcvG1r1C7ZslVKyQDlwtcFhEt4BhmvJAWrzSIVJ2pfoEGky6EsVNBldJa2Otd OWfgOQI57aT2dVfQgSzA19dnadxIvOiQJ3xd9kMLFaAAMfNt6p30tzIGtAhof9yULQ/u uzlgubvFAX35aSkGaOXzQf/1LqIYt5zVOC9VmPw13GulyPfUakEqLgDDpNjLw18bKOpO Rp/giE7FKjjfOQ+9gonis23ziVGg7I+q35vLrQY3b9I1Lfwz6bBvZqZ3uanGAK6+ho13 axpQ== X-Gm-Message-State: APjAAAUampyArhidBPb109Nj90sOZnjW9hQgzp4qRWblybT32SYXHWRg CfNqNom667Hfw7keVGDkn34j5YAo X-Google-Smtp-Source: APXvYqwZ8k+GIdIvG464d7bb9g5hI8ovmp+u+tGC7954ukk610VnYppuqyyat1ONvNOLglX4BesNEQ== X-Received: by 2002:a0c:c389:: with SMTP id o9mr25177144qvi.232.1577114273901; Mon, 23 Dec 2019 07:17:53 -0800 (PST) Received: from four.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id u15sm5823907qku.67.2019.12.23.07.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 07:17:53 -0800 (PST) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 23 Dec 2019 10:17:07 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 6/6] golang/xenlight: add error return type to Context.Cpupoolinfo 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" A previous commit that removed Context.CheckOpen revealed an ineffectual assignent to err in Context.Cpupoolinfo, as there is no error return type. Since it appears that the intent is to return an error here, add an error return value to the function signature. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- tools/golang/xenlight/xenlight.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 5f14cab6ce..237f26bce9 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -504,17 +504,17 @@ func (Ctx *Context) ListCpupool() (list []Cpupoolinfo) { } // int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid); -func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool Cpupoolinfo) { +func (Ctx *Context) CpupoolInfo(Poolid uint32) (pool Cpupoolinfo, err error) { var c_cpupool C.libxl_cpupoolinfo ret := C.libxl_cpupool_info(Ctx.ctx, &c_cpupool, C.uint32_t(Poolid)) if ret != 0 { - //err = Error(-ret) + err = Error(-ret) return } defer C.libxl_cpupoolinfo_dispose(&c_cpupool) - _ = pool.fromC(&c_cpupool) + err = pool.fromC(&c_cpupool) return }