Commit 893544c4 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] bdev: bd_acquire() cleanup

From: viro@parcelfarce.linux.theplanet.co.uk <viro@parcelfarce.linux.theplanet.co.uk>

bd_acquire() made static, switched to returning the block_device it had
found.  Callers updated.
parent 7ca0643e
...@@ -387,26 +387,27 @@ void bdput(struct block_device *bdev) ...@@ -387,26 +387,27 @@ void bdput(struct block_device *bdev)
EXPORT_SYMBOL(bdput); EXPORT_SYMBOL(bdput);
int bd_acquire(struct inode *inode) static struct block_device *bd_acquire(struct inode *inode)
{ {
struct block_device *bdev; struct block_device *bdev;
spin_lock(&bdev_lock); spin_lock(&bdev_lock);
if (inode->i_bdev && igrab(inode->i_bdev->bd_inode)) { bdev = inode->i_bdev;
if (bdev && igrab(bdev->bd_inode)) {
spin_unlock(&bdev_lock); spin_unlock(&bdev_lock);
return 0; return bdev;
} }
spin_unlock(&bdev_lock); spin_unlock(&bdev_lock);
bdev = bdget(inode->i_rdev); bdev = bdget(inode->i_rdev);
if (!bdev) if (bdev) {
return -ENOMEM; spin_lock(&bdev_lock);
spin_lock(&bdev_lock); if (inode->i_bdev)
if (inode->i_bdev) __bd_forget(inode);
__bd_forget(inode); inode->i_bdev = bdev;
inode->i_bdev = bdev; inode->i_mapping = bdev->bd_inode->i_mapping;
inode->i_mapping = bdev->bd_inode->i_mapping; list_add(&inode->i_devices, &bdev->bd_inodes);
list_add(&inode->i_devices, &bdev->bd_inodes); spin_unlock(&bdev_lock);
spin_unlock(&bdev_lock); }
return 0; return bdev;
} }
/* Call when you free inode */ /* Call when you free inode */
...@@ -666,8 +667,7 @@ int blkdev_open(struct inode * inode, struct file * filp) ...@@ -666,8 +667,7 @@ int blkdev_open(struct inode * inode, struct file * filp)
*/ */
filp->f_flags |= O_LARGEFILE; filp->f_flags |= O_LARGEFILE;
bd_acquire(inode); bdev = bd_acquire(inode);
bdev = inode->i_bdev;
res = do_open(bdev, filp); res = do_open(bdev, filp);
if (res) if (res)
...@@ -829,11 +829,10 @@ struct block_device *lookup_bdev(const char *path) ...@@ -829,11 +829,10 @@ struct block_device *lookup_bdev(const char *path)
error = -EACCES; error = -EACCES;
if (nd.mnt->mnt_flags & MNT_NODEV) if (nd.mnt->mnt_flags & MNT_NODEV)
goto fail; goto fail;
error = bd_acquire(inode); error = -ENOMEM;
if (error) bdev = bd_acquire(inode);
if (!bdev)
goto fail; goto fail;
bdev = inode->i_bdev;
out: out:
path_release(&nd); path_release(&nd);
return bdev; return bdev;
......
...@@ -1955,15 +1955,9 @@ static int devfs_notify_change (struct dentry *dentry, struct iattr *iattr) ...@@ -1955,15 +1955,9 @@ static int devfs_notify_change (struct dentry *dentry, struct iattr *iattr)
return 0; return 0;
} /* End Function devfs_notify_change */ } /* End Function devfs_notify_change */
static void devfs_clear_inode (struct inode *inode)
{
if ( S_ISBLK (inode->i_mode) ) bdput (inode->i_bdev);
} /* End Function devfs_clear_inode */
static struct super_operations devfs_sops = static struct super_operations devfs_sops =
{ {
.drop_inode = generic_delete_inode, .drop_inode = generic_delete_inode,
.clear_inode = devfs_clear_inode,
.statfs = simple_statfs, .statfs = simple_statfs,
}; };
...@@ -2015,11 +2009,7 @@ static struct inode *_devfs_get_vfs_inode (struct super_block *sb, ...@@ -2015,11 +2009,7 @@ static struct inode *_devfs_get_vfs_inode (struct super_block *sb,
inode->i_rdev = de->u.cdev.dev; inode->i_rdev = de->u.cdev.dev;
} }
else if ( S_ISBLK (de->mode) ) else if ( S_ISBLK (de->mode) )
{ init_special_inode(inode, de->mode, de->u.bdev.dev);
inode->i_rdev = de->u.bdev.dev;
if (bd_acquire (inode) != 0)
PRINTK ("(%d): no block device from bdget()\n",(int)inode->i_ino);
}
else if ( S_ISFIFO (de->mode) ) else if ( S_ISFIFO (de->mode) )
inode->i_fop = &def_fifo_fops; inode->i_fop = &def_fifo_fops;
else if ( S_ISDIR (de->mode) ) else if ( S_ISDIR (de->mode) )
...@@ -2118,11 +2108,7 @@ static int devfs_open (struct inode *inode, struct file *file) ...@@ -2118,11 +2108,7 @@ static int devfs_open (struct inode *inode, struct file *file)
if (de == NULL) return -ENODEV; if (de == NULL) return -ENODEV;
if ( S_ISDIR (de->mode) ) return 0; if ( S_ISDIR (de->mode) ) return 0;
file->private_data = de->info; file->private_data = de->info;
if ( S_ISBLK (inode->i_mode) ) if (S_ISCHR(inode->i_mode)) {
{
file->f_op = &def_blk_fops;
err = def_blk_fops.open (inode, file); /* Module refcount unchanged */
} else if (S_ISCHR(inode->i_mode)) {
ops = devfs_get_ops (de); /* Now have module refcount */ ops = devfs_get_ops (de); /* Now have module refcount */
file->f_op = ops; file->f_op = ops;
if (file->f_op) if (file->f_op)
......
...@@ -1125,7 +1125,6 @@ enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW}; ...@@ -1125,7 +1125,6 @@ enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};
extern int register_blkdev(unsigned int, const char *); extern int register_blkdev(unsigned int, const char *);
extern int unregister_blkdev(unsigned int, const char *); extern int unregister_blkdev(unsigned int, const char *);
extern struct block_device *bdget(dev_t); extern struct block_device *bdget(dev_t);
extern int bd_acquire(struct inode *inode);
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 int blkdev_open(struct inode *, struct file *); extern int blkdev_open(struct inode *, struct file *);
......
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