Skip to content

Commit 7170be5

Browse files
Neil HormanLinus Torvalds
authored andcommitted
[PATCH] convert /proc/devices to use seq_file interface
A Christoph suggested that the /proc/devices file be converted to use the seq_file interface. This patch does that. I've obxerved one or two installation that had sufficiently large sans that they overran the 4k limit on /proc/devices. Signed-off-by: Neil Horman <nhorman@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent faf3a98 commit 7170be5

4 files changed

Lines changed: 320 additions & 53 deletions

File tree

‎block/genhd.c‎

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,100 @@ static inline int major_to_index(int major)
3838
return major % MAX_PROBE_HASH;
3939
}
4040

41-
#ifdef CONFIG_PROC_FS
42-
/* get block device names in somewhat random order */
43-
int get_blkdev_list(char *p, int used)
41+
struct blkdev_info {
42+
int index;
43+
struct blk_major_name *bd;
44+
};
45+
46+
/*
47+
* iterate over a list of blkdev_info structures. allows
48+
* the major_names array to be iterated over from outside this file
49+
* must be called with the block_subsys_sem held
50+
*/
51+
void *get_next_blkdev(void *dev)
52+
{
53+
struct blkdev_info *info;
54+
55+
if (dev == NULL) {
56+
info = kmalloc(sizeof(*info), GFP_KERNEL);
57+
if (!info)
58+
goto out;
59+
info->index=0;
60+
info->bd = major_names[info->index];
61+
if (info->bd)
62+
goto out;
63+
} else {
64+
info = dev;
65+
}
66+
67+
while (info->index < ARRAY_SIZE(major_names)) {
68+
if (info->bd)
69+
info->bd = info->bd->next;
70+
if (info->bd)
71+
goto out;
72+
/*
73+
* No devices on this chain, move to the next
74+
*/
75+
info->index++;
76+
info->bd = (info->index < ARRAY_SIZE(major_names)) ?
77+
major_names[info->index] : NULL;
78+
if (info->bd)
79+
goto out;
80+
}
81+
82+
out:
83+
return info;
84+
}
85+
86+
void *acquire_blkdev_list(void)
87+
{
88+
down(&block_subsys_sem);
89+
return get_next_blkdev(NULL);
90+
}
91+
92+
void release_blkdev_list(void *dev)
93+
{
94+
up(&block_subsys_sem);
95+
kfree(dev);
96+
}
97+
98+
99+
/*
100+
* Count the number of records in the blkdev_list.
101+
* must be called with the block_subsys_sem held
102+
*/
103+
int count_blkdev_list(void)
44104
{
45105
struct blk_major_name *n;
46-
int i, len;
106+
int i, count;
47107

48-
len = snprintf(p, (PAGE_SIZE-used), "\nBlock devices:\n");
108+
count = 0;
49109

50-
down(&block_subsys_sem);
51110
for (i = 0; i < ARRAY_SIZE(major_names); i++) {
52-
for (n = major_names[i]; n; n = n->next) {
53-
/*
54-
* If the curent string plus the 5 extra characters
55-
* in the line would run us off the page, then we're done
56-
*/
57-
if ((len + used + strlen(n->name) + 5) >= PAGE_SIZE)
58-
goto page_full;
59-
len += sprintf(p+len, "%3d %s\n",
60-
n->major, n->name);
61-
}
111+
for (n = major_names[i]; n; n = n->next)
112+
count++;
62113
}
63-
page_full:
64-
up(&block_subsys_sem);
65114

66-
return len;
115+
return count;
67116
}
68-
#endif
117+
118+
/*
119+
* extract the major and name values from a blkdev_info struct
120+
* passed in as a void to *dev. Must be called with
121+
* block_subsys_sem held
122+
*/
123+
int get_blkdev_info(void *dev, int *major, char **name)
124+
{
125+
struct blkdev_info *info = dev;
126+
127+
if (info->bd == NULL)
128+
return 1;
129+
130+
*major = info->bd->major;
131+
*name = info->bd->name;
132+
return 0;
133+
}
134+
69135

