debuggers.hg

view tools/libxl/libxl_internal.h @ 21965:20540b8fe4b6

xl: detect pci-insert-failed dm status on pci-passthrough

NOTE: This functionality depends on a corresponding qemu-dm patch to work as
expected. Should be safe to use with an un-patched qemu-dm as before.

libxl_wait_for_device_model can only wait for one status value, re-work the
API so that a callback function can chose between several different possible
status values for qemu-dm and fix up all callers appropriately.

In the case of PCI device insert we succeed if qemu-dm reports
"pci-device-inserted" and error out instead of hanging forever if it fails
since qemu-dm now reports a status of "pci-insert-failed".

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Gianni Tedesco <gianni.tedesco@citrix.com>
date Wed Aug 04 14:43:46 2010 +0100 (2010-08-04)
parents 9ced33b68bd8
children 6b28b2dac7dd
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 #include "flexarray.h"
29 #include "libxl_utils.h"
31 #define LIBXL_DESTROY_TIMEOUT 10
32 #define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
33 #define LIBXL_XENCONSOLE_LIMIT 1048576
34 #define LIBXL_XENCONSOLE_PROTOCOL "vt100"
35 #define LIBXL_MAXMEM_CONSTANT 1024
36 #define QEMU_SIGNATURE "QemuDeviceModelRecord"
38 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
40 #define XL_LOGGING_ENABLED
42 #ifdef XL_LOGGING_ENABLED
43 #define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a)
44 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a)
45 #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...) xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
46 #else
47 #define XL_LOG(ctx, loglevel, _f, _a...)
48 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)
49 #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
50 #endif
51 /* all of these macros preserve errno (saving and restoring) */
53 /* logging */
54 void xl_logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
55 const char *file /* may be 0 */, int line /* ignored if !file */,
56 const char *func /* may be 0 */,
57 char *fmt, va_list al)
58 __attribute__((format(printf,7,0)));
60 void xl_log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
61 const char *file /* may be 0 */, int line /* ignored if !file */,
62 const char *func /* may be 0 */,
63 char *fmt, ...)
64 __attribute__((format(printf,7,8)));
66 /* these functions preserve errno (saving and restoring) */
69 typedef enum {
70 DEVICE_VIF = 1,
71 DEVICE_VIF2,
72 DEVICE_VBD,
73 DEVICE_TAP,
74 DEVICE_PCI,
75 DEVICE_VFB,
76 DEVICE_VKBD,
77 DEVICE_CONSOLE,
78 } libxl_device_kinds;
80 #define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE))
82 typedef struct {
83 uint32_t backend_devid;
84 uint32_t backend_domid;
85 uint32_t devid;
86 uint32_t domid;
87 libxl_device_kinds backend_kind;
88 libxl_device_kinds kind;
89 } libxl_device;
91 #define XC_PCI_BDF "0x%x, 0x%x, 0x%x, 0x%x"
92 #define AUTO_PHP_SLOT 0x100
93 #define SYSFS_PCI_DEV "/sys/bus/pci/devices"
94 #define SYSFS_PCIBACK_DRIVER "/sys/bus/pci/drivers/pciback"
96 #define PROC_PCI_NUM_RESOURCES 7
97 #define PCI_BAR_IO 0x01
99 #define PRINTF_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
101 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
102 #define string_of_uuid(ctx, u) \
103 libxl_sprintf(ctx, UUID_FMT, \
104 (u)[0], (u)[1], (u)[2], (u)[3], (u)[4], (u)[5], (u)[6], (u)[7], \
105 (u)[8], (u)[9], (u)[10], (u)[11], (u)[12], (u)[13], (u)[14], (u)[15])
107 int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]);
109 /* memory allocation tracking/helpers */
110 int libxl_ptr_add(libxl_ctx *ctx, void *ptr);
111 int libxl_free(libxl_ctx *ctx, void *ptr);
112 int libxl_free_all(libxl_ctx *ctx);
113 void *libxl_zalloc(libxl_ctx *ctx, int bytes);
114 void *libxl_calloc(libxl_ctx *ctx, size_t nmemb, size_t size);
115 char *libxl_sprintf(libxl_ctx *ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
116 char *libxl_strdup(libxl_ctx *ctx, const char *c);
117 char *libxl_dirname(libxl_ctx *ctx, const char *s);
119 char **libxl_xs_kvs_of_flexarray(libxl_ctx *ctx, flexarray_t *array, int length);
120 int libxl_xs_writev(libxl_ctx *ctx, xs_transaction_t t,
121 char *dir, char **kvs);
122 int libxl_xs_write(libxl_ctx *ctx, xs_transaction_t t,
123 char *path, char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
124 char *libxl_xs_get_dompath(libxl_ctx *ctx, uint32_t domid); // logs errs
125 char *libxl_xs_read(libxl_ctx *ctx, xs_transaction_t t, char *path);
126 char **libxl_xs_directory(libxl_ctx *ctx, xs_transaction_t t, char *path, unsigned int *nb);
128 /* from xl_dom */
129 int is_hvm(libxl_ctx *ctx, uint32_t domid);
130 int get_shutdown_reason(libxl_ctx *ctx, uint32_t domid);
131 #define dominfo_get_shutdown_reason(info) (((info)->flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask)
133 int build_pre(libxl_ctx *ctx, uint32_t domid,
134 libxl_domain_build_info *info, libxl_domain_build_state *state);
135 int build_post(libxl_ctx *ctx, uint32_t domid,
136 libxl_domain_build_info *info, libxl_domain_build_state *state,
137 char **vms_ents, char **local_ents);
139 int build_pv(libxl_ctx *ctx, uint32_t domid,
140 libxl_domain_build_info *info, libxl_domain_build_state *state);
141 int build_hvm(libxl_ctx *ctx, uint32_t domid,
142 libxl_domain_build_info *info, libxl_domain_build_state *state);
144 int restore_common(libxl_ctx *ctx, uint32_t domid,
145 libxl_domain_build_info *info, libxl_domain_build_state *state, int fd);
146 int core_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int hvm, int live, int debug);
147 int save_device_model(libxl_ctx *ctx, uint32_t domid, int fd);
148 void libxl__userdata_destroyall(libxl_ctx *ctx, uint32_t domid);
150 /* from xl_device */
151 char *device_disk_backend_type_of_phystype(libxl_disk_phystype phystype);
152 char *device_disk_string_of_phystype(libxl_disk_phystype phystype);
154 int device_physdisk_major_minor(const char *physpath, int *major, int *minor);
155 int device_disk_dev_number(char *virtpath);
157 int libxl_device_generic_add(libxl_ctx *ctx, libxl_device *device,
158 char **bents, char **fents);
159 int libxl_device_del(libxl_ctx *ctx, libxl_device *dev, int wait);
160 int libxl_device_destroy(libxl_ctx *ctx, char *be_path, int force);
161 int libxl_devices_destroy(libxl_ctx *ctx, uint32_t domid, int force);
162 int libxl_wait_for_device_model(libxl_ctx *ctx,
163 uint32_t domid, char *state,
164 int (*check_callback)(libxl_ctx *ctx,
165 uint32_t domid,
166 const char *state,
167 void *userdata),
168 void *check_callback_userdata);
169 int libxl_wait_for_backend(libxl_ctx *ctx, char *be_path, char *state);
170 int libxl_device_pci_reset(libxl_ctx *ctx, unsigned int domain, unsigned int bus,
171 unsigned int dev, unsigned int func);
173 /* from xenguest (helper */
174 int hvm_build_set_params(xc_interface *handle, uint32_t domid,
175 libxl_domain_build_info *info,
176 int store_evtchn, unsigned long *store_mfn);
178 /* xl_exec */
180 /* higher-level double-fork and separate detach eg as for device models */
182 typedef struct {
183 /* put this in your own status structure as returned to application */
184 /* all fields are private to libxl_spawn_... */
185 pid_t intermediate;
186 char *what; /* malloc'd in spawn_spawn */
187 } libxl_spawn_starting;
189 struct libxl_device_model_starting {
190 libxl_spawn_starting *for_spawn; /* first! */
191 char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
192 int domid;
193 };
195 int libxl_spawn_spawn(libxl_ctx *ctx,
196 libxl_device_model_starting *starting,
197 const char *what,
198 void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
199 /* Logs errors. A copy of "what" is taken. Return values:
200 * < 0 error, for_spawn need not be detached
201 * +1 caller is the parent, must call detach on *for_spawn eventually
202 * 0 caller is now the inner child, should probably call libxl_exec
203 * Caller, may pass 0 for for_spawn, in which case no need to detach.
204 */
205 int libxl_spawn_detach(libxl_ctx *ctx,
206 libxl_spawn_starting *for_spawn);
207 /* Logs errors. Idempotent, but only permitted after successful
208 * call to libxl_spawn_spawn, and no point calling it again if it fails. */
209 int libxl_spawn_check(libxl_ctx *ctx,
210 void *for_spawn);
211 /* Logs errors but also returns them.
212 * for_spawn must actually be a libxl_spawn_starting* but
213 * we take void* so you can pass this function directly to
214 * libxl_wait_for_device_model. Caller must still call detach. */
216 /* low-level stuff, for synchronous subprocesses etc. */
218 void libxl_exec(int stdinfd, int stdoutfd, int stderrfd, char *arg0, char **args); // logs errors, never returns
219 void libxl_log_child_exitstatus(libxl_ctx *ctx,
220 const char *what, pid_t pid, int status);
222 char *libxl_abs_path(libxl_ctx *ctx, char *s, const char *path);
224 #define XL_LOG_DEBUG XTL_DEBUG
225 #define XL_LOG_INFO XTL_INFO
226 #define XL_LOG_WARNING XTL_WARN
227 #define XL_LOG_ERROR XTL_ERROR
229 /* Error handling */
230 int libxl_xc_error(int xc_err);
232 #endif