dasd_genhd.c 4.8 KB

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