From patchwork Tue Oct 11 22:34:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 9371833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 614D36048F for ; Tue, 11 Oct 2016 22:34:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49100290FC for ; Tue, 11 Oct 2016 22:34:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DBF229106; Tue, 11 Oct 2016 22:34:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D25A1290FC for ; Tue, 11 Oct 2016 22:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754594AbcJKWeR (ORCPT ); Tue, 11 Oct 2016 18:34:17 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34683 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754591AbcJKWeQ (ORCPT ); Tue, 11 Oct 2016 18:34:16 -0400 Received: by mail-pf0-f194.google.com with SMTP id 128so1391427pfz.1 for ; Tue, 11 Oct 2016 15:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=g3eVn0KDtW66UIew1FmIiVAJQNB5e6PqPX2n8sxV8ug=; b=ncFodilukVcXPmpz5pfwLmo0bzu5tQOUVfm6n50LHCvGG48oARB+AdXCjPMl6QI2vV GBA3BTU2WjQEfnZpdCdEjGr6FdFa5LJ2R38h4e7tPu/PPMs0U4HSaBF+nO6xAeZihn7a 9KW4arHbmi+n29jethSWxecI5Au2VEoVoFGP1TK39ht/7//rw0oAms8PeFjraEwd4fFl vfcKmGd40oGuxAogFlNHkqKGZvf59yY2pcPp31+7VDeV3hSJddYhJU2kTf235qvo6wag qHFmNtvz2DzWSXSv1ewlcYwx6JTACwl6Yb2A/RpyFfwBSO2KHT5Hs4rGafVWHQSFh+lv 2Mag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=g3eVn0KDtW66UIew1FmIiVAJQNB5e6PqPX2n8sxV8ug=; b=hLGbuGj7JzXS1+I6nn8e1r/ISqnPmMY28UexKtcFBONplPfjujiAdpXfafxZnYGNdd 13zV+VdsTd3dankzLWCCOEaHmrqP3mcMbX40U09/oCA8vpjgbNUUf4GqvRNIpZaRTqzh pelwlmdbbBXA0PPRIdulg2+MTNosIgY6hHhUwE5fK6+G/m1hOy4RdvzvoZNQOI1w3iKW DsQb8WNcPGU0wTGbb4bZiF/x1vlQsCYd4+KSMvwItIIxbyE/9APzQbsNb4Mm+qEkdp3I Ax5ZwgTAcUxZfRAyN3SgPf8N6Dwd2q+VdiayO1J310fS7zcNsr9jwd6vT792U55mr92h DLIA== X-Gm-Message-State: AA6/9RkXn6u2Wbg0QYVhUo0nm8ncat11ozienVNJ6eNByPf+8s88IPvXRrAiCQiLGNxtfQ== X-Received: by 10.99.149.28 with SMTP id p28mr4596921pgd.150.1476225255395; Tue, 11 Oct 2016 15:34:15 -0700 (PDT) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:5::63b]) by smtp.gmail.com with ESMTPSA id o9sm265691pac.27.2016.10.11.15.34.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Oct 2016 15:34:14 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs Subject: [PATCH 1/3] CIFS: Fix tcon and file locking Date: Tue, 11 Oct 2016 15:34:05 -0700 Message-Id: <1476225247-30177-1-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pavel Shilovsky This fix is supposed to be squashed into "Clarify locking of cifs file and tcon structures and make more granular". Signed-off-by: Pavel Shilovsky --- fs/cifs/file.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 1e7c625..20801dc 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -318,14 +318,14 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, oplock = 0; } + spin_lock(&tcon->open_file_lock); if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE && oplock) oplock = fid->pending_open->oplock; - cifs_del_pending_open(fid->pending_open); + list_del(&fid->pending_open->olist); fid->purge_cache = false; server->ops->set_fid(cfile, fid, oplock); - spin_lock(&tcon->open_file_lock); list_add(&cfile->tlist, &tcon->openFileList); /* if readable file instance put first in list*/ @@ -354,7 +354,7 @@ cifsFileInfo_get(struct cifsFileInfo *cifs_file) /* * Release a reference on the file private data. This may involve closing * the filehandle out on the server. Must be called without holding - * cifs_file->file_info_lock. + * tcon->open_file_lock and cifs_file->file_info_lock. */ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) { @@ -369,11 +369,15 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) struct cifs_pending_open open; bool oplock_break_cancelled; + spin_lock(&tcon->open_file_lock); + spin_lock(&cifs_file->file_info_lock); if (--cifs_file->count > 0) { spin_unlock(&cifs_file->file_info_lock); + spin_unlock(&tcon->open_file_lock); return; } + spin_unlock(&cifs_file->file_info_lock); if (server->ops->get_lease_key) server->ops->get_lease_key(inode, &fid); @@ -397,7 +401,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) set_bit(CIFS_INO_INVALID_MAPPING, &cifsi->flags); cifs_set_oplock_level(cifsi, 0); } - spin_unlock(&cifs_file->file_info_lock); + + spin_unlock(&tcon->open_file_lock); oplock_break_cancelled = cancel_work_sync(&cifs_file->oplock_break); @@ -1765,7 +1770,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode, if (!open_file->invalidHandle) { /* found a good file */ /* lock it so it will not be closed on us */ - cifsFileInfo_get_locked(open_file); + cifsFileInfo_get(open_file); spin_unlock(&tcon->open_file_lock); return open_file; } /* else might as well continue, and look for @@ -1819,7 +1824,7 @@ refind_writable: if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { if (!open_file->invalidHandle) { /* found a good writable file */ - cifsFileInfo_get_locked(open_file); + cifsFileInfo_get(open_file); spin_unlock(&tcon->open_file_lock); return open_file; } else { @@ -1836,9 +1841,7 @@ refind_writable: if (inv_file) { any_available = false; - spin_lock(&inv_file->file_info_lock); - cifsFileInfo_get_locked(inv_file); - spin_unlock(&inv_file->file_info_lock); + cifsFileInfo_get(inv_file); } spin_unlock(&tcon->open_file_lock);