dasd_proc.c 9.6 KB

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