dasd_proc.c 9.5 KB

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