提交 2e7b651d 编写于 作者: P Peter Zijlstra 提交者: Linus Torvalds

[PATCH] remove the old bd_mutex lockdep annotation

Remove the old complex and crufty bd_mutex annotation.
Signed-off-by: NPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Neil Brown <neilb@cse.unsw.edu.au>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Jason Baron <jbaron@redhat.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 32694850
...@@ -72,7 +72,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -72,7 +72,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
bdevp = bdget_disk(disk, part); bdevp = bdget_disk(disk, part);
if (!bdevp) if (!bdevp)
return -ENOMEM; return -ENOMEM;
mutex_lock_nested(&bdevp->bd_mutex, BD_MUTEX_PARTITION); mutex_lock(&bdevp->bd_mutex);
if (bdevp->bd_openers) { if (bdevp->bd_openers) {
mutex_unlock(&bdevp->bd_mutex); mutex_unlock(&bdevp->bd_mutex);
bdput(bdevp); bdput(bdevp);
...@@ -82,7 +82,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -82,7 +82,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
fsync_bdev(bdevp); fsync_bdev(bdevp);
invalidate_bdev(bdevp, 0); invalidate_bdev(bdevp, 0);
mutex_lock_nested(&bdev->bd_mutex, BD_MUTEX_WHOLE); mutex_lock(&bdev->bd_mutex);
delete_partition(disk, part); delete_partition(disk, part);
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
mutex_unlock(&bdevp->bd_mutex); mutex_unlock(&bdevp->bd_mutex);
......
...@@ -1413,7 +1413,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev) ...@@ -1413,7 +1413,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
struct block_device *bdev; struct block_device *bdev;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
bdev = open_partition_by_devnum(dev, FMODE_READ|FMODE_WRITE); bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
printk(KERN_ERR "md: could not open %s.\n", printk(KERN_ERR "md: could not open %s.\n",
__bdevname(dev, b)); __bdevname(dev, b));
...@@ -1423,7 +1423,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev) ...@@ -1423,7 +1423,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
if (err) { if (err) {
printk(KERN_ERR "md: could not bd_claim %s.\n", printk(KERN_ERR "md: could not bd_claim %s.\n",
bdevname(bdev, b)); bdevname(bdev, b));
blkdev_put_partition(bdev); blkdev_put(bdev);
return err; return err;
} }
rdev->bdev = bdev; rdev->bdev = bdev;
...@@ -1437,7 +1437,7 @@ static void unlock_rdev(mdk_rdev_t *rdev) ...@@ -1437,7 +1437,7 @@ static void unlock_rdev(mdk_rdev_t *rdev)
if (!bdev) if (!bdev)
MD_BUG(); MD_BUG();
bd_release(bdev); bd_release(bdev);
blkdev_put_partition(bdev); blkdev_put(bdev);
} }
void md_autodetect_dev(dev_t dev); void md_autodetect_dev(dev_t dev);
......
...@@ -762,7 +762,7 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder, ...@@ -762,7 +762,7 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
if (!bo) if (!bo)
return -ENOMEM; return -ENOMEM;
mutex_lock_nested(&bdev->bd_mutex, BD_MUTEX_PARTITION); mutex_lock(&bdev->bd_mutex);
res = bd_claim(bdev, holder); res = bd_claim(bdev, holder);
if (res == 0) { if (res == 0) {
found = find_bd_holder(bdev, bo); found = find_bd_holder(bdev, bo);
...@@ -796,7 +796,7 @@ static void bd_release_from_kobject(struct block_device *bdev, ...@@ -796,7 +796,7 @@ static void bd_release_from_kobject(struct block_device *bdev,
if (!kobj) if (!kobj)
return; return;
mutex_lock_nested(&bdev->bd_mutex, BD_MUTEX_PARTITION); mutex_lock(&bdev->bd_mutex);
bd_release(bdev); bd_release(bdev);
if ((bo = del_bd_holder(bdev, kobj))) if ((bo = del_bd_holder(bdev, kobj)))
free_bd_holder(bo); free_bd_holder(bo);
...@@ -854,22 +854,6 @@ struct block_device *open_by_devnum(dev_t dev, unsigned mode) ...@@ -854,22 +854,6 @@ struct block_device *open_by_devnum(dev_t dev, unsigned mode)
EXPORT_SYMBOL(open_by_devnum); EXPORT_SYMBOL(open_by_devnum);
static int
blkdev_get_partition(struct block_device *bdev, mode_t mode, unsigned flags);
struct block_device *open_partition_by_devnum(dev_t dev, unsigned mode)
{
struct block_device *bdev = bdget(dev);
int err = -ENOMEM;
int flags = mode & FMODE_WRITE ? O_RDWR : O_RDONLY;
if (bdev)
err = blkdev_get_partition(bdev, mode, flags);
return err ? ERR_PTR(err) : bdev;
}
EXPORT_SYMBOL(open_partition_by_devnum);
/* /*
* This routine checks whether a removable media has been changed, * This routine checks whether a removable media has been changed,
* and invalidates all buffer-cache-entries in that case. This * and invalidates all buffer-cache-entries in that case. This
...@@ -916,66 +900,7 @@ void bd_set_size(struct block_device *bdev, loff_t size) ...@@ -916,66 +900,7 @@ void bd_set_size(struct block_device *bdev, loff_t size)
} }
EXPORT_SYMBOL(bd_set_size); EXPORT_SYMBOL(bd_set_size);
static int __blkdev_put(struct block_device *bdev, unsigned int subclass) static int do_open(struct block_device *bdev, struct file *file)
{
int ret = 0;
struct inode *bd_inode = bdev->bd_inode;
struct gendisk *disk = bdev->bd_disk;
mutex_lock_nested(&bdev->bd_mutex, subclass);
lock_kernel();
if (!--bdev->bd_openers) {
sync_blockdev(bdev);
kill_bdev(bdev);
}
if (bdev->bd_contains == bdev) {
if (disk->fops->release)
ret = disk->fops->release(bd_inode, NULL);
} else {
mutex_lock_nested(&bdev->bd_contains->bd_mutex,
subclass + 1);
bdev->bd_contains->bd_part_count--;
mutex_unlock(&bdev->bd_contains->bd_mutex);
}
if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner;
put_disk(disk);
module_put(owner);
if (bdev->bd_contains != bdev) {
kobject_put(&bdev->bd_part->kobj);
bdev->bd_part = NULL;
}
bdev->bd_disk = NULL;
bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
if (bdev != bdev->bd_contains)
__blkdev_put(bdev->bd_contains, subclass + 1);
bdev->bd_contains = NULL;
}
unlock_kernel();
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
return ret;
}
int blkdev_put(struct block_device *bdev)
{
return __blkdev_put(bdev, BD_MUTEX_NORMAL);
}
EXPORT_SYMBOL(blkdev_put);
int blkdev_put_partition(struct block_device *bdev)
{
return __blkdev_put(bdev, BD_MUTEX_PARTITION);
}
EXPORT_SYMBOL(blkdev_put_partition);
static int
blkdev_get_whole(struct block_device *bdev, mode_t mode, unsigned flags);
static int
do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
{ {
struct module *owner = NULL; struct module *owner = NULL;
struct gendisk *disk; struct gendisk *disk;
...@@ -992,8 +917,7 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass) ...@@ -992,8 +917,7 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
} }
owner = disk->fops->owner; owner = disk->fops->owner;
mutex_lock_nested(&bdev->bd_mutex, subclass); mutex_lock(&bdev->bd_mutex);
if (!bdev->bd_openers) { if (!bdev->bd_openers) {
bdev->bd_disk = disk; bdev->bd_disk = disk;
bdev->bd_contains = bdev; bdev->bd_contains = bdev;
...@@ -1020,11 +944,11 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass) ...@@ -1020,11 +944,11 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
ret = -ENOMEM; ret = -ENOMEM;
if (!whole) if (!whole)
goto out_first; goto out_first;
ret = blkdev_get_whole(whole, file->f_mode, file->f_flags); ret = blkdev_get(whole, file->f_mode, file->f_flags);
if (ret) if (ret)
goto out_first; goto out_first;
bdev->bd_contains = whole; bdev->bd_contains = whole;
mutex_lock_nested(&whole->bd_mutex, BD_MUTEX_WHOLE); mutex_lock(&whole->bd_mutex);
whole->bd_part_count++; whole->bd_part_count++;
p = disk->part[part - 1]; p = disk->part[part - 1];
bdev->bd_inode->i_data.backing_dev_info = bdev->bd_inode->i_data.backing_dev_info =
...@@ -1052,8 +976,7 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass) ...@@ -1052,8 +976,7 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
if (bdev->bd_invalidated) if (bdev->bd_invalidated)
rescan_partitions(bdev->bd_disk, bdev); rescan_partitions(bdev->bd_disk, bdev);
} else { } else {
mutex_lock_nested(&bdev->bd_contains->bd_mutex, mutex_lock(&bdev->bd_contains->bd_mutex);
BD_MUTEX_WHOLE);
bdev->bd_contains->bd_part_count++; bdev->bd_contains->bd_part_count++;
mutex_unlock(&bdev->bd_contains->bd_mutex); mutex_unlock(&bdev->bd_contains->bd_mutex);
} }
...@@ -1067,7 +990,7 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass) ...@@ -1067,7 +990,7 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
bdev->bd_disk = NULL; bdev->bd_disk = NULL;
bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
if (bdev != bdev->bd_contains) if (bdev != bdev->bd_contains)
__blkdev_put(bdev->bd_contains, BD_MUTEX_WHOLE); blkdev_put(bdev->bd_contains);
bdev->bd_contains = NULL; bdev->bd_contains = NULL;
put_disk(disk); put_disk(disk);
module_put(owner); module_put(owner);
...@@ -1094,49 +1017,11 @@ int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags) ...@@ -1094,49 +1017,11 @@ int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags)
fake_file.f_dentry = &fake_dentry; fake_file.f_dentry = &fake_dentry;
fake_dentry.d_inode = bdev->bd_inode; fake_dentry.d_inode = bdev->bd_inode;
return do_open(bdev, &fake_file, BD_MUTEX_NORMAL); return do_open(bdev, &fake_file);
} }
EXPORT_SYMBOL(blkdev_get); EXPORT_SYMBOL(blkdev_get);
static int
blkdev_get_whole(struct block_device *bdev, mode_t mode, unsigned flags)
{
/*
* This crockload is due to bad choice of ->open() type.
* It will go away.
* For now, block device ->open() routine must _not_
* examine anything in 'inode' argument except ->i_rdev.
*/
struct file fake_file = {};
struct dentry fake_dentry = {};
fake_file.f_mode = mode;
fake_file.f_flags = flags;
fake_file.f_dentry = &fake_dentry;
fake_dentry.d_inode = bdev->bd_inode;
return do_open(bdev, &fake_file, BD_MUTEX_WHOLE);
}
static int
blkdev_get_partition(struct block_device *bdev, mode_t mode, unsigned flags)
{
/*
* This crockload is due to bad choice of ->open() type.
* It will go away.
* For now, block device ->open() routine must _not_
* examine anything in 'inode' argument except ->i_rdev.
*/
struct file fake_file = {};
struct dentry fake_dentry = {};
fake_file.f_mode = mode;
fake_file.f_flags = flags;
fake_file.f_dentry = &fake_dentry;
fake_dentry.d_inode = bdev->bd_inode;
return do_open(bdev, &fake_file, BD_MUTEX_PARTITION);
}
static int blkdev_open(struct inode * inode, struct file * filp) static int blkdev_open(struct inode * inode, struct file * filp)
{ {
struct block_device *bdev; struct block_device *bdev;
...@@ -1154,7 +1039,7 @@ static int blkdev_open(struct inode * inode, struct file * filp) ...@@ -1154,7 +1039,7 @@ static int blkdev_open(struct inode * inode, struct file * filp)
if (bdev == NULL) if (bdev == NULL)
return -ENOMEM; return -ENOMEM;
res = do_open(bdev, filp, BD_MUTEX_NORMAL); res = do_open(bdev, filp);
if (res) if (res)
return res; return res;
...@@ -1168,6 +1053,51 @@ static int blkdev_open(struct inode * inode, struct file * filp) ...@@ -1168,6 +1053,51 @@ static int blkdev_open(struct inode * inode, struct file * filp)
return res; return res;
} }
int blkdev_put(struct block_device *bdev)
{
int ret = 0;
struct inode *bd_inode = bdev->bd_inode;
struct gendisk *disk = bdev->bd_disk;
mutex_lock(&bdev->bd_mutex);
lock_kernel();
if (!--bdev->bd_openers) {
sync_blockdev(bdev);
kill_bdev(bdev);
}
if (bdev->bd_contains == bdev) {
if (disk->fops->release)
ret = disk->fops->release(bd_inode, NULL);
} else {
mutex_lock(&bdev->bd_contains->bd_mutex);
bdev->bd_contains->bd_part_count--;
mutex_unlock(&bdev->bd_contains->bd_mutex);
}
if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner;
put_disk(disk);
module_put(owner);
if (bdev->bd_contains != bdev) {
kobject_put(&bdev->bd_part->kobj);
bdev->bd_part = NULL;
}
bdev->bd_disk = NULL;
bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
if (bdev != bdev->bd_contains) {
blkdev_put(bdev->bd_contains);
}
bdev->bd_contains = NULL;
}
unlock_kernel();
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
return ret;
}
EXPORT_SYMBOL(blkdev_put);
static int blkdev_close(struct inode * inode, struct file * filp) static int blkdev_close(struct inode * inode, struct file * filp)
{ {
struct block_device *bdev = I_BDEV(filp->f_mapping->host); struct block_device *bdev = I_BDEV(filp->f_mapping->host);
......
...@@ -481,21 +481,6 @@ struct block_device { ...@@ -481,21 +481,6 @@ struct block_device {
unsigned long bd_private; unsigned long bd_private;
}; };
/*
* bdev->bd_mutex nesting subclasses for the lock validator:
*
* 0: normal
* 1: 'whole'
* 2: 'partition'
*/
enum bdev_bd_mutex_lock_class
{
BD_MUTEX_NORMAL,
BD_MUTEX_WHOLE,
BD_MUTEX_PARTITION
};
/* /*
* Radix-tree tags, for tagging dirty and writeback pages within the pagecache * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
* radix trees * radix trees
...@@ -1499,7 +1484,6 @@ extern void bd_set_size(struct block_device *, loff_t size); ...@@ -1499,7 +1484,6 @@ extern void bd_set_size(struct block_device *, loff_t size);
extern void bd_forget(struct inode *inode); extern void bd_forget(struct inode *inode);
extern void bdput(struct block_device *); extern void bdput(struct block_device *);
extern struct block_device *open_by_devnum(dev_t, unsigned); extern struct block_device *open_by_devnum(dev_t, unsigned);
extern struct block_device *open_partition_by_devnum(dev_t, unsigned);
extern const struct address_space_operations def_blk_aops; extern const struct address_space_operations def_blk_aops;
#else #else
static inline void bd_forget(struct inode *inode) {} static inline void bd_forget(struct inode *inode) {}
...@@ -1517,7 +1501,6 @@ extern int blkdev_driver_ioctl(struct inode *inode, struct file *file, ...@@ -1517,7 +1501,6 @@ extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
extern int blkdev_get(struct block_device *, mode_t, unsigned); extern int blkdev_get(struct block_device *, mode_t, unsigned);
extern int blkdev_put(struct block_device *); extern int blkdev_put(struct block_device *);
extern int blkdev_put_partition(struct block_device *);
extern int bd_claim(struct block_device *, void *); extern int bd_claim(struct block_device *, void *);
extern void bd_release(struct block_device *); extern void bd_release(struct block_device *);
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册