2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* File...........: linux/drivers/s390/block/dasd_genhd.c
|
|
|
|
* 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>
|
|
|
|
* (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
/* 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;
|
2008-01-26 06:11:23 -07:00
|
|
|
gdp->driverfs_dev = &base->cdev->dev;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
add_disk(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);
|
|
|
|
block->gdp->queue = NULL;
|
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;
|
|
|
|
|
2008-01-26 06:11:23 -07:00
|
|
|
bdev = bdget_disk(block->gdp, 0);
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 03:55:17 -07:00
|
|
|
if (!bdev || blkdev_get(bdev, FMODE_READ, NULL) < 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
|
|
|
/*
|
|
|
|
* See fs/partition/check.c:register_disk,rescan_partitions
|
|
|
|
* Can't call rescan_partitions directly. Use ioctl.
|
|
|
|
*/
|
|
|
|
ioctl_by_bdev(bdev, BLKRRPART, 0);
|
|
|
|
/*
|
|
|
|
* 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) {
|
2009-03-26 08:23:49 -06:00
|
|
|
pr_warning("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");
|
|
|
|
}
|