direct-io.hg

view tools/libxc/xc_domain.c @ 8500:dd5649730b32

Fix a couple of bogus dom0_op names:
setdomaininfo -> setvcpucontext
pincpudomain -> setvcpuaffinity

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jan 06 12:53:19 2006 +0100 (2006-01-06)
parents d966b7a00959
children 8aeb417387ca
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_vcpu_setaffinity(int xc_handle,
62 uint32_t domid,
63 int vcpu,
64 cpumap_t cpumap)
65 {
66 DECLARE_DOM0_OP;
67 op.cmd = DOM0_SETVCPUAFFINITY;
68 op.u.setvcpuaffinity.domain = (domid_t)domid;
69 op.u.setvcpuaffinity.vcpu = vcpu;
70 op.u.setvcpuaffinity.cpumap = cpumap;
71 return do_dom0_op(xc_handle, &op);
72 }
75 int xc_domain_getinfo(int xc_handle,
76 uint32_t first_domid,
77 unsigned int max_doms,
78 xc_dominfo_t *info)
79 {
80 unsigned int nr_doms;
81 uint32_t next_domid = first_domid;
82 DECLARE_DOM0_OP;
83 int rc = 0;
85 memset(info, 0, max_doms*sizeof(xc_dominfo_t));
87 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
88 {
89 op.cmd = DOM0_GETDOMAININFO;
90 op.u.getdomaininfo.domain = (domid_t)next_domid;
91 if ( (rc = do_dom0_op(xc_handle, &op)) < 0 )
92 break;
93 info->domid = (uint16_t)op.u.getdomaininfo.domain;
95 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
96 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
97 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
98 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
99 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
101 info->shutdown_reason =
102 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
103 DOMFLAGS_SHUTDOWNMASK;
105 if ( info->shutdown && (info->shutdown_reason == SHUTDOWN_crash) )
106 {
107 info->shutdown = 0;
108 info->crashed = 1;
109 }
111 info->ssidref = op.u.getdomaininfo.ssidref;
112 info->nr_pages = op.u.getdomaininfo.tot_pages;
113 info->max_memkb = op.u.getdomaininfo.max_pages << (PAGE_SHIFT - 10);
114 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
115 info->cpu_time = op.u.getdomaininfo.cpu_time;
116 info->nr_online_vcpus = op.u.getdomaininfo.nr_online_vcpus;
117 info->max_vcpu_id = op.u.getdomaininfo.max_vcpu_id;
119 memcpy(info->handle, op.u.getdomaininfo.handle,
120 sizeof(xen_domain_handle_t));
122 next_domid = (uint16_t)op.u.getdomaininfo.domain + 1;
123 info++;
124 }
126 if( !nr_doms ) return rc;
128 return nr_doms;
129 }
131 int xc_domain_getinfolist(int xc_handle,
132 uint32_t first_domain,
133 unsigned int max_domains,
134 xc_domaininfo_t *info)
135 {
136 int ret = 0;
137 DECLARE_DOM0_OP;
139 if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
140 return -1;
142 op.cmd = DOM0_GETDOMAININFOLIST;
143 op.u.getdomaininfolist.first_domain = first_domain;
144 op.u.getdomaininfolist.max_domains = max_domains;
145 op.u.getdomaininfolist.buffer = info;
147 if ( xc_dom0_op(xc_handle, &op) < 0 )
148 ret = -1;
149 else
150 ret = op.u.getdomaininfolist.num_domains;
152 if ( munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
153 ret = -1;
155 return ret;
156 }
158 int xc_vcpu_getcontext(int xc_handle,
159 uint32_t domid,
160 uint32_t vcpu,
161 vcpu_guest_context_t *ctxt)
162 {
163 int rc;
164 DECLARE_DOM0_OP;
166 op.cmd = DOM0_GETVCPUCONTEXT;
167 op.u.getvcpucontext.domain = (domid_t)domid;
168 op.u.getvcpucontext.vcpu = (uint16_t)vcpu;
169 op.u.getvcpucontext.ctxt = ctxt;
171 if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
172 return rc;
174 rc = do_dom0_op(xc_handle, &op);
176 safe_munlock(ctxt, sizeof(*ctxt));
178 return rc;
179 }
182 int xc_shadow_control(int xc_handle,
183 uint32_t domid,
184 unsigned int sop,
185 unsigned long *dirty_bitmap,
186 unsigned long pages,
187 xc_shadow_control_stats_t *stats )
188 {
189 int rc;
190 DECLARE_DOM0_OP;
191 op.cmd = DOM0_SHADOW_CONTROL;
192 op.u.shadow_control.domain = (domid_t)domid;
193 op.u.shadow_control.op = sop;
194 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
195 op.u.shadow_control.pages = pages;
197 rc = do_dom0_op(xc_handle, &op);
199 if ( stats )
200 memcpy(stats, &op.u.shadow_control.stats,
201 sizeof(xc_shadow_control_stats_t));
203 return (rc == 0) ? op.u.shadow_control.pages : rc;
204 }
206 int xc_domain_setcpuweight(int xc_handle,
207 uint32_t domid,
208 float weight)
209 {
210 int sched_id;
211 int ret;
213 /* Figure out which scheduler is currently used: */
214 if ( (ret = xc_sched_id(xc_handle, &sched_id)) != 0 )
215 return ret;
217 switch ( sched_id )
218 {
219 case SCHED_BVT:
220 {
221 uint32_t mcuadv;
222 int warpback;
223 int32_t warpvalue;
224 long long warpl;
225 long long warpu;
227 /* Preserve all the scheduling parameters apart
228 of MCU advance. */
229 if ( (ret = xc_bvtsched_domain_get(
230 xc_handle, domid, &mcuadv,
231 &warpback, &warpvalue, &warpl, &warpu)) != 0 )
232 return ret;
234 /* The MCU advance is inverse of the weight.
235 Default value of the weight is 1, default mcuadv 10.
236 The scaling factor is therefore 10. */
237 if ( weight > 0 )
238 mcuadv = 10 / weight;
240 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
241 warpback, warpvalue, warpl, warpu);
242 break;
243 }
244 }
246 return ret;
247 }
249 int xc_domain_setmaxmem(int xc_handle,
250 uint32_t domid,
251 unsigned int max_memkb)
252 {
253 DECLARE_DOM0_OP;
254 op.cmd = DOM0_SETDOMAINMAXMEM;
255 op.u.setdomainmaxmem.domain = (domid_t)domid;
256 op.u.setdomainmaxmem.max_memkb = max_memkb;
257 return do_dom0_op(xc_handle, &op);
258 }
260 int xc_domain_memory_increase_reservation(int xc_handle,
261 uint32_t domid,
262 unsigned long nr_extents,
263 unsigned int extent_order,
264 unsigned int address_bits,
265 unsigned long *extent_start)
266 {
267 int err;
268 struct xen_memory_reservation reservation = {
269 .extent_start = extent_start, /* may be NULL */
270 .nr_extents = nr_extents,
271 .extent_order = extent_order,
272 .address_bits = address_bits,
273 .domid = domid
274 };
276 err = xc_memory_op(xc_handle, XENMEM_increase_reservation, &reservation);
277 if ( err == nr_extents )
278 return 0;
280 if ( err > 0 )
281 {
282 fprintf(stderr, "Failed allocation for dom %d: "
283 "%ld pages order %d addr_bits %d\n",
284 domid, nr_extents, extent_order, address_bits);
285 errno = ENOMEM;
286 err = -1;
287 }
289 return err;
290 }
292 int xc_domain_memory_decrease_reservation(int xc_handle,
293 uint32_t domid,
294 unsigned long nr_extents,
295 unsigned int extent_order,
296 unsigned long *extent_start)
297 {
298 int err;
299 struct xen_memory_reservation reservation = {
300 .extent_start = extent_start,
301 .nr_extents = nr_extents,
302 .extent_order = extent_order,
303 .address_bits = 0,
304 .domid = domid
305 };
307 if ( extent_start == NULL )
308 {
309 fprintf(stderr,"decrease_reservation extent_start is NULL!\n");
310 errno = EINVAL;
311 return -1;
312 }
314 err = xc_memory_op(xc_handle, XENMEM_decrease_reservation, &reservation);
315 if ( err == nr_extents )
316 return 0;
318 if ( err > 0 )
319 {
320 fprintf(stderr,"Failed deallocation for dom %d: %ld pages order %d\n",
321 domid, nr_extents, extent_order);
322 errno = EBUSY;
323 err = -1;
324 }
326 return err;
327 }
329 int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
330 {
331 DECLARE_DOM0_OP;
332 op.cmd = DOM0_MAX_VCPUS;
333 op.u.max_vcpus.domain = (domid_t)domid;
334 op.u.max_vcpus.max = max;
335 return do_dom0_op(xc_handle, &op);
336 }
338 int xc_domain_sethandle(int xc_handle, uint32_t domid,
339 xen_domain_handle_t handle)
340 {
341 DECLARE_DOM0_OP;
342 op.cmd = DOM0_SETDOMAINHANDLE;
343 op.u.setdomainhandle.domain = (domid_t)domid;
344 memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t));
345 return do_dom0_op(xc_handle, &op);
346 }
348 int xc_vcpu_getinfo(int xc_handle,
349 uint32_t domid,
350 uint32_t vcpu,
351 xc_vcpuinfo_t *info)
352 {
353 int rc;
354 DECLARE_DOM0_OP;
355 op.cmd = DOM0_GETVCPUINFO;
356 op.u.getvcpuinfo.domain = (domid_t)domid;
357 op.u.getvcpuinfo.vcpu = (uint16_t)vcpu;
359 rc = do_dom0_op(xc_handle, &op);
361 memcpy(info, &op.u.getvcpuinfo, sizeof(*info));
363 return rc;
364 }
366 int xc_domain_ioport_permission(int xc_handle,
367 uint32_t domid,
368 uint32_t first_port,
369 uint32_t nr_ports,
370 uint32_t allow_access)
371 {
372 DECLARE_DOM0_OP;
374 op.cmd = DOM0_IOPORT_PERMISSION;
375 op.u.ioport_permission.domain = (domid_t)domid;
376 op.u.ioport_permission.first_port = first_port;
377 op.u.ioport_permission.nr_ports = nr_ports;
378 op.u.ioport_permission.allow_access = allow_access;
380 return do_dom0_op(xc_handle, &op);
381 }
383 int xc_vcpu_setcontext(int xc_handle,
384 uint32_t domid,
385 uint32_t vcpu,
386 vcpu_guest_context_t *ctxt)
387 {
388 dom0_op_t op;
389 int rc;
391 op.cmd = DOM0_SETVCPUCONTEXT;
392 op.u.setvcpucontext.domain = domid;
393 op.u.setvcpucontext.vcpu = vcpu;
394 op.u.setvcpucontext.ctxt = ctxt;
396 if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
397 return rc;
399 rc = do_dom0_op(xc_handle, &op);
401 safe_munlock(ctxt, sizeof(*ctxt));
403 return rc;
405 }
407 int xc_domain_irq_permission(int xc_handle,
408 uint32_t domid,
409 uint8_t pirq,
410 uint8_t allow_access)
411 {
412 dom0_op_t op;
414 op.cmd = DOM0_IRQ_PERMISSION;
415 op.u.irq_permission.domain = domid;
416 op.u.irq_permission.pirq = pirq;
417 op.u.irq_permission.allow_access = allow_access;
419 return do_dom0_op(xc_handle, &op);
420 }
422 int xc_domain_iomem_permission(int xc_handle,
423 uint32_t domid,
424 unsigned long first_pfn,
425 unsigned long nr_pfns,
426 uint8_t allow_access)
427 {
428 dom0_op_t op;
430 op.cmd = DOM0_IOMEM_PERMISSION;
431 op.u.iomem_permission.domain = domid;
432 op.u.iomem_permission.first_pfn = first_pfn;
433 op.u.iomem_permission.nr_pfns = nr_pfns;
434 op.u.iomem_permission.allow_access = allow_access;
436 return do_dom0_op(xc_handle, &op);
437 }
439 /*
440 * Local variables:
441 * mode: C
442 * c-set-style: "BSD"
443 * c-basic-offset: 4
444 * tab-width: 4
445 * indent-tabs-mode: nil
446 * End:
447 */