Skip to content

Commit

Permalink
block: autoconvert trivial BKL users to private mutex
Browse files Browse the repository at this point in the history
The block device drivers have all gained new lock_kernel
calls from a recent pushdown, and some of the drivers
were already using the BKL before.

This turns the BKL into a set of per-driver mutexes.
Still need to check whether this is safe to do.

file=$1
name=$2
if grep -q lock_kernel ${file} ; then
    if grep -q 'include.*linux.mutex.h' ${file} ; then
            sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
    else
            sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
    fi
    sed -i ${file} \
        -e "/^#include.*linux.mutex.h/,$ {
                1,/^\(static\|int\|long\)/ {
                     /^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);

} }"  \
    -e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
    -e '/[      ]*cycle_kernel_lock();/d'
else
    sed -i -e '/include.*\<smp_lock.h\>/d' ${file}  \
                -e '/cycle_kernel_lock()/d'
fi

Signed-off-by: Arnd Bergmann <[email protected]>
  • Loading branch information
arndb committed Oct 5, 2010
1 parent 613655f commit 2a48fc0
Show file tree
Hide file tree
Showing 43 changed files with 277 additions and 250 deletions.
3 changes: 0 additions & 3 deletions block/bsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <linux/uio.h>
#include <linux/idr.h>
#include <linux/bsg.h>
#include <linux/smp_lock.h>
#include <linux/slab.h>

#include <scsi/scsi.h>
Expand Down Expand Up @@ -843,9 +842,7 @@ static int bsg_open(struct inode *inode, struct file *file)
{
struct bsg_device *bd;

lock_kernel();
bd = bsg_get_device(inode, file);
unlock_kernel();

if (IS_ERR(bd))
return PTR_ERR(bd);
Expand Down
11 changes: 6 additions & 5 deletions drivers/block/DAC960.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <linux/ioport.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/reboot.h>
Expand All @@ -54,6 +54,7 @@
#define DAC960_GAM_MINOR 252


static DEFINE_MUTEX(DAC960_mutex);
static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
static int DAC960_ControllerCount;
static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
Expand Down Expand Up @@ -81,7 +82,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
int drive_nr = (long)disk->private_data;
int ret = -ENXIO;

lock_kernel();
mutex_lock(&DAC960_mutex);
if (p->FirmwareType == DAC960_V1_Controller) {
if (p->V1.LogicalDriveInformation[drive_nr].
LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
Expand All @@ -99,7 +100,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
goto out;
ret = 0;
out:
unlock_kernel();
mutex_unlock(&DAC960_mutex);
return ret;
}

Expand Down Expand Up @@ -6625,7 +6626,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
long ErrorCode = 0;
if (!capable(CAP_SYS_ADMIN)) return -EACCES;

lock_kernel();
mutex_lock(&DAC960_mutex);
switch (Request)
{
case DAC960_IOCTL_GET_CONTROLLER_COUNT:
Expand Down Expand Up @@ -7056,7 +7057,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
default:
ErrorCode = -ENOTTY;
}
unlock_kernel();
mutex_unlock(&DAC960_mutex);
return ErrorCode;
}

Expand Down
19 changes: 10 additions & 9 deletions drivers/block/amiflop.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#include <linux/hdreg.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/amifdreg.h>
#include <linux/amifd.h>
#include <linux/buffer_head.h>
Expand Down Expand Up @@ -109,6 +109,7 @@
#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */
#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */

static DEFINE_MUTEX(amiflop_mutex);
static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */

module_param(fd_def_df0, ulong, 0);
Expand Down Expand Up @@ -1506,9 +1507,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
{
int ret;

lock_kernel();
mutex_lock(&amiflop_mutex);
ret = fd_locked_ioctl(bdev, mode, cmd, param);
unlock_kernel();
mutex_unlock(&amiflop_mutex);

return ret;
}
Expand Down Expand Up @@ -1555,11 +1556,11 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
int old_dev;
unsigned long flags;

lock_kernel();
mutex_lock(&amiflop_mutex);
old_dev = fd_device[drive];

if (fd_ref[drive] && old_dev != system) {
unlock_kernel();
mutex_unlock(&amiflop_mutex);
return -EBUSY;
}

Expand All @@ -1575,7 +1576,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
rel_fdc();

if (wrprot) {
unlock_kernel();
mutex_unlock(&amiflop_mutex);
return -EROFS;
}
}
Expand All @@ -1594,7 +1595,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive,
unit[drive].type->name, data_types[system].name);

unlock_kernel();
mutex_unlock(&amiflop_mutex);
return 0;
}

Expand All @@ -1603,7 +1604,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
struct amiga_floppy_struct *p = disk->private_data;
int drive = p - unit;

lock_kernel();
mutex_lock(&amiflop_mutex);
if (unit[drive].dirty == 1) {
del_timer (flush_track_timer + drive);
non_int_flush_track (drive);
Expand All @@ -1617,7 +1618,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
/* the mod_use counter is handled this way */
floppy_off (drive | 0x40000000);
#endif
unlock_kernel();
mutex_unlock(&amiflop_mutex);
return 0;
}

Expand Down
9 changes: 5 additions & 4 deletions drivers/block/aoe/aoeblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#include <linux/slab.h>
#include <linux/genhd.h>
#include <linux/netdevice.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include "aoe.h"

static DEFINE_MUTEX(aoeblk_mutex);
static struct kmem_cache *buf_pool_cache;

