debuggers.hg

view tools/libxl/libxl.h @ 20637:91555131e235

libxenlight: implement cdrom insert/eject

This patch implements functions in libxenlight to change the cdrom in
a VM at run time and to handle cdrom eject requests from guests.

This patch adds two new commands to xl: cd-insert and cd-eject; it
also modifies xl to handle cdrom eject requests coming from guests
(actually coming from qemu).

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 08 07:47:52 2009 +0000 (2009-12-08)
parents e0351b16a747
children 2c6a04fdf8fb
line source
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 #ifndef LIBXL_H
16 #define LIBXL_H
18 #include <stdint.h>
19 #include <stdarg.h>
20 #include <netinet/in.h>
21 #include <xenctrl.h>
22 #include <xs.h>
24 #include "xen_uuid.h"
26 #define XL_LOGGING_ENABLED
28 typedef void (*libxl_log_callback)(void *userdata, int loglevel, const char *file,
29 int line, const char *func, char *s);
30 struct libxl_dominfo {
31 xen_uuid_t uuid;
32 uint32_t domid;
33 };
35 struct libxl_ctx {
36 int xch;
37 struct xs_handle *xsh;
38 /* errors/debug buf */
39 void *log_userdata;
40 libxl_log_callback log_callback;
42 /* mini-GC */
43 int alloc_maxsize;
44 void **alloc_ptrs;
46 /* for callers who reap children willy-nilly; caller must only
47 * set this after libxl_init and before any other call - or
48 * may leave them untouched */
49 int (*waitpid_instead)(pid_t pid, int *status, int flags);
50 };
52 typedef struct {
53 bool hvm;
54 bool hap;
55 int ssidref;
56 char *name;
57 xen_uuid_t *uuid;
58 char **xsdata;
59 char **platformdata;
60 } libxl_domain_create_info;
62 typedef struct {
63 int timer_mode;
64 int hpet;
65 int vpt_align;
66 int max_vcpus;
67 int cur_vcpus;
68 uint32_t max_memkb;
69 uint32_t video_memkb;
70 uint32_t shadow_memkb;
71 const char *kernel;
72 int hvm;
73 union {
74 struct {
75 bool pae;
76 bool apic;
77 bool acpi;
78 bool nx;
79 bool viridian;
80 char *timeoffset;
81 } hvm;
82 struct {
83 uint32_t slack_memkb;
84 const char *cmdline;
85 const char *ramdisk;
86 const char *features;
87 } pv;
88 } u;
89 } libxl_domain_build_info;
91 typedef struct {
92 uint32_t store_port;
93 unsigned long store_mfn;
94 uint32_t console_port;
95 unsigned long console_mfn;
96 } libxl_domain_build_state;
98 typedef struct {
99 #define XL_SUSPEND_DEBUG 1
100 #define XL_SUSPEND_LIVE 2
101 int flags;
102 int (*suspend_callback)(void *, int);
103 } libxl_domain_suspend_info;
105 typedef enum {
106 XENFV,
107 XENPV,
108 } libxl_qemu_machine_type;
110 typedef struct {
111 int domid;
112 char *dom_name;
113 char *device_model;
114 char *saved_state;
115 libxl_qemu_machine_type type;
116 int videoram; /* size of the videoram in MB */
117 bool stdvga; /* stdvga enabled or disabled */
118 bool vnc; /* vnc enabled or disabled */
119 char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */
120 int vncdisplay; /* set VNC display number */
121 bool vncunused; /* try to find an unused port for the VNC server */
122 char *keymap; /* set keyboard layout, default is en-us keyboard */
123 bool sdl; /* sdl enabled or disabled */
124 bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */
125 bool nographic; /* no graphics, use serial port */
126 char *serial; /* serial port re-direct to pty deivce */
127 char *boot; /* boot order, for example dca */
128 bool usb; /* usb support enabled or disabled */
129 char *usbdevice; /* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */
130 bool apic; /* apic enabled or disabled */
131 char **extra; /* extra parameters pass directly to qemu, NULL terminated */
132 /* Network is missing */
133 } libxl_device_model_info;
135 typedef struct {
136 uint32_t backend_domid;
137 uint32_t domid;
138 int devid;
139 bool vnc; /* vnc enabled or disabled */
140 char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */
141 int vncdisplay; /* set VNC display number */
142 bool vncunused; /* try to find an unused port for the VNC server */
143 char *keymap; /* set keyboard layout, default is en-us keyboard */
144 bool sdl; /* sdl enabled or disabled */
145 bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */
146 char *display;
147 char *xauthority;
148 } libxl_device_vfb;
150 typedef struct {
151 uint32_t backend_domid;
152 uint32_t domid;
153 int devid;
154 } libxl_device_vkb;
156 typedef enum {
157 CONSTYPE_XENCONSOLED,
158 CONSTYPE_IOEMU,
159 } libxl_console_constype;
161 typedef struct {
162 uint32_t backend_domid;
163 uint32_t domid;
164 int devid;
165 libxl_console_constype constype;
166 libxl_domain_build_state *build_state;
167 } libxl_device_console;
169 typedef enum {
170 PHYSTYPE_QCOW,
171 PHYSTYPE_QCOW2,
172 PHYSTYPE_VHD,
173 PHYSTYPE_AIO,
174 PHYSTYPE_FILE,
175 PHYSTYPE_PHY,
176 } libxl_disk_phystype;
178 typedef struct {
179 uint32_t backend_domid;
180 uint32_t domid;
181 char *physpath;
182 libxl_disk_phystype phystype;
183 char *virtpath;
184 int unpluggable;
185 int readwrite;
186 int is_cdrom;
187 } libxl_device_disk;
189 typedef enum {
190 NICTYPE_IOEMU,
191 NICTYPE_VIF,
192 } libxl_nic_type;
194 typedef struct {
195 uint32_t backend_domid;
196 uint32_t domid;
197 int devid;
198 int mtu;
199 char *model;
200 uint8_t mac[6];
201 char *smac;
202 struct in_addr ip;
203 char *bridge;
204 char *ifname;
205 char *script;
206 libxl_nic_type nictype;
207 } libxl_device_nic;
209 typedef struct {
210 union {
211 unsigned int value;
212 struct {
213 unsigned int reserved1:2;
214 unsigned int reg:6;
215 unsigned int func:3;
216 unsigned int dev:5;
217 unsigned int bus:8;
218 unsigned int reserved2:7;
219 unsigned int enable:1;
220 };
221 };
222 unsigned int domain;
223 unsigned int vdevfn;
224 bool msitranslate;
225 bool power_mgmt;
226 } libxl_device_pci;
228 #define ERROR_FAIL (-2)
229 #define ERROR_NI (-101)
230 #define ERROR_NOMEM (-1032)
231 #define ERROR_INVAL (-1245)
233 /* logging */
234 void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
235 void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...);
237 #ifdef XL_LOGGING_ENABLED
238 #define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a)
239 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a)
240 #define XL_LOG_ERRNOVAL(ctx, errnoval, loglevel, _f, _a...) xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
241 #else
242 #define XL_LOG(ctx, loglevel, _f, _a...)
243 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)
244 #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
245 #endif
247 #define XL_LOG_DEBUG 3
248 #define XL_LOG_INFO 2
249 #define XL_LOG_WARNING 1
250 #define XL_LOG_ERROR 0
252 /* context functions */
253 int libxl_ctx_init(struct libxl_ctx *ctx);
254 int libxl_ctx_free(struct libxl_ctx *ctx);
255 int libxl_ctx_close(struct libxl_ctx *ctx);
256 int libxl_ctx_set_log(struct libxl_ctx *ctx, libxl_log_callback log_callback, void *log_data);
258 /* domain related functions */
259 int libxl_domain_make(struct libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid);
260 int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
261 int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
262 uint32_t domid, int fd, libxl_domain_build_state *state,
263 libxl_device_model_info *dm_info);
264 int libxl_domain_suspend(struct libxl_ctx *ctx, libxl_domain_suspend_info *info,
265 uint32_t domid, int fd);
266 int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid);
267 int libxl_domain_shutdown(struct libxl_ctx *ctx, uint32_t domid, int req);
268 int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
270 /* events handling */
272 typedef enum {
273 DOMAIN_DEATH,
274 DISK_EJECT,
275 } libxl_event_type;
277 typedef struct {
278 /* event type */
279 libxl_event_type type;
280 /* data for internal use of the library */
281 char *path;
282 char *token;
283 } libxl_event;
285 typedef struct {
286 char *path;
287 char *token;
288 } libxl_waiter;
291 int libxl_get_wait_fd(struct libxl_ctx *ctx, int *fd);
292 /* waiter is allocated by the caller */
293 int libxl_wait_for_domain_death(struct libxl_ctx *ctx, uint32_t domid, libxl_waiter *waiter);
294 /* waiter is a preallocated array of num_disks libxl_waiter elements */
295 int libxl_wait_for_disk_ejects(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disks, int num_disks, libxl_waiter *waiter);
296 int libxl_get_event(struct libxl_ctx *ctx, libxl_event *event);
297 int libxl_stop_waiting(struct libxl_ctx *ctx, libxl_waiter *waiter);
298 int libxl_free_event(libxl_event *event);
299 int libxl_free_waiter(libxl_waiter *waiter);
301 int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_dominfo_t *info);
302 int libxl_event_get_disk_eject_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk);
305 int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid);
306 int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid);
308 int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
310 struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain);
311 xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain);
312 xc_dominfo_t * libxl_domain_info(struct libxl_ctx *ctx, uint32_t domid);
314 typedef struct libxl_device_model_starting libxl_device_model_starting;
315 int libxl_create_device_model(struct libxl_ctx *ctx,
316 libxl_device_model_info *info,
317 libxl_device_disk *disk, int num_disks,
318 libxl_device_nic *vifs, int num_vifs,
319 libxl_device_model_starting **starting_r);
320 int libxl_create_xenpv_qemu(struct libxl_ctx *ctx, libxl_device_vfb *vfb,
321 int num_console, libxl_device_console *console,
322 libxl_device_model_starting **starting_r);
323 /* Caller must either: pass starting_r==0, or on successful
324 * return pass *starting_r (which will be non-0) to
325 * libxl_confirm_device_model or libxl_detach_device_model. */
326 int libxl_confirm_device_model_startup(struct libxl_ctx *ctx,
327 libxl_device_model_starting *starting);
328 int libxl_detach_device_model(struct libxl_ctx *ctx,
329 libxl_device_model_starting *starting);
330 /* DM is detached even if error is returned */
332 int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
333 int libxl_device_disk_del(struct libxl_ctx *ctx, libxl_device_disk *disk, int wait);
334 libxl_device_disk *libxl_device_disk_list(struct libxl_ctx *ctx, uint32_t domid, int *num);
335 int libxl_cdrom_insert(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
337 int libxl_device_nic_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
338 int libxl_device_nic_del(struct libxl_ctx *ctx, libxl_device_nic *nic, int wait);
340 int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);
342 int libxl_device_vkb_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
343 int libxl_device_vkb_clean_shutdown(struct libxl_ctx *ctx, uint32_t domid);
344 int libxl_device_vkb_hard_shutdown(struct libxl_ctx *ctx, uint32_t domid);
346 int libxl_device_vfb_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
347 int libxl_device_vfb_clean_shutdown(struct libxl_ctx *ctx, uint32_t domid);
348 int libxl_device_vfb_hard_shutdown(struct libxl_ctx *ctx, uint32_t domid);
350 #define PCI_BDF "%04x:%02x:%02x.%01x"
351 #define PCI_BDF_VDEVFN "%04x:%02x:%02x.%01x@%02x"
352 int libxl_device_pci_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
353 int libxl_device_pci_remove(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
354 int libxl_device_pci_shutdown(struct libxl_ctx *ctx, uint32_t domid);
355 libxl_device_pci *libxl_device_pci_list(struct libxl_ctx *ctx, uint32_t domid, int *num);
356 int libxl_device_pci_init(libxl_device_pci *pcidev, unsigned int domain,
357 unsigned int bus, unsigned int dev,
358 unsigned int func, unsigned int vdevfn);
360 void nic_info_domid_fixup(libxl_device_nic *nic_info, int domid);
361 void disk_info_domid_fixup(libxl_device_disk *disk_info, int domid);
362 void vfb_info_domid_fixup(libxl_device_vfb *vfb, int domid);
363 void vkb_info_domid_fixup(libxl_device_vkb *vkb, int domid);
364 void console_info_domid_fixup(libxl_device_console *console, int domid);
365 void device_model_info_domid_fixup(libxl_device_model_info *dm_info, int domid);
367 void init_create_info(libxl_domain_create_info *c_info);
368 void init_build_info(libxl_domain_build_info *b_info, libxl_domain_create_info *c_info);
369 void init_dm_info(libxl_device_model_info *dm_info,
370 libxl_domain_create_info *c_info, libxl_domain_build_info *b_info);
371 void init_nic_info(libxl_device_nic *nic_info, int devnum);
372 void init_vfb_info(libxl_device_vfb *vfb, int dev_num);
373 void init_vkb_info(libxl_device_vkb *vkb, int dev_num);
374 void init_console_info(libxl_device_console *console, int dev_num, libxl_domain_build_state *state);
376 #endif