From patchwork Fri Feb 1 20:03: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: 10793653 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 5F31C186E for ; Fri, 1 Feb 2019 20:04:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5191832C9E for ; Fri, 1 Feb 2019 20:04:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45E73330BE; Fri, 1 Feb 2019 20:04:30 +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 DE73832C9E for ; Fri, 1 Feb 2019 20:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729192AbfBAUE3 (ORCPT ); Fri, 1 Feb 2019 15:04:29 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42330 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730629AbfBAUE3 (ORCPT ); Fri, 1 Feb 2019 15:04:29 -0500 Received: by mail-pg1-f194.google.com with SMTP id d72so3417775pga.9 for ; Fri, 01 Feb 2019 12:04:28 -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=YbgPc8I9EhmndwgxVOFDxXP5pMMuY6HVHZ3jRaCwTEE=; b=YGjiNvRnYQBH95b6vR5fposaQZG8RqW92DsGvnByyORnYIEC6sBzsQbzmqfEI6TmVr UOHQQPT+wJzSV+DsAms6QxmsNmpKlYYmy/zwadIW2G+il5BBR7gL+bo9VTpbYUfuhlD6 r1ycBUNzNwCQtwN82frAHAfOjWz2zp1ptOAqQR6ILcSobDnQAdhYJ6VIDCElM+Pz+vdw zQfrRzCQ4QoAL+pb6+FVjQaKl3kXd5NLKntrI3EFUUMPdX19eM7KLte93BCgl/jzk0kU KxfzTb3XJyT3VfgXfxJS3qj4Qkm0jP4S+E/OeiLrObjk8URFgbuqjogJSwqL2zEFKtLd al0A== 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=YbgPc8I9EhmndwgxVOFDxXP5pMMuY6HVHZ3jRaCwTEE=; b=V06es6xeHKiCA9wRKz6H0dYdIklbRLpvl264oJA2oGQEbRnipiJCoMIJaTTMQmTS/4 37mXrBFoy7TcVPWRgW747RFrsoY7mLdhEzpKEvht7H+RTSmDjS2BF7jd18WCsP8mjF2E YMH4PGxEGAirLEBvXqQknBCxLUDGOO3oL2KiPOSKHDLRTWUN99c4wkIrkA0ukPiOKlVt 4bxFSq+lceVIbjUPD6hwfctfHBBh2UB1UdT0ftx3oMHm+URz6m0rGCJzMFVDukgdWplq RBgSeJpmlF5MNDaZZPC4mmL3krZPox6zhXLahrOTI6abcVWjC+98LcSU9SgAFd5ICu3o 8jrw== X-Gm-Message-State: AHQUAuYrHHSgDvrJbXwRdDeJI3jIuhhTEYaTjfUKCBLnbwPWOrV+u7xQ EXwrGRLDVPI4bEb1qnESV/YiEsw= X-Google-Smtp-Source: AHgI3IblPJNINWxC16eM7LKGL5eHessG2QLe4DnfOKhtUGzpCVu+rYos+1LlVmk5GcEDyrRs0A7L6A== X-Received: by 2002:a63:5455:: with SMTP id e21mr3612377pgm.316.1549051467996; Fri, 01 Feb 2019 12:04:27 -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.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:27 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 05/23] CIFS: Fix leaking locked VFS cache pages in writeback retry Date: Fri, 1 Feb 2019 12:03:53 -0800 Message-Id: <1549051452-5968-6-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 If we don't find a writable file handle when retrying writepages we break of the loop and do not unlock and put pages neither from wdata2 nor from the original wdata. Fix this by walking through all the remaining pages and cleanup them properly. Cc: Signed-off-by: Pavel Shilovsky --- fs/cifs/cifssmb.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index bb54ccf8..551924b 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -2125,12 +2125,13 @@ cifs_writev_requeue(struct cifs_writedata *wdata) wdata2->cfile = find_writable_file(CIFS_I(inode), false); if (!wdata2->cfile) { - cifs_dbg(VFS, "No writable handles for inode\n"); + cifs_dbg(VFS, "No writable handle to retry writepages\n"); rc = -EBADF; - break; + } else { + wdata2->pid = wdata2->cfile->pid; + rc = server->ops->async_writev(wdata2, + cifs_writedata_release); } - wdata2->pid = wdata2->cfile->pid; - rc = server->ops->async_writev(wdata2, cifs_writedata_release); for (j = 0; j < nr_pages; j++) { unlock_page(wdata2->pages[j]); @@ -2145,6 +2146,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata) kref_put(&wdata2->refcount, cifs_writedata_release); if (is_retryable_error(rc)) continue; + i += nr_pages; break; } @@ -2152,6 +2154,13 @@ cifs_writev_requeue(struct cifs_writedata *wdata) i += nr_pages; } while (i < wdata->nr_pages); + /* cleanup remaining pages from the original wdata */ + for (; i < wdata->nr_pages; i++) { + SetPageError(wdata->pages[i]); + end_page_writeback(wdata->pages[i]); + put_page(wdata->pages[i]); + } + if (rc != 0 && !is_retryable_error(rc)) mapping_set_error(inode->i_mapping, rc); kref_put(&wdata->refcount, cifs_writedata_release);