2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999, 2001
9 * gendisk related functions for the dasd driver.
13 #define KMSG_COMPONENT "dasd"
15 #include <linux/interrupt.h>
17 #include <linux/blkpg.h>
19 #include <asm/uaccess.h>
22 #define PRINTK_HEADER "dasd_gendisk:"
27 * Allocate and register gendisk structure for device.
29 int dasd_gendisk_alloc(struct dasd_block
*block
)
32 struct dasd_device
*base
;
35 /* Make sure the minor for this device exists. */
37 if (base
->devindex
>= DASD_PER_MAJOR
)
40 gdp
= alloc_disk(1 << DASD_PARTN_BITS
);
44 /* Initialize gendisk structure. */
45 gdp
->major
= DASD_MAJOR
;
46 gdp
->first_minor
= base
->devindex
<< DASD_PARTN_BITS
;
47 gdp
->fops
= &dasd_device_operations
;
48 gdp
->driverfs_dev
= &base
->cdev
->dev
;
52 * dasda - dasdz : 26 devices
53 * dasdaa - dasdzz : 676 devices, added up = 702
54 * dasdaaa - dasdzzz : 17576 devices, added up = 18278
55 * dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
57 len
= sprintf(gdp
->disk_name
, "dasd");
58 if (base
->devindex
> 25) {
59 if (base
->devindex
> 701) {
60 if (base
->devindex
> 18277)
61 len
+= sprintf(gdp
->disk_name
+ len
, "%c",
62 'a'+(((base
->devindex
-18278)
64 len
+= sprintf(gdp
->disk_name
+ len
, "%c",
65 'a'+(((base
->devindex
-702)/676)%26));
67 len
+= sprintf(gdp
->disk_name
+ len
, "%c",
68 'a'+(((base
->devindex
-26)/26)%26));
70 len
+= sprintf(gdp
->disk_name
+ len
, "%c", 'a'+(base
->devindex
%26));
72 if (base
->features
& DASD_FEATURE_READONLY
||
73 test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
))
75 dasd_add_link_to_gendisk(gdp
, base
);
76 gdp
->queue
= block
->request_queue
;
78 set_capacity(block
->gdp
, 0);
84 * Unregister and free gendisk structure for device.
86 void dasd_gendisk_free(struct dasd_block
*block
)
89 del_gendisk(block
->gdp
);
90 block
->gdp
->private_data
= NULL
;
97 * Trigger a partition detection.
99 int dasd_scan_partitions(struct dasd_block
*block
)
101 struct block_device
*bdev
;
105 bdev
= bdget_disk(block
->gdp
, 0);
107 DBF_DEV_EVENT(DBF_ERR
, block
->base
, "%s",
108 "scan partitions error, bdget returned NULL");
112 rc
= blkdev_get(bdev
, FMODE_READ
, NULL
);
114 DBF_DEV_EVENT(DBF_ERR
, block
->base
,
115 "scan partitions error, blkdev_get returned %d",
120 * See fs/partition/check.c:register_disk,rescan_partitions
121 * Can't call rescan_partitions directly. Use ioctl.
123 rc
= ioctl_by_bdev(bdev
, BLKRRPART
, 0);
124 while (rc
== -EBUSY
&& retry
> 0) {
126 rc
= ioctl_by_bdev(bdev
, BLKRRPART
, 0);
128 DBF_DEV_EVENT(DBF_ERR
, block
->base
,
129 "scan partitions error, retry %d rc %d",
134 * Since the matching blkdev_put call to the blkdev_get in
135 * this function is not called before dasd_destroy_partitions
136 * the offline open_count limit needs to be increased from
137 * 0 to 1. This is done by setting device->bdev (see
138 * dasd_generic_set_offline). As long as the partition
139 * detection is running no offline should be allowed. That
140 * is why the assignment to device->bdev is done AFTER
141 * the BLKRRPART ioctl.
148 * Remove all inodes in the system for a device, delete the
149 * partitions and make device unusable by setting its size to zero.
151 void dasd_destroy_partitions(struct dasd_block
*block
)
153 /* The two structs have 168/176 byte on 31/64 bit. */
154 struct blkpg_partition bpart
;
155 struct blkpg_ioctl_arg barg
;
156 struct block_device
*bdev
;
159 * Get the bdev pointer from the device structure and clear
160 * device->bdev to lower the offline open_count limit again.
166 * See fs/partition/check.c:delete_partition
167 * Can't call delete_partitions directly. Use ioctl.
168 * The ioctl also does locking and invalidation.
170 memset(&bpart
, 0, sizeof(struct blkpg_partition
));
171 memset(&barg
, 0, sizeof(struct blkpg_ioctl_arg
));
172 barg
.data
= (void __force __user
*) &bpart
;
173 barg
.op
= BLKPG_DEL_PARTITION
;
174 for (bpart
.pno
= block
->gdp
->minors
- 1; bpart
.pno
> 0; bpart
.pno
--)
175 ioctl_by_bdev(bdev
, BLKPG
, (unsigned long) &barg
);
177 invalidate_partition(block
->gdp
, 0);
178 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
179 blkdev_put(bdev
, FMODE_READ
);
180 set_capacity(block
->gdp
, 0);
183 int dasd_gendisk_init(void)
187 /* Register to static dasd major 94 */
188 rc
= register_blkdev(DASD_MAJOR
, "dasd");
190 pr_warning("Registering the device driver with major number "
191 "%d failed\n", DASD_MAJOR
);
197 void dasd_gendisk_exit(void)
199 unregister_blkdev(DASD_MAJOR
, "dasd");