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])) {