[SCSI] sg: use rwsem to solve race during exclusive open
authorVaughan Cao <vaughan.cao@oracle.com>
Thu, 29 Aug 2013 02:00:36 +0000 (10:00 +0800)
committerJames Bottomley <JBottomley@Parallels.com>
Tue, 3 Sep 2013 14:28:09 +0000 (07:28 -0700)
commit15b06f9a02406e5460001db6d5af5c738cd3d4e7
treea62209c714df581942342acb0a167889fe2e25da
parenta027b5b90eb6b5ec5c5890a5e4e198f458ae94cb
[SCSI] sg: use rwsem to solve race during exclusive open

A race condition may happen if two threads are both trying to open the same sg
with O_EXCL simultaneously. It's possible that they both find fsds list is
empty and get_exclude(sdp) returns 0, then they both call set_exclude() and
break out from wait_event_interruptible and resume open.

Now use rwsem to protect this process. Exclusive open gets write lock and
others get read lock. The lock will be held until file descriptor is closed.
This also leads 'exclude' only a status rather than a check mark.

Signed-off-by: Vaughan Cao <vaughan.cao@oracle.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/sg.c