ia64/xen-unstable

view tools/libxc/xc_domain.c @ 1820:3d4f8eb89670

bitkeeper revision 1.1106.1.2 (40faa780dekT3E5arFwcbQDu1MbX6g)

Cleaned up Xen's instruction emulator.
author kaf24@scramble.cl.cam.ac.uk
date Sun Jul 18 16:38:24 2004 +0000 (2004-07-18)
parents 236a9f2698a3
children de62fd103f99 dae98734f12e
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 const char *name,
14 int cpu,
15 u32 *pdomid)
16 {
17 int err;
18 dom0_op_t op;
20 op.cmd = DOM0_CREATEDOMAIN;
21 op.u.createdomain.memory_kb = mem_kb;
22 strncpy(op.u.createdomain.name, name, MAX_DOMAIN_NAME);
23 op.u.createdomain.name[MAX_DOMAIN_NAME-1] = '\0';
24 op.u.createdomain.cpu = cpu;
26 if ( (err = do_dom0_op(xc_handle, &op)) == 0 )
27 *pdomid = (u32)op.u.createdomain.domain;
29 return err;
30 }
33 int xc_domain_pause(int xc_handle,
34 u32 domid)
35 {
36 dom0_op_t op;
37 op.cmd = DOM0_PAUSEDOMAIN;
38 op.u.pausedomain.domain = (domid_t)domid;
39 return do_dom0_op(xc_handle, &op);
40 }
43 int xc_domain_unpause(int xc_handle,
44 u32 domid)
45 {
46 dom0_op_t op;
47 op.cmd = DOM0_UNPAUSEDOMAIN;
48 op.u.unpausedomain.domain = (domid_t)domid;
49 return do_dom0_op(xc_handle, &op);
50 }
53 int xc_domain_destroy(int xc_handle,
54 u32 domid)
55 {
56 dom0_op_t op;
57 op.cmd = DOM0_DESTROYDOMAIN;
58 op.u.destroydomain.domain = (domid_t)domid;
59 return do_dom0_op(xc_handle, &op);
60 }
62 int xc_domain_pincpu(int xc_handle,
63 u32 domid,
64 int cpu)
65 {
66 dom0_op_t op;
67 op.cmd = DOM0_PINCPUDOMAIN;
68 op.u.pincpudomain.domain = (domid_t)domid;
69 op.u.pincpudomain.cpu = cpu;
70 return do_dom0_op(xc_handle, &op);
71 }
74 int xc_domain_getinfo(int xc_handle,
75 u32 first_domid,
76 unsigned int max_doms,
77 xc_dominfo_t *info)
78 {
79 unsigned int nr_doms;
80 u32 next_domid = first_domid;
81 dom0_op_t op;
83 for ( nr_doms = 0; nr_doms < max_doms; nr_doms++ )
84 {
85 op.cmd = DOM0_GETDOMAININFO;
86 op.u.getdomaininfo.domain = (domid_t)next_domid;
87 op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
88 if ( do_dom0_op(xc_handle, &op) < 0 )
89 break;
90 info->domid = (u32)op.u.getdomaininfo.domain;
92 info->cpu =
93 (op.u.getdomaininfo.flags>>DOMFLAGS_CPUSHIFT) & DOMFLAGS_CPUMASK;
95 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
96 info->crashed = !!(op.u.getdomaininfo.flags & DOMFLAGS_CRASHED);
97 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
98 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
99 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
100 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
102 info->shutdown_reason =
103 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
104 DOMFLAGS_SHUTDOWNMASK;
106 info->nr_pages = op.u.getdomaininfo.tot_pages;
107 info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT-10);
108 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
109 info->cpu_time = op.u.getdomaininfo.cpu_time;
110 strncpy(info->name, op.u.getdomaininfo.name, XC_DOMINFO_MAXNAME);
111 info->name[XC_DOMINFO_MAXNAME-1] = '\0';
113 next_domid = (u32)op.u.getdomaininfo.domain + 1;
114 info++;
115 }
117 return nr_doms;
118 }
120 int xc_domain_getfullinfo(int xc_handle,
121 u32 domid,
122 dom0_op_t *op,
123 full_execution_context_t *ctxt )
124 {
125 int rc;
126 op->cmd = DOM0_GETDOMAININFO;
127 op->u.getdomaininfo.domain = (domid_t)domid;
128 op->u.getdomaininfo.ctxt = ctxt;
130 rc = do_dom0_op(xc_handle, op);
131 if ( ((u32)op->u.getdomaininfo.domain != domid) && rc > 0 )
132 return -ESRCH;
133 else
134 return rc;
135 }
138 int xc_shadow_control(int xc_handle,
139 u32 domid,
140 unsigned int sop,
141 unsigned long *dirty_bitmap,
142 unsigned long pages,
143 xc_shadow_control_stats_t *stats )
144 {
145 int rc;
146 dom0_op_t op;
147 op.cmd = DOM0_SHADOW_CONTROL;
148 op.u.shadow_control.domain = (domid_t)domid;
149 op.u.shadow_control.op = sop;
150 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
151 op.u.shadow_control.pages = pages;
153 rc = do_dom0_op(xc_handle, &op);
155 if ( stats )
156 memcpy(stats, &op.u.shadow_control.stats,
157 sizeof(xc_shadow_control_stats_t));
159 return (rc == 0) ? op.u.shadow_control.pages : rc;
160 }
162 int xc_domain_setname(int xc_handle,
163 u32 domid,
164 char *name)
165 {
166 dom0_op_t op;
167 op.cmd = DOM0_SETDOMAINNAME;
168 op.u.setdomainname.domain = (domid_t)domid;
169 strncpy(op.u.setdomainname.name, name, MAX_DOMAIN_NAME);
170 return do_dom0_op(xc_handle, &op);
171 }
173 int xc_domain_setinitialmem(int xc_handle,
174 u32 domid,
175 unsigned int initial_memkb)
176 {
177 dom0_op_t op;
178 op.cmd = DOM0_SETDOMAININITIALMEM;
179 op.u.setdomaininitialmem.domain = (domid_t)domid;
180 op.u.setdomaininitialmem.initial_memkb = initial_memkb;
181 return do_dom0_op(xc_handle, &op);
182 }
184 int xc_domain_setmaxmem(int xc_handle,
185 u32 domid,
186 unsigned int max_memkb)
187 {
188 dom0_op_t op;
189 op.cmd = DOM0_SETDOMAINMAXMEM;
190 op.u.setdomainmaxmem.domain = (domid_t)domid;
191 op.u.setdomainmaxmem.max_memkb = max_memkb;
192 return do_dom0_op(xc_handle, &op);
193 }