[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] golang/xenlight: re-track generated go code
commit ab2b8799e90cb9f3306cf2cf8e5336992240e8a3 Author: Nick Rosbrook <rosbrookn@xxxxxxxxx> AuthorDate: Tue May 12 20:58:05 2020 -0400 Commit: George Dunlap <george.dunlap@xxxxxxxxxx> CommitDate: Wed May 13 13:41:57 2020 +0100 golang/xenlight: re-track generated go code Commit df669de074c395a3b2eeb975fddd3da4c148da13 un-tracked the generated Go code, but it was decided that we actually keep the generated code in-tree. Undo the changes to ignore the generated code, and re-generate it. Signed-off-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx> Reviewed-by: George Dunlap <george.dunlap@xxxxxxxxxx> --- .gitignore | 3 - .hgignore | 2 - tools/golang/xenlight/Makefile | 1 - tools/golang/xenlight/helpers.gen.go | 4728 ++++++++++++++++++++++++++++++++++ tools/golang/xenlight/types.gen.go | 1226 +++++++++ 5 files changed, 5954 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9c8a31f896..bfa53723b3 100644 --- a/.gitignore +++ b/.gitignore @@ -406,9 +406,6 @@ tools/xenstore/xenstore-watch tools/xl/_paths.h tools/xl/xl -tools/golang/src -tools/golang/*/*.gen.go - docs/txt/misc/*.txt docs/txt/man/*.txt docs/figs/*.png diff --git a/.hgignore b/.hgignore index 2ec52982e1..2d41670632 100644 --- a/.hgignore +++ b/.hgignore @@ -282,8 +282,6 @@ ^tools/ocaml/test/xtl$ ^tools/ocaml/test/send_debug_keys$ ^tools/ocaml/test/list_domains$ -^tools/golang/src$ -^tools/golang/.*/.*\.gen\.go$ ^tools/autom4te\.cache$ ^tools/config\.h$ ^tools/config\.log$ diff --git a/tools/golang/xenlight/Makefile b/tools/golang/xenlight/Makefile index 144c133ced..753132306a 100644 --- a/tools/golang/xenlight/Makefile +++ b/tools/golang/xenlight/Makefile @@ -49,7 +49,6 @@ install: build clean: $(RM) -r $(XEN_GOPATH)$(GOXL_PKG_DIR) $(RM) $(XEN_GOPATH)/pkg/*/$(XEN_GOCODE_URL)/xenlight.a - $(RM) *.gen.go .PHONY: distclean distclean: clean diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go new file mode 100644 index 0000000000..109e9515a2 --- /dev/null +++ b/tools/golang/xenlight/helpers.gen.go @@ -0,0 +1,4728 @@ +// DO NOT EDIT. +// +// This file is generated by: +// gengotypes.py ../../libxl/libxl_types.idl +// +package xenlight + +import ( + "errors" + "fmt" + "unsafe" +) + +/* +#cgo LDFLAGS: -lxenlight +#include <stdlib.h> +#include <libxl.h> + +typedef typeof(((struct libxl_channelinfo *)NULL)->u.pty)libxl_channelinfo_connection_union_pty; +typedef typeof(((struct libxl_domain_build_info *)NULL)->u.hvm)libxl_domain_build_info_type_union_hvm; +typedef typeof(((struct libxl_domain_build_info *)NULL)->u.pv)libxl_domain_build_info_type_union_pv; +typedef typeof(((struct libxl_domain_build_info *)NULL)->u.pvh)libxl_domain_build_info_type_union_pvh; +typedef typeof(((struct libxl_device_usbdev *)NULL)->u.hostdev)libxl_device_usbdev_type_union_hostdev; +typedef typeof(((struct libxl_device_channel *)NULL)->u.socket)libxl_device_channel_connection_union_socket; +typedef typeof(((struct libxl_event *)NULL)->u.domain_shutdown)libxl_event_type_union_domain_shutdown; +typedef typeof(((struct libxl_event *)NULL)->u.disk_eject)libxl_event_type_union_disk_eject; +typedef typeof(((struct libxl_event *)NULL)->u.operation_complete)libxl_event_type_union_operation_complete; +typedef typeof(((struct libxl_psr_hw_info *)NULL)->u.cat)libxl_psr_hw_info_type_union_cat; +typedef typeof(((struct libxl_psr_hw_info *)NULL)->u.mba)libxl_psr_hw_info_type_union_mba; +*/ +import "C" + +// NewIoportRange returns an instance of IoportRange initialized with defaults. +func NewIoportRange() (*IoportRange, error) { + var ( + x IoportRange + xc C.libxl_ioport_range + ) + + C.libxl_ioport_range_init(&xc) + defer C.libxl_ioport_range_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *IoportRange) fromC(xc *C.libxl_ioport_range) error { + x.First = uint32(xc.first) + x.Number = uint32(xc.number) + + return nil +} + +func (x *IoportRange) toC(xc *C.libxl_ioport_range) (err error) { + defer func() { + if err != nil { + C.libxl_ioport_range_dispose(xc) + } + }() + + xc.first = C.uint32_t(x.First) + xc.number = C.uint32_t(x.Number) + + return nil +} + +// NewIomemRange returns an instance of IomemRange initialized with defaults. +func NewIomemRange() (*IomemRange, error) { + var ( + x IomemRange + xc C.libxl_iomem_range + ) + + C.libxl_iomem_range_init(&xc) + defer C.libxl_iomem_range_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *IomemRange) fromC(xc *C.libxl_iomem_range) error { + x.Start = uint64(xc.start) + x.Number = uint64(xc.number) + x.Gfn = uint64(xc.gfn) + + return nil +} + +func (x *IomemRange) toC(xc *C.libxl_iomem_range) (err error) { + defer func() { + if err != nil { + C.libxl_iomem_range_dispose(xc) + } + }() + + xc.start = C.uint64_t(x.Start) + xc.number = C.uint64_t(x.Number) + xc.gfn = C.uint64_t(x.Gfn) + + return nil +} + +// NewVgaInterfaceInfo returns an instance of VgaInterfaceInfo initialized with defaults. +func NewVgaInterfaceInfo() (*VgaInterfaceInfo, error) { + var ( + x VgaInterfaceInfo + xc C.libxl_vga_interface_info + ) + + C.libxl_vga_interface_info_init(&xc) + defer C.libxl_vga_interface_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *VgaInterfaceInfo) fromC(xc *C.libxl_vga_interface_info) error { + x.Kind = VgaInterfaceType(xc.kind) + + return nil +} + +func (x *VgaInterfaceInfo) toC(xc *C.libxl_vga_interface_info) (err error) { + defer func() { + if err != nil { + C.libxl_vga_interface_info_dispose(xc) + } + }() + + xc.kind = C.libxl_vga_interface_type(x.Kind) + + return nil +} + +// NewVncInfo returns an instance of VncInfo initialized with defaults. +func NewVncInfo() (*VncInfo, error) { + var ( + x VncInfo + xc C.libxl_vnc_info + ) + + C.libxl_vnc_info_init(&xc) + defer C.libxl_vnc_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *VncInfo) fromC(xc *C.libxl_vnc_info) error { + if err := x.Enable.fromC(&xc.enable); err != nil { + 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 fmt.Errorf("converting field Findunused: %v", err) + } + + return nil +} + +func (x *VncInfo) toC(xc *C.libxl_vnc_info) (err error) { + defer func() { + if err != nil { + C.libxl_vnc_info_dispose(xc) + } + }() + + if err := x.Enable.toC(&xc.enable); err != nil { + return fmt.Errorf("converting field Enable: %v", err) + } + if x.Listen != "" { + xc.listen = C.CString(x.Listen) + } + if x.Passwd != "" { + xc.passwd = C.CString(x.Passwd) + } + xc.display = C.int(x.Display) + if err := x.Findunused.toC(&xc.findunused); err != nil { + return fmt.Errorf("converting field Findunused: %v", err) + } + + return nil +} + +// NewSpiceInfo returns an instance of SpiceInfo initialized with defaults. +func NewSpiceInfo() (*SpiceInfo, error) { + var ( + x SpiceInfo + xc C.libxl_spice_info + ) + + C.libxl_spice_info_init(&xc) + defer C.libxl_spice_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *SpiceInfo) fromC(xc *C.libxl_spice_info) error { + if err := x.Enable.fromC(&xc.enable); err != nil { + 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 fmt.Errorf("converting field DisableTicketing: %v", err) + } + x.Passwd = C.GoString(xc.passwd) + if err := x.AgentMouse.fromC(&xc.agent_mouse); err != nil { + return fmt.Errorf("converting field AgentMouse: %v", err) + } + if err := x.Vdagent.fromC(&xc.vdagent); err != nil { + return fmt.Errorf("converting field Vdagent: %v", err) + } + if err := x.ClipboardSharing.fromC(&xc.clipboard_sharing); err != nil { + return fmt.Errorf("converting field ClipboardSharing: %v", err) + } + x.Usbredirection = int(xc.usbredirection) + x.ImageCompression = C.GoString(xc.image_compression) + x.StreamingVideo = C.GoString(xc.streaming_video) + + return nil +} + +func (x *SpiceInfo) toC(xc *C.libxl_spice_info) (err error) { + defer func() { + if err != nil { + C.libxl_spice_info_dispose(xc) + } + }() + + if err := x.Enable.toC(&xc.enable); err != nil { + return fmt.Errorf("converting field Enable: %v", err) + } + xc.port = C.int(x.Port) + xc.tls_port = C.int(x.TlsPort) + if x.Host != "" { + xc.host = C.CString(x.Host) + } + if err := x.DisableTicketing.toC(&xc.disable_ticketing); err != nil { + 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 fmt.Errorf("converting field AgentMouse: %v", err) + } + if err := x.Vdagent.toC(&xc.vdagent); err != nil { + return fmt.Errorf("converting field Vdagent: %v", err) + } + if err := x.ClipboardSharing.toC(&xc.clipboard_sharing); err != nil { + return fmt.Errorf("converting field ClipboardSharing: %v", err) + } + xc.usbredirection = C.int(x.Usbredirection) + if x.ImageCompression != "" { + xc.image_compression = C.CString(x.ImageCompression) + } + if x.StreamingVideo != "" { + xc.streaming_video = C.CString(x.StreamingVideo) + } + + return nil +} + +// NewSdlInfo returns an instance of SdlInfo initialized with defaults. +func NewSdlInfo() (*SdlInfo, error) { + var ( + x SdlInfo + xc C.libxl_sdl_info + ) + + C.libxl_sdl_info_init(&xc) + defer C.libxl_sdl_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *SdlInfo) fromC(xc *C.libxl_sdl_info) error { + if err := x.Enable.fromC(&xc.enable); err != nil { + return fmt.Errorf("converting field Enable: %v", err) + } + if err := x.Opengl.fromC(&xc.opengl); err != nil { + return fmt.Errorf("converting field Opengl: %v", err) + } + x.Display = C.GoString(xc.display) + x.Xauthority = C.GoString(xc.xauthority) + + return nil +} + +func (x *SdlInfo) toC(xc *C.libxl_sdl_info) (err error) { + defer func() { + if err != nil { + C.libxl_sdl_info_dispose(xc) + } + }() + + if err := x.Enable.toC(&xc.enable); err != nil { + return fmt.Errorf("converting field Enable: %v", err) + } + if err := x.Opengl.toC(&xc.opengl); err != nil { + return fmt.Errorf("converting field Opengl: %v", err) + } + if x.Display != "" { + xc.display = C.CString(x.Display) + } + if x.Xauthority != "" { + xc.xauthority = C.CString(x.Xauthority) + } + + return nil +} + +// NewDominfo returns an instance of Dominfo initialized with defaults. +func NewDominfo() (*Dominfo, error) { + var ( + x Dominfo + xc C.libxl_dominfo + ) + + C.libxl_dominfo_init(&xc) + defer C.libxl_dominfo_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *Dominfo) fromC(xc *C.libxl_dominfo) error { + if err := x.Uuid.fromC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + x.Domid = Domid(xc.domid) + x.Ssidref = uint32(xc.ssidref) + x.SsidLabel = C.GoString(xc.ssid_label) + x.Running = bool(xc.running) + x.Blocked = bool(xc.blocked) + x.Paused = bool(xc.paused) + x.Shutdown = bool(xc.shutdown) + x.Dying = bool(xc.dying) + x.NeverStop = bool(xc.never_stop) + x.ShutdownReason = ShutdownReason(xc.shutdown_reason) + x.OutstandingMemkb = uint64(xc.outstanding_memkb) + x.CurrentMemkb = uint64(xc.current_memkb) + x.SharedMemkb = uint64(xc.shared_memkb) + x.PagedMemkb = uint64(xc.paged_memkb) + x.MaxMemkb = uint64(xc.max_memkb) + x.CpuTime = uint64(xc.cpu_time) + x.VcpuMaxId = uint32(xc.vcpu_max_id) + x.VcpuOnline = uint32(xc.vcpu_online) + x.Cpupool = uint32(xc.cpupool) + x.DomainType = DomainType(xc.domain_type) + + return nil +} + +func (x *Dominfo) toC(xc *C.libxl_dominfo) (err error) { + defer func() { + if err != nil { + C.libxl_dominfo_dispose(xc) + } + }() + + if err := x.Uuid.toC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + xc.domid = C.libxl_domid(x.Domid) + xc.ssidref = C.uint32_t(x.Ssidref) + if x.SsidLabel != "" { + xc.ssid_label = C.CString(x.SsidLabel) + } + xc.running = C.bool(x.Running) + xc.blocked = C.bool(x.Blocked) + xc.paused = C.bool(x.Paused) + xc.shutdown = C.bool(x.Shutdown) + xc.dying = C.bool(x.Dying) + xc.never_stop = C.bool(x.NeverStop) + xc.shutdown_reason = C.libxl_shutdown_reason(x.ShutdownReason) + xc.outstanding_memkb = C.uint64_t(x.OutstandingMemkb) + xc.current_memkb = C.uint64_t(x.CurrentMemkb) + xc.shared_memkb = C.uint64_t(x.SharedMemkb) + xc.paged_memkb = C.uint64_t(x.PagedMemkb) + xc.max_memkb = C.uint64_t(x.MaxMemkb) + xc.cpu_time = C.uint64_t(x.CpuTime) + xc.vcpu_max_id = C.uint32_t(x.VcpuMaxId) + xc.vcpu_online = C.uint32_t(x.VcpuOnline) + xc.cpupool = C.uint32_t(x.Cpupool) + xc.domain_type = C.libxl_domain_type(x.DomainType) + + return nil +} + +// NewCpupoolinfo returns an instance of Cpupoolinfo initialized with defaults. +func NewCpupoolinfo() (*Cpupoolinfo, error) { + var ( + x Cpupoolinfo + xc C.libxl_cpupoolinfo + ) + + C.libxl_cpupoolinfo_init(&xc) + defer C.libxl_cpupoolinfo_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *Cpupoolinfo) fromC(xc *C.libxl_cpupoolinfo) error { + x.Poolid = uint32(xc.poolid) + x.PoolName = C.GoString(xc.pool_name) + x.Sched = Scheduler(xc.sched) + x.NDom = uint32(xc.n_dom) + if err := x.Cpumap.fromC(&xc.cpumap); err != nil { + return fmt.Errorf("converting field Cpumap: %v", err) + } + + return nil +} + +func (x *Cpupoolinfo) toC(xc *C.libxl_cpupoolinfo) (err error) { + defer func() { + if err != nil { + C.libxl_cpupoolinfo_dispose(xc) + } + }() + + xc.poolid = C.uint32_t(x.Poolid) + if x.PoolName != "" { + xc.pool_name = C.CString(x.PoolName) + } + 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 fmt.Errorf("converting field Cpumap: %v", err) + } + + return nil +} + +// NewChannelinfo returns an instance of Channelinfo initialized with defaults. +func NewChannelinfo(connection ChannelConnection) (*Channelinfo, error) { + var ( + x Channelinfo + xc C.libxl_channelinfo + ) + + C.libxl_channelinfo_init(&xc) + C.libxl_channelinfo_init_connection(&xc, C.libxl_channel_connection(connection)) + defer C.libxl_channelinfo_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *Channelinfo) fromC(xc *C.libxl_channelinfo) error { + x.Backend = C.GoString(xc.backend) + x.BackendId = uint32(xc.backend_id) + x.Frontend = C.GoString(xc.frontend) + x.FrontendId = uint32(xc.frontend_id) + x.Devid = Devid(xc.devid) + x.State = int(xc.state) + x.Evtch = int(xc.evtch) + x.Rref = int(xc.rref) + x.Connection = ChannelConnection(xc.connection) + switch x.Connection { + case ChannelConnectionUnknown: + x.ConnectionUnion = nil + case ChannelConnectionPty: + var connectionPty ChannelinfoConnectionUnionPty + if err := connectionPty.fromC(xc); err != nil { + return fmt.Errorf("converting field connectionPty: %v", err) + } + x.ConnectionUnion = connectionPty + case ChannelConnectionSocket: + x.ConnectionUnion = nil + default: + return fmt.Errorf("invalid union key '%v'", x.Connection) + } + + return nil +} + +func (x *ChannelinfoConnectionUnionPty) fromC(xc *C.libxl_channelinfo) error { + if ChannelConnection(xc.connection) != ChannelConnectionPty { + return errors.New("expected union key ChannelConnectionPty") + } + + tmp := (*C.libxl_channelinfo_connection_union_pty)(unsafe.Pointer(&xc.u[0])) + x.Path = C.GoString(tmp.path) + return nil +} + +func (x *Channelinfo) toC(xc *C.libxl_channelinfo) (err error) { + defer func() { + if err != nil { + C.libxl_channelinfo_dispose(xc) + } + }() + + if x.Backend != "" { + xc.backend = C.CString(x.Backend) + } + xc.backend_id = C.uint32_t(x.BackendId) + if x.Frontend != "" { + xc.frontend = C.CString(x.Frontend) + } + xc.frontend_id = C.uint32_t(x.FrontendId) + xc.devid = C.libxl_devid(x.Devid) + xc.state = C.int(x.State) + xc.evtch = C.int(x.Evtch) + xc.rref = C.int(x.Rref) + xc.connection = C.libxl_channel_connection(x.Connection) + switch x.Connection { + case ChannelConnectionUnknown: + break + case ChannelConnectionPty: + tmp, ok := x.ConnectionUnion.(ChannelinfoConnectionUnionPty) + if !ok { + return errors.New("wrong type for union key connection") + } + var pty C.libxl_channelinfo_connection_union_pty + if tmp.Path != "" { + pty.path = C.CString(tmp.Path) + } + ptyBytes := C.GoBytes(unsafe.Pointer(&pty), C.sizeof_libxl_channelinfo_connection_union_pty) + copy(xc.u[:], ptyBytes) + case ChannelConnectionSocket: + break + default: + return fmt.Errorf("invalid union key '%v'", x.Connection) + } + + return nil +} + +// NewVminfo returns an instance of Vminfo initialized with defaults. +func NewVminfo() (*Vminfo, error) { + var ( + x Vminfo + xc C.libxl_vminfo + ) + + C.libxl_vminfo_init(&xc) + defer C.libxl_vminfo_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *Vminfo) fromC(xc *C.libxl_vminfo) error { + if err := x.Uuid.fromC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + x.Domid = Domid(xc.domid) + + return nil +} + +func (x *Vminfo) toC(xc *C.libxl_vminfo) (err error) { + defer func() { + if err != nil { + C.libxl_vminfo_dispose(xc) + } + }() + + if err := x.Uuid.toC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + xc.domid = C.libxl_domid(x.Domid) + + return nil +} + +// NewVersionInfo returns an instance of VersionInfo initialized with defaults. +func NewVersionInfo() (*VersionInfo, error) { + var ( + x VersionInfo + xc C.libxl_version_info + ) + + C.libxl_version_info_init(&xc) + defer C.libxl_version_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *VersionInfo) fromC(xc *C.libxl_version_info) error { + x.XenVersionMajor = int(xc.xen_version_major) + x.XenVersionMinor = int(xc.xen_version_minor) + x.XenVersionExtra = C.GoString(xc.xen_version_extra) + x.Compiler = C.GoString(xc.compiler) + x.CompileBy = C.GoString(xc.compile_by) + x.CompileDomain = C.GoString(xc.compile_domain) + x.CompileDate = C.GoString(xc.compile_date) + x.Capabilities = C.GoString(xc.capabilities) + x.Changeset = C.GoString(xc.changeset) + x.VirtStart = uint64(xc.virt_start) + x.Pagesize = int(xc.pagesize) + x.Commandline = C.GoString(xc.commandline) + x.BuildId = C.GoString(xc.build_id) + + return nil +} + +func (x *VersionInfo) toC(xc *C.libxl_version_info) (err error) { + defer func() { + if err != nil { + C.libxl_version_info_dispose(xc) + } + }() + + xc.xen_version_major = C.int(x.XenVersionMajor) + xc.xen_version_minor = C.int(x.XenVersionMinor) + if x.XenVersionExtra != "" { + xc.xen_version_extra = C.CString(x.XenVersionExtra) + } + if x.Compiler != "" { + xc.compiler = C.CString(x.Compiler) + } + if x.CompileBy != "" { + xc.compile_by = C.CString(x.CompileBy) + } + if x.CompileDomain != "" { + xc.compile_domain = C.CString(x.CompileDomain) + } + if x.CompileDate != "" { + xc.compile_date = C.CString(x.CompileDate) + } + if x.Capabilities != "" { + xc.capabilities = C.CString(x.Capabilities) + } + if x.Changeset != "" { + xc.changeset = C.CString(x.Changeset) + } + xc.virt_start = C.uint64_t(x.VirtStart) + xc.pagesize = C.int(x.Pagesize) + if x.Commandline != "" { + xc.commandline = C.CString(x.Commandline) + } + if x.BuildId != "" { + xc.build_id = C.CString(x.BuildId) + } + + return nil +} + +// NewDomainCreateInfo returns an instance of DomainCreateInfo initialized with defaults. +func NewDomainCreateInfo() (*DomainCreateInfo, error) { + var ( + x DomainCreateInfo + xc C.libxl_domain_create_info + ) + + C.libxl_domain_create_info_init(&xc) + defer C.libxl_domain_create_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DomainCreateInfo) fromC(xc *C.libxl_domain_create_info) error { + x.Type = DomainType(xc._type) + if err := x.Hap.fromC(&xc.hap); err != nil { + return fmt.Errorf("converting field Hap: %v", err) + } + if err := x.Oos.fromC(&xc.oos); err != nil { + 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) + x.Domid = Domid(xc.domid) + if err := x.Uuid.fromC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + if err := x.Xsdata.fromC(&xc.xsdata); err != nil { + return fmt.Errorf("converting field Xsdata: %v", err) + } + if err := x.Platformdata.fromC(&xc.platformdata); err != nil { + 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 fmt.Errorf("converting field RunHotplugScripts: %v", err) + } + if err := x.DriverDomain.fromC(&xc.driver_domain); err != nil { + return fmt.Errorf("converting field DriverDomain: %v", err) + } + x.Passthrough = Passthrough(xc.passthrough) + if err := x.XendSuspendEvtchnCompat.fromC(&xc.xend_suspend_evtchn_compat); err != nil { + return fmt.Errorf("converting field XendSuspendEvtchnCompat: %v", err) + } + + return nil +} + +func (x *DomainCreateInfo) toC(xc *C.libxl_domain_create_info) (err error) { + defer func() { + if err != nil { + C.libxl_domain_create_info_dispose(xc) + } + }() + + xc._type = C.libxl_domain_type(x.Type) + if err := x.Hap.toC(&xc.hap); err != nil { + return fmt.Errorf("converting field Hap: %v", err) + } + if err := x.Oos.toC(&xc.oos); err != nil { + return fmt.Errorf("converting field Oos: %v", err) + } + xc.ssidref = C.uint32_t(x.Ssidref) + if x.SsidLabel != "" { + xc.ssid_label = C.CString(x.SsidLabel) + } + if x.Name != "" { + xc.name = C.CString(x.Name) + } + xc.domid = C.libxl_domid(x.Domid) + if err := x.Uuid.toC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + if err := x.Xsdata.toC(&xc.xsdata); err != nil { + return fmt.Errorf("converting field Xsdata: %v", err) + } + if err := x.Platformdata.toC(&xc.platformdata); err != nil { + 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 fmt.Errorf("converting field RunHotplugScripts: %v", err) + } + if err := x.DriverDomain.toC(&xc.driver_domain); err != nil { + return fmt.Errorf("converting field DriverDomain: %v", err) + } + xc.passthrough = C.libxl_passthrough(x.Passthrough) + if err := x.XendSuspendEvtchnCompat.toC(&xc.xend_suspend_evtchn_compat); err != nil { + return fmt.Errorf("converting field XendSuspendEvtchnCompat: %v", err) + } + + return nil +} + +// NewDomainRestoreParams returns an instance of DomainRestoreParams initialized with defaults. +func NewDomainRestoreParams() (*DomainRestoreParams, error) { + var ( + x DomainRestoreParams + xc C.libxl_domain_restore_params + ) + + C.libxl_domain_restore_params_init(&xc) + defer C.libxl_domain_restore_params_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DomainRestoreParams) fromC(xc *C.libxl_domain_restore_params) error { + x.CheckpointedStream = int(xc.checkpointed_stream) + 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 fmt.Errorf("converting field UserspaceColoProxy: %v", err) + } + + return nil +} + +func (x *DomainRestoreParams) toC(xc *C.libxl_domain_restore_params) (err error) { + defer func() { + if err != nil { + C.libxl_domain_restore_params_dispose(xc) + } + }() + + xc.checkpointed_stream = C.int(x.CheckpointedStream) + xc.stream_version = C.uint32_t(x.StreamVersion) + if x.ColoProxyScript != "" { + xc.colo_proxy_script = C.CString(x.ColoProxyScript) + } + if err := x.UserspaceColoProxy.toC(&xc.userspace_colo_proxy); err != nil { + return fmt.Errorf("converting field UserspaceColoProxy: %v", err) + } + + return nil +} + +// NewSchedParams returns an instance of SchedParams initialized with defaults. +func NewSchedParams() (*SchedParams, error) { + var ( + x SchedParams + xc C.libxl_sched_params + ) + + C.libxl_sched_params_init(&xc) + defer C.libxl_sched_params_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *SchedParams) fromC(xc *C.libxl_sched_params) error { + x.Vcpuid = int(xc.vcpuid) + x.Weight = int(xc.weight) + x.Cap = int(xc.cap) + x.Period = int(xc.period) + x.Extratime = int(xc.extratime) + x.Budget = int(xc.budget) + + return nil +} + +func (x *SchedParams) toC(xc *C.libxl_sched_params) (err error) { + defer func() { + if err != nil { + C.libxl_sched_params_dispose(xc) + } + }() + + xc.vcpuid = C.int(x.Vcpuid) + xc.weight = C.int(x.Weight) + xc.cap = C.int(x.Cap) + xc.period = C.int(x.Period) + xc.extratime = C.int(x.Extratime) + xc.budget = C.int(x.Budget) + + return nil +} + +// NewVcpuSchedParams returns an instance of VcpuSchedParams initialized with defaults. +func NewVcpuSchedParams() (*VcpuSchedParams, error) { + var ( + x VcpuSchedParams + xc C.libxl_vcpu_sched_params + ) + + C.libxl_vcpu_sched_params_init(&xc) + defer C.libxl_vcpu_sched_params_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { + x.Sched = Scheduler(xc.sched) + x.Vcpus = nil + if n := int(xc.num_vcpus); n > 0 { + cVcpus := (*[1 << 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:n:n] + x.Vcpus = make([]SchedParams, n) + for i, v := range cVcpus { + if err := x.Vcpus[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Vcpus: %v", err) + } + } + } + + return nil +} + +func (x *VcpuSchedParams) toC(xc *C.libxl_vcpu_sched_params) (err error) { + defer func() { + if err != nil { + C.libxl_vcpu_sched_params_dispose(xc) + } + }() + + xc.sched = C.libxl_scheduler(x.Sched) + if numVcpus := len(x.Vcpus); numVcpus > 0 { + xc.vcpus = (*C.libxl_sched_params)(C.malloc(C.ulong(numVcpus) * C.sizeof_libxl_sched_params)) + xc.num_vcpus = C.int(numVcpus) + cVcpus := (*[1 << 28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:numVcpus:numVcpus] + for i, v := range x.Vcpus { + if err := v.toC(&cVcpus[i]); err != nil { + return fmt.Errorf("converting field Vcpus: %v", err) + } + } + } + + return nil +} + +// NewDomainSchedParams returns an instance of DomainSchedParams initialized with defaults. +func NewDomainSchedParams() (*DomainSchedParams, error) { + var ( + x DomainSchedParams + xc C.libxl_domain_sched_params + ) + + C.libxl_domain_sched_params_init(&xc) + defer C.libxl_domain_sched_params_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DomainSchedParams) fromC(xc *C.libxl_domain_sched_params) error { + x.Sched = Scheduler(xc.sched) + x.Weight = int(xc.weight) + x.Cap = int(xc.cap) + x.Period = int(xc.period) + x.Budget = int(xc.budget) + x.Extratime = int(xc.extratime) + x.Slice = int(xc.slice) + x.Latency = int(xc.latency) + + return nil +} + +func (x *DomainSchedParams) toC(xc *C.libxl_domain_sched_params) (err error) { + defer func() { + if err != nil { + C.libxl_domain_sched_params_dispose(xc) + } + }() + + xc.sched = C.libxl_scheduler(x.Sched) + xc.weight = C.int(x.Weight) + xc.cap = C.int(x.Cap) + xc.period = C.int(x.Period) + xc.budget = C.int(x.Budget) + xc.extratime = C.int(x.Extratime) + xc.slice = C.int(x.Slice) + xc.latency = C.int(x.Latency) + + return nil +} + +// NewVnodeInfo returns an instance of VnodeInfo initialized with defaults. +func NewVnodeInfo() (*VnodeInfo, error) { + var ( + x VnodeInfo + xc C.libxl_vnode_info + ) + + C.libxl_vnode_info_init(&xc) + defer C.libxl_vnode_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { + x.Memkb = uint64(xc.memkb) + x.Distances = nil + if n := int(xc.num_distances); n > 0 { + cDistances := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.distances))[:n:n] + x.Distances = make([]uint32, n) + for i, v := range cDistances { + x.Distances[i] = uint32(v) + } + } + x.Pnode = uint32(xc.pnode) + if err := x.Vcpus.fromC(&xc.vcpus); err != nil { + return fmt.Errorf("converting field Vcpus: %v", err) + } + + return nil +} + +func (x *VnodeInfo) toC(xc *C.libxl_vnode_info) (err error) { + defer func() { + if err != nil { + C.libxl_vnode_info_dispose(xc) + } + }() + + xc.memkb = C.uint64_t(x.Memkb) + if numDistances := len(x.Distances); numDistances > 0 { + xc.distances = (*C.uint32_t)(C.malloc(C.size_t(numDistances * numDistances))) + xc.num_distances = C.int(numDistances) + cDistances := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.distances))[:numDistances:numDistances] + for i, v := range x.Distances { + cDistances[i] = C.uint32_t(v) + } + } + xc.pnode = C.uint32_t(x.Pnode) + if err := x.Vcpus.toC(&xc.vcpus); err != nil { + return fmt.Errorf("converting field Vcpus: %v", err) + } + + return nil +} + +// NewRdmReserve returns an instance of RdmReserve initialized with defaults. +func NewRdmReserve() (*RdmReserve, error) { + var ( + x RdmReserve + xc C.libxl_rdm_reserve + ) + + C.libxl_rdm_reserve_init(&xc) + defer C.libxl_rdm_reserve_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *RdmReserve) fromC(xc *C.libxl_rdm_reserve) error { + x.Strategy = RdmReserveStrategy(xc.strategy) + x.Policy = RdmReservePolicy(xc.policy) + + return nil +} + +func (x *RdmReserve) toC(xc *C.libxl_rdm_reserve) (err error) { + defer func() { + if err != nil { + C.libxl_rdm_reserve_dispose(xc) + } + }() + + xc.strategy = C.libxl_rdm_reserve_strategy(x.Strategy) + xc.policy = C.libxl_rdm_reserve_policy(x.Policy) + + return nil +} + +// NewDomainBuildInfo returns an instance of DomainBuildInfo initialized with defaults. +func NewDomainBuildInfo(dtype DomainType) (*DomainBuildInfo, error) { + var ( + x DomainBuildInfo + xc C.libxl_domain_build_info + ) + + C.libxl_domain_build_info_init(&xc) + C.libxl_domain_build_info_init_type(&xc, C.libxl_domain_type(dtype)) + defer C.libxl_domain_build_info_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { + x.MaxVcpus = int(xc.max_vcpus) + if err := x.AvailVcpus.fromC(&xc.avail_vcpus); err != nil { + return fmt.Errorf("converting field AvailVcpus: %v", err) + } + if err := x.Cpumap.fromC(&xc.cpumap); err != nil { + return fmt.Errorf("converting field Cpumap: %v", err) + } + if err := x.Nodemap.fromC(&xc.nodemap); err != nil { + return fmt.Errorf("converting field Nodemap: %v", err) + } + x.VcpuHardAffinity = nil + if n := int(xc.num_vcpu_hard_affinity); n > 0 { + cVcpuHardAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:n:n] + x.VcpuHardAffinity = make([]Bitmap, n) + for i, v := range cVcpuHardAffinity { + if err := x.VcpuHardAffinity[i].fromC(&v); err != nil { + return fmt.Errorf("converting field VcpuHardAffinity: %v", err) + } + } + } + x.VcpuSoftAffinity = nil + if n := int(xc.num_vcpu_soft_affinity); n > 0 { + cVcpuSoftAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:n:n] + x.VcpuSoftAffinity = make([]Bitmap, n) + for i, v := range cVcpuSoftAffinity { + if err := x.VcpuSoftAffinity[i].fromC(&v); err != nil { + return fmt.Errorf("converting field VcpuSoftAffinity: %v", err) + } + } + } + if err := x.NumaPlacement.fromC(&xc.numa_placement); err != nil { + return fmt.Errorf("converting field NumaPlacement: %v", err) + } + x.TscMode = TscMode(xc.tsc_mode) + x.MaxMemkb = uint64(xc.max_memkb) + x.TargetMemkb = uint64(xc.target_memkb) + x.VideoMemkb = uint64(xc.video_memkb) + x.ShadowMemkb = uint64(xc.shadow_memkb) + x.IommuMemkb = uint64(xc.iommu_memkb) + x.RtcTimeoffset = uint32(xc.rtc_timeoffset) + x.ExecSsidref = uint32(xc.exec_ssidref) + x.ExecSsidLabel = C.GoString(xc.exec_ssid_label) + if err := x.Localtime.fromC(&xc.localtime); err != nil { + return fmt.Errorf("converting field Localtime: %v", err) + } + if err := x.DisableMigrate.fromC(&xc.disable_migrate); err != nil { + return fmt.Errorf("converting field DisableMigrate: %v", err) + } + if err := x.Cpuid.fromC(&xc.cpuid); err != nil { + return fmt.Errorf("converting field Cpuid: %v", err) + } + x.BlkdevStart = C.GoString(xc.blkdev_start) + x.VnumaNodes = nil + if n := int(xc.num_vnuma_nodes); n > 0 { + cVnumaNodes := (*[1 << 28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:n:n] + x.VnumaNodes = make([]VnodeInfo, n) + for i, v := range cVnumaNodes { + if err := x.VnumaNodes[i].fromC(&v); err != nil { + return fmt.Errorf("converting field VnumaNodes: %v", err) + } + } + } + x.MaxGrantFrames = uint32(xc.max_grant_frames) + 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 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 fmt.Errorf("converting field Extra: %v", err) + } + if err := x.ExtraPv.fromC(&xc.extra_pv); err != nil { + return fmt.Errorf("converting field ExtraPv: %v", err) + } + if err := x.ExtraHvm.fromC(&xc.extra_hvm); err != nil { + return fmt.Errorf("converting field ExtraHvm: %v", err) + } + if err := x.SchedParams.fromC(&xc.sched_params); err != nil { + return fmt.Errorf("converting field SchedParams: %v", err) + } + x.Ioports = nil + if n := int(xc.num_ioports); n > 0 { + cIoports := (*[1 << 28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:n:n] + x.Ioports = make([]IoportRange, n) + for i, v := range cIoports { + if err := x.Ioports[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Ioports: %v", err) + } + } + } + x.Irqs = nil + if n := int(xc.num_irqs); n > 0 { + cIrqs := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:n:n] + x.Irqs = make([]uint32, n) + for i, v := range cIrqs { + x.Irqs[i] = uint32(v) + } + } + x.Iomem = nil + if n := int(xc.num_iomem); n > 0 { + cIomem := (*[1 << 28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:n:n] + x.Iomem = make([]IomemRange, n) + for i, v := range cIomem { + if err := x.Iomem[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Iomem: %v", err) + } + } + } + if err := x.ClaimMode.fromC(&xc.claim_mode); err != nil { + return fmt.Errorf("converting field ClaimMode: %v", err) + } + x.EventChannels = uint32(xc.event_channels) + x.Kernel = C.GoString(xc.kernel) + x.Cmdline = C.GoString(xc.cmdline) + x.Ramdisk = C.GoString(xc.ramdisk) + x.DeviceTree = C.GoString(xc.device_tree) + if err := x.Acpi.fromC(&xc.acpi); err != nil { + 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 fmt.Errorf("converting field BootloaderArgs: %v", err) + } + x.TimerMode = TimerMode(xc.timer_mode) + if err := x.NestedHvm.fromC(&xc.nested_hvm); err != nil { + return fmt.Errorf("converting field NestedHvm: %v", err) + } + if err := x.Apic.fromC(&xc.apic); err != nil { + return fmt.Errorf("converting field Apic: %v", err) + } + if err := x.DmRestrict.fromC(&xc.dm_restrict); err != nil { + return fmt.Errorf("converting field DmRestrict: %v", err) + } + x.Tee = TeeType(xc.tee) + x.Type = DomainType(xc._type) + switch x.Type { + case DomainTypeHvm: + var typeHvm DomainBuildInfoTypeUnionHvm + if err := typeHvm.fromC(xc); err != nil { + return fmt.Errorf("converting field typeHvm: %v", err) + } + x.TypeUnion = typeHvm + case DomainTypePv: + var typePv DomainBuildInfoTypeUnionPv + if err := typePv.fromC(xc); err != nil { + return fmt.Errorf("converting field typePv: %v", err) + } + x.TypeUnion = typePv + case DomainTypePvh: + var typePvh DomainBuildInfoTypeUnionPvh + if err := typePvh.fromC(xc); err != nil { + return fmt.Errorf("converting field typePvh: %v", err) + } + x.TypeUnion = typePvh + case DomainTypeInvalid: + x.TypeUnion = nil + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } + x.ArchArm.GicVersion = GicVersion(xc.arch_arm.gic_version) + x.ArchArm.Vuart = VuartType(xc.arch_arm.vuart) + x.Altp2M = Altp2MMode(xc.altp2m) + + return nil +} + +func (x *DomainBuildInfoTypeUnionHvm) fromC(xc *C.libxl_domain_build_info) error { + if DomainType(xc._type) != DomainTypeHvm { + return errors.New("expected union key DomainTypeHvm") + } + + tmp := (*C.libxl_domain_build_info_type_union_hvm)(unsafe.Pointer(&xc.u[0])) + x.Firmware = C.GoString(tmp.firmware) + x.Bios = BiosType(tmp.bios) + if err := x.Pae.fromC(&tmp.pae); err != nil { + return fmt.Errorf("converting field Pae: %v", err) + } + if err := x.Apic.fromC(&tmp.apic); err != nil { + return fmt.Errorf("converting field Apic: %v", err) + } + if err := x.Acpi.fromC(&tmp.acpi); err != nil { + return fmt.Errorf("converting field Acpi: %v", err) + } + if err := x.AcpiS3.fromC(&tmp.acpi_s3); err != nil { + return fmt.Errorf("converting field AcpiS3: %v", err) + } + if err := x.AcpiS4.fromC(&tmp.acpi_s4); err != nil { + return fmt.Errorf("converting field AcpiS4: %v", err) + } + if err := x.AcpiLaptopSlate.fromC(&tmp.acpi_laptop_slate); err != nil { + return fmt.Errorf("converting field AcpiLaptopSlate: %v", err) + } + if err := x.Nx.fromC(&tmp.nx); err != nil { + return fmt.Errorf("converting field Nx: %v", err) + } + if err := x.Viridian.fromC(&tmp.viridian); err != nil { + return fmt.Errorf("converting field Viridian: %v", err) + } + if err := x.ViridianEnable.fromC(&tmp.viridian_enable); err != nil { + return fmt.Errorf("converting field ViridianEnable: %v", err) + } + if err := x.ViridianDisable.fromC(&tmp.viridian_disable); err != nil { + return fmt.Errorf("converting field ViridianDisable: %v", err) + } + x.Timeoffset = C.GoString(tmp.timeoffset) + if err := x.Hpet.fromC(&tmp.hpet); err != nil { + return fmt.Errorf("converting field Hpet: %v", err) + } + if err := x.VptAlign.fromC(&tmp.vpt_align); err != nil { + 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 fmt.Errorf("converting field NestedHvm: %v", err) + } + if err := x.Altp2M.fromC(&tmp.altp2m); err != nil { + 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 fmt.Errorf("converting field Nographic: %v", err) + } + if err := x.Vga.fromC(&tmp.vga); err != nil { + return fmt.Errorf("converting field Vga: %v", err) + } + if err := x.Vnc.fromC(&tmp.vnc); err != nil { + return fmt.Errorf("converting field Vnc: %v", err) + } + x.Keymap = C.GoString(tmp.keymap) + if err := x.Sdl.fromC(&tmp.sdl); err != nil { + return fmt.Errorf("converting field Sdl: %v", err) + } + if err := x.Spice.fromC(&tmp.spice); err != nil { + return fmt.Errorf("converting field Spice: %v", err) + } + if err := x.GfxPassthru.fromC(&tmp.gfx_passthru); err != nil { + 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 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 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 fmt.Errorf("converting field XenPlatformPci: %v", err) + } + if err := x.UsbdeviceList.fromC(&tmp.usbdevice_list); err != nil { + 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 fmt.Errorf("converting field MsVmGenid: %v", err) + } + if err := x.SerialList.fromC(&tmp.serial_list); err != nil { + return fmt.Errorf("converting field SerialList: %v", err) + } + if err := x.Rdm.fromC(&tmp.rdm); err != nil { + return fmt.Errorf("converting field Rdm: %v", err) + } + x.RdmMemBoundaryMemkb = uint64(tmp.rdm_mem_boundary_memkb) + x.McaCaps = uint64(tmp.mca_caps) + return nil +} + +func (x *DomainBuildInfoTypeUnionPv) fromC(xc *C.libxl_domain_build_info) error { + if DomainType(xc._type) != DomainTypePv { + return errors.New("expected union key DomainTypePv") + } + + tmp := (*C.libxl_domain_build_info_type_union_pv)(unsafe.Pointer(&xc.u[0])) + x.Kernel = C.GoString(tmp.kernel) + x.SlackMemkb = uint64(tmp.slack_memkb) + x.Bootloader = C.GoString(tmp.bootloader) + if err := x.BootloaderArgs.fromC(&tmp.bootloader_args); err != nil { + 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 fmt.Errorf("converting field E820Host: %v", err) + } + return nil +} + +func (x *DomainBuildInfoTypeUnionPvh) fromC(xc *C.libxl_domain_build_info) error { + if DomainType(xc._type) != DomainTypePvh { + return errors.New("expected union key DomainTypePvh") + } + + tmp := (*C.libxl_domain_build_info_type_union_pvh)(unsafe.Pointer(&xc.u[0])) + if err := x.Pvshim.fromC(&tmp.pvshim); err != nil { + return fmt.Errorf("converting field Pvshim: %v", err) + } + x.PvshimPath = C.GoString(tmp.pvshim_path) + x.PvshimCmdline = C.GoString(tmp.pvshim_cmdline) + x.PvshimExtra = C.GoString(tmp.pvshim_extra) + return nil +} + +func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { + defer func() { + if err != nil { + C.libxl_domain_build_info_dispose(xc) + } + }() + + xc.max_vcpus = C.int(x.MaxVcpus) + if err := x.AvailVcpus.toC(&xc.avail_vcpus); err != nil { + return fmt.Errorf("converting field AvailVcpus: %v", err) + } + if err := x.Cpumap.toC(&xc.cpumap); err != nil { + return fmt.Errorf("converting field Cpumap: %v", err) + } + if err := x.Nodemap.toC(&xc.nodemap); err != nil { + 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)) + xc.num_vcpu_hard_affinity = C.int(numVcpuHardAffinity) + cVcpuHardAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:numVcpuHardAffinity:numVcpuHardAffinity] + for i, v := range x.VcpuHardAffinity { + if err := v.toC(&cVcpuHardAffinity[i]); err != nil { + return fmt.Errorf("converting field VcpuHardAffinity: %v", err) + } + } + } + if numVcpuSoftAffinity := len(x.VcpuSoftAffinity); numVcpuSoftAffinity > 0 { + xc.vcpu_soft_affinity = (*C.libxl_bitmap)(C.malloc(C.ulong(numVcpuSoftAffinity) * C.sizeof_libxl_bitmap)) + xc.num_vcpu_soft_affinity = C.int(numVcpuSoftAffinity) + cVcpuSoftAffinity := (*[1 << 28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:numVcpuSoftAffinity:numVcpuSoftAffinity] + for i, v := range x.VcpuSoftAffinity { + if err := v.toC(&cVcpuSoftAffinity[i]); err != nil { + return fmt.Errorf("converting field VcpuSoftAffinity: %v", err) + } + } + } + if err := x.NumaPlacement.toC(&xc.numa_placement); err != nil { + 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) + xc.target_memkb = C.uint64_t(x.TargetMemkb) + xc.video_memkb = C.uint64_t(x.VideoMemkb) + xc.shadow_memkb = C.uint64_t(x.ShadowMemkb) + xc.iommu_memkb = C.uint64_t(x.IommuMemkb) + xc.rtc_timeoffset = C.uint32_t(x.RtcTimeoffset) + xc.exec_ssidref = C.uint32_t(x.ExecSsidref) + if x.ExecSsidLabel != "" { + xc.exec_ssid_label = C.CString(x.ExecSsidLabel) + } + if err := x.Localtime.toC(&xc.localtime); err != nil { + return fmt.Errorf("converting field Localtime: %v", err) + } + if err := x.DisableMigrate.toC(&xc.disable_migrate); err != nil { + return fmt.Errorf("converting field DisableMigrate: %v", err) + } + if err := x.Cpuid.toC(&xc.cpuid); err != nil { + return fmt.Errorf("converting field Cpuid: %v", err) + } + if x.BlkdevStart != "" { + xc.blkdev_start = C.CString(x.BlkdevStart) + } + if numVnumaNodes := len(x.VnumaNodes); numVnumaNodes > 0 { + xc.vnuma_nodes = (*C.libxl_vnode_info)(C.malloc(C.ulong(numVnumaNodes) * C.sizeof_libxl_vnode_info)) + xc.num_vnuma_nodes = C.int(numVnumaNodes) + cVnumaNodes := (*[1 << 28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:numVnumaNodes:numVnumaNodes] + for i, v := range x.VnumaNodes { + if err := v.toC(&cVnumaNodes[i]); err != nil { + return fmt.Errorf("converting field VnumaNodes: %v", err) + } + } + } + xc.max_grant_frames = C.uint32_t(x.MaxGrantFrames) + xc.max_maptrack_frames = C.uint32_t(x.MaxMaptrackFrames) + xc.device_model_version = C.libxl_device_model_version(x.DeviceModelVersion) + if err := x.DeviceModelStubdomain.toC(&xc.device_model_stubdomain); err != nil { + return fmt.Errorf("converting field DeviceModelStubdomain: %v", err) + } + if x.DeviceModel != "" { + xc.device_model = C.CString(x.DeviceModel) + } + xc.device_model_ssidref = C.uint32_t(x.DeviceModelSsidref) + if x.DeviceModelSsidLabel != "" { + xc.device_model_ssid_label = C.CString(x.DeviceModelSsidLabel) + } + if x.DeviceModelUser != "" { + xc.device_model_user = C.CString(x.DeviceModelUser) + } + if err := x.Extra.toC(&xc.extra); err != nil { + return fmt.Errorf("converting field Extra: %v", err) + } + if err := x.ExtraPv.toC(&xc.extra_pv); err != nil { + return fmt.Errorf("converting field ExtraPv: %v", err) + } + if err := x.ExtraHvm.toC(&xc.extra_hvm); err != nil { + return fmt.Errorf("converting field ExtraHvm: %v", err) + } + if err := x.SchedParams.toC(&xc.sched_params); err != nil { + 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)) + xc.num_ioports = C.int(numIoports) + cIoports := (*[1 << 28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:numIoports:numIoports] + for i, v := range x.Ioports { + if err := v.toC(&cIoports[i]); err != nil { + return fmt.Errorf("converting field Ioports: %v", err) + } + } + } + if numIrqs := len(x.Irqs); numIrqs > 0 { + xc.irqs = (*C.uint32_t)(C.malloc(C.size_t(numIrqs * numIrqs))) + xc.num_irqs = C.int(numIrqs) + cIrqs := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:numIrqs:numIrqs] + for i, v := range x.Irqs { + cIrqs[i] = C.uint32_t(v) + } + } + if numIomem := len(x.Iomem); numIomem > 0 { + xc.iomem = (*C.libxl_iomem_range)(C.malloc(C.ulong(numIomem) * C.sizeof_libxl_iomem_range)) + xc.num_iomem = C.int(numIomem) + cIomem := (*[1 << 28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:numIomem:numIomem] + for i, v := range x.Iomem { + if err := v.toC(&cIomem[i]); err != nil { + return fmt.Errorf("converting field Iomem: %v", err) + } + } + } + if err := x.ClaimMode.toC(&xc.claim_mode); err != nil { + return fmt.Errorf("converting field ClaimMode: %v", err) + } + xc.event_channels = C.uint32_t(x.EventChannels) + if x.Kernel != "" { + xc.kernel = C.CString(x.Kernel) + } + if x.Cmdline != "" { + xc.cmdline = C.CString(x.Cmdline) + } + if x.Ramdisk != "" { + xc.ramdisk = C.CString(x.Ramdisk) + } + if x.DeviceTree != "" { + xc.device_tree = C.CString(x.DeviceTree) + } + if err := x.Acpi.toC(&xc.acpi); err != nil { + 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 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 fmt.Errorf("converting field NestedHvm: %v", err) + } + if err := x.Apic.toC(&xc.apic); err != nil { + return fmt.Errorf("converting field Apic: %v", err) + } + if err := x.DmRestrict.toC(&xc.dm_restrict); err != nil { + return fmt.Errorf("converting field DmRestrict: %v", err) + } + xc.tee = C.libxl_tee_type(x.Tee) + xc._type = C.libxl_domain_type(x.Type) + switch x.Type { + case DomainTypeHvm: + tmp, ok := x.TypeUnion.(DomainBuildInfoTypeUnionHvm) + if !ok { + return errors.New("wrong type for union key type") + } + var hvm C.libxl_domain_build_info_type_union_hvm + if tmp.Firmware != "" { + hvm.firmware = C.CString(tmp.Firmware) + } + hvm.bios = C.libxl_bios_type(tmp.Bios) + if err := tmp.Pae.toC(&hvm.pae); err != nil { + return fmt.Errorf("converting field Pae: %v", err) + } + if err := tmp.Apic.toC(&hvm.apic); err != nil { + return fmt.Errorf("converting field Apic: %v", err) + } + if err := tmp.Acpi.toC(&hvm.acpi); err != nil { + return fmt.Errorf("converting field Acpi: %v", err) + } + if err := tmp.AcpiS3.toC(&hvm.acpi_s3); err != nil { + return fmt.Errorf("converting field AcpiS3: %v", err) + } + if err := tmp.AcpiS4.toC(&hvm.acpi_s4); err != nil { + return fmt.Errorf("converting field AcpiS4: %v", err) + } + if err := tmp.AcpiLaptopSlate.toC(&hvm.acpi_laptop_slate); err != nil { + return fmt.Errorf("converting field AcpiLaptopSlate: %v", err) + } + if err := tmp.Nx.toC(&hvm.nx); err != nil { + return fmt.Errorf("converting field Nx: %v", err) + } + if err := tmp.Viridian.toC(&hvm.viridian); err != nil { + return fmt.Errorf("converting field Viridian: %v", err) + } + if err := tmp.ViridianEnable.toC(&hvm.viridian_enable); err != nil { + return fmt.Errorf("converting field ViridianEnable: %v", err) + } + if err := tmp.ViridianDisable.toC(&hvm.viridian_disable); err != nil { + 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 fmt.Errorf("converting field Hpet: %v", err) + } + if err := tmp.VptAlign.toC(&hvm.vpt_align); err != nil { + 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 fmt.Errorf("converting field NestedHvm: %v", err) + } + if err := tmp.Altp2M.toC(&hvm.altp2m); err != nil { + return fmt.Errorf("converting field Altp2M: %v", err) + } + if tmp.SystemFirmware != "" { + hvm.system_firmware = C.CString(tmp.SystemFirmware) + } + if tmp.SmbiosFirmware != "" { + hvm.smbios_firmware = C.CString(tmp.SmbiosFirmware) + } + if tmp.AcpiFirmware != "" { + hvm.acpi_firmware = C.CString(tmp.AcpiFirmware) + } + hvm.hdtype = C.libxl_hdtype(tmp.Hdtype) + if err := tmp.Nographic.toC(&hvm.nographic); err != nil { + return fmt.Errorf("converting field Nographic: %v", err) + } + if err := tmp.Vga.toC(&hvm.vga); err != nil { + return fmt.Errorf("converting field Vga: %v", err) + } + if err := tmp.Vnc.toC(&hvm.vnc); err != nil { + 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 fmt.Errorf("converting field Sdl: %v", err) + } + if err := tmp.Spice.toC(&hvm.spice); err != nil { + return fmt.Errorf("converting field Spice: %v", err) + } + if err := tmp.GfxPassthru.toC(&hvm.gfx_passthru); err != nil { + return fmt.Errorf("converting field GfxPassthru: %v", err) + } + hvm.gfx_passthru_kind = C.libxl_gfx_passthru_kind(tmp.GfxPassthruKind) + if tmp.Serial != "" { + hvm.serial = C.CString(tmp.Serial) + } + if tmp.Boot != "" { + hvm.boot = C.CString(tmp.Boot) + } + if err := tmp.Usb.toC(&hvm.usb); err != nil { + 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 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 fmt.Errorf("converting field XenPlatformPci: %v", err) + } + if err := tmp.UsbdeviceList.toC(&hvm.usbdevice_list); err != nil { + 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 fmt.Errorf("converting field MsVmGenid: %v", err) + } + if err := tmp.SerialList.toC(&hvm.serial_list); err != nil { + return fmt.Errorf("converting field SerialList: %v", err) + } + if err := tmp.Rdm.toC(&hvm.rdm); err != nil { + 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) + hvmBytes := C.GoBytes(unsafe.Pointer(&hvm), C.sizeof_libxl_domain_build_info_type_union_hvm) + copy(xc.u[:], hvmBytes) + case DomainTypePv: + tmp, ok := x.TypeUnion.(DomainBuildInfoTypeUnionPv) + if !ok { + return errors.New("wrong type for union key type") + } + var pv C.libxl_domain_build_info_type_union_pv + if tmp.Kernel != "" { + pv.kernel = C.CString(tmp.Kernel) + } + pv.slack_memkb = C.uint64_t(tmp.SlackMemkb) + if tmp.Bootloader != "" { + pv.bootloader = C.CString(tmp.Bootloader) + } + if err := tmp.BootloaderArgs.toC(&pv.bootloader_args); err != nil { + return fmt.Errorf("converting field BootloaderArgs: %v", err) + } + if tmp.Cmdline != "" { + pv.cmdline = C.CString(tmp.Cmdline) + } + if tmp.Ramdisk != "" { + pv.ramdisk = C.CString(tmp.Ramdisk) + } + if tmp.Features != "" { + pv.features = C.CString(tmp.Features) + } + if err := tmp.E820Host.toC(&pv.e820_host); err != nil { + 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) + case DomainTypePvh: + tmp, ok := x.TypeUnion.(DomainBuildInfoTypeUnionPvh) + if !ok { + return errors.New("wrong type for union key type") + } + var pvh C.libxl_domain_build_info_type_union_pvh + if err := tmp.Pvshim.toC(&pvh.pvshim); err != nil { + return fmt.Errorf("converting field Pvshim: %v", err) + } + if tmp.PvshimPath != "" { + pvh.pvshim_path = C.CString(tmp.PvshimPath) + } + if tmp.PvshimCmdline != "" { + pvh.pvshim_cmdline = C.CString(tmp.PvshimCmdline) + } + if tmp.PvshimExtra != "" { + pvh.pvshim_extra = C.CString(tmp.PvshimExtra) + } + pvhBytes := C.GoBytes(unsafe.Pointer(&pvh), C.sizeof_libxl_domain_build_info_type_union_pvh) + copy(xc.u[:], pvhBytes) + case DomainTypeInvalid: + break + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } + xc.arch_arm.gic_version = C.libxl_gic_version(x.ArchArm.GicVersion) + xc.arch_arm.vuart = C.libxl_vuart_type(x.ArchArm.Vuart) + xc.altp2m = C.libxl_altp2m_mode(x.Altp2M) + + return nil +} + +// NewDeviceVfb returns an instance of DeviceVfb initialized with defaults. +func NewDeviceVfb() (*DeviceVfb, error) { + var ( + x DeviceVfb + xc C.libxl_device_vfb + ) + + C.libxl_device_vfb_init(&xc) + defer C.libxl_device_vfb_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceVfb) fromC(xc *C.libxl_device_vfb) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Devid = Devid(xc.devid) + if err := x.Vnc.fromC(&xc.vnc); err != nil { + return fmt.Errorf("converting field Vnc: %v", err) + } + if err := x.Sdl.fromC(&xc.sdl); err != nil { + return fmt.Errorf("converting field Sdl: %v", err) + } + x.Keymap = C.GoString(xc.keymap) + + return nil +} + +func (x *DeviceVfb) toC(xc *C.libxl_device_vfb) (err error) { + defer func() { + if err != nil { + C.libxl_device_vfb_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + xc.devid = C.libxl_devid(x.Devid) + if err := x.Vnc.toC(&xc.vnc); err != nil { + return fmt.Errorf("converting field Vnc: %v", err) + } + if err := x.Sdl.toC(&xc.sdl); err != nil { + return fmt.Errorf("converting field Sdl: %v", err) + } + if x.Keymap != "" { + xc.keymap = C.CString(x.Keymap) + } + + return nil +} + +// NewDeviceVkb returns an instance of DeviceVkb initialized with defaults. +func NewDeviceVkb() (*DeviceVkb, error) { + var ( + x DeviceVkb + xc C.libxl_device_vkb + ) + + C.libxl_device_vkb_init(&xc) + defer C.libxl_device_vkb_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceVkb) fromC(xc *C.libxl_device_vkb) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Devid = Devid(xc.devid) + x.BackendType = VkbBackend(xc.backend_type) + x.UniqueId = C.GoString(xc.unique_id) + x.FeatureDisableKeyboard = bool(xc.feature_disable_keyboard) + x.FeatureDisablePointer = bool(xc.feature_disable_pointer) + x.FeatureAbsPointer = bool(xc.feature_abs_pointer) + x.FeatureRawPointer = bool(xc.feature_raw_pointer) + x.FeatureMultiTouch = bool(xc.feature_multi_touch) + x.Width = uint32(xc.width) + x.Height = uint32(xc.height) + x.MultiTouchWidth = uint32(xc.multi_touch_width) + x.MultiTouchHeight = uint32(xc.multi_touch_height) + x.MultiTouchNumContacts = uint32(xc.multi_touch_num_contacts) + + return nil +} + +func (x *DeviceVkb) toC(xc *C.libxl_device_vkb) (err error) { + defer func() { + if err != nil { + C.libxl_device_vkb_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + xc.devid = C.libxl_devid(x.Devid) + xc.backend_type = C.libxl_vkb_backend(x.BackendType) + if x.UniqueId != "" { + xc.unique_id = C.CString(x.UniqueId) + } + xc.feature_disable_keyboard = C.bool(x.FeatureDisableKeyboard) + xc.feature_disable_pointer = C.bool(x.FeatureDisablePointer) + xc.feature_abs_pointer = C.bool(x.FeatureAbsPointer) + xc.feature_raw_pointer = C.bool(x.FeatureRawPointer) + xc.feature_multi_touch = C.bool(x.FeatureMultiTouch) + xc.width = C.uint32_t(x.Width) + xc.height = C.uint32_t(x.Height) + xc.multi_touch_width = C.uint32_t(x.MultiTouchWidth) + xc.multi_touch_height = C.uint32_t(x.MultiTouchHeight) + xc.multi_touch_num_contacts = C.uint32_t(x.MultiTouchNumContacts) + + return nil +} + +// NewDeviceDisk returns an instance of DeviceDisk initialized with defaults. +func NewDeviceDisk() (*DeviceDisk, error) { + var ( + x DeviceDisk + xc C.libxl_device_disk + ) + + C.libxl_device_disk_init(&xc) + defer C.libxl_device_disk_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceDisk) fromC(xc *C.libxl_device_disk) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.PdevPath = C.GoString(xc.pdev_path) + x.Vdev = C.GoString(xc.vdev) + x.Backend = DiskBackend(xc.backend) + x.Format = DiskFormat(xc.format) + x.Script = C.GoString(xc.script) + x.Removable = int(xc.removable) + x.Readwrite = int(xc.readwrite) + x.IsCdrom = int(xc.is_cdrom) + x.DirectIoSafe = bool(xc.direct_io_safe) + if err := x.DiscardEnable.fromC(&xc.discard_enable); err != nil { + return fmt.Errorf("converting field DiscardEnable: %v", err) + } + if err := x.ColoEnable.fromC(&xc.colo_enable); err != nil { + return fmt.Errorf("converting field ColoEnable: %v", err) + } + if err := x.ColoRestoreEnable.fromC(&xc.colo_restore_enable); err != nil { + return fmt.Errorf("converting field ColoRestoreEnable: %v", err) + } + x.ColoHost = C.GoString(xc.colo_host) + x.ColoPort = int(xc.colo_port) + x.ColoExport = C.GoString(xc.colo_export) + x.ActiveDisk = C.GoString(xc.active_disk) + x.HiddenDisk = C.GoString(xc.hidden_disk) + + return nil +} + +func (x *DeviceDisk) toC(xc *C.libxl_device_disk) (err error) { + defer func() { + if err != nil { + C.libxl_device_disk_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + if x.PdevPath != "" { + xc.pdev_path = C.CString(x.PdevPath) + } + if x.Vdev != "" { + xc.vdev = C.CString(x.Vdev) + } + xc.backend = C.libxl_disk_backend(x.Backend) + xc.format = C.libxl_disk_format(x.Format) + if x.Script != "" { + xc.script = C.CString(x.Script) + } + xc.removable = C.int(x.Removable) + xc.readwrite = C.int(x.Readwrite) + xc.is_cdrom = C.int(x.IsCdrom) + xc.direct_io_safe = C.bool(x.DirectIoSafe) + if err := x.DiscardEnable.toC(&xc.discard_enable); err != nil { + return fmt.Errorf("converting field DiscardEnable: %v", err) + } + if err := x.ColoEnable.toC(&xc.colo_enable); err != nil { + return fmt.Errorf("converting field ColoEnable: %v", err) + } + if err := x.ColoRestoreEnable.toC(&xc.colo_restore_enable); err != nil { + return fmt.Errorf("converting field ColoRestoreEnable: %v", err) + } + if x.ColoHost != "" { + xc.colo_host = C.CString(x.ColoHost) + } + xc.colo_port = C.int(x.ColoPort) + if x.ColoExport != "" { + xc.colo_export = C.CString(x.ColoExport) + } + if x.ActiveDisk != "" { + xc.active_disk = C.CString(x.ActiveDisk) + } + if x.HiddenDisk != "" { + xc.hidden_disk = C.CString(x.HiddenDisk) + } + + return nil +} + +// NewDeviceNic returns an instance of DeviceNic initialized with defaults. +func NewDeviceNic() (*DeviceNic, error) { + var ( + x DeviceNic + xc C.libxl_device_nic + ) + + C.libxl_device_nic_init(&xc) + defer C.libxl_device_nic_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceNic) fromC(xc *C.libxl_device_nic) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Devid = Devid(xc.devid) + x.Mtu = int(xc.mtu) + x.Model = C.GoString(xc.model) + if err := x.Mac.fromC(&xc.mac); err != nil { + return fmt.Errorf("converting field Mac: %v", err) + } + x.Ip = C.GoString(xc.ip) + x.Bridge = C.GoString(xc.bridge) + x.Ifname = C.GoString(xc.ifname) + x.Script = C.GoString(xc.script) + x.Nictype = NicType(xc.nictype) + x.RateBytesPerInterval = uint64(xc.rate_bytes_per_interval) + x.RateIntervalUsecs = uint32(xc.rate_interval_usecs) + x.Gatewaydev = C.GoString(xc.gatewaydev) + x.ColoftForwarddev = C.GoString(xc.coloft_forwarddev) + x.ColoSockMirrorId = C.GoString(xc.colo_sock_mirror_id) + x.ColoSockMirrorIp = C.GoString(xc.colo_sock_mirror_ip) + x.ColoSockMirrorPort = C.GoString(xc.colo_sock_mirror_port) + x.ColoSockComparePriInId = C.GoString(xc.colo_sock_compare_pri_in_id) + x.ColoSockComparePriInIp = C.GoString(xc.colo_sock_compare_pri_in_ip) + x.ColoSockComparePriInPort = C.GoString(xc.colo_sock_compare_pri_in_port) + x.ColoSockCompareSecInId = C.GoString(xc.colo_sock_compare_sec_in_id) + x.ColoSockCompareSecInIp = C.GoString(xc.colo_sock_compare_sec_in_ip) + x.ColoSockCompareSecInPort = C.GoString(xc.colo_sock_compare_sec_in_port) + x.ColoSockCompareNotifyId = C.GoString(xc.colo_sock_compare_notify_id) + x.ColoSockCompareNotifyIp = C.GoString(xc.colo_sock_compare_notify_ip) + x.ColoSockCompareNotifyPort = C.GoString(xc.colo_sock_compare_notify_port) + x.ColoSockRedirector0Id = C.GoString(xc.colo_sock_redirector0_id) + x.ColoSockRedirector0Ip = C.GoString(xc.colo_sock_redirector0_ip) + x.ColoSockRedirector0Port = C.GoString(xc.colo_sock_redirector0_port) + x.ColoSockRedirector1Id = C.GoString(xc.colo_sock_redirector1_id) + x.ColoSockRedirector1Ip = C.GoString(xc.colo_sock_redirector1_ip) + x.ColoSockRedirector1Port = C.GoString(xc.colo_sock_redirector1_port) + x.ColoSockRedirector2Id = C.GoString(xc.colo_sock_redirector2_id) + x.ColoSockRedirector2Ip = C.GoString(xc.colo_sock_redirector2_ip) + x.ColoSockRedirector2Port = C.GoString(xc.colo_sock_redirector2_port) + x.ColoFilterMirrorQueue = C.GoString(xc.colo_filter_mirror_queue) + x.ColoFilterMirrorOutdev = C.GoString(xc.colo_filter_mirror_outdev) + x.ColoFilterRedirector0Queue = C.GoString(xc.colo_filter_redirector0_queue) + x.ColoFilterRedirector0Indev = C.GoString(xc.colo_filter_redirector0_indev) + x.ColoFilterRedirector0Outdev = C.GoString(xc.colo_filter_redirector0_outdev) + x.ColoFilterRedirector1Queue = C.GoString(xc.colo_filter_redirector1_queue) + x.ColoFilterRedirector1Indev = C.GoString(xc.colo_filter_redirector1_indev) + x.ColoFilterRedirector1Outdev = C.GoString(xc.colo_filter_redirector1_outdev) + x.ColoComparePriIn = C.GoString(xc.colo_compare_pri_in) + x.ColoCompareSecIn = C.GoString(xc.colo_compare_sec_in) + x.ColoCompareOut = C.GoString(xc.colo_compare_out) + x.ColoCompareNotifyDev = C.GoString(xc.colo_compare_notify_dev) + x.ColoSockSecRedirector0Id = C.GoString(xc.colo_sock_sec_redirector0_id) + x.ColoSockSecRedirector0Ip = C.GoString(xc.colo_sock_sec_redirector0_ip) + x.ColoSockSecRedirector0Port = C.GoString(xc.colo_sock_sec_redirector0_port) + x.ColoSockSecRedirector1Id = C.GoString(xc.colo_sock_sec_redirector1_id) + x.ColoSockSecRedirector1Ip = C.GoString(xc.colo_sock_sec_redirector1_ip) + x.ColoSockSecRedirector1Port = C.GoString(xc.colo_sock_sec_redirector1_port) + x.ColoFilterSecRedirector0Queue = C.GoString(xc.colo_filter_sec_redirector0_queue) + x.ColoFilterSecRedirector0Indev = C.GoString(xc.colo_filter_sec_redirector0_indev) + x.ColoFilterSecRedirector0Outdev = C.GoString(xc.colo_filter_sec_redirector0_outdev) + x.ColoFilterSecRedirector1Queue = C.GoString(xc.colo_filter_sec_redirector1_queue) + x.ColoFilterSecRedirector1Indev = C.GoString(xc.colo_filter_sec_redirector1_indev) + x.ColoFilterSecRedirector1Outdev = C.GoString(xc.colo_filter_sec_redirector1_outdev) + x.ColoFilterSecRewriter0Queue = C.GoString(xc.colo_filter_sec_rewriter0_queue) + x.ColoCheckpointHost = C.GoString(xc.colo_checkpoint_host) + x.ColoCheckpointPort = C.GoString(xc.colo_checkpoint_port) + + return nil +} + +func (x *DeviceNic) toC(xc *C.libxl_device_nic) (err error) { + defer func() { + if err != nil { + C.libxl_device_nic_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + xc.devid = C.libxl_devid(x.Devid) + xc.mtu = C.int(x.Mtu) + if x.Model != "" { + xc.model = C.CString(x.Model) + } + if err := x.Mac.toC(&xc.mac); err != nil { + return fmt.Errorf("converting field Mac: %v", err) + } + if x.Ip != "" { + xc.ip = C.CString(x.Ip) + } + if x.Bridge != "" { + xc.bridge = C.CString(x.Bridge) + } + if x.Ifname != "" { + xc.ifname = C.CString(x.Ifname) + } + if x.Script != "" { + xc.script = C.CString(x.Script) + } + xc.nictype = C.libxl_nic_type(x.Nictype) + xc.rate_bytes_per_interval = C.uint64_t(x.RateBytesPerInterval) + xc.rate_interval_usecs = C.uint32_t(x.RateIntervalUsecs) + if x.Gatewaydev != "" { + xc.gatewaydev = C.CString(x.Gatewaydev) + } + if x.ColoftForwarddev != "" { + xc.coloft_forwarddev = C.CString(x.ColoftForwarddev) + } + if x.ColoSockMirrorId != "" { + xc.colo_sock_mirror_id = C.CString(x.ColoSockMirrorId) + } + if x.ColoSockMirrorIp != "" { + xc.colo_sock_mirror_ip = C.CString(x.ColoSockMirrorIp) + } + if x.ColoSockMirrorPort != "" { + xc.colo_sock_mirror_port = C.CString(x.ColoSockMirrorPort) + } + if x.ColoSockComparePriInId != "" { + xc.colo_sock_compare_pri_in_id = C.CString(x.ColoSockComparePriInId) + } + if x.ColoSockComparePriInIp != "" { + xc.colo_sock_compare_pri_in_ip = C.CString(x.ColoSockComparePriInIp) + } + if x.ColoSockComparePriInPort != "" { + xc.colo_sock_compare_pri_in_port = C.CString(x.ColoSockComparePriInPort) + } + if x.ColoSockCompareSecInId != "" { + xc.colo_sock_compare_sec_in_id = C.CString(x.ColoSockCompareSecInId) + } + if x.ColoSockCompareSecInIp != "" { + xc.colo_sock_compare_sec_in_ip = C.CString(x.ColoSockCompareSecInIp) + } + if x.ColoSockCompareSecInPort != "" { + xc.colo_sock_compare_sec_in_port = C.CString(x.ColoSockCompareSecInPort) + } + if x.ColoSockCompareNotifyId != "" { + xc.colo_sock_compare_notify_id = C.CString(x.ColoSockCompareNotifyId) + } + if x.ColoSockCompareNotifyIp != "" { + xc.colo_sock_compare_notify_ip = C.CString(x.ColoSockCompareNotifyIp) + } + if x.ColoSockCompareNotifyPort != "" { + xc.colo_sock_compare_notify_port = C.CString(x.ColoSockCompareNotifyPort) + } + if x.ColoSockRedirector0Id != "" { + xc.colo_sock_redirector0_id = C.CString(x.ColoSockRedirector0Id) + } + if x.ColoSockRedirector0Ip != "" { + xc.colo_sock_redirector0_ip = C.CString(x.ColoSockRedirector0Ip) + } + if x.ColoSockRedirector0Port != "" { + xc.colo_sock_redirector0_port = C.CString(x.ColoSockRedirector0Port) + } + if x.ColoSockRedirector1Id != "" { + xc.colo_sock_redirector1_id = C.CString(x.ColoSockRedirector1Id) + } + if x.ColoSockRedirector1Ip != "" { + xc.colo_sock_redirector1_ip = C.CString(x.ColoSockRedirector1Ip) + } + if x.ColoSockRedirector1Port != "" { + xc.colo_sock_redirector1_port = C.CString(x.ColoSockRedirector1Port) + } + if x.ColoSockRedirector2Id != "" { + xc.colo_sock_redirector2_id = C.CString(x.ColoSockRedirector2Id) + } + if x.ColoSockRedirector2Ip != "" { + xc.colo_sock_redirector2_ip = C.CString(x.ColoSockRedirector2Ip) + } + if x.ColoSockRedirector2Port != "" { + xc.colo_sock_redirector2_port = C.CString(x.ColoSockRedirector2Port) + } + if x.ColoFilterMirrorQueue != "" { + xc.colo_filter_mirror_queue = C.CString(x.ColoFilterMirrorQueue) + } + if x.ColoFilterMirrorOutdev != "" { + xc.colo_filter_mirror_outdev = C.CString(x.ColoFilterMirrorOutdev) + } + if x.ColoFilterRedirector0Queue != "" { + xc.colo_filter_redirector0_queue = C.CString(x.ColoFilterRedirector0Queue) + } + if x.ColoFilterRedirector0Indev != "" { + xc.colo_filter_redirector0_indev = C.CString(x.ColoFilterRedirector0Indev) + } + if x.ColoFilterRedirector0Outdev != "" { + xc.colo_filter_redirector0_outdev = C.CString(x.ColoFilterRedirector0Outdev) + } + if x.ColoFilterRedirector1Queue != "" { + xc.colo_filter_redirector1_queue = C.CString(x.ColoFilterRedirector1Queue) + } + if x.ColoFilterRedirector1Indev != "" { + xc.colo_filter_redirector1_indev = C.CString(x.ColoFilterRedirector1Indev) + } + if x.ColoFilterRedirector1Outdev != "" { + xc.colo_filter_redirector1_outdev = C.CString(x.ColoFilterRedirector1Outdev) + } + if x.ColoComparePriIn != "" { + xc.colo_compare_pri_in = C.CString(x.ColoComparePriIn) + } + if x.ColoCompareSecIn != "" { + xc.colo_compare_sec_in = C.CString(x.ColoCompareSecIn) + } + if x.ColoCompareOut != "" { + xc.colo_compare_out = C.CString(x.ColoCompareOut) + } + if x.ColoCompareNotifyDev != "" { + xc.colo_compare_notify_dev = C.CString(x.ColoCompareNotifyDev) + } + if x.ColoSockSecRedirector0Id != "" { + xc.colo_sock_sec_redirector0_id = C.CString(x.ColoSockSecRedirector0Id) + } + if x.ColoSockSecRedirector0Ip != "" { + xc.colo_sock_sec_redirector0_ip = C.CString(x.ColoSockSecRedirector0Ip) + } + if x.ColoSockSecRedirector0Port != "" { + xc.colo_sock_sec_redirector0_port = C.CString(x.ColoSockSecRedirector0Port) + } + if x.ColoSockSecRedirector1Id != "" { + xc.colo_sock_sec_redirector1_id = C.CString(x.ColoSockSecRedirector1Id) + } + if x.ColoSockSecRedirector1Ip != "" { + xc.colo_sock_sec_redirector1_ip = C.CString(x.ColoSockSecRedirector1Ip) + } + if x.ColoSockSecRedirector1Port != "" { + xc.colo_sock_sec_redirector1_port = C.CString(x.ColoSockSecRedirector1Port) + } + if x.ColoFilterSecRedirector0Queue != "" { + xc.colo_filter_sec_redirector0_queue = C.CString(x.ColoFilterSecRedirector0Queue) + } + if x.ColoFilterSecRedirector0Indev != "" { + xc.colo_filter_sec_redirector0_indev = C.CString(x.ColoFilterSecRedirector0Indev) + } + if x.ColoFilterSecRedirector0Outdev != "" { + xc.colo_filter_sec_redirector0_outdev = C.CString(x.ColoFilterSecRedirector0Outdev) + } + if x.ColoFilterSecRedirector1Queue != "" { + xc.colo_filter_sec_redirector1_queue = C.CString(x.ColoFilterSecRedirector1Queue) + } + if x.ColoFilterSecRedirector1Indev != "" { + xc.colo_filter_sec_redirector1_indev = C.CString(x.ColoFilterSecRedirector1Indev) + } + if x.ColoFilterSecRedirector1Outdev != "" { + xc.colo_filter_sec_redirector1_outdev = C.CString(x.ColoFilterSecRedirector1Outdev) + } + if x.ColoFilterSecRewriter0Queue != "" { + xc.colo_filter_sec_rewriter0_queue = C.CString(x.ColoFilterSecRewriter0Queue) + } + if x.ColoCheckpointHost != "" { + xc.colo_checkpoint_host = C.CString(x.ColoCheckpointHost) + } + if x.ColoCheckpointPort != "" { + xc.colo_checkpoint_port = C.CString(x.ColoCheckpointPort) + } + + return nil +} + +// NewDevicePci returns an instance of DevicePci initialized with defaults. +func NewDevicePci() (*DevicePci, error) { + var ( + x DevicePci + xc C.libxl_device_pci + ) + + C.libxl_device_pci_init(&xc) + defer C.libxl_device_pci_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DevicePci) fromC(xc *C.libxl_device_pci) error { + x.Func = byte(xc._func) + x.Dev = byte(xc.dev) + x.Bus = byte(xc.bus) + x.Domain = int(xc.domain) + x.Vdevfn = uint32(xc.vdevfn) + x.VfuncMask = uint32(xc.vfunc_mask) + x.Msitranslate = bool(xc.msitranslate) + x.PowerMgmt = bool(xc.power_mgmt) + x.Permissive = bool(xc.permissive) + x.Seize = bool(xc.seize) + x.RdmPolicy = RdmReservePolicy(xc.rdm_policy) + + return nil +} + +func (x *DevicePci) toC(xc *C.libxl_device_pci) (err error) { + defer func() { + if err != nil { + C.libxl_device_pci_dispose(xc) + } + }() + + xc._func = C.uint8_t(x.Func) + xc.dev = C.uint8_t(x.Dev) + xc.bus = C.uint8_t(x.Bus) + xc.domain = C.int(x.Domain) + xc.vdevfn = C.uint32_t(x.Vdevfn) + xc.vfunc_mask = C.uint32_t(x.VfuncMask) + xc.msitranslate = C.bool(x.Msitranslate) + xc.power_mgmt = C.bool(x.PowerMgmt) + xc.permissive = C.bool(x.Permissive) + xc.seize = C.bool(x.Seize) + xc.rdm_policy = C.libxl_rdm_reserve_policy(x.RdmPolicy) + + return nil +} + +// NewDeviceRdm returns an instance of DeviceRdm initialized with defaults. +func NewDeviceRdm() (*DeviceRdm, error) { + var ( + x DeviceRdm + xc C.libxl_device_rdm + ) + + C.libxl_device_rdm_init(&xc) + defer C.libxl_device_rdm_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceRdm) fromC(xc *C.libxl_device_rdm) error { + x.Start = uint64(xc.start) + x.Size = uint64(xc.size) + x.Policy = RdmReservePolicy(xc.policy) + + return nil +} + +func (x *DeviceRdm) toC(xc *C.libxl_device_rdm) (err error) { + defer func() { + if err != nil { + C.libxl_device_rdm_dispose(xc) + } + }() + + xc.start = C.uint64_t(x.Start) + xc.size = C.uint64_t(x.Size) + xc.policy = C.libxl_rdm_reserve_policy(x.Policy) + + return nil +} + +// NewDeviceUsbctrl returns an instance of DeviceUsbctrl initialized with defaults. +func NewDeviceUsbctrl() (*DeviceUsbctrl, error) { + var ( + x DeviceUsbctrl + xc C.libxl_device_usbctrl + ) + + C.libxl_device_usbctrl_init(&xc) + defer C.libxl_device_usbctrl_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceUsbctrl) fromC(xc *C.libxl_device_usbctrl) error { + x.Type = UsbctrlType(xc._type) + x.Devid = Devid(xc.devid) + x.Version = int(xc.version) + x.Ports = int(xc.ports) + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + + return nil +} + +func (x *DeviceUsbctrl) toC(xc *C.libxl_device_usbctrl) (err error) { + defer func() { + if err != nil { + C.libxl_device_usbctrl_dispose(xc) + } + }() + + xc._type = C.libxl_usbctrl_type(x.Type) + xc.devid = C.libxl_devid(x.Devid) + xc.version = C.int(x.Version) + xc.ports = C.int(x.Ports) + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + + return nil +} + +// NewDeviceUsbdev returns an instance of DeviceUsbdev initialized with defaults. +func NewDeviceUsbdev(utype UsbdevType) (*DeviceUsbdev, error) { + var ( + x DeviceUsbdev + xc C.libxl_device_usbdev + ) + + C.libxl_device_usbdev_init(&xc) + C.libxl_device_usbdev_init_type(&xc, C.libxl_usbdev_type(utype)) + defer C.libxl_device_usbdev_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceUsbdev) fromC(xc *C.libxl_device_usbdev) error { + x.Ctrl = Devid(xc.ctrl) + x.Port = int(xc.port) + x.Type = UsbdevType(xc._type) + switch x.Type { + case UsbdevTypeHostdev: + var typeHostdev DeviceUsbdevTypeUnionHostdev + if err := typeHostdev.fromC(xc); err != nil { + return fmt.Errorf("converting field typeHostdev: %v", err) + } + x.TypeUnion = typeHostdev + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } + + return nil +} + +func (x *DeviceUsbdevTypeUnionHostdev) fromC(xc *C.libxl_device_usbdev) error { + if UsbdevType(xc._type) != UsbdevTypeHostdev { + return errors.New("expected union key UsbdevTypeHostdev") + } + + tmp := (*C.libxl_device_usbdev_type_union_hostdev)(unsafe.Pointer(&xc.u[0])) + x.Hostbus = byte(tmp.hostbus) + x.Hostaddr = byte(tmp.hostaddr) + return nil +} + +func (x *DeviceUsbdev) toC(xc *C.libxl_device_usbdev) (err error) { + defer func() { + if err != nil { + C.libxl_device_usbdev_dispose(xc) + } + }() + + xc.ctrl = C.libxl_devid(x.Ctrl) + xc.port = C.int(x.Port) + xc._type = C.libxl_usbdev_type(x.Type) + switch x.Type { + case UsbdevTypeHostdev: + tmp, ok := x.TypeUnion.(DeviceUsbdevTypeUnionHostdev) + if !ok { + return errors.New("wrong type for union key type") + } + var hostdev C.libxl_device_usbdev_type_union_hostdev + hostdev.hostbus = C.uint8_t(tmp.Hostbus) + hostdev.hostaddr = C.uint8_t(tmp.Hostaddr) + hostdevBytes := C.GoBytes(unsafe.Pointer(&hostdev), C.sizeof_libxl_device_usbdev_type_union_hostdev) + copy(xc.u[:], hostdevBytes) + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } + + return nil +} + +// NewDeviceDtdev returns an instance of DeviceDtdev initialized with defaults. +func NewDeviceDtdev() (*DeviceDtdev, error) { + var ( + x DeviceDtdev + xc C.libxl_device_dtdev + ) + + C.libxl_device_dtdev_init(&xc) + defer C.libxl_device_dtdev_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceDtdev) fromC(xc *C.libxl_device_dtdev) error { + x.Path = C.GoString(xc.path) + + return nil +} + +func (x *DeviceDtdev) toC(xc *C.libxl_device_dtdev) (err error) { + defer func() { + if err != nil { + C.libxl_device_dtdev_dispose(xc) + } + }() + + if x.Path != "" { + xc.path = C.CString(x.Path) + } + + return nil +} + +// NewDeviceVtpm returns an instance of DeviceVtpm initialized with defaults. +func NewDeviceVtpm() (*DeviceVtpm, error) { + var ( + x DeviceVtpm + xc C.libxl_device_vtpm + ) + + C.libxl_device_vtpm_init(&xc) + defer C.libxl_device_vtpm_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceVtpm) fromC(xc *C.libxl_device_vtpm) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Devid = Devid(xc.devid) + if err := x.Uuid.fromC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + + return nil +} + +func (x *DeviceVtpm) toC(xc *C.libxl_device_vtpm) (err error) { + defer func() { + if err != nil { + C.libxl_device_vtpm_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + xc.devid = C.libxl_devid(x.Devid) + if err := x.Uuid.toC(&xc.uuid); err != nil { + return fmt.Errorf("converting field Uuid: %v", err) + } + + return nil +} + +// NewDeviceP9 returns an instance of DeviceP9 initialized with defaults. +func NewDeviceP9() (*DeviceP9, error) { + var ( + x DeviceP9 + xc C.libxl_device_p9 + ) + + C.libxl_device_p9_init(&xc) + defer C.libxl_device_p9_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceP9) fromC(xc *C.libxl_device_p9) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Tag = C.GoString(xc.tag) + x.Path = C.GoString(xc.path) + x.SecurityModel = C.GoString(xc.security_model) + x.Devid = Devid(xc.devid) + + return nil +} + +func (x *DeviceP9) toC(xc *C.libxl_device_p9) (err error) { + defer func() { + if err != nil { + C.libxl_device_p9_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + if x.Tag != "" { + xc.tag = C.CString(x.Tag) + } + if x.Path != "" { + xc.path = C.CString(x.Path) + } + if x.SecurityModel != "" { + xc.security_model = C.CString(x.SecurityModel) + } + xc.devid = C.libxl_devid(x.Devid) + + return nil +} + +// NewDevicePvcallsif returns an instance of DevicePvcallsif initialized with defaults. +func NewDevicePvcallsif() (*DevicePvcallsif, error) { + var ( + x DevicePvcallsif + xc C.libxl_device_pvcallsif + ) + + C.libxl_device_pvcallsif_init(&xc) + defer C.libxl_device_pvcallsif_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DevicePvcallsif) fromC(xc *C.libxl_device_pvcallsif) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Devid = Devid(xc.devid) + + return nil +} + +func (x *DevicePvcallsif) toC(xc *C.libxl_device_pvcallsif) (err error) { + defer func() { + if err != nil { + C.libxl_device_pvcallsif_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + xc.devid = C.libxl_devid(x.Devid) + + return nil +} + +// NewDeviceChannel returns an instance of DeviceChannel initialized with defaults. +func NewDeviceChannel(connection ChannelConnection) (*DeviceChannel, error) { + var ( + x DeviceChannel + xc C.libxl_device_channel + ) + + C.libxl_device_channel_init(&xc) + C.libxl_device_channel_init_connection(&xc, C.libxl_channel_connection(connection)) + defer C.libxl_device_channel_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceChannel) fromC(xc *C.libxl_device_channel) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Devid = Devid(xc.devid) + x.Name = C.GoString(xc.name) + x.Connection = ChannelConnection(xc.connection) + switch x.Connection { + case ChannelConnectionUnknown: + x.ConnectionUnion = nil + case ChannelConnectionPty: + x.ConnectionUnion = nil + case ChannelConnectionSocket: + var connectionSocket DeviceChannelConnectionUnionSocket + if err := connectionSocket.fromC(xc); err != nil { + return fmt.Errorf("converting field connectionSocket: %v", err) + } + x.ConnectionUnion = connectionSocket + default: + return fmt.Errorf("invalid union key '%v'", x.Connection) + } + + return nil +} + +func (x *DeviceChannelConnectionUnionSocket) fromC(xc *C.libxl_device_channel) error { + if ChannelConnection(xc.connection) != ChannelConnectionSocket { + return errors.New("expected union key ChannelConnectionSocket") + } + + tmp := (*C.libxl_device_channel_connection_union_socket)(unsafe.Pointer(&xc.u[0])) + x.Path = C.GoString(tmp.path) + return nil +} + +func (x *DeviceChannel) toC(xc *C.libxl_device_channel) (err error) { + defer func() { + if err != nil { + C.libxl_device_channel_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + xc.devid = C.libxl_devid(x.Devid) + if x.Name != "" { + xc.name = C.CString(x.Name) + } + xc.connection = C.libxl_channel_connection(x.Connection) + switch x.Connection { + case ChannelConnectionUnknown: + break + case ChannelConnectionPty: + break + case ChannelConnectionSocket: + tmp, ok := x.ConnectionUnion.(DeviceChannelConnectionUnionSocket) + if !ok { + return errors.New("wrong type for union key connection") + } + var socket C.libxl_device_channel_connection_union_socket + if tmp.Path != "" { + socket.path = C.CString(tmp.Path) + } + socketBytes := C.GoBytes(unsafe.Pointer(&socket), C.sizeof_libxl_device_channel_connection_union_socket) + copy(xc.u[:], socketBytes) + default: + return fmt.Errorf("invalid union key '%v'", x.Connection) + } + + return nil +} + +// NewConnectorParam returns an instance of ConnectorParam initialized with defaults. +func NewConnectorParam() (*ConnectorParam, error) { + var ( + x ConnectorParam + xc C.libxl_connector_param + ) + + C.libxl_connector_param_init(&xc) + defer C.libxl_connector_param_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *ConnectorParam) fromC(xc *C.libxl_connector_param) error { + x.UniqueId = C.GoString(xc.unique_id) + x.Width = uint32(xc.width) + x.Height = uint32(xc.height) + + return nil +} + +func (x *ConnectorParam) toC(xc *C.libxl_connector_param) (err error) { + defer func() { + if err != nil { + C.libxl_connector_param_dispose(xc) + } + }() + + if x.UniqueId != "" { + xc.unique_id = C.CString(x.UniqueId) + } + xc.width = C.uint32_t(x.Width) + xc.height = C.uint32_t(x.Height) + + return nil +} + +// NewDeviceVdispl returns an instance of DeviceVdispl initialized with defaults. +func NewDeviceVdispl() (*DeviceVdispl, error) { + var ( + x DeviceVdispl + xc C.libxl_device_vdispl + ) + + C.libxl_device_vdispl_init(&xc) + defer C.libxl_device_vdispl_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error { + x.BackendDomid = Domid(xc.backend_domid) + x.BackendDomname = C.GoString(xc.backend_domname) + x.Devid = Devid(xc.devid) + x.BeAlloc = bool(xc.be_alloc) + x.Connectors = nil + if n := int(xc.num_connectors); n > 0 { + cConnectors := (*[1 << 28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:n:n] + x.Connectors = make([]ConnectorParam, n) + for i, v := range cConnectors { + if err := x.Connectors[i].fromC(&v); err != nil { + return fmt.Errorf("converting field Connectors: %v", err) + } + } + } + + return nil +} + +func (x *DeviceVdispl) toC(xc *C.libxl_device_vdispl) (err error) { + defer func() { + if err != nil { + C.libxl_device_vdispl_dispose(xc) + } + }() + + xc.backend_domid = C.libxl_domid(x.BackendDomid) + if x.BackendDomname != "" { + xc.backend_domname = C.CString(x.BackendDomname) + } + xc.devid = C.libxl_devid(x.Devid) + xc.be_alloc = C.bool(x.BeAlloc) + if numConnectors := len(x.Connectors); numConnectors > 0 { + xc.connectors = (*C.libxl_connector_param)(C.malloc(C.ulong(numConnectors) * C.sizeof_libxl_connector_param)) + xc.num_connectors = C.int(numConnectors) + cConnectors := (*[1 << 28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors] + for i, v := range x.Connectors { + if err := v.toC(&cConnectors[i]); err != nil { + return fmt.Errorf("converting field Connectors: %v", err) + } + } + } + + return nil +} + +// NewVsndParams returns an instance of VsndParams initialized with defaults. +func NewVsndParams() (*VsndParams, error) { + var ( + x VsndParams + xc C.libxl_vsnd_params + ) + + C.libxl_vsnd_params_init(&xc) + defer C.libxl_vsnd_params_dispose(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + +func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error { + x.SampleRates = nil + if n := int(xc.num_sample_rates); n > 0 { + cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:n:n] + x.SampleRates = make([]uint32, n) + for i, v := range cSampleRates { + x.SampleRates[i] = uint32(v) + } + } + x.SampleFormats = nil + if n := int(xc.num_sample_formats); n > 0 { + cSampleFormats := (*[1 << 28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:n:n] + x.SampleFormats = make([]VsndPcmFormat, n) + for i, v := range cSampleFormats { + x.SampleFormats[i] = VsndPcmFormat(v) + } + } + x.ChannelsMin = uint32(xc.channels_min) + x.ChannelsMax = uint32(xc.channels_max) + x.BufferSize = uint32(xc.buffer_size) + + return nil +} + +func (x *VsndParams) toC(xc *C.libxl_vsnd_params) (err error) { + defer func() { + if err != nil { + C.libxl_vsnd_params_dispose(xc) + } + }() + + if numSampleRates := len(x.SampleRates); numSampleRates > 0 { + xc.sample_rates = (*C.uint32_t)(C.malloc(C.size_t(numSampleRates * numSampleRates))) + xc.num_sample_rates = C.int(numSampleRates) + cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:numSampleRates:numSampleRates] + for i, v := range x.SampleRates { + cSampleRates[i] = C.uint32_t(v) + } + } + if numSampleFormats := len(x.SampleFormats); numSampleFormats > 0 { + xc.sample_formats = (*C.libxl_vsnd_pcm_format)(C.malloc(C.size_t(numSampleFormats * numSampleFormats))) + xc.num_sample_formats = C.int(numSampleFormats) + cSampleFormats := (*[1 << 28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:numSampleFormats:numSampleFormats] + for i, v := range x.SampleFormats { + cSampleFormats[i] = C.libxl_vsnd_pcm_format(v) + } + } + xc.channels_min = C.uint32_t(x.ChannelsMin) + xc.channels_max = C.uint32_t(x.ChannelsMax) + xc.buffer_size = C.uint32_t(x.BufferSize) + + return nil +}
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |