]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | * | |
1da177e4 LT |
12 | */ |
13 | ||
14 | #include <linux/config.h> | |
15 | #include <linux/ctype.h> | |
16 | #include <linux/seq_file.h> | |
17 | #include <linux/vmalloc.h> | |
66a464db | 18 | #include <linux/proc_fs.h> |
1da177e4 LT |
19 | |
20 | #include <asm/debug.h> | |
21 | #include <asm/uaccess.h> | |
22 | ||
23 | /* This is ugly... */ | |
24 | #define PRINTK_HEADER "dasd_proc:" | |
25 | ||
26 | #include "dasd_int.h" | |
27 | ||
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; | |
31 | ||
32 | static inline char * | |
33 | dasd_get_user_string(const char __user *user_buf, size_t user_len) | |
34 | { | |
35 | char *buffer; | |
36 | ||
37 | buffer = kmalloc(user_len + 1, GFP_KERNEL); | |
38 | if (buffer == NULL) | |
39 | return ERR_PTR(-ENOMEM); | |
40 | if (copy_from_user(buffer, user_buf, user_len) != 0) { | |
41 | kfree(buffer); | |
42 | return ERR_PTR(-EFAULT); | |
43 | } | |
44 | /* got the string, now strip linefeed. */ | |
45 | if (buffer[user_len - 1] == '\n') | |
46 | buffer[user_len - 1] = 0; | |
47 | else | |
48 | buffer[user_len] = 0; | |
49 | return buffer; | |
50 | } | |
51 | ||
52 | static int | |
53 | dasd_devices_show(struct seq_file *m, void *v) | |
54 | { | |
55 | struct dasd_device *device; | |
56 | char *substr; | |
57 | ||
58 | device = dasd_device_from_devindex((unsigned long) v - 1); | |
59 | if (IS_ERR(device)) | |
60 | return 0; | |
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); | |
66 | else | |
67 | seq_printf(m, "(none)"); | |
68 | /* Print kdev. */ | |
69 | if (device->gdp) | |
70 | seq_printf(m, " at (%3d:%6d)", | |
71 | device->gdp->major, device->gdp->first_minor); | |
72 | else | |
73 | seq_printf(m, " at (???:??????)"); | |
74 | /* Print device name. */ | |
75 | if (device->gdp) | |
76 | seq_printf(m, " is %-8s", device->gdp->disk_name); | |
77 | else | |
78 | seq_printf(m, " is ????????"); | |
79 | /* Print devices features. */ | |
c6eb7b77 | 80 | substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " "; |
1da177e4 LT |
81 | seq_printf(m, "%4s: ", substr); |
82 | /* Print device status information. */ | |
83 | switch ((device != NULL) ? device->state : -1) { | |
84 | case -1: | |
85 | seq_printf(m, "unknown"); | |
86 | break; | |
87 | case DASD_STATE_NEW: | |
88 | seq_printf(m, "new"); | |
89 | break; | |
90 | case DASD_STATE_KNOWN: | |
91 | seq_printf(m, "detected"); | |
92 | break; | |
93 | case DASD_STATE_BASIC: | |
94 | seq_printf(m, "basic"); | |
95 | break; | |
90f0094d HH |
96 | case DASD_STATE_UNFMT: |
97 | seq_printf(m, "unnformatted"); | |
98 | break; | |
1da177e4 LT |
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 "); | |
104 | else | |
105 | seq_printf(m, | |
106 | "at blocksize: %d, %ld blocks, %ld MB", | |
107 | device->bp_block, device->blocks, | |
108 | ((device->bp_block >> 9) * | |
109 | device->blocks) >> 11); | |
110 | break; | |
111 | default: | |
112 | seq_printf(m, "no stat"); | |
113 | break; | |
114 | } | |
115 | dasd_put_device(device); | |
116 | if (dasd_probeonly) | |
117 | seq_printf(m, "(probeonly)"); | |
118 | seq_printf(m, "\n"); | |
119 | return 0; | |
120 | } | |
121 | ||
122 | static void *dasd_devices_start(struct seq_file *m, loff_t *pos) | |
123 | { | |
124 | if (*pos >= dasd_max_devindex) | |
125 | return NULL; | |
126 | return (void *)((unsigned long) *pos + 1); | |
127 | } | |
128 | ||
129 | static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos) | |
130 | { | |
131 | ++*pos; | |
132 | return dasd_devices_start(m, pos); | |
133 | } | |
134 | ||
135 | static void dasd_devices_stop(struct seq_file *m, void *v) | |
136 | { | |
137 | } | |
138 | ||
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, | |
144 | }; | |
145 | ||
146 | static int dasd_devices_open(struct inode *inode, struct file *file) | |
147 | { | |
148 | return seq_open(file, &dasd_devices_seq_ops); | |
149 | } | |
150 | ||
151 | static struct file_operations dasd_devices_file_ops = { | |
152 | .open = dasd_devices_open, | |
153 | .read = seq_read, | |
154 | .llseek = seq_lseek, | |
155 | .release = seq_release, | |
156 | }; | |
157 | ||
158 | static inline int | |
159 | dasd_calc_metrics(char *page, char **start, off_t off, | |
160 | int count, int *eof, int len) | |
161 | { | |
162 | len = (len > off) ? len - off : 0; | |
163 | if (len > count) | |
164 | len = count; | |
165 | if (len < count) | |
166 | *eof = 1; | |
167 | *start = page + off; | |
168 | return len; | |
169 | } | |
170 | ||
171 | static inline char * | |
172 | dasd_statistics_array(char *str, int *array, int shift) | |
173 | { | |
174 | int i; | |
175 | ||
176 | for (i = 0; i < 32; i++) { | |
177 | str += sprintf(str, "%7d ", array[i] >> shift); | |
178 | if (i == 15) | |
179 | str += sprintf(str, "\n"); | |
180 | } | |
181 | str += sprintf(str,"\n"); | |
182 | return str; | |
183 | } | |
184 | ||
185 | static int | |
186 | dasd_statistics_read(char *page, char **start, off_t off, | |
187 | int count, int *eof, void *data) | |
188 | { | |
189 | unsigned long len; | |
190 | #ifdef CONFIG_DASD_PROFILE | |
191 | struct dasd_profile_info_t *prof; | |
192 | char *str; | |
193 | int shift; | |
194 | ||
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); | |
201 | } | |
202 | ||
203 | prof = &dasd_global_profile; | |
204 | /* prevent couter 'overflow' on output */ | |
205 | for (shift = 0; (prof->dasd_io_reqs >> shift) > 9999999; shift++); | |
206 | ||
207 | str = page; | |
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); | |
211 | str += sprintf(str, | |
212 | " __<4 ___8 __16 __32 __64 _128 " | |
213 | " _256 _512 __1k __2k __4k __8k " | |
214 | " _16k _32k _64k 128k\n"); | |
215 | str += sprintf(str, | |
216 | " _256 _512 __1M __2M __4M __8M " | |
217 | " _16M _32M _64M 128M 256M 512M " | |
218 | " __1G __2G __4G " " _>4G\n"); | |
219 | ||
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); | |
237 | len = str - page; | |
238 | #else | |
239 | len = sprintf(page, "Statistics are not activated in this kernel\n"); | |
240 | #endif | |
241 | return dasd_calc_metrics(page, start, off, count, eof, len); | |
242 | } | |
243 | ||
244 | static int | |
245 | dasd_statistics_write(struct file *file, const char __user *user_buf, | |
246 | unsigned long user_len, void *data) | |
247 | { | |
248 | #ifdef CONFIG_DASD_PROFILE | |
249 | char *buffer, *str; | |
250 | ||
251 | if (user_len > 65536) | |
252 | user_len = 65536; | |
253 | buffer = dasd_get_user_string(user_buf, user_len); | |
254 | if (IS_ERR(buffer)) | |
255 | return PTR_ERR(buffer); | |
256 | MESSAGE_LOG(KERN_INFO, "/proc/dasd/statictics: '%s'", buffer); | |
257 | ||
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"); | |
273 | } else | |
274 | goto out_error; | |
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"); | |
280 | } else | |
281 | goto out_error; | |
282 | kfree(buffer); | |
283 | return user_len; | |
284 | out_error: | |
285 | MESSAGE(KERN_WARNING, "%s", | |
286 | "/proc/dasd/statistics: only 'set on', 'set off' " | |
287 | "and 'reset' are supported verbs"); | |
288 | kfree(buffer); | |
289 | return -EINVAL; | |
290 | #else | |
291 | MESSAGE(KERN_WARNING, "%s", | |
292 | "/proc/dasd/statistics: is not activated in this kernel"); | |
293 | return user_len; | |
294 | #endif /* CONFIG_DASD_PROFILE */ | |
295 | } | |
296 | ||
297 | int | |
298 | dasd_proc_init(void) | |
299 | { | |
300 | dasd_proc_root_entry = proc_mkdir("dasd", &proc_root); | |
301 | dasd_proc_root_entry->owner = THIS_MODULE; | |
302 | dasd_devices_entry = create_proc_entry("devices", | |
303 | S_IFREG | S_IRUGO | S_IWUSR, | |
304 | dasd_proc_root_entry); | |
305 | dasd_devices_entry->proc_fops = &dasd_devices_file_ops; | |
306 | dasd_devices_entry->owner = THIS_MODULE; | |
307 | dasd_statistics_entry = create_proc_entry("statistics", | |
308 | S_IFREG | S_IRUGO | S_IWUSR, | |
309 | dasd_proc_root_entry); | |
310 | dasd_statistics_entry->read_proc = dasd_statistics_read; | |
311 | dasd_statistics_entry->write_proc = dasd_statistics_write; | |
312 | dasd_statistics_entry->owner = THIS_MODULE; | |
313 | return 0; | |
314 | } | |
315 | ||
316 | void | |
317 | dasd_proc_exit(void) | |
318 | { | |
319 | remove_proc_entry("devices", dasd_proc_root_entry); | |
320 | remove_proc_entry("statistics", dasd_proc_root_entry); | |
321 | remove_proc_entry("dasd", &proc_root); | |
322 | } |