From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E22C629 for ; Wed, 2 Nov 2022 03:22:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7173C433C1; Wed, 2 Nov 2022 03:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1667359350; bh=goZcnw56+R8qO0pjOt+2qXAofDQFM5JXKRkOGfRE2+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O8Q0KUgNlxQa/lbl2HsxjByJvL4q0W0EFRQn2Yj0KZuSy0gzfFpWxEpv++Lkz2wYk vEwM7c5q78WK8n32AystP7B9haetn37fpDVC5gyDOoxC57GDnCNV7gw19ujNi2lnyM YOAZHkAxf05yY75yFrqGs19TQ1QQXuaQRlhzdIuI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Darrick J. Wong" , Brian Foster , Christoph Hellwig , "Darrick J. Wong" , Chandan Babu R Subject: [PATCH 5.4 25/64] xfs: force the log after remapping a synchronous-writes file Date: Wed, 2 Nov 2022 03:33:51 +0100 Message-Id: <20221102022052.629283486@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102022051.821538553@linuxfoundation.org> References: <20221102022051.821538553@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Chandan Babu R From: "Darrick J. Wong" commit 5ffce3cc22a0e89813ed0c7162a68b639aef9ab6 upstream. Commit 5833112df7e9 tried to make it so that a remap operation would force the log out to disk if the filesystem is mounted with mandatory synchronous writes. Unfortunately, that commit failed to handle the case where the inode or the file descriptor require mandatory synchronous writes. Refactor the check into into a helper that will look for all three conditions, and now we can treat reflink just like any other synchronous write. Fixes: 5833112df7e9 ("xfs: reflink should force the log out if mounted with wsync") Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Reviewed-by: Christoph Hellwig Acked-by: Darrick J. Wong Signed-off-by: Chandan Babu R Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_file.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -990,6 +990,21 @@ xfs_file_fadvise( return ret; } +/* Does this file, inode, or mount want synchronous writes? */ +static inline bool xfs_file_sync_writes(struct file *filp) +{ + struct xfs_inode *ip = XFS_I(file_inode(filp)); + + if (ip->i_mount->m_flags & XFS_MOUNT_WSYNC) + return true; + if (filp->f_flags & (__O_SYNC | O_DSYNC)) + return true; + if (IS_SYNC(file_inode(filp))) + return true; + + return false; +} + STATIC loff_t xfs_file_remap_range( struct file *file_in, @@ -1047,7 +1062,7 @@ xfs_file_remap_range( if (ret) goto out_unlock; - if (mp->m_flags & XFS_MOUNT_WSYNC) + if (xfs_file_sync_writes(file_in) || xfs_file_sync_writes(file_out)) xfs_log_force_inode(dest); out_unlock: xfs_reflink_remap_unlock(file_in, file_out);