Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / s390 / block / dasd_proc.c
bloba490dd7072139b67122132b00bc95ec604e6e7fa
1 /*
2 * File...........: linux/drivers/s390/block/dasd_proc.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2002
10 * /proc interface for the dasd driver.
14 #include <linux/ctype.h>
15 #include <linux/seq_file.h>
16 #include <linux/vmalloc.h>
17 #include <linux/proc_fs.h>
19 #include <asm/debug.h>
20 #include <asm/uaccess.h>
22 /* This is ugly... */
23 #define PRINTK_HEADER "dasd_proc:"
25 #include "dasd_int.h"
27 static struct proc_dir_entry *dasd_proc_root_entry = NULL;
28 static struct proc_dir_entry *dasd_devices_entry = NULL;
29 static struct proc_dir_entry *dasd_statistics_entry = NULL;
31 #ifdef CONFIG_DASD_PROFILE
32 static char *
33 dasd_get_user_string(const char __user *user_buf, size_t user_len)
35 char *buffer;
37 buffer = kmalloc(user_len + 1, GFP_KERNEL);
38 if (buffer == NULL)
39 return ERR_PTR(-ENOMEM);
40 if (copy_from_user(buffer, user_buf, user_len) != 0) {
41 kfree(buffer);
42 return ERR_PTR(-EFAULT);
44 /* got the string, now strip linefeed. */
45 if (buffer[user_len - 1] == '\n')
46 buffer[user_len - 1] = 0;
47 else
48 buffer[user_len] = 0;
49 return buffer;
51 #endif /* CONFIG_DASD_PROFILE */
53 static int
54 dasd_devices_show(struct seq_file *m, void *v)
56 struct dasd_device *device;
57 struct dasd_block *block;
58 char *substr;
60 device = dasd_device_from_devindex((unsigned long) v - 1);
61 if (IS_ERR(device))
62 return 0;
63 if (device->block)
64 block = device->block;
65 <<<<<<< HEAD:drivers/s390/block/dasd_proc.c
66 else
67 =======
68 else {
69 dasd_put_device(device);
70 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/s390/block/dasd_proc.c
71 return 0;
72 <<<<<<< HEAD:drivers/s390/block/dasd_proc.c
73 =======
75 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/s390/block/dasd_proc.c
76 /* Print device number. */
77 seq_printf(m, "%s", device->cdev->dev.bus_id);
78 /* Print discipline string. */
79 if (device != NULL && device->discipline != NULL)
80 seq_printf(m, "(%s)", device->discipline->name);
81 else
82 seq_printf(m, "(none)");
83 /* Print kdev. */
84 if (block->gdp)
85 seq_printf(m, " at (%3d:%6d)",
86 block->gdp->major, block->gdp->first_minor);
87 else
88 seq_printf(m, " at (???:??????)");
89 /* Print device name. */
90 if (block->gdp)
91 seq_printf(m, " is %-8s", block->gdp->disk_name);
92 else
93 seq_printf(m, " is ????????");
94 /* Print devices features. */
95 substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
96 seq_printf(m, "%4s: ", substr);
97 /* Print device status information. */
98 switch ((device != NULL) ? device->state : -1) {
99 case -1:
100 seq_printf(m, "unknown");
101 break;
102 case DASD_STATE_NEW:
103 seq_printf(m, "new");
104 break;
105 case DASD_STATE_KNOWN:
106 seq_printf(m, "detected");
107 break;
108 case DASD_STATE_BASIC:
109 seq_printf(m, "basic");
110 break;
111 case DASD_STATE_UNFMT:
112 seq_printf(m, "unformatted");
113 break;
114 case DASD_STATE_READY:
115 case DASD_STATE_ONLINE:
116 seq_printf(m, "active ");
117 if (dasd_check_blocksize(block->bp_block))
118 seq_printf(m, "n/f ");
119 else
120 seq_printf(m,
121 "at blocksize: %d, %ld blocks, %ld MB",
122 block->bp_block, block->blocks,
123 ((block->bp_block >> 9) *
124 block->blocks) >> 11);
125 break;
126 default:
127 seq_printf(m, "no stat");
128 break;
130 dasd_put_device(device);
131 if (dasd_probeonly)
132 seq_printf(m, "(probeonly)");
133 seq_printf(m, "\n");
134 return 0;
137 static void *dasd_devices_start(struct seq_file *m, loff_t *pos)
139 if (*pos >= dasd_max_devindex)
140 return NULL;
141 return (void *)((unsigned long) *pos + 1);
144 static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos)
146 ++*pos;
147 return dasd_devices_start(m, pos);
150 static void dasd_devices_stop(struct seq_file *m, void *v)
154 static const struct seq_operations dasd_devices_seq_ops = {
155 .start = dasd_devices_start,
156 .next = dasd_devices_next,
157 .stop = dasd_devices_stop,
158 .show = dasd_devices_show,
161 static int dasd_devices_open(struct inode *inode, struct file *file)
163 return seq_open(file, &dasd_devices_seq_ops);
166 static const struct file_operations dasd_devices_file_ops = {
167 .open = dasd_devices_open,
168 .read = seq_read,
169 .llseek = seq_lseek,
170 .release = seq_release,
173 static int
174 dasd_calc_metrics(char *page, char **start, off_t off,
175 int count, int *eof, int len)
177 len = (len > off) ? len - off : 0;
178 if (len > count)
179 len = count;
180 if (len < count)
181 *eof = 1;
182 *start = page + off;
183 return len;
186 #ifdef CONFIG_DASD_PROFILE
187 static char *
188 dasd_statistics_array(char *str, unsigned int *array, int shift)
190 int i;
192 for (i = 0; i < 32; i++) {
193 str += sprintf(str, "%7d ", array[i] >> shift);
194 if (i == 15)
195 str += sprintf(str, "\n");
197 str += sprintf(str,"\n");
198 return str;
200 #endif /* CONFIG_DASD_PROFILE */
202 static int
203 dasd_statistics_read(char *page, char **start, off_t off,
204 int count, int *eof, void *data)
206 unsigned long len;
207 #ifdef CONFIG_DASD_PROFILE
208 struct dasd_profile_info_t *prof;
209 char *str;
210 int shift;
212 /* check for active profiling */
213 if (dasd_profile_level == DASD_PROFILE_OFF) {
214 len = sprintf(page, "Statistics are off - they might be "
215 "switched on using 'echo set on > "
216 "/proc/dasd/statistics'\n");
217 return dasd_calc_metrics(page, start, off, count, eof, len);
220 prof = &dasd_global_profile;
221 /* prevent couter 'overflow' on output */
222 for (shift = 0; (prof->dasd_io_reqs >> shift) > 9999999; shift++);
224 str = page;
225 str += sprintf(str, "%d dasd I/O requests\n", prof->dasd_io_reqs);
226 str += sprintf(str, "with %d sectors(512B each)\n",
227 prof->dasd_io_sects);
228 str += sprintf(str,
229 " __<4 ___8 __16 __32 __64 _128 "
230 " _256 _512 __1k __2k __4k __8k "
231 " _16k _32k _64k 128k\n");
232 str += sprintf(str,
233 " _256 _512 __1M __2M __4M __8M "
234 " _16M _32M _64M 128M 256M 512M "
235 " __1G __2G __4G " " _>4G\n");
237 str += sprintf(str, "Histogram of sizes (512B secs)\n");
238 str = dasd_statistics_array(str, prof->dasd_io_secs, shift);
239 str += sprintf(str, "Histogram of I/O times (microseconds)\n");
240 str = dasd_statistics_array(str, prof->dasd_io_times, shift);
241 str += sprintf(str, "Histogram of I/O times per sector\n");
242 str = dasd_statistics_array(str, prof->dasd_io_timps, shift);
243 str += sprintf(str, "Histogram of I/O time till ssch\n");
244 str = dasd_statistics_array(str, prof->dasd_io_time1, shift);
245 str += sprintf(str, "Histogram of I/O time between ssch and irq\n");
246 str = dasd_statistics_array(str, prof->dasd_io_time2, shift);
247 str += sprintf(str, "Histogram of I/O time between ssch "
248 "and irq per sector\n");
249 str = dasd_statistics_array(str, prof->dasd_io_time2ps, shift);
250 str += sprintf(str, "Histogram of I/O time between irq and end\n");
251 str = dasd_statistics_array(str, prof->dasd_io_time3, shift);
252 str += sprintf(str, "# of req in chanq at enqueuing (1..32) \n");
253 str = dasd_statistics_array(str, prof->dasd_io_nr_req, shift);
254 len = str - page;
255 #else
256 len = sprintf(page, "Statistics are not activated in this kernel\n");
257 #endif
258 return dasd_calc_metrics(page, start, off, count, eof, len);
261 static int
262 dasd_statistics_write(struct file *file, const char __user *user_buf,
263 unsigned long user_len, void *data)
265 #ifdef CONFIG_DASD_PROFILE
266 char *buffer, *str;
268 if (user_len > 65536)
269 user_len = 65536;
270 buffer = dasd_get_user_string(user_buf, user_len);
271 if (IS_ERR(buffer))
272 return PTR_ERR(buffer);
273 MESSAGE_LOG(KERN_INFO, "/proc/dasd/statictics: '%s'", buffer);
275 /* check for valid verbs */
276 for (str = buffer; isspace(*str); str++);
277 if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
278 /* 'set xxx' was given */
279 for (str = str + 4; isspace(*str); str++);
280 if (strcmp(str, "on") == 0) {
281 /* switch on statistics profiling */
282 dasd_profile_level = DASD_PROFILE_ON;
283 MESSAGE(KERN_INFO, "%s", "Statistics switched on");
284 } else if (strcmp(str, "off") == 0) {
285 /* switch off and reset statistics profiling */
286 memset(&dasd_global_profile,
287 0, sizeof (struct dasd_profile_info_t));
288 dasd_profile_level = DASD_PROFILE_OFF;
289 MESSAGE(KERN_INFO, "%s", "Statistics switched off");
290 } else
291 goto out_error;
292 } else if (strncmp(str, "reset", 5) == 0) {
293 /* reset the statistics */
294 memset(&dasd_global_profile, 0,
295 sizeof (struct dasd_profile_info_t));
296 MESSAGE(KERN_INFO, "%s", "Statistics reset");
297 } else
298 goto out_error;
299 kfree(buffer);
300 return user_len;
301 out_error:
302 MESSAGE(KERN_WARNING, "%s",
303 "/proc/dasd/statistics: only 'set on', 'set off' "
304 "and 'reset' are supported verbs");
305 kfree(buffer);
306 return -EINVAL;
307 #else
308 MESSAGE(KERN_WARNING, "%s",
309 "/proc/dasd/statistics: is not activated in this kernel");
310 return user_len;
311 #endif /* CONFIG_DASD_PROFILE */
315 * Create dasd proc-fs entries.
316 * In case creation failed, cleanup and return -ENOENT.
319 dasd_proc_init(void)
321 dasd_proc_root_entry = proc_mkdir("dasd", &proc_root);
322 if (!dasd_proc_root_entry)
323 goto out_nodasd;
324 dasd_proc_root_entry->owner = THIS_MODULE;
325 dasd_devices_entry = create_proc_entry("devices",
326 S_IFREG | S_IRUGO | S_IWUSR,
327 dasd_proc_root_entry);
328 if (!dasd_devices_entry)
329 goto out_nodevices;
330 dasd_devices_entry->proc_fops = &dasd_devices_file_ops;
331 dasd_devices_entry->owner = THIS_MODULE;
332 dasd_statistics_entry = create_proc_entry("statistics",
333 S_IFREG | S_IRUGO | S_IWUSR,
334 dasd_proc_root_entry);
335 if (!dasd_statistics_entry)
336 goto out_nostatistics;
337 dasd_statistics_entry->read_proc = dasd_statistics_read;
338 dasd_statistics_entry->write_proc = dasd_statistics_write;
339 dasd_statistics_entry->owner = THIS_MODULE;
340 return 0;
342 out_nostatistics:
343 remove_proc_entry("devices", dasd_proc_root_entry);
344 out_nodevices:
345 remove_proc_entry("dasd", &proc_root);
346 out_nodasd:
347 return -ENOENT;
350 void
351 dasd_proc_exit(void)
353 remove_proc_entry("devices", dasd_proc_root_entry);
354 remove_proc_entry("statistics", dasd_proc_root_entry);
355 remove_proc_entry("dasd", &proc_root);