70136
int register_blkdev(unsigned int major, const char *name)
71137
{

‎fs/char_dev.c‎

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static struct char_device_struct {
3535
unsigned int major;
3636
unsigned int baseminor;
3737
int minorct;
38-
const char *name;
38+
char name[64];
3939
struct file_operations *fops;
4040
struct cdev *cdev; /* will die */
4141
} *chrdevs[MAX_PROBE_HASH];
@@ -46,34 +46,84 @@ static inline int major_to_index(int major)
4646
return major % MAX_PROBE_HASH;
4747
}
4848

49-
/* get char device names in somewhat random order */
50-
int get_chrdev_list(char *page)
51-
{
49+
struct chrdev_info {
50+
int index;
5251
struct char_device_struct *cd;
53-
int i, len;
52+
};
5453

55-
len = sprintf(page, "Character devices:\n");
54+
void *get_next_chrdev(void *dev)
55+
{
56+
struct chrdev_info *info;
5657

58+
if (dev == NULL) {
59+
info = kmalloc(sizeof(*info), GFP_KERNEL);
60+
if (!info)
61+
goto out;
62+
info->index=0;
63+
info->cd = chrdevs[info->index];
64+
if (info->cd)
65+
goto out;
66+
} else {
67+
info = dev;
68+
}
69+
70+
while (info->index < ARRAY_SIZE(chrdevs)) {
71+
if (info->cd)
72+
info->cd = info->cd->next;
73+
if (info->cd)
74+
goto out;
75+
/*
76+
* No devices on this chain, move to the next
77+
*/
78+
info->index++;
79+
info->cd = (info->index < ARRAY_SIZE(chrdevs)) ?
80+
chrdevs[info->index] : NULL;
81+
if (info->cd)
82+
goto out;
83+
}
84+
85+
out:
86+
return info;
87+
}
88+
89+
void *acquire_chrdev_list(void)
90+
{
5791
down(&chrdevs_lock);
92+
return get_next_chrdev(NULL);
93+
}
94+
95+
void release_chrdev_list(void *dev)
96+
{
97+
up(&chrdevs_lock);
98+
kfree(dev);
99+
}
100+
101+
102+
int count_chrdev_list(void)
103+
{
104+
struct char_device_struct *cd;
105+
int i, count;
106+
107+
count = 0;
108+
58109
for (i = 0; i < ARRAY_SIZE(chrdevs) ; i++) {
59-
for (cd = chrdevs[i]; cd; cd = cd->next) {
60-
/*
61-
* if the current name, plus the 5 extra characters
62-
* in the device line for this entry
63-
* would run us off the page, we're done
64-
*/
65-
if ((len+strlen(cd->name) + 5) >= PAGE_SIZE)
66-
goto page_full;
67-
68-
69-
len += sprintf(page+len, "%3d %s\n",
70-
cd->major, cd->name);
71-
}
110+
for (cd = chrdevs[i]; cd; cd = cd->next)
111+
count++;
72112
}
73-
page_full:
74-
up(&chrdevs_lock);
75113

76-
return len;
114+
return count;
115+
}
116+
117+
int get_chrdev_info(void *dev, int *major, char **name)
118+
{
119+
struct chrdev_info *info = dev;
120+
121+
if (info->cd == NULL)
122+
return 1;
123+
124+
*major = info->cd->major;
125+
*name = info->cd->name;
126+
return 0;
77127
}
78128

79129
/*
@@ -121,7 +171,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
121171
cd->major = major;
122172
cd->baseminor = baseminor;
123173
cd->minorct = minorct;
124-
cd->name = name;
174+
strncpy(cd->name,name, 64);
125175

126176
i = major_to_index(major);
127177

0 commit comments

Comments
 (0)