dasd_proc.c 9.8 KB

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