dasd_proc.c 9.1 KB

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