dasd_proc.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. #define KMSG_COMPONENT "dasd"
  14. #include <linux/ctype.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. #ifdef CONFIG_DASD_PROFILE
  28. static char *
  29. dasd_get_user_string(const char __user *user_buf, size_t user_len)
  30. {
  31. char *buffer;
  32. buffer = kmalloc(user_len + 1, GFP_KERNEL);
  33. if (buffer == NULL)
  34. return ERR_PTR(-ENOMEM);
  35. if (copy_from_user(buffer, user_buf, user_len) != 0) {
  36. kfree(buffer);
  37. return ERR_PTR(-EFAULT);
  38. }
  39. /* got the string, now strip linefeed. */
  40. if (buffer[user_len - 1] == '\n')
  41. buffer[user_len - 1] = 0;
  42. else
  43. buffer[user_len] = 0;
  44. return buffer;
  45. }
  46. #endif /* CONFIG_DASD_PROFILE */
  47. static int
  48. dasd_devices_show(struct seq_file *m, void *v)
  49. {
  50. struct dasd_device *device;
  51. struct dasd_block *block;
  52. char *substr;
  53. device = dasd_device_from_devindex((unsigned long) v - 1);
  54. if (IS_ERR(device))
  55. return 0;
  56. if (device->block)
  57. block = device->block;
  58. else {
  59. dasd_put_device(device);
  60. return 0;
  61. }
  62. /* Print device number. */
  63. seq_printf(m, "%s", dev_name(&device->cdev->dev));
  64. /* Print discipline string. */
  65. if (device->discipline != NULL)
  66. seq_printf(m, "(%s)", device->discipline->name);
  67. else
  68. seq_printf(m, "(none)");
  69. /* Print kdev. */
  70. if (block->gdp)
  71. seq_printf(m, " at (%3d:%6d)",
  72. MAJOR(disk_devt(block->gdp)),
  73. MINOR(disk_devt(block->gdp)));
  74. else
  75. seq_printf(m, " at (???:??????)");
  76. /* Print device name. */
  77. if (block->gdp)
  78. seq_printf(m, " is %-8s", block->gdp->disk_name);
  79. else
  80. seq_printf(m, " is ????????");
  81. /* Print devices features. */
  82. substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
  83. seq_printf(m, "%4s: ", substr);
  84. /* Print device status information. */
  85. switch (device->state) {
  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, %lld blocks, %lld 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. .owner = THIS_MODULE,
  146. .open = dasd_devices_open,
  147. .read = seq_read,
  148. .llseek = seq_lseek,
  149. .release = seq_release,
  150. };
  151. #ifdef CONFIG_DASD_PROFILE
  152. static void dasd_statistics_array(struct seq_file *m, unsigned int *array, int factor)
  153. {
  154. int i;
  155. for (i = 0; i < 32; i++) {
  156. seq_printf(m, "%7d ", array[i] / factor);
  157. if (i == 15)
  158. seq_putc(m, '\n');
  159. }
  160. seq_putc(m, '\n');
  161. }
  162. #endif /* CONFIG_DASD_PROFILE */
  163. static int dasd_stats_proc_show(struct seq_file *m, void *v)
  164. {
  165. #ifdef CONFIG_DASD_PROFILE
  166. struct dasd_profile_info_t *prof;
  167. int factor;
  168. /* check for active profiling */
  169. if (dasd_profile_level == DASD_PROFILE_OFF) {
  170. seq_printf(m, "Statistics are off - they might be "
  171. "switched on using 'echo set on > "
  172. "/proc/dasd/statistics'\n");
  173. return 0;
  174. }
  175. prof = &dasd_global_profile;
  176. /* prevent counter 'overflow' on output */
  177. for (factor = 1; (prof->dasd_io_reqs / factor) > 9999999;
  178. factor *= 10);
  179. seq_printf(m, "%d dasd I/O requests\n", prof->dasd_io_reqs);
  180. seq_printf(m, "with %u sectors(512B each)\n",
  181. prof->dasd_io_sects);
  182. seq_printf(m, "Scale Factor is %d\n", factor);
  183. seq_printf(m,
  184. " __<4 ___8 __16 __32 __64 _128 "
  185. " _256 _512 __1k __2k __4k __8k "
  186. " _16k _32k _64k 128k\n");
  187. seq_printf(m,
  188. " _256 _512 __1M __2M __4M __8M "
  189. " _16M _32M _64M 128M 256M 512M "
  190. " __1G __2G __4G " " _>4G\n");
  191. seq_printf(m, "Histogram of sizes (512B secs)\n");
  192. dasd_statistics_array(m, prof->dasd_io_secs, factor);
  193. seq_printf(m, "Histogram of I/O times (microseconds)\n");
  194. dasd_statistics_array(m, prof->dasd_io_times, factor);
  195. seq_printf(m, "Histogram of I/O times per sector\n");
  196. dasd_statistics_array(m, prof->dasd_io_timps, factor);
  197. seq_printf(m, "Histogram of I/O time till ssch\n");
  198. dasd_statistics_array(m, prof->dasd_io_time1, factor);
  199. seq_printf(m, "Histogram of I/O time between ssch and irq\n");
  200. dasd_statistics_array(m, prof->dasd_io_time2, factor);
  201. seq_printf(m, "Histogram of I/O time between ssch "
  202. "and irq per sector\n");
  203. dasd_statistics_array(m, prof->dasd_io_time2ps, factor);
  204. seq_printf(m, "Histogram of I/O time between irq and end\n");
  205. dasd_statistics_array(m, prof->dasd_io_time3, factor);
  206. seq_printf(m, "# of req in chanq at enqueuing (1..32) \n");
  207. dasd_statistics_array(m, prof->dasd_io_nr_req, factor);
  208. #else
  209. seq_printf(m, "Statistics are not activated in this kernel\n");
  210. #endif
  211. return 0;
  212. }
  213. static int dasd_stats_proc_open(struct inode *inode, struct file *file)
  214. {
  215. return single_open(file, dasd_stats_proc_show, NULL);
  216. }
  217. static ssize_t dasd_stats_proc_write(struct file *file,
  218. const char __user *user_buf, size_t user_len, loff_t *pos)
  219. {
  220. #ifdef CONFIG_DASD_PROFILE
  221. char *buffer, *str;
  222. if (user_len > 65536)
  223. user_len = 65536;
  224. buffer = dasd_get_user_string(user_buf, user_len);
  225. if (IS_ERR(buffer))
  226. return PTR_ERR(buffer);
  227. DBF_EVENT(DBF_DEBUG, "/proc/dasd/statictics: '%s'\n", buffer);
  228. /* check for valid verbs */
  229. str = skip_spaces(buffer);
  230. if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
  231. /* 'set xxx' was given */
  232. str = skip_spaces(str + 4);
  233. if (strcmp(str, "on") == 0) {
  234. /* switch on statistics profiling */
  235. dasd_profile_level = DASD_PROFILE_ON;
  236. pr_info("The statistics feature has been switched "
  237. "on\n");
  238. } else if (strcmp(str, "off") == 0) {
  239. /* switch off and reset statistics profiling */
  240. memset(&dasd_global_profile,
  241. 0, sizeof (struct dasd_profile_info_t));
  242. dasd_profile_level = DASD_PROFILE_OFF;
  243. pr_info("The statistics feature has been switched "
  244. "off\n");
  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. pr_info("The statistics have been reset\n");
  252. } else
  253. goto out_error;
  254. kfree(buffer);
  255. return user_len;
  256. out_error:
  257. pr_warning("%s is not a supported value for /proc/dasd/statistics\n",
  258. str);
  259. kfree(buffer);
  260. return -EINVAL;
  261. #else
  262. pr_warning("/proc/dasd/statistics: is not activated in this kernel\n");
  263. return user_len;
  264. #endif /* CONFIG_DASD_PROFILE */
  265. }
  266. static const struct file_operations dasd_stats_proc_fops = {
  267. .owner = THIS_MODULE,
  268. .open = dasd_stats_proc_open,
  269. .read = seq_read,
  270. .llseek = seq_lseek,
  271. .release = single_release,
  272. .write = dasd_stats_proc_write,
  273. };
  274. /*
  275. * Create dasd proc-fs entries.
  276. * In case creation failed, cleanup and return -ENOENT.
  277. */
  278. int
  279. dasd_proc_init(void)
  280. {
  281. dasd_proc_root_entry = proc_mkdir("dasd", NULL);
  282. if (!dasd_proc_root_entry)
  283. goto out_nodasd;
  284. dasd_devices_entry = proc_create("devices",
  285. S_IFREG | S_IRUGO | S_IWUSR,
  286. dasd_proc_root_entry,
  287. &dasd_devices_file_ops);
  288. if (!dasd_devices_entry)
  289. goto out_nodevices;
  290. dasd_statistics_entry = proc_create("statistics",
  291. S_IFREG | S_IRUGO | S_IWUSR,
  292. dasd_proc_root_entry,
  293. &dasd_stats_proc_fops);
  294. if (!dasd_statistics_entry)
  295. goto out_nostatistics;
  296. return 0;
  297. out_nostatistics:
  298. remove_proc_entry("devices", dasd_proc_root_entry);
  299. out_nodevices:
  300. remove_proc_entry("dasd", NULL);
  301. out_nodasd:
  302. return -ENOENT;
  303. }
  304. void
  305. dasd_proc_exit(void)
  306. {
  307. remove_proc_entry("devices", dasd_proc_root_entry);
  308. remove_proc_entry("statistics", dasd_proc_root_entry);
  309. remove_proc_entry("dasd", NULL);
  310. }