Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2014 Christoph Hellwig.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "xfs_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "xfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "xfs_trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "xfs_bmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "xfs_iomap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "xfs_pnfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Ensure that we do not have any outstanding pNFS layouts that can be used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * clients to directly read from or write to this inode.  This must be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * before every operation that can remove blocks from the extent map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * Additionally we call it during the write operation, where aren't concerned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * about exposing unallocated blocks but just want to provide basic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * synchronization between a local writer and pNFS clients.  mmap writes would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * also benefit from this sort of synchronization, but due to the tricky locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * rules in the page fault path we don't bother.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) xfs_break_leased_layouts(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct inode		*inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	uint			*iolock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	bool			*did_unlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct xfs_inode	*ip = XFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	while ((error = break_layout(inode, false)) == -EWOULDBLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		xfs_iunlock(ip, *iolock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		*did_unlock = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		error = break_layout(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		*iolock &= ~XFS_IOLOCK_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		*iolock |= XFS_IOLOCK_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		xfs_ilock(ip, *iolock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Get a unique ID including its location so that the client can identify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * the exported device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) xfs_fs_get_uuid(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct super_block	*sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u8			*buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u32			*len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u64			*offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct xfs_mount	*mp = XFS_M(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	xfs_notice_once(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) "Using experimental pNFS feature, use at your own risk!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (*len < sizeof(uuid_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	memcpy(buf, &mp->m_sb.sb_uuid, sizeof(uuid_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	*len = sizeof(uuid_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	*offset = offsetof(struct xfs_dsb, sb_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Get a layout for the pNFS client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) xfs_fs_map_blocks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct inode		*inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	loff_t			offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u64			length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct iomap		*iomap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	bool			write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	u32			*device_generation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct xfs_inode	*ip = XFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct xfs_mount	*mp = ip->i_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct xfs_bmbt_irec	imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	xfs_fileoff_t		offset_fsb, end_fsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	loff_t			limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int			bmapi_flags = XFS_BMAPI_ENTIRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int			nimaps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	uint			lock_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (XFS_FORCED_SHUTDOWN(mp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	 * We can't export inodes residing on the realtime device.  The realtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 * device doesn't have a UUID to identify it, so the client has no way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * to find it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (XFS_IS_REALTIME_INODE(ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 * The pNFS block layout spec actually supports reflink like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * functionality, but the Linux pNFS server doesn't implement it yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (xfs_is_reflink_inode(ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * Lock out any other I/O before we flush and invalidate the pagecache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * and then hand out a layout to the remote system.  This is very
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * similar to direct I/O, except that the synchronization is much more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * complicated.  See the comment near xfs_break_leased_layouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 * for a detailed explanation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	xfs_ilock(ip, XFS_IOLOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	limit = mp->m_super->s_maxbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (!write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		limit = max(limit, round_up(i_size_read(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				     inode->i_sb->s_blocksize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (offset > limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (offset > limit - length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		length = limit - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	error = filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	error = invalidate_inode_pages2(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (WARN_ON_ONCE(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	offset_fsb = XFS_B_TO_FSBT(mp, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	lock_flags = xfs_ilock_data_map_shared(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				&imap, &nimaps, bmapi_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	ASSERT(!nimaps || imap.br_startblock != DELAYSTARTBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (!error && write &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	    (!nimaps || imap.br_startblock == HOLESTARTBLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (offset + length > XFS_ISIZE(ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			end_fsb = xfs_iomap_eof_align_last_fsb(ip, end_fsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		else if (nimaps && imap.br_startblock == HOLESTARTBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			end_fsb = min(end_fsb, imap.br_startoff +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					       imap.br_blockcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		xfs_iunlock(ip, lock_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		error = xfs_iomap_write_direct(ip, offset_fsb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				end_fsb - offset_fsb, &imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		 * Ensure the next transaction is committed synchronously so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		 * that the blocks allocated and handed out to the client are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		 * guaranteed to be present even after a server crash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		error = xfs_update_prealloc_flags(ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				XFS_PREALLOC_SET | XFS_PREALLOC_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		xfs_iunlock(ip, lock_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	xfs_iunlock(ip, XFS_IOLOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	error = xfs_bmbt_to_iomap(ip, iomap, &imap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	*device_generation = mp->m_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	xfs_iunlock(ip, XFS_IOLOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * Ensure the size update falls into a valid allocated block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) xfs_pnfs_validate_isize(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct xfs_inode	*ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	xfs_off_t		isize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct xfs_bmbt_irec	imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	int			nimaps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	xfs_ilock(ip, XFS_ILOCK_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	error = xfs_bmapi_read(ip, XFS_B_TO_FSBT(ip->i_mount, isize - 1), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				&imap, &nimaps, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (imap.br_startblock == HOLESTARTBLOCK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	    imap.br_startblock == DELAYSTARTBLOCK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	    imap.br_state == XFS_EXT_UNWRITTEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * Make sure the blocks described by maps are stable on disk.  This includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * converting any unwritten extents, flushing the disk cache and updating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * time stamps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * Note that we rely on the caller to always send us a timestamp update so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * we always commit a transaction here.  If that stops being true we will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * to manually flush the cache here similar to what the fsync code path does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * for datasyncs on files that have no dirty metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) xfs_fs_commit_blocks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct inode		*inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct iomap		*maps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	int			nr_maps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct iattr		*iattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct xfs_inode	*ip = XFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct xfs_mount	*mp = ip->i_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct xfs_trans	*tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	bool			update_isize = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int			error, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	loff_t			size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	ASSERT(iattr->ia_valid & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	xfs_ilock(ip, XFS_IOLOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if ((iattr->ia_valid & ATTR_SIZE) && iattr->ia_size > size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		update_isize = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		size = iattr->ia_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	for (i = 0; i < nr_maps; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		u64 start, length, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		start = maps[i].offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		if (start > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		end = start + maps[i].length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (end > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			end = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		length = end - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		if (!length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		 * Make sure reads through the pagecache see the new data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		error = invalidate_inode_pages2_range(inode->i_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 					start >> PAGE_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 					(end - 1) >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		WARN_ON_ONCE(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		error = xfs_iomap_write_unwritten(ip, start, length, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			goto out_drop_iolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (update_isize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		error = xfs_pnfs_validate_isize(ip, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			goto out_drop_iolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		goto out_drop_iolock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	xfs_ilock(ip, XFS_ILOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	xfs_setattr_time(ip, iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (update_isize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		i_size_write(inode, iattr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		ip->i_d.di_size = iattr->ia_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	xfs_trans_set_sync(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	error = xfs_trans_commit(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) out_drop_iolock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	xfs_iunlock(ip, XFS_IOLOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }