Commit 4d466c1f authored by Alexander Viro's avatar Alexander Viro Committed by James Bottomley

[PATCH] r/o state moved to gendisks

parent 1bec5152
...@@ -336,3 +336,40 @@ void put_disk(struct gendisk *disk) ...@@ -336,3 +336,40 @@ void put_disk(struct gendisk *disk)
EXPORT_SYMBOL(alloc_disk); EXPORT_SYMBOL(alloc_disk);
EXPORT_SYMBOL(get_disk); EXPORT_SYMBOL(get_disk);
EXPORT_SYMBOL(put_disk); EXPORT_SYMBOL(put_disk);
void set_device_ro(struct block_device *bdev, int flag)
{
struct gendisk *disk = bdev->bd_disk;
if (bdev->bd_contains != bdev) {
int part = bdev->bd_dev - MKDEV(disk->major, disk->first_minor);
struct hd_struct *p = &disk->part[part-1];
p->policy = flag;
} else
disk->policy = flag;
}
void set_disk_ro(struct gendisk *disk, int flag)
{
int i;
disk->policy = flag;
for (i = 0; i < disk->minors; i++)
disk->part[i].policy = flag;
}
int bdev_read_only(struct block_device *bdev)
{
struct gendisk *disk;
if (!bdev)
return 0;
disk = bdev->bd_disk;
if (bdev->bd_contains != bdev) {
int part = bdev->bd_dev - MKDEV(disk->major, disk->first_minor);
struct hd_struct *p = &disk->part[part-1];
return p->policy;
} else
return disk->policy;
}
EXPORT_SYMBOL(bdev_read_only);
EXPORT_SYMBOL(set_device_ro);
EXPORT_SYMBOL(set_disk_ro);
...@@ -202,7 +202,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, ...@@ -202,7 +202,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
return -EACCES; return -EACCES;
if (get_user(n, (int *)(arg))) if (get_user(n, (int *)(arg)))
return -EFAULT; return -EFAULT;
set_device_ro(to_kdev_t(bdev->bd_dev), n); set_device_ro(bdev, n);
return 0; return 0;
default: default:
if (bdev->bd_op->ioctl) { if (bdev->bd_op->ioctl) {
......
...@@ -1404,34 +1404,6 @@ void blk_insert_request(request_queue_t *q, struct request *rq, ...@@ -1404,34 +1404,6 @@ void blk_insert_request(request_queue_t *q, struct request *rq,
spin_unlock_irqrestore(q->queue_lock, flags); spin_unlock_irqrestore(q->queue_lock, flags);
} }
/* RO fail safe mechanism */
static long ro_bits[MAX_BLKDEV][8];
int bdev_read_only(struct block_device *bdev)
{
int minor,major;
if (!bdev)
return 0;
major = MAJOR(bdev->bd_dev);
minor = MINOR(bdev->bd_dev);
if (major < 0 || major >= MAX_BLKDEV)
return 0;
return ro_bits[major][minor >> 5] & (1 << (minor & 31));
}
void set_device_ro(kdev_t dev,int flag)
{
int minor,major;
major = major(dev);
minor = minor(dev);
if (major < 0 || major >= MAX_BLKDEV) return;
if (flag) ro_bits[major][minor >> 5] |= 1 << (minor & 31);
else ro_bits[major][minor >> 5] &= ~(1 << (minor & 31));
}
void drive_stat_acct(struct request *rq, int nr_sectors, int new_io) void drive_stat_acct(struct request *rq, int nr_sectors, int new_io)
{ {
unsigned int major = major(rq->rq_dev); unsigned int major = major(rq->rq_dev);
......
...@@ -650,7 +650,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -650,7 +650,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
{ {
struct file *file; struct file *file;
struct inode *inode; struct inode *inode;
kdev_t dev = to_kdev_t(bdev->bd_dev);
struct block_device *lo_device; struct block_device *lo_device;
int lo_flags = 0; int lo_flags = 0;
int error; int error;
...@@ -702,7 +701,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, ...@@ -702,7 +701,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
|| !(lo_file->f_mode & FMODE_WRITE)) || !(lo_file->f_mode & FMODE_WRITE))
lo_flags |= LO_FLAGS_READ_ONLY; lo_flags |= LO_FLAGS_READ_ONLY;
set_device_ro(dev, (lo_flags & LO_FLAGS_READ_ONLY) != 0); set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0);
lo->lo_device = lo_device; lo->lo_device = lo_device;
lo->lo_flags = lo_flags; lo->lo_flags = lo_flags;
......
...@@ -3062,7 +3062,7 @@ int ide_cdrom_setup (ide_drive_t *drive) ...@@ -3062,7 +3062,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
/* /*
* default to read-only always and fix latter at the bottom * default to read-only always and fix latter at the bottom
*/ */
set_device_ro(mk_kdev(drive->disk->major, drive->disk->first_minor), 1); set_disk_ro(drive->disk, 1);
blk_queue_hardsect_size(&drive->queue, CD_FRAMESIZE); blk_queue_hardsect_size(&drive->queue, CD_FRAMESIZE);
blk_queue_prep_rq(&drive->queue, ide_cdrom_prep_fn); blk_queue_prep_rq(&drive->queue, ide_cdrom_prep_fn);
...@@ -3185,7 +3185,7 @@ int ide_cdrom_setup (ide_drive_t *drive) ...@@ -3185,7 +3185,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
nslots = ide_cdrom_probe_capabilities (drive); nslots = ide_cdrom_probe_capabilities (drive);
if (CDROM_CONFIG_FLAGS(drive)->dvd_ram) if (CDROM_CONFIG_FLAGS(drive)->dvd_ram)
set_device_ro(mk_kdev(drive->disk->major, drive->disk->first_minor), 0); set_disk_ro(drive->disk, 0);
#if 0 #if 0
drive->dsc_overlap = (HWIF(drive)->no_dsc) ? 0 : 1; drive->dsc_overlap = (HWIF(drive)->no_dsc) ? 0 : 1;
......
...@@ -1467,6 +1467,7 @@ static int do_md_run(mddev_t * mddev) ...@@ -1467,6 +1467,7 @@ static int do_md_run(mddev_t * mddev)
static int restart_array(mddev_t *mddev) static int restart_array(mddev_t *mddev)
{ {
struct gendisk *disk = disks[mdidx(mddev)];
int err; int err;
/* /*
...@@ -1482,7 +1483,7 @@ static int restart_array(mddev_t *mddev) ...@@ -1482,7 +1483,7 @@ static int restart_array(mddev_t *mddev)
goto out; goto out;
mddev->ro = 0; mddev->ro = 0;
set_device_ro(mddev_to_kdev(mddev), 0); set_disk_ro(disk, 0);
printk(KERN_INFO printk(KERN_INFO
"md: md%d switched to read-write mode.\n", mdidx(mddev)); "md: md%d switched to read-write mode.\n", mdidx(mddev));
...@@ -1509,7 +1510,7 @@ static int restart_array(mddev_t *mddev) ...@@ -1509,7 +1510,7 @@ static int restart_array(mddev_t *mddev)
static int do_md_stop(mddev_t * mddev, int ro) static int do_md_stop(mddev_t * mddev, int ro)
{ {
int err = 0; int err = 0;
kdev_t dev = mddev_to_kdev(mddev); struct gendisk *disk = disks[mdidx(mddev)];
if (atomic_read(&mddev->active)>1) { if (atomic_read(&mddev->active)>1) {
printk(STILL_IN_USE, mdidx(mddev)); printk(STILL_IN_USE, mdidx(mddev));
...@@ -1525,7 +1526,7 @@ static int do_md_stop(mddev_t * mddev, int ro) ...@@ -1525,7 +1526,7 @@ static int do_md_stop(mddev_t * mddev, int ro)
mddev->sync_thread = NULL; mddev->sync_thread = NULL;
} }
invalidate_device(dev, 1); invalidate_device(mk_kdev(disk->major, disk->first_minor), 1);
if (ro) { if (ro) {
err = -ENXIO; err = -ENXIO;
...@@ -1534,11 +1535,11 @@ static int do_md_stop(mddev_t * mddev, int ro) ...@@ -1534,11 +1535,11 @@ static int do_md_stop(mddev_t * mddev, int ro)
mddev->ro = 1; mddev->ro = 1;
} else { } else {
if (mddev->ro) if (mddev->ro)
set_device_ro(dev, 0); set_disk_ro(disk, 0);
if (mddev->pers->stop(mddev)) { if (mddev->pers->stop(mddev)) {
err = -EBUSY; err = -EBUSY;
if (mddev->ro) if (mddev->ro)
set_device_ro(dev, 1); set_disk_ro(disk, 1);
goto out; goto out;
} }
if (mddev->ro) if (mddev->ro)
...@@ -1556,7 +1557,7 @@ static int do_md_stop(mddev_t * mddev, int ro) ...@@ -1556,7 +1557,7 @@ static int do_md_stop(mddev_t * mddev, int ro)
md_update_sb(mddev); md_update_sb(mddev);
} }
if (ro) if (ro)
set_device_ro(dev, 1); set_disk_ro(disk, 1);
} }
/* /*
* Free resources if final stop * Free resources if final stop
......
...@@ -330,7 +330,7 @@ static int mtdblock_open(struct inode *inode, struct file *file) ...@@ -330,7 +330,7 @@ static int mtdblock_open(struct inode *inode, struct file *file)
} }
mtdblks[dev] = mtdblk; mtdblks[dev] = mtdblk;
set_device_ro (inode->i_rdev, !(mtdblk->mtd->flags & MTD_WRITEABLE)); set_device_ro(inode->i_bdev, !(mtdblk->mtd->flags & MTD_WRITEABLE));
spin_unlock(&mtdblks_lock); spin_unlock(&mtdblks_lock);
......
...@@ -58,7 +58,7 @@ static int mtdblock_open(struct inode *inode, struct file *file) ...@@ -58,7 +58,7 @@ static int mtdblock_open(struct inode *inode, struct file *file)
} }
if (ret == 0) { if (ret == 0) {
set_device_ro(inode->i_rdev, !(mdev->mtd->flags & MTD_CAP_RAM)); set_device_ro(inode->i_bdev, !(mdev->mtd->flags & MTD_CAP_RAM));
mdev->open++; mdev->open++;
} }
up(&mtd_sem); up(&mtd_sem);
......
...@@ -427,17 +427,6 @@ dasd_state_accept_to_basic(dasd_device_t * device) ...@@ -427,17 +427,6 @@ dasd_state_accept_to_basic(dasd_device_t * device)
device->state = DASD_STATE_BASIC; device->state = DASD_STATE_BASIC;
} }
/*
* get the kdev_t of a device
* FIXME: remove this when no longer needed
*/
static inline kdev_t
dasd_partition_to_kdev_t(dasd_device_t *device, unsigned int partition)
{
return mk_kdev(device->gdp->major, device->gdp->first_minor+partition);
}
/* /*
* Setup block device. * Setup block device.
*/ */
...@@ -449,8 +438,6 @@ dasd_state_accept_to_ready(dasd_device_t * device) ...@@ -449,8 +438,6 @@ dasd_state_accept_to_ready(dasd_device_t * device)
devmap = dasd_devmap_from_devno(device->devinfo.devno); devmap = dasd_devmap_from_devno(device->devinfo.devno);
if (devmap->features & DASD_FEATURE_READONLY) { if (devmap->features & DASD_FEATURE_READONLY) {
for (i = 0; i < (1 << DASD_PARTN_BITS); i++)
set_device_ro(dasd_partition_to_kdev_t(device, i), 1);
device->ro_flag = 1; device->ro_flag = 1;
DEV_MESSAGE (KERN_WARNING, device, "%s", DEV_MESSAGE (KERN_WARNING, device, "%s",
"setting read-only mode "); "setting read-only mode ");
......
...@@ -249,6 +249,8 @@ dasd_setup_partitions(dasd_device_t * device) ...@@ -249,6 +249,8 @@ dasd_setup_partitions(dasd_device_t * device)
/* Make the disk known. */ /* Make the disk known. */
set_capacity(device->gdp, device->blocks << device->s2b_shift); set_capacity(device->gdp, device->blocks << device->s2b_shift);
device->gdp->queue = device->request_queue; device->gdp->queue = device->request_queue;
if (device->ro_flag)
set_disk_ro(device->gdp, 1);
add_disk(device->gdp); add_disk(device->gdp);
} }
......
...@@ -462,8 +462,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, int no, long args) ...@@ -462,8 +462,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, int no, long args)
devmap->features |= DASD_FEATURE_READONLY; devmap->features |= DASD_FEATURE_READONLY;
else else
devmap->features &= ~DASD_FEATURE_READONLY; devmap->features &= ~DASD_FEATURE_READONLY;
for (i = 0; i < (1 << DASD_PARTN_BITS); i++) set_disk_ro(bdev->bd_disk, intval);
set_device_ro(to_kdev_t(bdev->bd_dev + i), intval);
device->ro_flag = intval; device->ro_flag = intval;
dasd_put_device(devmap); dasd_put_device(devmap);
return 0; return 0;
......
...@@ -592,7 +592,7 @@ static int jsfd_init(void) ...@@ -592,7 +592,7 @@ static int jsfd_init(void)
disk->private_data = jdp; disk->private_data = jdp;
disk->queue = &jsf_queue; disk->queue = &jsf_queue;
add_disk(disk); add_disk(disk);
set_device_ro(MKDEV(JSFD_MAJOR, i), 1); set_disk_ro(disk, 1);
} }
return 0; return 0;
out: out:
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/compiler.h> #include <linux/compiler.h>
extern void set_device_ro(kdev_t dev,int flag); extern void set_device_ro(struct block_device *bdev, int flag);
extern void set_disk_ro(struct gendisk *disk, int flag);
extern void add_disk_randomness(struct gendisk *disk); extern void add_disk_randomness(struct gendisk *disk);
extern void rand_initialize_disk(struct gendisk *disk); extern void rand_initialize_disk(struct gendisk *disk);
......
...@@ -63,6 +63,7 @@ struct hd_struct { ...@@ -63,6 +63,7 @@ struct hd_struct {
sector_t nr_sects; sector_t nr_sects;
devfs_handle_t de; /* primary (master) devfs entry */ devfs_handle_t de; /* primary (master) devfs entry */
struct device *hd_driverfs_dev; /* support driverfs hiearchy */ struct device *hd_driverfs_dev; /* support driverfs hiearchy */
int policy;
}; };
#define GENHD_FL_REMOVABLE 1 #define GENHD_FL_REMOVABLE 1
...@@ -94,7 +95,7 @@ struct gendisk { ...@@ -94,7 +95,7 @@ struct gendisk {
struct device disk_dev; struct device disk_dev;
struct timer_rand_state *random; struct timer_rand_state *random;
int policy;
unsigned sync_io; /* RAID */ unsigned sync_io; /* RAID */
unsigned reads, writes; unsigned reads, writes;
......
...@@ -62,8 +62,6 @@ ...@@ -62,8 +62,6 @@
#include <linux/kmod.h> #include <linux/kmod.h>
#endif #endif
extern void set_device_ro(kdev_t dev,int flag);
extern struct timezone sys_tz; extern struct timezone sys_tz;
#ifdef CONFIG_MODVERSIONS #ifdef CONFIG_MODVERSIONS
...@@ -341,8 +339,6 @@ EXPORT_SYMBOL(tty_unregister_driver); ...@@ -341,8 +339,6 @@ EXPORT_SYMBOL(tty_unregister_driver);
EXPORT_SYMBOL(tty_std_termios); EXPORT_SYMBOL(tty_std_termios);
/* block device driver support */ /* block device driver support */
EXPORT_SYMBOL(bdev_read_only);
EXPORT_SYMBOL(set_device_ro);
EXPORT_SYMBOL(bmap); EXPORT_SYMBOL(bmap);
EXPORT_SYMBOL(blkdev_open); EXPORT_SYMBOL(blkdev_open);
EXPORT_SYMBOL(blkdev_get); EXPORT_SYMBOL(blkdev_get);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment