dasd_proc.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 != NULL && 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 != NULL) ? device->state : -1) {
  86. case -1:
  87. seq_printf(m, "unknown");
  88. break;
  89. case DASD_STATE_NEW:
  90. seq_printf(m, "new");
  91. break;
  92. case DASD_STATE_KNOWN:
  93. seq_printf(m, "detected");
  94. break;
  95. case DASD_STATE_BASIC:
  96. seq_printf(m, "basic");
  97. break;
  98. case DASD_STATE_UNFMT:
  99. seq_printf(m, "unformatted");
  100. break;
  101. case DASD_STATE_READY:
  102. case DASD_STATE_ONLINE:
  103. seq_printf(m, "active ");
  104. if (dasd_check_blocksize(block->bp_block))
  105. seq_printf(m, "n/f ");
  106. else
  107. seq_printf(m,
  108. "at blocksize: %d, %lld blocks, %lld MB",
  109. block->bp_block, block->blocks,
  110. ((block->bp_block >> 9) *
  111. block->blocks) >> 11);
  112. break;
  113. default:
  114. seq_printf(m, "no stat");
  115. break;
  116. }
  117. dasd_put_device(device);
  118. if (dasd_probeonly)
  119. seq_printf(m, "(probeonly)");
  120. seq_printf(m, "\n");
  121. return 0;
  122. }
  123. static void *dasd_devices_start(struct seq_file *m, loff_t *pos)
  124. {
  125. if (*pos >= dasd_max_devindex)
  126. return NULL;
  127. return (void *)((unsigned long) *pos + 1);
  128. }
  129. static void *dasd_devices_next(struct seq_file *m, void *v, loff_t *pos)
  130. {
  131. ++*pos;
  132. return dasd_devices_start(m, pos);
  133. }
  134. static void dasd_devices_stop(struct seq_file *m, void *v)
  135. {
  136. }
  137. static const struct seq_operations dasd_devices_seq_ops = {
  138. .start = dasd_devices_start,
  139. .next = dasd_devices_next,
  140. .stop = dasd_devices_stop,
  141. .show = dasd_devices_show,
  142. };
  143. static int dasd_devices_open(struct inode *inode, struct file *file)
  144. {
  145. return seq_open(file, &dasd_devices_seq_ops);
  146. }
  147. static const struct file_operations dasd_devices_file_ops = {
  148. .owner = THIS_MODULE,
  149. .open = dasd_devices_open,
  150. .read = seq_read,
  151. .llseek = seq_lseek,
  152. .release = seq_release,
  153. };
  154. static int
  155. dasd_calc_metrics(char *page, char **start, off_t off,
  156. int count, int *eof, int len)
  157. {
  158. len = (len > off) ? len - off : 0;
  159. if (len > count)
  160. len = count;
  161. if (len < count)
  162. *eof = 1;
  163. *start = page + off;
  164. return len;
  165. }
  166. #ifdef CONFIG_DASD_PROFILE
  167. static char *
  168. dasd_statistics_array(char *str, unsigned int *array, int factor)
  169. {
  170. int i;
  171. for (i = 0; i < 32; i++) {
  172. str += sprintf(str, "%7d ", array[i] / factor);
  173. if (i == 15)
  174. str += sprintf(str, "\n");
  175. }
  176. str += sprintf(str,"\n");
  177. return str;
  178. }
  179. #endif /* CONFIG_DASD_PROFILE */
  180. static int
  181. dasd_statistics_read(char *page, char **start, off_t off,
  182. int count, int *eof, void *data)
  183. {
  184. unsigned long len;
  185. #ifdef CONFIG_DASD_PROFILE
  186. struct dasd_profile_info_t *prof;
  187. char *str;
  188. int factor;
  189. /* check for active profiling */
  190. if (dasd_profile_level == DASD_PROFILE_OFF) {
  191. len = sprintf(page, "Statistics are off - they might be "
  192. "switched on using 'echo set on > "
  193. "/proc/dasd/statistics'\n");
  194. return dasd_calc_metrics(page, start, off, count, eof, len);
  195. }
  196. prof = &dasd_global_profile;
  197. /* prevent counter 'overflow' on output */
  198. for (factor = 1; (prof->dasd_io_reqs / factor) > 9999999;
  199. factor *= 10);
  200. str = page;
  201. str += sprintf(str, "%d dasd I/O requests\n", prof->dasd_io_reqs);
  202. str += sprintf(str, "with %u sectors(512B each)\n",
  203. prof->dasd_io_sects);
  204. str += sprintf(str, "Scale Factor is %d\n", factor);
  205. str += sprintf(str,
  206. " __<4 ___8 __16 __32 __64 _128 "
  207. " _256 _512 __1k __2k __4k __8k "
  208. " _16k _32k _64k 128k\n");
  209. str += sprintf(str,
  210. " _256 _512 __1M __2M __4M __8M "
  211. " _16M _32M _64M 128M 256M 512M "
  212. " __1G __2G __4G " " _>4G\n");
  213. str += sprintf(str, "Histogram of sizes (512B secs)\n");
  214. str = dasd_statistics_array(str, prof->dasd_io_secs, factor);
  215. str += sprintf(str, "Histogram of I/O times (microseconds)\n");
  216. str = dasd_statistics_array(str, prof->dasd_io_times, factor);
  217. str += sprintf(str, "Histogram of I/O times per sector\n");
  218. str = dasd_statistics_array(str, prof->dasd_io_timps, factor);
  219. str += sprintf(str, "Histogram of I/O time till ssch\n");
  220. str = dasd_statistics_array(str, prof->dasd_io_time1, factor);
  221. str += sprintf(str, "Histogram of I/O time between ssch and irq\n");
  222. str = dasd_statistics_array(str, prof->dasd_io_time2, factor);
  223. str += sprintf(str, "Histogram of I/O time between ssch "
  224. "and irq per sector\n");
  225. str = dasd_statistics_array(str, prof->dasd_io_time2ps, factor);
  226. str += sprintf(str, "Histogram of I/O time between irq and end\n");
  227. str = dasd_statistics_array(str, prof->dasd_io_time3, factor);
  228. str += sprintf(str, "# of req in chanq at enqueuing (1..32) \n");
  229. str = dasd_statistics_array(str, prof->dasd_io_nr_req, factor);
  230. len = str - page;
  231. #else
  232. len = sprintf(page, "Statistics are not activated in this kernel\n");
  233. #endif
  234. return dasd_calc_metrics(page, start, off, count, eof, len);
  235. }
  236. static int
  237. dasd_statistics_write(struct file *file, const char __user *user_buf,
  238. unsigned long user_len, void *data)
  239. {
  240. #ifdef CONFIG_DASD_PROFILE
  241. char *buffer, *str;
  242. if (user_len > 65536)
  243. user_len = 65536;
  244. buffer = dasd_get_user_string(user_buf, user_len);
  245. if (IS_ERR(buffer))
  246. return PTR_ERR(buffer);
  247. DBF_EVENT(DBF_DEBUG, "/proc/dasd/statictics: '%s'\n", buffer);
  248. /* check for valid verbs */
  249. str = skip_spaces(buffer);
  250. if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
  251. /* 'set xxx' was given */
  252. str = skip_spaces(str + 4);
  253. if (strcmp(str, "on") == 0) {
  254. /* switch on statistics profiling */
  255. dasd_profile_level = DASD_PROFILE_ON;
  256. pr_info("The statistics feature has been switched "
  257. "on\n");
  258. } else if (strcmp(str, "off") == 0) {
  259. /* switch off and reset statistics profiling */
  260. memset(&dasd_global_profile,
  261. 0, sizeof (struct dasd_profile_info_t));
  262. dasd_profile_level = DASD_PROFILE_OFF;
  263. pr_info("The statistics feature has been switched "
  264. "off\n");
  265. } else
  266. goto out_error;
  267. } else if (strncmp(str, "reset", 5) == 0) {
  268. /* reset the statistics */
  269. memset(&dasd_global_profile, 0,
  270. sizeof (struct dasd_profile_info_t));
  271. pr_info("The statistics have been reset\n");
  272. } else
  273. goto out_error;
  274. kfree(buffer);
  275. return user_len;
  276. out_error:
  277. pr_warning("%s is not a supported value for /proc/dasd/statistics\n",
  278. str);
  279. kfree(buffer);
  280. return -EINVAL;
  281. #else
  282. pr_warning("/proc/dasd/statistics: is not activated in this kernel\n");
  283. return user_len;
  284. #endif /* CONFIG_DASD_PROFILE */
  285. }
  286. /*
  287. * Create dasd proc-fs entries.
  288. * In case creation failed, cleanup and return -ENOENT.
  289. */
  290. int
  291. dasd_proc_init(void)
  292. {
  293. dasd_proc_root_entry = proc_mkdir("dasd", NULL);
  294. if (!dasd_proc_root_entry)
  295. goto out_nodasd;
  296. dasd_devices_entry = proc_create("devices",
  297. S_IFREG | S_IRUGO | S_IWUSR,
  298. dasd_proc_root_entry,
  299. &dasd_devices_file_ops);
  300. if (!dasd_devices_entry)
  301. goto out_nodevices;
  302. dasd_statistics_entry = create_proc_entry("statistics",
  303. S_IFREG | S_IRUGO | S_IWUSR,
  304. dasd_proc_root_entry);
  305. if (!dasd_statistics_entry)
  306. goto out_nostatistics;
  307. dasd_statistics_entry->read_proc = dasd_statistics_read;
  308. dasd_statistics_entry->write_proc = dasd_statistics_write;
  309. return 0;
  310. out_nostatistics:
  311. remove_proc_entry("devices", dasd_proc_root_entry);
  312. out_nodevices:
  313. remove_proc_entry("dasd", NULL);
  314. out_nodasd:
  315. return -ENOENT;
  316. }
  317. void
  318. dasd_proc_exit(void)
  319. {
  320. remove_proc_entry("devices", dasd_proc_root_entry);
  321. remove_proc_entry("statistics", dasd_proc_root_entry);
  322. remove_proc_entry("dasd", NULL);
  323. }