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