ia64/xen-unstable

view tools/libxc/xc_domain.c @ 1921:24ecc060e9d7

bitkeeper revision 1.1108.21.1 (41062740xHG36OEbpVAmVX5N9WCaNw)

make vmlinuz really stripped
author cl349@freefall.cl.cam.ac.uk
date Tue Jul 27 09:58:24 2004 +0000 (2004-07-27)
parents de62fd103f99
children 4068e3051909 7d853b31485c 04ebbad06e8f f9ae44cc1373
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.domain = (domid_t)*pdomid;
22 op.u.createdomain.memory_kb = mem_kb;
23 strncpy(op.u.createdomain.name, name, MAX_DOMAIN_NAME);
24 op.u.createdomain.name[MAX_DOMAIN_NAME-1] = '\0';
25 op.u.createdomain.cpu = cpu;
27 if ( (err = do_dom0_op(xc_handle, &op)) == 0 )
28 *pdomid = (u32)op.u.createdomain.domain;
30 return err;
31 }
34 int xc_domain_pause(int xc_handle,
35 u32 domid)
36 {
37 dom0_op_t op;
38 op.cmd = DOM0_PAUSEDOMAIN;
39 op.u.pausedomain.domain = (domid_t)domid;
40 return do_dom0_op(xc_handle, &op);
41 }
44 int xc_domain_unpause(int xc_handle,
45 u32 domid)
46 {
47 dom0_op_t op;
48 op.cmd = DOM0_UNPAUSEDOMAIN;
49 op.u.unpausedomain.domain = (domid_t)domid;
50 return do_dom0_op(xc_handle, &op);
51 }
54 int xc_domain_destroy(int xc_handle,
55 u32 domid)
56 {
57 dom0_op_t op;
58 op.cmd = DOM0_DESTROYDOMAIN;
59 op.u.destroydomain.domain = (domid_t)domid;
60 return do_dom0_op(xc_handle, &op);
61 }
63 int xc_domain_pincpu(int xc_handle,
64 u32 domid,
65 int cpu)
66 {
67 dom0_op_t op;
68 op.cmd = DOM0_PINCPUDOMAIN;
69 op.u.pincpudomain.domain = (domid_t)domid;
70 op.u.pincpudomain.cpu = cpu;
71 return do_dom0_op(xc_handle, &op);
72 }
75 int xc_domain_getinfo(int xc_handle,
76 u32 first_domid,
77 unsigned int max_doms,
78 xc_dominfo_t *info)
79 {
80 unsigned int nr_doms;
81 u32 next_domid = first_domid;
82 dom0_op_t op;
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 op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
89 if ( do_dom0_op(xc_handle, &op) < 0 )
90 break;
91 info->domid = (u32)op.u.getdomaininfo.domain;
93 info->cpu =
94 (op.u.getdomaininfo.flags>>DOMFLAGS_CPUSHIFT) & DOMFLAGS_CPUMASK;
96 info->dying = !!(op.u.getdomaininfo.flags & DOMFLAGS_DYING);
97 info->crashed = !!(op.u.getdomaininfo.flags & DOMFLAGS_CRASHED);
98 info->shutdown = !!(op.u.getdomaininfo.flags & DOMFLAGS_SHUTDOWN);
99 info->paused = !!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED);
100 info->blocked = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
101 info->running = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
103 info->shutdown_reason =
104 (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
105 DOMFLAGS_SHUTDOWNMASK;
107 info->nr_pages = op.u.getdomaininfo.tot_pages;
108 info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT-10);
109 info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
110 info->cpu_time = op.u.getdomaininfo.cpu_time;
111 strncpy(info->name, op.u.getdomaininfo.name, XC_DOMINFO_MAXNAME);
112 info->name[XC_DOMINFO_MAXNAME-1] = '\0';
114 next_domid = (u32)op.u.getdomaininfo.domain + 1;
115 info++;
116 }
118 return nr_doms;
119 }
121 int xc_domain_getfullinfo(int xc_handle,
122 u32 domid,
123 dom0_op_t *op,
124 full_execution_context_t *ctxt )
125 {
126 int rc;
127 op->cmd = DOM0_GETDOMAININFO;
128 op->u.getdomaininfo.domain = (domid_t)domid;
129 op->u.getdomaininfo.ctxt = ctxt;
131 rc = do_dom0_op(xc_handle, op);
132 if ( ((u32)op->u.getdomaininfo.domain != domid) && rc > 0 )
133 return -ESRCH;
134 else
135 return rc;
136 }
139 int xc_shadow_control(int xc_handle,
140 u32 domid,
141 unsigned int sop,
142 unsigned long *dirty_bitmap,
143 unsigned long pages,
144 xc_shadow_control_stats_t *stats )
145 {
146 int rc;
147 dom0_op_t op;
148 op.cmd = DOM0_SHADOW_CONTROL;
149 op.u.shadow_control.domain = (domid_t)domid;
150 op.u.shadow_control.op = sop;
151 op.u.shadow_control.dirty_bitmap = dirty_bitmap;
152 op.u.shadow_control.pages = pages;
154 rc = do_dom0_op(xc_handle, &op);
156 if ( stats )
157 memcpy(stats, &op.u.shadow_control.stats,
158 sizeof(xc_shadow_control_stats_t));
160 return (rc == 0) ? op.u.shadow_control.pages : rc;
161 }
163 int xc_domain_setname(int xc_handle,
164 u32 domid,
165 char *name)
166 {
167 dom0_op_t op;
168 op.cmd = DOM0_SETDOMAINNAME;
169 op.u.setdomainname.domain = (domid_t)domid;
170 strncpy(op.u.setdomainname.name, name, MAX_DOMAIN_NAME);
171 return do_dom0_op(xc_handle, &op);
172 }
174 int xc_domain_setinitialmem(int xc_handle,
175 u32 domid,
176 unsigned int initial_memkb)
177 {
178 dom0_op_t op;
179 op.cmd = DOM0_SETDOMAININITIALMEM;
180 op.u.setdomaininitialmem.domain = (domid_t)domid;
181 op.u.setdomaininitialmem.initial_memkb = initial_memkb;
182 return do_dom0_op(xc_handle, &op);
183 }
185 int xc_domain_setmaxmem(int xc_handle,
186 u32 domid,
187 unsigned int max_memkb)
188 {
189 dom0_op_t op;
190 op.cmd = DOM0_SETDOMAINMAXMEM;
191 op.u.setdomainmaxmem.domain = (domid_t)domid;
192 op.u.setdomainmaxmem.max_memkb = max_memkb;
193 return do_dom0_op(xc_handle, &op);
194 }