From patchwork Tue Feb 27 02:19:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13573146 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 B13A2FBEA for ; Tue, 27 Feb 2024 02:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000374; cv=none; b=nIPHpnDuxDAxqZYX20HGmuAzrhZo4DPz942SPjohw9o9RhgepYpbn4vS4ZPWckdTaZjYnWFTVPbqbkPjzDZkXQYu1f6rO1zW27/1YSAgKJUIhN1/gn/ZsPV2vuyWygCmj50z3xHeeSUIcFgiRbHjoCYnflxvJBjIMZcxggX7Apc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000374; c=relaxed/simple; bh=oeQ1V5NaKTeVChrMqWc9WTv+6Z791zrWzN1EiA2QIiY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AlHEL45F3tlYcX1ekVJEu4HpIZmj1cCr/7ZdXybhDmS8DN8b37D4KRx0b561AuP9QEZgIMiZ11gWoznN+coAM3A90X+JypQwZjYf0z7VbSLIYGAYS8ltqeF/WadhGuurD/IzW/2MExoIu5tB+SSeolW/pTNK1zZz37i/83Vsw98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CyWtiV9o; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CyWtiV9o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 513E1C433C7; Tue, 27 Feb 2024 02:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709000374; bh=oeQ1V5NaKTeVChrMqWc9WTv+6Z791zrWzN1EiA2QIiY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CyWtiV9oJrEBFcy9L4OW/w0LQDzuOzMBi7k0XiVRhN/fXGlEuO3eSawPbwiYCPWwT Et2IzW5QBZjox77d8E/CAklo2T+8M3KSdVrSsVPA2ycDG1hbONsHbKFuTJd+xdunqW IFfR8ZZccfrJ2uWIZ5b7B3ziN9QSUXPBY8CIutfRzbvPROzqc+oVHG/LiGHLBYxrUG AAnFWbkYNkKpg4lpXbIac8fyd97jiZjrBBbgnVrxWxusrZ0k7WVMuM3sXXf6C5PM/o eZDgRnSZJDFZGmxEqsOHes0oDErbhMfKS19ajvDhFKZCYl/s5n7UTDsurwoT47XGIc +guoiN2vmbJQg== Date: Mon, 26 Feb 2024 18:19:33 -0800 Subject: [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <170900011149.938068.2118965709387421042.stgit@frogsfrogsfrogs> In-Reply-To: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> References: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong The lease breaking functions operate at the scope of the entire VFS inode, not subranges of a file. Move them to xfs_inode.c since they're already declared in xfs_inode.h. This cleanup moves us closer to having xfs_FOO.h declare only the symbols in xfs_FOO.c. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 61 --------------------------------------------------- fs/xfs/xfs_inode.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_inode.h | 1 - 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index e33e5e13b95f4..40b778415f5fc 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -861,67 +861,6 @@ xfs_file_write_iter( return xfs_file_buffered_write(iocb, from); } -static void -xfs_wait_dax_page( - struct inode *inode) -{ - struct xfs_inode *ip = XFS_I(inode); - - xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); - schedule(); - xfs_ilock(ip, XFS_MMAPLOCK_EXCL); -} - -int -xfs_break_dax_layouts( - struct inode *inode, - bool *retry) -{ - struct page *page; - - ASSERT(xfs_isilocked(XFS_I(inode), XFS_MMAPLOCK_EXCL)); - - page = dax_layout_busy_page(inode->i_mapping); - if (!page) - return 0; - - *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, xfs_wait_dax_page(inode)); -} - -int -xfs_break_layouts( - struct inode *inode, - uint *iolock, - enum layout_break_reason reason) -{ - bool retry; - int error; - - ASSERT(xfs_isilocked(XFS_I(inode), XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)); - - do { - retry = false; - switch (reason) { - case BREAK_UNMAP: - error = xfs_break_dax_layouts(inode, &retry); - if (error || retry) - break; - fallthrough; - case BREAK_WRITE: - error = xfs_break_leased_layouts(inode, iolock, &retry); - break; - default: - WARN_ON_ONCE(1); - error = -EINVAL; - } - } while (error == 0 && retry); - - return error; -} - /* Does this file, inode, or mount want synchronous writes? */ static inline bool xfs_file_sync_writes(struct file *filp) { diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index c177e7f6ce7a3..97ad5e959f65e 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -38,6 +38,7 @@ #include "xfs_ag.h" #include "xfs_log_priv.h" #include "xfs_health.h" +#include "xfs_pnfs.h" struct kmem_cache *xfs_inode_cache; @@ -3957,3 +3958,64 @@ xfs_inode_count_blocks( xfs_bmap_count_leaves(ifp, rblocks); *dblocks = ip->i_nblocks - *rblocks; } + +static void +xfs_wait_dax_page( + struct inode *inode) +{ + struct xfs_inode *ip = XFS_I(inode); + + xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); + schedule(); + xfs_ilock(ip, XFS_MMAPLOCK_EXCL); +} + +int +xfs_break_dax_layouts( + struct inode *inode, + bool *retry) +{ + struct page *page; + + ASSERT(xfs_isilocked(XFS_I(inode), XFS_MMAPLOCK_EXCL)); + + page = dax_layout_busy_page(inode->i_mapping); + if (!page) + return 0; + + *retry = true; + return ___wait_var_event(&page->_refcount, + atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, + 0, 0, xfs_wait_dax_page(inode)); +} + +int +xfs_break_layouts( + struct inode *inode, + uint *iolock, + enum layout_break_reason reason) +{ + bool retry; + int error; + + ASSERT(xfs_isilocked(XFS_I(inode), XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)); + + do { + retry = false; + switch (reason) { + case BREAK_UNMAP: + error = xfs_break_dax_layouts(inode, &retry); + if (error || retry) + break; + fallthrough; + case BREAK_WRITE: + error = xfs_break_leased_layouts(inode, iolock, &retry); + break; + default: + WARN_ON_ONCE(1); + error = -EINVAL; + } + } while (error == 0 && retry); + + return error; +} diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 9fb404d27e710..dfa72cee2b230 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -565,7 +565,6 @@ xfs_itruncate_extents( return xfs_itruncate_extents_flags(tpp, ip, whichfork, new_size, 0); } -/* from xfs_file.c */ int xfs_break_dax_layouts(struct inode *inode, bool *retry); int xfs_break_layouts(struct inode *inode, uint *iolock, enum layout_break_reason reason); From patchwork Tue Feb 27 02:19:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13573147 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 6115F1096F for ; Tue, 27 Feb 2024 02:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000390; cv=none; b=j8doRgcDdEA1tPikIdQsPJW9muK0uMaQL+Ar+zF8/S9JcySBma8P0zE6QkBbOicv6+ssrs21O+9UJHRFkXgeNOcI/j6+Euzb9MDc4f//aka5ej+cnO4Sg4VR9AXGZMCDpKv7Ue6c/F4tZ6VbXV7wN3qeAIjLe5P7eI5+8P5MJDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000390; c=relaxed/simple; bh=FUYuDmBfAmSpQSFQXshGrN3/56VoOeKJhy4Ns/zt5NU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UL3fTK2kRQaUJB0luaIyI+WI2vMWySvDYBt2AnFxcbcL/9pZCfETzjmN8O2Jn96qTCYPwzS/dFdZVAsG829HOgBCxWJo6Kn0UUfaeKwVfbtOQGesLU+ZPkNLBkGzdZXKU21OPTdMef4ZBvwOERaDEMYXqR4Uo/pN+HuGAb7DLbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tMpM7HYY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tMpM7HYY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0DA2C433C7; Tue, 27 Feb 2024 02:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709000389; bh=FUYuDmBfAmSpQSFQXshGrN3/56VoOeKJhy4Ns/zt5NU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tMpM7HYYfanmSzX7tkWIoAhe0T+H5Ync4Cuz1dtPksDPNl2S49Tq30gudfRFwEz9K Z8pQA+LXjYIvixplbl8Csjf0w8x4rqV7H5ac4eXQ4XAW/L7AXRnK1uslwwCI6jZTe6 3l4EaiXpBOfhuD+qC+MNAEpuFlz8IHrQ53OCmRya+YRAXOEBnkJhVkvvN1rfZ6RdD6 YzeTWaBmOhIyK2ZMoohGnwM8BhZMJ/0Y41RXs149bf+wYPQDyvSTe+/qbRP9jBeQcf e0cSO7pg6wqMT/dkrrsdRWHjJfbDySXQ1gfHQlKTNXel99zoy9XKZbbq/KYDyQwRhT riSEpA7L6Wtpw== Date: Mon, 26 Feb 2024 18:19:49 -0800 Subject: [PATCH 2/6] xfs: move xfs_iops.c declarations out of xfs_inode.h From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <170900011166.938068.15976644595631519866.stgit@frogsfrogsfrogs> In-Reply-To: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> References: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Similarly, move declarations of public symbols of xfs_iops.c from xfs_inode.h to xfs_iops.h. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_inode.h | 5 ----- fs/xfs/xfs_iops.h | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index dfa72cee2b230..361a3d5efb903 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -569,11 +569,6 @@ int xfs_break_dax_layouts(struct inode *inode, bool *retry); int xfs_break_layouts(struct inode *inode, uint *iolock, enum layout_break_reason reason); -/* from xfs_iops.c */ -extern void xfs_setup_inode(struct xfs_inode *ip); -extern void xfs_setup_iops(struct xfs_inode *ip); -extern void xfs_diflags_to_iflags(struct xfs_inode *ip, bool init); - static inline void xfs_update_stable_writes(struct xfs_inode *ip) { if (bdev_stable_writes(xfs_inode_buftarg(ip)->bt_bdev)) diff --git a/fs/xfs/xfs_iops.h b/fs/xfs/xfs_iops.h index 7f84a0843b243..8a38c3e2ed0e8 100644 --- a/fs/xfs/xfs_iops.h +++ b/fs/xfs/xfs_iops.h @@ -19,4 +19,8 @@ int xfs_vn_setattr_size(struct mnt_idmap *idmap, int xfs_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr); +extern void xfs_setup_inode(struct xfs_inode *ip); +extern void xfs_setup_iops(struct xfs_inode *ip); +extern void xfs_diflags_to_iflags(struct xfs_inode *ip, bool init); + #endif /* __XFS_IOPS_H__ */ From patchwork Tue Feb 27 02:20:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13573148 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 CBDBFF4FB for ; Tue, 27 Feb 2024 02:20:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000405; cv=none; b=pqFHxF/fgVRbL7etv3rJ5dM8q28XehXLJbrhHS4qImIWO9cRzwo9UpQ5DxO1BSGi5f9iQMbUZKsTim18CGWwCDPYhOkHKo+VVyMdAnSQMnywopZQ3clI3bTpPmch4v+NcsIQMnl0zDnaiNANcO0H1ivJSFRUhYoEZVzxn/oeHbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000405; c=relaxed/simple; bh=59KO599Wx3wVXz9WifSnkYRFZ/tZ5+V/isPhCD3xmI8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UczlYAk0Yk1nFX/tiiZFdmrqJrXuEvBj1W5EzmeNHP2nz6gykODpoqPM8mLBDRIOtlObQ5ES1WpZrL50ZTNeWRht8HNoKTSbDgaoGRyAkDgW+g/DnVMoUHO9mpwX7AANCZG8VfV15wIrXroB90QGVOdh8X05xvdd/Cw/Z+NvUok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eQJyakOr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eQJyakOr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93EDDC433C7; Tue, 27 Feb 2024 02:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709000405; bh=59KO599Wx3wVXz9WifSnkYRFZ/tZ5+V/isPhCD3xmI8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=eQJyakOrOfclRukH6FE7D/kSJ/FbukO0/Xx1W6zNPXvPyKrfmoFN3egaaujNhImsn hG4dic5n4QSA53p8LdTlzr1q9JFaKWshMAojXOlWUQj02dmgTtsNACgn9ppxGnpNNB OKIPZ9QzFM6ATGvhPHgPneliXev6oTw3y+a8g16kHAxz9CyL/E9LXylXpohH9ssKD+ dBIlPHAMat2gcF192+CJcfnQsxjKPgIA7T0kt5UsWykPYtJjYfUPboFRbr15ojjEXo 9puOoTkAYLH3miMemzneuawtC+7qeMKVrccwRYZFO+vGBVh4AeP02qOfeQZE6KfhAA D3OqePcEhUmdg== Date: Mon, 26 Feb 2024 18:20:05 -0800 Subject: [PATCH 3/6] xfs: declare xfs_file.c symbols in xfs_file.h From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <170900011182.938068.18381389908075575352.stgit@frogsfrogsfrogs> In-Reply-To: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> References: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move the two public symbols in xfs_file.c to xfs_file.h. We're about to add more public symbols in that source file, so let's finally create the header file. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 1 + fs/xfs/xfs_file.h | 12 ++++++++++++ fs/xfs/xfs_ioctl.c | 1 + fs/xfs/xfs_iops.c | 1 + fs/xfs/xfs_iops.h | 3 --- 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 fs/xfs/xfs_file.h diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 40b778415f5fc..9961d4b5efbe6 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -24,6 +24,7 @@ #include "xfs_pnfs.h" #include "xfs_iomap.h" #include "xfs_reflink.h" +#include "xfs_file.h" #include #include diff --git a/fs/xfs/xfs_file.h b/fs/xfs/xfs_file.h new file mode 100644 index 0000000000000..7d39e3eca56dc --- /dev/null +++ b/fs/xfs/xfs_file.h @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000-2005 Silicon Graphics, Inc. + * All Rights Reserved. + */ +#ifndef __XFS_FILE_H__ +#define __XFS_FILE_H__ + +extern const struct file_operations xfs_file_operations; +extern const struct file_operations xfs_dir_file_operations; + +#endif /* __XFS_FILE_H__ */ diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index f02b6e558af58..1360a551118dd 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -39,6 +39,7 @@ #include "xfs_ioctl.h" #include "xfs_xattr.h" #include "xfs_rtbitmap.h" +#include "xfs_file.h" #include #include diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index a0d77f5f512e2..11382c499c92c 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -25,6 +25,7 @@ #include "xfs_error.h" #include "xfs_ioctl.h" #include "xfs_xattr.h" +#include "xfs_file.h" #include #include diff --git a/fs/xfs/xfs_iops.h b/fs/xfs/xfs_iops.h index 8a38c3e2ed0e8..3c1a2605ffd2b 100644 --- a/fs/xfs/xfs_iops.h +++ b/fs/xfs/xfs_iops.h @@ -8,9 +8,6 @@ struct xfs_inode; -extern const struct file_operations xfs_file_operations; -extern const struct file_operations xfs_dir_file_operations; - extern ssize_t xfs_vn_listxattr(struct dentry *, char *data, size_t size); int xfs_vn_setattr_size(struct mnt_idmap *idmap, From patchwork Tue Feb 27 02:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13573149 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 68BEBF4FC for ; Tue, 27 Feb 2024 02:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000421; cv=none; b=BL4sk0pXta8RZE27UXzHpjGqJQfiWDSz56d6ENg8DehlOTfOYIXVnnDAELneDieTleqLpwwRoZm6z6bkCRA9GAYkRtCFtV6OOjPJWr17zS5ecJEJ/fVp1OGszJq00V0UNCzuO45ThWwZm74IRp/+DEjtqTL6t0Evq19k4I7FAz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000421; c=relaxed/simple; bh=x3Ngt9tmDbuN83m0Phbi73LURLGzz+87zUziZluYG50=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kXnyz/ZSzyVUBS9d9vV/62WLixI9sF74f/OvgXOHaz1aROzCrQca1MqKs/mvzhM4Pl9XbhLwamf7HDb3NXFqn0rfYWvIl3gKRbwKSZpWE6yFfjmlT11VkXR9aicC+Pu1l0bYD8lmCwyGjjzBADRaz4VWZE9bLAa4bQuRkOLQTNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cleQro++; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cleQro++" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CB5AC433F1; Tue, 27 Feb 2024 02:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709000421; bh=x3Ngt9tmDbuN83m0Phbi73LURLGzz+87zUziZluYG50=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cleQro++Bpmc/Ljhn7T6gWf+YAroAz8QB04CFr5ZZ0Mm+4uuFnpA5OK80jVIwliEb 108Bg50QoWu8OaPitB5RRH3Hu/IdJYMLrGGbzukezo0i9VZPndZ+NZFsdY6eiwW51k ciRvggDl4CBmc5tz/TIPhM133mVgKGQqNA3/NGPvaKRkUxT+3Z2mm2GzMUhwQbNCtU XK5cXzr/zWBEg/36pElA6t6WnWOYiAfwwDLJSKpX/JNW4u8Nq5Sohg1gAaiO+KRvIG sxbcqkZYh/lN7lk1QA6twVZaFs3v51MSXj1tlXIxcK0k+Y/K0Zb8hWsCCjsN2WPIlt Klb6RYPWFQwKg== Date: Mon, 26 Feb 2024 18:20:20 -0800 Subject: [PATCH 4/6] xfs: create a new helper to return a file's allocation unit From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <170900011198.938068.6280271502861171630.stgit@frogsfrogsfrogs> In-Reply-To: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> References: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a new helper function to calculate the fundamental allocation unit (i.e. the smallest unit of space we can allocate) of a file. Things are going to get hairy with range-exchange on the realtime device, so prepare for this now. While we're at it, export xfs_is_falloc_aligned since the next patch will need it. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 28 ++++++++++------------------ fs/xfs/xfs_file.h | 3 +++ fs/xfs/xfs_inode.c | 13 +++++++++++++ fs/xfs/xfs_inode.h | 1 + 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 9961d4b5efbe6..64278f8acaeee 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -39,33 +39,25 @@ static const struct vm_operations_struct xfs_file_vm_ops; * Decide if the given file range is aligned to the size of the fundamental * allocation unit for the file. */ -static bool +bool xfs_is_falloc_aligned( struct xfs_inode *ip, loff_t pos, long long int len) { - struct xfs_mount *mp = ip->i_mount; - uint64_t mask; + unsigned int alloc_unit = xfs_inode_alloc_unitsize(ip); - if (XFS_IS_REALTIME_INODE(ip)) { - if (!is_power_of_2(mp->m_sb.sb_rextsize)) { - u64 rextbytes; - u32 mod; + if (!is_power_of_2(alloc_unit)) { + u32 mod; - rextbytes = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize); - div_u64_rem(pos, rextbytes, &mod); - if (mod) - return false; - div_u64_rem(len, rextbytes, &mod); - return mod == 0; - } - mask = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize) - 1; - } else { - mask = mp->m_sb.sb_blocksize - 1; + div_u64_rem(pos, alloc_unit, &mod); + if (mod) + return false; + div_u64_rem(len, alloc_unit, &mod); + return mod == 0; } - return !((pos | len) & mask); + return !((pos | len) & (alloc_unit - 1)); } /* diff --git a/fs/xfs/xfs_file.h b/fs/xfs/xfs_file.h index 7d39e3eca56dc..2ad91f755caf3 100644 --- a/fs/xfs/xfs_file.h +++ b/fs/xfs/xfs_file.h @@ -9,4 +9,7 @@ extern const struct file_operations xfs_file_operations; extern const struct file_operations xfs_dir_file_operations; +bool xfs_is_falloc_aligned(struct xfs_inode *ip, loff_t pos, + long long int len); + #endif /* __XFS_FILE_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 97ad5e959f65e..440e9c0ebd6b8 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -4019,3 +4019,16 @@ xfs_break_layouts( return error; } + +/* Returns the size of fundamental allocation unit for a file, in bytes. */ +unsigned int +xfs_inode_alloc_unitsize( + struct xfs_inode *ip) +{ + unsigned int blocks = 1; + + if (XFS_IS_REALTIME_INODE(ip)) + blocks = ip->i_mount->m_sb.sb_rextsize; + + return XFS_FSB_TO_B(ip->i_mount, blocks); +} diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 361a3d5efb903..c8799a55d885f 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -625,6 +625,7 @@ int xfs_inode_reload_unlinked(struct xfs_inode *ip); bool xfs_ifork_zapped(const struct xfs_inode *ip, int whichfork); void xfs_inode_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip, xfs_filblks_t *dblocks, xfs_filblks_t *rblocks); +unsigned int xfs_inode_alloc_unitsize(struct xfs_inode *ip); struct xfs_dir_update_params { const struct xfs_inode *dp; From patchwork Tue Feb 27 02:20:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13573150 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 393F2F4F1 for ; Tue, 27 Feb 2024 02:20:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000437; cv=none; b=NhFM9/rAxQoGTXtaE4DPrTT2OBN1sGzZ5c4cfaOowwNIuZdu0Be43L95KcVhBa+w1pjiax0i/L3xKGFwQhO6RneHK/tHTE+5XziNrcYyxI8psZ2ByAJDCW6/xD/71S5vNa4SclLp4D73G86cRscqeUNtOSDSxnKcjHqG5pVyTmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000437; c=relaxed/simple; bh=9rZI6HX6vbWdmJUIpEmtTMTEomcgFvKWqrDENsKad3Q=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kRtBtdR+t5TzuKjXhCQQI++at0vIbgxGBy5GQ1+5/Oxc9sgQnlIei9/LnXa8raZeoU6vlAIBvcgIn7g/niu7ovfzVNTvH1EulZPeiwAh+zqwjHB2rjCujuTUxV1SDZutQnQhUEjYEHHRGyTlP88p0sKlaiJc2IosBlvPL91ICEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LrFhRtSx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LrFhRtSx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEE1DC433C7; Tue, 27 Feb 2024 02:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709000436; bh=9rZI6HX6vbWdmJUIpEmtTMTEomcgFvKWqrDENsKad3Q=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LrFhRtSxHRglCfUY0J/QBtpm0xuStyEQor6NWsErN7hC32Esc/T7XLOnnyALPoriY l59qh1p27aVXR3Jt0Yg3zw3aP2wShG18NthTn7IUaZfHssiNxH79UEJ3PDHzPBn1Eg EwfXjUFORR0qZd7VYlJj6/VZzDlALpwYKQGdtrPZwQy+8SmUEAxo9wNzAK3BZOW1hU YcwYWvDxpq+Lcj4Pa2ihGXnyUINnF++A9/85yp4zIr28ewRphTvPIZ1jkn0tHPOxrK cBnL/WxQEfvKy9GgG8YoPdpNIA1w7zK/6+Ay5Vgv6t3ANOjah5Us4SeOLPwKojGfyK opYYSpQX1XH7g== Date: Mon, 26 Feb 2024 18:20:36 -0800 Subject: [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <170900011214.938068.18217925414531189912.stgit@frogsfrogsfrogs> In-Reply-To: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> References: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Replace the open-coded logic to decide if a file has a multi-fsb allocation unit to a helper to make the code easier to read. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_bmap_util.c | 4 ++-- fs/xfs/xfs_inode.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index e58ae3654e7a8..74c42544155d5 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -542,7 +542,7 @@ xfs_can_free_eofblocks( * forever. */ end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); - if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) + if (xfs_inode_has_bigallocunit(ip)) end_fsb = xfs_rtb_roundup_rtx(mp, end_fsb); last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); if (last_fsb <= end_fsb) @@ -843,7 +843,7 @@ xfs_free_file_space( endoffset_fsb = XFS_B_TO_FSBT(mp, offset + len); /* We can only free complete realtime extents. */ - if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) { + if (xfs_inode_has_bigallocunit(ip)) { startoffset_fsb = xfs_rtb_roundup_rtx(mp, startoffset_fsb); endoffset_fsb = xfs_rtb_rounddown_rtx(mp, endoffset_fsb); } diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index c8799a55d885f..b7b238e88f23a 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -311,6 +311,11 @@ static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip) return ip->i_diflags2 & XFS_DIFLAG2_NREXT64; } +static inline bool xfs_inode_has_bigallocunit(struct xfs_inode *ip) +{ + return XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1; +} + /* * Return the buftarg used for data allocations on a given inode. */ From patchwork Tue Feb 27 02:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13573151 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 08E5538DDC for ; Tue, 27 Feb 2024 02:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000453; cv=none; b=L2tftEe8ymTh9wrdoSfu72GhX7WiQh/ryHk2sWNN3jy7SsMNzlpMwXRC1sPIa1MOv6IcXSdqgSJ9Xmu3uD5742vANslUnU35I1YL2zy9ARx9hwcb4/Z6/6JLy/NLGdGVNOY6TNl0AUZl1L4LZv7novYRwqwuTaYWsLK/Cq70xTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709000453; c=relaxed/simple; bh=m1BorWELMFk0u6xfGHcvOVmN/8QF7CzwiQ6knkfp+84=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R4C79/q+k+32J5VmQJx8cZroHp5hcvJvKam5K0BXvAUt33TgFz85jfc9P5Nj8iO08GARHIes/oNBBuShyefkakZAOhNm72RxdSsz30Hr524xMlM2FGi9bKxS2OH+oKZzQKw2fAv+kVI5TNYdIbyTkvww/zhgTayqhxj8SRzfzEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=opsPvcZp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="opsPvcZp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85326C433C7; Tue, 27 Feb 2024 02:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709000452; bh=m1BorWELMFk0u6xfGHcvOVmN/8QF7CzwiQ6knkfp+84=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=opsPvcZpwZl6L9EBHDRTBUkj0ZIa7S3MezgXxyBCTW6y0/9k4yfJ871/fpAsJk9d3 boCBSpFdWFp26d4CLbfHTEg61IyPszWouRHmwaVAMgHZudZvHhIw8tWKcEcqpd+dFV pqU3PHtZIWza4lj4NpP8dkt4okn3D6LEQ1VWGedQP9EMR/SodfspN+jkvkxGwQi7WU 8l8khSf+YlHFqYqBn6Z1Btgmy9nUbP0K8D8/CEgfmsep8gerJ8pCS3M3/mTsFVE8yB /VfctjqpK2kx7a3JKdSTMEK0HTlXHP1Dy8i5GhMyEdvH0wj3SGdK4hnVgAXpy8+yXR w/gmu3RUsNDHw== Date: Mon, 26 Feb 2024 18:20:52 -0800 Subject: [PATCH 6/6] xfs: refactor non-power-of-two alignment checks From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <170900011230.938068.18189033969735593047.stgit@frogsfrogsfrogs> In-Reply-To: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> References: <170900011118.938068.16371783443726140795.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a helper function that can compute if a 64-bit number is an integer multiple of a 32-bit number, where the 32-bit number is not required to be an even power of two. This is needed for some new code for the realtime device, where we can set 37k allocation units and then have to remap them. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 12 +++--------- fs/xfs/xfs_linux.h | 5 +++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 64278f8acaeee..d1d4158441bd9 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -47,15 +47,9 @@ xfs_is_falloc_aligned( { unsigned int alloc_unit = xfs_inode_alloc_unitsize(ip); - if (!is_power_of_2(alloc_unit)) { - u32 mod; - - div_u64_rem(pos, alloc_unit, &mod); - if (mod) - return false; - div_u64_rem(len, alloc_unit, &mod); - return mod == 0; - } + if (!is_power_of_2(alloc_unit)) + return isaligned_64(pos, alloc_unit) && + isaligned_64(len, alloc_unit); return !((pos | len) & (alloc_unit - 1)); } diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index 73854ad981eb5..439f10b4a77a5 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -199,6 +199,11 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y) return x; } +static inline bool isaligned_64(uint64_t x, uint32_t y) +{ + return do_div(x, y) == 0; +} + /* If @b is a power of 2, return log2(b). Else return -1. */ static inline int8_t log2_if_power2(unsigned long b) {