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