ia64/xen-unstable

view tools/libxc/xc_domain.c @ 5548:d5eaab0c875d

bitkeeper revision 1.1730 (42ba7dbdkTADQfBqHaC_Ynqo3i1ZVw)

The xc_domain_getinfo does not clear the info structure before filling
it in, and in some circumstances it doesn't completely fill in the
structure for each domain. In particular, it sets the crashed flag if
the domain has crashed, but does not clear it if the domain has not
crashed, so the crashed flag may be random stack garbage from the
calling program. With the attached patch (against the latest nightly),
xc_domain_getinfo zeroes the array of info structures before filling
them in.

Signed-off-by: Josh Triplett <josht@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Jun 23 09:15:41 2005 +0000 (2005-06-23)
parents 76346519b28e
children eef23f57f20e 579d1e771025 c1a7ed266c7e
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);
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_get_vcpu_context(int xc_handle,
129 u32 domid,
130 u32 vcpu,
131 vcpu_guest_context_t *ctxt)
132 {
133 int rc;
134 dom0_op_t op;
136 op.cmd = DOM0_GETVCPUCONTEXT;
137 op.u.getvcpucontext.domain = (domid_t)domid;
138 op.u.getvcpucontext.vcpu = (u16)vcpu;
139 op.u.getvcpucontext.ctxt = ctxt;
141 if ( (ctxt != NULL) &&
142 ((rc = mlock(ctxt, sizeof(*ctxt))) != 0) )
143 return rc;
145 rc = do_dom0_op(xc_handle, &op);
147 if ( ctxt != NULL )
148 safe_munlock(ctxt, sizeof(*ctxt));
150 if ( rc > 0 )
151 return -ESRCH;
152 else
153 return rc;
154 }
157 int xc_shadow_control(int xc_handle,
158 u32 domid,
159 unsigned int sop,
160 unsigned long *dirty_bitmap,
161 unsigned long pages,
162 xc_shadow_control_stats_t *stats )
163 {
164 int rc;
165 dom0_op_t op;
166 op.cmd = DOM0_SHADOW_CONTROL;
167 op.u.shadow_control.domain = (domid_t)domid;
168 op.u.shadow_control.op = sop;
169 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
170 op.u.shadow_control.pages = pages;
172 rc = do_dom0_op(xc_handle, &op);
174 if ( stats )
175 memcpy(stats, &op.u.shadow_control.stats,
176 sizeof(xc_shadow_control_stats_t));
178 return (rc == 0) ? op.u.shadow_control.pages : rc;
179 }
181 int xc_domain_setcpuweight(int xc_handle,
182 u32 domid,
183 float weight)
184 {
185 int sched_id;
186 int ret;
188 /* Figure out which scheduler is currently used: */
189 if ( (ret = xc_sched_id(xc_handle, &sched_id)) != 0 )
190 return ret;
192 switch ( sched_id )
193 {
194 case SCHED_BVT:
195 {
196 u32 mcuadv;
197 int warpback;
198 s32 warpvalue;
199 long long warpl;
200 long long warpu;
202 /* Preserve all the scheduling parameters apart
203 of MCU advance. */
204 if ( (ret = xc_bvtsched_domain_get(
205 xc_handle, domid, &mcuadv,
206 &warpback, &warpvalue, &warpl, &warpu)) != 0 )
207 return ret;
209 /* The MCU advance is inverse of the weight.
210 Default value of the weight is 1, default mcuadv 10.
211 The scaling factor is therefore 10. */
212 if ( weight > 0 )
213 mcuadv = 10 / weight;
215 ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
216 warpback, warpvalue, warpl, warpu);
217 break;
218 }
219 }
221 return ret;
222 }
224 int xc_domain_setmaxmem(int xc_handle,
225 u32 domid,
226 unsigned int max_memkb)
227 {
228 dom0_op_t op;
229 op.cmd = DOM0_SETDOMAINMAXMEM;
230 op.u.setdomainmaxmem.domain = (domid_t)domid;
231 op.u.setdomainmaxmem.max_memkb = max_memkb;
232 return do_dom0_op(xc_handle, &op);
233 }
235 int xc_domain_memory_increase_reservation(int xc_handle,
236 u32 domid,
237 unsigned int mem_kb)
238 {
239 int err;
241 err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
242 mem_kb / 4, 0, domid);
243 if (err == mem_kb / 4)
244 return 0;
246 if (err > 0) {
247 errno = ENOMEM;
248 err = -1;
249 }
250 return err;
251 }