debuggers.hg

view tools/libxl/libxl_internal.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 9575425fdebd
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 (1 * 1024 * 1024)
35 #define QEMU_SIGNATURE "QemuDeviceModelRecord"
37 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
39 typedef enum {
40 DEVICE_VIF,
41 DEVICE_VBD,
42 DEVICE_TAP,
43 DEVICE_PCI,
44 DEVICE_VFB,
45 DEVICE_VKBD,
46 DEVICE_CONSOLE,
47 } libxl_device_kinds;
49 extern const char *string_of_kinds[];
51 typedef struct {
52 uint32_t backend_devid;
53 uint32_t backend_domid;
54 uint32_t devid;
55 uint32_t domid;
56 libxl_device_kinds backend_kind;
57 libxl_device_kinds kind;
58 } libxl_device;
60 #define XC_PCI_BDF "0x%x, 0x%x, 0x%x, 0x%x"
61 #define AUTO_PHP_SLOT 0x100
62 #define SYSFS_PCI_DEV "/sys/bus/pci/devices"
63 #define PROC_PCI_NUM_RESOURCES 7
64 #define PCI_BAR_IO 0x01
66 #define PRINTF_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
68 /* memory allocation tracking/helpers */
69 int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to);
70 static inline int libxl_clone_context_xs(
71 struct libxl_ctx *from, struct libxl_ctx *to)
72 {
73 int rc;
74 rc = libxl_clone_context(from, to);
75 if (rc) return rc;
76 to->xsh = xs_daemon_open();
77 return 0;
78 }
79 void libxl_discard_cloned_context(struct libxl_ctx *ctx);
80 static inline void libxl_discard_cloned_context_xs(
81 struct libxl_ctx *ctx)
82 {
83 libxl_discard_cloned_context(ctx);
84 xs_daemon_close(ctx->xsh);
85 }
86 int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr);
87 int libxl_free(struct libxl_ctx *ctx, void *ptr);
88 int libxl_free_all(struct libxl_ctx *ctx);
89 void *libxl_zalloc(struct libxl_ctx *ctx, int bytes);
90 void *libxl_calloc(struct libxl_ctx *ctx, size_t nmemb, size_t size);
91 char *libxl_sprintf(struct libxl_ctx *ctx, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
92 char *libxl_dirname(struct libxl_ctx *ctx, const char *s);
94 char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, int length);
95 int libxl_xs_writev(struct libxl_ctx *ctx, xs_transaction_t t,
96 char *dir, char **kvs);
97 int libxl_xs_write(struct libxl_ctx *ctx, xs_transaction_t t,
98 char *path, char *fmt, ...);
99 char *libxl_xs_get_dompath(struct libxl_ctx *ctx, uint32_t domid); // logs errs
100 char *libxl_xs_read(struct libxl_ctx *ctx, xs_transaction_t t, char *path);
101 char **libxl_xs_directory(struct libxl_ctx *ctx, xs_transaction_t t, char *path, unsigned int *nb);
103 /* from xl_dom */
104 int is_hvm(struct libxl_ctx *ctx, uint32_t domid);
105 int build_pre(struct libxl_ctx *ctx, uint32_t domid,
106 libxl_domain_build_info *info, libxl_domain_build_state *state);
107 int build_post(struct libxl_ctx *ctx, uint32_t domid,
108 libxl_domain_build_info *info, libxl_domain_build_state *state,
109 char **vms_ents, char **local_ents);
111 int build_pv(struct libxl_ctx *ctx, uint32_t domid,
112 libxl_domain_build_info *info, libxl_domain_build_state *state);
113 int build_hvm(struct libxl_ctx *ctx, uint32_t domid,
114 libxl_domain_build_info *info, libxl_domain_build_state *state);
116 int restore_common(struct libxl_ctx *ctx, uint32_t domid,
117 libxl_domain_build_info *info, libxl_domain_build_state *state, int fd);
118 int core_suspend(struct libxl_ctx *ctx, uint32_t domid, int fd, int hvm, int live, int debug);
120 /* from xl_device */
121 char *device_disk_backend_type_of_phystype(libxl_disk_phystype phystype);
122 char *device_disk_string_of_phystype(libxl_disk_phystype phystype);
124 int device_physdisk_major_minor(char *physpath, int *major, int *minor);
125 int device_virtdisk_major_minor(char *virtpath, int *major, int *minor);
126 int device_disk_dev_number(char *virtpath);
128 int libxl_device_generic_add(struct libxl_ctx *ctx, libxl_device *device,
129 char **bents, char **fents);
130 int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait);
131 int libxl_device_destroy(struct libxl_ctx *ctx, char *be_path, int force);
132 int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
133 int libxl_wait_for_device_model(struct libxl_ctx *ctx,
134 uint32_t domid, char *state,
135 int (*check_callback)(struct libxl_ctx *ctx,
136 void *userdata),
137 void *check_callback_userdata);
138 int libxl_wait_for_backend(struct libxl_ctx *ctx, char *be_path, char *state);
139 int libxl_device_pci_flr(struct libxl_ctx *ctx, unsigned int domain, unsigned int bus,
140 unsigned int dev, unsigned int func);
142 /* from xenguest (helper */
143 int hvm_build_set_params(int handle, uint32_t domid,
144 int apic, int acpi, int pae, int nx, int viridian,
145 int vcpus, int store_evtchn, unsigned long *store_mfn);
147 /* xl_exec */
149 /* higher-level double-fork and separate detach eg as for device models */
151 struct libxl_spawn_starting {
152 /* put this in your own stateu structure as returned to application */
153 /* all fields are private to libxl_spawn_... */
154 pid_t intermediate;
155 char *what; /* malloc'd in spawn_spawn */
156 };
158 struct libxl_device_model_starting {
159 struct libxl_spawn_starting *for_spawn; /* first! */
160 char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
161 int domid;
162 };
164 int libxl_spawn_spawn(struct libxl_ctx *ctx,
165 libxl_device_model_starting *starting,
166 const char *what,
167 void (*intermediate_hook)(struct libxl_ctx *ctx,
168 void *for_spawn,
169 pid_t innerchild));
170 /* Logs errors. A copy of "what" is taken. Return values:
171 * < 0 error, for_spawn need not be detached
172 * +1 caller is now the inner child, should probably call libxl_exec
173 * 0 caller is the parent, must call detach on *for_spawn eventually
174 * Caller, may pass 0 for for_spawn, in which case no need to detach.
175 */
176 int libxl_spawn_detach(struct libxl_ctx *ctx,
177 struct libxl_spawn_starting *for_spawn);
178 /* Logs errors. Idempotent, but only permitted after successful
179 * call to libxl_spawn_spawn, and no point calling it again if it fails. */
180 int libxl_spawn_check(struct libxl_ctx *ctx,
181 void *for_spawn);
182 /* Logs errors but also returns them.
183 * for_spawn must actually be a struct libxl_spawn_starting* but
184 * we take void* so you can pass this function directly to
185 * libxl_wait_for_device_model. Caller must still call detach. */
187 /* low-level stuff, for synchronous subprocesses etc. */
189 pid_t libxl_fork(struct libxl_ctx *ctx); // logs errors
190 void libxl_exec(struct libxl_ctx *ctx, int stdinfd, int stdoutfd, int stderrfd,
191 char *arg0, char **args); // logs errors, never returns
192 void libxl_log_child_exitstatus(struct libxl_ctx *ctx,
193 const char *what, pid_t pid, int status);
194 pid_t libxl_waitpid_instead_default(pid_t pid, int *status, int flags);
196 #endif