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 #define KMSG_COMPONENT "dasd"
16 #include <linux/ctype.h>
17 #include <linux/seq_file.h>
18 #include <linux/vmalloc.h>
19 #include <linux/proc_fs.h>
21 #include <asm/debug.h>
22 #include <asm/uaccess.h>
25 #define PRINTK_HEADER "dasd_proc:"
29 static struct proc_dir_entry *dasd_proc_root_entry = NULL;
30 static struct proc_dir_entry *dasd_devices_entry = NULL;
31 static struct proc_dir_entry *dasd_statistics_entry = NULL;
33 #ifdef CONFIG_DASD_PROFILE
35 dasd_get_user_string(const char __user *user_buf, size_t user_len)
39 buffer = kmalloc(user_len + 1, GFP_KERNEL);
41 return ERR_PTR(-ENOMEM);
42 if (copy_from_user(buffer, user_buf, user_len) != 0) {
44 return ERR_PTR(-EFAULT);
46 /* got the string, now strip linefeed. */
47 if (buffer[user_len - 1] == '\n')
48 buffer[user_len - 1] = 0;
53 #endif /* CONFIG_DASD_PROFILE */
56 dasd_devices_show(struct seq_file *m, void *v)
58 struct dasd_device *device;
59 struct dasd_block *block;
62 device = dasd_device_from_devindex((unsigned long) v - 1);
66 block = device->block;
68 dasd_put_device(device);
71 /* Print device number. */
72 seq_printf(m, "%s", dev_name(&device->cdev->dev));
73 /* Print discipline string. */
74 if (device != NULL && device->discipline != NULL)
75 seq_printf(m, "(%s)", device->discipline->name);
77 seq_printf(m, "(none)");
80 seq_printf(m, " at (%3d:%6d)",
81 MAJOR(disk_devt(block->gdp)),
82 MINOR(disk_devt(block->gdp)));
84 seq_printf(m, " at (???:??????)");
85 /* Print device name. */
87 seq_printf(m, " is %-8s", block->gdp->disk_name);
89 seq_printf(m, " is ????????");
90 /* Print devices features. */
91 substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
92 seq_printf(m, "%4s: ", substr);
93 /* Print device status information. */
94 switch ((device != NULL) ? device->state : -1) {
96 seq_printf(m, "unknown");
101 case DASD_STATE_KNOWN:
102 seq_printf(m, "detected");
104 case DASD_STATE_BASIC:
105 seq_printf(m, "basic");
107 case DASD_STATE_UNFMT:
108 seq_printf(m, "unformatted");
110 case DASD_STATE_READY:
111 case DASD_STATE_ONLINE:
112 seq_printf(m, "active ");
113 if (dasd_check_blocksize(block->bp_block))
114 seq_printf(m, "n/f ");
117 "at blocksize: %d, %lld blocks, %lld MB",
118 block->bp_block, block->blocks,
119 ((block->bp_block >> 9) *
120 block->blocks) >> 11);
123 seq_printf(m, "no stat");
126 dasd_put_device(device);
128 seq_printf(m, "(probeonly)");
133 static void *dasd_devices_start(struct seq_file *m, loff_t *pos)
135 if (*pos >= dasd_max_devindex)
137 return (void *)((unsigned long) *pos + 1);
140 static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos)
143 return dasd_devices_start(m, pos);
146 static void dasd_devices_stop(struct seq_file *m, void *v)
150 static const struct seq_operations dasd_devices_seq_ops = {
151 .start = dasd_devices_start,
152 .next = dasd_devices_next,
153 .stop = dasd_devices_stop,
154 .show = dasd_devices_show,
157 static int dasd_devices_open(struct inode *inode, struct file *file)
159 return seq_open(file, &dasd_devices_seq_ops);
162 static const struct file_operations dasd_devices_file_ops = {
163 .owner = THIS_MODULE,
164 .open = dasd_devices_open,
167 .release = seq_release,
171 dasd_calc_metrics(char *page, char **start, off_t off,
172 int count, int *eof, int len)
174 len = (len > off) ? len - off : 0;
183 #ifdef CONFIG_DASD_PROFILE
185 dasd_statistics_array(char *str, unsigned int *array, int factor)
189 for (i = 0; i < 32; i++) {
190 str += sprintf(str, "%7d ", array[i] / factor);
192 str += sprintf(str, "\n");
194 str += sprintf(str,"\n");
197 #endif /* CONFIG_DASD_PROFILE */
200 dasd_statistics_read(char *page, char **start, off_t off,
201 int count, int *eof, void *data)
204 #ifdef CONFIG_DASD_PROFILE
205 struct dasd_profile_info_t *prof;
209 /* check for active profiling */
210 if (dasd_profile_level == DASD_PROFILE_OFF) {
211 len = sprintf(page, "Statistics are off - they might be "
212 "switched on using 'echo set on > "
213 "/proc/dasd/statistics'\n");
214 return dasd_calc_metrics(page, start, off, count, eof, len);
217 prof = &dasd_global_profile;
218 /* prevent couter 'overflow' on output */
219 for (factor = 1; (prof->dasd_io_reqs / factor) > 9999999;
223 str += sprintf(str, "%d dasd I/O requests\n", prof->dasd_io_reqs);
224 str += sprintf(str, "with %u sectors(512B each)\n",
225 prof->dasd_io_sects);
226 str += sprintf(str, "Scale Factor is %d\n", factor);
228 " __<4 ___8 __16 __32 __64 _128 "
229 " _256 _512 __1k __2k __4k __8k "
230 " _16k _32k _64k 128k\n");
232 " _256 _512 __1M __2M __4M __8M "
233 " _16M _32M _64M 128M 256M 512M "
234 " __1G __2G __4G " " _>4G\n");
236 str += sprintf(str, "Histogram of sizes (512B secs)\n");
237 str = dasd_statistics_array(str, prof->dasd_io_secs, factor);
238 str += sprintf(str, "Histogram of I/O times (microseconds)\n");
239 str = dasd_statistics_array(str, prof->dasd_io_times, factor);
240 str += sprintf(str, "Histogram of I/O times per sector\n");
241 str = dasd_statistics_array(str, prof->dasd_io_timps, factor);
242 str += sprintf(str, "Histogram of I/O time till ssch\n");
243 str = dasd_statistics_array(str, prof->dasd_io_time1, factor);
244 str += sprintf(str, "Histogram of I/O time between ssch and irq\n");
245 str = dasd_statistics_array(str, prof->dasd_io_time2, factor);
246 str += sprintf(str, "Histogram of I/O time between ssch "
247 "and irq per sector\n");
248 str = dasd_statistics_array(str, prof->dasd_io_time2ps, factor);
249 str += sprintf(str, "Histogram of I/O time between irq and end\n");
250 str = dasd_statistics_array(str, prof->dasd_io_time3, factor);
251 str += sprintf(str, "# of req in chanq at enqueuing (1..32) \n");
252 str = dasd_statistics_array(str, prof->dasd_io_nr_req, factor);
255 len = sprintf(page, "Statistics are not activated in this kernel\n");
257 return dasd_calc_metrics(page, start, off, count, eof, len);
261 dasd_statistics_write(struct file *file, const char __user *user_buf,
262 unsigned long user_len, void *data)
264 #ifdef CONFIG_DASD_PROFILE
267 if (user_len > 65536)
269 buffer = dasd_get_user_string(user_buf, user_len);
271 return PTR_ERR(buffer);
272 DBF_EVENT(DBF_DEBUG, "/proc/dasd/statictics: '%s'\n", buffer);
274 /* check for valid verbs */
275 for (str = buffer; isspace(*str); str++);
276 if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
277 /* 'set xxx' was given */
278 for (str = str + 4; isspace(*str); str++);
279 if (strcmp(str, "on") == 0) {
280 /* switch on statistics profiling */
281 dasd_profile_level = DASD_PROFILE_ON;
282 pr_info("The statistics feature has been switched "
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 pr_info("The statistics feature has been switched "
293 } else if (strncmp(str, "reset", 5) == 0) {
294 /* reset the statistics */
295 memset(&dasd_global_profile, 0,
296 sizeof (struct dasd_profile_info_t));
297 pr_info("The statistics have been reset\n");
303 pr_warning("%s is not a supported value for /proc/dasd/statistics\n",
308 pr_warning("/proc/dasd/statistics: is not activated in this kernel\n");
310 #endif /* CONFIG_DASD_PROFILE */
314 * Create dasd proc-fs entries.
315 * In case creation failed, cleanup and return -ENOENT.
320 dasd_proc_root_entry = proc_mkdir("dasd", NULL);
321 if (!dasd_proc_root_entry)
323 dasd_proc_root_entry->owner = THIS_MODULE;
324 dasd_devices_entry = proc_create("devices",
325 S_IFREG | S_IRUGO | S_IWUSR,
326 dasd_proc_root_entry,
327 &dasd_devices_file_ops);
328 if (!dasd_devices_entry)
330 dasd_statistics_entry = create_proc_entry("statistics",
331 S_IFREG | S_IRUGO | S_IWUSR,
332 dasd_proc_root_entry);
333 if (!dasd_statistics_entry)
334 goto out_nostatistics;
335 dasd_statistics_entry->read_proc = dasd_statistics_read;
336 dasd_statistics_entry->write_proc = dasd_statistics_write;
337 dasd_statistics_entry->owner = THIS_MODULE;
341 remove_proc_entry("devices", dasd_proc_root_entry);
343 remove_proc_entry("dasd", NULL);
351 remove_proc_entry("devices", dasd_proc_root_entry);
352 remove_proc_entry("statistics", dasd_proc_root_entry);
353 remove_proc_entry("dasd", NULL);