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.
15 #include <linux/config.h>
16 #include <linux/ctype.h>
17 #include <linux/seq_file.h>
18 #include <linux/vmalloc.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
= test_bit(DASD_FLAG_RO
, &device
->flags
) ? "(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_READY
:
97 case DASD_STATE_ONLINE
:
98 seq_printf(m
, "active ");
99 if (dasd_check_blocksize(device
->bp_block
))
100 seq_printf(m
, "n/f ");
103 "at blocksize: %d, %ld blocks, %ld MB",
104 device
->bp_block
, device
->blocks
,
105 ((device
->bp_block
>> 9) *
106 device
->blocks
) >> 11);
109 seq_printf(m
, "no stat");
112 dasd_put_device(device
);
114 seq_printf(m
, "(probeonly)");
119 static void *dasd_devices_start(struct seq_file
*m
, loff_t
*pos
)
121 if (*pos
>= dasd_max_devindex
)
123 return (void *)((unsigned long) *pos
+ 1);
126 static void *dasd_devices_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
129 return dasd_devices_start(m
, pos
);
132 static void dasd_devices_stop(struct seq_file
*m
, void *v
)
136 static struct seq_operations dasd_devices_seq_ops
= {
137 .start
= dasd_devices_start
,
138 .next
= dasd_devices_next
,
139 .stop
= dasd_devices_stop
,
140 .show
= dasd_devices_show
,
143 static int dasd_devices_open(struct inode
*inode
, struct file
*file
)
145 return seq_open(file
, &dasd_devices_seq_ops
);
148 static struct file_operations dasd_devices_file_ops
= {
149 .open
= dasd_devices_open
,
152 .release
= seq_release
,
156 dasd_calc_metrics(char *page
, char **start
, off_t off
,
157 int count
, int *eof
, int len
)
159 len
= (len
> off
) ? len
- off
: 0;
169 dasd_statistics_array(char *str
, int *array
, int shift
)
173 for (i
= 0; i
< 32; i
++) {
174 str
+= sprintf(str
, "%7d ", array
[i
] >> shift
);
176 str
+= sprintf(str
, "\n");
178 str
+= sprintf(str
,"\n");
183 dasd_statistics_read(char *page
, char **start
, off_t off
,
184 int count
, int *eof
, void *data
)
187 #ifdef CONFIG_DASD_PROFILE
188 struct dasd_profile_info_t
*prof
;
192 /* check for active profiling */
193 if (dasd_profile_level
== DASD_PROFILE_OFF
) {
194 len
= sprintf(page
, "Statistics are off - they might be "
195 "switched on using 'echo set on > "
196 "/proc/dasd/statistics'\n");
197 return dasd_calc_metrics(page
, start
, off
, count
, eof
, len
);
200 prof
= &dasd_global_profile
;
201 /* prevent couter 'overflow' on output */
202 for (shift
= 0; (prof
->dasd_io_reqs
>> shift
) > 9999999; shift
++);
205 str
+= sprintf(str
, "%d dasd I/O requests\n", prof
->dasd_io_reqs
);
206 str
+= sprintf(str
, "with %d sectors(512B each)\n",
207 prof
->dasd_io_sects
);
209 " __<4 ___8 __16 __32 __64 _128 "
210 " _256 _512 __1k __2k __4k __8k "
211 " _16k _32k _64k 128k\n");
213 " _256 _512 __1M __2M __4M __8M "
214 " _16M _32M _64M 128M 256M 512M "
215 " __1G __2G __4G " " _>4G\n");
217 str
+= sprintf(str
, "Histogram of sizes (512B secs)\n");
218 str
= dasd_statistics_array(str
, prof
->dasd_io_secs
, shift
);
219 str
+= sprintf(str
, "Histogram of I/O times (microseconds)\n");
220 str
= dasd_statistics_array(str
, prof
->dasd_io_times
, shift
);
221 str
+= sprintf(str
, "Histogram of I/O times per sector\n");
222 str
= dasd_statistics_array(str
, prof
->dasd_io_timps
, shift
);
223 str
+= sprintf(str
, "Histogram of I/O time till ssch\n");
224 str
= dasd_statistics_array(str
, prof
->dasd_io_time1
, shift
);
225 str
+= sprintf(str
, "Histogram of I/O time between ssch and irq\n");
226 str
= dasd_statistics_array(str
, prof
->dasd_io_time2
, shift
);
227 str
+= sprintf(str
, "Histogram of I/O time between ssch "
228 "and irq per sector\n");
229 str
= dasd_statistics_array(str
, prof
->dasd_io_time2ps
, shift
);
230 str
+= sprintf(str
, "Histogram of I/O time between irq and end\n");
231 str
= dasd_statistics_array(str
, prof
->dasd_io_time3
, shift
);
232 str
+= sprintf(str
, "# of req in chanq at enqueuing (1..32) \n");
233 str
= dasd_statistics_array(str
, prof
->dasd_io_nr_req
, shift
);
236 len
= sprintf(page
, "Statistics are not activated in this kernel\n");
238 return dasd_calc_metrics(page
, start
, off
, count
, eof
, len
);
242 dasd_statistics_write(struct file
*file
, const char __user
*user_buf
,
243 unsigned long user_len
, void *data
)
245 #ifdef CONFIG_DASD_PROFILE
248 if (user_len
> 65536)
250 buffer
= dasd_get_user_string(user_buf
, user_len
);
252 return PTR_ERR(buffer
);
253 MESSAGE_LOG(KERN_INFO
, "/proc/dasd/statictics: '%s'", buffer
);
255 /* check for valid verbs */
256 for (str
= buffer
; isspace(*str
); str
++);
257 if (strncmp(str
, "set", 3) == 0 && isspace(str
[3])) {
258 /* 'set xxx' was given */
259 for (str
= str
+ 4; isspace(*str
); str
++);
260 if (strcmp(str
, "on") == 0) {
261 /* switch on statistics profiling */
262 dasd_profile_level
= DASD_PROFILE_ON
;
263 MESSAGE(KERN_INFO
, "%s", "Statistics switched on");
264 } else if (strcmp(str
, "off") == 0) {
265 /* switch off and reset statistics profiling */
266 memset(&dasd_global_profile
,
267 0, sizeof (struct dasd_profile_info_t
));
268 dasd_profile_level
= DASD_PROFILE_OFF
;
269 MESSAGE(KERN_INFO
, "%s", "Statistics switched off");
272 } else if (strncmp(str
, "reset", 5) == 0) {
273 /* reset the statistics */
274 memset(&dasd_global_profile
, 0,
275 sizeof (struct dasd_profile_info_t
));
276 MESSAGE(KERN_INFO
, "%s", "Statistics reset");
282 MESSAGE(KERN_WARNING
, "%s",
283 "/proc/dasd/statistics: only 'set on', 'set off' "
284 "and 'reset' are supported verbs");
288 MESSAGE(KERN_WARNING
, "%s",
289 "/proc/dasd/statistics: is not activated in this kernel");
291 #endif /* CONFIG_DASD_PROFILE */
297 dasd_proc_root_entry
= proc_mkdir("dasd", &proc_root
);
298 dasd_proc_root_entry
->owner
= THIS_MODULE
;
299 dasd_devices_entry
= create_proc_entry("devices",
300 S_IFREG
| S_IRUGO
| S_IWUSR
,
301 dasd_proc_root_entry
);
302 dasd_devices_entry
->proc_fops
= &dasd_devices_file_ops
;
303 dasd_devices_entry
->owner
= THIS_MODULE
;
304 dasd_statistics_entry
= create_proc_entry("statistics",
305 S_IFREG
| S_IRUGO
| S_IWUSR
,
306 dasd_proc_root_entry
);
307 dasd_statistics_entry
->read_proc
= dasd_statistics_read
;
308 dasd_statistics_entry
->write_proc
= dasd_statistics_write
;
309 dasd_statistics_entry
->owner
= THIS_MODULE
;
316 remove_proc_entry("devices", dasd_proc_root_entry
);
317 remove_proc_entry("statistics", dasd_proc_root_entry
);
318 remove_proc_entry("dasd", &proc_root
);