debuggers.hg

view tools/libxl/libxl.h @ 20647:2c6a04fdf8fb

libxenlight: implement libxl_set_memory_target

This patch adds a target_memkb parameter to libxl_domain_build_info to
set the target memory for the VM at build time and a new function
called libxl_set_memory_target to dynamically modify the memory target
of a VM at run time. Finally a new command "mem-set" is added to xl
that calls directly libxl_set_memory_target.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Dec 09 10:44:11 2009 +0000 (2009-12-09)
parents 91555131e235
children 042f50e7353f
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 target_memkb;
70 uint32_t video_memkb;
71 uint32_t shadow_memkb;
72 const char *kernel;
73 int hvm;
74 union {
75 struct {
76 bool pae;
77 bool apic;
78 bool acpi;
79 bool nx;
80 bool viridian;
81 char *timeoffset;
82 } hvm;
83 struct {
84 uint32_t slack_memkb;
85 const char *cmdline;
86 const char *ramdisk;
87 const char *features;
88 } pv;
89 } u;
90 } libxl_domain_build_info;
92 typedef struct {
93 uint32_t store_port;
94 unsigned long store_mfn;
95 uint32_t console_port;
96 unsigned long console_mfn;
97 } libxl_domain_build_state;
99 typedef struct {
100 #define XL_SUSPEND_DEBUG 1
101 #define XL_SUSPEND_LIVE 2
102 int flags;
103 int (*suspend_callback)(void *, int);
104 } libxl_domain_suspend_info;
106 typedef enum {
107 XENFV,
108 XENPV,
109 } libxl_qemu_machine_type;
111 typedef struct {
112 int domid;
113 char *dom_name;
114 char *device_model;
115 char *saved_state;
116 libxl_qemu_machine_type type;
117 int videoram; /* size of the videoram in MB */
118 bool stdvga; /* stdvga enabled or disabled */
119 bool vnc; /* vnc enabled or disabled */
120 char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */
121 int vncdisplay; /* set VNC display number */
122 bool vncunused; /* try to find an unused port for the VNC server */
123 char *keymap; /* set keyboard layout, default is en-us keyboard */
124 bool sdl; /* sdl enabled or disabled */
125 bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */
126 bool nographic; /* no graphics, use serial port */
127 char *serial; /* serial port re-direct to pty deivce */
128 char *boot; /* boot order, for example dca */
129 bool usb; /* usb support enabled or disabled */
130 char *usbdevice; /* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */
131 bool apic; /* apic enabled or disabled */
132 char **extra; /* extra parameters pass directly to qemu, NULL terminated */
133 /* Network is missing */
134 } libxl_device_model_info;
136 typedef struct {
137 uint32_t backend_domid;
138 uint32_t domid;
139 int devid;
140 bool vnc; /* vnc enabled or disabled */
141 char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */
142 int vncdisplay; /* set VNC display number */
143 bool vncunused; /* try to find an unused port for the VNC server */
144 char *keymap; /* set keyboard layout, default is en-us keyboard */
145 bool sdl; /* sdl enabled or disabled */
146 bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */
147 char *display;
148 char *xauthority;
149 } libxl_device_vfb;
151 typedef struct {
152 uint32_t backend_domid;
153 uint32_t domid;
154 int devid;
155 } libxl_device_vkb;
157 typedef enum {
158 CONSTYPE_XENCONSOLED,
159 CONSTYPE_IOEMU,
160 } libxl_console_constype;
162 typedef struct {
163 uint32_t backend_domid;
164 uint32_t domid;
165 int devid;
166 libxl_console_constype constype;
167 libxl_domain_build_state *build_state;
168 } libxl_device_console;
170 typedef enum {
171 PHYSTYPE_QCOW,
172 PHYSTYPE_QCOW2,
173 PHYSTYPE_VHD,
174 PHYSTYPE_AIO,
175 PHYSTYPE_FILE,
176 PHYSTYPE_PHY,
177 } libxl_disk_phystype;
179 typedef struct {
180 uint32_t backend_domid;
181 uint32_t domid;
182 char *physpath;
183 libxl_disk_phystype phystype;
184 char *virtpath;
185 int unpluggable;
186 int readwrite;
187 int is_cdrom;
188 } libxl_device_disk;
190 typedef enum {
191 NICTYPE_IOEMU,
192 NICTYPE_VIF,
193 } libxl_nic_type;
195 typedef struct {
196 uint32_t backend_domid;
197 uint32_t domid;
198 int devid;
199 int mtu;
200 char *model;
201 uint8_t mac[6];
202 char *smac;
203 struct in_addr ip;
204 char *bridge;
205 char *ifname;
206 char *script;
207 libxl_nic_type nictype;
208 } libxl_device_nic;
210 typedef struct {
211 union {
212 unsigned int value;
213 struct {
214 unsigned int reserved1:2;
215 unsigned int reg:6;
216 unsigned int func:3;
217 unsigned int dev:5;
218 unsigned int bus:8;
219 unsigned int reserved2:7;
220 unsigned int enable:1;
221 };
222 };
223 unsigned int domain;
224 unsigned int vdevfn;
225 bool msitranslate;
226 bool power_mgmt;
227 } libxl_device_pci;
229 #define ERROR_FAIL (-2)
230 #define ERROR_NI (-101)
231 #define ERROR_NOMEM (-1032)
232 #define ERROR_INVAL (-1245)
234 /* logging */
235 void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
236 void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...);
238 #ifdef XL_LOGGING_ENABLED
239 #define XL_LOG(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a)
240 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) xl_log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a)
241 #define XL_LOG_ERRNOVAL(ctx, errnoval, loglevel, _f, _a...) xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
242 #else
243 #define XL_LOG(ctx, loglevel, _f, _a...)
244 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)
245 #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
246 #endif
248 #define XL_LOG_DEBUG 3
249 #define XL_LOG_INFO 2
250 #define XL_LOG_WARNING 1
251 #define XL_LOG_ERROR 0
253 /* context functions */
254 int libxl_ctx_init(struct libxl_ctx *ctx);
255 int libxl_ctx_free(struct libxl_ctx *ctx);
256 int libxl_ctx_close(struct libxl_ctx *ctx);
257 int libxl_ctx_set_log(struct libxl_ctx *ctx, libxl_log_callback log_callback, void *log_data);
259 /* domain related functions */
260 int libxl_domain_make(struct libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid);
261 int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
262 int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
263 uint32_t domid, int fd, libxl_domain_build_state *state,
264 libxl_device_model_info *dm_info);
265 int libxl_domain_suspend(struct libxl_ctx *ctx, libxl_domain_suspend_info *info,
266 uint32_t domid, int fd);
267 int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid);
268 int libxl_domain_shutdown(struct libxl_ctx *ctx, uint32_t domid, int req);
269 int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
271 /* events handling */
273 typedef enum {
274 DOMAIN_DEATH,
275 DISK_EJECT,
276 } libxl_event_type;
278 typedef struct {
279 /* event type */
280 libxl_event_type type;
281 /* data for internal use of the library */
282 char *path;
283 char *token;
284 } libxl_event;
286 typedef struct {
287 char *path;
288 char *token;
289 } libxl_waiter;
292 int libxl_get_wait_fd(struct libxl_ctx *ctx, int *fd);
293 /* waiter is allocated by the caller */
294 int libxl_wait_for_domain_death(struct libxl_ctx *ctx, uint32_t domid, libxl_waiter *waiter);
295 /* waiter is a preallocated array of num_disks libxl_waiter elements */
296 int libxl_wait_for_disk_ejects(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disks, int num_disks, libxl_waiter *waiter);
297 int libxl_get_event(struct libxl_ctx *ctx, libxl_event *event);
298 int libxl_stop_waiting(struct libxl_ctx *ctx, libxl_waiter *waiter);
299 int libxl_free_event(libxl_event *event);
300 int libxl_free_waiter(libxl_waiter *waiter);
302 int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_dominfo_t *info);
303 int libxl_event_get_disk_eject_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk);
306 int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid);
307 int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid);
309 int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
311 int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
313 struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain);
314 xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain);
315 xc_dominfo_t * libxl_domain_info(struct libxl_ctx *ctx, uint32_t domid);
317 typedef struct libxl_device_model_starting libxl_device_model_starting;
318 int libxl_create_device_model(struct libxl_ctx *ctx,
319 libxl_device_model_info *info,
320 libxl_device_disk *disk, int num_disks,
321 libxl_device_nic *vifs, int num_vifs,
322 libxl_device_model_starting **starting_r);
323 int libxl_create_xenpv_qemu(struct libxl_ctx *ctx, libxl_device_vfb *vfb,
324 int num_console, libxl_device_console *console,
325 libxl_device_model_starting **starting_r);
326 /* Caller must either: pass starting_r==0, or on successful
327 * return pass *starting_r (which will be non-0) to
328 * libxl_confirm_device_model or libxl_detach_device_model. */
329 int libxl_confirm_device_model_startup(struct libxl_ctx *ctx,
330 libxl_device_model_starting *starting);
331 int libxl_detach_device_model(struct libxl_ctx *ctx,
332 libxl_device_model_starting *starting);
333 /* DM is detached even if error is returned */
335 int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
336 int libxl_device_disk_del(struct libxl_ctx *ctx, libxl_device_disk *disk, int wait);
337 libxl_device_disk *libxl_device_disk_list(struct libxl_ctx *ctx, uint32_t domid, int *num);
338 int libxl_cdrom_insert(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
340 int libxl_device_nic_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
341 int libxl_device_nic_del(struct libxl_ctx *ctx, libxl_device_nic *nic, int wait);
343 int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);
345 int libxl_device_vkb_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
346 int libxl_device_vkb_clean_shutdown(struct libxl_ctx *ctx, uint32_t domid);
347 int libxl_device_vkb_hard_shutdown(struct libxl_ctx *ctx, uint32_t domid);
349 int libxl_device_vfb_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
350 int libxl_device_vfb_clean_shutdown(struct libxl_ctx *ctx, uint32_t domid);
351 int libxl_device_vfb_hard_shutdown(struct libxl_ctx *ctx, uint32_t domid);
353 #define PCI_BDF "%04x:%02x:%02x.%01x"
354 #define PCI_BDF_VDEVFN "%04x:%02x:%02x.%01x@%02x"
355 int libxl_device_pci_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
356 int libxl_device_pci_remove(struct libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
357 int libxl_device_pci_shutdown(struct libxl_ctx *ctx, uint32_t domid);
358 libxl_device_pci *libxl_device_pci_list(struct libxl_ctx *ctx, uint32_t domid, int *num);
359 int libxl_device_pci_init(libxl_device_pci *pcidev, unsigned int domain,
360 unsigned int bus, unsigned int dev,
361 unsigned int func, unsigned int vdevfn);
363 void nic_info_domid_fixup(libxl_device_nic *nic_info, int domid);
364 void disk_info_domid_fixup(libxl_device_disk *disk_info, int domid);
365 void vfb_info_domid_fixup(libxl_device_vfb *vfb, int domid);
366 void vkb_info_domid_fixup(libxl_device_vkb *vkb, int domid);
367 void console_info_domid_fixup(libxl_device_console *console, int domid);
368 void device_model_info_domid_fixup(libxl_device_model_info *dm_info, int domid);
370 void init_create_info(libxl_domain_create_info *c_info);
371 void init_build_info(libxl_domain_build_info *b_info, libxl_domain_create_info *c_info);
372 void init_dm_info(libxl_device_model_info *dm_info,
373 libxl_domain_create_info *c_info, libxl_domain_build_info *b_info);
374 void init_nic_info(libxl_device_nic *nic_info, int devnum);
375 void init_vfb_info(libxl_device_vfb *vfb, int dev_num);
376 void init_vkb_info(libxl_device_vkb *vkb, int dev_num);
377 void init_console_info(libxl_device_console *console, int dev_num, libxl_domain_build_state *state);
379 #endif