From patchwork Tue Aug 30 02:15:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12958607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2065EECAAD3 for ; Tue, 30 Aug 2022 02:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229644AbiH3CP5 (ORCPT ); Mon, 29 Aug 2022 22:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbiH3CP4 (ORCPT ); Mon, 29 Aug 2022 22:15:56 -0400 Received: from mail-vs1-xe29.google.com (mail-vs1-xe29.google.com [IPv6:2607:f8b0:4864:20::e29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0BFE73304; Mon, 29 Aug 2022 19:15:55 -0700 (PDT) Received: by mail-vs1-xe29.google.com with SMTP id 190so10147379vsz.7; Mon, 29 Aug 2022 19:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc; bh=Oj3S4mz1YMZqLTYMLdQERsT0bL7qohRFCPvLzIXkMZQ=; b=Ikyv6bOJubYNpo+C1FAItktJeI1UHoFTE9cCOE+S6L2N3M9fcgX6VA0RDr3J7aLUea ky5YOmLiYCDwmANn/DzDCycz4gprWbJ5H2mMyt/a1r2pjq8v7479J5rDjINDn6VhYVEv o18kFIE/Hsa6NVU99DJ8qXQ0ZFcO8vJ/yQZ4Ww7uejrStRNUQsGQe07gkIjKtkwr/xF3 4iRVeD5yu3MpKj68cXIxgAOySEdJynmeJ3PQ23xvOEIRnR5RgxpHS/OcEgTXCjMp3V3f /g0rJCn2cheWV2BZAkhtfXiyvK4dbbhIjWDaNTiXI1/OVWamtNKH0Xct33vL0QeCYp7i fWLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=Oj3S4mz1YMZqLTYMLdQERsT0bL7qohRFCPvLzIXkMZQ=; b=mg5m1N/6oEdKA0bAPiHCAzN9FtUZMgM3ky+Icv8w2TRU/7tuYjSC0kB12887YMlfW4 F/CrGzYiF/IKP7Am5omno8cqubs5H29ndmk+DDGitveflf/KQe9XsMyIZGNVpMXPRx6f ypN1lrPx5mbLZYXbXKxnX9yKxOW5qp0PiYO3vCg4DpZc8Obd4LNSWgur+PCifygDoWYt LVUC/KVvQTKTn0XTL+cWRFMUZrHGIVaOdnI3YQVKbiJcvUKIMy3FeA8gbC/NBha1E8IH N2hl1DGdpvzfpFQ2f60t38CBaGe+VwqQ3AhdDpAauX0aPH4zXa+FuVKFiW9shHRMm+dT owNQ== X-Gm-Message-State: ACgBeo0cM+x4C5YOc+nChkmn/WOXX2ZTIQdPU9JdM3UZWP8ADR1YrD2I lSsXV7ci0ZsRr5FbbSNCdNEA6J9bG6vDXZav0vejO9fBkaUrLA== X-Google-Smtp-Source: AA6agR59sBMJEFng0G5tKDLfd505T3Z7CG+Vi7pAjb8Sex9HrM2H1ZJuKnpjfmtPFbs+lYew25EQlfbDTObJ4uIPRro= X-Received: by 2002:a67:b205:0:b0:390:7910:aae6 with SMTP id b5-20020a67b205000000b003907910aae6mr4026430vsf.61.1661825754556; Mon, 29 Aug 2022 19:15:54 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Mon, 29 Aug 2022 21:15:43 -0500 Message-ID: Subject: [PATCH v2][SMB3 client] smb3: use filemap_write_and_wait_range instead of filemap_write_and_wait To: CIFS Cc: David Howells , Matthew Wilcox , ronnie sahlberg , Jeff Layton , LKML , samba-technical Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org When doing insert range and collapse range we should be writing out the cached pages for the ranges affected but not the whole file (and also checking for errors if writing them out fails) See attached Reviewed-by: David Howells From 90ca08b3ee69f15c5a6e3d8d76d516d8f03ccf15 Mon Sep 17 00:00:00 2001 From: Steve French Date: Mon, 29 Aug 2022 11:53:41 -0500 Subject: [PATCH] smb3: use filemap_write_and_wait_range instead of filemap_write_and_wait When doing insert range and collapse range we should be writing out the cached pages for the ranges affected but not the whole file. Cc: stable@vger.kernel.org Signed-off-by: Steve French --- fs/cifs/cifsfs.c | 8 ++++++-- fs/cifs/smb2ops.c | 13 +++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index e9fb338b8e7e..8042d7280dec 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1219,8 +1219,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, cifs_dbg(FYI, "copychunk range\n"); - filemap_write_and_wait(src_inode->i_mapping); - if (!src_file->private_data || !dst_file->private_data) { rc = -EBADF; cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); @@ -1250,6 +1248,12 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, lock_two_nondirectories(target_inode, src_inode); cifs_dbg(FYI, "about to flush pages\n"); + + rc = filemap_write_and_wait_range(src_inode->i_mapping, off, + off + len - 1); + if (rc) + goto out; + /* should we flush first and last page first */ truncate_inode_pages(&target_inode->i_data, 0); diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 7c941ce1e7a9..f1d36b70cef7 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3687,7 +3687,10 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, } filemap_invalidate_lock(inode->i_mapping); - filemap_write_and_wait(inode->i_mapping); + rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1); + if (rc < 0) + goto out_2; + truncate_pagecache_range(inode, off, old_eof); rc = smb2_copychunk_range(xid, cfile, cfile, off + len, @@ -3708,7 +3711,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof); out_2: filemap_invalidate_unlock(inode->i_mapping); - out: +out: inode_unlock(inode); free_xid(xid); return rc; @@ -3738,7 +3741,9 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, eof = cpu_to_le64(old_eof + len); filemap_invalidate_lock(inode->i_mapping); - filemap_write_and_wait(inode->i_mapping); + rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1); + if (rc < 0) + goto out_2; truncate_pagecache_range(inode, off, old_eof); rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, @@ -3757,7 +3762,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, rc = 0; out_2: filemap_invalidate_unlock(inode->i_mapping); - out: +out: inode_unlock(inode); free_xid(xid); return rc; -- 2.34.1