debuggers.hg

view tools/libxl/libxl_internal.h @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents b59f04eb8978
children eefb8e971be5
line source
1 /*
2 * Copyright (C) 2009 Citrix Ltd.
3 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
4 * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; version 2.1 only. with the special
9 * exception on linking described in file LICENSE.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 */
17 #ifndef LIBXL_INTERNAL_H
18 #define LIBXL_INTERNAL_H
20 #include <stdint.h>
21 #include <stdarg.h>
22 #include <stdlib.h>
24 #include <xs.h>
25 #include <xenctrl.h>
26 #include "xentoollog.h"
28 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
29 #define _hidden __attribute__((visibility("hidden")))
30 #define _protected __attribute__((visibility("protected")))
31 #else
32 #define _hidden
33 #define _protected
34 #endif
36 #include "flexarray.h"
37 #include "libxl_utils.h"
39 #define LIBXL_DESTROY_TIMEOUT 10
40 #define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
41 #define LIBXL_XENCONSOLE_LIMIT 1048576
42 #define LIBXL_XENCONSOLE_PROTOCOL "vt100"
43 #define LIBXL_MAXMEM_CONSTANT 1024
44 #define LIBXL_PV_EXTRA_MEMORY 1024
45 #define LIBXL_HVM_EXTRA_MEMORY 2048
46 #define LIBXL_MIN_DOM0_MEM (128*1024)
47 #define QEMU_SIGNATURE "DeviceModelRecord0002"
48 #define STUBDOM_CONSOLE_LOGGING 0
49 #define STUBDOM_CONSOLE_SAVE 1
50 #define STUBDOM_CONSOLE_RESTORE 2
51 #define STUBDOM_CONSOLE_SERIAL 3
52 #define STUBDOM_SPECIAL_CONSOLES 3
53 #define SAVEFILE "/var/lib/xen/qemu-save"
55 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
57 #define LIBXL__LOGGING_ENABLED
59 #ifdef LIBXL__LOGGING_ENABLED
60 #define LIBXL__LOG(ctx, loglevel, _f, _a...) libxl__log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a)
61 #define LIBXL__LOG_ERRNO(ctx, loglevel, _f, _a...) libxl__log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a)
62 #define LIBXL__LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...) libxl__log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
63 #else
64 #define LIBXL__LOG(ctx, loglevel, _f, _a...)
65 #define LIBXL__LOG_ERRNO(ctx, loglevel, _f, _a...)
66 #define LIBXL__LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
67 #endif
68 /* all of these macros preserve errno (saving and restoring) */
70 /* logging */
71 _hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
72 const char *file /* may be 0 */, int line /* ignored if !file */,
73 const char *func /* may be 0 */,
74 char *fmt, va_list al)
75 __attribute__((format(printf,7,0)));
77 _hidden void libxl__log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
78 const char *file /* may be 0 */, int line /* ignored if !file */,
79 const char *func /* may be 0 */,
80 char *fmt, ...)
81 __attribute__((format(printf,7,8)));
83 /* these functions preserve errno (saving and restoring) */
86 typedef enum {
87 DEVICE_VIF = 1,
88 DEVICE_VIF2,
89 DEVICE_VBD,
90 DEVICE_TAP,
91 DEVICE_QDISK,
92 DEVICE_PCI,
93 DEVICE_VFB,
94 DEVICE_VKBD,
95 DEVICE_CONSOLE,
96 } libxl__device_kinds;
98 #define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE))
100 typedef struct {
101 uint32_t backend_devid;
102 uint32_t backend_domid;
103 uint32_t devid;
104 uint32_t domid;
105 libxl__device_kinds backend_kind;
106 libxl__device_kinds kind;
107 } libxl__device;
109 #define XC_PCI_BDF "0x%x, 0x%x, 0x%x, 0x%x"
110 #define AUTO_PHP_SLOT 0x100
111 #define SYSFS_PCI_DEV "/sys/bus/pci/devices"
112 #define SYSFS_PCIBACK_DRIVER "/sys/bus/pci/drivers/pciback"
114 #define PROC_PCI_NUM_RESOURCES 7
115 #define PCI_BAR_IO 0x01
117 #define PRINTF_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
119 typedef struct {
120 /* mini-GC */
121 int alloc_maxsize;
122 void **alloc_ptrs;
123 libxl_ctx *owner;
124 } libxl__gc;
126 #define LIBXL_INIT_GC(ctx) (libxl__gc){ .alloc_maxsize = 0, .alloc_ptrs = 0, .owner = ctx }
127 static inline libxl_ctx *libxl__gc_owner(libxl__gc *gc)
128 {
129 return gc->owner;
130 }
132 /* memory allocation tracking/helpers */
133 _hidden int libxl__ptr_add(libxl__gc *gc, void *ptr);
134 _hidden void libxl__free_all(libxl__gc *gc);
135 _hidden void *libxl__zalloc(libxl__gc *gc, int bytes);
136 _hidden void *libxl__calloc(libxl__gc *gc, size_t nmemb, size_t size);
137 _hidden char *libxl__sprintf(libxl__gc *gc, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
138 _hidden char *libxl__strdup(libxl__gc *gc, const char *c);
139 _hidden char *libxl__dirname(libxl__gc *gc, const char *s);
141 _hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length);
142 _hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
143 char *dir, char **kvs);
144 _hidden int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
145 char *path, char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
146 _hidden char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid); // logs errs
147 _hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path);
148 _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char *path, unsigned int *nb);
150 /* from xl_dom */
151 _hidden int libxl__domain_is_hvm(libxl_ctx *ctx, uint32_t domid);
152 _hidden int libxl__domain_shutdown_reason(libxl_ctx *ctx, uint32_t domid);
154 _hidden int libxl__build_pre(libxl_ctx *ctx, uint32_t domid,
155 libxl_domain_build_info *info, libxl_domain_build_state *state);
156 _hidden int libxl__build_post(libxl_ctx *ctx, uint32_t domid,
157 libxl_domain_build_info *info, libxl_domain_build_state *state,
158 char **vms_ents, char **local_ents);
160 _hidden int libxl__build_pv(libxl_ctx *ctx, uint32_t domid,
161 libxl_domain_build_info *info, libxl_domain_build_state *state);
162 _hidden int libxl__build_hvm(libxl_ctx *ctx, uint32_t domid,
163 libxl_domain_build_info *info, libxl_domain_build_state *state);
165 _hidden int libxl__domain_restore_common(libxl_ctx *ctx, uint32_t domid,
166 libxl_domain_build_info *info, libxl_domain_build_state *state, int fd);
167 _hidden int libxl__domain_suspend_common(libxl_ctx *ctx, uint32_t domid, int fd, int hvm, int live, int debug);
168 _hidden int libxl__domain_save_device_model(libxl_ctx *ctx, uint32_t domid, int fd);
169 _hidden void libxl__userdata_destroyall(libxl_ctx *ctx, uint32_t domid);
171 /* from xl_device */
172 _hidden char *libxl__device_disk_backend_type_of_phystype(libxl_disk_phystype phystype);
173 _hidden char *libxl__device_disk_string_of_phystype(libxl_disk_phystype phystype);
175 _hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor);
176 _hidden int libxl__device_disk_dev_number(char *virtpath);
178 _hidden int libxl__device_generic_add(libxl_ctx *ctx, libxl__device *device,
179 char **bents, char **fents);
180 _hidden int libxl__device_del(libxl_ctx *ctx, libxl__device *dev, int wait);
181 _hidden int libxl__device_destroy(libxl_ctx *ctx, char *be_path, int force);
182 _hidden int libxl__devices_destroy(libxl_ctx *ctx, uint32_t domid, int force);
183 _hidden int libxl__wait_for_device_model(libxl_ctx *ctx,
184 uint32_t domid, char *state,
185 int (*check_callback)(libxl_ctx *ctx,
186 uint32_t domid,
187 const char *state,
188 void *userdata),
189 void *check_callback_userdata);
190 _hidden int libxl__wait_for_backend(libxl_ctx *ctx, char *be_path, char *state);
192 /* xl_exec */
194 /* higher-level double-fork and separate detach eg as for device models */
196 typedef struct {
197 /* put this in your own status structure as returned to application */
198 /* all fields are private to libxl_spawn_... */
199 pid_t intermediate;
200 char *what; /* malloc'd in spawn_spawn */
201 } libxl__spawn_starting;
203 typedef struct {
204 libxl__spawn_starting *for_spawn; /* first! */
205 char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
206 int domid;
207 } libxl__device_model_starting;
209 /* from xl_create */
210 _hidden int libxl__domain_make(libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid);
211 _hidden int libxl__domain_build(libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
213 /* for device model creation */
214 _hidden int libxl__create_device_model(libxl_ctx *ctx,
215 libxl_device_model_info *info,
216 libxl_device_disk *disk, int num_disks,
217 libxl_device_nic *vifs, int num_vifs,
218 libxl__device_model_starting **starting_r);
219 _hidden int libxl__create_xenpv_qemu(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
220 libxl__device_model_starting **starting_r);
221 _hidden int libxl__need_xenpv_qemu(libxl_ctx *ctx,
222 int nr_consoles, libxl_device_console *consoles,
223 int nr_vfbs, libxl_device_vfb *vfbs,
224 int nr_disks, libxl_device_disk *disks);
226 /* Caller must either: pass starting_r==0, or on successful
227 * return pass *starting_r (which will be non-0) to
228 * libxl_confirm_device_model or libxl_detach_device_model. */
229 _hidden int libxl__confirm_device_model_startup(libxl_ctx *ctx,
230 libxl__device_model_starting *starting);
232 _hidden int libxl__spawn_spawn(libxl_ctx *ctx,
233 libxl__device_model_starting *starting,
234 const char *what,
235 void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
236 _hidden int libxl__destroy_device_model(libxl_ctx *ctx, uint32_t domid);
238 /* Logs errors. A copy of "what" is taken. Return values:
239 * < 0 error, for_spawn need not be detached
240 * +1 caller is the parent, must call detach on *for_spawn eventually
241 * 0 caller is now the inner child, should probably call libxl__exec
242 * Caller, may pass 0 for for_spawn, in which case no need to detach.
243 */
244 _hidden int libxl__spawn_detach(libxl_ctx *ctx,
245 libxl__spawn_starting *for_spawn);
246 /* Logs errors. Idempotent, but only permitted after successful
247 * call to libxl__spawn_spawn, and no point calling it again if it fails. */
248 _hidden int libxl__spawn_check(libxl_ctx *ctx,
249 void *for_spawn);
250 /* Logs errors but also returns them.
251 * for_spawn must actually be a libxl__spawn_starting* but
252 * we take void* so you can pass this function directly to
253 * libxl__wait_for_device_model. Caller must still call detach. */
255 /* low-level stuff, for synchronous subprocesses etc. */
257 _hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd,
258 const char *arg0, char **args); // logs errors, never returns
259 _hidden void libxl__log_child_exitstatus(libxl__gc *gc,
260 const char *what, pid_t pid, int status);
262 _hidden char *libxl__abs_path(libxl__gc *gc, char *s, const char *path);
264 #define LIBXL__LOG_DEBUG XTL_DEBUG
265 #define LIBXL__LOG_INFO XTL_INFO
266 #define LIBXL__LOG_WARNING XTL_WARN
267 #define LIBXL__LOG_ERROR XTL_ERROR
269 _hidden char *libxl__domid_to_name(libxl__gc *gc, uint32_t domid);
270 _hidden char *libxl__cpupoolid_to_name(libxl__gc *gc, uint32_t poolid);
273 /* holds the CPUID response for a single CPUID leaf
274 * input contains the value of the EAX and ECX register,
275 * and each policy string contains a filter to apply to
276 * the host given values for that particular leaf.
277 */
278 struct libxl__cpuid_policy {
279 uint32_t input[2];
280 char *policy[4];
281 };
283 /*
284 * blktap2 support
285 */
287 /* libxl__blktap_enabled:
288 * return true if blktap/blktap2 support is available.
289 */
290 _hidden int libxl__blktap_enabled(libxl__gc *gc);
292 /* libxl__blktap_devpath:
293 * Argument: path and disk image as specified in config file.
294 * The type specifies whether this is aio, qcow, qcow2, etc.
295 * returns device path xenstore wants to have. returns NULL
296 * if no device corresponds to the disk.
297 */
298 _hidden const char *libxl__blktap_devpath(libxl__gc *gc,
299 const char *disk,
300 libxl_disk_phystype phystype);
302 _hidden char *libxl__uuid2string(libxl__gc *gc, const libxl_uuid uuid);
304 struct libxl__xen_console_reader {
305 char *buffer;
306 unsigned int size;
307 unsigned int count;
308 unsigned int clear;
309 unsigned int incremental;
310 unsigned int index;
311 };
313 _hidden int libxl__error_set(libxl_ctx *ctx, int code);
315 _hidden int libxl__file_reference_map(libxl_file_reference *f);
316 _hidden int libxl__file_reference_unmap(libxl_file_reference *f);
318 #endif