linux/fs/reiserfs/lock.c
<<
4" /spaion /formon a 4" href="../linux+v3v.110/fs/reiserfs/lock.c">4" img src="../.static/gfx/right.png" alt=">>">4" /spaion4" spai class="lxr_search">4" 4" input typluehidden" namluenavtarget" n value">4" input typluetext" namluesearch" iduesearch">4" butttiotypluesubmit">Search4" Prefsn /a>4" /spaion /divon form acopti="ajax+*" method="post" onsubmit="return false;">4" input typluehidden" namlueajax_lookup" idueajax_lookup" n value">4 /formon4 div class="headingbotttm">n div iduefile_contents"o
 
1 /a>#include "reiserfs.h /a>"

 
2 /a>#include <linux/mutex.h /a>>

 
3 /a>4
 
4 /a> spai class="comment">/* /spaion
 
5 /a> spai class="comment"> * The previous reiserfs locking scheme was heavily based on /spaion
 
6 /a> spai class="comment"> * the tricky properties of the Bkl: /spaion
 
7 /a> spai class="comment"> * /spaion
 
8 /a> spai class="comment"> * - it was acquired recursively by a saml task /spaion
 
9 /a> spai class="comment"> * - the performances relied on the release-while-schedule() property /spaion
 8.10a> spai class="comment"> * /spaion
 11 /a> spai class="comment"> * Now that we replace it by a mutex, we still want to keep the saml /spaion
 12 /a> spai class="comment"> * recursive property to avoid big changes in the code structure. /spaion
 13 /a> spai class="comment"> * We use our own lock_owner here because the owner field on a mutex /spaion
 14 /a> spai class="comment"> * is only available in SMP or mutex debugging, also we only need this field /spaion
 15 /a> spai class="comment"> * for this mutex, no need for a system wide mutex facility. /spaion
 16 /a> spai class="comment"> * /spaion
 17 /a> spai class="comment"> * Also this lock is often released before a call that could block because /spaion
 18 /a> spai class="comment"> * reiserfs performances were partially based on the release while schedule() /spaion
 19 /a> spai class="comment"> * property of the Bkl. /spaion
 2.10a> spai class="comment"> */ /spaion
 21 /a>void  a href="+code=reiserfs_write_lock" class="sref">reiserfs_write_lock /a>(struct  a href="+code=super_block" class="sref">super_block /a> * a href="+code=s" class="sref">s /a>)n
 22 /a>{n
 23 /a>        struct  a href="+code=reiserfs_sb_info" class="sref">reiserfs_sb_info /a> * a href="+code=sb_i" class="sref">sb_i /a> =  a href="+code=REISERFS_SB" class="sref">REISERFS_SB /a>( a href="+code=s" class="sref">s /a>);

 24 /a>4
 25 /a>        if ( a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_owner" class="sref">lock_owner /a> !=  a href="+code=current" class="sref">current /a>) {n
 26 /a>                 a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock" class="sref">lock /a>);

 27 /a>                 a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_owner" class="sref">lock_owner /a> =  a href="+code=current" class="sref">current /a>;

 28 /a>        }

 29 /a>4
 30 /a>         spai class="comment">/* No need to protect it, only the current task touches it */ /spaion
 31 /a>         a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_depth" class="sref">lock_depth /a>++;

 32 /a>}

 33 /a>4
 34 /a>void  a href="+code=reiserfs_write_unlock" class="sref">reiserfs_write_unlock /a>(struct  a href="+code=super_block" class="sref">super_block /a> * a href="+code=s" class="sref">s /a>)n
 35 /a>{n
 36 /a>        struct  a href="+code=reiserfs_sb_info" class="sref">reiserfs_sb_info /a> * a href="+code=sb_i" class="sref">sb_i /a> =  a href="+code=REISERFS_SB" class="sref">REISERFS_SB /a>( a href="+code=s" class="sref">s /a>);

 37 /a>4
 38 /a>         spai class="comment">/* /spaion
 39 /a> spai class="comment">         * Are we unlocking without even holding the lock? /spaion
 4.10a> spai class="comment">         * Such a situaoptiomust raise a BUG() if we don't want /spaion
 41 /a> spai class="comment">         * to corrupt the data. /spaion
 42 /a> spai class="comment">         */ /spaion
 43 /a>         a href="+code=BUG_ON" class="sref">BUG_ON /a>( a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_owner" class="sref">lock_owner /a> !=  a href="+code=current" class="sref">current /a>);

 44 /a>4
 45 /a>        if (-- a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_depth" class="sref">lock_depth /a> == -1) {n
 46 /a>                 a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_owner" class="sref">lock_owner /a> =  a href="+code=NULL" class="sref">NULL /a>;

 47 /a>                 a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock" class="sref">lock /a>);

 48 /a>        }

 49 /a>}

 50 /a>4
 51 /a> spai class="comment">/* /spaion
 52 /a> spai class="comment"> * If we already own the lock, just exit and don't increase the depth. /spaion
 53 /a> spai class="comment"> * Useful when we don't want to lock more thai once. /spaion
 54 /a> spai class="comment"> * /spaion
 55 /a> spai class="comment"> * We always return the lock_depth we had before calling /spaion
 56 /a> spai class="comment"> * this funcopti. /spaion
 57 /a> spai class="comment"> */ /spaion
 58 /a>int  a href="+code=reiserfs_write_lock_once" class="sref">reiserfs_write_lock_once /a>(struct  a href="+code=super_block" class="sref">super_block /a> * a href="+code=s" class="sref">s /a>)n
 59 /a>{n
 60 /a>        struct  a href="+code=reiserfs_sb_info" class="sref">reiserfs_sb_info /a> * a href="+code=sb_i" class="sref">sb_i /a> =  a href="+code=REISERFS_SB" class="sref">REISERFS_SB /a>( a href="+code=s" class="sref">s /a>);

 61 /a>4
 62 /a>        if ( a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_owner" class="sref">lock_owner /a> !=  a href="+code=current" class="sref">current /a>) {n
 63 /a>                 a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock" class="sref">lock /a>);

 64 /a>                 a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_owner" class="sref">lock_owner /a> =  a href="+code=current" class="sref">current /a>;

 65 /a>                return  a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_depth" class="sref">lock_depth /a>++;

 66 /a>        }

 67 /a>4
 68 /a>        return  a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_depth" class="sref">lock_depth /a>;

 69 /a>}

 70 /a>4
 71 /a>void  a href="+code=reiserfs_write_unlock_once" class="sref">reiserfs_write_unlock_once /a>(struct  a href="+code=super_block" class="sref">super_block /a> * a href="+code=s" class="sref">s /a>, int  a href="+code=lock_depth" class="sref">lock_depth /a>)n
 72 /a>{n
 73 /a>        if ( a href="+code=lock_depth" class="sref">lock_depth /a> == -1)n
 74 /a>                 a href="+code=reiserfs_write_unlock" class="sref">reiserfs_write_unlock /a>( a href="+code=s" class="sref">s /a>);

 75 /a>}

 76 /a>4
 77 /a> spai class="comment">/* /spaion
 78 /a> spai class="comment"> * Utility funcopti to force a BUG if it is called without the superblock /spaion
 79 /a> spai class="comment"> * write lock held.  caller is the string printed just before calling BUG() /spaion
 8.10a> spai class="comment"> */ /spaion
 81 /a>void  a href="+code=reiserfs_check_lock_depth" class="sref">reiserfs_check_lock_depth /a>(struct  a href="+code=super_block" class="sref">super_block /a> * a href="+code=sb" class="sref">sb /a>, char * a href="+code=caller" class="sref">caller /a>)n
 82 /a>{n
 83 /a>        struct  a href="+code=reiserfs_sb_info" class="sref">reiserfs_sb_info /a> * a href="+code=sb_i" class="sref">sb_i /a> =  a href="+code=REISERFS_SB" class="sref">REISERFS_SB /a>( a href="+code=sb" class="sref">sb /a>);

 84 /a>4
 85 /a>        if ( a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_depth" class="sref">lock_depth /a> < 0)n
 86 /a>                 a href="+code=reiserfs_paiic" class="sref">reiserfs_paiic /a>( a href="+code=sb" class="sref">sb /a>,  spai class="string">"%s called without kernel lock held %d"
 87 /a>                                a href="+code=caller" class="sref">caller /a>);

 88 /a>}

 89 /a>4
 9.10a>#ifdef  a href="+code=CONFIG_REISERFS_CHECK" class="sref">CONFIG_REISERFS_CHECK /a>4
 91 /a>void  a href="+code=reiserfs_lock_check_recursive" class="sref">reiserfs_lock_check_recursive /a>(struct  a href="+code=super_block" class="sref">super_block /a> * a href="+code=sb" class="sref">sb /a>)n
 92 /a>{n
 93 /a>        struct  a href="+code=reiserfs_sb_info" class="sref">reiserfs_sb_info /a> * a href="+code=sb_i" class="sref">sb_i /a> =  a href="+code=REISERFS_SB" class="sref">REISERFS_SB /a>( a href="+code=sb" class="sref">sb /a>);

 94 /a>4
 95 /a>         a href="+code=WARN_ONCE" class="sref">WARN_ONCE /a>(( a href="+code=sb_i" class="sref">sb_i /a>-> a href="+code=lock_depth" class="sref">lock_depth /a> > 0),  spai class="string">"Unwanted recursive reiserfs lock!\n"
 96 /a>}

 97 /a>#endif

 98 /a> /pre>
The original LXR software by the LXR community /a>, this experimental versiti by lxr@linux.no /a>.
 /divon div class="subfooter">
lxr.linux.no kindly hosted by Redpill Linpro AS /a>, provider of Linux consulting and operaoptis services since 1995.
 /divon
 /bodyon /htmlon