Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 19 | #include "xfs_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_types.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 21 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "xfs_trans.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 26 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "xfs_mount.h" |
| 28 | #include "xfs_trans_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "xfs_bmap_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_dinode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 32 | #include "xfs_inode_item.h" |
David Chinner | db7a19f | 2008-04-10 12:22:24 +1000 | [diff] [blame] | 33 | #include "xfs_error.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 34 | #include "xfs_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | |
| 37 | kmem_zone_t *xfs_ili_zone; /* inode log item zone */ |
| 38 | |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 39 | static inline struct xfs_inode_log_item *INODE_ITEM(struct xfs_log_item *lip) |
| 40 | { |
| 41 | return container_of(lip, struct xfs_inode_log_item, ili_item); |
| 42 | } |
| 43 | |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
| 46 | * This returns the number of iovecs needed to log the given inode item. |
| 47 | * |
| 48 | * We need one iovec for the inode log format structure, one for the |
| 49 | * inode core, and possibly one for the inode data/extents/b-tree root |
| 50 | * and one for the inode attribute data/extents/b-tree root. |
| 51 | */ |
| 52 | STATIC uint |
| 53 | xfs_inode_item_size( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 54 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 56 | struct xfs_inode_log_item *iip = INODE_ITEM(lip); |
| 57 | struct xfs_inode *ip = iip->ili_inode; |
| 58 | uint nvecs = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | switch (ip->i_d.di_format) { |
| 61 | case XFS_DINODE_FMT_EXTENTS: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 62 | if ((iip->ili_fields & XFS_ILOG_DEXT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 63 | ip->i_d.di_nextents > 0 && |
| 64 | ip->i_df.if_bytes > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | nvecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | break; |
| 67 | |
| 68 | case XFS_DINODE_FMT_BTREE: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 69 | if ((iip->ili_fields & XFS_ILOG_DBROOT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 70 | ip->i_df.if_broot_bytes > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | nvecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | break; |
| 73 | |
| 74 | case XFS_DINODE_FMT_LOCAL: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 75 | if ((iip->ili_fields & XFS_ILOG_DDATA) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 76 | ip->i_df.if_bytes > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | nvecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | break; |
| 79 | |
| 80 | case XFS_DINODE_FMT_DEV: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | case XFS_DINODE_FMT_UUID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | break; |
| 83 | |
| 84 | default: |
| 85 | ASSERT(0); |
| 86 | break; |
| 87 | } |
| 88 | |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 89 | if (!XFS_IFORK_Q(ip)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return nvecs; |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * Log any necessary attribute data. |
| 95 | */ |
| 96 | switch (ip->i_d.di_aformat) { |
| 97 | case XFS_DINODE_FMT_EXTENTS: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 98 | if ((iip->ili_fields & XFS_ILOG_AEXT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 99 | ip->i_d.di_anextents > 0 && |
| 100 | ip->i_afp->if_bytes > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | nvecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | break; |
| 103 | |
| 104 | case XFS_DINODE_FMT_BTREE: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 105 | if ((iip->ili_fields & XFS_ILOG_ABROOT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 106 | ip->i_afp->if_broot_bytes > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | nvecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | break; |
| 109 | |
| 110 | case XFS_DINODE_FMT_LOCAL: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 111 | if ((iip->ili_fields & XFS_ILOG_ADATA) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 112 | ip->i_afp->if_bytes > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | nvecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | default: |
| 117 | ASSERT(0); |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | return nvecs; |
| 122 | } |
| 123 | |
| 124 | /* |
Dave Chinner | e828776 | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 125 | * xfs_inode_item_format_extents - convert in-core extents to on-disk form |
| 126 | * |
| 127 | * For either the data or attr fork in extent format, we need to endian convert |
| 128 | * the in-core extent as we place them into the on-disk inode. In this case, we |
| 129 | * need to do this conversion before we write the extents into the log. Because |
| 130 | * we don't have the disk inode to write into here, we allocate a buffer and |
| 131 | * format the extents into it via xfs_iextents_copy(). We free the buffer in |
| 132 | * the unlock routine after the copy for the log has been made. |
| 133 | * |
| 134 | * In the case of the data fork, the in-core and on-disk fork sizes can be |
| 135 | * different due to delayed allocation extents. We only log on-disk extents |
| 136 | * here, so always use the physical fork size to determine the size of the |
| 137 | * buffer we need to allocate. |
| 138 | */ |
| 139 | STATIC void |
| 140 | xfs_inode_item_format_extents( |
| 141 | struct xfs_inode *ip, |
| 142 | struct xfs_log_iovec *vecp, |
| 143 | int whichfork, |
| 144 | int type) |
| 145 | { |
| 146 | xfs_bmbt_rec_t *ext_buffer; |
| 147 | |
| 148 | ext_buffer = kmem_alloc(XFS_IFORK_SIZE(ip, whichfork), KM_SLEEP); |
| 149 | if (whichfork == XFS_DATA_FORK) |
| 150 | ip->i_itemp->ili_extents_buf = ext_buffer; |
| 151 | else |
| 152 | ip->i_itemp->ili_aextents_buf = ext_buffer; |
| 153 | |
| 154 | vecp->i_addr = ext_buffer; |
| 155 | vecp->i_len = xfs_iextents_copy(ip, ext_buffer, whichfork); |
| 156 | vecp->i_type = type; |
| 157 | } |
| 158 | |
| 159 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | * This is called to fill in the vector of log iovecs for the |
| 161 | * given inode log item. It fills the first item with an inode |
| 162 | * log format structure, the second with the on-disk inode structure, |
| 163 | * and a possible third and/or fourth with the inode data/extents/b-tree |
| 164 | * root and inode attributes data/extents/b-tree root. |
| 165 | */ |
| 166 | STATIC void |
| 167 | xfs_inode_item_format( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 168 | struct xfs_log_item *lip, |
| 169 | struct xfs_log_iovec *vecp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 171 | struct xfs_inode_log_item *iip = INODE_ITEM(lip); |
| 172 | struct xfs_inode *ip = iip->ili_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | uint nvecs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | size_t data_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | xfs_mount_t *mp; |
| 176 | |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 177 | vecp->i_addr = &iip->ili_format; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | vecp->i_len = sizeof(xfs_inode_log_format_t); |
Christoph Hellwig | 4139b3b | 2010-01-19 09:56:45 +0000 | [diff] [blame] | 179 | vecp->i_type = XLOG_REG_TYPE_IFORMAT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | vecp++; |
| 181 | nvecs = 1; |
| 182 | |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 183 | vecp->i_addr = &ip->i_d; |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 184 | vecp->i_len = sizeof(struct xfs_icdinode); |
Christoph Hellwig | 4139b3b | 2010-01-19 09:56:45 +0000 | [diff] [blame] | 185 | vecp->i_type = XLOG_REG_TYPE_ICORE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | vecp++; |
| 187 | nvecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * If this is really an old format inode, then we need to |
| 191 | * log it as such. This means that we have to copy the link |
| 192 | * count from the new field to the old. We don't have to worry |
| 193 | * about the new fields, because nothing trusts them as long as |
| 194 | * the old inode version number is there. If the superblock already |
| 195 | * has a new version number, then we don't bother converting back. |
| 196 | */ |
| 197 | mp = ip->i_mount; |
Christoph Hellwig | 51ce16d | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 198 | ASSERT(ip->i_d.di_version == 1 || xfs_sb_version_hasnlink(&mp->m_sb)); |
| 199 | if (ip->i_d.di_version == 1) { |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 200 | if (!xfs_sb_version_hasnlink(&mp->m_sb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* |
| 202 | * Convert it back. |
| 203 | */ |
| 204 | ASSERT(ip->i_d.di_nlink <= XFS_MAXLINK_1); |
| 205 | ip->i_d.di_onlink = ip->i_d.di_nlink; |
| 206 | } else { |
| 207 | /* |
| 208 | * The superblock version has already been bumped, |
| 209 | * so just make the conversion to the new inode |
| 210 | * format permanent. |
| 211 | */ |
Christoph Hellwig | 51ce16d | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 212 | ip->i_d.di_version = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | ip->i_d.di_onlink = 0; |
| 214 | memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad)); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | switch (ip->i_d.di_format) { |
| 219 | case XFS_DINODE_FMT_EXTENTS: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 220 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 221 | ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | |
| 222 | XFS_ILOG_DEV | XFS_ILOG_UUID); |
| 223 | |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 224 | if ((iip->ili_fields & XFS_ILOG_DEXT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 225 | ip->i_d.di_nextents > 0 && |
| 226 | ip->i_df.if_bytes > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | ASSERT(ip->i_df.if_u1.if_extents != NULL); |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 228 | ASSERT(ip->i_df.if_bytes / sizeof(xfs_bmbt_rec_t) > 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | ASSERT(iip->ili_extents_buf == NULL); |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 230 | |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 231 | #ifdef XFS_NATIVE_HOST |
Dave Chinner | 696123f | 2010-07-26 13:51:46 -0500 | [diff] [blame] | 232 | if (ip->i_d.di_nextents == ip->i_df.if_bytes / |
| 233 | (uint)sizeof(xfs_bmbt_rec_t)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /* |
| 235 | * There are no delayed allocation |
| 236 | * extents, so just point to the |
| 237 | * real extents array. |
| 238 | */ |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 239 | vecp->i_addr = ip->i_df.if_u1.if_extents; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | vecp->i_len = ip->i_df.if_bytes; |
Christoph Hellwig | 4139b3b | 2010-01-19 09:56:45 +0000 | [diff] [blame] | 241 | vecp->i_type = XLOG_REG_TYPE_IEXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } else |
| 243 | #endif |
| 244 | { |
Dave Chinner | e828776 | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 245 | xfs_inode_item_format_extents(ip, vecp, |
| 246 | XFS_DATA_FORK, XLOG_REG_TYPE_IEXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | ASSERT(vecp->i_len <= ip->i_df.if_bytes); |
| 249 | iip->ili_format.ilf_dsize = vecp->i_len; |
| 250 | vecp++; |
| 251 | nvecs++; |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 252 | } else { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 253 | iip->ili_fields &= ~XFS_ILOG_DEXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | break; |
| 256 | |
| 257 | case XFS_DINODE_FMT_BTREE: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 258 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 259 | ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | |
| 260 | XFS_ILOG_DEV | XFS_ILOG_UUID); |
| 261 | |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 262 | if ((iip->ili_fields & XFS_ILOG_DBROOT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 263 | ip->i_df.if_broot_bytes > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | ASSERT(ip->i_df.if_broot != NULL); |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 265 | vecp->i_addr = ip->i_df.if_broot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | vecp->i_len = ip->i_df.if_broot_bytes; |
Christoph Hellwig | 4139b3b | 2010-01-19 09:56:45 +0000 | [diff] [blame] | 267 | vecp->i_type = XLOG_REG_TYPE_IBROOT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | vecp++; |
| 269 | nvecs++; |
| 270 | iip->ili_format.ilf_dsize = ip->i_df.if_broot_bytes; |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 271 | } else { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 272 | ASSERT(!(iip->ili_fields & |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 273 | XFS_ILOG_DBROOT)); |
| 274 | #ifdef XFS_TRANS_DEBUG |
| 275 | if (iip->ili_root_size > 0) { |
| 276 | ASSERT(iip->ili_root_size == |
| 277 | ip->i_df.if_broot_bytes); |
| 278 | ASSERT(memcmp(iip->ili_orig_root, |
| 279 | ip->i_df.if_broot, |
| 280 | iip->ili_root_size) == 0); |
| 281 | } else { |
| 282 | ASSERT(ip->i_df.if_broot_bytes == 0); |
| 283 | } |
| 284 | #endif |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 285 | iip->ili_fields &= ~XFS_ILOG_DBROOT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | break; |
| 288 | |
| 289 | case XFS_DINODE_FMT_LOCAL: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 290 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 291 | ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT | |
| 292 | XFS_ILOG_DEV | XFS_ILOG_UUID); |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 293 | if ((iip->ili_fields & XFS_ILOG_DDATA) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 294 | ip->i_df.if_bytes > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | ASSERT(ip->i_df.if_u1.if_data != NULL); |
| 296 | ASSERT(ip->i_d.di_size > 0); |
| 297 | |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 298 | vecp->i_addr = ip->i_df.if_u1.if_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* |
| 300 | * Round i_bytes up to a word boundary. |
| 301 | * The underlying memory is guaranteed to |
| 302 | * to be there by xfs_idata_realloc(). |
| 303 | */ |
| 304 | data_bytes = roundup(ip->i_df.if_bytes, 4); |
| 305 | ASSERT((ip->i_df.if_real_bytes == 0) || |
| 306 | (ip->i_df.if_real_bytes == data_bytes)); |
| 307 | vecp->i_len = (int)data_bytes; |
Christoph Hellwig | 4139b3b | 2010-01-19 09:56:45 +0000 | [diff] [blame] | 308 | vecp->i_type = XLOG_REG_TYPE_ILOCAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | vecp++; |
| 310 | nvecs++; |
| 311 | iip->ili_format.ilf_dsize = (unsigned)data_bytes; |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 312 | } else { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 313 | iip->ili_fields &= ~XFS_ILOG_DDATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
| 315 | break; |
| 316 | |
| 317 | case XFS_DINODE_FMT_DEV: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 318 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 319 | ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | |
| 320 | XFS_ILOG_DEXT | XFS_ILOG_UUID); |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 321 | if (iip->ili_fields & XFS_ILOG_DEV) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | iip->ili_format.ilf_u.ilfu_rdev = |
| 323 | ip->i_df.if_u2.if_rdev; |
| 324 | } |
| 325 | break; |
| 326 | |
| 327 | case XFS_DINODE_FMT_UUID: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 328 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 329 | ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | |
| 330 | XFS_ILOG_DEXT | XFS_ILOG_DEV); |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 331 | if (iip->ili_fields & XFS_ILOG_UUID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | iip->ili_format.ilf_u.ilfu_uuid = |
| 333 | ip->i_df.if_u2.if_uuid; |
| 334 | } |
| 335 | break; |
| 336 | |
| 337 | default: |
| 338 | ASSERT(0); |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | /* |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 343 | * If there are no attributes associated with the file, then we're done. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | */ |
| 345 | if (!XFS_IFORK_Q(ip)) { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 346 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 347 | ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT); |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 348 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | switch (ip->i_d.di_aformat) { |
| 352 | case XFS_DINODE_FMT_EXTENTS: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 353 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 354 | ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT); |
| 355 | |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 356 | if ((iip->ili_fields & XFS_ILOG_AEXT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 357 | ip->i_d.di_anextents > 0 && |
| 358 | ip->i_afp->if_bytes > 0) { |
| 359 | ASSERT(ip->i_afp->if_bytes / sizeof(xfs_bmbt_rec_t) == |
| 360 | ip->i_d.di_anextents); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | ASSERT(ip->i_afp->if_u1.if_extents != NULL); |
Nathan Scott | f016bad | 2005-09-08 15:30:05 +1000 | [diff] [blame] | 362 | #ifdef XFS_NATIVE_HOST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | /* |
| 364 | * There are not delayed allocation extents |
| 365 | * for attributes, so just point at the array. |
| 366 | */ |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 367 | vecp->i_addr = ip->i_afp->if_u1.if_extents; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | vecp->i_len = ip->i_afp->if_bytes; |
Dave Chinner | e828776 | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 369 | vecp->i_type = XLOG_REG_TYPE_IATTR_EXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | #else |
| 371 | ASSERT(iip->ili_aextents_buf == NULL); |
Dave Chinner | e828776 | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 372 | xfs_inode_item_format_extents(ip, vecp, |
| 373 | XFS_ATTR_FORK, XLOG_REG_TYPE_IATTR_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | #endif |
| 375 | iip->ili_format.ilf_asize = vecp->i_len; |
| 376 | vecp++; |
| 377 | nvecs++; |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 378 | } else { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 379 | iip->ili_fields &= ~XFS_ILOG_AEXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | break; |
| 382 | |
| 383 | case XFS_DINODE_FMT_BTREE: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 384 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 385 | ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT); |
| 386 | |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 387 | if ((iip->ili_fields & XFS_ILOG_ABROOT) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 388 | ip->i_afp->if_broot_bytes > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | ASSERT(ip->i_afp->if_broot != NULL); |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 390 | |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 391 | vecp->i_addr = ip->i_afp->if_broot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | vecp->i_len = ip->i_afp->if_broot_bytes; |
Christoph Hellwig | 4139b3b | 2010-01-19 09:56:45 +0000 | [diff] [blame] | 393 | vecp->i_type = XLOG_REG_TYPE_IATTR_BROOT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | vecp++; |
| 395 | nvecs++; |
| 396 | iip->ili_format.ilf_asize = ip->i_afp->if_broot_bytes; |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 397 | } else { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 398 | iip->ili_fields &= ~XFS_ILOG_ABROOT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | break; |
| 401 | |
| 402 | case XFS_DINODE_FMT_LOCAL: |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 403 | iip->ili_fields &= |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 404 | ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT); |
| 405 | |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 406 | if ((iip->ili_fields & XFS_ILOG_ADATA) && |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 407 | ip->i_afp->if_bytes > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | ASSERT(ip->i_afp->if_u1.if_data != NULL); |
| 409 | |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 410 | vecp->i_addr = ip->i_afp->if_u1.if_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* |
| 412 | * Round i_bytes up to a word boundary. |
| 413 | * The underlying memory is guaranteed to |
| 414 | * to be there by xfs_idata_realloc(). |
| 415 | */ |
| 416 | data_bytes = roundup(ip->i_afp->if_bytes, 4); |
| 417 | ASSERT((ip->i_afp->if_real_bytes == 0) || |
| 418 | (ip->i_afp->if_real_bytes == data_bytes)); |
| 419 | vecp->i_len = (int)data_bytes; |
Christoph Hellwig | 4139b3b | 2010-01-19 09:56:45 +0000 | [diff] [blame] | 420 | vecp->i_type = XLOG_REG_TYPE_IATTR_LOCAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | vecp++; |
| 422 | nvecs++; |
| 423 | iip->ili_format.ilf_asize = (unsigned)data_bytes; |
Christoph Hellwig | 339a5f5 | 2012-02-29 09:53:53 +0000 | [diff] [blame] | 424 | } else { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 425 | iip->ili_fields &= ~XFS_ILOG_ADATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | break; |
| 428 | |
| 429 | default: |
| 430 | ASSERT(0); |
| 431 | break; |
| 432 | } |
| 433 | |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 434 | out: |
| 435 | /* |
| 436 | * Now update the log format that goes out to disk from the in-core |
| 437 | * values. We always write the inode core to make the arithmetic |
| 438 | * games in recovery easier, which isn't a big deal as just about any |
| 439 | * transaction would dirty it anyway. |
| 440 | */ |
Christoph Hellwig | 8f639dd | 2012-02-29 09:53:55 +0000 | [diff] [blame] | 441 | iip->ili_format.ilf_fields = XFS_ILOG_CORE | |
| 442 | (iip->ili_fields & ~XFS_ILOG_TIMESTAMP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | iip->ili_format.ilf_size = nvecs; |
| 444 | } |
| 445 | |
| 446 | |
| 447 | /* |
| 448 | * This is called to pin the inode associated with the inode log |
Christoph Hellwig | a14a5ab | 2010-02-18 12:43:22 +0000 | [diff] [blame] | 449 | * item in memory so it cannot be written out. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | */ |
| 451 | STATIC void |
| 452 | xfs_inode_item_pin( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 453 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 455 | struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode; |
Christoph Hellwig | a14a5ab | 2010-02-18 12:43:22 +0000 | [diff] [blame] | 456 | |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 457 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
| 458 | |
| 459 | trace_xfs_inode_pin(ip, _RET_IP_); |
| 460 | atomic_inc(&ip->i_pincount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | |
| 464 | /* |
| 465 | * This is called to unpin the inode associated with the inode log |
| 466 | * item which was previously pinned with a call to xfs_inode_item_pin(). |
Christoph Hellwig | a14a5ab | 2010-02-18 12:43:22 +0000 | [diff] [blame] | 467 | * |
| 468 | * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | STATIC void |
| 471 | xfs_inode_item_unpin( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 472 | struct xfs_log_item *lip, |
Christoph Hellwig | 9412e31 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 473 | int remove) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 475 | struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode; |
Christoph Hellwig | a14a5ab | 2010-02-18 12:43:22 +0000 | [diff] [blame] | 476 | |
Dave Chinner | 4aaf15d | 2010-03-08 11:24:07 +1100 | [diff] [blame] | 477 | trace_xfs_inode_unpin(ip, _RET_IP_); |
Christoph Hellwig | a14a5ab | 2010-02-18 12:43:22 +0000 | [diff] [blame] | 478 | ASSERT(atomic_read(&ip->i_pincount) > 0); |
| 479 | if (atomic_dec_and_test(&ip->i_pincount)) |
Christoph Hellwig | f392e63 | 2011-12-18 20:00:10 +0000 | [diff] [blame] | 480 | wake_up_bit(&ip->i_flags, __XFS_IPINNED_BIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | /* |
| 484 | * This is called to attempt to lock the inode associated with this |
| 485 | * inode log item, in preparation for the push routine which does the actual |
| 486 | * iflush. Don't sleep on the inode lock or the flush lock. |
| 487 | * |
| 488 | * If the flush lock is already held, indicating that the inode has |
| 489 | * been or is in the process of being flushed, then (ideally) we'd like to |
| 490 | * see if the inode's buffer is still incore, and if so give it a nudge. |
| 491 | * We delay doing so until the pushbuf routine, though, to avoid holding |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 492 | * the AIL lock across a call to the blackhole which is the buffer cache. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | * Also we don't want to sleep in any device strategy routines, which can happen |
| 494 | * if we do the subsequent bawrite in here. |
| 495 | */ |
| 496 | STATIC uint |
| 497 | xfs_inode_item_trylock( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 498 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 500 | struct xfs_inode_log_item *iip = INODE_ITEM(lip); |
| 501 | struct xfs_inode *ip = iip->ili_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 503 | if (xfs_ipincount(ip) > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | return XFS_ITEM_PINNED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 506 | if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | return XFS_ITEM_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Christoph Hellwig | 4c46819 | 2012-04-23 15:58:36 +1000 | [diff] [blame^] | 509 | /* |
| 510 | * Re-check the pincount now that we stabilized the value by |
| 511 | * taking the ilock. |
| 512 | */ |
| 513 | if (xfs_ipincount(ip) > 0) { |
| 514 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 515 | return XFS_ITEM_PINNED; |
| 516 | } |
| 517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (!xfs_iflock_nowait(ip)) { |
| 519 | /* |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 520 | * inode has already been flushed to the backing buffer, |
| 521 | * leave it locked in shared mode, pushbuf routine will |
| 522 | * unlock it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | */ |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 524 | return XFS_ITEM_PUSHBUF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /* Stale items should force out the iclog */ |
| 528 | if (ip->i_flags & XFS_ISTALE) { |
| 529 | xfs_ifunlock(ip); |
Christoph Hellwig | 5b03ff1 | 2012-02-20 02:31:22 +0000 | [diff] [blame] | 530 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return XFS_ITEM_PINNED; |
| 532 | } |
| 533 | |
| 534 | #ifdef DEBUG |
| 535 | if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) { |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 536 | ASSERT(iip->ili_fields != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | ASSERT(iip->ili_logged == 0); |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 538 | ASSERT(lip->li_flags & XFS_LI_IN_AIL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | #endif |
| 541 | return XFS_ITEM_SUCCESS; |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * Unlock the inode associated with the inode log item. |
| 546 | * Clear the fields of the inode and inode log item that |
| 547 | * are specific to the current transaction. If the |
| 548 | * hold flags is set, do not unlock the inode. |
| 549 | */ |
| 550 | STATIC void |
| 551 | xfs_inode_item_unlock( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 552 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 554 | struct xfs_inode_log_item *iip = INODE_ITEM(lip); |
| 555 | struct xfs_inode *ip = iip->ili_inode; |
Christoph Hellwig | 898621d | 2010-06-24 11:36:58 +1000 | [diff] [blame] | 556 | unsigned short lock_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Christoph Hellwig | f3ca8738 | 2011-07-08 14:34:47 +0200 | [diff] [blame] | 558 | ASSERT(ip->i_itemp != NULL); |
| 559 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | /* |
| 562 | * If the inode needed a separate buffer with which to log |
| 563 | * its extents, then free it now. |
| 564 | */ |
| 565 | if (iip->ili_extents_buf != NULL) { |
| 566 | ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS); |
| 567 | ASSERT(ip->i_d.di_nextents > 0); |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 568 | ASSERT(iip->ili_fields & XFS_ILOG_DEXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | ASSERT(ip->i_df.if_bytes > 0); |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 570 | kmem_free(iip->ili_extents_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | iip->ili_extents_buf = NULL; |
| 572 | } |
| 573 | if (iip->ili_aextents_buf != NULL) { |
| 574 | ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS); |
| 575 | ASSERT(ip->i_d.di_anextents > 0); |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 576 | ASSERT(iip->ili_fields & XFS_ILOG_AEXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | ASSERT(ip->i_afp->if_bytes > 0); |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 578 | kmem_free(iip->ili_aextents_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | iip->ili_aextents_buf = NULL; |
| 580 | } |
| 581 | |
Christoph Hellwig | 898621d | 2010-06-24 11:36:58 +1000 | [diff] [blame] | 582 | lock_flags = iip->ili_lock_flags; |
| 583 | iip->ili_lock_flags = 0; |
Christoph Hellwig | ddc3415 | 2011-09-19 15:00:54 +0000 | [diff] [blame] | 584 | if (lock_flags) |
Christoph Hellwig | f3ca8738 | 2011-07-08 14:34:47 +0200 | [diff] [blame] | 585 | xfs_iunlock(ip, lock_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* |
Dave Chinner | de25c18 | 2010-11-30 15:15:46 +1100 | [diff] [blame] | 589 | * This is called to find out where the oldest active copy of the inode log |
| 590 | * item in the on disk log resides now that the last log write of it completed |
| 591 | * at the given lsn. Since we always re-log all dirty data in an inode, the |
| 592 | * latest copy in the on disk log is the only one that matters. Therefore, |
| 593 | * simply return the given lsn. |
| 594 | * |
| 595 | * If the inode has been marked stale because the cluster is being freed, we |
| 596 | * don't want to (re-)insert this inode into the AIL. There is a race condition |
| 597 | * where the cluster buffer may be unpinned before the inode is inserted into |
| 598 | * the AIL during transaction committed processing. If the buffer is unpinned |
| 599 | * before the inode item has been committed and inserted, then it is possible |
Dave Chinner | 1316d4d | 2011-07-04 05:27:36 +0000 | [diff] [blame] | 600 | * for the buffer to be written and IO completes before the inode is inserted |
Dave Chinner | de25c18 | 2010-11-30 15:15:46 +1100 | [diff] [blame] | 601 | * into the AIL. In that case, we'd be inserting a clean, stale inode into the |
| 602 | * AIL which will never get removed. It will, however, get reclaimed which |
| 603 | * triggers an assert in xfs_inode_free() complaining about freein an inode |
| 604 | * still in the AIL. |
| 605 | * |
Dave Chinner | 1316d4d | 2011-07-04 05:27:36 +0000 | [diff] [blame] | 606 | * To avoid this, just unpin the inode directly and return a LSN of -1 so the |
| 607 | * transaction committed code knows that it does not need to do any further |
| 608 | * processing on the item. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | STATIC xfs_lsn_t |
| 611 | xfs_inode_item_committed( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 612 | struct xfs_log_item *lip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | xfs_lsn_t lsn) |
| 614 | { |
Dave Chinner | de25c18 | 2010-11-30 15:15:46 +1100 | [diff] [blame] | 615 | struct xfs_inode_log_item *iip = INODE_ITEM(lip); |
| 616 | struct xfs_inode *ip = iip->ili_inode; |
| 617 | |
Dave Chinner | 1316d4d | 2011-07-04 05:27:36 +0000 | [diff] [blame] | 618 | if (xfs_iflags_test(ip, XFS_ISTALE)) { |
| 619 | xfs_inode_item_unpin(lip, 0); |
| 620 | return -1; |
| 621 | } |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 622 | return lsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | * This gets called by xfs_trans_push_ail(), when IOP_TRYLOCK |
| 627 | * failed to get the inode flush lock but did get the inode locked SHARED. |
| 628 | * Here we're trying to see if the inode buffer is incore, and if so whether it's |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 629 | * marked delayed write. If that's the case, we'll promote it and that will |
| 630 | * allow the caller to write the buffer by triggering the xfsbufd to run. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | */ |
Christoph Hellwig | 17b3847 | 2011-10-11 15:14:09 +0000 | [diff] [blame] | 632 | STATIC bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | xfs_inode_item_pushbuf( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 634 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 636 | struct xfs_inode_log_item *iip = INODE_ITEM(lip); |
| 637 | struct xfs_inode *ip = iip->ili_inode; |
| 638 | struct xfs_buf *bp; |
Christoph Hellwig | 17b3847 | 2011-10-11 15:14:09 +0000 | [diff] [blame] | 639 | bool ret = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 641 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | /* |
David Chinner | c63942d | 2008-08-13 16:41:16 +1000 | [diff] [blame] | 644 | * If a flush is not in progress anymore, chances are that the |
| 645 | * inode was taken off the AIL. So, just get out. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | */ |
Christoph Hellwig | 474fce0 | 2011-12-18 20:00:09 +0000 | [diff] [blame] | 647 | if (!xfs_isiflocked(ip) || |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 648 | !(lip->li_flags & XFS_LI_IN_AIL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
Christoph Hellwig | 17b3847 | 2011-10-11 15:14:09 +0000 | [diff] [blame] | 650 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 653 | bp = xfs_incore(ip->i_mount->m_ddev_targp, iip->ili_format.ilf_blkno, |
| 654 | iip->ili_format.ilf_len, XBF_TRYLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 657 | if (!bp) |
Christoph Hellwig | 17b3847 | 2011-10-11 15:14:09 +0000 | [diff] [blame] | 658 | return true; |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 659 | if (XFS_BUF_ISDELAYWRITE(bp)) |
| 660 | xfs_buf_delwri_promote(bp); |
Christoph Hellwig | 17b3847 | 2011-10-11 15:14:09 +0000 | [diff] [blame] | 661 | if (xfs_buf_ispinned(bp)) |
| 662 | ret = false; |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 663 | xfs_buf_relse(bp); |
Christoph Hellwig | 17b3847 | 2011-10-11 15:14:09 +0000 | [diff] [blame] | 664 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | /* |
| 668 | * This is called to asynchronously write the inode associated with this |
| 669 | * inode log item out to disk. The inode will already have been locked by |
| 670 | * a successful call to xfs_inode_item_trylock(). |
| 671 | */ |
| 672 | STATIC void |
| 673 | xfs_inode_item_push( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 674 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 676 | struct xfs_inode_log_item *iip = INODE_ITEM(lip); |
| 677 | struct xfs_inode *ip = iip->ili_inode; |
Christoph Hellwig | 4c46819 | 2012-04-23 15:58:36 +1000 | [diff] [blame^] | 678 | struct xfs_buf *bp = NULL; |
| 679 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 681 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED)); |
Christoph Hellwig | 474fce0 | 2011-12-18 20:00:09 +0000 | [diff] [blame] | 682 | ASSERT(xfs_isiflocked(ip)); |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | /* |
| 685 | * Since we were able to lock the inode's flush lock and |
| 686 | * we found it on the AIL, the inode must be dirty. This |
| 687 | * is because the inode is removed from the AIL while still |
| 688 | * holding the flush lock in xfs_iflush_done(). Thus, if |
| 689 | * we found it in the AIL and were able to obtain the flush |
| 690 | * lock without sleeping, then there must not have been |
| 691 | * anyone in the process of flushing the inode. |
| 692 | */ |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 693 | ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || iip->ili_fields != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | /* |
Dave Chinner | c854363 | 2010-02-06 12:39:36 +1100 | [diff] [blame] | 696 | * Push the inode to it's backing buffer. This will not remove the |
| 697 | * inode from the AIL - a further push will be required to trigger a |
| 698 | * buffer push. However, this allows all the dirty inodes to be pushed |
Dave Chinner | 1bfd8d0 | 2011-03-26 09:13:55 +1100 | [diff] [blame] | 699 | * to the buffer before it is pushed to disk. The buffer IO completion |
| 700 | * will pull the inode from the AIL, mark it clean and unlock the flush |
Dave Chinner | c854363 | 2010-02-06 12:39:36 +1100 | [diff] [blame] | 701 | * lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | */ |
Christoph Hellwig | 4c46819 | 2012-04-23 15:58:36 +1000 | [diff] [blame^] | 703 | error = xfs_iflush(ip, &bp); |
| 704 | if (!error) { |
| 705 | xfs_buf_delwri_queue(bp); |
| 706 | xfs_buf_relse(bp); |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* |
| 712 | * XXX rcc - this one really has to do something. Probably needs |
| 713 | * to stamp in a new field in the incore inode. |
| 714 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | STATIC void |
| 716 | xfs_inode_item_committing( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 717 | struct xfs_log_item *lip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | xfs_lsn_t lsn) |
| 719 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 720 | INODE_ITEM(lip)->ili_last_lsn = lsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /* |
| 724 | * This is the ops vector shared by all buf log items. |
| 725 | */ |
Christoph Hellwig | 272e42b | 2011-10-28 09:54:24 +0000 | [diff] [blame] | 726 | static const struct xfs_item_ops xfs_inode_item_ops = { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 727 | .iop_size = xfs_inode_item_size, |
| 728 | .iop_format = xfs_inode_item_format, |
| 729 | .iop_pin = xfs_inode_item_pin, |
| 730 | .iop_unpin = xfs_inode_item_unpin, |
| 731 | .iop_trylock = xfs_inode_item_trylock, |
| 732 | .iop_unlock = xfs_inode_item_unlock, |
| 733 | .iop_committed = xfs_inode_item_committed, |
| 734 | .iop_push = xfs_inode_item_push, |
| 735 | .iop_pushbuf = xfs_inode_item_pushbuf, |
| 736 | .iop_committing = xfs_inode_item_committing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | }; |
| 738 | |
| 739 | |
| 740 | /* |
| 741 | * Initialize the inode log item for a newly allocated (in-core) inode. |
| 742 | */ |
| 743 | void |
| 744 | xfs_inode_item_init( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 745 | struct xfs_inode *ip, |
| 746 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 748 | struct xfs_inode_log_item *iip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | ASSERT(ip->i_itemp == NULL); |
| 751 | iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP); |
| 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | iip->ili_inode = ip; |
Dave Chinner | 43f5efc | 2010-03-23 10:10:00 +1100 | [diff] [blame] | 754 | xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE, |
| 755 | &xfs_inode_item_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | iip->ili_format.ilf_type = XFS_LI_INODE; |
| 757 | iip->ili_format.ilf_ino = ip->i_ino; |
Christoph Hellwig | 92bfc6e | 2008-11-28 14:23:41 +1100 | [diff] [blame] | 758 | iip->ili_format.ilf_blkno = ip->i_imap.im_blkno; |
| 759 | iip->ili_format.ilf_len = ip->i_imap.im_len; |
| 760 | iip->ili_format.ilf_boffset = ip->i_imap.im_boffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /* |
| 764 | * Free the inode log item and any memory hanging off of it. |
| 765 | */ |
| 766 | void |
| 767 | xfs_inode_item_destroy( |
| 768 | xfs_inode_t *ip) |
| 769 | { |
| 770 | #ifdef XFS_TRANS_DEBUG |
| 771 | if (ip->i_itemp->ili_root_size != 0) { |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 772 | kmem_free(ip->i_itemp->ili_orig_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | #endif |
| 775 | kmem_zone_free(xfs_ili_zone, ip->i_itemp); |
| 776 | } |
| 777 | |
| 778 | |
| 779 | /* |
| 780 | * This is the inode flushing I/O completion routine. It is called |
| 781 | * from interrupt level when the buffer containing the inode is |
| 782 | * flushed to disk. It is responsible for removing the inode item |
| 783 | * from the AIL if it has not been re-logged, and unlocking the inode's |
| 784 | * flush lock. |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 785 | * |
| 786 | * To reduce AIL lock traffic as much as possible, we scan the buffer log item |
| 787 | * list for other inodes that will run this function. We remove them from the |
| 788 | * buffer list so we can process all the inode IO completions in one AIL lock |
| 789 | * traversal. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | void |
| 792 | xfs_iflush_done( |
Christoph Hellwig | ca30b2a | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 793 | struct xfs_buf *bp, |
| 794 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 796 | struct xfs_inode_log_item *iip; |
| 797 | struct xfs_log_item *blip; |
| 798 | struct xfs_log_item *next; |
| 799 | struct xfs_log_item *prev; |
Christoph Hellwig | ca30b2a | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 800 | struct xfs_ail *ailp = lip->li_ailp; |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 801 | int need_ail = 0; |
| 802 | |
| 803 | /* |
| 804 | * Scan the buffer IO completions for other inodes being completed and |
| 805 | * attach them to the current inode log item. |
| 806 | */ |
Christoph Hellwig | adadbee | 2011-07-13 13:43:49 +0200 | [diff] [blame] | 807 | blip = bp->b_fspriv; |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 808 | prev = NULL; |
| 809 | while (blip != NULL) { |
| 810 | if (lip->li_cb != xfs_iflush_done) { |
| 811 | prev = blip; |
| 812 | blip = blip->li_bio_list; |
| 813 | continue; |
| 814 | } |
| 815 | |
| 816 | /* remove from list */ |
| 817 | next = blip->li_bio_list; |
| 818 | if (!prev) { |
Christoph Hellwig | adadbee | 2011-07-13 13:43:49 +0200 | [diff] [blame] | 819 | bp->b_fspriv = next; |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 820 | } else { |
| 821 | prev->li_bio_list = next; |
| 822 | } |
| 823 | |
| 824 | /* add to current list */ |
| 825 | blip->li_bio_list = lip->li_bio_list; |
| 826 | lip->li_bio_list = blip; |
| 827 | |
| 828 | /* |
| 829 | * while we have the item, do the unlocked check for needing |
| 830 | * the AIL lock. |
| 831 | */ |
| 832 | iip = INODE_ITEM(blip); |
| 833 | if (iip->ili_logged && blip->li_lsn == iip->ili_flush_lsn) |
| 834 | need_ail++; |
| 835 | |
| 836 | blip = next; |
| 837 | } |
| 838 | |
| 839 | /* make sure we capture the state of the initial inode. */ |
| 840 | iip = INODE_ITEM(lip); |
| 841 | if (iip->ili_logged && lip->li_lsn == iip->ili_flush_lsn) |
| 842 | need_ail++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | /* |
| 845 | * We only want to pull the item from the AIL if it is |
| 846 | * actually there and its location in the log has not |
| 847 | * changed since we started the flush. Thus, we only bother |
| 848 | * if the ili_logged flag is set and the inode's lsn has not |
| 849 | * changed. First we check the lsn outside |
| 850 | * the lock since it's cheaper, and then we recheck while |
| 851 | * holding the lock before removing the inode from the AIL. |
| 852 | */ |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 853 | if (need_ail) { |
| 854 | struct xfs_log_item *log_items[need_ail]; |
| 855 | int i = 0; |
David Chinner | 783a2f6 | 2008-10-30 17:39:58 +1100 | [diff] [blame] | 856 | spin_lock(&ailp->xa_lock); |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 857 | for (blip = lip; blip; blip = blip->li_bio_list) { |
| 858 | iip = INODE_ITEM(blip); |
| 859 | if (iip->ili_logged && |
| 860 | blip->li_lsn == iip->ili_flush_lsn) { |
| 861 | log_items[i++] = blip; |
| 862 | } |
| 863 | ASSERT(i <= need_ail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 865 | /* xfs_trans_ail_delete_bulk() drops the AIL lock. */ |
| 866 | xfs_trans_ail_delete_bulk(ailp, log_items, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | /* |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 871 | * clean up and unlock the flush lock now we are done. We can clear the |
| 872 | * ili_last_fields bits now that we know that the data corresponding to |
| 873 | * them is safely on disk. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | */ |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 875 | for (blip = lip; blip; blip = next) { |
| 876 | next = blip->li_bio_list; |
| 877 | blip->li_bio_list = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
Dave Chinner | 3013683 | 2010-12-20 12:03:17 +1100 | [diff] [blame] | 879 | iip = INODE_ITEM(blip); |
| 880 | iip->ili_logged = 0; |
| 881 | iip->ili_last_fields = 0; |
| 882 | xfs_ifunlock(iip->ili_inode); |
| 883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /* |
| 887 | * This is the inode flushing abort routine. It is called |
| 888 | * from xfs_iflush when the filesystem is shutting down to clean |
| 889 | * up the inode state. |
| 890 | * It is responsible for removing the inode item |
| 891 | * from the AIL if it has not been re-logged, and unlocking the inode's |
| 892 | * flush lock. |
| 893 | */ |
| 894 | void |
| 895 | xfs_iflush_abort( |
| 896 | xfs_inode_t *ip) |
| 897 | { |
David Chinner | 783a2f6 | 2008-10-30 17:39:58 +1100 | [diff] [blame] | 898 | xfs_inode_log_item_t *iip = ip->i_itemp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | if (iip) { |
David Chinner | 783a2f6 | 2008-10-30 17:39:58 +1100 | [diff] [blame] | 901 | struct xfs_ail *ailp = iip->ili_item.li_ailp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | if (iip->ili_item.li_flags & XFS_LI_IN_AIL) { |
David Chinner | 783a2f6 | 2008-10-30 17:39:58 +1100 | [diff] [blame] | 903 | spin_lock(&ailp->xa_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | if (iip->ili_item.li_flags & XFS_LI_IN_AIL) { |
David Chinner | 783a2f6 | 2008-10-30 17:39:58 +1100 | [diff] [blame] | 905 | /* xfs_trans_ail_delete() drops the AIL lock. */ |
| 906 | xfs_trans_ail_delete(ailp, (xfs_log_item_t *)iip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } else |
David Chinner | 783a2f6 | 2008-10-30 17:39:58 +1100 | [diff] [blame] | 908 | spin_unlock(&ailp->xa_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | } |
| 910 | iip->ili_logged = 0; |
| 911 | /* |
| 912 | * Clear the ili_last_fields bits now that we know that the |
| 913 | * data corresponding to them is safely on disk. |
| 914 | */ |
| 915 | iip->ili_last_fields = 0; |
| 916 | /* |
| 917 | * Clear the inode logging fields so no more flushes are |
| 918 | * attempted. |
| 919 | */ |
Christoph Hellwig | f5d8d5c | 2012-02-29 09:53:54 +0000 | [diff] [blame] | 920 | iip->ili_fields = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | /* |
| 923 | * Release the inode's flush lock since we're done with it. |
| 924 | */ |
| 925 | xfs_ifunlock(ip); |
| 926 | } |
| 927 | |
| 928 | void |
| 929 | xfs_istale_done( |
Christoph Hellwig | ca30b2a | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 930 | struct xfs_buf *bp, |
| 931 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | { |
Christoph Hellwig | ca30b2a | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 933 | xfs_iflush_abort(INODE_ITEM(lip)->ili_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } |
Tim Shimmin | 6d192a9 | 2006-06-09 14:55:38 +1000 | [diff] [blame] | 935 | |
| 936 | /* |
| 937 | * convert an xfs_inode_log_format struct from either 32 or 64 bit versions |
| 938 | * (which can have different field alignments) to the native version |
| 939 | */ |
| 940 | int |
| 941 | xfs_inode_item_format_convert( |
| 942 | xfs_log_iovec_t *buf, |
| 943 | xfs_inode_log_format_t *in_f) |
| 944 | { |
| 945 | if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) { |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 946 | xfs_inode_log_format_32_t *in_f32 = buf->i_addr; |
Tim Shimmin | 6d192a9 | 2006-06-09 14:55:38 +1000 | [diff] [blame] | 947 | |
Tim Shimmin | 6d192a9 | 2006-06-09 14:55:38 +1000 | [diff] [blame] | 948 | in_f->ilf_type = in_f32->ilf_type; |
| 949 | in_f->ilf_size = in_f32->ilf_size; |
| 950 | in_f->ilf_fields = in_f32->ilf_fields; |
| 951 | in_f->ilf_asize = in_f32->ilf_asize; |
| 952 | in_f->ilf_dsize = in_f32->ilf_dsize; |
| 953 | in_f->ilf_ino = in_f32->ilf_ino; |
| 954 | /* copy biggest field of ilf_u */ |
| 955 | memcpy(in_f->ilf_u.ilfu_uuid.__u_bits, |
| 956 | in_f32->ilf_u.ilfu_uuid.__u_bits, |
| 957 | sizeof(uuid_t)); |
| 958 | in_f->ilf_blkno = in_f32->ilf_blkno; |
| 959 | in_f->ilf_len = in_f32->ilf_len; |
| 960 | in_f->ilf_boffset = in_f32->ilf_boffset; |
| 961 | return 0; |
| 962 | } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){ |
Christoph Hellwig | 4e0d5f9 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 963 | xfs_inode_log_format_64_t *in_f64 = buf->i_addr; |
Tim Shimmin | 6d192a9 | 2006-06-09 14:55:38 +1000 | [diff] [blame] | 964 | |
Tim Shimmin | 6d192a9 | 2006-06-09 14:55:38 +1000 | [diff] [blame] | 965 | in_f->ilf_type = in_f64->ilf_type; |
| 966 | in_f->ilf_size = in_f64->ilf_size; |
| 967 | in_f->ilf_fields = in_f64->ilf_fields; |
| 968 | in_f->ilf_asize = in_f64->ilf_asize; |
| 969 | in_f->ilf_dsize = in_f64->ilf_dsize; |
| 970 | in_f->ilf_ino = in_f64->ilf_ino; |
| 971 | /* copy biggest field of ilf_u */ |
| 972 | memcpy(in_f->ilf_u.ilfu_uuid.__u_bits, |
| 973 | in_f64->ilf_u.ilfu_uuid.__u_bits, |
| 974 | sizeof(uuid_t)); |
| 975 | in_f->ilf_blkno = in_f64->ilf_blkno; |
| 976 | in_f->ilf_len = in_f64->ilf_len; |
| 977 | in_f->ilf_boffset = in_f64->ilf_boffset; |
| 978 | return 0; |
| 979 | } |
| 980 | return EFSCORRUPTED; |
| 981 | } |