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:"
27 static struct lock_class_key dasd_bio_compl_lkclass;
30 * Allocate and register gendisk structure for device.
32 int dasd_gendisk_alloc(struct dasd_block *block)
35 struct dasd_device *base;
38 /* Make sure the minor for this device exists. */
40 if (base->devindex >= DASD_PER_MAJOR)
43 gdp = __alloc_disk_node(NUMA_NO_NODE, &dasd_bio_compl_lkclass);
47 /* Initialize gendisk structure. */
48 gdp->major = DASD_MAJOR;
49 gdp->first_minor = base->devindex << DASD_PARTN_BITS;
50 gdp->minors = 1 << DASD_PARTN_BITS;
51 gdp->fops = &dasd_device_operations;
55 * dasda - dasdz : 26 devices
56 * dasdaa - dasdzz : 676 devices, added up = 702
57 * dasdaaa - dasdzzz : 17576 devices, added up = 18278
58 * dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
60 len = sprintf(gdp->disk_name, "dasd");
61 if (base->devindex > 25) {
62 if (base->devindex > 701) {
63 if (base->devindex > 18277)
64 len += sprintf(gdp->disk_name + len, "%c",
65 'a'+(((base->devindex-18278)
67 len += sprintf(gdp->disk_name + len, "%c",
68 'a'+(((base->devindex-702)/676)%26));
70 len += sprintf(gdp->disk_name + len, "%c",
71 'a'+(((base->devindex-26)/26)%26));
73 len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));
75 if (base->features & DASD_FEATURE_READONLY ||
76 test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
78 dasd_add_link_to_gendisk(gdp, base);
79 gdp->queue = block->request_queue;
81 set_capacity(block->gdp, 0);
82 device_add_disk(&base->cdev->dev, block->gdp, NULL);
87 * Unregister and free gendisk structure for device.
89 void dasd_gendisk_free(struct dasd_block *block)
92 del_gendisk(block->gdp);
93 block->gdp->private_data = NULL;
100 * Trigger a partition detection.
102 int dasd_scan_partitions(struct dasd_block *block)
104 struct block_device *bdev;
107 bdev = blkdev_get_by_dev(disk_devt(block->gdp), FMODE_READ, NULL);
109 DBF_DEV_EVENT(DBF_ERR, block->base,
110 "scan partitions error, blkdev_get returned %ld",
115 mutex_lock(&block->gdp->open_mutex);
116 rc = bdev_disk_changed(block->gdp, false);
117 mutex_unlock(&block->gdp->open_mutex);
119 DBF_DEV_EVENT(DBF_ERR, block->base,
120 "scan partitions error, rc %d", rc);
123 * Since the matching blkdev_put call to the blkdev_get in
124 * this function is not called before dasd_destroy_partitions
125 * the offline open_count limit needs to be increased from
126 * 0 to 1. This is done by setting device->bdev (see
127 * dasd_generic_set_offline). As long as the partition
128 * detection is running no offline should be allowed. That
129 * is why the assignment to device->bdev is done AFTER
130 * the BLKRRPART ioctl.
137 * Remove all inodes in the system for a device, delete the
138 * partitions and make device unusable by setting its size to zero.
140 void dasd_destroy_partitions(struct dasd_block *block)
142 struct block_device *bdev;
145 * Get the bdev pointer from the device structure and clear
146 * device->bdev to lower the offline open_count limit again.
151 mutex_lock(&bdev->bd_disk->open_mutex);
152 bdev_disk_changed(bdev->bd_disk, true);
153 mutex_unlock(&bdev->bd_disk->open_mutex);
155 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
156 blkdev_put(bdev, FMODE_READ);
159 int dasd_gendisk_init(void)
163 /* Register to static dasd major 94 */
164 rc = register_blkdev(DASD_MAJOR, "dasd");
166 pr_warn("Registering the device driver with major number %d failed\n",
173 void dasd_gendisk_exit(void)
175 unregister_blkdev(DASD_MAJOR, "dasd");