debuggers.hg

view tools/libxl/libxl_internal.h @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents bdce1894c6a7
children 5993c6b9f4e5
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>
27 #include "flexarray.h"
28 #include "libxl_utils.h"
30 #define LIBXL_DESTROY_TIMEOUT 10
31 #define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
32 #define LIBXL_XENCONSOLE_LIMIT 1048576
33 #define LIBXL_XENCONSOLE_PROTOCOL "vt100"
34 #define LIBXL_MAXMEM_CONSTANT 1024
35 #define QEMU_SIGNATURE "QemuDeviceModelRecord"
37 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
39 #define XL_LOGGING_ENABLED
41 #ifdef XL_LOGGING_ENABLED
42 #define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a)
43 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a)
44 #define XL_LOG_ERRNOVAL(ctx, errnoval, loglevel, _f, _a...) xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
45 #else
46 #define XL_LOG(ctx, loglevel, _f, _a...)
47 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)
48 #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
49 #endif
51 #define XL_LOG_DEBUG 3
52 #define XL_LOG_INFO 2
53 #define XL_LOG_WARNING 1
54 #define XL_LOG_ERROR 0
56 /* logging */
57 void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
58 void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...);
61 typedef enum {
62 DEVICE_VIF = 1,
63 DEVICE_VBD,
64 DEVICE_TAP,
65 DEVICE_PCI,
66 DEVICE_VFB,
67 DEVICE_VKBD,
68 DEVICE_CONSOLE,
69 } libxl_device_kinds;
71 #define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE))
73 typedef struct {
74 uint32_t backend_devid;
75 uint32_t backend_domid;
76 uint32_t devid;
77 uint32_t domid;
78 libxl_device_kinds backend_kind;
79 libxl_device_kinds kind;
80 } libxl_device;
82 #define XC_PCI_BDF "0x%x, 0x%x, 0x%x, 0x%x"
83 #define AUTO_PHP_SLOT 0x100
84 #define SYSFS_PCI_DEV "/sys/bus/pci/devices"
85 #define PROC_PCI_NUM_RESOURCES 7
86 #define PCI_BAR_IO 0x01
88 #define PRINTF_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
90 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
91 #define string_of_uuid(ctx, u) \
92 libxl_sprintf(ctx, UUID_FMT, \
93 (u)[0], (u)[1], (u)[2], (u)[3], (u)[4], (u)[5], (u)[6], (u)[7], \
94 (u)[8], (u)[9], (u)[10], (u)[11], (u)[12], (u)[13], (u)[14], (u)[15])
96 int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]);
98 /* memory allocation tracking/helpers */
99 int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr);
100 int libxl_free(struct libxl_ctx *ctx, void *ptr);
101 int libxl_free_all(struct libxl_ctx *ctx);
102 void *libxl_zalloc(struct libxl_ctx *ctx, int bytes);
103 void *libxl_calloc(struct libxl_ctx *ctx, size_t nmemb, size_t size);
104 char *libxl_sprintf(struct libxl_ctx *ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
105 char *libxl_dirname(struct libxl_ctx *ctx, const char *s);
107 char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, int length);
108 int libxl_xs_writev(struct libxl_ctx *ctx, xs_transaction_t t,
109 char *dir, char **kvs);
110 int libxl_xs_write(struct libxl_ctx *ctx, xs_transaction_t t,
111 char *path, char *fmt, ...);
112 char *libxl_xs_get_dompath(struct libxl_ctx *ctx, uint32_t domid); // logs errs
113 char *libxl_xs_read(struct libxl_ctx *ctx, xs_transaction_t t, char *path);
114 char **libxl_xs_directory(struct libxl_ctx *ctx, xs_transaction_t t, char *path, unsigned int *nb);
116 /* from xl_dom */
117 int is_hvm(struct libxl_ctx *ctx, uint32_t domid);
118 int get_shutdown_reason(struct libxl_ctx *ctx, uint32_t domid);
119 #define dominfo_get_shutdown_reason(info) (((info)->flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask)
121 int build_pre(struct libxl_ctx *ctx, uint32_t domid,
122 libxl_domain_build_info *info, libxl_domain_build_state *state);
123 int build_post(struct libxl_ctx *ctx, uint32_t domid,
124 libxl_domain_build_info *info, libxl_domain_build_state *state,
125 char **vms_ents, char **local_ents);
127 int build_pv(struct libxl_ctx *ctx, uint32_t domid,
128 libxl_domain_build_info *info, libxl_domain_build_state *state);
129 int build_hvm(struct libxl_ctx *ctx, uint32_t domid,
130 libxl_domain_build_info *info, libxl_domain_build_state *state);
132 int restore_common(struct libxl_ctx *ctx, uint32_t domid,
133 libxl_domain_build_info *info, libxl_domain_build_state *state, int fd);
134 int core_suspend(struct libxl_ctx *ctx, uint32_t domid, int fd, int hvm, int live, int debug);
135 int save_device_model(struct libxl_ctx *ctx, uint32_t domid, int fd);
137 /* from xl_device */
138 char *device_disk_backend_type_of_phystype(libxl_disk_phystype phystype);
139 char *device_disk_string_of_phystype(libxl_disk_phystype phystype);
141 int device_physdisk_major_minor(char *physpath, int *major, int *minor);
142 int device_disk_dev_number(char *virtpath);
144 int libxl_device_generic_add(struct libxl_ctx *ctx, libxl_device *device,
145 char **bents, char **fents);
146 int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait);
147 int libxl_device_destroy(struct libxl_ctx *ctx, char *be_path, int force);
148 int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
149 int libxl_wait_for_device_model(struct libxl_ctx *ctx,
150 uint32_t domid, char *state,
151 int (*check_callback)(struct libxl_ctx *ctx,
152 void *userdata),
153 void *check_callback_userdata);
154 int libxl_wait_for_backend(struct libxl_ctx *ctx, char *be_path, char *state);
155 int libxl_device_pci_flr(struct libxl_ctx *ctx, unsigned int domain, unsigned int bus,
156 unsigned int dev, unsigned int func);
158 /* from xenguest (helper */
159 int hvm_build_set_params(int handle, uint32_t domid,
160 int apic, int acpi, int pae, int nx, int viridian,
161 int vcpus, int store_evtchn, unsigned long *store_mfn);
163 /* xl_exec */
165 /* higher-level double-fork and separate detach eg as for device models */
167 struct libxl_spawn_starting {
168 /* put this in your own stateu structure as returned to application */
169 /* all fields are private to libxl_spawn_... */
170 pid_t intermediate;
171 char *what; /* malloc'd in spawn_spawn */
172 };
174 struct libxl_device_model_starting {
175 struct libxl_spawn_starting *for_spawn; /* first! */
176 char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
177 int domid;
178 };
180 int libxl_spawn_spawn(struct libxl_ctx *ctx,
181 libxl_device_model_starting *starting,
182 const char *what,
183 void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
184 /* Logs errors. A copy of "what" is taken. Return values:
185 * < 0 error, for_spawn need not be detached
186 * +1 caller is now the inner child, should probably call libxl_exec
187 * 0 caller is the parent, must call detach on *for_spawn eventually
188 * Caller, may pass 0 for for_spawn, in which case no need to detach.
189 */
190 int libxl_spawn_detach(struct libxl_ctx *ctx,
191 struct libxl_spawn_starting *for_spawn);
192 /* Logs errors. Idempotent, but only permitted after successful
193 * call to libxl_spawn_spawn, and no point calling it again if it fails. */
194 int libxl_spawn_check(struct libxl_ctx *ctx,
195 void *for_spawn);
196 /* Logs errors but also returns them.
197 * for_spawn must actually be a struct libxl_spawn_starting* but
198 * we take void* so you can pass this function directly to
199 * libxl_wait_for_device_model. Caller must still call detach. */
201 /* low-level stuff, for synchronous subprocesses etc. */
203 void libxl_exec(int stdinfd, int stdoutfd, int stderrfd, char *arg0, char **args); // logs errors, never returns
204 void libxl_log_child_exitstatus(struct libxl_ctx *ctx,
205 const char *what, pid_t pid, int status);
207 #endif