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/config.h>
15 #include <linux/ctype.h>
16 #include <linux/seq_file.h>
17 #include <linux/vmalloc.h>
18 #include <linux/proc_fs.h>
20 #include <asm/debug.h>
21 #include <asm/uaccess.h>
24 #define PRINTK_HEADER "dasd_proc:"
28 static struct proc_dir_entry *dasd_proc_root_entry = NULL;
29 static struct proc_dir_entry *dasd_devices_entry = NULL;
30 static struct proc_dir_entry *dasd_statistics_entry = NULL;
33 dasd_get_user_string(const char __user *user_buf, size_t user_len)
37 buffer = kmalloc(user_len + 1, GFP_KERNEL);
39 return ERR_PTR(-ENOMEM);
40 if (copy_from_user(buffer, user_buf, user_len) != 0) {
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;
53 dasd_devices_show(struct seq_file *m, void *v)
55 struct dasd_device *device;
58 device = dasd_device_from_devindex((unsigned long) v - 1);
61 /* Print device number. */
62 seq_printf(m, "%s", device->cdev->dev.bus_id);
63 /* Print discipline string. */
64 if (device != NULL && device->discipline != NULL)
65 seq_printf(m, "(%s)", device->discipline->name);
67 seq_printf(m, "(none)");
70 seq_printf(m, " at (%3d:%6d)",
71 device->gdp->major, device->gdp->first_minor);
73 seq_printf(m, " at (???:??????)");
74 /* Print device name. */
76 seq_printf(m, " is %-8s", device->gdp->disk_name);
78 seq_printf(m, " is ????????");
79 /* Print devices features. */
80 substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
81 seq_printf(m, "%4s: ", substr);
82 /* Print device status information. */
83 switch ((device != NULL) ? device->state : -1) {
85 seq_printf(m, "unknown");
90 case DASD_STATE_KNOWN:
91 seq_printf(m, "detected");
93 case DASD_STATE_BASIC:
94 seq_printf(m, "basic");
96 case DASD_STATE_UNFMT:
97 seq_printf(m, "unformatted");
99 case DASD_STATE_READY:
100 case DASD_STATE_ONLINE:
101 seq_printf(m, "active ");
102 if (dasd_check_blocksize(device->bp_block))
103 seq_printf(m, "n/f ");
106 "at blocksize: %d, %ld blocks, %ld MB",
107 device->bp_block, device->blocks,
108 ((device->bp_block >> 9) *
109 device->blocks) >> 11);
112 seq_printf(m, "no stat");
115 dasd_put_device(device);
117 seq_printf(m, "(probeonly)");
122 static void *dasd_devices_start(struct seq_file *m, loff_t *pos)
124 if (*pos >= dasd_max_devindex)
126 return (void *)((unsigned long) *pos + 1);
129 static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos)
132 return dasd_devices_start(m, pos);
135 static void dasd_devices_stop(struct seq_file *m, void *v)
139 static struct seq_operations dasd_devices_seq_ops = {
140 .start = dasd_devices_start,
141 .next = dasd_devices_next,
142 .stop = dasd_devices_stop,
143 .show = dasd_devices_show,
146 static int dasd_devices_open(struct inode *inode, struct file *file)
148 return seq_open(file, &dasd_devices_seq_ops);
151 static struct file_operations dasd_devices_file_ops = {
152 .open = dasd_devices_open,
155 .release = seq_release,
159 dasd_calc_metrics(char *page, char **start, off_t off,
160 int count, int *eof, int len)
162 len = (len > off) ? len - off : 0;
172 dasd_statistics_array(char *str, int *array, int shift)
176 for (i = 0; i < 32; i++) {
177 str += sprintf(str, "%7d ", array[i] >> shift);
179 str += sprintf(str, "\n");
181 str += sprintf(str,"\n");
186 dasd_statistics_read(char *page, char **start, off_t off,
187 int count, int *eof, void *data)
190 #ifdef CONFIG_DASD_PROFILE
191 struct dasd_profile_info_t *prof;
195 /* check for active profiling */
196 if (dasd_profile_level == DASD_PROFILE_OFF) {
197 len = sprintf(page, "Statistics are off - they might be "
198 "switched on using 'echo set on > "
199 "/proc/dasd/statistics'\n");
200 return dasd_calc_metrics(page, start, off, count, eof, len);
203 prof = &dasd_global_profile;
204 /* prevent couter 'overflow' on output */
205 for (shift = 0; (prof->dasd_io_reqs >> shift) > 9999999; shift++);
208 str += sprintf(str, "%d dasd I/O requests\n", prof->dasd_io_reqs);
209 str += sprintf(str, "with %d sectors(512B each)\n",
210 prof->dasd_io_sects);
212 " __<4 ___8 __16 __32 __64 _128 "
213 " _256 _512 __1k __2k __4k __8k "
214 " _16k _32k _64k 128k\n");
216 " _256 _512 __1M __2M __4M __8M "
217 " _16M _32M _64M 128M 256M 512M "
218 " __1G __2G __4G " " _>4G\n");
220 str += sprintf(str, "Histogram of sizes (512B secs)\n");
221 str = dasd_statistics_array(str, prof->dasd_io_secs, shift);
222 str += sprintf(str, "Histogram of I/O times (microseconds)\n");
223 str = dasd_statistics_array(str, prof->dasd_io_times, shift);
224 str += sprintf(str, "Histogram of I/O times per sector\n");
225 str = dasd_statistics_array(str, prof->dasd_io_timps, shift);
226 str += sprintf(str, "Histogram of I/O time till ssch\n");
227 str = dasd_statistics_array(str, prof->dasd_io_time1, shift);
228 str += sprintf(str, "Histogram of I/O time between ssch and irq\n");
229 str = dasd_statistics_array(str, prof->dasd_io_time2, shift);
230 str += sprintf(str, "Histogram of I/O time between ssch "
231 "and irq per sector\n");
232 str = dasd_statistics_array(str, prof->dasd_io_time2ps, shift);
233 str += sprintf(str, "Histogram of I/O time between irq and end\n");
234 str = dasd_statistics_array(str, prof->dasd_io_time3, shift);
235 str += sprintf(str, "# of req in chanq at enqueuing (1..32) \n");
236 str = dasd_statistics_array(str, prof->dasd_io_nr_req, shift);
239 len = sprintf(page, "Statistics are not activated in this kernel\n");
241 return dasd_calc_metrics(page, start, off, count, eof, len);
245 dasd_statistics_write(struct file *file, const char __user *user_buf,
246 unsigned long user_len, void *data)
248 #ifdef CONFIG_DASD_PROFILE
251 if (user_len > 65536)
253 buffer = dasd_get_user_string(user_buf, user_len);
255 return PTR_ERR(buffer);
256 MESSAGE_LOG(KERN_INFO, "/proc/dasd/statictics: '%s'", buffer);
258 /* check for valid verbs */
259 for (str = buffer; isspace(*str); str++);
260 if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
261 /* 'set xxx' was given */
262 for (str = str + 4; isspace(*str); str++);
263 if (strcmp(str, "on") == 0) {
264 /* switch on statistics profiling */
265 dasd_profile_level = DASD_PROFILE_ON;
266 MESSAGE(KERN_INFO, "%s", "Statistics switched on");
267 } else if (strcmp(str, "off") == 0) {
268 /* switch off and reset statistics profiling */
269 memset(&dasd_global_profile,
270 0, sizeof (struct dasd_profile_info_t));
271 dasd_profile_level = DASD_PROFILE_OFF;
272 MESSAGE(KERN_INFO, "%s", "Statistics switched off");
275 } else if (strncmp(str, "reset", 5) == 0) {
276 /* reset the statistics */
277 memset(&dasd_global_profile, 0,
278 sizeof (struct dasd_profile_info_t));
279 MESSAGE(KERN_INFO, "%s", "Statistics reset");
285 MESSAGE(KERN_WARNING, "%s",
286 "/proc/dasd/statistics: only 'set on', 'set off' "
287 "and 'reset' are supported verbs");
291 MESSAGE(KERN_WARNING, "%s",
292 "/proc/dasd/statistics: is not activated in this kernel");
294 #endif /* CONFIG_DASD_PROFILE */
298 * Create dasd proc-fs entries.
299 * In case creation failed, cleanup and return -ENOENT.
304 dasd_proc_root_entry = proc_mkdir("dasd", &proc_root);
305 if (!dasd_proc_root_entry)
307 dasd_proc_root_entry->owner = THIS_MODULE;
308 dasd_devices_entry = create_proc_entry("devices",
309 S_IFREG | S_IRUGO | S_IWUSR,
310 dasd_proc_root_entry);
311 if (!dasd_devices_entry)
313 dasd_devices_entry->proc_fops = &dasd_devices_file_ops;
314 dasd_devices_entry->owner = THIS_MODULE;
315 dasd_statistics_entry = create_proc_entry("statistics",
316 S_IFREG | S_IRUGO | S_IWUSR,
317 dasd_proc_root_entry);
318 if (!dasd_statistics_entry)
319 goto out_nostatistics;
320 dasd_statistics_entry->read_proc = dasd_statistics_read;
321 dasd_statistics_entry->write_proc = dasd_statistics_write;
322 dasd_statistics_entry->owner = THIS_MODULE;
326 remove_proc_entry("devices", dasd_proc_root_entry);
328 remove_proc_entry("dasd", &proc_root);
336 remove_proc_entry("devices", dasd_proc_root_entry);
337 remove_proc_entry("statistics", dasd_proc_root_entry);
338 remove_proc_entry("dasd", &proc_root);