xfs: split inode flushing from xfs_sync_inodes_ag

In many cases we only want to sync inode metadata. Split out the inode
flushing into a separate helper to prepare factoring the inode sync code.

Based on a patch from Dave Chinner, but redone to keep the current behaviour
exactly and leave changes to the flushing logic to another patch.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@sandeen.net>

authored by

Christoph Hellwig and committed by
Christoph Hellwig
845b6d0c 5a34d5cd

+33 -17
+33 -17
fs/xfs/linux-2.6/xfs_sync.c
··· 77 return error; 78 } 79 80 /* 81 * Sync all the inodes in the given AG according to the 82 * direction given by the flags. ··· 125 do { 126 struct inode *inode; 127 xfs_inode_t *ip = NULL; 128 - int lock_flags = XFS_ILOCK_SHARED; 129 130 /* 131 * use a gang lookup to find the next inode in the tree ··· 183 if (flags & SYNC_DELWRI) 184 error = xfs_sync_inode_data(ip, flags); 185 186 - xfs_ilock(ip, XFS_ILOCK_SHARED); 187 - if ((flags & SYNC_ATTR) && !xfs_inode_clean(ip)) { 188 - if (flags & SYNC_WAIT) { 189 - xfs_iflock(ip); 190 - if (!xfs_inode_clean(ip)) 191 - error = xfs_iflush(ip, XFS_IFLUSH_SYNC); 192 - else 193 - xfs_ifunlock(ip); 194 - } else if (xfs_iflock_nowait(ip)) { 195 - if (!xfs_inode_clean(ip)) 196 - error = xfs_iflush(ip, XFS_IFLUSH_DELWRI); 197 - else 198 - xfs_ifunlock(ip); 199 - } 200 - } 201 - xfs_iput(ip, lock_flags); 202 203 if (error) 204 last_error = error;
··· 77 return error; 78 } 79 80 + STATIC int 81 + xfs_sync_inode_attr( 82 + struct xfs_inode *ip, 83 + int flags) 84 + { 85 + int error = 0; 86 + 87 + xfs_ilock(ip, XFS_ILOCK_SHARED); 88 + if (xfs_inode_clean(ip)) 89 + goto out_unlock; 90 + if (!xfs_iflock_nowait(ip)) { 91 + if (!(flags & SYNC_WAIT)) 92 + goto out_unlock; 93 + xfs_iflock(ip); 94 + } 95 + 96 + if (xfs_inode_clean(ip)) { 97 + xfs_ifunlock(ip); 98 + goto out_unlock; 99 + } 100 + 101 + error = xfs_iflush(ip, (flags & SYNC_WAIT) ? 102 + XFS_IFLUSH_SYNC : XFS_IFLUSH_DELWRI); 103 + 104 + out_unlock: 105 + xfs_iunlock(ip, XFS_ILOCK_SHARED); 106 + return error; 107 + } 108 + 109 /* 110 * Sync all the inodes in the given AG according to the 111 * direction given by the flags. ··· 96 do { 97 struct inode *inode; 98 xfs_inode_t *ip = NULL; 99 100 /* 101 * use a gang lookup to find the next inode in the tree ··· 155 if (flags & SYNC_DELWRI) 156 error = xfs_sync_inode_data(ip, flags); 157 158 + if (flags & SYNC_ATTR) 159 + error = xfs_sync_inode_attr(ip, flags); 160 + 161 + IRELE(ip); 162 163 if (error) 164 last_error = error;