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-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_sb.h" |
| 26 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "xfs_dir2.h" |
| 28 | #include "xfs_dmapi.h" |
| 29 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_bmap_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 31 | #include "xfs_alloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "xfs_ialloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "xfs_dir2_sf.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 34 | #include "xfs_attr_sf.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "xfs_dinode.h" |
| 36 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 37 | #include "xfs_btree.h" |
| 38 | #include "xfs_ialloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "xfs_quota.h" |
| 40 | #include "xfs_utils.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
David Chinner | 6441e54 | 2008-10-30 17:21:19 +1100 | [diff] [blame^] | 43 | * Check the validity of the inode we just found it the cache |
| 44 | */ |
| 45 | static int |
| 46 | xfs_iget_cache_hit( |
| 47 | struct inode *inode, |
| 48 | struct xfs_perag *pag, |
| 49 | struct xfs_inode *ip, |
| 50 | int flags, |
| 51 | int lock_flags) __releases(pag->pag_ici_lock) |
| 52 | { |
| 53 | struct xfs_mount *mp = ip->i_mount; |
| 54 | struct inode *old_inode; |
| 55 | int error = 0; |
| 56 | |
| 57 | /* |
| 58 | * If INEW is set this inode is being set up |
| 59 | * Pause and try again. |
| 60 | */ |
| 61 | if (xfs_iflags_test(ip, XFS_INEW)) { |
| 62 | error = EAGAIN; |
| 63 | XFS_STATS_INC(xs_ig_frecycle); |
| 64 | goto out_error; |
| 65 | } |
| 66 | |
| 67 | old_inode = ip->i_vnode; |
| 68 | if (old_inode == NULL) { |
| 69 | /* |
| 70 | * If IRECLAIM is set this inode is |
| 71 | * on its way out of the system, |
| 72 | * we need to pause and try again. |
| 73 | */ |
| 74 | if (xfs_iflags_test(ip, XFS_IRECLAIM)) { |
| 75 | error = EAGAIN; |
| 76 | XFS_STATS_INC(xs_ig_frecycle); |
| 77 | goto out_error; |
| 78 | } |
| 79 | ASSERT(xfs_iflags_test(ip, XFS_IRECLAIMABLE)); |
| 80 | |
| 81 | /* |
| 82 | * If lookup is racing with unlink, then we |
| 83 | * should return an error immediately so we |
| 84 | * don't remove it from the reclaim list and |
| 85 | * potentially leak the inode. |
| 86 | */ |
| 87 | if ((ip->i_d.di_mode == 0) && |
| 88 | !(flags & XFS_IGET_CREATE)) { |
| 89 | error = ENOENT; |
| 90 | goto out_error; |
| 91 | } |
| 92 | xfs_itrace_exit_tag(ip, "xfs_iget.alloc"); |
| 93 | |
| 94 | xfs_iflags_clear(ip, XFS_IRECLAIMABLE); |
| 95 | read_unlock(&pag->pag_ici_lock); |
| 96 | |
| 97 | XFS_MOUNT_ILOCK(mp); |
| 98 | list_del_init(&ip->i_reclaim); |
| 99 | XFS_MOUNT_IUNLOCK(mp); |
| 100 | |
| 101 | } else if (inode != old_inode) { |
| 102 | /* The inode is being torn down, pause and |
| 103 | * try again. |
| 104 | */ |
| 105 | if (old_inode->i_state & (I_FREEING | I_CLEAR)) { |
| 106 | error = EAGAIN; |
| 107 | XFS_STATS_INC(xs_ig_frecycle); |
| 108 | goto out_error; |
| 109 | } |
| 110 | /* Chances are the other vnode (the one in the inode) is being torn |
| 111 | * down right now, and we landed on top of it. Question is, what do |
| 112 | * we do? Unhook the old inode and hook up the new one? |
| 113 | */ |
| 114 | cmn_err(CE_PANIC, |
| 115 | "xfs_iget_core: ambiguous vns: vp/0x%p, invp/0x%p", |
| 116 | old_inode, inode); |
| 117 | } else { |
| 118 | read_unlock(&pag->pag_ici_lock); |
| 119 | } |
| 120 | |
| 121 | if (ip->i_d.di_mode == 0 && !(flags & XFS_IGET_CREATE)) { |
| 122 | error = ENOENT; |
| 123 | goto out; |
| 124 | } |
| 125 | |
| 126 | if (lock_flags != 0) |
| 127 | xfs_ilock(ip, lock_flags); |
| 128 | |
| 129 | xfs_iflags_clear(ip, XFS_ISTALE); |
| 130 | xfs_itrace_exit_tag(ip, "xfs_iget.found"); |
| 131 | XFS_STATS_INC(xs_ig_found); |
| 132 | return 0; |
| 133 | |
| 134 | out_error: |
| 135 | read_unlock(&pag->pag_ici_lock); |
| 136 | out: |
| 137 | return error; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | static int |
| 142 | xfs_iget_cache_miss( |
| 143 | struct xfs_mount *mp, |
| 144 | struct xfs_perag *pag, |
| 145 | xfs_trans_t *tp, |
| 146 | xfs_ino_t ino, |
| 147 | struct xfs_inode **ipp, |
| 148 | xfs_daddr_t bno, |
| 149 | int flags, |
| 150 | int lock_flags) __releases(pag->pag_ici_lock) |
| 151 | { |
| 152 | struct xfs_inode *ip; |
| 153 | int error; |
| 154 | unsigned long first_index, mask; |
| 155 | xfs_agino_t agino = XFS_INO_TO_AGINO(mp, ino); |
| 156 | |
| 157 | /* |
| 158 | * Read the disk inode attributes into a new inode structure and get |
| 159 | * a new vnode for it. This should also initialize i_ino and i_mount. |
| 160 | */ |
| 161 | error = xfs_iread(mp, tp, ino, &ip, bno, |
| 162 | (flags & XFS_IGET_BULKSTAT) ? XFS_IMAP_BULKSTAT : 0); |
| 163 | if (error) |
| 164 | return error; |
| 165 | |
| 166 | xfs_itrace_exit_tag(ip, "xfs_iget.alloc"); |
| 167 | |
| 168 | if ((ip->i_d.di_mode == 0) && !(flags & XFS_IGET_CREATE)) { |
| 169 | error = ENOENT; |
| 170 | goto out_destroy; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Preload the radix tree so we can insert safely under the |
| 175 | * write spinlock. |
| 176 | */ |
| 177 | if (radix_tree_preload(GFP_KERNEL)) { |
| 178 | error = EAGAIN; |
| 179 | goto out_destroy; |
| 180 | } |
| 181 | |
| 182 | if (lock_flags) |
| 183 | xfs_ilock(ip, lock_flags); |
| 184 | |
| 185 | mask = ~(((XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog)) - 1); |
| 186 | first_index = agino & mask; |
| 187 | write_lock(&pag->pag_ici_lock); |
| 188 | |
| 189 | /* insert the new inode */ |
| 190 | error = radix_tree_insert(&pag->pag_ici_root, agino, ip); |
| 191 | if (unlikely(error)) { |
| 192 | WARN_ON(error != -EEXIST); |
| 193 | XFS_STATS_INC(xs_ig_dup); |
| 194 | error = EAGAIN; |
| 195 | goto out_unlock; |
| 196 | } |
| 197 | |
| 198 | /* These values _must_ be set before releasing the radix tree lock! */ |
| 199 | ip->i_udquot = ip->i_gdquot = NULL; |
| 200 | xfs_iflags_set(ip, XFS_INEW); |
| 201 | |
| 202 | write_unlock(&pag->pag_ici_lock); |
| 203 | radix_tree_preload_end(); |
| 204 | *ipp = ip; |
| 205 | return 0; |
| 206 | |
| 207 | out_unlock: |
| 208 | write_unlock(&pag->pag_ici_lock); |
| 209 | radix_tree_preload_end(); |
| 210 | out_destroy: |
| 211 | xfs_idestroy(ip); |
| 212 | return error; |
| 213 | } |
| 214 | |
| 215 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | * Look up an inode by number in the given file system. |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 217 | * The inode is looked up in the cache held in each AG. |
| 218 | * If the inode is found in the cache, attach it to the provided |
| 219 | * vnode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | * |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 221 | * If it is not in core, read it in from the file system's device, |
| 222 | * add it to the cache and attach the provided vnode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | * |
| 224 | * The inode is locked according to the value of the lock_flags parameter. |
| 225 | * This flag parameter indicates how and if the inode's IO lock and inode lock |
| 226 | * should be taken. |
| 227 | * |
| 228 | * mp -- the mount point structure for the current file system. It points |
| 229 | * to the inode hash table. |
| 230 | * tp -- a pointer to the current transaction if there is one. This is |
| 231 | * simply passed through to the xfs_iread() call. |
| 232 | * ino -- the number of the inode desired. This is the unique identifier |
| 233 | * within the file system for the inode being requested. |
| 234 | * lock_flags -- flags indicating how to lock the inode. See the comment |
| 235 | * for xfs_ilock() for a list of valid values. |
| 236 | * bno -- the block number starting the buffer containing the inode, |
| 237 | * if known (as by bulkstat), else 0. |
| 238 | */ |
| 239 | STATIC int |
| 240 | xfs_iget_core( |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 241 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | xfs_mount_t *mp, |
| 243 | xfs_trans_t *tp, |
| 244 | xfs_ino_t ino, |
| 245 | uint flags, |
| 246 | uint lock_flags, |
| 247 | xfs_inode_t **ipp, |
| 248 | xfs_daddr_t bno) |
| 249 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | xfs_inode_t *ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | int error; |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 252 | xfs_perag_t *pag; |
| 253 | xfs_agino_t agino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 255 | /* the radix tree exists only in inode capable AGs */ |
| 256 | if (XFS_INO_TO_AGNO(mp, ino) >= mp->m_maxagi) |
| 257 | return EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 259 | /* get the perag structure and ensure that it's inode capable */ |
| 260 | pag = xfs_get_perag(mp, ino); |
| 261 | if (!pag->pagi_inodeok) |
| 262 | return EINVAL; |
| 263 | ASSERT(pag->pag_ici_init); |
| 264 | agino = XFS_INO_TO_AGINO(mp, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | again: |
David Chinner | 6441e54 | 2008-10-30 17:21:19 +1100 | [diff] [blame^] | 267 | error = 0; |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 268 | read_lock(&pag->pag_ici_lock); |
| 269 | ip = radix_tree_lookup(&pag->pag_ici_root, agino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
David Chinner | 6441e54 | 2008-10-30 17:21:19 +1100 | [diff] [blame^] | 271 | if (ip) { |
| 272 | error = xfs_iget_cache_hit(inode, pag, ip, flags, lock_flags); |
| 273 | if (error) |
| 274 | goto out_error_or_again; |
| 275 | } else { |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 276 | read_unlock(&pag->pag_ici_lock); |
David Chinner | 6441e54 | 2008-10-30 17:21:19 +1100 | [diff] [blame^] | 277 | XFS_STATS_INC(xs_ig_missed); |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 278 | |
David Chinner | 6441e54 | 2008-10-30 17:21:19 +1100 | [diff] [blame^] | 279 | error = xfs_iget_cache_miss(mp, pag, tp, ino, &ip, bno, |
| 280 | flags, lock_flags); |
| 281 | if (error) |
| 282 | goto out_error_or_again; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 284 | xfs_put_perag(mp, pag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | ASSERT(ip->i_df.if_ext_max == |
| 287 | XFS_IFORK_DSIZE(ip) / sizeof(xfs_bmbt_rec_t)); |
| 288 | |
Christoph Hellwig | b3aea4e | 2007-08-29 11:44:37 +1000 | [diff] [blame] | 289 | xfs_iflags_set(ip, XFS_IMODIFIED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | *ipp = ip; |
| 291 | |
| 292 | /* |
Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 293 | * Set up the Linux with the Linux inode. |
| 294 | */ |
| 295 | ip->i_vnode = inode; |
| 296 | inode->i_private = ip; |
| 297 | |
| 298 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | * If we have a real type for an on-disk inode, we can set ops(&unlock) |
| 300 | * now. If it's a new inode being created, xfs_ialloc will handle it. |
| 301 | */ |
Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 302 | if (ip->i_d.di_mode != 0) |
| 303 | xfs_setup_inode(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return 0; |
David Chinner | 6441e54 | 2008-10-30 17:21:19 +1100 | [diff] [blame^] | 305 | |
| 306 | out_error_or_again: |
| 307 | if (error == EAGAIN) { |
| 308 | delay(1); |
| 309 | goto again; |
| 310 | } |
| 311 | xfs_put_perag(mp, pag); |
| 312 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
| 316 | /* |
| 317 | * The 'normal' internal xfs_iget, if needed it will |
| 318 | * 'allocate', or 'get', the vnode. |
| 319 | */ |
| 320 | int |
| 321 | xfs_iget( |
| 322 | xfs_mount_t *mp, |
| 323 | xfs_trans_t *tp, |
| 324 | xfs_ino_t ino, |
| 325 | uint flags, |
| 326 | uint lock_flags, |
| 327 | xfs_inode_t **ipp, |
| 328 | xfs_daddr_t bno) |
| 329 | { |
| 330 | struct inode *inode; |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 331 | xfs_inode_t *ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | int error; |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | XFS_STATS_INC(xs_ig_attempts); |
| 335 | |
Christoph Hellwig | ba403ab | 2005-09-05 08:33:00 +1000 | [diff] [blame] | 336 | retry: |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 337 | inode = iget_locked(mp->m_super, ino); |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 338 | if (!inode) |
| 339 | /* If we got no inode we are out of memory */ |
| 340 | return ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 342 | if (inode->i_state & I_NEW) { |
| 343 | XFS_STATS_INC(vn_active); |
| 344 | XFS_STATS_INC(vn_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 346 | error = xfs_iget_core(inode, mp, tp, ino, flags, |
| 347 | lock_flags, ipp, bno); |
| 348 | if (error) { |
| 349 | make_bad_inode(inode); |
| 350 | if (inode->i_state & I_NEW) |
| 351 | unlock_new_inode(inode); |
| 352 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 354 | return error; |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 357 | /* |
| 358 | * If the inode is not fully constructed due to |
| 359 | * filehandle mismatches wait for the inode to go |
| 360 | * away and try again. |
| 361 | * |
| 362 | * iget_locked will call __wait_on_freeing_inode |
| 363 | * to wait for the inode to go away. |
| 364 | */ |
| 365 | if (is_bad_inode(inode)) { |
| 366 | iput(inode); |
| 367 | delay(1); |
| 368 | goto retry; |
| 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 371 | ip = XFS_I(inode); |
| 372 | if (!ip) { |
| 373 | iput(inode); |
| 374 | delay(1); |
| 375 | goto retry; |
| 376 | } |
| 377 | |
| 378 | if (lock_flags != 0) |
| 379 | xfs_ilock(ip, lock_flags); |
| 380 | XFS_STATS_INC(xs_ig_found); |
| 381 | *ipp = ip; |
| 382 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* |
| 386 | * Look for the inode corresponding to the given ino in the hash table. |
| 387 | * If it is there and its i_transp pointer matches tp, return it. |
| 388 | * Otherwise, return NULL. |
| 389 | */ |
| 390 | xfs_inode_t * |
| 391 | xfs_inode_incore(xfs_mount_t *mp, |
| 392 | xfs_ino_t ino, |
| 393 | xfs_trans_t *tp) |
| 394 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | xfs_inode_t *ip; |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 396 | xfs_perag_t *pag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 398 | pag = xfs_get_perag(mp, ino); |
| 399 | read_lock(&pag->pag_ici_lock); |
| 400 | ip = radix_tree_lookup(&pag->pag_ici_root, XFS_INO_TO_AGINO(mp, ino)); |
| 401 | read_unlock(&pag->pag_ici_lock); |
| 402 | xfs_put_perag(mp, pag); |
| 403 | |
| 404 | /* the returned inode must match the transaction */ |
| 405 | if (ip && (ip->i_transp != tp)) |
| 406 | return NULL; |
| 407 | return ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* |
| 411 | * Decrement reference count of an inode structure and unlock it. |
| 412 | * |
| 413 | * ip -- the inode being released |
| 414 | * lock_flags -- this parameter indicates the inode's locks to be |
| 415 | * to be released. See the comment on xfs_iunlock() for a list |
| 416 | * of valid values. |
| 417 | */ |
| 418 | void |
| 419 | xfs_iput(xfs_inode_t *ip, |
| 420 | uint lock_flags) |
| 421 | { |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 422 | xfs_itrace_entry(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | xfs_iunlock(ip, lock_flags); |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 424 | IRELE(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /* |
| 428 | * Special iput for brand-new inodes that are still locked |
| 429 | */ |
| 430 | void |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 431 | xfs_iput_new( |
| 432 | xfs_inode_t *ip, |
| 433 | uint lock_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 435 | struct inode *inode = VFS_I(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 437 | xfs_itrace_entry(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | if ((ip->i_d.di_mode == 0)) { |
David Chinner | 7a18c38 | 2006-11-11 18:04:54 +1100 | [diff] [blame] | 440 | ASSERT(!xfs_iflags_test(ip, XFS_IRECLAIMABLE)); |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 441 | make_bad_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | if (inode->i_state & I_NEW) |
| 444 | unlock_new_inode(inode); |
| 445 | if (lock_flags) |
| 446 | xfs_iunlock(ip, lock_flags); |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 447 | IRELE(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | |
| 451 | /* |
| 452 | * This routine embodies the part of the reclaim code that pulls |
| 453 | * the inode from the inode hash table and the mount structure's |
| 454 | * inode list. |
| 455 | * This should only be called from xfs_reclaim(). |
| 456 | */ |
| 457 | void |
| 458 | xfs_ireclaim(xfs_inode_t *ip) |
| 459 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* |
| 461 | * Remove from old hash list and mount list. |
| 462 | */ |
| 463 | XFS_STATS_INC(xs_ig_reclaims); |
| 464 | |
| 465 | xfs_iextract(ip); |
| 466 | |
| 467 | /* |
David Chinner | a4e4c4f | 2008-10-30 17:16:11 +1100 | [diff] [blame] | 468 | * Here we do a spurious inode lock in order to coordinate with inode |
| 469 | * cache radix tree lookups. This is because the lookup can reference |
| 470 | * the inodes in the cache without taking references. We make that OK |
| 471 | * here by ensuring that we wait until the inode is unlocked after the |
| 472 | * lookup before we go ahead and free it. We get both the ilock and |
| 473 | * the iolock because the code may need to drop the ilock one but will |
| 474 | * still hold the iolock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | */ |
| 476 | xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); |
| 477 | |
| 478 | /* |
| 479 | * Release dquots (and their references) if any. An inode may escape |
| 480 | * xfs_inactive and get here via vn_alloc->vn_reclaim path. |
| 481 | */ |
| 482 | XFS_QM_DQDETACH(ip->i_mount, ip); |
| 483 | |
| 484 | /* |
| 485 | * Pull our behavior descriptor from the vnode chain. |
| 486 | */ |
Christoph Hellwig | 10090be | 2007-10-11 18:11:03 +1000 | [diff] [blame] | 487 | if (ip->i_vnode) { |
| 488 | ip->i_vnode->i_private = NULL; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 489 | ip->i_vnode = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /* |
| 493 | * Free all memory associated with the inode. |
| 494 | */ |
Tim Shimmin | 439b843 | 2006-11-11 18:04:34 +1100 | [diff] [blame] | 495 | xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | xfs_idestroy(ip); |
| 497 | } |
| 498 | |
| 499 | /* |
| 500 | * This routine removes an about-to-be-destroyed inode from |
| 501 | * all of the lists in which it is located with the exception |
| 502 | * of the behavior chain. |
| 503 | */ |
| 504 | void |
| 505 | xfs_iextract( |
| 506 | xfs_inode_t *ip) |
| 507 | { |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 508 | xfs_mount_t *mp = ip->i_mount; |
| 509 | xfs_perag_t *pag = xfs_get_perag(mp, ip->i_ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 511 | write_lock(&pag->pag_ici_lock); |
| 512 | radix_tree_delete(&pag->pag_ici_root, XFS_INO_TO_AGINO(mp, ip->i_ino)); |
| 513 | write_unlock(&pag->pag_ici_lock); |
| 514 | xfs_put_perag(mp, pag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | /* Deal with the deleted inodes list */ |
David Chinner | 6c7699c | 2008-10-30 17:11:29 +1100 | [diff] [blame] | 517 | XFS_MOUNT_ILOCK(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | list_del_init(&ip->i_reclaim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | mp->m_ireclaims++; |
| 520 | XFS_MOUNT_IUNLOCK(mp); |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * This is a wrapper routine around the xfs_ilock() routine |
| 525 | * used to centralize some grungy code. It is used in places |
| 526 | * that wish to lock the inode solely for reading the extents. |
| 527 | * The reason these places can't just call xfs_ilock(SHARED) |
| 528 | * is that the inode lock also guards to bringing in of the |
| 529 | * extents from disk for a file in b-tree format. If the inode |
| 530 | * is in b-tree format, then we need to lock the inode exclusively |
| 531 | * until the extents are read in. Locking it exclusively all |
| 532 | * the time would limit our parallelism unnecessarily, though. |
| 533 | * What we do instead is check to see if the extents have been |
| 534 | * read in yet, and only lock the inode exclusively if they |
| 535 | * have not. |
| 536 | * |
| 537 | * The function returns a value which should be given to the |
| 538 | * corresponding xfs_iunlock_map_shared(). This value is |
| 539 | * the mode in which the lock was actually taken. |
| 540 | */ |
| 541 | uint |
| 542 | xfs_ilock_map_shared( |
| 543 | xfs_inode_t *ip) |
| 544 | { |
| 545 | uint lock_mode; |
| 546 | |
| 547 | if ((ip->i_d.di_format == XFS_DINODE_FMT_BTREE) && |
| 548 | ((ip->i_df.if_flags & XFS_IFEXTENTS) == 0)) { |
| 549 | lock_mode = XFS_ILOCK_EXCL; |
| 550 | } else { |
| 551 | lock_mode = XFS_ILOCK_SHARED; |
| 552 | } |
| 553 | |
| 554 | xfs_ilock(ip, lock_mode); |
| 555 | |
| 556 | return lock_mode; |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * This is simply the unlock routine to go with xfs_ilock_map_shared(). |
| 561 | * All it does is call xfs_iunlock() with the given lock_mode. |
| 562 | */ |
| 563 | void |
| 564 | xfs_iunlock_map_shared( |
| 565 | xfs_inode_t *ip, |
| 566 | unsigned int lock_mode) |
| 567 | { |
| 568 | xfs_iunlock(ip, lock_mode); |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * The xfs inode contains 2 locks: a multi-reader lock called the |
| 573 | * i_iolock and a multi-reader lock called the i_lock. This routine |
| 574 | * allows either or both of the locks to be obtained. |
| 575 | * |
| 576 | * The 2 locks should always be ordered so that the IO lock is |
| 577 | * obtained first in order to prevent deadlock. |
| 578 | * |
| 579 | * ip -- the inode being locked |
| 580 | * lock_flags -- this parameter indicates the inode's locks |
| 581 | * to be locked. It can be: |
| 582 | * XFS_IOLOCK_SHARED, |
| 583 | * XFS_IOLOCK_EXCL, |
| 584 | * XFS_ILOCK_SHARED, |
| 585 | * XFS_ILOCK_EXCL, |
| 586 | * XFS_IOLOCK_SHARED | XFS_ILOCK_SHARED, |
| 587 | * XFS_IOLOCK_SHARED | XFS_ILOCK_EXCL, |
| 588 | * XFS_IOLOCK_EXCL | XFS_ILOCK_SHARED, |
| 589 | * XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL |
| 590 | */ |
| 591 | void |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 592 | xfs_ilock( |
| 593 | xfs_inode_t *ip, |
| 594 | uint lock_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
| 596 | /* |
| 597 | * You can't set both SHARED and EXCL for the same lock, |
| 598 | * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED, |
| 599 | * and XFS_ILOCK_EXCL are valid values to set in lock_flags. |
| 600 | */ |
| 601 | ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) != |
| 602 | (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)); |
| 603 | ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) != |
| 604 | (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 605 | ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 607 | if (lock_flags & XFS_IOLOCK_EXCL) |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 608 | mrupdate_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags)); |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 609 | else if (lock_flags & XFS_IOLOCK_SHARED) |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 610 | mraccess_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags)); |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 611 | |
| 612 | if (lock_flags & XFS_ILOCK_EXCL) |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 613 | mrupdate_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags)); |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 614 | else if (lock_flags & XFS_ILOCK_SHARED) |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 615 | mraccess_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags)); |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | xfs_ilock_trace(ip, 1, lock_flags, (inst_t *)__return_address); |
| 618 | } |
| 619 | |
| 620 | /* |
| 621 | * This is just like xfs_ilock(), except that the caller |
| 622 | * is guaranteed not to sleep. It returns 1 if it gets |
| 623 | * the requested locks and 0 otherwise. If the IO lock is |
| 624 | * obtained but the inode lock cannot be, then the IO lock |
| 625 | * is dropped before returning. |
| 626 | * |
| 627 | * ip -- the inode being locked |
| 628 | * lock_flags -- this parameter indicates the inode's locks to be |
| 629 | * to be locked. See the comment for xfs_ilock() for a list |
| 630 | * of valid values. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | */ |
| 632 | int |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 633 | xfs_ilock_nowait( |
| 634 | xfs_inode_t *ip, |
| 635 | uint lock_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | /* |
| 638 | * You can't set both SHARED and EXCL for the same lock, |
| 639 | * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED, |
| 640 | * and XFS_ILOCK_EXCL are valid values to set in lock_flags. |
| 641 | */ |
| 642 | ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) != |
| 643 | (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)); |
| 644 | ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) != |
| 645 | (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 646 | ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (lock_flags & XFS_IOLOCK_EXCL) { |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 649 | if (!mrtryupdate(&ip->i_iolock)) |
| 650 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } else if (lock_flags & XFS_IOLOCK_SHARED) { |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 652 | if (!mrtryaccess(&ip->i_iolock)) |
| 653 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | if (lock_flags & XFS_ILOCK_EXCL) { |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 656 | if (!mrtryupdate(&ip->i_lock)) |
| 657 | goto out_undo_iolock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } else if (lock_flags & XFS_ILOCK_SHARED) { |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 659 | if (!mrtryaccess(&ip->i_lock)) |
| 660 | goto out_undo_iolock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | xfs_ilock_trace(ip, 2, lock_flags, (inst_t *)__return_address); |
| 663 | return 1; |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 664 | |
| 665 | out_undo_iolock: |
| 666 | if (lock_flags & XFS_IOLOCK_EXCL) |
| 667 | mrunlock_excl(&ip->i_iolock); |
| 668 | else if (lock_flags & XFS_IOLOCK_SHARED) |
| 669 | mrunlock_shared(&ip->i_iolock); |
| 670 | out: |
| 671 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* |
| 675 | * xfs_iunlock() is used to drop the inode locks acquired with |
| 676 | * xfs_ilock() and xfs_ilock_nowait(). The caller must pass |
| 677 | * in the flags given to xfs_ilock() or xfs_ilock_nowait() so |
| 678 | * that we know which locks to drop. |
| 679 | * |
| 680 | * ip -- the inode being unlocked |
| 681 | * lock_flags -- this parameter indicates the inode's locks to be |
| 682 | * to be unlocked. See the comment for xfs_ilock() for a list |
| 683 | * of valid values for this parameter. |
| 684 | * |
| 685 | */ |
| 686 | void |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 687 | xfs_iunlock( |
| 688 | xfs_inode_t *ip, |
| 689 | uint lock_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
| 691 | /* |
| 692 | * You can't set both SHARED and EXCL for the same lock, |
| 693 | * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED, |
| 694 | * and XFS_ILOCK_EXCL are valid values to set in lock_flags. |
| 695 | */ |
| 696 | ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) != |
| 697 | (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)); |
| 698 | ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) != |
| 699 | (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 700 | ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_IUNLOCK_NONOTIFY | |
| 701 | XFS_LOCK_DEP_MASK)) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | ASSERT(lock_flags != 0); |
| 703 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 704 | if (lock_flags & XFS_IOLOCK_EXCL) |
| 705 | mrunlock_excl(&ip->i_iolock); |
| 706 | else if (lock_flags & XFS_IOLOCK_SHARED) |
| 707 | mrunlock_shared(&ip->i_iolock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 709 | if (lock_flags & XFS_ILOCK_EXCL) |
| 710 | mrunlock_excl(&ip->i_lock); |
| 711 | else if (lock_flags & XFS_ILOCK_SHARED) |
| 712 | mrunlock_shared(&ip->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 714 | if ((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) && |
| 715 | !(lock_flags & XFS_IUNLOCK_NONOTIFY) && ip->i_itemp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | /* |
| 717 | * Let the AIL know that this item has been unlocked in case |
| 718 | * it is in the AIL and anyone is waiting on it. Don't do |
| 719 | * this if the caller has asked us not to. |
| 720 | */ |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 721 | xfs_trans_unlocked_item(ip->i_mount, |
| 722 | (xfs_log_item_t*)(ip->i_itemp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | xfs_ilock_trace(ip, 3, lock_flags, (inst_t *)__return_address); |
| 725 | } |
| 726 | |
| 727 | /* |
| 728 | * give up write locks. the i/o lock cannot be held nested |
| 729 | * if it is being demoted. |
| 730 | */ |
| 731 | void |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 732 | xfs_ilock_demote( |
| 733 | xfs_inode_t *ip, |
| 734 | uint lock_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
| 736 | ASSERT(lock_flags & (XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)); |
| 737 | ASSERT((lock_flags & ~(XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)) == 0); |
| 738 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 739 | if (lock_flags & XFS_ILOCK_EXCL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | mrdemote(&ip->i_lock); |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 741 | if (lock_flags & XFS_IOLOCK_EXCL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | mrdemote(&ip->i_iolock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Christoph Hellwig | 579aa9c | 2008-04-22 17:34:00 +1000 | [diff] [blame] | 745 | #ifdef DEBUG |
| 746 | /* |
| 747 | * Debug-only routine, without additional rw_semaphore APIs, we can |
| 748 | * now only answer requests regarding whether we hold the lock for write |
| 749 | * (reader state is outside our visibility, we only track writer state). |
| 750 | * |
| 751 | * Note: this means !xfs_isilocked would give false positives, so don't do that. |
| 752 | */ |
| 753 | int |
| 754 | xfs_isilocked( |
| 755 | xfs_inode_t *ip, |
| 756 | uint lock_flags) |
| 757 | { |
| 758 | if ((lock_flags & (XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)) == |
| 759 | XFS_ILOCK_EXCL) { |
| 760 | if (!ip->i_lock.mr_writer) |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | if ((lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) == |
| 765 | XFS_IOLOCK_EXCL) { |
| 766 | if (!ip->i_iolock.mr_writer) |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | return 1; |
| 771 | } |
| 772 | #endif |
| 773 | |