ia64/xen-unstable

view tools/libxc/xc_domain.c @ 6435:b4b3f6be5226

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 17:27:49 2005 +0000 (2005-08-25)
parents 0610add7c3fe fdfd511768a3
children 8799d14bef77 9312a3e8a6f8 112d44270733
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"
11 int xc_domain_create(int xc_handle,
12 u32 ssidref,
13 u32 *pdomid)
14 {
15 int err;
16 dom0_op_t op;
18 op.cmd = DOM0_CREATEDOMAIN;
19 op.u.createdomain.domain = (domid_t)*pdomid;
20 op.u.createdomain.ssidref = ssidref;
21 if ( (err = do_dom0_op(xc_handle, &op)) != 0 )
22 return err;
24 *pdomid = (u16)op.u.createdomain.domain;
25 return 0;
26 }
29 int xc_domain_pause(int xc_handle,
30 u32 domid)
31 {
32 dom0_op_t op;
33 op.cmd = DOM0_PAUSEDOMAIN;
34 op.u.pausedomain.domain = (domid_t)domid;
35 return do_dom0_op(xc_handle, &op);
36 }
39 int xc_domain_unpause(int xc_handle,
40 u32 domid)
41 {
42 dom0_op_t op;
43 op.cmd = DOM0_UNPAUSEDOMAIN;
44 op.u.unpausedomain.domain = (domid_t)domid;
45 return do_dom0_op(xc_handle, &op);
46 }
49 int xc_domain_destroy(int xc_handle,
50 u32 domid)
51 {
52 dom0_op_t op;
53 op.cmd = DOM0_DESTROYDOMAIN;
54 op.u.destroydomain.domain = (domid_t)domid;
55 return do_dom0_op(xc_handle, &op);
56 }
58 int xc_domain_pincpu(int xc_handle,
59 u32 domid,
60 int vcpu,
61 cpumap_t *cpumap)
62 {
63 dom0_op_t op;
64 op.cmd = DOM0_PINCPUDOMAIN;
65 op.u.pincpudomain.domain = (domid_t)domid;
66 op.u.pincpudomain.vcpu = vcpu;
67 op.u.pincpudomain.cpumap = cpumap;
68 return do_dom0_op(xc_handle, &op);
69 }
72 int xc_domain_getinfo(int xc_handle,
73 u32 first_domid,
74 unsigned int max_doms,
75 xc_dominfo_t *info)
76 {
77 unsigned int nr_doms;
78 u32 next_domid = first_domid;
79 dom0_op_t op;
80 int rc = 0;
82 memset(info, 0, max_doms*sizeof(xc_dominfo_t));
84 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
85 {
86 op.cmd = DOM0_GETDOMAININFO;
87 op.u.getdomaininfo.domain = (domid_t)next_domid;
88 if ( (rc = do_dom0_op(xc_handle, &op)) < 0 )
89 break;
90 info->domid = (u16)op.u.getdomaininfo.domain;
92 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
93 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
94 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
95 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
96 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
98 info->shutdown_reason =
99 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
100 DOMFLAGS_SHUTDOWNMASK;
102 if ( info->shutdown && (info->shutdown_reason == SHUTDOWN_crash) )
103 {
104 info->shutdown = 0;
105 info->crashed = 1;
106 }
108 info->ssidref = op.u.getdomaininfo.ssidref;
109 info->nr_pages = op.u.getdomaininfo.tot_pages;
110 info->max_memkb = op.u.getdomaininfo.max_pages << (PAGE_SHIFT - 10);
111 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
112 info->cpu_time = op.u.getdomaininfo.cpu_time;
113 info->vcpus = op.u.getdomaininfo.n_vcpu;
114 memcpy(&info->vcpu_to_cpu, &op.u.getdomaininfo.vcpu_to_cpu,
115 sizeof(info->vcpu_to_cpu));
116 memcpy(&info->cpumap, &op.u.getdomaininfo.cpumap,
117 sizeof(info->cpumap));
119 next_domid = (u16)op.u.getdomaininfo.domain + 1;
120 info++;
121 }
123 if( !nr_doms ) return rc;
125 return nr_doms;
126 }
128 int xc_domain_getinfolist(int xc_handle,
129 u32 first_domain,
130 unsigned int max_domains,
131 xc_domaininfo_t *info)
132 {
133 int ret = 0;
134 dom0_op_t op;
136 if(mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0)
137 return -1;
139 op.cmd = DOM0_GETDOMAININFOLIST;
140 op.u.getdomaininfolist.first_domain = first_domain;
141 op.u.getdomaininfolist.max_domains = max_domains;
142 op.u.getdomaininfolist.buffer = info;
144 if(xc_dom0_op(xc_handle, &op) < 0)
145 ret = -1;
146 else
147 ret = op.u.getdomaininfolist.num_domains;
149 if(munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0)
150 ret = -1;
152 return ret;
153 }
155 int xc_domain_get_vcpu_context(int xc_handle,
156 u32 domid,
157 u32 vcpu,
158 vcpu_guest_context_t *ctxt)
159 {
160 int rc;
161 dom0_op_t op;
163 op.cmd = DOM0_GETVCPUCONTEXT;
164 op.u.getvcpucontext.domain = (domid_t)domid;
165 op.u.getvcpucontext.vcpu = (u16)vcpu;
166 op.u.getvcpucontext.ctxt = ctxt;
168 if ( (ctxt != NULL) &&
169 ((rc = mlock(ctxt, sizeof(*ctxt))) != 0) )
170 return rc;
172 rc = do_dom0_op(xc_handle, &op);
174 if ( ctxt != NULL )
175 safe_munlock(ctxt, sizeof(*ctxt));
177 if ( rc > 0 )
178 return -ESRCH;
179 else
180 return rc;
181 }
184 int xc_shadow_control(int xc_handle,
185 u32 domid,
186 unsigned int sop,
187 unsigned long *dirty_bitmap,
188 unsigned long pages,
189 xc_shadow_control_stats_t *stats )
190 {
191 int rc;
192 dom0_op_t op;
193 op.cmd = DOM0_SHADOW_CONTROL;
194 op.u.shadow_control.domain = (domid_t)domid;
195 op.u.shadow_control.op = sop;
196 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
197 op.u.shadow_control.pages = pages;
199 rc = do_dom0_op(xc_handle, &op);
201 if ( stats )
202 memcpy(stats, &op.u.shadow_control.stats,
203 sizeof(xc_shadow_control_stats_t));
205 return (rc == 0) ? op.u.shadow_control.pages : rc;
206 }
208 int xc_domain_setcpuweight(int xc_handle,
209 u32 domid,
210 float weight)
211 {
212 int sched_id;
213 int ret;
215 /* Figure out which scheduler is currently used: */
216 if ( (ret = xc_sched_id(xc_handle, &sched_id)) != 0 )
217 return ret;
219 switch ( sched_id )
220 {
221 case SCHED_BVT:
222 {
223 u32 mcuadv;
224 int warpback;
225 s32 warpvalue;
226 long long warpl;
227 long long warpu;
229 /* Preserve all the scheduling parameters apart
230 of MCU advance. */
231 if ( (ret = xc_bvtsched_domain_get(
232 xc_handle, domid, &mcuadv,
233 &warpback, &warpvalue, &warpl, &warpu)) != 0 )
234 return ret;
236 /* The MCU advance is inverse of the weight.
237 Default value of the weight is 1, default mcuadv 10.
238 The scaling factor is therefore 10. */
239 if ( weight > 0 )
240 mcuadv = 10 / weight;
242 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
243 warpback, warpvalue, warpl, warpu);
244 break;
245 }
246 }
248 return ret;
249 }
251 int xc_domain_setmaxmem(int xc_handle,
252 u32 domid,
253 unsigned int max_memkb)
254 {
255 dom0_op_t op;
256 op.cmd = DOM0_SETDOMAINMAXMEM;
257 op.u.setdomainmaxmem.domain = (domid_t)domid;
258 op.u.setdomainmaxmem.max_memkb = max_memkb;
259 return do_dom0_op(xc_handle, &op);
260 }
262 int xc_domain_memory_increase_reservation(int xc_handle,
263 u32 domid,
264 unsigned int mem_kb)
265 {
266 int err;
267 unsigned int npages = mem_kb / (PAGE_SIZE/1024);
269 err = xc_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
270 npages, 0, domid);
271 if (err == npages)
272 return 0;
274 if (err > 0) {
275 errno = ENOMEM;
276 err = -1;
277 }
278 return err;
279 }