2009-03-11 05:39:59 +08:00
|
|
|
/*
|
|
|
|
* copyright (c) 2006 IBM Corporation
|
|
|
|
* Authored by: Mike D. Day <ncmike@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-03-11 05:39:59 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kobject.h>
|
|
|
|
|
|
|
|
#include <asm/xen/hypervisor.h>
|
|
|
|
#include <asm/xen/hypercall.h>
|
|
|
|
|
2009-10-07 06:11:14 +08:00
|
|
|
#include <xen/xen.h>
|
2009-03-11 05:39:59 +08:00
|
|
|
#include <xen/xenbus.h>
|
|
|
|
#include <xen/interface/xen.h>
|
|
|
|
#include <xen/interface/version.h>
|
|
|
|
|
|
|
|
#define HYPERVISOR_ATTR_RO(_name) \
|
|
|
|
static struct hyp_sysfs_attr _name##_attr = __ATTR_RO(_name)
|
|
|
|
|
|
|
|
#define HYPERVISOR_ATTR_RW(_name) \
|
|
|
|
static struct hyp_sysfs_attr _name##_attr = \
|
|
|
|
__ATTR(_name, 0644, _name##_show, _name##_store)
|
|
|
|
|
|
|
|
struct hyp_sysfs_attr {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct hyp_sysfs_attr *, char *);
|
|
|
|
ssize_t (*store)(struct hyp_sysfs_attr *, const char *, size_t);
|
|
|
|
void *hyp_attr_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t type_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
return sprintf(buffer, "xen\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(type);
|
|
|
|
|
|
|
|
static int __init xen_sysfs_type_init(void)
|
|
|
|
{
|
|
|
|
return sysfs_create_file(hypervisor_kobj, &type_attr.attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_sysfs_type_destroy(void)
|
|
|
|
{
|
|
|
|
sysfs_remove_file(hypervisor_kobj, &type_attr.attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* xen version attributes */
|
|
|
|
static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int version = HYPERVISOR_xen_version(XENVER_version, NULL);
|
|
|
|
if (version)
|
|
|
|
return sprintf(buffer, "%d\n", version >> 16);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(major);
|
|
|
|
|
|
|
|
static ssize_t minor_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int version = HYPERVISOR_xen_version(XENVER_version, NULL);
|
|
|
|
if (version)
|
|
|
|
return sprintf(buffer, "%d\n", version & 0xff);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(minor);
|
|
|
|
|
|
|
|
static ssize_t extra_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
char *extra;
|
|
|
|
|
|
|
|
extra = kmalloc(XEN_EXTRAVERSION_LEN, GFP_KERNEL);
|
|
|
|
if (extra) {
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_extraversion, extra);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%s\n", extra);
|
|
|
|
kfree(extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(extra);
|
|
|
|
|
|
|
|
static struct attribute *version_attrs[] = {
|
|
|
|
&major_attr.attr,
|
|
|
|
&minor_attr.attr,
|
|
|
|
&extra_attr.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group version_group = {
|
|
|
|
.name = "version",
|
|
|
|
.attrs = version_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init xen_sysfs_version_init(void)
|
|
|
|
{
|
|
|
|
return sysfs_create_group(hypervisor_kobj, &version_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_sysfs_version_destroy(void)
|
|
|
|
{
|
|
|
|
sysfs_remove_group(hypervisor_kobj, &version_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UUID */
|
|
|
|
|
|
|
|
static ssize_t uuid_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
char *vm, *val;
|
|
|
|
int ret;
|
|
|
|
extern int xenstored_ready;
|
|
|
|
|
|
|
|
if (!xenstored_ready)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
vm = xenbus_read(XBT_NIL, "vm", "", NULL);
|
|
|
|
if (IS_ERR(vm))
|
|
|
|
return PTR_ERR(vm);
|
|
|
|
val = xenbus_read(XBT_NIL, vm, "uuid", NULL);
|
|
|
|
kfree(vm);
|
|
|
|
if (IS_ERR(val))
|
|
|
|
return PTR_ERR(val);
|
|
|
|
ret = sprintf(buffer, "%s\n", val);
|
|
|
|
kfree(val);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(uuid);
|
|
|
|
|
|
|
|
static int __init xen_sysfs_uuid_init(void)
|
|
|
|
{
|
|
|
|
return sysfs_create_file(hypervisor_kobj, &uuid_attr.attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_sysfs_uuid_destroy(void)
|
|
|
|
{
|
|
|
|
sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* xen compilation attributes */
|
|
|
|
|
|
|
|
static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct xen_compile_info *info;
|
|
|
|
|
|
|
|
info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
|
|
|
|
if (info) {
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%s\n", info->compiler);
|
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(compiler);
|
|
|
|
|
|
|
|
static ssize_t compiled_by_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct xen_compile_info *info;
|
|
|
|
|
|
|
|
info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
|
|
|
|
if (info) {
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%s\n", info->compile_by);
|
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(compiled_by);
|
|
|
|
|
|
|
|
static ssize_t compile_date_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct xen_compile_info *info;
|
|
|
|
|
|
|
|
info = kmalloc(sizeof(struct xen_compile_info), GFP_KERNEL);
|
|
|
|
if (info) {
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_compile_info, info);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%s\n", info->compile_date);
|
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(compile_date);
|
|
|
|
|
|
|
|
static struct attribute *xen_compile_attrs[] = {
|
|
|
|
&compiler_attr.attr,
|
|
|
|
&compiled_by_attr.attr,
|
|
|
|
&compile_date_attr.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group xen_compilation_group = {
|
|
|
|
.name = "compilation",
|
|
|
|
.attrs = xen_compile_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
int __init static xen_compilation_init(void)
|
|
|
|
{
|
|
|
|
return sysfs_create_group(hypervisor_kobj, &xen_compilation_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_compilation_destroy(void)
|
|
|
|
{
|
|
|
|
sysfs_remove_group(hypervisor_kobj, &xen_compilation_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* xen properties info */
|
|
|
|
|
|
|
|
static ssize_t capabilities_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
char *caps;
|
|
|
|
|
|
|
|
caps = kmalloc(XEN_CAPABILITIES_INFO_LEN, GFP_KERNEL);
|
|
|
|
if (caps) {
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_capabilities, caps);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%s\n", caps);
|
|
|
|
kfree(caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(capabilities);
|
|
|
|
|
|
|
|
static ssize_t changeset_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
char *cset;
|
|
|
|
|
|
|
|
cset = kmalloc(XEN_CHANGESET_INFO_LEN, GFP_KERNEL);
|
|
|
|
if (cset) {
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_changeset, cset);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%s\n", cset);
|
|
|
|
kfree(cset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(changeset);
|
|
|
|
|
|
|
|
static ssize_t virtual_start_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
struct xen_platform_parameters *parms;
|
|
|
|
|
|
|
|
parms = kmalloc(sizeof(struct xen_platform_parameters), GFP_KERNEL);
|
|
|
|
if (parms) {
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_platform_parameters,
|
|
|
|
parms);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%lx\n", parms->virt_start);
|
|
|
|
kfree(parms);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(virtual_start);
|
|
|
|
|
|
|
|
static ssize_t pagesize_show(struct hyp_sysfs_attr *attr, char *buffer)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_pagesize, NULL);
|
|
|
|
if (ret > 0)
|
|
|
|
ret = sprintf(buffer, "%x\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HYPERVISOR_ATTR_RO(pagesize);
|
|
|
|
|
|
|
|
static ssize_t xen_feature_show(int index, char *buffer)
|
|
|
|
{
|
2009-03-11 08:17:41 +08:00
|
|
|
ssize_t ret;
|
|
|
|
struct xen_feature_info info;
|
2009-03-11 05:39:59 +08:00
|
|
|
|
2009-03-11 08:17:41 +08:00
|
|
|
info.submap_idx = index;
|
|
|
|
ret = HYPERVISOR_xen_version(XENVER_get_features, &info);
|
|
|
|
if (!ret)
|
|
|
|
ret = sprintf(buffer, "%08x", info.submap);
|
2009-03-11 05:39:59 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-11 08:17:41 +08:00
|
|
|
static ssize_t features_show(struct hyp_sysfs_attr *attr, char *buffer)
|
2009-03-11 05:39:59 +08:00
|
|
|
{
|
2009-03-11 08:17:41 +08:00
|
|
|
ssize_t len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
for (i = XENFEAT_NR_SUBMAPS-1; i >= 0; i--) {
|
|
|
|
int ret = xen_feature_show(i, buffer + len);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (len == 0)
|
|
|
|
len = ret;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
len += ret;
|
|
|
|
}
|
|
|
|
if (len > 0)
|
|
|
|
buffer[len++] = '\n';
|
|
|
|
|
|
|
|
return len;
|
2009-03-11 05:39:59 +08:00
|
|
|
}
|
|
|
|
|
2009-03-11 08:17:41 +08:00
|
|
|
HYPERVISOR_ATTR_RO(features);
|
2009-03-11 05:39:59 +08:00
|
|
|
|
|
|
|
static struct attribute *xen_properties_attrs[] = {
|
|
|
|
&capabilities_attr.attr,
|
|
|
|
&changeset_attr.attr,
|
|
|
|
&virtual_start_attr.attr,
|
|
|
|
&pagesize_attr.attr,
|
2009-03-11 08:17:41 +08:00
|
|
|
&features_attr.attr,
|
2009-03-11 05:39:59 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group xen_properties_group = {
|
|
|
|
.name = "properties",
|
|
|
|
.attrs = xen_properties_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init xen_properties_init(void)
|
|
|
|
{
|
|
|
|
return sysfs_create_group(hypervisor_kobj, &xen_properties_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_properties_destroy(void)
|
|
|
|
{
|
|
|
|
sysfs_remove_group(hypervisor_kobj, &xen_properties_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init hyper_sysfs_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!xen_domain())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = xen_sysfs_type_init();
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = xen_sysfs_version_init();
|
|
|
|
if (ret)
|
|
|
|
goto version_out;
|
|
|
|
ret = xen_compilation_init();
|
|
|
|
if (ret)
|
|
|
|
goto comp_out;
|
|
|
|
ret = xen_sysfs_uuid_init();
|
|
|
|
if (ret)
|
|
|
|
goto uuid_out;
|
|
|
|
ret = xen_properties_init();
|
|
|
|
if (ret)
|
|
|
|
goto prop_out;
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
prop_out:
|
|
|
|
xen_sysfs_uuid_destroy();
|
|
|
|
uuid_out:
|
|
|
|
xen_compilation_destroy();
|
|
|
|
comp_out:
|
|
|
|
xen_sysfs_version_destroy();
|
|
|
|
version_out:
|
|
|
|
xen_sysfs_type_destroy();
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit hyper_sysfs_exit(void)
|
|
|
|
{
|
|
|
|
xen_properties_destroy();
|
|
|
|
xen_compilation_destroy();
|
|
|
|
xen_sysfs_uuid_destroy();
|
|
|
|
xen_sysfs_version_destroy();
|
|
|
|
xen_sysfs_type_destroy();
|
|
|
|
|
|
|
|
}
|
|
|
|
module_init(hyper_sysfs_init);
|
|
|
|
module_exit(hyper_sysfs_exit);
|
|
|
|
|
|
|
|
static ssize_t hyp_sysfs_show(struct kobject *kobj,
|
|
|
|
struct attribute *attr,
|
|
|
|
char *buffer)
|
|
|
|
{
|
|
|
|
struct hyp_sysfs_attr *hyp_attr;
|
|
|
|
hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr);
|
|
|
|
if (hyp_attr->show)
|
|
|
|
return hyp_attr->show(hyp_attr, buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t hyp_sysfs_store(struct kobject *kobj,
|
|
|
|
struct attribute *attr,
|
|
|
|
const char *buffer,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
struct hyp_sysfs_attr *hyp_attr;
|
|
|
|
hyp_attr = container_of(attr, struct hyp_sysfs_attr, attr);
|
|
|
|
if (hyp_attr->store)
|
|
|
|
return hyp_attr->store(hyp_attr, buffer, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-19 09:58:23 +08:00
|
|
|
static const struct sysfs_ops hyp_sysfs_ops = {
|
2009-03-11 05:39:59 +08:00
|
|
|
.show = hyp_sysfs_show,
|
|
|
|
.store = hyp_sysfs_store,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kobj_type hyp_sysfs_kobj_type = {
|
|
|
|
.sysfs_ops = &hyp_sysfs_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init hypervisor_subsys_init(void)
|
|
|
|
{
|
|
|
|
if (!xen_domain())
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
hypervisor_kobj->ktype = &hyp_sysfs_kobj_type;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
device_initcall(hypervisor_subsys_init);
|