Skip to content

Commit

Permalink
CIFS: Fix a deadlock when a file is reopened
Browse files Browse the repository at this point in the history
If we request reading or writing on a file that needs to be
reopened, it causes the deadlock: we are already holding rw
semaphore for reading and then we try to acquire it for writing
in cifs_relock_file. Fix this by acquiring the semaphore for
reading in cifs_relock_file due to we don't make any changes in
locks and don't need a write access.

CC: <[email protected]>
Signed-off-by: Pavel Shilovsky <[email protected]>
Acked-by: Jeff Layton <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
piastry authored and smfrench committed Jul 11, 2013
1 parent b33fcf1 commit 689c3db
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,10 @@ cifs_relock_file(struct cifsFileInfo *cfile)
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
int rc = 0;

/* we are going to update can_cache_brlcks here - need a write access */
down_write(&cinode->lock_sem);
down_read(&cinode->lock_sem);
if (cinode->can_cache_brlcks) {
/* can cache locks - no need to push them */
up_write(&cinode->lock_sem);
/* can cache locks - no need to relock */
up_read(&cinode->lock_sem);
return rc;
}

Expand All @@ -576,7 +575,7 @@ cifs_relock_file(struct cifsFileInfo *cfile)
else
rc = tcon->ses->server->ops->push_mand_locks(cfile);

up_write(&cinode->lock_sem);
up_read(&cinode->lock_sem);
return rc;
}

Expand Down

0 comments on commit 689c3db

Please sign in to comment.