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