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