dasd_proc.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. *
  12. * $Revision: 1.33 $
  13. */
  14. #include <linux/config.h>
  15. #include <linux/ctype.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/proc_fs.h>
  19. #include <asm/debug.h>
  20. #include <asm/uaccess.h>
  21. /* This is ugly... */
  22. #define PRINTK_HEADER "dasd_proc:"
  23. #include "dasd_int.h"
  24. static struct proc_dir_entry *dasd_proc_root_entry = NULL;
  25. static struct proc_dir_entry *dasd_devices_entry = NULL;
  26. static struct proc_dir_entry *dasd_statistics_entry = NULL;
  27. static inline char *
  28. dasd_get_user_string(const char __user *user_buf, size_t user_len)
  29. {
  30. char *buffer;
  31. buffer = kmalloc(user_len + 1, GFP_KERNEL);
  32. if (buffer == NULL)
  33. return ERR_PTR(-ENOMEM);
  34. if (copy_from_user(buffer, user_buf, user_len) != 0) {
  35. kfree(buffer);
  36. return ERR_PTR(-EFAULT);
  37. }
  38. /* got the string, now strip linefeed. */
  39. if (buffer[user_len - 1] == '\n')
  40. buffer[user_len - 1] = 0;
  41. else
  42. buffer[user_len] = 0;
  43. return buffer;
  44. }
  45. static int
  46. dasd_devices_show(struct seq_file *m, void *v)
  47. {
  48. struct dasd_device *device;
  49. char *substr;
  50. device = dasd_device_from_devindex((unsigned long) v - 1);
  51. if (IS_ERR(device))
  52. return 0;
  53. /* Print device number. */
  54. seq_printf(m, "%s", device->cdev->dev.bus_id);
  55. /* Print discipline string. */
  56. if (device != NULL && device->discipline != NULL)
  57. seq_printf(m, "(%s)", device->discipline->name);
  58. else
  59. seq_printf(m, "(none)");
  60. /* Print kdev. */
  61. if (device->gdp)
  62. seq_printf(m, " at (%3d:%6d)",
  63. device->gdp->major, device->gdp->first_minor);
  64. else
  65. seq_printf(m, " at (???:??????)");
  66. /* Print device name. */
  67. if (device->gdp)
  68. seq_printf(m, " is %-8s", device->gdp->disk_name);
  69. else
  70. seq_printf(m, " is ????????");
  71. /* Print devices features. */
  72. substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
  73. seq_printf(m, "%4s: ", substr);
  74. /* Print device status information. */
  75. switch ((device != NULL) ? device->state : -1) {
  76. case -1:
  77. seq_printf(m, "unknown");
  78. break;
  79. case DASD_STATE_NEW:
  80. seq_printf(m, "new");
  81. break;
  82. case DASD_STATE_KNOWN:
  83. seq_printf(m, "detected");
  84. break;
  85. case DASD_STATE_BASIC:
  86. seq_printf(m, "basic");
  87. break;
  88. case DASD_STATE_READY:
  89. case DASD_STATE_ONLINE:
  90. seq_printf(m, "active ");
  91. if (dasd_check_blocksize(device->bp_block))
  92. seq_printf(m, "n/f ");
  93. else
  94. seq_printf(m,
  95. "at blocksize: %d, %ld blocks, %ld MB",
  96. device->bp_block, device->blocks,
  97. ((device->bp_block >> 9) *
  98. device->blocks) >> 11);
  99. break;
  100. default:
  101. seq_printf(m, "no stat");
  102. break;
  103. }
  104. dasd_put_device(device);
  105. if (dasd_probeonly)
  106. seq_printf(m, "(probeonly)");
  107. seq_printf(m, "\n");
  108. return 0;
  109. }
  110. static void *dasd_devices_start(struct seq_file *m, loff_t *pos)
  111. {
  112. if (*pos >= dasd_max_devindex)
  113. return NULL;
  114. return (void *)((unsigned long) *pos + 1);
  115. }
  116. static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos)
  117. {
  118. ++*pos;
  119. return dasd_devices_start(m, pos);
  120. }
  121. static void dasd_devices_stop(struct seq_file *m, void *v)
  122. {
  123. }
  124. static struct seq_operations dasd_devices_seq_ops = {
  125. .start = dasd_devices_start,
  126. .next = dasd_devices_next,
  127. .stop = dasd_devices_stop,
  128. .show = dasd_devices_show,
  129. };
  130. static int dasd_devices_open(struct inode *inode, struct file *file)
  131. {
  132. return seq_open(file, &dasd_devices_seq_ops);
  133. }
  134. static struct file_operations dasd_devices_file_ops = {
  135. .open = dasd_devices_open,
  136. .read = seq_read,
  137. .llseek = seq_lseek,
  138. .release = seq_release,
  139. };
  140. static inline int
  141. dasd_calc_metrics(char *page, char **start, off_t off,
  142. int count, int *eof, int len)
  143. {
  144. len = (len > off) ? len - off : 0;
  145. if (len > count)
  146. len = count;
  147. if (len < count)
  148. *eof = 1;
  149. *start = page + off;
  150. return len;
  151. }
  152. static inline char *
  153. dasd_statistics_array(char *str, int *array, int shift)
  154. {
  155. int i;
  156. for (i = 0; i < 32; i++) {
  157. str += sprintf(str, "%7d ", array[i] >> shift);
  158. if (i == 15)
  159. str += sprintf(str, "\n");
  160. }
  161. str += sprintf(str,"\n");
  162. return str;
  163. }
  164. static int
  165. dasd_statistics_read(char *page, char **start, off_t off,
  166. int count, int *eof, void *data)
  167. {
  168. unsigned long len;
  169. #ifdef CONFIG_DASD_PROFILE
  170. struct dasd_profile_info_t *prof;
  171. char *str;
  172. int shift;
  173. /* check for active profiling */
  174. if (dasd_profile_level == DASD_PROFILE_OFF) {
  175. len = sprintf(page, "Statistics are off - they might be "
  176. "switched on using 'echo set on > "
  177. "/proc/dasd/statistics'\n");
  178. return dasd_calc_metrics(page, start, off, count, eof, len);
  179. }
  180. prof = &dasd_global_profile;
  181. /* prevent couter 'overflow' on output */
  182. for (shift = 0; (prof->dasd_io_reqs >> shift) > 9999999; shift++);
  183. str = page;
  184. str += sprintf(str, "%d dasd I/O requests\n", prof->dasd_io_reqs);
  185. str += sprintf(str, "with %d sectors(512B each)\n",
  186. prof->dasd_io_sects);
  187. str += sprintf(str,
  188. " __<4 ___8 __16 __32 __64 _128 "
  189. " _256 _512 __1k __2k __4k __8k "
  190. " _16k _32k _64k 128k\n");
  191. str += sprintf(str,
  192. " _256 _512 __1M __2M __4M __8M "
  193. " _16M _32M _64M 128M 256M 512M "
  194. " __1G __2G __4G " " _>4G\n");
  195. str += sprintf(str, "Histogram of sizes (512B secs)\n");
  196. str = dasd_statistics_array(str, prof->dasd_io_secs, shift);
  197. str += sprintf(str, "Histogram of I/O times (microseconds)\n");
  198. str = dasd_statistics_array(str, prof->dasd_io_times, shift);
  199. str += sprintf(str, "Histogram of I/O times per sector\n");
  200. str = dasd_statistics_array(str, prof->dasd_io_timps, shift);
  201. str += sprintf(str, "Histogram of I/O time till ssch\n");
  202. str = dasd_statistics_array(str, prof->dasd_io_time1, shift);
  203. str += sprintf(str, "Histogram of I/O time between ssch and irq\n");
  204. str = dasd_statistics_array(str, prof->dasd_io_time2, shift);
  205. str += sprintf(str, "Histogram of I/O time between ssch "
  206. "and irq per sector\n");
  207. str = dasd_statistics_array(str, prof->dasd_io_time2ps, shift);
  208. str += sprintf(str, "Histogram of I/O time between irq and end\n");
  209. str = dasd_statistics_array(str, prof->dasd_io_time3, shift);
  210. str += sprintf(str, "# of req in chanq at enqueuing (1..32) \n");
  211. str = dasd_statistics_array(str, prof->dasd_io_nr_req, shift);
  212. len = str - page;
  213. #else
  214. len = sprintf(page, "Statistics are not activated in this kernel\n");
  215. #endif
  216. return dasd_calc_metrics(page, start, off, count, eof, len);
  217. }
  218. static int
  219. dasd_statistics_write(struct file *file, const char __user *user_buf,
  220. unsigned long user_len, void *data)
  221. {
  222. #ifdef CONFIG_DASD_PROFILE
  223. char *buffer, *str;
  224. if (user_len > 65536)
  225. user_len = 65536;
  226. buffer = dasd_get_user_string(user_buf, user_len);
  227. if (IS_ERR(buffer))
  228. return PTR_ERR(buffer);
  229. MESSAGE_LOG(KERN_INFO, "/proc/dasd/statictics: '%s'", buffer);
  230. /* check for valid verbs */
  231. for (str = buffer; isspace(*str); str++);
  232. if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
  233. /* 'set xxx' was given */
  234. for (str = str + 4; isspace(*str); str++);
  235. if (strcmp(str, "on") == 0) {
  236. /* switch on statistics profiling */
  237. dasd_profile_level = DASD_PROFILE_ON;
  238. MESSAGE(KERN_INFO, "%s", "Statistics switched on");
  239. } else if (strcmp(str, "off") == 0) {
  240. /* switch off and reset statistics profiling */
  241. memset(&dasd_global_profile,
  242. 0, sizeof (struct dasd_profile_info_t));
  243. dasd_profile_level = DASD_PROFILE_OFF;
  244. MESSAGE(KERN_INFO, "%s", "Statistics switched off");
  245. } else
  246. goto out_error;
  247. } else if (strncmp(str, "reset", 5) == 0) {
  248. /* reset the statistics */
  249. memset(&dasd_global_profile, 0,
  250. sizeof (struct dasd_profile_info_t));
  251. MESSAGE(KERN_INFO, "%s", "Statistics reset");
  252. } else
  253. goto out_error;
  254. kfree(buffer);
  255. return user_len;
  256. out_error:
  257. MESSAGE(KERN_WARNING, "%s",
  258. "/proc/dasd/statistics: only 'set on', 'set off' "
  259. "and 'reset' are supported verbs");
  260. kfree(buffer);
  261. return -EINVAL;
  262. #else
  263. MESSAGE(KERN_WARNING, "%s",
  264. "/proc/dasd/statistics: is not activated in this kernel");
  265. return user_len;
  266. #endif /* CONFIG_DASD_PROFILE */
  267. }
  268. int
  269. dasd_proc_init(void)
  270. {
  271. dasd_proc_root_entry = proc_mkdir("dasd", &proc_root);
  272. dasd_proc_root_entry->owner = THIS_MODULE;
  273. dasd_devices_entry = create_proc_entry("devices",
  274. S_IFREG | S_IRUGO | S_IWUSR,
  275. dasd_proc_root_entry);
  276. dasd_devices_entry->proc_fops = &dasd_devices_file_ops;
  277. dasd_devices_entry->owner = THIS_MODULE;
  278. dasd_statistics_entry = create_proc_entry("statistics",
  279. S_IFREG | S_IRUGO | S_IWUSR,
  280. dasd_proc_root_entry);
  281. dasd_statistics_entry->read_proc = dasd_statistics_read;
  282. dasd_statistics_entry->write_proc = dasd_statistics_write;
  283. dasd_statistics_entry->owner = THIS_MODULE;
  284. return 0;
  285. }
  286. void
  287. dasd_proc_exit(void)
  288. {
  289. remove_proc_entry("devices", dasd_proc_root_entry);
  290. remove_proc_entry("statistics", dasd_proc_root_entry);
  291. remove_proc_entry("dasd", &proc_root);
  292. }