Magellan Linux

Annotation of /trunk/kernel26-xen/patches-2.6.25-r1/1015-2.6.25-xen-Add-Xen-s-sys-hypervisor-interface.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 606 - (hide annotations) (download)
Thu May 22 23:13:13 2008 UTC (16 years ago) by niro
File size: 11534 byte(s)
-ver bump to 2.6.25-magellan-r1:
- linux-2.6.25.4
- fbcondecor-0.9.4
- squashfs-3.3
- unionfs-2.3.3
- tuxonice-3.0-rc7
- linux-phc-0.3.0
- acpi-dstd-0.9a
- reiser4
- xen-3.2.0
. ipw3945-1.2.2

1 niro 606 From a3bd6211ccaf28b2325c6034d3fe24859b184a1f Mon Sep 17 00:00:00 2001
2     From: Mark McLoughlin <markmc@redhat.com>
3     Date: Thu, 7 Feb 2008 15:32:28 +0000
4     Subject: [PATCH] xen: Add Xen's /sys/hypervisor interface
5    
6     Hook up Xen's /sys/hypervisor interface:
7    
8     /sys/hypervisor/
9     -> type
10     -> uuid
11     -> compilation
12     -> compile_date
13     -> compiled_by
14     -> compiler
15     -> properties
16     -> capabilities
17     -> changeset
18     -> pagesize
19     -> virtual_start
20     -> writable_pt
21     -> version
22     -> extra
23     -> major
24     -> minor
25    
26     Note: the hypervisor subsys hook requires that
27     SYS_HYPERVISOR is selected to enabled it, which in
28     turns means that the subsys will be registered by
29     a pv-ops kernel with Xen support, even on bare
30     metal. This hook needs to be changed to be runtime
31     enabled.
32    
33     Signed-off-by: Mark McLoughlin <markmc@redhat.com>
34     ---
35     arch/x86/xen/Kconfig | 3 +-
36     drivers/xen/xenctrl/Makefile | 1 +
37     drivers/xen/xenctrl/main.c | 6 +
38     drivers/xen/xenctrl/sysfs.c | 349 +++++++++++++++++++++++++++++++++++++++
39     drivers/xen/xenctrl/xenctrl.h | 6 +
40     include/xen/interface/version.h | 6 +
41     6 files changed, 370 insertions(+), 1 deletions(-)
42     create mode 100644 drivers/xen/xenctrl/sysfs.c
43    
44     diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
45     index 4723bc1..ff6a56a 100644
46     --- a/arch/x86/xen/Kconfig
47     +++ b/arch/x86/xen/Kconfig
48     @@ -14,7 +14,8 @@ config XEN
49    
50     config XENCTRL
51     tristate "Xen's user space control interfaces"
52     - depends on XEN && PROC_FS
53     + depends on XEN && PROC_FS && SYSFS
54     default y if XEN
55     + select SYS_HYPERVISOR
56     help
57     This is the /proc/xen interface used by Xen's libxc.
58     diff --git a/drivers/xen/xenctrl/Makefile b/drivers/xen/xenctrl/Makefile
59     index 23dafa3..e126e76 100644
60     --- a/drivers/xen/xenctrl/Makefile
61     +++ b/drivers/xen/xenctrl/Makefile
62     @@ -5,3 +5,4 @@ xenctrl-objs += main.o
63     xenctrl-objs += capabilities.o
64     xenctrl-objs += privcmd.o
65     xenctrl-objs += xenbus.o
66     +xenctrl-objs += sysfs.o
67     diff --git a/drivers/xen/xenctrl/main.c b/drivers/xen/xenctrl/main.c
68     index b0cf61b..87d0dba 100644
69     --- a/drivers/xen/xenctrl/main.c
70     +++ b/drivers/xen/xenctrl/main.c
71     @@ -63,8 +63,13 @@ static int __init xenctrl_init(void)
72     if (ret)
73     goto fail3;
74    
75     + ret = sys_hypervisor_init();
76     + if (ret)
77     + goto fail4;
78     +
79     return 0;
80    
81     + fail4: xenbus_remove_proc_entry();
82     fail3: privcmd_remove_proc_entry();
83     fail2: capabilities_remove_proc_entry();
84     fail1: remove_proc_entry("xen", NULL);
85     @@ -73,6 +78,7 @@ static int __init xenctrl_init(void)
86    
87     static void __exit xenctrl_exit(void)
88     {
89     + sys_hypervisor_exit();
90     xenbus_remove_proc_entry();
91     privcmd_remove_proc_entry();
92     capabilities_remove_proc_entry();
93     diff --git a/drivers/xen/xenctrl/sysfs.c b/drivers/xen/xenctrl/sysfs.c
94     new file mode 100644
95     index 0000000..8cbf4d6
96     --- /dev/null
97     +++ b/drivers/xen/xenctrl/sysfs.c
98     @@ -0,0 +1,349 @@
99     +/*
100     + * copyright (c) 2006 IBM Corporation
101     + * Authored by: Mike D. Day <ncmike@us.ibm.com>
102     + *
103     + * This program is free software; you can redistribute it and/or modify
104     + * it under the terms of the GNU General Public License version 2 as
105     + * published by the Free Software Foundation.
106     + */
107     +
108     +#include <linux/kobject.h>
109     +#include <linux/sysfs.h>
110     +#include <linux/err.h>
111     +#include <asm/xen/hypervisor.h>
112     +#include <xen/xenbus.h>
113     +#include "xenctrl.h"
114     +
115     +#define HYPERVISOR_ATTR_RO(_name) \
116     +static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
117     +
118     +#define HYPERVISOR_ATTR_RW(_name) \
119     +static struct kobj_attribute _name##_attr = \
120     + __ATTR(_name, 0644, _name##_show, _name##_store)
121     +
122     +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
123     +{
124     + return sprintf(buffer, "xen\n");
125     +}
126     +
127     +HYPERVISOR_ATTR_RO(type);
128     +
129     +static int __init xen_sysfs_type_init(void)
130     +{
131     + return sysfs_create_file(hypervisor_kobj, &type_attr.attr);
132     +}
133     +
134     +static void xen_sysfs_type_destroy(void)
135     +{
136     + sysfs_remove_file(hypervisor_kobj, &type_attr.attr);
137     +}
138     +
139     +static ssize_t major_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
140     +{
141     + int version;
142     +
143     + version = HYPERVISOR_xen_version(XENVER_version, NULL);
144     + if (!version)
145     + return -ENODEV;
146     +
147     + return sprintf(buffer, "%d\n", version >> 16);
148     +}
149     +
150     +HYPERVISOR_ATTR_RO(major);
151     +
152     +static ssize_t minor_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
153     +{
154     + int version;
155     +
156     + version = HYPERVISOR_xen_version(XENVER_version, NULL);
157     + if (!version)
158     + return -ENODEV;
159     +
160     + return sprintf(buffer, "%d\n", version & 0xff);
161     +}
162     +
163     +HYPERVISOR_ATTR_RO(minor);
164     +
165     +static ssize_t extra_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
166     +{
167     + int ret;
168     + struct xen_extraversion extra;
169     +
170     + ret = HYPERVISOR_xen_version(XENVER_extraversion, &extra);
171     + if (ret)
172     + return ret;
173     +
174     + return sprintf(buffer, "%s\n", extra.extraversion);
175     +}
176     +
177     +HYPERVISOR_ATTR_RO(extra);
178     +
179     +static struct attribute *version_attrs[] = {
180     + &major_attr.attr,
181     + &minor_attr.attr,
182     + &extra_attr.attr,
183     + NULL
184     +};
185     +
186     +static struct attribute_group version_group = {
187     + .name = "version",
188     + .attrs = version_attrs,
189     +};
190     +
191     +static int __init xen_sysfs_version_init(void)
192     +{
193     + return sysfs_create_group(hypervisor_kobj, &version_group);
194     +}
195     +
196     +static void xen_sysfs_version_destroy(void)
197     +{
198     + sysfs_remove_group(hypervisor_kobj, &version_group);
199     +}
200     +
201     +static ssize_t uuid_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
202     +{
203     + char *vm, *val;
204     + int ret;
205     +
206     + vm = xenbus_read(XBT_NIL, "vm", "", NULL);
207     + if (IS_ERR(vm))
208     + return PTR_ERR(vm);
209     +
210     + val = xenbus_read(XBT_NIL, vm, "uuid", NULL);
211     + if (IS_ERR(val)) {
212     + ret = PTR_ERR(val);
213     + goto out;
214     + }
215     +
216     + ret = sprintf(buffer, "%s\n", val);
217     +
218     + kfree(val);
219     +out: kfree(vm);
220     +
221     + return ret;
222     +}
223     +
224     +HYPERVISOR_ATTR_RO(uuid);
225     +
226     +static int __init xen_sysfs_uuid_init(void)
227     +{
228     + return sysfs_create_file(hypervisor_kobj, &uuid_attr.attr);
229     +}
230     +
231     +static void xen_sysfs_uuid_destroy(void)
232     +{
233     + sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr);
234     +}
235     +
236     +static ssize_t compiler_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
237     +{
238     + struct xen_compile_info info;
239     + int ret;
240     +
241     + ret = HYPERVISOR_xen_version(XENVER_compile_info, &info);
242     + if (ret)
243     + return ret;
244     +
245     + return sprintf(buffer, "%s\n", info.compiler);
246     +}
247     +
248     +HYPERVISOR_ATTR_RO(compiler);
249     +
250     +static ssize_t compiled_by_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
251     +{
252     + struct xen_compile_info info;
253     + int ret;
254     +
255     + ret = HYPERVISOR_xen_version(XENVER_compile_info, &info);
256     + if (ret)
257     + return ret;
258     +
259     + return sprintf(buffer, "%s\n", info.compile_by);
260     +}
261     +
262     +HYPERVISOR_ATTR_RO(compiled_by);
263     +
264     +static ssize_t compile_date_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
265     +{
266     + struct xen_compile_info info;
267     + int ret;
268     +
269     + ret = HYPERVISOR_xen_version(XENVER_compile_info, &info);
270     + if (ret)
271     + return ret;
272     +
273     + return sprintf(buffer, "%s\n", info.compile_date);
274     +}
275     +
276     +HYPERVISOR_ATTR_RO(compile_date);
277     +
278     +static struct attribute *xen_compile_attrs[] = {
279     + &compiler_attr.attr,
280     + &compiled_by_attr.attr,
281     + &compile_date_attr.attr,
282     + NULL
283     +};
284     +
285     +static struct attribute_group xen_compilation_group = {
286     + .name = "compilation",
287     + .attrs = xen_compile_attrs,
288     +};
289     +
290     +static int __init xen_compilation_init(void)
291     +{
292     + return sysfs_create_group(hypervisor_kobj,
293     + &xen_compilation_group);
294     +}
295     +
296     +static void xen_compilation_destroy(void)
297     +{
298     + sysfs_remove_group(hypervisor_kobj,
299     + &xen_compilation_group);
300     +}
301     +
302     +static ssize_t capabilities_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
303     +{
304     + struct xen_capabilities_info *caps;
305     + int ret;
306     +
307     + caps = kmalloc(sizeof(struct xen_capabilities_info), GFP_KERNEL);
308     + if (!caps)
309     + return -ENOMEM;
310     +
311     + ret = HYPERVISOR_xen_version(XENVER_capabilities, caps);
312     + if (ret)
313     + goto out;
314     +
315     + ret = sprintf(buffer, "%s\n", caps->info);
316     +
317     +out: kfree(caps);
318     +
319     + return ret;
320     +}
321     +
322     +HYPERVISOR_ATTR_RO(capabilities);
323     +
324     +static ssize_t changeset_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
325     +{
326     + struct xen_changeset_info cset;
327     + int ret;
328     +
329     + ret = HYPERVISOR_xen_version(XENVER_changeset, &cset);
330     + if (ret)
331     + return ret;
332     +
333     + return sprintf(buffer, "%s\n", cset.info);
334     +}
335     +
336     +HYPERVISOR_ATTR_RO(changeset);
337     +
338     +static ssize_t virtual_start_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
339     +{
340     + struct xen_platform_parameters parms;
341     + int ret;
342     +
343     + ret = HYPERVISOR_xen_version(XENVER_platform_parameters, &parms);
344     + if (ret)
345     + return ret;
346     +
347     + return sprintf(buffer, "%lx\n", parms.virt_start);
348     +}
349     +
350     +HYPERVISOR_ATTR_RO(virtual_start);
351     +
352     +static ssize_t pagesize_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
353     +{
354     + int ret;
355     +
356     + ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL);
357     + if (ret < 0)
358     + return ret;
359     +
360     + return sprintf(buffer, "%x\n", ret);
361     +}
362     +
363     +HYPERVISOR_ATTR_RO(pagesize);
364     +
365     +static ssize_t writable_pt_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
366     +{
367     + struct xen_feature_info info;
368     + int ret;
369     +
370     + info.submap_idx = XENFEAT_writable_page_tables;
371     +
372     + ret = HYPERVISOR_xen_version(XENVER_get_features, &info);
373     + if (ret)
374     + return ret;
375     +
376     + return sprintf(buffer, "%d\n", info.submap);
377     +}
378     +
379     +HYPERVISOR_ATTR_RO(writable_pt);
380     +
381     +static struct attribute *xen_properties_attrs[] = {
382     + &capabilities_attr.attr,
383     + &changeset_attr.attr,
384     + &virtual_start_attr.attr,
385     + &pagesize_attr.attr,
386     + &writable_pt_attr.attr,
387     + NULL
388     +};
389     +
390     +static struct attribute_group xen_properties_group = {
391     + .name = "properties",
392     + .attrs = xen_properties_attrs,
393     +};
394     +
395     +static int __init xen_properties_init(void)
396     +{
397     + return sysfs_create_group(hypervisor_kobj,
398     + &xen_properties_group);
399     +}
400     +
401     +static void xen_properties_destroy(void)
402     +{
403     + sysfs_remove_group(hypervisor_kobj, &xen_properties_group);
404     +}
405     +
406     +int __init sys_hypervisor_init(void)
407     +{
408     + int ret;
409     +
410     + if (!is_running_on_xen())
411     + return -ENODEV;
412     +
413     + ret = xen_sysfs_type_init();
414     + if (ret)
415     + goto out;
416     + ret = xen_sysfs_version_init();
417     + if (ret)
418     + goto version_out;
419     + ret = xen_compilation_init();
420     + if (ret)
421     + goto comp_out;
422     + ret = xen_sysfs_uuid_init();
423     + if (ret)
424     + goto uuid_out;
425     + ret = xen_properties_init();
426     + if (!ret)
427     + goto out;
428     +
429     + xen_sysfs_uuid_destroy();
430     +uuid_out:
431     + xen_compilation_destroy();
432     +comp_out:
433     + xen_sysfs_version_destroy();
434     +version_out:
435     + xen_sysfs_type_destroy();
436     +out:
437     + return ret;
438     +}
439     +
440     +void __exit sys_hypervisor_exit(void)
441     +{
442     + xen_properties_destroy();
443     + xen_compilation_destroy();
444     + xen_sysfs_uuid_destroy();
445     + xen_sysfs_version_destroy();
446     + xen_sysfs_type_destroy();
447     +}
448     diff --git a/drivers/xen/xenctrl/xenctrl.h b/drivers/xen/xenctrl/xenctrl.h
449     index e585c4b..1afbdfb 100644
450     --- a/drivers/xen/xenctrl/xenctrl.h
451     +++ b/drivers/xen/xenctrl/xenctrl.h
452     @@ -49,3 +49,9 @@ void privcmd_remove_proc_entry(void) __exit;
453     */
454     int xenbus_create_proc_entry(void) __init;
455     void xenbus_remove_proc_entry(void) __exit;
456     +
457     +/*
458     + * sysfs.c
459     + */
460     +int sys_hypervisor_init(void) __init;
461     +void sys_hypervisor_exit(void) __exit;
462     diff --git a/include/xen/interface/version.h b/include/xen/interface/version.h
463     index 453235e..dd58cf5 100644
464     --- a/include/xen/interface/version.h
465     +++ b/include/xen/interface/version.h
466     @@ -57,4 +57,10 @@ struct xen_feature_info {
467     /* Declares the features reported by XENVER_get_features. */
468     #include "features.h"
469    
470     +/* arg == NULL; returns host memory page size. */
471     +#define XENVER_pagesize 7
472     +
473     +/* arg == xen_domain_handle_t. */
474     +#define XENVER_guest_handle 8
475     +
476     #endif /* __XEN_PUBLIC_VERSION_H__ */
477     --
478     1.5.4.1
479