diff options
Diffstat (limited to 'drivers/base/node.c')
-rw-r--r-- | drivers/base/node.c | 146 |
1 files changed, 76 insertions, 70 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c index 6ce1501c7de5..996d2189689b 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c | |||
@@ -1,8 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * drivers/base/node.c - basic Node class support | 2 | * Basic Node interface support |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include <linux/sysdev.h> | ||
6 | #include <linux/module.h> | 5 | #include <linux/module.h> |
7 | #include <linux/init.h> | 6 | #include <linux/init.h> |
8 | #include <linux/mm.h> | 7 | #include <linux/mm.h> |
@@ -19,18 +18,16 @@ | |||
19 | #include <linux/swap.h> | 18 | #include <linux/swap.h> |
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
21 | 20 | ||
22 | static struct sysdev_class_attribute *node_state_attrs[]; | 21 | static struct bus_type node_subsys = { |
23 | |||
24 | static struct sysdev_class node_class = { | ||
25 | .name = "node", | 22 | .name = "node", |
26 | .attrs = node_state_attrs, | 23 | .dev_name = "node", |
27 | }; | 24 | }; |
28 | 25 | ||
29 | 26 | ||
30 | static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) | 27 | static ssize_t node_read_cpumap(struct device *dev, int type, char *buf) |
31 | { | 28 | { |
32 | struct node *node_dev = to_node(dev); | 29 | struct node *node_dev = to_node(dev); |
33 | const struct cpumask *mask = cpumask_of_node(node_dev->sysdev.id); | 30 | const struct cpumask *mask = cpumask_of_node(node_dev->dev.id); |
34 | int len; | 31 | int len; |
35 | 32 | ||
36 | /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */ | 33 | /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */ |
@@ -44,23 +41,23 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) | |||
44 | return len; | 41 | return len; |
45 | } | 42 | } |
46 | 43 | ||
47 | static inline ssize_t node_read_cpumask(struct sys_device *dev, | 44 | static inline ssize_t node_read_cpumask(struct device *dev, |
48 | struct sysdev_attribute *attr, char *buf) | 45 | struct device_attribute *attr, char *buf) |
49 | { | 46 | { |
50 | return node_read_cpumap(dev, 0, buf); | 47 | return node_read_cpumap(dev, 0, buf); |
51 | } | 48 | } |
52 | static inline ssize_t node_read_cpulist(struct sys_device *dev, | 49 | static inline ssize_t node_read_cpulist(struct device *dev, |
53 | struct sysdev_attribute *attr, char *buf) | 50 | struct device_attribute *attr, char *buf) |
54 | { | 51 | { |
55 | return node_read_cpumap(dev, 1, buf); | 52 | return node_read_cpumap(dev, 1, buf); |
56 | } | 53 | } |
57 | 54 | ||
58 | static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); | 55 | static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); |
59 | static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); | 56 | static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); |
60 | 57 | ||
61 | #define K(x) ((x) << (PAGE_SHIFT - 10)) | 58 | #define K(x) ((x) << (PAGE_SHIFT - 10)) |
62 | static ssize_t node_read_meminfo(struct sys_device * dev, | 59 | static ssize_t node_read_meminfo(struct device *dev, |
63 | struct sysdev_attribute *attr, char * buf) | 60 | struct device_attribute *attr, char *buf) |
64 | { | 61 | { |
65 | int n; | 62 | int n; |
66 | int nid = dev->id; | 63 | int nid = dev->id; |
@@ -155,10 +152,10 @@ static ssize_t node_read_meminfo(struct sys_device * dev, | |||
155 | } | 152 | } |
156 | 153 | ||
157 | #undef K | 154 | #undef K |
158 | static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); | 155 | static DEVICE_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); |
159 | 156 | ||
160 | static ssize_t node_read_numastat(struct sys_device * dev, | 157 | static ssize_t node_read_numastat(struct device *dev, |
161 | struct sysdev_attribute *attr, char * buf) | 158 | struct device_attribute *attr, char *buf) |
162 | { | 159 | { |
163 | return sprintf(buf, | 160 | return sprintf(buf, |
164 | "numa_hit %lu\n" | 161 | "numa_hit %lu\n" |
@@ -174,10 +171,10 @@ static ssize_t node_read_numastat(struct sys_device * dev, | |||
174 | node_page_state(dev->id, NUMA_LOCAL), | 171 | node_page_state(dev->id, NUMA_LOCAL), |
175 | node_page_state(dev->id, NUMA_OTHER)); | 172 | node_page_state(dev->id, NUMA_OTHER)); |
176 | } | 173 | } |
177 | static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); | 174 | static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); |
178 | 175 | ||
179 | static ssize_t node_read_vmstat(struct sys_device *dev, | 176 | static ssize_t node_read_vmstat(struct device *dev, |
180 | struct sysdev_attribute *attr, char *buf) | 177 | struct device_attribute *attr, char *buf) |
181 | { | 178 | { |
182 | int nid = dev->id; | 179 | int nid = dev->id; |
183 | int i; | 180 | int i; |
@@ -189,10 +186,10 @@ static ssize_t node_read_vmstat(struct sys_device *dev, | |||
189 | 186 | ||
190 | return n; | 187 | return n; |
191 | } | 188 | } |
192 | static SYSDEV_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL); | 189 | static DEVICE_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL); |
193 | 190 | ||
194 | static ssize_t node_read_distance(struct sys_device * dev, | 191 | static ssize_t node_read_distance(struct device *dev, |
195 | struct sysdev_attribute *attr, char * buf) | 192 | struct device_attribute *attr, char * buf) |
196 | { | 193 | { |
197 | int nid = dev->id; | 194 | int nid = dev->id; |
198 | int len = 0; | 195 | int len = 0; |
@@ -210,7 +207,7 @@ static ssize_t node_read_distance(struct sys_device * dev, | |||
210 | len += sprintf(buf + len, "\n"); | 207 | len += sprintf(buf + len, "\n"); |
211 | return len; | 208 | return len; |
212 | } | 209 | } |
213 | static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL); | 210 | static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL); |
214 | 211 | ||
215 | #ifdef CONFIG_HUGETLBFS | 212 | #ifdef CONFIG_HUGETLBFS |
216 | /* | 213 | /* |
@@ -228,7 +225,7 @@ static node_registration_func_t __hugetlb_unregister_node; | |||
228 | static inline bool hugetlb_register_node(struct node *node) | 225 | static inline bool hugetlb_register_node(struct node *node) |
229 | { | 226 | { |
230 | if (__hugetlb_register_node && | 227 | if (__hugetlb_register_node && |
231 | node_state(node->sysdev.id, N_HIGH_MEMORY)) { | 228 | node_state(node->dev.id, N_HIGH_MEMORY)) { |
232 | __hugetlb_register_node(node); | 229 | __hugetlb_register_node(node); |
233 | return true; | 230 | return true; |
234 | } | 231 | } |
@@ -264,17 +261,17 @@ int register_node(struct node *node, int num, struct node *parent) | |||
264 | { | 261 | { |
265 | int error; | 262 | int error; |
266 | 263 | ||
267 | node->sysdev.id = num; | 264 | node->dev.id = num; |
268 | node->sysdev.cls = &node_class; | 265 | node->dev.bus = &node_subsys; |
269 | error = sysdev_register(&node->sysdev); | 266 | error = device_register(&node->dev); |
270 | 267 | ||
271 | if (!error){ | 268 | if (!error){ |
272 | sysdev_create_file(&node->sysdev, &attr_cpumap); | 269 | device_create_file(&node->dev, &dev_attr_cpumap); |
273 | sysdev_create_file(&node->sysdev, &attr_cpulist); | 270 | device_create_file(&node->dev, &dev_attr_cpulist); |
274 | sysdev_create_file(&node->sysdev, &attr_meminfo); | 271 | device_create_file(&node->dev, &dev_attr_meminfo); |
275 | sysdev_create_file(&node->sysdev, &attr_numastat); | 272 | device_create_file(&node->dev, &dev_attr_numastat); |
276 | sysdev_create_file(&node->sysdev, &attr_distance); | 273 | device_create_file(&node->dev, &dev_attr_distance); |
277 | sysdev_create_file(&node->sysdev, &attr_vmstat); | 274 | device_create_file(&node->dev, &dev_attr_vmstat); |
278 | 275 | ||
279 | scan_unevictable_register_node(node); | 276 | scan_unevictable_register_node(node); |
280 | 277 | ||
@@ -294,17 +291,17 @@ int register_node(struct node *node, int num, struct node *parent) | |||
294 | */ | 291 | */ |
295 | void unregister_node(struct node *node) | 292 | void unregister_node(struct node *node) |
296 | { | 293 | { |
297 | sysdev_remove_file(&node->sysdev, &attr_cpumap); | 294 | device_remove_file(&node->dev, &dev_attr_cpumap); |
298 | sysdev_remove_file(&node->sysdev, &attr_cpulist); | 295 | device_remove_file(&node->dev, &dev_attr_cpulist); |
299 | sysdev_remove_file(&node->sysdev, &attr_meminfo); | 296 | device_remove_file(&node->dev, &dev_attr_meminfo); |
300 | sysdev_remove_file(&node->sysdev, &attr_numastat); | 297 | device_remove_file(&node->dev, &dev_attr_numastat); |
301 | sysdev_remove_file(&node->sysdev, &attr_distance); | 298 | device_remove_file(&node->dev, &dev_attr_distance); |
302 | sysdev_remove_file(&node->sysdev, &attr_vmstat); | 299 | device_remove_file(&node->dev, &dev_attr_vmstat); |
303 | 300 | ||
304 | scan_unevictable_unregister_node(node); | 301 | scan_unevictable_unregister_node(node); |
305 | hugetlb_unregister_node(node); /* no-op, if memoryless node */ | 302 | hugetlb_unregister_node(node); /* no-op, if memoryless node */ |
306 | 303 | ||
307 | sysdev_unregister(&node->sysdev); | 304 | device_unregister(&node->dev); |
308 | } | 305 | } |
309 | 306 | ||
310 | struct node node_devices[MAX_NUMNODES]; | 307 | struct node node_devices[MAX_NUMNODES]; |
@@ -324,15 +321,15 @@ int register_cpu_under_node(unsigned int cpu, unsigned int nid) | |||
324 | if (!obj) | 321 | if (!obj) |
325 | return 0; | 322 | return 0; |
326 | 323 | ||
327 | ret = sysfs_create_link(&node_devices[nid].sysdev.kobj, | 324 | ret = sysfs_create_link(&node_devices[nid].dev.kobj, |
328 | &obj->kobj, | 325 | &obj->kobj, |
329 | kobject_name(&obj->kobj)); | 326 | kobject_name(&obj->kobj)); |
330 | if (ret) | 327 | if (ret) |
331 | return ret; | 328 | return ret; |
332 | 329 | ||
333 | return sysfs_create_link(&obj->kobj, | 330 | return sysfs_create_link(&obj->kobj, |
334 | &node_devices[nid].sysdev.kobj, | 331 | &node_devices[nid].dev.kobj, |
335 | kobject_name(&node_devices[nid].sysdev.kobj)); | 332 | kobject_name(&node_devices[nid].dev.kobj)); |
336 | } | 333 | } |
337 | 334 | ||
338 | int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) | 335 | int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) |
@@ -346,10 +343,10 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) | |||
346 | if (!obj) | 343 | if (!obj) |
347 | return 0; | 344 | return 0; |
348 | 345 | ||
349 | sysfs_remove_link(&node_devices[nid].sysdev.kobj, | 346 | sysfs_remove_link(&node_devices[nid].dev.kobj, |
350 | kobject_name(&obj->kobj)); | 347 | kobject_name(&obj->kobj)); |
351 | sysfs_remove_link(&obj->kobj, | 348 | sysfs_remove_link(&obj->kobj, |
352 | kobject_name(&node_devices[nid].sysdev.kobj)); | 349 | kobject_name(&node_devices[nid].dev.kobj)); |
353 | 350 | ||
354 | return 0; | 351 | return 0; |
355 | } | 352 | } |
@@ -391,15 +388,15 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid) | |||
391 | continue; | 388 | continue; |
392 | if (page_nid != nid) | 389 | if (page_nid != nid) |
393 | continue; | 390 | continue; |
394 | ret = sysfs_create_link_nowarn(&node_devices[nid].sysdev.kobj, | 391 | ret = sysfs_create_link_nowarn(&node_devices[nid].dev.kobj, |
395 | &mem_blk->sysdev.kobj, | 392 | &mem_blk->dev.kobj, |
396 | kobject_name(&mem_blk->sysdev.kobj)); | 393 | kobject_name(&mem_blk->dev.kobj)); |
397 | if (ret) | 394 | if (ret) |
398 | return ret; | 395 | return ret; |
399 | 396 | ||
400 | return sysfs_create_link_nowarn(&mem_blk->sysdev.kobj, | 397 | return sysfs_create_link_nowarn(&mem_blk->dev.kobj, |
401 | &node_devices[nid].sysdev.kobj, | 398 | &node_devices[nid].dev.kobj, |
402 | kobject_name(&node_devices[nid].sysdev.kobj)); | 399 | kobject_name(&node_devices[nid].dev.kobj)); |
403 | } | 400 | } |
404 | /* mem section does not span the specified node */ | 401 | /* mem section does not span the specified node */ |
405 | return 0; | 402 | return 0; |
@@ -432,10 +429,10 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, | |||
432 | continue; | 429 | continue; |
433 | if (node_test_and_set(nid, *unlinked_nodes)) | 430 | if (node_test_and_set(nid, *unlinked_nodes)) |
434 | continue; | 431 | continue; |
435 | sysfs_remove_link(&node_devices[nid].sysdev.kobj, | 432 | sysfs_remove_link(&node_devices[nid].dev.kobj, |
436 | kobject_name(&mem_blk->sysdev.kobj)); | 433 | kobject_name(&mem_blk->dev.kobj)); |
437 | sysfs_remove_link(&mem_blk->sysdev.kobj, | 434 | sysfs_remove_link(&mem_blk->dev.kobj, |
438 | kobject_name(&node_devices[nid].sysdev.kobj)); | 435 | kobject_name(&node_devices[nid].dev.kobj)); |
439 | } | 436 | } |
440 | NODEMASK_FREE(unlinked_nodes); | 437 | NODEMASK_FREE(unlinked_nodes); |
441 | return 0; | 438 | return 0; |
@@ -466,7 +463,7 @@ static int link_mem_sections(int nid) | |||
466 | } | 463 | } |
467 | 464 | ||
468 | if (mem_blk) | 465 | if (mem_blk) |
469 | kobject_put(&mem_blk->sysdev.kobj); | 466 | kobject_put(&mem_blk->dev.kobj); |
470 | return err; | 467 | return err; |
471 | } | 468 | } |
472 | 469 | ||
@@ -594,19 +591,19 @@ static ssize_t print_nodes_state(enum node_states state, char *buf) | |||
594 | } | 591 | } |
595 | 592 | ||
596 | struct node_attr { | 593 | struct node_attr { |
597 | struct sysdev_class_attribute attr; | 594 | struct device_attribute attr; |
598 | enum node_states state; | 595 | enum node_states state; |
599 | }; | 596 | }; |
600 | 597 | ||
601 | static ssize_t show_node_state(struct sysdev_class *class, | 598 | static ssize_t show_node_state(struct device *dev, |
602 | struct sysdev_class_attribute *attr, char *buf) | 599 | struct device_attribute *attr, char *buf) |
603 | { | 600 | { |
604 | struct node_attr *na = container_of(attr, struct node_attr, attr); | 601 | struct node_attr *na = container_of(attr, struct node_attr, attr); |
605 | return print_nodes_state(na->state, buf); | 602 | return print_nodes_state(na->state, buf); |
606 | } | 603 | } |
607 | 604 | ||
608 | #define _NODE_ATTR(name, state) \ | 605 | #define _NODE_ATTR(name, state) \ |
609 | { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state } | 606 | { __ATTR(name, 0444, show_node_state, NULL), state } |
610 | 607 | ||
611 | static struct node_attr node_state_attr[] = { | 608 | static struct node_attr node_state_attr[] = { |
612 | _NODE_ATTR(possible, N_POSSIBLE), | 609 | _NODE_ATTR(possible, N_POSSIBLE), |
@@ -618,17 +615,26 @@ static struct node_attr node_state_attr[] = { | |||
618 | #endif | 615 | #endif |
619 | }; | 616 | }; |
620 | 617 | ||
621 | static struct sysdev_class_attribute *node_state_attrs[] = { | 618 | static struct attribute *node_state_attrs[] = { |
622 | &node_state_attr[0].attr, | 619 | &node_state_attr[0].attr.attr, |
623 | &node_state_attr[1].attr, | 620 | &node_state_attr[1].attr.attr, |
624 | &node_state_attr[2].attr, | 621 | &node_state_attr[2].attr.attr, |
625 | &node_state_attr[3].attr, | 622 | &node_state_attr[3].attr.attr, |
626 | #ifdef CONFIG_HIGHMEM | 623 | #ifdef CONFIG_HIGHMEM |
627 | &node_state_attr[4].attr, | 624 | &node_state_attr[4].attr.attr, |
628 | #endif | 625 | #endif |
629 | NULL | 626 | NULL |
630 | }; | 627 | }; |
631 | 628 | ||
629 | static struct attribute_group memory_root_attr_group = { | ||
630 | .attrs = node_state_attrs, | ||
631 | }; | ||
632 | |||
633 | static const struct attribute_group *cpu_root_attr_groups[] = { | ||
634 | &memory_root_attr_group, | ||
635 | NULL, | ||
636 | }; | ||
637 | |||
632 | #define NODE_CALLBACK_PRI 2 /* lower than SLAB */ | 638 | #define NODE_CALLBACK_PRI 2 /* lower than SLAB */ |
633 | static int __init register_node_type(void) | 639 | static int __init register_node_type(void) |
634 | { | 640 | { |
@@ -637,7 +643,7 @@ static int __init register_node_type(void) | |||
637 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); | 643 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); |
638 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES); | 644 | BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES); |
639 | 645 | ||
640 | ret = sysdev_class_register(&node_class); | 646 | ret = subsys_system_register(&node_subsys, cpu_root_attr_groups); |
641 | if (!ret) { | 647 | if (!ret) { |
642 | hotplug_memory_notifier(node_memory_callback, | 648 | hotplug_memory_notifier(node_memory_callback, |
643 | NODE_CALLBACK_PRI); | 649 | NODE_CALLBACK_PRI); |