Skip to content

Commit 00b2d9d

Browse files
Vaughan CaoJames Bottomley
authored andcommitted
[SCSI] sg: no need sg_open_exclusive_lock
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]>
1 parent 15b06f9 commit 00b2d9d

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

drivers/scsi/sg.c

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
105105
static int sg_add(struct device *, struct class_interface *);
106106
static void sg_remove(struct device *, struct class_interface *);
107107

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

228-
static int get_exclude(Sg_device *sdp)
229-
{
230-
unsigned long flags;
231-
int ret;
232-
233-
spin_lock_irqsave(&sg_open_exclusive_lock, flags);
234-
ret = sdp->exclude;
235-
spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
236-
return ret;
237-
}
238-
239-
static int set_exclude(Sg_device *sdp, char val)
240-
{
241-
unsigned long flags;
242-
243-
spin_lock_irqsave(&sg_open_exclusive_lock, flags);
244-
sdp->exclude = val;
245-
spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
246-
return val;
247-
}
248-
249225
static int sfds_list_empty(Sg_device *sdp)
250226
{
251227
unsigned long flags;
@@ -317,7 +293,7 @@ sg_open(struct inode *inode, struct file *filp)
317293
}
318294
/* Since write lock is held, no need to check sfd_list */
319295
if (flags & O_EXCL)
320-
set_exclude(sdp, 1);
296+
sdp->exclude = 1; /* used by release lock */
321297

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

367-
excl = get_exclude(sdp);
368-
set_exclude(sdp, 0);
343+
excl = sdp->exclude;
344+
sdp->exclude = 0;
369345
if (excl)
370346
up_write(&sdp->o_sem);
371347
else
@@ -2622,7 +2598,7 @@ static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
26222598
scsidp->lun,
26232599
scsidp->host->hostt->emulated);
26242600
seq_printf(s, " sg_tablesize=%d excl=%d\n",
2625-
sdp->sg_tablesize, get_exclude(sdp));
2601+
sdp->sg_tablesize, sdp->exclude);
26262602
sg_proc_debug_helper(s, sdp);
26272603
}
26282604
read_unlock_irqrestore(&sg_index_lock, iflags);

0 commit comments

Comments
 (0)