f925335e4553ae93fad266e3880abad1863b753c
2 * Copyright (c) 2000-2005 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/
34 #include "xfs_types.h"
38 #include "xfs_trans.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_mount.h"
45 #include "xfs_bmap_btree.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_dir_sf.h"
49 #include "xfs_dir2_sf.h"
50 #include "xfs_attr_sf.h"
51 #include "xfs_dinode.h"
52 #include "xfs_inode.h"
53 #include "xfs_btree.h"
54 #include "xfs_ialloc.h"
55 #include "xfs_quota.h"
56 #include "xfs_utils.h"
59 * Initialize the inode hash table for the newly mounted file system.
60 * Choose an initial table size based on user specified value, else
61 * use a simple algorithm using the maximum number of inodes as an
62 * indicator for table size, and clamp it between one and some large
66 xfs_ihash_init(xfs_mount_t
*mp
)
69 uint i
, flags
= KM_SLEEP
| KM_MAYFAIL
;
72 icount
= mp
->m_maxicount
? mp
->m_maxicount
:
73 (mp
->m_sb
.sb_dblocks
<< mp
->m_sb
.sb_inopblog
);
74 mp
->m_ihsize
= 1 << max_t(uint
, 8,
75 (xfs_highbit64(icount
) + 1) / 2);
76 mp
->m_ihsize
= min_t(uint
, mp
->m_ihsize
,
77 (64 * NBPP
) / sizeof(xfs_ihash_t
));
80 while (!(mp
->m_ihash
= (xfs_ihash_t
*)kmem_zalloc(mp
->m_ihsize
*
81 sizeof(xfs_ihash_t
), flags
))) {
82 if ((mp
->m_ihsize
>>= 1) <= NBPP
)
85 for (i
= 0; i
< mp
->m_ihsize
; i
++) {
86 rwlock_init(&(mp
->m_ihash
[i
].ih_lock
));
91 * Free up structures allocated by xfs_ihash_init, at unmount time.
94 xfs_ihash_free(xfs_mount_t
*mp
)
96 kmem_free(mp
->m_ihash
, mp
->m_ihsize
*sizeof(xfs_ihash_t
));
101 * Initialize the inode cluster hash table for the newly mounted file system.
102 * Its size is derived from the ihash table size.
105 xfs_chash_init(xfs_mount_t
*mp
)
109 mp
->m_chsize
= max_t(uint
, 1, mp
->m_ihsize
/
110 (XFS_INODE_CLUSTER_SIZE(mp
) >> mp
->m_sb
.sb_inodelog
));
111 mp
->m_chsize
= min_t(uint
, mp
->m_chsize
, mp
->m_ihsize
);
112 mp
->m_chash
= (xfs_chash_t
*)kmem_zalloc(mp
->m_chsize
113 * sizeof(xfs_chash_t
),
115 for (i
= 0; i
< mp
->m_chsize
; i
++) {
116 spinlock_init(&mp
->m_chash
[i
].ch_lock
,"xfshash");
121 * Free up structures allocated by xfs_chash_init, at unmount time.
124 xfs_chash_free(xfs_mount_t
*mp
)
128 for (i
= 0; i
< mp
->m_chsize
; i
++) {
129 spinlock_destroy(&mp
->m_chash
[i
].ch_lock
);
132 kmem_free(mp
->m_chash
, mp
->m_chsize
*sizeof(xfs_chash_t
));
137 * Try to move an inode to the front of its hash list if possible
138 * (and if its not there already). Called right after obtaining
139 * the list version number and then dropping the read_lock on the
140 * hash list in question (which is done right after looking up the
141 * inode in question...).
151 if ((ip
->i_prevp
!= &ih
->ih_next
) && write_trylock(&ih
->ih_lock
)) {
152 if (likely(version
== ih
->ih_version
)) {
153 /* remove from list */
154 if ((iq
= ip
->i_next
)) {
155 iq
->i_prevp
= ip
->i_prevp
;
159 /* insert at list head */
161 iq
->i_prevp
= &ip
->i_next
;
163 ip
->i_prevp
= &ih
->ih_next
;
166 write_unlock(&ih
->ih_lock
);
171 * Look up an inode by number in the given file system.
172 * The inode is looked up in the hash table for the file system
173 * represented by the mount point parameter mp. Each bucket of
174 * the hash table is guarded by an individual semaphore.
176 * If the inode is found in the hash table, its corresponding vnode
177 * is obtained with a call to vn_get(). This call takes care of
178 * coordination with the reclamation of the inode and vnode. Note
179 * that the vmap structure is filled in while holding the hash lock.
180 * This gives us the state of the inode/vnode when we found it and
181 * is used for coordination in vn_get().
183 * If it is not in core, read it in from the file system's device and
184 * add the inode into the hash table.
186 * The inode is locked according to the value of the lock_flags parameter.
187 * This flag parameter indicates how and if the inode's IO lock and inode lock
190 * mp -- the mount point structure for the current file system. It points
191 * to the inode hash table.
192 * tp -- a pointer to the current transaction if there is one. This is
193 * simply passed through to the xfs_iread() call.
194 * ino -- the number of the inode desired. This is the unique identifier
195 * within the file system for the inode being requested.
196 * lock_flags -- flags indicating how to lock the inode. See the comment
197 * for xfs_ilock() for a list of valid values.
198 * bno -- the block number starting the buffer containing the inode,
199 * if known (as by bulkstat), else 0.
220 xfs_chashlist_t
*chl
, *chlnew
;
224 ih
= XFS_IHASH(mp
, ino
);
227 read_lock(&ih
->ih_lock
);
229 for (ip
= ih
->ih_next
; ip
!= NULL
; ip
= ip
->i_next
) {
230 if (ip
->i_ino
== ino
) {
232 * If INEW is set this inode is being set up
233 * we need to pause and try again.
235 if (ip
->i_flags
& XFS_INEW
) {
236 read_unlock(&ih
->ih_lock
);
238 XFS_STATS_INC(xs_ig_frecycle
);
243 inode_vp
= XFS_ITOV_NULL(ip
);
244 if (inode_vp
== NULL
) {
246 * If IRECLAIM is set this inode is
247 * on its way out of the system,
248 * we need to pause and try again.
250 if (ip
->i_flags
& XFS_IRECLAIM
) {
251 read_unlock(&ih
->ih_lock
);
253 XFS_STATS_INC(xs_ig_frecycle
);
258 vn_trace_exit(vp
, "xfs_iget.alloc",
259 (inst_t
*)__return_address
);
261 XFS_STATS_INC(xs_ig_found
);
263 ip
->i_flags
&= ~XFS_IRECLAIMABLE
;
264 version
= ih
->ih_version
;
265 read_unlock(&ih
->ih_lock
);
266 xfs_ihash_promote(ih
, ip
, version
);
269 list_del_init(&ip
->i_reclaim
);
270 XFS_MOUNT_IUNLOCK(mp
);
274 } else if (vp
!= inode_vp
) {
275 struct inode
*inode
= LINVFS_GET_IP(inode_vp
);
277 /* The inode is being torn down, pause and
280 if (inode
->i_state
& (I_FREEING
| I_CLEAR
)) {
281 read_unlock(&ih
->ih_lock
);
283 XFS_STATS_INC(xs_ig_frecycle
);
287 /* Chances are the other vnode (the one in the inode) is being torn
288 * down right now, and we landed on top of it. Question is, what do
289 * we do? Unhook the old inode and hook up the new one?
292 "xfs_iget_core: ambiguous vns: vp/0x%p, invp/0x%p",
297 * Inode cache hit: if ip is not at the front of
298 * its hash chain, move it there now.
299 * Do this with the lock held for update, but
300 * do statistics after releasing the lock.
302 version
= ih
->ih_version
;
303 read_unlock(&ih
->ih_lock
);
304 xfs_ihash_promote(ih
, ip
, version
);
305 XFS_STATS_INC(xs_ig_found
);
308 if (ip
->i_d
.di_mode
== 0) {
309 if (!(flags
& IGET_CREATE
))
311 xfs_iocore_inode_reinit(ip
);
315 xfs_ilock(ip
, lock_flags
);
317 ip
->i_flags
&= ~XFS_ISTALE
;
319 vn_trace_exit(vp
, "xfs_iget.found",
320 (inst_t
*)__return_address
);
326 * Inode cache miss: save the hash chain version stamp and unlock
327 * the chain, so we don't deadlock in vn_alloc.
329 XFS_STATS_INC(xs_ig_missed
);
331 version
= ih
->ih_version
;
333 read_unlock(&ih
->ih_lock
);
336 * Read the disk inode attributes into a new inode structure and get
337 * a new vnode for it. This should also initialize i_ino and i_mount.
339 error
= xfs_iread(mp
, tp
, ino
, &ip
, bno
);
344 vn_trace_exit(vp
, "xfs_iget.alloc", (inst_t
*)__return_address
);
346 xfs_inode_lock_init(ip
, vp
);
347 xfs_iocore_inode_init(ip
);
349 if (lock_flags
!= 0) {
350 xfs_ilock(ip
, lock_flags
);
353 if ((ip
->i_d
.di_mode
== 0) && !(flags
& IGET_CREATE
)) {
359 * Put ip on its hash chain, unless someone else hashed a duplicate
360 * after we released the hash lock.
362 write_lock(&ih
->ih_lock
);
364 if (ih
->ih_version
!= version
) {
365 for (iq
= ih
->ih_next
; iq
!= NULL
; iq
= iq
->i_next
) {
366 if (iq
->i_ino
== ino
) {
367 write_unlock(&ih
->ih_lock
);
370 XFS_STATS_INC(xs_ig_dup
);
377 * These values _must_ be set before releasing ihlock!
380 if ((iq
= ih
->ih_next
)) {
381 iq
->i_prevp
= &ip
->i_next
;
384 ip
->i_prevp
= &ih
->ih_next
;
386 ip
->i_udquot
= ip
->i_gdquot
= NULL
;
388 ip
->i_flags
|= XFS_INEW
;
390 write_unlock(&ih
->ih_lock
);
393 * put ip on its cluster's hash chain
395 ASSERT(ip
->i_chash
== NULL
&& ip
->i_cprev
== NULL
&&
396 ip
->i_cnext
== NULL
);
399 ch
= XFS_CHASH(mp
, ip
->i_blkno
);
401 s
= mutex_spinlock(&ch
->ch_lock
);
402 for (chl
= ch
->ch_list
; chl
!= NULL
; chl
= chl
->chl_next
) {
403 if (chl
->chl_blkno
== ip
->i_blkno
) {
405 /* insert this inode into the doubly-linked list
406 * where chl points */
407 if ((iq
= chl
->chl_ip
)) {
408 ip
->i_cprev
= iq
->i_cprev
;
409 iq
->i_cprev
->i_cnext
= ip
;
422 /* no hash list found for this block; add a new hash list */
424 if (chlnew
== NULL
) {
425 mutex_spinunlock(&ch
->ch_lock
, s
);
426 ASSERT(xfs_chashlist_zone
!= NULL
);
427 chlnew
= (xfs_chashlist_t
*)
428 kmem_zone_alloc(xfs_chashlist_zone
,
430 ASSERT(chlnew
!= NULL
);
435 ip
->i_chash
= chlnew
;
437 chlnew
->chl_blkno
= ip
->i_blkno
;
438 chlnew
->chl_next
= ch
->ch_list
;
439 ch
->ch_list
= chlnew
;
443 if (chlnew
!= NULL
) {
444 kmem_zone_free(xfs_chashlist_zone
, chlnew
);
448 mutex_spinunlock(&ch
->ch_lock
, s
);
452 * Link ip to its mount and thread it on the mount's inode list.
455 if ((iq
= mp
->m_inodes
)) {
456 ASSERT(iq
->i_mprev
->i_mnext
== iq
);
457 ip
->i_mprev
= iq
->i_mprev
;
458 iq
->i_mprev
->i_mnext
= ip
;
467 XFS_MOUNT_IUNLOCK(mp
);
470 ASSERT(ip
->i_df
.if_ext_max
==
471 XFS_IFORK_DSIZE(ip
) / sizeof(xfs_bmbt_rec_t
));
473 ASSERT(((ip
->i_d
.di_flags
& XFS_DIFLAG_REALTIME
) != 0) ==
474 ((ip
->i_iocore
.io_flags
& XFS_IOCORE_RT
) != 0));
479 * If we have a real type for an on-disk inode, we can set ops(&unlock)
480 * now. If it's a new inode being created, xfs_ialloc will handle it.
482 VFS_INIT_VNODE(XFS_MTOVFS(mp
), vp
, XFS_ITOBHV(ip
), 1);
489 * The 'normal' internal xfs_iget, if needed it will
490 * 'allocate', or 'get', the vnode.
506 XFS_STATS_INC(xs_ig_attempts
);
509 if ((inode
= iget_locked(XFS_MTOVFS(mp
)->vfs_super
, ino
))) {
513 vp
= LINVFS_GET_VP(inode
);
514 if (inode
->i_state
& I_NEW
) {
515 vn_initialize(inode
);
516 error
= xfs_iget_core(vp
, mp
, tp
, ino
, flags
,
517 lock_flags
, ipp
, bno
);
520 if (inode
->i_state
& I_NEW
)
521 unlock_new_inode(inode
);
526 * If the inode is not fully constructed due to
527 * filehandle mistmatches wait for the inode to go
528 * away and try again.
530 * iget_locked will call __wait_on_freeing_inode
531 * to wait for the inode to go away.
533 if (is_bad_inode(inode
) ||
534 ((bdp
= vn_bhv_lookup(VN_BHV_HEAD(vp
),
535 &xfs_vnodeops
)) == NULL
)) {
541 ip
= XFS_BHVTOI(bdp
);
543 xfs_ilock(ip
, lock_flags
);
544 XFS_STATS_INC(xs_ig_found
);
549 error
= ENOMEM
; /* If we got no inode we are out of memory */
555 * Do the setup for the various locks within the incore inode.
562 mrlock_init(&ip
->i_lock
, MRLOCK_ALLOW_EQUAL_PRI
|MRLOCK_BARRIER
,
563 "xfsino", (long)vp
->v_number
);
564 mrlock_init(&ip
->i_iolock
, MRLOCK_BARRIER
, "xfsio", vp
->v_number
);
565 init_waitqueue_head(&ip
->i_ipin_wait
);
566 atomic_set(&ip
->i_pincount
, 0);
567 init_sema(&ip
->i_flock
, 1, "xfsfino", vp
->v_number
);
571 * Look for the inode corresponding to the given ino in the hash table.
572 * If it is there and its i_transp pointer matches tp, return it.
573 * Otherwise, return NULL.
576 xfs_inode_incore(xfs_mount_t
*mp
,
584 ih
= XFS_IHASH(mp
, ino
);
585 read_lock(&ih
->ih_lock
);
586 for (ip
= ih
->ih_next
; ip
!= NULL
; ip
= ip
->i_next
) {
587 if (ip
->i_ino
== ino
) {
589 * If we find it and tp matches, return it.
590 * Also move it to the front of the hash list
591 * if we find it and it is not already there.
592 * Otherwise break from the loop and return
595 if (ip
->i_transp
== tp
) {
596 version
= ih
->ih_version
;
597 read_unlock(&ih
->ih_lock
);
598 xfs_ihash_promote(ih
, ip
, version
);
604 read_unlock(&ih
->ih_lock
);
609 * Decrement reference count of an inode structure and unlock it.
611 * ip -- the inode being released
612 * lock_flags -- this parameter indicates the inode's locks to be
613 * to be released. See the comment on xfs_iunlock() for a list
617 xfs_iput(xfs_inode_t
*ip
,
620 vnode_t
*vp
= XFS_ITOV(ip
);
622 vn_trace_entry(vp
, "xfs_iput", (inst_t
*)__return_address
);
624 xfs_iunlock(ip
, lock_flags
);
630 * Special iput for brand-new inodes that are still locked
633 xfs_iput_new(xfs_inode_t
*ip
,
636 vnode_t
*vp
= XFS_ITOV(ip
);
637 struct inode
*inode
= LINVFS_GET_IP(vp
);
639 vn_trace_entry(vp
, "xfs_iput_new", (inst_t
*)__return_address
);
641 if ((ip
->i_d
.di_mode
== 0)) {
642 ASSERT(!(ip
->i_flags
& XFS_IRECLAIMABLE
));
645 if (inode
->i_state
& I_NEW
)
646 unlock_new_inode(inode
);
648 xfs_iunlock(ip
, lock_flags
);
654 * This routine embodies the part of the reclaim code that pulls
655 * the inode from the inode hash table and the mount structure's
657 * This should only be called from xfs_reclaim().
660 xfs_ireclaim(xfs_inode_t
*ip
)
665 * Remove from old hash list and mount list.
667 XFS_STATS_INC(xs_ig_reclaims
);
672 * Here we do a spurious inode lock in order to coordinate with
673 * xfs_sync(). This is because xfs_sync() references the inodes
674 * in the mount list without taking references on the corresponding
675 * vnodes. We make that OK here by ensuring that we wait until
676 * the inode is unlocked in xfs_sync() before we go ahead and
677 * free it. We get both the regular lock and the io lock because
678 * the xfs_sync() code may need to drop the regular one but will
679 * still hold the io lock.
681 xfs_ilock(ip
, XFS_ILOCK_EXCL
| XFS_IOLOCK_EXCL
);
684 * Release dquots (and their references) if any. An inode may escape
685 * xfs_inactive and get here via vn_alloc->vn_reclaim path.
687 XFS_QM_DQDETACH(ip
->i_mount
, ip
);
690 * Pull our behavior descriptor from the vnode chain.
692 vp
= XFS_ITOV_NULL(ip
);
694 vn_bhv_remove(VN_BHV_HEAD(vp
), XFS_ITOBHV(ip
));
698 * Free all memory associated with the inode.
704 * This routine removes an about-to-be-destroyed inode from
705 * all of the lists in which it is located with the exception
706 * of the behavior chain.
716 xfs_chashlist_t
*chl
, *chm
;
720 write_lock(&ih
->ih_lock
);
721 if ((iq
= ip
->i_next
)) {
722 iq
->i_prevp
= ip
->i_prevp
;
726 write_unlock(&ih
->ih_lock
);
729 * Remove from cluster hash list
730 * 1) delete the chashlist if this is the last inode on the chashlist
731 * 2) unchain from list of inodes
732 * 3) point chashlist->chl_ip to 'chl_next' if to this inode.
735 ch
= XFS_CHASH(mp
, ip
->i_blkno
);
736 s
= mutex_spinlock(&ch
->ch_lock
);
738 if (ip
->i_cnext
== ip
) {
739 /* Last inode on chashlist */
740 ASSERT(ip
->i_cnext
== ip
&& ip
->i_cprev
== ip
);
741 ASSERT(ip
->i_chash
!= NULL
);
743 for (chl
= ch
->ch_list
; chl
!= NULL
; chl
= chl
->chl_next
) {
744 if (chl
->chl_blkno
== ip
->i_blkno
) {
746 /* first item on the list */
747 ch
->ch_list
= chl
->chl_next
;
749 chm
->chl_next
= chl
->chl_next
;
751 kmem_zone_free(xfs_chashlist_zone
, chl
);
754 ASSERT(chl
->chl_ip
!= ip
);
758 ASSERT_ALWAYS(chl
!= NULL
);
760 /* delete one inode from a non-empty list */
762 iq
->i_cprev
= ip
->i_cprev
;
763 ip
->i_cprev
->i_cnext
= iq
;
764 if (ip
->i_chash
->chl_ip
== ip
) {
765 ip
->i_chash
->chl_ip
= iq
;
767 ip
->i_chash
= __return_address
;
768 ip
->i_cprev
= __return_address
;
769 ip
->i_cnext
= __return_address
;
771 mutex_spinunlock(&ch
->ch_lock
, s
);
774 * Remove from mount's inode list.
777 ASSERT((ip
->i_mnext
!= NULL
) && (ip
->i_mprev
!= NULL
));
779 iq
->i_mprev
= ip
->i_mprev
;
780 ip
->i_mprev
->i_mnext
= iq
;
783 * Fix up the head pointer if it points to the inode being deleted.
785 if (mp
->m_inodes
== ip
) {
793 /* Deal with the deleted inodes list */
794 list_del_init(&ip
->i_reclaim
);
797 XFS_MOUNT_IUNLOCK(mp
);
801 * This is a wrapper routine around the xfs_ilock() routine
802 * used to centralize some grungy code. It is used in places
803 * that wish to lock the inode solely for reading the extents.
804 * The reason these places can't just call xfs_ilock(SHARED)
805 * is that the inode lock also guards to bringing in of the
806 * extents from disk for a file in b-tree format. If the inode
807 * is in b-tree format, then we need to lock the inode exclusively
808 * until the extents are read in. Locking it exclusively all
809 * the time would limit our parallelism unnecessarily, though.
810 * What we do instead is check to see if the extents have been
811 * read in yet, and only lock the inode exclusively if they
814 * The function returns a value which should be given to the
815 * corresponding xfs_iunlock_map_shared(). This value is
816 * the mode in which the lock was actually taken.
819 xfs_ilock_map_shared(
824 if ((ip
->i_d
.di_format
== XFS_DINODE_FMT_BTREE
) &&
825 ((ip
->i_df
.if_flags
& XFS_IFEXTENTS
) == 0)) {
826 lock_mode
= XFS_ILOCK_EXCL
;
828 lock_mode
= XFS_ILOCK_SHARED
;
831 xfs_ilock(ip
, lock_mode
);
837 * This is simply the unlock routine to go with xfs_ilock_map_shared().
838 * All it does is call xfs_iunlock() with the given lock_mode.
841 xfs_iunlock_map_shared(
843 unsigned int lock_mode
)
845 xfs_iunlock(ip
, lock_mode
);
849 * The xfs inode contains 2 locks: a multi-reader lock called the
850 * i_iolock and a multi-reader lock called the i_lock. This routine
851 * allows either or both of the locks to be obtained.
853 * The 2 locks should always be ordered so that the IO lock is
854 * obtained first in order to prevent deadlock.
856 * ip -- the inode being locked
857 * lock_flags -- this parameter indicates the inode's locks
858 * to be locked. It can be:
863 * XFS_IOLOCK_SHARED | XFS_ILOCK_SHARED,
864 * XFS_IOLOCK_SHARED | XFS_ILOCK_EXCL,
865 * XFS_IOLOCK_EXCL | XFS_ILOCK_SHARED,
866 * XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL
869 xfs_ilock(xfs_inode_t
*ip
,
873 * You can't set both SHARED and EXCL for the same lock,
874 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
875 * and XFS_ILOCK_EXCL are valid values to set in lock_flags.
877 ASSERT((lock_flags
& (XFS_IOLOCK_SHARED
| XFS_IOLOCK_EXCL
)) !=
878 (XFS_IOLOCK_SHARED
| XFS_IOLOCK_EXCL
));
879 ASSERT((lock_flags
& (XFS_ILOCK_SHARED
| XFS_ILOCK_EXCL
)) !=
880 (XFS_ILOCK_SHARED
| XFS_ILOCK_EXCL
));
881 ASSERT((lock_flags
& ~XFS_LOCK_MASK
) == 0);
883 if (lock_flags
& XFS_IOLOCK_EXCL
) {
884 mrupdate(&ip
->i_iolock
);
885 } else if (lock_flags
& XFS_IOLOCK_SHARED
) {
886 mraccess(&ip
->i_iolock
);
888 if (lock_flags
& XFS_ILOCK_EXCL
) {
889 mrupdate(&ip
->i_lock
);
890 } else if (lock_flags
& XFS_ILOCK_SHARED
) {
891 mraccess(&ip
->i_lock
);
893 xfs_ilock_trace(ip
, 1, lock_flags
, (inst_t
*)__return_address
);
897 * This is just like xfs_ilock(), except that the caller
898 * is guaranteed not to sleep. It returns 1 if it gets
899 * the requested locks and 0 otherwise. If the IO lock is
900 * obtained but the inode lock cannot be, then the IO lock
901 * is dropped before returning.
903 * ip -- the inode being locked
904 * lock_flags -- this parameter indicates the inode's locks to be
905 * to be locked. See the comment for xfs_ilock() for a list
910 xfs_ilock_nowait(xfs_inode_t
*ip
,
917 * You can't set both SHARED and EXCL for the same lock,
918 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
919 * and XFS_ILOCK_EXCL are valid values to set in lock_flags.
921 ASSERT((lock_flags
& (XFS_IOLOCK_SHARED
| XFS_IOLOCK_EXCL
)) !=
922 (XFS_IOLOCK_SHARED
| XFS_IOLOCK_EXCL
));
923 ASSERT((lock_flags
& (XFS_ILOCK_SHARED
| XFS_ILOCK_EXCL
)) !=
924 (XFS_ILOCK_SHARED
| XFS_ILOCK_EXCL
));
925 ASSERT((lock_flags
& ~XFS_LOCK_MASK
) == 0);
928 if (lock_flags
& XFS_IOLOCK_EXCL
) {
929 iolocked
= mrtryupdate(&ip
->i_iolock
);
933 } else if (lock_flags
& XFS_IOLOCK_SHARED
) {
934 iolocked
= mrtryaccess(&ip
->i_iolock
);
939 if (lock_flags
& XFS_ILOCK_EXCL
) {
940 ilocked
= mrtryupdate(&ip
->i_lock
);
943 mrunlock(&ip
->i_iolock
);
947 } else if (lock_flags
& XFS_ILOCK_SHARED
) {
948 ilocked
= mrtryaccess(&ip
->i_lock
);
951 mrunlock(&ip
->i_iolock
);
956 xfs_ilock_trace(ip
, 2, lock_flags
, (inst_t
*)__return_address
);
961 * xfs_iunlock() is used to drop the inode locks acquired with
962 * xfs_ilock() and xfs_ilock_nowait(). The caller must pass
963 * in the flags given to xfs_ilock() or xfs_ilock_nowait() so
964 * that we know which locks to drop.
966 * ip -- the inode being unlocked
967 * lock_flags -- this parameter indicates the inode's locks to be
968 * to be unlocked. See the comment for xfs_ilock() for a list
969 * of valid values for this parameter.
973 xfs_iunlock(xfs_inode_t
*ip
,
977 * You can't set both SHARED and EXCL for the same lock,
978 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
979 * and XFS_ILOCK_EXCL are valid values to set in lock_flags.
981 ASSERT((lock_flags
& (XFS_IOLOCK_SHARED
| XFS_IOLOCK_EXCL
)) !=
982 (XFS_IOLOCK_SHARED
| XFS_IOLOCK_EXCL
));
983 ASSERT((lock_flags
& (XFS_ILOCK_SHARED
| XFS_ILOCK_EXCL
)) !=
984 (XFS_ILOCK_SHARED
| XFS_ILOCK_EXCL
));
985 ASSERT((lock_flags
& ~(XFS_LOCK_MASK
| XFS_IUNLOCK_NONOTIFY
)) == 0);
986 ASSERT(lock_flags
!= 0);
988 if (lock_flags
& (XFS_IOLOCK_SHARED
| XFS_IOLOCK_EXCL
)) {
989 ASSERT(!(lock_flags
& XFS_IOLOCK_SHARED
) ||
990 (ismrlocked(&ip
->i_iolock
, MR_ACCESS
)));
991 ASSERT(!(lock_flags
& XFS_IOLOCK_EXCL
) ||
992 (ismrlocked(&ip
->i_iolock
, MR_UPDATE
)));
993 mrunlock(&ip
->i_iolock
);
996 if (lock_flags
& (XFS_ILOCK_SHARED
| XFS_ILOCK_EXCL
)) {
997 ASSERT(!(lock_flags
& XFS_ILOCK_SHARED
) ||
998 (ismrlocked(&ip
->i_lock
, MR_ACCESS
)));
999 ASSERT(!(lock_flags
& XFS_ILOCK_EXCL
) ||
1000 (ismrlocked(&ip
->i_lock
, MR_UPDATE
)));
1001 mrunlock(&ip
->i_lock
);
1004 * Let the AIL know that this item has been unlocked in case
1005 * it is in the AIL and anyone is waiting on it. Don't do
1006 * this if the caller has asked us not to.
1008 if (!(lock_flags
& XFS_IUNLOCK_NONOTIFY
) &&
1009 ip
->i_itemp
!= NULL
) {
1010 xfs_trans_unlocked_item(ip
->i_mount
,
1011 (xfs_log_item_t
*)(ip
->i_itemp
));
1014 xfs_ilock_trace(ip
, 3, lock_flags
, (inst_t
*)__return_address
);
1018 * give up write locks. the i/o lock cannot be held nested
1019 * if it is being demoted.
1022 xfs_ilock_demote(xfs_inode_t
*ip
,
1025 ASSERT(lock_flags
& (XFS_IOLOCK_EXCL
|XFS_ILOCK_EXCL
));
1026 ASSERT((lock_flags
& ~(XFS_IOLOCK_EXCL
|XFS_ILOCK_EXCL
)) == 0);
1028 if (lock_flags
& XFS_ILOCK_EXCL
) {
1029 ASSERT(ismrlocked(&ip
->i_lock
, MR_UPDATE
));
1030 mrdemote(&ip
->i_lock
);
1032 if (lock_flags
& XFS_IOLOCK_EXCL
) {
1033 ASSERT(ismrlocked(&ip
->i_iolock
, MR_UPDATE
));
1034 mrdemote(&ip
->i_iolock
);
1039 * The following three routines simply manage the i_flock
1040 * semaphore embedded in the inode. This semaphore synchronizes
1041 * processes attempting to flush the in-core inode back to disk.
1044 xfs_iflock(xfs_inode_t
*ip
)
1046 psema(&(ip
->i_flock
), PINOD
|PLTWAIT
);
1050 xfs_iflock_nowait(xfs_inode_t
*ip
)
1052 return (cpsema(&(ip
->i_flock
)));
1056 xfs_ifunlock(xfs_inode_t
*ip
)
1058 ASSERT(valusema(&(ip
->i_flock
)) <= 0);
1059 vsema(&(ip
->i_flock
));
This page took 0.101207 seconds and 5 git commands to generate.