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_CONSOLE_NOTIFY_FD
71 *
72 * If this is defined, libxl_console_exec and
73 * libxl_primary_console_exe take a notify_fd parameter. That
74 * parameter will be used to notify the caller that the console is connected.
75 */
76 #define LIBXL_HAVE_CONSOLE_NOTIFY_FD 1
77
78 /* LIBXL_HAVE_CONST_COPY_AND_LENGTH_FUNCTIONS
79 *
80 * If this is defined, the copy functions have constified src parameter and the
81 * length functions accept constified parameter.
82 */
83 #define LIBXL_HAVE_CONST_COPY_AND_LENGTH_FUNCTIONS 1
84
85 /* LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONST_B_INFO
86 *
87 * If this is defined, libxl_domain_need_memory no longer modifies
88 * the b_info paseed in.
89 */
90 #define LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONST_B_INFO 1
91
92 /* LIBXL_HAVE_VNUMA
93 *
94 * If this is defined the type libxl_vnode_info exists, and a
95 * field 'vnuma_nodes' is present in libxl_domain_build_info.
96 */
97 #define LIBXL_HAVE_VNUMA 1
98
99 /* LIBXL_HAVE_USERDATA_UNLINK
100 *
101 * If it is defined, libxl has a library function called
102 * libxl_userdata_unlink.
103 */
104 #define LIBXL_HAVE_USERDATA_UNLINK 1
105
106 /* LIBXL_HAVE_CPUPOOL_QUALIFIER_TO_CPUPOOLID
107 *
108 * If this is defined, libxl has a library function called
109 * libxl_cpupool_qualifier_to_cpupoolid, which takes in a CPU pool
110 * qualifier in the form of number or string, then returns the ID of
111 * that CPU pool.
112 */
113 #define LIBXL_HAVE_CPUPOOL_QUALIFIER_TO_CPUPOOLID 1
114
115 /* LIBXL_HAVE_CPUPOOL_ADD_REM_CPUMAP
116 *
117 * If this is defined, libxl has two library functions called
118 * libxl_cpupool_cpuadd_cpumap and libxl_cpupool_cpuremove_cpumap,
119 * which allow to add to or remove from a cpupool all the cpus
120 * specified in a bitmap.
121 */
122 #define LIBXL_HAVE_CPUPOOL_ADD_REM_CPUMAP 1
123
124 /*
125 *
126 * LIBXL_HAVE_BITMAP_AND_OR
127 *
128 * If this is defined, libxl has two library functions, libxl_bitmap_and
129 * and libxl_bitmap_or to compute the logical and and or of two bitmaps
130 */
131 #define LIBXL_HAVE_BITMAP_AND_OR 1
132
133 /*
134 * LIBXL_HAVE_FIRMWARE_PASSTHROUGH indicates the feature for
135 * passing in SMBIOS and ACPI firmware to HVM guests is present
136 * in the library.
137 */
138 #define LIBXL_HAVE_FIRMWARE_PASSTHROUGH 1
139
140 /*
141 * LIBXL_HAVE_DOMAIN_NODEAFFINITY indicates that a 'nodemap' field
142 * (of libxl_bitmap type) is present in libxl_domain_build_info,
143 * containing the node-affinity for the domain.
144 */
145 #define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1
146
147 /*
148 * LIBXL_HAVE_PVUSB indicates functions for plugging in USB devices
149 * through pvusb -- both hotplug and at domain creation time..
150 */
151 #define LIBXL_HAVE_PVUSB 1
152
153 /*
154 * LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE indicates that the
155 * libxl_vendor_device field is present in the hvm sections of
156 * libxl_domain_build_info. This field tells libxl which
157 * flavour of xen-pvdevice to enable in QEMU.
158 */
159 #define LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE 1
160
161 /*
162 * The libxl_domain_build_info has the event_channels field.
163 */
164 #define LIBXL_HAVE_BUILDINFO_EVENT_CHANNELS 1
165
166 /*
167 * libxl_domain_build_info has the u.hvm.ms_vm_genid field.
168 */
169 #define LIBXL_HAVE_BUILDINFO_HVM_MS_VM_GENID 1
170
171 /*
172 * LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY indicates that a 'cpumap_soft'
173 * field (of libxl_bitmap type) is present in libxl_vcpuinfo,
174 * containing the soft affinity of a vcpu.
175 */
176 #define LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY 1
177
178 /*
179 * LIBXL_HAVE_SET_VCPUAFFINITY_FORCE indicates that the
180 * libxl_set_vcpuaffinity_force() library call is available.
181 */
182 #define LIBXL_HAVE_SET_VCPUAFFINITY_FORCE 1
183
184 /*
185 * LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE indicates that a
186 * 'direct_io_safe' field (of boolean type) is present in
187 * libxl_device_disk.
188 */
189 #define LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE 1
190
191 /*
192 * The libxl_device_disk has the discard_enable field.
193 */
194 #define LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE 1
195
196 /*
197 * LIBXL_HAVE_BUILDINFO_IOMEM_START_GFN indicates that it is possible
198 * to specify the start guest frame number used to map a range of I/O
199 * memory machine frame numbers via the 'gfn' field (of type uint64)
200 * of the 'iomem' structure. An array of iomem structures is embedded
201 * in libxl_domain_build_info and used to map the indicated memory
202 * ranges during domain build.
203 */
204 #define LIBXL_HAVE_BUILDINFO_IOMEM_START_GFN 1
205
206 /*
207 * LIBXL_HAVE_SCHED_RTDS indicates that the RTDS real time scheduler
208 * is available. A 'budget' field added in libxl_domain_sched_params.
209 */
210 #define LIBXL_HAVE_SCHED_RTDS 1
211
212 /*
213 * LIBXL_HAVE_SCHED_NULL indicates that the 'null' static scheduler
214 * is available.
215 */
216 #define LIBXL_HAVE_SCHED_NULL 1
217
218 /*
219 * libxl_domain_build_info has u.hvm.viridian_enable and _disable bitmaps
220 * of the specified width.
221 */
222 #define LIBXL_HAVE_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE 1
223 #define LIBXL_BUILDINFO_HVM_VIRIDIAN_ENABLE_DISABLE_WIDTH 64
224
225 /*
226 * libxl_domain_build_info has the u.hvm.mmio_hole_memkb field.
227 */
228 #define LIBXL_HAVE_BUILDINFO_HVM_MMIO_HOLE_MEMKB 1
229
230 /*
231 * libxl_domain_info returns ERROR_DOMAIN_NOTFOUND if the domain
232 * is not present, instead of ERROR_INVAL.
233 */
234 #define LIBXL_HAVE_ERROR_DOMAIN_NOTFOUND 1
235
236 /*
237 * libxl_domain_build_info has device_tree and libxl_device_dtdev
238 * exists. This mean Device Tree passthrough is supported for ARM
239 */
240 #define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1
241
242 /*
243 * libxl_domain_build_info has device_model_user to specify the user to
244 * run the device model with. See docs/misc/qemu-deprivilege.txt.
245 */
246 #define LIBXL_HAVE_DEVICE_MODEL_USER 1
247
248 /*
249 * libxl_vcpu_sched_params is used to store per-vcpu params.
250 */
251 #define LIBXL_HAVE_VCPU_SCHED_PARAMS 1
252
253 /*
254 * LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS indicates RTDS scheduler
255 * now supports per-vcpu settings.
256 */
257 #define LIBXL_HAVE_SCHED_RTDS_VCPU_PARAMS 1
258
259 /*
260 * LIBXL_HAVE_SCHED_RTDS_VCPU_EXTRA indicates RTDS scheduler
261 * now supports per-vcpu extratime settings.
262 */
263 #define LIBXL_HAVE_SCHED_RTDS_VCPU_EXTRA 1
264
265 /*
266 * libxl_domain_build_info has the arm.gic_version field.
267 */
268 #define LIBXL_HAVE_BUILDINFO_ARM_GIC_VERSION 1
269
270 /*
271 * LIBXL_HAVE_SOFT_RESET indicates that libxl supports performing
272 * 'soft reset' for domains and there is 'soft_reset' shutdown reason
273 * in enum libxl_shutdown_reason.
274 */
275 #define LIBXL_HAVE_SOFT_RESET 1
276
277 /*
278 * LIBXL_HAVE_APIC_ASSIST indicates that the 'apic_assist' value
279 * is present in the viridian enlightenment enumeration.
280 */
281 #define LIBXL_HAVE_APIC_ASSIST 1
282
283 /*
284 * LIBXL_HAVE_BUILD_ID means that libxl_version_info has the extra
285 * field for the hypervisor build_id.
286 */
287 #define LIBXL_HAVE_BUILD_ID 1
288
289 /*
290 * LIBXL_HAVE_QEMU_MONITOR_COMMAND indiactes the availability of the
291 * libxl_qemu_monitor_command() function.
292 */
293 #define LIBXL_HAVE_QEMU_MONITOR_COMMAND 1
294
295 /*
296 * LIBXL_HAVE_SCHED_CREDIT2_PARAMS indicates the existance of a
297 * libxl_sched_credit2_params structure, containing Credit2 scheduler
298 * wide parameters (i.e., the ratelimiting value).
299 */
300 #define LIBXL_HAVE_SCHED_CREDIT2_PARAMS 1
301
302 /*
303 * LIBXL_HAVE_VIRIDIAN_CRASH_CTL indicates that the 'crash_ctl' value
304 * is present in the viridian enlightenment enumeration.
305 */
306 #define LIBXL_HAVE_VIRIDIAN_CRASH_CTL 1
307
308 /*
309 * LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE indicates that
310 * libxl_domain_build_info has the u.hvm.acpi_laptop_slate field.
311 */
312 #define LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE 1
313
314 /*
315 * LIBXL_HAVE_P9S indicates that the p9 field in IDL has been changed to p9s
316 */
317 #define LIBXL_HAVE_P9S 1
318
319 /*
320 * LIBXL_HAVE_BUILDINFO_ARM_VUART indicates that the toolstack supports virtual UART
321 * for ARM.
322 */
323 #define LIBXL_HAVE_BUILDINFO_ARM_VUART 1
324
325 /*
326 * LIBXL_HAVE_BUILDINFO_GRANT_LIMITS indicates that libxl_domain_build_info
327 * has the max_grant_frames and max_maptrack_frames fields.
328 */
329 #define LIBXL_HAVE_BUILDINFO_GRANT_LIMITS 1
330
331 #define LIBXL_MAX_GRANT_FRAMES_DEFAULT 32
332 #define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT 1024
333
334 /*
335 * LIBXL_HAVE_BUILDINFO_* indicates that libxl_domain_build_info has
336 * the field represented by the '*'. The original position of those
337 * fields is:
338 * - u.hvm.timer_mode
339 * - u.hvm.apic
340 * - u.hvm.nested_hvm
341 * - u.pv.bootloader
342 * - u.pv.bootloader_args
343 */
344 #define LIBXL_HAVE_BUILDINFO_TIMER_MODE 1
345 #define LIBXL_HAVE_BUILDINFO_APIC 1
346 #define LIBXL_HAVE_BUILDINFO_NESTED_HVM 1
347 #define LIBXL_HAVE_BUILDINFO_BOOTLOADER 1
348 #define LIBXL_HAVE_BUILDINFO_BOOTLOADER_ARGS 1
349
350 /*
351 * libxl ABI compatibility
352 *
353 * The only guarantee which libxl makes regarding ABI compatibility
354 * across releases is that the SONAME will always be bumped whenever
355 * the ABI is changed in an incompatible way.
356 *
357 * This applies within stable branches as well as
358 * development branches. It is possible that a new stable release of
359 * Xen may require a rebuild of applications using the
360 * library. However per the API compatibility gaurantees such a
361 * rebuild should not normally require any source level changes.
362 *
363 * As with the API compatiblity the SONAME will only be bumped for the
364 * first ABI incompatible change in a development branch.
365 */
366
367 /*
368 * libxl memory management
369 *
370 * From the point of view of the application (ie, libxl's caller),
371 * struct libxl_ctx* is threadsafe, and all returned allocated
372 * structures are obtained from malloc(), and must be freed by the
373 * caller either directly or by calling an appropriate free function
374 * provided by libxl. Ie the application does not get automatic
375 * assistance from libxl in managing these allocations.
376 *
377 * Specific details are in the header comments which should be found
378 * in libxl.h or libxlutil.h, next to the relevant function
379 * declarations.
380 *
381 * Internally, libxl has a garbage collection scheme which allows much libxl
382 * code to allocate strings etc. for internal use without needing to
383 * free them. These are called "temporary allocations".
384 *
385 * The pool for these temporary allocations, along with any other
386 * thread-specific data which is private to libxl but shared between
387 * libxl functions (such as the current xenstore transaction), is
388 * stored in the "gc context" which is a special enhanced context
389 * structure allocated automatically by convenience macros at every
390 * entry to libxl.
391 *
392 * Every libxl function falls into one of these categories:
393 *
394 * 1. Public functions (declared in libxl.h, libxlutil.h), which may
395 * be called by libxl applications. If a public function returns
396 * any allocated object to its caller, that object must have come
397 * from malloc.
398 *
399 * The definitions of public functions MUST use the gc context
400 * initialisation macros (or do the equivalent work themselves).
401 * These macros will ensure that all temporary allocations will be
402 * automatically freed before the function returns to its caller.
403 *
404 * A public function may be called from within libxl; the call
405 * context initialisation macros will make sure that the internal
406 * caller's context is reused (eg, so that the same xenstore
407 * transaction is used). But in-libxl callers of libxl public
408 * functions should note that any libxl public function may cause
409 * recursively reentry into libxl via the application's event
410 * callback hook.
411 *
412 * Public functions have names like libxl_foobar.
413 *
414 * 2. Private functions, which may not be called by libxl
415 * applications; they are not declared in libxl.h or libxlutil.h
416 * and they may not be called other than by other libxl functions.
417 *
418 * Private functions should not use the gc context initialisation
419 * macros.
420 *
421 * Private functions have names like libxl__foobar (NB, two underscores).
422 * Also the declaration of such functions must be preceeded by the _hidden
423 * macro.
424 *
425 * Allocations made by a libxl function fall into one of the following
426 * categories (where "object" includes any memory allocation):
427 *
428 * (a) Objects which are not returned to the function's caller.
429 * These should be allocated from the temporary pool.
430 *
431 * (b) Objects which are intended for return to the calling
432 * application. This includes all allocated objects returned by
433 * any public function.
434 *
435 * It may also include objects allocated by an internal function
436 * specifically for eventual return by the function's external
437 * callers, but this situation should be clearly documented in
438 * comments.
439 *
440 * These should be allocated from malloc() et al. and comments
441 * near the function declaration should explain the memory
442 * ownership. If a simple free() by the application is not
443 * sufficient, a suitable public freeing function should be
444 * provided.
445 *
446 * (c) Internal objects whose size and/or lifetime dictate explicit
447 * memory management within libxl. This includes objects which
448 * will be embedded in opaque structures which will be returned to
449 * the libxl caller (more generally, any internal object whose
450 * lifetime exceeds the libxl entrypoint which creates it) and
451 * objects which are so large or numerous that explicit memory
452 * management is required.
453 *
454 * These should be allocated from malloc() et al., and freed
455 * explicitly at the appropriate point. The situation should be
456 * documented in comments.
457 *
458 * (d) Objects which are allocated by internal-only functions and
459 * returned to the function's (therefore, internal) caller but are
460 * strictly for internal use by other parts of libxl. These
461 * should be allocated from the temporary pool.
462 *
463 * Where a function's primary purpose is to return such an object,
464 * it should have a libxl__gc * as it's first argument.
465 *
466 * Note that there are two ways to change an allocation from this
467 * category to the "public" category. Either the implementation
468 * is kept internal and a wrapper function duplicates all memory
469 * allocations so that they are suitable for return to external
470 * callers or the implementation uses plain malloc() et al calls
471 * and an internal wrapper adds the relevant pointers to the gc.
472 * The latter method is preferred for obvious performance reasons.
473 *
474 * No temporary objects allocated from the pool may be explicitly freed.
475 * Therefore public functions which initialize a libxl__gc MUST call
476 * libxl__free_all() before returning.
477 *
478 * Memory allocation failures are not handled gracefully. If malloc
479 * (or realloc) fails, libxl will cause the entire process to print
480 * a message to stderr and exit with status 255.
481 */
482 /*
483 * libxl types
484 *
485 * Most libxl types are defined by the libxl IDL (see
486 * libxl_types.idl). The library provides a common set of methods for
487 * initialising and freeing these types.
488 *
489 * IDL-generated libxl types should be used as follows: the user must
490 * always call the "init" function before using a type, even if the
491 * variable is simply being passed by reference as an out parameter
492 * to a libxl function. The user must always calls "dispose" exactly
493 * once afterwards, to clean up, regardless of whether operations on
494 * this object succeeded or failed. See the xl code for examples.
495 *
496 * "init" and "dispose" are idempotent.
497 *
498 * void libxl_<type>_init(<type> *p):
499 *
500 * Initialises the members of "p" to all defaults. These may either
501 * be special value which indicates to the library that it should
502 * select an appropriate default when using this field or actual
503 * default values.
504 *
505 * Some fields within a data type (e.g. unions) cannot be sensibly
506 * initialised without further information. In these cases a
507 * separate subfield initialisation function is provided (see
508 * below).
509 *
510 * An instance which has been initialised using this method can
511 * always be safely passed to the dispose function (see
512 * below). This is true even if the data type contains fields which
513 * require a separate call to a subfield initialisation function.
514 *
515 * This method is provided for any aggregate type which is used as
516 * an input parameter.
517 *
518 * void libxl_<type>_init_<subfield>(<type> *p, subfield):
519 *
520 * Initialise those parts of "p" which are not initialised by the
521 * main init function due to the unknown value of "subfield". Sets
522 * p->subfield as well as initialising any fields to their default
523 * values.
524 *
525 * p->subfield must not have been previously initialised.
526 *
527 * This method is provided for any aggregate type.
528 *
529 * void libxl_<type>_dispose(instance *p):
530 *
531 * Frees any dynamically allocated memory used by the members of
532 * "p" but not the storage used by "p" itself (this allows for the
533 * allocation of arrays of types and for the composition of types).
534 *
535 * char *libxl_<type>_to_json(instance *p)
536 *
537 * Generates a JSON object from "p" in the form of a NULL terminated
538 * string.
539 *
540 * <type *> libxl_<type>_from_json(const char *json)
541 * int libxl_<type>_from_json(const char *json)
542 *
543 * Parses "json" and returns:
544 *
545 * an int value, if <type> is enumeration type. The value is the enum value
546 * representing the respective string in "json".
547 *
548 * an instance of <type>, if <type> is aggregate type. The returned
549 * instance has its fields filled in by the parser according to "json".
550 *
551 * If the parsing fails, caller cannot rely on the value / instance
552 * returned.
553 */
554 #ifndef LIBXL_H
555 #define LIBXL_H
556
557 #include <stdbool.h>
558 #include <stdint.h>
559 #include <stdarg.h>
560 #include <string.h>
561 #include <errno.h>
562 #include <netinet/in.h>
563 #include <sys/wait.h> /* for pid_t */
564
565 #include <xentoollog.h>
566
567 typedef struct libxl__ctx libxl_ctx;
568
569 #include <libxl_uuid.h>
570 #include <_libxl_list.h>
571
572 /* API compatibility. */
573 #ifdef LIBXL_API_VERSION
574 #if LIBXL_API_VERSION != 0x040200 && LIBXL_API_VERSION != 0x040300 && \
575 LIBXL_API_VERSION != 0x040400 && LIBXL_API_VERSION != 0x040500
576 #error Unknown LIBXL_API_VERSION
577 #endif
578 #endif
579
580 /* LIBXL_HAVE_RETRIEVE_DOMAIN_CONFIGURATION
581 *
582 * If this is defined we have libxl_retrieve_domain_configuration which
583 * returns the current configuration of a domain, which can be used to
584 * rebuild a domain.
585 */
586 #define LIBXL_HAVE_RETRIEVE_DOMAIN_CONFIGURATION 1
587
588 /*
589 * LIBXL_HAVE_BUILDINFO_VCPU_AFFINITY_ARRAYS
590 *
591 * If this is defined, then the libxl_domain_build_info structure will
592 * contain two arrays of libxl_bitmap-s, with all the necessary information
593 * to set the hard affinity (vcpu_hard_affinity) and the soft affinity
594 * (vcpu_soft_affinity) of the VCPUs.
595 *
596 * Note that, if the vcpu_hard_affinity array is used, libxl will ignore
597 * the content of the cpumap field of libxl_domain_build_info. That is to
598 * say, if the array is allocated and used by the caller, it is it and
599 * only it that determines the hard affinity of the domain's VCPUs.
600 *
601 * The number of libxl_bitmap-s in the arrays should be equal to the
602 * maximum number of VCPUs of the domain. If there only are N elements in
603 * an array, with N smaller the the maximum number of VCPUs, the hard or
604 * soft affinity (depending on which array we are talking about) will be
605 * set only for the first N VCPUs. The other VCPUs will just have affinity,
606 * both hard and soft, with all the host PCPUs.
607 * Each bitmap should be big enough to accommodate the maximum number of
608 * PCPUs of the host.
609 */
610 #define LIBXL_HAVE_BUILDINFO_VCPU_AFFINITY_ARRAYS 1
611
612 /*
613 * LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST
614 *
615 * If this is defined, then the libxl_domain_build_info structure will
616 * contain hvm.usbdevice_list, a libxl_string_list type that contains
617 * a list of USB devices to specify on the qemu command-line.
618 *
619 * If it is set, callers may use either hvm.usbdevice or
620 * hvm.usbdevice_list, but not both; if both are set, libxl will
621 * throw an error.
622 *
623 * If this is not defined, callers can only use hvm.usbdevice. Note
624 * that this means only one device can be added at domain build time.
625 */
626 #define LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST 1
627
628 /*
629 * LIBXL_HAVE_BUILDINFO_USBVERSION
630 *
631 * If this is defined, then the libxl_domain_build_info structure will
632 * contain hvm.usbversion, a integer type that contains a USB
633 * controller version to specify on the qemu upstream command-line.
634 *
635 * If it is set, callers may use hvm.usbversion to specify if the usb
636 * controller is usb1, usb2 or usb3.
637 *
638 * If this is not defined, the hvm.usbversion field does not exist.
639 */
640 #define LIBXL_HAVE_BUILDINFO_USBVERSION 1
641
642 /*
643 * LIBXL_HAVE_DEVICE_BACKEND_DOMNAME
644 *
645 * If this is defined, libxl_device_* structures containing a backend_domid
646 * field also contain a backend_domname field. If backend_domname is set, it is
647 * resolved to a domain ID when the device is used and takes precedence over the
648 * backend_domid field.
649 *
650 * If this is not defined, the backend_domname field does not exist.
651 */
652 #define LIBXL_HAVE_DEVICE_BACKEND_DOMNAME 1
653
654 /*
655 * LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG
656 *
657 * This argument was erroneously "const" in the 4.2 release despite
658 * the requirement for the callback to free the event.
659 */
660 #if LIBXL_API_VERSION != 0x040200
661 #define LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG 1
662 #endif
663
664 /*
665 * LIBXL_HAVE_NONCONST_LIBXL_BASENAME_RETURN_VALUE
666 *
667 * The return value of libxl_basename is malloc'ed but the erroneously
668 * marked as "const" in releases before 4.5.
669 */
670 #if !defined(LIBXL_API_VERSION) || LIBXL_API_VERSION >= 0x040500
671 #define LIBXL_HAVE_NONCONST_LIBXL_BASENAME_RETURN_VALUE 1
672 #endif
673
674 /*
675 * LIBXL_HAVE_PHYSINFO_OUTSTANDING_PAGES
676 *
677 * If this is defined, libxl_physinfo structure will contain an uint64 field
678 * called outstanding_pages, containing the number of pages claimed but not
679 * yet allocated for all domains.
680 */
681 #define LIBXL_HAVE_PHYSINFO_OUTSTANDING_PAGES 1
682
683 /*
684 * LIBXL_HAVE_PHYSINFO_MAX_POSSIBLE_MFN
685 *
686 * If this is defined, libxl_physinfo structure will contain an uint64 field
687 * called max_possible_mfn, containing the highest possible mfn on this host,
688 * possibly taking memory hotplug into account.
689 */
690 #define LIBXL_HAVE_PHYSINFO_MAX_POSSIBLE_MFN 1
691
692 /*
693 * LIBXL_HAVE_DOMINFO_OUTSTANDING_MEMKB 1
694 *
695 * If this is defined, libxl_dominfo will contain a MemKB type field called
696 * outstanding_memkb, containing the amount of claimed but not yet allocated
697 * memory for a specific domain.
698 */
699 #define LIBXL_HAVE_DOMINFO_OUTSTANDING_MEMKB 1
700
701 /*
702 * LIBXL_HAVE_DOMINFO_NEVER_STOP
703 *
704 * If this is defined, libxl_dominfo will contain a flag called never_stop
705 * indicating that the specific domain should never be stopped by the
706 * toolstack.
707 */
708 #define LIBXL_HAVE_DOMINFO_NEVER_STOP 1
709
710 /*
711 * LIBXL_HAVE_QXL
712 *
713 * If defined, then the libxl_vga_interface_type will contain another value:
714 * "QXL". This value define if qxl vga is supported.
715 *
716 * If this is not defined, the qxl vga support is missed.
717 */
718 #define LIBXL_HAVE_QXL 1
719
720 /*
721 * LIBXL_HAVE_SPICE_VDAGENT
722 *
723 * If defined, then the libxl_spice_info structure will contain a boolean type:
724 * vdagent and clipboard_sharing. These values define if Spice vdagent and
725 * clipboard sharing are enabled.
726 *
727 * If this is not defined, the Spice vdagent support is ignored.
728 */
729 #define LIBXL_HAVE_SPICE_VDAGENT 1
730
731 /*
732 * LIBXL_HAVE_SPICE_USBREDIRECTION
733 *
734 * If defined, then the libxl_spice_info structure will contain an integer type
735 * field: usbredirection. This value defines if Spice usbredirection is enabled
736 * and with how much channels.
737 *
738 * If this is not defined, the Spice usbredirection support is ignored.
739 */
740 #define LIBXL_HAVE_SPICE_USBREDIREDIRECTION 1
741
742 /*
743 * LIBXL_HAVE_SPICE_IMAGECOMPRESSION
744 *
745 * If defined, then the libxl_spice_info structure will contain a string type
746 * field: image_compression. This value defines what Spice image compression
747 * is used.
748 *
749 * If this is not defined, the Spice image compression setting support is ignored.
750 */
751 #define LIBXL_HAVE_SPICE_IMAGECOMPRESSION 1
752
753 /*
754 * LIBXL_HAVE_SPICE_STREAMINGVIDEO
755 *
756 * If defined, then the libxl_spice_info structure will contain a string type
757 * field: streaming_video. This value defines what Spice streaming video setting
758 * is used.
759 *
760 * If this is not defined, the Spice streaming video setting support is ignored.
761 */
762 #define LIBXL_HAVE_SPICE_STREAMINGVIDEO 1
763
764 /*
765 * LIBXL_HAVE_HVM_HDTYPE
766 *
767 * If defined, then the u.hvm structure will contain a enum type
768 * hdtype.
769 */
770 #define LIBXL_HAVE_HVM_HDTYPE 1
771
772 /*
773 * LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS 1
774 *
775 * If this is defined, libxl_domain_create_restore()'s API has changed to
776 * include a params structure.
777 */
778 #define LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS 1
779
780 /*
781 * LIBXL_HAVE_DOMAIN_CREATE_RESTORE_SEND_BACK_FD 1
782 *
783 * If this is defined, libxl_domain_create_restore()'s API includes the
784 * send_back_fd param. This is used only with COLO, for the libxl migration
785 * back channel; other callers should pass -1.
786 */
787 #define LIBXL_HAVE_DOMAIN_CREATE_RESTORE_SEND_BACK_FD 1
788
789 /*
790 * LIBXL_HAVE_DRIVER_DOMAIN_CREATION 1
791 *
792 * If this is defined, libxl_domain_create_info contains a driver_domain
793 * field that can be used to tell libxl that the domain that is going
794 * to be created is a driver domain, so the necessary actions are taken.
795 */
796 #define LIBXL_HAVE_DRIVER_DOMAIN_CREATION 1
797
798 /*
799 * LIBXL_HAVE_SIGCHLD_SELECTIVE_REAP
800 *
801 * If this is defined:
802 *
803 * Firstly, the enum libxl_sigchld_owner (in libxl_event.h) has the
804 * value libxl_sigchld_owner_libxl_always_selective_reap which may be
805 * passed to libxl_childproc_setmode in hooks->chldmode.
806 *
807 * Secondly, the function libxl_childproc_sigchld_occurred exists.
808 */
809 #define LIBXL_HAVE_SIGCHLD_OWNER_SELECTIVE_REAP 1
810
811 /*
812 * LIBXL_HAVE_SIGCHLD_SHARING
813 *
814 * If this is defined, it is permissible for multiple libxl ctxs
815 * to simultaneously "own" SIGCHLD. See "Subprocess handling"
816 * in libxl_event.h.
817 */
818 #define LIBXL_HAVE_SIGCHLD_SHARING 1
819
820 /*
821 * LIBXL_HAVE_NO_SUSPEND_RESUME
822 *
823 * Is this is defined then the platform has no support for saving,
824 * restoring or migrating a domain. In this case the related functions
825 * should be expected to return failure. That is:
826 * - libxl_domain_suspend
827 * - libxl_domain_resume
828 * - libxl_domain_remus_start
829 */
830 #if defined(__arm__) || defined(__aarch64__)
831 #define LIBXL_HAVE_NO_SUSPEND_RESUME 1
832 #endif
833
834 /*
835 * LIBXL_HAVE_DEVICE_PCI_SEIZE
836 *
837 * If this is defined, then the libxl_device_pci struct will contain
838 * the "seize" boolean field. If this field is set, libxl_pci_add will
839 * check to see if the device is currently assigned to pciback, and if not,
840 * it will attempt to do so (unbinding the device from the existing driver).
841 */
842 #define LIBXL_HAVE_DEVICE_PCI_SEIZE 1
843
844 /*
845 * LIBXL_HAVE_BUILDINFO_KERNEL
846 *
847 * If this is defined, then the libxl_domain_build_info structure will
848 * contain 'kernel', 'ramdisk', 'cmdline' fields. 'kernel' is a string
849 * to indicate kernel image location, 'ramdisk' is a string to indicate
850 * ramdisk location, 'cmdline' is a string to indicate the paramters which
851 * would be appended to kernel image.
852 *
853 * Both PV guest and HVM guest can use these fields for direct kernel boot.
854 * But for compatibility reason, u.pv.kernel, u.pv.ramdisk and u.pv.cmdline
855 * still exist.
856 */
857 #define LIBXL_HAVE_BUILDINFO_KERNEL 1
858
859 /*
860 * LIBXL_HAVE_DEVICE_CHANNEL
861 *
862 * If this is defined, then the libxl_device_channel struct exists
863 * and channels can be attached to a domain. Channels manifest as consoles
864 * with names, see docs/misc/console.txt.
865 */
866 #define LIBXL_HAVE_DEVICE_CHANNEL 1
867
868 /*
869 * LIBXL_HAVE_AO_ABORT indicates the availability of libxl_ao_abort
870 */
871 #define LIBXL_HAVE_AO_ABORT 1
872
873 /* Functions annotated with LIBXL_EXTERNAL_CALLERS_ONLY may not be
874 * called from within libxl itself. Callers outside libxl, who
875 * do not #include libxl_internal.h, are fine. */
876 #ifndef LIBXL_EXTERNAL_CALLERS_ONLY
877 #define LIBXL_EXTERNAL_CALLERS_ONLY /* disappears for callers outside libxl */
878 #endif
879
880 /*
881 * LIBXL_HAVE_UUID_COPY_CTX_PARAM
882 *
883 * If this is defined, libxl_uuid_copy has changed to take a libxl_ctx
884 * structure.
885 */
886 #define LIBXL_HAVE_UUID_COPY_CTX_PARAM 1
887
888 /*
889 * LIBXL_HAVE_SSID_LABEL
890 *
891 * If this is defined, then libxl IDL contains string of XSM security
892 * label in all XSM related structures.
893 *
894 * If set this string takes precedence over the numeric field.
895 */
896 #define LIBXL_HAVE_SSID_LABEL 1
897
898 /*
899 * LIBXL_HAVE_CPUPOOL_NAME
900 *
901 * If this is defined, then libxl IDL contains string of CPU pool
902 * name in all CPU pool related structures.
903 *
904 * If set this string takes precedence over the numeric field.
905 */
906 #define LIBXL_HAVE_CPUPOOL_NAME 1
907
908 /*
909 * LIBXL_HAVE_BUILDINFO_SERIAL_LIST
910 *
911 * If this is defined, then the libxl_domain_build_info structure will
912 * contain hvm.serial_list, a libxl_string_list type that contains
913 * a list of serial ports to specify on the qemu command-line.
914 *
915 * If it is set, callers may use either hvm.serial or
916 * hvm.serial_list, but not both; if both are set, libxl will
917 * throw an error.
918 *
919 * If this is not defined, callers can only use hvm.serial. Note
920 * that this means only one serial port can be added at domain build time.
921 */
922 #define LIBXL_HAVE_BUILDINFO_SERIAL_LIST 1
923
924 /*
925 * LIBXL_HAVE_ALTP2M
926 * If this is defined, then libxl supports alternate p2m functionality.
927 */
928 #define LIBXL_HAVE_ALTP2M 1
929
930 /*
931 * LIBXL_HAVE_REMUS
932 * If this is defined, then libxl supports remus.
933 */
934 #define LIBXL_HAVE_REMUS 1
935
936 /*
937 * LIBXL_HAVE_COLO_USERSPACE_PROXY
938 * If this is defined, then libxl supports COLO userspace proxy.
939 */
940 #define LIBXL_HAVE_COLO_USERSPACE_PROXY 1
941
942 typedef uint8_t libxl_mac[6];
943 #define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
944 #define LIBXL_MAC_FMTLEN ((2*6)+5) /* 6 hex bytes plus 5 colons */
945 #define LIBXL_MAC_BYTES(mac) mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
946 void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);
947
948 #if defined(__i386__) || defined(__x86_64__)
949 /*
950 * LIBXL_HAVE_PSR_CMT
951 *
952 * If this is defined, the Cache Monitoring Technology feature is supported.
953 */
954 #define LIBXL_HAVE_PSR_CMT 1
955
956 /*
957 * LIBXL_HAVE_PSR_MBM
958 *
959 * If this is defined, the Memory Bandwidth Monitoring feature is supported.
960 */
961 #define LIBXL_HAVE_PSR_MBM 1
962
963 /*
964 * LIBXL_HAVE_PSR_CAT
965 *
966 * If this is defined, the Cache Allocation Technology feature is supported.
967 */
968 #define LIBXL_HAVE_PSR_CAT 1
969
970 /*
971 * LIBXL_HAVE_PSR_CDP
972 *
973 * If this is defined, the Code and Data Prioritization feature is supported.
974 */
975 #define LIBXL_HAVE_PSR_CDP 1
976
977 /*
978 * LIBXL_HAVE_PSR_L2_CAT
979 *
980 * If this is defined, the L2 Cache Allocation Technology feature is supported.
981 */
982 #define LIBXL_HAVE_PSR_L2_CAT 1
983
984 /*
985 * LIBXL_HAVE_MCA_CAPS
986 *
987 * If this is defined, setting MCA capabilities for HVM domain is supported.
988 */
989 #define LIBXL_HAVE_MCA_CAPS 1
990 #endif
991
992 /*
993 * LIBXL_HAVE_PCITOPOLOGY
994 *
995 * If this is defined, then interface to query hypervisor about PCI device
996 * topology is available.
997 */
998 #define LIBXL_HAVE_PCITOPOLOGY 1
999
1000 /*
1001 * LIBXL_HAVE_SOCKET_BITMAP
1002 *
1003 * If this is defined, then libxl_socket_bitmap_alloc and
1004 * libxl_get_online_socketmap exist.
1005 */
1006 #define LIBXL_HAVE_SOCKET_BITMAP 1
1007
1008 /*
1009 * LIBXL_HAVE_SRM_V2
1010 *
1011 * If this is defined, then the libxl_domain_create_restore() interface takes
1012 * a "stream_version" parameter and supports a value of 2.
1013 *
1014 * libxl_domain_suspend() will produce a v2 stream.
1015 */
1016 #define LIBXL_HAVE_SRM_V2 1
1017
1018 /*
1019 * LIBXL_HAVE_SRM_V1
1020 *
1021 * In the case that LIBXL_HAVE_SRM_V2 is set, LIBXL_HAVE_SRM_V1
1022 * indicates that libxl_domain_create_restore() can handle a "stream_version"
1023 * parameter of 1, and convert the stream format automatically.
1024 */
1025 #define LIBXL_HAVE_SRM_V1 1
1026
1027 /*
1028 * libxl_domain_build_info has the u.hvm.gfx_passthru_kind field and
1029 * the libxl_gfx_passthru_kind enumeration is defined.
1030 */
1031 #define LIBXL_HAVE_GFX_PASSTHRU_KIND
1032
1033 /*
1034 * LIBXL_HAVE_CHECKPOINTED_STREAM
1035 *
1036 * If this is defined, then libxl_checkpointed_stream exists.
1037 */
1038 #define LIBXL_HAVE_CHECKPOINTED_STREAM 1
1039
1040 /*
1041 * LIBXL_HAVE_BUILDINFO_HVM_SYSTEM_FIRMWARE
1042 *
1043 * libxl_domain_build_info has u.hvm.system_firmware field which can be use
1044 * to provide a different firmware blob (like SeaBIOS or OVMF).
1045 */
1046 #define LIBXL_HAVE_BUILDINFO_HVM_SYSTEM_FIRMWARE
1047
1048 /*
1049 * ERROR_REMUS_XXX error code only exists from Xen 4.5, Xen 4.6 and it
1050 * is changed to ERROR_CHECKPOINT_XXX in Xen 4.7
1051 */
1052 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION >= 0x040500 \
1053 && LIBXL_API_VERSION < 0x040700
1054 #define ERROR_REMUS_DEVOPS_DOES_NOT_MATCH \
1055 ERROR_CHECKPOINT_DEVOPS_DOES_NOT_MATCH
1056 #define ERROR_REMUS_DEVICE_NOT_SUPPORTED \
1057 ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED
1058 #endif
1059
1060 /*
1061 * LIBXL_HAVE_VGA_INTERFACE_TYPE_UNKNOWN
1062 *
1063 * In the case that LIBXL_HAVE_VGA_INTERFACE_TYPE_UNKNOWN is set the
1064 * libxl_vga_interface_type enumeration type contains a
1065 * LIBXL_VGA_INTERFACE_TYPE_UNKNOWN identifier. This is used to signal
1066 * that a libxl_vga_interface_type type has not been initialized yet.
1067 */
1068 #define LIBXL_HAVE_VGA_INTERFACE_TYPE_UNKNOWN 1
1069
1070 /*
1071 * LIBXL_HAVE_BYTEARRAY_UUID
1072 *
1073 * If this is defined, the internal member of libxl_uuid is defined
1074 * as a 16 byte array that contains the UUID in big endian format.
1075 * Also, the same structure layout is used across all OSes.
1076 */
1077 #define LIBXL_HAVE_BYTEARRAY_UUID 1
1078
1079 /*
1080 * LIBXL_HAVE_MEMKB_64BITS
1081 *
1082 * If this is defined libxl_set_memory_target(), libxl_domain_setmaxmem()
1083 * and libxl_wait_for_free_memory() will take a 64 bit value for the memory
1084 * size parameter.
1085 * From Xen 4.8 on libxl_get_memory_target(), libxl_domain_need_memory() and
1086 * libxl_get_free_memory() return the memory size in a 64 bit value, too.
1087 */
1088 #define LIBXL_HAVE_MEMKB_64BITS 1
1089
1090 /*
1091 * LIBXL_HAVE_QED
1092 *
1093 * If this is defined QED disk formats can be used for both HVM and PV guests.
1094 */
1095 #define LIBXL_HAVE_QED 1
1096
1097 /*
1098 * LIBXL_HAVE_SET_PARAMETERS
1099 *
1100 * If this is defined setting hypervisor parameters is supported.
1101 */
1102 #define LIBXL_HAVE_SET_PARAMETERS 1
1103
1104 /*
1105 * LIBXL_HAVE_PV_SHIM
1106 *
1107 * If this is defined, libxl_domain_build_info's pvh type information
1108 * contains members pvshim, pvshim_path, pvshim_cmdline, pvshim_extra.
1109 */
1110 #define LIBXL_HAVE_PV_SHIM 1
1111
1112 typedef char **libxl_string_list;
1113 void libxl_string_list_dispose(libxl_string_list *sl);
1114 int libxl_string_list_length(const libxl_string_list *sl);
1115 void libxl_string_list_copy(libxl_ctx *ctx, libxl_string_list *dst,
1116 const libxl_string_list *src);
1117
1118 typedef char **libxl_key_value_list;
1119 void libxl_key_value_list_dispose(libxl_key_value_list *kvl);
1120 int libxl_key_value_list_length(const libxl_key_value_list *kvl);
1121 void libxl_key_value_list_copy(libxl_ctx *ctx,
1122 libxl_key_value_list *dst,
1123 const libxl_key_value_list *src);
1124
1125 typedef uint32_t libxl_hwcap[8];
1126 void libxl_hwcap_copy(libxl_ctx *ctx, libxl_hwcap *dst, const libxl_hwcap *src);
1127
1128 typedef uint64_t libxl_ev_user;
1129
1130 typedef struct {
1131 uint32_t size; /* number of bytes in map */
1132 uint8_t *map;
1133 } libxl_bitmap;
1134 void libxl_bitmap_init(libxl_bitmap *map);
1135 void libxl_bitmap_dispose(libxl_bitmap *map);
1136
1137 /* libxl_cpuid_policy_list is a dynamic array storing CPUID policies
1138 * for multiple leafs. It is terminated with an entry holding
1139 * XEN_CPUID_INPUT_UNUSED in input[0]
1140 */
1141 typedef struct libxl__cpuid_policy libxl_cpuid_policy;
1142 typedef libxl_cpuid_policy * libxl_cpuid_policy_list;
1143 void libxl_cpuid_dispose(libxl_cpuid_policy_list *cpuid_list);
1144 int libxl_cpuid_policy_list_length(const libxl_cpuid_policy_list *l);
1145 void libxl_cpuid_policy_list_copy(libxl_ctx *ctx,
1146 libxl_cpuid_policy_list *dst,
1147 const libxl_cpuid_policy_list *src);
1148
1149 #define LIBXL_PCI_FUNC_ALL (~0U)
1150
1151 typedef uint32_t libxl_domid;
1152 typedef int libxl_devid;
1153
1154 /*
1155 * Formatting Enumerations.
1156 *
1157 * Each enumeration type libxl_E declares an associated lookup table
1158 * libxl_E_string_table and a lookup function libxl_E_from_string.
1159 */
1160 typedef struct {
1161 const char *s;
1162 int v;
1163 } libxl_enum_string_table;
1164
1165 struct libxl_event;
1166 typedef LIBXL_TAILQ_ENTRY(struct libxl_event) libxl_ev_link;
1167
1168 /*
1169 * A boolean variable with an explicit default state.
1170 *
1171 * Users should treat this struct as opaque and use the following
1172 * defined macros and accessor functions.
1173 *
1174 * To allow users of the library to naively select all defaults this
1175 * state is represented as 0. False is < 0 and True is > 0.
1176 */
1177 typedef struct {
1178 int val;
1179 } libxl_defbool;
1180
1181 void libxl_defbool_set(libxl_defbool *db, bool b);
1182 /* Resets to default */
1183 void libxl_defbool_unset(libxl_defbool *db);
1184 /* Sets db only if it is currently == default */
1185 void libxl_defbool_setdefault(libxl_defbool *db, bool b);
1186 bool libxl_defbool_is_default(libxl_defbool db);
1187 /* db must not be == default */
1188 bool libxl_defbool_val(libxl_defbool db);
1189
1190 const char *libxl_defbool_to_string(libxl_defbool b);
1191
1192 #define LIBXL_TIMER_MODE_DEFAULT -1
1193 #define LIBXL_MEMKB_DEFAULT ~0ULL
1194
1195 /*
1196 * We'd like to set a memory boundary to determine if we need to check
1197 * any overlap with reserved device memory.
1198 */
1199 #define LIBXL_RDM_MEM_BOUNDARY_MEMKB_DEFAULT (2048 * 1024)
1200
1201 #define LIBXL_MS_VM_GENID_LEN 16
1202 typedef struct {
1203 uint8_t bytes[LIBXL_MS_VM_GENID_LEN];
1204 } libxl_ms_vm_genid;
1205
1206 #include "_libxl_types.h"
1207
1208 const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx);
1209
1210 /*
1211 * Some libxl operations can take a long time. These functions take a
1212 * parameter to control their concurrency:
1213 * libxl_asyncop_how *ao_how
1214 *
1215 * If ao_how==NULL, the function will be synchronous.
1216 *
1217 * If ao_how!=NULL, the function will set the operation going, and if
1218 * this is successful will return 0. In this case the zero error
1219 * response does NOT mean that the operation was successful; it just
1220 * means that it has been successfully started. It will finish later,
1221 * perhaps with an error.
1222 *
1223 * If ao_how->callback!=NULL, the callback will be called when the
1224 * operation completes. The same rules as for libxl_event_hooks
1225 * apply, including the reentrancy rules and the possibility of
1226 * "disaster", except that libxl calls ao_how->callback instead of
1227 * libxl_event_hooks.event_occurs. (See libxl_event.h.)
1228 *
1229 * If ao_how->callback==NULL, a libxl_event will be generated which
1230 * can be obtained from libxl_event_wait or libxl_event_check. The
1231 * event will have type OPERATION_COMPLETE (which is not used
1232 * elsewhere).
1233 *
1234 * Note that it is possible for an asynchronous operation which is to
1235 * result in a callback to complete during its initiating function
1236 * call. In this case the initiating function will return 0
1237 * indicating the at the operation is "in progress", even though by
1238 * the time it returns the operation is complete and the callback has
1239 * already happened.
1240 *
1241 * The application must set and use ao_how->for_event (which will be
1242 * copied into libxl_event.for_user) or ao_how->for_callback (passed
1243 * to the callback) to determine which operation finished, and it must
1244 * of course check the rc value for errors.
1245 *
1246 * *ao_how does not need to remain valid after the initiating function
1247 * returns. All other parameters must remain valid for the lifetime of
1248 * the asynchronous operation, unless otherwise specified.
1249 *
1250 * Callbacks may occur on any thread in which the application calls
1251 * libxl.
1252 */
1253
1254 typedef struct {
1255 void (*callback)(libxl_ctx *ctx, int rc, void *for_callback);
1256 union {
1257 libxl_ev_user for_event; /* used if callback==NULL */
1258 void *for_callback; /* passed to callback */
1259 } u;
1260 } libxl_asyncop_how;
1261
1262 /*
1263 * Some more complex asynchronous operations can report intermediate
1264 * progress. How this is to be reported is controlled, for each
1265 * function, by a parameter
1266 * libxl_asyncprogress_how *aop_FOO_how;
1267 * for each kind of progress FOO supported by that function. Each
1268 * such kind of progress is associated with an event type.
1269 *
1270 * The function description will document whether, when, and how
1271 * many times, the intermediate progress will be reported, and
1272 * what the corresponding event type(s) are.
1273 *
1274 * If aop_FOO_how==NULL, intermediate progress reports are discarded.
1275 *
1276 * If aop_FOO_how->callback==NULL, intermediate progress reports
1277 * generate libxl events which can be obtained from libxl_event_wait
1278 * or libxl_event_check.
1279 *
1280 * If aop_FOO_how->callback!=NULL, libxl will report intermediate
1281 * progress by calling callback(ctx, &event, for_callback).
1282 *
1283 * The rules for these events are otherwise the same as those for
1284 * ordinary events. The reentrancy and threading rules for the
1285 * callback are the same as those for ao completion callbacks.
1286 *
1287 * Note that the callback, if provided, is responsible for freeing
1288 * the event.
1289 *
1290 * If callbacks are requested, they will be made, and returned, before
1291 * the long-running libxl operation is considered finished (so if the
1292 * long-running libxl operation was invoked with ao_how==NULL then any
1293 * callbacks will occur strictly before the long-running operation
1294 * returns). However, the callbacks may occur on any thread.
1295 *
1296 * In general, otherwise, no promises are made about the relative
1297 * order of callbacks in a multithreaded program. In particular
1298 * different callbacks relating to the same long-running operation may
1299 * be delivered out of order.
1300 */
1301
1302 typedef struct {
1303 void (*callback)(libxl_ctx *ctx, libxl_event*, void *for_callback);
1304 libxl_ev_user for_event; /* always used */
1305 void *for_callback; /* passed to callback */
1306 } libxl_asyncprogress_how;
1307
1308 /*
1309 * It is sometimes possible to abort an asynchronous operation.
1310 *
1311 * libxl_ao_abort searches for an ongoing asynchronous operation whose
1312 * ao_how is identical to *how, and tries to abort it. The return
1313 * values from libxl_ao_abort are as follows:
1314 *
1315 * 0
1316 *
1317 * The operation was found, and attempts are being made to cut it
1318 * short. However, it may still take some time to stop. It is
1319 * also possible that the operation will nevertheless complete
1320 * successfully.
1321 *
1322 * ERROR_NOTFOUND
1323 *
1324 * No matching ongoing operation was found. This might happen
1325 * for an actual operation if the operation has already completed
1326 * (perhaps on another thread). The call to libxl_ao_abort has
1327 * had no effect.
1328 *
1329 * ERROR_ABORTED
1330 *
1331 * The operation has already been the subject of at least one
1332 * call to libxl_ao_abort.
1333 *
1334 * If the operation was indeed cut short due to the abort request, it
1335 * will complete, at some point in the future, with ERROR_ABORTED. In
1336 * that case, depending on the operation it have performed some of the
1337 * work in question and left the operation half-done. Consult the
1338 * documentation for individual operations.
1339 *
1340 * Note that an aborted operation might still fail for other reasons
1341 * even after the abort was requested.
1342 *
1343 * If your application is multithreaded you must not reuse an
1344 * ao_how->for_event or ao_how->for_callback value (with a particular
1345 * ao_how->callback) unless you are sure that none of your other
1346 * threads are going to abort the previous operation using that
1347 * value; otherwise you risk aborting the wrong operation if the
1348 * intended target of the abort request completes in the meantime.
1349 *
1350 * It is possible to abort even an operation which is being performed
1351 * synchronously, but since in that case how==NULL you had better only
1352 * have one such operation, because it is not possible to tell them
1353 * apart (and libxl_ao_abort will abort only the first one it finds).
1354 * (And, if you want to do this, obviously the abort would have to be
1355 * requested on a different thread.)
1356 */
1357 int libxl_ao_abort(libxl_ctx *ctx, const libxl_asyncop_how *how)
1358 LIBXL_EXTERNAL_CALLERS_ONLY;
1359
1360
1361 #define LIBXL_VERSION 0
1362
1363 /* context functions */
1364 int libxl_ctx_alloc(libxl_ctx **pctx, int version,
1365 unsigned flags /* none currently defined */,
1366 xentoollog_logger *lg);
1367 int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */);
1368
1369 /* domain related functions */
1370
1371 /* If the result is ERROR_ABORTED, the domain may or may not exist
1372 * (in a half-created state). *domid will be valid and will be the
1373 * domain id, or -1, as appropriate */
1374
1375 int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
1376 uint32_t *domid,
1377 const libxl_asyncop_how *ao_how,
1378 const libxl_asyncprogress_how *aop_console_how)
1379 LIBXL_EXTERNAL_CALLERS_ONLY;
1380 int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
1381 uint32_t *domid, int restore_fd,
1382 int send_back_fd,
1383 const libxl_domain_restore_params *params,
1384 const libxl_asyncop_how *ao_how,
1385 const libxl_asyncprogress_how *aop_console_how)
1386 LIBXL_EXTERNAL_CALLERS_ONLY;
1387
1388 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040400
1389
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)1390 static inline int libxl_domain_create_restore_0x040200(
1391 libxl_ctx *ctx, libxl_domain_config *d_config,
1392 uint32_t *domid, int restore_fd,
1393 const libxl_asyncop_how *ao_how,
1394 const libxl_asyncprogress_how *aop_console_how)
1395 LIBXL_EXTERNAL_CALLERS_ONLY
1396 {
1397 libxl_domain_restore_params params;
1398 int ret;
1399
1400 libxl_domain_restore_params_init(¶ms);
1401
1402 ret = libxl_domain_create_restore(
1403 ctx, d_config, domid, restore_fd, -1, ¶ms, ao_how, aop_console_how);
1404
1405 libxl_domain_restore_params_dispose(¶ms);
1406 return ret;
1407 }
1408
1409 #define libxl_domain_create_restore libxl_domain_create_restore_0x040200
1410
1411 #elif defined(LIBXL_API_VERSION) && LIBXL_API_VERSION >= 0x040400 \
1412 && LIBXL_API_VERSION < 0x040700
1413
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)1414 static inline int libxl_domain_create_restore_0x040400(
1415 libxl_ctx *ctx, libxl_domain_config *d_config,
1416 uint32_t *domid, int restore_fd,
1417 const libxl_domain_restore_params *params,
1418 const libxl_asyncop_how *ao_how,
1419 const libxl_asyncprogress_how *aop_console_how)
1420 LIBXL_EXTERNAL_CALLERS_ONLY
1421 {
1422 return libxl_domain_create_restore(ctx, d_config, domid, restore_fd,
1423 -1, params, ao_how, aop_console_how);
1424 }
1425
1426 #define libxl_domain_create_restore libxl_domain_create_restore_0x040400
1427
1428 #endif
1429
1430 int libxl_domain_soft_reset(libxl_ctx *ctx,
1431 libxl_domain_config *d_config,
1432 uint32_t domid,
1433 const libxl_asyncop_how *ao_how,
1434 const libxl_asyncprogress_how
1435 *aop_console_how)
1436 LIBXL_EXTERNAL_CALLERS_ONLY;
1437
1438 /* A progress report will be made via ao_console_how, of type
1439 * domain_create_console_available, when the domain's primary
1440 * console is available and can be connected to.
1441 */
1442
1443 void libxl_domain_config_init(libxl_domain_config *d_config);
1444 void libxl_domain_config_dispose(libxl_domain_config *d_config);
1445
1446 /*
1447 * Retrieve domain configuration and filled it in d_config. The
1448 * returned configuration can be used to rebuild a domain. It only
1449 * works with DomU.
1450 */
1451 int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
1452 libxl_domain_config *d_config)
1453 LIBXL_EXTERNAL_CALLERS_ONLY;
1454
1455 int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd,
1456 int flags, /* LIBXL_SUSPEND_* */
1457 const libxl_asyncop_how *ao_how)
1458 LIBXL_EXTERNAL_CALLERS_ONLY;
1459 #define LIBXL_SUSPEND_DEBUG 1
1460 #define LIBXL_SUSPEND_LIVE 2
1461
1462 /* @param suspend_cancel [from xenctrl.h:xc_domain_resume( @param fast )]
1463 * If this parameter is true, use co-operative resume. The guest
1464 * must support this.
1465 */
1466 int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid, int suspend_cancel,
1467 const libxl_asyncop_how *ao_how)
1468 LIBXL_EXTERNAL_CALLERS_ONLY;
1469
1470 /*
1471 * This function doesn't return unless something has gone wrong with
1472 * the replication to the secondary. If this function returns then the
1473 * caller should resume the (primary) domain.
1474 */
1475 int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
1476 uint32_t domid, int send_fd, int recv_fd,
1477 const libxl_asyncop_how *ao_how)
1478 LIBXL_EXTERNAL_CALLERS_ONLY;
1479
1480 int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid);
1481 int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid);
1482 int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
1483 const libxl_asyncop_how *ao_how)
1484 LIBXL_EXTERNAL_CALLERS_ONLY;
1485 int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_info *info, const char *name_suffix, libxl_uuid new_uuid);
1486
1487 /* get max. number of cpus supported by hypervisor */
1488 int libxl_get_max_cpus(libxl_ctx *ctx);
1489
1490 /* get the actual number of currently online cpus on the host */
1491 int libxl_get_online_cpus(libxl_ctx *ctx);
1492 /* Beware that no locking or serialization is provided by libxl,
1493 * so the information can be outdated as far as the function
1494 * returns. If there are other entities in the system capable
1495 * of onlining/offlining CPUs, it is up to the application
1496 * to guarantee consistency, if that is important. */
1497
1498 /* get max. number of NUMA nodes supported by hypervisor */
1499 int libxl_get_max_nodes(libxl_ctx *ctx);
1500
1501 int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid,
1502 const char *old_name, const char *new_name);
1503
1504 /* if old_name is NULL, any old name is OK; otherwise we check
1505 * transactionally that the domain has the old old name; if
1506 * trans is not 0 we use caller's transaction and caller must do retries */
1507
1508 int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid);
1509 int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid);
1510
1511 int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
1512 const char *filename,
1513 const libxl_asyncop_how *ao_how)
1514 LIBXL_EXTERNAL_CALLERS_ONLY;
1515
1516 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint64_t target_memkb);
1517 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, int64_t target_memkb, int relative, int enforce);
1518 int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint64_t *out_target);
1519 int libxl_get_memory_target_0x040700(libxl_ctx *ctx, uint32_t domid,
1520 uint32_t *out_target)
1521 LIBXL_EXTERNAL_CALLERS_ONLY;
1522
1523 /*
1524 * WARNING
1525 * This memory management API is unstable even in Xen 4.2.
1526 * It has a numer of deficiencies and we intend to replace it.
1527 *
1528 * The semantics of these functions should not be relied on to be very
1529 * coherent or stable. We will however endeavour to keep working
1530 * existing programs which use them in roughly the same way as libxl.
1531 */
1532 /* how much free memory in the system a domain needs to be built */
1533 int libxl_domain_need_memory(libxl_ctx *ctx,
1534 const libxl_domain_build_info *b_info_in,
1535 uint64_t *need_memkb);
1536 int libxl_domain_need_memory_0x040700(libxl_ctx *ctx,
1537 const libxl_domain_build_info *b_info_in,
1538 uint32_t *need_memkb)
1539 LIBXL_EXTERNAL_CALLERS_ONLY;
1540 /* how much free memory is available in the system */
1541 int libxl_get_free_memory(libxl_ctx *ctx, uint64_t *memkb);
1542 int libxl_get_free_memory_0x040700(libxl_ctx *ctx, uint32_t *memkb)
1543 LIBXL_EXTERNAL_CALLERS_ONLY;
1544 /* wait for a given amount of memory to be free in the system */
1545 int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint64_t memory_kb, int wait_secs);
1546 /*
1547 * Wait for the memory target of a domain to be reached. Does not
1548 * decrement wait_secs if the domain is making progress toward reaching
1549 * the target. If the domain is not making progress, wait_secs is
1550 * decremented. If the timeout expires before the target is reached, the
1551 * function returns ERROR_FAIL.
1552 *
1553 * Older versions of this function (Xen 4.5 and older), decremented
1554 * wait_secs even if the domain was making progress, resulting in far
1555 * lower overall wait times. To make sure that your calling routine
1556 * works with new and old implementations of the function, pass enough
1557 * time for the guest to reach its target as an argument.
1558 */
1559 int libxl_wait_for_memory_target(libxl_ctx *ctx, uint32_t domid, int wait_secs);
1560
1561 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040800
1562 #define libxl_get_memory_target libxl_get_memory_target_0x040700
1563 #define libxl_domain_need_memory libxl_domain_need_memory_0x040700
1564 #define libxl_get_free_memory libxl_get_free_memory_0x040700
1565 #endif
1566
1567 int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass);
1568
1569 /*
1570 * If notify_fd is not -1, xenconsole will write 0x00 to it to nofity
1571 * the caller that it has connected to the guest console.
1572 */
1573 int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num,
1574 libxl_console_type type, int notify_fd);
1575 /* libxl_primary_console_exec finds the domid and console number
1576 * corresponding to the primary console of the given vm, then calls
1577 * libxl_console_exec with the right arguments (domid might be different
1578 * if the guest is using stubdoms).
1579 * This function can be called after creating the device model, in
1580 * case of HVM guests, and before libxl_run_bootloader in case of PV
1581 * guests using pygrub.
1582 * If notify_fd is not -1, xenconsole will write 0x00 to it to nofity
1583 * the caller that it has connected to the guest console.
1584 */
1585 int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm,
1586 int notify_fd);
1587
1588 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040800
1589
libxl_console_exec_0x040700(libxl_ctx * ctx,uint32_t domid,int cons_num,libxl_console_type type)1590 static inline int libxl_console_exec_0x040700(libxl_ctx *ctx,
1591 uint32_t domid, int cons_num,
1592 libxl_console_type type)
1593 {
1594 return libxl_console_exec(ctx, domid, cons_num, type, -1);
1595 }
1596 #define libxl_console_exec libxl_console_exec_0x040700
1597
libxl_primary_console_exec_0x040700(libxl_ctx * ctx,uint32_t domid_vm)1598 static inline int libxl_primary_console_exec_0x040700(libxl_ctx *ctx,
1599 uint32_t domid_vm)
1600 {
1601 return libxl_primary_console_exec(ctx, domid_vm, -1);
1602 }
1603 #define libxl_primary_console_exec libxl_primary_console_exec_0x040700
1604
1605 #endif
1606
1607 /* libxl_console_get_tty retrieves the specified domain's console tty path
1608 * and stores it in path. Caller is responsible for freeing the memory.
1609 */
1610 int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num,
1611 libxl_console_type type, char **path);
1612
1613 /* libxl_primary_console_get_tty retrieves the specified domain's primary
1614 * console tty path and stores it in path. Caller is responsible for freeing
1615 * the memory.
1616 */
1617 int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm, char **path);
1618
1619 /* May be called with info_r == NULL to check for domain's existence.
1620 * Returns ERROR_DOMAIN_NOTFOUND if domain does not exist (used to return
1621 * ERROR_INVAL for this scenario). */
1622 int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r,
1623 uint32_t domid);
1624
1625 /* These functions each return (on success) an array of elements,
1626 * and the length via the int* out parameter. These arrays and
1627 * their contents come from malloc, and must be freed with the
1628 * corresponding libxl_THING_list_free function.
1629 */
1630 libxl_dominfo * libxl_list_domain(libxl_ctx*, int *nb_domain_out);
1631 void libxl_dominfo_list_free(libxl_dominfo *list, int nb_domain);
1632
1633 libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out);
1634 void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool);
1635
1636 libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm_out);
1637 void libxl_vminfo_list_free(libxl_vminfo *list, int nb_vm);
1638
1639 #define LIBXL_CPUTOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
1640 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out);
1641 void libxl_cputopology_list_free(libxl_cputopology *, int nb_cpu);
1642
1643 #define LIBXL_PCITOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
1644 libxl_pcitopology *libxl_get_pci_topology(libxl_ctx *ctx, int *num_devs);
1645 void libxl_pcitopology_list_free(libxl_pcitopology *, int num_devs);
1646
1647 #define LIBXL_NUMAINFO_INVALID_ENTRY (~(uint32_t)0)
1648 libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr);
1649 void libxl_numainfo_list_free(libxl_numainfo *, int nr);
1650
1651 libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
1652 int *nb_vcpu, int *nr_cpus_out);
1653 void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int nr_vcpus);
1654
1655 /*
1656 * Devices
1657 * =======
1658 *
1659 * Each device is represented by a libxl_device_<TYPE> data structure
1660 * which is defined via the IDL. In addition some devices have an
1661 * additional data type libxl_device_<TYPE>_getinfo which contains
1662 * further runtime information about the device.
1663 *
1664 * In addition to the general methods available for libxl types (see
1665 * "libxl types" above) a common set of methods are available for each
1666 * device type. These are described below.
1667 *
1668 * Querying
1669 * --------
1670 *
1671 * libxl_device_<type>_list(ctx, domid, nr):
1672 *
1673 * Returns an array of libxl_device_<type> length nr representing
1674 * the devices attached to the specified domain.
1675 *
1676 * libxl_device_<type>_getinfo(ctx, domid, device, info):
1677 *
1678 * Initialises info with details of the given device which must be
1679 * attached to the specified domain.
1680 *
1681 * Creation / Control
1682 * ------------------
1683 *
1684 * libxl_device_<type>_add(ctx, domid, device):
1685 *
1686 * Adds the given device to the specified domain. This can be called
1687 * while the guest is running (hotplug) or before boot (coldplug).
1688 *
1689 * This function only sets up the device but does not wait for the
1690 * domain to connect to the device and therefore cannot block on the
1691 * guest.
1692 *
1693 * device is an in/out parameter: fields left unspecified when the
1694 * structure is passed in are filled in with appropriate values for
1695 * the device created.
1696 *
1697 * libxl_device_<type>_remove(ctx, domid, device):
1698 *
1699 * Removes the given device from the specified domain by performing
1700 * an orderly unplug with guest co-operation. This requires that the
1701 * guest is running.
1702 *
1703 * This method is currently synchronous and therefore can block
1704 * while interacting with the guest.
1705 *
1706 * libxl_device_<type>_destroy(ctx, domid, device):
1707 *
1708 * Removes the given device from the specified domain without guest
1709 * co-operation. It is guest specific what affect this will have on
1710 * a running guest.
1711 *
1712 * This function does not interact with the guest and therefore
1713 * cannot block on the guest.
1714 *
1715 * Controllers
1716 * -----------
1717 *
1718 * Most devices are treated individually. Some classes of device,
1719 * however, like USB or SCSI, inherently have the need to have a
1720 * hierarchy of different levels, with lower-level devices "attached"
1721 * to higher-level ones. USB for instance has "controllers" at the
1722 * top, which have buses, on which are devices, which consist of
1723 * multiple interfaces. SCSI has "hosts" at the top, then buses,
1724 * targets, and LUNs.
1725 *
1726 * In that case, for each <class>, there will be a set of functions
1727 * and types for each <level>. For example, for <class>=usb, there
1728 * may be <levels> ctrl (controller) and dev (device), with ctrl being
1729 * level 0.
1730 *
1731 * libxl_device_<class><level0>_<function> will act more or
1732 * less like top-level non-bus devices: they will either create or
1733 * accept a libxl_devid which will be unique within the
1734 * <class><level0> libxl_devid namespace.
1735 *
1736 * Lower-level devices must have a unique way to be identified. One
1737 * way to do this would be to name it via the name of the next level
1738 * up plus an index; for instance, <ctrl devid, port number>. Another
1739 * way would be to have another devid namespace for that level. This
1740 * identifier will be used for queries and removals.
1741 *
1742 * Lower-level devices will include in their
1743 * libxl_device_<class><level> struct a field referring to the unique
1744 * index of the level above. For instance, libxl_device_usbdev might
1745 * contain the controller devid.
1746 *
1747 * In the case where there are multiple different ways to implement a
1748 * given device -- for instance, one which is fully PV and one which
1749 * uses an emulator -- the controller will contain a field which
1750 * specifies what type of implementation is used. The implementations
1751 * of individual devices will be known by the controller to which they
1752 * are attached.
1753 *
1754 * If libxl_device_<class><level>_add receives an empty reference to
1755 * the level above, it may return an error. Or it may (but is not
1756 * required to) automatically choose a suitable device in the level
1757 * above to which to attach the new device at this level. It may also
1758 * (but is not required to) automatically create a new device at the
1759 * level above if no suitable devices exist. Each class should
1760 * document its behavior.
1761 *
1762 * libxl_device_<class><level>_list will list all devices of <class>
1763 * at <level> in the domain. For example, libxl_device_usbctrl_list
1764 * will list all usb controllers; libxl_class_usbdev_list will list
1765 * all usb devices across all controllers.
1766 *
1767 * For each class, the domain config file will contain a single list
1768 * for each level. libxl will first iterate through the list of
1769 * top-level devices, then iterate through each level down in turn,
1770 * adding devices to devices in the level above. For instance, there
1771 * will be one list for all usb controllers, and one list for all usb
1772 * devices.
1773 *
1774 * If libxl_device_<class><level>_add automatically creates
1775 * higher-level devices as necessary, then it is permissible for the
1776 * higher-level lists to be empty and the device list to have devices
1777 * with the field containing a reference to the higher level device
1778 * uninitialized.
1779 */
1780
1781 /* Disks */
1782 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
1783 libxl_device_disk *disk,
1784 const libxl_asyncop_how *ao_how)
1785 LIBXL_EXTERNAL_CALLERS_ONLY;
1786 int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
1787 libxl_device_disk *disk,
1788 const libxl_asyncop_how *ao_how)
1789 LIBXL_EXTERNAL_CALLERS_ONLY;
1790 int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid,
1791 libxl_device_disk *disk,
1792 const libxl_asyncop_how *ao_how)
1793 LIBXL_EXTERNAL_CALLERS_ONLY;
1794
1795 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx,
1796 uint32_t domid, int *num)
1797 LIBXL_EXTERNAL_CALLERS_ONLY;
1798 void libxl_device_disk_list_free(libxl_device_disk* list, int num)
1799 LIBXL_EXTERNAL_CALLERS_ONLY;
1800 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
1801 libxl_device_disk *disk, libxl_diskinfo *diskinfo)
1802 LIBXL_EXTERNAL_CALLERS_ONLY;
1803
1804 /*
1805 * Insert a CD-ROM device. A device corresponding to disk must already
1806 * be attached to the guest.
1807 */
1808 int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
1809 const libxl_asyncop_how *ao_how)
1810 LIBXL_EXTERNAL_CALLERS_ONLY;
1811
1812 /*
1813 * USB
1814 *
1815 * For each device removed or added, one of these protocols is available:
1816 * - PV (i.e., PVUSB)
1817 * - DEVICEMODEL (i.e, qemu)
1818 *
1819 * PV is available for either PV or HVM domains. DEVICEMODEL is only
1820 * available for HVM domains. The caller can additionally specify
1821 * "AUTO", in which case the library will try to determine the best
1822 * protocol automatically.
1823 *
1824 * At the moment, the only protocol implemented is PV.
1825 *
1826 * One can add/remove USB controllers to/from guest, and attach/detach USB
1827 * devices to/from USB controllers.
1828 *
1829 * To add USB controllers and USB devices, one can adding USB controllers
1830 * first and then attaching USB devices to some USB controller, or adding
1831 * USB devices to guest directly, it will automatically create a USB
1832 * controller for USB devices to attach.
1833 *
1834 * To remove USB controllers or USB devices, one can remove USB devices
1835 * under USB controller one by one and then remove USB controller, or
1836 * remove USB controller directly, it will remove all USB devices under
1837 * it automatically.
1838 *
1839 */
1840 /* USB Controllers*/
1841 int libxl_device_usbctrl_add(libxl_ctx *ctx, uint32_t domid,
1842 libxl_device_usbctrl *usbctrl,
1843 const libxl_asyncop_how *ao_how)
1844 LIBXL_EXTERNAL_CALLERS_ONLY;
1845
1846 int libxl_device_usbctrl_remove(libxl_ctx *ctx, uint32_t domid,
1847 libxl_device_usbctrl *usbctrl,
1848 const libxl_asyncop_how *ao_how)
1849 LIBXL_EXTERNAL_CALLERS_ONLY;
1850
1851 int libxl_device_usbctrl_destroy(libxl_ctx *ctx, uint32_t domid,
1852 libxl_device_usbctrl *usbctrl,
1853 const libxl_asyncop_how *ao_how)
1854 LIBXL_EXTERNAL_CALLERS_ONLY;
1855
1856 libxl_device_usbctrl *libxl_device_usbctrl_list(libxl_ctx *ctx,
1857 uint32_t domid, int *num);
1858
1859 void libxl_device_usbctrl_list_free(libxl_device_usbctrl *list, int nr);
1860
1861
1862 int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid,
1863 libxl_device_usbctrl *usbctrl,
1864 libxl_usbctrlinfo *usbctrlinfo);
1865
1866 /* USB Devices */
1867
1868 int libxl_device_usbdev_add(libxl_ctx *ctx, uint32_t domid,
1869 libxl_device_usbdev *usbdev,
1870 const libxl_asyncop_how *ao_how)
1871 LIBXL_EXTERNAL_CALLERS_ONLY;
1872
1873 int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid,
1874 libxl_device_usbdev *usbdev,
1875 const libxl_asyncop_how *ao_how)
1876 LIBXL_EXTERNAL_CALLERS_ONLY;
1877
1878 libxl_device_usbdev *
1879 libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num);
1880
1881 void libxl_device_usbdev_list_free(libxl_device_usbdev *list, int nr);
1882
1883 /* Network Interfaces */
1884 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic,
1885 const libxl_asyncop_how *ao_how)
1886 LIBXL_EXTERNAL_CALLERS_ONLY;
1887 int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
1888 libxl_device_nic *nic,
1889 const libxl_asyncop_how *ao_how)
1890 LIBXL_EXTERNAL_CALLERS_ONLY;
1891 int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid,
1892 libxl_device_nic *nic,
1893 const libxl_asyncop_how *ao_how)
1894 LIBXL_EXTERNAL_CALLERS_ONLY;
1895
1896 libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx,
1897 uint32_t domid, int *num)
1898 LIBXL_EXTERNAL_CALLERS_ONLY;
1899 void libxl_device_nic_list_free(libxl_device_nic* list, int num)
1900 LIBXL_EXTERNAL_CALLERS_ONLY;
1901 int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
1902 libxl_device_nic *nic, libxl_nicinfo *nicinfo)
1903 LIBXL_EXTERNAL_CALLERS_ONLY;
1904
1905 /*
1906 * Virtual Channels
1907 * Channels manifest as consoles with names, see docs/misc/channels.txt
1908 */
1909 libxl_device_channel *libxl_device_channel_list(libxl_ctx *ctx,
1910 uint32_t domid,
1911 int *num);
1912 int libxl_device_channel_getinfo(libxl_ctx *ctx, uint32_t domid,
1913 libxl_device_channel *channel,
1914 libxl_channelinfo *channelinfo);
1915
1916 /* Virtual TPMs */
1917 int libxl_device_vtpm_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vtpm *vtpm,
1918 const libxl_asyncop_how *ao_how)
1919 LIBXL_EXTERNAL_CALLERS_ONLY;
1920 int libxl_device_vtpm_remove(libxl_ctx *ctx, uint32_t domid,
1921 libxl_device_vtpm *vtpm,
1922 const libxl_asyncop_how *ao_how)
1923 LIBXL_EXTERNAL_CALLERS_ONLY;
1924 int libxl_device_vtpm_destroy(libxl_ctx *ctx, uint32_t domid,
1925 libxl_device_vtpm *vtpm,
1926 const libxl_asyncop_how *ao_how)
1927 LIBXL_EXTERNAL_CALLERS_ONLY;
1928
1929 libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx,
1930 uint32_t domid, int *num)
1931 LIBXL_EXTERNAL_CALLERS_ONLY;
1932 void libxl_device_vtpm_list_free(libxl_device_vtpm*, int num)
1933 LIBXL_EXTERNAL_CALLERS_ONLY;
1934 int libxl_device_vtpm_getinfo(libxl_ctx *ctx, uint32_t domid,
1935 libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo)
1936 LIBXL_EXTERNAL_CALLERS_ONLY;
1937
1938 /* Virtual displays */
1939 int libxl_device_vdispl_add(libxl_ctx *ctx, uint32_t domid,
1940 libxl_device_vdispl *displ,
1941 const libxl_asyncop_how *ao_how)
1942 LIBXL_EXTERNAL_CALLERS_ONLY;
1943 int libxl_device_vdispl_remove(libxl_ctx *ctx, uint32_t domid,
1944 libxl_device_vdispl *vdispl,
1945 const libxl_asyncop_how *ao_how)
1946 LIBXL_EXTERNAL_CALLERS_ONLY;
1947 int libxl_device_vdispl_destroy(libxl_ctx *ctx, uint32_t domid,
1948 libxl_device_vdispl *vdispl,
1949 const libxl_asyncop_how *ao_how)
1950 LIBXL_EXTERNAL_CALLERS_ONLY;
1951
1952 libxl_device_vdispl *libxl_device_vdispl_list(libxl_ctx *ctx,
1953 uint32_t domid, int *num)
1954 LIBXL_EXTERNAL_CALLERS_ONLY;
1955 void libxl_device_vdispl_list_free(libxl_device_vdispl* list, int num)
1956 LIBXL_EXTERNAL_CALLERS_ONLY;
1957 int libxl_device_vdispl_getinfo(libxl_ctx *ctx, uint32_t domid,
1958 libxl_device_vdispl *vdispl,
1959 libxl_vdisplinfo *vdisplinfo)
1960 LIBXL_EXTERNAL_CALLERS_ONLY;
1961
1962 /* Keyboard */
1963 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
1964 const libxl_asyncop_how *ao_how)
1965 LIBXL_EXTERNAL_CALLERS_ONLY;
1966 int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid,
1967 libxl_device_vkb *vkb,
1968 const libxl_asyncop_how *ao_how)
1969 LIBXL_EXTERNAL_CALLERS_ONLY;
1970 int libxl_device_vkb_destroy(libxl_ctx *ctx, uint32_t domid,
1971 libxl_device_vkb *vkb,
1972 const libxl_asyncop_how *ao_how)
1973 LIBXL_EXTERNAL_CALLERS_ONLY;
1974
1975 /* Framebuffer */
1976 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
1977 const libxl_asyncop_how *ao_how)
1978 LIBXL_EXTERNAL_CALLERS_ONLY;
1979 int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid,
1980 libxl_device_vfb *vfb,
1981 const libxl_asyncop_how *ao_how)
1982 LIBXL_EXTERNAL_CALLERS_ONLY;
1983 int libxl_device_vfb_destroy(libxl_ctx *ctx, uint32_t domid,
1984 libxl_device_vfb *vfb,
1985 const libxl_asyncop_how *ao_how)
1986 LIBXL_EXTERNAL_CALLERS_ONLY;
1987
1988 /* 9pfs */
1989 int libxl_device_p9_remove(libxl_ctx *ctx, uint32_t domid,
1990 libxl_device_p9 *p9,
1991 const libxl_asyncop_how *ao_how)
1992 LIBXL_EXTERNAL_CALLERS_ONLY;
1993 int libxl_device_p9_destroy(libxl_ctx *ctx, uint32_t domid,
1994 libxl_device_p9 *p9,
1995 const libxl_asyncop_how *ao_how)
1996 LIBXL_EXTERNAL_CALLERS_ONLY;
1997
1998 /* PCI Passthrough */
1999 int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid,
2000 libxl_device_pci *pcidev,
2001 const libxl_asyncop_how *ao_how)
2002 LIBXL_EXTERNAL_CALLERS_ONLY;
2003 int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid,
2004 libxl_device_pci *pcidev,
2005 const libxl_asyncop_how *ao_how)
2006 LIBXL_EXTERNAL_CALLERS_ONLY;
2007 int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid,
2008 libxl_device_pci *pcidev,
2009 const libxl_asyncop_how *ao_how)
2010 LIBXL_EXTERNAL_CALLERS_ONLY;
2011
2012 libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid,
2013 int *num);
2014
2015 /*
2016 * Turns the current process into a backend device service daemon
2017 * for a driver domain.
2018 *
2019 * From a libxl API point of view, this starts a long-running
2020 * operation. That operation consists of "being a driver domain"
2021 * and never completes.
2022 *
2023 * Attempting to abort this operation is not advisable; proper
2024 * shutdown of the driver domain task is not supported.
2025 */
2026 int libxl_device_events_handler(libxl_ctx *ctx,
2027 const libxl_asyncop_how *ao_how)
2028 LIBXL_EXTERNAL_CALLERS_ONLY;
2029
2030 /*
2031 * Functions related to making devices assignable -- that is, bound to
2032 * the pciback driver, ready to be given to a guest via
2033 * libxl_pci_device_add.
2034 *
2035 * - ..._add() will unbind the device from its current driver (if
2036 * already bound) and re-bind it to pciback; at that point it will be
2037 * ready to be assigned to a VM. If rebind is set, it will store the
2038 * path to the old driver in xenstore so that it can be handed back to
2039 * dom0 on restore.
2040 *
2041 * - ..._remove() will unbind the device from pciback, and if
2042 * rebind is non-zero, attempt to assign it back to the driver
2043 * from whence it came.
2044 *
2045 * - ..._list() will return a list of the PCI devices available to be
2046 * assigned.
2047 *
2048 * add and remove are idempotent: if the device in question is already
2049 * added or is not bound, the functions will emit a warning but return
2050 * SUCCESS.
2051 */
2052 int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pcidev, int rebind);
2053 int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *pcidev, int rebind);
2054 libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num);
2055
2056 /* CPUID handling */
2057 int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str);
2058 int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,
2059 const char* str);
2060 void libxl_cpuid_apply_policy(libxl_ctx *ctx, uint32_t domid);
2061 void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
2062 libxl_cpuid_policy_list cpuid);
2063
2064 /*
2065 * Functions for allowing users of libxl to store private data
2066 * relating to a domain. The data is an opaque sequence of bytes and
2067 * is not interpreted or used by libxl.
2068 *
2069 * Data is indexed by the userdata userid, which is a short printable
2070 * ASCII string. The following list is a registry of userdata userids
2071 * (the registry may be updated by posting a patch to xen-devel):
2072 *
2073 * userid Data contents
2074 * "xl" domain config file in xl format, Unix line endings
2075 * "libvirt-xml" domain config file in libvirt XML format. See
2076 * http://libvirt.org/formatdomain.html
2077 * "domain-userdata-lock" lock file to protect domain userdata in libxl.
2078 * It's a per-domain lock. Applications should
2079 * not touch this file.
2080 * "libxl-json" libxl_domain_config object in JSON format, generated
2081 * by libxl. Applications should not access this file
2082 * directly. This file is protected by domain-userdata-lock
2083 * for against Read-Modify-Write operation and domain
2084 * destruction.
2085 *
2086 * libxl does not enforce the registration of userdata userids or the
2087 * semantics of the data. For specifications of the data formats
2088 * see the code or documentation for the libxl caller in question.
2089 */
2090 int libxl_userdata_store(libxl_ctx *ctx, uint32_t domid,
2091 const char *userdata_userid,
2092 const uint8_t *data, int datalen)
2093 LIBXL_EXTERNAL_CALLERS_ONLY;
2094 /* If datalen==0, data is not used and the user data for
2095 * that domain and userdata_userid is deleted. */
2096 int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,
2097 const char *userdata_userid,
2098 uint8_t **data_r, int *datalen_r)
2099 LIBXL_EXTERNAL_CALLERS_ONLY;
2100 /* On successful return, *data_r is from malloc.
2101 * If there is no data for that domain and userdata_userid,
2102 * *data_r and *datalen_r will be set to 0.
2103 * data_r and datalen_r may be 0.
2104 * On error return, *data_r and *datalen_r are undefined.
2105 */
2106 int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
2107 const char *userdata_userid);
2108
2109
2110 int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
2111 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
2112 const libxl_bitmap *cpumap_hard,
2113 const libxl_bitmap *cpumap_soft);
2114 int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid,
2115 uint32_t vcpuid,
2116 const libxl_bitmap *cpumap_hard,
2117 const libxl_bitmap *cpumap_soft);
2118 int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
2119 unsigned int max_vcpus,
2120 const libxl_bitmap *cpumap_hard,
2121 const libxl_bitmap *cpumap_soft);
2122
2123 #if defined (LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040500
2124
2125 #define libxl_set_vcpuaffinity(ctx, domid, vcpuid, map) \
2126 libxl_set_vcpuaffinity((ctx), (domid), (vcpuid), (map), NULL)
2127 #define libxl_set_vcpuaffinity_all(ctx, domid, max_vcpus, map) \
2128 libxl_set_vcpuaffinity_all((ctx), (domid), (max_vcpus), (map), NULL)
2129
2130 #endif
2131
2132 int libxl_domain_set_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
2133 libxl_bitmap *nodemap);
2134 int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
2135 libxl_bitmap *nodemap);
2136 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap);
2137
2138 /* A return value less than 0 should be interpreted as a libxl_error, while a
2139 * return value greater than or equal to 0 should be interpreted as a
2140 * libxl_scheduler. */
2141 int libxl_get_scheduler(libxl_ctx *ctx);
2142
2143 /* Per-scheduler parameters */
2144 int libxl_sched_credit_params_get(libxl_ctx *ctx, uint32_t poolid,
2145 libxl_sched_credit_params *scinfo);
2146 int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
2147 libxl_sched_credit_params *scinfo);
2148 int libxl_sched_credit2_params_get(libxl_ctx *ctx, uint32_t poolid,
2149 libxl_sched_credit2_params *scinfo);
2150 int libxl_sched_credit2_params_set(libxl_ctx *ctx, uint32_t poolid,
2151 libxl_sched_credit2_params *scinfo);
2152
2153 /* Scheduler Per-domain parameters */
2154
2155 #define LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT -1
2156 #define LIBXL_DOMAIN_SCHED_PARAM_CAP_DEFAULT -1
2157 #define LIBXL_DOMAIN_SCHED_PARAM_PERIOD_DEFAULT -1
2158 #define LIBXL_DOMAIN_SCHED_PARAM_SLICE_DEFAULT -1
2159 #define LIBXL_DOMAIN_SCHED_PARAM_LATENCY_DEFAULT -1
2160 #define LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT -1
2161 #define LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT -1
2162
2163 /* Per-VCPU parameters */
2164 #define LIBXL_SCHED_PARAM_VCPU_INDEX_DEFAULT -1
2165
2166 /* Get the per-domain scheduling parameters.
2167 * For schedulers that support per-vcpu settings (e.g., RTDS),
2168 * calling *_domain_get functions will get default scheduling
2169 * parameters.
2170 */
2171 int libxl_domain_sched_params_get(libxl_ctx *ctx, uint32_t domid,
2172 libxl_domain_sched_params *params);
2173
2174 /* Set the per-domain scheduling parameters.
2175 * For schedulers that support per-vcpu settings (e.g., RTDS),
2176 * calling *_domain_set functions will set all vcpus with the same
2177 * scheduling parameters.
2178 */
2179 int libxl_domain_sched_params_set(libxl_ctx *ctx, uint32_t domid,
2180 const libxl_domain_sched_params *params);
2181
2182 /* Get the per-vcpu scheduling parameters */
2183 int libxl_vcpu_sched_params_get(libxl_ctx *ctx, uint32_t domid,
2184 libxl_vcpu_sched_params *params);
2185
2186 /* Get the per-vcpu scheduling parameters of all vcpus of a domain */
2187 int libxl_vcpu_sched_params_get_all(libxl_ctx *ctx, uint32_t domid,
2188 libxl_vcpu_sched_params *params);
2189
2190 /* Set the per-vcpu scheduling parameters */
2191 int libxl_vcpu_sched_params_set(libxl_ctx *ctx, uint32_t domid,
2192 const libxl_vcpu_sched_params *params);
2193
2194 /* Set the per-vcpu scheduling parameters of all vcpus of a domain */
2195 int libxl_vcpu_sched_params_set_all(libxl_ctx *ctx, uint32_t domid,
2196 const libxl_vcpu_sched_params *params);
2197
2198 int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
2199 libxl_trigger trigger, uint32_t vcpuid);
2200 int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
2201 int libxl_send_debug_keys(libxl_ctx *ctx, char *keys);
2202 int libxl_set_parameters(libxl_ctx *ctx, char *params);
2203
2204 typedef struct libxl__xen_console_reader libxl_xen_console_reader;
2205
2206 libxl_xen_console_reader *
2207 libxl_xen_console_read_start(libxl_ctx *ctx, int clear);
2208 int libxl_xen_console_read_line(libxl_ctx *ctx,
2209 libxl_xen_console_reader *cr,
2210 char **line_r);
2211 void libxl_xen_console_read_finish(libxl_ctx *ctx,
2212 libxl_xen_console_reader *cr);
2213
2214 uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid);
2215
2216 char *libxl_tmem_list(libxl_ctx *ctx, uint32_t domid, int use_long);
2217 int libxl_tmem_freeze(libxl_ctx *ctx, uint32_t domid);
2218 int libxl_tmem_thaw(libxl_ctx *ctx, uint32_t domid);
2219 int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name,
2220 uint32_t set);
2221 int libxl_tmem_shared_auth(libxl_ctx *ctx, uint32_t domid, char* uuid,
2222 int auth);
2223 int libxl_tmem_freeable(libxl_ctx *ctx);
2224
2225 int libxl_get_freecpus(libxl_ctx *ctx, libxl_bitmap *cpumap);
2226
2227 /*
2228 * Set poolid to LIBXL_CPUOOL_POOLID_ANY to have Xen choose a
2229 * free poolid for you.
2230 */
2231 #define LIBXL_CPUPOOL_POOLID_ANY 0xFFFFFFFF
2232 int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
2233 libxl_scheduler sched,
2234 libxl_bitmap cpumap, libxl_uuid *uuid,
2235 uint32_t *poolid);
2236 int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid);
2237 int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid);
2238 int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu);
2239 int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
2240 int libxl_cpupool_cpuadd_cpumap(libxl_ctx *ctx, uint32_t poolid,
2241 const libxl_bitmap *cpumap);
2242 int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu);
2243 int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
2244 int libxl_cpupool_cpuremove_cpumap(libxl_ctx *ctx, uint32_t poolid,
2245 const libxl_bitmap *cpumap);
2246 int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid);
2247 int libxl_cpupool_info(libxl_ctx *ctx, libxl_cpupoolinfo *info, uint32_t poolid);
2248
2249 int libxl_domid_valid_guest(uint32_t domid);
2250
2251 int libxl_flask_context_to_sid(libxl_ctx *ctx, char *buf, size_t len,
2252 uint32_t *ssidref);
2253 int libxl_flask_sid_to_context(libxl_ctx *ctx, uint32_t ssidref, char **buf,
2254 size_t *len);
2255 int libxl_flask_getenforce(libxl_ctx *ctx);
2256 int libxl_flask_setenforce(libxl_ctx *ctx, int mode);
2257 int libxl_flask_loadpolicy(libxl_ctx *ctx, void *policy, uint32_t size);
2258
2259 int libxl_ms_vm_genid_generate(libxl_ctx *ctx, libxl_ms_vm_genid *id);
2260 bool libxl_ms_vm_genid_is_zero(const libxl_ms_vm_genid *id);
2261 void libxl_ms_vm_genid_copy(libxl_ctx *ctx, libxl_ms_vm_genid *dst,
2262 const libxl_ms_vm_genid *src);
2263
2264 #if defined(__i386__) || defined(__x86_64__)
2265 int libxl_psr_cmt_attach(libxl_ctx *ctx, uint32_t domid);
2266 int libxl_psr_cmt_detach(libxl_ctx *ctx, uint32_t domid);
2267 int libxl_psr_cmt_domain_attached(libxl_ctx *ctx, uint32_t domid);
2268 int libxl_psr_cmt_enabled(libxl_ctx *ctx);
2269 int libxl_psr_cmt_get_total_rmid(libxl_ctx *ctx, uint32_t *total_rmid);
2270 int libxl_psr_cmt_get_l3_cache_size(libxl_ctx *ctx,
2271 uint32_t socketid,
2272 uint32_t *l3_cache_size);
2273 int libxl_psr_cmt_get_cache_occupancy(libxl_ctx *ctx,
2274 uint32_t domid,
2275 uint32_t socketid,
2276 uint32_t *l3_cache_occupancy);
2277
2278 int libxl_psr_cmt_type_supported(libxl_ctx *ctx, libxl_psr_cmt_type type);
2279 int libxl_psr_cmt_get_sample(libxl_ctx *ctx,
2280 uint32_t domid,
2281 libxl_psr_cmt_type type,
2282 uint64_t scope,
2283 uint64_t *sample_r,
2284 uint64_t *tsc_r);
2285
2286 /*
2287 * Function to set a domain's cbm. It operates on a single or multiple
2288 * target(s) defined in 'target_map'. The definition of 'target_map' is
2289 * related to 'type':
2290 * 'L3_CBM': 'target_map' specifies all the sockets to be operated on.
2291 */
2292 int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid,
2293 libxl_psr_cbm_type type, libxl_bitmap *target_map,
2294 uint64_t cbm);
2295 /*
2296 * Function to get a domain's cbm. It operates on a single 'target'.
2297 * The definition of 'target' is related to 'type':
2298 * 'L3_CBM': 'target' specifies which socket to be operated on.
2299 */
2300 int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
2301 libxl_psr_cbm_type type, uint32_t target,
2302 uint64_t *cbm_r);
2303
2304 /*
2305 * On success, the function returns an array of elements in 'info',
2306 * and the length in 'nr'.
2307 */
2308 int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
2309 unsigned int *nr, unsigned int lvl);
2310 int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
2311 int *nr);
2312 void libxl_psr_cat_info_list_free(libxl_psr_cat_info *list, int nr);
2313 #endif
2314
2315 /* misc */
2316
2317 /* Each of these sets or clears the flag according to whether the
2318 * 2nd parameter is nonzero. On failure, they log, and
2319 * return ERROR_FAIL, but also leave errno valid. */
2320 int libxl_fd_set_cloexec(libxl_ctx *ctx, int fd, int cloexec);
2321 int libxl_fd_set_nonblock(libxl_ctx *ctx, int fd, int nonblock);
2322
2323 /*
2324 * Issue a qmp monitor command to the device model of the specified domain.
2325 * The function returns the output of the command in a new allocated buffer
2326 * via output.
2327 */
2328 int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid,
2329 const char *command_line, char **output);
2330
2331 #include <libxl_event.h>
2332
2333 #endif /* LIBXL_H */
2334
2335 /*
2336 * Local variables:
2337 * mode: C
2338 * c-basic-offset: 4
2339 * indent-tabs-mode: nil
2340 * End:
2341 */
2342