1 /*
2 * Copyright (C) 2009 Citrix Ltd.
3 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; version 2.1 only. with the special
8 * exception on linking described in file LICENSE.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 */
15
16 /*
17 * libxl API compatibility
18 *
19 * From Xen 4.2 onwards the API of libxl will be maintained in a
20 * stable manner. This means that it should be possible to write an
21 * application against the API provided by libxl in Xen 4.2 and expect
22 * that it will continue to compile against future versions of Xen
23 * without source modification.
24 *
25 * In order to make such compatibility possible it is required that
26 * application which want to be exposed to a particular API #define
27 * LIBXL_API_VERSION before including libxl.h or any other libxl
28 * header. The syntax of the LIBXL_API_VERSION is:
29 * 0xVVSSEE
30 * where ($(XEN_xxx) from xen/Makefile):
31 * VV is the Xen major release number, $(XEN_VERSION)
32 * SS is the Xen sub version number, $(XEN_SUBVERSION)
33 * EE is the Xen extra version digit, first numeric part of
34 * $(XEN_EXTRAVERSION) not including the leading "."
35 * For example the first stable API version, supported by Xen 4.2.0,
36 * is 0x040200.
37 *
38 * Lack of LIBXL_API_VERSION means "the latest" which will
39 * change. Specifying an unknown LIBXL_API_VERSION will result in a
40 * compile time error.
41 *
42 * Identical versions of the libxl API will represented by the version
43 * containing the earliest instance of that API. e.g. if 4.2.0 and
44 * 4.3.0 contain an identical libxl API then only LIBXL_API_VERSION
45 * 0x040200 will be valid.
46 *
47 * We will try especially hard to avoid changing the API during a
48 * stable series, i.e. it should be unusual for the last byte of
49 * LIBXL_API_VERSION to be non-zero.
50 *
51 * In the event that a change is required which cannot be made
52 * backwards compatible in this manner a #define of the form
53 * LIBXL_HAVE_<interface> will always be added in order to make it
54 * possible to write applications which build against any version of
55 * libxl. Such changes are expected to be exceptional and used as a
56 * last resort. The barrier for backporting such a change to a stable
57 * branch will be very high.
58 *
59 * These guarantees apply only to stable releases of Xen. When an
60 * incompatible change is made in the unstable tree then
61 * LIBXL_API_VERSION will be bumped to the next expected stable
62 * release number on the first such change only. Applications which
63 * want to support building against Xen unstable are expected to track
64 * API changes in that tree until it is released as a stable release.
65 *
66 * API compatibility will be maintained for all versions of Xen using
67 * the same $(XEN_VERSION) (e.g. throughout a major release).
68 */
69
70 /* LIBXL_HAVE_PHYSINFO_CAP_PV
71 *
72 * If this is defined, libxl_physinfo has a "cap_pv" field.
73 */
74 #define LIBXL_HAVE_PHYSINFO_CAP_PV 1
75
76 /* LIBXL_HAVE_CONSOLE_NOTIFY_FD
77 *
78 * If this is defined, libxl_console_exec and
79 * libxl_primary_console_exe take a notify_fd parameter. That
80 * parameter will be used to notify the caller that the console is connected.
81 */
82 #define LIBXL_HAVE_CONSOLE_NOTIFY_FD 1
83
84 /* LIBXL_HAVE_CONSOLE_ESCAPE_CHARACTER
85 *
86 * If this is defined, libxl_console_exec and
87 * libxl_primary_console_exe take an escape_character parameter. That
88 * parameter will be used to modify the escape sequence used to exit the
89 * console.
90 */
91 #define LIBXL_HAVE_CONSOLE_ESCAPE_CHARACTER 1
92
93 /* LIBXL_HAVE_CONST_COPY_AND_LENGTH_FUNCTIONS
94 *
95 * If this is defined, the copy functions have constified src parameter and the
96 * length functions accept constified parameter.
97 */
98 #define LIBXL_HAVE_CONST_COPY_AND_LENGTH_FUNCTIONS 1
99
100 /* LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONST_B_INFO
101 *
102 * If this is defined, libxl_domain_need_memory no longer modifies
103 * the b_info paseed in.
104 */
105 #define LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONST_B_INFO 1
106
107 /* LIBXL_HAVE_VNUMA
108 *
109 * If this is defined the type libxl_vnode_info exists, and a
110 * field 'vnuma_nodes' is present in libxl_domain_build_info.
111 */
112 #define LIBXL_HAVE_VNUMA 1
113
114 /* LIBXL_HAVE_USERDATA_UNLINK
115 *
116 * If it is defined, libxl has a library function called
117 * libxl_userdata_unlink.
118 */
119 #define LIBXL_HAVE_USERDATA_UNLINK 1
120
121 /* LIBXL_HAVE_CPUPOOL_QUALIFIER_TO_CPUPOOLID
122 *
123 * If this is defined, libxl has a library function called
124 * libxl_cpupool_qualifier_to_cpupoolid, which takes in a CPU pool
125 * qualifier in the form of number or string, then returns the ID of
126 * that CPU pool.
127 */
128 #define LIBXL_HAVE_CPUPOOL_QUALIFIER_TO_CPUPOOLID 1
129
130 /* LIBXL_HAVE_CPUPOOL_ADD_REM_CPUMAP
131 *
132 * If this is defined, libxl has two library functions called
133 * libxl_cpupool_cpuadd_cpumap and libxl_cpupool_cpuremove_cpumap,
134 * which allow to add to or remove from a cpupool all the cpus
135 * specified in a bitmap.
136 */
137 #define LIBXL_HAVE_CPUPOOL_ADD_REM_CPUMAP 1
138
139 /*
140 *
141 * LIBXL_HAVE_BITMAP_AND_OR
142 *
143 * If this is defined, libxl has two library functions, libxl_bitmap_and
144 * and libxl_bitmap_or to compute the logical and and or of two bitmaps
145 */
146 #define LIBXL_HAVE_BITMAP_AND_OR 1
147
148 /*
149 * LIBXL_HAVE_FIRMWARE_PASSTHROUGH indicates the feature for
150 * passing in SMBIOS and ACPI firmware to HVM guests is present
151 * in the library.
152 */
153 #define LIBXL_HAVE_FIRMWARE_PASSTHROUGH 1
154
155 /*
156 * LIBXL_HAVE_DOMAIN_NODEAFFINITY indicates that a 'nodemap' field
157 * (of libxl_bitmap type) is present in libxl_domain_build_info,
158 * containing the node-affinity for the domain.
159 */
160 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1
161
162 /*
163 * LIBXL_HAVE_PVUSB indicates functions for plugging in USB devices
164 * through pvusb -- both hotplug and at domain creation time..
165 */
166 #define LIBXL_HAVE_PVUSB 1
167
168 /*
169 * LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE indicates that the
170 * libxl_vendor_device field is present in the hvm sections of
171 * libxl_domain_build_info. This field tells libxl which
172 * flavour of xen-pvdevice to enable in QEMU.
173 */
174 #define LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE 1
175
176 /*
177 * The libxl_domain_build_info has the event_channels field.
178 */
179 #define LIBXL_HAVE_BUILDINFO_EVENT_CHANNELS 1
180
181 /*
182 * libxl_domain_build_info has the u.hvm.ms_vm_genid field.
183 */
184 #define LIBXL_HAVE_BUILDINFO_HVM_MS_VM_GENID 1
185
186 /*
187 * libxl_domain_build_info has the u.hvm.smbios field.
188 */
189 #define LIBXL_HAVE_BUILDINFO_HVM_SMBIOS 1
190
191 /*
192 * LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY indicates that a 'cpumap_soft'
193 * field (of libxl_bitmap type) is present in libxl_vcpuinfo,
194 * containing the soft affinity of a vcpu.
195 */
196 #define LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY 1
197
198 /*
199 * LIBXL_HAVE_SET_VCPUAFFINITY_FORCE indicates that the
200 * libxl_set_vcpuaffinity_force() library call is available.
201 */
202 #define LIBXL_HAVE_SET_VCPUAFFINITY_FORCE 1
203
204 /*
205 * LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE indicates that a
206 * 'direct_io_safe' field (of boolean type) is present in
207 * libxl_device_disk.
208 */
209 #define LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE 1
210
211 /*
212 * The libxl_device_disk has the discard_enable field.
213 */
214 #define LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE 1
215
216 /*
217 * LIBXL_HAVE_BUILDINFO_IOMEM_START_GFN indicates that it is possible
218 * to specify the start guest frame number used to map a range of I/O
219 * memory machine frame numbers via the 'gfn' field (of type uint64)
220 * of the 'iomem' structure. An array of iomem structures is embedded
221 * in libxl_domain_build_info and used to map the indicated memory
222 * ranges during domain build.
223 */
224 #define LIBXL_HAVE_BUILDINFO_IOMEM_START_GFN 1
225
226 /*
227 * LIBXL_HAVE_SCHED_RTDS indicates that the RTDS real time scheduler
228 * is available. A 'budget' field added in libxl_domain_sched_params.
229 */
230 #define LIBXL_HAVE_SCHED_RTDS 1
231
232 /*
233 * LIBXL_HAVE_SCHED_NULL indicates that the 'null' static scheduler
234 * is available.
235 */
236 #define LIBXL_HAVE_SCHED_NULL 1
237
238 /*
239 * libxl_domain_build_info has u.hvm.viridian_enable and _disable bitmaps
240 * of the specified width.
241 */
242 #define LIBXL_HAVE_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE 1
243 #define LIBXL_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE_WIDTH 64
244
245 /*
246 * libxl_domain_build_info has the u.hvm.mmio_hole_memkb field.
247 */
248 #define LIBXL_HAVE_BUILDINFO_HVM_MMIO_HOLE_MEMKB 1
249
250 /*
251 * libxl_domain_info returns ERROR_DOMAIN_NOTFOUND if the domain
252 * is not present, instead of ERROR_INVAL.
253 */
254 #define LIBXL_HAVE_ERROR_DOMAIN_NOTFOUND 1
255
256 /*
257 * libxl_domain_build_info has device_tree and libxl_device_dtdev
258 * exists. This mean Device Tree passthrough is supported for ARM
259 */
260 #define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1
261
262 #if defined(__arm__) || defined(__aarch64__)
263 /**
264 * This means Device Tree Overlay is supported.
265 */
266 #define LIBXL_HAVE_DT_OVERLAY 1
267 #endif
268 /*
269 * libxl_domain_build_info has device_model_user to specify the user to
270 * run the device model with. See docs/misc/qemu-deprivilege.txt.
271 */
272 #define LIBXL_HAVE_DEVICE_MODEL_USER 1
273
274 /*
275 * libxl_vcpu_sched_params is used to store per-vcpu params.
276 */
277 #define LIBXL_HAVE_VCPU_SCHED_PARAMS 1
278
279 /*
280 * LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS indicates RTDS scheduler
281 * now supports per-vcpu settings.
282 */
283 #define LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS 1
284
285 /*
286 * LIBXL_HAVE_SCHED_RTDS_VCPU_EXTRA indicates RTDS scheduler
287 * now supports per-vcpu extratime settings.
288 */
289 #define LIBXL_HAVE_SCHED_RTDS_VCPU_EXTRA 1
290
291 /*
292 * libxl_domain_build_info has the arm.gic_version field.
293 */
294 #define LIBXL_HAVE_BUILDINFO_ARM_GIC_VERSION 1
295
296 /*
297 * libxl_domain_build_info has the arch_arm.tee field.
298 */
299 #define LIBXL_HAVE_BUILDINFO_ARCH_ARM_TEE 1
300
301 /*
302 * arch_arm.tee field in libxl_domain_build_info has ffa value.
303 */
304 #define LIBXL_HAVE_BUILDINFO_ARCH_ARM_TEE_FFA 1
305
306 /*
307 * libxl_domain_build_info has the arch_arm.sve_vl field.
308 */
309 #define LIBXL_HAVE_BUILDINFO_ARCH_ARM_SVE_VL 1
310
311 /*
312 * libxl_domain_build_info has the arch_arm.nr_spis field
313 */
314 #define LIBXL_HAVE_BUILDINFO_ARCH_NR_SPIS 1
315
316 /*
317 * LIBXL_HAVE_SOFT_RESET indicates that libxl supports performing
318 * 'soft reset' for domains and there is 'soft_reset' shutdown reason
319 * in enum libxl_shutdown_reason.
320 */
321 #define LIBXL_HAVE_SOFT_RESET 1
322
323 /*
324 * LIBXL_HAVE_APIC_ASSIST indicates that the 'apic_assist' value
325 * is present in the viridian enlightenment enumeration.
326 */
327 #define LIBXL_HAVE_APIC_ASSIST 1
328
329 /*
330 * LIBXL_HAVE_BUILD_ID means that libxl_version_info has the extra
331 * field for the hypervisor build_id.
332 */
333 #define LIBXL_HAVE_BUILD_ID 1
334
335 /*
336 * LIBXL_HAVE_QEMU_MONITOR_COMMAND indiactes the availability of the
337 * libxl_qemu_monitor_command() function.
338 */
339 #define LIBXL_HAVE_QEMU_MONITOR_COMMAND 1
340
341 /*
342 * LIBXL_HAVE_SCHED_CREDIT2_PARAMS indicates the existance of a
343 * libxl_sched_credit2_params structure, containing Credit2 scheduler
344 * wide parameters (i.e., the ratelimiting value).
345 */
346 #define LIBXL_HAVE_SCHED_CREDIT2_PARAMS 1
347
348 /*
349 * LIBXL_HAVE_SCHED_CREDIT_MIGR_DELAY indicates that there is a field
350 * in libxl_sched_credit_params called vcpu_migr_delay_us which controls
351 * the resistance of the vCPUs of the cpupool to migrations among pCPUs.
352 */
353 #define LIBXL_HAVE_SCHED_CREDIT_MIGR_DELAY
354
355 /*
356 * LIBXL_HAVE_VIRIDIAN_CRASH_CTL indicates that the 'crash_ctl' value
357 * is present in the viridian enlightenment enumeration.
358 */
359 #define LIBXL_HAVE_VIRIDIAN_CRASH_CTL 1
360
361 /*
362 * LIBXL_HAVE_VIRIDIAN_SYNIC indicates that the 'synic' value
363 * is present in the viridian enlightenment enumeration.
364 */
365 #define LIBXL_HAVE_VIRIDIAN_SYNIC 1
366
367 /*
368 * LIBXL_HAVE_VIRIDIAN_STIMER indicates that the 'stimer' value
369 * is present in the viridian enlightenment enumeration.
370 */
371 #define LIBXL_HAVE_VIRIDIAN_STIMER 1
372
373 /*
374 * LIBXL_HAVE_VIRIDIAN_HCALL_IPI indicates that the 'hcall_ipi' value
375 * is present in the viridian enlightenment enumeration.
376 */
377 #define LIBXL_HAVE_VIRIDIAN_HCALL_IPI 1
378
379 /*
380 * LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE indicates that
381 * libxl_domain_build_info has the u.hvm.acpi_laptop_slate field.
382 */
383 #define LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE 1
384
385 /*
386 * LIBXL_HAVE_P9S indicates that the p9 field in IDL has been changed to p9s
387 */
388 #define LIBXL_HAVE_P9S 1
389
390 /*
391 * LIBXL_HAVE_BUILDINFO_ARM_VUART indicates that the toolstack supports virtual UART
392 * for ARM.
393 */
394 #define LIBXL_HAVE_BUILDINFO_ARM_VUART 1
395
396 /*
397 * LIBXL_HAVE_BUILDINFO_GRANT_LIMITS indicates that libxl_domain_build_info
398 * has the max_grant_frames and max_maptrack_frames fields.
399 */
400 #define LIBXL_HAVE_BUILDINFO_GRANT_LIMITS 1
401
402 #define LIBXL_MAX_GRANT_DEFAULT (~(uint32_t)0)
403 #define LIBXL_MAX_GRANT_FRAMES_DEFAULT 32 /* deprecated */
404 #define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT 1024 /* deprecated */
405 /*
406 * LIBXL_HAVE_BUILDINFO_GRANT_DEFAULT indicates that the default
407 * values of max_grant_frames and max_maptrack_frames fields in
408 * libxl_domain_build_info are the special sentinel value
409 * LIBXL_MAX_GRANT_DEFAULT rather than the fixed values above.
410 * This means to use the hypervisor's default.
411 */
412 #define LIBXL_HAVE_BUILDINFO_GRANT_DEFAULT 1
413
414 /*
415 * LIBXL_HAVE_BUILDINFO_* indicates that libxl_domain_build_info has
416 * the field represented by the '*'. The original position of those
417 * fields is:
418 * - u.hvm.timer_mode
419 * - u.hvm.apic
420 * - u.hvm.nested_hvm
421 * - u.pv.bootloader
422 * - u.pv.bootloader_args
423 */
424 #define LIBXL_HAVE_BUILDINFO_TIMER_MODE 1
425 #define LIBXL_HAVE_BUILDINFO_APIC 1
426 #define LIBXL_HAVE_BUILDINFO_NESTED_HVM 1
427 #define LIBXL_HAVE_BUILDINFO_BOOTLOADER 1
428 #define LIBXL_HAVE_BUILDINFO_BOOTLOADER_ARGS 1
429
430 /*
431 * LIBXL_HAVE_EXTENDED_VKB indicates that libxl_device_vkb has extended fields:
432 * - unique_id;
433 * - feature_disable_keyboard;
434 * - feature_disable_pointer;
435 * - feature_abs_pointer;
436 * - feature_raw_pointer;
437 * - feature_multi_touch;
438 * - width;
439 * - height;
440 * - multi_touch_width;
441 * - multi_touch_height;
442 * - multi_touch_num_contacts.
443 */
444 #define LIBXL_HAVE_EXTENDED_VKB 1
445
446 /*
447 * LIBXL_HAVE_PHYSINFO_CAP_HAP_SHADOW indicates that libxl_physinfo has
448 * cap_hap and cap_shadow fields reflecting the hardware and Xen availability
449 * of Hardware Assisted, and Shadow paging support.
450 */
451 #define LIBXL_HAVE_PHYSINFO_CAP_HAP_SHADOW 1
452
453 /*
454 * LIBXL_HAVE_PHYSINFO_CAP_IOMMU_HAP_PT_SHARE indicates that libxl_physinfo
455 * has a cap_iommu_hap_pt_share field that indicates whether the hardware
456 * supports sharing the IOMMU and HAP page tables.
457 */
458 #define LIBXL_HAVE_PHYSINFO_CAP_IOMMU_HAP_PT_SHARE 1
459
460 /*
461 * LIBXL_HAVE_BUILDINFO_IOMMU_MEMKB indicates thate libxl_domain_build_info
462 * has an iommu_memkb field which should be set with the amount of memory
463 * overhead needed by the domain for populating IOMMU page tables.
464 */
465 #define LIBXL_HAVE_BUILDINFO_IOMMU_MEMKB 1
466
467 /*
468 * LIBXL_HAVE_CREATEINFO_PASSTHROUGH indicates that
469 * libxl_domain_create_info has a passthrough field (which is a
470 * libxl_passthrough enumeration) that indicates whether device pass-
471 * through is enabled for the domain and, if so, whether the IOMMU and
472 * HAP page tables may be shared or not.
473 */
474 #define LIBXL_HAVE_CREATEINFO_PASSTHROUGH 1
475
476 /*
477 * LIBXL_HAVE_DISK_SAFE_REMOVE indicates that the
478 * libxl_device_disk_safe_remove() function is defined.
479 */
480 #define LIBXL_HAVE_DISK_SAFE_REMOVE 1
481
482 /*
483 * LIBXL_HAVE_VIRIDIAN_EX_PROCESSOR_MASKS indicates that the
484 * 'ex_processor_masks' value is present in the viridian enlightenment
485 * enumeration.
486 */
487 #define LIBXL_HAVE_VIRIDIAN_EX_PROCESSOR_MASKS 1
488
489 /*
490 * LIBXL_HAVE_VIRIDIAN_NO_VP_LIMIT indicates that the 'no_vp_limit' value
491 * is present in the viridian enlightenment enumeration.
492 */
493 #define LIBXL_HAVE_VIRIDIAN_NO_VP_LIMIT 1
494
495 /*
496 * LIBXL_HAVE_VIRIDIAN_CPU_HOTPLUG indicates that the 'cpu_hotplug' value
497 * is present in the viridian enlightenment enumeration.
498 */
499 #define LIBXL_HAVE_VIRIDIAN_CPU_HOTPLUG 1
500
501 /*
502 * LIBXL_HAVE_DEVICE_PCI_LIST_FREE indicates that the
503 * libxl_device_pci_list_free() function is defined.
504 */
505 #define LIBXL_HAVE_DEVICE_PCI_LIST_FREE 1
506
507 /*
508 * LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE indicates that the
509 * libxl_device_pci_assignable_list_free() function is defined.
510 */
511 #define LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE 1
512
513 /*
514 * LIBXL_HAVE_DEVICE_PCI_NAME indicates that the libxl_device_pci type
515 * has a name field.
516 */
517 #define LIBXL_HAVE_DEVICE_PCI_NAME 1
518
519 /*
520 * LIBXL_HAVE_PHYSINFO_CAP_VMTRACE indicates that libxl_physinfo has a
521 * cap_vmtrace field, which indicates the availability of platform tracing
522 * functionality.
523 */
524 #define LIBXL_HAVE_PHYSINFO_CAP_VMTRACE 1
525
526 /*
527 * LIBXL_HAVE_VMTRACE_BUF_KB indicates that libxl_domain_build_info has a
528 * vmtrace_buf_kb parameter, which allows to enable pre-allocation of
529 * processor tracing buffers of given size.
530 */
531 #define LIBXL_HAVE_VMTRACE_BUF_KB 1
532
533 /*
534 * LIBXL_HAVE_X86_MSR_RELAXED indicates the toolstack has support for switching
535 * the MSR access handling in the hypervisor to relaxed mode. This is done by
536 * setting the libxl_domain_build_info arch_x86.msr_relaxed field.
537 */
538 #define LIBXL_HAVE_X86_MSR_RELAXED 1
539
540 /*
541 * LIBXL_HAVE_PHYSINFO_CAP_VPMU indicates that libxl_physinfo has a cap_vpmu
542 * field, which indicates the availability of vPMU functionality.
543 */
544 #define LIBXL_HAVE_PHYSINFO_CAP_VPMU 1
545
546 /*
547 * LIBXL_HAVE_VPMU indicates that libxl_domain_build_info has a vpmu parameter,
548 * which allows to enable the access to PMU registers.
549 */
550 #define LIBXL_HAVE_VPMU 1
551
552 /*
553 * LIBXL_HAVE_PHYSINFO_CAP_GNTTAB indicates that libxl_physinfo has a
554 * cap_gnttab_v1/2 fields, which indicates the available grant table ABIs.
555 */
556 #define LIBXL_HAVE_PHYSINFO_CAP_GNTTAB 1
557
558 /*
559 * LIBXL_HAVE_PHYSINFO_ARCH_CAPABILITIES indicates that libxl_physinfo has a
560 * arch_capabilities field.
561 */
562 #define LIBXL_HAVE_PHYSINFO_ARCH_CAPABILITIES 1
563
564 /*
565 * LIBXL_HAVE_MAX_GRANT_VERSION indicates libxl_domain_build_info has a
566 * max_grant_version field for setting the max grant table version per
567 * domain.
568 */
569 #define LIBXL_HAVE_MAX_GRANT_VERSION 1
570
571 /*
572 * LIBXL_HAVE_{DISK,NIC}_TRUSTED indicates that the libxl_device_disk and
573 * libxl_device_nic structs have a field to signal whether the backend of the
574 * device is to be trusted. Such information is propagated to the frontend.
575 */
576 #define LIBXL_HAVE_DISK_TRUSTED 1
577 #define LIBXL_HAVE_NIC_TRUSTED 1
578
579 /*
580 * LIBXL_HAVE_DEVICE_DISK_SPECIFICATION indicates that 'specification' and
581 * 'transport' fields (of libxl_disk_specification and libxl_disk_transport
582 * types respectively) are present in libxl_device_disk.
583 */
584 #define LIBXL_HAVE_DEVICE_DISK_SPECIFICATION 1
585
586 /*
587 * LIBXL_HAVE_DISK_GRANT_USAGE indicates that the libxl_device_disk
588 * has 'grant_usage' field to specify the usage of Xen grants for
589 * the specification 'virtio'.
590 */
591 #define LIBXL_HAVE_DISK_GRANT_USAGE 1
592
593 /*
594 * LIBXL_HAVE_CONSOLE_ADD_XENSTORE indicates presence of the function
595 * libxl_console_add_xenstore() in libxl.
596 */
597 #define LIBXL_HAVE_CONSOLE_ADD_XENSTORE 1
598
599 /*
600 * LIBXL_HAVE_P9_ADD indicates presence of the function
601 * libxl_device_9pfs_add() in libxl.
602 */
603 #define LIBXL_HAVE_P9_ADD 1
604
605 /*
606 * libxl ABI compatibility
607 *
608 * The only guarantee which libxl makes regarding ABI compatibility
609 * across releases is that the SONAME will always be bumped whenever
610 * the ABI is changed in an incompatible way.
611 *
612 * This applies within stable branches as well as
613 * development branches. It is possible that a new stable release of
614 * Xen may require a rebuild of applications using the
615 * library. However per the API compatibility gaurantees such a
616 * rebuild should not normally require any source level changes.
617 *
618 * As with the API compatiblity the SONAME will only be bumped for the
619 * first ABI incompatible change in a development branch.
620 */
621
622 #define LIBXL_HAVE_BOOTLOADER_RESTRICT 1
623 /*
624 * LIBXL_HAVE_BOOTLOADER_RESTRICT indicates the presence of the
625 * bootloader_restrict and bootloader_user fields in libxl_domain_build_info.
626 * Such fields signal the need to pass a --runas parameter to the bootloader
627 * executable in order to not run it as the same user as libxl.
628 */
629
630 /*
631 * LIBXL_HAVE_HVM_PIRQ indicates the presence of the u.hvm.pirq filed in
632 * libxl_domain_build_info that signals whether an HVM guest has accesses to
633 * the XENFEAT_hvm_pirqs feature.
634 */
635 #define LIBXL_HAVE_HVM_PIRQ 1
636
637 /*
638 * LIBXL_HAVE_XEN_9PFS indicates the presence of the xen-9pfsd related
639 * fields in libxl_device_p9: type, max_space, max_files, max_open_files and
640 * auto_delete.
641 */
642 #define LIBXL_HAVE_XEN_9PFS 1
643
644 /*
645 * LIBXL_HAVE_DT_OVERLAY_DOMAIN indicates the presence of
646 * libxl_dt_overlay_domain.
647 */
648 #define LIBXL_HAVE_DT_OVERLAY_DOMAIN 1
649
650 /*
651 * libxl memory management
652 *
653 * From the point of view of the application (ie, libxl's caller),
654 * struct libxl_ctx* is threadsafe, and all returned allocated
655 * structures are obtained from malloc(), and must be freed by the
656 * caller either directly or by calling an appropriate free function
657 * provided by libxl. Ie the application does not get automatic
658 * assistance from libxl in managing these allocations.
659 *
660 * Specific details are in the header comments which should be found
661 * in libxl.h or libxlutil.h, next to the relevant function
662 * declarations.
663 *
664 * Internally, libxl has a garbage collection scheme which allows much libxl
665 * code to allocate strings etc. for internal use without needing to
666 * free them. These are called "temporary allocations".
667 *
668 * The pool for these temporary allocations, along with any other
669 * thread-specific data which is private to libxl but shared between
670 * libxl functions (such as the current xenstore transaction), is
671 * stored in the "gc context" which is a special enhanced context
672 * structure allocated automatically by convenience macros at every
673 * entry to libxl.
674 *
675 * Every libxl function falls into one of these categories:
676 *
677 * 1. Public functions (declared in libxl.h, libxlutil.h), which may
678 * be called by libxl applications. If a public function returns
679 * any allocated object to its caller, that object must have come
680 * from malloc.
681 *
682 * The definitions of public functions MUST use the gc context
683 * initialisation macros (or do the equivalent work themselves).
684 * These macros will ensure that all temporary allocations will be
685 * automatically freed before the function returns to its caller.
686 *
687 * A public function may be called from within libxl; the call
688 * context initialisation macros will make sure that the internal
689 * caller's context is reused (eg, so that the same xenstore
690 * transaction is used). But in-libxl callers of libxl public
691 * functions should note that any libxl public function may cause
692 * recursively reentry into libxl via the application's event
693 * callback hook.
694 *
695 * Public functions have names like libxl_foobar.
696 *
697 * 2. Private functions, which may not be called by libxl
698 * applications; they are not declared in libxl.h or libxlutil.h
699 * and they may not be called other than by other libxl functions.
700 *
701 * Private functions should not use the gc context initialisation
702 * macros.
703 *
704 * Private functions have names like libxl__foobar (NB, two underscores).
705 * Also the declaration of such functions must be preceeded by the _hidden
706 * macro.
707 *
708 * Allocations made by a libxl function fall into one of the following
709 * categories (where "object" includes any memory allocation):
710 *
711 * (a) Objects which are not returned to the function's caller.
712 * These should be allocated from the temporary pool.
713 *
714 * (b) Objects which are intended for return to the calling
715 * application. This includes all allocated objects returned by
716 * any public function.
717 *
718 * It may also include objects allocated by an internal function
719 * specifically for eventual return by the function's external
720 * callers, but this situation should be clearly documented in
721 * comments.
722 *
723 * These should be allocated from malloc() et al. and comments
724 * near the function declaration should explain the memory
725 * ownership. If a simple free() by the application is not
726 * sufficient, a suitable public freeing function should be
727 * provided.
728 *
729 * (c) Internal objects whose size and/or lifetime dictate explicit
730 * memory management within libxl. This includes objects which
731 * will be embedded in opaque structures which will be returned to
732 * the libxl caller (more generally, any internal object whose
733 * lifetime exceeds the libxl entrypoint which creates it) and
734 * objects which are so large or numerous that explicit memory
735 * management is required.
736 *
737 * These should be allocated from malloc() et al., and freed
738 * explicitly at the appropriate point. The situation should be
739 * documented in comments.
740 *
741 * (d) Objects which are allocated by internal-only functions and
742 * returned to the function's (therefore, internal) caller but are
743 * strictly for internal use by other parts of libxl. These
744 * should be allocated from the temporary pool.
745 *
746 * Where a function's primary purpose is to return such an object,
747 * it should have a libxl__gc * as it's first argument.
748 *
749 * Note that there are two ways to change an allocation from this
750 * category to the "public" category. Either the implementation
751 * is kept internal and a wrapper function duplicates all memory
752 * allocations so that they are suitable for return to external
753 * callers or the implementation uses plain malloc() et al calls
754 * and an internal wrapper adds the relevant pointers to the gc.
755 * The latter method is preferred for obvious performance reasons.
756 *
757 * No temporary objects allocated from the pool may be explicitly freed.
758 * Therefore public functions which initialize a libxl__gc MUST call
759 * libxl__free_all() before returning.
760 *
761 * Memory allocation failures are not handled gracefully. If malloc
762 * (or realloc) fails, libxl will cause the entire process to print
763 * a message to stderr and exit with status 255.
764 */
765 /*
766 * libxl types
767 *
768 * Most libxl types are defined by the libxl IDL (see
769 * libxl_types.idl). The library provides a common set of methods for
770 * initialising and freeing these types.
771 *
772 * IDL-generated libxl types should be used as follows: the user must
773 * always call the "init" function before using a type, even if the
774 * variable is simply being passed by reference as an out parameter
775 * to a libxl function. The user must always calls "dispose" exactly
776 * once afterwards, to clean up, regardless of whether operations on
777 * this object succeeded or failed. See the xl code for examples.
778 *
779 * "init" and "dispose" are idempotent.
780 *
781 * void libxl_<type>_init(<type> *p):
782 *
783 * Initialises the members of "p" to all defaults. These may either
784 * be special value which indicates to the library that it should
785 * select an appropriate default when using this field or actual
786 * default values.
787 *
788 * Some fields within a data type (e.g. unions) cannot be sensibly
789 * initialised without further information. In these cases a
790 * separate subfield initialisation function is provided (see
791 * below).
792 *
793 * An instance which has been initialised using this method can
794 * always be safely passed to the dispose function (see
795 * below). This is true even if the data type contains fields which
796 * require a separate call to a subfield initialisation function.
797 *
798 * This method is provided for any aggregate type which is used as
799 * an input parameter.
800 *
801 * void libxl_<type>_init_<subfield>(<type> *p, subfield):
802 *
803 * Initialise those parts of "p" which are not initialised by the
804 * main init function due to the unknown value of "subfield". Sets
805 * p->subfield as well as initialising any fields to their default
806 * values.
807 *
808 * p->subfield must not have been previously initialised.
809 *
810 * This method is provided for any aggregate type.
811 *
812 * void libxl_<type>_dispose(instance *p):
813 *
814 * Frees any dynamically allocated memory used by the members of
815 * "p" but not the storage used by "p" itself (this allows for the
816 * allocation of arrays of types and for the composition of types).
817 *
818 * char *libxl_<type>_to_json(instance *p)
819 *
820 * Generates a JSON object from "p" in the form of a NULL terminated
821 * string.
822 *
823 * <type *> libxl_<type>_from_json(const char *json)
824 * int libxl_<type>_from_json(const char *json)
825 *
826 * Parses "json" and returns:
827 *
828 * an int value, if <type> is enumeration type. The value is the enum value
829 * representing the respective string in "json".
830 *
831 * an instance of <type>, if <type> is aggregate type. The returned
832 * instance has its fields filled in by the parser according to "json".
833 *
834 * If the parsing fails, caller cannot rely on the value / instance
835 * returned.
836 */
837 #ifndef LIBXL_H
838 #define LIBXL_H
839
840 #include <stdbool.h>
841 #include <stdint.h>
842 #include <stdarg.h>
843 #include <string.h>
844 #include <errno.h>
845 #include <netinet/in.h>
846 #include <sys/wait.h> /* for pid_t */
847
848 #include <xentoollog.h>
849
850 typedef struct libxl__ctx libxl_ctx;
851
852 #include <libxl_uuid.h>
853 #include <xen_list.h>
854
855 /* API compatibility. */
856 #ifdef LIBXL_API_VERSION
857 #if LIBXL_API_VERSION != 0x040200 && LIBXL_API_VERSION != 0x040300 && \
858 LIBXL_API_VERSION != 0x040400 && LIBXL_API_VERSION != 0x040500 && \
859 LIBXL_API_VERSION != 0x040700 && LIBXL_API_VERSION != 0x040800 && \
860 LIBXL_API_VERSION != 0x041300 && LIBXL_API_VERSION != 0x041400 && \
861 LIBXL_API_VERSION != 0x041800
862 #error Unknown LIBXL_API_VERSION
863 #endif
864 #endif
865
866 /* LIBXL_HAVE_RETRIEVE_DOMAIN_CONFIGURATION
867 *
868 * If this is defined we have libxl_retrieve_domain_configuration which
869 * returns the current configuration of a domain, which can be used to
870 * rebuild a domain.
871 */
872 #define LIBXL_HAVE_RETRIEVE_DOMAIN_CONFIGURATION 1
873
874 /*
875 * LIBXL_HAVE_BUILDINFO_VCPU_AFFINITY_ARRAYS
876 *
877 * If this is defined, then the libxl_domain_build_info structure will
878 * contain two arrays of libxl_bitmap-s, with all the necessary information
879 * to set the hard affinity (vcpu_hard_affinity) and the soft affinity
880 * (vcpu_soft_affinity) of the VCPUs.
881 *
882 * Note that, if the vcpu_hard_affinity array is used, libxl will ignore
883 * the content of the cpumap field of libxl_domain_build_info. That is to
884 * say, if the array is allocated and used by the caller, it is it and
885 * only it that determines the hard affinity of the domain's VCPUs.
886 *
887 * The number of libxl_bitmap-s in the arrays should be equal to the
888 * maximum number of VCPUs of the domain. If there only are N elements in
889 * an array, with N smaller the the maximum number of VCPUs, the hard or
890 * soft affinity (depending on which array we are talking about) will be
891 * set only for the first N VCPUs. The other VCPUs will just have affinity,
892 * both hard and soft, with all the host PCPUs.
893 * Each bitmap should be big enough to accommodate the maximum number of
894 * PCPUs of the host.
895 */
896 #define LIBXL_HAVE_BUILDINFO_VCPU_AFFINITY_ARRAYS 1
897
898 /*
899 * LIBXL_HAVE_BUILDINFO_VKB_DEVICE
900 *
901 * If this is defined, then the libxl_domain_build_info structure will
902 * contain a boolean hvm.vkb_device which instructs libxl whether to include
903 * a vkbd at build time or not.
904 */
905 #define LIBXL_HAVE_BUILDINFO_VKB_DEVICE 1
906
907 /*
908 * LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST
909 *
910 * If this is defined, then the libxl_domain_build_info structure will
911 * contain hvm.usbdevice_list, a libxl_string_list type that contains
912 * a list of USB devices to specify on the qemu command-line.
913 *
914 * If it is set, callers may use either hvm.usbdevice or
915 * hvm.usbdevice_list, but not both; if both are set, libxl will
916 * throw an error.
917 *
918 * If this is not defined, callers can only use hvm.usbdevice. Note
919 * that this means only one device can be added at domain build time.
920 */
921 #define LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST 1
922
923 /*
924 * LIBXL_HAVE_BUILDINFO_USBVERSION
925 *
926 * If this is defined, then the libxl_domain_build_info structure will
927 * contain hvm.usbversion, a integer type that contains a USB
928 * controller version to specify on the qemu upstream command-line.
929 *
930 * If it is set, callers may use hvm.usbversion to specify if the usb
931 * controller is usb1, usb2 or usb3.
932 *
933 * If this is not defined, the hvm.usbversion field does not exist.
934 */
935 #define LIBXL_HAVE_BUILDINFO_USBVERSION 1
936
937 /*
938 * LIBXL_HAVE_DEVICE_BACKEND_DOMNAME
939 *
940 * If this is defined, libxl_device_* structures containing a backend_domid
941 * field also contain a backend_domname field. If backend_domname is set, it is
942 * resolved to a domain ID when the device is used and takes precedence over the
943 * backend_domid field.
944 *
945 * If this is not defined, the backend_domname field does not exist.
946 */
947 #define LIBXL_HAVE_DEVICE_BACKEND_DOMNAME 1
948
949 /*
950 * LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG
951 *
952 * This argument was erroneously "const" in the 4.2 release despite
953 * the requirement for the callback to free the event.
954 */
955 #if LIBXL_API_VERSION != 0x040200
956 #define LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG 1
957 #endif
958
959 /*
960 * LIBXL_HAVE_NONCONST_LIBXL_BASENAME_RETURN_VALUE
961 *
962 * The return value of libxl_basename is malloc'ed but the erroneously
963 * marked as "const" in releases before 4.5.
964 */
965 #if !defined(LIBXL_API_VERSION) || LIBXL_API_VERSION >= 0x040500
966 #define LIBXL_HAVE_NONCONST_LIBXL_BASENAME_RETURN_VALUE 1
967 #endif
968
969 /*
970 * LIBXL_HAVE_PHYSINFO_OUTSTANDING_PAGES
971 *
972 * If this is defined, libxl_physinfo structure will contain an uint64 field
973 * called outstanding_pages, containing the number of pages claimed but not
974 * yet allocated for all domains.
975 */
976 #define LIBXL_HAVE_PHYSINFO_OUTSTANDING_PAGES 1
977
978 /*
979 * LIBXL_HAVE_PHYSINFO_MAX_POSSIBLE_MFN
980 *
981 * If this is defined, libxl_physinfo structure will contain an uint64 field
982 * called max_possible_mfn, containing the highest possible mfn on this host,
983 * possibly taking memory hotplug into account.
984 */
985 #define LIBXL_HAVE_PHYSINFO_MAX_POSSIBLE_MFN 1
986
987 /*
988 * LIBXL_HAVE_DOMINFO_OUTSTANDING_MEMKB 1
989 *
990 * If this is defined, libxl_dominfo will contain a MemKB type field called
991 * outstanding_memkb, containing the amount of claimed but not yet allocated
992 * memory for a specific domain.
993 */
994 #define LIBXL_HAVE_DOMINFO_OUTSTANDING_MEMKB 1
995
996 /*
997 * LIBXL_HAVE_DOMINFO_NEVER_STOP
998 *
999 * If this is defined, libxl_dominfo will contain a flag called never_stop
1000 * indicating that the specific domain should never be stopped by the
1001 * toolstack.
1002 */
1003 #define LIBXL_HAVE_DOMINFO_NEVER_STOP 1
1004
1005 /*
1006 * LIBXL_HAVE_DOMINFO_GPADDR_BITS
1007 *
1008 * If this is defined, libxl_dominfo will contain an uint8 field called
1009 * gpaddr_bits, containing the guest physical address space size.
1010 */
1011 #define LIBXL_HAVE_DOMINFO_GPADDR_BITS 1
1012
1013 /*
1014 * LIBXL_HAVE_QXL
1015 *
1016 * If defined, then the libxl_vga_interface_type will contain another value:
1017 * "QXL". This value define if qxl vga is supported.
1018 *
1019 * If this is not defined, the qxl vga support is missed.
1020 */
1021 #define LIBXL_HAVE_QXL 1
1022
1023 /*
1024 * LIBXL_HAVE_SPICE_VDAGENT
1025 *
1026 * If defined, then the libxl_spice_info structure will contain a boolean type:
1027 * vdagent and clipboard_sharing. These values define if Spice vdagent and
1028 * clipboard sharing are enabled.
1029 *
1030 * If this is not defined, the Spice vdagent support is ignored.
1031 */
1032 #define LIBXL_HAVE_SPICE_VDAGENT 1
1033
1034 /*
1035 * LIBXL_HAVE_SPICE_USBREDIRECTION
1036 *
1037 * If defined, then the libxl_spice_info structure will contain an integer type
1038 * field: usbredirection. This value defines if Spice usbredirection is enabled
1039 * and with how much channels.
1040 *
1041 * If this is not defined, the Spice usbredirection support is ignored.
1042 */
1043 #define LIBXL_HAVE_SPICE_USBREDIREDIRECTION 1
1044
1045 /*
1046 * LIBXL_HAVE_SPICE_IMAGECOMPRESSION
1047 *
1048 * If defined, then the libxl_spice_info structure will contain a string type
1049 * field: image_compression. This value defines what Spice image compression
1050 * is used.
1051 *
1052 * If this is not defined, the Spice image compression setting support is ignored.
1053 */
1054 #define LIBXL_HAVE_SPICE_IMAGECOMPRESSION 1
1055
1056 /*
1057 * LIBXL_HAVE_SPICE_STREAMINGVIDEO
1058 *
1059 * If defined, then the libxl_spice_info structure will contain a string type
1060 * field: streaming_video. This value defines what Spice streaming video setting
1061 * is used.
1062 *
1063 * If this is not defined, the Spice streaming video setting support is ignored.
1064 */
1065 #define LIBXL_HAVE_SPICE_STREAMINGVIDEO 1
1066
1067 /*
1068 * LIBXL_HAVE_HVM_HDTYPE
1069 *
1070 * If defined, then the u.hvm structure will contain a enum type
1071 * hdtype.
1072 */
1073 #define LIBXL_HAVE_HVM_HDTYPE 1
1074
1075 /*
1076 * LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS 1
1077 *
1078 * If this is defined, libxl_domain_create_restore()'s API has changed to
1079 * include a params structure.
1080 */
1081 #define LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS 1
1082
1083 /*
1084 * LIBXL_HAVE_DOMAIN_CREATE_RESTORE_SEND_BACK_FD 1
1085 *
1086 * If this is defined, libxl_domain_create_restore()'s API includes the
1087 * send_back_fd param. This is used only with COLO, for the libxl migration
1088 * back channel; other callers should pass -1.
1089 */
1090 #define LIBXL_HAVE_DOMAIN_CREATE_RESTORE_SEND_BACK_FD 1
1091
1092 /*
1093 * LIBXL_HAVE_DRIVER_DOMAIN_CREATION 1
1094 *
1095 * If this is defined, libxl_domain_create_info contains a driver_domain
1096 * field that can be used to tell libxl that the domain that is going
1097 * to be created is a driver domain, so the necessary actions are taken.
1098 */
1099 #define LIBXL_HAVE_DRIVER_DOMAIN_CREATION 1
1100
1101 /*
1102 * LIBXL_HAVE_SIGCHLD_SELECTIVE_REAP
1103 *
1104 * If this is defined:
1105 *
1106 * Firstly, the enum libxl_sigchld_owner (in libxl_event.h) has the
1107 * value libxl_sigchld_owner_libxl_always_selective_reap which may be
1108 * passed to libxl_childproc_setmode in hooks->chldmode.
1109 *
1110 * Secondly, the function libxl_childproc_sigchld_occurred exists.
1111 */
1112 #define LIBXL_HAVE_SIGCHLD_OWNER_SELECTIVE_REAP 1
1113
1114 /*
1115 * LIBXL_HAVE_SIGCHLD_SHARING
1116 *
1117 * If this is defined, it is permissible for multiple libxl ctxs
1118 * to simultaneously "own" SIGCHLD. See "Subprocess handling"
1119 * in libxl_event.h.
1120 */
1121 #define LIBXL_HAVE_SIGCHLD_SHARING 1
1122
1123 /*
1124 * LIBXL_HAVE_NO_SUSPEND_RESUME
1125 *
1126 * Is this is defined then the platform has no support for saving,
1127 * restoring or migrating a domain. In this case the related functions
1128 * should be expected to return failure. That is:
1129 * - libxl_domain_suspend
1130 * - libxl_domain_resume
1131 * - libxl_domain_remus_start
1132 */
1133 #if defined(__arm__) || defined(__aarch64__)
1134 #define LIBXL_HAVE_NO_SUSPEND_RESUME 1
1135 #endif
1136
1137 /*
1138 * LIBXL_HAVE_DOMAIN_SUSPEND_ONLY
1139 *
1140 * If this is defined, function libxl_domains_suspend_only() is available.
1141 */
1142
1143 #define LIBXL_HAVE_DOMAIN_SUSPEND_ONLY 1
1144
1145 /*
1146 * LIBXL_HAVE_DEVICE_PCI_SEIZE
1147 *
1148 * If this is defined, then the libxl_device_pci struct will contain
1149 * the "seize" boolean field. If this field is set, libxl_pci_add will
1150 * check to see if the device is currently assigned to pciback, and if not,
1151 * it will attempt to do so (unbinding the device from the existing driver).
1152 */
1153 #define LIBXL_HAVE_DEVICE_PCI_SEIZE 1
1154
1155 /*
1156 * LIBXL_HAVE_BUILDINFO_KERNEL
1157 *
1158 * If this is defined, then the libxl_domain_build_info structure will
1159 * contain 'kernel', 'ramdisk', 'cmdline' fields. 'kernel' is a string
1160 * to indicate kernel image location, 'ramdisk' is a string to indicate
1161 * ramdisk location, 'cmdline' is a string to indicate the paramters which
1162 * would be appended to kernel image.
1163 *
1164 * Both PV guest and HVM guest can use these fields for direct kernel boot.
1165 * But for compatibility reason, u.pv.kernel, u.pv.ramdisk and u.pv.cmdline
1166 * still exist.
1167 */
1168 #define LIBXL_HAVE_BUILDINFO_KERNEL 1
1169
1170 /*
1171 * LIBXL_HAVE_BUILDINFO_DEVICE_MODEL_STUBDOMAIN
1172 *
1173 * If this is defined, then the libxl_domain_build_info structure will contain
1174 * the following fields that specify options for device model stubdomains:
1175 * - stubdomain_memkb: integer indicating stubdomain RAM size
1176 * - stubdomain_kernel: string indicating stubdomain kernel image location
1177 * - stubdomain_cmdline: string of parameters to pass to the stubdomain kernel
1178 * - stubdomain_ramdisk: string indicating stubdomain ramdisk location
1179 */
1180 #define LIBXL_HAVE_BUILDINFO_DEVICE_MODEL_STUBDOMAIN 1
1181
1182 /*
1183 * LIBXL_HAVE_DEVICE_CHANNEL
1184 *
1185 * If this is defined, then the libxl_device_channel struct exists
1186 * and channels can be attached to a domain. Channels manifest as consoles
1187 * with names, see docs/misc/console.txt.
1188 */
1189 #define LIBXL_HAVE_DEVICE_CHANNEL 1
1190
1191 /*
1192 * LIBXL_HAVE_AO_ABORT indicates the availability of libxl_ao_abort
1193 */
1194 #define LIBXL_HAVE_AO_ABORT 1
1195
1196 /* Functions annotated with LIBXL_EXTERNAL_CALLERS_ONLY may not be
1197 * called from within libxl itself. Callers outside libxl, who
1198 * do not #include libxl_internal.h, are fine. */
1199 #ifndef LIBXL_EXTERNAL_CALLERS_ONLY
1200 #define LIBXL_EXTERNAL_CALLERS_ONLY /* disappears for callers outside libxl */
1201 #endif
1202
1203 /*
1204 * LIBXL_HAVE_UUID_COPY_CTX_PARAM
1205 *
1206 * If this is defined, libxl_uuid_copy has changed to take a libxl_ctx
1207 * structure.
1208 */
1209 #define LIBXL_HAVE_UUID_COPY_CTX_PARAM 1
1210
1211 /*
1212 * LIBXL_HAVE_SSID_LABEL
1213 *
1214 * If this is defined, then libxl IDL contains string of XSM security
1215 * label in all XSM related structures.
1216 *
1217 * If set this string takes precedence over the numeric field.
1218 */
1219 #define LIBXL_HAVE_SSID_LABEL 1
1220
1221 /*
1222 * LIBXL_HAVE_CPUPOOL_NAME
1223 *
1224 * If this is defined, then libxl IDL contains string of CPU pool
1225 * name in all CPU pool related structures.
1226 *
1227 * If set this string takes precedence over the numeric field.
1228 */
1229 #define LIBXL_HAVE_CPUPOOL_NAME 1
1230
1231 /*
1232 * LIBXL_HAVE_BUILDINFO_SERIAL_LIST
1233 *
1234 * If this is defined, then the libxl_domain_build_info structure will
1235 * contain hvm.serial_list, a libxl_string_list type that contains
1236 * a list of serial ports to specify on the qemu command-line.
1237 *
1238 * If it is set, callers may use either hvm.serial or
1239 * hvm.serial_list, but not both; if both are set, libxl will
1240 * throw an error.
1241 *
1242 * If this is not defined, callers can only use hvm.serial. Note
1243 * that this means only one serial port can be added at domain build time.
1244 */
1245 #define LIBXL_HAVE_BUILDINFO_SERIAL_LIST 1
1246
1247 /*
1248 * LIBXL_HAVE_ALTP2M
1249 * If this is defined, then libxl supports alternate p2m functionality.
1250 */
1251 #define LIBXL_HAVE_ALTP2M 1
1252
1253 /*
1254 * LIBXL_HAVE_REMUS
1255 * If this is defined, then libxl supports remus.
1256 */
1257 #define LIBXL_HAVE_REMUS 1
1258
1259 /*
1260 * LIBXL_HAVE_COLO_USERSPACE_PROXY
1261 * If this is defined, then libxl supports COLO userspace proxy.
1262 */
1263 #define LIBXL_HAVE_COLO_USERSPACE_PROXY 1
1264
1265 typedef uint8_t libxl_mac[6];
1266 #define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
1267 #define LIBXL_MAC_FMTLEN ((2*6)+5) /* 6 hex bytes plus 5 colons */
1268 #define LIBXL_MAC_BYTES(mac) mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
1269 void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);
1270
1271 #if defined(__i386__) || defined(__x86_64__)
1272 /*
1273 * LIBXL_HAVE_PSR_CMT
1274 *
1275 * If this is defined, the Cache Monitoring Technology feature is supported.
1276 */
1277 #define LIBXL_HAVE_PSR_CMT 1
1278
1279 /*
1280 * LIBXL_HAVE_PSR_MBM
1281 *
1282 * If this is defined, the Memory Bandwidth Monitoring feature is supported.
1283 */
1284 #define LIBXL_HAVE_PSR_MBM 1
1285
1286 /*
1287 * LIBXL_HAVE_PSR_CAT
1288 *
1289 * If this is defined, the Cache Allocation Technology feature is supported.
1290 */
1291 #define LIBXL_HAVE_PSR_CAT 1
1292
1293 /*
1294 * LIBXL_HAVE_PSR_CDP
1295 *
1296 * If this is defined, the Code and Data Prioritization feature is supported.
1297 */
1298 #define LIBXL_HAVE_PSR_CDP 1
1299
1300 /*
1301 * LIBXL_HAVE_PSR_L2_CAT
1302 *
1303 * If this is defined, the L2 Cache Allocation Technology feature is supported.
1304 */
1305 #define LIBXL_HAVE_PSR_L2_CAT 1
1306
1307 /*
1308 * LIBXL_HAVE_PSR_GENERIC
1309 *
1310 * If this is defined, the Memory Bandwidth Allocation feature is supported.
1311 * The following public functions are available:
1312 * libxl_psr_{set/get}_val
1313 * libxl_psr_get_hw_info
1314 * libxl_psr_hw_info_list_free
1315 */
1316 #define LIBXL_HAVE_PSR_GENERIC 1
1317
1318 /*
1319 * LIBXL_HAVE_MCA_CAPS
1320 *
1321 * If this is defined, setting MCA capabilities for HVM domain is supported.
1322 */
1323 #define LIBXL_HAVE_MCA_CAPS 1
1324 #endif
1325
1326 /*
1327 * LIBXL_HAVE_PCITOPOLOGY
1328 *
1329 * If this is defined, then interface to query hypervisor about PCI device
1330 * topology is available.
1331 */
1332 #define LIBXL_HAVE_PCITOPOLOGY 1
1333
1334 /*
1335 * LIBXL_HAVE_SOCKET_BITMAP
1336 *
1337 * If this is defined, then libxl_socket_bitmap_alloc and
1338 * libxl_get_online_socketmap exist.
1339 */
1340 #define LIBXL_HAVE_SOCKET_BITMAP 1
1341
1342 /*
1343 * LIBXL_HAVE_SRM_V2
1344 *
1345 * If this is defined, then the libxl_domain_create_restore() interface takes
1346 * a "stream_version" parameter and supports a value of 2.
1347 *
1348 * libxl_domain_suspend() will produce a v2 stream.
1349 */
1350 #define LIBXL_HAVE_SRM_V2 1
1351
1352 /*
1353 * LIBXL_HAVE_SRM_V1
1354 *
1355 * In the case that LIBXL_HAVE_SRM_V2 is set, LIBXL_HAVE_SRM_V1
1356 * indicates that libxl_domain_create_restore() can handle a "stream_version"
1357 * parameter of 1, and convert the stream format automatically.
1358 */
1359 #define LIBXL_HAVE_SRM_V1 1
1360
1361 /*
1362 * libxl_domain_build_info has the u.hvm.gfx_passthru_kind field and
1363 * the libxl_gfx_passthru_kind enumeration is defined.
1364 */
1365 #define LIBXL_HAVE_GFX_PASSTHRU_KIND
1366
1367 /*
1368 * LIBXL_HAVE_CHECKPOINTED_STREAM
1369 *
1370 * If this is defined, then libxl_checkpointed_stream exists.
1371 */
1372 #define LIBXL_HAVE_CHECKPOINTED_STREAM 1
1373
1374 /*
1375 * LIBXL_HAVE_BUILDINFO_HVM_SYSTEM_FIRMWARE
1376 *
1377 * libxl_domain_build_info has u.hvm.system_firmware field which can be use
1378 * to provide a different firmware blob (like SeaBIOS or OVMF).
1379 */
1380 #define LIBXL_HAVE_BUILDINFO_HVM_SYSTEM_FIRMWARE
1381
1382 /*
1383 * ERROR_REMUS_XXX error code only exists from Xen 4.5, Xen 4.6 and it
1384 * is changed to ERROR_CHECKPOINT_XXX in Xen 4.7
1385 */
1386 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION >= 0x040500 \
1387 && LIBXL_API_VERSION < 0x040700
1388 #define ERROR_REMUS_DEVOPS_DOES_NOT_MATCH \
1389 ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH
1390 #define ERROR_REMUS_DEVICE_NOT_SUPPORTED \
1391 ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED
1392 #endif
1393
1394 /*
1395 * LIBXL_HAVE_VGA_INTERFACE_TYPE_UNKNOWN
1396 *
1397 * In the case that LIBXL_HAVE_VGA_INTERFACE_TYPE_UNKNOWN is set the
1398 * libxl_vga_interface_type enumeration type contains a
1399 * LIBXL_VGA_INTERFACE_TYPE_UNKNOWN identifier. This is used to signal
1400 * that a libxl_vga_interface_type type has not been initialized yet.
1401 */
1402 #define LIBXL_HAVE_VGA_INTERFACE_TYPE_UNKNOWN 1
1403
1404 /*
1405 * LIBXL_HAVE_BYTEARRAY_UUID
1406 *
1407 * If this is defined, the internal member of libxl_uuid is defined
1408 * as a 16 byte array that contains the UUID in big endian format.
1409 * Also, the same structure layout is used across all OSes.
1410 */
1411 #define LIBXL_HAVE_BYTEARRAY_UUID 1
1412
1413 /*
1414 * LIBXL_HAVE_MEMKB_64BITS
1415 *
1416 * If this is defined libxl_set_memory_target(), libxl_domain_setmaxmem()
1417 * and libxl_wait_for_free_memory() will take a 64 bit value for the memory
1418 * size parameter.
1419 * From Xen 4.8 on libxl_get_memory_target(), libxl_domain_need_memory() and
1420 * libxl_get_free_memory() return the memory size in a 64 bit value, too.
1421 */
1422 #define LIBXL_HAVE_MEMKB_64BITS 1
1423
1424 /*
1425 * LIBXL_HAVE_QED
1426 *
1427 * If this is defined QED disk formats can be used for both HVM and PV guests.
1428 */
1429 #define LIBXL_HAVE_QED 1
1430
1431 /*
1432 * LIBXL_HAVE_SET_PARAMETERS
1433 *
1434 * If this is defined setting hypervisor parameters is supported.
1435 */
1436 #define LIBXL_HAVE_SET_PARAMETERS 1
1437
1438 /*
1439 * LIBXL_HAVE_PV_SHIM
1440 *
1441 * If this is defined, libxl_domain_build_info's pvh type information
1442 * contains members pvshim, pvshim_path, pvshim_cmdline, pvshim_extra.
1443 */
1444 #define LIBXL_HAVE_PV_SHIM 1
1445
1446 /*
1447 * LIBXL_HAVE_PVCALLS
1448 *
1449 * If this is defined, libxl supports creating pvcalls interfaces.
1450 */
1451 #define LIBXL_HAVE_PVCALLS 1
1452
1453 /*
1454 * LIBXL_HAVE_FN_USING_QMP_ASYNC
1455 *
1456 * This define indicates that some function's API has changed and have an
1457 * extra parameter "ao_how" which means that the function can be executed
1458 * asynchronously. Those functions are:
1459 * libxl_domain_pause()
1460 * libxl_domain_unpause()
1461 * libxl_send_trigger()
1462 * libxl_set_vcpuonline()
1463 * libxl_retrieve_domain_configuration()
1464 * libxl_qemu_monitor_command()
1465 * libxl_domain_shutdown()
1466 * libxl_domain_reboot()
1467 */
1468 #define LIBXL_HAVE_FN_USING_QMP_ASYNC 1
1469
1470 /*
1471 * LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONFIG
1472 *
1473 * If this is set, libxl_domain_need_memory takes a
1474 * libxl_domain_config* (non-const) and uint32_t domid_for_logging
1475 * (instead of a const libxl_domain_build_info*).
1476 *
1477 * If this is set, there is no need to call
1478 * libxl_get_required_shadow_memory and instead the caller should
1479 * simply leave shadow_memkb set to LIBXL_MEMKB_DEFAULT and allow
1480 * libxl to fill in a suitable default in the usual way.
1481 */
1482 #define LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONFIG
1483
1484 /*
1485 * LIBXL_HAVE_CREATEINFO_DOMID
1486 *
1487 * libxl_domain_create_new() and libxl_domain_create_restore() will use
1488 * a domid specified in libxl_domain_create_info.
1489 */
1490 #define LIBXL_HAVE_CREATEINFO_DOMID
1491
1492 /*
1493 * LIBXL_HAVE_CREATEINFO_XEND_SUSPEND_EVTCHN_COMPAT
1494 *
1495 * libxl_domain_create_info contains a boolean 'xend_suspend_evtchn_compat'
1496 * value to control creation of the xenstore path for a domain's suspend
1497 * event channel.
1498 */
1499 #define LIBXL_HAVE_CREATEINFO_XEND_SUSPEND_EVTCHN_COMPAT
1500
1501 typedef char **libxl_string_list;
1502 void libxl_string_list_dispose(libxl_string_list *sl);
1503 int libxl_string_list_length(const libxl_string_list *sl);
1504 void libxl_string_list_copy(libxl_ctx *ctx, libxl_string_list *dst,
1505 const libxl_string_list *src);
1506
1507 typedef char **libxl_key_value_list;
1508 void libxl_key_value_list_dispose(libxl_key_value_list *kvl);
1509 int libxl_key_value_list_length(const libxl_key_value_list *kvl);
1510 void libxl_key_value_list_copy(libxl_ctx *ctx,
1511 libxl_key_value_list *dst,
1512 const libxl_key_value_list *src);
1513
1514 typedef uint32_t libxl_hwcap[8];
1515 void libxl_hwcap_copy(libxl_ctx *ctx, libxl_hwcap *dst, const libxl_hwcap *src);
1516
1517 typedef uint64_t libxl_ev_user;
1518
1519 typedef struct {
1520 uint32_t size; /* number of bytes in map */
1521 uint8_t *map;
1522 } libxl_bitmap;
1523 void libxl_bitmap_init(libxl_bitmap *map);
1524 void libxl_bitmap_dispose(libxl_bitmap *map);
1525
1526 struct libxl__cpu_policy;
1527 typedef struct libxl__cpu_policy *libxl_cpuid_policy_list;
1528 void libxl_cpuid_dispose(libxl_cpuid_policy_list *cpuid_list);
1529 int libxl_cpuid_policy_list_length(const libxl_cpuid_policy_list *l);
1530 void libxl_cpuid_policy_list_copy(libxl_ctx *ctx,
1531 libxl_cpuid_policy_list *dst,
1532 const libxl_cpuid_policy_list *src);
1533
1534 #define LIBXL_PCI_FUNC_ALL (~0U)
1535
1536 typedef uint32_t libxl_domid;
1537 typedef int libxl_devid;
1538
1539 /*
1540 * Formatting Enumerations.
1541 *
1542 * Each enumeration type libxl_E declares an associated lookup table
1543 * libxl_E_string_table and a lookup function libxl_E_from_string.
1544 */
1545 typedef struct {
1546 const char *s;
1547 int v;
1548 } libxl_enum_string_table;
1549
1550 struct libxl_event;
1551 typedef XEN_TAILQ_ENTRY(struct libxl_event) libxl_ev_link;
1552
1553 /*
1554 * A boolean variable with an explicit default state.
1555 *
1556 * Users should treat this struct as opaque and use the following
1557 * defined macros and accessor functions.
1558 *
1559 * To allow users of the library to naively select all defaults this
1560 * state is represented as 0. False is < 0 and True is > 0.
1561 */
1562 typedef struct {
1563 int val;
1564 } libxl_defbool;
1565
1566 void libxl_defbool_set(libxl_defbool *db, bool b);
1567 /* Resets to default */
1568 void libxl_defbool_unset(libxl_defbool *db);
1569 /* Sets db only if it is currently == default */
1570 void libxl_defbool_setdefault(libxl_defbool *db, bool b);
1571 bool libxl_defbool_is_default(libxl_defbool db);
1572 /* db must not be == default */
1573 bool libxl_defbool_val(libxl_defbool db);
1574
1575 const char *libxl_defbool_to_string(libxl_defbool b);
1576
1577 #define LIBXL_TIMER_MODE_DEFAULT -1
1578 #define LIBXL_MEMKB_DEFAULT ~0ULL
1579
1580 /*
1581 * We'd like to set a memory boundary to determine if we need to check
1582 * any overlap with reserved device memory.
1583 */
1584 #define LIBXL_RDM_MEM_BOUNDARY_MEMKB_DEFAULT (2048 * 1024)
1585
1586 #define LIBXL_MS_VM_GENID_LEN 16
1587 typedef struct {
1588 uint8_t bytes[LIBXL_MS_VM_GENID_LEN];
1589 } libxl_ms_vm_genid;
1590
1591 #include "_libxl_types.h"
1592
1593 const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx);
1594
1595 /*
1596 * Some libxl operations can take a long time. These functions take a
1597 * parameter to control their concurrency:
1598 * libxl_asyncop_how *ao_how
1599 *
1600 * If ao_how==NULL, the function will be synchronous.
1601 *
1602 * If ao_how!=NULL, the function will set the operation going, and if
1603 * this is successful will return 0. In this case the zero error
1604 * response does NOT mean that the operation was successful; it just
1605 * means that it has been successfully started. It will finish later,
1606 * perhaps with an error.
1607 *
1608 * If ao_how->callback!=NULL, the callback will be called when the
1609 * operation completes. The same rules as for libxl_event_hooks
1610 * apply, including the reentrancy rules and the possibility of
1611 * "disaster", except that libxl calls ao_how->callback instead of
1612 * libxl_event_hooks.event_occurs. (See libxl_event.h.)
1613 *
1614 * If ao_how->callback==NULL, a libxl_event will be generated which
1615 * can be obtained from libxl_event_wait or libxl_event_check. The
1616 * event will have type OPERATION_COMPLETE (which is not used
1617 * elsewhere).
1618 *
1619 * Note that it is possible for an asynchronous operation which is to
1620 * result in a callback to complete during its initiating function
1621 * call. In this case the initiating function will return 0
1622 * indicating the at the operation is "in progress", even though by
1623 * the time it returns the operation is complete and the callback has
1624 * already happened.
1625 *
1626 * The application must set and use ao_how->for_event (which will be
1627 * copied into libxl_event.for_user) or ao_how->for_callback (passed
1628 * to the callback) to determine which operation finished, and it must
1629 * of course check the rc value for errors.
1630 *
1631 * *ao_how does not need to remain valid after the initiating function
1632 * returns. All other parameters must remain valid for the lifetime of
1633 * the asynchronous operation, unless otherwise specified.
1634 *
1635 * Callbacks may occur on any thread in which the application calls
1636 * libxl.
1637 */
1638
1639 typedef struct {
1640 void (*callback)(libxl_ctx *ctx, int rc, void *for_callback);
1641 union {
1642 libxl_ev_user for_event; /* used if callback==NULL */
1643 void *for_callback; /* passed to callback */
1644 } u;
1645 } libxl_asyncop_how;
1646
1647 /*
1648 * Some more complex asynchronous operations can report intermediate
1649 * progress. How this is to be reported is controlled, for each
1650 * function, by a parameter
1651 * libxl_asyncprogress_how *aop_FOO_how;
1652 * for each kind of progress FOO supported by that function. Each
1653 * such kind of progress is associated with an event type.
1654 *
1655 * The function description will document whether, when, and how
1656 * many times, the intermediate progress will be reported, and
1657 * what the corresponding event type(s) are.
1658 *
1659 * If aop_FOO_how==NULL, intermediate progress reports are discarded.
1660 *
1661 * If aop_FOO_how->callback==NULL, intermediate progress reports
1662 * generate libxl events which can be obtained from libxl_event_wait
1663 * or libxl_event_check.
1664 *
1665 * If aop_FOO_how->callback!=NULL, libxl will report intermediate
1666 * progress by calling callback(ctx, &event, for_callback).
1667 *
1668 * The rules for these events are otherwise the same as those for
1669 * ordinary events. The reentrancy and threading rules for the
1670 * callback are the same as those for ao completion callbacks.
1671 *
1672 * Note that the callback, if provided, is responsible for freeing
1673 * the event.
1674 *
1675 * If callbacks are requested, they will be made, and returned, before
1676 * the long-running libxl operation is considered finished (so if the
1677 * long-running libxl operation was invoked with ao_how==NULL then any
1678 * callbacks will occur strictly before the long-running operation
1679 * returns). However, the callbacks may occur on any thread.
1680 *
1681 * In general, otherwise, no promises are made about the relative
1682 * order of callbacks in a multithreaded program. In particular
1683 * different callbacks relating to the same long-running operation may
1684 * be delivered out of order.
1685 */
1686
1687 typedef struct {
1688 void (*callback)(libxl_ctx *ctx, libxl_event*, void *for_callback);
1689 libxl_ev_user for_event; /* always used */
1690 void *for_callback; /* passed to callback */
1691 } libxl_asyncprogress_how;
1692
1693 /*
1694 * It is sometimes possible to abort an asynchronous operation.
1695 *
1696 * libxl_ao_abort searches for an ongoing asynchronous operation whose
1697 * ao_how is identical to *how, and tries to abort it. The return
1698 * values from libxl_ao_abort are as follows:
1699 *
1700 * 0
1701 *
1702 * The operation was found, and attempts are being made to cut it
1703 * short. However, it may still take some time to stop. It is
1704 * also possible that the operation will nevertheless complete
1705 * successfully.
1706 *
1707 * ERROR_NOTFOUND
1708 *
1709 * No matching ongoing operation was found. This might happen
1710 * for an actual operation if the operation has already completed
1711 * (perhaps on another thread). The call to libxl_ao_abort has
1712 * had no effect.
1713 *
1714 * ERROR_ABORTED
1715 *
1716 * The operation has already been the subject of at least one
1717 * call to libxl_ao_abort.
1718 *
1719 * If the operation was indeed cut short due to the abort request, it
1720 * will complete, at some point in the future, with ERROR_ABORTED. In
1721 * that case, depending on the operation it have performed some of the
1722 * work in question and left the operation half-done. Consult the
1723 * documentation for individual operations.
1724 *
1725 * Note that an aborted operation might still fail for other reasons
1726 * even after the abort was requested.
1727 *
1728 * If your application is multithreaded you must not reuse an
1729 * ao_how->for_event or ao_how->for_callback value (with a particular
1730 * ao_how->callback) unless you are sure that none of your other
1731 * threads are going to abort the previous operation using that
1732 * value; otherwise you risk aborting the wrong operation if the
1733 * intended target of the abort request completes in the meantime.
1734 *
1735 * It is possible to abort even an operation which is being performed
1736 * synchronously, but since in that case how==NULL you had better only
1737 * have one such operation, because it is not possible to tell them
1738 * apart (and libxl_ao_abort will abort only the first one it finds).
1739 * (And, if you want to do this, obviously the abort would have to be
1740 * requested on a different thread.)
1741 */
1742 int libxl_ao_abort(libxl_ctx *ctx, const libxl_asyncop_how *how)
1743 LIBXL_EXTERNAL_CALLERS_ONLY;
1744
1745
1746 #define LIBXL_VERSION 0
1747
1748 /* context functions */
1749 int libxl_ctx_alloc(libxl_ctx **pctx, int version,
1750 unsigned flags /* none currently defined */,
1751 xentoollog_logger *lg);
1752 int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */);
1753
1754 /* domain related functions */
1755
1756 #define INVALID_DOMID ~0
1757 #define RANDOM_DOMID (INVALID_DOMID - 1)
1758
1759 /* If the result is ERROR_ABORTED, the domain may or may not exist
1760 * (in a half-created state). *domid will be valid and will be the
1761 * domain id, or INVALID_DOMID, as appropriate */
1762
1763 int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
1764 uint32_t *domid,
1765 const libxl_asyncop_how *ao_how,
1766 const libxl_asyncprogress_how *aop_console_how)
1767 LIBXL_EXTERNAL_CALLERS_ONLY;
1768 int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
1769 uint32_t *domid, int restore_fd,
1770 int send_back_fd,
1771 const libxl_domain_restore_params *params,
1772 const libxl_asyncop_how *ao_how,
1773 const libxl_asyncprogress_how *aop_console_how)
1774 LIBXL_EXTERNAL_CALLERS_ONLY;
1775
1776 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040400
1777
libxl_domain_create_restore_0x040200(libxl_ctx * ctx,libxl_domain_config * d_config,uint32_t * domid,int restore_fd,const libxl_asyncop_how * ao_how,const libxl_asyncprogress_how * aop_console_how)1778 static inline int libxl_domain_create_restore_0x040200(
1779 libxl_ctx *ctx, libxl_domain_config *d_config,
1780 uint32_t *domid, int restore_fd,
1781 const libxl_asyncop_how *ao_how,
1782 const libxl_asyncprogress_how *aop_console_how)
1783 LIBXL_EXTERNAL_CALLERS_ONLY
1784 {
1785 libxl_domain_restore_params params;
1786 int ret;
1787
1788 libxl_domain_restore_params_init(¶ms);
1789
1790 ret = libxl_domain_create_restore(
1791 ctx, d_config, domid, restore_fd, -1, ¶ms, ao_how, aop_console_how);
1792
1793 libxl_domain_restore_params_dispose(¶ms);
1794 return ret;
1795 }
1796
1797 #define libxl_domain_create_restore libxl_domain_create_restore_0x040200
1798
1799 #elif defined(LIBXL_API_VERSION) && LIBXL_API_VERSION >= 0x040400 \
1800 && LIBXL_API_VERSION < 0x040700
1801
libxl_domain_create_restore_0x040400(libxl_ctx * ctx,libxl_domain_config * d_config,uint32_t * domid,int restore_fd,const libxl_domain_restore_params * params,const libxl_asyncop_how * ao_how,const libxl_asyncprogress_how * aop_console_how)1802 static inline int libxl_domain_create_restore_0x040400(
1803 libxl_ctx *ctx, libxl_domain_config *d_config,
1804 uint32_t *domid, int restore_fd,
1805 const libxl_domain_restore_params *params,
1806 const libxl_asyncop_how *ao_how,
1807 const libxl_asyncprogress_how *aop_console_how)
1808 LIBXL_EXTERNAL_CALLERS_ONLY
1809 {
1810 return libxl_domain_create_restore(ctx, d_config, domid, restore_fd,
1811 -1, params, ao_how, aop_console_how);
1812 }
1813
1814 #define libxl_domain_create_restore libxl_domain_create_restore_0x040400
1815
1816 #endif
1817
1818 int libxl_domain_soft_reset(libxl_ctx *ctx,
1819 libxl_domain_config *d_config,
1820 uint32_t domid,
1821 const libxl_asyncop_how *ao_how,
1822 const libxl_asyncprogress_how
1823 *aop_console_how)
1824 LIBXL_EXTERNAL_CALLERS_ONLY;
1825
1826 /* A progress report will be made via ao_console_how, of type
1827 * domain_create_console_available, when the domain's primary
1828 * console is available and can be connected to.
1829 */
1830
1831 void libxl_domain_config_init(libxl_domain_config *d_config);
1832 void libxl_domain_config_dispose(libxl_domain_config *d_config);
1833
1834 /*
1835 * Retrieve domain configuration and filled it in d_config. The
1836 * returned configuration can be used to rebuild a domain. It only
1837 * works with DomU.
1838 */
1839 int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
1840 libxl_domain_config *d_config,
1841 const libxl_asyncop_how *ao_how)
1842 LIBXL_EXTERNAL_CALLERS_ONLY;
1843 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
libxl_retrieve_domain_configuration_0x041200(libxl_ctx * ctx,uint32_t domid,libxl_domain_config * d_config)1844 static inline int libxl_retrieve_domain_configuration_0x041200(
1845 libxl_ctx *ctx, uint32_t domid, libxl_domain_config *d_config)
1846 {
1847 return libxl_retrieve_domain_configuration(ctx, domid, d_config, NULL);
1848 }
1849 #define libxl_retrieve_domain_configuration \
1850 libxl_retrieve_domain_configuration_0x041200
1851 #endif
1852
1853 int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd,
1854 int flags, /* LIBXL_SUSPEND_* */
1855 const libxl_asyncop_how *ao_how)
1856 LIBXL_EXTERNAL_CALLERS_ONLY;
1857 #define LIBXL_SUSPEND_DEBUG 1
1858 #define LIBXL_SUSPEND_LIVE 2
1859
1860 /*
1861 * Only suspend domain, do not save its state to file, do not destroy it.
1862 * Suspended domain can be resumed with libxl_domain_resume()
1863 */
1864 int libxl_domain_suspend_only(libxl_ctx *ctx, uint32_t domid,
1865 const libxl_asyncop_how *ao_how)
1866 LIBXL_EXTERNAL_CALLERS_ONLY;
1867
1868 /* @param suspend_cancel [from xenctrl.h:xc_domain_resume( @param fast )]
1869 * If this parameter is true, use co-operative resume. The guest
1870 * must support this.
1871 */
1872 int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid, int suspend_cancel,
1873 const libxl_asyncop_how *ao_how)
1874 LIBXL_EXTERNAL_CALLERS_ONLY;
1875
1876 /*
1877 * This function doesn't return unless something has gone wrong with
1878 * the replication to the secondary. If this function returns then the
1879 * caller should resume the (primary) domain.
1880 */
1881 int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
1882 uint32_t domid, int send_fd, int recv_fd,
1883 const libxl_asyncop_how *ao_how)
1884 LIBXL_EXTERNAL_CALLERS_ONLY;
1885
1886 int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid,
1887 const libxl_asyncop_how *ao_how)
1888 LIBXL_EXTERNAL_CALLERS_ONLY;
1889 int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid,
1890 const libxl_asyncop_how *ao_how)
1891 LIBXL_EXTERNAL_CALLERS_ONLY;
1892 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
libxl_domain_shutdown_0x041200(libxl_ctx * ctx,uint32_t domid)1893 static inline int libxl_domain_shutdown_0x041200(libxl_ctx *ctx,
1894 uint32_t domid)
1895 {
1896 return libxl_domain_shutdown(ctx, domid, NULL);
1897 }
1898 #define libxl_domain_shutdown libxl_domain_shutdown_0x041200
libxl_domain_reboot_0x041200(libxl_ctx * ctx,uint32_t domid)1899 static inline int libxl_domain_reboot_0x041200(libxl_ctx *ctx,
1900 uint32_t domid)
1901 {
1902 return libxl_domain_reboot(ctx, domid, NULL);
1903 }
1904 #define libxl_domain_reboot libxl_domain_reboot_0x041200
1905 #endif
1906
1907 int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
1908 const libxl_asyncop_how *ao_how)
1909 LIBXL_EXTERNAL_CALLERS_ONLY;
1910 int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_info *info, const char *name_suffix, libxl_uuid new_uuid);
1911
1912 /* get max. number of cpus supported by hypervisor */
1913 int libxl_get_max_cpus(libxl_ctx *ctx);
1914
1915 /* get the actual number of currently online cpus on the host */
1916 int libxl_get_online_cpus(libxl_ctx *ctx);
1917 /* Beware that no locking or serialization is provided by libxl,
1918 * so the information can be outdated as far as the function
1919 * returns. If there are other entities in the system capable
1920 * of onlining/offlining CPUs, it is up to the application
1921 * to guarantee consistency, if that is important. */
1922
1923 /* get max. number of NUMA nodes supported by hypervisor */
1924 int libxl_get_max_nodes(libxl_ctx *ctx);
1925
1926 int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid,
1927 const char *old_name, const char *new_name);
1928
1929 /* if old_name is NULL, any old name is OK; otherwise we check
1930 * transactionally that the domain has the old old name; if
1931 * trans is not 0 we use caller's transaction and caller must do retries */
1932
1933 int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid,
1934 const libxl_asyncop_how *ao_how)
1935 LIBXL_EXTERNAL_CALLERS_ONLY;
1936 int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid,
1937 const libxl_asyncop_how *ao_how)
1938 LIBXL_EXTERNAL_CALLERS_ONLY;
1939 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
libxl_domain_pause_0x041200(libxl_ctx * ctx,uint32_t domid)1940 static inline int libxl_domain_pause_0x041200(
1941 libxl_ctx *ctx, uint32_t domid)
1942 {
1943 return libxl_domain_pause(ctx, domid, NULL);
1944 }
libxl_domain_unpause_0x041200(libxl_ctx * ctx,uint32_t domid)1945 static inline int libxl_domain_unpause_0x041200(
1946 libxl_ctx *ctx, uint32_t domid)
1947 {
1948 return libxl_domain_unpause(ctx, domid, NULL);
1949 }
1950 #define libxl_domain_pause libxl_domain_pause_0x041200
1951 #define libxl_domain_unpause libxl_domain_unpause_0x041200
1952 #endif
1953
1954
1955 int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
1956 const char *filename,
1957 const libxl_asyncop_how *ao_how)
1958 LIBXL_EXTERNAL_CALLERS_ONLY;
1959
1960 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint64_t target_memkb);
1961 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, int64_t target_memkb, int relative, int enforce);
1962 int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint64_t *out_target);
1963 int libxl_get_memory_target_0x040700(libxl_ctx *ctx, uint32_t domid,
1964 uint32_t *out_target)
1965 LIBXL_EXTERNAL_CALLERS_ONLY;
1966
1967 /*
1968 * WARNING
1969 * This memory management API is unstable even in Xen 4.2.
1970 * It has a numer of deficiencies and we intend to replace it.
1971 *
1972 * The semantics of these functions should not be relied on to be very
1973 * coherent or stable. We will however endeavour to keep working
1974 * existing programs which use them in roughly the same way as libxl.
1975 */
1976 /* how much free memory in the system a domain needs to be built */
1977 int libxl_domain_need_memory(libxl_ctx *ctx,
1978 libxl_domain_config *config
1979 /* ^ will be partially defaulted */,
1980 uint32_t domid_for_logging /* INVALID_DOMID ok */,
1981 uint64_t *need_memkb);
1982 int libxl_domain_need_memory_0x041200(libxl_ctx *ctx,
1983 const libxl_domain_build_info *b_info_in,
1984 uint64_t *need_memkb);
1985 int libxl_domain_need_memory_0x040700(libxl_ctx *ctx,
1986 const libxl_domain_build_info *b_info_in,
1987 uint32_t *need_memkb)
1988 LIBXL_EXTERNAL_CALLERS_ONLY;
1989 /* how much free memory is available in the system */
1990 int libxl_get_free_memory(libxl_ctx *ctx, uint64_t *memkb);
1991 int libxl_get_free_memory_0x040700(libxl_ctx *ctx, uint32_t *memkb)
1992 LIBXL_EXTERNAL_CALLERS_ONLY;
1993 /* wait for a given amount of memory to be free in the system */
1994 int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint64_t memory_kb, int wait_secs);
1995 /*
1996 * Wait for the memory target of a domain to be reached. Does not
1997 * decrement wait_secs if the domain is making progress toward reaching
1998 * the target. If the domain is not making progress, wait_secs is
1999 * decremented. If the timeout expires before the target is reached, the
2000 * function returns ERROR_FAIL.
2001 *
2002 * Older versions of this function (Xen 4.5 and older), decremented
2003 * wait_secs even if the domain was making progress, resulting in far
2004 * lower overall wait times. To make sure that your calling routine
2005 * works with new and old implementations of the function, pass enough
2006 * time for the guest to reach its target as an argument.
2007 */
2008 int libxl_wait_for_memory_target(libxl_ctx *ctx, uint32_t domid, int wait_secs);
2009
2010 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040800
2011 #define libxl_get_memory_target libxl_get_memory_target_0x040700
2012 #define libxl_domain_need_memory libxl_domain_need_memory_0x040700
2013 #define libxl_get_free_memory libxl_get_free_memory_0x040700
2014 #elif defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
2015 #define libxl_domain_need_memory libxl_domain_need_memory_0x041200
2016 #endif
2017
2018 int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass);
2019
2020 /*
2021 * If notify_fd is not -1, xenconsole will write 0x00 to it to nofity
2022 * the caller that it has connected to the guest console.
2023 */
2024 int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num,
2025 libxl_console_type type, int notify_fd,
2026 char* escape_character);
2027 /* libxl_primary_console_exec finds the domid and console number
2028 * corresponding to the primary console of the given vm, then calls
2029 * libxl_console_exec with the right arguments (domid might be different
2030 * if the guest is using stubdoms).
2031 * This function can be called after creating the device model, in
2032 * case of HVM guests, and before libxl_run_bootloader in case of PV
2033 * guests using pygrub.
2034 * If notify_fd is not -1, xenconsole will write 0x00 to it to nofity
2035 * the caller that it has connected to the guest console.
2036 * If escape_character is not NULL, the provided value is used to exit
2037 * the guest console.
2038 */
2039 int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm,
2040 int notify_fd,
2041 char* escape_character);
2042
2043 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040800
2044
libxl_console_exec_0x040700(libxl_ctx * ctx,uint32_t domid,int cons_num,libxl_console_type type)2045 static inline int libxl_console_exec_0x040700(libxl_ctx *ctx,
2046 uint32_t domid, int cons_num,
2047 libxl_console_type type)
2048 {
2049 return libxl_console_exec(ctx, domid, cons_num, type, -1, NULL);
2050 }
2051 #define libxl_console_exec libxl_console_exec_0x040700
2052
libxl_primary_console_exec_0x040700(libxl_ctx * ctx,uint32_t domid_vm)2053 static inline int libxl_primary_console_exec_0x040700(libxl_ctx *ctx,
2054 uint32_t domid_vm)
2055 {
2056 return libxl_primary_console_exec(ctx, domid_vm, -1, NULL);
2057 }
2058 #define libxl_primary_console_exec libxl_primary_console_exec_0x040700
2059
2060 #elif defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041800
2061
libxl_console_exec_0x041700(libxl_ctx * ctx,uint32_t domid,int cons_num,libxl_console_type type,int notify_fd)2062 static inline int libxl_console_exec_0x041700(libxl_ctx *ctx, uint32_t domid,
2063 int cons_num,
2064 libxl_console_type type,
2065 int notify_fd)
2066 {
2067 return libxl_console_exec(ctx, domid, cons_num, type, notify_fd, NULL);
2068 }
2069 #define libxl_console_exec libxl_console_exec_0x041700
2070
libxl_primary_console_exec_0x041700(libxl_ctx * ctx,uint32_t domid_vm,int notify_fd)2071 static inline int libxl_primary_console_exec_0x041700(libxl_ctx *ctx,
2072 uint32_t domid_vm,
2073 int notify_fd)
2074 {
2075 return libxl_primary_console_exec(ctx, domid_vm, notify_fd, NULL);
2076 }
2077 #define libxl_primary_console_exec libxl_primary_console_exec_0x041700
2078
2079 #endif
2080
2081 /* libxl_console_get_tty retrieves the specified domain's console tty path
2082 * and stores it in path. Caller is responsible for freeing the memory.
2083 */
2084 int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num,
2085 libxl_console_type type, char **path);
2086
2087 /* libxl_primary_console_get_tty retrieves the specified domain's primary
2088 * console tty path and stores it in path. Caller is responsible for freeing
2089 * the memory.
2090 */
2091 int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm, char **path);
2092
2093 /* libxl_console_add_xenstore writes the Xenstore entries for a domain's
2094 * primary console based on domid, event channel port and the guest frame
2095 * number of the PV console's ring page.
2096 */
2097 int libxl_console_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend,
2098 unsigned int evtch, unsigned long gfn,
2099 const libxl_asyncop_how *ao_how)
2100 LIBXL_EXTERNAL_CALLERS_ONLY;
2101
2102 /* libxl_device_9pfs_add writes the Xenstore entries for a domain's
2103 * primary 9pfs device based on domid, and device parameters.
2104 * If needed it will start the backend daemon.
2105 */
2106 int libxl_device_9pfs_add(libxl_ctx *ctx, uint32_t domid, libxl_device_p9 *p9,
2107 const libxl_asyncop_how *ao_how)
2108 LIBXL_EXTERNAL_CALLERS_ONLY;
2109
2110 /* May be called with info_r == NULL to check for domain's existence.
2111 * Returns ERROR_DOMAIN_NOTFOUND if domain does not exist (used to return
2112 * ERROR_INVAL for this scenario). */
2113 int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r,
2114 uint32_t domid);
2115
2116 /* These functions each return (on success) an array of elements,
2117 * and the length via the int* out parameter. These arrays and
2118 * their contents come from malloc, and must be freed with the
2119 * corresponding libxl_THING_list_free function.
2120 */
2121 libxl_dominfo * libxl_list_domain(libxl_ctx*, int *nb_domain_out);
2122 void libxl_dominfo_list_free(libxl_dominfo *list, int nb_domain);
2123
2124 libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out);
2125 void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool);
2126
2127 libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm_out);
2128 void libxl_vminfo_list_free(libxl_vminfo *list, int nb_vm);
2129
2130 #define LIBXL_CPUTOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
2131 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out);
2132 void libxl_cputopology_list_free(libxl_cputopology *, int nb_cpu);
2133
2134 #define LIBXL_PCITOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
2135 libxl_pcitopology *libxl_get_pci_topology(libxl_ctx *ctx, int *num_devs);
2136 void libxl_pcitopology_list_free(libxl_pcitopology *, int num_devs);
2137
2138 #define LIBXL_NUMAINFO_INVALID_ENTRY (~(uint32_t)0)
2139 libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr);
2140 void libxl_numainfo_list_free(libxl_numainfo *, int nr);
2141
2142 libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
2143 int *nb_vcpu, int *nr_cpus_out);
2144 void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int nr_vcpus);
2145
2146 /*
2147 * Devices
2148 * =======
2149 *
2150 * Each device is represented by a libxl_device_<TYPE> data structure
2151 * which is defined via the IDL. In addition some devices have an
2152 * additional data type libxl_device_<TYPE>_getinfo which contains
2153 * further runtime information about the device.
2154 *
2155 * In addition to the general methods available for libxl types (see
2156 * "libxl types" above) a common set of methods are available for each
2157 * device type. These are described below.
2158 *
2159 * Querying
2160 * --------
2161 *
2162 * libxl_device_<type>_list(ctx, domid, nr):
2163 *
2164 * Returns an array of libxl_device_<type> length nr representing
2165 * the devices attached to the specified domain.
2166 *
2167 * libxl_device_<type>_getinfo(ctx, domid, device, info):
2168 *
2169 * Initialises info with details of the given device which must be
2170 * attached to the specified domain.
2171 *
2172 * Creation / Control
2173 * ------------------
2174 *
2175 * libxl_device_<type>_add(ctx, domid, device):
2176 *
2177 * Adds the given device to the specified domain. This can be called
2178 * while the guest is running (hotplug) or before boot (coldplug).
2179 *
2180 * This function only sets up the device but does not wait for the
2181 * domain to connect to the device and therefore cannot block on the
2182 * guest.
2183 *
2184 * device is an in/out parameter: fields left unspecified when the
2185 * structure is passed in are filled in with appropriate values for
2186 * the device created.
2187 *
2188 * libxl_device_<type>_destroy(ctx, domid, device):
2189 *
2190 * Removes the given device from the specified domain without guest
2191 * co-operation. It is guest specific what affect this will have on
2192 * a running guest.
2193 *
2194 * This function does not interact with the guest and therefore
2195 * cannot block on the guest.
2196 *
2197 * libxl_device_<type>_remove(ctx, domid, device):
2198 *
2199 * Removes the given device from the specified domain by performing
2200 * an orderly unplug with guest co-operation. This requires that the
2201 * guest is running.
2202 *
2203 * This method is currently synchronous and therefore can block
2204 * while interacting with the guest. There is a time-out of 10s on
2205 * this interaction after which libxl_device_<type>_destroy()
2206 * semantics apply.
2207 *
2208 * libxl_device_<type>_safe_remove(ctx, domid, device):
2209 *
2210 * This has the same semantics as libxl_device_<type>_remove() but,
2211 * in the event of hitting the 10s time-out, this function will fail.
2212 *
2213 * Controllers
2214 * -----------
2215 *
2216 * Most devices are treated individually. Some classes of device,
2217 * however, like USB or SCSI, inherently have the need to have a
2218 * hierarchy of different levels, with lower-level devices "attached"
2219 * to higher-level ones. USB for instance has "controllers" at the
2220 * top, which have buses, on which are devices, which consist of
2221 * multiple interfaces. SCSI has "hosts" at the top, then buses,
2222 * targets, and LUNs.
2223 *
2224 * In that case, for each <class>, there will be a set of functions
2225 * and types for each <level>. For example, for <class>=usb, there
2226 * may be <levels> ctrl (controller) and dev (device), with ctrl being
2227 * level 0.
2228 *
2229 * libxl_device_<class><level0>_<function> will act more or
2230 * less like top-level non-bus devices: they will either create or
2231 * accept a libxl_devid which will be unique within the
2232 * <class><level0> libxl_devid namespace.
2233 *
2234 * Lower-level devices must have a unique way to be identified. One
2235 * way to do this would be to name it via the name of the next level
2236 * up plus an index; for instance, <ctrl devid, port number>. Another
2237 * way would be to have another devid namespace for that level. This
2238 * identifier will be used for queries and removals.
2239 *
2240 * Lower-level devices will include in their
2241 * libxl_device_<class><level> struct a field referring to the unique
2242 * index of the level above. For instance, libxl_device_usbdev might
2243 * contain the controller devid.
2244 *
2245 * In the case where there are multiple different ways to implement a
2246 * given device -- for instance, one which is fully PV and one which
2247 * uses an emulator -- the controller will contain a field which
2248 * specifies what type of implementation is used. The implementations
2249 * of individual devices will be known by the controller to which they
2250 * are attached.
2251 *
2252 * If libxl_device_<class><level>_add receives an empty reference to
2253 * the level above, it may return an error. Or it may (but is not
2254 * required to) automatically choose a suitable device in the level
2255 * above to which to attach the new device at this level. It may also
2256 * (but is not required to) automatically create a new device at the
2257 * level above if no suitable devices exist. Each class should
2258 * document its behavior.
2259 *
2260 * libxl_device_<class><level>_list will list all devices of <class>
2261 * at <level> in the domain. For example, libxl_device_usbctrl_list
2262 * will list all usb controllers; libxl_class_usbdev_list will list
2263 * all usb devices across all controllers.
2264 *
2265 * For each class, the domain config file will contain a single list
2266 * for each level. libxl will first iterate through the list of
2267 * top-level devices, then iterate through each level down in turn,
2268 * adding devices to devices in the level above. For instance, there
2269 * will be one list for all usb controllers, and one list for all usb
2270 * devices.
2271 *
2272 * If libxl_device_<class><level>_add automatically creates
2273 * higher-level devices as necessary, then it is permissible for the
2274 * higher-level lists to be empty and the device list to have devices
2275 * with the field containing a reference to the higher level device
2276 * uninitialized.
2277 */
2278
2279 /* Disks */
2280 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
2281 libxl_device_disk *disk,
2282 const libxl_asyncop_how *ao_how)
2283 LIBXL_EXTERNAL_CALLERS_ONLY;
2284 int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
2285 libxl_device_disk *disk,
2286 const libxl_asyncop_how *ao_how)
2287 LIBXL_EXTERNAL_CALLERS_ONLY;
2288 int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid,
2289 libxl_device_disk *disk,
2290 const libxl_asyncop_how *ao_how)
2291 LIBXL_EXTERNAL_CALLERS_ONLY;
2292 int libxl_device_disk_safe_remove(libxl_ctx *ctx, uint32_t domid,
2293 libxl_device_disk *disk,
2294 const libxl_asyncop_how *ao_how)
2295 LIBXL_EXTERNAL_CALLERS_ONLY;
2296
2297 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx,
2298 uint32_t domid, int *num)
2299 LIBXL_EXTERNAL_CALLERS_ONLY;
2300 void libxl_device_disk_list_free(libxl_device_disk* list, int num)
2301 LIBXL_EXTERNAL_CALLERS_ONLY;
2302 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
2303 const libxl_device_disk *disk, libxl_diskinfo *diskinfo)
2304 LIBXL_EXTERNAL_CALLERS_ONLY;
2305
2306 /*
2307 * Insert a CD-ROM device. A device corresponding to disk must already
2308 * be attached to the guest.
2309 */
2310 int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
2311 const libxl_asyncop_how *ao_how)
2312 LIBXL_EXTERNAL_CALLERS_ONLY;
2313
2314 /*
2315 * USB
2316 *
2317 * For each device removed or added, one of these protocols is available:
2318 * - PV (i.e., PVUSB)
2319 * - DEVICEMODEL (i.e, qemu)
2320 *
2321 * PV is available for either PV or HVM domains. DEVICEMODEL is only
2322 * available for HVM domains. The caller can additionally specify
2323 * "AUTO", in which case the library will try to determine the best
2324 * protocol automatically.
2325 *
2326 * At the moment, the only protocol implemented is PV.
2327 *
2328 * One can add/remove USB controllers to/from guest, and attach/detach USB
2329 * devices to/from USB controllers.
2330 *
2331 * To add USB controllers and USB devices, one can adding USB controllers
2332 * first and then attaching USB devices to some USB controller, or adding
2333 * USB devices to guest directly, it will automatically create a USB
2334 * controller for USB devices to attach.
2335 *
2336 * To remove USB controllers or USB devices, one can remove USB devices
2337 * under USB controller one by one and then remove USB controller, or
2338 * remove USB controller directly, it will remove all USB devices under
2339 * it automatically.
2340 *
2341 */
2342 /* USB Controllers*/
2343 int libxl_device_usbctrl_add(libxl_ctx *ctx, uint32_t domid,
2344 libxl_device_usbctrl *usbctrl,
2345 const libxl_asyncop_how *ao_how)
2346 LIBXL_EXTERNAL_CALLERS_ONLY;
2347
2348 int libxl_device_usbctrl_remove(libxl_ctx *ctx, uint32_t domid,
2349 libxl_device_usbctrl *usbctrl,
2350 const libxl_asyncop_how *ao_how)
2351 LIBXL_EXTERNAL_CALLERS_ONLY;
2352
2353 int libxl_device_usbctrl_destroy(libxl_ctx *ctx, uint32_t domid,
2354 libxl_device_usbctrl *usbctrl,
2355 const libxl_asyncop_how *ao_how)
2356 LIBXL_EXTERNAL_CALLERS_ONLY;
2357
2358 libxl_device_usbctrl *libxl_device_usbctrl_list(libxl_ctx *ctx,
2359 uint32_t domid, int *num);
2360
2361 void libxl_device_usbctrl_list_free(libxl_device_usbctrl *list, int nr);
2362
2363
2364 int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid,
2365 const libxl_device_usbctrl *usbctrl,
2366 libxl_usbctrlinfo *usbctrlinfo);
2367
2368 /* USB Devices */
2369
2370 int libxl_device_usbdev_add(libxl_ctx *ctx, uint32_t domid,
2371 libxl_device_usbdev *usbdev,
2372 const libxl_asyncop_how *ao_how)
2373 LIBXL_EXTERNAL_CALLERS_ONLY;
2374
2375 int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid,
2376 libxl_device_usbdev *usbdev,
2377 const libxl_asyncop_how *ao_how)
2378 LIBXL_EXTERNAL_CALLERS_ONLY;
2379
2380 libxl_device_usbdev *
2381 libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num);
2382
2383 void libxl_device_usbdev_list_free(libxl_device_usbdev *list, int nr);
2384
2385 /* Network Interfaces */
2386 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic,
2387 const libxl_asyncop_how *ao_how)
2388 LIBXL_EXTERNAL_CALLERS_ONLY;
2389 int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
2390 libxl_device_nic *nic,
2391 const libxl_asyncop_how *ao_how)
2392 LIBXL_EXTERNAL_CALLERS_ONLY;
2393 int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid,
2394 libxl_device_nic *nic,
2395 const libxl_asyncop_how *ao_how)
2396 LIBXL_EXTERNAL_CALLERS_ONLY;
2397
2398 libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx,
2399 uint32_t domid, int *num)
2400 LIBXL_EXTERNAL_CALLERS_ONLY;
2401 void libxl_device_nic_list_free(libxl_device_nic* list, int num)
2402 LIBXL_EXTERNAL_CALLERS_ONLY;
2403 int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
2404 const libxl_device_nic *nic, libxl_nicinfo *nicinfo)
2405 LIBXL_EXTERNAL_CALLERS_ONLY;
2406
2407 /*
2408 * Virtual Channels
2409 * Channels manifest as consoles with names, see docs/misc/channels.txt
2410 */
2411 libxl_device_channel *libxl_device_channel_list(libxl_ctx *ctx,
2412 uint32_t domid,
2413 int *num);
2414 int libxl_device_channel_getinfo(libxl_ctx *ctx, uint32_t domid,
2415 const libxl_device_channel *channel,
2416 libxl_channelinfo *channelinfo);
2417
2418 /* Virtual TPMs */
2419 int libxl_device_vtpm_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vtpm *vtpm,
2420 const libxl_asyncop_how *ao_how)
2421 LIBXL_EXTERNAL_CALLERS_ONLY;
2422 int libxl_device_vtpm_remove(libxl_ctx *ctx, uint32_t domid,
2423 libxl_device_vtpm *vtpm,
2424 const libxl_asyncop_how *ao_how)
2425 LIBXL_EXTERNAL_CALLERS_ONLY;
2426 int libxl_device_vtpm_destroy(libxl_ctx *ctx, uint32_t domid,
2427 libxl_device_vtpm *vtpm,
2428 const libxl_asyncop_how *ao_how)
2429 LIBXL_EXTERNAL_CALLERS_ONLY;
2430
2431 libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx,
2432 uint32_t domid, int *num)
2433 LIBXL_EXTERNAL_CALLERS_ONLY;
2434 void libxl_device_vtpm_list_free(libxl_device_vtpm*, int num)
2435 LIBXL_EXTERNAL_CALLERS_ONLY;
2436 int libxl_device_vtpm_getinfo(libxl_ctx *ctx, uint32_t domid,
2437 const libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo)
2438 LIBXL_EXTERNAL_CALLERS_ONLY;
2439
2440 /* Virtual displays */
2441 int libxl_device_vdispl_add(libxl_ctx *ctx, uint32_t domid,
2442 libxl_device_vdispl *displ,
2443 const libxl_asyncop_how *ao_how)
2444 LIBXL_EXTERNAL_CALLERS_ONLY;
2445 int libxl_device_vdispl_remove(libxl_ctx *ctx, uint32_t domid,
2446 libxl_device_vdispl *vdispl,
2447 const libxl_asyncop_how *ao_how)
2448 LIBXL_EXTERNAL_CALLERS_ONLY;
2449 int libxl_device_vdispl_destroy(libxl_ctx *ctx, uint32_t domid,
2450 libxl_device_vdispl *vdispl,
2451 const libxl_asyncop_how *ao_how)
2452 LIBXL_EXTERNAL_CALLERS_ONLY;
2453
2454 libxl_device_vdispl *libxl_device_vdispl_list(libxl_ctx *ctx,
2455 uint32_t domid, int *num)
2456 LIBXL_EXTERNAL_CALLERS_ONLY;
2457 void libxl_device_vdispl_list_free(libxl_device_vdispl* list, int num)
2458 LIBXL_EXTERNAL_CALLERS_ONLY;
2459 int libxl_device_vdispl_getinfo(libxl_ctx *ctx, uint32_t domid,
2460 const libxl_device_vdispl *vdispl,
2461 libxl_vdisplinfo *vdisplinfo)
2462 LIBXL_EXTERNAL_CALLERS_ONLY;
2463
2464 /* Virtual sounds */
2465 int libxl_device_vsnd_add(libxl_ctx *ctx, uint32_t domid,
2466 libxl_device_vsnd *vsnd,
2467 const libxl_asyncop_how *ao_how)
2468 LIBXL_EXTERNAL_CALLERS_ONLY;
2469 int libxl_device_vsnd_remove(libxl_ctx *ctx, uint32_t domid,
2470 libxl_device_vsnd *vsnd,
2471 const libxl_asyncop_how *ao_how)
2472 LIBXL_EXTERNAL_CALLERS_ONLY;
2473 int libxl_device_vsnd_destroy(libxl_ctx *ctx, uint32_t domid,
2474 libxl_device_vsnd *vsnd,
2475 const libxl_asyncop_how *ao_how)
2476 LIBXL_EXTERNAL_CALLERS_ONLY;
2477
2478 libxl_device_vsnd *libxl_device_vsnd_list(libxl_ctx *ctx,
2479 uint32_t domid, int *num)
2480 LIBXL_EXTERNAL_CALLERS_ONLY;
2481 void libxl_device_vsnd_list_free(libxl_device_vsnd* list, int num)
2482 LIBXL_EXTERNAL_CALLERS_ONLY;
2483 int libxl_device_vsnd_getinfo(libxl_ctx *ctx, uint32_t domid,
2484 const libxl_device_vsnd *vsnd,
2485 libxl_vsndinfo *vsndlinfo)
2486 LIBXL_EXTERNAL_CALLERS_ONLY;
2487
2488 /* Keyboard */
2489 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
2490 const libxl_asyncop_how *ao_how)
2491 LIBXL_EXTERNAL_CALLERS_ONLY;
2492 int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid,
2493 libxl_device_vkb *vkb,
2494 const libxl_asyncop_how *ao_how)
2495 LIBXL_EXTERNAL_CALLERS_ONLY;
2496 int libxl_device_vkb_destroy(libxl_ctx *ctx, uint32_t domid,
2497 libxl_device_vkb *vkb,
2498 const libxl_asyncop_how *ao_how)
2499 LIBXL_EXTERNAL_CALLERS_ONLY;
2500
2501 libxl_device_vkb *libxl_device_vkb_list(libxl_ctx *ctx,
2502 uint32_t domid, int *num)
2503 LIBXL_EXTERNAL_CALLERS_ONLY;
2504 void libxl_device_vkb_list_free(libxl_device_vkb* list, int num)
2505 LIBXL_EXTERNAL_CALLERS_ONLY;
2506 int libxl_device_vkb_getinfo(libxl_ctx *ctx, uint32_t domid,
2507 const libxl_device_vkb *vkb,
2508 libxl_vkbinfo *vkbinfo)
2509 LIBXL_EXTERNAL_CALLERS_ONLY;
2510
2511 /* Framebuffer */
2512 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
2513 const libxl_asyncop_how *ao_how)
2514 LIBXL_EXTERNAL_CALLERS_ONLY;
2515 int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid,
2516 libxl_device_vfb *vfb,
2517 const libxl_asyncop_how *ao_how)
2518 LIBXL_EXTERNAL_CALLERS_ONLY;
2519 int libxl_device_vfb_destroy(libxl_ctx *ctx, uint32_t domid,
2520 libxl_device_vfb *vfb,
2521 const libxl_asyncop_how *ao_how)
2522 LIBXL_EXTERNAL_CALLERS_ONLY;
2523
2524 /* 9pfs */
2525 int libxl_device_p9_remove(libxl_ctx *ctx, uint32_t domid,
2526 libxl_device_p9 *p9,
2527 const libxl_asyncop_how *ao_how)
2528 LIBXL_EXTERNAL_CALLERS_ONLY;
2529 int libxl_device_p9_destroy(libxl_ctx *ctx, uint32_t domid,
2530 libxl_device_p9 *p9,
2531 const libxl_asyncop_how *ao_how)
2532 LIBXL_EXTERNAL_CALLERS_ONLY;
2533
2534 /* pvcalls interface */
2535 int libxl_device_pvcallsif_remove(libxl_ctx *ctx, uint32_t domid,
2536 libxl_device_pvcallsif *pvcallsif,
2537 const libxl_asyncop_how *ao_how)
2538 LIBXL_EXTERNAL_CALLERS_ONLY;
2539 int libxl_device_pvcallsif_destroy(libxl_ctx *ctx, uint32_t domid,
2540 libxl_device_pvcallsif *pvcallsif,
2541 const libxl_asyncop_how *ao_how)
2542 LIBXL_EXTERNAL_CALLERS_ONLY;
2543
2544 /* PCI Passthrough */
2545 int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid,
2546 libxl_device_pci *pci,
2547 const libxl_asyncop_how *ao_how)
2548 LIBXL_EXTERNAL_CALLERS_ONLY;
2549 int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid,
2550 libxl_device_pci *pci,
2551 const libxl_asyncop_how *ao_how)
2552 LIBXL_EXTERNAL_CALLERS_ONLY;
2553 int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid,
2554 libxl_device_pci *pci,
2555 const libxl_asyncop_how *ao_how)
2556 LIBXL_EXTERNAL_CALLERS_ONLY;
2557
2558 libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid,
2559 int *num);
2560 void libxl_device_pci_list_free(libxl_device_pci* list, int num);
2561
2562 #if defined(__arm__) || defined(__aarch64__)
2563 /* Values should keep consistent with the op from XEN_SYSCTL_dt_overlay */
2564 #define LIBXL_DT_OVERLAY_ADD 1
2565 #define LIBXL_DT_OVERLAY_REMOVE 2
2566 int libxl_dt_overlay(libxl_ctx *ctx, void *overlay,
2567 uint32_t overlay_size, uint8_t overlay_op);
2568
2569 /* Values should keep consistent with the op from XEN_DOMCTL_dt_overlay */
2570 #define LIBXL_DT_OVERLAY_DOMAIN_ATTACH 1
2571 int libxl_dt_overlay_domain(libxl_ctx *ctx, uint32_t domain_id,
2572 void *overlay_dt, uint32_t overlay_dt_size,
2573 uint8_t overlay_op);
2574 #endif
2575
2576 /*
2577 * Turns the current process into a backend device service daemon
2578 * for a driver domain.
2579 *
2580 * From a libxl API point of view, this starts a long-running
2581 * operation. That operation consists of "being a driver domain"
2582 * and never completes.
2583 *
2584 * Attempting to abort this operation is not advisable; proper
2585 * shutdown of the driver domain task is not supported.
2586 */
2587 int libxl_device_events_handler(libxl_ctx *ctx,
2588 const libxl_asyncop_how *ao_how)
2589 LIBXL_EXTERNAL_CALLERS_ONLY;
2590
2591 /*
2592 * Functions related to making devices assignable -- that is, bound to
2593 * the pciback driver, ready to be given to a guest via
2594 * libxl_pci_device_add.
2595 *
2596 * - ..._add() will unbind the device from its current driver (if
2597 * already bound) and re-bind it to pciback; at that point it will be
2598 * ready to be assigned to a VM. If rebind is set, it will store the
2599 * path to the old driver in xenstore so that it can be handed back to
2600 * dom0 on restore.
2601 *
2602 * - ..._remove() will unbind the device from pciback, and if
2603 * rebind is non-zero, attempt to assign it back to the driver
2604 * from whence it came.
2605 *
2606 * - ..._list() will return a list of the PCI devices available to be
2607 * assigned.
2608 *
2609 * add and remove are idempotent: if the device in question is already
2610 * added or is not bound, the functions will emit a warning but return
2611 * SUCCESS.
2612 */
2613 int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci, int rebind);
2614 int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *pci, int rebind);
2615 libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num);
2616 void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num);
2617
2618 /* CPUID handling */
2619 int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str);
2620 int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,
2621 const char* str);
2622 #if LIBXL_API_VERSION < 0x041400
2623 /*
2624 * Dropped from the API in Xen 4.14. At the time of writing, these functions
2625 * don't appear to ever have had external callers.
2626 *
2627 * These have always been used internally during domain construction, and
2628 * can't easily be used externally because of their implicit parameters in
2629 * other pieces of global state.
2630 *
2631 * Furthermore, an API user can't usefully determine whether they get
2632 * libxl_cpuid (the real implementation) or libxl_nocpuid (no-op stubs).
2633 *
2634 * The internal behaviour of these functions also needs to change. Therefore
2635 * for simplicitly, provide the no-op stubs. Yes technically this is an API
2636 * change in some cases for existing software, but there is 0 of that in
2637 * practice.
2638 */
libxl_cpuid_apply_policy(libxl_ctx * ctx,uint32_t domid)2639 static inline void libxl_cpuid_apply_policy(libxl_ctx *ctx __attribute__((unused)),
2640 uint32_t domid __attribute__((unused)))
2641 {}
libxl_cpuid_set(libxl_ctx * ctx,uint32_t domid,libxl_cpuid_policy_list cpuid)2642 static inline void libxl_cpuid_set(libxl_ctx *ctx __attribute__((unused)),
2643 uint32_t domid __attribute__((unused)),
2644 libxl_cpuid_policy_list cpuid __attribute__((unused)))
2645 {}
2646 #endif
2647
2648 /*
2649 * Functions for allowing users of libxl to store private data
2650 * relating to a domain. The data is an opaque sequence of bytes and
2651 * is not interpreted or used by libxl.
2652 *
2653 * Data is indexed by the userdata userid, which is a short printable
2654 * ASCII string. The following list is a registry of userdata userids
2655 * (the registry may be updated by posting a patch to xen-devel):
2656 *
2657 * userid Data contents
2658 * "xl" domain config file in xl format, Unix line endings
2659 * "libvirt-xml" domain config file in libvirt XML format. See
2660 * http://libvirt.org/formatdomain.html
2661 * "domain-userdata-lock" lock file to protect domain userdata in libxl.
2662 * It's a per-domain lock. Applications should
2663 * not touch this file.
2664 * "libxl-json" libxl_domain_config object in JSON format, generated
2665 * by libxl. Applications should not access this file
2666 * directly. This file is protected by domain-userdata-lock
2667 * for against Read-Modify-Write operation and domain
2668 * destruction.
2669 *
2670 * libxl does not enforce the registration of userdata userids or the
2671 * semantics of the data. For specifications of the data formats
2672 * see the code or documentation for the libxl caller in question.
2673 */
2674 int libxl_userdata_store(libxl_ctx *ctx, uint32_t domid,
2675 const char *userdata_userid,
2676 const uint8_t *data, int datalen)
2677 LIBXL_EXTERNAL_CALLERS_ONLY;
2678 /* If datalen==0, data is not used and the user data for
2679 * that domain and userdata_userid is deleted. */
2680 int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,
2681 const char *userdata_userid,
2682 uint8_t **data_r, int *datalen_r)
2683 LIBXL_EXTERNAL_CALLERS_ONLY;
2684 /* On successful return, *data_r is from malloc.
2685 * If there is no data for that domain and userdata_userid,
2686 * *data_r and *datalen_r will be set to 0.
2687 * data_r and datalen_r may be 0.
2688 * On error return, *data_r and *datalen_r are undefined.
2689 */
2690 int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
2691 const char *userdata_userid);
2692
2693
2694 int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
2695 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
2696 const libxl_bitmap *cpumap_hard,
2697 const libxl_bitmap *cpumap_soft);
2698 int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid,
2699 uint32_t vcpuid,
2700 const libxl_bitmap *cpumap_hard,
2701 const libxl_bitmap *cpumap_soft);
2702 int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
2703 unsigned int max_vcpus,
2704 const libxl_bitmap *cpumap_hard,
2705 const libxl_bitmap *cpumap_soft);
2706
2707 #if defined (LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040500
2708
2709 #define libxl_set_vcpuaffinity(ctx, domid, vcpuid, map) \
2710 libxl_set_vcpuaffinity((ctx), (domid), (vcpuid), (map), NULL)
2711 #define libxl_set_vcpuaffinity_all(ctx, domid, max_vcpus, map) \
2712 libxl_set_vcpuaffinity_all((ctx), (domid), (max_vcpus), (map), NULL)
2713
2714 #endif
2715
2716 int libxl_domain_set_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
2717 libxl_bitmap *nodemap);
2718 int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
2719 libxl_bitmap *nodemap);
2720 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid,
2721 libxl_bitmap *cpumap,
2722 const libxl_asyncop_how *ao_how)
2723 LIBXL_EXTERNAL_CALLERS_ONLY;
2724 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
libxl_set_vcpuonline_0x041200(libxl_ctx * ctx,uint32_t domid,libxl_bitmap * cpumap)2725 static inline int libxl_set_vcpuonline_0x041200(libxl_ctx *ctx,
2726 uint32_t domid,
2727 libxl_bitmap *cpumap)
2728 {
2729 return libxl_set_vcpuonline(ctx, domid, cpumap, NULL);
2730 }
2731 #define libxl_set_vcpuonline libxl_set_vcpuonline_0x041200
2732 #endif
2733
2734 /* A return value less than 0 should be interpreted as a libxl_error, while a
2735 * return value greater than or equal to 0 should be interpreted as a
2736 * libxl_scheduler. */
2737 int libxl_get_scheduler(libxl_ctx *ctx);
2738
2739 /* Per-scheduler parameters */
2740 int libxl_sched_credit_params_get(libxl_ctx *ctx, uint32_t poolid,
2741 libxl_sched_credit_params *scinfo);
2742 int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
2743 libxl_sched_credit_params *scinfo);
2744 int libxl_sched_credit2_params_get(libxl_ctx *ctx, uint32_t poolid,
2745 libxl_sched_credit2_params *scinfo);
2746 int libxl_sched_credit2_params_set(libxl_ctx *ctx, uint32_t poolid,
2747 libxl_sched_credit2_params *scinfo);
2748
2749 /* Scheduler Per-domain parameters */
2750
2751 #define LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT -1
2752 #define LIBXL_DOMAIN_SCHED_PARAM_CAP_DEFAULT -1
2753 #define LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT -1
2754 #define LIBXL_DOMAIN_SCHED_PARAM_SLICE_DEFAULT -1
2755 #define LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT -1
2756 #define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1
2757 #define LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT -1
2758
2759 /* Per-VCPU parameters */
2760 #define LIBXL_SCHED_PARAM_VCPU_INDEX_DEFAULT -1
2761
2762 /* Get the per-domain scheduling parameters.
2763 * For schedulers that support per-vcpu settings (e.g., RTDS),
2764 * calling *_domain_get functions will get default scheduling
2765 * parameters.
2766 */
2767 int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
2768 libxl_domain_sched_params *params);
2769
2770 /* Set the per-domain scheduling parameters.
2771 * For schedulers that support per-vcpu settings (e.g., RTDS),
2772 * calling *_domain_set functions will set all vcpus with the same
2773 * scheduling parameters.
2774 */
2775 int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
2776 const libxl_domain_sched_params *params);
2777
2778 /* Get the per-vcpu scheduling parameters */
2779 int libxl_vcpu_sched_params_get(libxl_ctx *ctx, uint32_t domid,
2780 libxl_vcpu_sched_params *params);
2781
2782 /* Get the per-vcpu scheduling parameters of all vcpus of a domain */
2783 int libxl_vcpu_sched_params_get_all(libxl_ctx *ctx, uint32_t domid,
2784 libxl_vcpu_sched_params *params);
2785
2786 /* Set the per-vcpu scheduling parameters */
2787 int libxl_vcpu_sched_params_set(libxl_ctx *ctx, uint32_t domid,
2788 const libxl_vcpu_sched_params *params);
2789
2790 /* Set the per-vcpu scheduling parameters of all vcpus of a domain */
2791 int libxl_vcpu_sched_params_set_all(libxl_ctx *ctx, uint32_t domid,
2792 const libxl_vcpu_sched_params *params);
2793
2794 int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
2795 libxl_trigger trigger, uint32_t vcpuid,
2796 const libxl_asyncop_how *ao_how)
2797 LIBXL_EXTERNAL_CALLERS_ONLY;
2798 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
libxl_send_trigger_0x041200(libxl_ctx * ctx,uint32_t domid,libxl_trigger trigger,uint32_t vcpuid)2799 static inline int libxl_send_trigger_0x041200(
2800 libxl_ctx *ctx, uint32_t domid, libxl_trigger trigger, uint32_t vcpuid)
2801 {
2802 return libxl_send_trigger(ctx, domid, trigger, vcpuid, NULL);
2803 }
2804 #define libxl_send_trigger libxl_send_trigger_0x041200
2805 #endif
2806 int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
2807 int libxl_send_debug_keys(libxl_ctx *ctx, char *keys);
2808 int libxl_set_parameters(libxl_ctx *ctx, char *params);
2809
2810 typedef struct libxl__xen_console_reader libxl_xen_console_reader;
2811
2812 libxl_xen_console_reader *
2813 libxl_xen_console_read_start(libxl_ctx *ctx, int clear);
2814 int libxl_xen_console_read_line(libxl_ctx *ctx,
2815 libxl_xen_console_reader *cr,
2816 char **line_r);
2817 void libxl_xen_console_read_finish(libxl_ctx *ctx,
2818 libxl_xen_console_reader *cr);
2819
2820 uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid);
2821
2822 char *libxl_tmem_list(libxl_ctx *ctx, uint32_t domid, int use_long);
2823 int libxl_tmem_freeze(libxl_ctx *ctx, uint32_t domid);
2824 int libxl_tmem_thaw(libxl_ctx *ctx, uint32_t domid);
2825 int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name,
2826 uint32_t set);
2827 int libxl_tmem_shared_auth(libxl_ctx *ctx, uint32_t domid, char* uuid,
2828 int auth);
2829 int libxl_tmem_freeable(libxl_ctx *ctx);
2830
2831 int libxl_get_freecpus(libxl_ctx *ctx, libxl_bitmap *cpumap);
2832
2833 /*
2834 * Set poolid to LIBXL_CPUOOL_POOLID_ANY to have Xen choose a
2835 * free poolid for you.
2836 */
2837 #define LIBXL_CPUPOOL_POOLID_ANY 0xFFFFFFFF
2838 int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
2839 libxl_scheduler sched,
2840 libxl_bitmap cpumap, libxl_uuid *uuid,
2841 uint32_t *poolid);
2842 int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid);
2843 int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid);
2844 int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu);
2845 int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
2846 int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid,
2847 const libxl_bitmap *cpumap);
2848 int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu);
2849 int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
2850 int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid,
2851 const libxl_bitmap *cpumap);
2852 int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid);
2853 int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid);
2854
2855 int libxl_domid_valid_guest(uint32_t domid);
2856
2857 int libxl_flask_context_to_sid(libxl_ctx *ctx, char *buf, size_t len,
2858 uint32_t *ssidref);
2859 int libxl_flask_sid_to_context(libxl_ctx *ctx, uint32_t ssidref, char **buf,
2860 size_t *len);
2861 int libxl_flask_getenforce(libxl_ctx *ctx);
2862 int libxl_flask_setenforce(libxl_ctx *ctx, int mode);
2863 int libxl_flask_loadpolicy(libxl_ctx *ctx, void *policy, uint32_t size);
2864
2865 int libxl_ms_vm_genid_generate(libxl_ctx *ctx, libxl_ms_vm_genid *id);
2866 bool libxl_ms_vm_genid_is_zero(const libxl_ms_vm_genid *id);
2867 void libxl_ms_vm_genid_copy(libxl_ctx *ctx, libxl_ms_vm_genid *dst,
2868 const libxl_ms_vm_genid *src);
2869
2870 #if defined(__i386__) || defined(__x86_64__)
2871 int libxl_psr_cmt_attach(libxl_ctx *ctx, uint32_t domid);
2872 int libxl_psr_cmt_detach(libxl_ctx *ctx, uint32_t domid);
2873 int libxl_psr_cmt_domain_attached(libxl_ctx *ctx, uint32_t domid);
2874 int libxl_psr_cmt_enabled(libxl_ctx *ctx);
2875 int libxl_psr_cmt_get_total_rmid(libxl_ctx *ctx, uint32_t *total_rmid);
2876 int libxl_psr_cmt_get_l3_cache_size(libxl_ctx *ctx,
2877 uint32_t socketid,
2878 uint32_t *l3_cache_size);
2879 int libxl_psr_cmt_get_cache_occupancy(libxl_ctx *ctx,
2880 uint32_t domid,
2881 uint32_t socketid,
2882 uint32_t *l3_cache_occupancy);
2883
2884 int libxl_psr_cmt_type_supported(libxl_ctx *ctx, libxl_psr_cmt_type type);
2885 int libxl_psr_cmt_get_sample(libxl_ctx *ctx,
2886 uint32_t domid,
2887 libxl_psr_cmt_type type,
2888 uint64_t scope,
2889 uint64_t *sample_r,
2890 uint64_t *tsc_r);
2891
2892 /*
2893 * Function to set a domain's cbm. It operates on a single or multiple
2894 * target(s) defined in 'target_map'. The definition of 'target_map' is
2895 * related to 'type':
2896 * 'L3_CBM': 'target_map' specifies all the sockets to be operated on.
2897 */
2898 int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid,
2899 libxl_psr_cbm_type type, libxl_bitmap *target_map,
2900 uint64_t cbm);
2901 /*
2902 * Function to get a domain's cbm. It operates on a single 'target'.
2903 * The definition of 'target' is related to 'type':
2904 * 'L3_CBM': 'target' specifies which socket to be operated on.
2905 */
2906 int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
2907 libxl_psr_cbm_type type, uint32_t target,
2908 uint64_t *cbm_r);
2909
2910 /*
2911 * On success, the function returns an array of elements in 'info',
2912 * and the length in 'nr'.
2913 */
2914 int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
2915 unsigned int *nr, unsigned int lvl);
2916 int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
2917 int *nr);
2918 void libxl_psr_cat_info_list_free(libxl_psr_cat_info *list, int nr);
2919
2920 typedef enum libxl_psr_cbm_type libxl_psr_type;
2921
2922 /*
2923 * Function to set a domain's value. It operates on a single or multiple
2924 * target(s) defined in 'target_map'. 'target_map' specifies all the sockets
2925 * to be operated on.
2926 */
2927 int libxl_psr_set_val(libxl_ctx *ctx, uint32_t domid,
2928 libxl_psr_type type, libxl_bitmap *target_map,
2929 uint64_t val);
2930 /*
2931 * Function to get a domain's cbm. It operates on a single 'target'.
2932 * 'target' specifies which socket to be operated on.
2933 */
2934 int libxl_psr_get_val(libxl_ctx *ctx, uint32_t domid,
2935 libxl_psr_type type, unsigned int target,
2936 uint64_t *val);
2937 /*
2938 * On success, the function returns an array of elements in 'info',
2939 * and the length in 'nr'.
2940 */
2941 int libxl_psr_get_hw_info(libxl_ctx *ctx, libxl_psr_feat_type type,
2942 unsigned int lvl, unsigned int *nr,
2943 libxl_psr_hw_info **info);
2944 void libxl_psr_hw_info_list_free(libxl_psr_hw_info *list, unsigned int nr);
2945 #endif
2946
2947 /* misc */
2948
2949 /* Each of these sets or clears the flag according to whether the
2950 * 2nd parameter is nonzero. On failure, they log, and
2951 * return ERROR_FAIL, but also leave errno valid. */
2952 int libxl_fd_set_cloexec(libxl_ctx *ctx, int fd, int cloexec);
2953 int libxl_fd_set_nonblock(libxl_ctx *ctx, int fd, int nonblock);
2954
2955 /*
2956 * Issue a qmp monitor command to the device model of the specified domain.
2957 * The function returns the output of the command in a new allocated buffer
2958 * via output.
2959 */
2960 int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid,
2961 const char *command_line, char **output,
2962 const libxl_asyncop_how *ao_how)
2963 LIBXL_EXTERNAL_CALLERS_ONLY;
2964 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300
libxl_qemu_monitor_command_0x041200(libxl_ctx * ctx,uint32_t domid,const char * command_line,char ** output)2965 static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx,
2966 uint32_t domid, const char *command_line, char **output)
2967 {
2968 return libxl_qemu_monitor_command(ctx, domid, command_line, output,
2969 NULL);
2970 }
2971 #define libxl_qemu_monitor_command libxl_qemu_monitor_command_0x041200
2972 #endif
2973
2974 #include <libxl_event.h>
2975
2976 /*
2977 * This function is for use only during host initialisation. If it is
2978 * invoked on a host with running domains, or concurrent libxl
2979 * processes then the system may malfuntion.
2980 */
2981 int libxl_clear_domid_history(libxl_ctx *ctx);
2982
2983 #endif /* LIBXL_H */
2984
2985 /*
2986 * Local variables:
2987 * mode: C
2988 * c-basic-offset: 4
2989 * indent-tabs-mode: nil
2990 * End:
2991 */
2992