tape_proc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * tape device driver for S/390 and zSeries tapes.
  3. *
  4. * S390 and zSeries version
  5. * Copyright IBM Corp. 2001
  6. * Author(s): Carsten Otte <cotte@de.ibm.com>
  7. * Michael Holzheu <holzheu@de.ibm.com>
  8. * Tuan Ngo-Anh <ngoanh@de.ibm.com>
  9. *
  10. * PROCFS Functions
  11. */
  12. #define KMSG_COMPONENT "tape"
  13. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  14. #include <linux/module.h>
  15. #include <linux/vmalloc.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/proc_fs.h>
  18. #define TAPE_DBF_AREA tape_core_dbf
  19. #include "tape.h"
  20. static const char *tape_med_st_verbose[MS_SIZE] =
  21. {
  22. [MS_UNKNOWN] = "UNKNOWN ",
  23. [MS_LOADED] = "LOADED ",
  24. [MS_UNLOADED] = "UNLOADED"
  25. };
  26. /* our proc tapedevices entry */
  27. static struct proc_dir_entry *tape_proc_devices;
  28. /*
  29. * Show function for /proc/tapedevices
  30. */
  31. static int tape_proc_show(struct seq_file *m, void *v)
  32. {
  33. struct tape_device *device;
  34. struct tape_request *request;
  35. const char *str;
  36. unsigned long n;
  37. n = (unsigned long) v - 1;
  38. if (!n) {
  39. seq_printf(m, "TapeNo\tBusID CuType/Model\t"
  40. "DevType/Model\tBlkSize\tState\tOp\tMedState\n");
  41. }
  42. device = tape_find_device(n);
  43. if (IS_ERR(device))
  44. return 0;
  45. spin_lock_irq(get_ccwdev_lock(device->cdev));
  46. seq_printf(m, "%d\t", (int) n);
  47. seq_printf(m, "%-10.10s ", dev_name(&device->cdev->dev));
  48. seq_printf(m, "%04X/", device->cdev->id.cu_type);
  49. seq_printf(m, "%02X\t", device->cdev->id.cu_model);
  50. seq_printf(m, "%04X/", device->cdev->id.dev_type);
  51. seq_printf(m, "%02X\t\t", device->cdev->id.dev_model);
  52. if (device->char_data.block_size == 0)
  53. seq_printf(m, "auto\t");
  54. else
  55. seq_printf(m, "%i\t", device->char_data.block_size);
  56. if (device->tape_state >= 0 &&
  57. device->tape_state < TS_SIZE)
  58. str = tape_state_verbose[device->tape_state];
  59. else
  60. str = "UNKNOWN";
  61. seq_printf(m, "%s\t", str);
  62. if (!list_empty(&device->req_queue)) {
  63. request = list_entry(device->req_queue.next,
  64. struct tape_request, list);
  65. str = tape_op_verbose[request->op];
  66. } else
  67. str = "---";
  68. seq_printf(m, "%s\t", str);
  69. seq_printf(m, "%s\n", tape_med_st_verbose[device->medium_state]);
  70. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  71. tape_put_device(device);
  72. return 0;
  73. }
  74. static void *tape_proc_start(struct seq_file *m, loff_t *pos)
  75. {
  76. if (*pos >= 256 / TAPE_MINORS_PER_DEV)
  77. return NULL;
  78. return (void *)((unsigned long) *pos + 1);
  79. }
  80. static void *tape_proc_next(struct seq_file *m, void *v, loff_t *pos)
  81. {
  82. ++*pos;
  83. return tape_proc_start(m, pos);
  84. }
  85. static void tape_proc_stop(struct seq_file *m, void *v)
  86. {
  87. }
  88. static const struct seq_operations tape_proc_seq = {
  89. .start = tape_proc_start,
  90. .next = tape_proc_next,
  91. .stop = tape_proc_stop,
  92. .show = tape_proc_show,
  93. };
  94. static int tape_proc_open(struct inode *inode, struct file *file)
  95. {
  96. return seq_open(file, &tape_proc_seq);
  97. }
  98. static const struct file_operations tape_proc_ops =
  99. {
  100. .owner = THIS_MODULE,
  101. .open = tape_proc_open,
  102. .read = seq_read,
  103. .llseek = seq_lseek,
  104. .release = seq_release,
  105. };
  106. /*
  107. * Initialize procfs stuff on startup
  108. */
  109. void
  110. tape_proc_init(void)
  111. {
  112. tape_proc_devices =
  113. proc_create("tapedevices", S_IFREG | S_IRUGO | S_IWUSR, NULL,
  114. &tape_proc_ops);
  115. if (tape_proc_devices == NULL) {
  116. return;
  117. }
  118. }
  119. /*
  120. * Cleanup all stuff registered to the procfs
  121. */
  122. void
  123. tape_proc_cleanup(void)
  124. {
  125. if (tape_proc_devices != NULL)
  126. remove_proc_entry ("tapedevices", NULL);
  127. }