debuggers.hg

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