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: 10757017 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 19A991515 for ; Thu, 10 Jan 2019 22:25:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06DA329B6B for ; Thu, 10 Jan 2019 22:25:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF1ED29B8C; 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 7F41E29B94 for ; Thu, 10 Jan 2019 22:25:16 +0000 (UTC) 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 X-Virus-Scanned: ClamAV using ClamSMTP 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;