dasd_genhd.c 4.9 KB

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