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