1 // SPDX-License-Identifier: GPL-2.0
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 * Copyright IBM Corp. 1999, 2001
10 * gendisk related functions for the dasd driver.
14 #define KMSG_COMPONENT "dasd"
16 #include <linux/interrupt.h>
18 #include <linux/blkpg.h>
20 #include <linux/uaccess.h>
23 #define PRINTK_HEADER "dasd_gendisk:"
28 * Allocate and register gendisk structure for device.
30 int dasd_gendisk_alloc(struct dasd_block *block)
33 struct dasd_device *base;
36 /* Make sure the minor for this device exists. */
38 if (base->devindex >= DASD_PER_MAJOR)
41 gdp = alloc_disk(1 << DASD_PARTN_BITS);
45 /* Initialize gendisk structure. */
46 gdp->major = DASD_MAJOR;
47 gdp->first_minor = base->devindex << DASD_PARTN_BITS;
48 gdp->fops = &dasd_device_operations;
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);
79 device_add_disk(&base->cdev->dev, block->gdp, NULL);
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;
104 bdev = blkdev_get_by_dev(disk_devt(block->gdp), FMODE_READ, NULL);
106 DBF_DEV_EVENT(DBF_ERR, block->base,
107 "scan partitions error, blkdev_get returned %ld",
112 mutex_lock(&bdev->bd_mutex);
113 rc = bdev_disk_changed(bdev, false);
114 mutex_unlock(&bdev->bd_mutex);
116 DBF_DEV_EVENT(DBF_ERR, block->base,
117 "scan partitions error, rc %d", rc);
120 * Since the matching blkdev_put call to the blkdev_get in
121 * this function is not called before dasd_destroy_partitions
122 * the offline open_count limit needs to be increased from
123 * 0 to 1. This is done by setting device->bdev (see
124 * dasd_generic_set_offline). As long as the partition
125 * detection is running no offline should be allowed. That
126 * is why the assignment to device->bdev is done AFTER
127 * the BLKRRPART ioctl.
134 * Remove all inodes in the system for a device, delete the
135 * partitions and make device unusable by setting its size to zero.
137 void dasd_destroy_partitions(struct dasd_block *block)
139 struct block_device *bdev;
142 * Get the bdev pointer from the device structure and clear
143 * device->bdev to lower the offline open_count limit again.
148 mutex_lock(&bdev->bd_mutex);
149 blk_drop_partitions(bdev);
150 mutex_unlock(&bdev->bd_mutex);
152 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
153 blkdev_put(bdev, FMODE_READ);
154 set_capacity(block->gdp, 0);
157 int dasd_gendisk_init(void)
161 /* Register to static dasd major 94 */
162 rc = register_blkdev(DASD_MAJOR, "dasd");
164 pr_warn("Registering the device driver with major number %d failed\n",
171 void dasd_gendisk_exit(void)
173 unregister_blkdev(DASD_MAJOR, "dasd");