Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: prepare xfs_break_layouts() for another layout type

When xfs is operating as the back-end of a pNFS block server, it
prevents collisions between local and remote operations by requiring a
lease to be held for remotely accessed blocks. Local filesystem
operations break those leases before writing or mutating the extent map
of the file.

A similar mechanism is needed to prevent operations on pinned dax
mappings, like device-DMA, from colliding with extent unmap operations.

BREAK_WRITE and BREAK_UNMAP are introduced as two distinct levels of
layout breaking.

Layouts are broken in the BREAK_WRITE case to ensure that layout-holders
do not collide with local writes. Additionally, layouts are broken in
the BREAK_UNMAP case to make sure the layout-holder has a consistent
view of the file's extent map. While BREAK_WRITE breaks can be satisfied
be recalling FL_LAYOUT leases, BREAK_UNMAP breaks additionally require
waiting for busy dax-pages to go idle while holding XFS_MMAPLOCK_EXCL.

After this refactoring xfs_break_layouts() becomes the entry point for
coordinating both types of breaks. Finally, xfs_break_leased_layouts()
becomes just the BREAK_WRITE handler.

Note that the unlock tracking is needed in a follow on change. That will
coordinate retrying either break handler until both successfully test
for a lease break while maintaining the lock state.

Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>
Reported-by: Dave Chinner <david@fromorbit.com>
Reported-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

