ia64/xen-unstable

view tools/libxc/xc_domain.c @ 9730:74ee53209cca

Fix whitespace in libxc. Tabs are manually fixed.
Trailing whitespace removed with:
perl -p -i -e 's/\s+$/\n/g' tools/libxc/*.[ch]

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Apr 15 10:07:31 2006 +0100 (2006-04-15)
parents b128f55ca05c
children ec61a8c25429
line source
1 /******************************************************************************
2 * xc_domain.c
3 *
4 * API for manipulating and obtaining information on domains.
5 *
6 * Copyright (c) 2003, K A Fraser.
7 */
9 #include "xc_private.h"
10 #include <xen/memory.h>
12 int xc_domain_create(int xc_handle,
13 uint32_t ssidref,
14 xen_domain_handle_t handle,
15 uint32_t *pdomid)
16 {
17 int err;
18 DECLARE_DOM0_OP;
20 op.cmd = DOM0_CREATEDOMAIN;
21 op.u.createdomain.domain = (domid_t)*pdomid;
22 op.u.createdomain.ssidref = ssidref;
23 memcpy(op.u.createdomain.handle, handle, sizeof(xen_domain_handle_t));
24 if ( (err = do_dom0_op(xc_handle, &op)) != 0 )
25 return err;
27 *pdomid = (uint16_t)op.u.createdomain.domain;
28 return 0;
29 }
32 int xc_domain_pause(int xc_handle,
33 uint32_t domid)
34 {
35 DECLARE_DOM0_OP;
36 op.cmd = DOM0_PAUSEDOMAIN;
37 op.u.pausedomain.domain = (domid_t)domid;
38 return do_dom0_op(xc_handle, &op);
39 }
42 int xc_domain_unpause(int xc_handle,
43 uint32_t domid)
44 {
45 DECLARE_DOM0_OP;
46 op.cmd = DOM0_UNPAUSEDOMAIN;
47 op.u.unpausedomain.domain = (domid_t)domid;
48 return do_dom0_op(xc_handle, &op);
49 }
52 int xc_domain_destroy(int xc_handle,
53 uint32_t domid)
54 {
55 DECLARE_DOM0_OP;
56 op.cmd = DOM0_DESTROYDOMAIN;
57 op.u.destroydomain.domain = (domid_t)domid;
58 return do_dom0_op(xc_handle, &op);
59 }
61 int xc_domain_shutdown(int xc_handle,
62 uint32_t domid,
63 int reason)
64 {
65 int ret = -1;
66 sched_remote_shutdown_t arg;
67 DECLARE_HYPERCALL;
69 hypercall.op = __HYPERVISOR_sched_op;
70 hypercall.arg[0] = (unsigned long)SCHEDOP_remote_shutdown;
71 hypercall.arg[1] = (unsigned long)&arg;
72 arg.domain_id = domid;
73 arg.reason = reason;
75 if ( mlock(&arg, sizeof(arg)) != 0 )
76 {
77 PERROR("Could not lock memory for Xen hypercall");
78 goto out1;
79 }
81 ret = do_xen_hypercall(xc_handle, &hypercall);
83 safe_munlock(&arg, sizeof(arg));
85 out1:
86 return ret;
87 }
90 int xc_vcpu_setaffinity(int xc_handle,
91 uint32_t domid,
92 int vcpu,
93 cpumap_t cpumap)
94 {
95 DECLARE_DOM0_OP;
96 op.cmd = DOM0_SETVCPUAFFINITY;
97 op.u.setvcpuaffinity.domain = (domid_t)domid;
98 op.u.setvcpuaffinity.vcpu = vcpu;
99 op.u.setvcpuaffinity.cpumap = cpumap;
100 return do_dom0_op(xc_handle, &op);
101 }
104 int xc_domain_getinfo(int xc_handle,
105 uint32_t first_domid,
106 unsigned int max_doms,
107 xc_dominfo_t *info)
108 {
109 unsigned int nr_doms;
110 uint32_t next_domid = first_domid;
111 DECLARE_DOM0_OP;
112 int rc = 0;
114 memset(info, 0, max_doms*sizeof(xc_dominfo_t));
116 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
117 {
118 op.cmd = DOM0_GETDOMAININFO;
119 op.u.getdomaininfo.domain = (domid_t)next_domid;
120 if ( (rc = do_dom0_op(xc_handle, &op)) < 0 )
121 break;
122 info->domid = (uint16_t)op.u.getdomaininfo.domain;
124 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
125 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
126 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
127 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
128 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
130 info->shutdown_reason =
131 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
132 DOMFLAGS_SHUTDOWNMASK;
134 if ( info->shutdown && (info->shutdown_reason == SHUTDOWN_crash) )
135 {
136 info->shutdown = 0;
137 info->crashed = 1;
138 }
140 info->ssidref = op.u.getdomaininfo.ssidref;
141 info->nr_pages = op.u.getdomaininfo.tot_pages;
142 info->max_memkb = op.u.getdomaininfo.max_pages << (PAGE_SHIFT - 10);
143 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
144 info->cpu_time = op.u.getdomaininfo.cpu_time;
145 info->nr_online_vcpus = op.u.getdomaininfo.nr_online_vcpus;
146 info->max_vcpu_id = op.u.getdomaininfo.max_vcpu_id;
148 memcpy(info->handle, op.u.getdomaininfo.handle,
149 sizeof(xen_domain_handle_t));
151 next_domid = (uint16_t)op.u.getdomaininfo.domain + 1;
152 info++;
153 }
155 if( !nr_doms ) return rc;
157 return nr_doms;
158 }
160 int xc_domain_getinfolist(int xc_handle,
161 uint32_t first_domain,
162 unsigned int max_domains,
163 xc_domaininfo_t *info)
164 {
165 int ret = 0;
166 DECLARE_DOM0_OP;
168 if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
169 return -1;
171 op.cmd = DOM0_GETDOMAININFOLIST;
172 op.u.getdomaininfolist.first_domain = first_domain;
173 op.u.getdomaininfolist.max_domains = max_domains;
174 op.u.getdomaininfolist.buffer = info;
176 if ( xc_dom0_op(xc_handle, &op) < 0 )
177 ret = -1;
178 else
179 ret = op.u.getdomaininfolist.num_domains;
181 if ( munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
182 ret = -1;
184 return ret;
185 }
187 int xc_vcpu_getcontext(int xc_handle,
188 uint32_t domid,
189 uint32_t vcpu,
190 vcpu_guest_context_t *ctxt)
191 {
192 int rc;
193 DECLARE_DOM0_OP;
195 op.cmd = DOM0_GETVCPUCONTEXT;
196 op.u.getvcpucontext.domain = (domid_t)domid;
197 op.u.getvcpucontext.vcpu = (uint16_t)vcpu;
198 op.u.getvcpucontext.ctxt = ctxt;
200 if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
201 return rc;
203 rc = do_dom0_op(xc_handle, &op);
205 safe_munlock(ctxt, sizeof(*ctxt));
207 return rc;
208 }
211 int xc_shadow_control(int xc_handle,
212 uint32_t domid,
213 unsigned int sop,
214 unsigned long *dirty_bitmap,
215 unsigned long pages,
216 xc_shadow_control_stats_t *stats )
217 {
218 int rc;
219 DECLARE_DOM0_OP;
220 op.cmd = DOM0_SHADOW_CONTROL;
221 op.u.shadow_control.domain = (domid_t)domid;
222 op.u.shadow_control.op = sop;
223 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
224 op.u.shadow_control.pages = pages;
226 rc = do_dom0_op(xc_handle, &op);
228 if ( stats )
229 memcpy(stats, &op.u.shadow_control.stats,
230 sizeof(xc_shadow_control_stats_t));
232 return (rc == 0) ? op.u.shadow_control.pages : rc;
233 }
235 int xc_domain_setcpuweight(int xc_handle,
236 uint32_t domid,
237 float weight)
238 {
239 int sched_id;
240 int ret;
242 /* Figure out which scheduler is currently used: */
243 if ( (ret = xc_sched_id(xc_handle, &sched_id)) != 0 )
244 return ret;
246 switch ( sched_id )
247 {
248 case SCHED_BVT:
249 {
250 uint32_t mcuadv;
251 int warpback;
252 int32_t warpvalue;
253 long long warpl;
254 long long warpu;
256 /* Preserve all the scheduling parameters apart
257 of MCU advance. */
258 if ( (ret = xc_bvtsched_domain_get(
259 xc_handle, domid, &mcuadv,
260 &warpback, &warpvalue, &warpl, &warpu)) != 0 )
261 return ret;
263 /* The MCU advance is inverse of the weight.
264 Default value of the weight is 1, default mcuadv 10.
265 The scaling factor is therefore 10. */
266 if ( weight > 0 )
267 mcuadv = 10 / weight;
269 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
270 warpback, warpvalue, warpl, warpu);
271 break;
272 }
273 }
275 return ret;
276 }
278 int xc_domain_setmaxmem(int xc_handle,
279 uint32_t domid,
280 unsigned int max_memkb)
281 {
282 DECLARE_DOM0_OP;
283 op.cmd = DOM0_SETDOMAINMAXMEM;
284 op.u.setdomainmaxmem.domain = (domid_t)domid;
285 op.u.setdomainmaxmem.max_memkb = max_memkb;
286 return do_dom0_op(xc_handle, &op);
287 }
289 int xc_domain_memory_increase_reservation(int xc_handle,
290 uint32_t domid,
291 unsigned long nr_extents,
292 unsigned int extent_order,
293 unsigned int address_bits,
294 unsigned long *extent_start)
295 {
296 int err;
297 struct xen_memory_reservation reservation = {
298 .extent_start = extent_start, /* may be NULL */
299 .nr_extents = nr_extents,
300 .extent_order = extent_order,
301 .address_bits = address_bits,
302 .domid = domid
303 };
305 err = xc_memory_op(xc_handle, XENMEM_increase_reservation, &reservation);
306 if ( err == nr_extents )
307 return 0;
309 if ( err > 0 )
310 {
311 fprintf(stderr, "Failed allocation for dom %d: "
312 "%ld pages order %d addr_bits %d\n",
313 domid, nr_extents, extent_order, address_bits);
314 errno = ENOMEM;
315 err = -1;
316 }
318 return err;
319 }
321 int xc_domain_memory_decrease_reservation(int xc_handle,
322 uint32_t domid,
323 unsigned long nr_extents,
324 unsigned int extent_order,
325 unsigned long *extent_start)
326 {
327 int err;
328 struct xen_memory_reservation reservation = {
329 .extent_start = extent_start,
330 .nr_extents = nr_extents,
331 .extent_order = extent_order,
332 .address_bits = 0,
333 .domid = domid
334 };
336 if ( extent_start == NULL )
337 {
338 fprintf(stderr,"decrease_reservation extent_start is NULL!\n");
339 errno = EINVAL;
340 return -1;
341 }
343 err = xc_memory_op(xc_handle, XENMEM_decrease_reservation, &reservation);
344 if ( err == nr_extents )
345 return 0;
347 if ( err > 0 )
348 {
349 fprintf(stderr,"Failed deallocation for dom %d: %ld pages order %d\n",
350 domid, nr_extents, extent_order);
351 errno = EBUSY;
352 err = -1;
353 }
355 return err;
356 }
358 int xc_domain_memory_populate_physmap(int xc_handle,
359 uint32_t domid,
360 unsigned long nr_extents,
361 unsigned int extent_order,
362 unsigned int address_bits,
363 unsigned long *extent_start)
364 {
365 int err;
366 struct xen_memory_reservation reservation = {
367 .extent_start = extent_start,
368 .nr_extents = nr_extents,
369 .extent_order = extent_order,
370 .address_bits = address_bits,
371 .domid = domid
372 };
374 err = xc_memory_op(xc_handle, XENMEM_populate_physmap, &reservation);
375 if ( err == nr_extents )
376 return 0;
378 if ( err > 0 )
379 {
380 fprintf(stderr,"Failed deallocation for dom %d: %ld pages order %d\n",
381 domid, nr_extents, extent_order);
382 errno = EBUSY;
383 err = -1;
384 }
386 return err;
387 }
389 int xc_domain_translate_gpfn_list(int xc_handle,
390 uint32_t domid,
391 unsigned long nr_gpfns,
392 unsigned long *gpfn_list,
393 unsigned long *mfn_list)
394 {
395 struct xen_translate_gpfn_list op = {
396 .domid = domid,
397 .nr_gpfns = nr_gpfns,
398 .gpfn_list = gpfn_list,
399 .mfn_list = mfn_list
400 };
402 return xc_memory_op(xc_handle, XENMEM_translate_gpfn_list, &op);
403 }
405 int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
406 {
407 DECLARE_DOM0_OP;
408 op.cmd = DOM0_MAX_VCPUS;
409 op.u.max_vcpus.domain = (domid_t)domid;
410 op.u.max_vcpus.max = max;
411 return do_dom0_op(xc_handle, &op);
412 }
414 int xc_domain_sethandle(int xc_handle, uint32_t domid,
415 xen_domain_handle_t handle)
416 {
417 DECLARE_DOM0_OP;
418 op.cmd = DOM0_SETDOMAINHANDLE;
419 op.u.setdomainhandle.domain = (domid_t)domid;
420 memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t));
421 return do_dom0_op(xc_handle, &op);
422 }
424 int xc_vcpu_getinfo(int xc_handle,
425 uint32_t domid,
426 uint32_t vcpu,
427 xc_vcpuinfo_t *info)
428 {
429 int rc;
430 DECLARE_DOM0_OP;
431 op.cmd = DOM0_GETVCPUINFO;
432 op.u.getvcpuinfo.domain = (domid_t)domid;
433 op.u.getvcpuinfo.vcpu = (uint16_t)vcpu;
435 rc = do_dom0_op(xc_handle, &op);
437 memcpy(info, &op.u.getvcpuinfo, sizeof(*info));
439 return rc;
440 }
442 int xc_domain_ioport_permission(int xc_handle,
443 uint32_t domid,
444 uint32_t first_port,
445 uint32_t nr_ports,
446 uint32_t allow_access)
447 {
448 DECLARE_DOM0_OP;
450 op.cmd = DOM0_IOPORT_PERMISSION;
451 op.u.ioport_permission.domain = (domid_t)domid;
452 op.u.ioport_permission.first_port = first_port;
453 op.u.ioport_permission.nr_ports = nr_ports;
454 op.u.ioport_permission.allow_access = allow_access;
456 return do_dom0_op(xc_handle, &op);
457 }
459 int xc_vcpu_setcontext(int xc_handle,
460 uint32_t domid,
461 uint32_t vcpu,
462 vcpu_guest_context_t *ctxt)
463 {
464 dom0_op_t op;
465 int rc;
467 op.cmd = DOM0_SETVCPUCONTEXT;
468 op.u.setvcpucontext.domain = domid;
469 op.u.setvcpucontext.vcpu = vcpu;
470 op.u.setvcpucontext.ctxt = ctxt;
472 if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
473 return rc;
475 rc = do_dom0_op(xc_handle, &op);
477 safe_munlock(ctxt, sizeof(*ctxt));
479 return rc;
481 }
483 int xc_domain_irq_permission(int xc_handle,
484 uint32_t domid,
485 uint8_t pirq,
486 uint8_t allow_access)
487 {
488 dom0_op_t op;
490 op.cmd = DOM0_IRQ_PERMISSION;
491 op.u.irq_permission.domain = domid;
492 op.u.irq_permission.pirq = pirq;
493 op.u.irq_permission.allow_access = allow_access;
495 return do_dom0_op(xc_handle, &op);
496 }
498 int xc_domain_iomem_permission(int xc_handle,
499 uint32_t domid,
500 unsigned long first_mfn,
501 unsigned long nr_mfns,
502 uint8_t allow_access)
503 {
504 dom0_op_t op;
506 op.cmd = DOM0_IOMEM_PERMISSION;
507 op.u.iomem_permission.domain = domid;
508 op.u.iomem_permission.first_mfn = first_mfn;
509 op.u.iomem_permission.nr_mfns = nr_mfns;
510 op.u.iomem_permission.allow_access = allow_access;
512 return do_dom0_op(xc_handle, &op);
513 }
515 /*
516 * Local variables:
517 * mode: C
518 * c-set-style: "BSD"
519 * c-basic-offset: 4
520 * tab-width: 4
521 * indent-tabs-mode: nil
522 * End:
523 */