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