+53 -15
+24 -2
fs/xfs/xfs_file.c
··· 312 312 if (error <= 0) 313 313 return error; 314 314 315 - error = xfs_break_layouts(inode, iolock); 315 + error = xfs_break_layouts(inode, iolock, BREAK_WRITE); 316 316 if (error) 317 317 return error; 318 318 ··· 718 718 return ret; 719 719 } 720 720 721 + int 722 + xfs_break_layouts( 723 + struct inode *inode, 724 + uint *iolock, 725 + enum layout_break_reason reason) 726 + { 727 + bool retry; 728 + 729 + ASSERT(xfs_isilocked(XFS_I(inode), XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)); 730 + 731 + switch (reason) { 732 + case BREAK_UNMAP: 733 + ASSERT(xfs_isilocked(XFS_I(inode), XFS_MMAPLOCK_EXCL)); 734 + /* fall through */ 735 + case BREAK_WRITE: 736 + return xfs_break_leased_layouts(inode, iolock, &retry); 737 + default: 738 + WARN_ON_ONCE(1); 739 + return -EINVAL; 740 + } 741 + } 742 + 721 743 #define XFS_FALLOC_FL_SUPPORTED \ 722 744 (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ 723 745 FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | \ ··· 766 744 return -EOPNOTSUPP; 767 745 768 746 xfs_ilock(ip, iolock); 769 - error = xfs_break_layouts(inode, &iolock); 747 + error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP); 770 748 if (error) 771 749 goto out_unlock; 772 750
+16
fs/xfs/xfs_inode.h
··· 379 379 >> XFS_ILOCK_SHIFT) 380 380 381 381 /* 382 + * Layouts are broken in the BREAK_WRITE case to ensure that 383 + * layout-holders do not collide with local writes. Additionally, 384 + * layouts are broken in the BREAK_UNMAP case to make sure the 385 + * layout-holder has a consistent view of the file's extent map. While 386 + * BREAK_WRITE breaks can be satisfied by recalling FL_LAYOUT leases, 387 + * BREAK_UNMAP breaks additionally require waiting for busy dax-pages to 388 + * go idle. 389 + */ 390 + enum layout_break_reason { 391 + BREAK_WRITE, 392 + BREAK_UNMAP, 393 + }; 394 + 395 + /* 382 396 * For multiple groups support: if S_ISGID bit is set in the parent 383 397 * directory, group of new file is set to that of the parent, and 384 398 * new subdirectory gets S_ISGID bit from parent. ··· 457 443 458 444 int xfs_update_prealloc_flags(struct xfs_inode *ip, 459 445 enum xfs_prealloc_flags flags); 446 + int xfs_break_layouts(struct inode *inode, uint *iolock, 447 + enum layout_break_reason reason); 460 448 461 449 /* from xfs_iops.c */ 462 450 extern void xfs_setup_inode(struct xfs_inode *ip);
+1 -2
fs/xfs/xfs_ioctl.c
··· 39 39 #include "xfs_icache.h" 40 40 #include "xfs_symlink.h" 41 41 #include "xfs_trans.h" 42 - #include "xfs_pnfs.h" 43 42 #include "xfs_acl.h" 44 43 #include "xfs_btree.h" 45 44 #include <linux/fsmap.h> ··· 643 644 return error; 644 645 645 646 xfs_ilock(ip, iolock); 646 - error = xfs_break_layouts(inode, &iolock); 647 + error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP); 647 648 if (error) 648 649 goto out_unlock; 649 650
+3 -3
fs/xfs/xfs_iops.c
··· 37 37 #include "xfs_da_btree.h" 38 38 #include "xfs_dir2.h" 39 39 #include "xfs_trans_space.h" 40 - #include "xfs_pnfs.h" 41 40 #include "xfs_iomap.h" 42 41 43 42 #include <linux/capability.h> ··· 1029 1030 int error; 1030 1031 1031 1032 if (iattr->ia_valid & ATTR_SIZE) { 1032 - struct xfs_inode *ip = XFS_I(d_inode(dentry)); 1033 + struct inode *inode = d_inode(dentry); 1034 + struct xfs_inode *ip = XFS_I(inode); 1033 1035 uint iolock; 1034 1036 1035 1037 xfs_ilock(ip, XFS_MMAPLOCK_EXCL); 1036 1038 iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; 1037 1039 1038 - error = xfs_break_layouts(d_inode(dentry), &iolock); 1040 + error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP); 1039 1041 if (error) { 1040 1042 xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); 1041 1043 return error;
+6 -6
fs/xfs/xfs_pnfs.c
··· 31 31 * rules in the page fault path we don't bother. 32 32 */ 33 33 int 34 - xfs_break_layouts( 34 + xfs_break_leased_layouts( 35 35 struct inode *inode, 36 - uint *iolock) 36 + uint *iolock, 37 + bool *did_unlock) 37 38 { 38 39 struct xfs_inode *ip = XFS_I(inode); 39 40 int error; 40 41 41 - ASSERT(xfs_isilocked(ip, XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)); 42 - 43 42 while ((error = break_layout(inode, false) == -EWOULDBLOCK)) { 44 43 xfs_iunlock(ip, *iolock); 44 + *did_unlock = true; 45 45 error = break_layout(inode, true); 46 46 *iolock &= ~XFS_IOLOCK_SHARED; 47 47 *iolock |= XFS_IOLOCK_EXCL; ··· 121 121 * Lock out any other I/O before we flush and invalidate the pagecache, 122 122 * and then hand out a layout to the remote system. This is very 123 123 * similar to direct I/O, except that the synchronization is much more 124 - * complicated. See the comment near xfs_break_layouts for a detailed 125 - * explanation. 124 + * complicated. See the comment near xfs_break_leased_layouts 125 + * for a detailed explanation. 126 126 */ 127 127 xfs_ilock(ip, XFS_IOLOCK_EXCL); 128 128
+3 -2
fs/xfs/xfs_pnfs.h
··· 9 9 int xfs_fs_commit_blocks(struct inode *inode, struct iomap *maps, int nr_maps, 10 10 struct iattr *iattr); 11 11 12 - int xfs_break_layouts(struct inode *inode, uint *iolock); 12 + int xfs_break_leased_layouts(struct inode *inode, uint *iolock, 13 + bool *did_unlock); 13 14 #else 14 15 static inline int 15 - xfs_break_layouts(struct inode *inode, uint *iolock) 16 + xfs_break_leased_layouts(struct inode *inode, uint *iolock, bool *did_unlock) 16 17 { 17 18 return 0; 18 19 }