2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #include "xfs_macros.h"
36 #include "xfs_types.h"
39 #include "xfs_trans.h"
44 #include "xfs_dmapi.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_btree.h"
50 #include "xfs_ialloc.h"
51 #include "xfs_attr_sf.h"
52 #include "xfs_dir_sf.h"
53 #include "xfs_dir2_sf.h"
54 #include "xfs_dinode.h"
55 #include "xfs_inode.h"
56 #include "xfs_quota.h"
57 #include "xfs_utils.h"
60 * Initialize the inode hash table for the newly mounted file system.
62 * mp -- this is the mount point structure for the file system being
66 xfs_ihash_init(xfs_mount_t *mp)
70 mp->m_ihsize = XFS_BUCKETS(mp);
71 mp->m_ihash = (xfs_ihash_t *)kmem_zalloc(mp->m_ihsize
72 * sizeof(xfs_ihash_t), KM_SLEEP);
73 ASSERT(mp->m_ihash != NULL);
74 for (i = 0; i < mp->m_ihsize; i++) {
75 rwlock_init(&(mp->m_ihash[i].ih_lock));
80 * Free up structures allocated by xfs_ihash_init, at unmount time.
83 xfs_ihash_free(xfs_mount_t *mp)
85 kmem_free(mp->m_ihash, mp->m_ihsize*sizeof(xfs_ihash_t));
90 * Initialize the inode cluster hash table for the newly mounted file system.
92 * mp -- this is the mount point structure for the file system being
96 xfs_chash_init(xfs_mount_t *mp)
101 * m_chash size is based on m_ihash
102 * with a minimum of 37 entries
104 mp->m_chsize = (XFS_BUCKETS(mp)) /
105 (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog);
106 if (mp->m_chsize < 37) {
109 mp->m_chash = (xfs_chash_t *)kmem_zalloc(mp->m_chsize
110 * sizeof(xfs_chash_t),
112 ASSERT(mp->m_chash != NULL);
114 for (i = 0; i < mp->m_chsize; i++) {
115 spinlock_init(&mp->m_chash[i].ch_lock,"xfshash");
120 * Free up structures allocated by xfs_chash_init, at unmount time.
123 xfs_chash_free(xfs_mount_t *mp)
127 for (i = 0; i < mp->m_chsize; i++) {
128 spinlock_destroy(&mp->m_chash[i].ch_lock);
131 kmem_free(mp->m_chash, mp->m_chsize*sizeof(xfs_chash_t));
136 * Look up an inode by number in the given file system.
137 * The inode is looked up in the hash table for the file system
138 * represented by the mount point parameter mp. Each bucket of
139 * the hash table is guarded by an individual semaphore.
141 * If the inode is found in the hash table, its corresponding vnode
142 * is obtained with a call to vn_get(). This call takes care of
143 * coordination with the reclamation of the inode and vnode. Note
144 * that the vmap structure is filled in while holding the hash lock.
145 * This gives us the state of the inode/vnode when we found it and
146 * is used for coordination in vn_get().
148 * If it is not in core, read it in from the file system's device and
149 * add the inode into the hash table.
151 * The inode is locked according to the value of the lock_flags parameter.
152 * This flag parameter indicates how and if the inode's IO lock and inode lock
155 * mp -- the mount point structure for the current file system. It points
156 * to the inode hash table.
157 * tp -- a pointer to the current transaction if there is one. This is
158 * simply passed through to the xfs_iread() call.
159 * ino -- the number of the inode desired. This is the unique identifier
160 * within the file system for the inode being requested.
161 * lock_flags -- flags indicating how to lock the inode. See the comment
162 * for xfs_ilock() for a list of valid values.
163 * bno -- the block number starting the buffer containing the inode,
164 * if known (as by bulkstat), else 0.
185 xfs_chashlist_t *chl, *chlnew;
189 ih = XFS_IHASH(mp, ino);
192 read_lock(&ih->ih_lock);
194 for (ip = ih->ih_next; ip != NULL; ip = ip->i_next) {
195 if (ip->i_ino == ino) {
197 * If INEW is set this inode is being set up
198 * we need to pause and try again.
200 if (ip->i_flags & XFS_INEW) {
201 read_unlock(&ih->ih_lock);
203 XFS_STATS_INC(xs_ig_frecycle);
208 inode_vp = XFS_ITOV_NULL(ip);
209 if (inode_vp == NULL) {
211 * If IRECLAIM is set this inode is
212 * on its way out of the system,
213 * we need to pause and try again.
215 if (ip->i_flags & XFS_IRECLAIM) {
216 read_unlock(&ih->ih_lock);
218 XFS_STATS_INC(xs_ig_frecycle);
223 vn_trace_exit(vp, "xfs_iget.alloc",
224 (inst_t *)__return_address);
226 XFS_STATS_INC(xs_ig_found);
228 ip->i_flags &= ~XFS_IRECLAIMABLE;
229 read_unlock(&ih->ih_lock);
232 list_del_init(&ip->i_reclaim);
233 XFS_MOUNT_IUNLOCK(mp);
237 } else if (vp != inode_vp) {
238 struct inode *inode = LINVFS_GET_IP(inode_vp);
240 /* The inode is being torn down, pause and
243 if (inode->i_state & (I_FREEING | I_CLEAR)) {
244 read_unlock(&ih->ih_lock);
246 XFS_STATS_INC(xs_ig_frecycle);
250 /* Chances are the other vnode (the one in the inode) is being torn
251 * down right now, and we landed on top of it. Question is, what do
252 * we do? Unhook the old inode and hook up the new one?
255 "xfs_iget_core: ambiguous vns: vp/0x%p, invp/0x%p",
259 read_unlock(&ih->ih_lock);
261 XFS_STATS_INC(xs_ig_found);
264 if (ip->i_d.di_mode == 0) {
265 if (!(flags & IGET_CREATE))
267 xfs_iocore_inode_reinit(ip);
271 xfs_ilock(ip, lock_flags);
273 ip->i_flags &= ~XFS_ISTALE;
275 vn_trace_exit(vp, "xfs_iget.found",
276 (inst_t *)__return_address);
282 * Inode cache miss: save the hash chain version stamp and unlock
283 * the chain, so we don't deadlock in vn_alloc.
285 XFS_STATS_INC(xs_ig_missed);
287 version = ih->ih_version;
289 read_unlock(&ih->ih_lock);
292 * Read the disk inode attributes into a new inode structure and get
293 * a new vnode for it. This should also initialize i_ino and i_mount.
295 error = xfs_iread(mp, tp, ino, &ip, bno);
300 vn_trace_exit(vp, "xfs_iget.alloc", (inst_t *)__return_address);
302 xfs_inode_lock_init(ip, vp);
303 xfs_iocore_inode_init(ip);
305 if (lock_flags != 0) {
306 xfs_ilock(ip, lock_flags);
309 if ((ip->i_d.di_mode == 0) && !(flags & IGET_CREATE)) {
315 * Put ip on its hash chain, unless someone else hashed a duplicate
316 * after we released the hash lock.
318 write_lock(&ih->ih_lock);
320 if (ih->ih_version != version) {
321 for (iq = ih->ih_next; iq != NULL; iq = iq->i_next) {
322 if (iq->i_ino == ino) {
323 write_unlock(&ih->ih_lock);
326 XFS_STATS_INC(xs_ig_dup);
333 * These values _must_ be set before releasing ihlock!
336 if ((iq = ih->ih_next)) {
337 iq->i_prevp = &ip->i_next;
340 ip->i_prevp = &ih->ih_next;
342 ip->i_udquot = ip->i_gdquot = NULL;
344 ip->i_flags |= XFS_INEW;
346 write_unlock(&ih->ih_lock);
349 * put ip on its cluster's hash chain
351 ASSERT(ip->i_chash == NULL && ip->i_cprev == NULL &&
352 ip->i_cnext == NULL);
355 ch = XFS_CHASH(mp, ip->i_blkno);
357 s = mutex_spinlock(&ch->ch_lock);
358 for (chl = ch->ch_list; chl != NULL; chl = chl->chl_next) {
359 if (chl->chl_blkno == ip->i_blkno) {
361 /* insert this inode into the doubly-linked list
362 * where chl points */
363 if ((iq = chl->chl_ip)) {
364 ip->i_cprev = iq->i_cprev;
365 iq->i_cprev->i_cnext = ip;
378 /* no hash list found for this block; add a new hash list */
380 if (chlnew == NULL) {
381 mutex_spinunlock(&ch->ch_lock, s);
382 ASSERT(xfs_chashlist_zone != NULL);
383 chlnew = (xfs_chashlist_t *)
384 kmem_zone_alloc(xfs_chashlist_zone,
386 ASSERT(chlnew != NULL);
391 ip->i_chash = chlnew;
393 chlnew->chl_blkno = ip->i_blkno;
394 chlnew->chl_next = ch->ch_list;
395 ch->ch_list = chlnew;
399 if (chlnew != NULL) {
400 kmem_zone_free(xfs_chashlist_zone, chlnew);
404 mutex_spinunlock(&ch->ch_lock, s);
408 * Link ip to its mount and thread it on the mount's inode list.
411 if ((iq = mp->m_inodes)) {
412 ASSERT(iq->i_mprev->i_mnext == iq);
413 ip->i_mprev = iq->i_mprev;
414 iq->i_mprev->i_mnext = ip;
423 XFS_MOUNT_IUNLOCK(mp);
426 ASSERT(ip->i_df.if_ext_max ==
427 XFS_IFORK_DSIZE(ip) / sizeof(xfs_bmbt_rec_t));
429 ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
430 ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
435 * If we have a real type for an on-disk inode, we can set ops(&unlock)
436 * now. If it's a new inode being created, xfs_ialloc will handle it.
438 VFS_INIT_VNODE(XFS_MTOVFS(mp), vp, XFS_ITOBHV(ip), 1);
445 * The 'normal' internal xfs_iget, if needed it will
446 * 'allocate', or 'get', the vnode.
463 XFS_STATS_INC(xs_ig_attempts);
465 if ((inode = iget_locked(XFS_MTOVFS(mp)->vfs_super, ino))) {
470 vp = LINVFS_GET_VP(inode);
471 if (inode->i_state & I_NEW) {
473 vn_initialize(inode);
474 error = xfs_iget_core(vp, mp, tp, ino, flags,
475 lock_flags, ipp, bno);
478 if (inode->i_state & I_NEW)
479 unlock_new_inode(inode);
483 /* These are true if the inode is in inactive or
484 * reclaim. The linux inode is about to go away,
485 * wait for that path to finish, and try again.
487 if (vp->v_flag & (VINACT | VRECLM)) {
493 bdp = vn_bhv_lookup(VN_BHV_HEAD(vp), &xfs_vnodeops);
495 XFS_STATS_INC(xs_ig_dup);
498 ip = XFS_BHVTOI(bdp);
500 xfs_ilock(ip, lock_flags);
501 newnode = (ip->i_d.di_mode == 0);
503 xfs_iocore_inode_reinit(ip);
504 XFS_STATS_INC(xs_ig_found);
509 error = ENOMEM; /* If we got no inode we are out of memory */
515 * Do the setup for the various locks within the incore inode.
522 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
523 "xfsino", (long)vp->v_number);
524 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", vp->v_number);
525 init_waitqueue_head(&ip->i_ipin_wait);
526 atomic_set(&ip->i_pincount, 0);
527 init_sema(&ip->i_flock, 1, "xfsfino", vp->v_number);
531 * Look for the inode corresponding to the given ino in the hash table.
532 * If it is there and its i_transp pointer matches tp, return it.
533 * Otherwise, return NULL.
536 xfs_inode_incore(xfs_mount_t *mp,
543 ih = XFS_IHASH(mp, ino);
544 read_lock(&ih->ih_lock);
545 for (ip = ih->ih_next; ip != NULL; ip = ip->i_next) {
546 if (ip->i_ino == ino) {
548 * If we find it and tp matches, return it.
549 * Otherwise break from the loop and return
552 if (ip->i_transp == tp) {
553 read_unlock(&ih->ih_lock);
559 read_unlock(&ih->ih_lock);
564 * Decrement reference count of an inode structure and unlock it.
566 * ip -- the inode being released
567 * lock_flags -- this parameter indicates the inode's locks to be
568 * to be released. See the comment on xfs_iunlock() for a list
572 xfs_iput(xfs_inode_t *ip,
575 vnode_t *vp = XFS_ITOV(ip);
577 vn_trace_entry(vp, "xfs_iput", (inst_t *)__return_address);
579 xfs_iunlock(ip, lock_flags);
585 * Special iput for brand-new inodes that are still locked
588 xfs_iput_new(xfs_inode_t *ip,
591 vnode_t *vp = XFS_ITOV(ip);
592 struct inode *inode = LINVFS_GET_IP(vp);
594 vn_trace_entry(vp, "xfs_iput_new", (inst_t *)__return_address);
596 if ((ip->i_d.di_mode == 0)) {
597 ASSERT(!(ip->i_flags & XFS_IRECLAIMABLE));
600 if (inode->i_state & I_NEW)
601 unlock_new_inode(inode);
603 xfs_iunlock(ip, lock_flags);
609 * This routine embodies the part of the reclaim code that pulls
610 * the inode from the inode hash table and the mount structure's
612 * This should only be called from xfs_reclaim().
615 xfs_ireclaim(xfs_inode_t *ip)
620 * Remove from old hash list and mount list.
622 XFS_STATS_INC(xs_ig_reclaims);
627 * Here we do a spurious inode lock in order to coordinate with
628 * xfs_sync(). This is because xfs_sync() references the inodes
629 * in the mount list without taking references on the corresponding
630 * vnodes. We make that OK here by ensuring that we wait until
631 * the inode is unlocked in xfs_sync() before we go ahead and
632 * free it. We get both the regular lock and the io lock because
633 * the xfs_sync() code may need to drop the regular one but will
634 * still hold the io lock.
636 xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
639 * Release dquots (and their references) if any. An inode may escape
640 * xfs_inactive and get here via vn_alloc->vn_reclaim path.
642 XFS_QM_DQDETACH(ip->i_mount, ip);
645 * Pull our behavior descriptor from the vnode chain.
647 vp = XFS_ITOV_NULL(ip);
649 vn_bhv_remove(VN_BHV_HEAD(vp), XFS_ITOBHV(ip));
653 * Free all memory associated with the inode.
659 * This routine removes an about-to-be-destroyed inode from
660 * all of the lists in which it is located with the exception
661 * of the behavior chain.
671 xfs_chashlist_t *chl, *chm;
675 write_lock(&ih->ih_lock);
676 if ((iq = ip->i_next)) {
677 iq->i_prevp = ip->i_prevp;
680 write_unlock(&ih->ih_lock);
683 * Remove from cluster hash list
684 * 1) delete the chashlist if this is the last inode on the chashlist
685 * 2) unchain from list of inodes
686 * 3) point chashlist->chl_ip to 'chl_next' if to this inode.
689 ch = XFS_CHASH(mp, ip->i_blkno);
690 s = mutex_spinlock(&ch->ch_lock);
692 if (ip->i_cnext == ip) {
693 /* Last inode on chashlist */
694 ASSERT(ip->i_cnext == ip && ip->i_cprev == ip);
695 ASSERT(ip->i_chash != NULL);
697 for (chl = ch->ch_list; chl != NULL; chl = chl->chl_next) {
698 if (chl->chl_blkno == ip->i_blkno) {
700 /* first item on the list */
701 ch->ch_list = chl->chl_next;
703 chm->chl_next = chl->chl_next;
705 kmem_zone_free(xfs_chashlist_zone, chl);
708 ASSERT(chl->chl_ip != ip);
712 ASSERT_ALWAYS(chl != NULL);
714 /* delete one inode from a non-empty list */
716 iq->i_cprev = ip->i_cprev;
717 ip->i_cprev->i_cnext = iq;
718 if (ip->i_chash->chl_ip == ip) {
719 ip->i_chash->chl_ip = iq;
721 ip->i_chash = __return_address;
722 ip->i_cprev = __return_address;
723 ip->i_cnext = __return_address;
725 mutex_spinunlock(&ch->ch_lock, s);
728 * Remove from mount's inode list.
731 ASSERT((ip->i_mnext != NULL) && (ip->i_mprev != NULL));
733 iq->i_mprev = ip->i_mprev;
734 ip->i_mprev->i_mnext = iq;
737 * Fix up the head pointer if it points to the inode being deleted.
739 if (mp->m_inodes == ip) {
747 /* Deal with the deleted inodes list */
748 list_del_init(&ip->i_reclaim);
751 XFS_MOUNT_IUNLOCK(mp);
755 * This is a wrapper routine around the xfs_ilock() routine
756 * used to centralize some grungy code. It is used in places
757 * that wish to lock the inode solely for reading the extents.
758 * The reason these places can't just call xfs_ilock(SHARED)
759 * is that the inode lock also guards to bringing in of the
760 * extents from disk for a file in b-tree format. If the inode
761 * is in b-tree format, then we need to lock the inode exclusively
762 * until the extents are read in. Locking it exclusively all
763 * the time would limit our parallelism unnecessarily, though.
764 * What we do instead is check to see if the extents have been
765 * read in yet, and only lock the inode exclusively if they
768 * The function returns a value which should be given to the
769 * corresponding xfs_iunlock_map_shared(). This value is
770 * the mode in which the lock was actually taken.
773 xfs_ilock_map_shared(
778 if ((ip->i_d.di_format == XFS_DINODE_FMT_BTREE) &&
779 ((ip->i_df.if_flags & XFS_IFEXTENTS) == 0)) {
780 lock_mode = XFS_ILOCK_EXCL;
782 lock_mode = XFS_ILOCK_SHARED;
785 xfs_ilock(ip, lock_mode);
791 * This is simply the unlock routine to go with xfs_ilock_map_shared().
792 * All it does is call xfs_iunlock() with the given lock_mode.
795 xfs_iunlock_map_shared(
797 unsigned int lock_mode)
799 xfs_iunlock(ip, lock_mode);
803 * The xfs inode contains 2 locks: a multi-reader lock called the
804 * i_iolock and a multi-reader lock called the i_lock. This routine
805 * allows either or both of the locks to be obtained.
807 * The 2 locks should always be ordered so that the IO lock is
808 * obtained first in order to prevent deadlock.
810 * ip -- the inode being locked
811 * lock_flags -- this parameter indicates the inode's locks
812 * to be locked. It can be:
817 * XFS_IOLOCK_SHARED | XFS_ILOCK_SHARED,
818 * XFS_IOLOCK_SHARED | XFS_ILOCK_EXCL,
819 * XFS_IOLOCK_EXCL | XFS_ILOCK_SHARED,
820 * XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL
823 xfs_ilock(xfs_inode_t *ip,
827 * You can't set both SHARED and EXCL for the same lock,
828 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
829 * and XFS_ILOCK_EXCL are valid values to set in lock_flags.
831 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
832 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
833 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
834 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
835 ASSERT((lock_flags & ~XFS_LOCK_MASK) == 0);
837 if (lock_flags & XFS_IOLOCK_EXCL) {
838 mrupdate(&ip->i_iolock);
839 } else if (lock_flags & XFS_IOLOCK_SHARED) {
840 mraccess(&ip->i_iolock);
842 if (lock_flags & XFS_ILOCK_EXCL) {
843 mrupdate(&ip->i_lock);
844 } else if (lock_flags & XFS_ILOCK_SHARED) {
845 mraccess(&ip->i_lock);
847 xfs_ilock_trace(ip, 1, lock_flags, (inst_t *)__return_address);
851 * This is just like xfs_ilock(), except that the caller
852 * is guaranteed not to sleep. It returns 1 if it gets
853 * the requested locks and 0 otherwise. If the IO lock is
854 * obtained but the inode lock cannot be, then the IO lock
855 * is dropped before returning.
857 * ip -- the inode being locked
858 * lock_flags -- this parameter indicates the inode's locks to be
859 * to be locked. See the comment for xfs_ilock() for a list
864 xfs_ilock_nowait(xfs_inode_t *ip,
871 * You can't set both SHARED and EXCL for the same lock,
872 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
873 * and XFS_ILOCK_EXCL are valid values to set in lock_flags.
875 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
876 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
877 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
878 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
879 ASSERT((lock_flags & ~XFS_LOCK_MASK) == 0);
882 if (lock_flags & XFS_IOLOCK_EXCL) {
883 iolocked = mrtryupdate(&ip->i_iolock);
887 } else if (lock_flags & XFS_IOLOCK_SHARED) {
888 iolocked = mrtryaccess(&ip->i_iolock);
893 if (lock_flags & XFS_ILOCK_EXCL) {
894 ilocked = mrtryupdate(&ip->i_lock);
897 mrunlock(&ip->i_iolock);
901 } else if (lock_flags & XFS_ILOCK_SHARED) {
902 ilocked = mrtryaccess(&ip->i_lock);
905 mrunlock(&ip->i_iolock);
910 xfs_ilock_trace(ip, 2, lock_flags, (inst_t *)__return_address);
915 * xfs_iunlock() is used to drop the inode locks acquired with
916 * xfs_ilock() and xfs_ilock_nowait(). The caller must pass
917 * in the flags given to xfs_ilock() or xfs_ilock_nowait() so
918 * that we know which locks to drop.
920 * ip -- the inode being unlocked
921 * lock_flags -- this parameter indicates the inode's locks to be
922 * to be unlocked. See the comment for xfs_ilock() for a list
923 * of valid values for this parameter.
927 xfs_iunlock(xfs_inode_t *ip,
931 * You can't set both SHARED and EXCL for the same lock,
932 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
933 * and XFS_ILOCK_EXCL are valid values to set in lock_flags.
935 ASSERT((lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) !=
936 (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
937 ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
938 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
939 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_IUNLOCK_NONOTIFY)) == 0);
940 ASSERT(lock_flags != 0);
942 if (lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) {
943 ASSERT(!(lock_flags & XFS_IOLOCK_SHARED) ||
944 (ismrlocked(&ip->i_iolock, MR_ACCESS)));
945 ASSERT(!(lock_flags & XFS_IOLOCK_EXCL) ||
946 (ismrlocked(&ip->i_iolock, MR_UPDATE)));
947 mrunlock(&ip->i_iolock);
950 if (lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) {
951 ASSERT(!(lock_flags & XFS_ILOCK_SHARED) ||
952 (ismrlocked(&ip->i_lock, MR_ACCESS)));
953 ASSERT(!(lock_flags & XFS_ILOCK_EXCL) ||
954 (ismrlocked(&ip->i_lock, MR_UPDATE)));
955 mrunlock(&ip->i_lock);
958 * Let the AIL know that this item has been unlocked in case
959 * it is in the AIL and anyone is waiting on it. Don't do
960 * this if the caller has asked us not to.
962 if (!(lock_flags & XFS_IUNLOCK_NONOTIFY) &&
963 ip->i_itemp != NULL) {
964 xfs_trans_unlocked_item(ip->i_mount,
965 (xfs_log_item_t*)(ip->i_itemp));
968 xfs_ilock_trace(ip, 3, lock_flags, (inst_t *)__return_address);
972 * give up write locks. the i/o lock cannot be held nested
973 * if it is being demoted.
976 xfs_ilock_demote(xfs_inode_t *ip,
979 ASSERT(lock_flags & (XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL));
980 ASSERT((lock_flags & ~(XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)) == 0);
982 if (lock_flags & XFS_ILOCK_EXCL) {
983 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
984 mrdemote(&ip->i_lock);
986 if (lock_flags & XFS_IOLOCK_EXCL) {
987 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
988 mrdemote(&ip->i_iolock);
993 * The following three routines simply manage the i_flock
994 * semaphore embedded in the inode. This semaphore synchronizes
995 * processes attempting to flush the in-core inode back to disk.
998 xfs_iflock(xfs_inode_t *ip)
1000 psema(&(ip->i_flock), PINOD|PLTWAIT);
1004 xfs_iflock_nowait(xfs_inode_t *ip)
1006 return (cpsema(&(ip->i_flock)));
1010 xfs_ifunlock(xfs_inode_t *ip)
1012 ASSERT(valusema(&(ip->i_flock)) <= 0);
1013 vsema(&(ip->i_flock));