From mboxrd@z Thu Jan 1 00:00:00 1970 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 EB48BC4332F for ; Tue, 26 Apr 2022 19:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353818AbiDZTFy (ORCPT ); Tue, 26 Apr 2022 15:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353772AbiDZTFk (ORCPT ); Tue, 26 Apr 2022 15:05:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC7061999D1; Tue, 26 Apr 2022 12:02:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 74B64B82252; Tue, 26 Apr 2022 19:02:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BD25C385AF; Tue, 26 Apr 2022 19:02:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650999746; bh=Gzzt0waAa8K+0dMB3qQiJ0MfV9GnsZLefeXzHn4bzdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wchi+Td9d95kWU4iG3/qqc7cQtFQLtLNvtxWEXcRoey4d4mB0pkxt8/pakAm1T/DF Dw/vOHalH5BmXmj1lvzjiLyx+raeqC4GwV+EAoQd6avrTufij6aqKDWZtOC88mEaSO YlRpJ/BMeQhLb+GKDBDVhsPlzIkBoun9W0mFNcihKi2NKfimRSyxr8tJ+Piu7YMC/3 Yh/tcIyD4KWBbtawMD+9AvSZbCGBhgSdYDpC08akWjwQ7AYwwwlHXNDdgbmiws0bUi F6I7w5KT6LK6EH47APc0MSxWah4kCkI38LVhf8dL3Na0AdZzEK44/uJYFdvnJ+1mSl VVsSpi8Fjv8Nw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ronnie Sahlberg , Xiaoli Feng , Steve French , Sasha Levin , sfrench@samba.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Subject: [PATCH AUTOSEL 5.15 10/15] cifs: destage any unwritten data to the server before calling copychunk_write Date: Tue, 26 Apr 2022 15:02:09 -0400 Message-Id: <20220426190216.2351413-10-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220426190216.2351413-1-sashal@kernel.org> References: <20220426190216.2351413-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Ronnie Sahlberg [ Upstream commit f5d0f921ea362636e4a2efb7c38d1ead373a8700 ] because the copychunk_write might cover a region of the file that has not yet been sent to the server and thus fail. A simple way to reproduce this is: truncate -s 0 /mnt/testfile; strace -f -o x -ttT xfs_io -i -f -c 'pwrite 0k 128k' -c 'fcollapse 16k 24k' /mnt/testfile the issue is that the 'pwrite 0k 128k' becomes rearranged on the wire with the 'fcollapse 16k 24k' due to write-back caching. fcollapse is implemented in cifs.ko as a SMB2 IOCTL(COPYCHUNK_WRITE) call and it will fail serverside since the file is still 0b in size serverside until the writes have been destaged. To avoid this we must ensure that we destage any unwritten data to the server before calling COPYCHUNK_WRITE. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1997373 Reported-by: Xiaoli Feng Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/smb2ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index db3ead52ec7c..0c1af2dd9069 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1849,9 +1849,17 @@ smb2_copychunk_range(const unsigned int xid, int chunks_copied = 0; bool chunk_sizes_updated = false; ssize_t bytes_written, total_bytes_written = 0; + struct inode *inode; pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); + /* + * We need to flush all unwritten data before we can send the + * copychunk ioctl to the server. + */ + inode = d_inode(trgtfile->dentry); + filemap_write_and_wait(inode->i_mapping); + if (pcchunk == NULL) return -ENOMEM; -- 2.35.1