dasd_proc.c 9.4 KB

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