ia64/xen-unstable

view tools/libxc/xc_domain.c @ 4645:cc637433c0fd

bitkeeper revision 1.1373 (426a2bc8m7wX71OOkLtSOgNXcrObMA)

xc_domain.c:
Ensure ctxt is mlocked in xc_domain_getfullinfo.
author kaf24@firebug.cl.cam.ac.uk
date Sat Apr 23 11:04:40 2005 +0000 (2005-04-23)
parents 10b57175d4e2
children a6945f416cd0 98d5be103415
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 unsigned int mem_kb,
13 int cpu,
14 float cpu_weight,
15 u32 *pdomid)
16 {
17 int err, errno_saved;
18 dom0_op_t op;
20 op.cmd = DOM0_CREATEDOMAIN;
21 op.u.createdomain.domain = (domid_t)*pdomid;
22 if ( (err = do_dom0_op(xc_handle, &op)) != 0 )
23 return err;
25 *pdomid = (u16)op.u.createdomain.domain;
27 if ( (cpu != -1) &&
28 ((err = xc_domain_pincpu(xc_handle, *pdomid, cpu)) != 0) )
29 goto fail;
31 if ( (err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight)) != 0 )
32 goto fail;
34 if ( (err = xc_domain_setmaxmem(xc_handle, *pdomid, mem_kb)) != 0 )
35 goto fail;
37 if ( (err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation,
38 NULL, mem_kb/4, 0, *pdomid)) != (mem_kb/4) )
39 {
40 if ( err > 0 )
41 errno = ENOMEM;
42 err = -1;
43 goto fail;
44 }
46 return err;
48 fail:
49 errno_saved = errno;
50 (void)xc_domain_destroy(xc_handle, *pdomid);
51 errno = errno_saved;
52 return err;
53 }
56 int xc_domain_pause(int xc_handle,
57 u32 domid)
58 {
59 dom0_op_t op;
60 op.cmd = DOM0_PAUSEDOMAIN;
61 op.u.pausedomain.domain = (domid_t)domid;
62 return do_dom0_op(xc_handle, &op);
63 }
66 int xc_domain_unpause(int xc_handle,
67 u32 domid)
68 {
69 dom0_op_t op;
70 op.cmd = DOM0_UNPAUSEDOMAIN;
71 op.u.unpausedomain.domain = (domid_t)domid;
72 return do_dom0_op(xc_handle, &op);
73 }
76 int xc_domain_destroy(int xc_handle,
77 u32 domid)
78 {
79 dom0_op_t op;
80 op.cmd = DOM0_DESTROYDOMAIN;
81 op.u.destroydomain.domain = (domid_t)domid;
82 return do_dom0_op(xc_handle, &op);
83 }
85 int xc_domain_pincpu(int xc_handle,
86 u32 domid,
87 int cpu)
88 {
89 dom0_op_t op;
90 op.cmd = DOM0_PINCPUDOMAIN;
91 op.u.pincpudomain.domain = (domid_t)domid;
92 op.u.pincpudomain.exec_domain = 0;
93 op.u.pincpudomain.cpu = cpu;
94 return do_dom0_op(xc_handle, &op);
95 }
98 int xc_domain_getinfo(int xc_handle,
99 u32 first_domid,
100 unsigned int max_doms,
101 xc_dominfo_t *info)
102 {
103 unsigned int nr_doms;
104 u32 next_domid = first_domid;
105 dom0_op_t op;
107 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
108 {
109 op.cmd = DOM0_GETDOMAININFO;
110 op.u.getdomaininfo.domain = (domid_t)next_domid;
111 op.u.getdomaininfo.exec_domain = 0; // FIX ME?!?
112 op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
113 if ( do_dom0_op(xc_handle, &op) < 0 )
114 break;
115 info->domid = (u16)op.u.getdomaininfo.domain;
117 info->cpu =
118 (op.u.getdomaininfo.flags>>DOMFLAGS_CPUSHIFT) & DOMFLAGS_CPUMASK;
120 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
121 info->crashed = !!(op.u.getdomaininfo.flags & DOMFLAGS_CRASHED);
122 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
123 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
124 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
125 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
127 info->shutdown_reason =
128 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
129 DOMFLAGS_SHUTDOWNMASK;
131 info->nr_pages = op.u.getdomaininfo.tot_pages;
132 info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT);
133 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
134 info->cpu_time = op.u.getdomaininfo.cpu_time;
136 next_domid = (u16)op.u.getdomaininfo.domain + 1;
137 info++;
138 }
140 return nr_doms;
141 }
143 int xc_domain_getfullinfo(int xc_handle,
144 u32 domid,
145 u32 vcpu,
146 xc_domaininfo_t *info,
147 full_execution_context_t *ctxt)
148 {
149 int rc, errno_saved;
150 dom0_op_t op;
152 op.cmd = DOM0_GETDOMAININFO;
153 op.u.getdomaininfo.domain = (domid_t)domid;
154 op.u.getdomaininfo.exec_domain = (u16)vcpu;
155 op.u.getdomaininfo.ctxt = ctxt;
157 if ( (ctxt != NULL) &&
158 ((rc = mlock(ctxt, sizeof(*ctxt))) != 0) )
159 return rc;
161 rc = do_dom0_op(xc_handle, &op);
163 if ( ctxt != NULL )
164 {
165 errno_saved = errno;
166 (void)munlock(ctxt, sizeof(*ctxt));
167 errno = errno_saved;
168 }
170 if ( info != NULL )
171 memcpy(info, &op.u.getdomaininfo, sizeof(*info));
173 if ( ((u16)op.u.getdomaininfo.domain != domid) && (rc > 0) )
174 return -ESRCH;
175 else
176 return rc;
177 }
180 int xc_shadow_control(int xc_handle,
181 u32 domid,
182 unsigned int sop,
183 unsigned long *dirty_bitmap,
184 unsigned long pages,
185 xc_shadow_control_stats_t *stats )
186 {
187 int rc;
188 dom0_op_t op;
189 op.cmd = DOM0_SHADOW_CONTROL;
190 op.u.shadow_control.domain = (domid_t)domid;
191 op.u.shadow_control.op = sop;
192 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
193 op.u.shadow_control.pages = pages;
195 rc = do_dom0_op(xc_handle, &op);
197 if ( stats )
198 memcpy(stats, &op.u.shadow_control.stats,
199 sizeof(xc_shadow_control_stats_t));
201 return (rc == 0) ? op.u.shadow_control.pages : rc;
202 }
204 int xc_domain_setcpuweight(int xc_handle,
205 u32 domid,
206 float weight)
207 {
208 int sched_id;
209 int ret;
211 /* Figure out which scheduler is currently used: */
212 if ( (ret = xc_sched_id(xc_handle, &sched_id)) != 0 )
213 return ret;
215 switch ( sched_id )
216 {
217 case SCHED_BVT:
218 {
219 u32 mcuadv;
220 int warpback;
221 s32 warpvalue;
222 long long warpl;
223 long long warpu;
225 /* Preserve all the scheduling parameters apart
226 of MCU advance. */
227 if ( (ret = xc_bvtsched_domain_get(
228 xc_handle, domid, &mcuadv,
229 &warpback, &warpvalue, &warpl, &warpu)) != 0 )
230 return ret;
232 /* The MCU advance is inverse of the weight.
233 Default value of the weight is 1, default mcuadv 10.
234 The scaling factor is therefore 10. */
235 if ( weight > 0 )
236 mcuadv = 10 / weight;
238 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
239 warpback, warpvalue, warpl, warpu);
240 break;
241 }
242 }
244 return ret;
245 }
247 int xc_domain_setmaxmem(int xc_handle,
248 u32 domid,
249 unsigned int max_memkb)
250 {
251 dom0_op_t op;
252 op.cmd = DOM0_SETDOMAINMAXMEM;
253 op.u.setdomainmaxmem.domain = (domid_t)domid;
254 op.u.setdomainmaxmem.max_memkb = max_memkb;
255 return do_dom0_op(xc_handle, &op);
256 }