diff options
author | Vaughan Cao <vaughan.cao@oracle.com> | 2013-08-28 22:00:37 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-09-03 10:28:09 -0400 |
commit | 00b2d9d6d05b56fc1d77071ff8ccbd2c65b48dec (patch) | |
tree | a7d2ef1188d8c631f80316a6bc4f287eae3beb8e | |
parent | 15b06f9a02406e5460001db6d5af5c738cd3d4e7 (diff) |
[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 <vaughan.cao@oracle.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | drivers/scsi/sg.c | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 4efa9b5884b7..d4af13269e85 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c | |||
@@ -105,8 +105,6 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ; | |||
105 | static int sg_add(struct device *, struct class_interface *); | 105 | static int sg_add(struct device *, struct class_interface *); |
106 | static void sg_remove(struct device *, struct class_interface *); | 106 | static void sg_remove(struct device *, struct class_interface *); |
107 | 107 | ||
108 | static DEFINE_SPINLOCK(sg_open_exclusive_lock); | ||
109 | |||
110 | static DEFINE_IDR(sg_index_idr); | 108 | static DEFINE_IDR(sg_index_idr); |
111 | static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock | 109 | static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock |
112 | file descriptor list for device */ | 110 | file descriptor list for device */ |
@@ -176,7 +174,6 @@ typedef struct sg_device { /* holds the state of each scsi generic device */ | |||
176 | struct list_head sfds; | 174 | struct list_head sfds; |
177 | struct rw_semaphore o_sem; /* exclude open should hold this rwsem */ | 175 | struct rw_semaphore o_sem; /* exclude open should hold this rwsem */ |
178 | volatile char detached; /* 0->attached, 1->detached pending removal */ | 176 | volatile char detached; /* 0->attached, 1->detached pending removal */ |
179 | /* exclude protected by sg_open_exclusive_lock */ | ||
180 | char exclude; /* opened for exclusive access */ | 177 | char exclude; /* opened for exclusive access */ |
181 | char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */ | 178 | char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */ |
182 | struct gendisk *disk; | 179 | struct gendisk *disk; |
@@ -225,27 +222,6 @@ static int sg_allow_access(struct file *filp, unsigned char *cmd) | |||
225 | return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE); | 222 | return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE); |
226 | } | 223 | } |
227 | 224 | ||
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 | |||
249 | static int sfds_list_empty(Sg_device *sdp) | 225 | static int sfds_list_empty(Sg_device *sdp) |
250 | { | 226 | { |
251 | unsigned long flags; | 227 | unsigned long flags; |
@@ -317,7 +293,7 @@ sg_open(struct inode *inode, struct file *filp) | |||
317 | } | 293 | } |
318 | /* Since write lock is held, no need to check sfd_list */ | 294 | /* Since write lock is held, no need to check sfd_list */ |
319 | if (flags & O_EXCL) | 295 | if (flags & O_EXCL) |
320 | set_exclude(sdp, 1); | 296 | sdp->exclude = 1; /* used by release lock */ |
321 | 297 | ||
322 | if (sdp->detached) { | 298 | if (sdp->detached) { |
323 | retval = -ENODEV; | 299 | retval = -ENODEV; |
@@ -337,7 +313,7 @@ sg_open(struct inode *inode, struct file *filp) | |||
337 | retval = -ENOMEM; | 313 | retval = -ENOMEM; |
338 | sem_out: | 314 | sem_out: |
339 | if (flags & O_EXCL) { | 315 | if (flags & O_EXCL) { |
340 | set_exclude(sdp, 0); /* undo if error */ | 316 | sdp->exclude = 0; /* undo if error */ |
341 | up_write(&sdp->o_sem); | 317 | up_write(&sdp->o_sem); |
342 | } else | 318 | } else |
343 | up_read(&sdp->o_sem); | 319 | up_read(&sdp->o_sem); |
@@ -364,8 +340,8 @@ sg_release(struct inode *inode, struct file *filp) | |||
364 | return -ENXIO; | 340 | return -ENXIO; |
365 | SCSI_LOG_TIMEOUT(3, printk("sg_release: %s\n", sdp->disk->disk_name)); | 341 | SCSI_LOG_TIMEOUT(3, printk("sg_release: %s\n", sdp->disk->disk_name)); |
366 | 342 | ||
367 | excl = get_exclude(sdp); | 343 | excl = sdp->exclude; |
368 | set_exclude(sdp, 0); | 344 | sdp->exclude = 0; |
369 | if (excl) | 345 | if (excl) |
370 | up_write(&sdp->o_sem); | 346 | up_write(&sdp->o_sem); |
371 | else | 347 | else |
@@ -2622,7 +2598,7 @@ static int sg_proc_seq_show_debug(struct seq_file *s, void *v) | |||
2622 | scsidp->lun, | 2598 | scsidp->lun, |
2623 | scsidp->host->hostt->emulated); | 2599 | scsidp->host->hostt->emulated); |
2624 | seq_printf(s, " sg_tablesize=%d excl=%d\n", | 2600 | seq_printf(s, " sg_tablesize=%d excl=%d\n", |
2625 | sdp->sg_tablesize, get_exclude(sdp)); | 2601 | sdp->sg_tablesize, sdp->exclude); |
2626 | sg_proc_debug_helper(s, sdp); | 2602 | sg_proc_debug_helper(s, sdp); |
2627 | } | 2603 | } |
2628 | read_unlock_irqrestore(&sg_index_lock, iflags); | 2604 | read_unlock_irqrestore(&sg_index_lock, iflags); |