From patchwork Wed Aug 28 21:02:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13781955 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 598DEC71147 for ; Wed, 28 Aug 2024 21:03:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A28766B0095; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6646B0096; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F02F6B0098; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 52B056B0095 for ; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 01B3EC07AF for ; Wed, 28 Aug 2024 21:03:29 +0000 (UTC) X-FDA: 82502880180.17.D3E57E2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 4AAE6140013 for ; Wed, 28 Aug 2024 21:03:28 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UQP4RqFT; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724878963; a=rsa-sha256; cv=none; b=w7X8U5152FQQzAfdKYEqWy9/iU4VHSATBdXbsax2WZL6kAybQ2f6O/2Ye7GHy3VtWGLIOS QT5Gey4vrLvkVjsvmCJX24R2BxqvMMaR+3aHuSccX5T1UFPMg/XlAGDTKtVRcaagJy158e IsZstGTqbFvbUj5gGwaPn8GByka3Sig= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UQP4RqFT; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724878963; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=29rNMGcbzhhOXDnkGZZqENHeVIOwTy/JkQWfMjJEQZk=; b=cO/PvhmJ8IvbEcxsP/NmYMMF7CuMy+7K5QB78c+OVDKCQriJLv6ZF9SM/84IL6SgeC1J3S 2pWDv2tfy7kXihDAXT+t6d3VG9WWyyqyZ2ucXxiPaca67KaFAxJbRSAA+0oJ1EbWjIadVj UipRYBO/Ydfg0kQppCqPfW0LXVjvCHA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724879007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=29rNMGcbzhhOXDnkGZZqENHeVIOwTy/JkQWfMjJEQZk=; b=UQP4RqFTR76c/OHdYgdQnAcRt7gxPvetQSF0PaUH7SDvdbREzQTrM2nISSPfXD+CvIot7M iMqha0zuLikwtcASkJ40S6U071aG5um+CImIv/b3/EGhsXRfwoxtfI4V+opV2BkRSGjcgJ E9cyz6i0+Xc43wjk/kxZ7zsFBbLfZ1U= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-Gp7aQV_ZPh6R-b_4tg_Akg-1; Wed, 28 Aug 2024 17:03:24 -0400 X-MC-Unique: Gp7aQV_ZPh6R-b_4tg_Akg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30BFC19560B7; Wed, 28 Aug 2024 21:03:21 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B57471955F1B; Wed, 28 Aug 2024 21:03:15 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Paulo Alcantara , Tom Talpey , Dominique Martinet , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Steve French , Shyam Prasad N , Rohith Surabattula Subject: [PATCH 3/6] cifs: Fix copy offload to flush destination region Date: Wed, 28 Aug 2024 22:02:44 +0100 Message-ID: <20240828210249.1078637-4-dhowells@redhat.com> In-Reply-To: <20240828210249.1078637-1-dhowells@redhat.com> References: <20240828210249.1078637-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Stat-Signature: 1purhbig8o1p8rxhbyrp65aqhk76y5b9 X-Rspamd-Queue-Id: 4AAE6140013 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724879008-949426 X-HE-Meta: U2FsdGVkX1+lp7ZaM09kqE78yohYQDKMllDPyouD+Q13xZiWqcY1a30d8n0uwWXAhhLnxkhw8XkqzMh1sBc3c+5fwZTYBxOCSQz/Vg9ajX6ChcSGb8aKFBy8qOI5hcp1UzPQGzbn7iTbTsDylYM3TTizvSiYByYWqpzzmcI37feCMBC+UKadT+oQa0LsjQaMsLyQIPYugOHVjvR9RlKRFP8xArJKpklTAjKea84hAe01ekaD21GnI1uYWo39ejEi4IdGTz+seiLo8+bXBsrYkWkxv856NOI43opPjT8rvOri+A7owvM1mgNCGYyDptBBbNFS+t9Wlo0kbTeDk5ynrTHpnOnUxXRIWOv1bCvnIeYltozosJXcCJlZ9DGOq4ZIIyeTl9eXT9emPsqtosUqUImRsimElghBkGDT4EbFBewhBwt1gWJsYcE37+4fBSNBUKUFx+53mIqEXjsWej/eCbOgiPFTVsdczHhOlm44tH1M1NT6myKrUrp8/FPKGinqrmfZXh4ZZqDGN9wTWxTLAO7WgQLytTsPf1Mqb6zMvkqfPfcoHKj0ap66YzNBpptFuTLXpsVfGcoOuwgBFSokYlsfWnWnWctK/Gmqrnlfv35c5xRtGudQbBxpqW/Cr9ifWprNfNeS/nDd2dn37QGNfxGzjiqCmAZiSEICT97WQbBb8Ge9c9g6DvK3vWbh4FrjM7mZpAzsHELnMQF91k9DfKhM/SnVTCpmmFnCCGnzazCnE3214NOf3gvY3bXDjc9iXfUSsqrYbXoTUII6W0adyzADSn3mkfz5NJycbyTZBLIyQ8PFZIs342biOfaFipUKAoR5UIGQA848SfRu0s983Wwa9Z9ip13FthGvpt46aTBJyUkZKi5tDOmU5ZlbdnzsIb7PfwIa24JtQoDQGrjm1wUORV0FFvWJOWsDMybOAf4LtGAaHiyuo95x+1pyQfaA1OAM8aye8pUnYYkI7vy 39VN8xbI Hp6s+uU0R/YGbSB+vRQTxioO88pQgBtrkgJ+EEc/5rYNi88kwGS/pWetHoW5oRMc0aYbm1mpmU3rRKZ9NJY3tHkuuOGga3IU3GNBlB7Vup421qsNNXXRlXirHGAICdVL6b9lWfM2ceus+cTniUuFlSF9Xs7jQF5k52kiTc+vnD4DU4lGLJiiKFQ3FjkP36u1c2QJ9rWU6QTXTDOOrc8mmsn1PjcRP2Ki1FXJd42EVP/Cyarmqo4xDw3J8Skx5LYP7/vKr9W28oG0H061rma6vkL3RH754nBZFtdBmsm0G2UWe3Z0AnJ8Yxc4xcRUukpALVp2ETwd4owXbfFmJFaiv6tv9W0b9q8Lm5OMb0BUWOmtEQ/NybEORv5kNCPBt8+2RPFbh85vRZ9IBKNXHQv/O2CKyljolc1zM8WNQILxN/H9IgSU+dVTFFiqL1aoI/PmJVc9JylQclSv8q4AXFFugrcJQrNAQMqciUr1y8Fe3ytK5ODYBFH0O3adM8hw3xJYbrrCzc/dykX7sWWuQH06+3KdpG7NVUh4Njzqt6RPZF7AHzaE+R9xETp1Vp0MWAc3oWaKf21UvL+XhPpzzg8FeFszXPPE3CgEQlgpLjcFMydR0Y8axDYf7XGbaz/QkSpafIUeT8uPMC1bwxUv5sukBRdP9vuKoTRn6YOXFJFrHdJck/2w= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fix cifs_file_copychunk_range() to flush the destination region before invalidating it to avoid potential loss of data should the copy fail, in whole or in part, in some way. Fixes: 7b2404a886f8 ("cifs: Fix flushing, invalidation and file size with copy_file_range()") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Matthew Wilcox cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/cifsfs.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index d89485235425..2a2523c93944 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1341,7 +1341,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, struct cifsFileInfo *smb_file_target; struct cifs_tcon *src_tcon; struct cifs_tcon *target_tcon; - unsigned long long destend, fstart, fend; ssize_t rc; cifs_dbg(FYI, "copychunk range\n"); @@ -1391,25 +1390,13 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, goto unlock; } - destend = destoff + len - 1; - - /* Flush the folios at either end of the destination range to prevent - * accidental loss of dirty data outside of the range. + /* Flush and invalidate all the folios in the destination region. If + * the copy was successful, then some of the flush is extra overhead, + * but we need to allow for the copy failing in some way (eg. ENOSPC). */ - fstart = destoff; - fend = destend; - - rc = cifs_flush_folio(target_inode, destoff, &fstart, &fend, true); + rc = filemap_invalidate_inode(target_inode, true, destoff, destoff + len - 1); if (rc) goto unlock; - rc = cifs_flush_folio(target_inode, destend, &fstart, &fend, false); - if (rc) - goto unlock; - if (fend > target_cifsi->netfs.zero_point) - target_cifsi->netfs.zero_point = fend + 1; - - /* Discard all the folios that overlap the destination region. */ - truncate_inode_pages_range(&target_inode->i_data, fstart, fend); fscache_invalidate(cifs_inode_cookie(target_inode), NULL, i_size_read(target_inode), 0);