Skip to content

Commit

Permalink
[SCSI] sg: no need sg_open_exclusive_lock
Browse files Browse the repository at this point in the history
Open exclusive check is protected by o_sem, no need sg_open_exclusive_lock.
@exclude is used to record which type of rwsem we are holding.

Signed-off-by: Vaughan Cao <[email protected]>
Acked-by: Douglas Gilbert <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
  • Loading branch information
Vaughan Cao authored and James Bottomley committed Sep 3, 2013
1 parent 15b06f9 commit 00b2d9d
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions drivers/scsi/sg.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
static int sg_add(struct device *, struct class_interface *);
static void sg_remove(struct device *, struct class_interface *);

static DEFINE_SPINLOCK(sg_open_exclusive_lock);

static DEFINE_IDR(sg_index_idr);
static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock
file descriptor list for device */
Expand Down Expand Up @@ -176,7 +174,6 @@ typedef struct sg_device { /* holds the state of each scsi generic device */
struct list_head sfds;
struct rw_semaphore o_sem; /* exclude open should hold this rwsem */
volatile char detached; /* 0->attached, 1->detached pending removal */
/* exclude protected by sg_open_exclusive_lock */
char exclude; /* opened for exclusive access */
char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */
struct gendisk *disk;
Expand Down Expand Up @@ -225,27 +222,6 @@ static int sg_allow_access(struct file *filp, unsigned char *cmd)
return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE);
}

static int get_exclude(Sg_device *sdp)
{
unsigned long flags;
int ret;

spin_lock_irqsave(&sg_open_exclusive_lock, flags);
ret = sdp->exclude;
spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
return ret;
}

static int set_exclude(Sg_device *sdp, char val)
{
unsigned long flags;

spin_lock_irqsave(&sg_open_exclusive_lock, flags);
sdp->exclude = val;
spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
return val;
}

static int sfds_list_empty(Sg_device *sdp)
{
unsigned long flags;
Expand Down Expand Up @@ -317,7 +293,7 @@ sg_open(struct inode *inode, struct file *filp)
}
/* Since write lock is held, no need to check sfd_list */
if (flags & O_EXCL)
set_exclude(sdp, 1);
sdp->exclude = 1; /* used by release lock */

if (sdp->detached) {
retval = -ENODEV;
Expand All @@ -337,7 +313,7 @@ sg_open(struct inode *inode, struct file *filp)
retval = -ENOMEM;
sem_out:
if (flags & O_EXCL) {
set_exclude(sdp, 0); /* undo if error */
sdp->exclude = 0; /* undo if error */
up_write(&sdp->o_sem);
} else
up_read(&sdp->o_sem);
Expand All @@ -364,8 +340,8 @@ sg_release(struct inode *inode, struct file *filp)
return -ENXIO;
SCSI_LOG_TIMEOUT(3, printk("sg_release: %s\n", sdp->disk->disk_name));

excl = get_exclude(sdp);
set_exclude(sdp, 0);
excl = sdp->exclude;
sdp->exclude = 0;
if (excl)
up_write(&sdp->o_sem);
else
Expand Down Expand Up @@ -2622,7 +2598,7 @@ static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
scsidp->lun,
scsidp->host->hostt->emulated);
seq_printf(s, " sg_tablesize=%d excl=%d\n",
sdp->sg_tablesize, get_exclude(sdp));
sdp->sg_tablesize, sdp->exclude);
sg_proc_debug_helper(s, sdp);
}
read_unlock_irqrestore(&sg_index_lock, iflags);
Expand Down

0 comments on commit 00b2d9d

Please sign in to comment.