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; }