From patchwork Thu Jan 10 22:24: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: 1023249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GFOSWyeZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43bLCq0cQ1z9sCs for ; Fri, 11 Jan 2019 09:25:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728880AbfAJWZK (ORCPT ); Thu, 10 Jan 2019 17:25:10 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43354 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727733AbfAJWZK (ORCPT ); Thu, 10 Jan 2019 17:25:10 -0500 Received: by mail-pf1-f194.google.com with SMTP id w73so5940486pfk.10 for ; Thu, 10 Jan 2019 14:25:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=105S6pQ5pA4b/rPVxwVJglt6CcPumATISPUxGARhoGo=; b=GFOSWyeZscI18W8mNS12zIKlGuR9+f0lgrGJWm+ZgUe+CNusMBQ7ifmKpl9hKbuPZ9 w2SOqU5ArD8EfayRlekfFqvuN+Vew+4+nmADgmkO6wQG0HywFFQ5njRKSaMvu25vIF7o gFNalJ4/vNTU0kz9bpvqVlP5jWesHqL64k0FQ36r+yLBp1wFkHybrj29ah94uDwq3/eB 4gbS59V/PR8lF812eHV0oHxvGP/c4GBkrXU41VEJL7GscxbvODbmIPEzy5P/ggEufZYk 5FthZq0iMSZsrDgkDZBcrVxyXhIuGK6MhGHMRsDDawT7/bAO+vuucqVDUjuI/nbjh8Os mk9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=105S6pQ5pA4b/rPVxwVJglt6CcPumATISPUxGARhoGo=; b=bm40rjiJWzPDfL3rXTpBnt05ovVZaPIDQo637Jo0c6ZKy+048jiPZtW1IY8WG4gHk4 r97I9pTkiapNMwDxCoGMMS9PZiQAsYkQwCKgUnpXVmwirSYf15P4IRpn9JbpXVhm84bl tUJUqFuMdwVyD2GzS444sBOC85kuuTw9CBMyiwhvw2By9a+wppIB7X693zV7xn379Jef I81eKbeOvVURUxPjvJEOpFIUhBnJk9ScZauDtU+3HF7uaa7/YCv+WRFDZRSnjM16ga+k 6CUMHWipS3dKjMQueOamGU9f6R/YZJXa/RVfIJ05IbeQPcVtwKgdLw9/WgP5z31aHKsX U4fw== X-Gm-Message-State: AJcUukdgzbl6Nx88dfBO4jV6H5Wy/77CwgHD+q2rWZOcjsC8PV+yjemQ Us5F3sBxSnPXD2yQ3R2bL4NC4uo= X-Google-Smtp-Source: ALg8bN4sY56UqmCivF40mV++kdO2DUKVFAp5RhWutuiB6evorVSK56hK6EoduDT9V1qQYFTeB1FrcQ== X-Received: by 2002:a62:5182:: with SMTP id f124mr12097910pfb.238.1547159108288; Thu, 10 Jan 2019 14:25:08 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:3:a18b:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id z127sm118006755pfb.80.2019.01.10.14.25.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 14:25:07 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Steve French , Ronnie Sahlberg Subject: [PATCH 1/7] CIFS: Fix adjustment of credits for MTU requests Date: Thu, 10 Jan 2019 14:24:52 -0800 Message-Id: <1547159098-19011-2-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547159098-19011-1-git-send-email-pshilov@microsoft.com> References: <1547159098-19011-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 Currently for MTU requests we allocate maximum possible credits in advance and then adjust them according to the request size. While we were adjusting the number of credits belonging to the server, we were skipping adjustment of credits belonging to the request. This patch fixes it by setting request credits to CreditCharge field value of SMB2 packet header. Also ask 1 credit more for async read and write operations to increase parallelism and match the behavior of other operations. Cc: Signed-off-by: Pavel Shilovskiy --- fs/cifs/smb2pdu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index e283590..f158825 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3264,12 +3264,14 @@ smb2_async_readv(struct cifs_readdata *rdata) if (rdata->credits) { shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes, SMB2_MAX_BUFFER_SIZE)); - shdr->CreditRequest = shdr->CreditCharge; + shdr->CreditRequest = + cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); spin_lock(&server->req_lock); server->credits += rdata->credits - le16_to_cpu(shdr->CreditCharge); spin_unlock(&server->req_lock); wake_up(&server->request_q); + rdata->credits = le16_to_cpu(shdr->CreditCharge); flags |= CIFS_HAS_CREDITS; } @@ -3541,12 +3543,14 @@ smb2_async_writev(struct cifs_writedata *wdata, if (wdata->credits) { shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes, SMB2_MAX_BUFFER_SIZE)); - shdr->CreditRequest = shdr->CreditCharge; + shdr->CreditRequest = + cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 1); spin_lock(&server->req_lock); server->credits += wdata->credits - le16_to_cpu(shdr->CreditCharge); spin_unlock(&server->req_lock); wake_up(&server->request_q); + wdata->credits = le16_to_cpu(shdr->CreditCharge); flags |= CIFS_HAS_CREDITS; } From patchwork Thu Jan 10 22:24: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: 1023250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uYrmD5qd"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43bLCq626Mz9sCr for ; Fri, 11 Jan 2019 09:25:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727733AbfAJWZL (ORCPT ); Thu, 10 Jan 2019 17:25:11 -0500 Received: from mail-pg1-f175.google.com ([209.85.215.175]:33198 "EHLO mail-pg1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728800AbfAJWZL (ORCPT ); Thu, 10 Jan 2019 17:25:11 -0500 Received: by mail-pg1-f175.google.com with SMTP id z11so5430718pgu.0 for ; Thu, 10 Jan 2019 14:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Yy1kzkUReLtCO4bKAAShZG0eJGrSq9RSrExy7M5jaIU=; b=uYrmD5qdrT4yvq1w24cyPKnZEx+jHnwKMn/KJLyMi5DxvfHpTx7UZf8qhjLxqFZkxc 51buuSGWCvzYVZ31OI6ByZ0og/5H6DwzNpSsDo14lhDEn73Zv4mvanJce9QJqFLHFPgp lprux9LBQdlDkL3d7wbJ30Zd4OrE9HKqIdtfG2A/XEmE3aW7EYLz9//pF4AVK/d4ofuj gJIf9DTmfVsZW+X6MHRtHvve6yqzT/4Hlr8wfQSv0s2V5pOXOwTROtd3GsFCaj/+5COv oZRlEt5cKrcpE//wHozoyEAS4GwxpCM3sMrIBcLm61cW/QF2df6M1qXnEOO4KkDB4mZ6 DeUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Yy1kzkUReLtCO4bKAAShZG0eJGrSq9RSrExy7M5jaIU=; b=CUQQ7uwCuV1NU+Lhf/m6Vtl+Z1+G6dgQloG6Ps88gkgrink34xd/plQR8JeaaBilf7 1yfzg4N6glwkovWNZTu+8zZiOu5Rc8LW2/kfsHPWGV6lySborg6ohbmu2FaUG+04tx81 QbWMvAVS6VYmKadGa7CqB7PAer7KLOPf9gLuI6op/cbBxWc8X7pMimARTkulBAtD0HVV wAhLeq/5+/2c2xECOEXdiXyAgSfboIte5pjkGw7+87W+8gn9JfvdPtSFngfrK9Q7tAkQ qdYFflubQIiVr1sy4Q7wqaygdGwFFgdQB73qBVmRlExNqQ67xbjsfKTzpSA0zhBIEFY5 Cjmg== X-Gm-Message-State: AJcUukcGdVRtjWU0atvhZcKm4R3j6ugiOL4tG3dvgR1fVoVYd/hr9bdt j6Hu9upmdM3LHMOWDi+GrGWT5cg= X-Google-Smtp-Source: ALg8bN7yexqczq/sMQomZk/v+UQbOBFQfOLRzH+dPDRE6qBgNNvIKq/XEIf/tlYfSuVnb3CIMrRyww== X-Received: by 2002:a63:4187:: with SMTP id o129mr877861pga.370.1547159109562; Thu, 10 Jan 2019 14:25:09 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:3:a18b:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id z127sm118006755pfb.80.2019.01.10.14.25.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 14:25:08 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Steve French , Ronnie Sahlberg Subject: [PATCH 2/7] CIFS: Do not set credits to 1 if the server didn't grant anything Date: Thu, 10 Jan 2019 14:24:53 -0800 Message-Id: <1547159098-19011-3-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547159098-19011-1-git-send-email-pshilov@microsoft.com> References: <1547159098-19011-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 Currently we reset the number of total credits granted by the server to 1 if the server didn't grant us anything int the response. This violates the SMB3 protocol - we need to trust the server and use the credit values from the response. Fix this by removing the corresponding code. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/transport.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 5be7302..8e75d68 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -894,8 +894,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, for (i = 0; i < num_rqst; i++) if (midQ[i]->resp_buf) credits += ses->server->ops->get_credits(midQ[i]); - if (!credits) - credits = 1; for (i = 0; i < num_rqst; i++) { if (rc < 0) From patchwork Thu Jan 10 22:24: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: 1023251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pjZBDZIP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43bLCs07f7z9sCr for ; Fri, 11 Jan 2019 09:25:13 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728991AbfAJWZM (ORCPT ); Thu, 10 Jan 2019 17:25:12 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43357 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728800AbfAJWZM (ORCPT ); Thu, 10 Jan 2019 17:25:12 -0500 Received: by mail-pf1-f194.google.com with SMTP id w73so5940547pfk.10 for ; Thu, 10 Jan 2019 14:25:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ctm6dsa1PPQY/Zp33MkcTFiyzDPnCNzcx4cWaEFRmsc=; b=pjZBDZIPeOhygE29qpER8UqwQqg517DEenfckKhuuLbyL1SN4kpoIdtkf9F8qw3PRu /CGbhBvpNY58pGkLdP+m0kHBaMg6Z22jbONrBzAFpo2r4lXNekeA78H4kB7wWl6SiWSO ZltFFRcA4hcqMy7Oy8NWWMp4fKuZ2gVU235Go2CtOWuKu4mgJm2o5Cm8GG/DjrZbWOLK cZHrxEZKjE9qTEECbHHJxY/G/RUgg8BEGBSaY9GtcjLw0++fM2wKEsUbVOScoytmk3HT bb6diH8idW/zNmTwcXerYyIUDRkALH8VuvmysMkQyZLJ5Ye0Q0tYGEUAWK2m/5YxhFY/ uXfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ctm6dsa1PPQY/Zp33MkcTFiyzDPnCNzcx4cWaEFRmsc=; b=ggza5hCFz2f+jolfOClV4B4x7pBb4aBtbION7/VuHBlU+tgZI+eJ+6Ni+E+MZ0oXZ/ noGvfMhbzunCLltIBz4nHWmAStc6NNlr6DedobjvdgKmI/nrOf23umugDImaNyfT419E tmrKysJOkXAZAvWJlkIQ9gYOhdrh+NyniOLZe+cwyVvkZ7XXtgzzQ3KDxYM3RVEa2ffR 9DHDQZBw+BvSufvny3ipCOadoItlkpq0QZ8OUX6nAY3/6+OLdoI5iSttBPj15rm4KTHO OjRvzM4CdqC3uFeFROaRpNH56ghUYrjhJ+yLxEa5YB7BsRCJf173mf1DdB9+ssBzo1XA zerg== X-Gm-Message-State: AJcUukdqySR3IPkwcSk7DxeLZIe0nhQxS0P90r9lMOGbX8yaC/EbFhQr OMu/NCleQRlG6z976JOWzYB7T4U= X-Google-Smtp-Source: ALg8bN7tSdh/9Xu+A+5XevUXAjWHQ+cwf6pLKRgO1AmEa68CFvHmrhyiZssp+398AIaMq1mf9v9Y9w== X-Received: by 2002:a63:a41:: with SMTP id z1mr11001425pgk.117.1547159110872; Thu, 10 Jan 2019 14:25:10 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:3:a18b:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id z127sm118006755pfb.80.2019.01.10.14.25.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 14:25:09 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Steve French , Ronnie Sahlberg Subject: [PATCH 3/7] CIFS: Fix credit computation for compounded requests Date: Thu, 10 Jan 2019 14:24:54 -0800 Message-Id: <1547159098-19011-4-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547159098-19011-1-git-send-email-pshilov@microsoft.com> References: <1547159098-19011-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 In SMB3 protocol every part of the compound chain consumes credits individually, so we need to call wait_for_free_credits() for each of the PDUs in the chain. If an operation is interrupted, we must ensure we return all credits taken from the server structure back. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/transport.c | 59 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 8e75d68..e047f06 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -795,7 +795,8 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, int i, j, rc = 0; int timeout, optype; struct mid_q_entry *midQ[MAX_COMPOUND]; - unsigned int credits = 0; + bool cancelled_mid[MAX_COMPOUND] = {false}; + unsigned int credits[MAX_COMPOUND] = {0}; char *buf; timeout = flags & CIFS_TIMEOUT_MASK; @@ -813,13 +814,31 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, return -ENOENT; /* - * Ensure that we do not send more than 50 overlapping requests - * to the same server. We may make this configurable later or - * use ses->maxReq. + * 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. */ - rc = wait_for_free_request(ses->server, timeout, optype); - if (rc) - return rc; + for (i = 0; i < num_rqst; i++) { + rc = wait_for_free_request(ses->server, timeout, optype); + if (rc) { + /* + * We haven't sent an SMB packet to the server yet but + * we already obtained credits for i requests in the + * compound chain - need to return those credits back + * for future use. Note that we need to call add_credits + * multiple times to match the way we obtained credits + * in the first place and to account for in flight + * requests correctly. + */ + for (j = 0; j < i; j++) + add_credits(ses->server, 1, optype); + return rc; + } + credits[i] = 1; + } /* * Make sure that we sign in the same order that we send on this socket @@ -835,8 +854,10 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, for (j = 0; j < i; j++) cifs_delete_mid(midQ[j]); mutex_unlock(&ses->server->srv_mutex); + /* Update # of requests on wire to server */ - add_credits(ses->server, 1, optype); + for (j = 0; j < num_rqst; j++) + add_credits(ses->server, credits[j], optype); return PTR_ERR(midQ[i]); } @@ -883,17 +904,16 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED) { midQ[i]->mid_flags |= MID_WAIT_CANCELLED; midQ[i]->callback = DeleteMidQEntry; - spin_unlock(&GlobalMid_Lock); - add_credits(ses->server, 1, optype); - return rc; + cancelled_mid[i] = true; } spin_unlock(&GlobalMid_Lock); } } for (i = 0; i < num_rqst; i++) - if (midQ[i]->resp_buf) - credits += ses->server->ops->get_credits(midQ[i]); + if (!cancelled_mid[i] && midQ[i]->resp_buf + && (midQ[i]->mid_state == MID_RESPONSE_RECEIVED)) + credits[i] = ses->server->ops->get_credits(midQ[i]); for (i = 0; i < num_rqst; i++) { if (rc < 0) @@ -901,8 +921,9 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, rc = cifs_sync_mid_result(midQ[i], ses->server); if (rc != 0) { - add_credits(ses->server, credits, optype); - return rc; + /* mark this mid as cancelled to not free it below */ + cancelled_mid[i] = true; + goto out; } if (!midQ[i]->resp_buf || @@ -949,9 +970,11 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, * This is prevented above by using a noop callback that will not * wake this thread except for the very last PDU. */ - for (i = 0; i < num_rqst; i++) - cifs_delete_mid(midQ[i]); - add_credits(ses->server, credits, optype); + for (i = 0; i < num_rqst; i++) { + if (!cancelled_mid[i]) + cifs_delete_mid(midQ[i]); + add_credits(ses->server, credits[i], optype); + } return rc; } From patchwork Thu Jan 10 22:24: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: 1023252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="p2w8UXlg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43bLCt03sMz9sCs for ; Fri, 11 Jan 2019 09:25:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728288AbfAJWZN (ORCPT ); Thu, 10 Jan 2019 17:25:13 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46458 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728800AbfAJWZN (ORCPT ); Thu, 10 Jan 2019 17:25:13 -0500 Received: by mail-pf1-f196.google.com with SMTP id c73so5932653pfe.13 for ; Thu, 10 Jan 2019 14:25:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cGJpAd8GqozJxbETvXV0rZRryFlooCje2snJMs+3SP8=; b=p2w8UXlgQ61JuYEAJa+T7HTEEWirM9UoXgBrjFClFOKMkfi89M83JEw8uS+tZbU+kY YRF3VqRhz/MjVL+lkuVAmnZThxuIA0lX9qCCmUoycVvzgfAGVaDENjtLPX/vDmk3hUGH PQwxS+UTCT0UUbRIg3P96/KtbEzE63b6T9jGWIi8KAwCQpWw6Ss5eWANi+yh4zq8KVDO TxMKuOuDCTOyB/KbtyPrcj105QskQctwgK3ZqvnN8yNr3j1vThGrHE0GJ62Tbe89MHSC hjRfosp6o2PgO2gf+QRukKw+mvrMI+2c2/DQOIaSdwHP9EtARC00OpX6x24+A3oFYIFP DfYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cGJpAd8GqozJxbETvXV0rZRryFlooCje2snJMs+3SP8=; b=gtynk1Oy6maIDTSiDMKCHMwq+aK2c01zjvtYMhZAzwH9Qow57XluxcUhRjQ2nbJI00 rYh87+fi4gaarDnjS82KdYRm0rk5jp2tFe6R4mQ9lZ/AwnLkxqwZr9wFXqEyw+VTNNQ8 acvhNPk58wwDaLh3HolWFCuUY0/L0GHouLMSrU0h5oq3UnKlw6e+WnLHBL/IGBFyl9VG OI0zqIX+x47JxhydUl11sNMVtIX4QgyKRNBKF2EPsah1tf0l0rtKSTcR/Fck0B39vH/r 1k2DtX2mugPOeJxcwpxu/vQGXWnCWVIDmPru54TNy9/WgkBvZ4PmLJ6lrOfvOL3PlfIr xuSQ== X-Gm-Message-State: AJcUukdLr1HmDD5iBG26p2AOH+yz/kHQnWxElLlmeh8Boy1H2HuACyTG Zhu9ZjN2PVZ7+xj4B25rv+3J4kM= X-Google-Smtp-Source: ALg8bN7p2UcOqFARTfm/bmBtniGCTo49zqezOjj05E5+xnziHen81MYglWd3bHbuG2PzdzSa9CvHVQ== X-Received: by 2002:a63:9501:: with SMTP id p1mr11077882pgd.149.1547159112301; Thu, 10 Jan 2019 14:25:12 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:3:a18b:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id z127sm118006755pfb.80.2019.01.10.14.25.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 14:25:11 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Steve French , Ronnie Sahlberg Subject: [PATCH 4/7] CIFS: Do not hide EINTR after sending network packets Date: Thu, 10 Jan 2019 14:24:55 -0800 Message-Id: <1547159098-19011-5-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547159098-19011-1-git-send-email-pshilov@microsoft.com> References: <1547159098-19011-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 Currently we hide EINTR code returned from sock_sendmsg() and return 0 instead. This makes a caller think that we have successfully completed the network operation which is not true. Fix this by properly returning EINTR to callers. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index e047f06..aaff9c5 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -387,7 +387,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, if (rc < 0 && rc != -EINTR) cifs_dbg(VFS, "Error %d sending data on socket to server\n", rc); - else + else if (rc > 0) rc = 0; return rc; From patchwork Thu Jan 10 22:24: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: 1023253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="puEj9ku/"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43bLCv4LRxz9sCr for ; Fri, 11 Jan 2019 09:25:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728797AbfAJWZP (ORCPT ); Thu, 10 Jan 2019 17:25:15 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39670 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728614AbfAJWZP (ORCPT ); Thu, 10 Jan 2019 17:25:15 -0500 Received: by mail-pg1-f196.google.com with SMTP id w6so5418176pgl.6 for ; Thu, 10 Jan 2019 14:25:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZTYyfM7fxF949rf1pBCjUX6GOJDQhhzdvfT2dmJ7rLs=; b=puEj9ku/CYJcptWK3sy7FMiTOSumgDKNuG+AkjRLAjKvURhG1Op+wLB+EWPS3BRMl4 hcWe1TGsPmjeXDG5YDhQObJo7XdSt8AkRFlnxHxxkQu37MjSMgCJR6gDxF7marwMVa4R gYxLcGja1DFF9T+CEmdr5QZKIYoDXcGLmluUj4yD+RJA2Fy2PN+FY9qNPje+MqLmtHzb VlmRtJNu+PB37vnvFEMjmPcy9vpu+9bkDszVQmxY0w7h+LiXFTdT5DrU2OwSSRZLyruF u3DBn5Hq5pN7xvPCeAVr99/NQgPw8uKSZ8J/Bw0UrC3OT2GmiBgEF2Mbzl5e01CblTYS V3GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZTYyfM7fxF949rf1pBCjUX6GOJDQhhzdvfT2dmJ7rLs=; b=IQOe+5ueYIibtoMNkTg5l9Vnnu1HvvosAMPLpp8xvNPbVlc3tiMFWeLV/XvFOG9IJq XQItlCWM4WhhbsYJYqVyvzTeTetPmWCCv/Fe5UFT6hzhcrnoIeQsptwdWFTVpbr3MPbY Fwj6zYsQiWoijuWhLEJawXBtlZFYRiLqJImexVSAaeDfDPayhXH3IOVRfgokMLFehcp0 4JC8Kg/DwhMPA2WkAHa2d4ZMuyb7q/oy+gT+rKYBItdWaZOuFIHsiwc+Wd2AwFwxYqUs rOxiUbBNzkqZ8/M1Nn6PV/DGvAFhApVwcsxZAwd2RFCvAv6eZmtAt3RAIvGYebQb0Lsq CDxg== X-Gm-Message-State: AJcUukfO30lrXaoe9lDg2Dgaw45Vvij3xpnjpvKxe4hOL5F3qvba3PH3 X1sJDYK4qV9WAj6vCaCmtqVcln4= X-Google-Smtp-Source: ALg8bN4yRhC15Q5sSZpjlrt3VN+Q48KQRPc0f85uzk9OuEPaNE6wkzgf5Q6sxWuoPDIzMwmkmtqONA== X-Received: by 2002:a63:be4d:: with SMTP id g13mr11100762pgo.378.1547159113554; Thu, 10 Jan 2019 14:25:13 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:3:a18b:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id z127sm118006755pfb.80.2019.01.10.14.25.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 14:25:12 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Steve French , Ronnie Sahlberg Subject: [PATCH 5/7] CIFS: Fix credits calculation for cancelled requests Date: Thu, 10 Jan 2019 14:24:56 -0800 Message-Id: <1547159098-19011-6-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547159098-19011-1-git-send-email-pshilov@microsoft.com> References: <1547159098-19011-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 If a request is cancelled, we can't assume that the server returns 1 credit back. Instead we need to wait for a response and process the number of credits granted by the server. Create a separate mid callback for cancelled request, parse the number of credits in a response buffer and add them to the client's credits. If the didn't get a response (no response buffer available) assume 0 credits granted. The latter most probably happens together with session reconnect, so the client's credits are adjusted anyway. Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsglob.h | 1 + fs/cifs/transport.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 01ded70..7709268 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -1438,6 +1438,7 @@ struct mid_q_entry { int mid_state; /* wish this were enum but can not pass to wait_event */ unsigned int mid_flags; __le16 command; /* smb command code */ + unsigned int optype; /* operation type */ bool large_buf:1; /* if valid response, is pointer to large buf */ bool multiRsp:1; /* multiple trans2 responses for one request */ bool multiEnd:1; /* both received */ diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index aaff9c5..450c434 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -787,6 +787,24 @@ cifs_noop_callback(struct mid_q_entry *mid) { } +static void +cifs_cancelled_callback(struct mid_q_entry *mid) +{ + struct TCP_Server_Info *server = mid->server; + unsigned int optype = mid->optype; + unsigned int credits_received = 0; + + if (mid->mid_state == MID_RESPONSE_RECEIVED) { + if (mid->resp_buf) + credits_received = server->ops->get_credits(mid); + else + cifs_dbg(FYI, "Bad state for cancelled MID\n"); + } + + DeleteMidQEntry(mid); + add_credits(server, credits_received, optype); +} + int compound_send_recv(const unsigned int xid, struct cifs_ses *ses, const int flags, const int num_rqst, struct smb_rqst *rqst, @@ -862,6 +880,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, } midQ[i]->mid_state = MID_REQUEST_SUBMITTED; + midQ[i]->optype = optype; /* * We don't invoke the callback compounds unless it is the last * request. @@ -896,15 +915,20 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, for (i = 0; i < num_rqst; i++) { rc = wait_for_response(ses->server, midQ[i]); - if (rc != 0) { + if (rc != 0) + break; + } + if (rc != 0) { + for (; i < num_rqst; i++) { cifs_dbg(VFS, "Cancelling wait for mid %llu cmd: %d\n", midQ[i]->mid, le16_to_cpu(midQ[i]->command)); send_cancel(ses->server, &rqst[i], midQ[i]); spin_lock(&GlobalMid_Lock); if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED) { midQ[i]->mid_flags |= MID_WAIT_CANCELLED; - midQ[i]->callback = DeleteMidQEntry; + midQ[i]->callback = cifs_cancelled_callback; cancelled_mid[i] = true; + credits[i] = 0; } spin_unlock(&GlobalMid_Lock); } From patchwork Thu Jan 10 22:24:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1023254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ryg/zO9o"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43bLCw4LyMz9sCs for ; Fri, 11 Jan 2019 09:25:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728800AbfAJWZQ (ORCPT ); Thu, 10 Jan 2019 17:25:16 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38764 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728614AbfAJWZQ (ORCPT ); Thu, 10 Jan 2019 17:25:16 -0500 Received: by mail-pl1-f195.google.com with SMTP id e5so5794154plb.5 for ; Thu, 10 Jan 2019 14:25:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=da7MaxySknub6xi8zpWBDpkbpudmn2GIlGY9rNOR9/0=; b=ryg/zO9oAlZTwkc3vsPzNiIKXC5ZjuZd3sYMwtYcCnnRsJgJgtnkGaPd2BUm2F9ENv x2lH6bgMXFjXMIgoCvEJeTvDDSv2vQG1daZXytZNglF26vuC3ko/2clgN4C3Hmq43MyL um8lI6iYcj0zahyHRMjNzbhKCXiUDk8jF2D49CO0z8iN9mB2x3jcECqb7fAE9+ZgGnXV O5V3QMae40rxLByzTJoiGXBjPjFdVd8+4GC0W+5wLumwjy1GA10wP4e44LmWXxsOBlO7 /W/VJfaDlDB0Ce3dc6BI5lzMWZLAjnVYsPI1FD3nK38+Lm1aH4D6OQ1npfxHueur/ITh H8jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=da7MaxySknub6xi8zpWBDpkbpudmn2GIlGY9rNOR9/0=; b=Negm1rogjb//AyF0GsTash0V2QjMOhoItxVHTVmhbf46mPHyoZ4mpA+27/E8FiH7fS I1Hx64BhfUbVa8WHWHA1PcG/ewmQcN/VsQaZMB8GjQ/LoNWzqhHL8PxvrramfAZXx7AS Z5hve4nOOtVAY1SakC2tPpRy5ZWk4yPNrp2p0DXyVqBzNdq/Js7bMh1oFLFT/Kp1GRCD 11GlcxTnwoa3ec6RicZhjJBlvfGlkeNw1Cnltz1wFhGEi27D/ECTfR22Tvo/NQeWXq29 BW7nMCCUmI9+CDloW3qtHrZoswaIrXbwlxEx3aRCBpSRUSqLIU41xLPM0WHaygnfs9eZ OuVA== X-Gm-Message-State: AJcUukd/3oVZ3wko/Q3NhXuvn/YQB8r8Dg8Co+6h7uAwNUtBRsxzK/RO /IYtSmwdjDsI4AfSNJwjpWIbZ8Q= X-Google-Smtp-Source: ALg8bN4yQ0pAFh6HS2LQGnoi64GJ3sQvVn7zyhR5u/Z+aVs9e96S+DgGkXLviLtcRXThZcaoVo2cnw== X-Received: by 2002:a17:902:8306:: with SMTP id bd6mr12184951plb.217.1547159114918; Thu, 10 Jan 2019 14:25:14 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:3:a18b:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id z127sm118006755pfb.80.2019.01.10.14.25.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 14:25:13 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Steve French , Ronnie Sahlberg Subject: [PATCH 6/7] CIFS: Move credit processing to mid callbacks for SMB3 Date: Thu, 10 Jan 2019 14:24:57 -0800 Message-Id: <1547159098-19011-7-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547159098-19011-1-git-send-email-pshilov@microsoft.com> References: <1547159098-19011-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 Currently we account for credits in the thread initiating a request and waiting for a response. The demultiplex thread receives the response, wakes up the thread and the latter collects credits from the response buffer and add them to the server structure on the client. This approach is not accurate, because it may race with reconnect events in the demultiplex thread which resets the number of credits. Fix this by moving credit processing to new mid callbacks that collect credits granted by the server from the response in the demultiplex thread. Signed-off-by: Pavel Shilovsky --- fs/cifs/transport.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 450c434..202e0e8 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -783,12 +783,7 @@ cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) } static void -cifs_noop_callback(struct mid_q_entry *mid) -{ -} - -static void -cifs_cancelled_callback(struct mid_q_entry *mid) +cifs_compound_callback(struct mid_q_entry *mid) { struct TCP_Server_Info *server = mid->server; unsigned int optype = mid->optype; @@ -801,10 +796,23 @@ cifs_cancelled_callback(struct mid_q_entry *mid) cifs_dbg(FYI, "Bad state for cancelled MID\n"); } - DeleteMidQEntry(mid); add_credits(server, credits_received, optype); } +static void +cifs_compound_last_callback(struct mid_q_entry *mid) +{ + cifs_compound_callback(mid); + cifs_wake_up_task(mid); +} + +static void +cifs_cancelled_callback(struct mid_q_entry *mid) +{ + cifs_compound_callback(mid); + DeleteMidQEntry(mid); +} + int compound_send_recv(const unsigned int xid, struct cifs_ses *ses, const int flags, const int num_rqst, struct smb_rqst *rqst, @@ -882,11 +890,14 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, midQ[i]->mid_state = MID_REQUEST_SUBMITTED; midQ[i]->optype = optype; /* - * We don't invoke the callback compounds unless it is the last - * request. + * Invoke callback for every part of the compound chain + * to calculate credits properly. Wake up this thread only when + * the last element is received. */ if (i < num_rqst - 1) - midQ[i]->callback = cifs_noop_callback; + midQ[i]->callback = cifs_compound_callback; + else + midQ[i]->callback = cifs_compound_last_callback; } cifs_in_send_inc(ses->server); rc = smb_send_rqst(ses->server, num_rqst, rqst, flags); @@ -900,8 +911,20 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, mutex_unlock(&ses->server->srv_mutex); - if (rc < 0) + 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); goto out; + } + + /* + * At this point the request is passed to the network stack - we assume + * that any credits taken from the server structure on the client have + * been spent and we can't return them back. Once we receive responses + * we will collect credits granted by the server in the mid callbacks + * and add those credits to the server structure. + */ /* * Compounding is never used during session establish. @@ -934,11 +957,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, } } - for (i = 0; i < num_rqst; i++) - if (!cancelled_mid[i] && midQ[i]->resp_buf - && (midQ[i]->mid_state == MID_RESPONSE_RECEIVED)) - credits[i] = ses->server->ops->get_credits(midQ[i]); - for (i = 0; i < num_rqst; i++) { if (rc < 0) goto out; @@ -997,7 +1015,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, for (i = 0; i < num_rqst; i++) { if (!cancelled_mid[i]) cifs_delete_mid(midQ[i]); - add_credits(ses->server, credits[i], optype); } return rc; From patchwork Thu Jan 10 22:24: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: 1023255 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="U77vZgk8"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43bLCy2zWyz9sCr for ; Fri, 11 Jan 2019 09:25:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728876AbfAJWZS (ORCPT ); Thu, 10 Jan 2019 17:25:18 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42124 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728614AbfAJWZR (ORCPT ); Thu, 10 Jan 2019 17:25:17 -0500 Received: by mail-pf1-f195.google.com with SMTP id 64so5938219pfr.9 for ; Thu, 10 Jan 2019 14:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5/O7ogoXRZ2RlBpkxauJ+cYIG/dlHZ5camohReMTWag=; b=U77vZgk8P+c6UC1fvEQF4Sr2mUqe04Ke0XL+nmui6rYNp2Nx2rzAQe5VTiP43dKH/O feWGxhgSdc7rSnqMVcIA2DYKVpI0MBJFbcXXd6bfI0pCpKZ4IWXuBCg49gD8FQ9qUUOS r1RYcry0l99hX0YTBp6WHWmoIvA5x2vh9yS1MghpwT7h1+ItbkF6FAI0qamofkdXsk/J fMrdaxcv4Nrav678YqmykCkBzHEe8I6tvHOJBEhkA3RkuUax3uFHmDoGATJn14ELK4tA H8q8xnGktnzbx0JGpEWuq2ZvM+0oOzlVeSl6HPenHub7wFnHbhfWwPKqZFyD9uii/wmY ZO8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5/O7ogoXRZ2RlBpkxauJ+cYIG/dlHZ5camohReMTWag=; b=G3hQ3qDfIMnGH39xGJJ8o9bAdwUdfyF6X4x3PKmrPZx+YN6e7yRjKRgfEFIZGtpv/r eTysJbaQTVHkHaPg34dA8AonjowpK5zFqww5Phs9AtIn0SgR+G7fYCjKZwENKr6vVeHR jj9Z63zZgRwHih4ilW5BlMyK1h0pPNjWGJ/6xX5fW6tGvkzOKTSbjeImzk3uSfjNAL7y dL4ordf0mgoO3yMRgpO28s+Zw4rGW7LD+hRJ5hHNzrXtGyLVh9feNhtChKUPGDE9G22d qF44wOm1IjOYWeY3uu/DMnBSkobmRE8oRZOMuDWC9qZxHBLeO0XJedL4tdMvSzggV6SA cEsA== X-Gm-Message-State: AJcUukcS0VRuxndrjpn9cs6Zl0G+PDeeO7sLlNPaGwimiGFfsAo5CGbJ 48hG8mExreCQTvevA/kfGbD20Tw= X-Google-Smtp-Source: ALg8bN5z6tWUul2MLytw+Ky+32ZmqeFsTz68M2NwEc7Q3mBOP+wTA9zufqOI/tB2V0pgU2TOH9/jhA== X-Received: by 2002:a63:d747:: with SMTP id w7mr10785907pgi.360.1547159116171; Thu, 10 Jan 2019 14:25:16 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:3:a18b:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id z127sm118006755pfb.80.2019.01.10.14.25.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 14:25:15 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Steve French , Ronnie Sahlberg Subject: [PATCH 7/7] CIFS: Fix error paths in writeback code Date: Thu, 10 Jan 2019 14:24:58 -0800 Message-Id: <1547159098-19011-8-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547159098-19011-1-git-send-email-pshilov@microsoft.com> References: <1547159098-19011-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 This patch aims to address writeback code problems related to error paths. In particular it respects EINTR and related error codes and stores the first error occured during writeback in order to return it to a caller. Signed-off-by: Pavel Shilovsky Acked-by: Jeff Layton --- fs/cifs/cifsglob.h | 19 +++++++++++++++++++ fs/cifs/cifssmb.c | 7 ++++--- fs/cifs/file.c | 29 +++++++++++++++++++++++------ fs/cifs/inode.c | 10 ++++++++++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 7709268..94dbdbe 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -1575,6 +1575,25 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param, kfree(param); } +static inline bool is_interrupt_error(int error) +{ + switch (error) { + case -EINTR: + case -ERESTARTSYS: + case -ERESTARTNOHAND: + case -ERESTARTNOINTR: + return true; + } + return false; +} + +static inline bool is_retryable_error(int error) +{ + if (is_interrupt_error(error) || error == -EAGAIN) + return true; + return false; +} + #define MID_FREE 0 #define MID_REQUEST_ALLOCATED 1 #define MID_REQUEST_SUBMITTED 2 diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index b1f49c1..6930cdb 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -2114,7 +2114,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata) for (j = 0; j < nr_pages; j++) { unlock_page(wdata2->pages[j]); - if (rc != 0 && rc != -EAGAIN) { + if (rc != 0 && !is_retryable_error(rc)) { SetPageError(wdata2->pages[j]); end_page_writeback(wdata2->pages[j]); put_page(wdata2->pages[j]); @@ -2123,7 +2123,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata) if (rc) { kref_put(&wdata2->refcount, cifs_writedata_release); - if (rc == -EAGAIN) + if (is_retryable_error(rc)) continue; break; } @@ -2132,7 +2132,8 @@ cifs_writev_requeue(struct cifs_writedata *wdata) i += nr_pages; } while (i < wdata->nr_pages); - mapping_set_error(inode->i_mapping, rc); + if (rc != 0 && !is_retryable_error(rc)) + mapping_set_error(inode->i_mapping, rc); kref_put(&wdata->refcount, cifs_writedata_release); } diff --git a/fs/cifs/file.c b/fs/cifs/file.c index c23bf9d..109b1ef 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -732,7 +732,8 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) if (can_flush) { rc = filemap_write_and_wait(inode->i_mapping); - mapping_set_error(inode->i_mapping, rc); + if (!is_interrupt_error(rc)) + mapping_set_error(inode->i_mapping, rc); if (tcon->unix_ext) rc = cifs_get_inode_info_unix(&inode, full_path, @@ -2109,6 +2110,7 @@ static int cifs_writepages(struct address_space *mapping, pgoff_t end, index; struct cifs_writedata *wdata; int rc = 0; + int saved_rc = 0; unsigned int xid; /* @@ -2137,8 +2139,10 @@ static int cifs_writepages(struct address_space *mapping, rc = server->ops->wait_mtu_credits(server, cifs_sb->wsize, &wsize, &credits); - if (rc) + if (rc != 0) { + done = true; break; + } tofind = min((wsize / PAGE_SIZE) - 1, end - index) + 1; @@ -2146,6 +2150,7 @@ static int cifs_writepages(struct address_space *mapping, &found_pages); if (!wdata) { rc = -ENOMEM; + done = true; add_credits_and_wake_if(server, credits, 0); break; } @@ -2174,7 +2179,7 @@ static int cifs_writepages(struct address_space *mapping, if (rc != 0) { add_credits_and_wake_if(server, wdata->credits, 0); for (i = 0; i < nr_pages; ++i) { - if (rc == -EAGAIN) + if (is_retryable_error(rc)) redirty_page_for_writepage(wbc, wdata->pages[i]); else @@ -2182,7 +2187,7 @@ static int cifs_writepages(struct address_space *mapping, end_page_writeback(wdata->pages[i]); put_page(wdata->pages[i]); } - if (rc != -EAGAIN) + if (!is_retryable_error(rc)) mapping_set_error(mapping, rc); } kref_put(&wdata->refcount, cifs_writedata_release); @@ -2192,6 +2197,15 @@ static int cifs_writepages(struct address_space *mapping, continue; } + /* Return immediately if we received a signal during writing */ + if (is_interrupt_error(rc)) { + done = true; + break; + } + + if (rc != 0 && saved_rc == 0) + saved_rc = rc; + wbc->nr_to_write -= nr_pages; if (wbc->nr_to_write <= 0) done = true; @@ -2209,6 +2223,9 @@ static int cifs_writepages(struct address_space *mapping, goto retry; } + if (saved_rc != 0) + rc = saved_rc; + if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) mapping->writeback_index = index; @@ -2241,8 +2258,8 @@ cifs_writepage_locked(struct page *page, struct writeback_control *wbc) set_page_writeback(page); retry_write: rc = cifs_partialpagewrite(page, 0, PAGE_SIZE); - if (rc == -EAGAIN) { - if (wbc->sync_mode == WB_SYNC_ALL) + if (is_retryable_error(rc)) { + if (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN) goto retry_write; redirty_page_for_writepage(wbc, page); } else if (rc != 0) { diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 5b883a0..ba1152b 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -2260,6 +2260,11 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) * the flush returns error? */ rc = filemap_write_and_wait(inode->i_mapping); + if (is_interrupt_error(rc)) { + rc = -ERESTARTSYS; + goto out; + } + mapping_set_error(inode->i_mapping, rc); rc = 0; @@ -2403,6 +2408,11 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) * the flush returns error? */ rc = filemap_write_and_wait(inode->i_mapping); + if (is_interrupt_error(rc)) { + rc = -ERESTARTSYS; + goto cifs_setattr_exit; + } + mapping_set_error(inode->i_mapping, rc); rc = 0;