From patchwork Fri Jan 17 15:57:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339513 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 AFFCA92A for ; Fri, 17 Jan 2020 15:59: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 7F8102064C for ; Fri, 17 Jan 2020 15:59:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="aopqZ255" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F8102064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0m-0002fw-4H; Fri, 17 Jan 2020 15:58:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isU0l-0002fV-BS for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:58:15 +0000 X-Inumbo-ID: 1e6a4566-3942-11ea-b833-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1e6a4566-3942-11ea-b833-bc764e2007e4; Fri, 17 Jan 2020 15:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276672; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uXFfchwDKdeHifUh7fNkbcVxcXpXnJ9DhhwXwM9KJYM=; b=aopqZ255ylCYejAxE+0As/rRHNgwaRttRVlwAlhVG5a+sz1LMo0ZLGnF tSZ0FEEmqbrVddeyTvn76oudCHXSs0mB4YlqSSmzpqHR9TAQdeHSL4FpE Yv35ANphkXGTjQm7r2SS5p8INGGKQ0ZyGZa0C6PlfLdBJH1gshqTM818Q A=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: itp8s+tDMuAVROX6M9HA4d+yo7zZWWbNndqu7pQbfz8SRvDyd8eLdJQoYiqlRL6GFH0sV6Irxq 3bAjwh4pwQzXwguGr6eFYjWhZm8b9VqP00Uvhtk6hyFjTacrcWMLuT9VWjB7uCSZmwTNYZz4+Y pGUPHF8sqIvqgBddHJKgPJ+ntgUpNC99aJhE58Z0ugil/QWwXcXf4MTjHZFsq8rOrQq2wj8jO8 eG7A6Ph7VskoZajj+8Xx9iu5NHvgMIPDzL9DyT8cX6+GIeig7ywsw/iFrtkPRS2TrgaGPxpvA3 Ih0= X-SBRS: 2.7 X-MesageID: 11674367 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674367" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:27 +0000 Message-ID: <20200117155734.1067550-1-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 1/8] golang/xenlight: Don't try to marshall zero-length arrays in fromC 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The current fromC array code will do the "magic" casting and martialling even when num_foo variable is 0. Go crashes when doing the cast. Only do array marshalling if the number of elements is non-zero; otherwise, leave the target pointer empty (nil for Go slices, NULL for C arrays). Signed-off-by: George Dunlap --- v2: - Remove toC part of this, which has been folded into Nick's patch series. CC: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 5 +- tools/golang/xenlight/helpers.gen.go | 452 +++++++++++++++------------ 2 files changed, 261 insertions(+), 196 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index 27edf66241..ad2c573da9 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -419,7 +419,8 @@ def xenlight_golang_array_from_C(ty = None): clenvar = ty.type.lenvar.name golenvar = xenlight_golang_fmt_name(clenvar,exported=False) - s += '{} := int(xc.{})\n'.format(golenvar, clenvar) + s += 'x.{} = nil\n'.format(goname) + s += 'if {} := int(xc.{}); {} > 0 {{\n'.format(golenvar, clenvar, golenvar) s += '{} := '.format(cslice) s +='(*[1<<28]C.{})(unsafe.Pointer(xc.{}))[:{}:{}]\n'.format(ctypename, cname, golenvar, golenvar) @@ -433,7 +434,7 @@ def xenlight_golang_array_from_C(ty = None): s += 'if err := x.{}[i].fromC(&v); err != nil {{\n'.format(goname) s += 'return err }\n' - s += '}\n' + s += '}\n}\n' return s diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index b9a7e828a0..889807d928 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -623,12 +623,14 @@ func (x *SchedParams) toC(xc *C.libxl_sched_params) (err 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 + x.Vcpus = nil + if numVcpus := int(xc.num_vcpus); numVcpus > 0 { + 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 + } } } @@ -691,11 +693,13 @@ func (x *DomainSchedParams) toC(xc *C.libxl_domain_sched_params) (err 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.Distances = nil + if numDistances := int(xc.num_distances); numDistances > 0 { + 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 { @@ -760,20 +764,24 @@ 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 + x.VcpuHardAffinity = nil + if numVcpuHardAffinity := int(xc.num_vcpu_hard_affinity); numVcpuHardAffinity > 0 { + 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 + x.VcpuSoftAffinity = nil + if numVcpuSoftAffinity := int(xc.num_vcpu_soft_affinity); numVcpuSoftAffinity > 0 { + 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 { @@ -798,12 +806,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.VnumaNodes = nil + if numVnumaNodes := int(xc.num_vnuma_nodes); numVnumaNodes > 0 { + 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) @@ -828,26 +838,32 @@ 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 + x.Ioports = nil + if numIoports := int(xc.num_ioports); numIoports > 0 { + 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) + x.Irqs = nil + if numIrqs := int(xc.num_irqs); numIrqs > 0 { + 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 + x.Iomem = nil + if numIomem := int(xc.num_iomem); numIomem > 0 { + 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 { @@ -878,18 +894,18 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.Tee = TeeType(xc.tee) x.Type = DomainType(xc._type) switch x.Type { - case DomainTypePv: - var typePv DomainBuildInfoTypeUnionPv - if err := typePv.fromC(xc); err != nil { - return err - } - x.TypeUnion = typePv case DomainTypeHvm: var typeHvm DomainBuildInfoTypeUnionHvm if err := typeHvm.fromC(xc); err != nil { return err } x.TypeUnion = typeHvm + case DomainTypePv: + var typePv DomainBuildInfoTypeUnionPv + if err := typePv.fromC(xc); err != nil { + return err + } + x.TypeUnion = typePv case DomainTypePvh: var typePvh DomainBuildInfoTypeUnionPvh if err := typePvh.fromC(xc); err != nil { @@ -2187,12 +2203,14 @@ 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 + x.Connectors = nil + if numConnectors := int(xc.num_connectors); numConnectors > 0 { + 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 + } } } @@ -2227,17 +2245,21 @@ func (x *DeviceVdispl) toC(xc *C.libxl_device_vdispl) (err error) { } 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.SampleRates = nil + if numSampleRates := int(xc.num_sample_rates); numSampleRates > 0 { + 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) + } + } + x.SampleFormats = nil + if numSampleFormats := int(xc.num_sample_formats); numSampleFormats > 0 { + 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) @@ -2309,12 +2331,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 + x.Streams = nil + if numVsndStreams := int(xc.num_vsnd_streams); numVsndStreams > 0 { + 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 + } } } @@ -2357,12 +2381,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 + x.Pcms = nil + if numVsndPcms := int(xc.num_vsnd_pcms); numVsndPcms > 0 { + 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 + } } } @@ -2411,124 +2437,154 @@ 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 + x.Disks = nil + if numDisks := int(xc.num_disks); numDisks > 0 { + 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 + x.Nics = nil + if numNics := int(xc.num_nics); numNics > 0 { + 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 + x.Pcidevs = nil + if numPcidevs := int(xc.num_pcidevs); numPcidevs > 0 { + 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 + x.Rdms = nil + if numRdms := int(xc.num_rdms); numRdms > 0 { + 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 + x.Dtdevs = nil + if numDtdevs := int(xc.num_dtdevs); numDtdevs > 0 { + 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 + x.Vfbs = nil + if numVfbs := int(xc.num_vfbs); numVfbs > 0 { + 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 + x.Vkbs = nil + if numVkbs := int(xc.num_vkbs); numVkbs > 0 { + 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 + x.Vtpms = nil + if numVtpms := int(xc.num_vtpms); numVtpms > 0 { + 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 + x.P9S = nil + if numP9S := int(xc.num_p9s); numP9S > 0 { + 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 + x.Pvcallsifs = nil + if numPvcallsifs := int(xc.num_pvcallsifs); numPvcallsifs > 0 { + 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 + x.Vdispls = nil + if numVdispls := int(xc.num_vdispls); numVdispls > 0 { + 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 + x.Vsnds = nil + if numVsnds := int(xc.num_vsnds); numVsnds > 0 { + 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 + x.Channels = nil + if numChannels := int(xc.num_channels); numChannels > 0 { + 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 + x.Usbctrls = nil + if numUsbctrls := int(xc.num_usbctrls); numUsbctrls > 0 { + 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.Usbdevs = nil + if numUsbdevs := int(xc.num_usbdevs); numUsbdevs > 0 { + 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) @@ -3012,12 +3068,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 + x.Connectors = nil + if numConnectors := int(xc.num_connectors); numConnectors > 0 { + 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 + } } } @@ -3077,12 +3135,14 @@ func (x *Streaminfo) toC(xc *C.libxl_streaminfo) (err 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 + x.Streams = nil + if numVsndStreams := int(xc.num_vsnd_streams); numVsndStreams > 0 { + 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 + } } } @@ -3117,12 +3177,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 + x.Pcms = nil + if numVsndPcms := int(xc.num_vsnd_pcms); numVsndPcms > 0 { + 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 + } } } @@ -3199,11 +3261,13 @@ func (x *Vkbinfo) toC(xc *C.libxl_vkbinfo) (err 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) + x.Dists = nil + if numDists := int(xc.num_dists); numDists > 0 { + 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 Fri Jan 17 15:57:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339505 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 D94A192A for ; Fri, 17 Jan 2020 15:58:54 +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 B58E42064C for ; Fri, 17 Jan 2020 15:58:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="QcJ7OEKb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B58E42064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0X-0002Y8-4Q; Fri, 17 Jan 2020 15:58:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isU0W-0002Xs-AN for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:58:00 +0000 X-Inumbo-ID: 1900756e-3942-11ea-b833-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1900756e-3942-11ea-b833-bc764e2007e4; Fri, 17 Jan 2020 15:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VuZJzWZghr54Ihbi9LwnW7Xlt5ouevKSKJb7hSv05Wk=; b=QcJ7OEKbXGlwlvYdF15kAOc2vjT6HNgpLtT7VrRqEnNdGFJeKsBbRn7t v53wgI329wEVMKeQxzRN+FJMyBWGX7rRh3sHG4VK9UstTk8HnCtmeprb9 gEhyrhooaK5vyLuESS9u3lL500DA31yMEAgOyCiOijRtlwx8Gpg5c9/yu E=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: bX1ymuBVfVruhi2tmvXrgWHvEW3aysskTMhoAMxWx5Lj+ZTeubfNF5bhsq6I7RZrj1FORmrb8B sdX3M+tYs24E24ks8sqe2/uualkAxktcKeFINH4D9HgJSR+R4Y/ddckoSQx2AZCObKvF8Rtqo7 3iIJ14dDowKonxX7p1HKlx9yjAzdobGV67AbWI1IxFm9103oY5ghjTZq9GZ2WjEsDkRoX/IxS0 5hqu7crBrwjTdfVT7y7F5HyPfV33yZueDKO+5AgpFVfKMktp4yBdcaPDZ0yK+q7RsMkI5jIzvW RSw= X-SBRS: 2.7 X-MesageID: 11674363 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674363" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:28 +0000 Message-ID: <20200117155734.1067550-2-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200117155734.1067550-1-george.dunlap@citrix.com> References: <20200117155734.1067550-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 2/8] go/xenlight: Fix CpuidPoliclyList conversion 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Empty Go strings should be converted to `nil` libxl_cpuid_policy_list; otherwise libxl_cpuid_parse_config gets confused. Also, libxl_cpuid_policy_list returns a weird error, not a "normal" libxl error; if it returns one of these non-standard errors, convert it to ErrorInval. Finally, make the fromC() method take a pointer, and set the value of CpuidPolicyList such that it will generate a valid CpuidPolicyList in response. Signed-off-by: George Dunlap Reviewed-by: Nick Rosbrook --- v2: - Port over toC() function signature change - Have fromC set the string to "" CC: Nick Rosbrook --- tools/golang/xenlight/xenlight.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index b1587b964f..1299981713 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -306,9 +306,14 @@ func (el *EvLink) toC(cel *C.libxl_ev_link) (err error) { return } // empty when it is returned from libxl. type CpuidPolicyList string -func (cpl CpuidPolicyList) fromC(ccpl *C.libxl_cpuid_policy_list) error { return nil } +func (cpl *CpuidPolicyList) fromC(ccpl *C.libxl_cpuid_policy_list) error { *cpl = ""; return nil } func (cpl CpuidPolicyList) toC(ccpl *C.libxl_cpuid_policy_list) error { + if cpl == "" { + *ccpl = nil + return nil + } + s := C.CString(string(cpl)) defer C.free(unsafe.Pointer(s)) @@ -316,7 +321,8 @@ func (cpl CpuidPolicyList) toC(ccpl *C.libxl_cpuid_policy_list) error { if ret != 0 { C.libxl_cpuid_dispose(ccpl) - return Error(-ret) + // libxl_cpuid_parse_config doesn't return a normal libxl error. + return ErrorInval } return nil From patchwork Fri Jan 17 15:57:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339515 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 2583913A0 for ; Fri, 17 Jan 2020 15:59:51 +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 D333A2064C for ; Fri, 17 Jan 2020 15:59:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="BbDMVbOL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D333A2064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0w-0002n0-Uq; Fri, 17 Jan 2020 15:58:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isU0v-0002m3-C0 for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:58:25 +0000 X-Inumbo-ID: 21a6c75e-3942-11ea-9fd7-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 21a6c75e-3942-11ea-9fd7-bc764e2007e4; Fri, 17 Jan 2020 15:57:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276678; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DqzxPBGLXlAPOevm9+DmIQN1bfiqbkyVF8GZfq2FmZQ=; b=BbDMVbOLfomU11JNSTZSnyEYc4FqAb2RcRs/AqOlDNDNpj48q90oWcxH axDQKf1UzBsWAloiN8ANLYqbJsBp1UIUXoYFEhBSZ/cAuWz62l79+n8zh KHRrzqRbEURnGvNb61VHWerVkzyWX4XoyuXComkGKs5Y2nScdaoLm1OUC o=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: zY3jDXenYhxcL+uo6U+PjfFxvRHKzf5eTKgBR+NV+EwPeEgudpsFz69YO0wuaaunEgFMPeVolB OOLPQTFF8JiHCUZKl9xkV41smQKOhu//IsGEItSRS++ALHwyIx0QNXjCim98qIcnKTN7uBRom5 9Gupgjdodf8SMB6jG+UX388v1arz+b7ule+9y3aCxOo1aAVnSLAO48WcziHgMWE9x8FqTZtzv9 uNS6ZJGDmOQJgepHqi/X7ushnv7V0h1ZPtgUAnbZewikI72LM/zyLzMQXq5eFegNv7SDqW0J2J u2c= X-SBRS: 2.7 X-MesageID: 11674372 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674372" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:29 +0000 Message-ID: <20200117155734.1067550-3-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200117155734.1067550-1-george.dunlap@citrix.com> References: <20200117155734.1067550-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 3/8] go/xenlight: More informative error messages 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" If an error is encountered deep in a complicated data structure, it's often difficult to tell where the error actually is. Make the error message from the generated toC() and fromC() structures more informative by tagging which field being converted encountered the error. This will have the effect of giving a "stack trace" of the failure inside a nested data structure. NB that my version of python insists on reordering a couple of switch statements for some reason; In other patches I've reverted those changes, but in this case it's more difficult because they interact with actual code changes. I'll leave this here for now, as we're going to remove helpers.gen.go from being tracked by git at some point in the near future anyway. Signed-off-by: George Dunlap Reviewed-by: Nick Rosbrook --- v2: - Keep error messages lower case - Actually implement .toC changes CC: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 10 +- tools/golang/xenlight/helpers.gen.go | 530 +++++++++++++-------------- 2 files changed, 270 insertions(+), 270 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index ad2c573da9..17b0ca00bd 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -314,7 +314,7 @@ def xenlight_golang_convert_from_C(ty = None, outer_name = None, cvarname = None # If the type is not castable, we need to call its fromC # function. s += 'if err := x.{}.fromC(&{}.{});'.format(goname,cvarname,cname) - s += 'err != nil {\n return err \n}\n' + s += 'err != nil {{\nreturn fmt.Errorf("converting field {}: %v", err) \n}}\n'.format(goname) elif gotypename == 'string': # Use the cgo helper for converting C strings. @@ -389,7 +389,7 @@ def xenlight_golang_union_from_C(ty = None, union_name = '', struct_name = ''): s += 'var {} {}\n'.format(goname, gotype) s += 'if err := {}.fromC(xc);'.format(goname) - s += 'err != nil {\n return err \n}\n' + s += 'err != nil {{\n return fmt.Errorf("converting field {}: %v", err) \n}}\n'.format(goname) field_name = xenlight_golang_fmt_name('{}_union'.format(keyname)) s += 'x.{} = {}\n'.format(field_name, goname) @@ -432,7 +432,7 @@ def xenlight_golang_array_from_C(ty = None): 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 += 'return fmt.Errorf("converting field {}: %v", err) }}\n'.format(goname) s += '}\n}\n' @@ -513,7 +513,7 @@ def xenlight_golang_convert_to_C(ty = None, outer_name = None, if not is_castable: s += 'if err := {}.{}.toC(&{}.{}); err != nil {{\n'.format(govarname,goname, cvarname,cname) - s += 'return err\n}\n' + s += 'return fmt.Errorf("converting field {}: %v", err) \n}}\n'.format(goname) elif gotypename == 'string': # Use the cgo helper for converting C strings. @@ -615,7 +615,7 @@ def xenlight_golang_array_to_C(ty = None): golenvar,golenvar) s += 'for i,v := range x.{} {{\n'.format(goname) s += 'if err := v.toC(&c{}[i]); err != nil {{\n'.format(goname) - s += 'return err\n' + s += 'return fmt.Errorf("converting field {}: %v", err) \n'.format(goname) s += '}\n}\n}\n' return s diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 889807d928..078c37f1c8 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -92,13 +92,13 @@ func (x *VgaInterfaceInfo) toC(xc *C.libxl_vga_interface_info) (err error) { func (x *VncInfo) fromC(xc *C.libxl_vnc_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { - return err + return fmt.Errorf("converting field Enable: %v", err) } x.Listen = C.GoString(xc.listen) x.Passwd = C.GoString(xc.passwd) x.Display = int(xc.display) if err := x.Findunused.fromC(&xc.findunused); err != nil { - return err + return fmt.Errorf("converting field Findunused: %v", err) } return nil @@ -112,7 +112,7 @@ func (x *VncInfo) toC(xc *C.libxl_vnc_info) (err error) { }() if err := x.Enable.toC(&xc.enable); err != nil { - return err + return fmt.Errorf("converting field Enable: %v", err) } if x.Listen != "" { xc.listen = C.CString(x.Listen) @@ -122,7 +122,7 @@ func (x *VncInfo) toC(xc *C.libxl_vnc_info) (err error) { } xc.display = C.int(x.Display) if err := x.Findunused.toC(&xc.findunused); err != nil { - return err + return fmt.Errorf("converting field Findunused: %v", err) } return nil @@ -130,23 +130,23 @@ func (x *VncInfo) toC(xc *C.libxl_vnc_info) (err error) { func (x *SpiceInfo) fromC(xc *C.libxl_spice_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { - return err + return fmt.Errorf("converting field Enable: %v", err) } x.Port = int(xc.port) x.TlsPort = int(xc.tls_port) x.Host = C.GoString(xc.host) if err := x.DisableTicketing.fromC(&xc.disable_ticketing); err != nil { - return err + return fmt.Errorf("converting field DisableTicketing: %v", err) } x.Passwd = C.GoString(xc.passwd) if err := x.AgentMouse.fromC(&xc.agent_mouse); err != nil { - return err + return fmt.Errorf("converting field AgentMouse: %v", err) } if err := x.Vdagent.fromC(&xc.vdagent); err != nil { - return err + return fmt.Errorf("converting field Vdagent: %v", err) } if err := x.ClipboardSharing.fromC(&xc.clipboard_sharing); err != nil { - return err + return fmt.Errorf("converting field ClipboardSharing: %v", err) } x.Usbredirection = int(xc.usbredirection) x.ImageCompression = C.GoString(xc.image_compression) @@ -163,7 +163,7 @@ func (x *SpiceInfo) toC(xc *C.libxl_spice_info) (err error) { }() if err := x.Enable.toC(&xc.enable); err != nil { - return err + return fmt.Errorf("converting field Enable: %v", err) } xc.port = C.int(x.Port) xc.tls_port = C.int(x.TlsPort) @@ -171,19 +171,19 @@ func (x *SpiceInfo) toC(xc *C.libxl_spice_info) (err error) { xc.host = C.CString(x.Host) } if err := x.DisableTicketing.toC(&xc.disable_ticketing); err != nil { - return err + return fmt.Errorf("converting field DisableTicketing: %v", err) } if x.Passwd != "" { xc.passwd = C.CString(x.Passwd) } if err := x.AgentMouse.toC(&xc.agent_mouse); err != nil { - return err + return fmt.Errorf("converting field AgentMouse: %v", err) } if err := x.Vdagent.toC(&xc.vdagent); err != nil { - return err + return fmt.Errorf("converting field Vdagent: %v", err) } if err := x.ClipboardSharing.toC(&xc.clipboard_sharing); err != nil { - return err + return fmt.Errorf("converting field ClipboardSharing: %v", err) } xc.usbredirection = C.int(x.Usbredirection) if x.ImageCompression != "" { @@ -198,10 +198,10 @@ func (x *SpiceInfo) toC(xc *C.libxl_spice_info) (err error) { func (x *SdlInfo) fromC(xc *C.libxl_sdl_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { - return err + return fmt.Errorf("converting field Enable: %v", err) } if err := x.Opengl.fromC(&xc.opengl); err != nil { - return err + return fmt.Errorf("converting field Opengl: %v", err) } x.Display = C.GoString(xc.display) x.Xauthority = C.GoString(xc.xauthority) @@ -217,10 +217,10 @@ func (x *SdlInfo) toC(xc *C.libxl_sdl_info) (err error) { }() if err := x.Enable.toC(&xc.enable); err != nil { - return err + return fmt.Errorf("converting field Enable: %v", err) } if err := x.Opengl.toC(&xc.opengl); err != nil { - return err + return fmt.Errorf("converting field Opengl: %v", err) } if x.Display != "" { xc.display = C.CString(x.Display) @@ -234,7 +234,7 @@ func (x *SdlInfo) toC(xc *C.libxl_sdl_info) (err error) { func (x *Dominfo) fromC(xc *C.libxl_dominfo) error { if err := x.Uuid.fromC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } x.Domid = Domid(xc.domid) x.Ssidref = uint32(xc.ssidref) @@ -268,7 +268,7 @@ func (x *Dominfo) toC(xc *C.libxl_dominfo) (err error) { }() if err := x.Uuid.toC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } xc.domid = C.libxl_domid(x.Domid) xc.ssidref = C.uint32_t(x.Ssidref) @@ -302,7 +302,7 @@ func (x *Cpupoolinfo) fromC(xc *C.libxl_cpupoolinfo) error { x.Sched = Scheduler(xc.sched) x.NDom = uint32(xc.n_dom) if err := x.Cpumap.fromC(&xc.cpumap); err != nil { - return err + return fmt.Errorf("converting field Cpumap: %v", err) } return nil @@ -322,7 +322,7 @@ func (x *Cpupoolinfo) toC(xc *C.libxl_cpupoolinfo) (err error) { xc.sched = C.libxl_scheduler(x.Sched) xc.n_dom = C.uint32_t(x.NDom) if err := x.Cpumap.toC(&xc.cpumap); err != nil { - return err + return fmt.Errorf("converting field Cpumap: %v", err) } return nil @@ -342,7 +342,7 @@ func (x *Channelinfo) fromC(xc *C.libxl_channelinfo) error { case ChannelConnectionPty: var connectionPty ChannelinfoConnectionUnionPty if err := connectionPty.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field connectionPty: %v", err) } x.ConnectionUnion = connectionPty default: @@ -403,7 +403,7 @@ func (x *Channelinfo) toC(xc *C.libxl_channelinfo) (err error) { func (x *Vminfo) fromC(xc *C.libxl_vminfo) error { if err := x.Uuid.fromC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } x.Domid = Domid(xc.domid) @@ -418,7 +418,7 @@ func (x *Vminfo) toC(xc *C.libxl_vminfo) (err error) { }() if err := x.Uuid.toC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } xc.domid = C.libxl_domid(x.Domid) @@ -488,30 +488,30 @@ func (x *VersionInfo) toC(xc *C.libxl_version_info) (err error) { 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 { - return err + return fmt.Errorf("converting field Hap: %v", err) } if err := x.Oos.fromC(&xc.oos); err != nil { - return err + return fmt.Errorf("converting field Oos: %v", err) } x.Ssidref = uint32(xc.ssidref) x.SsidLabel = C.GoString(xc.ssid_label) x.Name = C.GoString(xc.name) if err := x.Uuid.fromC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } if err := x.Xsdata.fromC(&xc.xsdata); err != nil { - return err + return fmt.Errorf("converting field Xsdata: %v", err) } if err := x.Platformdata.fromC(&xc.platformdata); err != nil { - return err + return fmt.Errorf("converting field Platformdata: %v", err) } x.Poolid = uint32(xc.poolid) x.PoolName = C.GoString(xc.pool_name) if err := x.RunHotplugScripts.fromC(&xc.run_hotplug_scripts); err != nil { - return err + return fmt.Errorf("converting field RunHotplugScripts: %v", err) } if err := x.DriverDomain.fromC(&xc.driver_domain); err != nil { - return err + return fmt.Errorf("converting field DriverDomain: %v", err) } x.Passthrough = Passthrough(xc.passthrough) @@ -527,10 +527,10 @@ func (x *DomainCreateInfo) toC(xc *C.libxl_domain_create_info) (err error) { xc._type = C.libxl_domain_type(x.Type) if err := x.Hap.toC(&xc.hap); err != nil { - return err + return fmt.Errorf("converting field Hap: %v", err) } if err := x.Oos.toC(&xc.oos); err != nil { - return err + return fmt.Errorf("converting field Oos: %v", err) } xc.ssidref = C.uint32_t(x.Ssidref) if x.SsidLabel != "" { @@ -540,23 +540,23 @@ func (x *DomainCreateInfo) toC(xc *C.libxl_domain_create_info) (err error) { xc.name = C.CString(x.Name) } if err := x.Uuid.toC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } if err := x.Xsdata.toC(&xc.xsdata); err != nil { - return err + return fmt.Errorf("converting field Xsdata: %v", err) } if err := x.Platformdata.toC(&xc.platformdata); err != nil { - return err + return fmt.Errorf("converting field Platformdata: %v", err) } xc.poolid = C.uint32_t(x.Poolid) if x.PoolName != "" { xc.pool_name = C.CString(x.PoolName) } if err := x.RunHotplugScripts.toC(&xc.run_hotplug_scripts); err != nil { - return err + return fmt.Errorf("converting field RunHotplugScripts: %v", err) } if err := x.DriverDomain.toC(&xc.driver_domain); err != nil { - return err + return fmt.Errorf("converting field DriverDomain: %v", err) } xc.passthrough = C.libxl_passthrough(x.Passthrough) @@ -568,7 +568,7 @@ func (x *DomainRestoreParams) fromC(xc *C.libxl_domain_restore_params) error { x.StreamVersion = uint32(xc.stream_version) x.ColoProxyScript = C.GoString(xc.colo_proxy_script) if err := x.UserspaceColoProxy.fromC(&xc.userspace_colo_proxy); err != nil { - return err + return fmt.Errorf("converting field UserspaceColoProxy: %v", err) } return nil @@ -587,7 +587,7 @@ func (x *DomainRestoreParams) toC(xc *C.libxl_domain_restore_params) (err error) xc.colo_proxy_script = C.CString(x.ColoProxyScript) } if err := x.UserspaceColoProxy.toC(&xc.userspace_colo_proxy); err != nil { - return err + return fmt.Errorf("converting field UserspaceColoProxy: %v", err) } return nil @@ -629,7 +629,7 @@ func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { x.Vcpus = make([]SchedParams, numVcpus) for i, v := range cVcpus { if err := x.Vcpus[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Vcpus: %v", err) } } } @@ -651,7 +651,7 @@ func (x *VcpuSchedParams) toC(xc *C.libxl_vcpu_sched_params) (err error) { cVcpus := (*[1 << 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:numVcpus:numVcpus] for i, v := range x.Vcpus { if err := v.toC(&cVcpus[i]); err != nil { - return err + return fmt.Errorf("converting field Vcpus: %v", err) } } } @@ -703,7 +703,7 @@ func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { } x.Pnode = uint32(xc.pnode) if err := x.Vcpus.fromC(&xc.vcpus); err != nil { - return err + return fmt.Errorf("converting field Vcpus: %v", err) } return nil @@ -727,7 +727,7 @@ func (x *VnodeInfo) toC(xc *C.libxl_vnode_info) (err error) { } xc.pnode = C.uint32_t(x.Pnode) if err := x.Vcpus.toC(&xc.vcpus); err != nil { - return err + return fmt.Errorf("converting field Vcpus: %v", err) } return nil @@ -756,13 +756,13 @@ func (x *RdmReserve) toC(xc *C.libxl_rdm_reserve) (err error) { 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 { - return err + return fmt.Errorf("converting field AvailVcpus: %v", err) } if err := x.Cpumap.fromC(&xc.cpumap); err != nil { - return err + return fmt.Errorf("converting field Cpumap: %v", err) } if err := x.Nodemap.fromC(&xc.nodemap); err != nil { - return err + return fmt.Errorf("converting field Nodemap: %v", err) } x.VcpuHardAffinity = nil if numVcpuHardAffinity := int(xc.num_vcpu_hard_affinity); numVcpuHardAffinity > 0 { @@ -770,7 +770,7 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.VcpuHardAffinity = make([]Bitmap, numVcpuHardAffinity) for i, v := range cVcpuHardAffinity { if err := x.VcpuHardAffinity[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field VcpuHardAffinity: %v", err) } } } @@ -780,12 +780,12 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.VcpuSoftAffinity = make([]Bitmap, numVcpuSoftAffinity) for i, v := range cVcpuSoftAffinity { if err := x.VcpuSoftAffinity[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field VcpuSoftAffinity: %v", err) } } } if err := x.NumaPlacement.fromC(&xc.numa_placement); err != nil { - return err + return fmt.Errorf("converting field NumaPlacement: %v", err) } x.TscMode = TscMode(xc.tsc_mode) x.MaxMemkb = uint64(xc.max_memkb) @@ -797,13 +797,13 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.ExecSsidref = uint32(xc.exec_ssidref) x.ExecSsidLabel = C.GoString(xc.exec_ssid_label) if err := x.Localtime.fromC(&xc.localtime); err != nil { - return err + return fmt.Errorf("converting field Localtime: %v", err) } if err := x.DisableMigrate.fromC(&xc.disable_migrate); err != nil { - return err + return fmt.Errorf("converting field DisableMigrate: %v", err) } if err := x.Cpuid.fromC(&xc.cpuid); err != nil { - return err + return fmt.Errorf("converting field Cpuid: %v", err) } x.BlkdevStart = C.GoString(xc.blkdev_start) x.VnumaNodes = nil @@ -812,7 +812,7 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.VnumaNodes = make([]VnodeInfo, numVnumaNodes) for i, v := range cVnumaNodes { if err := x.VnumaNodes[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field VnumaNodes: %v", err) } } } @@ -820,23 +820,23 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.MaxMaptrackFrames = uint32(xc.max_maptrack_frames) x.DeviceModelVersion = DeviceModelVersion(xc.device_model_version) if err := x.DeviceModelStubdomain.fromC(&xc.device_model_stubdomain); err != nil { - return err + return fmt.Errorf("converting field DeviceModelStubdomain: %v", err) } x.DeviceModel = C.GoString(xc.device_model) x.DeviceModelSsidref = uint32(xc.device_model_ssidref) x.DeviceModelSsidLabel = C.GoString(xc.device_model_ssid_label) x.DeviceModelUser = C.GoString(xc.device_model_user) if err := x.Extra.fromC(&xc.extra); err != nil { - return err + return fmt.Errorf("converting field Extra: %v", err) } if err := x.ExtraPv.fromC(&xc.extra_pv); err != nil { - return err + return fmt.Errorf("converting field ExtraPv: %v", err) } if err := x.ExtraHvm.fromC(&xc.extra_hvm); err != nil { - return err + return fmt.Errorf("converting field ExtraHvm: %v", err) } if err := x.SchedParams.fromC(&xc.sched_params); err != nil { - return err + return fmt.Errorf("converting field SchedParams: %v", err) } x.Ioports = nil if numIoports := int(xc.num_ioports); numIoports > 0 { @@ -844,7 +844,7 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.Ioports = make([]IoportRange, numIoports) for i, v := range cIoports { if err := x.Ioports[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Ioports: %v", err) } } } @@ -862,12 +862,12 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.Iomem = make([]IomemRange, numIomem) for i, v := range cIomem { if err := x.Iomem[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Iomem: %v", err) } } } if err := x.ClaimMode.fromC(&xc.claim_mode); err != nil { - return err + return fmt.Errorf("converting field ClaimMode: %v", err) } x.EventChannels = uint32(xc.event_channels) x.Kernel = C.GoString(xc.kernel) @@ -875,21 +875,21 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.Ramdisk = C.GoString(xc.ramdisk) x.DeviceTree = C.GoString(xc.device_tree) if err := x.Acpi.fromC(&xc.acpi); err != nil { - return err + return fmt.Errorf("converting field Acpi: %v", err) } x.Bootloader = C.GoString(xc.bootloader) if err := x.BootloaderArgs.fromC(&xc.bootloader_args); err != nil { - return err + return fmt.Errorf("converting field BootloaderArgs: %v", err) } x.TimerMode = TimerMode(xc.timer_mode) if err := x.NestedHvm.fromC(&xc.nested_hvm); err != nil { - return err + return fmt.Errorf("converting field NestedHvm: %v", err) } if err := x.Apic.fromC(&xc.apic); err != nil { - return err + return fmt.Errorf("converting field Apic: %v", err) } if err := x.DmRestrict.fromC(&xc.dm_restrict); err != nil { - return err + return fmt.Errorf("converting field DmRestrict: %v", err) } x.Tee = TeeType(xc.tee) x.Type = DomainType(xc._type) @@ -897,19 +897,19 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { case DomainTypeHvm: var typeHvm DomainBuildInfoTypeUnionHvm if err := typeHvm.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field typeHvm: %v", err) } x.TypeUnion = typeHvm case DomainTypePv: var typePv DomainBuildInfoTypeUnionPv if err := typePv.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field typePv: %v", err) } x.TypeUnion = typePv case DomainTypePvh: var typePvh DomainBuildInfoTypeUnionPvh if err := typePvh.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field typePvh: %v", err) } x.TypeUnion = typePvh default: @@ -931,100 +931,100 @@ func (x *DomainBuildInfoTypeUnionHvm) fromC(xc *C.libxl_domain_build_info) error x.Firmware = C.GoString(tmp.firmware) x.Bios = BiosType(tmp.bios) if err := x.Pae.fromC(&tmp.pae); err != nil { - return err + return fmt.Errorf("converting field Pae: %v", err) } if err := x.Apic.fromC(&tmp.apic); err != nil { - return err + return fmt.Errorf("converting field Apic: %v", err) } if err := x.Acpi.fromC(&tmp.acpi); err != nil { - return err + return fmt.Errorf("converting field Acpi: %v", err) } if err := x.AcpiS3.fromC(&tmp.acpi_s3); err != nil { - return err + return fmt.Errorf("converting field AcpiS3: %v", err) } if err := x.AcpiS4.fromC(&tmp.acpi_s4); err != nil { - return err + return fmt.Errorf("converting field AcpiS4: %v", err) } if err := x.AcpiLaptopSlate.fromC(&tmp.acpi_laptop_slate); err != nil { - return err + return fmt.Errorf("converting field AcpiLaptopSlate: %v", err) } if err := x.Nx.fromC(&tmp.nx); err != nil { - return err + return fmt.Errorf("converting field Nx: %v", err) } if err := x.Viridian.fromC(&tmp.viridian); err != nil { - return err + return fmt.Errorf("converting field Viridian: %v", err) } if err := x.ViridianEnable.fromC(&tmp.viridian_enable); err != nil { - return err + return fmt.Errorf("converting field ViridianEnable: %v", err) } if err := x.ViridianDisable.fromC(&tmp.viridian_disable); err != nil { - return err + return fmt.Errorf("converting field ViridianDisable: %v", err) } x.Timeoffset = C.GoString(tmp.timeoffset) if err := x.Hpet.fromC(&tmp.hpet); err != nil { - return err + return fmt.Errorf("converting field Hpet: %v", err) } if err := x.VptAlign.fromC(&tmp.vpt_align); err != nil { - return err + return fmt.Errorf("converting field VptAlign: %v", err) } x.MmioHoleMemkb = uint64(tmp.mmio_hole_memkb) x.TimerMode = TimerMode(tmp.timer_mode) if err := x.NestedHvm.fromC(&tmp.nested_hvm); err != nil { - return err + return fmt.Errorf("converting field NestedHvm: %v", err) } if err := x.Altp2M.fromC(&tmp.altp2m); err != nil { - return err + return fmt.Errorf("converting field Altp2M: %v", err) } x.SystemFirmware = C.GoString(tmp.system_firmware) x.SmbiosFirmware = C.GoString(tmp.smbios_firmware) x.AcpiFirmware = C.GoString(tmp.acpi_firmware) x.Hdtype = Hdtype(tmp.hdtype) if err := x.Nographic.fromC(&tmp.nographic); err != nil { - return err + return fmt.Errorf("converting field Nographic: %v", err) } if err := x.Vga.fromC(&tmp.vga); err != nil { - return err + return fmt.Errorf("converting field Vga: %v", err) } if err := x.Vnc.fromC(&tmp.vnc); err != nil { - return err + return fmt.Errorf("converting field Vnc: %v", err) } x.Keymap = C.GoString(tmp.keymap) if err := x.Sdl.fromC(&tmp.sdl); err != nil { - return err + return fmt.Errorf("converting field Sdl: %v", err) } if err := x.Spice.fromC(&tmp.spice); err != nil { - return err + return fmt.Errorf("converting field Spice: %v", err) } if err := x.GfxPassthru.fromC(&tmp.gfx_passthru); err != nil { - return err + return fmt.Errorf("converting field GfxPassthru: %v", err) } x.GfxPassthruKind = GfxPassthruKind(tmp.gfx_passthru_kind) x.Serial = C.GoString(tmp.serial) x.Boot = C.GoString(tmp.boot) if err := x.Usb.fromC(&tmp.usb); err != nil { - return err + return fmt.Errorf("converting field Usb: %v", err) } x.Usbversion = int(tmp.usbversion) x.Usbdevice = C.GoString(tmp.usbdevice) if err := x.VkbDevice.fromC(&tmp.vkb_device); err != nil { - return err + return fmt.Errorf("converting field VkbDevice: %v", err) } x.Soundhw = C.GoString(tmp.soundhw) if err := x.XenPlatformPci.fromC(&tmp.xen_platform_pci); err != nil { - return err + return fmt.Errorf("converting field XenPlatformPci: %v", err) } if err := x.UsbdeviceList.fromC(&tmp.usbdevice_list); err != nil { - return err + return fmt.Errorf("converting field UsbdeviceList: %v", err) } x.VendorDevice = VendorDevice(tmp.vendor_device) if err := x.MsVmGenid.fromC(&tmp.ms_vm_genid); err != nil { - return err + return fmt.Errorf("converting field MsVmGenid: %v", err) } if err := x.SerialList.fromC(&tmp.serial_list); err != nil { - return err + return fmt.Errorf("converting field SerialList: %v", err) } if err := x.Rdm.fromC(&tmp.rdm); err != nil { - return err + return fmt.Errorf("converting field Rdm: %v", err) } x.RdmMemBoundaryMemkb = uint64(tmp.rdm_mem_boundary_memkb) x.McaCaps = uint64(tmp.mca_caps) @@ -1041,13 +1041,13 @@ func (x *DomainBuildInfoTypeUnionPv) fromC(xc *C.libxl_domain_build_info) error x.SlackMemkb = uint64(tmp.slack_memkb) x.Bootloader = C.GoString(tmp.bootloader) if err := x.BootloaderArgs.fromC(&tmp.bootloader_args); err != nil { - return err + return fmt.Errorf("converting field BootloaderArgs: %v", err) } x.Cmdline = C.GoString(tmp.cmdline) x.Ramdisk = C.GoString(tmp.ramdisk) x.Features = C.GoString(tmp.features) if err := x.E820Host.fromC(&tmp.e820_host); err != nil { - return err + return fmt.Errorf("converting field E820Host: %v", err) } return nil } @@ -1059,7 +1059,7 @@ func (x *DomainBuildInfoTypeUnionPvh) fromC(xc *C.libxl_domain_build_info) error tmp := (*C.libxl_domain_build_info_type_union_pvh)(unsafe.Pointer(&xc.u[0])) if err := x.Pvshim.fromC(&tmp.pvshim); err != nil { - return err + return fmt.Errorf("converting field Pvshim: %v", err) } x.PvshimPath = C.GoString(tmp.pvshim_path) x.PvshimCmdline = C.GoString(tmp.pvshim_cmdline) @@ -1076,13 +1076,13 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { xc.max_vcpus = C.int(x.MaxVcpus) if err := x.AvailVcpus.toC(&xc.avail_vcpus); err != nil { - return err + return fmt.Errorf("converting field AvailVcpus: %v", err) } if err := x.Cpumap.toC(&xc.cpumap); err != nil { - return err + return fmt.Errorf("converting field Cpumap: %v", err) } if err := x.Nodemap.toC(&xc.nodemap); err != nil { - return err + return fmt.Errorf("converting field Nodemap: %v", err) } if numVcpuHardAffinity := len(x.VcpuHardAffinity); numVcpuHardAffinity > 0 { xc.vcpu_hard_affinity = (*C.libxl_bitmap)(C.malloc(C.ulong(numVcpuHardAffinity) * C.sizeof_libxl_bitmap)) @@ -1090,7 +1090,7 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { cVcpuHardAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:numVcpuHardAffinity:numVcpuHardAffinity] for i, v := range x.VcpuHardAffinity { if err := v.toC(&cVcpuHardAffinity[i]); err != nil { - return err + return fmt.Errorf("converting field VcpuHardAffinity: %v", err) } } } @@ -1100,12 +1100,12 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { cVcpuSoftAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:numVcpuSoftAffinity:numVcpuSoftAffinity] for i, v := range x.VcpuSoftAffinity { if err := v.toC(&cVcpuSoftAffinity[i]); err != nil { - return err + return fmt.Errorf("converting field VcpuSoftAffinity: %v", err) } } } if err := x.NumaPlacement.toC(&xc.numa_placement); err != nil { - return err + return fmt.Errorf("converting field NumaPlacement: %v", err) } xc.tsc_mode = C.libxl_tsc_mode(x.TscMode) xc.max_memkb = C.uint64_t(x.MaxMemkb) @@ -1119,13 +1119,13 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { xc.exec_ssid_label = C.CString(x.ExecSsidLabel) } if err := x.Localtime.toC(&xc.localtime); err != nil { - return err + return fmt.Errorf("converting field Localtime: %v", err) } if err := x.DisableMigrate.toC(&xc.disable_migrate); err != nil { - return err + return fmt.Errorf("converting field DisableMigrate: %v", err) } if err := x.Cpuid.toC(&xc.cpuid); err != nil { - return err + return fmt.Errorf("converting field Cpuid: %v", err) } if x.BlkdevStart != "" { xc.blkdev_start = C.CString(x.BlkdevStart) @@ -1136,7 +1136,7 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { cVnumaNodes := (*[1 << 28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:numVnumaNodes:numVnumaNodes] for i, v := range x.VnumaNodes { if err := v.toC(&cVnumaNodes[i]); err != nil { - return err + return fmt.Errorf("converting field VnumaNodes: %v", err) } } } @@ -1144,7 +1144,7 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { xc.max_maptrack_frames = C.uint32_t(x.MaxMaptrackFrames) xc.device_model_version = C.libxl_device_model_version(x.DeviceModelVersion) if err := x.DeviceModelStubdomain.toC(&xc.device_model_stubdomain); err != nil { - return err + return fmt.Errorf("converting field DeviceModelStubdomain: %v", err) } if x.DeviceModel != "" { xc.device_model = C.CString(x.DeviceModel) @@ -1157,16 +1157,16 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { xc.device_model_user = C.CString(x.DeviceModelUser) } if err := x.Extra.toC(&xc.extra); err != nil { - return err + return fmt.Errorf("converting field Extra: %v", err) } if err := x.ExtraPv.toC(&xc.extra_pv); err != nil { - return err + return fmt.Errorf("converting field ExtraPv: %v", err) } if err := x.ExtraHvm.toC(&xc.extra_hvm); err != nil { - return err + return fmt.Errorf("converting field ExtraHvm: %v", err) } if err := x.SchedParams.toC(&xc.sched_params); err != nil { - return err + return fmt.Errorf("converting field SchedParams: %v", err) } if numIoports := len(x.Ioports); numIoports > 0 { xc.ioports = (*C.libxl_ioport_range)(C.malloc(C.ulong(numIoports) * C.sizeof_libxl_ioport_range)) @@ -1174,7 +1174,7 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { cIoports := (*[1 << 28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:numIoports:numIoports] for i, v := range x.Ioports { if err := v.toC(&cIoports[i]); err != nil { - return err + return fmt.Errorf("converting field Ioports: %v", err) } } } @@ -1192,12 +1192,12 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { cIomem := (*[1 << 28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:numIomem:numIomem] for i, v := range x.Iomem { if err := v.toC(&cIomem[i]); err != nil { - return err + return fmt.Errorf("converting field Iomem: %v", err) } } } if err := x.ClaimMode.toC(&xc.claim_mode); err != nil { - return err + return fmt.Errorf("converting field ClaimMode: %v", err) } xc.event_channels = C.uint32_t(x.EventChannels) if x.Kernel != "" { @@ -1213,23 +1213,23 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { xc.device_tree = C.CString(x.DeviceTree) } if err := x.Acpi.toC(&xc.acpi); err != nil { - return err + return fmt.Errorf("converting field Acpi: %v", err) } if x.Bootloader != "" { xc.bootloader = C.CString(x.Bootloader) } if err := x.BootloaderArgs.toC(&xc.bootloader_args); err != nil { - return err + return fmt.Errorf("converting field BootloaderArgs: %v", err) } xc.timer_mode = C.libxl_timer_mode(x.TimerMode) if err := x.NestedHvm.toC(&xc.nested_hvm); err != nil { - return err + return fmt.Errorf("converting field NestedHvm: %v", err) } if err := x.Apic.toC(&xc.apic); err != nil { - return err + return fmt.Errorf("converting field Apic: %v", err) } if err := x.DmRestrict.toC(&xc.dm_restrict); err != nil { - return err + return fmt.Errorf("converting field DmRestrict: %v", err) } xc.tee = C.libxl_tee_type(x.Tee) xc._type = C.libxl_domain_type(x.Type) @@ -1245,51 +1245,51 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { } hvm.bios = C.libxl_bios_type(tmp.Bios) if err := tmp.Pae.toC(&hvm.pae); err != nil { - return err + return fmt.Errorf("converting field Pae: %v", err) } if err := tmp.Apic.toC(&hvm.apic); err != nil { - return err + return fmt.Errorf("converting field Apic: %v", err) } if err := tmp.Acpi.toC(&hvm.acpi); err != nil { - return err + return fmt.Errorf("converting field Acpi: %v", err) } if err := tmp.AcpiS3.toC(&hvm.acpi_s3); err != nil { - return err + return fmt.Errorf("converting field AcpiS3: %v", err) } if err := tmp.AcpiS4.toC(&hvm.acpi_s4); err != nil { - return err + return fmt.Errorf("converting field AcpiS4: %v", err) } if err := tmp.AcpiLaptopSlate.toC(&hvm.acpi_laptop_slate); err != nil { - return err + return fmt.Errorf("converting field AcpiLaptopSlate: %v", err) } if err := tmp.Nx.toC(&hvm.nx); err != nil { - return err + return fmt.Errorf("converting field Nx: %v", err) } if err := tmp.Viridian.toC(&hvm.viridian); err != nil { - return err + return fmt.Errorf("converting field Viridian: %v", err) } if err := tmp.ViridianEnable.toC(&hvm.viridian_enable); err != nil { - return err + return fmt.Errorf("converting field ViridianEnable: %v", err) } if err := tmp.ViridianDisable.toC(&hvm.viridian_disable); err != nil { - return err + return fmt.Errorf("converting field ViridianDisable: %v", err) } if tmp.Timeoffset != "" { hvm.timeoffset = C.CString(tmp.Timeoffset) } if err := tmp.Hpet.toC(&hvm.hpet); err != nil { - return err + return fmt.Errorf("converting field Hpet: %v", err) } if err := tmp.VptAlign.toC(&hvm.vpt_align); err != nil { - return err + return fmt.Errorf("converting field VptAlign: %v", err) } hvm.mmio_hole_memkb = C.uint64_t(tmp.MmioHoleMemkb) hvm.timer_mode = C.libxl_timer_mode(tmp.TimerMode) if err := tmp.NestedHvm.toC(&hvm.nested_hvm); err != nil { - return err + return fmt.Errorf("converting field NestedHvm: %v", err) } if err := tmp.Altp2M.toC(&hvm.altp2m); err != nil { - return err + return fmt.Errorf("converting field Altp2M: %v", err) } if tmp.SystemFirmware != "" { hvm.system_firmware = C.CString(tmp.SystemFirmware) @@ -1302,25 +1302,25 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { } hvm.hdtype = C.libxl_hdtype(tmp.Hdtype) if err := tmp.Nographic.toC(&hvm.nographic); err != nil { - return err + return fmt.Errorf("converting field Nographic: %v", err) } if err := tmp.Vga.toC(&hvm.vga); err != nil { - return err + return fmt.Errorf("converting field Vga: %v", err) } if err := tmp.Vnc.toC(&hvm.vnc); err != nil { - return err + return fmt.Errorf("converting field Vnc: %v", err) } if tmp.Keymap != "" { hvm.keymap = C.CString(tmp.Keymap) } if err := tmp.Sdl.toC(&hvm.sdl); err != nil { - return err + return fmt.Errorf("converting field Sdl: %v", err) } if err := tmp.Spice.toC(&hvm.spice); err != nil { - return err + return fmt.Errorf("converting field Spice: %v", err) } if err := tmp.GfxPassthru.toC(&hvm.gfx_passthru); err != nil { - return err + return fmt.Errorf("converting field GfxPassthru: %v", err) } hvm.gfx_passthru_kind = C.libxl_gfx_passthru_kind(tmp.GfxPassthruKind) if tmp.Serial != "" { @@ -1330,33 +1330,33 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { hvm.boot = C.CString(tmp.Boot) } if err := tmp.Usb.toC(&hvm.usb); err != nil { - return err + return fmt.Errorf("converting field Usb: %v", err) } hvm.usbversion = C.int(tmp.Usbversion) if tmp.Usbdevice != "" { hvm.usbdevice = C.CString(tmp.Usbdevice) } if err := tmp.VkbDevice.toC(&hvm.vkb_device); err != nil { - return err + return fmt.Errorf("converting field VkbDevice: %v", err) } if tmp.Soundhw != "" { hvm.soundhw = C.CString(tmp.Soundhw) } if err := tmp.XenPlatformPci.toC(&hvm.xen_platform_pci); err != nil { - return err + return fmt.Errorf("converting field XenPlatformPci: %v", err) } if err := tmp.UsbdeviceList.toC(&hvm.usbdevice_list); err != nil { - return err + return fmt.Errorf("converting field UsbdeviceList: %v", err) } hvm.vendor_device = C.libxl_vendor_device(tmp.VendorDevice) if err := tmp.MsVmGenid.toC(&hvm.ms_vm_genid); err != nil { - return err + return fmt.Errorf("converting field MsVmGenid: %v", err) } if err := tmp.SerialList.toC(&hvm.serial_list); err != nil { - return err + return fmt.Errorf("converting field SerialList: %v", err) } if err := tmp.Rdm.toC(&hvm.rdm); err != nil { - return err + return fmt.Errorf("converting field Rdm: %v", err) } hvm.rdm_mem_boundary_memkb = C.uint64_t(tmp.RdmMemBoundaryMemkb) hvm.mca_caps = C.uint64_t(tmp.McaCaps) @@ -1376,7 +1376,7 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { pv.bootloader = C.CString(tmp.Bootloader) } if err := tmp.BootloaderArgs.toC(&pv.bootloader_args); err != nil { - return err + return fmt.Errorf("converting field BootloaderArgs: %v", err) } if tmp.Cmdline != "" { pv.cmdline = C.CString(tmp.Cmdline) @@ -1388,7 +1388,7 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { pv.features = C.CString(tmp.Features) } if err := tmp.E820Host.toC(&pv.e820_host); err != nil { - return err + return fmt.Errorf("converting field E820Host: %v", err) } pvBytes := C.GoBytes(unsafe.Pointer(&pv), C.sizeof_libxl_domain_build_info_type_union_pv) copy(xc.u[:], pvBytes) @@ -1399,7 +1399,7 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { } var pvh C.libxl_domain_build_info_type_union_pvh if err := tmp.Pvshim.toC(&pvh.pvshim); err != nil { - return err + return fmt.Errorf("converting field Pvshim: %v", err) } if tmp.PvshimPath != "" { pvh.pvshim_path = C.CString(tmp.PvshimPath) @@ -1427,10 +1427,10 @@ func (x *DeviceVfb) fromC(xc *C.libxl_device_vfb) error { x.BackendDomname = C.GoString(xc.backend_domname) x.Devid = Devid(xc.devid) if err := x.Vnc.fromC(&xc.vnc); err != nil { - return err + return fmt.Errorf("converting field Vnc: %v", err) } if err := x.Sdl.fromC(&xc.sdl); err != nil { - return err + return fmt.Errorf("converting field Sdl: %v", err) } x.Keymap = C.GoString(xc.keymap) @@ -1450,10 +1450,10 @@ func (x *DeviceVfb) toC(xc *C.libxl_device_vfb) (err error) { } xc.devid = C.libxl_devid(x.Devid) if err := x.Vnc.toC(&xc.vnc); err != nil { - return err + return fmt.Errorf("converting field Vnc: %v", err) } if err := x.Sdl.toC(&xc.sdl); err != nil { - return err + return fmt.Errorf("converting field Sdl: %v", err) } if x.Keymap != "" { xc.keymap = C.CString(x.Keymap) @@ -1525,13 +1525,13 @@ func (x *DeviceDisk) fromC(xc *C.libxl_device_disk) error { x.IsCdrom = int(xc.is_cdrom) x.DirectIoSafe = bool(xc.direct_io_safe) if err := x.DiscardEnable.fromC(&xc.discard_enable); err != nil { - return err + return fmt.Errorf("converting field DiscardEnable: %v", err) } if err := x.ColoEnable.fromC(&xc.colo_enable); err != nil { - return err + return fmt.Errorf("converting field ColoEnable: %v", err) } if err := x.ColoRestoreEnable.fromC(&xc.colo_restore_enable); err != nil { - return err + return fmt.Errorf("converting field ColoRestoreEnable: %v", err) } x.ColoHost = C.GoString(xc.colo_host) x.ColoPort = int(xc.colo_port) @@ -1569,13 +1569,13 @@ func (x *DeviceDisk) toC(xc *C.libxl_device_disk) (err error) { xc.is_cdrom = C.int(x.IsCdrom) xc.direct_io_safe = C.bool(x.DirectIoSafe) if err := x.DiscardEnable.toC(&xc.discard_enable); err != nil { - return err + return fmt.Errorf("converting field DiscardEnable: %v", err) } if err := x.ColoEnable.toC(&xc.colo_enable); err != nil { - return err + return fmt.Errorf("converting field ColoEnable: %v", err) } if err := x.ColoRestoreEnable.toC(&xc.colo_restore_enable); err != nil { - return err + return fmt.Errorf("converting field ColoRestoreEnable: %v", err) } if x.ColoHost != "" { xc.colo_host = C.CString(x.ColoHost) @@ -1601,7 +1601,7 @@ func (x *DeviceNic) fromC(xc *C.libxl_device_nic) error { x.Mtu = int(xc.mtu) x.Model = C.GoString(xc.model) if err := x.Mac.fromC(&xc.mac); err != nil { - return err + return fmt.Errorf("converting field Mac: %v", err) } x.Ip = C.GoString(xc.ip) x.Bridge = C.GoString(xc.bridge) @@ -1681,7 +1681,7 @@ func (x *DeviceNic) toC(xc *C.libxl_device_nic) (err error) { xc.model = C.CString(x.Model) } if err := x.Mac.toC(&xc.mac); err != nil { - return err + return fmt.Errorf("converting field Mac: %v", err) } if x.Ip != "" { xc.ip = C.CString(x.Ip) @@ -1950,7 +1950,7 @@ func (x *DeviceUsbdev) fromC(xc *C.libxl_device_usbdev) error { case UsbdevTypeHostdev: var typeHostdev DeviceUsbdevTypeUnionHostdev if err := typeHostdev.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field typeHostdev: %v", err) } x.TypeUnion = typeHostdev default: @@ -2024,7 +2024,7 @@ func (x *DeviceVtpm) fromC(xc *C.libxl_device_vtpm) error { x.BackendDomname = C.GoString(xc.backend_domname) x.Devid = Devid(xc.devid) if err := x.Uuid.fromC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } return nil @@ -2043,7 +2043,7 @@ func (x *DeviceVtpm) toC(xc *C.libxl_device_vtpm) (err error) { } xc.devid = C.libxl_devid(x.Devid) if err := x.Uuid.toC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } return nil @@ -2119,7 +2119,7 @@ func (x *DeviceChannel) fromC(xc *C.libxl_device_channel) error { case ChannelConnectionSocket: var connectionSocket DeviceChannelConnectionUnionSocket if err := connectionSocket.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field connectionSocket: %v", err) } x.ConnectionUnion = connectionSocket default: @@ -2209,7 +2209,7 @@ func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error { x.Connectors = make([]ConnectorParam, numConnectors) for i, v := range cConnectors { if err := x.Connectors[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Connectors: %v", err) } } } @@ -2236,7 +2236,7 @@ func (x *DeviceVdispl) toC(xc *C.libxl_device_vdispl) (err error) { cConnectors := (*[1 << 28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] for i, v := range x.Connectors { if err := v.toC(&cConnectors[i]); err != nil { - return err + return fmt.Errorf("converting field Connectors: %v", err) } } } @@ -2302,7 +2302,7 @@ func (x *VsndStream) fromC(xc *C.libxl_vsnd_stream) error { x.UniqueId = C.GoString(xc.unique_id) x.Type = VsndStreamType(xc._type) if err := x.Params.fromC(&xc.params); err != nil { - return err + return fmt.Errorf("converting field Params: %v", err) } return nil @@ -2320,7 +2320,7 @@ func (x *VsndStream) toC(xc *C.libxl_vsnd_stream) (err error) { } xc._type = C.libxl_vsnd_stream_type(x.Type) if err := x.Params.toC(&xc.params); err != nil { - return err + return fmt.Errorf("converting field Params: %v", err) } return nil @@ -2329,7 +2329,7 @@ func (x *VsndStream) toC(xc *C.libxl_vsnd_stream) (err error) { 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 { - return err + return fmt.Errorf("converting field Params: %v", err) } x.Streams = nil if numVsndStreams := int(xc.num_vsnd_streams); numVsndStreams > 0 { @@ -2337,7 +2337,7 @@ func (x *VsndPcm) fromC(xc *C.libxl_vsnd_pcm) error { x.Streams = make([]VsndStream, numVsndStreams) for i, v := range cStreams { if err := x.Streams[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Streams: %v", err) } } } @@ -2356,7 +2356,7 @@ func (x *VsndPcm) toC(xc *C.libxl_vsnd_pcm) (err error) { xc.name = C.CString(x.Name) } if err := x.Params.toC(&xc.params); err != nil { - return err + return fmt.Errorf("converting field Params: %v", err) } if numVsndStreams := len(x.Streams); numVsndStreams > 0 { xc.streams = (*C.libxl_vsnd_stream)(C.malloc(C.ulong(numVsndStreams) * C.sizeof_libxl_vsnd_stream)) @@ -2364,7 +2364,7 @@ func (x *VsndPcm) toC(xc *C.libxl_vsnd_pcm) (err error) { cStreams := (*[1 << 28]C.libxl_vsnd_stream)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] for i, v := range x.Streams { if err := v.toC(&cStreams[i]); err != nil { - return err + return fmt.Errorf("converting field Streams: %v", err) } } } @@ -2379,7 +2379,7 @@ func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error { x.ShortName = C.GoString(xc.short_name) x.LongName = C.GoString(xc.long_name) if err := x.Params.fromC(&xc.params); err != nil { - return err + return fmt.Errorf("converting field Params: %v", err) } x.Pcms = nil if numVsndPcms := int(xc.num_vsnd_pcms); numVsndPcms > 0 { @@ -2387,7 +2387,7 @@ func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error { x.Pcms = make([]VsndPcm, numVsndPcms) for i, v := range cPcms { if err := x.Pcms[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Pcms: %v", err) } } } @@ -2414,7 +2414,7 @@ func (x *DeviceVsnd) toC(xc *C.libxl_device_vsnd) (err error) { xc.long_name = C.CString(x.LongName) } if err := x.Params.toC(&xc.params); err != nil { - return err + return fmt.Errorf("converting field Params: %v", err) } if numVsndPcms := len(x.Pcms); numVsndPcms > 0 { xc.pcms = (*C.libxl_vsnd_pcm)(C.malloc(C.ulong(numVsndPcms) * C.sizeof_libxl_vsnd_pcm)) @@ -2422,7 +2422,7 @@ func (x *DeviceVsnd) toC(xc *C.libxl_device_vsnd) (err error) { cPcms := (*[1 << 28]C.libxl_vsnd_pcm)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] for i, v := range x.Pcms { if err := v.toC(&cPcms[i]); err != nil { - return err + return fmt.Errorf("converting field Pcms: %v", err) } } } @@ -2432,10 +2432,10 @@ func (x *DeviceVsnd) toC(xc *C.libxl_device_vsnd) (err error) { func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { if err := x.CInfo.fromC(&xc.c_info); err != nil { - return err + return fmt.Errorf("converting field CInfo: %v", err) } if err := x.BInfo.fromC(&xc.b_info); err != nil { - return err + return fmt.Errorf("converting field BInfo: %v", err) } x.Disks = nil if numDisks := int(xc.num_disks); numDisks > 0 { @@ -2443,7 +2443,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Disks = make([]DeviceDisk, numDisks) for i, v := range cDisks { if err := x.Disks[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Disks: %v", err) } } } @@ -2453,7 +2453,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Nics = make([]DeviceNic, numNics) for i, v := range cNics { if err := x.Nics[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Nics: %v", err) } } } @@ -2463,7 +2463,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Pcidevs = make([]DevicePci, numPcidevs) for i, v := range cPcidevs { if err := x.Pcidevs[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Pcidevs: %v", err) } } } @@ -2473,7 +2473,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Rdms = make([]DeviceRdm, numRdms) for i, v := range cRdms { if err := x.Rdms[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Rdms: %v", err) } } } @@ -2483,7 +2483,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Dtdevs = make([]DeviceDtdev, numDtdevs) for i, v := range cDtdevs { if err := x.Dtdevs[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Dtdevs: %v", err) } } } @@ -2493,7 +2493,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Vfbs = make([]DeviceVfb, numVfbs) for i, v := range cVfbs { if err := x.Vfbs[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Vfbs: %v", err) } } } @@ -2503,7 +2503,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Vkbs = make([]DeviceVkb, numVkbs) for i, v := range cVkbs { if err := x.Vkbs[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Vkbs: %v", err) } } } @@ -2513,7 +2513,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Vtpms = make([]DeviceVtpm, numVtpms) for i, v := range cVtpms { if err := x.Vtpms[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Vtpms: %v", err) } } } @@ -2523,7 +2523,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.P9S = make([]DeviceP9, numP9S) for i, v := range cP9S { if err := x.P9S[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field P9S: %v", err) } } } @@ -2533,7 +2533,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Pvcallsifs = make([]DevicePvcallsif, numPvcallsifs) for i, v := range cPvcallsifs { if err := x.Pvcallsifs[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Pvcallsifs: %v", err) } } } @@ -2543,7 +2543,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Vdispls = make([]DeviceVdispl, numVdispls) for i, v := range cVdispls { if err := x.Vdispls[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Vdispls: %v", err) } } } @@ -2553,7 +2553,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Vsnds = make([]DeviceVsnd, numVsnds) for i, v := range cVsnds { if err := x.Vsnds[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Vsnds: %v", err) } } } @@ -2563,7 +2563,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Channels = make([]DeviceChannel, numChannels) for i, v := range cChannels { if err := x.Channels[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Channels: %v", err) } } } @@ -2573,7 +2573,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Usbctrls = make([]DeviceUsbctrl, numUsbctrls) for i, v := range cUsbctrls { if err := x.Usbctrls[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Usbctrls: %v", err) } } } @@ -2583,7 +2583,7 @@ func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { x.Usbdevs = make([]DeviceUsbdev, numUsbdevs) for i, v := range cUsbdevs { if err := x.Usbdevs[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Usbdevs: %v", err) } } } @@ -2604,10 +2604,10 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { }() if err := x.CInfo.toC(&xc.c_info); err != nil { - return err + return fmt.Errorf("converting field CInfo: %v", err) } if err := x.BInfo.toC(&xc.b_info); err != nil { - return err + return fmt.Errorf("converting field BInfo: %v", err) } if numDisks := len(x.Disks); numDisks > 0 { xc.disks = (*C.libxl_device_disk)(C.malloc(C.ulong(numDisks) * C.sizeof_libxl_device_disk)) @@ -2615,7 +2615,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cDisks := (*[1 << 28]C.libxl_device_disk)(unsafe.Pointer(xc.disks))[:numDisks:numDisks] for i, v := range x.Disks { if err := v.toC(&cDisks[i]); err != nil { - return err + return fmt.Errorf("converting field Disks: %v", err) } } } @@ -2625,7 +2625,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cNics := (*[1 << 28]C.libxl_device_nic)(unsafe.Pointer(xc.nics))[:numNics:numNics] for i, v := range x.Nics { if err := v.toC(&cNics[i]); err != nil { - return err + return fmt.Errorf("converting field Nics: %v", err) } } } @@ -2635,7 +2635,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cPcidevs := (*[1 << 28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:numPcidevs:numPcidevs] for i, v := range x.Pcidevs { if err := v.toC(&cPcidevs[i]); err != nil { - return err + return fmt.Errorf("converting field Pcidevs: %v", err) } } } @@ -2645,7 +2645,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cRdms := (*[1 << 28]C.libxl_device_rdm)(unsafe.Pointer(xc.rdms))[:numRdms:numRdms] for i, v := range x.Rdms { if err := v.toC(&cRdms[i]); err != nil { - return err + return fmt.Errorf("converting field Rdms: %v", err) } } } @@ -2655,7 +2655,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cDtdevs := (*[1 << 28]C.libxl_device_dtdev)(unsafe.Pointer(xc.dtdevs))[:numDtdevs:numDtdevs] for i, v := range x.Dtdevs { if err := v.toC(&cDtdevs[i]); err != nil { - return err + return fmt.Errorf("converting field Dtdevs: %v", err) } } } @@ -2665,7 +2665,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cVfbs := (*[1 << 28]C.libxl_device_vfb)(unsafe.Pointer(xc.vfbs))[:numVfbs:numVfbs] for i, v := range x.Vfbs { if err := v.toC(&cVfbs[i]); err != nil { - return err + return fmt.Errorf("converting field Vfbs: %v", err) } } } @@ -2675,7 +2675,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cVkbs := (*[1 << 28]C.libxl_device_vkb)(unsafe.Pointer(xc.vkbs))[:numVkbs:numVkbs] for i, v := range x.Vkbs { if err := v.toC(&cVkbs[i]); err != nil { - return err + return fmt.Errorf("converting field Vkbs: %v", err) } } } @@ -2685,7 +2685,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cVtpms := (*[1 << 28]C.libxl_device_vtpm)(unsafe.Pointer(xc.vtpms))[:numVtpms:numVtpms] for i, v := range x.Vtpms { if err := v.toC(&cVtpms[i]); err != nil { - return err + return fmt.Errorf("converting field Vtpms: %v", err) } } } @@ -2695,7 +2695,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cP9S := (*[1 << 28]C.libxl_device_p9)(unsafe.Pointer(xc.p9s))[:numP9S:numP9S] for i, v := range x.P9S { if err := v.toC(&cP9S[i]); err != nil { - return err + return fmt.Errorf("converting field P9S: %v", err) } } } @@ -2705,7 +2705,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cPvcallsifs := (*[1 << 28]C.libxl_device_pvcallsif)(unsafe.Pointer(xc.pvcallsifs))[:numPvcallsifs:numPvcallsifs] for i, v := range x.Pvcallsifs { if err := v.toC(&cPvcallsifs[i]); err != nil { - return err + return fmt.Errorf("converting field Pvcallsifs: %v", err) } } } @@ -2715,7 +2715,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cVdispls := (*[1 << 28]C.libxl_device_vdispl)(unsafe.Pointer(xc.vdispls))[:numVdispls:numVdispls] for i, v := range x.Vdispls { if err := v.toC(&cVdispls[i]); err != nil { - return err + return fmt.Errorf("converting field Vdispls: %v", err) } } } @@ -2725,7 +2725,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cVsnds := (*[1 << 28]C.libxl_device_vsnd)(unsafe.Pointer(xc.vsnds))[:numVsnds:numVsnds] for i, v := range x.Vsnds { if err := v.toC(&cVsnds[i]); err != nil { - return err + return fmt.Errorf("converting field Vsnds: %v", err) } } } @@ -2735,7 +2735,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cChannels := (*[1 << 28]C.libxl_device_channel)(unsafe.Pointer(xc.channels))[:numChannels:numChannels] for i, v := range x.Channels { if err := v.toC(&cChannels[i]); err != nil { - return err + return fmt.Errorf("converting field Channels: %v", err) } } } @@ -2745,7 +2745,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cUsbctrls := (*[1 << 28]C.libxl_device_usbctrl)(unsafe.Pointer(xc.usbctrls))[:numUsbctrls:numUsbctrls] for i, v := range x.Usbctrls { if err := v.toC(&cUsbctrls[i]); err != nil { - return err + return fmt.Errorf("converting field Usbctrls: %v", err) } } } @@ -2755,7 +2755,7 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { cUsbdevs := (*[1 << 28]C.libxl_device_usbdev)(unsafe.Pointer(xc.usbdevs))[:numUsbdevs:numUsbdevs] for i, v := range x.Usbdevs { if err := v.toC(&cUsbdevs[i]); err != nil { - return err + return fmt.Errorf("converting field Usbdevs: %v", err) } } } @@ -2852,7 +2852,7 @@ func (x *Vtpminfo) fromC(xc *C.libxl_vtpminfo) error { x.Evtch = int(xc.evtch) x.Rref = int(xc.rref) if err := x.Uuid.fromC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } return nil @@ -2878,7 +2878,7 @@ func (x *Vtpminfo) toC(xc *C.libxl_vtpminfo) (err error) { xc.evtch = C.int(x.Evtch) xc.rref = C.int(x.Rref) if err := x.Uuid.toC(&xc.uuid); err != nil { - return err + return fmt.Errorf("converting field Uuid: %v", err) } return nil @@ -2936,10 +2936,10 @@ func (x *Vcpuinfo) fromC(xc *C.libxl_vcpuinfo) error { x.Running = bool(xc.running) x.VcpuTime = uint64(xc.vcpu_time) if err := x.Cpumap.fromC(&xc.cpumap); err != nil { - return err + return fmt.Errorf("converting field Cpumap: %v", err) } if err := x.CpumapSoft.fromC(&xc.cpumap_soft); err != nil { - return err + return fmt.Errorf("converting field CpumapSoft: %v", err) } return nil @@ -2959,10 +2959,10 @@ func (x *Vcpuinfo) toC(xc *C.libxl_vcpuinfo) (err error) { xc.running = C.bool(x.Running) xc.vcpu_time = C.uint64_t(x.VcpuTime) if err := x.Cpumap.toC(&xc.cpumap); err != nil { - return err + return fmt.Errorf("converting field Cpumap: %v", err) } if err := x.CpumapSoft.toC(&xc.cpumap_soft); err != nil { - return err + return fmt.Errorf("converting field CpumapSoft: %v", err) } return nil @@ -2983,7 +2983,7 @@ func (x *Physinfo) fromC(xc *C.libxl_physinfo) error { x.MaxPossibleMfn = uint64(xc.max_possible_mfn) x.NrNodes = uint32(xc.nr_nodes) if err := x.HwCap.fromC(&xc.hw_cap); err != nil { - return err + return fmt.Errorf("converting field HwCap: %v", err) } x.CapHvm = bool(xc.cap_hvm) x.CapPv = bool(xc.cap_pv) @@ -3016,7 +3016,7 @@ func (x *Physinfo) toC(xc *C.libxl_physinfo) (err error) { xc.max_possible_mfn = C.uint64_t(x.MaxPossibleMfn) xc.nr_nodes = C.uint32_t(x.NrNodes) if err := x.HwCap.toC(&xc.hw_cap); err != nil { - return err + return fmt.Errorf("converting field HwCap: %v", err) } xc.cap_hvm = C.bool(x.CapHvm) xc.cap_pv = C.bool(x.CapPv) @@ -3074,7 +3074,7 @@ func (x *Vdisplinfo) fromC(xc *C.libxl_vdisplinfo) error { x.Connectors = make([]Connectorinfo, numConnectors) for i, v := range cConnectors { if err := x.Connectors[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Connectors: %v", err) } } } @@ -3106,7 +3106,7 @@ func (x *Vdisplinfo) toC(xc *C.libxl_vdisplinfo) (err error) { cConnectors := (*[1 << 28]C.libxl_connectorinfo)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] for i, v := range x.Connectors { if err := v.toC(&cConnectors[i]); err != nil { - return err + return fmt.Errorf("converting field Connectors: %v", err) } } } @@ -3141,7 +3141,7 @@ func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error { x.Streams = make([]Streaminfo, numVsndStreams) for i, v := range cStreams { if err := x.Streams[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Streams: %v", err) } } } @@ -3162,7 +3162,7 @@ func (x *Pcminfo) toC(xc *C.libxl_pcminfo) (err error) { cStreams := (*[1 << 28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] for i, v := range x.Streams { if err := v.toC(&cStreams[i]); err != nil { - return err + return fmt.Errorf("converting field Streams: %v", err) } } } @@ -3183,7 +3183,7 @@ func (x *Vsndinfo) fromC(xc *C.libxl_vsndinfo) error { x.Pcms = make([]Pcminfo, numVsndPcms) for i, v := range cPcms { if err := x.Pcms[i].fromC(&v); err != nil { - return err + return fmt.Errorf("converting field Pcms: %v", err) } } } @@ -3214,7 +3214,7 @@ func (x *Vsndinfo) toC(xc *C.libxl_vsndinfo) (err error) { cPcms := (*[1 << 28]C.libxl_pcminfo)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms] for i, v := range x.Pcms { if err := v.toC(&cPcms[i]); err != nil { - return err + return fmt.Errorf("converting field Pcms: %v", err) } } } @@ -3371,26 +3371,26 @@ func (x *SchedCredit2Params) toC(xc *C.libxl_sched_credit2_params) (err error) { 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 { - return err + return fmt.Errorf("converting field AllowUnsafe: %v", err) } if err := x.Blackhole.fromC(&xc.blackhole); err != nil { - return err + return fmt.Errorf("converting field Blackhole: %v", err) } if err := x.Compression.fromC(&xc.compression); err != nil { - return err + return fmt.Errorf("converting field Compression: %v", err) } if err := x.Netbuf.fromC(&xc.netbuf); err != nil { - return err + return fmt.Errorf("converting field Netbuf: %v", err) } x.Netbufscript = C.GoString(xc.netbufscript) if err := x.Diskbuf.fromC(&xc.diskbuf); err != nil { - return err + return fmt.Errorf("converting field Diskbuf: %v", err) } if err := x.Colo.fromC(&xc.colo); err != nil { - return err + return fmt.Errorf("converting field Colo: %v", err) } if err := x.UserspaceColoProxy.fromC(&xc.userspace_colo_proxy); err != nil { - return err + return fmt.Errorf("converting field UserspaceColoProxy: %v", err) } return nil @@ -3405,28 +3405,28 @@ func (x *DomainRemusInfo) toC(xc *C.libxl_domain_remus_info) (err error) { xc.interval = C.int(x.Interval) if err := x.AllowUnsafe.toC(&xc.allow_unsafe); err != nil { - return err + return fmt.Errorf("converting field AllowUnsafe: %v", err) } if err := x.Blackhole.toC(&xc.blackhole); err != nil { - return err + return fmt.Errorf("converting field Blackhole: %v", err) } if err := x.Compression.toC(&xc.compression); err != nil { - return err + return fmt.Errorf("converting field Compression: %v", err) } if err := x.Netbuf.toC(&xc.netbuf); err != nil { - return err + return fmt.Errorf("converting field Netbuf: %v", err) } if x.Netbufscript != "" { xc.netbufscript = C.CString(x.Netbufscript) } if err := x.Diskbuf.toC(&xc.diskbuf); err != nil { - return err + return fmt.Errorf("converting field Diskbuf: %v", err) } if err := x.Colo.toC(&xc.colo); err != nil { - return err + return fmt.Errorf("converting field Colo: %v", err) } if err := x.UserspaceColoProxy.toC(&xc.userspace_colo_proxy); err != nil { - return err + return fmt.Errorf("converting field UserspaceColoProxy: %v", err) } return nil @@ -3434,33 +3434,33 @@ func (x *DomainRemusInfo) toC(xc *C.libxl_domain_remus_info) (err error) { func (x *Event) fromC(xc *C.libxl_event) error { if err := x.Link.fromC(&xc.link); err != nil { - return err + return fmt.Errorf("converting field Link: %v", err) } x.Domid = Domid(xc.domid) if err := x.Domuuid.fromC(&xc.domuuid); err != nil { - return err + return fmt.Errorf("converting field Domuuid: %v", err) } x.ForUser = uint64(xc.for_user) x.Type = EventType(xc._type) switch x.Type { - case EventTypeOperationComplete: - var typeOperationComplete EventTypeUnionOperationComplete - if err := typeOperationComplete.fromC(xc); err != nil { - return err - } - x.TypeUnion = typeOperationComplete case EventTypeDomainShutdown: var typeDomainShutdown EventTypeUnionDomainShutdown if err := typeDomainShutdown.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field typeDomainShutdown: %v", err) } x.TypeUnion = typeDomainShutdown case EventTypeDiskEject: var typeDiskEject EventTypeUnionDiskEject if err := typeDiskEject.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field typeDiskEject: %v", err) } x.TypeUnion = typeDiskEject + case EventTypeOperationComplete: + var typeOperationComplete EventTypeUnionOperationComplete + if err := typeOperationComplete.fromC(xc); err != nil { + return fmt.Errorf("converting field typeOperationComplete: %v", err) + } + x.TypeUnion = typeOperationComplete default: return fmt.Errorf("invalid union key '%v'", x.Type) } @@ -3486,7 +3486,7 @@ func (x *EventTypeUnionDiskEject) fromC(xc *C.libxl_event) error { tmp := (*C.libxl_event_type_union_disk_eject)(unsafe.Pointer(&xc.u[0])) x.Vdev = C.GoString(tmp.vdev) if err := x.Disk.fromC(&tmp.disk); err != nil { - return err + return fmt.Errorf("converting field Disk: %v", err) } return nil } @@ -3509,11 +3509,11 @@ func (x *Event) toC(xc *C.libxl_event) (err error) { }() if err := x.Link.toC(&xc.link); err != nil { - return err + return fmt.Errorf("converting field Link: %v", err) } xc.domid = C.libxl_domid(x.Domid) if err := x.Domuuid.toC(&xc.domuuid); err != nil { - return err + return fmt.Errorf("converting field Domuuid: %v", err) } xc.for_user = C.uint64_t(x.ForUser) xc._type = C.libxl_event_type(x.Type) @@ -3537,7 +3537,7 @@ func (x *Event) toC(xc *C.libxl_event) (err error) { disk_eject.vdev = C.CString(tmp.Vdev) } if err := tmp.Disk.toC(&disk_eject.disk); err != nil { - return err + return fmt.Errorf("converting field Disk: %v", err) } disk_ejectBytes := C.GoBytes(unsafe.Pointer(&disk_eject), C.sizeof_libxl_event_type_union_disk_eject) copy(xc.u[:], disk_ejectBytes) @@ -3585,18 +3585,18 @@ func (x *PsrHwInfo) fromC(xc *C.libxl_psr_hw_info) error { x.Id = uint32(xc.id) x.Type = PsrFeatType(xc._type) switch x.Type { - case PsrFeatTypeMba: - var typeMba PsrHwInfoTypeUnionMba - if err := typeMba.fromC(xc); err != nil { - return err - } - x.TypeUnion = typeMba case PsrFeatTypeCat: var typeCat PsrHwInfoTypeUnionCat if err := typeCat.fromC(xc); err != nil { - return err + return fmt.Errorf("converting field typeCat: %v", err) } x.TypeUnion = typeCat + case PsrFeatTypeMba: + var typeMba PsrHwInfoTypeUnionMba + if err := typeMba.fromC(xc); err != nil { + return fmt.Errorf("converting field typeMba: %v", err) + } + x.TypeUnion = typeMba default: return fmt.Errorf("invalid union key '%v'", x.Type) } From patchwork Fri Jan 17 15:57:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339503 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 EC1C413A0 for ; Fri, 17 Jan 2020 15:58:50 +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 C73792064C for ; Fri, 17 Jan 2020 15:58:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="gR7PqKvO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C73792064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0S-0002WO-LF; Fri, 17 Jan 2020 15:57:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isU0R-0002W7-Ax for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:57:55 +0000 X-Inumbo-ID: 182e0138-3942-11ea-9fd7-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 182e0138-3942-11ea-9fd7-bc764e2007e4; Fri, 17 Jan 2020 15:57:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=41jiLhUK+rJBShbXoF53s8BPT3orNgLEoRhZmZrUAMg=; b=gR7PqKvOdaZ2PETPcICU9FtyDCN+p4zuoa1EVmoAOMJCG3HxLtMkMYuH c8WM5WGasF2YMRCNZBSw9MYu1qksvRy+jXgOJXRaftLXfkCBRuQrN7HVg DfvYxsuQBSugNHCcfi0m+Cc68XnVw7oDRwGuE8/qWIYV0kMR6wa6ft9WJ I=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: gr6POZZBnx/sUyvQ15FK3IQNdfDc3Eu7uCDYfE+ffs8kKDDX8boNs3YS5bYSieVCYmpDm1mlNU 9U3PhCN5cCpZqlM3TyR0/iLB3UMUT3vIN/uOnMJPjDhru31grI5SpnSS3YtYgcU6QN3JJhKTr9 ahye6xg8ggOoGEyNNzhSGQUom1H9HO5ybJYasUIjQKHNfccvqngawaqUsANQRXvKMStRRv79c7 fmRn+93r3D4KeKbOCgoW4YBcu+bHhJys36+R5kQasbt8PZhUqhGp69TGM7ewLOBik7C48kSEJB A7c= X-SBRS: 2.7 X-MesageID: 11674360 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674360" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:30 +0000 Message-ID: <20200117155734.1067550-4-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200117155734.1067550-1-george.dunlap@citrix.com> References: <20200117155734.1067550-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 4/8] golang/xenlight: Errors are negative 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Commit 871e51d2d4 changed the sign on the xenlight error types (making the values negative, same as the C-generated constants), but failed to flip the sign in the Error() string function. The result is that ErrorNonspecific.String() prints "libxl error: 1" rather than the human-readable error message. Get rid of the whole issue by making libxlErrors a map, and mapping actual error values to string, falling back to printing the actual value of the Error type if it's not present. Signed-off-by: George Dunlap Reviewed-by: Nick Rosbrook --- v2: - Convert libxlErrors to a map. CC: Nick Rosbrook --- tools/golang/xenlight/xenlight.go | 62 +++++++++++++++---------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 1299981713..aa1e63a61a 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -36,42 +36,40 @@ import ( "unsafe" ) -var libxlErrors = [...]string{ - -ErrorNonspecific: "Non-specific error", - -ErrorVersion: "Wrong version", - -ErrorFail: "Failed", - -ErrorNi: "Not Implemented", - -ErrorNomem: "No memory", - -ErrorInval: "Invalid argument", - -ErrorBadfail: "Bad Fail", - -ErrorGuestTimedout: "Guest timed out", - -ErrorTimedout: "Timed out", - -ErrorNoparavirt: "No Paravirtualization", - -ErrorNotReady: "Not ready", - -ErrorOseventRegFail: "OS event registration failed", - -ErrorBufferfull: "Buffer full", - -ErrorUnknownChild: "Unknown child", - -ErrorLockFail: "Lock failed", - -ErrorJsonConfigEmpty: "JSON config empty", - -ErrorDeviceExists: "Device exists", - -ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match", - -ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported", - -ErrorVnumaConfigInvalid: "VNUMA config invalid", - -ErrorDomainNotfound: "Domain not found", - -ErrorAborted: "Aborted", - -ErrorNotfound: "Not found", - -ErrorDomainDestroyed: "Domain destroyed", - -ErrorFeatureRemoved: "Feature removed", +var libxlErrors = map[Error]string{ + ErrorNonspecific: "Non-specific error", + ErrorVersion: "Wrong version", + ErrorFail: "Failed", + ErrorNi: "Not Implemented", + ErrorNomem: "No memory", + ErrorInval: "Invalid argument", + ErrorBadfail: "Bad Fail", + ErrorGuestTimedout: "Guest timed out", + ErrorTimedout: "Timed out", + ErrorNoparavirt: "No Paravirtualization", + ErrorNotReady: "Not ready", + ErrorOseventRegFail: "OS event registration failed", + ErrorBufferfull: "Buffer full", + ErrorUnknownChild: "Unknown child", + ErrorLockFail: "Lock failed", + ErrorJsonConfigEmpty: "JSON config empty", + ErrorDeviceExists: "Device exists", + ErrorCheckpointDevopsDoesNotMatch: "Checkpoint devops does not match", + ErrorCheckpointDeviceNotSupported: "Checkpoint device not supported", + ErrorVnumaConfigInvalid: "VNUMA config invalid", + ErrorDomainNotfound: "Domain not found", + ErrorAborted: "Aborted", + ErrorNotfound: "Not found", + ErrorDomainDestroyed: "Domain destroyed", + ErrorFeatureRemoved: "Feature removed", } func (e Error) Error() string { - if 0 < int(e) && int(e) < len(libxlErrors) { - s := libxlErrors[e] - if s != "" { - return s - } + if s, ok := libxlErrors[e]; ok { + return s } - return fmt.Sprintf("libxl error: %d", -e) + + return fmt.Sprintf("libxl error: %d", e) } // Context represents a libxl_ctx. From patchwork Fri Jan 17 15:57:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339501 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 87C2D13A0 for ; Fri, 17 Jan 2020 15:58:45 +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 633CF2064C for ; Fri, 17 Jan 2020 15:58:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="g5HCzbgD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 633CF2064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0O-0002Va-Bo; Fri, 17 Jan 2020 15:57: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 1isU0M-0002VR-Cm for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:57:50 +0000 X-Inumbo-ID: 17771a7c-3942-11ea-b833-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 17771a7c-3942-11ea-b833-bc764e2007e4; Fri, 17 Jan 2020 15:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rFuVzKQ9OuTB+RQgWp0Vao74hawqHb77AcRIS5OBuhM=; b=g5HCzbgDgZhJ6kyyuJqH1k8NE99XhoD1RRGmuLQrau/XYVsECq+gW7wZ A52NR6A3KKKm7CpRnOBx7ouWLUwAk19eFvs8j/mjjRXjRdpXiNGhk06lk EaO/WJDcJreMWcIE3/8MdZfxiAR6CApkaqnvUOm7knfjGwsuwf+F6jPyZ 4=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: aupfuAVvOcw9jDAAlx4vrQf8hNPGdtpvEfrVmQ/CnLt44OXAWsuCJ+v23M6gXZ8dbMPJiNSN/M 3ghCTOLh83pxP7E0RVqCZL5ISnJSI2K2G3jJyKzhGkeg6tHjV1yeYowl9aIOZHdii2cHhLTwFN vq+72Pyklk1J216Q3e1ltSsWihspeXiIMgNdqV5Jl1D382ADtl6kpK6Uea0VaGExZ5mqofoE2e FnjOcnCcgCXTH2E6zqRDpRhbaCuotA7GK3WaPFzcj68cxy1G+gp+4qv9DDQ+nZ7SxLmKLMc8Vn AhI= X-SBRS: 2.7 X-MesageID: 11674357 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674357" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:31 +0000 Message-ID: <20200117155734.1067550-5-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200117155734.1067550-1-george.dunlap@citrix.com> References: <20200117155734.1067550-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 5/8] golang/xenlight: Default loglevel to DEBUG until we get everything working 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: George Dunlap --- The other option would be to expose the XTL logging levels and let the caller set them somehow. CC: Nick Rosbrook --- tools/golang/xenlight/xenlight.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index aa1e63a61a..0e71f6ca7d 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -82,7 +82,7 @@ type Context struct { func NewContext() (*Context, error) { var ctx Context - ctx.logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_ERROR, 0) + ctx.logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_DEBUG, 0) ret := C.libxl_ctx_alloc(&ctx.ctx, C.LIBXL_VERSION, 0, (*C.xentoollog_logger)(unsafe.Pointer(ctx.logger))) From patchwork Fri Jan 17 15:57:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339507 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 302B592A for ; Fri, 17 Jan 2020 15:58:59 +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 0BCD52064C for ; Fri, 17 Jan 2020 15:58:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="QmkY0szO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0BCD52064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0c-0002aN-Eh; Fri, 17 Jan 2020 15:58:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isU0b-0002Zp-AP for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:58:05 +0000 X-Inumbo-ID: 1cd576f8-3942-11ea-b833-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1cd576f8-3942-11ea-b833-bc764e2007e4; Fri, 17 Jan 2020 15:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276670; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MBs6V8s3hLnXcrUbnYa2dDVmTmQfIxPcUoGbkPwkuxQ=; b=QmkY0szOF8p9bBki9j/rPVt0hY0bS0xpWgBYl1UeC7CaEM8JkSpvssAb iVYMhkDDMZkOeNWYWrrlgk+pbixi1fjAJtryls/2Y0LsQGmvR1UhOM52E oH3CzgUhElFvdE1y1f5tew+dewHsUb+sC6t4ZUh33wNet9gBh+ld+2M/6 Q=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: n/vSxt2PlFiwHOZLBezxBIYcQsiPgu4Hxymjdums3JbzWCfdA7wmWik4jGN5YJLiIQkL/Qcw1M xHMfuyyskw39BuI17QFDGW8bJbQ3+aOlk8+7ia+tKoK/jlyJm0A97/N50NJYQx9cvmuum9XiaT lpFItAWLhjyld+N+pd/+C3yz/HNlthj5JoX7PAzOrxs0eSjN0xLxaIWPwDkEcC938ruNAkrsl/ OXSV6dCgIEsKEcZYE416/1K66C6wSc3vaXMP11ou+aujJpdoqjI8vv4+rMNXFHMkcpVEZNW7aU rXM= X-SBRS: 2.7 X-MesageID: 11674364 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674364" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:32 +0000 Message-ID: <20200117155734.1067550-6-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200117155734.1067550-1-george.dunlap@citrix.com> References: <20200117155734.1067550-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 6/8] golang/xenlight: Don't leak memory on context open failure 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" If libxl_ctx_alloc() returns an error, we need to destroy the logger that we made. Restructure the Close() method such that it checks for each resource to be freed and then frees it. This allows Close() to be come idempotent, as well as to be a useful clean-up to a partially-created context. Signed-off-by: George Dunlap Reviewed-by: Nick Rosbrook --- CC: Nick Rosbrook --- tools/golang/xenlight/xenlight.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 0e71f6ca7d..662b266250 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -79,28 +79,40 @@ type Context struct { } // NewContext returns a new Context. -func NewContext() (*Context, error) { - var ctx Context +func NewContext() (ctx *Context, err error) { + ctx = &Context{} + + defer func() { + if err != nil { + ctx.Close() + ctx = nil + } + }() ctx.logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_DEBUG, 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, Error(ret) } - return &ctx, nil + 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 ctx.ctx != nil { + ret := C.libxl_ctx_free(ctx.ctx) + if ret != 0 { + return Error(ret) + } + ctx.ctx = nil + } - if ret != 0 { - return Error(ret) + if ctx.logger != nil { + C.xtl_logger_destroy((*C.xentoollog_logger)(unsafe.Pointer(ctx.logger))) + ctx.logger = nil } return nil From patchwork Fri Jan 17 15:57:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339509 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 16F7814B7 for ; Fri, 17 Jan 2020 15:59:05 +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 E6F912064C for ; Fri, 17 Jan 2020 15:59:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="iRHYGB9a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6F912064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0g-0002cx-QH; Fri, 17 Jan 2020 15:58:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isU0g-0002cE-An for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:58:10 +0000 X-Inumbo-ID: 1d97c410-3942-11ea-9fd7-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1d97c410-3942-11ea-9fd7-bc764e2007e4; Fri, 17 Jan 2020 15:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pxpaa2v2iad66B8kvb2k9dwGuWp9mnfKF/5hDp1VZVU=; b=iRHYGB9aQURE0woiDrk4rukAe+2ORQEKKya4iOlbqFEsVxLPkAZPvvIg abaxn3JlBdpETYwZJCnp2+Ex9Qjf1YDJZtiIrf7MyPvCj8TbBMj00nDc7 m6kN3iY1QIGFNoEE881h8R8VyGxe0pAeGwTPH3Duf2hzTV3QsWaalnXwZ w=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 73DUylGE7OTi2kjhTiwjs0kUdavzLkKjlBwWO5PulM05vsl5yAJUd1s2bn/FI+6Qi99mKSqag3 frXyY0jkxh3H6cPMWWNvNo4GuAc2l0tveOYRGu7Xwj+R3rB+JMsdKhYFSqGyT7oKK0sTsBtvjI zaSicGOfI29W4PMDFpDzceoA4pv4oJ4ye7U22C2pKHcUqDlJa/1SuqSxmq14RJI2UNsbIrDtDO EkayD3ZXZKukIUI3n50ykYzGwvA5u7xfNxyVeChHuOqFsy/TstQSopbgWKeZgx9htxKlWT3QRB MCw= X-SBRS: 2.7 X-MesageID: 11674366 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674366" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:33 +0000 Message-ID: <20200117155734.1067550-7-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200117155734.1067550-1-george.dunlap@citrix.com> References: <20200117155734.1067550-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 7/8] golang/xenlight: Notify xenlight of SIGCHLD 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" libxl forks external processes and waits for them to complete; it therefore needs to be notified when children exit. In absence of instructions to the contrary, libxl sets up its own SIGCHLD handlers. Golang always unmasks and handles SIGCHLD itself. libxl thankfully notices this and throws an assert() rather than clobbering SIGCHLD handlers. Tell libxl that we'll be responsible for getting SIGCHLD notifications to it. Arrange for a channel in the context to receive notifications on SIGCHLD, and set up a goroutine that will pass these on to libxl. NB that every libxl context needs a notification; so multiple contexts will each spin up their own goroutine when opening a context, and shut it down on close. libxl also wants to hold on to a const pointer to xenlight_childproc_hooks rather than do a copy; so make a global structure in C space and initialize it once on library creation. While here, add a few comments to make the context set-up a bit easier to follow. Signed-off-by: George Dunlap Reviewed-by: Ian Jackson --- v2: - Fix unsafe libxl_childproc_hooks pointer behavior - Close down the SIGCHLD handler first, and make sure it's exited before closing the context - Explicitly decide to have a separate goroutine per ctx NB that due to a bug in libxl, this will hang without Ian's "[PATCH v2 00/10] libxl: event: Fix hang for some applications" series. CC: Nick Rosbrook CC: Ian Jackson --- tools/golang/xenlight/xenlight.go | 72 ++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 662b266250..c462e4bb42 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -20,6 +20,8 @@ package xenlight #cgo LDFLAGS: -lxenlight -lyajl -lxentoollog #include #include + +libxl_childproc_hooks xenlight_childproc_hooks; */ import "C" @@ -33,6 +35,9 @@ import "C" import ( "fmt" + "os" + "os/signal" + "syscall" "unsafe" ) @@ -72,10 +77,49 @@ func (e Error) Error() string { return fmt.Sprintf("libxl error: %d", e) } +func init() { + // libxl for some reason wants to: + // 1. Retain a copy to this pointer as long as the context is open, and + // 2. Not free it when it's done + // + // Rather than alloc and free multiple copies, just keep a single + // static copy in the C space (since C code isn't allowed to retain pointers + // to go code), and initialize it once. + C.xenlight_childproc_hooks.chldowner = C.libxl_sigchld_owner_mainloop +} + // Context represents a libxl_ctx. type Context struct { - ctx *C.libxl_ctx - logger *C.xentoollog_logger_stdiostream + ctx *C.libxl_ctx + logger *C.xentoollog_logger_stdiostream + sigchld chan os.Signal + sigchldDone chan bool +} + +// Golang always unmasks SIGCHLD, and internally has ways of +// distributing SIGCHLD to multiple recipients. libxl has provision +// for this model: just tell it when a SIGCHLD happened, and it will +// look after its own processes. +// +// This should "play nicely" with other users of SIGCHLD as long as +// they don't reap libxl's processes. +// +// Every context needs to be notified on each SIGCHLD; so spin up a +// new goroutine for each context. If there are a large number of contexts, +// this means each context will be woken up looking through its own list of children. +// +// The alternate would be to register a fork callback, such that the +// xenlight package can make a single list of all children, and only +// notify the specific libxl context(s) that have children woken. But +// it's not clear to me this will be much more work than having the +// xenlight go library do the same thing; doing it in separate go +// threads has the potential to do it in parallel. Leave that as an +// optimization for later if it turns out to be a bottleneck. +func sigchldHandler(ctx *Context) { + for _ = range ctx.sigchld { + go C.libxl_childproc_sigchld_occurred(ctx.ctx) + } + close(ctx.sigchldDone) } // NewContext returns a new Context. @@ -89,19 +133,43 @@ func NewContext() (ctx *Context, err error) { } }() + // Create a logger ctx.logger = C.xtl_createlogger_stdiostream(C.stderr, C.XTL_DEBUG, 0) + // Allocate a context ret := C.libxl_ctx_alloc(&ctx.ctx, C.LIBXL_VERSION, 0, (*C.xentoollog_logger)(unsafe.Pointer(ctx.logger))) if ret != 0 { return ctx, Error(ret) } + // Tell libxl that we'll be dealing with SIGCHLD... + C.libxl_childproc_setmode(ctx.ctx, &C.xenlight_childproc_hooks, nil) + + // ...and arrange to keep that promise. + ctx.sigchld = make(chan os.Signal, 2) + ctx.sigchldDone = make(chan bool, 1) + signal.Notify(ctx.sigchld, syscall.SIGCHLD) + + go sigchldHandler(ctx) + return ctx, nil } // Close closes the Context. func (ctx *Context) Close() error { + // Tell our SIGCHLD notifier to shut down, and wait for it to exit + // before we free the context. + if ctx.sigchld == nil { + signal.Stop(ctx.sigchld) + close(ctx.sigchld) + + <-ctx.sigchldDone + + ctx.sigchld = nil + ctx.sigchldDone = nil + } + if ctx.ctx != nil { ret := C.libxl_ctx_free(ctx.ctx) if ret != 0 { From patchwork Fri Jan 17 15:57:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 11339511 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 55DF613A0 for ; Fri, 17 Jan 2020 15:59:12 +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 31D9B2064C for ; Fri, 17 Jan 2020 15:59:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="baalfIp+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31D9B2064C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1isU0r-0002jn-Id; Fri, 17 Jan 2020 15:58:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isU0q-0002j3-Ad for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 15:58:20 +0000 X-Inumbo-ID: 20c0987e-3942-11ea-b833-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 20c0987e-3942-11ea-b833-bc764e2007e4; Fri, 17 Jan 2020 15:57:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579276676; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AM8Xf7hx61ynSqs8IBtGz549ZAkR2Wzi3DTSNGi918Q=; b=baalfIp+TaF1I5wZ2Pj88nw5AiPDMPsw9R+l9CVSdwwH+Lje06ZuegKK 2hoAQ37IMgiS6HW4zkgVcNHGUkqt59XDNVb6Y1DSfyezGNrT0ZriZmkeM ikYJF/6vakSHozbGa67i0/qyTB2WJpqnlWHpz37vIqFG/vD1W+TMWyWY5 c=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: phDJsRD1+0pRTgV+tA2Wf07jXibt+z2i1gIbzgkboJ11U5Tzcljcv8DW41uwcNIwlAhADCL1sc U/VnphM3S3uxkHx5mOyEFPlvv2nP79uQnFCLaJHjQZeIF8BrkD4uFZgW6KnPBTtcFBn7xxn4wU INbIuxcI4KZj6ysGPpAXILDnASiLZp4OZqEj0sNpn00/lLXDykyk4TrbTQJ0sDMzU0+K3EHQ+a tw2SB9REVWkxqcc2guZrhQV9CPt4HxNUDagh68Qa++P4xTR6vgdyYEpiL5KwGDYkepoaqzJVZn Z5Q= X-SBRS: 2.7 X-MesageID: 11674368 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11674368" From: George Dunlap To: Date: Fri, 17 Jan 2020 15:57:34 +0000 Message-ID: <20200117155734.1067550-8-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200117155734.1067550-1-george.dunlap@citrix.com> References: <20200117155734.1067550-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 8/8] RFC: Sketch constructors, DomainCreateNew 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 , George Dunlap Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This is a sketch of functionality suitable for creating a basic domain, with a disk and a vif. DomainConfig, DeviceDisk, and DeviceNic types are all created using constructor functions, which initialize them with libxl's defaults. DomainCreateNew takes the config and calls without any updates. Obviously some of these will need to be changed it we switch to passing references to .toC() rather than passing back by value. The main purpose of this is to allow testing of creating a hard-coded domain. Creating a domain would look like this: // type = "pv" dconf, err := xl.NewDomainConfig(xl.DomainTypePv) if err != nil { fmt.Printf("NewDomainConfig: %v\n", err) return } dconf.CInfo.Type = xl.DomainTypePv // name = "c6-01" dconf.CInfo.Name = "c6-01" // vcpus=4 dconf.BInfo.MaxVcpus = 4 // memory = "2048" dconf.BInfo.MaxMemkb = 2048 * 1024 dconf.BInfo.TargetMemkb = 2048 * 1024 // on_crash = 'destroy' dconf.OnCrash = xl.ActionOnShutdownDestroy // bootloader = "pygrub" dconf.BInfo.Bootloader = "pygrub" // disk = [ 'vdev=hda,format=raw,target=/images/c6-01.raw'] { disk, err := xl.NewDeviceDisk() if err != nil { fmt.Printf("NewDeviceDisk: %v\n", err) return } disk.Vdev = "hda" //disk.DiskBackend = xl.DiskBackendPhy disk.Format = xl.DiskFormatRaw disk.Readwrite = 1 disk.PdevPath = "/images/c6-01.raw" dconf.Disks = append(dconf.Disks, *disk) } // vif = [ 'mac=5a:5b:d6:f1:d6:b4' ] { vif, err := xl.NewDeviceNic() if err != nil { fmt.Printf("NewDeviceNic: %v\n", err) return } vif.Mac = xl.Mac{ 0x5a, 0x5b, 0xd6, 0x31, 0xd6, 0xb4 } dconf.Nics = append(dconf.Nics, *vif) } // serial='pty' # HVM only did, err := ctx.DomainCreateNew(dconf) if err != nil { fmt.Printf("Creating domain: %v\n", err) return } fmt.Printf("Domain %s(%d) created successfully", dconf.CInfo.Name, did) Signed-off-by: George Dunlap --- CC: Nick Rosbrook --- tools/golang/xenlight/xenlight.go | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index c462e4bb42..5a21a2b9b8 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -1113,3 +1113,69 @@ func (Ctx *Context) PrimaryConsoleGetTty(domid uint32) (path string, err error) path = C.GoString(cpath) return } + +func NewDomainConfig(t DomainType) (*DomainConfig, error) { + var cconfig C.libxl_domain_config + + C.libxl_domain_config_init(&cconfig) + C.libxl_domain_build_info_init_type(&cconfig.b_info, C.libxl_domain_type(t)) + + gconfig := &DomainConfig{} + err := gconfig.fromC(&cconfig) + if err != nil { + return nil, err + } + + return gconfig, nil +} + +func NewDeviceDisk() (*DeviceDisk, error) { + var ctype C.libxl_device_disk + + C.libxl_device_disk_init(&ctype) + + gtype := &DeviceDisk{} + err := gtype.fromC(&ctype) + + if err != nil { + return nil, err + } + + return gtype, nil +} + +func NewDeviceNic() (*DeviceNic, error) { + var ctype C.libxl_device_nic + + C.libxl_device_nic_init(&ctype) + + gtype := &DeviceNic{} + err := gtype.fromC(&ctype) + + if err != nil { + return nil, err + } + + return gtype, nil +} + +// int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, +// uint32_t *domid, +// const libxl_asyncop_how *ao_how, +// const libxl_asyncprogress_how *aop_console_how) +func (Ctx *Context) DomainCreateNew(config *DomainConfig) (Domid, error) { + var cdomid C.uint32_t + var cconfig C.libxl_domain_config + err := config.toC(&cconfig) + if err != nil { + return Domid(0), fmt.Errorf("converting domain config to C: %v", err) + } + defer C.libxl_domain_config_dispose(&cconfig) + + ret := C.libxl_domain_create_new(Ctx.ctx, &cconfig, &cdomid, nil, nil) + if ret != 0 { + return Domid(0), Error(ret) + } + + return Domid(cdomid), nil +}