0001
0002 #include "reiserfs.h"
0003 #include <linux/mutex.h>
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 void reiserfs_write_lock(struct super_block *s)
0023 {
0024 struct reiserfs_sb_info *sb_i = REISERFS_SB(s);
0025
0026 if (sb_i->lock_owner != current) {
0027 mutex_lock(&sb_i->lock);
0028 sb_i->lock_owner = current;
0029 }
0030
0031
0032 sb_i->lock_depth++;
0033 }
0034
0035 void reiserfs_write_unlock(struct super_block *s)
0036 {
0037 struct reiserfs_sb_info *sb_i = REISERFS_SB(s);
0038
0039
0040
0041
0042
0043
0044 BUG_ON(sb_i->lock_owner != current);
0045
0046 if (--sb_i->lock_depth == -1) {
0047 sb_i->lock_owner = NULL;
0048 mutex_unlock(&sb_i->lock);
0049 }
0050 }
0051
0052 int __must_check reiserfs_write_unlock_nested(struct super_block *s)
0053 {
0054 struct reiserfs_sb_info *sb_i = REISERFS_SB(s);
0055 int depth;
0056
0057
0058 if (sb_i->lock_owner != current)
0059 return -1;
0060
0061 depth = sb_i->lock_depth;
0062
0063 sb_i->lock_depth = -1;
0064 sb_i->lock_owner = NULL;
0065 mutex_unlock(&sb_i->lock);
0066
0067 return depth;
0068 }
0069
0070 void reiserfs_write_lock_nested(struct super_block *s, int depth)
0071 {
0072 struct reiserfs_sb_info *sb_i = REISERFS_SB(s);
0073
0074
0075 if (depth == -1)
0076 return;
0077
0078 mutex_lock(&sb_i->lock);
0079 sb_i->lock_owner = current;
0080 sb_i->lock_depth = depth;
0081 }
0082
0083
0084
0085
0086
0087 void reiserfs_check_lock_depth(struct super_block *sb, char *caller)
0088 {
0089 struct reiserfs_sb_info *sb_i = REISERFS_SB(sb);
0090
0091 WARN_ON(sb_i->lock_depth < 0);
0092 }
0093
0094 #ifdef CONFIG_REISERFS_CHECK
0095 void reiserfs_lock_check_recursive(struct super_block *sb)
0096 {
0097 struct reiserfs_sb_info *sb_i = REISERFS_SB(sb);
0098
0099 WARN_ONCE((sb_i->lock_depth > 0), "Unwanted recursive reiserfs lock!\n");
0100 }
0101 #endif