2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
|
|
|
|
* Horst Hummel <Horst.Hummel@de.ibm.com>
|
|
|
|
* Carsten Otte <Cotte@de.ibm.com>
|
|
|
|
* Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
|
|
* Bugreports.to..: <Linux390@de.ibm.com>
|
2012-07-20 03:15:04 -06:00
|
|
|
* Copyright IBM Corp. 1999, 2001
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
|
|
|
* gendisk related functions for the dasd driver.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-03-26 08:23:49 -06:00
|
|
|
#define KMSG_COMPONENT "dasd"
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/blkpg.h>
|
|
|
|
|
2016-12-24 12:46:01 -07:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* This is ugly... */
|
|
|
|
#define PRINTK_HEADER "dasd_gendisk:"
|
|
|
|
|
|
|
|
#include "dasd_int.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and register gendisk structure for device.
|
|
|
|
*/
|
2008-01-26 06:11:23 -07:00
|
|
|
int dasd_gendisk_alloc(struct dasd_block *block)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct gendisk *gdp;
|
2008-01-26 06:11:23 -07:00
|
|
|
struct dasd_device *base;
|
2005-09-03 16:57:58 -06:00
|
|
|
int len;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Make sure the minor for this device exists. */
|
2008-01-26 06:11:23 -07:00
|
|
|
base = block->base;
|
|
|
|
if (base->devindex >= DASD_PER_MAJOR)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
gdp = alloc_disk(1 << DASD_PARTN_BITS);
|
|
|
|
if (!gdp)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Initialize gendisk structure. */
|
|
|
|
gdp->major = DASD_MAJOR;
|
2008-01-26 06:11:23 -07:00
|
|
|
gdp->first_minor = base->devindex << DASD_PARTN_BITS;
|
2005-04-16 16:20:36 -06:00
|
|
|
gdp->fops = &dasd_device_operations;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set device name.
|
|
|
|
* dasda - dasdz : 26 devices
|
|
|
|
* dasdaa - dasdzz : 676 devices, added up = 702
|
|
|
|
* dasdaaa - dasdzzz : 17576 devices, added up = 18278
|
|
|
|
* dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
|
|
|
|
*/
|
|
|
|
len = sprintf(gdp->disk_name, "dasd");
|
2008-01-26 06:11:23 -07:00
|
|
|
if (base->devindex > 25) {
|
|
|
|
if (base->devindex > 701) {
|
|
|
|
if (base->devindex > 18277)
|
2005-04-16 16:20:36 -06:00
|
|
|
len += sprintf(gdp->disk_name + len, "%c",
|
2008-01-26 06:11:23 -07:00
|
|
|
'a'+(((base->devindex-18278)
|
2005-04-16 16:20:36 -06:00
|
|
|
/17576)%26));
|
|
|
|
len += sprintf(gdp->disk_name + len, "%c",
|
2008-01-26 06:11:23 -07:00
|
|
|
'a'+(((base->devindex-702)/676)%26));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
len += sprintf(gdp->disk_name + len, "%c",
|
2008-01-26 06:11:23 -07:00
|
|
|
'a'+(((base->devindex-26)/26)%26));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2008-01-26 06:11:23 -07:00
|
|
|
len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-03-08 04:26:24 -07:00
|
|
|
if (base->features & DASD_FEATURE_READONLY ||
|
|
|
|
test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
|
2005-04-16 16:20:36 -06:00
|
|
|
set_disk_ro(gdp, 1);
|
2011-04-20 02:15:30 -06:00
|
|
|
dasd_add_link_to_gendisk(gdp, base);
|
2008-01-26 06:11:23 -07:00
|
|
|
gdp->queue = block->request_queue;
|
|
|
|
block->gdp = gdp;
|
|
|
|
set_capacity(block->gdp, 0);
|
2016-06-15 20:44:20 -06:00
|
|
|
device_add_disk(&base->cdev->dev, block->gdp);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister and free gendisk structure for device.
|
|
|
|
*/
|
2008-01-26 06:11:23 -07:00
|
|
|
void dasd_gendisk_free(struct dasd_block *block)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-01-26 06:11:23 -07:00
|
|
|
if (block->gdp) {
|
|
|
|
del_gendisk(block->gdp);
|
2010-02-26 14:37:46 -07:00
|
|
|
block->gdp->private_data = NULL;
|
2008-01-26 06:11:23 -07:00
|
|
|
put_disk(block->gdp);
|
|
|
|
block->gdp = NULL;
|
2006-08-30 06:33:33 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trigger a partition detection.
|
|
|
|
*/
|
2008-01-26 06:11:23 -07:00
|
|
|
int dasd_scan_partitions(struct dasd_block *block)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct block_device *bdev;
|
2015-05-05 22:26:28 -06:00
|
|
|
int rc;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-01-26 06:11:23 -07:00
|
|
|
bdev = bdget_disk(block->gdp, 0);
|
2014-11-24 07:04:09 -07:00
|
|
|
if (!bdev) {
|
|
|
|
DBF_DEV_EVENT(DBF_ERR, block->base, "%s",
|
|
|
|
"scan partitions error, bdget returned NULL");
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
2014-11-24 07:04:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = blkdev_get(bdev, FMODE_READ, NULL);
|
|
|
|
if (rc < 0) {
|
|
|
|
DBF_DEV_EVENT(DBF_ERR, block->base,
|
|
|
|
"scan partitions error, blkdev_get returned %d",
|
|
|
|
rc);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2015-05-05 22:26:26 -06:00
|
|
|
|
|
|
|
rc = blkdev_reread_part(bdev);
|
2015-05-05 22:26:28 -06:00
|
|
|
if (rc)
|
2014-11-24 07:04:09 -07:00
|
|
|
DBF_DEV_EVENT(DBF_ERR, block->base,
|
2015-05-05 22:26:28 -06:00
|
|
|
"scan partitions error, rc %d", rc);
|
2014-11-24 07:04:09 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Since the matching blkdev_put call to the blkdev_get in
|
|
|
|
* this function is not called before dasd_destroy_partitions
|
|
|
|
* the offline open_count limit needs to be increased from
|
|
|
|
* 0 to 1. This is done by setting device->bdev (see
|
|
|
|
* dasd_generic_set_offline). As long as the partition
|
|
|
|
* detection is running no offline should be allowed. That
|
|
|
|
* is why the assignment to device->bdev is done AFTER
|
|
|
|
* the BLKRRPART ioctl.
|
|
|
|
*/
|
2008-01-26 06:11:23 -07:00
|
|
|
block->bdev = bdev;
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove all inodes in the system for a device, delete the
|
|
|
|
* partitions and make device unusable by setting its size to zero.
|
|
|
|
*/
|
2008-01-26 06:11:23 -07:00
|
|
|
void dasd_destroy_partitions(struct dasd_block *block)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
/* The two structs have 168/176 byte on 31/64 bit. */
|
|
|
|
struct blkpg_partition bpart;
|
|
|
|
struct blkpg_ioctl_arg barg;
|
|
|
|
struct block_device *bdev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the bdev pointer from the device structure and clear
|
|
|
|
* device->bdev to lower the offline open_count limit again.
|
|
|
|
*/
|
2008-01-26 06:11:23 -07:00
|
|
|
bdev = block->bdev;
|
|
|
|
block->bdev = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* See fs/partition/check.c:delete_partition
|
|
|
|
* Can't call delete_partitions directly. Use ioctl.
|
|
|
|
* The ioctl also does locking and invalidation.
|
|
|
|
*/
|
|
|
|
memset(&bpart, 0, sizeof(struct blkpg_partition));
|
|
|
|
memset(&barg, 0, sizeof(struct blkpg_ioctl_arg));
|
2007-02-05 13:16:47 -07:00
|
|
|
barg.data = (void __force __user *) &bpart;
|
2005-04-16 16:20:36 -06:00
|
|
|
barg.op = BLKPG_DEL_PARTITION;
|
2008-01-26 06:11:23 -07:00
|
|
|
for (bpart.pno = block->gdp->minors - 1; bpart.pno > 0; bpart.pno--)
|
2005-04-16 16:20:36 -06:00
|
|
|
ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg);
|
|
|
|
|
2008-01-26 06:11:23 -07:00
|
|
|
invalidate_partition(block->gdp, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
|
2008-02-22 18:40:24 -07:00
|
|
|
blkdev_put(bdev, FMODE_READ);
|
2008-01-26 06:11:23 -07:00
|
|
|
set_capacity(block->gdp, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-01-26 06:11:23 -07:00
|
|
|
int dasd_gendisk_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Register to static dasd major 94 */
|
|
|
|
rc = register_blkdev(DASD_MAJOR, "dasd");
|
|
|
|
if (rc != 0) {
|
2016-03-03 21:49:57 -07:00
|
|
|
pr_warn("Registering the device driver with major number %d failed\n",
|
|
|
|
DASD_MAJOR);
|
2005-04-16 16:20:36 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-26 06:11:23 -07:00
|
|
|
void dasd_gendisk_exit(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
unregister_blkdev(DASD_MAJOR, "dasd");
|
|
|
|
}
|