dasd_proc.c 9.6 KB

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