ia64/linux-2.6.18-xen.hg

view drivers/xen/core/xen_sysfs.c @ 876:bd7e30b58d12

xenbus: Allow lazy init in case xenstored runs in a separate minios domain.

Here's an explanation of the states:

It starts out in XENBUS_XSD_UNCOMMITTED.

As the master xenbus (the one local to xenstored), it will receive an
mmap from xenstore, putting it in XENBUS_XSD_LOCAL_INIT. This enables
the wake_waiting IRQ, which will put it in XENBUS_XSD_LOCAL_READY.

Alternatively, as a slave xenbus, it will receive an ioctl from the
xenstore domain builder, putting it in XENBUS_XSD_FOREIGN_INIT. This
enables the wake_waiting IRQ, which will put it in
XENBUS_XSD_FOREIGN_READY.

DomU's are immediately initialized to XENBUS_XSD_FOREIGN_READY.

Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 19 14:45:50 2009 +0100 (2009-05-19)
parents f40f4f86d5a2
children
line source
1 /*
2 * copyright (c) 2006 IBM Corporation
3 * Authored by: Mike D. Day <ncmike@us.ibm.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
10 #include <linux/err.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <asm/hypervisor.h>
15 #include <xen/features.h>
16 #include <xen/hypervisor_sysfs.h>
17 #include <xen/xenbus.h>
18 #include <xen/interface/kexec.h>
19 #include "../xenbus/xenbus_comms.h"
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Mike D. Day <ncmike@us.ibm.com>");
24 static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer)
25 {
26 return sprintf(buffer, "xen\n");
27 }
29 HYPERVISOR_ATTR_RO(type);
31 static int __init xen_sysfs_type_init(void)
32 {
33 return sysfs_create_file(&hypervisor_subsys.kset.kobj, &type_attr.attr);
34 }
36 static void xen_sysfs_type_destroy(void)
37 {
38 sysfs_remove_file(&hypervisor_subsys.kset.kobj, &type_attr.attr);
39 }
41 /* xen version attributes */
42 static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer)
43 {
44 int version = HYPERVISOR_xen_version(XENVER_version, NULL);
45 if (version)
46 return sprintf(buffer, "%d\n", version >> 16);
47 return -ENODEV;
48 }
50 HYPERVISOR_ATTR_RO(major);
52 static ssize_t minor_show(struct hyp_sysfs_attr *attr, char *buffer)
53 {
54 int version = HYPERVISOR_xen_version(XENVER_version, NULL);
55 if (version)
56 return sprintf(buffer, "%d\n", version & 0xff);
57 return -ENODEV;
58 }
60 HYPERVISOR_ATTR_RO(minor);
62 static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer)
63 {
64 int ret = -ENOMEM;
65 char *extra;
67 extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL);
68 if (extra) {
69 ret = HYPERVISOR_xen_version(XENVER_extraversion, extra);
70 if (!ret)
71 ret = sprintf(buffer, "%s\n", extra);
72 kfree(extra);
73 }
75 return ret;
76 }
78 HYPERVISOR_ATTR_RO(extra);
80 static struct attribute *version_attrs[] = {
81 &major_attr.attr,
82 &minor_attr.attr,
83 &extra_attr.attr,
84 NULL
85 };
87 static struct attribute_group version_group = {
88 .name = "version",
89 .attrs = version_attrs,
90 };
92 static int __init xen_sysfs_version_init(void)
93 {
94 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
95 &version_group);
96 }
98 static void xen_sysfs_version_destroy(void)
99 {
100 sysfs_remove_group(&hypervisor_subsys.kset.kobj, &version_group);
101 }
103 /* UUID */
105 static ssize_t uuid_show(struct hyp_sysfs_attr *attr, char *buffer)
106 {
107 char *vm, *val;
108 int ret;
110 if (!is_xenstored_ready())
111 return -EBUSY;
113 vm = xenbus_read(XBT_NIL, "vm", "", NULL);
114 if (IS_ERR(vm))
115 return PTR_ERR(vm);
116 val = xenbus_read(XBT_NIL, vm, "uuid", NULL);
117 kfree(vm);
118 if (IS_ERR(val))
119 return PTR_ERR(val);
120 ret = sprintf(buffer, "%s\n", val);
121 kfree(val);
122 return ret;
123 }
125 HYPERVISOR_ATTR_RO(uuid);
127 static int __init xen_sysfs_uuid_init(void)
128 {
129 return sysfs_create_file(&hypervisor_subsys.kset.kobj, &uuid_attr.attr);
130 }
132 static void xen_sysfs_uuid_destroy(void)
133 {
134 sysfs_remove_file(&hypervisor_subsys.kset.kobj, &uuid_attr.attr);
135 }
137 /* xen compilation attributes */
139 static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer)
140 {
141 int ret = -ENOMEM;
142 struct xen_compile_info *info;
144 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
145 if (info) {
146 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
147 if (!ret)
148 ret = sprintf(buffer, "%s\n", info->compiler);
149 kfree(info);
150 }
152 return ret;
153 }
155 HYPERVISOR_ATTR_RO(compiler);
157 static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer)
158 {
159 int ret = -ENOMEM;
160 struct xen_compile_info *info;
162 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
163 if (info) {
164 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
165 if (!ret)
166 ret = sprintf(buffer, "%s\n", info->compile_by);
167 kfree(info);
168 }
170 return ret;
171 }
173 HYPERVISOR_ATTR_RO(compiled_by);
175 static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer)
176 {
177 int ret = -ENOMEM;
178 struct xen_compile_info *info;
180 info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
181 if (info) {
182 ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
183 if (!ret)
184 ret = sprintf(buffer, "%s\n", info->compile_date);
185 kfree(info);
186 }
188 return ret;
189 }
191 HYPERVISOR_ATTR_RO(compile_date);
193 static struct attribute *xen_compile_attrs[] = {
194 &compiler_attr.attr,
195 &compiled_by_attr.attr,
196 &compile_date_attr.attr,
197 NULL
198 };
200 static struct attribute_group xen_compilation_group = {
201 .name = "compilation",
202 .attrs = xen_compile_attrs,
203 };
205 int __init static xen_compilation_init(void)
206 {
207 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
208 &xen_compilation_group);
209 }
211 static void xen_compilation_destroy(void)
212 {
213 sysfs_remove_group(&hypervisor_subsys.kset.kobj,
214 &xen_compilation_group);
215 }
217 /* xen properties info */
219 static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer)
220 {
221 int ret = -ENOMEM;
222 char *caps;
224 caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL);
225 if (caps) {
226 ret = HYPERVISOR_xen_version(XENVER_capabilities, caps);
227 if (!ret)
228 ret = sprintf(buffer, "%s\n", caps);
229 kfree(caps);
230 }
232 return ret;
233 }
235 HYPERVISOR_ATTR_RO(capabilities);
237 static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer)
238 {
239 int ret = -ENOMEM;
240 char *cset;
242 cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL);
243 if (cset) {
244 ret = HYPERVISOR_xen_version(XENVER_changeset, cset);
245 if (!ret)
246 ret = sprintf(buffer, "%s\n", cset);
247 kfree(cset);
248 }
250 return ret;
251 }
253 HYPERVISOR_ATTR_RO(changeset);
255 static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer)
256 {
257 int ret = -ENOMEM;
258 struct xen_platform_parameters *parms;
260 parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL);
261 if (parms) {
262 ret = HYPERVISOR_xen_version(XENVER_platform_parameters,
263 parms);
264 if (!ret)
265 ret = sprintf(buffer, "%lx\n", parms->virt_start);
266 kfree(parms);
267 }
269 return ret;
270 }
272 HYPERVISOR_ATTR_RO(virtual_start);
274 static ssize_t pagesize_show(struct hyp_sysfs_attr *attr, char *buffer)
275 {
276 int ret;
278 ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL);
279 if (ret > 0)
280 ret = sprintf(buffer, "%x\n", ret);
282 return ret;
283 }
285 HYPERVISOR_ATTR_RO(pagesize);
287 /* eventually there will be several more features to export */
288 static ssize_t xen_feature_show(int index, char *buffer)
289 {
290 int ret = -ENOMEM;
291 struct xen_feature_info *info;
293 info = kmalloc(sizeof(struct xen_feature_info), GFP_KERNEL);
294 if (info) {
295 info->submap_idx = index;
296 ret = HYPERVISOR_xen_version(XENVER_get_features, info);
297 if (!ret)
298 ret = sprintf(buffer, "%d\n", info->submap);
299 kfree(info);
300 }
302 return ret;
303 }
305 static ssize_t writable_pt_show(struct hyp_sysfs_attr *attr, char *buffer)
306 {
307 return xen_feature_show(XENFEAT_writable_page_tables, buffer);
308 }
310 HYPERVISOR_ATTR_RO(writable_pt);
312 static struct attribute *xen_properties_attrs[] = {
313 &capabilities_attr.attr,
314 &changeset_attr.attr,
315 &virtual_start_attr.attr,
316 &pagesize_attr.attr,
317 &writable_pt_attr.attr,
318 NULL
319 };
321 static struct attribute_group xen_properties_group = {
322 .name = "properties",
323 .attrs = xen_properties_attrs,
324 };
326 static int __init xen_properties_init(void)
327 {
328 return sysfs_create_group(&hypervisor_subsys.kset.kobj,
329 &xen_properties_group);
330 }
332 static void xen_properties_destroy(void)
333 {
334 sysfs_remove_group(&hypervisor_subsys.kset.kobj,
335 &xen_properties_group);
336 }
338 #ifdef CONFIG_KEXEC
340 extern size_t vmcoreinfo_size_xen;
341 extern unsigned long paddr_vmcoreinfo_xen;
343 static ssize_t vmcoreinfo_show(struct hyp_sysfs_attr *attr, char *page)
344 {
345 return sprintf(page, "%lx %zx\n",
346 paddr_vmcoreinfo_xen, vmcoreinfo_size_xen);
347 }
349 HYPERVISOR_ATTR_RO(vmcoreinfo);
351 static int __init xen_sysfs_vmcoreinfo_init(void)
352 {
353 return sysfs_create_file(&hypervisor_subsys.kset.kobj,
354 &vmcoreinfo_attr.attr);
355 }
357 static void xen_sysfs_vmcoreinfo_destroy(void)
358 {
359 sysfs_remove_file(&hypervisor_subsys.kset.kobj, &vmcoreinfo_attr.attr);
360 }
362 #endif
364 static int __init hyper_sysfs_init(void)
365 {
366 int ret;
368 if (!is_running_on_xen())
369 return -ENODEV;
371 ret = xen_sysfs_type_init();
372 if (ret)
373 goto out;
374 ret = xen_sysfs_version_init();
375 if (ret)
376 goto version_out;
377 ret = xen_compilation_init();
378 if (ret)
379 goto comp_out;
380 ret = xen_sysfs_uuid_init();
381 if (ret)
382 goto uuid_out;
383 ret = xen_properties_init();
384 if (ret)
385 goto prop_out;
386 #ifdef CONFIG_KEXEC
387 if (vmcoreinfo_size_xen != 0) {
388 ret = xen_sysfs_vmcoreinfo_init();
389 if (ret)
390 goto vmcoreinfo_out;
391 }
392 #endif
394 goto out;
396 #ifdef CONFIG_KEXEC
397 vmcoreinfo_out:
398 #endif
399 xen_properties_destroy();
400 prop_out:
401 xen_sysfs_uuid_destroy();
402 uuid_out:
403 xen_compilation_destroy();
404 comp_out:
405 xen_sysfs_version_destroy();
406 version_out:
407 xen_sysfs_type_destroy();
408 out:
409 return ret;
410 }
412 static void __exit hyper_sysfs_exit(void)
413 {
414 #ifdef CONFIG_KEXEC
415 if (vmcoreinfo_size_xen != 0)
416 xen_sysfs_vmcoreinfo_destroy();
417 #endif
418 xen_properties_destroy();
419 xen_compilation_destroy();
420 xen_sysfs_uuid_destroy();
421 xen_sysfs_version_destroy();
422 xen_sysfs_type_destroy();
424 }
426 module_init(hyper_sysfs_init);
427 module_exit(hyper_sysfs_exit);