From patchwork Fri Feb 1 20:03:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9B081390 for ; Fri, 1 Feb 2019 20:04:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABAF732C9E for ; Fri, 1 Feb 2019 20:04:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FE57330BE; Fri, 1 Feb 2019 20:04:24 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 498AD32C9E for ; Fri, 1 Feb 2019 20:04:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730292AbfBAUEY (ORCPT ); Fri, 1 Feb 2019 15:04:24 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40415 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729192AbfBAUEX (ORCPT ); Fri, 1 Feb 2019 15:04:23 -0500 Received: by mail-pg1-f194.google.com with SMTP id z10so3420722pgp.7 for ; Fri, 01 Feb 2019 12:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=NA6vvVyMDJPhQ9KgJXIJfBmv8U2CY45OLDLgFA0V5yM=; b=OuiYT/BaB9/iCTDObIpGDBZ/ANp5JmuAz7vm1DjNoRcbrHoeYePBTHtI+HTepSzym1 PJrL2Kyz5yeBRVEMF0bID7hrXFVAsZzcAB7Yino6yo/s/wICjsE0w21FfwJI/P4tZaJe zFnA4x4m9JqzTtiNtOKQplRip+YkV+ms4FeWdoGbKKxAIkyLCozWb1lKhfyp4809rn8i W3HOSXANky3qElmDCvHvKLuTR+mcJ4IWeTw8gG8P3qc8rQaZMsLW+D7mptbzIEp/+Xkx X1ukuDs3i/UyMSV0GdJqGGWBkgqMWnqdTitZsjIkEkSDlHFr9eE1wDtVE2IGAJgYUn4S 6oaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=NA6vvVyMDJPhQ9KgJXIJfBmv8U2CY45OLDLgFA0V5yM=; b=Xh2n7MXokOIIe/TgbA1ETeqqJPBmoN9M6fGjoHkw8ujHGqYgjvAPAQtbc+mWHKGZCa fFSLJMi/P3PBtE5A/sMu+u5BskrAN3jS4iYHVbH7obc7JKvH3vE5UEJO6eHZAdEdAe1U P5ykmifMDkHHAZZ0KCVo6s5w0U/oYMEkVYs8bUMFFsS2tYRGLW/n1ptnV8MW2v19f95V S2zTYIr0E3/edGzWaGIKJKISIdeD7tJkt3M3GmXa8JSeh+NsreVCs5n6l5y6dvH6XM5t VMJ0mnNDiP5D61l2a6lm0HCW109lUb7PYBXuXjIYtAhI5tOwFX9feIZJsD9GwXJsnmmh oHrQ== X-Gm-Message-State: AJcUukcNLUFOMKdiAp/i4H9N1Jxxjw9uR4IF+pGgh4sEK5PQO8KNXSl7 jodJQKlPruN1/jc6KuBpJJcqedc= X-Google-Smtp-Source: ALg8bN4CPKP4yPRVdTv//6YlvAHXv+2ffsy/+LO9HkH2fucUzuRjRm9WVHsZ+Ak0NfORAYBAybH8TQ== X-Received: by 2002:a62:2781:: with SMTP id n123mr41311199pfn.138.1549051462535; Fri, 01 Feb 2019 12:04:22 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:21 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 01/23] CIFS: Fix possible oops and memory leaks in async IO Date: Fri, 1 Feb 2019 12:03:49 -0800 Message-Id: <1549051452-5968-2-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Allocation of a page array for non-cached IO was separated from allocation of rdata and wdata structures and this introduced memory leaks and a possible null pointer dereference. This patch fixes these problems. Cc: Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/file.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 2c7689f..659ce1b 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2696,6 +2696,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, rc = cifs_write_allocate_pages(wdata->pages, nr_pages); if (rc) { + kvfree(wdata->pages); kfree(wdata); add_credits_and_wake_if(server, credits, 0); break; @@ -2707,6 +2708,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, if (rc) { for (i = 0; i < nr_pages; i++) put_page(wdata->pages[i]); + kvfree(wdata->pages); kfree(wdata); add_credits_and_wake_if(server, credits, 0); break; @@ -3386,8 +3388,12 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, } rc = cifs_read_allocate_pages(rdata, npages); - if (rc) - goto error; + if (rc) { + kvfree(rdata->pages); + kfree(rdata); + add_credits_and_wake_if(server, credits, 0); + break; + } rdata->tailsz = PAGE_SIZE; } @@ -3407,7 +3413,6 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, if (!rdata->cfile->invalidHandle || !(rc = cifs_reopen_file(rdata->cfile, true))) rc = server->ops->async_readv(rdata); -error: if (rc) { add_credits_and_wake_if(server, rdata->credits, 0); kref_put(&rdata->refcount, From patchwork Fri Feb 1 20:03:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9881414E1 for ; Fri, 1 Feb 2019 20:04:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A47D32C9E for ; Fri, 1 Feb 2019 20:04:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E4BC330BE; Fri, 1 Feb 2019 20:04:26 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 196D732C9E for ; Fri, 1 Feb 2019 20:04:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730302AbfBAUEZ (ORCPT ); Fri, 1 Feb 2019 15:04:25 -0500 Received: from mail-pg1-f172.google.com ([209.85.215.172]:42880 "EHLO mail-pg1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729192AbfBAUEZ (ORCPT ); Fri, 1 Feb 2019 15:04:25 -0500 Received: by mail-pg1-f172.google.com with SMTP id d72so3417710pga.9 for ; Fri, 01 Feb 2019 12:04:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=fQMmL3qaWXSf0y+ycF2h9CuuA+10oAyqhSQqmtJm53E=; b=CxNVFQwClE7zSkGxR/WP9+iN42mb7pEozejN1PXd2BH5MVPkU32NC6cxnZHnWVPojf YuBgfM7AaLSQBcNzPrnqkTmcsiGX9TeaoZC79nnjL8HNRi+DMgev2ctRxHzG7QhDAVpi 31YPzwcDB10xxzyUkrL/czMy7QDzH2GcMopti8e/j/RrBseK1H7Q8KN9TVANcnbmlgu6 qrdHZrg6/AO+zekDUsBlT92vxvqihzWU2MCxm3Kv45dAE8Y5Zd1pfKyogiJhz5bh8ytH mFYypVMnocSESR1xpKEG9KQPYJduJVoKxnghde14P6aLYnsB6ddxPsMXICj1VDxdoPo2 XNTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=fQMmL3qaWXSf0y+ycF2h9CuuA+10oAyqhSQqmtJm53E=; b=O2teOaniVnAczfWVj20wym0umPUj4d2ltXZyejI4DXLMHs+Kz1vR11wjl8UiHY9Jbc 15vxt5X7G6okcxT12DNqVoDvWjimQfP1ftObxuz0kjXrb0ah6d2Ozd5NXi8+/OGytubc lB30NZgzhC7FEgSuZWGvvL6gbKipBtWKkCG2uAJRNY+gZum+EYX18geZv/bIyyl2JtJf vmumLCtmhOuXuKVXtCS05k2Oak46tKGN/SNUu8vxrJmvxaTdmIxvJC6kq+ymFaEcYG7o r9pHhnCVQTSH2pMOegcb6xhawkLutwYjgPJaToD/I6jHBcTWuHiKf81s6DURCbeNiscu UyZQ== X-Gm-Message-State: AHQUAub6mQ52kEHlDYNy49gptLTWw7bjhxMGdos0nceHtwgC6vO6f3+C wzgsU+JQm2sVIYMmUfVqiPGzNFA= X-Google-Smtp-Source: AHgI3IaFg1fQuIy/QQJf+zUKD1OPH4wQ6Vg9+xxxgjEs4i56VsHw++h5x2G0Hu44JO6FN4O/SMxWjg== X-Received: by 2002:a63:cf48:: with SMTP id b8mr3621411pgj.17.1549051463970; Fri, 01 Feb 2019 12:04:23 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:22 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 02/23] CIFS: Fix trace command logging for SMB2 reads and writes Date: Fri, 1 Feb 2019 12:03:50 -0800 Message-Id: <1549051452-5968-3-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we log success once we send an async IO request to the server. Instead we need to analyse a response and then log success or failure for a particular command. Also fix argument list for read logging. Cc: # 4.18 Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/smb2pdu.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 2ff209e..4b5ab9c 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3241,8 +3241,17 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->mr = NULL; } #endif - if (rdata->result) + if (rdata->result) { cifs_stats_fail_inc(tcon, SMB2_READ_HE); + trace_smb3_read_err(0 /* xid */, + rdata->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, rdata->offset, + rdata->bytes, rdata->result); + } else + trace_smb3_read_done(0 /* xid */, + rdata->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, + rdata->offset, rdata->got_bytes); queue_work(cifsiod_wq, &rdata->work); DeleteMidQEntry(mid); @@ -3317,13 +3326,11 @@ smb2_async_readv(struct cifs_readdata *rdata) if (rc) { kref_put(&rdata->refcount, cifs_readdata_release); cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); - trace_smb3_read_err(rc, 0 /* xid */, io_parms.persistent_fid, - io_parms.tcon->tid, io_parms.tcon->ses->Suid, - io_parms.offset, io_parms.length); - } else - trace_smb3_read_done(0 /* xid */, io_parms.persistent_fid, - io_parms.tcon->tid, io_parms.tcon->ses->Suid, - io_parms.offset, io_parms.length); + trace_smb3_read_err(0 /* xid */, io_parms.persistent_fid, + io_parms.tcon->tid, + io_parms.tcon->ses->Suid, + io_parms.offset, io_parms.length, rc); + } cifs_small_buf_release(buf); return rc; @@ -3367,10 +3374,11 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, if (rc != -ENODATA) { cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE); cifs_dbg(VFS, "Send error in read = %d\n", rc); + trace_smb3_read_err(xid, req->PersistentFileId, + io_parms->tcon->tid, ses->Suid, + io_parms->offset, io_parms->length, + rc); } - trace_smb3_read_err(rc, xid, req->PersistentFileId, - io_parms->tcon->tid, ses->Suid, - io_parms->offset, io_parms->length); free_rsp_buf(resp_buftype, rsp_iov.iov_base); return rc == -ENODATA ? 0 : rc; } else @@ -3459,8 +3467,17 @@ smb2_writev_callback(struct mid_q_entry *mid) wdata->mr = NULL; } #endif - if (wdata->result) + if (wdata->result) { cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); + trace_smb3_write_err(0 /* no xid */, + wdata->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, wdata->offset, + wdata->bytes, wdata->result); + } else + trace_smb3_write_done(0 /* no xid */, + wdata->cfile->fid.persistent_fid, + tcon->tid, tcon->ses->Suid, + wdata->offset, wdata->bytes); queue_work(cifsiod_wq, &wdata->work); DeleteMidQEntry(mid); @@ -3602,10 +3619,7 @@ smb2_async_writev(struct cifs_writedata *wdata, wdata->bytes, rc); kref_put(&wdata->refcount, release); cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); - } else - trace_smb3_write_done(0 /* no xid */, req->PersistentFileId, - tcon->tid, tcon->ses->Suid, wdata->offset, - wdata->bytes); + } async_writev_out: cifs_small_buf_release(req); From patchwork Fri Feb 1 20:03:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5876E14E1 for ; Fri, 1 Feb 2019 20:04:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4877B32C9E for ; Fri, 1 Feb 2019 20:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A36E330BE; Fri, 1 Feb 2019 20:04:28 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E8DA432C9E for ; Fri, 1 Feb 2019 20:04:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730552AbfBAUE1 (ORCPT ); Fri, 1 Feb 2019 15:04:27 -0500 Received: from mail-pf1-f180.google.com ([209.85.210.180]:34467 "EHLO mail-pf1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729192AbfBAUE1 (ORCPT ); Fri, 1 Feb 2019 15:04:27 -0500 Received: by mail-pf1-f180.google.com with SMTP id h3so3755071pfg.1 for ; Fri, 01 Feb 2019 12:04:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=wEN9Zfq0t0p2ho73CH7ACXTAx/Vq+AZR8Yd/ytQMKtY=; b=bCC6jOO/tOpL4iKNJPXGGIZFjPkjs+aA29CRwzX31xDZp8Hw7g+TD8ENgj1odUTZDg Y5RMiYnS0PxftUeQe4gYKaYEZxjqg/fkLFFStkOE8/jlPXwUiCaphVM6hfrnmkQa2NpN wilNpss4XYl0zYS22Mv0Ow+wJfCR8t891hBz0yzKKa0FMq5NoIP8RhveqquiDYwN3r2M LfUeaihIBrXdYuR/7p6US+5CEFK60C07rCFgwTiM3sWKGudcIdYPVCbeSX1JlG0wzWJn dxxEKyWvpGmmriMbpnfzH31kO1V/O711IEb/zTdBYc33K9k/r1RrU1aTnUhMWdC549ex c0zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=wEN9Zfq0t0p2ho73CH7ACXTAx/Vq+AZR8Yd/ytQMKtY=; b=OCBlXlAZth7OwXELTfpxRK7m9MgMxAO+OgXen/wil18zOtqvVxxY+moC99BUr5b1XQ oVTcs0claf5tGhCnjCUk/hOI0jHyr3TPqzmq4pQxxyqs4VxC1/ts5C9+wTimUMuEkdK2 hYFCZI+TWaqh8YQq4DoM/3rv+PpQuNhJlsiacsCZBGx4NyN0HjQ/Gt31C1cZieoBpFXf N4+551JGKhAFJjihCnnQLaO8RMdz9cxvcxGSqvzM1W60ZVCDHpd4UhCsYfYZ90Zvh+mh I2eBo0q+HoMuoKMhX7ZmpeQj2XKfgEm8jWzXOqhPv601JKmpmvkYNQS1Ek9OgKttX2MB T1mw== X-Gm-Message-State: AHQUAuZIZDOfsvEw3y90zepuWdiP9D4GCLntqf7T0Ympqkqt4h6xuJLZ Ee3l7ENKBN8Q7eSKmxZQN8lkmgA= X-Google-Smtp-Source: AHgI3Ia1WvXLl8V+yxAQsxb2gdQfi6R5BGFVLim70nEFJuguOc1/ciupgyx8F7y3O12B4jX2Pk1X+A== X-Received: by 2002:a63:4d0e:: with SMTP id a14mr3604664pgb.408.1549051465394; Fri, 01 Feb 2019 12:04:25 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:24 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 03/23] CIFS: Do not count -ENODATA as failure for query directory Date: Fri, 1 Feb 2019 12:03:51 -0800 Message-Id: <1549051452-5968-4-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French CC: Stable --- fs/cifs/smb2pdu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 4b5ab9c..d858dc0 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3845,8 +3845,8 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) { srch_inf->endOfSearch = true; rc = 0; - } - cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE); + } else + cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE); goto qdir_exit; } From patchwork Fri Feb 1 20:03:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 970401390 for ; Fri, 1 Feb 2019 20:04:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8874932C9E for ; Fri, 1 Feb 2019 20:04:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C99B330BE; Fri, 1 Feb 2019 20:04:29 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 25BEA32C9E for ; Fri, 1 Feb 2019 20:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730653AbfBAUE2 (ORCPT ); Fri, 1 Feb 2019 15:04:28 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:32836 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729192AbfBAUE2 (ORCPT ); Fri, 1 Feb 2019 15:04:28 -0500 Received: by mail-pf1-f195.google.com with SMTP id c123so3755333pfb.0 for ; Fri, 01 Feb 2019 12:04:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=fcJzqbKcJhEcAUtDF+x6Y9SMilRLQMqUU4J04Yn29FE=; b=qgv6UH/jlsWJnqxAF4lOjIS+kAUaR7FqDwYfI+HbAlkei2ePhumi4OaS3ShTfB455S RUKmIin05ecwwxqATZaqm6BiGYVCfhvh66noomNMBJsWER3vR9jRWGKSzKoy8m+jVdfv Qa/aPwpwj1DGyHNCcqOgfGJjdiVkHlYYkWdtPtjzZ211/+fnVDfFEB4wtaP2qN4xH6gX 1qlYQ+suRmQkQH+1yV2V95+KNMuobJFDtnPZeQsE7Ui29H7KTMaSsCeQ6cFj3MU+HuR9 E22XNBo/mb7duKAZluD801FcZCiDkAc1+uIrxvQFbR5XtdIdeEhoQKjCfpqqkUsCC1dN HlmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=fcJzqbKcJhEcAUtDF+x6Y9SMilRLQMqUU4J04Yn29FE=; b=VkmwBsagWyQsJ5V4hy+HVSozjAqO0F+2jhe6oYwv1HSBGDB7iLe08GW2q/824qD65C HOZZ8Nwp4MYM9YBE1aMfdAPWRIzy0pWxiJgf8756qnFU+BaAZv5vlzNvg0Ond+PXlzaM 44iVtwNR8uNOlyT5lJ9DJUDUVOowAUDH/4HvYdCPFOvvsGtECnDQk8toH6tecVo7i5ub InBCnpw+5u63FWyzZrFKg9rxxpxc8cfJBWAV9PIGzqVpklYLwpeKUFKlNqTyg7gufLe9 9oJW470A0WBE64Z8KHBBarE/rmjpFWtv66K/zeCX7P/DbUg/1zZUyND5FQQgU+HqyeFi ZMmw== X-Gm-Message-State: AHQUAuaEojGcEehhHscg7nRXppG6GozL0lVgQJ/c1yHff36m85DMT5vd eSjQlg+8/R+zGrvcPm4JM8zyqVE= X-Google-Smtp-Source: AHgI3Ib3ljjOzXjDO8EFtFHRAg0omJOAsWaIu9/nRmy87sd3w/aGPg5zji0P1EyKFibA/U5NMVsevg== X-Received: by 2002:a63:ee0e:: with SMTP id e14mr3483191pgi.8.1549051466825; Fri, 01 Feb 2019 12:04:26 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:26 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 04/23] CIFS: Do not consider -ENODATA as stat failure for reads Date: Fri, 1 Feb 2019 12:03:52 -0800 Message-Id: <1549051452-5968-5-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 When doing reads beyound the end of a file the server returns error STATUS_END_OF_FILE error which is mapped to -ENODATA. Currently we report it as a failure which confuses read stats. Change it to not consider -ENODATA as failure for stat purposes. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French CC: Stable --- fs/cifs/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index d858dc0..ef52d66 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3241,7 +3241,7 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->mr = NULL; } #endif - if (rdata->result) { + if (rdata->result && rdata->result != -ENODATA) { cifs_stats_fail_inc(tcon, SMB2_READ_HE); trace_smb3_read_err(0 /* xid */, rdata->cfile->fid.persistent_fid, From patchwork Fri Feb 1 20:03:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F31C186E for ; Fri, 1 Feb 2019 20:04:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5191832C9E for ; Fri, 1 Feb 2019 20:04:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45E73330BE; Fri, 1 Feb 2019 20:04:30 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 DE73832C9E for ; Fri, 1 Feb 2019 20:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729192AbfBAUE3 (ORCPT ); Fri, 1 Feb 2019 15:04:29 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42330 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730629AbfBAUE3 (ORCPT ); Fri, 1 Feb 2019 15:04:29 -0500 Received: by mail-pg1-f194.google.com with SMTP id d72so3417775pga.9 for ; Fri, 01 Feb 2019 12:04:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=YbgPc8I9EhmndwgxVOFDxXP5pMMuY6HVHZ3jRaCwTEE=; b=YGjiNvRnYQBH95b6vR5fposaQZG8RqW92DsGvnByyORnYIEC6sBzsQbzmqfEI6TmVr UOHQQPT+wJzSV+DsAms6QxmsNmpKlYYmy/zwadIW2G+il5BBR7gL+bo9VTpbYUfuhlD6 r1ycBUNzNwCQtwN82frAHAfOjWz2zp1ptOAqQR6ILcSobDnQAdhYJ6VIDCElM+Pz+vdw zQfrRzCQ4QoAL+pb6+FVjQaKl3kXd5NLKntrI3EFUUMPdX19eM7KLte93BCgl/jzk0kU KxfzTb3XJyT3VfgXfxJS3qj4Qkm0jP4S+E/OeiLrObjk8URFgbuqjogJSwqL2zEFKtLd al0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=YbgPc8I9EhmndwgxVOFDxXP5pMMuY6HVHZ3jRaCwTEE=; b=V06es6xeHKiCA9wRKz6H0dYdIklbRLpvl264oJA2oGQEbRnipiJCoMIJaTTMQmTS/4 37mXrBFoy7TcVPWRgW747RFrsoY7mLdhEzpKEvht7H+RTSmDjS2BF7jd18WCsP8mjF2E YMH4PGxEGAirLEBvXqQknBCxLUDGOO3oL2KiPOSKHDLRTWUN99c4wkIrkA0ukPiOKlVt 4bxFSq+lceVIbjUPD6hwfctfHBBh2UB1UdT0ftx3oMHm+URz6m0rGCJzMFVDukgdWplq RBgSeJpmlF5MNDaZZPC4mmL3krZPox6zhXLahrOTI6abcVWjC+98LcSU9SgAFd5ICu3o 8jrw== X-Gm-Message-State: AHQUAuYrHHSgDvrJbXwRdDeJI3jIuhhTEYaTjfUKCBLnbwPWOrV+u7xQ EXwrGRLDVPI4bEb1qnESV/YiEsw= X-Google-Smtp-Source: AHgI3IblPJNINWxC16eM7LKGL5eHessG2QLe4DnfOKhtUGzpCVu+rYos+1LlVmk5GcEDyrRs0A7L6A== X-Received: by 2002:a63:5455:: with SMTP id e21mr3612377pgm.316.1549051467996; Fri, 01 Feb 2019 12:04:27 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:27 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 05/23] CIFS: Fix leaking locked VFS cache pages in writeback retry Date: Fri, 1 Feb 2019 12:03:53 -0800 Message-Id: <1549051452-5968-6-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 If we don't find a writable file handle when retrying writepages we break of the loop and do not unlock and put pages neither from wdata2 nor from the original wdata. Fix this by walking through all the remaining pages and cleanup them properly. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/cifssmb.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index bb54ccf8..551924b 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -2125,12 +2125,13 @@ cifs_writev_requeue(struct cifs_writedata *wdata) wdata2->cfile = find_writable_file(CIFS_I(inode), false); if (!wdata2->cfile) { - cifs_dbg(VFS, "No writable handles for inode\n"); + cifs_dbg(VFS, "No writable handle to retry writepages\n"); rc = -EBADF; - break; + } else { + wdata2->pid = wdata2->cfile->pid; + rc = server->ops->async_writev(wdata2, + cifs_writedata_release); } - wdata2->pid = wdata2->cfile->pid; - rc = server->ops->async_writev(wdata2, cifs_writedata_release); for (j = 0; j < nr_pages; j++) { unlock_page(wdata2->pages[j]); @@ -2145,6 +2146,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata) kref_put(&wdata2->refcount, cifs_writedata_release); if (is_retryable_error(rc)) continue; + i += nr_pages; break; } @@ -2152,6 +2154,13 @@ cifs_writev_requeue(struct cifs_writedata *wdata) i += nr_pages; } while (i < wdata->nr_pages); + /* cleanup remaining pages from the original wdata */ + for (; i < wdata->nr_pages; i++) { + SetPageError(wdata->pages[i]); + end_page_writeback(wdata->pages[i]); + put_page(wdata->pages[i]); + } + if (rc != 0 && !is_retryable_error(rc)) mapping_set_error(inode->i_mapping, rc); kref_put(&wdata->refcount, cifs_writedata_release); From patchwork Fri Feb 1 20:03:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C7A41390 for ; Fri, 1 Feb 2019 20:04:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F36E232C9E for ; Fri, 1 Feb 2019 20:04:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8014330BE; Fri, 1 Feb 2019 20:04:31 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 A29E032C9E for ; Fri, 1 Feb 2019 20:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730671AbfBAUEb (ORCPT ); Fri, 1 Feb 2019 15:04:31 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43843 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730629AbfBAUEb (ORCPT ); Fri, 1 Feb 2019 15:04:31 -0500 Received: by mail-pf1-f195.google.com with SMTP id w73so3727057pfk.10 for ; Fri, 01 Feb 2019 12:04:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=bE5ua07h59ttEc4rK9jgyEkfZdFMv9mZ6rTxJ6EFKro=; b=S5TBgu+8D51Cn+jikD1QG+neEJJzPmTuyMRo4y75B81YVDUMeQctdDc3Yl75407eKu UGLYNF4851yfpS5rc5MGMCJpaY2SWYmQuIHL43ueYTq2bP8is7qCD1DqjvQK2qdgbY47 8tk9bityRt4ZOq8qqUXcv0ZLApvb4BBE4ZCKBk8xQVh0zsmO9MYLucwa6Qj+0sCTDuXR +lqrxKN+nlug99cf7ipHizlH+yyTaBUKRvz1BeicG/ozlkC5PRxZ+4oMHE0JG/54rVMh FSgK2Ya5l1yqxo5vcb6HrOWqCR3lwpyJKvMkdPs8xnvOmQyOoajNxHsIpMCFFujPPkHj NUgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=bE5ua07h59ttEc4rK9jgyEkfZdFMv9mZ6rTxJ6EFKro=; b=BrNV6ytsEjBI5XDB2qIj4AlpdAUd763zldpZr8EJ8hU+TLwbDFSabaP8TfSeogyeH3 Mf9XAPCZRdQ9Dsg31bipt2PTq2oi+ZiDZh4LlOjiCPRwrh1vGUCqV9GBB5h6Qzk+gE8I 5PnxOM8W7KX3WgV5GrpYmvsGwV4pAYCKK4SPkr67fcuKX+3gz9GjDynG5t5A0cipC73x FPVx/RI1uRimXi4wjmZypWIH3ZtxMI7OmEXqcEUDlgwJYcaJU+NehwMHj6XivPnR06Of 2f6tZSDFducXrxoMTD0bDe22atbgQOlev+lgFKJtyhP7jrsbKk+jTYtbnfbrf4RjmLU7 Q33g== X-Gm-Message-State: AHQUAuZ/cKtib68OqhmWvvo5Ocwp85b9JZpocsYwgrWEQFAbELFXIhCd aOuj27uTcxYkBMZ/KF58693x8Fw= X-Google-Smtp-Source: AHgI3IYnN5e1TL/ed8GP8Y4cceTZDi0+vCLN91atGhzLh9wzcc/LH+6AAYkm8Qt236IlBRR9fBFINA== X-Received: by 2002:a63:2c0e:: with SMTP id s14mr3597530pgs.132.1549051469295; Fri, 01 Feb 2019 12:04:29 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:28 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 06/23] CIFS: Always reset read error to -EIO if no response Date: Fri, 1 Feb 2019 12:03:54 -0800 Message-Id: <1549051452-5968-7-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we skip setting a read error to -EIO if a stored result is -ENODATA and a response hasn't been received. With the recent changes in read error processing there shouldn't be cases when -ENODATA is set without a response from the server, so reset the error to -EIO unconditionally. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/smb2pdu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index ef52d66..18f0177 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3227,8 +3227,7 @@ smb2_readv_callback(struct mid_q_entry *mid) credits_received = le16_to_cpu(shdr->CreditRequest); /* fall through */ default: - if (rdata->result != -ENODATA) - rdata->result = -EIO; + rdata->result = -EIO; } #ifdef CONFIG_CIFS_SMB_DIRECT /* From patchwork Fri Feb 1 20:03:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74B1814E1 for ; Fri, 1 Feb 2019 20:04:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6691232C9E for ; Fri, 1 Feb 2019 20:04:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B609330BE; Fri, 1 Feb 2019 20:04:32 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 14ED532C9E for ; Fri, 1 Feb 2019 20:04:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730629AbfBAUEb (ORCPT ); Fri, 1 Feb 2019 15:04:31 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35455 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730654AbfBAUEb (ORCPT ); Fri, 1 Feb 2019 15:04:31 -0500 Received: by mail-pf1-f195.google.com with SMTP id z9so3752869pfi.2 for ; Fri, 01 Feb 2019 12:04:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=z2Asmfk1i1HKhQRpKVf9MkV5Q+e9KRD8JP1YcEc3jPg=; b=qBMLoL5J37Q3QeeFhe2OznS1hQFxjQnlgPe9jMH2fUGp3CAwf+aRGzUYuFGB2l/igS /e8qGoxWhm9BhON3COsajgVGuV4CvfWanXgapWPO9BVXjLdxG56UMdmSPsXSaSon/XeN R/GTrfKw19Uiw+oHDqeYaHKXP/VQR//dR76xhAeuq3an4MqJ3ucgCN9a16jftwjmEVxn yPciCbqr2Emu6F4n0vNjG0Hwe9zS+YEauSc+PLEjf7eWAdePeBZ9lEilPR6VX6RxD5s1 5hcOf2pF1U/ZvDX2FDdUVXbKVlZCG7FwXVa+u9Q4bVGvNPjyvMuNdwqBuPa6MO1Jykf2 oyxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=z2Asmfk1i1HKhQRpKVf9MkV5Q+e9KRD8JP1YcEc3jPg=; b=ulOaV5snKoAhZhIw058mQ0118omtcvcanr5+WhJ8D5DwC1G1MiIMJM9mN6xNnGbUoQ ZiZno2o54B/qDHJBYuLfxiPjw4PjJN6NwM7KmCXap0+W0tSyAjj/noB1LehV3rw5njSr 6D26n+ojcqAJUCc25Hjrm1zgCn1wMHJnaCiWUhSnBnA4ITet8DZziiJlTJrbFZfd9XSf 7FK2zUwrg+cAmV24tMnHZQRyzsOHn+czuV2WHrymLa9gNxuH8Qzb3Hc5OaXKvLK/wotj cudo0rhCHqgZ3aJoj8qLxRXtvTL4O7CcI0PLUk+JWZ1kjep/wiw6nckJLif0PBVx/dM5 Fd4A== X-Gm-Message-State: AJcUukeGCfMEtuXxPhBHFMfofAtgVfj26b6OWtQgGvMVjTjhxq/WwmY8 7SiCthHtN61syA76vWeElG9iRd8= X-Google-Smtp-Source: ALg8bN7Rew1dCUbe/yoL/LD7xJ84m60KC9wTn9S1IGJM50Jzv+6GdRhzPM0KePWrugwk9LIr3cIFcw== X-Received: by 2002:a63:e615:: with SMTP id g21mr37496664pgh.290.1549051470450; Fri, 01 Feb 2019 12:04:30 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:29 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 07/23] CIFS: Do not log credits when unmounting a share Date: Fri, 1 Feb 2019 12:03:55 -0800 Message-Id: <1549051452-5968-8-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we only skip credits logging on reconnects. When unmounting a share the number of credits on the client doesn't matter, so skip logging in such cases too. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/smb2ops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 6f96e22..49667ae 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -102,7 +102,8 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, spin_unlock(&server->req_lock); wake_up(&server->request_q); - if (server->tcpStatus == CifsNeedReconnect) + if (server->tcpStatus == CifsNeedReconnect + || server->tcpStatus == CifsExiting) return; switch (rc) { From patchwork Fri Feb 1 20:03:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E08E14E1 for ; Fri, 1 Feb 2019 20:04:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4036932C9E for ; Fri, 1 Feb 2019 20:04:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34C3D330BE; Fri, 1 Feb 2019 20:04:34 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E18EF32C9E for ; Fri, 1 Feb 2019 20:04:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730676AbfBAUEd (ORCPT ); Fri, 1 Feb 2019 15:04:33 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41472 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730654AbfBAUEd (ORCPT ); Fri, 1 Feb 2019 15:04:33 -0500 Received: by mail-pf1-f196.google.com with SMTP id b7so3732273pfi.8 for ; Fri, 01 Feb 2019 12:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=6zDk1ODTjzk9I9ws0KumEuHVUsXThJPSbWETmCZZcM8=; b=UUhYNpFVDLwyq9cf4VE3j4wmkFjKbobE5v/3XZ0+EK0agkuWPA7/aLg0ia4Me/7IVd JfW50s0TeXKFaytWFZfUNy66Ds94/abh/KLYKY4x3mT2bFEVb9ZrjFnAY1UpEwuO3mwY w57eOne6A+yz6+0OZvcx5Xb6uFbtRgxYrR26m/5nuOLfRP4yMBqXrqrlTS4OQYgisNgY Q0+J8sXqJ28M8/E2uj2/HM+JFysOMYFWlOtxmwoMBJAspLrg+pn5RbI5K9hUM/wj/r9a jDK8B1sHp5QWAHkG2oY7TcqBYKeLiBc3VocNdzf5C9SwltIC+RBU7XvuAE5hbUjEJFWB oYCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=6zDk1ODTjzk9I9ws0KumEuHVUsXThJPSbWETmCZZcM8=; b=tALQoHPU+Il+xLhBSvxFMXymXVLhYeN/W5LSLy0+ZScUDmPduw9yRCnjT5gNKj6Dc5 Aq51jSi2AEe1lWQfEO3oOUjSftgUd6KnQZcqdl95aVCRdSqD2qVzSACBUWARbWWafuh/ G845D/CGuBJoq+Qm+iv5Ai/9TxIuM0xujmQ7tp+dHVzlZ3sBAnTjDrbtKTjM/ZoWXm4l yD5AVkOKiMFJ+smvNuGNgWZBw7v9jqzNm5tu6hXWhWqdRv55F32m/aAwRmO3kxqABDva sEgGRXtWu0L24tqZ56RD2zc4DjYIWwOl2wZUzNoMsOB54xQOs1coBSff4ExX8grU9ovc LG3w== X-Gm-Message-State: AHQUAubnDVZdLOVhrNV6Gi0JAfmK+V4vRepbYXh9kYJvSuk6QJDSOCsJ 057jcPWMqinYoS3DyxiZHXruCAc= X-Google-Smtp-Source: AHgI3Ia52EG5nWH8KG6OlVoio6FFdnUVMquxAtkJt4RqHGsitxjyoPMY2wzNbxubOw7T9eP/DyYiHQ== X-Received: by 2002:a63:8742:: with SMTP id i63mr3531980pge.298.1549051471887; Fri, 01 Feb 2019 12:04:31 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:30 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 08/23] CIFS: Count credits for malformed error pending responses Date: Fri, 1 Feb 2019 12:03:56 -0800 Message-Id: <1549051452-5968-9-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Even if the response is malformed, we should count credits granted by the server to avoid miscalculations and unnecessary reconnects due to client or server bugs. If the response has been received partially, the session will be reconnected anyway on the next iteration of the demultiplex thread, so counting credits for such cases shouldn't break things. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/smb2ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 49667ae..79e23c3 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1761,7 +1761,7 @@ smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) if (shdr->Status != STATUS_PENDING) return false; - if (!length) { + if (shdr->CreditRequest) { spin_lock(&server->req_lock); server->credits += le16_to_cpu(shdr->CreditRequest); spin_unlock(&server->req_lock); From patchwork Fri Feb 1 20:03:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 866831390 for ; Fri, 1 Feb 2019 20:04:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75FA232C9E for ; Fri, 1 Feb 2019 20:04:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 655E4330BE; Fri, 1 Feb 2019 20:04:38 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 4CB7332C9E for ; Fri, 1 Feb 2019 20:04:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730697AbfBAUEh (ORCPT ); Fri, 1 Feb 2019 15:04:37 -0500 Received: from mail-pl1-f170.google.com ([209.85.214.170]:40265 "EHLO mail-pl1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730654AbfBAUEg (ORCPT ); Fri, 1 Feb 2019 15:04:36 -0500 Received: by mail-pl1-f170.google.com with SMTP id u18so3741474plq.7 for ; Fri, 01 Feb 2019 12:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=0vG0ItUofS7Hr3Vjltitg5/iFPuTngU7I0QuDylkY/Q=; b=CiMef5fJr44Y9ezp3vg5JIk1Xtalf/6ZekBSo/svRgDpMgNcV01J1IHjg+Cpw/CHgE SAsYxcci74ldeIz/c6cW4zewTvpbHQXXLClSefNzgRHLNI1CW38GMobLpWzAKEsJT7Uu NtgiSB1okkGWlZNZBfq0T0O6waUDlUIRbU4jomEcewCCOlRjcdYUNVvSl3YfPPavv56q /B9Vo2eCDK3eQ3RVPonNU0CZh5WXjSvdWo4b+Px2sksB6bEWmxHmsa/eEZcTYiNl/ume j1BohKyVfJHAdHMzYAyKwr8eLAZ5ozqK8b9bWxTAPtZFgIdWIYlWlj0qYZQD5ucwAda6 bnSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0vG0ItUofS7Hr3Vjltitg5/iFPuTngU7I0QuDylkY/Q=; b=DqN7WivSsWWmkidsXC5zh3XmE83X2AukYbVjv8GEi7dwUAMosnoj+iVuTp1oEiEXYs MrWeeLqXXglBkZkt/qYOesgglWowrPgnI75dH7iSRYiQMnziNgx9b+iTIm2KUyjPp7aq 5jtU9WBELJiPgJeput5DBRmvaE4HRTbME7D+Px4AceG0lHGfCtyQZjR4Jj+YocR/vMjs pSkfT9d/7rxxsP8RRRmxAvL1F+X+F2bQ1X/3tMnLE2kM3GIDUMif2b0SU5eKWEnEAwDz Pu8FlX5IJ/fR9mItr54A1wISdjHrKIVcUQxsw78GZDK7bd7g6+RJGHk0Pp9mqPGllmkU knfQ== X-Gm-Message-State: AJcUukdUt4dtB0edI3V4hqAwQDxSZaVLaB48m6kxQbOrsJuIu6hXrrQu O+5ct5plfZgm1Z8VkHfWD7zxs6U= X-Google-Smtp-Source: ALg8bN5nZD0fhoCdvrw/hQ4Gr/P4+31SNXzQzVVaOjY6ixsJXJRxYsGy3RBBfZLpFgkWIJj8dIqz5g== X-Received: by 2002:a17:902:8f83:: with SMTP id z3mr39832105plo.328.1549051474900; Fri, 01 Feb 2019 12:04:34 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:33 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 09/23] CIFS: Respect SMB2 hdr preamble size in read responses Date: Fri, 1 Feb 2019 12:03:58 -0800 Message-Id: <1549051452-5968-11-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 There are a couple places where we still account for 4 bytes in the beginning of SMB2 packet which is not true in the current code. Fix this to use a header preamble size where possible. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/cifssmb.c | 7 ++++--- fs/cifs/smb2ops.c | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index d40ded3..0ea06f5 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -1612,9 +1612,10 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) /* set up first two iov for signature check and to get credits */ rdata->iov[0].iov_base = buf; - rdata->iov[0].iov_len = 4; - rdata->iov[1].iov_base = buf + 4; - rdata->iov[1].iov_len = server->total_read - 4; + rdata->iov[0].iov_len = server->vals->header_preamble_size; + rdata->iov[1].iov_base = buf + server->vals->header_preamble_size; + rdata->iov[1].iov_len = + server->total_read - server->vals->header_preamble_size; cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", rdata->iov[0].iov_base, rdata->iov[0].iov_len); cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index b2849a7..5489f7d 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3216,10 +3216,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, /* set up first two iov to get credits */ rdata->iov[0].iov_base = buf; - rdata->iov[0].iov_len = 4; - rdata->iov[1].iov_base = buf + 4; + rdata->iov[0].iov_len = 0; + rdata->iov[1].iov_base = buf; rdata->iov[1].iov_len = - min_t(unsigned int, buf_len, server->vals->read_rsp_size) - 4; + min_t(unsigned int, buf_len, server->vals->read_rsp_size); cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", rdata->iov[0].iov_base, rdata->iov[0].iov_len); cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", From patchwork Fri Feb 1 20:03:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06C8814E1 for ; Fri, 1 Feb 2019 20:04:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9273330BE for ; Fri, 1 Feb 2019 20:04:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD01032E44; Fri, 1 Feb 2019 20:04:38 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 79E97330C3 for ; Fri, 1 Feb 2019 20:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730737AbfBAUEi (ORCPT ); Fri, 1 Feb 2019 15:04:38 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:36285 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730654AbfBAUEi (ORCPT ); Fri, 1 Feb 2019 15:04:38 -0500 Received: by mail-pl1-f193.google.com with SMTP id g9so3755547plo.3 for ; Fri, 01 Feb 2019 12:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=1Nqq7VAAKEOUHsQviQI8Zx2ixgo/VkLTI3lblB/sV2E=; b=Eg9Y/SA26LISZRb5iEXR/RygJdaG4LvGeYmlvXoEMi2cwdRRnuYRCL/BIYai/p/m3S eTF7NycA8uB+k4GFwGpnpAEKJeUEFbKeMfZRvCPmzOMq54ZfJRPnl13USI3YMCICeLTS V95DxohCVmUyBUYA3zMrmCs06cbzX6n+he7Ps/iG1hUup6qkWzs3xGa1RSSbmKN3Ya6o /K+BWZVSGJQcVblPwpTWW8ycm2pur8aIfqQeys8CuPdyqwGbcinujFL9Q7mOULkhKscM QrVFQOJjEQBUn4ZckR6+qR/i7nMZk0F1g/DDhyZoNAynGeoQqmkCIXxYlNb+tD9RVRaH tG2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=1Nqq7VAAKEOUHsQviQI8Zx2ixgo/VkLTI3lblB/sV2E=; b=EOsAU4BoiuiPKg9XsMBJnH4pNpDtLXLwKVGKrjFB7sHExeiePTeQdZHrsHkMy7DGH/ Hp2MfsKWIcOmdYJ0opagWCwIMifCFYiwi0CJnWUcv/uo1w4Ro9DJFSrtlrvGRfgRKiE3 LC4Trvm7qXqDQnl1Z4j49tGUrwpOMsUa4mEGTxi0YXolq5RrkTNJOz/tGpWdP6PZCixS +5wZ9U8bIZ2SF4wARhDjQbOCaup/AVyR6Xmio5dpTjjOFxQ2N8dv3pG36G49TzU3Ie7m vGpV3WnRZWI5UHVSfU11AuSXQyJQ+AvC3VZD3Hu/pEPdx4wGb88i3wO3tsbwKK5Oxeq7 ehug== X-Gm-Message-State: AJcUukcrqWvJ9a0kfNntCJCSuzTGrPRstV3yG+fw0KWNWTV3O/l9SNuz 4gIP5hO8GHUdjvgoBl6BYcpT8go= X-Google-Smtp-Source: ALg8bN7c8212Ck3JcngVc38/RHz/5tWBgEif4+fLL54fi4/GSsHc5UOnJJtqPTK1jfR79pWdPxlRiA== X-Received: by 2002:a17:902:2969:: with SMTP id g96mr40724394plb.295.1549051476042; Fri, 01 Feb 2019 12:04:36 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:35 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 10/23] CIFS: Mask signals during sock_sendmsg() Date: Fri, 1 Feb 2019 12:03:59 -0800 Message-Id: <1549051452-5968-12-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 We don't want to break a session if we receive a signal during sending a packet through the network. Fix it by masking signals during execution of sock_sendmsg() and then checking for pending signals. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/transport.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 53532bd..eff9e3c 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "cifspdu.h" #include "cifsglob.h" #include "cifsproto.h" @@ -176,6 +177,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, int rc = 0; int retries = 0; struct socket *ssocket = server->ssocket; + sigset_t mask, oldmask; *sent = 0; @@ -189,6 +191,28 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, smb_msg->msg_flags = MSG_NOSIGNAL; while (msg_data_left(smb_msg)) { + if (signal_pending(current)) { + /* Should we stop sending if we receive SIG_KILL? */ + if (__fatal_signal_pending(current)) + cifs_dbg(FYI, "SIG_KILL signal is pending\n"); + + /* It is safe to return if we haven't sent anything */ + if (*sent == 0) { + cifs_dbg(FYI, "signal is pending before sending any data\n"); + return -EINTR; + } + } + + /* + * We should not allow signals to interrupt the network send + * because any partial send will cause session reconnects thus + * increasing latency of system calls and overload a server + * with unnecessary requests. + */ + + sigfillset(&mask); + sigprocmask(SIG_BLOCK, &mask, &oldmask); + /* * If blocking send, we try 3 times, since each can block * for 5 seconds. For nonblocking we have to try more @@ -208,20 +232,23 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, * reconnect which may clear the network problem. */ rc = sock_sendmsg(ssocket, smb_msg); + + sigprocmask(SIG_SETMASK, &oldmask, NULL); + if (rc == -EAGAIN) { retries++; if (retries >= 14 || (!server->noblocksnd && (retries > 2))) { cifs_dbg(VFS, "sends on sock %p stuck for 15 seconds\n", ssocket); - return -EAGAIN; + return signal_pending(current) ? -EINTR : rc; } msleep(1 << retries); continue; } if (rc < 0) - return rc; + return signal_pending(current) ? -EINTR : rc; if (rc == 0) { /* should never happen, letting socket clear before @@ -235,7 +262,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, *sent += rc; retries = 0; /* in case we get ENOSPC on the next send */ } - return 0; + return signal_pending(current) ? -EINTR : 0; } unsigned long From patchwork Fri Feb 1 20:04:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52E8D1390 for ; Fri, 1 Feb 2019 20:04:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4556B32C9E for ; Fri, 1 Feb 2019 20:04:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39584330BE; Fri, 1 Feb 2019 20:04:39 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E3D6132C9E for ; Fri, 1 Feb 2019 20:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730654AbfBAUEi (ORCPT ); Fri, 1 Feb 2019 15:04:38 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45606 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730734AbfBAUEi (ORCPT ); Fri, 1 Feb 2019 15:04:38 -0500 Received: by mail-pf1-f195.google.com with SMTP id g62so3720628pfd.12 for ; Fri, 01 Feb 2019 12:04:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=ogcXlVKO9zD1c7jsLlT35CeyUPu7LA9uWQ8SYeUmzHo=; b=fyTVgr3TIlgLVJkxb1n7c54DNJ0Q+m6uVcpjQ/P4iu/HCUvDu/oGxGhibFad3/kSh3 lNEs+AR2aYXmkh0Z3nunvQzXz0hKme5ATjWLw319iQZCYZBuKzPVr8vy8CbV16UgD7c5 lrZBIwM/b9tE7nj7i7gPqnB+VSMYGbhnkTmS8bU6lH3ge8rjcMp7ACG1lkcjqP+raKCh 3MWrS19eD8NQxmOaj2Yb7hWq8x5qPuoI8Gqt4CYI6bM7+ofSKqmNLCW+slV0V1lxuasZ q5ovZa6E13OemvcFBlWx8oFsQxvPalbeR8gBO4bcb0NDA0wp+wHnwPV53zbFwH5TRGZV NXkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ogcXlVKO9zD1c7jsLlT35CeyUPu7LA9uWQ8SYeUmzHo=; b=WBHYq+pxOTv/QmmOZhjNCk/eTdkvTCRXHoEs+oJceZGomD7BX1Hfy4y92Kflsh1DDm UdGnyylSrCKGaPymihsDQG339W5yAk8SHDbr0SrE6f5ggbaySRqs7+pHn2HUY2xROrW+ 1VqqdLvlmjnQOZtiL6rTyPn+q3zOr4wDW37ZMCxeml/PRc9nd8/etirjqo8BPAEeHHx1 PNnOhqT4/gEMEnZhCE98fP6ovP/lt+JiA1kgFuQ0qfLuRzrLKdmGXmaNQDnBk6XqRUC4 cA0GEw9Mi0A8dBmRrSL014+H48a+YNlPkhI+FMDZ4YYqZfjEVLaIWkcomkzcevgSHs64 pn3g== X-Gm-Message-State: AHQUAuZ7jozs6UMxYrHCyvgD/YR9v8giePsSzhi7M8XQlt9fxlaRHBxv PVaM2YNy9IuUDi2pGuB4xTwiwfI= X-Google-Smtp-Source: AHgI3IZBgTU2A+cZWR13+UX+UmO76kyYCgBIJ5dVHNk2F7kj3qV/9YDfVX7k1T096E3VyaTmtA4VMg== X-Received: by 2002:a63:db02:: with SMTP id e2mr3542123pgg.419.1549051477326; Fri, 01 Feb 2019 12:04:37 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:36 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 11/23] CIFS: Set reconnect instance to one initially Date: Fri, 1 Feb 2019 12:04:00 -0800 Message-Id: <1549051452-5968-13-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we set reconnect instance to zero on the first connection but this is not convenient because we need to reserve some special value for credit handling on reconnects which is coming in subsequent patches. Fix this by starting with one when initiating a new TCP connection. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/connect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 67af18a..f771ad4 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -2609,7 +2609,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) volume_info->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); tcp_ses->session_estab = false; tcp_ses->sequence_number = 0; - tcp_ses->reconnect_instance = 0; + tcp_ses->reconnect_instance = 1; tcp_ses->lstrp = jiffies; spin_lock_init(&tcp_ses->req_lock); INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); From patchwork Fri Feb 1 20:04:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E38F1390 for ; Fri, 1 Feb 2019 20:04:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CEEE32C9E for ; Fri, 1 Feb 2019 20:04:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2144E330BE; Fri, 1 Feb 2019 20:04:43 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 C62A132C9E for ; Fri, 1 Feb 2019 20:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730767AbfBAUEl (ORCPT ); Fri, 1 Feb 2019 15:04:41 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40426 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730734AbfBAUEl (ORCPT ); Fri, 1 Feb 2019 15:04:41 -0500 Received: by mail-pg1-f193.google.com with SMTP id z10so3420982pgp.7 for ; Fri, 01 Feb 2019 12:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=dlafpBoF1N7yc8hw76XalllPp1mTXI3Wzn8Kme7wYoY=; b=sWSohYS4lT1C5Qs0eU62Rvhex/YJ5abFZLNg9wwoercViA242AsLpNl4J2xZeGGLDY EYqCObxOpMIiznWiMCyFXIIK3ItMTIWFSVl4EONPpCNndz1iaw/OdN4J3GZE33s9YsKc S2/cHDE2A1pTQoF3zRWp86QlC19zfx3hzKzJ0molq1wLkZMEKn30K6xnPYWe5yppSnSe ioUXq+t4TtbMHWuoghx7enMbYpRF8wNJjzn64fEqSwk11FsCtbAA0qJh2NHlIndX48JZ JiKQSAfmtG2nc5SpopXrvdYmhnjEwq4npo5Q+HfiYoBBnMUWtXhcGZgMg+J/UeAthcV0 pJPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=dlafpBoF1N7yc8hw76XalllPp1mTXI3Wzn8Kme7wYoY=; b=ncLWZuRM8mK8qDvnZqJA6SneiSldBVehdEKVvPSLTslkL+Ax5MBjVc6AiJTs+Dq0UL cxNOj7oTTQYXbNwfvaeSBaJV3fJ4GNv0oLSg+qrQClvxslVgAqFLNF0Ok9A0iEHzrWpx jANQKEmo8GQCbhWFLooDhJ7R4+F5cGrlZrPTx7DdWwCyFtFVrCNnu14HEMA1m1IzIrvg 1JUsa7GC9KZaHYIFRmLGblyeX7RX9uvAcPdSIYF/rmpO5CedmhSggjijg36DQgU1p6hj Zwsf/NLdAKeLMPb21biF7FAXrAWDCxn/DWS8XVogiD/h0wBpqq88e3298ZC6FUnIIDNg x7Pg== X-Gm-Message-State: AHQUAuYlUfevnwQdKd/LIVL0YGEnZMqEvjIJOHmejJ2slPG+9bEV6gWh wMSOkFYNlhDpsEfxME7pGwZyyMY= X-Google-Smtp-Source: AHgI3Ibe3naNF2eiHqhwjgDd2kU0TZ7BRy9oVri5bWX9kzdlhbcrax730Q5VPpBVQtKsPsuz8RVvHg== X-Received: by 2002:a63:c748:: with SMTP id v8mr3639747pgg.108.1549051478933; Fri, 01 Feb 2019 12:04:38 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:37 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 12/23] CIFS: Respect reconnect in MTU credits calculations Date: Fri, 1 Feb 2019 12:04:01 -0800 Message-Id: <1549051452-5968-14-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Every time after a session reconnect we don't need to account for credits obtained in previous sessions. Introduce new struct cifs_credits which contains both credits value and reconnect instance of the time those credits were taken. Modify a routine that add credits back to handle the reconnect instance by assuming zero credits if the reconnect happened after the credits were obtained and before we decided to add them back due to some errors during sending. This patch fixes the MTU credits cases. The subsequent patch will handle non-MTU ones. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 29 ++++++++++++++++--------- fs/cifs/cifsproto.h | 2 +- fs/cifs/connect.c | 3 +-- fs/cifs/file.c | 62 ++++++++++++++++++++++++++++++++--------------------- fs/cifs/smb1ops.c | 6 +++--- fs/cifs/smb2ops.c | 27 +++++++++++++++++------ fs/cifs/smb2pdu.c | 39 ++++++++++++++++++++++++--------- fs/cifs/transport.c | 13 +++++------ 8 files changed, 118 insertions(+), 63 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index b84b1fc..9071e47 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -216,6 +216,7 @@ struct cifs_io_parms; struct cifs_search_info; struct cifsInodeInfo; struct cifs_open_parms; +struct cifs_credits; struct smb_version_operations { int (*send_cancel)(struct TCP_Server_Info *, struct smb_rqst *, @@ -230,8 +231,9 @@ struct smb_version_operations { /* check response: verify signature, map error */ int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *, bool); - void (*add_credits)(struct TCP_Server_Info *, const unsigned int, - const int); + void (*add_credits)(struct TCP_Server_Info *server, + const struct cifs_credits *credits, + const int optype); void (*set_credits)(struct TCP_Server_Info *, const int); int * (*get_credits_field)(struct TCP_Server_Info *, const int); unsigned int (*get_credits)(struct mid_q_entry *); @@ -452,7 +454,7 @@ struct smb_version_operations { unsigned int (*wp_retry_size)(struct inode *); /* get mtu credits */ int (*wait_mtu_credits)(struct TCP_Server_Info *, unsigned int, - unsigned int *, unsigned int *); + unsigned int *, struct cifs_credits *); /* check if we need to issue closedir */ bool (*dir_needs_close)(struct cifsFileInfo *); long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t, @@ -710,6 +712,11 @@ struct TCP_Server_Info { int nr_targets; }; +struct cifs_credits { + unsigned int value; + unsigned int instance; +}; + static inline unsigned int in_flight(struct TCP_Server_Info *server) { @@ -734,15 +741,17 @@ static inline void add_credits(struct TCP_Server_Info *server, const unsigned int add, const int optype) { - server->ops->add_credits(server, add, optype); + struct cifs_credits credits = { .value = add, .instance = 0 }; + + server->ops->add_credits(server, &credits, optype); } static inline void -add_credits_and_wake_if(struct TCP_Server_Info *server, const unsigned int add, - const int optype) +add_credits_and_wake_if(struct TCP_Server_Info *server, + const struct cifs_credits *credits, const int optype) { - if (add) { - server->ops->add_credits(server, add, optype); + if (credits->value) { + server->ops->add_credits(server, credits, optype); wake_up(&server->request_q); } } @@ -1234,7 +1243,7 @@ struct cifs_readdata { unsigned int pagesz; unsigned int page_offset; unsigned int tailsz; - unsigned int credits; + struct cifs_credits credits; unsigned int nr_pages; struct page **pages; }; @@ -1260,7 +1269,7 @@ struct cifs_writedata { unsigned int pagesz; unsigned int page_offset; unsigned int tailsz; - unsigned int credits; + struct cifs_credits credits; unsigned int nr_pages; struct page **pages; }; diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 336c116..7a9a9fd 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -115,7 +115,7 @@ extern int cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, bool log_error); extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, unsigned int *num, - unsigned int *credits); + struct cifs_credits *credits); extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, struct kvec *, int /* nvec to send */, int * /* type of buf returned */, const int flags, diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index f771ad4..431ca65 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -592,6 +592,7 @@ cifs_reconnect(struct TCP_Server_Info *server) msleep(3000); } else { atomic_inc(&tcpSesReconnectCount); + set_credits(server, 1); spin_lock(&GlobalMid_Lock); if (server->tcpStatus != CifsExiting) server->tcpStatus = CifsNeedNegotiate; @@ -4902,8 +4903,6 @@ cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses) if (!server->ops->need_neg(server)) return 0; - set_credits(server, 1); - rc = server->ops->negotiate(xid, ses); if (rc == 0) { spin_lock(&GlobalMid_Lock); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 659ce1b..2adcf42 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2143,11 +2143,13 @@ static int cifs_writepages(struct address_space *mapping, server = cifs_sb_master_tcon(cifs_sb)->ses->server; retry: while (!done && index <= end) { - unsigned int i, nr_pages, found_pages, wsize, credits; + unsigned int i, nr_pages, found_pages, wsize; pgoff_t next = 0, tofind, saved_index = index; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, - &wsize, &credits); + &wsize, credits); if (rc != 0) { done = true; break; @@ -2180,13 +2182,13 @@ static int cifs_writepages(struct address_space *mapping, continue; } - wdata->credits = credits; + wdata->credits = credits_on_stack; rc = wdata_send_pages(wdata, nr_pages, mapping, wbc); /* send failure -- clean up the mess */ if (rc != 0) { - add_credits_and_wake_if(server, wdata->credits, 0); + add_credits_and_wake_if(server, &wdata->credits, 0); for (i = 0; i < nr_pages; ++i) { if (is_retryable_error(rc)) redirty_page_for_writepage(wbc, @@ -2567,7 +2569,8 @@ static int cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list, struct cifs_aio_ctx *ctx) { - unsigned int wsize, credits; + unsigned int wsize; + struct cifs_credits credits; int rc; struct TCP_Server_Info *server = tlink_tcon(wdata->cfile->tlink)->ses->server; @@ -2577,18 +2580,19 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list, * Note: we are attempting to resend the whole wdata not in segments */ do { - rc = server->ops->wait_mtu_credits( - server, wdata->bytes, &wsize, &credits); + rc = server->ops->wait_mtu_credits(server, wdata->bytes, &wsize, + &credits); if (rc) goto out; if (wsize < wdata->bytes) { - add_credits_and_wake_if(server, credits, 0); + add_credits_and_wake_if(server, &credits, 0); msleep(1000); } } while (wsize < wdata->bytes); + wdata->credits = credits; rc = -EAGAIN; while (rc == -EAGAIN) { rc = 0; @@ -2604,7 +2608,7 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list, return 0; } - add_credits_and_wake_if(server, wdata->credits, 0); + add_credits_and_wake_if(server, &wdata->credits, 0); out: kref_put(&wdata->refcount, cifs_uncached_writedata_release); @@ -2627,6 +2631,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, struct TCP_Server_Info *server; struct page **pagevec; size_t start; + unsigned int xid; if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) pid = open_file->pid; @@ -2634,12 +2639,15 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, pid = current->tgid; server = tlink_tcon(open_file->tlink)->ses->server; + xid = get_xid(); do { - unsigned int wsize, credits; + unsigned int wsize; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, - &wsize, &credits); + &wsize, credits); if (rc) break; @@ -2731,7 +2739,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, wdata->pid = pid; wdata->bytes = cur_len; wdata->pagesz = PAGE_SIZE; - wdata->credits = credits; + wdata->credits = credits_on_stack; wdata->ctx = ctx; kref_get(&ctx->refcount); @@ -2740,7 +2748,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, rc = server->ops->async_writev(wdata, cifs_uncached_writedata_release); if (rc) { - add_credits_and_wake_if(server, wdata->credits, 0); + add_credits_and_wake_if(server, &wdata->credits, 0); kref_put(&wdata->refcount, cifs_uncached_writedata_release); if (rc == -EAGAIN) { @@ -2756,6 +2764,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, len -= cur_len; } while (len > 0); + free_xid(xid); return rc; } @@ -3260,7 +3269,8 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata, struct list_head *rdata_list, struct cifs_aio_ctx *ctx) { - unsigned int rsize, credits; + unsigned int rsize; + struct cifs_credits credits; int rc; struct TCP_Server_Info *server = tlink_tcon(rdata->cfile->tlink)->ses->server; @@ -3277,11 +3287,12 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata, goto out; if (rsize < rdata->bytes) { - add_credits_and_wake_if(server, credits, 0); + add_credits_and_wake_if(server, &credits, 0); msleep(1000); } } while (rsize < rdata->bytes); + rdata->credits = credits; rc = -EAGAIN; while (rc == -EAGAIN) { rc = 0; @@ -3297,7 +3308,7 @@ static int cifs_resend_rdata(struct cifs_readdata *rdata, return 0; } - add_credits_and_wake_if(server, rdata->credits, 0); + add_credits_and_wake_if(server, &rdata->credits, 0); out: kref_put(&rdata->refcount, cifs_uncached_readdata_release); @@ -3311,7 +3322,9 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, struct cifs_aio_ctx *ctx) { struct cifs_readdata *rdata; - unsigned int npages, rsize, credits; + unsigned int npages, rsize; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; size_t cur_len; int rc; pid_t pid; @@ -3332,7 +3345,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, do { rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, - &rsize, &credits); + &rsize, credits); if (rc) break; @@ -3406,7 +3419,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, rdata->pagesz = PAGE_SIZE; rdata->read_into_pages = cifs_uncached_read_into_pages; rdata->copy_into_pages = cifs_uncached_copy_into_pages; - rdata->credits = credits; + rdata->credits = credits_on_stack; rdata->ctx = ctx; kref_get(&ctx->refcount); @@ -3414,7 +3427,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, !(rc = cifs_reopen_file(rdata->cfile, true))) rc = server->ops->async_readv(rdata); if (rc) { - add_credits_and_wake_if(server, rdata->credits, 0); + add_credits_and_wake_if(server, &rdata->credits, 0); kref_put(&rdata->refcount, cifs_uncached_readdata_release); if (rc == -EAGAIN) { @@ -4095,10 +4108,11 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, loff_t offset; struct page *page, *tpage; struct cifs_readdata *rdata; - unsigned credits; + struct cifs_credits credits_on_stack; + struct cifs_credits *credits = &credits_on_stack; rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, - &rsize, &credits); + &rsize, credits); if (rc) break; @@ -4144,7 +4158,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, rdata->tailsz = PAGE_SIZE; rdata->read_into_pages = cifs_readpages_read_into_pages; rdata->copy_into_pages = cifs_readpages_copy_into_pages; - rdata->credits = credits; + rdata->credits = credits_on_stack; list_for_each_entry_safe(page, tpage, &tmplist, lru) { list_del(&page->lru); @@ -4155,7 +4169,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, !(rc = cifs_reopen_file(rdata->cfile, true))) rc = server->ops->async_readv(rdata); if (rc) { - add_credits_and_wake_if(server, rdata->credits, 0); + add_credits_and_wake_if(server, &rdata->credits, 0); for (i = 0; i < rdata->nr_pages; i++) { page = rdata->pages[i]; lru_cache_add_file(page); diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c index 32a6c02..6f92d64 100644 --- a/fs/cifs/smb1ops.c +++ b/fs/cifs/smb1ops.c @@ -117,11 +117,11 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer) } static void -cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add, - const int optype) +cifs_add_credits(struct TCP_Server_Info *server, + const struct cifs_credits *credits, const int optype) { spin_lock(&server->req_lock); - server->credits += add; + server->credits += credits->value; server->in_flight--; spin_unlock(&server->req_lock); wake_up(&server->request_q); diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 5489f7d..354a7bc 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -67,10 +67,13 @@ change_conf(struct TCP_Server_Info *server) } static void -smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, - const int optype) +smb2_add_credits(struct TCP_Server_Info *server, + const struct cifs_credits *credits, const int optype) { int *val, rc = -1; + unsigned int add = credits->value; + unsigned int instance = credits->instance; + bool reconnect_detected = false; spin_lock(&server->req_lock); val = server->ops->get_credits_field(server, optype); @@ -79,8 +82,11 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0)) trace_smb3_reconnect_with_invalid_credits(server->CurrentMid, server->hostname, *val); + if ((instance == 0) || (instance == server->reconnect_instance)) + *val += add; + else + reconnect_detected = true; - *val += add; if (*val > 65000) { *val = 65000; /* Don't get near 64K credits, avoid srv bugs */ printk_once(KERN_WARNING "server overflowed SMB3 credits\n"); @@ -102,6 +108,10 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, spin_unlock(&server->req_lock); wake_up(&server->request_q); + if (reconnect_detected) + cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n", + add, instance); + if (server->tcpStatus == CifsNeedReconnect || server->tcpStatus == CifsExiting) return; @@ -164,7 +174,7 @@ smb2_get_credits(struct mid_q_entry *mid) static int smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, - unsigned int *num, unsigned int *credits) + unsigned int *num, struct cifs_credits *credits) { int rc = 0; unsigned int scredits; @@ -190,7 +200,8 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, /* can deadlock with reopen */ if (scredits <= 8) { *num = SMB2_MAX_BUFFER_SIZE; - *credits = 0; + credits->value = 0; + credits->instance = 0; break; } @@ -199,8 +210,10 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, *num = min_t(unsigned int, size, scredits * SMB2_MAX_BUFFER_SIZE); - *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); - server->credits -= *credits; + credits->value = + DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); + credits->instance = server->reconnect_instance; + server->credits -= credits->value; server->in_flight++; break; } diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 18f0177..f83a237 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3285,9 +3285,9 @@ smb2_async_readv(struct cifs_readdata *rdata) rc = smb2_new_read_req( (void **) &buf, &total_len, &io_parms, rdata, 0, 0); if (rc) { - if (rc == -EAGAIN && rdata->credits) { + if (rc == -EAGAIN && rdata->credits.value) { /* credits was reset by reconnect */ - rdata->credits = 0; + rdata->credits.value = 0; /* reduce in_flight value since we won't send the req */ spin_lock(&server->req_lock); server->in_flight--; @@ -3304,17 +3304,26 @@ smb2_async_readv(struct cifs_readdata *rdata) shdr = (struct smb2_sync_hdr *)buf; - if (rdata->credits) { + if (rdata->credits.value > 0) { shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes, SMB2_MAX_BUFFER_SIZE)); shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); spin_lock(&server->req_lock); - server->credits += rdata->credits - + if (server->reconnect_instance == rdata->credits.instance) + server->credits += rdata->credits.value - le16_to_cpu(shdr->CreditCharge); + else { + spin_unlock(&server->req_lock); + cifs_dbg(VFS, "trying to return %u credits to old session\n", + rdata->credits.value + - le16_to_cpu(shdr->CreditCharge)); + rc = -EAGAIN; + goto async_readv_out; + } spin_unlock(&server->req_lock); wake_up(&server->request_q); - rdata->credits = le16_to_cpu(shdr->CreditCharge); + rdata->credits.value = le16_to_cpu(shdr->CreditCharge); flags |= CIFS_HAS_CREDITS; } @@ -3331,6 +3340,7 @@ smb2_async_readv(struct cifs_readdata *rdata) io_parms.offset, io_parms.length, rc); } +async_readv_out: cifs_small_buf_release(buf); return rc; } @@ -3499,9 +3509,9 @@ smb2_async_writev(struct cifs_writedata *wdata, rc = smb2_plain_req_init(SMB2_WRITE, tcon, (void **) &req, &total_len); if (rc) { - if (rc == -EAGAIN && wdata->credits) { + if (rc == -EAGAIN && wdata->credits.value) { /* credits was reset by reconnect */ - wdata->credits = 0; + wdata->credits.value = 0; /* reduce in_flight value since we won't send the req */ spin_lock(&server->req_lock); server->in_flight--; @@ -3594,17 +3604,26 @@ smb2_async_writev(struct cifs_writedata *wdata, req->Length = cpu_to_le32(wdata->bytes); #endif - if (wdata->credits) { + if (wdata->credits.value > 0) { shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes, SMB2_MAX_BUFFER_SIZE)); shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); spin_lock(&server->req_lock); - server->credits += wdata->credits - + if (server->reconnect_instance == wdata->credits.instance) + server->credits += wdata->credits.value - le16_to_cpu(shdr->CreditCharge); + else { + spin_unlock(&server->req_lock); + cifs_dbg(VFS, "trying to return %d credits to old session\n", + wdata->credits.value + - le16_to_cpu(shdr->CreditCharge)); + rc = -EAGAIN; + goto async_writev_out; + } spin_unlock(&server->req_lock); wake_up(&server->request_q); - wdata->credits = le16_to_cpu(shdr->CreditCharge); + wdata->credits.value = le16_to_cpu(shdr->CreditCharge); flags |= CIFS_HAS_CREDITS; } diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index eff9e3c..f364a08 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -539,10 +539,11 @@ wait_for_free_request(struct TCP_Server_Info *server, const int timeout, int cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, - unsigned int *num, unsigned int *credits) + unsigned int *num, struct cifs_credits *credits) { *num = size; - *credits = 0; + credits->value = 0; + credits->instance = server->reconnect_instance; return 0; } @@ -633,7 +634,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, { int rc, timeout, optype; struct mid_q_entry *mid; - unsigned int credits = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; timeout = flags & CIFS_TIMEOUT_MASK; optype = flags & CIFS_OP_MASK; @@ -642,14 +643,14 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, rc = wait_for_free_request(server, timeout, optype); if (rc) return rc; - credits = 1; + credits.value = 1; } mutex_lock(&server->srv_mutex); mid = server->ops->setup_async_request(server, rqst); if (IS_ERR(mid)) { mutex_unlock(&server->srv_mutex); - add_credits_and_wake_if(server, credits, optype); + add_credits_and_wake_if(server, &credits, optype); return PTR_ERR(mid); } @@ -683,7 +684,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, if (rc == 0) return 0; - add_credits_and_wake_if(server, credits, optype); + add_credits_and_wake_if(server, &credits, optype); return rc; } From patchwork Fri Feb 1 20:04:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73F0F1390 for ; Fri, 1 Feb 2019 20:04:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6455432E44 for ; Fri, 1 Feb 2019 20:04:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 583B4330BE; Fri, 1 Feb 2019 20:04:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 60BDF32C9E for ; Fri, 1 Feb 2019 20:04:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730734AbfBAUEm (ORCPT ); Fri, 1 Feb 2019 15:04:42 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38185 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730755AbfBAUEm (ORCPT ); Fri, 1 Feb 2019 15:04:42 -0500 Received: by mail-pg1-f193.google.com with SMTP id g189so3429820pgc.5 for ; Fri, 01 Feb 2019 12:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=YeW4Mok2dRCK9Q9ur3YkmRzcg3fRETXBYcoQnc+aqrk=; b=eyAU8imuaADjNei/TuCEpJoyxw4fLYqG1rI8I50nX5U9Ty2KLM/T5IRtVnfwBXxKis 1ZCSSQFooEO8JD6JUJI76eFJKe1IqAOVijaHUSbHZeHDpGfcw8q7/2+QYnXFQgm7+8SP dUaXmd6DogbzO6WTlynXukooHP6xv173zOezn1uPiMaZXTQOqTop+zOarRTkCQAG7cCw F/uzjzm7c/4w5XGLo9Sjwt0ubXekTzxyVT8gSnOz7pf59j49Gk/D4nl/BWHvR9f7MCi0 wXkENlXLq3SDKkkf8gDfOKS3nhq7vo+lx3HuQxgowQMV1RCL8g4938qKHSX686SJUZFU ltYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=YeW4Mok2dRCK9Q9ur3YkmRzcg3fRETXBYcoQnc+aqrk=; b=trxKZwda+nah1GYGyNvq6MmLWz6ts45dpZtdaYIIA8sf+NfO0JQY5dX8xHcl/3nUo9 ev92IyDcCHKNIkO8jFgC6GgpVmWxchr8yQnVRxpbH+kxM8OxznZX4Sj7pBI9ti8KuZtc tb8dt+LTTnEmLFTlULC/ZNZZE2NbPJrOD2yPpQ/UNsNUIoX2VfwQGRBlAffNV2tcaApS 1+5fd/jWvHfAqLEzk4wg/D0a6H5mFjFOBJpIh7zefmp+HuQxevLVe8P4FY/Ge3gzi9mQ XRTNZ+J+bdVoHNVhNPDy+EIy9P+7FcQpaAd+/cSqdocjwLy+X5SgCkg1p1JeMdh8v6ZN JNRw== X-Gm-Message-State: AJcUukefNm3K467j03eR9sJ23XyVogJyLeOzni65tC5mdZdZNJ+bvXT+ guqe/rTv15bCwn1pocnIWhFrRv0= X-Google-Smtp-Source: ALg8bN7rftMnBfoSrRM1po+0cx/SFpg+QPvDhM1OVsGlr5deEUCA0b83PHTq1yTxbeI8iUzWnhAvNw== X-Received: by 2002:a62:c711:: with SMTP id w17mr41070398pfg.50.1549051480090; Fri, 01 Feb 2019 12:04:40 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:39 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 13/23] CIFS: Respect reconnect in non-MTU credits calculations Date: Fri, 1 Feb 2019 12:04:02 -0800 Message-Id: <1549051452-5968-15-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Every time after a session reconnect we don't need to account for credits obtained in previous sessions. Make use of the recently added cifs_credits structure to properly calculate credits for non-MTU requests the same way we did for MTU ones. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 6 ++---- fs/cifs/cifssmb.c | 9 ++++++--- fs/cifs/smb2pdu.c | 33 +++++++++++++++++++------------- fs/cifs/transport.c | 54 +++++++++++++++++++++++++++++++++++------------------ 4 files changed, 64 insertions(+), 38 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 9071e47..545b91d 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -738,12 +738,10 @@ has_credits(struct TCP_Server_Info *server, int *credits) } static inline void -add_credits(struct TCP_Server_Info *server, const unsigned int add, +add_credits(struct TCP_Server_Info *server, const struct cifs_credits *credits, const int optype) { - struct cifs_credits credits = { .value = add, .instance = 0 }; - - server->ops->add_credits(server, &credits, optype); + server->ops->add_credits(server, credits, optype); } static inline void diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 0ea06f5..cf97fc0 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -822,9 +822,10 @@ static void cifs_echo_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->callback_data; + struct cifs_credits credits = { .value = 1, .instance = 0 }; DeleteMidQEntry(mid); - add_credits(server, 1, CIFS_ECHO_OP); + add_credits(server, &credits, CIFS_ECHO_OP); } int @@ -1714,6 +1715,7 @@ cifs_readv_callback(struct mid_q_entry *mid) .rq_npages = rdata->nr_pages, .rq_pagesz = rdata->pagesz, .rq_tailsz = rdata->tailsz }; + struct cifs_credits credits = { .value = 1, .instance = 0 }; cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", __func__, mid->mid, mid->mid_state, rdata->result, @@ -1751,7 +1753,7 @@ cifs_readv_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &rdata->work); DeleteMidQEntry(mid); - add_credits(server, 1, 0); + add_credits(server, &credits, 0); } /* cifs_async_readv - send an async write, and set up mid to handle result */ @@ -2236,6 +2238,7 @@ cifs_writev_callback(struct mid_q_entry *mid) struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); unsigned int written; WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; + struct cifs_credits credits = { .value = 1, .instance = 0 }; switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: @@ -2271,7 +2274,7 @@ cifs_writev_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &wdata->work); DeleteMidQEntry(mid); - add_credits(tcon->ses->server, 1, 0); + add_credits(tcon->ses->server, &credits, 0); } /* cifs_async_writev - send an async write, and set up mid to handle result */ diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index f83a237..746be24 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2924,14 +2924,16 @@ smb2_echo_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->callback_data; struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf; - unsigned int credits_received = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; if (mid->mid_state == MID_RESPONSE_RECEIVED - || mid->mid_state == MID_RESPONSE_MALFORMED) - credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); + || mid->mid_state == MID_RESPONSE_MALFORMED) { + credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.instance = server->reconnect_instance; + } DeleteMidQEntry(mid); - add_credits(server, credits_received, CIFS_ECHO_OP); + add_credits(server, &credits, CIFS_ECHO_OP); } void smb2_reconnect_server(struct work_struct *work) @@ -3184,7 +3186,7 @@ smb2_readv_callback(struct mid_q_entry *mid) struct TCP_Server_Info *server = tcon->ses->server; struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)rdata->iov[0].iov_base; - unsigned int credits_received = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; struct smb_rqst rqst = { .rq_iov = rdata->iov, .rq_nvec = 2, .rq_pages = rdata->pages, @@ -3199,7 +3201,8 @@ smb2_readv_callback(struct mid_q_entry *mid) switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: - credits_received = le16_to_cpu(shdr->CreditRequest); + credits.value = le16_to_cpu(shdr->CreditRequest); + credits.instance = server->reconnect_instance; /* result already set, check signature */ if (server->sign && !mid->decrypted) { int rc; @@ -3224,7 +3227,8 @@ smb2_readv_callback(struct mid_q_entry *mid) cifs_stats_bytes_read(tcon, rdata->got_bytes); break; case MID_RESPONSE_MALFORMED: - credits_received = le16_to_cpu(shdr->CreditRequest); + credits.value = le16_to_cpu(shdr->CreditRequest); + credits.instance = server->reconnect_instance; /* fall through */ default: rdata->result = -EIO; @@ -3254,7 +3258,7 @@ smb2_readv_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &rdata->work); DeleteMidQEntry(mid); - add_credits(server, credits_received, 0); + add_credits(server, &credits, 0); } /* smb2_async_readv - send an async read, and set up mid to handle result */ @@ -3426,14 +3430,16 @@ smb2_writev_callback(struct mid_q_entry *mid) { struct cifs_writedata *wdata = mid->callback_data; struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); + struct TCP_Server_Info *server = tcon->ses->server; unsigned int written; struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; - unsigned int credits_received = 0; + struct cifs_credits credits = { .value = 0, .instance = 0 }; switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: - credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); - wdata->result = smb2_check_receive(mid, tcon->ses->server, 0); + credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.instance = server->reconnect_instance; + wdata->result = smb2_check_receive(mid, server, 0); if (wdata->result != 0) break; @@ -3457,7 +3463,8 @@ smb2_writev_callback(struct mid_q_entry *mid) wdata->result = -EAGAIN; break; case MID_RESPONSE_MALFORMED: - credits_received = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.value = le16_to_cpu(rsp->sync_hdr.CreditRequest); + credits.instance = server->reconnect_instance; /* fall through */ default: wdata->result = -EIO; @@ -3490,7 +3497,7 @@ smb2_writev_callback(struct mid_q_entry *mid) queue_work(cifsiod_wq, &wdata->work); DeleteMidQEntry(mid); - add_credits(tcon->ses->server, credits_received, 0); + add_credits(server, &credits, 0); } /* smb2_async_writev - send an async write, and set up mid to handle result */ diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index f364a08..8b512a9 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -478,15 +478,18 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, static int wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, - int *credits) + int *credits, unsigned int *instance) { int rc; + *instance = 0; + spin_lock(&server->req_lock); if (timeout == CIFS_ASYNC_OP) { /* oplock breaks must not be held up */ server->in_flight++; *credits -= 1; + *instance = server->reconnect_instance; spin_unlock(&server->req_lock); return 0; } @@ -516,6 +519,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, if (timeout != CIFS_BLOCKING_OP) { *credits -= 1; server->in_flight++; + *instance = server->reconnect_instance; } spin_unlock(&server->req_lock); break; @@ -526,7 +530,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, static int wait_for_free_request(struct TCP_Server_Info *server, const int timeout, - const int optype) + const int optype, unsigned int *instance) { int *val; @@ -534,7 +538,7 @@ wait_for_free_request(struct TCP_Server_Info *server, const int timeout, /* Since an echo is already inflight, no need to wait to send another */ if (*val <= 0 && optype == CIFS_ECHO_OP) return -EAGAIN; - return wait_for_free_credits(server, timeout, val); + return wait_for_free_credits(server, timeout, val, instance); } int @@ -635,15 +639,17 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, int rc, timeout, optype; struct mid_q_entry *mid; struct cifs_credits credits = { .value = 0, .instance = 0 }; + unsigned int instance; timeout = flags & CIFS_TIMEOUT_MASK; optype = flags & CIFS_OP_MASK; if ((flags & CIFS_HAS_CREDITS) == 0) { - rc = wait_for_free_request(server, timeout, optype); + rc = wait_for_free_request(server, timeout, optype, &instance); if (rc) return rc; credits.value = 1; + credits.instance = instance; } mutex_lock(&server->srv_mutex); @@ -814,8 +820,12 @@ static void cifs_compound_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->server; + struct cifs_credits credits; + + credits.value = server->ops->get_credits(mid); + credits.instance = server->reconnect_instance; - add_credits(server, server->ops->get_credits(mid), mid->optype); + add_credits(server, &credits, mid->optype); } static void @@ -841,7 +851,10 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, int timeout, optype; struct mid_q_entry *midQ[MAX_COMPOUND]; bool cancelled_mid[MAX_COMPOUND] = {false}; - unsigned int credits[MAX_COMPOUND] = {0}; + struct cifs_credits credits[MAX_COMPOUND] = { + { .value = 0, .instance = 0 } + }; + unsigned int instance; char *buf; timeout = flags & CIFS_TIMEOUT_MASK; @@ -867,7 +880,8 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, * needed anyway. */ for (i = 0; i < num_rqst; i++) { - rc = wait_for_free_request(ses->server, timeout, optype); + rc = wait_for_free_request(ses->server, timeout, optype, + &instance); if (rc) { /* * We haven't sent an SMB packet to the server yet but @@ -879,10 +893,11 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, * requests correctly. */ for (j = 0; j < i; j++) - add_credits(ses->server, 1, optype); + add_credits(ses->server, &credits[j], optype); return rc; } - credits[i] = 1; + credits[i].value = 1; + credits[i].instance = instance; } /* @@ -902,7 +917,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, /* Update # of requests on wire to server */ for (j = 0; j < num_rqst; j++) - add_credits(ses->server, credits[j], optype); + add_credits(ses->server, &credits[j], optype); return PTR_ERR(midQ[i]); } @@ -933,7 +948,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, if (rc < 0) { /* Sending failed for some reason - return credits back */ for (i = 0; i < num_rqst; i++) - add_credits(ses->server, credits[i], optype); + add_credits(ses->server, &credits[i], optype); goto out; } @@ -970,7 +985,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, midQ[i]->mid_flags |= MID_WAIT_CANCELLED; midQ[i]->callback = cifs_cancelled_callback; cancelled_mid[i] = true; - credits[i] = 0; + credits[i].value = 0; } spin_unlock(&GlobalMid_Lock); } @@ -1096,6 +1111,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, unsigned int len = be32_to_cpu(in_buf->smb_buf_length); struct kvec iov = { .iov_base = in_buf, .iov_len = len }; struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; + struct cifs_credits credits = { .value = 1, .instance = 0 }; if (ses == NULL) { cifs_dbg(VFS, "Null smb session\n"); @@ -1119,7 +1135,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, return -EIO; } - rc = wait_for_free_request(ses->server, timeout, 0); + rc = wait_for_free_request(ses->server, timeout, 0, &credits.instance); if (rc) return rc; @@ -1133,7 +1149,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, if (rc) { mutex_unlock(&ses->server->srv_mutex); /* Update # of requests on wire to server */ - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } @@ -1169,7 +1185,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, /* no longer considered to be "in-flight" */ midQ->callback = DeleteMidQEntry; spin_unlock(&GlobalMid_Lock); - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } spin_unlock(&GlobalMid_Lock); @@ -1177,7 +1193,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, rc = cifs_sync_mid_result(midQ, ses->server); if (rc != 0) { - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } @@ -1193,7 +1209,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, rc = cifs_check_receive(midQ, ses->server, 0); out: cifs_delete_mid(midQ); - add_credits(ses->server, 1, 0); + add_credits(ses->server, &credits, 0); return rc; } @@ -1235,6 +1251,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, unsigned int len = be32_to_cpu(in_buf->smb_buf_length); struct kvec iov = { .iov_base = in_buf, .iov_len = len }; struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 }; + unsigned int instance; if (tcon == NULL || tcon->ses == NULL) { cifs_dbg(VFS, "Null smb session\n"); @@ -1260,7 +1277,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, return -EIO; } - rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0); + rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0, + &instance); if (rc) return rc; From patchwork Fri Feb 1 20:04:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7D1B14E1 for ; Fri, 1 Feb 2019 20:04:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D98B732C9E for ; Fri, 1 Feb 2019 20:04:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD7CB330BE; Fri, 1 Feb 2019 20:04:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 5A9D932C9E for ; Fri, 1 Feb 2019 20:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730755AbfBAUEo (ORCPT ); Fri, 1 Feb 2019 15:04:44 -0500 Received: from mail-pl1-f178.google.com ([209.85.214.178]:33821 "EHLO mail-pl1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730775AbfBAUEn (ORCPT ); Fri, 1 Feb 2019 15:04:43 -0500 Received: by mail-pl1-f178.google.com with SMTP id w4so3755494plz.1 for ; Fri, 01 Feb 2019 12:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=01Szu3F6S9vDeVaJ2wBf3+c1URmIwthqWF4PdGjqCGY=; b=o8zKh3i/lA6gwQEIO43ukBp2TaxGNB34vPLa5Uic3kSmRxtGIZo6UF/hJvEqTlQdrE ChxnEluT5pH51caULq2nhtHCP+UoCjcPhewKqZcaZMhLakE06SSytdawA+HkwcPQ0QMj 1udoAv5XNPP7Ck0Fy8EvRBYzDYVKc7qgsiZhPuwFhJf5UJpq5qL0ImazioCdvpwFeQrC 4GspfJhe0e6hBVuKFrGbI1QFeGWf2kKamMYBuEP6n2qcT8gFAY+drSbik9hFdAnv+b3H hKoIKGTM1tmtDd6D3vrivQtQxUjozC3aDHc9ST4Voga1VXisgevdRUpeYlC9nJTN0ku4 OI1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=01Szu3F6S9vDeVaJ2wBf3+c1URmIwthqWF4PdGjqCGY=; b=IxDialIrAvEreJL/eT/aC1np/EnJvGV48BhUbM3Q9wa3/4MgZcgb/2+291JvOKOJar K7Y2KU/F5lVVC35G23DErD5JssrnDoylrsqG26HBtQ6CIhxXfHlDt7ETUB1lgLT1Ewz9 Kr2qXTS8Kxq2qj+WCutugujzGK50BTV366hagIBH4MtlNBlSLxPToNf26xSRGixGnlcT oZ+7keEpcRDDpWw6B82XYwUyMGDa5CJ5y0RPNsQJpbrME7x2mk/5sRq549Eo3ndbdu7h aaUclN7K0CdQ/eOgtZzU7gCWvMFFapZhmuQVgTBDEaU8wYoh67BVZE8eYVuPzuBWBxV4 g0vw== X-Gm-Message-State: AJcUukdX0XtF1ouVEM82NmXFlJxoyssChhdsma6711Y6PpCFnbpV3OxZ LDvsxo3AeLHNbRMwHL623TNqfAU= X-Google-Smtp-Source: ALg8bN4Z1e1qLkrl5Py2vTRcxEPIgQbtY31w2dehSNib+2Z/fiJ1Sv+sjngSb5VEAhyWY6GbNFZsZw== X-Received: by 2002:a17:902:9a04:: with SMTP id v4mr41590502plp.34.1549051482087; Fri, 01 Feb 2019 12:04:42 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:40 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 14/23] CIFS: Check for reconnects before sending async requests Date: Fri, 1 Feb 2019 12:04:03 -0800 Message-Id: <1549051452-5968-16-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 The reconnect might have happended after we obtained credits and before we acquired srv_mutex. Check for that under the mutex and retry an async operation if the reconnect is detected. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/cifsproto.h | 3 ++- fs/cifs/cifssmb.c | 6 +++--- fs/cifs/smb2pdu.c | 7 ++++--- fs/cifs/transport.c | 18 ++++++++++++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 7a9a9fd..9e8394f 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -93,7 +93,8 @@ extern int cifs_discard_remaining_data(struct TCP_Server_Info *server); extern int cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback, - mid_handle_t *handle, void *cbdata, const int flags); + mid_handle_t *handle, void *cbdata, const int flags, + const struct cifs_credits *exist_credits); extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, struct smb_rqst *rqst, int *resp_buf_type, const int flags, struct kvec *resp_iov); diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index cf97fc0..6c89279 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -860,7 +860,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) iov[1].iov_base = (char *)smb + 4; rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, NULL, - server, CIFS_ASYNC_OP | CIFS_ECHO_OP); + server, CIFS_ASYNC_OP | CIFS_ECHO_OP, NULL); if (rc) cifs_dbg(FYI, "Echo request failed: %d\n", rc); @@ -1812,7 +1812,7 @@ cifs_async_readv(struct cifs_readdata *rdata) kref_get(&rdata->refcount); rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, - cifs_readv_callback, NULL, rdata, 0); + cifs_readv_callback, NULL, rdata, 0, NULL); if (rc == 0) cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); @@ -2352,7 +2352,7 @@ cifs_async_writev(struct cifs_writedata *wdata, kref_get(&wdata->refcount); rc = cifs_call_async(tcon->ses->server, &rqst, NULL, - cifs_writev_callback, NULL, wdata, 0); + cifs_writev_callback, NULL, wdata, 0, NULL); if (rc == 0) cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 746be24..8f92c22 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3025,7 +3025,7 @@ SMB2_echo(struct TCP_Server_Info *server) iov[0].iov_base = (char *)req; rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, NULL, - server, CIFS_ECHO_OP); + server, CIFS_ECHO_OP, NULL); if (rc) cifs_dbg(FYI, "Echo request failed: %d\n", rc); @@ -3334,7 +3334,8 @@ smb2_async_readv(struct cifs_readdata *rdata) kref_get(&rdata->refcount); rc = cifs_call_async(io_parms.tcon->ses->server, &rqst, cifs_readv_receive, smb2_readv_callback, - smb3_handle_read_data, rdata, flags); + smb3_handle_read_data, rdata, flags, + &rdata->credits); if (rc) { kref_put(&rdata->refcount, cifs_readdata_release); cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); @@ -3636,7 +3637,7 @@ smb2_async_writev(struct cifs_writedata *wdata, kref_get(&wdata->refcount); rc = cifs_call_async(server, &rqst, NULL, smb2_writev_callback, NULL, - wdata, flags); + wdata, flags, &wdata->credits); if (rc) { trace_smb3_write_err(0 /* no xid */, req->PersistentFileId, diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 8b512a9..26e9912 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -634,7 +634,8 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) int cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback, - mid_handle_t *handle, void *cbdata, const int flags) + mid_handle_t *handle, void *cbdata, const int flags, + const struct cifs_credits *exist_credits) { int rc, timeout, optype; struct mid_q_entry *mid; @@ -650,9 +651,22 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, return rc; credits.value = 1; credits.instance = instance; - } + } else + instance = exist_credits->instance; mutex_lock(&server->srv_mutex); + + /* + * We can't use credits obtained from the previous session to send this + * request. Check if there were reconnects after we obtained credits and + * return -EAGAIN in such cases to let callers handle it. + */ + if (instance != server->reconnect_instance) { + mutex_unlock(&server->srv_mutex); + add_credits_and_wake_if(server, &credits, optype); + return -EAGAIN; + } + mid = server->ops->setup_async_request(server, rqst); if (IS_ERR(mid)) { mutex_unlock(&server->srv_mutex); From patchwork Fri Feb 1 20:04:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF7B21390 for ; Fri, 1 Feb 2019 20:04:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A29C232C9E for ; Fri, 1 Feb 2019 20:04:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96EDE330C9; Fri, 1 Feb 2019 20:04:47 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 8A20D32C9E for ; Fri, 1 Feb 2019 20:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730795AbfBAUEq (ORCPT ); Fri, 1 Feb 2019 15:04:46 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:32920 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730775AbfBAUEq (ORCPT ); Fri, 1 Feb 2019 15:04:46 -0500 Received: by mail-pg1-f195.google.com with SMTP id z11so3439136pgu.0 for ; Fri, 01 Feb 2019 12:04:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=D9XlWdMfdZT4foKFmA6mUkjYE2iPaIh+gLAY+FwZUK8=; b=sRQ8y18W9GpQeQniO3eqAW1Zm4G4kPc1EuaFuraW4kK/zV/eBV9iaXc6OEVuETi4rp dJ5MfVA9Sc6wz5ux43DHeySHFhPJ/7x7fb3/ykKPbFP94gKaZUv1xHLmTOWW8QdG16dA CYa5x86/nFbZZBo5I9n4StbuloeQ1AVD1qCv6pt7Do2ZZe4fnrs7j/Za5Ca6sVkr75l9 GcdYNS84pur7YkRvjxV1impXg3fYiDTqgC6tGBQRlUVFMMSXr449U/aNs7Tsz/dkhsAr vzzGq/FEzPPpiAX3BCLGWMjuo4CP4TCPyU9vzh31KfRv/Ky4oesRDX0A2jv2e6FZoIYv U//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=D9XlWdMfdZT4foKFmA6mUkjYE2iPaIh+gLAY+FwZUK8=; b=WRHbT14mO1oBoZhSZ1fuXbczDbfXymKKctbHPooImvP21hRjwe54YTbYBo1WHQKjw/ awM0rX8fjWQiOV/67SKWR/ir8BFnoeuDBXhGjxq3KoVxPEcvpgGKrkPwsZxPdyOts7UZ dimpTHItGnRTtOfqSCsMky6lLrq6ntpOXg1KYl2sGrqP/VFKj6sz3KLgL9l6HFkJlM05 S8qctk7BD7DkaRFzij6+6doW5RMyUTELmgidL4jvwaUFeK+0vepTQRk8G24EUJqfHgtT lQP7gmB5nuKtoL8hXLoyQQ7ia3V6u/JqYYMe/SuP+uPcS7/cQM4IS/ZpcTQC7iitxxL8 ggSw== X-Gm-Message-State: AJcUukebtbaup2sPoC3J24/ITgNRZ0et3KtWio3CQiHLsAn5IjCSrlbd al1wc+1SoNMrECJPvughCzSodHY= X-Google-Smtp-Source: ALg8bN5KN64tvTNVLx95AttlNou7u5/hB8gZImu1nOsips45rCLcRwoA/ILQUl12rgYX495Lsu+lWA== X-Received: by 2002:a62:42d4:: with SMTP id h81mr40558638pfd.259.1549051483441; Fri, 01 Feb 2019 12:04:43 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:42 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 15/23] CIFS: Check for reconnects before sending compound requests Date: Fri, 1 Feb 2019 12:04:04 -0800 Message-Id: <1549051452-5968-17-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 The reconnect might have happended after we obtained credits and before we acquired srv_mutex. Check for that under the mutex and retry a sync operation if the reconnect is detected. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/transport.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 26e9912..2187bc3 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -869,6 +869,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, { .value = 0, .instance = 0 } }; unsigned int instance; + unsigned int first_instance = 0; char *buf; timeout = flags & CIFS_TIMEOUT_MASK; @@ -896,6 +897,25 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, for (i = 0; i < num_rqst; i++) { rc = wait_for_free_request(ses->server, timeout, optype, &instance); + + if (rc == 0) { + credits[i].value = 1; + credits[i].instance = instance; + /* + * All parts of the compound chain must get credits from + * the same session, otherwise we may end up using more + * credits than the server granted. If there were + * reconnects in between, return -EAGAIN and let callers + * handle it. + */ + if (i == 0) + first_instance = instance; + else if (first_instance != instance) { + i++; + rc = -EAGAIN; + } + } + if (rc) { /* * We haven't sent an SMB packet to the server yet but @@ -910,8 +930,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, add_credits(ses->server, &credits[j], optype); return rc; } - credits[i].value = 1; - credits[i].instance = instance; } /* @@ -922,6 +940,22 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, mutex_lock(&ses->server->srv_mutex); + /* + * All the parts of the compound chain belong obtained credits from the + * same session (see the appropriate checks above). In the same time + * there might be reconnects after those checks but before we acquired + * the srv_mutex. We can not use credits obtained from the previous + * session to send this request. Check if there were reconnects after + * we obtained credits and return -EAGAIN in such cases to let callers + * handle it. + */ + if (first_instance != ses->server->reconnect_instance) { + mutex_unlock(&ses->server->srv_mutex); + for (j = 0; j < num_rqst; j++) + add_credits(ses->server, &credits[j], optype); + return -EAGAIN; + } + for (i = 0; i < num_rqst; i++) { midQ[i] = ses->server->ops->setup_request(ses, &rqst[i]); if (IS_ERR(midQ[i])) { From patchwork Fri Feb 1 20:04:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14A59186E for ; Fri, 1 Feb 2019 20:04:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 059EC32C9E for ; Fri, 1 Feb 2019 20:04:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE149330C9; Fri, 1 Feb 2019 20:04:47 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 B84CD32E44 for ; Fri, 1 Feb 2019 20:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730775AbfBAUEq (ORCPT ); Fri, 1 Feb 2019 15:04:46 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40988 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUEq (ORCPT ); Fri, 1 Feb 2019 15:04:46 -0500 Received: by mail-pl1-f196.google.com with SMTP id u6so3733470plm.8 for ; Fri, 01 Feb 2019 12:04:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=2ZvrvImtpqXKWCYI9BgomQW03ySs8NRR2dYt0WBnzdA=; b=WQVfaEsKyodC6NkaE8zKlOBCRfK65N0Fm1fs4cODx4F3Oi1saPcappMymgEPazr90v 5LEyFJ/zJrQMykMFL9zRqhb51VP1TTXLTyIFegCQ64vZcBnrqz0ba4s9yZ4WUmHe0Kit OEcj7yb3Bb1bPdIdsx/Cje0pe9EcYlif72Yg85u0R58EICsNJ5XGLpVzMlqLbwCnK6SQ EUHhXzEIRwYKwmYgUHUT7oNSz8jYI9YFmZwGIrO/Z+8ufknw9ThQWtPmr8xPOxJz7RzJ k6ZTJc8xqem81ttAek0nGLVJv12AI8M4tiFrilvCW6yA7578JHYMp7LPTRPbjx/CR6PD 7tPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2ZvrvImtpqXKWCYI9BgomQW03ySs8NRR2dYt0WBnzdA=; b=XsC1RWBr01/SePQIH4p4RkaFdSlMsoFjFzhH3f+hP6ViIMuXtWAktVyCoa6Xvx5Y7e PZYMdeJZRfKVMd4kvoRmBQIMXbyJZnKGY1GoiR6/sFRV6Rt1Y+rT+UhiX0aV15yv/Cao snMSzOw5DFAY7Xr06zhIzU/bXEPk/+Jku+K2AJBGOicRXGRzK7EBsWXyrdE5URyNaWWC ftscERnhw9h2PzbWnN/3w/5VtnrK8C/RhNc3Lz5TsU3rfZ+4hdGFBIsbgSZWno9wnfsX yTFrXxKPsCQToFQ8/16Yw9/m7WGvfPnp7ZwrzfhRQiecokxeiShbVrUnnTRTkiYCPxVK nWaw== X-Gm-Message-State: AJcUukc4Rvhld8GZGQjqcVTKMf9nrwUkVg6WDJxbnGLvrv+tZ3NakYlW +Inh6hNg5PuIhf6YLauYhJgonvc= X-Google-Smtp-Source: ALg8bN5cVRAxQHQz0iV8Yg7Cbx31U9hs3gcLuf9Lkda4uwIcbxlFXF7oosFk08m3F0/+xDFnnsi2Uw== X-Received: by 2002:a17:902:9691:: with SMTP id n17mr42116171plp.9.1549051484792; Fri, 01 Feb 2019 12:04:44 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:43 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 16/23] CIFS: Adjust MTU credits before reopening a file Date: Fri, 1 Feb 2019 12:04:05 -0800 Message-Id: <1549051452-5968-18-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we adjust MTU credits before sending an IO request and after reopening a file. This approach doesn't allow the reopen routine to use existing credits that are not needed for IO. Reorder credit adjustment and reopening a file to use credits available to the client more efficiently. Also unwrap complex if statement into few pieces to improve readability. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 12 ++++++++++++ fs/cifs/file.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- fs/cifs/smb2ops.c | 35 +++++++++++++++++++++++++++++++++++ fs/cifs/smb2pdu.c | 36 ++++++++---------------------------- 4 files changed, 94 insertions(+), 42 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 545b91d..5bf463c 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -455,6 +455,10 @@ struct smb_version_operations { /* get mtu credits */ int (*wait_mtu_credits)(struct TCP_Server_Info *, unsigned int, unsigned int *, struct cifs_credits *); + /* adjust previously taken mtu credits to request size */ + int (*adjust_credits)(struct TCP_Server_Info *server, + struct cifs_credits *credits, + const unsigned int payload_size); /* check if we need to issue closedir */ bool (*dir_needs_close)(struct cifsFileInfo *); long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t, @@ -760,6 +764,14 @@ set_credits(struct TCP_Server_Info *server, const int val) server->ops->set_credits(server, val); } +static inline int +adjust_credits(struct TCP_Server_Info *server, struct cifs_credits *credits, + const unsigned int payload_size) +{ + return server->ops->adjust_credits ? + server->ops->adjust_credits(server, credits, payload_size) : 0; +} + static inline __le64 get_next_mid64(struct TCP_Server_Info *server) { diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 2adcf42..e793b55 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2076,11 +2076,11 @@ wdata_prepare_pages(struct cifs_writedata *wdata, unsigned int found_pages, } static int -wdata_send_pages(struct cifs_writedata *wdata, unsigned int nr_pages, - struct address_space *mapping, struct writeback_control *wbc) +wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, + unsigned int nr_pages, struct address_space *mapping, + struct writeback_control *wbc) { int rc = 0; - struct TCP_Server_Info *server; unsigned int i; wdata->sync_mode = wbc->sync_mode; @@ -2092,6 +2092,10 @@ wdata_send_pages(struct cifs_writedata *wdata, unsigned int nr_pages, (loff_t)PAGE_SIZE); wdata->bytes = ((nr_pages - 1) * PAGE_SIZE) + wdata->tailsz; + rc = adjust_credits(server, &wdata->credits, wdata->bytes); + if (rc) + goto send_pages_out; + if (wdata->cfile != NULL) cifsFileInfo_put(wdata->cfile); wdata->cfile = find_writable_file(CIFS_I(mapping->host), false); @@ -2100,10 +2104,10 @@ wdata_send_pages(struct cifs_writedata *wdata, unsigned int nr_pages, rc = -EBADF; } else { wdata->pid = wdata->cfile->pid; - server = tlink_tcon(wdata->cfile->tlink)->ses->server; rc = server->ops->async_writev(wdata, cifs_writedata_release); } +send_pages_out: for (i = 0; i < nr_pages; ++i) unlock_page(wdata->pages[i]); @@ -2184,7 +2188,7 @@ static int cifs_writepages(struct address_space *mapping, wdata->credits = credits_on_stack; - rc = wdata_send_pages(wdata, nr_pages, mapping, wbc); + rc = wdata_send_pages(server, wdata, nr_pages, mapping, wbc); /* send failure -- clean up the mess */ if (rc != 0) { @@ -2743,10 +2747,17 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, wdata->ctx = ctx; kref_get(&ctx->refcount); - if (!wdata->cfile->invalidHandle || - !(rc = cifs_reopen_file(wdata->cfile, false))) - rc = server->ops->async_writev(wdata, + rc = adjust_credits(server, &wdata->credits, wdata->bytes); + + if (!rc) { + if (wdata->cfile->invalidHandle) + rc = cifs_reopen_file(wdata->cfile, false); + + if (!rc) + rc = server->ops->async_writev(wdata, cifs_uncached_writedata_release); + } + if (rc) { add_credits_and_wake_if(server, &wdata->credits, 0); kref_put(&wdata->refcount, @@ -3423,9 +3434,16 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, rdata->ctx = ctx; kref_get(&ctx->refcount); - if (!rdata->cfile->invalidHandle || - !(rc = cifs_reopen_file(rdata->cfile, true))) - rc = server->ops->async_readv(rdata); + rc = adjust_credits(server, &rdata->credits, rdata->bytes); + + if (!rc) { + if (rdata->cfile->invalidHandle) + rc = cifs_reopen_file(rdata->cfile, true); + + if (!rc) + rc = server->ops->async_readv(rdata); + } + if (rc) { add_credits_and_wake_if(server, &rdata->credits, 0); kref_put(&rdata->refcount, @@ -4165,9 +4183,16 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, rdata->pages[rdata->nr_pages++] = page; } - if (!rdata->cfile->invalidHandle || - !(rc = cifs_reopen_file(rdata->cfile, true))) - rc = server->ops->async_readv(rdata); + rc = adjust_credits(server, &rdata->credits, rdata->bytes); + + if (!rc) { + if (rdata->cfile->invalidHandle) + rc = cifs_reopen_file(rdata->cfile, true); + + if (!rc) + rc = server->ops->async_readv(rdata); + } + if (rc) { add_credits_and_wake_if(server, &rdata->credits, 0); for (i = 0; i < rdata->nr_pages; i++) { diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 354a7bc..1995bbe 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -222,6 +222,38 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, return rc; } +static int +smb2_adjust_credits(struct TCP_Server_Info *server, + struct cifs_credits *credits, + const unsigned int payload_size) +{ + int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE); + + if (!credits->value || credits->value == new_val) + return 0; + + if (credits->value < new_val) { + WARN_ONCE(1, "request has less credits (%d) than required (%d)", + credits->value, new_val); + return -ENOTSUPP; + } + + spin_lock(&server->req_lock); + + if (server->reconnect_instance != credits->instance) { + spin_unlock(&server->req_lock); + cifs_dbg(VFS, "trying to return %d credits to old session\n", + credits->value - new_val); + return -EAGAIN; + } + + server->credits += credits->value - new_val; + spin_unlock(&server->req_lock); + wake_up(&server->request_q); + credits->value = new_val; + return 0; +} + static __u64 smb2_get_next_mid(struct TCP_Server_Info *server) { @@ -3649,6 +3681,7 @@ struct smb_version_operations smb21_operations = { .get_credits_field = smb2_get_credits_field, .get_credits = smb2_get_credits, .wait_mtu_credits = smb2_wait_mtu_credits, + .adjust_credits = smb2_adjust_credits, .get_next_mid = smb2_get_next_mid, .read_data_offset = smb2_read_data_offset, .read_data_length = smb2_read_data_length, @@ -3745,6 +3778,7 @@ struct smb_version_operations smb30_operations = { .get_credits_field = smb2_get_credits_field, .get_credits = smb2_get_credits, .wait_mtu_credits = smb2_wait_mtu_credits, + .adjust_credits = smb2_adjust_credits, .get_next_mid = smb2_get_next_mid, .read_data_offset = smb2_read_data_offset, .read_data_length = smb2_read_data_length, @@ -3850,6 +3884,7 @@ struct smb_version_operations smb311_operations = { .get_credits_field = smb2_get_credits_field, .get_credits = smb2_get_credits, .wait_mtu_credits = smb2_wait_mtu_credits, + .adjust_credits = smb2_adjust_credits, .get_next_mid = smb2_get_next_mid, .read_data_offset = smb2_read_data_offset, .read_data_length = smb2_read_data_length, diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 8f92c22..ae558a4 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3313,21 +3313,11 @@ smb2_async_readv(struct cifs_readdata *rdata) SMB2_MAX_BUFFER_SIZE)); shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); - spin_lock(&server->req_lock); - if (server->reconnect_instance == rdata->credits.instance) - server->credits += rdata->credits.value - - le16_to_cpu(shdr->CreditCharge); - else { - spin_unlock(&server->req_lock); - cifs_dbg(VFS, "trying to return %u credits to old session\n", - rdata->credits.value - - le16_to_cpu(shdr->CreditCharge)); - rc = -EAGAIN; + + rc = adjust_credits(server, &rdata->credits, rdata->bytes); + if (rc) goto async_readv_out; - } - spin_unlock(&server->req_lock); - wake_up(&server->request_q); - rdata->credits.value = le16_to_cpu(shdr->CreditCharge); + flags |= CIFS_HAS_CREDITS; } @@ -3617,21 +3607,11 @@ smb2_async_writev(struct cifs_writedata *wdata, SMB2_MAX_BUFFER_SIZE)); shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); - spin_lock(&server->req_lock); - if (server->reconnect_instance == wdata->credits.instance) - server->credits += wdata->credits.value - - le16_to_cpu(shdr->CreditCharge); - else { - spin_unlock(&server->req_lock); - cifs_dbg(VFS, "trying to return %d credits to old session\n", - wdata->credits.value - - le16_to_cpu(shdr->CreditCharge)); - rc = -EAGAIN; + + rc = adjust_credits(server, &wdata->credits, wdata->bytes); + if (rc) goto async_writev_out; - } - spin_unlock(&server->req_lock); - wake_up(&server->request_q); - wdata->credits.value = le16_to_cpu(shdr->CreditCharge); + flags |= CIFS_HAS_CREDITS; } From patchwork Fri Feb 1 20:04:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793679 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 841E414E1 for ; Fri, 1 Feb 2019 20:04:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7721832C9E for ; Fri, 1 Feb 2019 20:04:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A511330BE; Fri, 1 Feb 2019 20:04:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 96A81330C8 for ; Fri, 1 Feb 2019 20:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730802AbfBAUEr (ORCPT ); Fri, 1 Feb 2019 15:04:47 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36296 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUEr (ORCPT ); Fri, 1 Feb 2019 15:04:47 -0500 Received: by mail-pl1-f196.google.com with SMTP id g9so3755749plo.3 for ; Fri, 01 Feb 2019 12:04:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=97zzKktc3udbeHhInQ+VvKJbp5abho+cFioCHTMeMXE=; b=od7fySbnFUR5ix/16AgIE7GP1ZsHpgpGF6mUjOv9T/4/aPvPf5F14CxnvR8qrUR5LF FlW8KdbJVKQ2B3CumQRlVlz1Lk1Vua7VquMpSgeFCx3LO4z9qGkWPfGN4BYSxILeLK76 kE5L+w1fXnHYlFDt1GUrE6RSPtdk5AXaAegrwZD2XNSFEMXSpl/ABgvAfVcUwrRbdM7k GEGgGmfhXaHrvUS2rv3COQVc3ebjMQF8bh4b9Smz3gK36GzMsnI/anskYB92bGHwij5w uJbEZggT7suD8VE6s49ALYY7fX0tjaDHamCWuof9TSTd7YHqMgk7seWc083DUzpIiEmY GP2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=97zzKktc3udbeHhInQ+VvKJbp5abho+cFioCHTMeMXE=; b=AIq1Pu2eN17MjXILsOiLkS8i6+JdPRRGqFGgIVaHNFTB8l67ymFasAn/TxnG5n86LT 13XEA75VVZ892DmhAFwHhBtPShXgZYlOQKrmP7VvBhzMvSDeqk1jA6V3uvGJg3IdYfH2 FmFnnMyGi9qHMw1YVwKHqPeN6tSroKcA5Jfuf7rFs0NhJaRuy2o97mEE7GZWR+W4Fn8s RlbTEta7LD/a/OChoxXnaaHHlzya9ki44QgdXcGqI3bNCTAidkL56HuU1xyQg0J8y6+D YZeXQuYIdBCTAZT1PlIAK6Iqw4ZVXyqara8lAsrN4NaubE4jRQyErkHZR4NJQFX7L9CD S0Fg== X-Gm-Message-State: AJcUukcninfR/XHv7ATs1Q4/u1qXYs2d6OTBzFEi4yVdQTR5QFAd1sn6 lN12pe+9OsfjCthHDeJ1E1/G1uU= X-Google-Smtp-Source: ALg8bN7YK1yQzrt2YgFFGdNMZtccaX3u/oY0byH/VCN/+hyGeEDy4qbaUxmrxnBwrNf0eAs1X+Wi1Q== X-Received: by 2002:a17:902:d911:: with SMTP id c17mr42190851plz.151.1549051486129; Fri, 01 Feb 2019 12:04:46 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:45 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 17/23] CIFS: Remove custom credit adjustments for SMB2 async IO Date: Fri, 1 Feb 2019 12:04:06 -0800 Message-Id: <1549051452-5968-19-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we do proper accounting for credits in regards to reconnects and error handling, thus we do not need custom credit adjustments when reconnect is detected developed previously. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/smb2pdu.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index ae558a4..03810b6 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3288,17 +3288,8 @@ smb2_async_readv(struct cifs_readdata *rdata) rc = smb2_new_read_req( (void **) &buf, &total_len, &io_parms, rdata, 0, 0); - if (rc) { - if (rc == -EAGAIN && rdata->credits.value) { - /* credits was reset by reconnect */ - rdata->credits.value = 0; - /* reduce in_flight value since we won't send the req */ - spin_lock(&server->req_lock); - server->in_flight--; - spin_unlock(&server->req_lock); - } + if (rc) return rc; - } if (smb3_encryption_required(io_parms.tcon)) flags |= CIFS_TRANSFORM_REQ; @@ -3506,17 +3497,8 @@ smb2_async_writev(struct cifs_writedata *wdata, unsigned int total_len; rc = smb2_plain_req_init(SMB2_WRITE, tcon, (void **) &req, &total_len); - if (rc) { - if (rc == -EAGAIN && wdata->credits.value) { - /* credits was reset by reconnect */ - wdata->credits.value = 0; - /* reduce in_flight value since we won't send the req */ - spin_lock(&server->req_lock); - server->in_flight--; - spin_unlock(&server->req_lock); - } - goto async_writev_out; - } + if (rc) + return rc; if (smb3_encryption_required(tcon)) flags |= CIFS_TRANSFORM_REQ; From patchwork Fri Feb 1 20:04:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEBA3186E for ; Fri, 1 Feb 2019 20:04:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C0432C9E for ; Fri, 1 Feb 2019 20:04:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C558F330BE; Fri, 1 Feb 2019 20:04:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 65E4D32E44 for ; Fri, 1 Feb 2019 20:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730805AbfBAUEt (ORCPT ); Fri, 1 Feb 2019 15:04:49 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34484 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUEs (ORCPT ); Fri, 1 Feb 2019 15:04:48 -0500 Received: by mail-pg1-f194.google.com with SMTP id j10so3437999pga.1 for ; Fri, 01 Feb 2019 12:04:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=S/XOWhkw0eO5pCMeHogTi4vaXlPRpWPK6e3BkJEqpvo=; b=hEpnlQycXO9qrO/7MUmuDCXdLp5DkXBnupdfk8nmUutJMqdR4vZ6xJvduY/JidB3hr /bARpcDJOtOF30kFJKEQx/uaHZzpRNShJTPmEz+HF3Mk2bv+OctpwTG61G98dcBu5bLf /ELlwMvlwaXY83Z7TDDx5FKvgAAmxl0ELMwup4K+//fCifyba1aWaZeXoyADoZ6t+uyE dSi8cpYHIekCQYHxgD0eRYPoYEqNcoeoMXd0OYbU2dKtd4LYXKljmPqEpz2EXC9CmlqG k7DF8prmsYkDsURAFmm0HMx6J/+I/6zn6tycraGTJQxua5KWh0Xrqk+ZSSp/jmbR0/ir plZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=S/XOWhkw0eO5pCMeHogTi4vaXlPRpWPK6e3BkJEqpvo=; b=aqx8W+8x6vlIfCmhfXVAhf6PHNwGibkKpza9XOQvsyqlt0wqEGvkDs/yY+6Y288bya PfousPEaX40gafXwYb4dwjHYYn/ySrWX6njkGduy2PKvqsbVZ+GEDCwgMj1e0r2yWCXa /p2rJMviJInHd3rY4La+OBvbjyoqc4sGHggAA3a/HHLuEzpoz80dW3LVEUPzGu6PoQL0 NYq1prh8Lqn6RIvZOWp4HAkB/qwRo1uY2i2m9//iq7NaG+p2Br9Oneg86warbEjFdHkN puiqMCHAMX1aicdu96AgL3PAPblYEgUQdlu4VlcrNdugoz5cxMAvKRj7Q0gj05VUHo07 SkSA== X-Gm-Message-State: AJcUukf1xmn8MZTnrnL/t6HsDYIuxJv+7vutbwQd9FhhhDSdFUOksGB8 tkky8JuG4soBmSpB/T0wGQR8Cs0= X-Google-Smtp-Source: ALg8bN4IjHJ2qB8E3CatqL0uKaXNlLALOmxSlGS7cDUG1RVlFyqJbriyBsS8o/KA1ApQf6Ntze/u9w== X-Received: by 2002:a62:c302:: with SMTP id v2mr41088896pfg.155.1549051487376; Fri, 01 Feb 2019 12:04:47 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:46 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 18/23] CIFS: Reopen file before get SMB2 MTU credits for async IO Date: Fri, 1 Feb 2019 12:04:07 -0800 Message-Id: <1549051452-5968-20-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we get MTU credits before we check an open file if it needs to be reopened. Reopening the file in such conditions leads to a possibility of being stuck waiting indefinitely for credits in the transport layer. Fix this by reopening the file first if needed and then getting MTU credits for async IO. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/file.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index e793b55..ef85a3c 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2650,6 +2650,14 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, struct cifs_credits credits_on_stack; struct cifs_credits *credits = &credits_on_stack; + if (open_file->invalidHandle) { + rc = cifs_reopen_file(open_file, false); + if (rc == -EAGAIN) + continue; + else if (rc) + break; + } + rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, &wsize, credits); if (rc) @@ -2751,9 +2759,8 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, if (!rc) { if (wdata->cfile->invalidHandle) - rc = cifs_reopen_file(wdata->cfile, false); - - if (!rc) + rc = -EAGAIN; + else rc = server->ops->async_writev(wdata, cifs_uncached_writedata_release); } @@ -3355,6 +3362,14 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, iov_iter_advance(&direct_iov, offset - ctx->pos); do { + if (open_file->invalidHandle) { + rc = cifs_reopen_file(open_file, true); + if (rc == -EAGAIN) + continue; + else if (rc) + break; + } + rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, &rsize, credits); if (rc) @@ -3438,9 +3453,8 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, if (!rc) { if (rdata->cfile->invalidHandle) - rc = cifs_reopen_file(rdata->cfile, true); - - if (!rc) + rc = -EAGAIN; + else rc = server->ops->async_readv(rdata); } @@ -4129,6 +4143,14 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, struct cifs_credits credits_on_stack; struct cifs_credits *credits = &credits_on_stack; + if (open_file->invalidHandle) { + rc = cifs_reopen_file(open_file, true); + if (rc == -EAGAIN) + continue; + else if (rc) + break; + } + rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize, &rsize, credits); if (rc) @@ -4187,9 +4209,8 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, if (!rc) { if (rdata->cfile->invalidHandle) - rc = cifs_reopen_file(rdata->cfile, true); - - if (!rc) + rc = -EAGAIN; + else rc = server->ops->async_readv(rdata); } From patchwork Fri Feb 1 20:04:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 863021390 for ; Fri, 1 Feb 2019 20:04:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77EAD32C9E for ; Fri, 1 Feb 2019 20:04:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C9F3330BE; Fri, 1 Feb 2019 20:04:51 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 10A8A32C9E for ; Fri, 1 Feb 2019 20:04:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730836AbfBAUEu (ORCPT ); Fri, 1 Feb 2019 15:04:50 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:32856 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUEu (ORCPT ); Fri, 1 Feb 2019 15:04:50 -0500 Received: by mail-pf1-f194.google.com with SMTP id c123so3755729pfb.0 for ; Fri, 01 Feb 2019 12:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=k3DR/GJI3ri84dMwIWJ8jof776E4fIH2W50KfxxDMCE=; b=FuRFkWZyR29Adp156Wan0rGaCzXWXr2Tn3yC4vXbhN44/XXbUXJw5i7NSTG7iMDtpA LCoq6IQGkUFJ+ikOC3OJ6Nc4Imw+mCnRq4h4iEFcx/7ApBfv42Yp/n7hCc4CZzvyRzsB 6OirGrA8S1IGC2tgiABQdBgSVZrUaDhASm9mNiHMdu1Ofvssn3YFcy24/TRUjRquNyT0 edAUDgmdJUVnib0K95kD31YkRcvQUxhELIBMntKLDyFsQ04vxWKHYRqUH2+gSTLswQ47 wshtumWpFG1rHrtteiyEDfElaEVhTbq3bw6okvcIDExNdIejqI/RfT2loOJhaOkDumq3 aleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=k3DR/GJI3ri84dMwIWJ8jof776E4fIH2W50KfxxDMCE=; b=SUGs0lH4kWrYLehdQrVgxGkteoDrKCYUyiGooLuQDEUmqIz/g1pZl3k3EG5k2e/0Rj EKHC7H8o4EWsLPIymfWfJtAcarCOzW/XCn/2YTIQH58M69037aldHXqV7V2jqr8gnZD+ XUQL0/VwDYaEKQPcjdEKlcVzUvDZGRws6urzaqwy02yt4bjLP/Usq0RPMhejBDEtWdBY afoIiq22OPZj9XUjDI909bcBgrjslum00V1vXnPR1IJeV6RvLSminYWG/k4g4vmmxArG tyWydATYGa11NVjomw4Fj8E0xY7XUdmhUVveejn/Lx0EpU3/HGWPP8a0ZxEdiP5BrN23 4oiA== X-Gm-Message-State: AJcUukcELPNJrTNFz3qzU7a4GKoHY1eEzUArwzsP5GZlyKBC7hAfv4P8 QO4DAmFJTsej+BAqjQVA9xEoz3A= X-Google-Smtp-Source: ALg8bN7WS7y6vS8yLczX4gH01Sq9PKJ5f2aQ50VA1UnR1BejOdxWOBUFoq+u9LU18cXor3gPuybeYg== X-Received: by 2002:a62:509b:: with SMTP id g27mr41121602pfj.48.1549051488540; Fri, 01 Feb 2019 12:04:48 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:47 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 19/23] CIFS: Find and reopen a file before get MTU credits in writepages Date: Fri, 1 Feb 2019 12:04:08 -0800 Message-Id: <1549051452-5968-21-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Reorder finding and reopening a writable handle file and getting MTU credits in writepages because we may be stuck on low credits otherwise. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/file.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index ef85a3c..dd8bf69 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2096,15 +2096,16 @@ wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, if (rc) goto send_pages_out; - if (wdata->cfile != NULL) - cifsFileInfo_put(wdata->cfile); - wdata->cfile = find_writable_file(CIFS_I(mapping->host), false); if (!wdata->cfile) { - cifs_dbg(VFS, "No writable handles for inode\n"); + cifs_dbg(VFS, "No writable handle in writepages\n"); rc = -EBADF; } else { wdata->pid = wdata->cfile->pid; - rc = server->ops->async_writev(wdata, cifs_writedata_release); + if (wdata->cfile->invalidHandle) + rc = -EAGAIN; + else + rc = server->ops->async_writev(wdata, + cifs_writedata_release); } send_pages_out: @@ -2117,11 +2118,13 @@ wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, static int cifs_writepages(struct address_space *mapping, struct writeback_control *wbc) { - struct cifs_sb_info *cifs_sb = CIFS_SB(mapping->host->i_sb); + struct inode *inode = mapping->host; + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct TCP_Server_Info *server; bool done = false, scanned = false, range_whole = false; pgoff_t end, index; struct cifs_writedata *wdata; + struct cifsFileInfo *cfile = NULL; int rc = 0; int saved_rc = 0; unsigned int xid; @@ -2152,6 +2155,11 @@ static int cifs_writepages(struct address_space *mapping, struct cifs_credits credits_on_stack; struct cifs_credits *credits = &credits_on_stack; + if (cfile) + cifsFileInfo_put(cfile); + + cfile = find_writable_file(CIFS_I(inode), false); + rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, &wsize, credits); if (rc != 0) { @@ -2187,6 +2195,8 @@ static int cifs_writepages(struct address_space *mapping, } wdata->credits = credits_on_stack; + wdata->cfile = cfile; + cfile = NULL; rc = wdata_send_pages(server, wdata, nr_pages, mapping, wbc); @@ -2244,6 +2254,8 @@ static int cifs_writepages(struct address_space *mapping, if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) mapping->writeback_index = index; + if (cfile) + cifsFileInfo_put(cfile); free_xid(xid); return rc; } From patchwork Fri Feb 1 20:04:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE6401390 for ; Fri, 1 Feb 2019 20:04:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B04A032C9E for ; Fri, 1 Feb 2019 20:04:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5067330BE; Fri, 1 Feb 2019 20:04:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 46E0332C9E for ; Fri, 1 Feb 2019 20:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730838AbfBAUEw (ORCPT ); Fri, 1 Feb 2019 15:04:52 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37126 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUEv (ORCPT ); Fri, 1 Feb 2019 15:04:51 -0500 Received: by mail-pg1-f195.google.com with SMTP id c25so3433088pgb.4 for ; Fri, 01 Feb 2019 12:04:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=T9tOKlKtEoIY8+gqJRbprGCpsBu5Rn8NVjmO/12hMEM=; b=dE7MYqaIhQ6vmNin8yz7npNkU7tnziX2XBmOqzFdslskCeB1pcS0blYtTtg3vWQRYs Fsn2nBOGBP7jjjMPcAjpVSDXOuCo3L3WpesBqr4e2dUzYYUNDJtw0aineW1y5IYlnQr7 cklVrGgalyO5fOyKJmL5J5ZLlTP1Nbv6d6/csXGNoWDZ6MUo+QEhQrYSP+eR0jRoyw85 U178w81yqZkZii7yhjwLIw2D8PFU9+HYsmjStMacHqf+c3IyqG1m+6JqRXmxrLQ7oMhE LUtmu/z72t60WdFNh6lClq+G4eqX3so9aDSbf4mOd/WA8yilPYYqbElcVldMsj6slypl vgSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=T9tOKlKtEoIY8+gqJRbprGCpsBu5Rn8NVjmO/12hMEM=; b=nKwuljn2y7tp9tPX62lOQHGjYvUSiposgiCenUkDKkVEYkMRJj1lddi+OO+BG9AcWu gP9XcQy6eE80jenAlhoWOqK1qK4YU7S5UKs18EMGQ+bI5Rf+q7080ZmSeLAptcykNvzS PQfBlyeF3hAW2Xx5GRwxkFS4pI8yClKahjaskaNFREV7tzo5hzXfsnbDqTKhMYlEg7PS O+KrFyMZrkMkvLO0ZOoDHpUmqvCmlv7knKZowkgZPNSycr3YTMwQeeMrQuCvCY7ymF+j Y9Yoan7Qc+OBDj4W4kbNaczEX1iit/+5i/RpcIagsHsb3DitgDHZr74+C8WFqeuuG9e1 OPmg== X-Gm-Message-State: AJcUukdCVAntLUa5FdO9e6n6wfrixt2fL2Hn4YFCqcPw8xke1pwb8NlS S8kmQ7kgYaLK4OoGnVLGY0uBncA= X-Google-Smtp-Source: ALg8bN6irD6mLNGaGHnrRgQJCIjv+ZL/4jQijEjOxg79xd2LPagJo+VHtfahGyKD2HgW6Ci3xEA2Eg== X-Received: by 2002:a62:56c7:: with SMTP id h68mr42449756pfj.134.1549051490435; Fri, 01 Feb 2019 12:04:50 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:48 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 20/23] CIFS: Move unlocking pages from wdata_send_pages() Date: Fri, 1 Feb 2019 12:04:09 -0800 Message-Id: <1549051452-5968-22-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently wdata_send_pages() unlocks pages after sending. This complicates further refactoring and doesn't align with the function name. Move unlocking to writepages. Signed-off-by: Pavel Shilovsky --- fs/cifs/file.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index dd8bf69..cb37b1f 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2080,8 +2080,7 @@ wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, unsigned int nr_pages, struct address_space *mapping, struct writeback_control *wbc) { - int rc = 0; - unsigned int i; + int rc; wdata->sync_mode = wbc->sync_mode; wdata->nr_pages = nr_pages; @@ -2094,7 +2093,7 @@ wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, rc = adjust_credits(server, &wdata->credits, wdata->bytes); if (rc) - goto send_pages_out; + return rc; if (!wdata->cfile) { cifs_dbg(VFS, "No writable handle in writepages\n"); @@ -2108,10 +2107,6 @@ wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, cifs_writedata_release); } -send_pages_out: - for (i = 0; i < nr_pages; ++i) - unlock_page(wdata->pages[i]); - return rc; } @@ -2200,6 +2195,9 @@ static int cifs_writepages(struct address_space *mapping, rc = wdata_send_pages(server, wdata, nr_pages, mapping, wbc); + for (i = 0; i < nr_pages; ++i) + unlock_page(wdata->pages[i]); + /* send failure -- clean up the mess */ if (rc != 0) { add_credits_and_wake_if(server, &wdata->credits, 0); From patchwork Fri Feb 1 20:04:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F70514E1 for ; Fri, 1 Feb 2019 20:04:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 910A932C9E for ; Fri, 1 Feb 2019 20:04:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 828B8330BE; Fri, 1 Feb 2019 20:04:54 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 247D832C9E for ; Fri, 1 Feb 2019 20:04:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730896AbfBAUEx (ORCPT ); Fri, 1 Feb 2019 15:04:53 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43210 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUEx (ORCPT ); Fri, 1 Feb 2019 15:04:53 -0500 Received: by mail-pl1-f196.google.com with SMTP id gn14so3733806plb.10 for ; Fri, 01 Feb 2019 12:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=toRxBoqLZ2IHytwWefehAzDcg9toGYJnopSsVEdJtoc=; b=K/0KrO7nqd6IUz3su4qGKaZn5zhAsO/RYcGonXO/kC579HqsML8Qs7x8YmAySjscVq +0POaOd20bno1fyzhaLRdcTDk+fOMvqp9V+BrxvCb3rQhrpSmLVtWtpH37p+7bktKvXq zCiLhlu29esIUa8H4K3o1BMZChxHF0UoUyKYNKgEBNVN2Sl0L+I3WISxahCvP3jjxMh8 2ciKTaXUZMYLppYA4ESC8gjnjcF4SwAtsUZq+zvaBqL7wLiMgnsFlSLbX/HWstx1M41z iilk7nkuKoKGF0lACvtZ+o5UJ/E2PGwlflGAG8AH0QAeBa9OmhfzrEvXzT4Nz/9fxF+i ZqRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=toRxBoqLZ2IHytwWefehAzDcg9toGYJnopSsVEdJtoc=; b=qhiHBEzQA9UJhvysJ4KGRHD3Hhe/UrXWjMNJBDXHE8iGxA9jVuxDSISf4wQ1E4POZj +QvNKSIJhChlC/hLaCGO18+2bUlS4sXsf3wTkHbQs0lmLWDxYfnFN3q4lsfgZrtHU16u Zv3bzyMit8F/MYQ9nDHzAlCMUqCXxFrMlCuZyhRG5fopVWzSg/p2wb1J4d4F89hsQI0x pV2LK7sNsYGrs3dl+jeGoEU9p9f23acCfnn+QJN3NMh/HqqAzU4nb6SovH3D+esu2eUh IQqbqh/CPwqQTx7IImn0xoEHt2mAKfubNdYhQBfZsXKs+KA2TIaRbraB/aZCcqVCKiyg YMTA== X-Gm-Message-State: AJcUukc03Qs/iOCcNZD8dBklbhe/+dgYYDm6OC+LAKAMtUtSCz2C6Gg1 WhYM32UD00C6SsiEoa0QdPEk4vI= X-Google-Smtp-Source: ALg8bN6HI4qalP5UKrZ7HkfXoZG/XuruNqytRipoRa1ZdOHNV2v+Vg+IwXm5ICM69XeZM+3SqFwb9A== X-Received: by 2002:a17:902:7614:: with SMTP id k20mr41543046pll.285.1549051492586; Fri, 01 Feb 2019 12:04:52 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:51 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 21/23] CIFS: Move open file handling to writepages Date: Fri, 1 Feb 2019 12:04:10 -0800 Message-Id: <1549051452-5968-23-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we check for an open file existence in wdata_send_pages() which doesn't provide an easy way to handle error codes that will be returned from find_writable_filehandle() once it is changed. Move the check to writepages. Signed-off-by: Pavel Shilovsky --- fs/cifs/file.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index cb37b1f..9de7ad5 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2076,11 +2076,12 @@ wdata_prepare_pages(struct cifs_writedata *wdata, unsigned int found_pages, } static int -wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, - unsigned int nr_pages, struct address_space *mapping, - struct writeback_control *wbc) +wdata_send_pages(struct cifs_writedata *wdata, unsigned int nr_pages, + struct address_space *mapping, struct writeback_control *wbc) { int rc; + struct TCP_Server_Info *server = + tlink_tcon(wdata->cfile->tlink)->ses->server; wdata->sync_mode = wbc->sync_mode; wdata->nr_pages = nr_pages; @@ -2090,22 +2091,16 @@ wdata_send_pages(struct TCP_Server_Info *server, struct cifs_writedata *wdata, page_offset(wdata->pages[nr_pages - 1]), (loff_t)PAGE_SIZE); wdata->bytes = ((nr_pages - 1) * PAGE_SIZE) + wdata->tailsz; + wdata->pid = wdata->cfile->pid; rc = adjust_credits(server, &wdata->credits, wdata->bytes); if (rc) return rc; - if (!wdata->cfile) { - cifs_dbg(VFS, "No writable handle in writepages\n"); - rc = -EBADF; - } else { - wdata->pid = wdata->cfile->pid; - if (wdata->cfile->invalidHandle) - rc = -EAGAIN; - else - rc = server->ops->async_writev(wdata, - cifs_writedata_release); - } + if (wdata->cfile->invalidHandle) + rc = -EAGAIN; + else + rc = server->ops->async_writev(wdata, cifs_writedata_release); return rc; } @@ -2193,7 +2188,11 @@ static int cifs_writepages(struct address_space *mapping, wdata->cfile = cfile; cfile = NULL; - rc = wdata_send_pages(server, wdata, nr_pages, mapping, wbc); + if (!wdata->cfile) { + cifs_dbg(VFS, "No writable handle in writepages\n"); + rc = -EBADF; + } else + rc = wdata_send_pages(wdata, nr_pages, mapping, wbc); for (i = 0; i < nr_pages; ++i) unlock_page(wdata->pages[i]); From patchwork Fri Feb 1 20:04:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE11414E1 for ; Fri, 1 Feb 2019 20:04:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEA6432C9E for ; Fri, 1 Feb 2019 20:04:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2EA0330BE; Fri, 1 Feb 2019 20:04:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 05E6432C9E for ; Fri, 1 Feb 2019 20:04:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730907AbfBAUE4 (ORCPT ); Fri, 1 Feb 2019 15:04:56 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34149 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUE4 (ORCPT ); Fri, 1 Feb 2019 15:04:56 -0500 Received: by mail-pl1-f193.google.com with SMTP id w4so3755715plz.1 for ; Fri, 01 Feb 2019 12:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=eeODu+Anqq7007oRLFqaUWtcfY2hLJg5RcOxDwuXI7g=; b=LXfkyAxVwTCMS4JZwBxHtPNFV0RNZ8fuXrXMmO7zxoCdzkWM1mOhxKbmADbtjMoJwD y27haodbUV9WTlX09four8vVdOzAYJ+QPz2SaYabNCgEryQMYSPjRo8Jg/wZ/7TnqN7T 0cfM01IqKpo02AOf/dGUqpGIuXk5wDRg9/mwrfScyym4stH9nUfUPkqqgTtqBBClor+F LDcSMdARUwvixx1Q7eNvymcRMxMKteNjyNx1oR00n8XW4x2WYWsP9X6q6TtDqMQZ20Ws 0RPlcQEtp9vzDH2UH2wBikxUiHv5n5kLjpW85I3z1dD63DkMpl2jXHgYQNgq7erm3y6G byYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=eeODu+Anqq7007oRLFqaUWtcfY2hLJg5RcOxDwuXI7g=; b=nDTGlV9DqYxqfYCyRfXU2025MziJLn5AbD7wr2IJyuT/CyUW+yJGzeE8lnlhKgYKOA L+bSBe0Rwi0GNhxhB1jx4bPKPKq41N6ACrwT6taiAkqWQ+7x8zYbJSr/yobC78tZz+/j bo2YCK1aBbUpnboOry48qoGP+zD4YwOdbw5TydPanZdeUvqvY0sWkAVfXMOFeJpsxsKY pBMfBuvsCUzKYxBr1bWJb0//bTYBv4GUQPnN++xHgeRF2rHFVtMdTq6g0fmDpf8V1XhX lZngtjo1lcPNPBv4gPUVqUZqvjQvd33y069X/wUy9judZ3yhQupM0HE6zxUAlIedNVCz St1w== X-Gm-Message-State: AJcUukeQIs9pVAhjeGvtPsykrasGW+kVSXUcecd09p23XJm+GQuNbNl7 3fN49X4aWJ7GdurYdquJX0LVMvE= X-Google-Smtp-Source: ALg8bN48Cmc2ZeK3aQ60CitzixNxKe6oWXvmv4728tSBgPie2CrWy0nhCkjW4fyhJJAGBLbD34bwew== X-Received: by 2002:a17:902:d891:: with SMTP id b17mr41621319plz.80.1549051495118; Fri, 01 Feb 2019 12:04:55 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:53 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 22/23] CIFS: Return error code when getting file handle for writeback Date: Fri, 1 Feb 2019 12:04:11 -0800 Message-Id: <1549051452-5968-24-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Now we just return NULL cifsFileInfo pointer in cases we didn't find or couldn't reopen a file. This hides errors from cifs_reopen_file() especially retryable errors which should be handled appropriately. Create new cifs_get_writable_file() routine that returns error codes from cifs_reopen_file() and use it in the writeback codepath. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsproto.h | 3 ++ fs/cifs/cifssmb.c | 9 ++++-- fs/cifs/file.c | 90 ++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 70 insertions(+), 32 deletions(-) diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 9e8394f..4f96b3b 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h @@ -134,6 +134,9 @@ extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, unsigned int bytes_written); extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); +extern int cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, + bool fsuid_only, + struct cifsFileInfo **ret_file); extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); extern unsigned int smbCalcSize(void *buf, struct TCP_Server_Info *server); extern int decode_negTokenInit(unsigned char *security_blob, int length, diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 6c89279..c0e3a04 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -2126,10 +2126,13 @@ cifs_writev_requeue(struct cifs_writedata *wdata) wdata2->tailsz = tailsz; wdata2->bytes = cur_len; - wdata2->cfile = find_writable_file(CIFS_I(inode), false); + rc = cifs_get_writable_file(CIFS_I(inode), false, + &wdata2->cfile); if (!wdata2->cfile) { - cifs_dbg(VFS, "No writable handle to retry writepages\n"); - rc = -EBADF; + cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n", + rc); + if (!is_retryable_error(rc)) + rc = -EBADF; } else { wdata2->pid = wdata2->cfile->pid; rc = server->ops->async_writev(wdata2, diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 9de7ad5..85a034d 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1842,24 +1842,30 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode, return NULL; } -struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, - bool fsuid_only) +/* Return -EBADF if no handle is found and general rc otherwise */ +int +cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, bool fsuid_only, + struct cifsFileInfo **ret_file) { struct cifsFileInfo *open_file, *inv_file = NULL; struct cifs_sb_info *cifs_sb; struct cifs_tcon *tcon; bool any_available = false; - int rc; + int rc = -EBADF; unsigned int refind = 0; - /* Having a null inode here (because mapping->host was set to zero by - the VFS or MM) should not happen but we had reports of on oops (due to - it being zero) during stress testcases so we need to check for it */ + *ret_file = NULL; + + /* + * Having a null inode here (because mapping->host was set to zero by + * the VFS or MM) should not happen but we had reports of on oops (due + * to it being zero) during stress testcases so we need to check for it + */ if (cifs_inode == NULL) { cifs_dbg(VFS, "Null inode passed to cifs_writeable_file\n"); dump_stack(); - return NULL; + return rc; } cifs_sb = CIFS_SB(cifs_inode->vfs_inode.i_sb); @@ -1873,7 +1879,7 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, refind_writable: if (refind > MAX_REOPEN_ATT) { spin_unlock(&tcon->open_file_lock); - return NULL; + return rc; } list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { if (!any_available && open_file->pid != current->tgid) @@ -1885,7 +1891,8 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, /* found a good writable file */ cifsFileInfo_get(open_file); spin_unlock(&tcon->open_file_lock); - return open_file; + *ret_file = open_file; + return 0; } else { if (!inv_file) inv_file = open_file; @@ -1907,22 +1914,35 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, if (inv_file) { rc = cifs_reopen_file(inv_file, false); - if (!rc) - return inv_file; - else { - spin_lock(&tcon->open_file_lock); - list_move_tail(&inv_file->flist, - &cifs_inode->openFileList); - spin_unlock(&tcon->open_file_lock); - cifsFileInfo_put(inv_file); - ++refind; - inv_file = NULL; - spin_lock(&tcon->open_file_lock); - goto refind_writable; + if (!rc) { + *ret_file = inv_file; + return 0; } + + spin_lock(&tcon->open_file_lock); + list_move_tail(&inv_file->flist, &cifs_inode->openFileList); + spin_unlock(&tcon->open_file_lock); + cifsFileInfo_put(inv_file); + ++refind; + inv_file = NULL; + spin_lock(&tcon->open_file_lock); + goto refind_writable; } - return NULL; + return rc; +} + +struct cifsFileInfo * +find_writable_file(struct cifsInodeInfo *cifs_inode, bool fsuid_only) +{ + struct cifsFileInfo *cfile; + int rc; + + rc = cifs_get_writable_file(cifs_inode, fsuid_only, &cfile); + if (rc) + cifs_dbg(FYI, "couldn't find writable handle rc=%d", rc); + + return cfile; } static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) @@ -1959,8 +1979,8 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) if (mapping->host->i_size - offset < (loff_t)to) to = (unsigned)(mapping->host->i_size - offset); - open_file = find_writable_file(CIFS_I(mapping->host), false); - if (open_file) { + rc = cifs_get_writable_file(CIFS_I(mapping->host), false, &open_file); + if (!rc) { bytes_written = cifs_write(open_file, open_file->pid, write_data, to - from, &offset); cifsFileInfo_put(open_file); @@ -1970,9 +1990,12 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) rc = 0; else if (bytes_written < 0) rc = bytes_written; + else + rc = -EFAULT; } else { - cifs_dbg(FYI, "No writeable filehandles for inode\n"); - rc = -EIO; + cifs_dbg(FYI, "No writable handle for write page rc=%d\n", rc); + if (!is_retryable_error(rc)) + rc = -EIO; } kunmap(page); @@ -2144,11 +2167,16 @@ static int cifs_writepages(struct address_space *mapping, pgoff_t next = 0, tofind, saved_index = index; struct cifs_credits credits_on_stack; struct cifs_credits *credits = &credits_on_stack; + int get_file_rc = 0; if (cfile) cifsFileInfo_put(cfile); - cfile = find_writable_file(CIFS_I(inode), false); + rc = cifs_get_writable_file(CIFS_I(inode), false, &cfile); + + /* in case of an error store it to return later */ + if (rc) + get_file_rc = rc; rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, &wsize, credits); @@ -2189,8 +2217,12 @@ static int cifs_writepages(struct address_space *mapping, cfile = NULL; if (!wdata->cfile) { - cifs_dbg(VFS, "No writable handle in writepages\n"); - rc = -EBADF; + cifs_dbg(VFS, "No writable handle in writepages rc=%d\n", + get_file_rc); + if (is_retryable_error(get_file_rc)) + rc = get_file_rc; + else + rc = -EBADF; } else rc = wdata_send_pages(wdata, nr_pages, mapping, wbc); From patchwork Fri Feb 1 20:04:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B29F81390 for ; Fri, 1 Feb 2019 20:04:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A158332BED for ; Fri, 1 Feb 2019 20:04:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9294D330BE; Fri, 1 Feb 2019 20:04:59 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 F1DDC32C9E for ; Fri, 1 Feb 2019 20:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730964AbfBAUE6 (ORCPT ); Fri, 1 Feb 2019 15:04:58 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45021 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfBAUE6 (ORCPT ); Fri, 1 Feb 2019 15:04:58 -0500 Received: by mail-pl1-f195.google.com with SMTP id p4so464447plq.11 for ; Fri, 01 Feb 2019 12:04:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=V+Ma/W/HROjy51lLUDIsOEXiXNxj0ddW5oujNV1TfkM=; b=BzLgvT8GcbJkbeBcxy1m6kJs2YtaQKXeNo84E6kuu3HudwaM0JGkpk9C2k2RLw55g6 yDWojSxSghAvgycz64lBIhqgNc0FClMkT+UYm/4XTC4i7bhqs+Ddcb0QsukHbPzMUVLj KETRUHglGJzjH9/D245pq00aDMJBR8e5hIp8V8prHjMM7E8v5sMd6Jq/hE0+q2cHmCQl tJro4jmp5SpMs1GApJQCSHyGe7gm8io88OJ08oBhU8cHR+UxU6SJs3ubBIhJLnoFrqR3 R15a75zTnZaqA88cIwm1t4N6CE5qJK+dqvFuZlz+mKWAvJr07qCV7KYHzOnVSpjk8hJl mFJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=V+Ma/W/HROjy51lLUDIsOEXiXNxj0ddW5oujNV1TfkM=; b=oyG0cAbYudPYJJMD79n+MY0eBb0YgUdHhooaOXZuXahFICq1WEulfKXZgbw8gyTKln cp52CXI49eBgm6Qsn5gn71Pay4vE/bx//TSuX0OtPJ+6/qVPch68uM7U7Kcx1IcwR4fH R02HnhXqbjtYAqAno6TydciTc4F+um7aJieXS1BVn5jZ28zYwkMILhJxZ80PA2j1e4mY mI2eGQVC0YhPQWTOcZAwsucYaWrFgXEDuXCSFZfmxSSZ8SXSKcM5ICHTO9eWh8LZPv+K qRB82zoJW/1vrxLxsZWN0fgOOHo/Aq2vhWNZfYoIST4DYErAd829iUdUUvCnXbDFKbHU dtlA== X-Gm-Message-State: AJcUukekp7fu65qTnJFi2dmAuU4xMPPjmqO0B7mtaY6QJzDRueso5fM6 Qq8LUkQA7MI2VgYxxDHkcnhZRxU= X-Google-Smtp-Source: ALg8bN4MJC9ePmxJf9OYX3nPJXqAocp7egnMK6SgrOElxYawKPVzcHx9q6nrm5Z3OW0RptiidgG2Iw== X-Received: by 2002:a17:902:3064:: with SMTP id u91mr40226141plb.325.1549051497395; Fri, 01 Feb 2019 12:04:57 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:55 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 23/23] CIFS: Try to acquire credits at once for compound requests Date: Fri, 1 Feb 2019 12:04:12 -0800 Message-Id: <1549051452-5968-25-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.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 Currently we get one credit per compound part of the request individually. This may lead to being stuck on waiting for credits if multiple compounded operations happen in parallel. Try acquire credits for all compound parts at once. Return immediately if not enough credits and too few requests are in flight currently thus narrowing the possibility of infinite waiting for credits. The more advance fix is to return right away if not enough credits for the compound request and do not look at the number of requests in flight. The caller should handle such situations by falling back to sequential execution of SMB commands instead of compounding. Signed-off-by: Pavel Shilovsky --- fs/cifs/transport.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 2187bc3..d4f1224f 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -886,13 +886,41 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, if (ses->server->tcpStatus == CifsExiting) return -ENOENT; + spin_lock(&ses->server->req_lock); + if (ses->server->credits < num_rqst) { + /* + * Return immediately if not too many requests in flight since + * we will likely be stuck on waiting for credits. + */ + if (ses->server->in_flight < num_rqst - ses->server->credits) { + spin_unlock(&ses->server->req_lock); + return -ENOTSUPP; + } + } else { + /* enough credits to send the whole compounded request */ + ses->server->credits -= num_rqst; + ses->server->in_flight += num_rqst; + first_instance = ses->server->reconnect_instance; + } + spin_unlock(&ses->server->req_lock); + + if (first_instance) { + cifs_dbg(FYI, "Acquired %d credits at once\n", num_rqst); + for (i = 0; i < num_rqst; i++) { + credits[i].value = 1; + credits[i].instance = first_instance; + } + goto setup_rqsts; + } + /* + * There are not enough credits to send the whole compound request but + * there are requests in flight that may bring credits from the server. + * This approach still leaves the possibility to be stuck waiting for + * credits if the server doesn't grant credits to the outstanding + * requests. This should be fixed by returning immediately and letting + * a caller fallback to sequential commands instead of compounding. * Ensure we obtain 1 credit per request in the compound chain. - * It can be optimized further by waiting for all the credits - * at once but this can wait long enough if we don't have enough - * credits due to some heavy operations in progress or the server - * not granting us much, so a fallback to the current approach is - * needed anyway. */ for (i = 0; i < num_rqst; i++) { rc = wait_for_free_request(ses->server, timeout, optype, @@ -932,6 +960,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, } } +setup_rqsts: /* * Make sure that we sign in the same order that we send on this socket * and avoid races inside tcp sendmsg code that could cause corruption