dasd_proc.c 9.4 KB

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