Commit c039e313 authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Linus Torvalds

[PATCH] sem2mutex: blockdev #2

Semaphore to mutex conversion.

The conversion was generated via scripts, and the result was validated
automatically via a script as well.
Signed-off-by: default avatarArjan van de Ven <arjan@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Acked-by: default avatarJens Axboe <axboe@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6f87f0de
...@@ -42,9 +42,9 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -42,9 +42,9 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
return -EINVAL; return -EINVAL;
} }
/* partition number in use? */ /* partition number in use? */
down(&bdev->bd_sem); mutex_lock(&bdev->bd_mutex);
if (disk->part[part - 1]) { if (disk->part[part - 1]) {
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
return -EBUSY; return -EBUSY;
} }
/* overlap? */ /* overlap? */
...@@ -55,13 +55,13 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -55,13 +55,13 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
continue; continue;
if (!(start+length <= s->start_sect || if (!(start+length <= s->start_sect ||
start >= s->start_sect + s->nr_sects)) { start >= s->start_sect + s->nr_sects)) {
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
return -EBUSY; return -EBUSY;
} }
} }
/* all seems OK */ /* all seems OK */
add_partition(disk, part, start, length); add_partition(disk, part, start, length);
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
return 0; return 0;
case BLKPG_DEL_PARTITION: case BLKPG_DEL_PARTITION:
if (!disk->part[part-1]) if (!disk->part[part-1])
...@@ -71,9 +71,9 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -71,9 +71,9 @@ 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;
down(&bdevp->bd_sem); mutex_lock(&bdevp->bd_mutex);
if (bdevp->bd_openers) { if (bdevp->bd_openers) {
up(&bdevp->bd_sem); mutex_unlock(&bdevp->bd_mutex);
bdput(bdevp); bdput(bdevp);
return -EBUSY; return -EBUSY;
} }
...@@ -81,10 +81,10 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -81,10 +81,10 @@ 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);
down(&bdev->bd_sem); mutex_lock(&bdev->bd_mutex);
delete_partition(disk, part); delete_partition(disk, part);
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
up(&bdevp->bd_sem); mutex_unlock(&bdevp->bd_mutex);
bdput(bdevp); bdput(bdevp);
return 0; return 0;
...@@ -102,10 +102,10 @@ static int blkdev_reread_part(struct block_device *bdev) ...@@ -102,10 +102,10 @@ static int blkdev_reread_part(struct block_device *bdev)
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
if (down_trylock(&bdev->bd_sem)) if (!mutex_trylock(&bdev->bd_mutex))
return -EBUSY; return -EBUSY;
res = rescan_partitions(disk, bdev); res = rescan_partitions(disk, bdev);
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
return res; return res;
} }
......
...@@ -310,12 +310,12 @@ static int rd_ioctl(struct inode *inode, struct file *file, ...@@ -310,12 +310,12 @@ static int rd_ioctl(struct inode *inode, struct file *file,
* cache * cache
*/ */
error = -EBUSY; error = -EBUSY;
down(&bdev->bd_sem); mutex_lock(&bdev->bd_mutex);
if (bdev->bd_openers <= 2) { if (bdev->bd_openers <= 2) {
truncate_inode_pages(bdev->bd_inode->i_mapping, 0); truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
error = 0; error = 0;
} }
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
return error; return error;
} }
......
...@@ -151,9 +151,9 @@ dasd_ioctl_enable(struct block_device *bdev, int no, long args) ...@@ -151,9 +151,9 @@ dasd_ioctl_enable(struct block_device *bdev, int no, long args)
return -ENODEV; return -ENODEV;
dasd_enable_device(device); dasd_enable_device(device);
/* Formatting the dasd device can change the capacity. */ /* Formatting the dasd device can change the capacity. */
down(&bdev->bd_sem); mutex_lock(&bdev->bd_mutex);
i_size_write(bdev->bd_inode, (loff_t)get_capacity(device->gdp) << 9); i_size_write(bdev->bd_inode, (loff_t)get_capacity(device->gdp) << 9);
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
return 0; return 0;
} }
...@@ -184,9 +184,9 @@ dasd_ioctl_disable(struct block_device *bdev, int no, long args) ...@@ -184,9 +184,9 @@ dasd_ioctl_disable(struct block_device *bdev, int no, long args)
* Set i_size to zero, since read, write, etc. check against this * Set i_size to zero, since read, write, etc. check against this
* value. * value.
*/ */
down(&bdev->bd_sem); mutex_lock(&bdev->bd_mutex);
i_size_write(bdev->bd_inode, 0); i_size_write(bdev->bd_inode, 0);
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
return 0; return 0;
} }
......
...@@ -265,8 +265,8 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) ...@@ -265,8 +265,8 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
SLAB_CTOR_CONSTRUCTOR) SLAB_CTOR_CONSTRUCTOR)
{ {
memset(bdev, 0, sizeof(*bdev)); memset(bdev, 0, sizeof(*bdev));
sema_init(&bdev->bd_sem, 1); mutex_init(&bdev->bd_mutex);
sema_init(&bdev->bd_mount_sem, 1); mutex_init(&bdev->bd_mount_mutex);
INIT_LIST_HEAD(&bdev->bd_inodes); INIT_LIST_HEAD(&bdev->bd_inodes);
INIT_LIST_HEAD(&bdev->bd_list); INIT_LIST_HEAD(&bdev->bd_list);
inode_init_once(&ei->vfs_inode); inode_init_once(&ei->vfs_inode);
...@@ -574,7 +574,7 @@ static int do_open(struct block_device *bdev, struct file *file) ...@@ -574,7 +574,7 @@ static int do_open(struct block_device *bdev, struct file *file)
} }
owner = disk->fops->owner; owner = disk->fops->owner;
down(&bdev->bd_sem); 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;
...@@ -605,21 +605,21 @@ static int do_open(struct block_device *bdev, struct file *file) ...@@ -605,21 +605,21 @@ static int do_open(struct block_device *bdev, struct file *file)
if (ret) if (ret)
goto out_first; goto out_first;
bdev->bd_contains = whole; bdev->bd_contains = whole;
down(&whole->bd_sem); 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 =
whole->bd_inode->i_data.backing_dev_info; whole->bd_inode->i_data.backing_dev_info;
if (!(disk->flags & GENHD_FL_UP) || !p || !p->nr_sects) { if (!(disk->flags & GENHD_FL_UP) || !p || !p->nr_sects) {
whole->bd_part_count--; whole->bd_part_count--;
up(&whole->bd_sem); mutex_unlock(&whole->bd_mutex);
ret = -ENXIO; ret = -ENXIO;
goto out_first; goto out_first;
} }
kobject_get(&p->kobj); kobject_get(&p->kobj);
bdev->bd_part = p; bdev->bd_part = p;
bd_set_size(bdev, (loff_t) p->nr_sects << 9); bd_set_size(bdev, (loff_t) p->nr_sects << 9);
up(&whole->bd_sem); mutex_unlock(&whole->bd_mutex);
} }
} else { } else {
put_disk(disk); put_disk(disk);
...@@ -633,13 +633,13 @@ static int do_open(struct block_device *bdev, struct file *file) ...@@ -633,13 +633,13 @@ static int do_open(struct block_device *bdev, struct file *file)
if (bdev->bd_invalidated) if (bdev->bd_invalidated)
rescan_partitions(bdev->bd_disk, bdev); rescan_partitions(bdev->bd_disk, bdev);
} else { } else {
down(&bdev->bd_contains->bd_sem); mutex_lock(&bdev->bd_contains->bd_mutex);
bdev->bd_contains->bd_part_count++; bdev->bd_contains->bd_part_count++;
up(&bdev->bd_contains->bd_sem); mutex_unlock(&bdev->bd_contains->bd_mutex);
} }
} }
bdev->bd_openers++; bdev->bd_openers++;
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
unlock_kernel(); unlock_kernel();
return 0; return 0;
...@@ -652,7 +652,7 @@ static int do_open(struct block_device *bdev, struct file *file) ...@@ -652,7 +652,7 @@ static int do_open(struct block_device *bdev, struct file *file)
put_disk(disk); put_disk(disk);
module_put(owner); module_put(owner);
out: out:
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
unlock_kernel(); unlock_kernel();
if (ret) if (ret)
bdput(bdev); bdput(bdev);
...@@ -714,7 +714,7 @@ int blkdev_put(struct block_device *bdev) ...@@ -714,7 +714,7 @@ int blkdev_put(struct block_device *bdev)
struct inode *bd_inode = bdev->bd_inode; struct inode *bd_inode = bdev->bd_inode;
struct gendisk *disk = bdev->bd_disk; struct gendisk *disk = bdev->bd_disk;
down(&bdev->bd_sem); mutex_lock(&bdev->bd_mutex);
lock_kernel(); lock_kernel();
if (!--bdev->bd_openers) { if (!--bdev->bd_openers) {
sync_blockdev(bdev); sync_blockdev(bdev);
...@@ -724,9 +724,9 @@ int blkdev_put(struct block_device *bdev) ...@@ -724,9 +724,9 @@ int blkdev_put(struct block_device *bdev)
if (disk->fops->release) if (disk->fops->release)
ret = disk->fops->release(bd_inode, NULL); ret = disk->fops->release(bd_inode, NULL);
} else { } else {
down(&bdev->bd_contains->bd_sem); mutex_lock(&bdev->bd_contains->bd_mutex);
bdev->bd_contains->bd_part_count--; bdev->bd_contains->bd_part_count--;
up(&bdev->bd_contains->bd_sem); mutex_unlock(&bdev->bd_contains->bd_mutex);
} }
if (!bdev->bd_openers) { if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner; struct module *owner = disk->fops->owner;
...@@ -746,7 +746,7 @@ int blkdev_put(struct block_device *bdev) ...@@ -746,7 +746,7 @@ int blkdev_put(struct block_device *bdev)
bdev->bd_contains = NULL; bdev->bd_contains = NULL;
} }
unlock_kernel(); unlock_kernel();
up(&bdev->bd_sem); mutex_unlock(&bdev->bd_mutex);
bdput(bdev); bdput(bdev);
return ret; return ret;
} }
......
...@@ -201,7 +201,7 @@ int fsync_bdev(struct block_device *bdev) ...@@ -201,7 +201,7 @@ int fsync_bdev(struct block_device *bdev)
* freeze_bdev -- lock a filesystem and force it into a consistent state * freeze_bdev -- lock a filesystem and force it into a consistent state
* @bdev: blockdevice to lock * @bdev: blockdevice to lock
* *
* This takes the block device bd_mount_sem to make sure no new mounts * This takes the block device bd_mount_mutex to make sure no new mounts
* happen on bdev until thaw_bdev() is called. * happen on bdev until thaw_bdev() is called.
* If a superblock is found on this device, we take the s_umount semaphore * If a superblock is found on this device, we take the s_umount semaphore
* on it to make sure nobody unmounts until the snapshot creation is done. * on it to make sure nobody unmounts until the snapshot creation is done.
...@@ -210,7 +210,7 @@ struct super_block *freeze_bdev(struct block_device *bdev) ...@@ -210,7 +210,7 @@ struct super_block *freeze_bdev(struct block_device *bdev)
{ {
struct super_block *sb; struct super_block *sb;
down(&bdev->bd_mount_sem); mutex_lock(&bdev->bd_mount_mutex);
sb = get_super(bdev); sb = get_super(bdev);
if (sb && !(sb->s_flags & MS_RDONLY)) { if (sb && !(sb->s_flags & MS_RDONLY)) {
sb->s_frozen = SB_FREEZE_WRITE; sb->s_frozen = SB_FREEZE_WRITE;
...@@ -264,7 +264,7 @@ void thaw_bdev(struct block_device *bdev, struct super_block *sb) ...@@ -264,7 +264,7 @@ void thaw_bdev(struct block_device *bdev, struct super_block *sb)
drop_super(sb); drop_super(sb);
} }
up(&bdev->bd_mount_sem); mutex_unlock(&bdev->bd_mount_mutex);
} }
EXPORT_SYMBOL(thaw_bdev); EXPORT_SYMBOL(thaw_bdev);
......
...@@ -693,9 +693,9 @@ struct super_block *get_sb_bdev(struct file_system_type *fs_type, ...@@ -693,9 +693,9 @@ struct super_block *get_sb_bdev(struct file_system_type *fs_type,
* will protect the lockfs code from trying to start a snapshot * will protect the lockfs code from trying to start a snapshot
* while we are mounting * while we are mounting
*/ */
down(&bdev->bd_mount_sem); mutex_lock(&bdev->bd_mount_mutex);
s = sget(fs_type, test_bdev_super, set_bdev_super, bdev); s = sget(fs_type, test_bdev_super, set_bdev_super, bdev);
up(&bdev->bd_mount_sem); mutex_unlock(&bdev->bd_mount_mutex);
if (IS_ERR(s)) if (IS_ERR(s))
goto out; goto out;
......
...@@ -397,8 +397,8 @@ struct block_device { ...@@ -397,8 +397,8 @@ struct block_device {
dev_t bd_dev; /* not a kdev_t - it's a search key */ dev_t bd_dev; /* not a kdev_t - it's a search key */
struct inode * bd_inode; /* will die */ struct inode * bd_inode; /* will die */
int bd_openers; int bd_openers;
struct semaphore bd_sem; /* open/close mutex */ struct mutex bd_mutex; /* open/close mutex */
struct semaphore bd_mount_sem; /* mount mutex */ struct mutex bd_mount_mutex; /* mount mutex */
struct list_head bd_inodes; struct list_head bd_inodes;
void * bd_holder; void * bd_holder;
int bd_holders; int bd_holders;
......
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