ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/balloon/sysfs.c @ 14100:e47738923a05

[LINUX] Purge include <linux/config.h>. It has been obsolete for some time now.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Fri Feb 23 16:56:45 2007 +0000 (2007-02-23)
parents 93f0957e02ce
children 2bbd28891160
line source
1 /******************************************************************************
2 * balloon/sysfs.c
3 *
4 * Xen balloon driver - sysfs interfaces.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation; or, when distributed
9 * separately from the Linux kernel or incorporated into other
10 * software packages, subject to the following license:
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this source file (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use, copy, modify,
15 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
16 * and to permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
31 #include <linux/capability.h>
32 #include <linux/stat.h>
33 #include <linux/sysdev.h>
34 #include "common.h"
36 #define BALLOON_CLASS_NAME "memory"
38 #define BALLOON_SHOW(name, format, args...) \
39 static ssize_t show_##name(struct sys_device *dev, \
40 char *buf) \
41 { \
42 return sprintf(buf, format, ##args); \
43 } \
44 static SYSDEV_ATTR(name, S_IRUGO, show_##name, NULL)
46 BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(bs.current_pages));
47 BALLOON_SHOW(low_kb, "%lu\n", PAGES2KB(bs.balloon_low));
48 BALLOON_SHOW(high_kb, "%lu\n", PAGES2KB(bs.balloon_high));
49 BALLOON_SHOW(hard_limit_kb,
50 (bs.hard_limit!=~0UL) ? "%lu\n" : "???\n",
51 (bs.hard_limit!=~0UL) ? PAGES2KB(bs.hard_limit) : 0);
52 BALLOON_SHOW(driver_kb, "%lu\n", PAGES2KB(bs.driver_pages));
54 static ssize_t show_target_kb(struct sys_device *dev, char *buf)
55 {
56 return sprintf(buf, "%lu\n", PAGES2KB(bs.target_pages));
57 }
59 static ssize_t store_target_kb(struct sys_device *dev,
60 const char *buf,
61 size_t count)
62 {
63 char memstring[64], *endchar;
64 unsigned long long target_bytes;
66 if (!capable(CAP_SYS_ADMIN))
67 return -EPERM;
69 if (count <= 1)
70 return -EBADMSG; /* runt */
71 if (count > sizeof(memstring))
72 return -EFBIG; /* too long */
73 strcpy(memstring, buf);
75 target_bytes = memparse(memstring, &endchar);
76 balloon_set_new_target(target_bytes >> PAGE_SHIFT);
78 return count;
79 }
81 static SYSDEV_ATTR(target_kb, S_IRUGO | S_IWUSR,
82 show_target_kb, store_target_kb);
84 static struct sysdev_attribute *balloon_attrs[] = {
85 &attr_target_kb,
86 };
88 static struct attribute *balloon_info_attrs[] = {
89 &attr_current_kb.attr,
90 &attr_low_kb.attr,
91 &attr_high_kb.attr,
92 &attr_hard_limit_kb.attr,
93 &attr_driver_kb.attr,
94 NULL
95 };
97 static struct attribute_group balloon_info_group = {
98 .name = "info",
99 .attrs = balloon_info_attrs,
100 };
102 static struct sysdev_class balloon_sysdev_class = {
103 set_kset_name(BALLOON_CLASS_NAME),
104 };
106 static struct sys_device balloon_sysdev;
108 static int register_balloon(struct sys_device *sysdev)
109 {
110 int i, error;
112 error = sysdev_class_register(&balloon_sysdev_class);
113 if (error)
114 return error;
116 sysdev->id = 0;
117 sysdev->cls = &balloon_sysdev_class;
119 error = sysdev_register(sysdev);
120 if (error) {
121 sysdev_class_unregister(&balloon_sysdev_class);
122 return error;
123 }
125 for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++) {
126 error = sysdev_create_file(sysdev, balloon_attrs[i]);
127 if (error)
128 goto fail;
129 }
131 error = sysfs_create_group(&sysdev->kobj, &balloon_info_group);
132 if (error)
133 goto fail;
135 return 0;
137 fail:
138 while (--i >= 0)
139 sysdev_remove_file(sysdev, balloon_attrs[i]);
140 sysdev_unregister(sysdev);
141 sysdev_class_unregister(&balloon_sysdev_class);
142 return error;
143 }
145 static void unregister_balloon(struct sys_device *sysdev)
146 {
147 int i;
149 sysfs_remove_group(&sysdev->kobj, &balloon_info_group);
150 for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++)
151 sysdev_remove_file(sysdev, balloon_attrs[i]);
152 sysdev_unregister(sysdev);
153 sysdev_class_unregister(&balloon_sysdev_class);
154 }
156 int balloon_sysfs_init(void)
157 {
158 return register_balloon(&balloon_sysdev);
159 }
161 void balloon_sysfs_exit(void)
162 {
163 unregister_balloon(&balloon_sysdev);
164 }