static ssize_t aoedisk_show_state(struct device *dev,
Expand Down Expand Up @@ -125,16 +126,16 @@ aoeblk_open(struct block_device *bdev, fmode_t mode)
struct aoedev *d = bdev->bd_disk->private_data;
ulong flags;

lock_kernel();
mutex_lock(&aoeblk_mutex);
spin_lock_irqsave(&d->lock, flags);
if (d->flags & DEVFL_UP) {
d->nopen++;
spin_unlock_irqrestore(&d->lock, flags);
unlock_kernel();
mutex_unlock(&aoeblk_mutex);
return 0;
}
spin_unlock_irqrestore(&d->lock, flags);
unlock_kernel();
mutex_unlock(&aoeblk_mutex);
return -ENODEV;
}

Expand Down
9 changes: 5 additions & 4 deletions drivers/block/aoe/aoechr.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/skbuff.h>
#include "aoe.h"

Expand Down Expand Up @@ -37,6 +37,7 @@ struct ErrMsg {
char *msg;
};

static DEFINE_MUTEX(aoechr_mutex);
static struct ErrMsg emsgs[NMSG];
static int emsgs_head_idx, emsgs_tail_idx;
static struct completion emsgs_comp;
Expand Down Expand Up @@ -183,16 +184,16 @@ aoechr_open(struct inode *inode, struct file *filp)
{
int n, i;

lock_kernel();
mutex_lock(&aoechr_mutex);
n = iminor(inode);
filp->private_data = (void *) (unsigned long) n;

for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
if (chardevs[i].minor == n) {
unlock_kernel();
mutex_unlock(&aoechr_mutex);
return 0;
}
unlock_kernel();
mutex_unlock(&aoechr_mutex);
return -EINVAL;
}

Expand Down
15 changes: 8 additions & 7 deletions drivers/block/ataflop.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>

#include <asm/atafd.h>
#include <asm/atafdreg.h>
Expand All @@ -79,6 +79,7 @@

#undef DEBUG

static DEFINE_MUTEX(ataflop_mutex);
static struct request_queue *floppy_queue;
static struct request *fd_request;

Expand Down Expand Up @@ -1671,9 +1672,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
{
int ret;

lock_kernel();
mutex_lock(&ataflop_mutex);
ret = fd_locked_ioctl(bdev, mode, cmd, arg);
unlock_kernel();
mutex_unlock(&ataflop_mutex);

return ret;
}
Expand Down Expand Up @@ -1854,24 +1855,24 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
{
int ret;

lock_kernel();
mutex_lock(&ataflop_mutex);
ret = floppy_open(bdev, mode);
unlock_kernel();
mutex_unlock(&ataflop_mutex);

return ret;
}

static int floppy_release(struct gendisk *disk, fmode_t mode)
{
struct atari_floppy_struct *p = disk->private_data;
lock_kernel();
mutex_lock(&ataflop_mutex);
if (p->ref < 0)
p->ref = 0;
else if (!p->ref--) {
printk(KERN_ERR "floppy_release with fd_ref == 0");
p->ref = 0;
}
unlock_kernel();
mutex_unlock(&ataflop_mutex);
return 0;
}

Expand Down
7 changes: 4 additions & 3 deletions drivers/block/brd.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <linux/blkdev.h>
#include <linux/bio.h>
#include <linux/highmem.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/radix-tree.h>
#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
#include <linux/slab.h>
Expand Down Expand Up @@ -55,6 +55,7 @@ struct brd_device {
/*
* Look up and return a brd's page for a given sector.
*/
static DEFINE_MUTEX(brd_mutex);
static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
{
pgoff_t idx;
Expand Down Expand Up @@ -402,7 +403,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
* ram device BLKFLSBUF has special semantics, we want to actually
* release and destroy the ramdisk data.
*/
lock_kernel();
mutex_lock(&brd_mutex);
mutex_lock(&bdev->bd_mutex);
error = -EBUSY;
if (bdev->bd_openers <= 1) {
Expand All @@ -419,7 +420,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
error = 0;
}
mutex_unlock(&bdev->bd_mutex);
unlock_kernel();
mutex_unlock(&brd_mutex);

return error;
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/block/cciss.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <linux/pci.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/delay.h>
#include <linux/major.h>
#include <linux/fs.h>
Expand Down Expand Up @@ -66,6 +65,7 @@ MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
MODULE_VERSION("3.6.26");
MODULE_LICENSE("GPL");

static DEFINE_MUTEX(cciss_mutex);
static int cciss_allow_hpsa;
module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(cciss_allow_hpsa,
Expand Down Expand Up @@ -1059,9 +1059,9 @@ static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
{
int ret;

lock_kernel();
mutex_lock(&cciss_mutex);
ret = cciss_open(bdev, mode);
unlock_kernel();
mutex_unlock(&cciss_mutex);

return ret;
}
Expand All @@ -1074,23 +1074,23 @@ static int cciss_release(struct gendisk *disk, fmode_t mode)
ctlr_info_t *h;
drive_info_struct *drv;

lock_kernel();
mutex_lock(&cciss_mutex);
h = get_host(disk);
drv = get_drv(disk);
dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name);
drv->usage_count--;
h->usage_count--;
unlock_kernel();
mutex_unlock(&cciss_mutex);
return 0;
}

static int do_ioctl(struct block_device *bdev, fmode_t mode,
unsigned cmd, unsigned long arg)
{
int ret;
lock_kernel();
mutex_lock(&cciss_mutex);
ret = cciss_ioctl(bdev, mode, cmd, arg);
unlock_kernel();
mutex_unlock(&cciss_mutex);
return ret;
}

Expand Down
Loading

0 comments on commit 2a48fc0

Please sign in to comment.