blob: 2080ba6a69b0ea5b906c0a3bfc1c6ed639651b8b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
9 *
10 * /proc interface for the dasd driver.
11 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
Stefan Haberlandfc19f382009-03-26 15:23:49 +010014#define KMSG_COMPONENT "dasd"
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/ctype.h>
17#include <linux/seq_file.h>
18#include <linux/vmalloc.h>
Michael Holzheu66a464d2005-06-25 14:55:33 -070019#include <linux/proc_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/debug.h>
22#include <asm/uaccess.h>
23
24/* This is ugly... */
25#define PRINTK_HEADER "dasd_proc:"
26
27#include "dasd_int.h"
28
29static struct proc_dir_entry *dasd_proc_root_entry = NULL;
30static struct proc_dir_entry *dasd_devices_entry = NULL;
31static struct proc_dir_entry *dasd_statistics_entry = NULL;
32
Heiko Carstens3d621492007-07-10 11:24:17 +020033#ifdef CONFIG_DASD_PROFILE
Heiko Carstens4d284ca2007-02-05 21:18:53 +010034static char *
Linus Torvalds1da177e2005-04-16 15:20:36 -070035dasd_get_user_string(const char __user *user_buf, size_t user_len)
36{
37 char *buffer;
38
39 buffer = kmalloc(user_len + 1, GFP_KERNEL);
40 if (buffer == NULL)
41 return ERR_PTR(-ENOMEM);
42 if (copy_from_user(buffer, user_buf, user_len) != 0) {
43 kfree(buffer);
44 return ERR_PTR(-EFAULT);
45 }
46 /* got the string, now strip linefeed. */
47 if (buffer[user_len - 1] == '\n')
48 buffer[user_len - 1] = 0;
49 else
50 buffer[user_len] = 0;
51 return buffer;
52}
Heiko Carstens3d621492007-07-10 11:24:17 +020053#endif /* CONFIG_DASD_PROFILE */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55static int
56dasd_devices_show(struct seq_file *m, void *v)
57{
58 struct dasd_device *device;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010059 struct dasd_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 char *substr;
61
62 device = dasd_device_from_devindex((unsigned long) v - 1);
63 if (IS_ERR(device))
64 return 0;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010065 if (device->block)
66 block = device->block;
Stefan Weinhubera5e23832008-03-05 12:37:11 +010067 else {
68 dasd_put_device(device);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010069 return 0;
Stefan Weinhubera5e23832008-03-05 12:37:11 +010070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 /* Print device number. */
Kay Sievers2a0217d2008-10-10 21:33:09 +020072 seq_printf(m, "%s", dev_name(&device->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 /* Print discipline string. */
74 if (device != NULL && device->discipline != NULL)
75 seq_printf(m, "(%s)", device->discipline->name);
76 else
77 seq_printf(m, "(none)");
78 /* Print kdev. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010079 if (block->gdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 seq_printf(m, " at (%3d:%6d)",
Tejun Heof331c022008-09-03 09:01:48 +020081 MAJOR(disk_devt(block->gdp)),
82 MINOR(disk_devt(block->gdp)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 else
84 seq_printf(m, " at (???:??????)");
85 /* Print device name. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010086 if (block->gdp)
87 seq_printf(m, " is %-8s", block->gdp->disk_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 else
89 seq_printf(m, " is ????????");
90 /* Print devices features. */
Horst Hummelc6eb7b72005-09-03 15:57:58 -070091 substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 seq_printf(m, "%4s: ", substr);
93 /* Print device status information. */
94 switch ((device != NULL) ? device->state : -1) {
95 case -1:
96 seq_printf(m, "unknown");
97 break;
98 case DASD_STATE_NEW:
99 seq_printf(m, "new");
100 break;
101 case DASD_STATE_KNOWN:
102 seq_printf(m, "detected");
103 break;
104 case DASD_STATE_BASIC:
105 seq_printf(m, "basic");
106 break;
Horst Hummel90f00942006-03-07 21:55:39 -0800107 case DASD_STATE_UNFMT:
Horst Hummelb707dbe2006-03-09 17:33:52 -0800108 seq_printf(m, "unformatted");
Horst Hummel90f00942006-03-07 21:55:39 -0800109 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 case DASD_STATE_READY:
111 case DASD_STATE_ONLINE:
112 seq_printf(m, "active ");
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100113 if (dasd_check_blocksize(block->bp_block))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 seq_printf(m, "n/f ");
115 else
116 seq_printf(m,
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100117 "at blocksize: %d, %lld blocks, %lld MB",
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100118 block->bp_block, block->blocks,
119 ((block->bp_block >> 9) *
120 block->blocks) >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 break;
122 default:
123 seq_printf(m, "no stat");
124 break;
125 }
126 dasd_put_device(device);
127 if (dasd_probeonly)
128 seq_printf(m, "(probeonly)");
129 seq_printf(m, "\n");
130 return 0;
131}
132
133static void *dasd_devices_start(struct seq_file *m, loff_t *pos)
134{
135 if (*pos >= dasd_max_devindex)
136 return NULL;
137 return (void *)((unsigned long) *pos + 1);
138}
139
140static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos)
141{
142 ++*pos;
143 return dasd_devices_start(m, pos);
144}
145
146static void dasd_devices_stop(struct seq_file *m, void *v)
147{
148}
149
Jan Engelhardt5c81cdb2008-01-26 14:11:29 +0100150static const struct seq_operations dasd_devices_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 .start = dasd_devices_start,
152 .next = dasd_devices_next,
153 .stop = dasd_devices_stop,
154 .show = dasd_devices_show,
155};
156
157static int dasd_devices_open(struct inode *inode, struct file *file)
158{
159 return seq_open(file, &dasd_devices_seq_ops);
160}
161
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800162static const struct file_operations dasd_devices_file_ops = {
Denis V. Lunev8b594002008-04-29 01:02:20 -0700163 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 .open = dasd_devices_open,
165 .read = seq_read,
166 .llseek = seq_lseek,
167 .release = seq_release,
168};
169
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100170static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171dasd_calc_metrics(char *page, char **start, off_t off,
172 int count, int *eof, int len)
173{
174 len = (len > off) ? len - off : 0;
175 if (len > count)
176 len = count;
177 if (len < count)
178 *eof = 1;
179 *start = page + off;
180 return len;
181}
182
Heiko Carstens3d621492007-07-10 11:24:17 +0200183#ifdef CONFIG_DASD_PROFILE
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100184static char *
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100185dasd_statistics_array(char *str, unsigned int *array, int factor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
187 int i;
188
189 for (i = 0; i < 32; i++) {
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100190 str += sprintf(str, "%7d ", array[i] / factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if (i == 15)
192 str += sprintf(str, "\n");
193 }
194 str += sprintf(str,"\n");
195 return str;
196}
Heiko Carstens3d621492007-07-10 11:24:17 +0200197#endif /* CONFIG_DASD_PROFILE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199static int
200dasd_statistics_read(char *page, char **start, off_t off,
201 int count, int *eof, void *data)
202{
203 unsigned long len;
204#ifdef CONFIG_DASD_PROFILE
205 struct dasd_profile_info_t *prof;
206 char *str;
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100207 int factor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
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);
215 }
216
217 prof = &dasd_global_profile;
218 /* prevent couter 'overflow' on output */
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100219 for (factor = 1; (prof->dasd_io_reqs / factor) > 9999999;
220 factor *= 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 str = page;
223 str += sprintf(str, "%d dasd I/O requests\n", prof->dasd_io_reqs);
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100224 str += sprintf(str, "with %u sectors(512B each)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 prof->dasd_io_sects);
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100226 str += sprintf(str, "Scale Factor is %d\n", factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 str += sprintf(str,
228 " __<4 ___8 __16 __32 __64 _128 "
229 " _256 _512 __1k __2k __4k __8k "
230 " _16k _32k _64k 128k\n");
231 str += sprintf(str,
232 " _256 _512 __1M __2M __4M __8M "
233 " _16M _32M _64M 128M 256M 512M "
234 " __1G __2G __4G " " _>4G\n");
235
236 str += sprintf(str, "Histogram of sizes (512B secs)\n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100237 str = dasd_statistics_array(str, prof->dasd_io_secs, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 str += sprintf(str, "Histogram of I/O times (microseconds)\n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100239 str = dasd_statistics_array(str, prof->dasd_io_times, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 str += sprintf(str, "Histogram of I/O times per sector\n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100241 str = dasd_statistics_array(str, prof->dasd_io_timps, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 str += sprintf(str, "Histogram of I/O time till ssch\n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100243 str = dasd_statistics_array(str, prof->dasd_io_time1, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 str += sprintf(str, "Histogram of I/O time between ssch and irq\n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100245 str = dasd_statistics_array(str, prof->dasd_io_time2, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 str += sprintf(str, "Histogram of I/O time between ssch "
247 "and irq per sector\n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100248 str = dasd_statistics_array(str, prof->dasd_io_time2ps, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 str += sprintf(str, "Histogram of I/O time between irq and end\n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100250 str = dasd_statistics_array(str, prof->dasd_io_time3, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 str += sprintf(str, "# of req in chanq at enqueuing (1..32) \n");
Stefan Haberland2bf373b2008-12-25 13:38:51 +0100252 str = dasd_statistics_array(str, prof->dasd_io_nr_req, factor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 len = str - page;
254#else
255 len = sprintf(page, "Statistics are not activated in this kernel\n");
256#endif
257 return dasd_calc_metrics(page, start, off, count, eof, len);
258}
259
260static int
261dasd_statistics_write(struct file *file, const char __user *user_buf,
262 unsigned long user_len, void *data)
263{
264#ifdef CONFIG_DASD_PROFILE
265 char *buffer, *str;
266
267 if (user_len > 65536)
268 user_len = 65536;
269 buffer = dasd_get_user_string(user_buf, user_len);
270 if (IS_ERR(buffer))
271 return PTR_ERR(buffer);
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100272 DBF_EVENT(DBF_DEBUG, "/proc/dasd/statictics: '%s'\n", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
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;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100282 pr_info("The statistics feature has been switched "
283 "on\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 } 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;
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100289 pr_info("The statistics feature has been switched "
290 "off\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 } else
292 goto out_error;
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));
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100297 pr_info("The statistics have been reset\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 } else
299 goto out_error;
300 kfree(buffer);
301 return user_len;
302out_error:
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100303 pr_warning("%s is not a supported value for /proc/dasd/statistics\n",
304 str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 kfree(buffer);
306 return -EINVAL;
307#else
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100308 pr_warning("/proc/dasd/statistics: is not activated in this kernel\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return user_len;
310#endif /* CONFIG_DASD_PROFILE */
311}
312
Horst Hummel7220fe82006-04-10 22:53:48 -0700313/*
314 * Create dasd proc-fs entries.
315 * In case creation failed, cleanup and return -ENOENT.
316 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317int
318dasd_proc_init(void)
319{
Alexey Dobriyanc74c1202008-04-29 01:01:44 -0700320 dasd_proc_root_entry = proc_mkdir("dasd", NULL);
Horst Hummel7220fe82006-04-10 22:53:48 -0700321 if (!dasd_proc_root_entry)
322 goto out_nodasd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 dasd_proc_root_entry->owner = THIS_MODULE;
Denis V. Lunev8b594002008-04-29 01:02:20 -0700324 dasd_devices_entry = proc_create("devices",
325 S_IFREG | S_IRUGO | S_IWUSR,
326 dasd_proc_root_entry,
327 &dasd_devices_file_ops);
Horst Hummel7220fe82006-04-10 22:53:48 -0700328 if (!dasd_devices_entry)
329 goto out_nodevices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 dasd_statistics_entry = create_proc_entry("statistics",
331 S_IFREG | S_IRUGO | S_IWUSR,
332 dasd_proc_root_entry);
Horst Hummel7220fe82006-04-10 22:53:48 -0700333 if (!dasd_statistics_entry)
334 goto out_nostatistics;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 dasd_statistics_entry->read_proc = dasd_statistics_read;
336 dasd_statistics_entry->write_proc = dasd_statistics_write;
337 dasd_statistics_entry->owner = THIS_MODULE;
338 return 0;
Horst Hummel7220fe82006-04-10 22:53:48 -0700339
340 out_nostatistics:
341 remove_proc_entry("devices", dasd_proc_root_entry);
342 out_nodevices:
Alexey Dobriyanc74c1202008-04-29 01:01:44 -0700343 remove_proc_entry("dasd", NULL);
Horst Hummel7220fe82006-04-10 22:53:48 -0700344 out_nodasd:
345 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
348void
349dasd_proc_exit(void)
350{
351 remove_proc_entry("devices", dasd_proc_root_entry);
352 remove_proc_entry("statistics", dasd_proc_root_entry);
Alexey Dobriyanc74c1202008-04-29 01:01:44 -0700353 remove_proc_entry("dasd", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}