dasd_genhd.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd_genhd.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-2001
  9. *
  10. * gendisk related functions for the dasd driver.
  11. *
  12. */
  13. #include <linux/interrupt.h>
  14. #include <linux/fs.h>
  15. #include <linux/blkpg.h>
  16. #include <asm/uaccess.h>
  17. /* This is ugly... */
  18. #define PRINTK_HEADER "dasd_gendisk:"
  19. #include "dasd_int.h"
  20. /*
  21. * Allocate and register gendisk structure for device.
  22. */
  23. int
  24. dasd_gendisk_alloc(struct dasd_device *device)
  25. {
  26. struct gendisk *gdp;
  27. int len;
  28. /* Make sure the minor for this device exists. */
  29. if (device->devindex >= DASD_PER_MAJOR)
  30. return -EBUSY;
  31. gdp = alloc_disk(1 << DASD_PARTN_BITS);
  32. if (!gdp)
  33. return -ENOMEM;
  34. /* Initialize gendisk structure. */
  35. gdp->major = DASD_MAJOR;
  36. gdp->first_minor = device->devindex << DASD_PARTN_BITS;
  37. gdp->fops = &dasd_device_operations;
  38. gdp->driverfs_dev = &device->cdev->dev;
  39. /*
  40. * Set device name.
  41. * dasda - dasdz : 26 devices
  42. * dasdaa - dasdzz : 676 devices, added up = 702
  43. * dasdaaa - dasdzzz : 17576 devices, added up = 18278
  44. * dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
  45. */
  46. len = sprintf(gdp->disk_name, "dasd");
  47. if (device->devindex > 25) {
  48. if (device->devindex > 701) {
  49. if (device->devindex > 18277)
  50. len += sprintf(gdp->disk_name + len, "%c",
  51. 'a'+(((device->devindex-18278)
  52. /17576)%26));
  53. len += sprintf(gdp->disk_name + len, "%c",
  54. 'a'+(((device->devindex-702)/676)%26));
  55. }
  56. len += sprintf(gdp->disk_name + len, "%c",
  57. 'a'+(((device->devindex-26)/26)%26));
  58. }
  59. len += sprintf(gdp->disk_name + len, "%c", 'a'+(device->devindex%26));
  60. if (device->features & DASD_FEATURE_READONLY)
  61. set_disk_ro(gdp, 1);
  62. gdp->private_data = device;
  63. gdp->queue = device->request_queue;
  64. device->gdp = gdp;
  65. set_capacity(device->gdp, 0);
  66. add_disk(device->gdp);
  67. return 0;
  68. }
  69. /*
  70. * Unregister and free gendisk structure for device.
  71. */
  72. void
  73. dasd_gendisk_free(struct dasd_device *device)
  74. {
  75. if (device->gdp) {
  76. del_gendisk(device->gdp);
  77. device->gdp->queue = NULL;
  78. put_disk(device->gdp);
  79. device->gdp = NULL;
  80. }
  81. }
  82. /*
  83. * Trigger a partition detection.
  84. */
  85. int
  86. dasd_scan_partitions(struct dasd_device * device)
  87. {
  88. struct block_device *bdev;
  89. bdev = bdget_disk(device->gdp, 0);
  90. if (!bdev || blkdev_get(bdev, FMODE_READ, 1) < 0)
  91. return -ENODEV;
  92. /*
  93. * See fs/partition/check.c:register_disk,rescan_partitions
  94. * Can't call rescan_partitions directly. Use ioctl.
  95. */
  96. ioctl_by_bdev(bdev, BLKRRPART, 0);
  97. /*
  98. * Since the matching blkdev_put call to the blkdev_get in
  99. * this function is not called before dasd_destroy_partitions
  100. * the offline open_count limit needs to be increased from
  101. * 0 to 1. This is done by setting device->bdev (see
  102. * dasd_generic_set_offline). As long as the partition
  103. * detection is running no offline should be allowed. That
  104. * is why the assignment to device->bdev is done AFTER
  105. * the BLKRRPART ioctl.
  106. */
  107. device->bdev = bdev;
  108. return 0;
  109. }
  110. /*
  111. * Remove all inodes in the system for a device, delete the
  112. * partitions and make device unusable by setting its size to zero.
  113. */
  114. void
  115. dasd_destroy_partitions(struct dasd_device * device)
  116. {
  117. /* The two structs have 168/176 byte on 31/64 bit. */
  118. struct blkpg_partition bpart;
  119. struct blkpg_ioctl_arg barg;
  120. struct block_device *bdev;
  121. /*
  122. * Get the bdev pointer from the device structure and clear
  123. * device->bdev to lower the offline open_count limit again.
  124. */
  125. bdev = device->bdev;
  126. device->bdev = NULL;
  127. /*
  128. * See fs/partition/check.c:delete_partition
  129. * Can't call delete_partitions directly. Use ioctl.
  130. * The ioctl also does locking and invalidation.
  131. */
  132. memset(&bpart, 0, sizeof(struct blkpg_partition));
  133. memset(&barg, 0, sizeof(struct blkpg_ioctl_arg));
  134. barg.data = (void __force __user *) &bpart;
  135. barg.op = BLKPG_DEL_PARTITION;
  136. for (bpart.pno = device->gdp->minors - 1; bpart.pno > 0; bpart.pno--)
  137. ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg);
  138. invalidate_partition(device->gdp, 0);
  139. /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
  140. blkdev_put(bdev);
  141. set_capacity(device->gdp, 0);
  142. }
  143. int
  144. dasd_gendisk_init(void)
  145. {
  146. int rc;
  147. /* Register to static dasd major 94 */
  148. rc = register_blkdev(DASD_MAJOR, "dasd");
  149. if (rc != 0) {
  150. MESSAGE(KERN_WARNING,
  151. "Couldn't register successfully to "
  152. "major no %d", DASD_MAJOR);
  153. return rc;
  154. }
  155. return 0;
  156. }
  157. void
  158. dasd_gendisk_exit(void)
  159. {
  160. unregister_blkdev(DASD_MAJOR, "dasd");
  161. }