Linux-XFS Archive mirror
 help / color / mirror / Atom feed
* [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges
@ 2024-02-27  2:17 Darrick J. Wong
  2024-02-27  2:19 ` [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c Darrick J. Wong
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27  2:17 UTC (permalink / raw
  To: djwong; +Cc: linux-xfs, hch

Hi all,

This series applies various cleanups and refactorings to file IO
handling code ahead of the main series to implement atomic file content
exchanges.

If you're going to start using this code, I strongly recommend pulling
from my git trees, which are linked below.

This has been running on the djcloud for months with no problems.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=file-exchange-refactorings
---
Commits in this patchset:
 * xfs: move inode lease breaking functions to xfs_inode.c
 * xfs: move xfs_iops.c declarations out of xfs_inode.h
 * xfs: declare xfs_file.c symbols in xfs_file.h
 * xfs: create a new helper to return a file's allocation unit
 * xfs: hoist multi-fsb allocation unit detection to a helper
 * xfs: refactor non-power-of-two alignment checks
---
 fs/xfs/xfs_bmap_util.c |    4 +-
 fs/xfs/xfs_file.c      |   88 ++++--------------------------------------------
 fs/xfs/xfs_file.h      |   15 ++++++++
 fs/xfs/xfs_inode.c     |   75 +++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_inode.h     |   12 +++----
 fs/xfs/xfs_ioctl.c     |    1 +
 fs/xfs/xfs_iops.c      |    1 +
 fs/xfs/xfs_iops.h      |    7 ++--
 fs/xfs/xfs_linux.h     |    5 +++
 9 files changed, 116 insertions(+), 92 deletions(-)
 create mode 100644 fs/xfs/xfs_file.h


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c
  2024-02-27  2:17 [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges Darrick J. Wong
@ 2024-02-27  2:19 ` Darrick J. Wong
  2024-02-27 15:49   ` Christoph Hellwig
  2024-02-27  2:19 ` [PATCH 2/6] xfs: move xfs_iops.c declarations out of xfs_inode.h Darrick J. Wong
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27  2:19 UTC (permalink / raw
  To: djwong; +Cc: linux-xfs, hch

From: Darrick J. Wong <djwong@kernel.org>

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 <djwong@kernel.org>
---
 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);


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/6] xfs: move xfs_iops.c declarations out of xfs_inode.h
  2024-02-27  2:17 [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges Darrick J. Wong
  2024-02-27  2:19 ` [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c Darrick J. Wong
@ 2024-02-27  2:19 ` Darrick J. Wong
  2024-02-27 15:49   ` Christoph Hellwig
  2024-02-27  2:20 ` [PATCH 3/6] xfs: declare xfs_file.c symbols in xfs_file.h Darrick J. Wong
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27  2:19 UTC (permalink / raw
  To: djwong; +Cc: linux-xfs, hch

From: Darrick J. Wong <djwong@kernel.org>

Similarly, move declarations of public symbols of xfs_iops.c from
xfs_inode.h to xfs_iops.h.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 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__ */


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/6] xfs: declare xfs_file.c symbols in xfs_file.h
  2024-02-27  2:17 [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges Darrick J. Wong
  2024-02-27  2:19 ` [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c Darrick J. Wong
  2024-02-27  2:19 ` [PATCH 2/6] xfs: move xfs_iops.c declarations out of xfs_inode.h Darrick J. Wong
@ 2024-02-27  2:20 ` Darrick J. Wong
  2024-02-27 15:50   ` Christoph Hellwig
  2024-02-27  2:20 ` [PATCH 4/6] xfs: create a new helper to return a file's allocation unit Darrick J. Wong
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27  2:20 UTC (permalink / raw
  To: djwong; +Cc: linux-xfs, hch

From: Darrick J. Wong <djwong@kernel.org>

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 <djwong@kernel.org>
---
 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 <linux/dax.h>
 #include <linux/falloc.h>
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 <linux/mount.h>
 #include <linux/namei.h>
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 <linux/posix_acl.h>
 #include <linux/security.h>
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,


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/6] xfs: create a new helper to return a file's allocation unit
  2024-02-27  2:17 [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges Darrick J. Wong
                   ` (2 preceding siblings ...)
  2024-02-27  2:20 ` [PATCH 3/6] xfs: declare xfs_file.c symbols in xfs_file.h Darrick J. Wong
@ 2024-02-27  2:20 ` Darrick J. Wong
  2024-02-27 15:50   ` Christoph Hellwig
  2024-02-27  2:20 ` [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper Darrick J. Wong
  2024-02-27  2:20 ` [PATCH 6/6] xfs: refactor non-power-of-two alignment checks Darrick J. Wong
  5 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27  2:20 UTC (permalink / raw
  To: djwong; +Cc: linux-xfs, hch

From: Darrick J. Wong <djwong@kernel.org>

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 <djwong@kernel.org>
---
 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;


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper
  2024-02-27  2:17 [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges Darrick J. Wong
                   ` (3 preceding siblings ...)
  2024-02-27  2:20 ` [PATCH 4/6] xfs: create a new helper to return a file's allocation unit Darrick J. Wong
@ 2024-02-27  2:20 ` Darrick J. Wong
  2024-02-27 15:51   ` Christoph Hellwig
  2024-02-27  2:20 ` [PATCH 6/6] xfs: refactor non-power-of-two alignment checks Darrick J. Wong
  5 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27  2:20 UTC (permalink / raw
  To: djwong; +Cc: linux-xfs, hch

From: Darrick J. Wong <djwong@kernel.org>

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 <djwong@kernel.org>
---
 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.
  */


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 6/6] xfs: refactor non-power-of-two alignment checks
  2024-02-27  2:17 [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges Darrick J. Wong
                   ` (4 preceding siblings ...)
  2024-02-27  2:20 ` [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper Darrick J. Wong
@ 2024-02-27  2:20 ` Darrick J. Wong
  2024-02-27 15:51   ` Christoph Hellwig
  5 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27  2:20 UTC (permalink / raw
  To: djwong; +Cc: linux-xfs, hch

From: Darrick J. Wong <djwong@kernel.org>

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 <djwong@kernel.org>
---
 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)
 {


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c
  2024-02-27  2:19 ` [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c Darrick J. Wong
@ 2024-02-27 15:49   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2024-02-27 15:49 UTC (permalink / raw
  To: Darrick J. Wong; +Cc: linux-xfs, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/6] xfs: move xfs_iops.c declarations out of xfs_inode.h
  2024-02-27  2:19 ` [PATCH 2/6] xfs: move xfs_iops.c declarations out of xfs_inode.h Darrick J. Wong
@ 2024-02-27 15:49   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2024-02-27 15:49 UTC (permalink / raw
  To: Darrick J. Wong; +Cc: linux-xfs, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/6] xfs: declare xfs_file.c symbols in xfs_file.h
  2024-02-27  2:20 ` [PATCH 3/6] xfs: declare xfs_file.c symbols in xfs_file.h Darrick J. Wong
@ 2024-02-27 15:50   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2024-02-27 15:50 UTC (permalink / raw
  To: Darrick J. Wong; +Cc: linux-xfs, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/6] xfs: create a new helper to return a file's allocation unit
  2024-02-27  2:20 ` [PATCH 4/6] xfs: create a new helper to return a file's allocation unit Darrick J. Wong
@ 2024-02-27 15:50   ` Christoph Hellwig
  2024-02-28 18:41     ` Darrick J. Wong
  0 siblings, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2024-02-27 15:50 UTC (permalink / raw
  To: Darrick J. Wong; +Cc: linux-xfs, hch

On Mon, Feb 26, 2024 at 06:20:20PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> 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.

No really exported, but only marked non-static fortunately.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper
  2024-02-27  2:20 ` [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper Darrick J. Wong
@ 2024-02-27 15:51   ` Christoph Hellwig
  2024-02-27 16:10     ` Darrick J. Wong
  0 siblings, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2024-02-27 15:51 UTC (permalink / raw
  To: Darrick J. Wong; +Cc: linux-xfs, hch

> +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;
> +}

Given that bigallocunit is an entirely new term in XFS, maybe add
a big fat comment explaining it?

Otherwise this looks useful.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 6/6] xfs: refactor non-power-of-two alignment checks
  2024-02-27  2:20 ` [PATCH 6/6] xfs: refactor non-power-of-two alignment checks Darrick J. Wong
@ 2024-02-27 15:51   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2024-02-27 15:51 UTC (permalink / raw
  To: Darrick J. Wong; +Cc: linux-xfs, hch

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper
  2024-02-27 15:51   ` Christoph Hellwig
@ 2024-02-27 16:10     ` Darrick J. Wong
  2024-02-27 16:57       ` Christoph Hellwig
  0 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-27 16:10 UTC (permalink / raw
  To: Christoph Hellwig; +Cc: linux-xfs, hch

On Tue, Feb 27, 2024 at 07:51:27AM -0800, Christoph Hellwig wrote:
> > +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;
> > +}
> 
> Given that bigallocunit is an entirely new term in XFS, maybe add
> a big fat comment explaining it?
> 
> Otherwise this looks useful.

How about:

/*
 * Decide if the file data allocation unit for this file is larger than
 * a single filesystem block.
 */

--D

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper
  2024-02-27 16:10     ` Darrick J. Wong
@ 2024-02-27 16:57       ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2024-02-27 16:57 UTC (permalink / raw
  To: Darrick J. Wong; +Cc: Christoph Hellwig, linux-xfs, hch

Sounds good.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/6] xfs: create a new helper to return a file's allocation unit
  2024-02-27 15:50   ` Christoph Hellwig
@ 2024-02-28 18:41     ` Darrick J. Wong
  0 siblings, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2024-02-28 18:41 UTC (permalink / raw
  To: Christoph Hellwig; +Cc: linux-xfs, hch

On Tue, Feb 27, 2024 at 07:50:38AM -0800, Christoph Hellwig wrote:
> On Mon, Feb 26, 2024 at 06:20:20PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > 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.
> 
> No really exported, but only marked non-static fortunately.
> 
> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

I'll change that to say that it's removing the static attribute.

Thank you for reviewing!

--D

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-02-28 18:41 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-27  2:17 [PATCHSET v29.4 02/13] xfs: refactorings for atomic file content exchanges Darrick J. Wong
2024-02-27  2:19 ` [PATCH 1/6] xfs: move inode lease breaking functions to xfs_inode.c Darrick J. Wong
2024-02-27 15:49   ` Christoph Hellwig
2024-02-27  2:19 ` [PATCH 2/6] xfs: move xfs_iops.c declarations out of xfs_inode.h Darrick J. Wong
2024-02-27 15:49   ` Christoph Hellwig
2024-02-27  2:20 ` [PATCH 3/6] xfs: declare xfs_file.c symbols in xfs_file.h Darrick J. Wong
2024-02-27 15:50   ` Christoph Hellwig
2024-02-27  2:20 ` [PATCH 4/6] xfs: create a new helper to return a file's allocation unit Darrick J. Wong
2024-02-27 15:50   ` Christoph Hellwig
2024-02-28 18:41     ` Darrick J. Wong
2024-02-27  2:20 ` [PATCH 5/6] xfs: hoist multi-fsb allocation unit detection to a helper Darrick J. Wong
2024-02-27 15:51   ` Christoph Hellwig
2024-02-27 16:10     ` Darrick J. Wong
2024-02-27 16:57       ` Christoph Hellwig
2024-02-27  2:20 ` [PATCH 6/6] xfs: refactor non-power-of-two alignment checks Darrick J. Wong
2024-02-27 15:51   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).