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: 10757015 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 AECFB14E5 for ; Thu, 10 Jan 2019 22:25:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C48529B8C for ; Thu, 10 Jan 2019 22:25:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E3A429B6B; Thu, 10 Jan 2019 22:25:16 +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 7BD4129B6B for ; Thu, 10 Jan 2019 22:25:15 +0000 (UTC) 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 X-Virus-Scanned: ClamAV using ClamSMTP 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); }