Commit 689c3db4d57a73bee6c5ad7797fce7b54d32a87c

Authored by Pavel Shilovsky
Committed by Steve French
1 parent b33fcf1c9d

CIFS: Fix a deadlock when a file is reopened

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: <stable@vger.kernel.org>
Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
Acked-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>

Showing 1 changed file with 4 additions and 5 deletions Side-by-side Diff

... ... @@ -561,11 +561,10 @@
561 561 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
562 562 int rc = 0;
563 563  
564   - /* we are going to update can_cache_brlcks here - need a write access */
565   - down_write(&cinode->lock_sem);
  564 + down_read(&cinode->lock_sem);
566 565 if (cinode->can_cache_brlcks) {
567   - /* can cache locks - no need to push them */
568   - up_write(&cinode->lock_sem);
  566 + /* can cache locks - no need to relock */
  567 + up_read(&cinode->lock_sem);
569 568 return rc;
570 569 }
571 570  
... ... @@ -576,7 +575,7 @@
576 575 else
577 576 rc = tcon->ses->server->ops->push_mand_locks(cfile);
578 577  
579   - up_write(&cinode->lock_sem);
  578 + up_read(&cinode->lock_sem);
580 579 return rc;
581 580 }
582 581