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>
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
;
34 dasd_get_user_string(const char __user
*user_buf
, size_t user_len
)
38 buffer
= kmalloc(user_len
+ 1, GFP_KERNEL
);
40 return ERR_PTR(-ENOMEM
);
41 if (copy_from_user(buffer
, user_buf
, user_len
) != 0) {
43 return ERR_PTR(-EFAULT
);
45 /* got the string, now strip linefeed. */
46 if (buffer
[user_len
- 1] == '\n')
47 buffer
[user_len
- 1] = 0;
54 dasd_devices_show(struct seq_file
*m
, void *v
)
56 struct dasd_device
*device
;
59 device
= dasd_device_from_devindex((unsigned long) v
- 1);
62 /* Print device number. */
63 seq_printf(m
, "%s", device
->cdev
->dev
.bus_id
);
64 /* Print discipline string. */
65 if (device
!= NULL
&& device
->discipline
!= NULL
)
66 seq_printf(m
, "(%s)", device
->discipline
->name
);
68 seq_printf(m
, "(none)");
71 seq_printf(m
, " at (%3d:%6d)",
72 device
->gdp
->major
, device
->gdp
->first_minor
);
74 seq_printf(m
, " at (???:??????)");
75 /* Print device name. */
77 seq_printf(m
, " is %-8s", device
->gdp
->disk_name
);
79 seq_printf(m
, " is ????????");
80 /* Print devices features. */
81 substr
= (device
->features
& DASD_FEATURE_READONLY
) ? "(ro)" : " ";
82 seq_printf(m
, "%4s: ", substr
);
83 /* Print device status information. */
84 switch ((device
!= NULL
) ? device
->state
: -1) {
86 seq_printf(m
, "unknown");
91 case DASD_STATE_KNOWN
:
92 seq_printf(m
, "detected");
94 case DASD_STATE_BASIC
:
95 seq_printf(m
, "basic");
97 case DASD_STATE_READY
:
98 case DASD_STATE_ONLINE
:
99 seq_printf(m
, "active ");
100 if (dasd_check_blocksize(device
->bp_block
))
101 seq_printf(m
, "n/f ");
104 "at blocksize: %d, %ld blocks, %ld MB",
105 device
->bp_block
, device
->blocks
,
106 ((device
->bp_block
>> 9) *
107 device
->blocks
) >> 11);
110 seq_printf(m
, "no stat");
113 dasd_put_device(device
);
115 seq_printf(m
, "(probeonly)");
120 static void *dasd_devices_start(struct seq_file
*m
, loff_t
*pos
)
122 if (*pos
>= dasd_max_devindex
)
124 return (void *)((unsigned long) *pos
+ 1);
127 static void *dasd_devices_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
130 return dasd_devices_start(m
, pos
);
133 static void dasd_devices_stop(struct seq_file
*m
, void *v
)
137 static struct seq_operations dasd_devices_seq_ops
= {
138 .start
= dasd_devices_start
,
139 .next
= dasd_devices_next
,
140 .stop
= dasd_devices_stop
,
141 .show
= dasd_devices_show
,
144 static int dasd_devices_open(struct inode
*inode
, struct file
*file
)
146 return seq_open(file
, &dasd_devices_seq_ops
);
149 static struct file_operations dasd_devices_file_ops
= {
150 .open
= dasd_devices_open
,
153 .release
= seq_release
,
157 dasd_calc_metrics(char *page
, char **start
, off_t off
,
158 int count
, int *eof
, int len
)
160 len
= (len
> off
) ? len
- off
: 0;
170 dasd_statistics_array(char *str
, int *array
, int shift
)
174 for (i
= 0; i
< 32; i
++) {
175 str
+= sprintf(str
, "%7d ", array
[i
] >> shift
);
177 str
+= sprintf(str
, "\n");
179 str
+= sprintf(str
,"\n");
184 dasd_statistics_read(char *page
, char **start
, off_t off
,
185 int count
, int *eof
, void *data
)
188 #ifdef CONFIG_DASD_PROFILE
189 struct dasd_profile_info_t
*prof
;
193 /* check for active profiling */
194 if (dasd_profile_level
== DASD_PROFILE_OFF
) {
195 len
= sprintf(page
, "Statistics are off - they might be "
196 "switched on using 'echo set on > "
197 "/proc/dasd/statistics'\n");
198 return dasd_calc_metrics(page
, start
, off
, count
, eof
, len
);
201 prof
= &dasd_global_profile
;
202 /* prevent couter 'overflow' on output */
203 for (shift
= 0; (prof
->dasd_io_reqs
>> shift
) > 9999999; shift
++);
206 str
+= sprintf(str
, "%d dasd I/O requests\n", prof
->dasd_io_reqs
);
207 str
+= sprintf(str
, "with %d sectors(512B each)\n",
208 prof
->dasd_io_sects
);
210 " __<4 ___8 __16 __32 __64 _128 "
211 " _256 _512 __1k __2k __4k __8k "
212 " _16k _32k _64k 128k\n");
214 " _256 _512 __1M __2M __4M __8M "
215 " _16M _32M _64M 128M 256M 512M "
216 " __1G __2G __4G " " _>4G\n");
218 str
+= sprintf(str
, "Histogram of sizes (512B secs)\n");
219 str
= dasd_statistics_array(str
, prof
->dasd_io_secs
, shift
);
220 str
+= sprintf(str
, "Histogram of I/O times (microseconds)\n");
221 str
= dasd_statistics_array(str
, prof
->dasd_io_times
, shift
);
222 str
+= sprintf(str
, "Histogram of I/O times per sector\n");
223 str
= dasd_statistics_array(str
, prof
->dasd_io_timps
, shift
);
224 str
+= sprintf(str
, "Histogram of I/O time till ssch\n");
225 str
= dasd_statistics_array(str
, prof
->dasd_io_time1
, shift
);
226 str
+= sprintf(str
, "Histogram of I/O time between ssch and irq\n");
227 str
= dasd_statistics_array(str
, prof
->dasd_io_time2
, shift
);
228 str
+= sprintf(str
, "Histogram of I/O time between ssch "
229 "and irq per sector\n");
230 str
= dasd_statistics_array(str
, prof
->dasd_io_time2ps
, shift
);
231 str
+= sprintf(str
, "Histogram of I/O time between irq and end\n");
232 str
= dasd_statistics_array(str
, prof
->dasd_io_time3
, shift
);
233 str
+= sprintf(str
, "# of req in chanq at enqueuing (1..32) \n");
234 str
= dasd_statistics_array(str
, prof
->dasd_io_nr_req
, shift
);
237 len
= sprintf(page
, "Statistics are not activated in this kernel\n");
239 return dasd_calc_metrics(page
, start
, off
, count
, eof
, len
);
243 dasd_statistics_write(struct file
*file
, const char __user
*user_buf
,
244 unsigned long user_len
, void *data
)
246 #ifdef CONFIG_DASD_PROFILE
249 if (user_len
> 65536)
251 buffer
= dasd_get_user_string(user_buf
, user_len
);
253 return PTR_ERR(buffer
);
254 MESSAGE_LOG(KERN_INFO
, "/proc/dasd/statictics: '%s'", buffer
);
256 /* check for valid verbs */
257 for (str
= buffer
; isspace(*str
); str
++);
258 if (strncmp(str
, "set", 3) == 0 && isspace(str
[3])) {
259 /* 'set xxx' was given */
260 for (str
= str
+ 4; isspace(*str
); str
++);
261 if (strcmp(str
, "on") == 0) {
262 /* switch on statistics profiling */
263 dasd_profile_level
= DASD_PROFILE_ON
;
264 MESSAGE(KERN_INFO
, "%s", "Statistics switched on");
265 } else if (strcmp(str
, "off") == 0) {
266 /* switch off and reset statistics profiling */
267 memset(&dasd_global_profile
,
268 0, sizeof (struct dasd_profile_info_t
));
269 dasd_profile_level
= DASD_PROFILE_OFF
;
270 MESSAGE(KERN_INFO
, "%s", "Statistics switched off");
273 } else if (strncmp(str
, "reset", 5) == 0) {
274 /* reset the statistics */
275 memset(&dasd_global_profile
, 0,
276 sizeof (struct dasd_profile_info_t
));
277 MESSAGE(KERN_INFO
, "%s", "Statistics reset");
283 MESSAGE(KERN_WARNING
, "%s",
284 "/proc/dasd/statistics: only 'set on', 'set off' "
285 "and 'reset' are supported verbs");
289 MESSAGE(KERN_WARNING
, "%s",
290 "/proc/dasd/statistics: is not activated in this kernel");
292 #endif /* CONFIG_DASD_PROFILE */
298 dasd_proc_root_entry
= proc_mkdir("dasd", &proc_root
);
299 dasd_proc_root_entry
->owner
= THIS_MODULE
;
300 dasd_devices_entry
= create_proc_entry("devices",
301 S_IFREG
| S_IRUGO
| S_IWUSR
,
302 dasd_proc_root_entry
);
303 dasd_devices_entry
->proc_fops
= &dasd_devices_file_ops
;
304 dasd_devices_entry
->owner
= THIS_MODULE
;
305 dasd_statistics_entry
= create_proc_entry("statistics",
306 S_IFREG
| S_IRUGO
| S_IWUSR
,
307 dasd_proc_root_entry
);
308 dasd_statistics_entry
->read_proc
= dasd_statistics_read
;
309 dasd_statistics_entry
->write_proc
= dasd_statistics_write
;
310 dasd_statistics_entry
->owner
= THIS_MODULE
;
317 remove_proc_entry("devices", dasd_proc_root_entry
);
318 remove_proc_entry("statistics", dasd_proc_root_entry
);
319 remove_proc_entry("dasd", &proc_root
);