dasd_proc.c 9.5 KB

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