Debian Codegraph @

tools/golang/xenlight/helpers.gen.go

raw
1 // Code generated by gengotypes.py. DO NOT EDIT.
2 // source: libxl_types.idl
3
4 package xenlight
5
6 import (
7 "unsafe"
8 "errors"
9 "fmt"
10 )
11 /*
12 #cgo LDFLAGS: -lxenlight
13 #include <stdlib.h>
14 #include <libxl.h>
15
16 typedef typeof(((struct libxl_channelinfo *)NULL)->u.pty)libxl_channelinfo_connection_union_pty;
17 typedef typeof(((struct libxl_domain_build_info *)NULL)->u.hvm)libxl_domain_build_info_type_union_hvm;
18 typedef typeof(((struct libxl_domain_build_info *)NULL)->u.pv)libxl_domain_build_info_type_union_pv;
19 typedef typeof(((struct libxl_domain_build_info *)NULL)->u.pvh)libxl_domain_build_info_type_union_pvh;
20 typedef typeof(((struct libxl_device_usbdev *)NULL)->u.hostdev)libxl_device_usbdev_type_union_hostdev;
21 typedef typeof(((struct libxl_device_channel *)NULL)->u.socket)libxl_device_channel_connection_union_socket;
22 typedef typeof(((struct libxl_event *)NULL)->u.domain_shutdown)libxl_event_type_union_domain_shutdown;
23 typedef typeof(((struct libxl_event *)NULL)->u.disk_eject)libxl_event_type_union_disk_eject;
24 typedef typeof(((struct libxl_event *)NULL)->u.operation_complete)libxl_event_type_union_operation_complete;
25 typedef typeof(((struct libxl_psr_hw_info *)NULL)->u.cat)libxl_psr_hw_info_type_union_cat;
26 typedef typeof(((struct libxl_psr_hw_info *)NULL)->u.mba)libxl_psr_hw_info_type_union_mba;
27 */
28 import "C"
29 // NewIoportRange returns an instance of IoportRange initialized with defaults.
30 func NewIoportRange() (*IoportRange, error) {
31 var (
32 x IoportRange
33 xc C.libxl_ioport_range)
34
35 C.libxl_ioport_range_init(&xc)
36 defer C.libxl_ioport_range_dispose(&xc)
37
38 if err := x.fromC(&xc); err != nil {
39 return nil, err }
40
41 return &x, nil}
42
43 func (x *IoportRange) fromC(xc *C.libxl_ioport_range) error {
44 x.First = uint32(xc.first)
45 x.Number = uint32(xc.number)
46
47 return nil}
48
49 func (x *IoportRange) toC(xc *C.libxl_ioport_range) (err error){defer func(){
50 if err != nil{
51 C.libxl_ioport_range_dispose(xc)}
52 }()
53
54 xc.first = C.uint32_t(x.First)
55 xc.number = C.uint32_t(x.Number)
56
57 return nil
58 }
59
60 // NewIomemRange returns an instance of IomemRange initialized with defaults.
61 func NewIomemRange() (*IomemRange, error) {
62 var (
63 x IomemRange
64 xc C.libxl_iomem_range)
65
66 C.libxl_iomem_range_init(&xc)
67 defer C.libxl_iomem_range_dispose(&xc)
68
69 if err := x.fromC(&xc); err != nil {
70 return nil, err }
71
72 return &x, nil}
73
74 func (x *IomemRange) fromC(xc *C.libxl_iomem_range) error {
75 x.Start = uint64(xc.start)
76 x.Number = uint64(xc.number)
77 x.Gfn = uint64(xc.gfn)
78
79 return nil}
80
81 func (x *IomemRange) toC(xc *C.libxl_iomem_range) (err error){defer func(){
82 if err != nil{
83 C.libxl_iomem_range_dispose(xc)}
84 }()
85
86 xc.start = C.uint64_t(x.Start)
87 xc.number = C.uint64_t(x.Number)
88 xc.gfn = C.uint64_t(x.Gfn)
89
90 return nil
91 }
92
93 // NewVgaInterfaceInfo returns an instance of VgaInterfaceInfo initialized with defaults.
94 func NewVgaInterfaceInfo() (*VgaInterfaceInfo, error) {
95 var (
96 x VgaInterfaceInfo
97 xc C.libxl_vga_interface_info)
98
99 C.libxl_vga_interface_info_init(&xc)
100 defer C.libxl_vga_interface_info_dispose(&xc)
101
102 if err := x.fromC(&xc); err != nil {
103 return nil, err }
104
105 return &x, nil}
106
107 func (x *VgaInterfaceInfo) fromC(xc *C.libxl_vga_interface_info) error {
108 x.Kind = VgaInterfaceType(xc.kind)
109
110 return nil}
111
112 func (x *VgaInterfaceInfo) toC(xc *C.libxl_vga_interface_info) (err error){defer func(){
113 if err != nil{
114 C.libxl_vga_interface_info_dispose(xc)}
115 }()
116
117 xc.kind = C.libxl_vga_interface_type(x.Kind)
118
119 return nil
120 }
121
122 // NewVncInfo returns an instance of VncInfo initialized with defaults.
123 func NewVncInfo() (*VncInfo, error) {
124 var (
125 x VncInfo
126 xc C.libxl_vnc_info)
127
128 C.libxl_vnc_info_init(&xc)
129 defer C.libxl_vnc_info_dispose(&xc)
130
131 if err := x.fromC(&xc); err != nil {
132 return nil, err }
133
134 return &x, nil}
135
136 func (x *VncInfo) fromC(xc *C.libxl_vnc_info) error {
137 if err := x.Enable.fromC(&xc.enable);err != nil {
138 return fmt.Errorf("converting field Enable: %v", err)
139 }
140 x.Listen = C.GoString(xc.listen)
141 x.Passwd = C.GoString(xc.passwd)
142 x.Display = int(xc.display)
143 if err := x.Findunused.fromC(&xc.findunused);err != nil {
144 return fmt.Errorf("converting field Findunused: %v", err)
145 }
146
147 return nil}
148
149 func (x *VncInfo) toC(xc *C.libxl_vnc_info) (err error){defer func(){
150 if err != nil{
151 C.libxl_vnc_info_dispose(xc)}
152 }()
153
154 if err := x.Enable.toC(&xc.enable); err != nil {
155 return fmt.Errorf("converting field Enable: %v", err)
156 }
157 if x.Listen != "" {
158 xc.listen = C.CString(x.Listen)}
159 if x.Passwd != "" {
160 xc.passwd = C.CString(x.Passwd)}
161 xc.display = C.int(x.Display)
162 if err := x.Findunused.toC(&xc.findunused); err != nil {
163 return fmt.Errorf("converting field Findunused: %v", err)
164 }
165
166 return nil
167 }
168
169 // NewSpiceInfo returns an instance of SpiceInfo initialized with defaults.
170 func NewSpiceInfo() (*SpiceInfo, error) {
171 var (
172 x SpiceInfo
173 xc C.libxl_spice_info)
174
175 C.libxl_spice_info_init(&xc)
176 defer C.libxl_spice_info_dispose(&xc)
177
178 if err := x.fromC(&xc); err != nil {
179 return nil, err }
180
181 return &x, nil}
182
183 func (x *SpiceInfo) fromC(xc *C.libxl_spice_info) error {
184 if err := x.Enable.fromC(&xc.enable);err != nil {
185 return fmt.Errorf("converting field Enable: %v", err)
186 }
187 x.Port = int(xc.port)
188 x.TlsPort = int(xc.tls_port)
189 x.Host = C.GoString(xc.host)
190 if err := x.DisableTicketing.fromC(&xc.disable_ticketing);err != nil {
191 return fmt.Errorf("converting field DisableTicketing: %v", err)
192 }
193 x.Passwd = C.GoString(xc.passwd)
194 if err := x.AgentMouse.fromC(&xc.agent_mouse);err != nil {
195 return fmt.Errorf("converting field AgentMouse: %v", err)
196 }
197 if err := x.Vdagent.fromC(&xc.vdagent);err != nil {
198 return fmt.Errorf("converting field Vdagent: %v", err)
199 }
200 if err := x.ClipboardSharing.fromC(&xc.clipboard_sharing);err != nil {
201 return fmt.Errorf("converting field ClipboardSharing: %v", err)
202 }
203 x.Usbredirection = int(xc.usbredirection)
204 x.ImageCompression = C.GoString(xc.image_compression)
205 x.StreamingVideo = C.GoString(xc.streaming_video)
206
207 return nil}
208
209 func (x *SpiceInfo) toC(xc *C.libxl_spice_info) (err error){defer func(){
210 if err != nil{
211 C.libxl_spice_info_dispose(xc)}
212 }()
213
214 if err := x.Enable.toC(&xc.enable); err != nil {
215 return fmt.Errorf("converting field Enable: %v", err)
216 }
217 xc.port = C.int(x.Port)
218 xc.tls_port = C.int(x.TlsPort)
219 if x.Host != "" {
220 xc.host = C.CString(x.Host)}
221 if err := x.DisableTicketing.toC(&xc.disable_ticketing); err != nil {
222 return fmt.Errorf("converting field DisableTicketing: %v", err)
223 }
224 if x.Passwd != "" {
225 xc.passwd = C.CString(x.Passwd)}
226 if err := x.AgentMouse.toC(&xc.agent_mouse); err != nil {
227 return fmt.Errorf("converting field AgentMouse: %v", err)
228 }
229 if err := x.Vdagent.toC(&xc.vdagent); err != nil {
230 return fmt.Errorf("converting field Vdagent: %v", err)
231 }
232 if err := x.ClipboardSharing.toC(&xc.clipboard_sharing); err != nil {
233 return fmt.Errorf("converting field ClipboardSharing: %v", err)
234 }
235 xc.usbredirection = C.int(x.Usbredirection)
236 if x.ImageCompression != "" {
237 xc.image_compression = C.CString(x.ImageCompression)}
238 if x.StreamingVideo != "" {
239 xc.streaming_video = C.CString(x.StreamingVideo)}
240
241 return nil
242 }
243
244 // NewSdlInfo returns an instance of SdlInfo initialized with defaults.
245 func NewSdlInfo() (*SdlInfo, error) {
246 var (
247 x SdlInfo
248 xc C.libxl_sdl_info)
249
250 C.libxl_sdl_info_init(&xc)
251 defer C.libxl_sdl_info_dispose(&xc)
252
253 if err := x.fromC(&xc); err != nil {
254 return nil, err }
255
256 return &x, nil}
257
258 func (x *SdlInfo) fromC(xc *C.libxl_sdl_info) error {
259 if err := x.Enable.fromC(&xc.enable);err != nil {
260 return fmt.Errorf("converting field Enable: %v", err)
261 }
262 if err := x.Opengl.fromC(&xc.opengl);err != nil {
263 return fmt.Errorf("converting field Opengl: %v", err)
264 }
265 x.Display = C.GoString(xc.display)
266 x.Xauthority = C.GoString(xc.xauthority)
267
268 return nil}
269
270 func (x *SdlInfo) toC(xc *C.libxl_sdl_info) (err error){defer func(){
271 if err != nil{
272 C.libxl_sdl_info_dispose(xc)}
273 }()
274
275 if err := x.Enable.toC(&xc.enable); err != nil {
276 return fmt.Errorf("converting field Enable: %v", err)
277 }
278 if err := x.Opengl.toC(&xc.opengl); err != nil {
279 return fmt.Errorf("converting field Opengl: %v", err)
280 }
281 if x.Display != "" {
282 xc.display = C.CString(x.Display)}
283 if x.Xauthority != "" {
284 xc.xauthority = C.CString(x.Xauthority)}
285
286 return nil
287 }
288
289 // NewDominfo returns an instance of Dominfo initialized with defaults.
290 func NewDominfo() (*Dominfo, error) {
291 var (
292 x Dominfo
293 xc C.libxl_dominfo)
294
295 C.libxl_dominfo_init(&xc)
296 defer C.libxl_dominfo_dispose(&xc)
297
298 if err := x.fromC(&xc); err != nil {
299 return nil, err }
300
301 return &x, nil}
302
303 func (x *Dominfo) fromC(xc *C.libxl_dominfo) error {
304 if err := x.Uuid.fromC(&xc.uuid);err != nil {
305 return fmt.Errorf("converting field Uuid: %v", err)
306 }
307 x.Domid = Domid(xc.domid)
308 x.Ssidref = uint32(xc.ssidref)
309 x.SsidLabel = C.GoString(xc.ssid_label)
310 x.Running = bool(xc.running)
311 x.Blocked = bool(xc.blocked)
312 x.Paused = bool(xc.paused)
313 x.Shutdown = bool(xc.shutdown)
314 x.Dying = bool(xc.dying)
315 x.NeverStop = bool(xc.never_stop)
316 x.ShutdownReason = ShutdownReason(xc.shutdown_reason)
317 x.OutstandingMemkb = uint64(xc.outstanding_memkb)
318 x.CurrentMemkb = uint64(xc.current_memkb)
319 x.SharedMemkb = uint64(xc.shared_memkb)
320 x.PagedMemkb = uint64(xc.paged_memkb)
321 x.MaxMemkb = uint64(xc.max_memkb)
322 x.CpuTime = uint64(xc.cpu_time)
323 x.VcpuMaxId = uint32(xc.vcpu_max_id)
324 x.VcpuOnline = uint32(xc.vcpu_online)
325 x.Cpupool = uint32(xc.cpupool)
326 x.GpaddrBits = byte(xc.gpaddr_bits)
327 x.DomainType = DomainType(xc.domain_type)
328
329 return nil}
330
331 func (x *Dominfo) toC(xc *C.libxl_dominfo) (err error){defer func(){
332 if err != nil{
333 C.libxl_dominfo_dispose(xc)}
334 }()
335
336 if err := x.Uuid.toC(&xc.uuid); err != nil {
337 return fmt.Errorf("converting field Uuid: %v", err)
338 }
339 xc.domid = C.libxl_domid(x.Domid)
340 xc.ssidref = C.uint32_t(x.Ssidref)
341 if x.SsidLabel != "" {
342 xc.ssid_label = C.CString(x.SsidLabel)}
343 xc.running = C.bool(x.Running)
344 xc.blocked = C.bool(x.Blocked)
345 xc.paused = C.bool(x.Paused)
346 xc.shutdown = C.bool(x.Shutdown)
347 xc.dying = C.bool(x.Dying)
348 xc.never_stop = C.bool(x.NeverStop)
349 xc.shutdown_reason = C.libxl_shutdown_reason(x.ShutdownReason)
350 xc.outstanding_memkb = C.uint64_t(x.OutstandingMemkb)
351 xc.current_memkb = C.uint64_t(x.CurrentMemkb)
352 xc.shared_memkb = C.uint64_t(x.SharedMemkb)
353 xc.paged_memkb = C.uint64_t(x.PagedMemkb)
354 xc.max_memkb = C.uint64_t(x.MaxMemkb)
355 xc.cpu_time = C.uint64_t(x.CpuTime)
356 xc.vcpu_max_id = C.uint32_t(x.VcpuMaxId)
357 xc.vcpu_online = C.uint32_t(x.VcpuOnline)
358 xc.cpupool = C.uint32_t(x.Cpupool)
359 xc.gpaddr_bits = C.uint8_t(x.GpaddrBits)
360 xc.domain_type = C.libxl_domain_type(x.DomainType)
361
362 return nil
363 }
364
365 // NewCpupoolinfo returns an instance of Cpupoolinfo initialized with defaults.
366 func NewCpupoolinfo() (*Cpupoolinfo, error) {
367 var (
368 x Cpupoolinfo
369 xc C.libxl_cpupoolinfo)
370
371 C.libxl_cpupoolinfo_init(&xc)
372 defer C.libxl_cpupoolinfo_dispose(&xc)
373
374 if err := x.fromC(&xc); err != nil {
375 return nil, err }
376
377 return &x, nil}
378
379 func (x *Cpupoolinfo) fromC(xc *C.libxl_cpupoolinfo) error {
380 x.Poolid = uint32(xc.poolid)
381 x.PoolName = C.GoString(xc.pool_name)
382 x.Sched = Scheduler(xc.sched)
383 x.NDom = uint32(xc.n_dom)
384 if err := x.Cpumap.fromC(&xc.cpumap);err != nil {
385 return fmt.Errorf("converting field Cpumap: %v", err)
386 }
387
388 return nil}
389
390 func (x *Cpupoolinfo) toC(xc *C.libxl_cpupoolinfo) (err error){defer func(){
391 if err != nil{
392 C.libxl_cpupoolinfo_dispose(xc)}
393 }()
394
395 xc.poolid = C.uint32_t(x.Poolid)
396 if x.PoolName != "" {
397 xc.pool_name = C.CString(x.PoolName)}
398 xc.sched = C.libxl_scheduler(x.Sched)
399 xc.n_dom = C.uint32_t(x.NDom)
400 if err := x.Cpumap.toC(&xc.cpumap); err != nil {
401 return fmt.Errorf("converting field Cpumap: %v", err)
402 }
403
404 return nil
405 }
406
407 // NewChannelinfo returns an instance of Channelinfo initialized with defaults.
408 func NewChannelinfo(connection ChannelConnection) (*Channelinfo, error) {
409 var (
410 x Channelinfo
411 xc C.libxl_channelinfo)
412
413 C.libxl_channelinfo_init(&xc)
414 C.libxl_channelinfo_init_connection(&xc, C.libxl_channel_connection(connection))
415 defer C.libxl_channelinfo_dispose(&xc)
416
417 if err := x.fromC(&xc); err != nil {
418 return nil, err }
419
420 return &x, nil}
421
422 func (x *Channelinfo) fromC(xc *C.libxl_channelinfo) error {
423 x.Backend = C.GoString(xc.backend)
424 x.BackendId = uint32(xc.backend_id)
425 x.Frontend = C.GoString(xc.frontend)
426 x.FrontendId = uint32(xc.frontend_id)
427 x.Devid = Devid(xc.devid)
428 x.State = int(xc.state)
429 x.Evtch = int(xc.evtch)
430 x.Rref = int(xc.rref)
431 x.Connection = ChannelConnection(xc.connection)
432 switch x.Connection{
433 case ChannelConnectionPty:
434 var connectionPty ChannelinfoConnectionUnionPty
435 if err := connectionPty.fromC(xc);err != nil {
436 return fmt.Errorf("converting field connectionPty: %v", err)
437 }
438 x.ConnectionUnion = &connectionPty
439 case ChannelConnectionSocket:
440 x.ConnectionUnion = nil
441 case ChannelConnectionUnknown:
442 x.ConnectionUnion = nil
443 default:
444 return fmt.Errorf("invalid union key '%v'", x.Connection)}
445
446 return nil}
447
448 func (x *ChannelinfoConnectionUnionPty) fromC(xc *C.libxl_channelinfo) error {
449 if ChannelConnection(xc.connection) != ChannelConnectionPty {
450 return errors.New("expected union key ChannelConnectionPty")
451 }
452
453 tmp := (*C.libxl_channelinfo_connection_union_pty)(unsafe.Pointer(&xc.u[0]))
454 x.Path = C.GoString(tmp.path)
455 return nil
456 }
457
458 func (x *Channelinfo) toC(xc *C.libxl_channelinfo) (err error){defer func(){
459 if err != nil{
460 C.libxl_channelinfo_dispose(xc)}
461 }()
462
463 if x.Backend != "" {
464 xc.backend = C.CString(x.Backend)}
465 xc.backend_id = C.uint32_t(x.BackendId)
466 if x.Frontend != "" {
467 xc.frontend = C.CString(x.Frontend)}
468 xc.frontend_id = C.uint32_t(x.FrontendId)
469 xc.devid = C.libxl_devid(x.Devid)
470 xc.state = C.int(x.State)
471 xc.evtch = C.int(x.Evtch)
472 xc.rref = C.int(x.Rref)
473 xc.connection = C.libxl_channel_connection(x.Connection)
474 switch x.Connection{
475 case ChannelConnectionUnknown:
476 break
477 case ChannelConnectionPty:
478 tmp, ok := x.ConnectionUnion.(*ChannelinfoConnectionUnionPty)
479 if !ok {
480 return errors.New("wrong type for union key connection")
481 }
482 var pty C.libxl_channelinfo_connection_union_pty
483 if tmp.Path != "" {
484 pty.path = C.CString(tmp.Path)}
485 ptyBytes := C.GoBytes(unsafe.Pointer(&pty),C.sizeof_libxl_channelinfo_connection_union_pty)
486 copy(xc.u[:],ptyBytes)
487 case ChannelConnectionSocket:
488 break
489 default:
490 return fmt.Errorf("invalid union key '%v'", x.Connection)}
491
492 return nil
493 }
494
495 // NewVminfo returns an instance of Vminfo initialized with defaults.
496 func NewVminfo() (*Vminfo, error) {
497 var (
498 x Vminfo
499 xc C.libxl_vminfo)
500
501 C.libxl_vminfo_init(&xc)
502 defer C.libxl_vminfo_dispose(&xc)
503
504 if err := x.fromC(&xc); err != nil {
505 return nil, err }
506
507 return &x, nil}
508
509 func (x *Vminfo) fromC(xc *C.libxl_vminfo) error {
510 if err := x.Uuid.fromC(&xc.uuid);err != nil {
511 return fmt.Errorf("converting field Uuid: %v", err)
512 }
513 x.Domid = Domid(xc.domid)
514
515 return nil}
516
517 func (x *Vminfo) toC(xc *C.libxl_vminfo) (err error){defer func(){
518 if err != nil{
519 C.libxl_vminfo_dispose(xc)}
520 }()
521
522 if err := x.Uuid.toC(&xc.uuid); err != nil {
523 return fmt.Errorf("converting field Uuid: %v", err)
524 }
525 xc.domid = C.libxl_domid(x.Domid)
526
527 return nil
528 }
529
530 // NewVersionInfo returns an instance of VersionInfo initialized with defaults.
531 func NewVersionInfo() (*VersionInfo, error) {
532 var (
533 x VersionInfo
534 xc C.libxl_version_info)
535
536 C.libxl_version_info_init(&xc)
537 defer C.libxl_version_info_dispose(&xc)
538
539 if err := x.fromC(&xc); err != nil {
540 return nil, err }
541
542 return &x, nil}
543
544 func (x *VersionInfo) fromC(xc *C.libxl_version_info) error {
545 x.XenVersionMajor = int(xc.xen_version_major)
546 x.XenVersionMinor = int(xc.xen_version_minor)
547 x.XenVersionExtra = C.GoString(xc.xen_version_extra)
548 x.Compiler = C.GoString(xc.compiler)
549 x.CompileBy = C.GoString(xc.compile_by)
550 x.CompileDomain = C.GoString(xc.compile_domain)
551 x.CompileDate = C.GoString(xc.compile_date)
552 x.Capabilities = C.GoString(xc.capabilities)
553 x.Changeset = C.GoString(xc.changeset)
554 x.VirtStart = uint64(xc.virt_start)
555 x.Pagesize = int(xc.pagesize)
556 x.Commandline = C.GoString(xc.commandline)
557 x.BuildId = C.GoString(xc.build_id)
558
559 return nil}
560
561 func (x *VersionInfo) toC(xc *C.libxl_version_info) (err error){defer func(){
562 if err != nil{
563 C.libxl_version_info_dispose(xc)}
564 }()
565
566 xc.xen_version_major = C.int(x.XenVersionMajor)
567 xc.xen_version_minor = C.int(x.XenVersionMinor)
568 if x.XenVersionExtra != "" {
569 xc.xen_version_extra = C.CString(x.XenVersionExtra)}
570 if x.Compiler != "" {
571 xc.compiler = C.CString(x.Compiler)}
572 if x.CompileBy != "" {
573 xc.compile_by = C.CString(x.CompileBy)}
574 if x.CompileDomain != "" {
575 xc.compile_domain = C.CString(x.CompileDomain)}
576 if x.CompileDate != "" {
577 xc.compile_date = C.CString(x.CompileDate)}
578 if x.Capabilities != "" {
579 xc.capabilities = C.CString(x.Capabilities)}
580 if x.Changeset != "" {
581 xc.changeset = C.CString(x.Changeset)}
582 xc.virt_start = C.uint64_t(x.VirtStart)
583 xc.pagesize = C.int(x.Pagesize)
584 if x.Commandline != "" {
585 xc.commandline = C.CString(x.Commandline)}
586 if x.BuildId != "" {
587 xc.build_id = C.CString(x.BuildId)}
588
589 return nil
590 }
591
592 // NewSmbios returns an instance of Smbios initialized with defaults.
593 func NewSmbios() (*Smbios, error) {
594 var (
595 x Smbios
596 xc C.libxl_smbios)
597
598 C.libxl_smbios_init(&xc)
599 defer C.libxl_smbios_dispose(&xc)
600
601 if err := x.fromC(&xc); err != nil {
602 return nil, err }
603
604 return &x, nil}
605
606 func (x *Smbios) fromC(xc *C.libxl_smbios) error {
607 x.Key = SmbiosType(xc.key)
608 x.Value = C.GoString(xc.value)
609
610 return nil}
611
612 func (x *Smbios) toC(xc *C.libxl_smbios) (err error){defer func(){
613 if err != nil{
614 C.libxl_smbios_dispose(xc)}
615 }()
616
617 xc.key = C.libxl_smbios_type(x.Key)
618 if x.Value != "" {
619 xc.value = C.CString(x.Value)}
620
621 return nil
622 }
623
624 // NewDomainCreateInfo returns an instance of DomainCreateInfo initialized with defaults.
625 func NewDomainCreateInfo() (*DomainCreateInfo, error) {
626 var (
627 x DomainCreateInfo
628 xc C.libxl_domain_create_info)
629
630 C.libxl_domain_create_info_init(&xc)
631 defer C.libxl_domain_create_info_dispose(&xc)
632
633 if err := x.fromC(&xc); err != nil {
634 return nil, err }
635
636 return &x, nil}
637
638 func (x *DomainCreateInfo) fromC(xc *C.libxl_domain_create_info) error {
639 x.Type = DomainType(xc._type)
640 if err := x.Hap.fromC(&xc.hap);err != nil {
641 return fmt.Errorf("converting field Hap: %v", err)
642 }
643 if err := x.Oos.fromC(&xc.oos);err != nil {
644 return fmt.Errorf("converting field Oos: %v", err)
645 }
646 x.Ssidref = uint32(xc.ssidref)
647 x.SsidLabel = C.GoString(xc.ssid_label)
648 x.Name = C.GoString(xc.name)
649 x.Domid = Domid(xc.domid)
650 if err := x.Uuid.fromC(&xc.uuid);err != nil {
651 return fmt.Errorf("converting field Uuid: %v", err)
652 }
653 if err := x.Xsdata.fromC(&xc.xsdata);err != nil {
654 return fmt.Errorf("converting field Xsdata: %v", err)
655 }
656 if err := x.Platformdata.fromC(&xc.platformdata);err != nil {
657 return fmt.Errorf("converting field Platformdata: %v", err)
658 }
659 x.Poolid = uint32(xc.poolid)
660 x.PoolName = C.GoString(xc.pool_name)
661 if err := x.RunHotplugScripts.fromC(&xc.run_hotplug_scripts);err != nil {
662 return fmt.Errorf("converting field RunHotplugScripts: %v", err)
663 }
664 if err := x.DriverDomain.fromC(&xc.driver_domain);err != nil {
665 return fmt.Errorf("converting field DriverDomain: %v", err)
666 }
667 x.Passthrough = Passthrough(xc.passthrough)
668 if err := x.XendSuspendEvtchnCompat.fromC(&xc.xend_suspend_evtchn_compat);err != nil {
669 return fmt.Errorf("converting field XendSuspendEvtchnCompat: %v", err)
670 }
671
672 return nil}
673
674 func (x *DomainCreateInfo) toC(xc *C.libxl_domain_create_info) (err error){defer func(){
675 if err != nil{
676 C.libxl_domain_create_info_dispose(xc)}
677 }()
678
679 xc._type = C.libxl_domain_type(x.Type)
680 if err := x.Hap.toC(&xc.hap); err != nil {
681 return fmt.Errorf("converting field Hap: %v", err)
682 }
683 if err := x.Oos.toC(&xc.oos); err != nil {
684 return fmt.Errorf("converting field Oos: %v", err)
685 }
686 xc.ssidref = C.uint32_t(x.Ssidref)
687 if x.SsidLabel != "" {
688 xc.ssid_label = C.CString(x.SsidLabel)}
689 if x.Name != "" {
690 xc.name = C.CString(x.Name)}
691 xc.domid = C.libxl_domid(x.Domid)
692 if err := x.Uuid.toC(&xc.uuid); err != nil {
693 return fmt.Errorf("converting field Uuid: %v", err)
694 }
695 if err := x.Xsdata.toC(&xc.xsdata); err != nil {
696 return fmt.Errorf("converting field Xsdata: %v", err)
697 }
698 if err := x.Platformdata.toC(&xc.platformdata); err != nil {
699 return fmt.Errorf("converting field Platformdata: %v", err)
700 }
701 xc.poolid = C.uint32_t(x.Poolid)
702 if x.PoolName != "" {
703 xc.pool_name = C.CString(x.PoolName)}
704 if err := x.RunHotplugScripts.toC(&xc.run_hotplug_scripts); err != nil {
705 return fmt.Errorf("converting field RunHotplugScripts: %v", err)
706 }
707 if err := x.DriverDomain.toC(&xc.driver_domain); err != nil {
708 return fmt.Errorf("converting field DriverDomain: %v", err)
709 }
710 xc.passthrough = C.libxl_passthrough(x.Passthrough)
711 if err := x.XendSuspendEvtchnCompat.toC(&xc.xend_suspend_evtchn_compat); err != nil {
712 return fmt.Errorf("converting field XendSuspendEvtchnCompat: %v", err)
713 }
714
715 return nil
716 }
717
718 // NewDomainRestoreParams returns an instance of DomainRestoreParams initialized with defaults.
719 func NewDomainRestoreParams() (*DomainRestoreParams, error) {
720 var (
721 x DomainRestoreParams
722 xc C.libxl_domain_restore_params)
723
724 C.libxl_domain_restore_params_init(&xc)
725 defer C.libxl_domain_restore_params_dispose(&xc)
726
727 if err := x.fromC(&xc); err != nil {
728 return nil, err }
729
730 return &x, nil}
731
732 func (x *DomainRestoreParams) fromC(xc *C.libxl_domain_restore_params) error {
733 x.CheckpointedStream = int(xc.checkpointed_stream)
734 x.StreamVersion = uint32(xc.stream_version)
735 x.ColoProxyScript = C.GoString(xc.colo_proxy_script)
736 if err := x.UserspaceColoProxy.fromC(&xc.userspace_colo_proxy);err != nil {
737 return fmt.Errorf("converting field UserspaceColoProxy: %v", err)
738 }
739
740 return nil}
741
742 func (x *DomainRestoreParams) toC(xc *C.libxl_domain_restore_params) (err error){defer func(){
743 if err != nil{
744 C.libxl_domain_restore_params_dispose(xc)}
745 }()
746
747 xc.checkpointed_stream = C.int(x.CheckpointedStream)
748 xc.stream_version = C.uint32_t(x.StreamVersion)
749 if x.ColoProxyScript != "" {
750 xc.colo_proxy_script = C.CString(x.ColoProxyScript)}
751 if err := x.UserspaceColoProxy.toC(&xc.userspace_colo_proxy); err != nil {
752 return fmt.Errorf("converting field UserspaceColoProxy: %v", err)
753 }
754
755 return nil
756 }
757
758 // NewSchedParams returns an instance of SchedParams initialized with defaults.
759 func NewSchedParams() (*SchedParams, error) {
760 var (
761 x SchedParams
762 xc C.libxl_sched_params)
763
764 C.libxl_sched_params_init(&xc)
765 defer C.libxl_sched_params_dispose(&xc)
766
767 if err := x.fromC(&xc); err != nil {
768 return nil, err }
769
770 return &x, nil}
771
772 func (x *SchedParams) fromC(xc *C.libxl_sched_params) error {
773 x.Vcpuid = int(xc.vcpuid)
774 x.Weight = int(xc.weight)
775 x.Cap = int(xc.cap)
776 x.Period = int(xc.period)
777 x.Extratime = int(xc.extratime)
778 x.Budget = int(xc.budget)
779
780 return nil}
781
782 func (x *SchedParams) toC(xc *C.libxl_sched_params) (err error){defer func(){
783 if err != nil{
784 C.libxl_sched_params_dispose(xc)}
785 }()
786
787 xc.vcpuid = C.int(x.Vcpuid)
788 xc.weight = C.int(x.Weight)
789 xc.cap = C.int(x.Cap)
790 xc.period = C.int(x.Period)
791 xc.extratime = C.int(x.Extratime)
792 xc.budget = C.int(x.Budget)
793
794 return nil
795 }
796
797 // NewVcpuSchedParams returns an instance of VcpuSchedParams initialized with defaults.
798 func NewVcpuSchedParams() (*VcpuSchedParams, error) {
799 var (
800 x VcpuSchedParams
801 xc C.libxl_vcpu_sched_params)
802
803 C.libxl_vcpu_sched_params_init(&xc)
804 defer C.libxl_vcpu_sched_params_dispose(&xc)
805
806 if err := x.fromC(&xc); err != nil {
807 return nil, err }
808
809 return &x, nil}
810
811 func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error {
812 x.Sched = Scheduler(xc.sched)
813 x.Vcpus = nil
814 if n := int(xc.num_vcpus); n > 0 {
815 cVcpus := (*[1<<28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:n:n]
816 x.Vcpus = make([]SchedParams, n)
817 for i, v := range cVcpus {
818 if err := x.Vcpus[i].fromC(&v); err != nil {
819 return fmt.Errorf("converting field Vcpus: %v", err) }
820 }
821 }
822
823 return nil}
824
825 func (x *VcpuSchedParams) toC(xc *C.libxl_vcpu_sched_params) (err error){defer func(){
826 if err != nil{
827 C.libxl_vcpu_sched_params_dispose(xc)}
828 }()
829
830 xc.sched = C.libxl_scheduler(x.Sched)
831 if numVcpus := len(x.Vcpus); numVcpus > 0 {
832 xc.vcpus = (*C.libxl_sched_params)(C.malloc(C.ulong(numVcpus)*C.sizeof_libxl_sched_params))
833 xc.num_vcpus = C.int(numVcpus)
834 cVcpus := (*[1<<28]C.libxl_sched_params)(unsafe.Pointer(xc.vcpus))[:numVcpus:numVcpus]
835 for i,v := range x.Vcpus {
836 if err := v.toC(&cVcpus[i]); err != nil {
837 return fmt.Errorf("converting field Vcpus: %v", err)
838 }
839 }
840 }
841
842 return nil
843 }
844
845 // NewDomainSchedParams returns an instance of DomainSchedParams initialized with defaults.
846 func NewDomainSchedParams() (*DomainSchedParams, error) {
847 var (
848 x DomainSchedParams
849 xc C.libxl_domain_sched_params)
850
851 C.libxl_domain_sched_params_init(&xc)
852 defer C.libxl_domain_sched_params_dispose(&xc)
853
854 if err := x.fromC(&xc); err != nil {
855 return nil, err }
856
857 return &x, nil}
858
859 func (x *DomainSchedParams) fromC(xc *C.libxl_domain_sched_params) error {
860 x.Sched = Scheduler(xc.sched)
861 x.Weight = int(xc.weight)
862 x.Cap = int(xc.cap)
863 x.Period = int(xc.period)
864 x.Budget = int(xc.budget)
865 x.Extratime = int(xc.extratime)
866 x.Slice = int(xc.slice)
867 x.Latency = int(xc.latency)
868
869 return nil}
870
871 func (x *DomainSchedParams) toC(xc *C.libxl_domain_sched_params) (err error){defer func(){
872 if err != nil{
873 C.libxl_domain_sched_params_dispose(xc)}
874 }()
875
876 xc.sched = C.libxl_scheduler(x.Sched)
877 xc.weight = C.int(x.Weight)
878 xc.cap = C.int(x.Cap)
879 xc.period = C.int(x.Period)
880 xc.budget = C.int(x.Budget)
881 xc.extratime = C.int(x.Extratime)
882 xc.slice = C.int(x.Slice)
883 xc.latency = C.int(x.Latency)
884
885 return nil
886 }
887
888 // NewVnodeInfo returns an instance of VnodeInfo initialized with defaults.
889 func NewVnodeInfo() (*VnodeInfo, error) {
890 var (
891 x VnodeInfo
892 xc C.libxl_vnode_info)
893
894 C.libxl_vnode_info_init(&xc)
895 defer C.libxl_vnode_info_dispose(&xc)
896
897 if err := x.fromC(&xc); err != nil {
898 return nil, err }
899
900 return &x, nil}
901
902 func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error {
903 x.Memkb = uint64(xc.memkb)
904 x.Distances = nil
905 if n := int(xc.num_distances); n > 0 {
906 cDistances := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.distances))[:n:n]
907 x.Distances = make([]uint32, n)
908 for i, v := range cDistances {
909 x.Distances[i] = uint32(v)
910 }
911 }
912 x.Pnode = uint32(xc.pnode)
913 if err := x.Vcpus.fromC(&xc.vcpus);err != nil {
914 return fmt.Errorf("converting field Vcpus: %v", err)
915 }
916
917 return nil}
918
919 func (x *VnodeInfo) toC(xc *C.libxl_vnode_info) (err error){defer func(){
920 if err != nil{
921 C.libxl_vnode_info_dispose(xc)}
922 }()
923
924 xc.memkb = C.uint64_t(x.Memkb)
925 if numDistances := len(x.Distances); numDistances > 0 {
926 xc.distances = (*C.uint32_t)(C.malloc(C.size_t(numDistances*numDistances)))
927 xc.num_distances = C.int(numDistances)
928 cDistances := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.distances))[:numDistances:numDistances]
929 for i,v := range x.Distances {
930 cDistances[i] = C.uint32_t(v)
931 }
932 }
933 xc.pnode = C.uint32_t(x.Pnode)
934 if err := x.Vcpus.toC(&xc.vcpus); err != nil {
935 return fmt.Errorf("converting field Vcpus: %v", err)
936 }
937
938 return nil
939 }
940
941 // NewRdmReserve returns an instance of RdmReserve initialized with defaults.
942 func NewRdmReserve() (*RdmReserve, error) {
943 var (
944 x RdmReserve
945 xc C.libxl_rdm_reserve)
946
947 C.libxl_rdm_reserve_init(&xc)
948 defer C.libxl_rdm_reserve_dispose(&xc)
949
950 if err := x.fromC(&xc); err != nil {
951 return nil, err }
952
953 return &x, nil}
954
955 func (x *RdmReserve) fromC(xc *C.libxl_rdm_reserve) error {
956 x.Strategy = RdmReserveStrategy(xc.strategy)
957 x.Policy = RdmReservePolicy(xc.policy)
958
959 return nil}
960
961 func (x *RdmReserve) toC(xc *C.libxl_rdm_reserve) (err error){defer func(){
962 if err != nil{
963 C.libxl_rdm_reserve_dispose(xc)}
964 }()
965
966 xc.strategy = C.libxl_rdm_reserve_strategy(x.Strategy)
967 xc.policy = C.libxl_rdm_reserve_policy(x.Policy)
968
969 return nil
970 }
971
972 // NewDomainBuildInfo returns an instance of DomainBuildInfo initialized with defaults.
973 func NewDomainBuildInfo(dtype DomainType) (*DomainBuildInfo, error) {
974 var (
975 x DomainBuildInfo
976 xc C.libxl_domain_build_info)
977
978 C.libxl_domain_build_info_init(&xc)
979 C.libxl_domain_build_info_init_type(&xc, C.libxl_domain_type(dtype))
980 defer C.libxl_domain_build_info_dispose(&xc)
981
982 if err := x.fromC(&xc); err != nil {
983 return nil, err }
984
985 return &x, nil}
986
987 func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error {
988 x.MaxVcpus = int(xc.max_vcpus)
989 if err := x.AvailVcpus.fromC(&xc.avail_vcpus);err != nil {
990 return fmt.Errorf("converting field AvailVcpus: %v", err)
991 }
992 if err := x.Cpumap.fromC(&xc.cpumap);err != nil {
993 return fmt.Errorf("converting field Cpumap: %v", err)
994 }
995 if err := x.Nodemap.fromC(&xc.nodemap);err != nil {
996 return fmt.Errorf("converting field Nodemap: %v", err)
997 }
998 x.VcpuHardAffinity = nil
999 if n := int(xc.num_vcpu_hard_affinity); n > 0 {
1000 cVcpuHardAffinity := (*[1<<28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:n:n]
1001 x.VcpuHardAffinity = make([]Bitmap, n)
1002 for i, v := range cVcpuHardAffinity {
1003 if err := x.VcpuHardAffinity[i].fromC(&v); err != nil {
1004 return fmt.Errorf("converting field VcpuHardAffinity: %v", err) }
1005 }
1006 }
1007 x.VcpuSoftAffinity = nil
1008 if n := int(xc.num_vcpu_soft_affinity); n > 0 {
1009 cVcpuSoftAffinity := (*[1<<28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:n:n]
1010 x.VcpuSoftAffinity = make([]Bitmap, n)
1011 for i, v := range cVcpuSoftAffinity {
1012 if err := x.VcpuSoftAffinity[i].fromC(&v); err != nil {
1013 return fmt.Errorf("converting field VcpuSoftAffinity: %v", err) }
1014 }
1015 }
1016 if err := x.NumaPlacement.fromC(&xc.numa_placement);err != nil {
1017 return fmt.Errorf("converting field NumaPlacement: %v", err)
1018 }
1019 x.TscMode = TscMode(xc.tsc_mode)
1020 x.MaxMemkb = uint64(xc.max_memkb)
1021 x.TargetMemkb = uint64(xc.target_memkb)
1022 x.VideoMemkb = uint64(xc.video_memkb)
1023 x.ShadowMemkb = uint64(xc.shadow_memkb)
1024 x.IommuMemkb = uint64(xc.iommu_memkb)
1025 x.RtcTimeoffset = uint32(xc.rtc_timeoffset)
1026 x.ExecSsidref = uint32(xc.exec_ssidref)
1027 x.ExecSsidLabel = C.GoString(xc.exec_ssid_label)
1028 if err := x.Localtime.fromC(&xc.localtime);err != nil {
1029 return fmt.Errorf("converting field Localtime: %v", err)
1030 }
1031 if err := x.DisableMigrate.fromC(&xc.disable_migrate);err != nil {
1032 return fmt.Errorf("converting field DisableMigrate: %v", err)
1033 }
1034 if err := x.Cpuid.fromC(&xc.cpuid);err != nil {
1035 return fmt.Errorf("converting field Cpuid: %v", err)
1036 }
1037 x.BlkdevStart = C.GoString(xc.blkdev_start)
1038 x.VnumaNodes = nil
1039 if n := int(xc.num_vnuma_nodes); n > 0 {
1040 cVnumaNodes := (*[1<<28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:n:n]
1041 x.VnumaNodes = make([]VnodeInfo, n)
1042 for i, v := range cVnumaNodes {
1043 if err := x.VnumaNodes[i].fromC(&v); err != nil {
1044 return fmt.Errorf("converting field VnumaNodes: %v", err) }
1045 }
1046 }
1047 x.MaxGrantFrames = uint32(xc.max_grant_frames)
1048 x.MaxMaptrackFrames = uint32(xc.max_maptrack_frames)
1049 x.MaxGrantVersion = int(xc.max_grant_version)
1050 x.DeviceModelVersion = DeviceModelVersion(xc.device_model_version)
1051 if err := x.DeviceModelStubdomain.fromC(&xc.device_model_stubdomain);err != nil {
1052 return fmt.Errorf("converting field DeviceModelStubdomain: %v", err)
1053 }
1054 x.StubdomainMemkb = uint64(xc.stubdomain_memkb)
1055 x.StubdomainKernel = C.GoString(xc.stubdomain_kernel)
1056 x.StubdomainCmdline = C.GoString(xc.stubdomain_cmdline)
1057 x.StubdomainRamdisk = C.GoString(xc.stubdomain_ramdisk)
1058 x.DeviceModel = C.GoString(xc.device_model)
1059 x.DeviceModelSsidref = uint32(xc.device_model_ssidref)
1060 x.DeviceModelSsidLabel = C.GoString(xc.device_model_ssid_label)
1061 x.DeviceModelUser = C.GoString(xc.device_model_user)
1062 if err := x.Extra.fromC(&xc.extra);err != nil {
1063 return fmt.Errorf("converting field Extra: %v", err)
1064 }
1065 if err := x.ExtraPv.fromC(&xc.extra_pv);err != nil {
1066 return fmt.Errorf("converting field ExtraPv: %v", err)
1067 }
1068 if err := x.ExtraHvm.fromC(&xc.extra_hvm);err != nil {
1069 return fmt.Errorf("converting field ExtraHvm: %v", err)
1070 }
1071 if err := x.SchedParams.fromC(&xc.sched_params);err != nil {
1072 return fmt.Errorf("converting field SchedParams: %v", err)
1073 }
1074 x.Ioports = nil
1075 if n := int(xc.num_ioports); n > 0 {
1076 cIoports := (*[1<<28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:n:n]
1077 x.Ioports = make([]IoportRange, n)
1078 for i, v := range cIoports {
1079 if err := x.Ioports[i].fromC(&v); err != nil {
1080 return fmt.Errorf("converting field Ioports: %v", err) }
1081 }
1082 }
1083 x.Irqs = nil
1084 if n := int(xc.num_irqs); n > 0 {
1085 cIrqs := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:n:n]
1086 x.Irqs = make([]uint32, n)
1087 for i, v := range cIrqs {
1088 x.Irqs[i] = uint32(v)
1089 }
1090 }
1091 x.Iomem = nil
1092 if n := int(xc.num_iomem); n > 0 {
1093 cIomem := (*[1<<28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:n:n]
1094 x.Iomem = make([]IomemRange, n)
1095 for i, v := range cIomem {
1096 if err := x.Iomem[i].fromC(&v); err != nil {
1097 return fmt.Errorf("converting field Iomem: %v", err) }
1098 }
1099 }
1100 x.LlcColors = nil
1101 if n := int(xc.num_llc_colors); n > 0 {
1102 cLlcColors := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.llc_colors))[:n:n]
1103 x.LlcColors = make([]uint32, n)
1104 for i, v := range cLlcColors {
1105 x.LlcColors[i] = uint32(v)
1106 }
1107 }
1108 if err := x.ClaimMode.fromC(&xc.claim_mode);err != nil {
1109 return fmt.Errorf("converting field ClaimMode: %v", err)
1110 }
1111 x.EventChannels = uint32(xc.event_channels)
1112 x.Kernel = C.GoString(xc.kernel)
1113 x.Cmdline = C.GoString(xc.cmdline)
1114 x.Ramdisk = C.GoString(xc.ramdisk)
1115 x.DeviceTree = C.GoString(xc.device_tree)
1116 if err := x.Acpi.fromC(&xc.acpi);err != nil {
1117 return fmt.Errorf("converting field Acpi: %v", err)
1118 }
1119 x.Bootloader = C.GoString(xc.bootloader)
1120 if err := x.BootloaderArgs.fromC(&xc.bootloader_args);err != nil {
1121 return fmt.Errorf("converting field BootloaderArgs: %v", err)
1122 }
1123 if err := x.BootloaderRestrict.fromC(&xc.bootloader_restrict);err != nil {
1124 return fmt.Errorf("converting field BootloaderRestrict: %v", err)
1125 }
1126 x.BootloaderUser = C.GoString(xc.bootloader_user)
1127 x.TimerMode = TimerMode(xc.timer_mode)
1128 if err := x.NestedHvm.fromC(&xc.nested_hvm);err != nil {
1129 return fmt.Errorf("converting field NestedHvm: %v", err)
1130 }
1131 if err := x.Apic.fromC(&xc.apic);err != nil {
1132 return fmt.Errorf("converting field Apic: %v", err)
1133 }
1134 if err := x.DmRestrict.fromC(&xc.dm_restrict);err != nil {
1135 return fmt.Errorf("converting field DmRestrict: %v", err)
1136 }
1137 x.Tee = TeeType(xc.tee)
1138 x.Type = DomainType(xc._type)
1139 switch x.Type{
1140 case DomainTypeHvm:
1141 var typeHvm DomainBuildInfoTypeUnionHvm
1142 if err := typeHvm.fromC(xc);err != nil {
1143 return fmt.Errorf("converting field typeHvm: %v", err)
1144 }
1145 x.TypeUnion = &typeHvm
1146 case DomainTypeInvalid:
1147 x.TypeUnion = nil
1148 case DomainTypePv:
1149 var typePv DomainBuildInfoTypeUnionPv
1150 if err := typePv.fromC(xc);err != nil {
1151 return fmt.Errorf("converting field typePv: %v", err)
1152 }
1153 x.TypeUnion = &typePv
1154 case DomainTypePvh:
1155 var typePvh DomainBuildInfoTypeUnionPvh
1156 if err := typePvh.fromC(xc);err != nil {
1157 return fmt.Errorf("converting field typePvh: %v", err)
1158 }
1159 x.TypeUnion = &typePvh
1160 default:
1161 return fmt.Errorf("invalid union key '%v'", x.Type)}
1162 x.ArchArm.GicVersion = GicVersion(xc.arch_arm.gic_version)
1163 x.ArchArm.Vuart = VuartType(xc.arch_arm.vuart)
1164 x.ArchArm.SveVl = SveType(xc.arch_arm.sve_vl)
1165 x.ArchArm.NrSpis = uint32(xc.arch_arm.nr_spis)
1166 if err := x.ArchX86.MsrRelaxed.fromC(&xc.arch_x86.msr_relaxed);err != nil {
1167 return fmt.Errorf("converting field ArchX86.MsrRelaxed: %v", err)
1168 }
1169 x.Altp2M = Altp2MMode(xc.altp2m)
1170 x.VmtraceBufKb = int(xc.vmtrace_buf_kb)
1171 if err := x.Vpmu.fromC(&xc.vpmu);err != nil {
1172 return fmt.Errorf("converting field Vpmu: %v", err)
1173 }
1174
1175 return nil}
1176
1177 func (x *DomainBuildInfoTypeUnionHvm) fromC(xc *C.libxl_domain_build_info) error {
1178 if DomainType(xc._type) != DomainTypeHvm {
1179 return errors.New("expected union key DomainTypeHvm")
1180 }
1181
1182 tmp := (*C.libxl_domain_build_info_type_union_hvm)(unsafe.Pointer(&xc.u[0]))
1183 x.Firmware = C.GoString(tmp.firmware)
1184 x.Bios = BiosType(tmp.bios)
1185 if err := x.Pae.fromC(&tmp.pae);err != nil {
1186 return fmt.Errorf("converting field Pae: %v", err)
1187 }
1188 if err := x.Apic.fromC(&tmp.apic);err != nil {
1189 return fmt.Errorf("converting field Apic: %v", err)
1190 }
1191 if err := x.Acpi.fromC(&tmp.acpi);err != nil {
1192 return fmt.Errorf("converting field Acpi: %v", err)
1193 }
1194 if err := x.AcpiS3.fromC(&tmp.acpi_s3);err != nil {
1195 return fmt.Errorf("converting field AcpiS3: %v", err)
1196 }
1197 if err := x.AcpiS4.fromC(&tmp.acpi_s4);err != nil {
1198 return fmt.Errorf("converting field AcpiS4: %v", err)
1199 }
1200 if err := x.AcpiLaptopSlate.fromC(&tmp.acpi_laptop_slate);err != nil {
1201 return fmt.Errorf("converting field AcpiLaptopSlate: %v", err)
1202 }
1203 if err := x.Nx.fromC(&tmp.nx);err != nil {
1204 return fmt.Errorf("converting field Nx: %v", err)
1205 }
1206 if err := x.Viridian.fromC(&tmp.viridian);err != nil {
1207 return fmt.Errorf("converting field Viridian: %v", err)
1208 }
1209 if err := x.ViridianEnable.fromC(&tmp.viridian_enable);err != nil {
1210 return fmt.Errorf("converting field ViridianEnable: %v", err)
1211 }
1212 if err := x.ViridianDisable.fromC(&tmp.viridian_disable);err != nil {
1213 return fmt.Errorf("converting field ViridianDisable: %v", err)
1214 }
1215 x.Timeoffset = C.GoString(tmp.timeoffset)
1216 if err := x.Hpet.fromC(&tmp.hpet);err != nil {
1217 return fmt.Errorf("converting field Hpet: %v", err)
1218 }
1219 if err := x.VptAlign.fromC(&tmp.vpt_align);err != nil {
1220 return fmt.Errorf("converting field VptAlign: %v", err)
1221 }
1222 x.MmioHoleMemkb = uint64(tmp.mmio_hole_memkb)
1223 x.TimerMode = TimerMode(tmp.timer_mode)
1224 if err := x.NestedHvm.fromC(&tmp.nested_hvm);err != nil {
1225 return fmt.Errorf("converting field NestedHvm: %v", err)
1226 }
1227 if err := x.Altp2M.fromC(&tmp.altp2m);err != nil {
1228 return fmt.Errorf("converting field Altp2M: %v", err)
1229 }
1230 x.SystemFirmware = C.GoString(tmp.system_firmware)
1231 x.SmbiosFirmware = C.GoString(tmp.smbios_firmware)
1232 x.Smbios = nil
1233 if n := int(tmp.num_smbios); n > 0 {
1234 cSmbios := (*[1<<28]C.libxl_smbios)(unsafe.Pointer(tmp.smbios))[:n:n]
1235 x.Smbios = make([]Smbios, n)
1236 for i, v := range cSmbios {
1237 if err := x.Smbios[i].fromC(&v); err != nil {
1238 return fmt.Errorf("converting field Smbios: %v", err) }
1239 }
1240 }
1241 x.AcpiFirmware = C.GoString(tmp.acpi_firmware)
1242 x.Hdtype = Hdtype(tmp.hdtype)
1243 if err := x.Nographic.fromC(&tmp.nographic);err != nil {
1244 return fmt.Errorf("converting field Nographic: %v", err)
1245 }
1246 if err := x.Vga.fromC(&tmp.vga);err != nil {
1247 return fmt.Errorf("converting field Vga: %v", err)
1248 }
1249 if err := x.Vnc.fromC(&tmp.vnc);err != nil {
1250 return fmt.Errorf("converting field Vnc: %v", err)
1251 }
1252 x.Keymap = C.GoString(tmp.keymap)
1253 if err := x.Sdl.fromC(&tmp.sdl);err != nil {
1254 return fmt.Errorf("converting field Sdl: %v", err)
1255 }
1256 if err := x.Spice.fromC(&tmp.spice);err != nil {
1257 return fmt.Errorf("converting field Spice: %v", err)
1258 }
1259 if err := x.GfxPassthru.fromC(&tmp.gfx_passthru);err != nil {
1260 return fmt.Errorf("converting field GfxPassthru: %v", err)
1261 }
1262 x.GfxPassthruKind = GfxPassthruKind(tmp.gfx_passthru_kind)
1263 x.Serial = C.GoString(tmp.serial)
1264 x.Boot = C.GoString(tmp.boot)
1265 if err := x.Usb.fromC(&tmp.usb);err != nil {
1266 return fmt.Errorf("converting field Usb: %v", err)
1267 }
1268 x.Usbversion = int(tmp.usbversion)
1269 x.Usbdevice = C.GoString(tmp.usbdevice)
1270 if err := x.VkbDevice.fromC(&tmp.vkb_device);err != nil {
1271 return fmt.Errorf("converting field VkbDevice: %v", err)
1272 }
1273 x.Soundhw = C.GoString(tmp.soundhw)
1274 if err := x.XenPlatformPci.fromC(&tmp.xen_platform_pci);err != nil {
1275 return fmt.Errorf("converting field XenPlatformPci: %v", err)
1276 }
1277 if err := x.UsbdeviceList.fromC(&tmp.usbdevice_list);err != nil {
1278 return fmt.Errorf("converting field UsbdeviceList: %v", err)
1279 }
1280 x.VendorDevice = VendorDevice(tmp.vendor_device)
1281 if err := x.MsVmGenid.fromC(&tmp.ms_vm_genid);err != nil {
1282 return fmt.Errorf("converting field MsVmGenid: %v", err)
1283 }
1284 if err := x.SerialList.fromC(&tmp.serial_list);err != nil {
1285 return fmt.Errorf("converting field SerialList: %v", err)
1286 }
1287 if err := x.Rdm.fromC(&tmp.rdm);err != nil {
1288 return fmt.Errorf("converting field Rdm: %v", err)
1289 }
1290 x.RdmMemBoundaryMemkb = uint64(tmp.rdm_mem_boundary_memkb)
1291 x.McaCaps = uint64(tmp.mca_caps)
1292 if err := x.Pirq.fromC(&tmp.pirq);err != nil {
1293 return fmt.Errorf("converting field Pirq: %v", err)
1294 }
1295 return nil
1296 }
1297
1298 func (x *DomainBuildInfoTypeUnionPv) fromC(xc *C.libxl_domain_build_info) error {
1299 if DomainType(xc._type) != DomainTypePv {
1300 return errors.New("expected union key DomainTypePv")
1301 }
1302
1303 tmp := (*C.libxl_domain_build_info_type_union_pv)(unsafe.Pointer(&xc.u[0]))
1304 x.Kernel = C.GoString(tmp.kernel)
1305 x.SlackMemkb = uint64(tmp.slack_memkb)
1306 x.Bootloader = C.GoString(tmp.bootloader)
1307 if err := x.BootloaderArgs.fromC(&tmp.bootloader_args);err != nil {
1308 return fmt.Errorf("converting field BootloaderArgs: %v", err)
1309 }
1310 x.Cmdline = C.GoString(tmp.cmdline)
1311 x.Ramdisk = C.GoString(tmp.ramdisk)
1312 x.Features = C.GoString(tmp.features)
1313 if err := x.E820Host.fromC(&tmp.e820_host);err != nil {
1314 return fmt.Errorf("converting field E820Host: %v", err)
1315 }
1316 return nil
1317 }
1318
1319 func (x *DomainBuildInfoTypeUnionPvh) fromC(xc *C.libxl_domain_build_info) error {
1320 if DomainType(xc._type) != DomainTypePvh {
1321 return errors.New("expected union key DomainTypePvh")
1322 }
1323
1324 tmp := (*C.libxl_domain_build_info_type_union_pvh)(unsafe.Pointer(&xc.u[0]))
1325 if err := x.Pvshim.fromC(&tmp.pvshim);err != nil {
1326 return fmt.Errorf("converting field Pvshim: %v", err)
1327 }
1328 x.PvshimPath = C.GoString(tmp.pvshim_path)
1329 x.PvshimCmdline = C.GoString(tmp.pvshim_cmdline)
1330 x.PvshimExtra = C.GoString(tmp.pvshim_extra)
1331 return nil
1332 }
1333
1334 func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error){defer func(){
1335 if err != nil{
1336 C.libxl_domain_build_info_dispose(xc)}
1337 }()
1338
1339 xc.max_vcpus = C.int(x.MaxVcpus)
1340 if err := x.AvailVcpus.toC(&xc.avail_vcpus); err != nil {
1341 return fmt.Errorf("converting field AvailVcpus: %v", err)
1342 }
1343 if err := x.Cpumap.toC(&xc.cpumap); err != nil {
1344 return fmt.Errorf("converting field Cpumap: %v", err)
1345 }
1346 if err := x.Nodemap.toC(&xc.nodemap); err != nil {
1347 return fmt.Errorf("converting field Nodemap: %v", err)
1348 }
1349 if numVcpuHardAffinity := len(x.VcpuHardAffinity); numVcpuHardAffinity > 0 {
1350 xc.vcpu_hard_affinity = (*C.libxl_bitmap)(C.malloc(C.ulong(numVcpuHardAffinity)*C.sizeof_libxl_bitmap))
1351 xc.num_vcpu_hard_affinity = C.int(numVcpuHardAffinity)
1352 cVcpuHardAffinity := (*[1<<28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_hard_affinity))[:numVcpuHardAffinity:numVcpuHardAffinity]
1353 for i,v := range x.VcpuHardAffinity {
1354 if err := v.toC(&cVcpuHardAffinity[i]); err != nil {
1355 return fmt.Errorf("converting field VcpuHardAffinity: %v", err)
1356 }
1357 }
1358 }
1359 if numVcpuSoftAffinity := len(x.VcpuSoftAffinity); numVcpuSoftAffinity > 0 {
1360 xc.vcpu_soft_affinity = (*C.libxl_bitmap)(C.malloc(C.ulong(numVcpuSoftAffinity)*C.sizeof_libxl_bitmap))
1361 xc.num_vcpu_soft_affinity = C.int(numVcpuSoftAffinity)
1362 cVcpuSoftAffinity := (*[1<<28]C.libxl_bitmap)(unsafe.Pointer(xc.vcpu_soft_affinity))[:numVcpuSoftAffinity:numVcpuSoftAffinity]
1363 for i,v := range x.VcpuSoftAffinity {
1364 if err := v.toC(&cVcpuSoftAffinity[i]); err != nil {
1365 return fmt.Errorf("converting field VcpuSoftAffinity: %v", err)
1366 }
1367 }
1368 }
1369 if err := x.NumaPlacement.toC(&xc.numa_placement); err != nil {
1370 return fmt.Errorf("converting field NumaPlacement: %v", err)
1371 }
1372 xc.tsc_mode = C.libxl_tsc_mode(x.TscMode)
1373 xc.max_memkb = C.uint64_t(x.MaxMemkb)
1374 xc.target_memkb = C.uint64_t(x.TargetMemkb)
1375 xc.video_memkb = C.uint64_t(x.VideoMemkb)
1376 xc.shadow_memkb = C.uint64_t(x.ShadowMemkb)
1377 xc.iommu_memkb = C.uint64_t(x.IommuMemkb)
1378 xc.rtc_timeoffset = C.uint32_t(x.RtcTimeoffset)
1379 xc.exec_ssidref = C.uint32_t(x.ExecSsidref)
1380 if x.ExecSsidLabel != "" {
1381 xc.exec_ssid_label = C.CString(x.ExecSsidLabel)}
1382 if err := x.Localtime.toC(&xc.localtime); err != nil {
1383 return fmt.Errorf("converting field Localtime: %v", err)
1384 }
1385 if err := x.DisableMigrate.toC(&xc.disable_migrate); err != nil {
1386 return fmt.Errorf("converting field DisableMigrate: %v", err)
1387 }
1388 if err := x.Cpuid.toC(&xc.cpuid); err != nil {
1389 return fmt.Errorf("converting field Cpuid: %v", err)
1390 }
1391 if x.BlkdevStart != "" {
1392 xc.blkdev_start = C.CString(x.BlkdevStart)}
1393 if numVnumaNodes := len(x.VnumaNodes); numVnumaNodes > 0 {
1394 xc.vnuma_nodes = (*C.libxl_vnode_info)(C.malloc(C.ulong(numVnumaNodes)*C.sizeof_libxl_vnode_info))
1395 xc.num_vnuma_nodes = C.int(numVnumaNodes)
1396 cVnumaNodes := (*[1<<28]C.libxl_vnode_info)(unsafe.Pointer(xc.vnuma_nodes))[:numVnumaNodes:numVnumaNodes]
1397 for i,v := range x.VnumaNodes {
1398 if err := v.toC(&cVnumaNodes[i]); err != nil {
1399 return fmt.Errorf("converting field VnumaNodes: %v", err)
1400 }
1401 }
1402 }
1403 xc.max_grant_frames = C.uint32_t(x.MaxGrantFrames)
1404 xc.max_maptrack_frames = C.uint32_t(x.MaxMaptrackFrames)
1405 xc.max_grant_version = C.int(x.MaxGrantVersion)
1406 xc.device_model_version = C.libxl_device_model_version(x.DeviceModelVersion)
1407 if err := x.DeviceModelStubdomain.toC(&xc.device_model_stubdomain); err != nil {
1408 return fmt.Errorf("converting field DeviceModelStubdomain: %v", err)
1409 }
1410 xc.stubdomain_memkb = C.uint64_t(x.StubdomainMemkb)
1411 if x.StubdomainKernel != "" {
1412 xc.stubdomain_kernel = C.CString(x.StubdomainKernel)}
1413 if x.StubdomainCmdline != "" {
1414 xc.stubdomain_cmdline = C.CString(x.StubdomainCmdline)}
1415 if x.StubdomainRamdisk != "" {
1416 xc.stubdomain_ramdisk = C.CString(x.StubdomainRamdisk)}
1417 if x.DeviceModel != "" {
1418 xc.device_model = C.CString(x.DeviceModel)}
1419 xc.device_model_ssidref = C.uint32_t(x.DeviceModelSsidref)
1420 if x.DeviceModelSsidLabel != "" {
1421 xc.device_model_ssid_label = C.CString(x.DeviceModelSsidLabel)}
1422 if x.DeviceModelUser != "" {
1423 xc.device_model_user = C.CString(x.DeviceModelUser)}
1424 if err := x.Extra.toC(&xc.extra); err != nil {
1425 return fmt.Errorf("converting field Extra: %v", err)
1426 }
1427 if err := x.ExtraPv.toC(&xc.extra_pv); err != nil {
1428 return fmt.Errorf("converting field ExtraPv: %v", err)
1429 }
1430 if err := x.ExtraHvm.toC(&xc.extra_hvm); err != nil {
1431 return fmt.Errorf("converting field ExtraHvm: %v", err)
1432 }
1433 if err := x.SchedParams.toC(&xc.sched_params); err != nil {
1434 return fmt.Errorf("converting field SchedParams: %v", err)
1435 }
1436 if numIoports := len(x.Ioports); numIoports > 0 {
1437 xc.ioports = (*C.libxl_ioport_range)(C.malloc(C.ulong(numIoports)*C.sizeof_libxl_ioport_range))
1438 xc.num_ioports = C.int(numIoports)
1439 cIoports := (*[1<<28]C.libxl_ioport_range)(unsafe.Pointer(xc.ioports))[:numIoports:numIoports]
1440 for i,v := range x.Ioports {
1441 if err := v.toC(&cIoports[i]); err != nil {
1442 return fmt.Errorf("converting field Ioports: %v", err)
1443 }
1444 }
1445 }
1446 if numIrqs := len(x.Irqs); numIrqs > 0 {
1447 xc.irqs = (*C.uint32_t)(C.malloc(C.size_t(numIrqs*numIrqs)))
1448 xc.num_irqs = C.int(numIrqs)
1449 cIrqs := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.irqs))[:numIrqs:numIrqs]
1450 for i,v := range x.Irqs {
1451 cIrqs[i] = C.uint32_t(v)
1452 }
1453 }
1454 if numIomem := len(x.Iomem); numIomem > 0 {
1455 xc.iomem = (*C.libxl_iomem_range)(C.malloc(C.ulong(numIomem)*C.sizeof_libxl_iomem_range))
1456 xc.num_iomem = C.int(numIomem)
1457 cIomem := (*[1<<28]C.libxl_iomem_range)(unsafe.Pointer(xc.iomem))[:numIomem:numIomem]
1458 for i,v := range x.Iomem {
1459 if err := v.toC(&cIomem[i]); err != nil {
1460 return fmt.Errorf("converting field Iomem: %v", err)
1461 }
1462 }
1463 }
1464 if numLlcColors := len(x.LlcColors); numLlcColors > 0 {
1465 xc.llc_colors = (*C.uint32_t)(C.malloc(C.size_t(numLlcColors*numLlcColors)))
1466 xc.num_llc_colors = C.int(numLlcColors)
1467 cLlcColors := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.llc_colors))[:numLlcColors:numLlcColors]
1468 for i,v := range x.LlcColors {
1469 cLlcColors[i] = C.uint32_t(v)
1470 }
1471 }
1472 if err := x.ClaimMode.toC(&xc.claim_mode); err != nil {
1473 return fmt.Errorf("converting field ClaimMode: %v", err)
1474 }
1475 xc.event_channels = C.uint32_t(x.EventChannels)
1476 if x.Kernel != "" {
1477 xc.kernel = C.CString(x.Kernel)}
1478 if x.Cmdline != "" {
1479 xc.cmdline = C.CString(x.Cmdline)}
1480 if x.Ramdisk != "" {
1481 xc.ramdisk = C.CString(x.Ramdisk)}
1482 if x.DeviceTree != "" {
1483 xc.device_tree = C.CString(x.DeviceTree)}
1484 if err := x.Acpi.toC(&xc.acpi); err != nil {
1485 return fmt.Errorf("converting field Acpi: %v", err)
1486 }
1487 if x.Bootloader != "" {
1488 xc.bootloader = C.CString(x.Bootloader)}
1489 if err := x.BootloaderArgs.toC(&xc.bootloader_args); err != nil {
1490 return fmt.Errorf("converting field BootloaderArgs: %v", err)
1491 }
1492 if err := x.BootloaderRestrict.toC(&xc.bootloader_restrict); err != nil {
1493 return fmt.Errorf("converting field BootloaderRestrict: %v", err)
1494 }
1495 if x.BootloaderUser != "" {
1496 xc.bootloader_user = C.CString(x.BootloaderUser)}
1497 xc.timer_mode = C.libxl_timer_mode(x.TimerMode)
1498 if err := x.NestedHvm.toC(&xc.nested_hvm); err != nil {
1499 return fmt.Errorf("converting field NestedHvm: %v", err)
1500 }
1501 if err := x.Apic.toC(&xc.apic); err != nil {
1502 return fmt.Errorf("converting field Apic: %v", err)
1503 }
1504 if err := x.DmRestrict.toC(&xc.dm_restrict); err != nil {
1505 return fmt.Errorf("converting field DmRestrict: %v", err)
1506 }
1507 xc.tee = C.libxl_tee_type(x.Tee)
1508 xc._type = C.libxl_domain_type(x.Type)
1509 switch x.Type{
1510 case DomainTypeHvm:
1511 tmp, ok := x.TypeUnion.(*DomainBuildInfoTypeUnionHvm)
1512 if !ok {
1513 return errors.New("wrong type for union key type")
1514 }
1515 var hvm C.libxl_domain_build_info_type_union_hvm
1516 if tmp.Firmware != "" {
1517 hvm.firmware = C.CString(tmp.Firmware)}
1518 hvm.bios = C.libxl_bios_type(tmp.Bios)
1519 if err := tmp.Pae.toC(&hvm.pae); err != nil {
1520 return fmt.Errorf("converting field Pae: %v", err)
1521 }
1522 if err := tmp.Apic.toC(&hvm.apic); err != nil {
1523 return fmt.Errorf("converting field Apic: %v", err)
1524 }
1525 if err := tmp.Acpi.toC(&hvm.acpi); err != nil {
1526 return fmt.Errorf("converting field Acpi: %v", err)
1527 }
1528 if err := tmp.AcpiS3.toC(&hvm.acpi_s3); err != nil {
1529 return fmt.Errorf("converting field AcpiS3: %v", err)
1530 }
1531 if err := tmp.AcpiS4.toC(&hvm.acpi_s4); err != nil {
1532 return fmt.Errorf("converting field AcpiS4: %v", err)
1533 }
1534 if err := tmp.AcpiLaptopSlate.toC(&hvm.acpi_laptop_slate); err != nil {
1535 return fmt.Errorf("converting field AcpiLaptopSlate: %v", err)
1536 }
1537 if err := tmp.Nx.toC(&hvm.nx); err != nil {
1538 return fmt.Errorf("converting field Nx: %v", err)
1539 }
1540 if err := tmp.Viridian.toC(&hvm.viridian); err != nil {
1541 return fmt.Errorf("converting field Viridian: %v", err)
1542 }
1543 if err := tmp.ViridianEnable.toC(&hvm.viridian_enable); err != nil {
1544 return fmt.Errorf("converting field ViridianEnable: %v", err)
1545 }
1546 if err := tmp.ViridianDisable.toC(&hvm.viridian_disable); err != nil {
1547 return fmt.Errorf("converting field ViridianDisable: %v", err)
1548 }
1549 if tmp.Timeoffset != "" {
1550 hvm.timeoffset = C.CString(tmp.Timeoffset)}
1551 if err := tmp.Hpet.toC(&hvm.hpet); err != nil {
1552 return fmt.Errorf("converting field Hpet: %v", err)
1553 }
1554 if err := tmp.VptAlign.toC(&hvm.vpt_align); err != nil {
1555 return fmt.Errorf("converting field VptAlign: %v", err)
1556 }
1557 hvm.mmio_hole_memkb = C.uint64_t(tmp.MmioHoleMemkb)
1558 hvm.timer_mode = C.libxl_timer_mode(tmp.TimerMode)
1559 if err := tmp.NestedHvm.toC(&hvm.nested_hvm); err != nil {
1560 return fmt.Errorf("converting field NestedHvm: %v", err)
1561 }
1562 if err := tmp.Altp2M.toC(&hvm.altp2m); err != nil {
1563 return fmt.Errorf("converting field Altp2M: %v", err)
1564 }
1565 if tmp.SystemFirmware != "" {
1566 hvm.system_firmware = C.CString(tmp.SystemFirmware)}
1567 if tmp.SmbiosFirmware != "" {
1568 hvm.smbios_firmware = C.CString(tmp.SmbiosFirmware)}
1569 if numSmbios := len(tmp.Smbios); numSmbios > 0 {
1570 hvm.smbios = (*C.libxl_smbios)(C.malloc(C.ulong(numSmbios)*C.sizeof_libxl_smbios))
1571 hvm.num_smbios = C.int(numSmbios)
1572 cSmbios := (*[1<<28]C.libxl_smbios)(unsafe.Pointer(hvm.smbios))[:numSmbios:numSmbios]
1573 for i,v := range tmp.Smbios {
1574 if err := v.toC(&cSmbios[i]); err != nil {
1575 return fmt.Errorf("converting field Smbios: %v", err)
1576 }
1577 }
1578 }
1579 if tmp.AcpiFirmware != "" {
1580 hvm.acpi_firmware = C.CString(tmp.AcpiFirmware)}
1581 hvm.hdtype = C.libxl_hdtype(tmp.Hdtype)
1582 if err := tmp.Nographic.toC(&hvm.nographic); err != nil {
1583 return fmt.Errorf("converting field Nographic: %v", err)
1584 }
1585 if err := tmp.Vga.toC(&hvm.vga); err != nil {
1586 return fmt.Errorf("converting field Vga: %v", err)
1587 }
1588 if err := tmp.Vnc.toC(&hvm.vnc); err != nil {
1589 return fmt.Errorf("converting field Vnc: %v", err)
1590 }
1591 if tmp.Keymap != "" {
1592 hvm.keymap = C.CString(tmp.Keymap)}
1593 if err := tmp.Sdl.toC(&hvm.sdl); err != nil {
1594 return fmt.Errorf("converting field Sdl: %v", err)
1595 }
1596 if err := tmp.Spice.toC(&hvm.spice); err != nil {
1597 return fmt.Errorf("converting field Spice: %v", err)
1598 }
1599 if err := tmp.GfxPassthru.toC(&hvm.gfx_passthru); err != nil {
1600 return fmt.Errorf("converting field GfxPassthru: %v", err)
1601 }
1602 hvm.gfx_passthru_kind = C.libxl_gfx_passthru_kind(tmp.GfxPassthruKind)
1603 if tmp.Serial != "" {
1604 hvm.serial = C.CString(tmp.Serial)}
1605 if tmp.Boot != "" {
1606 hvm.boot = C.CString(tmp.Boot)}
1607 if err := tmp.Usb.toC(&hvm.usb); err != nil {
1608 return fmt.Errorf("converting field Usb: %v", err)
1609 }
1610 hvm.usbversion = C.int(tmp.Usbversion)
1611 if tmp.Usbdevice != "" {
1612 hvm.usbdevice = C.CString(tmp.Usbdevice)}
1613 if err := tmp.VkbDevice.toC(&hvm.vkb_device); err != nil {
1614 return fmt.Errorf("converting field VkbDevice: %v", err)
1615 }
1616 if tmp.Soundhw != "" {
1617 hvm.soundhw = C.CString(tmp.Soundhw)}
1618 if err := tmp.XenPlatformPci.toC(&hvm.xen_platform_pci); err != nil {
1619 return fmt.Errorf("converting field XenPlatformPci: %v", err)
1620 }
1621 if err := tmp.UsbdeviceList.toC(&hvm.usbdevice_list); err != nil {
1622 return fmt.Errorf("converting field UsbdeviceList: %v", err)
1623 }
1624 hvm.vendor_device = C.libxl_vendor_device(tmp.VendorDevice)
1625 if err := tmp.MsVmGenid.toC(&hvm.ms_vm_genid); err != nil {
1626 return fmt.Errorf("converting field MsVmGenid: %v", err)
1627 }
1628 if err := tmp.SerialList.toC(&hvm.serial_list); err != nil {
1629 return fmt.Errorf("converting field SerialList: %v", err)
1630 }
1631 if err := tmp.Rdm.toC(&hvm.rdm); err != nil {
1632 return fmt.Errorf("converting field Rdm: %v", err)
1633 }
1634 hvm.rdm_mem_boundary_memkb = C.uint64_t(tmp.RdmMemBoundaryMemkb)
1635 hvm.mca_caps = C.uint64_t(tmp.McaCaps)
1636 if err := tmp.Pirq.toC(&hvm.pirq); err != nil {
1637 return fmt.Errorf("converting field Pirq: %v", err)
1638 }
1639 hvmBytes := C.GoBytes(unsafe.Pointer(&hvm),C.sizeof_libxl_domain_build_info_type_union_hvm)
1640 copy(xc.u[:],hvmBytes)
1641 case DomainTypePv:
1642 tmp, ok := x.TypeUnion.(*DomainBuildInfoTypeUnionPv)
1643 if !ok {
1644 return errors.New("wrong type for union key type")
1645 }
1646 var pv C.libxl_domain_build_info_type_union_pv
1647 if tmp.Kernel != "" {
1648 pv.kernel = C.CString(tmp.Kernel)}
1649 pv.slack_memkb = C.uint64_t(tmp.SlackMemkb)
1650 if tmp.Bootloader != "" {
1651 pv.bootloader = C.CString(tmp.Bootloader)}
1652 if err := tmp.BootloaderArgs.toC(&pv.bootloader_args); err != nil {
1653 return fmt.Errorf("converting field BootloaderArgs: %v", err)
1654 }
1655 if tmp.Cmdline != "" {
1656 pv.cmdline = C.CString(tmp.Cmdline)}
1657 if tmp.Ramdisk != "" {
1658 pv.ramdisk = C.CString(tmp.Ramdisk)}
1659 if tmp.Features != "" {
1660 pv.features = C.CString(tmp.Features)}
1661 if err := tmp.E820Host.toC(&pv.e820_host); err != nil {
1662 return fmt.Errorf("converting field E820Host: %v", err)
1663 }
1664 pvBytes := C.GoBytes(unsafe.Pointer(&pv),C.sizeof_libxl_domain_build_info_type_union_pv)
1665 copy(xc.u[:],pvBytes)
1666 case DomainTypePvh:
1667 tmp, ok := x.TypeUnion.(*DomainBuildInfoTypeUnionPvh)
1668 if !ok {
1669 return errors.New("wrong type for union key type")
1670 }
1671 var pvh C.libxl_domain_build_info_type_union_pvh
1672 if err := tmp.Pvshim.toC(&pvh.pvshim); err != nil {
1673 return fmt.Errorf("converting field Pvshim: %v", err)
1674 }
1675 if tmp.PvshimPath != "" {
1676 pvh.pvshim_path = C.CString(tmp.PvshimPath)}
1677 if tmp.PvshimCmdline != "" {
1678 pvh.pvshim_cmdline = C.CString(tmp.PvshimCmdline)}
1679 if tmp.PvshimExtra != "" {
1680 pvh.pvshim_extra = C.CString(tmp.PvshimExtra)}
1681 pvhBytes := C.GoBytes(unsafe.Pointer(&pvh),C.sizeof_libxl_domain_build_info_type_union_pvh)
1682 copy(xc.u[:],pvhBytes)
1683 case DomainTypeInvalid:
1684 break
1685 default:
1686 return fmt.Errorf("invalid union key '%v'", x.Type)}
1687 xc.arch_arm.gic_version = C.libxl_gic_version(x.ArchArm.GicVersion)
1688 xc.arch_arm.vuart = C.libxl_vuart_type(x.ArchArm.Vuart)
1689 xc.arch_arm.sve_vl = C.libxl_sve_type(x.ArchArm.SveVl)
1690 xc.arch_arm.nr_spis = C.uint32_t(x.ArchArm.NrSpis)
1691 if err := x.ArchX86.MsrRelaxed.toC(&xc.arch_x86.msr_relaxed); err != nil {
1692 return fmt.Errorf("converting field ArchX86.MsrRelaxed: %v", err)
1693 }
1694 xc.altp2m = C.libxl_altp2m_mode(x.Altp2M)
1695 xc.vmtrace_buf_kb = C.int(x.VmtraceBufKb)
1696 if err := x.Vpmu.toC(&xc.vpmu); err != nil {
1697 return fmt.Errorf("converting field Vpmu: %v", err)
1698 }
1699
1700 return nil
1701 }
1702
1703 // NewDeviceVfb returns an instance of DeviceVfb initialized with defaults.
1704 func NewDeviceVfb() (*DeviceVfb, error) {
1705 var (
1706 x DeviceVfb
1707 xc C.libxl_device_vfb)
1708
1709 C.libxl_device_vfb_init(&xc)
1710 defer C.libxl_device_vfb_dispose(&xc)
1711
1712 if err := x.fromC(&xc); err != nil {
1713 return nil, err }
1714
1715 return &x, nil}
1716
1717 func (x *DeviceVfb) fromC(xc *C.libxl_device_vfb) error {
1718 x.BackendDomid = Domid(xc.backend_domid)
1719 x.BackendDomname = C.GoString(xc.backend_domname)
1720 x.Devid = Devid(xc.devid)
1721 if err := x.Vnc.fromC(&xc.vnc);err != nil {
1722 return fmt.Errorf("converting field Vnc: %v", err)
1723 }
1724 if err := x.Sdl.fromC(&xc.sdl);err != nil {
1725 return fmt.Errorf("converting field Sdl: %v", err)
1726 }
1727 x.Keymap = C.GoString(xc.keymap)
1728
1729 return nil}
1730
1731 func (x *DeviceVfb) toC(xc *C.libxl_device_vfb) (err error){defer func(){
1732 if err != nil{
1733 C.libxl_device_vfb_dispose(xc)}
1734 }()
1735
1736 xc.backend_domid = C.libxl_domid(x.BackendDomid)
1737 if x.BackendDomname != "" {
1738 xc.backend_domname = C.CString(x.BackendDomname)}
1739 xc.devid = C.libxl_devid(x.Devid)
1740 if err := x.Vnc.toC(&xc.vnc); err != nil {
1741 return fmt.Errorf("converting field Vnc: %v", err)
1742 }
1743 if err := x.Sdl.toC(&xc.sdl); err != nil {
1744 return fmt.Errorf("converting field Sdl: %v", err)
1745 }
1746 if x.Keymap != "" {
1747 xc.keymap = C.CString(x.Keymap)}
1748
1749 return nil
1750 }
1751
1752 // NewDeviceVkb returns an instance of DeviceVkb initialized with defaults.
1753 func NewDeviceVkb() (*DeviceVkb, error) {
1754 var (
1755 x DeviceVkb
1756 xc C.libxl_device_vkb)
1757
1758 C.libxl_device_vkb_init(&xc)
1759 defer C.libxl_device_vkb_dispose(&xc)
1760
1761 if err := x.fromC(&xc); err != nil {
1762 return nil, err }
1763
1764 return &x, nil}
1765
1766 func (x *DeviceVkb) fromC(xc *C.libxl_device_vkb) error {
1767 x.BackendDomid = Domid(xc.backend_domid)
1768 x.BackendDomname = C.GoString(xc.backend_domname)
1769 x.Devid = Devid(xc.devid)
1770 x.BackendType = VkbBackend(xc.backend_type)
1771 x.UniqueId = C.GoString(xc.unique_id)
1772 x.FeatureDisableKeyboard = bool(xc.feature_disable_keyboard)
1773 x.FeatureDisablePointer = bool(xc.feature_disable_pointer)
1774 x.FeatureAbsPointer = bool(xc.feature_abs_pointer)
1775 x.FeatureRawPointer = bool(xc.feature_raw_pointer)
1776 x.FeatureMultiTouch = bool(xc.feature_multi_touch)
1777 x.Width = uint32(xc.width)
1778 x.Height = uint32(xc.height)
1779 x.MultiTouchWidth = uint32(xc.multi_touch_width)
1780 x.MultiTouchHeight = uint32(xc.multi_touch_height)
1781 x.MultiTouchNumContacts = uint32(xc.multi_touch_num_contacts)
1782
1783 return nil}
1784
1785 func (x *DeviceVkb) toC(xc *C.libxl_device_vkb) (err error){defer func(){
1786 if err != nil{
1787 C.libxl_device_vkb_dispose(xc)}
1788 }()
1789
1790 xc.backend_domid = C.libxl_domid(x.BackendDomid)
1791 if x.BackendDomname != "" {
1792 xc.backend_domname = C.CString(x.BackendDomname)}
1793 xc.devid = C.libxl_devid(x.Devid)
1794 xc.backend_type = C.libxl_vkb_backend(x.BackendType)
1795 if x.UniqueId != "" {
1796 xc.unique_id = C.CString(x.UniqueId)}
1797 xc.feature_disable_keyboard = C.bool(x.FeatureDisableKeyboard)
1798 xc.feature_disable_pointer = C.bool(x.FeatureDisablePointer)
1799 xc.feature_abs_pointer = C.bool(x.FeatureAbsPointer)
1800 xc.feature_raw_pointer = C.bool(x.FeatureRawPointer)
1801 xc.feature_multi_touch = C.bool(x.FeatureMultiTouch)
1802 xc.width = C.uint32_t(x.Width)
1803 xc.height = C.uint32_t(x.Height)
1804 xc.multi_touch_width = C.uint32_t(x.MultiTouchWidth)
1805 xc.multi_touch_height = C.uint32_t(x.MultiTouchHeight)
1806 xc.multi_touch_num_contacts = C.uint32_t(x.MultiTouchNumContacts)
1807
1808 return nil
1809 }
1810
1811 // NewDeviceVirtio returns an instance of DeviceVirtio initialized with defaults.
1812 func NewDeviceVirtio() (*DeviceVirtio, error) {
1813 var (
1814 x DeviceVirtio
1815 xc C.libxl_device_virtio)
1816
1817 C.libxl_device_virtio_init(&xc)
1818 defer C.libxl_device_virtio_dispose(&xc)
1819
1820 if err := x.fromC(&xc); err != nil {
1821 return nil, err }
1822
1823 return &x, nil}
1824
1825 func (x *DeviceVirtio) fromC(xc *C.libxl_device_virtio) error {
1826 x.BackendDomid = Domid(xc.backend_domid)
1827 x.BackendDomname = C.GoString(xc.backend_domname)
1828 x.Type = C.GoString(xc._type)
1829 x.Transport = VirtioTransport(xc.transport)
1830 if err := x.GrantUsage.fromC(&xc.grant_usage);err != nil {
1831 return fmt.Errorf("converting field GrantUsage: %v", err)
1832 }
1833 x.Devid = Devid(xc.devid)
1834 x.Irq = uint32(xc.irq)
1835 x.Base = uint64(xc.base)
1836
1837 return nil}
1838
1839 func (x *DeviceVirtio) toC(xc *C.libxl_device_virtio) (err error){defer func(){
1840 if err != nil{
1841 C.libxl_device_virtio_dispose(xc)}
1842 }()
1843
1844 xc.backend_domid = C.libxl_domid(x.BackendDomid)
1845 if x.BackendDomname != "" {
1846 xc.backend_domname = C.CString(x.BackendDomname)}
1847 if x.Type != "" {
1848 xc._type = C.CString(x.Type)}
1849 xc.transport = C.libxl_virtio_transport(x.Transport)
1850 if err := x.GrantUsage.toC(&xc.grant_usage); err != nil {
1851 return fmt.Errorf("converting field GrantUsage: %v", err)
1852 }
1853 xc.devid = C.libxl_devid(x.Devid)
1854 xc.irq = C.uint32_t(x.Irq)
1855 xc.base = C.uint64_t(x.Base)
1856
1857 return nil
1858 }
1859
1860 // NewDeviceDisk returns an instance of DeviceDisk initialized with defaults.
1861 func NewDeviceDisk() (*DeviceDisk, error) {
1862 var (
1863 x DeviceDisk
1864 xc C.libxl_device_disk)
1865
1866 C.libxl_device_disk_init(&xc)
1867 defer C.libxl_device_disk_dispose(&xc)
1868
1869 if err := x.fromC(&xc); err != nil {
1870 return nil, err }
1871
1872 return &x, nil}
1873
1874 func (x *DeviceDisk) fromC(xc *C.libxl_device_disk) error {
1875 x.BackendDomid = Domid(xc.backend_domid)
1876 x.BackendDomname = C.GoString(xc.backend_domname)
1877 x.PdevPath = C.GoString(xc.pdev_path)
1878 x.Vdev = C.GoString(xc.vdev)
1879 x.Backend = DiskBackend(xc.backend)
1880 x.Format = DiskFormat(xc.format)
1881 x.Script = C.GoString(xc.script)
1882 x.Removable = int(xc.removable)
1883 x.Readwrite = int(xc.readwrite)
1884 x.IsCdrom = int(xc.is_cdrom)
1885 x.DirectIoSafe = bool(xc.direct_io_safe)
1886 if err := x.DiscardEnable.fromC(&xc.discard_enable);err != nil {
1887 return fmt.Errorf("converting field DiscardEnable: %v", err)
1888 }
1889 x.Specification = DiskSpecification(xc.specification)
1890 x.Transport = DiskTransport(xc.transport)
1891 x.Irq = uint32(xc.irq)
1892 x.Base = uint64(xc.base)
1893 if err := x.ColoEnable.fromC(&xc.colo_enable);err != nil {
1894 return fmt.Errorf("converting field ColoEnable: %v", err)
1895 }
1896 if err := x.ColoRestoreEnable.fromC(&xc.colo_restore_enable);err != nil {
1897 return fmt.Errorf("converting field ColoRestoreEnable: %v", err)
1898 }
1899 x.ColoHost = C.GoString(xc.colo_host)
1900 x.ColoPort = int(xc.colo_port)
1901 x.ColoExport = C.GoString(xc.colo_export)
1902 x.ActiveDisk = C.GoString(xc.active_disk)
1903 x.HiddenDisk = C.GoString(xc.hidden_disk)
1904 if err := x.Trusted.fromC(&xc.trusted);err != nil {
1905 return fmt.Errorf("converting field Trusted: %v", err)
1906 }
1907 if err := x.GrantUsage.fromC(&xc.grant_usage);err != nil {
1908 return fmt.Errorf("converting field GrantUsage: %v", err)
1909 }
1910
1911 return nil}
1912
1913 func (x *DeviceDisk) toC(xc *C.libxl_device_disk) (err error){defer func(){
1914 if err != nil{
1915 C.libxl_device_disk_dispose(xc)}
1916 }()
1917
1918 xc.backend_domid = C.libxl_domid(x.BackendDomid)
1919 if x.BackendDomname != "" {
1920 xc.backend_domname = C.CString(x.BackendDomname)}
1921 if x.PdevPath != "" {
1922 xc.pdev_path = C.CString(x.PdevPath)}
1923 if x.Vdev != "" {
1924 xc.vdev = C.CString(x.Vdev)}
1925 xc.backend = C.libxl_disk_backend(x.Backend)
1926 xc.format = C.libxl_disk_format(x.Format)
1927 if x.Script != "" {
1928 xc.script = C.CString(x.Script)}
1929 xc.removable = C.int(x.Removable)
1930 xc.readwrite = C.int(x.Readwrite)
1931 xc.is_cdrom = C.int(x.IsCdrom)
1932 xc.direct_io_safe = C.bool(x.DirectIoSafe)
1933 if err := x.DiscardEnable.toC(&xc.discard_enable); err != nil {
1934 return fmt.Errorf("converting field DiscardEnable: %v", err)
1935 }
1936 xc.specification = C.libxl_disk_specification(x.Specification)
1937 xc.transport = C.libxl_disk_transport(x.Transport)
1938 xc.irq = C.uint32_t(x.Irq)
1939 xc.base = C.uint64_t(x.Base)
1940 if err := x.ColoEnable.toC(&xc.colo_enable); err != nil {
1941 return fmt.Errorf("converting field ColoEnable: %v", err)
1942 }
1943 if err := x.ColoRestoreEnable.toC(&xc.colo_restore_enable); err != nil {
1944 return fmt.Errorf("converting field ColoRestoreEnable: %v", err)
1945 }
1946 if x.ColoHost != "" {
1947 xc.colo_host = C.CString(x.ColoHost)}
1948 xc.colo_port = C.int(x.ColoPort)
1949 if x.ColoExport != "" {
1950 xc.colo_export = C.CString(x.ColoExport)}
1951 if x.ActiveDisk != "" {
1952 xc.active_disk = C.CString(x.ActiveDisk)}
1953 if x.HiddenDisk != "" {
1954 xc.hidden_disk = C.CString(x.HiddenDisk)}
1955 if err := x.Trusted.toC(&xc.trusted); err != nil {
1956 return fmt.Errorf("converting field Trusted: %v", err)
1957 }
1958 if err := x.GrantUsage.toC(&xc.grant_usage); err != nil {
1959 return fmt.Errorf("converting field GrantUsage: %v", err)
1960 }
1961
1962 return nil
1963 }
1964
1965 // NewDeviceNic returns an instance of DeviceNic initialized with defaults.
1966 func NewDeviceNic() (*DeviceNic, error) {
1967 var (
1968 x DeviceNic
1969 xc C.libxl_device_nic)
1970
1971 C.libxl_device_nic_init(&xc)
1972 defer C.libxl_device_nic_dispose(&xc)
1973
1974 if err := x.fromC(&xc); err != nil {
1975 return nil, err }
1976
1977 return &x, nil}
1978
1979 func (x *DeviceNic) fromC(xc *C.libxl_device_nic) error {
1980 x.BackendDomid = Domid(xc.backend_domid)
1981 x.BackendDomname = C.GoString(xc.backend_domname)
1982 x.Devid = Devid(xc.devid)
1983 x.Mtu = int(xc.mtu)
1984 x.Vlan = C.GoString(xc.vlan)
1985 x.Model = C.GoString(xc.model)
1986 if err := x.Mac.fromC(&xc.mac);err != nil {
1987 return fmt.Errorf("converting field Mac: %v", err)
1988 }
1989 x.Ip = C.GoString(xc.ip)
1990 x.Bridge = C.GoString(xc.bridge)
1991 x.Ifname = C.GoString(xc.ifname)
1992 x.Script = C.GoString(xc.script)
1993 x.Nictype = NicType(xc.nictype)
1994 x.RateBytesPerInterval = uint64(xc.rate_bytes_per_interval)
1995 x.RateIntervalUsecs = uint32(xc.rate_interval_usecs)
1996 x.Gatewaydev = C.GoString(xc.gatewaydev)
1997 x.ColoftForwarddev = C.GoString(xc.coloft_forwarddev)
1998 x.ColoSockMirrorId = C.GoString(xc.colo_sock_mirror_id)
1999 x.ColoSockMirrorIp = C.GoString(xc.colo_sock_mirror_ip)
2000 x.ColoSockMirrorPort = C.GoString(xc.colo_sock_mirror_port)
2001 x.ColoSockComparePriInId = C.GoString(xc.colo_sock_compare_pri_in_id)
2002 x.ColoSockComparePriInIp = C.GoString(xc.colo_sock_compare_pri_in_ip)
2003 x.ColoSockComparePriInPort = C.GoString(xc.colo_sock_compare_pri_in_port)
2004 x.ColoSockCompareSecInId = C.GoString(xc.colo_sock_compare_sec_in_id)
2005 x.ColoSockCompareSecInIp = C.GoString(xc.colo_sock_compare_sec_in_ip)
2006 x.ColoSockCompareSecInPort = C.GoString(xc.colo_sock_compare_sec_in_port)
2007 x.ColoSockCompareNotifyId = C.GoString(xc.colo_sock_compare_notify_id)
2008 x.ColoSockCompareNotifyIp = C.GoString(xc.colo_sock_compare_notify_ip)
2009 x.ColoSockCompareNotifyPort = C.GoString(xc.colo_sock_compare_notify_port)
2010 x.ColoSockRedirector0Id = C.GoString(xc.colo_sock_redirector0_id)
2011 x.ColoSockRedirector0Ip = C.GoString(xc.colo_sock_redirector0_ip)
2012 x.ColoSockRedirector0Port = C.GoString(xc.colo_sock_redirector0_port)
2013 x.ColoSockRedirector1Id = C.GoString(xc.colo_sock_redirector1_id)
2014 x.ColoSockRedirector1Ip = C.GoString(xc.colo_sock_redirector1_ip)
2015 x.ColoSockRedirector1Port = C.GoString(xc.colo_sock_redirector1_port)
2016 x.ColoSockRedirector2Id = C.GoString(xc.colo_sock_redirector2_id)
2017 x.ColoSockRedirector2Ip = C.GoString(xc.colo_sock_redirector2_ip)
2018 x.ColoSockRedirector2Port = C.GoString(xc.colo_sock_redirector2_port)
2019 x.ColoFilterMirrorQueue = C.GoString(xc.colo_filter_mirror_queue)
2020 x.ColoFilterMirrorOutdev = C.GoString(xc.colo_filter_mirror_outdev)
2021 x.ColoFilterRedirector0Queue = C.GoString(xc.colo_filter_redirector0_queue)
2022 x.ColoFilterRedirector0Indev = C.GoString(xc.colo_filter_redirector0_indev)
2023 x.ColoFilterRedirector0Outdev = C.GoString(xc.colo_filter_redirector0_outdev)
2024 x.ColoFilterRedirector1Queue = C.GoString(xc.colo_filter_redirector1_queue)
2025 x.ColoFilterRedirector1Indev = C.GoString(xc.colo_filter_redirector1_indev)
2026 x.ColoFilterRedirector1Outdev = C.GoString(xc.colo_filter_redirector1_outdev)
2027 x.ColoComparePriIn = C.GoString(xc.colo_compare_pri_in)
2028 x.ColoCompareSecIn = C.GoString(xc.colo_compare_sec_in)
2029 x.ColoCompareOut = C.GoString(xc.colo_compare_out)
2030 x.ColoCompareNotifyDev = C.GoString(xc.colo_compare_notify_dev)
2031 x.ColoSockSecRedirector0Id = C.GoString(xc.colo_sock_sec_redirector0_id)
2032 x.ColoSockSecRedirector0Ip = C.GoString(xc.colo_sock_sec_redirector0_ip)
2033 x.ColoSockSecRedirector0Port = C.GoString(xc.colo_sock_sec_redirector0_port)
2034 x.ColoSockSecRedirector1Id = C.GoString(xc.colo_sock_sec_redirector1_id)
2035 x.ColoSockSecRedirector1Ip = C.GoString(xc.colo_sock_sec_redirector1_ip)
2036 x.ColoSockSecRedirector1Port = C.GoString(xc.colo_sock_sec_redirector1_port)
2037 x.ColoFilterSecRedirector0Queue = C.GoString(xc.colo_filter_sec_redirector0_queue)
2038 x.ColoFilterSecRedirector0Indev = C.GoString(xc.colo_filter_sec_redirector0_indev)
2039 x.ColoFilterSecRedirector0Outdev = C.GoString(xc.colo_filter_sec_redirector0_outdev)
2040 x.ColoFilterSecRedirector1Queue = C.GoString(xc.colo_filter_sec_redirector1_queue)
2041 x.ColoFilterSecRedirector1Indev = C.GoString(xc.colo_filter_sec_redirector1_indev)
2042 x.ColoFilterSecRedirector1Outdev = C.GoString(xc.colo_filter_sec_redirector1_outdev)
2043 x.ColoFilterSecRewriter0Queue = C.GoString(xc.colo_filter_sec_rewriter0_queue)
2044 x.ColoCheckpointHost = C.GoString(xc.colo_checkpoint_host)
2045 x.ColoCheckpointPort = C.GoString(xc.colo_checkpoint_port)
2046 if err := x.Trusted.fromC(&xc.trusted);err != nil {
2047 return fmt.Errorf("converting field Trusted: %v", err)
2048 }
2049
2050 return nil}
2051
2052 func (x *DeviceNic) toC(xc *C.libxl_device_nic) (err error){defer func(){
2053 if err != nil{
2054 C.libxl_device_nic_dispose(xc)}
2055 }()
2056
2057 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2058 if x.BackendDomname != "" {
2059 xc.backend_domname = C.CString(x.BackendDomname)}
2060 xc.devid = C.libxl_devid(x.Devid)
2061 xc.mtu = C.int(x.Mtu)
2062 if x.Vlan != "" {
2063 xc.vlan = C.CString(x.Vlan)}
2064 if x.Model != "" {
2065 xc.model = C.CString(x.Model)}
2066 if err := x.Mac.toC(&xc.mac); err != nil {
2067 return fmt.Errorf("converting field Mac: %v", err)
2068 }
2069 if x.Ip != "" {
2070 xc.ip = C.CString(x.Ip)}
2071 if x.Bridge != "" {
2072 xc.bridge = C.CString(x.Bridge)}
2073 if x.Ifname != "" {
2074 xc.ifname = C.CString(x.Ifname)}
2075 if x.Script != "" {
2076 xc.script = C.CString(x.Script)}
2077 xc.nictype = C.libxl_nic_type(x.Nictype)
2078 xc.rate_bytes_per_interval = C.uint64_t(x.RateBytesPerInterval)
2079 xc.rate_interval_usecs = C.uint32_t(x.RateIntervalUsecs)
2080 if x.Gatewaydev != "" {
2081 xc.gatewaydev = C.CString(x.Gatewaydev)}
2082 if x.ColoftForwarddev != "" {
2083 xc.coloft_forwarddev = C.CString(x.ColoftForwarddev)}
2084 if x.ColoSockMirrorId != "" {
2085 xc.colo_sock_mirror_id = C.CString(x.ColoSockMirrorId)}
2086 if x.ColoSockMirrorIp != "" {
2087 xc.colo_sock_mirror_ip = C.CString(x.ColoSockMirrorIp)}
2088 if x.ColoSockMirrorPort != "" {
2089 xc.colo_sock_mirror_port = C.CString(x.ColoSockMirrorPort)}
2090 if x.ColoSockComparePriInId != "" {
2091 xc.colo_sock_compare_pri_in_id = C.CString(x.ColoSockComparePriInId)}
2092 if x.ColoSockComparePriInIp != "" {
2093 xc.colo_sock_compare_pri_in_ip = C.CString(x.ColoSockComparePriInIp)}
2094 if x.ColoSockComparePriInPort != "" {
2095 xc.colo_sock_compare_pri_in_port = C.CString(x.ColoSockComparePriInPort)}
2096 if x.ColoSockCompareSecInId != "" {
2097 xc.colo_sock_compare_sec_in_id = C.CString(x.ColoSockCompareSecInId)}
2098 if x.ColoSockCompareSecInIp != "" {
2099 xc.colo_sock_compare_sec_in_ip = C.CString(x.ColoSockCompareSecInIp)}
2100 if x.ColoSockCompareSecInPort != "" {
2101 xc.colo_sock_compare_sec_in_port = C.CString(x.ColoSockCompareSecInPort)}
2102 if x.ColoSockCompareNotifyId != "" {
2103 xc.colo_sock_compare_notify_id = C.CString(x.ColoSockCompareNotifyId)}
2104 if x.ColoSockCompareNotifyIp != "" {
2105 xc.colo_sock_compare_notify_ip = C.CString(x.ColoSockCompareNotifyIp)}
2106 if x.ColoSockCompareNotifyPort != "" {
2107 xc.colo_sock_compare_notify_port = C.CString(x.ColoSockCompareNotifyPort)}
2108 if x.ColoSockRedirector0Id != "" {
2109 xc.colo_sock_redirector0_id = C.CString(x.ColoSockRedirector0Id)}
2110 if x.ColoSockRedirector0Ip != "" {
2111 xc.colo_sock_redirector0_ip = C.CString(x.ColoSockRedirector0Ip)}
2112 if x.ColoSockRedirector0Port != "" {
2113 xc.colo_sock_redirector0_port = C.CString(x.ColoSockRedirector0Port)}
2114 if x.ColoSockRedirector1Id != "" {
2115 xc.colo_sock_redirector1_id = C.CString(x.ColoSockRedirector1Id)}
2116 if x.ColoSockRedirector1Ip != "" {
2117 xc.colo_sock_redirector1_ip = C.CString(x.ColoSockRedirector1Ip)}
2118 if x.ColoSockRedirector1Port != "" {
2119 xc.colo_sock_redirector1_port = C.CString(x.ColoSockRedirector1Port)}
2120 if x.ColoSockRedirector2Id != "" {
2121 xc.colo_sock_redirector2_id = C.CString(x.ColoSockRedirector2Id)}
2122 if x.ColoSockRedirector2Ip != "" {
2123 xc.colo_sock_redirector2_ip = C.CString(x.ColoSockRedirector2Ip)}
2124 if x.ColoSockRedirector2Port != "" {
2125 xc.colo_sock_redirector2_port = C.CString(x.ColoSockRedirector2Port)}
2126 if x.ColoFilterMirrorQueue != "" {
2127 xc.colo_filter_mirror_queue = C.CString(x.ColoFilterMirrorQueue)}
2128 if x.ColoFilterMirrorOutdev != "" {
2129 xc.colo_filter_mirror_outdev = C.CString(x.ColoFilterMirrorOutdev)}
2130 if x.ColoFilterRedirector0Queue != "" {
2131 xc.colo_filter_redirector0_queue = C.CString(x.ColoFilterRedirector0Queue)}
2132 if x.ColoFilterRedirector0Indev != "" {
2133 xc.colo_filter_redirector0_indev = C.CString(x.ColoFilterRedirector0Indev)}
2134 if x.ColoFilterRedirector0Outdev != "" {
2135 xc.colo_filter_redirector0_outdev = C.CString(x.ColoFilterRedirector0Outdev)}
2136 if x.ColoFilterRedirector1Queue != "" {
2137 xc.colo_filter_redirector1_queue = C.CString(x.ColoFilterRedirector1Queue)}
2138 if x.ColoFilterRedirector1Indev != "" {
2139 xc.colo_filter_redirector1_indev = C.CString(x.ColoFilterRedirector1Indev)}
2140 if x.ColoFilterRedirector1Outdev != "" {
2141 xc.colo_filter_redirector1_outdev = C.CString(x.ColoFilterRedirector1Outdev)}
2142 if x.ColoComparePriIn != "" {
2143 xc.colo_compare_pri_in = C.CString(x.ColoComparePriIn)}
2144 if x.ColoCompareSecIn != "" {
2145 xc.colo_compare_sec_in = C.CString(x.ColoCompareSecIn)}
2146 if x.ColoCompareOut != "" {
2147 xc.colo_compare_out = C.CString(x.ColoCompareOut)}
2148 if x.ColoCompareNotifyDev != "" {
2149 xc.colo_compare_notify_dev = C.CString(x.ColoCompareNotifyDev)}
2150 if x.ColoSockSecRedirector0Id != "" {
2151 xc.colo_sock_sec_redirector0_id = C.CString(x.ColoSockSecRedirector0Id)}
2152 if x.ColoSockSecRedirector0Ip != "" {
2153 xc.colo_sock_sec_redirector0_ip = C.CString(x.ColoSockSecRedirector0Ip)}
2154 if x.ColoSockSecRedirector0Port != "" {
2155 xc.colo_sock_sec_redirector0_port = C.CString(x.ColoSockSecRedirector0Port)}
2156 if x.ColoSockSecRedirector1Id != "" {
2157 xc.colo_sock_sec_redirector1_id = C.CString(x.ColoSockSecRedirector1Id)}
2158 if x.ColoSockSecRedirector1Ip != "" {
2159 xc.colo_sock_sec_redirector1_ip = C.CString(x.ColoSockSecRedirector1Ip)}
2160 if x.ColoSockSecRedirector1Port != "" {
2161 xc.colo_sock_sec_redirector1_port = C.CString(x.ColoSockSecRedirector1Port)}
2162 if x.ColoFilterSecRedirector0Queue != "" {
2163 xc.colo_filter_sec_redirector0_queue = C.CString(x.ColoFilterSecRedirector0Queue)}
2164 if x.ColoFilterSecRedirector0Indev != "" {
2165 xc.colo_filter_sec_redirector0_indev = C.CString(x.ColoFilterSecRedirector0Indev)}
2166 if x.ColoFilterSecRedirector0Outdev != "" {
2167 xc.colo_filter_sec_redirector0_outdev = C.CString(x.ColoFilterSecRedirector0Outdev)}
2168 if x.ColoFilterSecRedirector1Queue != "" {
2169 xc.colo_filter_sec_redirector1_queue = C.CString(x.ColoFilterSecRedirector1Queue)}
2170 if x.ColoFilterSecRedirector1Indev != "" {
2171 xc.colo_filter_sec_redirector1_indev = C.CString(x.ColoFilterSecRedirector1Indev)}
2172 if x.ColoFilterSecRedirector1Outdev != "" {
2173 xc.colo_filter_sec_redirector1_outdev = C.CString(x.ColoFilterSecRedirector1Outdev)}
2174 if x.ColoFilterSecRewriter0Queue != "" {
2175 xc.colo_filter_sec_rewriter0_queue = C.CString(x.ColoFilterSecRewriter0Queue)}
2176 if x.ColoCheckpointHost != "" {
2177 xc.colo_checkpoint_host = C.CString(x.ColoCheckpointHost)}
2178 if x.ColoCheckpointPort != "" {
2179 xc.colo_checkpoint_port = C.CString(x.ColoCheckpointPort)}
2180 if err := x.Trusted.toC(&xc.trusted); err != nil {
2181 return fmt.Errorf("converting field Trusted: %v", err)
2182 }
2183
2184 return nil
2185 }
2186
2187 // NewDevicePci returns an instance of DevicePci initialized with defaults.
2188 func NewDevicePci() (*DevicePci, error) {
2189 var (
2190 x DevicePci
2191 xc C.libxl_device_pci)
2192
2193 C.libxl_device_pci_init(&xc)
2194 defer C.libxl_device_pci_dispose(&xc)
2195
2196 if err := x.fromC(&xc); err != nil {
2197 return nil, err }
2198
2199 return &x, nil}
2200
2201 func (x *DevicePci) fromC(xc *C.libxl_device_pci) error {
2202 x.Func = byte(xc._func)
2203 x.Dev = byte(xc.dev)
2204 x.Bus = byte(xc.bus)
2205 x.Domain = int(xc.domain)
2206 x.Vdevfn = uint32(xc.vdevfn)
2207 x.VfuncMask = uint32(xc.vfunc_mask)
2208 x.Msitranslate = bool(xc.msitranslate)
2209 x.PowerMgmt = bool(xc.power_mgmt)
2210 x.Permissive = bool(xc.permissive)
2211 x.Seize = bool(xc.seize)
2212 x.RdmPolicy = RdmReservePolicy(xc.rdm_policy)
2213 x.Name = C.GoString(xc.name)
2214
2215 return nil}
2216
2217 func (x *DevicePci) toC(xc *C.libxl_device_pci) (err error){defer func(){
2218 if err != nil{
2219 C.libxl_device_pci_dispose(xc)}
2220 }()
2221
2222 xc._func = C.uint8_t(x.Func)
2223 xc.dev = C.uint8_t(x.Dev)
2224 xc.bus = C.uint8_t(x.Bus)
2225 xc.domain = C.int(x.Domain)
2226 xc.vdevfn = C.uint32_t(x.Vdevfn)
2227 xc.vfunc_mask = C.uint32_t(x.VfuncMask)
2228 xc.msitranslate = C.bool(x.Msitranslate)
2229 xc.power_mgmt = C.bool(x.PowerMgmt)
2230 xc.permissive = C.bool(x.Permissive)
2231 xc.seize = C.bool(x.Seize)
2232 xc.rdm_policy = C.libxl_rdm_reserve_policy(x.RdmPolicy)
2233 if x.Name != "" {
2234 xc.name = C.CString(x.Name)}
2235
2236 return nil
2237 }
2238
2239 // NewDeviceRdm returns an instance of DeviceRdm initialized with defaults.
2240 func NewDeviceRdm() (*DeviceRdm, error) {
2241 var (
2242 x DeviceRdm
2243 xc C.libxl_device_rdm)
2244
2245 C.libxl_device_rdm_init(&xc)
2246 defer C.libxl_device_rdm_dispose(&xc)
2247
2248 if err := x.fromC(&xc); err != nil {
2249 return nil, err }
2250
2251 return &x, nil}
2252
2253 func (x *DeviceRdm) fromC(xc *C.libxl_device_rdm) error {
2254 x.Start = uint64(xc.start)
2255 x.Size = uint64(xc.size)
2256 x.Policy = RdmReservePolicy(xc.policy)
2257
2258 return nil}
2259
2260 func (x *DeviceRdm) toC(xc *C.libxl_device_rdm) (err error){defer func(){
2261 if err != nil{
2262 C.libxl_device_rdm_dispose(xc)}
2263 }()
2264
2265 xc.start = C.uint64_t(x.Start)
2266 xc.size = C.uint64_t(x.Size)
2267 xc.policy = C.libxl_rdm_reserve_policy(x.Policy)
2268
2269 return nil
2270 }
2271
2272 // NewDeviceUsbctrl returns an instance of DeviceUsbctrl initialized with defaults.
2273 func NewDeviceUsbctrl() (*DeviceUsbctrl, error) {
2274 var (
2275 x DeviceUsbctrl
2276 xc C.libxl_device_usbctrl)
2277
2278 C.libxl_device_usbctrl_init(&xc)
2279 defer C.libxl_device_usbctrl_dispose(&xc)
2280
2281 if err := x.fromC(&xc); err != nil {
2282 return nil, err }
2283
2284 return &x, nil}
2285
2286 func (x *DeviceUsbctrl) fromC(xc *C.libxl_device_usbctrl) error {
2287 x.Type = UsbctrlType(xc._type)
2288 x.Devid = Devid(xc.devid)
2289 x.Version = int(xc.version)
2290 x.Ports = int(xc.ports)
2291 x.BackendDomid = Domid(xc.backend_domid)
2292 x.BackendDomname = C.GoString(xc.backend_domname)
2293
2294 return nil}
2295
2296 func (x *DeviceUsbctrl) toC(xc *C.libxl_device_usbctrl) (err error){defer func(){
2297 if err != nil{
2298 C.libxl_device_usbctrl_dispose(xc)}
2299 }()
2300
2301 xc._type = C.libxl_usbctrl_type(x.Type)
2302 xc.devid = C.libxl_devid(x.Devid)
2303 xc.version = C.int(x.Version)
2304 xc.ports = C.int(x.Ports)
2305 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2306 if x.BackendDomname != "" {
2307 xc.backend_domname = C.CString(x.BackendDomname)}
2308
2309 return nil
2310 }
2311
2312 // NewDeviceUsbdev returns an instance of DeviceUsbdev initialized with defaults.
2313 func NewDeviceUsbdev(utype UsbdevType) (*DeviceUsbdev, error) {
2314 var (
2315 x DeviceUsbdev
2316 xc C.libxl_device_usbdev)
2317
2318 C.libxl_device_usbdev_init(&xc)
2319 C.libxl_device_usbdev_init_type(&xc, C.libxl_usbdev_type(utype))
2320 defer C.libxl_device_usbdev_dispose(&xc)
2321
2322 if err := x.fromC(&xc); err != nil {
2323 return nil, err }
2324
2325 return &x, nil}
2326
2327 func (x *DeviceUsbdev) fromC(xc *C.libxl_device_usbdev) error {
2328 x.Ctrl = Devid(xc.ctrl)
2329 x.Port = int(xc.port)
2330 x.Type = UsbdevType(xc._type)
2331 switch x.Type{
2332 case UsbdevTypeHostdev:
2333 var typeHostdev DeviceUsbdevTypeUnionHostdev
2334 if err := typeHostdev.fromC(xc);err != nil {
2335 return fmt.Errorf("converting field typeHostdev: %v", err)
2336 }
2337 x.TypeUnion = &typeHostdev
2338 default:
2339 return fmt.Errorf("invalid union key '%v'", x.Type)}
2340
2341 return nil}
2342
2343 func (x *DeviceUsbdevTypeUnionHostdev) fromC(xc *C.libxl_device_usbdev) error {
2344 if UsbdevType(xc._type) != UsbdevTypeHostdev {
2345 return errors.New("expected union key UsbdevTypeHostdev")
2346 }
2347
2348 tmp := (*C.libxl_device_usbdev_type_union_hostdev)(unsafe.Pointer(&xc.u[0]))
2349 x.Hostbus = byte(tmp.hostbus)
2350 x.Hostaddr = byte(tmp.hostaddr)
2351 return nil
2352 }
2353
2354 func (x *DeviceUsbdev) toC(xc *C.libxl_device_usbdev) (err error){defer func(){
2355 if err != nil{
2356 C.libxl_device_usbdev_dispose(xc)}
2357 }()
2358
2359 xc.ctrl = C.libxl_devid(x.Ctrl)
2360 xc.port = C.int(x.Port)
2361 xc._type = C.libxl_usbdev_type(x.Type)
2362 switch x.Type{
2363 case UsbdevTypeHostdev:
2364 tmp, ok := x.TypeUnion.(*DeviceUsbdevTypeUnionHostdev)
2365 if !ok {
2366 return errors.New("wrong type for union key type")
2367 }
2368 var hostdev C.libxl_device_usbdev_type_union_hostdev
2369 hostdev.hostbus = C.uint8_t(tmp.Hostbus)
2370 hostdev.hostaddr = C.uint8_t(tmp.Hostaddr)
2371 hostdevBytes := C.GoBytes(unsafe.Pointer(&hostdev),C.sizeof_libxl_device_usbdev_type_union_hostdev)
2372 copy(xc.u[:],hostdevBytes)
2373 default:
2374 return fmt.Errorf("invalid union key '%v'", x.Type)}
2375
2376 return nil
2377 }
2378
2379 // NewDeviceDtdev returns an instance of DeviceDtdev initialized with defaults.
2380 func NewDeviceDtdev() (*DeviceDtdev, error) {
2381 var (
2382 x DeviceDtdev
2383 xc C.libxl_device_dtdev)
2384
2385 C.libxl_device_dtdev_init(&xc)
2386 defer C.libxl_device_dtdev_dispose(&xc)
2387
2388 if err := x.fromC(&xc); err != nil {
2389 return nil, err }
2390
2391 return &x, nil}
2392
2393 func (x *DeviceDtdev) fromC(xc *C.libxl_device_dtdev) error {
2394 x.Path = C.GoString(xc.path)
2395
2396 return nil}
2397
2398 func (x *DeviceDtdev) toC(xc *C.libxl_device_dtdev) (err error){defer func(){
2399 if err != nil{
2400 C.libxl_device_dtdev_dispose(xc)}
2401 }()
2402
2403 if x.Path != "" {
2404 xc.path = C.CString(x.Path)}
2405
2406 return nil
2407 }
2408
2409 // NewDeviceVtpm returns an instance of DeviceVtpm initialized with defaults.
2410 func NewDeviceVtpm() (*DeviceVtpm, error) {
2411 var (
2412 x DeviceVtpm
2413 xc C.libxl_device_vtpm)
2414
2415 C.libxl_device_vtpm_init(&xc)
2416 defer C.libxl_device_vtpm_dispose(&xc)
2417
2418 if err := x.fromC(&xc); err != nil {
2419 return nil, err }
2420
2421 return &x, nil}
2422
2423 func (x *DeviceVtpm) fromC(xc *C.libxl_device_vtpm) error {
2424 x.BackendDomid = Domid(xc.backend_domid)
2425 x.BackendDomname = C.GoString(xc.backend_domname)
2426 x.Devid = Devid(xc.devid)
2427 if err := x.Uuid.fromC(&xc.uuid);err != nil {
2428 return fmt.Errorf("converting field Uuid: %v", err)
2429 }
2430
2431 return nil}
2432
2433 func (x *DeviceVtpm) toC(xc *C.libxl_device_vtpm) (err error){defer func(){
2434 if err != nil{
2435 C.libxl_device_vtpm_dispose(xc)}
2436 }()
2437
2438 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2439 if x.BackendDomname != "" {
2440 xc.backend_domname = C.CString(x.BackendDomname)}
2441 xc.devid = C.libxl_devid(x.Devid)
2442 if err := x.Uuid.toC(&xc.uuid); err != nil {
2443 return fmt.Errorf("converting field Uuid: %v", err)
2444 }
2445
2446 return nil
2447 }
2448
2449 // NewDeviceP9 returns an instance of DeviceP9 initialized with defaults.
2450 func NewDeviceP9() (*DeviceP9, error) {
2451 var (
2452 x DeviceP9
2453 xc C.libxl_device_p9)
2454
2455 C.libxl_device_p9_init(&xc)
2456 defer C.libxl_device_p9_dispose(&xc)
2457
2458 if err := x.fromC(&xc); err != nil {
2459 return nil, err }
2460
2461 return &x, nil}
2462
2463 func (x *DeviceP9) fromC(xc *C.libxl_device_p9) error {
2464 x.BackendDomid = Domid(xc.backend_domid)
2465 x.BackendDomname = C.GoString(xc.backend_domname)
2466 x.Tag = C.GoString(xc.tag)
2467 x.Path = C.GoString(xc.path)
2468 x.SecurityModel = C.GoString(xc.security_model)
2469 x.Devid = Devid(xc.devid)
2470 x.Type = P9Type(xc._type)
2471 x.MaxSpace = int(xc.max_space)
2472 x.MaxFiles = int(xc.max_files)
2473 x.MaxOpenFiles = int(xc.max_open_files)
2474 x.AutoDelete = bool(xc.auto_delete)
2475
2476 return nil}
2477
2478 func (x *DeviceP9) toC(xc *C.libxl_device_p9) (err error){defer func(){
2479 if err != nil{
2480 C.libxl_device_p9_dispose(xc)}
2481 }()
2482
2483 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2484 if x.BackendDomname != "" {
2485 xc.backend_domname = C.CString(x.BackendDomname)}
2486 if x.Tag != "" {
2487 xc.tag = C.CString(x.Tag)}
2488 if x.Path != "" {
2489 xc.path = C.CString(x.Path)}
2490 if x.SecurityModel != "" {
2491 xc.security_model = C.CString(x.SecurityModel)}
2492 xc.devid = C.libxl_devid(x.Devid)
2493 xc._type = C.libxl_p9_type(x.Type)
2494 xc.max_space = C.int(x.MaxSpace)
2495 xc.max_files = C.int(x.MaxFiles)
2496 xc.max_open_files = C.int(x.MaxOpenFiles)
2497 xc.auto_delete = C.bool(x.AutoDelete)
2498
2499 return nil
2500 }
2501
2502 // NewDevicePvcallsif returns an instance of DevicePvcallsif initialized with defaults.
2503 func NewDevicePvcallsif() (*DevicePvcallsif, error) {
2504 var (
2505 x DevicePvcallsif
2506 xc C.libxl_device_pvcallsif)
2507
2508 C.libxl_device_pvcallsif_init(&xc)
2509 defer C.libxl_device_pvcallsif_dispose(&xc)
2510
2511 if err := x.fromC(&xc); err != nil {
2512 return nil, err }
2513
2514 return &x, nil}
2515
2516 func (x *DevicePvcallsif) fromC(xc *C.libxl_device_pvcallsif) error {
2517 x.BackendDomid = Domid(xc.backend_domid)
2518 x.BackendDomname = C.GoString(xc.backend_domname)
2519 x.Devid = Devid(xc.devid)
2520
2521 return nil}
2522
2523 func (x *DevicePvcallsif) toC(xc *C.libxl_device_pvcallsif) (err error){defer func(){
2524 if err != nil{
2525 C.libxl_device_pvcallsif_dispose(xc)}
2526 }()
2527
2528 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2529 if x.BackendDomname != "" {
2530 xc.backend_domname = C.CString(x.BackendDomname)}
2531 xc.devid = C.libxl_devid(x.Devid)
2532
2533 return nil
2534 }
2535
2536 // NewDeviceChannel returns an instance of DeviceChannel initialized with defaults.
2537 func NewDeviceChannel(connection ChannelConnection) (*DeviceChannel, error) {
2538 var (
2539 x DeviceChannel
2540 xc C.libxl_device_channel)
2541
2542 C.libxl_device_channel_init(&xc)
2543 C.libxl_device_channel_init_connection(&xc, C.libxl_channel_connection(connection))
2544 defer C.libxl_device_channel_dispose(&xc)
2545
2546 if err := x.fromC(&xc); err != nil {
2547 return nil, err }
2548
2549 return &x, nil}
2550
2551 func (x *DeviceChannel) fromC(xc *C.libxl_device_channel) error {
2552 x.BackendDomid = Domid(xc.backend_domid)
2553 x.BackendDomname = C.GoString(xc.backend_domname)
2554 x.Devid = Devid(xc.devid)
2555 x.Name = C.GoString(xc.name)
2556 x.Connection = ChannelConnection(xc.connection)
2557 switch x.Connection{
2558 case ChannelConnectionPty:
2559 x.ConnectionUnion = nil
2560 case ChannelConnectionSocket:
2561 var connectionSocket DeviceChannelConnectionUnionSocket
2562 if err := connectionSocket.fromC(xc);err != nil {
2563 return fmt.Errorf("converting field connectionSocket: %v", err)
2564 }
2565 x.ConnectionUnion = &connectionSocket
2566 case ChannelConnectionUnknown:
2567 x.ConnectionUnion = nil
2568 default:
2569 return fmt.Errorf("invalid union key '%v'", x.Connection)}
2570
2571 return nil}
2572
2573 func (x *DeviceChannelConnectionUnionSocket) fromC(xc *C.libxl_device_channel) error {
2574 if ChannelConnection(xc.connection) != ChannelConnectionSocket {
2575 return errors.New("expected union key ChannelConnectionSocket")
2576 }
2577
2578 tmp := (*C.libxl_device_channel_connection_union_socket)(unsafe.Pointer(&xc.u[0]))
2579 x.Path = C.GoString(tmp.path)
2580 return nil
2581 }
2582
2583 func (x *DeviceChannel) toC(xc *C.libxl_device_channel) (err error){defer func(){
2584 if err != nil{
2585 C.libxl_device_channel_dispose(xc)}
2586 }()
2587
2588 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2589 if x.BackendDomname != "" {
2590 xc.backend_domname = C.CString(x.BackendDomname)}
2591 xc.devid = C.libxl_devid(x.Devid)
2592 if x.Name != "" {
2593 xc.name = C.CString(x.Name)}
2594 xc.connection = C.libxl_channel_connection(x.Connection)
2595 switch x.Connection{
2596 case ChannelConnectionUnknown:
2597 break
2598 case ChannelConnectionPty:
2599 break
2600 case ChannelConnectionSocket:
2601 tmp, ok := x.ConnectionUnion.(*DeviceChannelConnectionUnionSocket)
2602 if !ok {
2603 return errors.New("wrong type for union key connection")
2604 }
2605 var socket C.libxl_device_channel_connection_union_socket
2606 if tmp.Path != "" {
2607 socket.path = C.CString(tmp.Path)}
2608 socketBytes := C.GoBytes(unsafe.Pointer(&socket),C.sizeof_libxl_device_channel_connection_union_socket)
2609 copy(xc.u[:],socketBytes)
2610 default:
2611 return fmt.Errorf("invalid union key '%v'", x.Connection)}
2612
2613 return nil
2614 }
2615
2616 // NewConnectorParam returns an instance of ConnectorParam initialized with defaults.
2617 func NewConnectorParam() (*ConnectorParam, error) {
2618 var (
2619 x ConnectorParam
2620 xc C.libxl_connector_param)
2621
2622 C.libxl_connector_param_init(&xc)
2623 defer C.libxl_connector_param_dispose(&xc)
2624
2625 if err := x.fromC(&xc); err != nil {
2626 return nil, err }
2627
2628 return &x, nil}
2629
2630 func (x *ConnectorParam) fromC(xc *C.libxl_connector_param) error {
2631 x.UniqueId = C.GoString(xc.unique_id)
2632 x.Width = uint32(xc.width)
2633 x.Height = uint32(xc.height)
2634
2635 return nil}
2636
2637 func (x *ConnectorParam) toC(xc *C.libxl_connector_param) (err error){defer func(){
2638 if err != nil{
2639 C.libxl_connector_param_dispose(xc)}
2640 }()
2641
2642 if x.UniqueId != "" {
2643 xc.unique_id = C.CString(x.UniqueId)}
2644 xc.width = C.uint32_t(x.Width)
2645 xc.height = C.uint32_t(x.Height)
2646
2647 return nil
2648 }
2649
2650 // NewDeviceVdispl returns an instance of DeviceVdispl initialized with defaults.
2651 func NewDeviceVdispl() (*DeviceVdispl, error) {
2652 var (
2653 x DeviceVdispl
2654 xc C.libxl_device_vdispl)
2655
2656 C.libxl_device_vdispl_init(&xc)
2657 defer C.libxl_device_vdispl_dispose(&xc)
2658
2659 if err := x.fromC(&xc); err != nil {
2660 return nil, err }
2661
2662 return &x, nil}
2663
2664 func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error {
2665 x.BackendDomid = Domid(xc.backend_domid)
2666 x.BackendDomname = C.GoString(xc.backend_domname)
2667 x.Devid = Devid(xc.devid)
2668 x.BeAlloc = bool(xc.be_alloc)
2669 x.Connectors = nil
2670 if n := int(xc.num_connectors); n > 0 {
2671 cConnectors := (*[1<<28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:n:n]
2672 x.Connectors = make([]ConnectorParam, n)
2673 for i, v := range cConnectors {
2674 if err := x.Connectors[i].fromC(&v); err != nil {
2675 return fmt.Errorf("converting field Connectors: %v", err) }
2676 }
2677 }
2678
2679 return nil}
2680
2681 func (x *DeviceVdispl) toC(xc *C.libxl_device_vdispl) (err error){defer func(){
2682 if err != nil{
2683 C.libxl_device_vdispl_dispose(xc)}
2684 }()
2685
2686 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2687 if x.BackendDomname != "" {
2688 xc.backend_domname = C.CString(x.BackendDomname)}
2689 xc.devid = C.libxl_devid(x.Devid)
2690 xc.be_alloc = C.bool(x.BeAlloc)
2691 if numConnectors := len(x.Connectors); numConnectors > 0 {
2692 xc.connectors = (*C.libxl_connector_param)(C.malloc(C.ulong(numConnectors)*C.sizeof_libxl_connector_param))
2693 xc.num_connectors = C.int(numConnectors)
2694 cConnectors := (*[1<<28]C.libxl_connector_param)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors]
2695 for i,v := range x.Connectors {
2696 if err := v.toC(&cConnectors[i]); err != nil {
2697 return fmt.Errorf("converting field Connectors: %v", err)
2698 }
2699 }
2700 }
2701
2702 return nil
2703 }
2704
2705 // NewVsndParams returns an instance of VsndParams initialized with defaults.
2706 func NewVsndParams() (*VsndParams, error) {
2707 var (
2708 x VsndParams
2709 xc C.libxl_vsnd_params)
2710
2711 C.libxl_vsnd_params_init(&xc)
2712 defer C.libxl_vsnd_params_dispose(&xc)
2713
2714 if err := x.fromC(&xc); err != nil {
2715 return nil, err }
2716
2717 return &x, nil}
2718
2719 func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error {
2720 x.SampleRates = nil
2721 if n := int(xc.num_sample_rates); n > 0 {
2722 cSampleRates := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:n:n]
2723 x.SampleRates = make([]uint32, n)
2724 for i, v := range cSampleRates {
2725 x.SampleRates[i] = uint32(v)
2726 }
2727 }
2728 x.SampleFormats = nil
2729 if n := int(xc.num_sample_formats); n > 0 {
2730 cSampleFormats := (*[1<<28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:n:n]
2731 x.SampleFormats = make([]VsndPcmFormat, n)
2732 for i, v := range cSampleFormats {
2733 x.SampleFormats[i] = VsndPcmFormat(v)
2734 }
2735 }
2736 x.ChannelsMin = uint32(xc.channels_min)
2737 x.ChannelsMax = uint32(xc.channels_max)
2738 x.BufferSize = uint32(xc.buffer_size)
2739
2740 return nil}
2741
2742 func (x *VsndParams) toC(xc *C.libxl_vsnd_params) (err error){defer func(){
2743 if err != nil{
2744 C.libxl_vsnd_params_dispose(xc)}
2745 }()
2746
2747 if numSampleRates := len(x.SampleRates); numSampleRates > 0 {
2748 xc.sample_rates = (*C.uint32_t)(C.malloc(C.size_t(numSampleRates*numSampleRates)))
2749 xc.num_sample_rates = C.int(numSampleRates)
2750 cSampleRates := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:numSampleRates:numSampleRates]
2751 for i,v := range x.SampleRates {
2752 cSampleRates[i] = C.uint32_t(v)
2753 }
2754 }
2755 if numSampleFormats := len(x.SampleFormats); numSampleFormats > 0 {
2756 xc.sample_formats = (*C.libxl_vsnd_pcm_format)(C.malloc(C.size_t(numSampleFormats*numSampleFormats)))
2757 xc.num_sample_formats = C.int(numSampleFormats)
2758 cSampleFormats := (*[1<<28]C.libxl_vsnd_pcm_format)(unsafe.Pointer(xc.sample_formats))[:numSampleFormats:numSampleFormats]
2759 for i,v := range x.SampleFormats {
2760 cSampleFormats[i] = C.libxl_vsnd_pcm_format(v)
2761 }
2762 }
2763 xc.channels_min = C.uint32_t(x.ChannelsMin)
2764 xc.channels_max = C.uint32_t(x.ChannelsMax)
2765 xc.buffer_size = C.uint32_t(x.BufferSize)
2766
2767 return nil
2768 }
2769
2770 // NewVsndStream returns an instance of VsndStream initialized with defaults.
2771 func NewVsndStream() (*VsndStream, error) {
2772 var (
2773 x VsndStream
2774 xc C.libxl_vsnd_stream)
2775
2776 C.libxl_vsnd_stream_init(&xc)
2777 defer C.libxl_vsnd_stream_dispose(&xc)
2778
2779 if err := x.fromC(&xc); err != nil {
2780 return nil, err }
2781
2782 return &x, nil}
2783
2784 func (x *VsndStream) fromC(xc *C.libxl_vsnd_stream) error {
2785 x.UniqueId = C.GoString(xc.unique_id)
2786 x.Type = VsndStreamType(xc._type)
2787 if err := x.Params.fromC(&xc.params);err != nil {
2788 return fmt.Errorf("converting field Params: %v", err)
2789 }
2790
2791 return nil}
2792
2793 func (x *VsndStream) toC(xc *C.libxl_vsnd_stream) (err error){defer func(){
2794 if err != nil{
2795 C.libxl_vsnd_stream_dispose(xc)}
2796 }()
2797
2798 if x.UniqueId != "" {
2799 xc.unique_id = C.CString(x.UniqueId)}
2800 xc._type = C.libxl_vsnd_stream_type(x.Type)
2801 if err := x.Params.toC(&xc.params); err != nil {
2802 return fmt.Errorf("converting field Params: %v", err)
2803 }
2804
2805 return nil
2806 }
2807
2808 // NewVsndPcm returns an instance of VsndPcm initialized with defaults.
2809 func NewVsndPcm() (*VsndPcm, error) {
2810 var (
2811 x VsndPcm
2812 xc C.libxl_vsnd_pcm)
2813
2814 C.libxl_vsnd_pcm_init(&xc)
2815 defer C.libxl_vsnd_pcm_dispose(&xc)
2816
2817 if err := x.fromC(&xc); err != nil {
2818 return nil, err }
2819
2820 return &x, nil}
2821
2822 func (x *VsndPcm) fromC(xc *C.libxl_vsnd_pcm) error {
2823 x.Name = C.GoString(xc.name)
2824 if err := x.Params.fromC(&xc.params);err != nil {
2825 return fmt.Errorf("converting field Params: %v", err)
2826 }
2827 x.Streams = nil
2828 if n := int(xc.num_vsnd_streams); n > 0 {
2829 cStreams := (*[1<<28]C.libxl_vsnd_stream)(unsafe.Pointer(xc.streams))[:n:n]
2830 x.Streams = make([]VsndStream, n)
2831 for i, v := range cStreams {
2832 if err := x.Streams[i].fromC(&v); err != nil {
2833 return fmt.Errorf("converting field Streams: %v", err) }
2834 }
2835 }
2836
2837 return nil}
2838
2839 func (x *VsndPcm) toC(xc *C.libxl_vsnd_pcm) (err error){defer func(){
2840 if err != nil{
2841 C.libxl_vsnd_pcm_dispose(xc)}
2842 }()
2843
2844 if x.Name != "" {
2845 xc.name = C.CString(x.Name)}
2846 if err := x.Params.toC(&xc.params); err != nil {
2847 return fmt.Errorf("converting field Params: %v", err)
2848 }
2849 if numVsndStreams := len(x.Streams); numVsndStreams > 0 {
2850 xc.streams = (*C.libxl_vsnd_stream)(C.malloc(C.ulong(numVsndStreams)*C.sizeof_libxl_vsnd_stream))
2851 xc.num_vsnd_streams = C.int(numVsndStreams)
2852 cStreams := (*[1<<28]C.libxl_vsnd_stream)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams]
2853 for i,v := range x.Streams {
2854 if err := v.toC(&cStreams[i]); err != nil {
2855 return fmt.Errorf("converting field Streams: %v", err)
2856 }
2857 }
2858 }
2859
2860 return nil
2861 }
2862
2863 // NewDeviceVsnd returns an instance of DeviceVsnd initialized with defaults.
2864 func NewDeviceVsnd() (*DeviceVsnd, error) {
2865 var (
2866 x DeviceVsnd
2867 xc C.libxl_device_vsnd)
2868
2869 C.libxl_device_vsnd_init(&xc)
2870 defer C.libxl_device_vsnd_dispose(&xc)
2871
2872 if err := x.fromC(&xc); err != nil {
2873 return nil, err }
2874
2875 return &x, nil}
2876
2877 func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error {
2878 x.BackendDomid = Domid(xc.backend_domid)
2879 x.BackendDomname = C.GoString(xc.backend_domname)
2880 x.Devid = Devid(xc.devid)
2881 x.ShortName = C.GoString(xc.short_name)
2882 x.LongName = C.GoString(xc.long_name)
2883 if err := x.Params.fromC(&xc.params);err != nil {
2884 return fmt.Errorf("converting field Params: %v", err)
2885 }
2886 x.Pcms = nil
2887 if n := int(xc.num_vsnd_pcms); n > 0 {
2888 cPcms := (*[1<<28]C.libxl_vsnd_pcm)(unsafe.Pointer(xc.pcms))[:n:n]
2889 x.Pcms = make([]VsndPcm, n)
2890 for i, v := range cPcms {
2891 if err := x.Pcms[i].fromC(&v); err != nil {
2892 return fmt.Errorf("converting field Pcms: %v", err) }
2893 }
2894 }
2895
2896 return nil}
2897
2898 func (x *DeviceVsnd) toC(xc *C.libxl_device_vsnd) (err error){defer func(){
2899 if err != nil{
2900 C.libxl_device_vsnd_dispose(xc)}
2901 }()
2902
2903 xc.backend_domid = C.libxl_domid(x.BackendDomid)
2904 if x.BackendDomname != "" {
2905 xc.backend_domname = C.CString(x.BackendDomname)}
2906 xc.devid = C.libxl_devid(x.Devid)
2907 if x.ShortName != "" {
2908 xc.short_name = C.CString(x.ShortName)}
2909 if x.LongName != "" {
2910 xc.long_name = C.CString(x.LongName)}
2911 if err := x.Params.toC(&xc.params); err != nil {
2912 return fmt.Errorf("converting field Params: %v", err)
2913 }
2914 if numVsndPcms := len(x.Pcms); numVsndPcms > 0 {
2915 xc.pcms = (*C.libxl_vsnd_pcm)(C.malloc(C.ulong(numVsndPcms)*C.sizeof_libxl_vsnd_pcm))
2916 xc.num_vsnd_pcms = C.int(numVsndPcms)
2917 cPcms := (*[1<<28]C.libxl_vsnd_pcm)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms]
2918 for i,v := range x.Pcms {
2919 if err := v.toC(&cPcms[i]); err != nil {
2920 return fmt.Errorf("converting field Pcms: %v", err)
2921 }
2922 }
2923 }
2924
2925 return nil
2926 }
2927
2928 // NewDomainConfig returns an instance of DomainConfig initialized with defaults.
2929 func NewDomainConfig() (*DomainConfig, error) {
2930 var (
2931 x DomainConfig
2932 xc C.libxl_domain_config)
2933
2934 C.libxl_domain_config_init(&xc)
2935 defer C.libxl_domain_config_dispose(&xc)
2936
2937 if err := x.fromC(&xc); err != nil {
2938 return nil, err }
2939
2940 return &x, nil}
2941
2942 func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error {
2943 if err := x.CInfo.fromC(&xc.c_info);err != nil {
2944 return fmt.Errorf("converting field CInfo: %v", err)
2945 }
2946 if err := x.BInfo.fromC(&xc.b_info);err != nil {
2947 return fmt.Errorf("converting field BInfo: %v", err)
2948 }
2949 x.Disks = nil
2950 if n := int(xc.num_disks); n > 0 {
2951 cDisks := (*[1<<28]C.libxl_device_disk)(unsafe.Pointer(xc.disks))[:n:n]
2952 x.Disks = make([]DeviceDisk, n)
2953 for i, v := range cDisks {
2954 if err := x.Disks[i].fromC(&v); err != nil {
2955 return fmt.Errorf("converting field Disks: %v", err) }
2956 }
2957 }
2958 x.Nics = nil
2959 if n := int(xc.num_nics); n > 0 {
2960 cNics := (*[1<<28]C.libxl_device_nic)(unsafe.Pointer(xc.nics))[:n:n]
2961 x.Nics = make([]DeviceNic, n)
2962 for i, v := range cNics {
2963 if err := x.Nics[i].fromC(&v); err != nil {
2964 return fmt.Errorf("converting field Nics: %v", err) }
2965 }
2966 }
2967 x.Pcidevs = nil
2968 if n := int(xc.num_pcidevs); n > 0 {
2969 cPcidevs := (*[1<<28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:n:n]
2970 x.Pcidevs = make([]DevicePci, n)
2971 for i, v := range cPcidevs {
2972 if err := x.Pcidevs[i].fromC(&v); err != nil {
2973 return fmt.Errorf("converting field Pcidevs: %v", err) }
2974 }
2975 }
2976 x.Rdms = nil
2977 if n := int(xc.num_rdms); n > 0 {
2978 cRdms := (*[1<<28]C.libxl_device_rdm)(unsafe.Pointer(xc.rdms))[:n:n]
2979 x.Rdms = make([]DeviceRdm, n)
2980 for i, v := range cRdms {
2981 if err := x.Rdms[i].fromC(&v); err != nil {
2982 return fmt.Errorf("converting field Rdms: %v", err) }
2983 }
2984 }
2985 x.Dtdevs = nil
2986 if n := int(xc.num_dtdevs); n > 0 {
2987 cDtdevs := (*[1<<28]C.libxl_device_dtdev)(unsafe.Pointer(xc.dtdevs))[:n:n]
2988 x.Dtdevs = make([]DeviceDtdev, n)
2989 for i, v := range cDtdevs {
2990 if err := x.Dtdevs[i].fromC(&v); err != nil {
2991 return fmt.Errorf("converting field Dtdevs: %v", err) }
2992 }
2993 }
2994 x.Vfbs = nil
2995 if n := int(xc.num_vfbs); n > 0 {
2996 cVfbs := (*[1<<28]C.libxl_device_vfb)(unsafe.Pointer(xc.vfbs))[:n:n]
2997 x.Vfbs = make([]DeviceVfb, n)
2998 for i, v := range cVfbs {
2999 if err := x.Vfbs[i].fromC(&v); err != nil {
3000 return fmt.Errorf("converting field Vfbs: %v", err) }
3001 }
3002 }
3003 x.Vkbs = nil
3004 if n := int(xc.num_vkbs); n > 0 {
3005 cVkbs := (*[1<<28]C.libxl_device_vkb)(unsafe.Pointer(xc.vkbs))[:n:n]
3006 x.Vkbs = make([]DeviceVkb, n)
3007 for i, v := range cVkbs {
3008 if err := x.Vkbs[i].fromC(&v); err != nil {
3009 return fmt.Errorf("converting field Vkbs: %v", err) }
3010 }
3011 }
3012 x.Virtios = nil
3013 if n := int(xc.num_virtios); n > 0 {
3014 cVirtios := (*[1<<28]C.libxl_device_virtio)(unsafe.Pointer(xc.virtios))[:n:n]
3015 x.Virtios = make([]DeviceVirtio, n)
3016 for i, v := range cVirtios {
3017 if err := x.Virtios[i].fromC(&v); err != nil {
3018 return fmt.Errorf("converting field Virtios: %v", err) }
3019 }
3020 }
3021 x.Vtpms = nil
3022 if n := int(xc.num_vtpms); n > 0 {
3023 cVtpms := (*[1<<28]C.libxl_device_vtpm)(unsafe.Pointer(xc.vtpms))[:n:n]
3024 x.Vtpms = make([]DeviceVtpm, n)
3025 for i, v := range cVtpms {
3026 if err := x.Vtpms[i].fromC(&v); err != nil {
3027 return fmt.Errorf("converting field Vtpms: %v", err) }
3028 }
3029 }
3030 x.P9S = nil
3031 if n := int(xc.num_p9s); n > 0 {
3032 cP9S := (*[1<<28]C.libxl_device_p9)(unsafe.Pointer(xc.p9s))[:n:n]
3033 x.P9S = make([]DeviceP9, n)
3034 for i, v := range cP9S {
3035 if err := x.P9S[i].fromC(&v); err != nil {
3036 return fmt.Errorf("converting field P9S: %v", err) }
3037 }
3038 }
3039 x.Pvcallsifs = nil
3040 if n := int(xc.num_pvcallsifs); n > 0 {
3041 cPvcallsifs := (*[1<<28]C.libxl_device_pvcallsif)(unsafe.Pointer(xc.pvcallsifs))[:n:n]
3042 x.Pvcallsifs = make([]DevicePvcallsif, n)
3043 for i, v := range cPvcallsifs {
3044 if err := x.Pvcallsifs[i].fromC(&v); err != nil {
3045 return fmt.Errorf("converting field Pvcallsifs: %v", err) }
3046 }
3047 }
3048 x.Vdispls = nil
3049 if n := int(xc.num_vdispls); n > 0 {
3050 cVdispls := (*[1<<28]C.libxl_device_vdispl)(unsafe.Pointer(xc.vdispls))[:n:n]
3051 x.Vdispls = make([]DeviceVdispl, n)
3052 for i, v := range cVdispls {
3053 if err := x.Vdispls[i].fromC(&v); err != nil {
3054 return fmt.Errorf("converting field Vdispls: %v", err) }
3055 }
3056 }
3057 x.Vsnds = nil
3058 if n := int(xc.num_vsnds); n > 0 {
3059 cVsnds := (*[1<<28]C.libxl_device_vsnd)(unsafe.Pointer(xc.vsnds))[:n:n]
3060 x.Vsnds = make([]DeviceVsnd, n)
3061 for i, v := range cVsnds {
3062 if err := x.Vsnds[i].fromC(&v); err != nil {
3063 return fmt.Errorf("converting field Vsnds: %v", err) }
3064 }
3065 }
3066 x.Channels = nil
3067 if n := int(xc.num_channels); n > 0 {
3068 cChannels := (*[1<<28]C.libxl_device_channel)(unsafe.Pointer(xc.channels))[:n:n]
3069 x.Channels = make([]DeviceChannel, n)
3070 for i, v := range cChannels {
3071 if err := x.Channels[i].fromC(&v); err != nil {
3072 return fmt.Errorf("converting field Channels: %v", err) }
3073 }
3074 }
3075 x.Usbctrls = nil
3076 if n := int(xc.num_usbctrls); n > 0 {
3077 cUsbctrls := (*[1<<28]C.libxl_device_usbctrl)(unsafe.Pointer(xc.usbctrls))[:n:n]
3078 x.Usbctrls = make([]DeviceUsbctrl, n)
3079 for i, v := range cUsbctrls {
3080 if err := x.Usbctrls[i].fromC(&v); err != nil {
3081 return fmt.Errorf("converting field Usbctrls: %v", err) }
3082 }
3083 }
3084 x.Usbdevs = nil
3085 if n := int(xc.num_usbdevs); n > 0 {
3086 cUsbdevs := (*[1<<28]C.libxl_device_usbdev)(unsafe.Pointer(xc.usbdevs))[:n:n]
3087 x.Usbdevs = make([]DeviceUsbdev, n)
3088 for i, v := range cUsbdevs {
3089 if err := x.Usbdevs[i].fromC(&v); err != nil {
3090 return fmt.Errorf("converting field Usbdevs: %v", err) }
3091 }
3092 }
3093 x.OnPoweroff = ActionOnShutdown(xc.on_poweroff)
3094 x.OnReboot = ActionOnShutdown(xc.on_reboot)
3095 x.OnWatchdog = ActionOnShutdown(xc.on_watchdog)
3096 x.OnCrash = ActionOnShutdown(xc.on_crash)
3097 x.OnSoftReset = ActionOnShutdown(xc.on_soft_reset)
3098
3099 return nil}
3100
3101 func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error){defer func(){
3102 if err != nil{
3103 C.libxl_domain_config_dispose(xc)}
3104 }()
3105
3106 if err := x.CInfo.toC(&xc.c_info); err != nil {
3107 return fmt.Errorf("converting field CInfo: %v", err)
3108 }
3109 if err := x.BInfo.toC(&xc.b_info); err != nil {
3110 return fmt.Errorf("converting field BInfo: %v", err)
3111 }
3112 if numDisks := len(x.Disks); numDisks > 0 {
3113 xc.disks = (*C.libxl_device_disk)(C.malloc(C.ulong(numDisks)*C.sizeof_libxl_device_disk))
3114 xc.num_disks = C.int(numDisks)
3115 cDisks := (*[1<<28]C.libxl_device_disk)(unsafe.Pointer(xc.disks))[:numDisks:numDisks]
3116 for i,v := range x.Disks {
3117 if err := v.toC(&cDisks[i]); err != nil {
3118 return fmt.Errorf("converting field Disks: %v", err)
3119 }
3120 }
3121 }
3122 if numNics := len(x.Nics); numNics > 0 {
3123 xc.nics = (*C.libxl_device_nic)(C.malloc(C.ulong(numNics)*C.sizeof_libxl_device_nic))
3124 xc.num_nics = C.int(numNics)
3125 cNics := (*[1<<28]C.libxl_device_nic)(unsafe.Pointer(xc.nics))[:numNics:numNics]
3126 for i,v := range x.Nics {
3127 if err := v.toC(&cNics[i]); err != nil {
3128 return fmt.Errorf("converting field Nics: %v", err)
3129 }
3130 }
3131 }
3132 if numPcidevs := len(x.Pcidevs); numPcidevs > 0 {
3133 xc.pcidevs = (*C.libxl_device_pci)(C.malloc(C.ulong(numPcidevs)*C.sizeof_libxl_device_pci))
3134 xc.num_pcidevs = C.int(numPcidevs)
3135 cPcidevs := (*[1<<28]C.libxl_device_pci)(unsafe.Pointer(xc.pcidevs))[:numPcidevs:numPcidevs]
3136 for i,v := range x.Pcidevs {
3137 if err := v.toC(&cPcidevs[i]); err != nil {
3138 return fmt.Errorf("converting field Pcidevs: %v", err)
3139 }
3140 }
3141 }
3142 if numRdms := len(x.Rdms); numRdms > 0 {
3143 xc.rdms = (*C.libxl_device_rdm)(C.malloc(C.ulong(numRdms)*C.sizeof_libxl_device_rdm))
3144 xc.num_rdms = C.int(numRdms)
3145 cRdms := (*[1<<28]C.libxl_device_rdm)(unsafe.Pointer(xc.rdms))[:numRdms:numRdms]
3146 for i,v := range x.Rdms {
3147 if err := v.toC(&cRdms[i]); err != nil {
3148 return fmt.Errorf("converting field Rdms: %v", err)
3149 }
3150 }
3151 }
3152 if numDtdevs := len(x.Dtdevs); numDtdevs > 0 {
3153 xc.dtdevs = (*C.libxl_device_dtdev)(C.malloc(C.ulong(numDtdevs)*C.sizeof_libxl_device_dtdev))
3154 xc.num_dtdevs = C.int(numDtdevs)
3155 cDtdevs := (*[1<<28]C.libxl_device_dtdev)(unsafe.Pointer(xc.dtdevs))[:numDtdevs:numDtdevs]
3156 for i,v := range x.Dtdevs {
3157 if err := v.toC(&cDtdevs[i]); err != nil {
3158 return fmt.Errorf("converting field Dtdevs: %v", err)
3159 }
3160 }
3161 }
3162 if numVfbs := len(x.Vfbs); numVfbs > 0 {
3163 xc.vfbs = (*C.libxl_device_vfb)(C.malloc(C.ulong(numVfbs)*C.sizeof_libxl_device_vfb))
3164 xc.num_vfbs = C.int(numVfbs)
3165 cVfbs := (*[1<<28]C.libxl_device_vfb)(unsafe.Pointer(xc.vfbs))[:numVfbs:numVfbs]
3166 for i,v := range x.Vfbs {
3167 if err := v.toC(&cVfbs[i]); err != nil {
3168 return fmt.Errorf("converting field Vfbs: %v", err)
3169 }
3170 }
3171 }
3172 if numVkbs := len(x.Vkbs); numVkbs > 0 {
3173 xc.vkbs = (*C.libxl_device_vkb)(C.malloc(C.ulong(numVkbs)*C.sizeof_libxl_device_vkb))
3174 xc.num_vkbs = C.int(numVkbs)
3175 cVkbs := (*[1<<28]C.libxl_device_vkb)(unsafe.Pointer(xc.vkbs))[:numVkbs:numVkbs]
3176 for i,v := range x.Vkbs {
3177 if err := v.toC(&cVkbs[i]); err != nil {
3178 return fmt.Errorf("converting field Vkbs: %v", err)
3179 }
3180 }
3181 }
3182 if numVirtios := len(x.Virtios); numVirtios > 0 {
3183 xc.virtios = (*C.libxl_device_virtio)(C.malloc(C.ulong(numVirtios)*C.sizeof_libxl_device_virtio))
3184 xc.num_virtios = C.int(numVirtios)
3185 cVirtios := (*[1<<28]C.libxl_device_virtio)(unsafe.Pointer(xc.virtios))[:numVirtios:numVirtios]
3186 for i,v := range x.Virtios {
3187 if err := v.toC(&cVirtios[i]); err != nil {
3188 return fmt.Errorf("converting field Virtios: %v", err)
3189 }
3190 }
3191 }
3192 if numVtpms := len(x.Vtpms); numVtpms > 0 {
3193 xc.vtpms = (*C.libxl_device_vtpm)(C.malloc(C.ulong(numVtpms)*C.sizeof_libxl_device_vtpm))
3194 xc.num_vtpms = C.int(numVtpms)
3195 cVtpms := (*[1<<28]C.libxl_device_vtpm)(unsafe.Pointer(xc.vtpms))[:numVtpms:numVtpms]
3196 for i,v := range x.Vtpms {
3197 if err := v.toC(&cVtpms[i]); err != nil {
3198 return fmt.Errorf("converting field Vtpms: %v", err)
3199 }
3200 }
3201 }
3202 if numP9S := len(x.P9S); numP9S > 0 {
3203 xc.p9s = (*C.libxl_device_p9)(C.malloc(C.ulong(numP9S)*C.sizeof_libxl_device_p9))
3204 xc.num_p9s = C.int(numP9S)
3205 cP9S := (*[1<<28]C.libxl_device_p9)(unsafe.Pointer(xc.p9s))[:numP9S:numP9S]
3206 for i,v := range x.P9S {
3207 if err := v.toC(&cP9S[i]); err != nil {
3208 return fmt.Errorf("converting field P9S: %v", err)
3209 }
3210 }
3211 }
3212 if numPvcallsifs := len(x.Pvcallsifs); numPvcallsifs > 0 {
3213 xc.pvcallsifs = (*C.libxl_device_pvcallsif)(C.malloc(C.ulong(numPvcallsifs)*C.sizeof_libxl_device_pvcallsif))
3214 xc.num_pvcallsifs = C.int(numPvcallsifs)
3215 cPvcallsifs := (*[1<<28]C.libxl_device_pvcallsif)(unsafe.Pointer(xc.pvcallsifs))[:numPvcallsifs:numPvcallsifs]
3216 for i,v := range x.Pvcallsifs {
3217 if err := v.toC(&cPvcallsifs[i]); err != nil {
3218 return fmt.Errorf("converting field Pvcallsifs: %v", err)
3219 }
3220 }
3221 }
3222 if numVdispls := len(x.Vdispls); numVdispls > 0 {
3223 xc.vdispls = (*C.libxl_device_vdispl)(C.malloc(C.ulong(numVdispls)*C.sizeof_libxl_device_vdispl))
3224 xc.num_vdispls = C.int(numVdispls)
3225 cVdispls := (*[1<<28]C.libxl_device_vdispl)(unsafe.Pointer(xc.vdispls))[:numVdispls:numVdispls]
3226 for i,v := range x.Vdispls {
3227 if err := v.toC(&cVdispls[i]); err != nil {
3228 return fmt.Errorf("converting field Vdispls: %v", err)
3229 }
3230 }
3231 }
3232 if numVsnds := len(x.Vsnds); numVsnds > 0 {
3233 xc.vsnds = (*C.libxl_device_vsnd)(C.malloc(C.ulong(numVsnds)*C.sizeof_libxl_device_vsnd))
3234 xc.num_vsnds = C.int(numVsnds)
3235 cVsnds := (*[1<<28]C.libxl_device_vsnd)(unsafe.Pointer(xc.vsnds))[:numVsnds:numVsnds]
3236 for i,v := range x.Vsnds {
3237 if err := v.toC(&cVsnds[i]); err != nil {
3238 return fmt.Errorf("converting field Vsnds: %v", err)
3239 }
3240 }
3241 }
3242 if numChannels := len(x.Channels); numChannels > 0 {
3243 xc.channels = (*C.libxl_device_channel)(C.malloc(C.ulong(numChannels)*C.sizeof_libxl_device_channel))
3244 xc.num_channels = C.int(numChannels)
3245 cChannels := (*[1<<28]C.libxl_device_channel)(unsafe.Pointer(xc.channels))[:numChannels:numChannels]
3246 for i,v := range x.Channels {
3247 if err := v.toC(&cChannels[i]); err != nil {
3248 return fmt.Errorf("converting field Channels: %v", err)
3249 }
3250 }
3251 }
3252 if numUsbctrls := len(x.Usbctrls); numUsbctrls > 0 {
3253 xc.usbctrls = (*C.libxl_device_usbctrl)(C.malloc(C.ulong(numUsbctrls)*C.sizeof_libxl_device_usbctrl))
3254 xc.num_usbctrls = C.int(numUsbctrls)
3255 cUsbctrls := (*[1<<28]C.libxl_device_usbctrl)(unsafe.Pointer(xc.usbctrls))[:numUsbctrls:numUsbctrls]
3256 for i,v := range x.Usbctrls {
3257 if err := v.toC(&cUsbctrls[i]); err != nil {
3258 return fmt.Errorf("converting field Usbctrls: %v", err)
3259 }
3260 }
3261 }
3262 if numUsbdevs := len(x.Usbdevs); numUsbdevs > 0 {
3263 xc.usbdevs = (*C.libxl_device_usbdev)(C.malloc(C.ulong(numUsbdevs)*C.sizeof_libxl_device_usbdev))
3264 xc.num_usbdevs = C.int(numUsbdevs)
3265 cUsbdevs := (*[1<<28]C.libxl_device_usbdev)(unsafe.Pointer(xc.usbdevs))[:numUsbdevs:numUsbdevs]
3266 for i,v := range x.Usbdevs {
3267 if err := v.toC(&cUsbdevs[i]); err != nil {
3268 return fmt.Errorf("converting field Usbdevs: %v", err)
3269 }
3270 }
3271 }
3272 xc.on_poweroff = C.libxl_action_on_shutdown(x.OnPoweroff)
3273 xc.on_reboot = C.libxl_action_on_shutdown(x.OnReboot)
3274 xc.on_watchdog = C.libxl_action_on_shutdown(x.OnWatchdog)
3275 xc.on_crash = C.libxl_action_on_shutdown(x.OnCrash)
3276 xc.on_soft_reset = C.libxl_action_on_shutdown(x.OnSoftReset)
3277
3278 return nil
3279 }
3280
3281 // NewDiskinfo returns an instance of Diskinfo initialized with defaults.
3282 func NewDiskinfo() (*Diskinfo, error) {
3283 var (
3284 x Diskinfo
3285 xc C.libxl_diskinfo)
3286
3287 C.libxl_diskinfo_init(&xc)
3288 defer C.libxl_diskinfo_dispose(&xc)
3289
3290 if err := x.fromC(&xc); err != nil {
3291 return nil, err }
3292
3293 return &x, nil}
3294
3295 func (x *Diskinfo) fromC(xc *C.libxl_diskinfo) error {
3296 x.Backend = C.GoString(xc.backend)
3297 x.BackendId = uint32(xc.backend_id)
3298 x.Frontend = C.GoString(xc.frontend)
3299 x.FrontendId = uint32(xc.frontend_id)
3300 x.Devid = Devid(xc.devid)
3301 x.State = int(xc.state)
3302 x.Evtch = int(xc.evtch)
3303 x.Rref = int(xc.rref)
3304
3305 return nil}
3306
3307 func (x *Diskinfo) toC(xc *C.libxl_diskinfo) (err error){defer func(){
3308 if err != nil{
3309 C.libxl_diskinfo_dispose(xc)}
3310 }()
3311
3312 if x.Backend != "" {
3313 xc.backend = C.CString(x.Backend)}
3314 xc.backend_id = C.uint32_t(x.BackendId)
3315 if x.Frontend != "" {
3316 xc.frontend = C.CString(x.Frontend)}
3317 xc.frontend_id = C.uint32_t(x.FrontendId)
3318 xc.devid = C.libxl_devid(x.Devid)
3319 xc.state = C.int(x.State)
3320 xc.evtch = C.int(x.Evtch)
3321 xc.rref = C.int(x.Rref)
3322
3323 return nil
3324 }
3325
3326 // NewNicinfo returns an instance of Nicinfo initialized with defaults.
3327 func NewNicinfo() (*Nicinfo, error) {
3328 var (
3329 x Nicinfo
3330 xc C.libxl_nicinfo)
3331
3332 C.libxl_nicinfo_init(&xc)
3333 defer C.libxl_nicinfo_dispose(&xc)
3334
3335 if err := x.fromC(&xc); err != nil {
3336 return nil, err }
3337
3338 return &x, nil}
3339
3340 func (x *Nicinfo) fromC(xc *C.libxl_nicinfo) error {
3341 x.Backend = C.GoString(xc.backend)
3342 x.BackendId = uint32(xc.backend_id)
3343 x.Frontend = C.GoString(xc.frontend)
3344 x.FrontendId = uint32(xc.frontend_id)
3345 x.Devid = Devid(xc.devid)
3346 x.State = int(xc.state)
3347 x.Evtch = int(xc.evtch)
3348 x.RrefTx = int(xc.rref_tx)
3349 x.RrefRx = int(xc.rref_rx)
3350
3351 return nil}
3352
3353 func (x *Nicinfo) toC(xc *C.libxl_nicinfo) (err error){defer func(){
3354 if err != nil{
3355 C.libxl_nicinfo_dispose(xc)}
3356 }()
3357
3358 if x.Backend != "" {
3359 xc.backend = C.CString(x.Backend)}
3360 xc.backend_id = C.uint32_t(x.BackendId)
3361 if x.Frontend != "" {
3362 xc.frontend = C.CString(x.Frontend)}
3363 xc.frontend_id = C.uint32_t(x.FrontendId)
3364 xc.devid = C.libxl_devid(x.Devid)
3365 xc.state = C.int(x.State)
3366 xc.evtch = C.int(x.Evtch)
3367 xc.rref_tx = C.int(x.RrefTx)
3368 xc.rref_rx = C.int(x.RrefRx)
3369
3370 return nil
3371 }
3372
3373 // NewVtpminfo returns an instance of Vtpminfo initialized with defaults.
3374 func NewVtpminfo() (*Vtpminfo, error) {
3375 var (
3376 x Vtpminfo
3377 xc C.libxl_vtpminfo)
3378
3379 C.libxl_vtpminfo_init(&xc)
3380 defer C.libxl_vtpminfo_dispose(&xc)
3381
3382 if err := x.fromC(&xc); err != nil {
3383 return nil, err }
3384
3385 return &x, nil}
3386
3387 func (x *Vtpminfo) fromC(xc *C.libxl_vtpminfo) error {
3388 x.Backend = C.GoString(xc.backend)
3389 x.BackendId = uint32(xc.backend_id)
3390 x.Frontend = C.GoString(xc.frontend)
3391 x.FrontendId = uint32(xc.frontend_id)
3392 x.Devid = Devid(xc.devid)
3393 x.State = int(xc.state)
3394 x.Evtch = int(xc.evtch)
3395 x.Rref = int(xc.rref)
3396 if err := x.Uuid.fromC(&xc.uuid);err != nil {
3397 return fmt.Errorf("converting field Uuid: %v", err)
3398 }
3399
3400 return nil}
3401
3402 func (x *Vtpminfo) toC(xc *C.libxl_vtpminfo) (err error){defer func(){
3403 if err != nil{
3404 C.libxl_vtpminfo_dispose(xc)}
3405 }()
3406
3407 if x.Backend != "" {
3408 xc.backend = C.CString(x.Backend)}
3409 xc.backend_id = C.uint32_t(x.BackendId)
3410 if x.Frontend != "" {
3411 xc.frontend = C.CString(x.Frontend)}
3412 xc.frontend_id = C.uint32_t(x.FrontendId)
3413 xc.devid = C.libxl_devid(x.Devid)
3414 xc.state = C.int(x.State)
3415 xc.evtch = C.int(x.Evtch)
3416 xc.rref = C.int(x.Rref)
3417 if err := x.Uuid.toC(&xc.uuid); err != nil {
3418 return fmt.Errorf("converting field Uuid: %v", err)
3419 }
3420
3421 return nil
3422 }
3423
3424 // NewUsbctrlinfo returns an instance of Usbctrlinfo initialized with defaults.
3425 func NewUsbctrlinfo() (*Usbctrlinfo, error) {
3426 var (
3427 x Usbctrlinfo
3428 xc C.libxl_usbctrlinfo)
3429
3430 C.libxl_usbctrlinfo_init(&xc)
3431 defer C.libxl_usbctrlinfo_dispose(&xc)
3432
3433 if err := x.fromC(&xc); err != nil {
3434 return nil, err }
3435
3436 return &x, nil}
3437
3438 func (x *Usbctrlinfo) fromC(xc *C.libxl_usbctrlinfo) error {
3439 x.Type = UsbctrlType(xc._type)
3440 x.Devid = Devid(xc.devid)
3441 x.Version = int(xc.version)
3442 x.Ports = int(xc.ports)
3443 x.Backend = C.GoString(xc.backend)
3444 x.BackendId = uint32(xc.backend_id)
3445 x.Frontend = C.GoString(xc.frontend)
3446 x.FrontendId = uint32(xc.frontend_id)
3447 x.State = int(xc.state)
3448 x.Evtch = int(xc.evtch)
3449 x.RefUrb = int(xc.ref_urb)
3450 x.RefConn = int(xc.ref_conn)
3451
3452 return nil}
3453
3454 func (x *Usbctrlinfo) toC(xc *C.libxl_usbctrlinfo) (err error){defer func(){
3455 if err != nil{
3456 C.libxl_usbctrlinfo_dispose(xc)}
3457 }()
3458
3459 xc._type = C.libxl_usbctrl_type(x.Type)
3460 xc.devid = C.libxl_devid(x.Devid)
3461 xc.version = C.int(x.Version)
3462 xc.ports = C.int(x.Ports)
3463 if x.Backend != "" {
3464 xc.backend = C.CString(x.Backend)}
3465 xc.backend_id = C.uint32_t(x.BackendId)
3466 if x.Frontend != "" {
3467 xc.frontend = C.CString(x.Frontend)}
3468 xc.frontend_id = C.uint32_t(x.FrontendId)
3469 xc.state = C.int(x.State)
3470 xc.evtch = C.int(x.Evtch)
3471 xc.ref_urb = C.int(x.RefUrb)
3472 xc.ref_conn = C.int(x.RefConn)
3473
3474 return nil
3475 }
3476
3477 // NewVcpuinfo returns an instance of Vcpuinfo initialized with defaults.
3478 func NewVcpuinfo() (*Vcpuinfo, error) {
3479 var (
3480 x Vcpuinfo
3481 xc C.libxl_vcpuinfo)
3482
3483 C.libxl_vcpuinfo_init(&xc)
3484 defer C.libxl_vcpuinfo_dispose(&xc)
3485
3486 if err := x.fromC(&xc); err != nil {
3487 return nil, err }
3488
3489 return &x, nil}
3490
3491 func (x *Vcpuinfo) fromC(xc *C.libxl_vcpuinfo) error {
3492 x.Vcpuid = uint32(xc.vcpuid)
3493 x.Cpu = uint32(xc.cpu)
3494 x.Online = bool(xc.online)
3495 x.Blocked = bool(xc.blocked)
3496 x.Running = bool(xc.running)
3497 x.VcpuTime = uint64(xc.vcpu_time)
3498 if err := x.Cpumap.fromC(&xc.cpumap);err != nil {
3499 return fmt.Errorf("converting field Cpumap: %v", err)
3500 }
3501 if err := x.CpumapSoft.fromC(&xc.cpumap_soft);err != nil {
3502 return fmt.Errorf("converting field CpumapSoft: %v", err)
3503 }
3504
3505 return nil}
3506
3507 func (x *Vcpuinfo) toC(xc *C.libxl_vcpuinfo) (err error){defer func(){
3508 if err != nil{
3509 C.libxl_vcpuinfo_dispose(xc)}
3510 }()
3511
3512 xc.vcpuid = C.uint32_t(x.Vcpuid)
3513 xc.cpu = C.uint32_t(x.Cpu)
3514 xc.online = C.bool(x.Online)
3515 xc.blocked = C.bool(x.Blocked)
3516 xc.running = C.bool(x.Running)
3517 xc.vcpu_time = C.uint64_t(x.VcpuTime)
3518 if err := x.Cpumap.toC(&xc.cpumap); err != nil {
3519 return fmt.Errorf("converting field Cpumap: %v", err)
3520 }
3521 if err := x.CpumapSoft.toC(&xc.cpumap_soft); err != nil {
3522 return fmt.Errorf("converting field CpumapSoft: %v", err)
3523 }
3524
3525 return nil
3526 }
3527
3528 // NewPhysinfo returns an instance of Physinfo initialized with defaults.
3529 func NewPhysinfo() (*Physinfo, error) {
3530 var (
3531 x Physinfo
3532 xc C.libxl_physinfo)
3533
3534 C.libxl_physinfo_init(&xc)
3535 defer C.libxl_physinfo_dispose(&xc)
3536
3537 if err := x.fromC(&xc); err != nil {
3538 return nil, err }
3539
3540 return &x, nil}
3541
3542 func (x *Physinfo) fromC(xc *C.libxl_physinfo) error {
3543 x.ThreadsPerCore = uint32(xc.threads_per_core)
3544 x.CoresPerSocket = uint32(xc.cores_per_socket)
3545 x.MaxCpuId = uint32(xc.max_cpu_id)
3546 x.NrCpus = uint32(xc.nr_cpus)
3547 x.CpuKhz = uint32(xc.cpu_khz)
3548 x.TotalPages = uint64(xc.total_pages)
3549 x.FreePages = uint64(xc.free_pages)
3550 x.ScrubPages = uint64(xc.scrub_pages)
3551 x.OutstandingPages = uint64(xc.outstanding_pages)
3552 x.SharingFreedPages = uint64(xc.sharing_freed_pages)
3553 x.SharingUsedFrames = uint64(xc.sharing_used_frames)
3554 x.MaxPossibleMfn = uint64(xc.max_possible_mfn)
3555 x.NrNodes = uint32(xc.nr_nodes)
3556 if err := x.HwCap.fromC(&xc.hw_cap);err != nil {
3557 return fmt.Errorf("converting field HwCap: %v", err)
3558 }
3559 x.CapHvm = bool(xc.cap_hvm)
3560 x.CapPv = bool(xc.cap_pv)
3561 x.CapHvmDirectio = bool(xc.cap_hvm_directio)
3562 x.CapHap = bool(xc.cap_hap)
3563 x.CapShadow = bool(xc.cap_shadow)
3564 x.CapIommuHapPtShare = bool(xc.cap_iommu_hap_pt_share)
3565 x.CapVmtrace = bool(xc.cap_vmtrace)
3566 x.CapVpmu = bool(xc.cap_vpmu)
3567 x.CapGnttabV1 = bool(xc.cap_gnttab_v1)
3568 x.CapGnttabV2 = bool(xc.cap_gnttab_v2)
3569 x.ArchCapabilities = uint32(xc.arch_capabilities)
3570
3571 return nil}
3572
3573 func (x *Physinfo) toC(xc *C.libxl_physinfo) (err error){defer func(){
3574 if err != nil{
3575 C.libxl_physinfo_dispose(xc)}
3576 }()
3577
3578 xc.threads_per_core = C.uint32_t(x.ThreadsPerCore)
3579 xc.cores_per_socket = C.uint32_t(x.CoresPerSocket)
3580 xc.max_cpu_id = C.uint32_t(x.MaxCpuId)
3581 xc.nr_cpus = C.uint32_t(x.NrCpus)
3582 xc.cpu_khz = C.uint32_t(x.CpuKhz)
3583 xc.total_pages = C.uint64_t(x.TotalPages)
3584 xc.free_pages = C.uint64_t(x.FreePages)
3585 xc.scrub_pages = C.uint64_t(x.ScrubPages)
3586 xc.outstanding_pages = C.uint64_t(x.OutstandingPages)
3587 xc.sharing_freed_pages = C.uint64_t(x.SharingFreedPages)
3588 xc.sharing_used_frames = C.uint64_t(x.SharingUsedFrames)
3589 xc.max_possible_mfn = C.uint64_t(x.MaxPossibleMfn)
3590 xc.nr_nodes = C.uint32_t(x.NrNodes)
3591 if err := x.HwCap.toC(&xc.hw_cap); err != nil {
3592 return fmt.Errorf("converting field HwCap: %v", err)
3593 }
3594 xc.cap_hvm = C.bool(x.CapHvm)
3595 xc.cap_pv = C.bool(x.CapPv)
3596 xc.cap_hvm_directio = C.bool(x.CapHvmDirectio)
3597 xc.cap_hap = C.bool(x.CapHap)
3598 xc.cap_shadow = C.bool(x.CapShadow)
3599 xc.cap_iommu_hap_pt_share = C.bool(x.CapIommuHapPtShare)
3600 xc.cap_vmtrace = C.bool(x.CapVmtrace)
3601 xc.cap_vpmu = C.bool(x.CapVpmu)
3602 xc.cap_gnttab_v1 = C.bool(x.CapGnttabV1)
3603 xc.cap_gnttab_v2 = C.bool(x.CapGnttabV2)
3604 xc.arch_capabilities = C.uint32_t(x.ArchCapabilities)
3605
3606 return nil
3607 }
3608
3609 // NewConnectorinfo returns an instance of Connectorinfo initialized with defaults.
3610 func NewConnectorinfo() (*Connectorinfo, error) {
3611 var (
3612 x Connectorinfo
3613 xc C.libxl_connectorinfo)
3614
3615 C.libxl_connectorinfo_init(&xc)
3616 defer C.libxl_connectorinfo_dispose(&xc)
3617
3618 if err := x.fromC(&xc); err != nil {
3619 return nil, err }
3620
3621 return &x, nil}
3622
3623 func (x *Connectorinfo) fromC(xc *C.libxl_connectorinfo) error {
3624 x.UniqueId = C.GoString(xc.unique_id)
3625 x.Width = uint32(xc.width)
3626 x.Height = uint32(xc.height)
3627 x.ReqEvtch = int(xc.req_evtch)
3628 x.ReqRref = int(xc.req_rref)
3629 x.EvtEvtch = int(xc.evt_evtch)
3630 x.EvtRref = int(xc.evt_rref)
3631
3632 return nil}
3633
3634 func (x *Connectorinfo) toC(xc *C.libxl_connectorinfo) (err error){defer func(){
3635 if err != nil{
3636 C.libxl_connectorinfo_dispose(xc)}
3637 }()
3638
3639 if x.UniqueId != "" {
3640 xc.unique_id = C.CString(x.UniqueId)}
3641 xc.width = C.uint32_t(x.Width)
3642 xc.height = C.uint32_t(x.Height)
3643 xc.req_evtch = C.int(x.ReqEvtch)
3644 xc.req_rref = C.int(x.ReqRref)
3645 xc.evt_evtch = C.int(x.EvtEvtch)
3646 xc.evt_rref = C.int(x.EvtRref)
3647
3648 return nil
3649 }
3650
3651 // NewVdisplinfo returns an instance of Vdisplinfo initialized with defaults.
3652 func NewVdisplinfo() (*Vdisplinfo, error) {
3653 var (
3654 x Vdisplinfo
3655 xc C.libxl_vdisplinfo)
3656
3657 C.libxl_vdisplinfo_init(&xc)
3658 defer C.libxl_vdisplinfo_dispose(&xc)
3659
3660 if err := x.fromC(&xc); err != nil {
3661 return nil, err }
3662
3663 return &x, nil}
3664
3665 func (x *Vdisplinfo) fromC(xc *C.libxl_vdisplinfo) error {
3666 x.Backend = C.GoString(xc.backend)
3667 x.BackendId = uint32(xc.backend_id)
3668 x.Frontend = C.GoString(xc.frontend)
3669 x.FrontendId = uint32(xc.frontend_id)
3670 x.Devid = Devid(xc.devid)
3671 x.State = int(xc.state)
3672 x.BeAlloc = bool(xc.be_alloc)
3673 x.Connectors = nil
3674 if n := int(xc.num_connectors); n > 0 {
3675 cConnectors := (*[1<<28]C.libxl_connectorinfo)(unsafe.Pointer(xc.connectors))[:n:n]
3676 x.Connectors = make([]Connectorinfo, n)
3677 for i, v := range cConnectors {
3678 if err := x.Connectors[i].fromC(&v); err != nil {
3679 return fmt.Errorf("converting field Connectors: %v", err) }
3680 }
3681 }
3682
3683 return nil}
3684
3685 func (x *Vdisplinfo) toC(xc *C.libxl_vdisplinfo) (err error){defer func(){
3686 if err != nil{
3687 C.libxl_vdisplinfo_dispose(xc)}
3688 }()
3689
3690 if x.Backend != "" {
3691 xc.backend = C.CString(x.Backend)}
3692 xc.backend_id = C.uint32_t(x.BackendId)
3693 if x.Frontend != "" {
3694 xc.frontend = C.CString(x.Frontend)}
3695 xc.frontend_id = C.uint32_t(x.FrontendId)
3696 xc.devid = C.libxl_devid(x.Devid)
3697 xc.state = C.int(x.State)
3698 xc.be_alloc = C.bool(x.BeAlloc)
3699 if numConnectors := len(x.Connectors); numConnectors > 0 {
3700 xc.connectors = (*C.libxl_connectorinfo)(C.malloc(C.ulong(numConnectors)*C.sizeof_libxl_connectorinfo))
3701 xc.num_connectors = C.int(numConnectors)
3702 cConnectors := (*[1<<28]C.libxl_connectorinfo)(unsafe.Pointer(xc.connectors))[:numConnectors:numConnectors]
3703 for i,v := range x.Connectors {
3704 if err := v.toC(&cConnectors[i]); err != nil {
3705 return fmt.Errorf("converting field Connectors: %v", err)
3706 }
3707 }
3708 }
3709
3710 return nil
3711 }
3712
3713 // NewStreaminfo returns an instance of Streaminfo initialized with defaults.
3714 func NewStreaminfo() (*Streaminfo, error) {
3715 var (
3716 x Streaminfo
3717 xc C.libxl_streaminfo)
3718
3719 C.libxl_streaminfo_init(&xc)
3720 defer C.libxl_streaminfo_dispose(&xc)
3721
3722 if err := x.fromC(&xc); err != nil {
3723 return nil, err }
3724
3725 return &x, nil}
3726
3727 func (x *Streaminfo) fromC(xc *C.libxl_streaminfo) error {
3728 x.ReqEvtch = int(xc.req_evtch)
3729 x.ReqRref = int(xc.req_rref)
3730
3731 return nil}
3732
3733 func (x *Streaminfo) toC(xc *C.libxl_streaminfo) (err error){defer func(){
3734 if err != nil{
3735 C.libxl_streaminfo_dispose(xc)}
3736 }()
3737
3738 xc.req_evtch = C.int(x.ReqEvtch)
3739 xc.req_rref = C.int(x.ReqRref)
3740
3741 return nil
3742 }
3743
3744 // NewPcminfo returns an instance of Pcminfo initialized with defaults.
3745 func NewPcminfo() (*Pcminfo, error) {
3746 var (
3747 x Pcminfo
3748 xc C.libxl_pcminfo)
3749
3750 C.libxl_pcminfo_init(&xc)
3751 defer C.libxl_pcminfo_dispose(&xc)
3752
3753 if err := x.fromC(&xc); err != nil {
3754 return nil, err }
3755
3756 return &x, nil}
3757
3758 func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error {
3759 x.Streams = nil
3760 if n := int(xc.num_vsnd_streams); n > 0 {
3761 cStreams := (*[1<<28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:n:n]
3762 x.Streams = make([]Streaminfo, n)
3763 for i, v := range cStreams {
3764 if err := x.Streams[i].fromC(&v); err != nil {
3765 return fmt.Errorf("converting field Streams: %v", err) }
3766 }
3767 }
3768
3769 return nil}
3770
3771 func (x *Pcminfo) toC(xc *C.libxl_pcminfo) (err error){defer func(){
3772 if err != nil{
3773 C.libxl_pcminfo_dispose(xc)}
3774 }()
3775
3776 if numVsndStreams := len(x.Streams); numVsndStreams > 0 {
3777 xc.streams = (*C.libxl_streaminfo)(C.malloc(C.ulong(numVsndStreams)*C.sizeof_libxl_streaminfo))
3778 xc.num_vsnd_streams = C.int(numVsndStreams)
3779 cStreams := (*[1<<28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams]
3780 for i,v := range x.Streams {
3781 if err := v.toC(&cStreams[i]); err != nil {
3782 return fmt.Errorf("converting field Streams: %v", err)
3783 }
3784 }
3785 }
3786
3787 return nil
3788 }
3789
3790 // NewVsndinfo returns an instance of Vsndinfo initialized with defaults.
3791 func NewVsndinfo() (*Vsndinfo, error) {
3792 var (
3793 x Vsndinfo
3794 xc C.libxl_vsndinfo)
3795
3796 C.libxl_vsndinfo_init(&xc)
3797 defer C.libxl_vsndinfo_dispose(&xc)
3798
3799 if err := x.fromC(&xc); err != nil {
3800 return nil, err }
3801
3802 return &x, nil}
3803
3804 func (x *Vsndinfo) fromC(xc *C.libxl_vsndinfo) error {
3805 x.Backend = C.GoString(xc.backend)
3806 x.BackendId = uint32(xc.backend_id)
3807 x.Frontend = C.GoString(xc.frontend)
3808 x.FrontendId = uint32(xc.frontend_id)
3809 x.Devid = Devid(xc.devid)
3810 x.State = int(xc.state)
3811 x.Pcms = nil
3812 if n := int(xc.num_vsnd_pcms); n > 0 {
3813 cPcms := (*[1<<28]C.libxl_pcminfo)(unsafe.Pointer(xc.pcms))[:n:n]
3814 x.Pcms = make([]Pcminfo, n)
3815 for i, v := range cPcms {
3816 if err := x.Pcms[i].fromC(&v); err != nil {
3817 return fmt.Errorf("converting field Pcms: %v", err) }
3818 }
3819 }
3820
3821 return nil}
3822
3823 func (x *Vsndinfo) toC(xc *C.libxl_vsndinfo) (err error){defer func(){
3824 if err != nil{
3825 C.libxl_vsndinfo_dispose(xc)}
3826 }()
3827
3828 if x.Backend != "" {
3829 xc.backend = C.CString(x.Backend)}
3830 xc.backend_id = C.uint32_t(x.BackendId)
3831 if x.Frontend != "" {
3832 xc.frontend = C.CString(x.Frontend)}
3833 xc.frontend_id = C.uint32_t(x.FrontendId)
3834 xc.devid = C.libxl_devid(x.Devid)
3835 xc.state = C.int(x.State)
3836 if numVsndPcms := len(x.Pcms); numVsndPcms > 0 {
3837 xc.pcms = (*C.libxl_pcminfo)(C.malloc(C.ulong(numVsndPcms)*C.sizeof_libxl_pcminfo))
3838 xc.num_vsnd_pcms = C.int(numVsndPcms)
3839 cPcms := (*[1<<28]C.libxl_pcminfo)(unsafe.Pointer(xc.pcms))[:numVsndPcms:numVsndPcms]
3840 for i,v := range x.Pcms {
3841 if err := v.toC(&cPcms[i]); err != nil {
3842 return fmt.Errorf("converting field Pcms: %v", err)
3843 }
3844 }
3845 }
3846
3847 return nil
3848 }
3849
3850 // NewVkbinfo returns an instance of Vkbinfo initialized with defaults.
3851 func NewVkbinfo() (*Vkbinfo, error) {
3852 var (
3853 x Vkbinfo
3854 xc C.libxl_vkbinfo)
3855
3856 C.libxl_vkbinfo_init(&xc)
3857 defer C.libxl_vkbinfo_dispose(&xc)
3858
3859 if err := x.fromC(&xc); err != nil {
3860 return nil, err }
3861
3862 return &x, nil}
3863
3864 func (x *Vkbinfo) fromC(xc *C.libxl_vkbinfo) error {
3865 x.Backend = C.GoString(xc.backend)
3866 x.BackendId = uint32(xc.backend_id)
3867 x.Frontend = C.GoString(xc.frontend)
3868 x.FrontendId = uint32(xc.frontend_id)
3869 x.Devid = Devid(xc.devid)
3870 x.State = int(xc.state)
3871 x.Evtch = int(xc.evtch)
3872 x.Rref = int(xc.rref)
3873
3874 return nil}
3875
3876 func (x *Vkbinfo) toC(xc *C.libxl_vkbinfo) (err error){defer func(){
3877 if err != nil{
3878 C.libxl_vkbinfo_dispose(xc)}
3879 }()
3880
3881 if x.Backend != "" {
3882 xc.backend = C.CString(x.Backend)}
3883 xc.backend_id = C.uint32_t(x.BackendId)
3884 if x.Frontend != "" {
3885 xc.frontend = C.CString(x.Frontend)}
3886 xc.frontend_id = C.uint32_t(x.FrontendId)
3887 xc.devid = C.libxl_devid(x.Devid)
3888 xc.state = C.int(x.State)
3889 xc.evtch = C.int(x.Evtch)
3890 xc.rref = C.int(x.Rref)
3891
3892 return nil
3893 }
3894
3895 // NewNumainfo returns an instance of Numainfo initialized with defaults.
3896 func NewNumainfo() (*Numainfo, error) {
3897 var (
3898 x Numainfo
3899 xc C.libxl_numainfo)
3900
3901 C.libxl_numainfo_init(&xc)
3902 defer C.libxl_numainfo_dispose(&xc)
3903
3904 if err := x.fromC(&xc); err != nil {
3905 return nil, err }
3906
3907 return &x, nil}
3908
3909 func (x *Numainfo) fromC(xc *C.libxl_numainfo) error {
3910 x.Size = uint64(xc.size)
3911 x.Free = uint64(xc.free)
3912 x.Dists = nil
3913 if n := int(xc.num_dists); n > 0 {
3914 cDists := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.dists))[:n:n]
3915 x.Dists = make([]uint32, n)
3916 for i, v := range cDists {
3917 x.Dists[i] = uint32(v)
3918 }
3919 }
3920
3921 return nil}
3922
3923 func (x *Numainfo) toC(xc *C.libxl_numainfo) (err error){defer func(){
3924 if err != nil{
3925 C.libxl_numainfo_dispose(xc)}
3926 }()
3927
3928 xc.size = C.uint64_t(x.Size)
3929 xc.free = C.uint64_t(x.Free)
3930 if numDists := len(x.Dists); numDists > 0 {
3931 xc.dists = (*C.uint32_t)(C.malloc(C.size_t(numDists*numDists)))
3932 xc.num_dists = C.int(numDists)
3933 cDists := (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.dists))[:numDists:numDists]
3934 for i,v := range x.Dists {
3935 cDists[i] = C.uint32_t(v)
3936 }
3937 }
3938
3939 return nil
3940 }
3941
3942 // NewCputopology returns an instance of Cputopology initialized with defaults.
3943 func NewCputopology() (*Cputopology, error) {
3944 var (
3945 x Cputopology
3946 xc C.libxl_cputopology)
3947
3948 C.libxl_cputopology_init(&xc)
3949 defer C.libxl_cputopology_dispose(&xc)
3950
3951 if err := x.fromC(&xc); err != nil {
3952 return nil, err }
3953
3954 return &x, nil}
3955
3956 func (x *Cputopology) fromC(xc *C.libxl_cputopology) error {
3957 x.Core = uint32(xc.core)
3958 x.Socket = uint32(xc.socket)
3959 x.Node = uint32(xc.node)
3960
3961 return nil}
3962
3963 func (x *Cputopology) toC(xc *C.libxl_cputopology) (err error){defer func(){
3964 if err != nil{
3965 C.libxl_cputopology_dispose(xc)}
3966 }()
3967
3968 xc.core = C.uint32_t(x.Core)
3969 xc.socket = C.uint32_t(x.Socket)
3970 xc.node = C.uint32_t(x.Node)
3971
3972 return nil
3973 }
3974
3975 // NewPcitopology returns an instance of Pcitopology initialized with defaults.
3976 func NewPcitopology() (*Pcitopology, error) {
3977 var (
3978 x Pcitopology
3979 xc C.libxl_pcitopology)
3980
3981 C.libxl_pcitopology_init(&xc)
3982 defer C.libxl_pcitopology_dispose(&xc)
3983
3984 if err := x.fromC(&xc); err != nil {
3985 return nil, err }
3986
3987 return &x, nil}
3988
3989 func (x *Pcitopology) fromC(xc *C.libxl_pcitopology) error {
3990 x.Seg = uint16(xc.seg)
3991 x.Bus = byte(xc.bus)
3992 x.Devfn = byte(xc.devfn)
3993 x.Node = uint32(xc.node)
3994
3995 return nil}
3996
3997 func (x *Pcitopology) toC(xc *C.libxl_pcitopology) (err error){defer func(){
3998 if err != nil{
3999 C.libxl_pcitopology_dispose(xc)}
4000 }()
4001
4002 xc.seg = C.uint16_t(x.Seg)
4003 xc.bus = C.uint8_t(x.Bus)
4004 xc.devfn = C.uint8_t(x.Devfn)
4005 xc.node = C.uint32_t(x.Node)
4006
4007 return nil
4008 }
4009
4010 // NewSchedCreditParams returns an instance of SchedCreditParams initialized with defaults.
4011 func NewSchedCreditParams() (*SchedCreditParams, error) {
4012 var (
4013 x SchedCreditParams
4014 xc C.libxl_sched_credit_params)
4015
4016 C.libxl_sched_credit_params_init(&xc)
4017
4018 if err := x.fromC(&xc); err != nil {
4019 return nil, err }
4020
4021 return &x, nil}
4022
4023 func (x *SchedCreditParams) fromC(xc *C.libxl_sched_credit_params) error {
4024 x.TsliceMs = int(xc.tslice_ms)
4025 x.RatelimitUs = int(xc.ratelimit_us)
4026 x.VcpuMigrDelayUs = int(xc.vcpu_migr_delay_us)
4027
4028 return nil}
4029
4030 func (x *SchedCreditParams) toC(xc *C.libxl_sched_credit_params) (err error){xc.tslice_ms = C.int(x.TsliceMs)
4031 xc.ratelimit_us = C.int(x.RatelimitUs)
4032 xc.vcpu_migr_delay_us = C.int(x.VcpuMigrDelayUs)
4033
4034 return nil
4035 }
4036
4037 // NewSchedCredit2Params returns an instance of SchedCredit2Params initialized with defaults.
4038 func NewSchedCredit2Params() (*SchedCredit2Params, error) {
4039 var (
4040 x SchedCredit2Params
4041 xc C.libxl_sched_credit2_params)
4042
4043 C.libxl_sched_credit2_params_init(&xc)
4044
4045 if err := x.fromC(&xc); err != nil {
4046 return nil, err }
4047
4048 return &x, nil}
4049
4050 func (x *SchedCredit2Params) fromC(xc *C.libxl_sched_credit2_params) error {
4051 x.RatelimitUs = int(xc.ratelimit_us)
4052
4053 return nil}
4054
4055 func (x *SchedCredit2Params) toC(xc *C.libxl_sched_credit2_params) (err error){xc.ratelimit_us = C.int(x.RatelimitUs)
4056
4057 return nil
4058 }
4059
4060 // NewDomainRemusInfo returns an instance of DomainRemusInfo initialized with defaults.
4061 func NewDomainRemusInfo() (*DomainRemusInfo, error) {
4062 var (
4063 x DomainRemusInfo
4064 xc C.libxl_domain_remus_info)
4065
4066 C.libxl_domain_remus_info_init(&xc)
4067 defer C.libxl_domain_remus_info_dispose(&xc)
4068
4069 if err := x.fromC(&xc); err != nil {
4070 return nil, err }
4071
4072 return &x, nil}
4073
4074 func (x *DomainRemusInfo) fromC(xc *C.libxl_domain_remus_info) error {
4075 x.Interval = int(xc.interval)
4076 if err := x.AllowUnsafe.fromC(&xc.allow_unsafe);err != nil {
4077 return fmt.Errorf("converting field AllowUnsafe: %v", err)
4078 }
4079 if err := x.Blackhole.fromC(&xc.blackhole);err != nil {
4080 return fmt.Errorf("converting field Blackhole: %v", err)
4081 }
4082 if err := x.Compression.fromC(&xc.compression);err != nil {
4083 return fmt.Errorf("converting field Compression: %v", err)
4084 }
4085 if err := x.Netbuf.fromC(&xc.netbuf);err != nil {
4086 return fmt.Errorf("converting field Netbuf: %v", err)
4087 }
4088 x.Netbufscript = C.GoString(xc.netbufscript)
4089 if err := x.Diskbuf.fromC(&xc.diskbuf);err != nil {
4090 return fmt.Errorf("converting field Diskbuf: %v", err)
4091 }
4092 if err := x.Colo.fromC(&xc.colo);err != nil {
4093 return fmt.Errorf("converting field Colo: %v", err)
4094 }
4095 if err := x.UserspaceColoProxy.fromC(&xc.userspace_colo_proxy);err != nil {
4096 return fmt.Errorf("converting field UserspaceColoProxy: %v", err)
4097 }
4098
4099 return nil}
4100
4101 func (x *DomainRemusInfo) toC(xc *C.libxl_domain_remus_info) (err error){defer func(){
4102 if err != nil{
4103 C.libxl_domain_remus_info_dispose(xc)}
4104 }()
4105
4106 xc.interval = C.int(x.Interval)
4107 if err := x.AllowUnsafe.toC(&xc.allow_unsafe); err != nil {
4108 return fmt.Errorf("converting field AllowUnsafe: %v", err)
4109 }
4110 if err := x.Blackhole.toC(&xc.blackhole); err != nil {
4111 return fmt.Errorf("converting field Blackhole: %v", err)
4112 }
4113 if err := x.Compression.toC(&xc.compression); err != nil {
4114 return fmt.Errorf("converting field Compression: %v", err)
4115 }
4116 if err := x.Netbuf.toC(&xc.netbuf); err != nil {
4117 return fmt.Errorf("converting field Netbuf: %v", err)
4118 }
4119 if x.Netbufscript != "" {
4120 xc.netbufscript = C.CString(x.Netbufscript)}
4121 if err := x.Diskbuf.toC(&xc.diskbuf); err != nil {
4122 return fmt.Errorf("converting field Diskbuf: %v", err)
4123 }
4124 if err := x.Colo.toC(&xc.colo); err != nil {
4125 return fmt.Errorf("converting field Colo: %v", err)
4126 }
4127 if err := x.UserspaceColoProxy.toC(&xc.userspace_colo_proxy); err != nil {
4128 return fmt.Errorf("converting field UserspaceColoProxy: %v", err)
4129 }
4130
4131 return nil
4132 }
4133
4134 // NewEvent returns an instance of Event initialized with defaults.
4135 func NewEvent(etype EventType) (*Event, error) {
4136 var (
4137 x Event
4138 xc C.libxl_event)
4139
4140 C.libxl_event_init(&xc)
4141 C.libxl_event_init_type(&xc, C.libxl_event_type(etype))
4142 defer C.libxl_event_dispose(&xc)
4143
4144 if err := x.fromC(&xc); err != nil {
4145 return nil, err }
4146
4147 return &x, nil}
4148
4149 func (x *Event) fromC(xc *C.libxl_event) error {
4150 if err := x.Link.fromC(&xc.link);err != nil {
4151 return fmt.Errorf("converting field Link: %v", err)
4152 }
4153 x.Domid = Domid(xc.domid)
4154 if err := x.Domuuid.fromC(&xc.domuuid);err != nil {
4155 return fmt.Errorf("converting field Domuuid: %v", err)
4156 }
4157 x.ForUser = uint64(xc.for_user)
4158 x.Type = EventType(xc._type)
4159 switch x.Type{
4160 case EventTypeDiskEject:
4161 var typeDiskEject EventTypeUnionDiskEject
4162 if err := typeDiskEject.fromC(xc);err != nil {
4163 return fmt.Errorf("converting field typeDiskEject: %v", err)
4164 }
4165 x.TypeUnion = &typeDiskEject
4166 case EventTypeDomainCreateConsoleAvailable:
4167 x.TypeUnion = nil
4168 case EventTypeDomainDeath:
4169 x.TypeUnion = nil
4170 case EventTypeDomainShutdown:
4171 var typeDomainShutdown EventTypeUnionDomainShutdown
4172 if err := typeDomainShutdown.fromC(xc);err != nil {
4173 return fmt.Errorf("converting field typeDomainShutdown: %v", err)
4174 }
4175 x.TypeUnion = &typeDomainShutdown
4176 case EventTypeOperationComplete:
4177 var typeOperationComplete EventTypeUnionOperationComplete
4178 if err := typeOperationComplete.fromC(xc);err != nil {
4179 return fmt.Errorf("converting field typeOperationComplete: %v", err)
4180 }
4181 x.TypeUnion = &typeOperationComplete
4182 default:
4183 return fmt.Errorf("invalid union key '%v'", x.Type)}
4184
4185 return nil}
4186
4187 func (x *EventTypeUnionDomainShutdown) fromC(xc *C.libxl_event) error {
4188 if EventType(xc._type) != EventTypeDomainShutdown {
4189 return errors.New("expected union key EventTypeDomainShutdown")
4190 }
4191
4192 tmp := (*C.libxl_event_type_union_domain_shutdown)(unsafe.Pointer(&xc.u[0]))
4193 x.ShutdownReason = byte(tmp.shutdown_reason)
4194 return nil
4195 }
4196
4197 func (x *EventTypeUnionDiskEject) fromC(xc *C.libxl_event) error {
4198 if EventType(xc._type) != EventTypeDiskEject {
4199 return errors.New("expected union key EventTypeDiskEject")
4200 }
4201
4202 tmp := (*C.libxl_event_type_union_disk_eject)(unsafe.Pointer(&xc.u[0]))
4203 x.Vdev = C.GoString(tmp.vdev)
4204 if err := x.Disk.fromC(&tmp.disk);err != nil {
4205 return fmt.Errorf("converting field Disk: %v", err)
4206 }
4207 return nil
4208 }
4209
4210 func (x *EventTypeUnionOperationComplete) fromC(xc *C.libxl_event) error {
4211 if EventType(xc._type) != EventTypeOperationComplete {
4212 return errors.New("expected union key EventTypeOperationComplete")
4213 }
4214
4215 tmp := (*C.libxl_event_type_union_operation_complete)(unsafe.Pointer(&xc.u[0]))
4216 x.Rc = int(tmp.rc)
4217 return nil
4218 }
4219
4220 func (x *Event) toC(xc *C.libxl_event) (err error){defer func(){
4221 if err != nil{
4222 C.libxl_event_dispose(xc)}
4223 }()
4224
4225 if err := x.Link.toC(&xc.link); err != nil {
4226 return fmt.Errorf("converting field Link: %v", err)
4227 }
4228 xc.domid = C.libxl_domid(x.Domid)
4229 if err := x.Domuuid.toC(&xc.domuuid); err != nil {
4230 return fmt.Errorf("converting field Domuuid: %v", err)
4231 }
4232 xc.for_user = C.uint64_t(x.ForUser)
4233 xc._type = C.libxl_event_type(x.Type)
4234 switch x.Type{
4235 case EventTypeDomainShutdown:
4236 tmp, ok := x.TypeUnion.(*EventTypeUnionDomainShutdown)
4237 if !ok {
4238 return errors.New("wrong type for union key type")
4239 }
4240 var domain_shutdown C.libxl_event_type_union_domain_shutdown
4241 domain_shutdown.shutdown_reason = C.uint8_t(tmp.ShutdownReason)
4242 domain_shutdownBytes := C.GoBytes(unsafe.Pointer(&domain_shutdown),C.sizeof_libxl_event_type_union_domain_shutdown)
4243 copy(xc.u[:],domain_shutdownBytes)
4244 case EventTypeDomainDeath:
4245 break
4246 case EventTypeDiskEject:
4247 tmp, ok := x.TypeUnion.(*EventTypeUnionDiskEject)
4248 if !ok {
4249 return errors.New("wrong type for union key type")
4250 }
4251 var disk_eject C.libxl_event_type_union_disk_eject
4252 if tmp.Vdev != "" {
4253 disk_eject.vdev = C.CString(tmp.Vdev)}
4254 if err := tmp.Disk.toC(&disk_eject.disk); err != nil {
4255 return fmt.Errorf("converting field Disk: %v", err)
4256 }
4257 disk_ejectBytes := C.GoBytes(unsafe.Pointer(&disk_eject),C.sizeof_libxl_event_type_union_disk_eject)
4258 copy(xc.u[:],disk_ejectBytes)
4259 case EventTypeOperationComplete:
4260 tmp, ok := x.TypeUnion.(*EventTypeUnionOperationComplete)
4261 if !ok {
4262 return errors.New("wrong type for union key type")
4263 }
4264 var operation_complete C.libxl_event_type_union_operation_complete
4265 operation_complete.rc = C.int(tmp.Rc)
4266 operation_completeBytes := C.GoBytes(unsafe.Pointer(&operation_complete),C.sizeof_libxl_event_type_union_operation_complete)
4267 copy(xc.u[:],operation_completeBytes)
4268 case EventTypeDomainCreateConsoleAvailable:
4269 break
4270 default:
4271 return fmt.Errorf("invalid union key '%v'", x.Type)}
4272
4273 return nil
4274 }
4275
4276 // NewPsrCatInfo returns an instance of PsrCatInfo initialized with defaults.
4277 func NewPsrCatInfo() (*PsrCatInfo, error) {
4278 var (
4279 x PsrCatInfo
4280 xc C.libxl_psr_cat_info)
4281
4282 C.libxl_psr_cat_info_init(&xc)
4283 defer C.libxl_psr_cat_info_dispose(&xc)
4284
4285 if err := x.fromC(&xc); err != nil {
4286 return nil, err }
4287
4288 return &x, nil}
4289
4290 func (x *PsrCatInfo) fromC(xc *C.libxl_psr_cat_info) error {
4291 x.Id = uint32(xc.id)
4292 x.CosMax = uint32(xc.cos_max)
4293 x.CbmLen = uint32(xc.cbm_len)
4294 x.CdpEnabled = bool(xc.cdp_enabled)
4295
4296 return nil}
4297
4298 func (x *PsrCatInfo) toC(xc *C.libxl_psr_cat_info) (err error){defer func(){
4299 if err != nil{
4300 C.libxl_psr_cat_info_dispose(xc)}
4301 }()
4302
4303 xc.id = C.uint32_t(x.Id)
4304 xc.cos_max = C.uint32_t(x.CosMax)
4305 xc.cbm_len = C.uint32_t(x.CbmLen)
4306 xc.cdp_enabled = C.bool(x.CdpEnabled)
4307
4308 return nil
4309 }
4310
4311 // NewPsrHwInfo returns an instance of PsrHwInfo initialized with defaults.
4312 func NewPsrHwInfo(ptype PsrFeatType) (*PsrHwInfo, error) {
4313 var (
4314 x PsrHwInfo
4315 xc C.libxl_psr_hw_info)
4316
4317 C.libxl_psr_hw_info_init(&xc)
4318 C.libxl_psr_hw_info_init_type(&xc, C.libxl_psr_feat_type(ptype))
4319 defer C.libxl_psr_hw_info_dispose(&xc)
4320
4321 if err := x.fromC(&xc); err != nil {
4322 return nil, err }
4323
4324 return &x, nil}
4325
4326 func (x *PsrHwInfo) fromC(xc *C.libxl_psr_hw_info) error {
4327 x.Id = uint32(xc.id)
4328 x.Type = PsrFeatType(xc._type)
4329 switch x.Type{
4330 case PsrFeatTypeCat:
4331 var typeCat PsrHwInfoTypeUnionCat
4332 if err := typeCat.fromC(xc);err != nil {
4333 return fmt.Errorf("converting field typeCat: %v", err)
4334 }
4335 x.TypeUnion = &typeCat
4336 case PsrFeatTypeMba:
4337 var typeMba PsrHwInfoTypeUnionMba
4338 if err := typeMba.fromC(xc);err != nil {
4339 return fmt.Errorf("converting field typeMba: %v", err)
4340 }
4341 x.TypeUnion = &typeMba
4342 default:
4343 return fmt.Errorf("invalid union key '%v'", x.Type)}
4344
4345 return nil}
4346
4347 func (x *PsrHwInfoTypeUnionCat) fromC(xc *C.libxl_psr_hw_info) error {
4348 if PsrFeatType(xc._type) != PsrFeatTypeCat {
4349 return errors.New("expected union key PsrFeatTypeCat")
4350 }
4351
4352 tmp := (*C.libxl_psr_hw_info_type_union_cat)(unsafe.Pointer(&xc.u[0]))
4353 x.CosMax = uint32(tmp.cos_max)
4354 x.CbmLen = uint32(tmp.cbm_len)
4355 x.CdpEnabled = bool(tmp.cdp_enabled)
4356 return nil
4357 }
4358
4359 func (x *PsrHwInfoTypeUnionMba) fromC(xc *C.libxl_psr_hw_info) error {
4360 if PsrFeatType(xc._type) != PsrFeatTypeMba {
4361 return errors.New("expected union key PsrFeatTypeMba")
4362 }
4363
4364 tmp := (*C.libxl_psr_hw_info_type_union_mba)(unsafe.Pointer(&xc.u[0]))
4365 x.CosMax = uint32(tmp.cos_max)
4366 x.ThrtlMax = uint32(tmp.thrtl_max)
4367 x.Linear = bool(tmp.linear)
4368 return nil
4369 }
4370
4371 func (x *PsrHwInfo) toC(xc *C.libxl_psr_hw_info) (err error){defer func(){
4372 if err != nil{
4373 C.libxl_psr_hw_info_dispose(xc)}
4374 }()
4375
4376 xc.id = C.uint32_t(x.Id)
4377 xc._type = C.libxl_psr_feat_type(x.Type)
4378 switch x.Type{
4379 case PsrFeatTypeCat:
4380 tmp, ok := x.TypeUnion.(*PsrHwInfoTypeUnionCat)
4381 if !ok {
4382 return errors.New("wrong type for union key type")
4383 }
4384 var cat C.libxl_psr_hw_info_type_union_cat
4385 cat.cos_max = C.uint32_t(tmp.CosMax)
4386 cat.cbm_len = C.uint32_t(tmp.CbmLen)
4387 cat.cdp_enabled = C.bool(tmp.CdpEnabled)
4388 catBytes := C.GoBytes(unsafe.Pointer(&cat),C.sizeof_libxl_psr_hw_info_type_union_cat)
4389 copy(xc.u[:],catBytes)
4390 case PsrFeatTypeMba:
4391 tmp, ok := x.TypeUnion.(*PsrHwInfoTypeUnionMba)
4392 if !ok {
4393 return errors.New("wrong type for union key type")
4394 }
4395 var mba C.libxl_psr_hw_info_type_union_mba
4396 mba.cos_max = C.uint32_t(tmp.CosMax)
4397 mba.thrtl_max = C.uint32_t(tmp.ThrtlMax)
4398 mba.linear = C.bool(tmp.Linear)
4399 mbaBytes := C.GoBytes(unsafe.Pointer(&mba),C.sizeof_libxl_psr_hw_info_type_union_mba)
4400 copy(xc.u[:],mbaBytes)
4401 default:
4402 return fmt.Errorf("invalid union key '%v'", x.Type)}
4403
4404 return nil
4405 }
4406