direct-io.hg

view tools/libxc/xenctrl.h @ 7404:75ec60b67f64

Have xenstored initialise its connections, meaning that xend can be out of
that loop completely -- the xc_init_store, initDomainStore calls can all go.

Have xenstored understand where the local domain information goes. Xend no
longer has to generate a path and pass it to xenstored through
xs_introduce_domain -- we just allow xenstored to generate the path, and then
call GetDomainPath later. There is still some work required to tidy this up.

Change the uuid module to generate uuids as lists of bytes, not in the
stringified form. Added a unit test for that module.

Change the semantics of Xend restart, relying on these changes to the
xenstored semantics and earlier changes to add an opaque handle to the
hypervisor's domain-specific data block. The semantics are now clearer, as
Xend can validate whether the details in the store match the current live
domain.

Added a usage statement to xenstored.

Some of this code is by Steven Hand.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Oct 17 16:22:05 2005 +0100 (2005-10-17)
parents fa0faada967b
children 8928c89a8d0a
line source
1 /******************************************************************************
2 * xenctrl.h
3 *
4 * A library for low-level access to the Xen control interfaces.
5 *
6 * Copyright (c) 2003-2004, K A Fraser.
7 */
9 #ifndef XENCTRL_H
10 #define XENCTRL_H
12 #include <stdint.h>
13 #include <sys/ptrace.h>
14 #include <xen/xen.h>
15 #include <xen/dom0_ops.h>
16 #include <xen/version.h>
17 #include <xen/event_channel.h>
18 #include <xen/sched.h>
19 #include <xen/sched_ctl.h>
20 #include <xen/acm.h>
22 #ifdef __ia64__
23 #define XC_PAGE_SHIFT 14
24 #else
25 #define XC_PAGE_SHIFT 12
26 #endif
27 #define XC_PAGE_SIZE (1UL << XC_PAGE_SHIFT)
28 #define XC_PAGE_MASK (~(XC_PAGE_SIZE-1))
30 /*
31 * DEFINITIONS FOR CPU BARRIERS
32 */
34 #if defined(__i386__)
35 #define mb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
36 #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
37 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
38 #elif defined(__x86_64__)
39 #define mb() __asm__ __volatile__ ( "mfence" : : : "memory")
40 #define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
41 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
42 #elif defined(__ia64__)
43 /* FIXME */
44 #define mb()
45 #define rmb()
46 #define wmb()
47 #else
48 #error "Define barriers"
49 #endif
51 /*
52 * INITIALIZATION FUNCTIONS
53 */
55 /**
56 * This function opens a handle to the hypervisor interface. This function can
57 * be called multiple times within a single process. Multiple processes can
58 * have an open hypervisor interface at the same time.
59 *
60 * Each call to this function should have a corresponding call to
61 * xc_interface_close().
62 *
63 * This function can fail if the caller does not have superuser permission or
64 * if a Xen-enabled kernel is not currently running.
65 *
66 * @return a handle to the hypervisor interface or -1 on failure
67 */
68 int xc_interface_open(void);
70 /**
71 * This function closes an open hypervisor interface.
72 *
73 * This function can fail if the handle does not represent an open interface or
74 * if there were problems closing the interface.
75 *
76 * @parm xc_handle a handle to an open hypervisor interface
77 * @return 0 on success, -1 otherwise.
78 */
79 int xc_interface_close(int xc_handle);
81 /*
82 * DOMAIN DEBUGGING FUNCTIONS
83 */
85 typedef struct xc_core_header {
86 unsigned int xch_magic;
87 unsigned int xch_nr_vcpus;
88 unsigned int xch_nr_pages;
89 unsigned int xch_ctxt_offset;
90 unsigned int xch_index_offset;
91 unsigned int xch_pages_offset;
92 } xc_core_header_t;
95 long xc_ptrace(
96 int xc_handle,
97 enum __ptrace_request request,
98 uint32_t domid,
99 long addr,
100 long data);
102 long xc_ptrace_core(
103 int xc_handle,
104 enum __ptrace_request request,
105 uint32_t domid,
106 long addr,
107 long data);
109 int xc_waitdomain(
110 int xc_handle,
111 int domain,
112 int *status,
113 int options);
115 int xc_waitdomain_core(
116 int xc_handle,
117 int domain,
118 int *status,
119 int options);
121 /*
122 * DOMAIN MANAGEMENT FUNCTIONS
123 */
125 typedef struct {
126 uint32_t domid;
127 uint32_t ssidref;
128 unsigned int dying:1, crashed:1, shutdown:1,
129 paused:1, blocked:1, running:1;
130 unsigned int shutdown_reason; /* only meaningful if shutdown==1 */
131 unsigned long nr_pages;
132 unsigned long shared_info_frame;
133 uint64_t cpu_time;
134 unsigned long max_memkb;
135 unsigned int nr_online_vcpus;
136 unsigned int max_vcpu_id;
137 xen_domain_handle_t handle;
138 } xc_dominfo_t;
140 typedef dom0_getdomaininfo_t xc_domaininfo_t;
141 int xc_domain_create(int xc_handle,
142 uint32_t ssidref,
143 xen_domain_handle_t handle,
144 uint32_t *pdomid);
147 int xc_domain_dumpcore(int xc_handle,
148 uint32_t domid,
149 const char *corename);
151 /*
152 * This function sets the maximum number vcpus that a domian may create.
153 *
154 * @parm xc_handle a handle to an open hypervisor interface.
155 * @parm domid the domain id in which vcpus are to be created.
156 * @parm max the maximum number of vcpus that the domain may create.
157 * @return 0 on success, -1 on failure.
158 */
159 int xc_domain_max_vcpus(int xc_handle,
160 uint32_t domid,
161 unsigned int max);
163 /**
164 * This function pauses a domain. A paused domain still exists in memory
165 * however it does not receive any timeslices from the hypervisor.
166 *
167 * @parm xc_handle a handle to an open hypervisor interface
168 * @parm domid the domain id to pause
169 * @return 0 on success, -1 on failure.
170 */
171 int xc_domain_pause(int xc_handle,
172 uint32_t domid);
173 /**
174 * This function unpauses a domain. The domain should have been previously
175 * paused.
176 *
177 * @parm xc_handle a handle to an open hypervisor interface
178 * @parm domid the domain id to unpause
179 * return 0 on success, -1 on failure
180 */
181 int xc_domain_unpause(int xc_handle,
182 uint32_t domid);
184 /**
185 * This function will destroy a domain. Destroying a domain removes the domain
186 * completely from memory. This function should be called after sending the
187 * domain a SHUTDOWN control message to free up the domain resources.
188 *
189 * @parm xc_handle a handle to an open hypervisor interface
190 * @parm domid the domain id to destroy
191 * @return 0 on success, -1 on failure
192 */
193 int xc_domain_destroy(int xc_handle,
194 uint32_t domid);
195 int xc_domain_pincpu(int xc_handle,
196 uint32_t domid,
197 int vcpu,
198 cpumap_t cpumap);
200 /**
201 * This function will return information about one or more domains. It is
202 * designed to iterate over the list of domains. If a single domain is
203 * requested, this function will return the next domain in the list - if
204 * one exists. It is, therefore, important in this case to make sure the
205 * domain requested was the one returned.
206 *
207 * @parm xc_handle a handle to an open hypervisor interface
208 * @parm first_domid the first domain to enumerate information from. Domains
209 * are currently enumerate in order of creation.
210 * @parm max_doms the number of elements in info
211 * @parm info an array of max_doms size that will contain the information for
212 * the enumerated domains.
213 * @return the number of domains enumerated or -1 on error
214 */
215 int xc_domain_getinfo(int xc_handle,
216 uint32_t first_domid,
217 unsigned int max_doms,
218 xc_dominfo_t *info);
220 /**
221 * This function will return information about one or more domains, using a
222 * single hypercall. The domain information will be stored into the supplied
223 * array of xc_domaininfo_t structures.
224 *
225 * @parm xc_handle a handle to an open hypervisor interface
226 * @parm first_domain the first domain to enumerate information from.
227 * Domains are currently enumerate in order of creation.
228 * @parm max_domains the number of elements in info
229 * @parm info an array of max_doms size that will contain the information for
230 * the enumerated domains.
231 * @return the number of domains enumerated or -1 on error
232 */
233 int xc_domain_getinfolist(int xc_handle,
234 uint32_t first_domain,
235 unsigned int max_domains,
236 xc_domaininfo_t *info);
238 /**
239 * This function returns information about the execution context of a
240 * particular vcpu of a domain.
241 *
242 * @parm xc_handle a handle to an open hypervisor interface
243 * @parm domid the domain to get information from
244 * @parm vcpu the vcpu number
245 * @parm ctxt a pointer to a structure to store the execution context of the
246 * domain
247 * @return 0 on success, -1 on failure
248 */
249 int xc_domain_get_vcpu_context(int xc_handle,
250 uint32_t domid,
251 uint32_t vcpu,
252 vcpu_guest_context_t *ctxt);
254 typedef dom0_getvcpuinfo_t xc_vcpuinfo_t;
255 int xc_domain_get_vcpu_info(int xc_handle,
256 uint32_t domid,
257 uint32_t vcpu,
258 xc_vcpuinfo_t *info);
261 int xc_domain_setcpuweight(int xc_handle,
262 uint32_t domid,
263 float weight);
264 long long xc_domain_get_cpu_usage(int xc_handle,
265 domid_t domid,
266 int vcpu);
268 int xc_domain_sethandle(int xc_handle, uint32_t domid,
269 xen_domain_handle_t handle);
271 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
272 int xc_shadow_control(int xc_handle,
273 uint32_t domid,
274 unsigned int sop,
275 unsigned long *dirty_bitmap,
276 unsigned long pages,
277 xc_shadow_control_stats_t *stats);
279 int xc_bvtsched_global_set(int xc_handle,
280 unsigned long ctx_allow);
282 int xc_bvtsched_domain_set(int xc_handle,
283 uint32_t domid,
284 uint32_t mcuadv,
285 int warpback,
286 int32_t warpvalue,
287 long long warpl,
288 long long warpu);
290 int xc_bvtsched_global_get(int xc_handle,
291 unsigned long *ctx_allow);
293 int xc_bvtsched_domain_get(int xc_handle,
294 uint32_t domid,
295 uint32_t *mcuadv,
296 int *warpback,
297 int32_t *warpvalue,
298 long long *warpl,
299 long long *warpu);
301 int xc_sedf_domain_set(int xc_handle,
302 uint32_t domid,
303 uint64_t period, uint64_t slice,
304 uint64_t latency, uint16_t extratime,
305 uint16_t weight);
307 int xc_sedf_domain_get(int xc_handle,
308 uint32_t domid,
309 uint64_t* period, uint64_t *slice,
310 uint64_t *latency, uint16_t *extratime,
311 uint16_t *weight);
313 typedef evtchn_status_t xc_evtchn_status_t;
315 /*
316 * EVENT CHANNEL FUNCTIONS
317 */
319 /**
320 * This function allocates an unbound port. Ports are named endpoints used for
321 * interdomain communication. This function is most useful in opening a
322 * well-known port within a domain to receive events on.
323 *
324 * @parm xc_handle a handle to an open hypervisor interface
325 * @parm dom the ID of the local domain (the 'allocatee')
326 * @parm remote_dom the ID of the domain who will later bind
327 * @return allocated port (in @dom) on success, -1 on failure
328 */
329 int xc_evtchn_alloc_unbound(int xc_handle,
330 uint32_t dom,
331 uint32_t remote_dom);
333 int xc_evtchn_status(int xc_handle,
334 uint32_t dom, /* may be DOMID_SELF */
335 int port,
336 xc_evtchn_status_t *status);
338 int xc_physdev_pci_access_modify(int xc_handle,
339 uint32_t domid,
340 int bus,
341 int dev,
342 int func,
343 int enable);
345 int xc_readconsolering(int xc_handle,
346 char **pbuffer,
347 unsigned int *pnr_chars,
348 int clear);
350 typedef dom0_physinfo_t xc_physinfo_t;
351 int xc_physinfo(int xc_handle,
352 xc_physinfo_t *info);
354 int xc_sched_id(int xc_handle,
355 int *sched_id);
357 int xc_domain_setmaxmem(int xc_handle,
358 uint32_t domid,
359 unsigned int max_memkb);
361 int xc_domain_memory_increase_reservation(int xc_handle,
362 uint32_t domid,
363 unsigned long nr_extents,
364 unsigned int extent_order,
365 unsigned int address_bits,
366 unsigned long *extent_start);
368 int xc_domain_memory_decrease_reservation(int xc_handle,
369 uint32_t domid,
370 unsigned long nr_extents,
371 unsigned int extent_order,
372 unsigned long *extent_start);
374 unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid,
375 unsigned long mfn);
377 typedef dom0_perfc_desc_t xc_perfc_desc_t;
378 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
379 int xc_perfc_control(int xc_handle,
380 uint32_t op,
381 xc_perfc_desc_t *desc);
383 /* read/write msr */
384 long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
385 int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
386 unsigned int high);
388 /**
389 * Memory maps a range within one domain to a local address range. Mappings
390 * should be unmapped with munmap and should follow the same rules as mmap
391 * regarding page alignment. Returns NULL on failure.
392 *
393 * In Linux, the ring queue for the control channel is accessible by mapping
394 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
395 * stored there is of type control_if_t.
396 *
397 * @parm xc_handle a handle on an open hypervisor interface
398 * @parm dom the domain to map memory from
399 * @parm size the amount of memory to map (in multiples of page size)
400 * @parm prot same flag as in mmap().
401 * @parm mfn the frame address to map.
402 */
403 void *xc_map_foreign_range(int xc_handle, uint32_t dom,
404 int size, int prot,
405 unsigned long mfn );
407 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
408 unsigned long *arr, int num );
410 int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf,
411 unsigned long max_pfns);
413 int xc_ia64_get_pfn_list(int xc_handle, uint32_t domid,
414 unsigned long *pfn_buf,
415 unsigned int start_page, unsigned int nr_pages);
417 long xc_get_max_pages(int xc_handle, uint32_t domid);
419 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
420 domid_t dom);
422 int xc_memory_op(int xc_handle, int cmd, void *arg);
424 int xc_get_pfn_type_batch(int xc_handle, uint32_t dom,
425 int num, unsigned long *arr);
428 /*\
429 * GRANT TABLE FUNCTIONS
430 \*/
432 /**
433 * This function opens a handle to the more restricted grant table hypervisor
434 * interface. This may be used where the standard interface is not
435 * available because the domain is not privileged.
436 * This function can be called multiple times within a single process.
437 * Multiple processes can have an open hypervisor interface at the same time.
438 *
439 * Each call to this function should have a corresponding call to
440 * xc_grant_interface_close().
441 *
442 * This function can fail if a Xen-enabled kernel is not currently running.
443 *
444 * @return a handle to the hypervisor grant table interface or -1 on failure
445 */
446 int xc_grant_interface_open(void);
448 /**
449 * This function closes an open grant table hypervisor interface.
450 *
451 * This function can fail if the handle does not represent an open interface or
452 * if there were problems closing the interface.
453 *
454 * @parm xc_handle a handle to an open grant table hypervisor interface
455 * @return 0 on success, -1 otherwise.
456 */
457 int xc_grant_interface_close(int xc_handle);
459 int xc_gnttab_map_grant_ref(int xc_handle,
460 uint64_t host_virt_addr,
461 uint32_t dom,
462 uint16_t ref,
463 uint16_t flags,
464 int16_t *handle,
465 uint64_t *dev_bus_addr);
467 int xc_gnttab_unmap_grant_ref(int xc_handle,
468 uint64_t host_virt_addr,
469 uint64_t dev_bus_addr,
470 uint16_t handle,
471 int16_t *status);
473 int xc_gnttab_setup_table(int xc_handle,
474 uint32_t dom,
475 uint16_t nr_frames,
476 int16_t *status,
477 unsigned long **frame_list);
479 /* Grant debug builds only: */
480 int xc_gnttab_dump_table(int xc_handle,
481 uint32_t dom,
482 int16_t *status);
484 /* Get current total pages allocated to a domain. */
485 long xc_get_tot_pages(int xc_handle, uint32_t domid);
487 /* Execute a privileged dom0 operation. */
488 int xc_dom0_op(int xc_handle, dom0_op_t *op);
490 int xc_version(int xc_handle, int cmd, void *arg);
492 /*
493 * MMU updates.
494 */
495 #define MAX_MMU_UPDATES 1024
496 struct xc_mmu {
497 mmu_update_t updates[MAX_MMU_UPDATES];
498 int idx;
499 domid_t subject;
500 };
501 typedef struct xc_mmu xc_mmu_t;
502 xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
503 int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
504 unsigned long long ptr, unsigned long long val);
505 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
507 #endif