From patchwork Tue Oct 11 22:34:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 9371835 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 E29FC6048F for ; Tue, 11 Oct 2016 22:34:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB03E290FC for ; Tue, 11 Oct 2016 22:34:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF94029106; Tue, 11 Oct 2016 22:34:19 +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 6D3F3290FC for ; Tue, 11 Oct 2016 22:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754614AbcJKWeT (ORCPT ); Tue, 11 Oct 2016 18:34:19 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35128 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754591AbcJKWeS (ORCPT ); Tue, 11 Oct 2016 18:34:18 -0400 Received: by mail-pf0-f194.google.com with SMTP id s8so1383804pfj.2 for ; Tue, 11 Oct 2016 15:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=qulrEz+Adjb5lsiZlKU5OrO17Ly/avLciHE1CTG5ynQ=; b=NftNBWs4O7AThjx8BRdbU2xdVzLc1YXO5qWBBNhg0y6Kx9+3Pkr1trUv/W1uXPEtor a75Yweba5r0G1ILrmnJdH2o0U/VN/mj1aXymNXlWyPv0HYZHQfITkrgPeg0T7onb6Rnd BLoimIeiARIDx4ZPz+RFsvIqEwPctqKxN8Rek3gu20LtAiDQXdU7eTRBLq9Ncv8+Y2sq UrTxZIN5mSnaA7ZSPfIpkjnHwAiXwJNs95R4FMp+E8kGxmhfpmnvd1iymhKxB0yNstC2 jLHa8lim4gBrdpixxCk4AbBWh8bLd1NvTDLbH7lnsW8gDw3DHckKVpCuV3AzHgw1ig03 HoIg== 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:in-reply-to :references; bh=qulrEz+Adjb5lsiZlKU5OrO17Ly/avLciHE1CTG5ynQ=; b=S1/83VRN/KeWDRKeiSCW53yquYRNB0IpLIWP9OwL8xW/MQwPITYhbk+6NqF7HyaLVU 23XAN9ojAs4i2PmfAKw8Y6Y9k8PNQpdzh/VbDSi7s/CKr8akR5zrPui45mlg3naDGCgv Jx2feGob2e8Bsi9lL+0jaT6KfgehQRHGLjqSyWdDEXH+8E0LYeNFB0EqPqQrmTebptz8 pLXKHpvk7dpky+EQ4nl7RFT1N0fAcd2wX2HpmYtcF+CzWxCGK2IX1i74lsPC95WGQUqU SYDpyIIBOD2Onpl8Ircpr7TYIwLhVhuFdsilOZEetYor6tITnljOeir82yaSrLPlqTUr 49mg== X-Gm-Message-State: AA6/9Rlfh02td6XQSS+xLcqgfJ9Q7ryZ0E3jReQipM1tt75xrMxKkGagmQB4iAAVwA9bMA== X-Received: by 10.99.143.82 with SMTP id r18mr4576548pgn.171.1476225257488; Tue, 11 Oct 2016 15:34:17 -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.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Oct 2016 15:34:16 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs Subject: [PATCH 2/3] CIFS: Fix persistent handles re-opening on reconnect Date: Tue, 11 Oct 2016 15:34:06 -0700 Message-Id: <1476225247-30177-2-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476225247-30177-1-git-send-email-piastryyy@gmail.com> References: <1476225247-30177-1-git-send-email-piastryyy@gmail.com> 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 openFileList of tcon can be changed while cifs_reopen_file() is called that can lead to an unexpected behavior when we return to the loop. Fix this by introducing a temp list for keeping all file handles that need to be reopen. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsglob.h | 1 + fs/cifs/file.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 0eaed19..149ac16 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -1067,6 +1067,7 @@ struct cifsFileInfo { kuid_t uid; /* allows finding which FileInfo structure */ __u32 pid; /* process id who opened file */ struct cifs_fid fid; /* file id from remote */ + struct list_head rlist; /* reconnect list */ /* BB add lock scope info here if needed */ ; /* lock scope id (0 if none) */ struct dentry *dentry; diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 20801dc..40b015b 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -763,19 +763,31 @@ int cifs_close(struct inode *inode, struct file *file) void cifs_reopen_persistent_handles(struct cifs_tcon *tcon) { - struct cifsFileInfo *open_file = NULL; + struct cifsFileInfo *open_file; struct list_head *tmp; struct list_head *tmp1; + struct list_head tmp_list; + + cifs_dbg(FYI, "Reopen persistent handles"); + INIT_LIST_HEAD(&tmp_list); /* list all files open on tree connection, reopen resilient handles */ spin_lock(&tcon->open_file_lock); - list_for_each_safe(tmp, tmp1, &tcon->openFileList) { + list_for_each(tmp, &tcon->openFileList) { open_file = list_entry(tmp, struct cifsFileInfo, tlist); - spin_unlock(&tcon->open_file_lock); - cifs_reopen_file(open_file, false /* do not flush */); - spin_lock(&tcon->open_file_lock); + if (!open_file->invalidHandle) + continue; + cifsFileInfo_get(open_file); + list_add_tail(&open_file->rlist, &tmp_list); } spin_unlock(&tcon->open_file_lock); + + list_for_each_safe(tmp, tmp1, &tmp_list) { + open_file = list_entry(tmp, struct cifsFileInfo, rlist); + cifs_reopen_file(open_file, false /* do not flush */); + list_del_init(&open_file->rlist); + cifsFileInfo_put(open_file); + } } int cifs_closedir(struct inode *inode, struct file *file)