aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2013-08-08 17:27:19 -0400
committerJeff Mahoney <jeffm@suse.de>2013-08-08 17:27:19 -0400
commit4c05141df57f4ffc1a9a28f1925434924179bfe4 (patch)
treed210b251b6f46e50b27f4db4f15010f9b40aad45 /fs
parentc095ba7224d8edc71dcef0d655911399a8bd4a3f (diff)
reiserfs: locking, push write lock out of xattr code
The reiserfs xattr code doesn't need the write lock and sleeps all over the place. We can simplify the locking by releasing it and reacquiring after the xattr call. Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/reiserfs/inode.c38
-rw-r--r--fs/reiserfs/super.c48
-rw-r--r--fs/reiserfs/xattr.c46
-rw-r--r--fs/reiserfs/xattr_acl.c16
4 files changed, 70 insertions, 78 deletions
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 0048cc16a6a8..bf1331a0f04b 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -30,7 +30,6 @@ void reiserfs_evict_inode(struct inode *inode)
30 JOURNAL_PER_BALANCE_CNT * 2 + 30 JOURNAL_PER_BALANCE_CNT * 2 +
31 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); 31 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb);
32 struct reiserfs_transaction_handle th; 32 struct reiserfs_transaction_handle th;
33 int depth;
34 int err; 33 int err;
35 34
36 if (!inode->i_nlink && !is_bad_inode(inode)) 35 if (!inode->i_nlink && !is_bad_inode(inode))
@@ -40,12 +39,14 @@ void reiserfs_evict_inode(struct inode *inode)
40 if (inode->i_nlink) 39 if (inode->i_nlink)
41 goto no_delete; 40 goto no_delete;
42 41
43 depth = reiserfs_write_lock_once(inode->i_sb);
44
45 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ 42 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */
46 if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */ 43 if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */
44 int depth;
45
47 reiserfs_delete_xattrs(inode); 46 reiserfs_delete_xattrs(inode);
48 47
48 depth = reiserfs_write_lock_once(inode->i_sb);
49
49 if (journal_begin(&th, inode->i_sb, jbegin_count)) 50 if (journal_begin(&th, inode->i_sb, jbegin_count))
50 goto out; 51 goto out;
51 reiserfs_update_inode_transaction(inode); 52 reiserfs_update_inode_transaction(inode);
@@ -72,12 +73,12 @@ void reiserfs_evict_inode(struct inode *inode)
72 /* all items of file are deleted, so we can remove "save" link */ 73 /* all items of file are deleted, so we can remove "save" link */
73 remove_save_link(inode, 0 /* not truncate */ ); /* we can't do anything 74 remove_save_link(inode, 0 /* not truncate */ ); /* we can't do anything
74 * about an error here */ 75 * about an error here */
76out:
77 reiserfs_write_unlock_once(inode->i_sb, depth);
75 } else { 78 } else {
76 /* no object items are in the tree */ 79 /* no object items are in the tree */
77 ; 80 ;
78 } 81 }
79 out:
80 reiserfs_write_unlock_once(inode->i_sb, depth);
81 clear_inode(inode); /* note this must go after the journal_end to prevent deadlock */ 82 clear_inode(inode); /* note this must go after the journal_end to prevent deadlock */
82 dquot_drop(inode); 83 dquot_drop(inode);
83 inode->i_blocks = 0; 84 inode->i_blocks = 0;
@@ -1941,7 +1942,9 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1941 } 1942 }
1942 1943
1943 if (reiserfs_posixacl(inode->i_sb)) { 1944 if (reiserfs_posixacl(inode->i_sb)) {
1945 reiserfs_write_unlock(inode->i_sb);
1944 retval = reiserfs_inherit_default_acl(th, dir, dentry, inode); 1946 retval = reiserfs_inherit_default_acl(th, dir, dentry, inode);
1947 reiserfs_write_lock(inode->i_sb);
1945 if (retval) { 1948 if (retval) {
1946 err = retval; 1949 err = retval;
1947 reiserfs_check_path(&path_to_key); 1950 reiserfs_check_path(&path_to_key);
@@ -1956,7 +1959,9 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1956 inode->i_flags |= S_PRIVATE; 1959 inode->i_flags |= S_PRIVATE;
1957 1960
1958 if (security->name) { 1961 if (security->name) {
1962 reiserfs_write_unlock(inode->i_sb);
1959 retval = reiserfs_security_write(th, inode, security); 1963 retval = reiserfs_security_write(th, inode, security);
1964 reiserfs_write_lock(inode->i_sb);
1960 if (retval) { 1965 if (retval) {
1961 err = retval; 1966 err = retval;
1962 reiserfs_check_path(&path_to_key); 1967 reiserfs_check_path(&path_to_key);
@@ -3129,6 +3134,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3129 */ 3134 */
3130 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5 && 3135 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5 &&
3131 attr->ia_size > MAX_NON_LFS) { 3136 attr->ia_size > MAX_NON_LFS) {
3137 reiserfs_write_unlock_once(inode->i_sb, depth);
3132 error = -EFBIG; 3138 error = -EFBIG;
3133 goto out; 3139 goto out;
3134 } 3140 }
@@ -3150,8 +3156,10 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3150 if (err) 3156 if (err)
3151 error = err; 3157 error = err;
3152 } 3158 }
3153 if (error) 3159 if (error) {
3160 reiserfs_write_unlock_once(inode->i_sb, depth);
3154 goto out; 3161 goto out;
3162 }
3155 /* 3163 /*
3156 * file size is changed, ctime and mtime are 3164 * file size is changed, ctime and mtime are
3157 * to be updated 3165 * to be updated
@@ -3159,6 +3167,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3159 attr->ia_valid |= (ATTR_MTIME | ATTR_CTIME); 3167 attr->ia_valid |= (ATTR_MTIME | ATTR_CTIME);
3160 } 3168 }
3161 } 3169 }
3170 reiserfs_write_unlock_once(inode->i_sb, depth);
3162 3171
3163 if ((((attr->ia_valid & ATTR_UID) && (from_kuid(&init_user_ns, attr->ia_uid) & ~0xffff)) || 3172 if ((((attr->ia_valid & ATTR_UID) && (from_kuid(&init_user_ns, attr->ia_uid) & ~0xffff)) ||
3164 ((attr->ia_valid & ATTR_GID) && (from_kgid(&init_user_ns, attr->ia_gid) & ~0xffff))) && 3173 ((attr->ia_valid & ATTR_GID) && (from_kgid(&init_user_ns, attr->ia_gid) & ~0xffff))) &&
@@ -3183,14 +3192,16 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3183 return error; 3192 return error;
3184 3193
3185 /* (user+group)*(old+new) structure - we count quota info and , inode write (sb, inode) */ 3194 /* (user+group)*(old+new) structure - we count quota info and , inode write (sb, inode) */
3195 depth = reiserfs_write_lock_once(inode->i_sb);
3186 error = journal_begin(&th, inode->i_sb, jbegin_count); 3196 error = journal_begin(&th, inode->i_sb, jbegin_count);
3197 reiserfs_write_unlock_once(inode->i_sb, depth);
3187 if (error) 3198 if (error)
3188 goto out; 3199 goto out;
3189 reiserfs_write_unlock_once(inode->i_sb, depth);
3190 error = dquot_transfer(inode, attr); 3200 error = dquot_transfer(inode, attr);
3191 depth = reiserfs_write_lock_once(inode->i_sb); 3201 depth = reiserfs_write_lock_once(inode->i_sb);
3192 if (error) { 3202 if (error) {
3193 journal_end(&th, inode->i_sb, jbegin_count); 3203 journal_end(&th, inode->i_sb, jbegin_count);
3204 reiserfs_write_unlock_once(inode->i_sb, depth);
3194 goto out; 3205 goto out;
3195 } 3206 }
3196 3207
@@ -3202,17 +3213,11 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3202 inode->i_gid = attr->ia_gid; 3213 inode->i_gid = attr->ia_gid;
3203 mark_inode_dirty(inode); 3214 mark_inode_dirty(inode);
3204 error = journal_end(&th, inode->i_sb, jbegin_count); 3215 error = journal_end(&th, inode->i_sb, jbegin_count);
3216 reiserfs_write_unlock_once(inode->i_sb, depth);
3205 if (error) 3217 if (error)
3206 goto out; 3218 goto out;
3207 } 3219 }
3208 3220
3209 /*
3210 * Relax the lock here, as it might truncate the
3211 * inode pages and wait for inode pages locks.
3212 * To release such page lock, the owner needs the
3213 * reiserfs lock
3214 */
3215 reiserfs_write_unlock_once(inode->i_sb, depth);
3216 if ((attr->ia_valid & ATTR_SIZE) && 3221 if ((attr->ia_valid & ATTR_SIZE) &&
3217 attr->ia_size != i_size_read(inode)) { 3222 attr->ia_size != i_size_read(inode)) {
3218 error = inode_newsize_ok(inode, attr->ia_size); 3223 error = inode_newsize_ok(inode, attr->ia_size);
@@ -3226,16 +3231,13 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3226 setattr_copy(inode, attr); 3231 setattr_copy(inode, attr);
3227 mark_inode_dirty(inode); 3232 mark_inode_dirty(inode);
3228 } 3233 }
3229 depth = reiserfs_write_lock_once(inode->i_sb);
3230 3234
3231 if (!error && reiserfs_posixacl(inode->i_sb)) { 3235 if (!error && reiserfs_posixacl(inode->i_sb)) {
3232 if (attr->ia_valid & ATTR_MODE) 3236 if (attr->ia_valid & ATTR_MODE)
3233 error = reiserfs_acl_chmod(inode); 3237 error = reiserfs_acl_chmod(inode);
3234 } 3238 }
3235 3239
3236 out: 3240out:
3237 reiserfs_write_unlock_once(inode->i_sb, depth);
3238
3239 return error; 3241 return error;
3240} 3242}
3241 3243
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index f8a23c3078f8..7e81d9774916 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -1335,7 +1335,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1335 kfree(qf_names[i]); 1335 kfree(qf_names[i]);
1336#endif 1336#endif
1337 err = -EINVAL; 1337 err = -EINVAL;
1338 goto out_unlock; 1338 goto out_err_unlock;
1339 } 1339 }
1340#ifdef CONFIG_QUOTA 1340#ifdef CONFIG_QUOTA
1341 handle_quota_files(s, qf_names, &qfmt); 1341 handle_quota_files(s, qf_names, &qfmt);
@@ -1379,35 +1379,32 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1379 if (blocks) { 1379 if (blocks) {
1380 err = reiserfs_resize(s, blocks); 1380 err = reiserfs_resize(s, blocks);
1381 if (err != 0) 1381 if (err != 0)
1382 goto out_unlock; 1382 goto out_err_unlock;
1383 } 1383 }
1384 1384
1385 if (*mount_flags & MS_RDONLY) { 1385 if (*mount_flags & MS_RDONLY) {
1386 reiserfs_write_unlock(s);
1386 reiserfs_xattr_init(s, *mount_flags); 1387 reiserfs_xattr_init(s, *mount_flags);
1387 /* remount read-only */ 1388 /* remount read-only */
1388 if (s->s_flags & MS_RDONLY) 1389 if (s->s_flags & MS_RDONLY)
1389 /* it is read-only already */ 1390 /* it is read-only already */
1390 goto out_ok; 1391 goto out_ok_unlocked;
1391 1392
1392 /*
1393 * Drop write lock. Quota will retake it when needed and lock
1394 * ordering requires calling dquot_suspend() without it.
1395 */
1396 reiserfs_write_unlock(s);
1397 err = dquot_suspend(s, -1); 1393 err = dquot_suspend(s, -1);
1398 if (err < 0) 1394 if (err < 0)
1399 goto out_err; 1395 goto out_err;
1400 reiserfs_write_lock(s);
1401 1396
1402 /* try to remount file system with read-only permissions */ 1397 /* try to remount file system with read-only permissions */
1403 if (sb_umount_state(rs) == REISERFS_VALID_FS 1398 if (sb_umount_state(rs) == REISERFS_VALID_FS
1404 || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) { 1399 || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
1405 goto out_ok; 1400 goto out_ok_unlocked;
1406 } 1401 }
1407 1402
1403 reiserfs_write_lock(s);
1404
1408 err = journal_begin(&th, s, 10); 1405 err = journal_begin(&th, s, 10);
1409 if (err) 1406 if (err)
1410 goto out_unlock; 1407 goto out_err_unlock;
1411 1408
1412 /* Mounting a rw partition read-only. */ 1409 /* Mounting a rw partition read-only. */
1413 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1); 1410 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
@@ -1416,13 +1413,14 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1416 } else { 1413 } else {
1417 /* remount read-write */ 1414 /* remount read-write */
1418 if (!(s->s_flags & MS_RDONLY)) { 1415 if (!(s->s_flags & MS_RDONLY)) {
1416 reiserfs_write_unlock(s);
1419 reiserfs_xattr_init(s, *mount_flags); 1417 reiserfs_xattr_init(s, *mount_flags);
1420 goto out_ok; /* We are read-write already */ 1418 goto out_ok_unlocked; /* We are read-write already */
1421 } 1419 }
1422 1420
1423 if (reiserfs_is_journal_aborted(journal)) { 1421 if (reiserfs_is_journal_aborted(journal)) {
1424 err = journal->j_errno; 1422 err = journal->j_errno;
1425 goto out_unlock; 1423 goto out_err_unlock;
1426 } 1424 }
1427 1425
1428 handle_data_mode(s, mount_options); 1426 handle_data_mode(s, mount_options);
@@ -1431,7 +1429,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1431 s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */ 1429 s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */
1432 err = journal_begin(&th, s, 10); 1430 err = journal_begin(&th, s, 10);
1433 if (err) 1431 if (err)
1434 goto out_unlock; 1432 goto out_err_unlock;
1435 1433
1436 /* Mount a partition which is read-only, read-write */ 1434 /* Mount a partition which is read-only, read-write */
1437 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1); 1435 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
@@ -1448,26 +1446,22 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1448 SB_JOURNAL(s)->j_must_wait = 1; 1446 SB_JOURNAL(s)->j_must_wait = 1;
1449 err = journal_end(&th, s, 10); 1447 err = journal_end(&th, s, 10);
1450 if (err) 1448 if (err)
1451 goto out_unlock; 1449 goto out_err_unlock;
1452 1450
1451 reiserfs_write_unlock(s);
1453 if (!(*mount_flags & MS_RDONLY)) { 1452 if (!(*mount_flags & MS_RDONLY)) {
1454 /*
1455 * Drop write lock. Quota will retake it when needed and lock
1456 * ordering requires calling dquot_resume() without it.
1457 */
1458 reiserfs_write_unlock(s);
1459 dquot_resume(s, -1); 1453 dquot_resume(s, -1);
1460 reiserfs_write_lock(s); 1454 reiserfs_write_lock(s);
1461 finish_unfinished(s); 1455 finish_unfinished(s);
1456 reiserfs_write_unlock(s);
1462 reiserfs_xattr_init(s, *mount_flags); 1457 reiserfs_xattr_init(s, *mount_flags);
1463 } 1458 }
1464 1459
1465out_ok: 1460out_ok_unlocked:
1466 replace_mount_options(s, new_opts); 1461 replace_mount_options(s, new_opts);
1467 reiserfs_write_unlock(s);
1468 return 0; 1462 return 0;
1469 1463
1470out_unlock: 1464out_err_unlock:
1471 reiserfs_write_unlock(s); 1465 reiserfs_write_unlock(s);
1472out_err: 1466out_err:
1473 kfree(new_opts); 1467 kfree(new_opts);
@@ -2014,12 +2008,14 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
2014 goto error; 2008 goto error;
2015 } 2009 }
2016 2010
2011 reiserfs_write_unlock(s);
2017 if ((errval = reiserfs_lookup_privroot(s)) || 2012 if ((errval = reiserfs_lookup_privroot(s)) ||
2018 (errval = reiserfs_xattr_init(s, s->s_flags))) { 2013 (errval = reiserfs_xattr_init(s, s->s_flags))) {
2019 dput(s->s_root); 2014 dput(s->s_root);
2020 s->s_root = NULL; 2015 s->s_root = NULL;
2021 goto error; 2016 goto error_unlocked;
2022 } 2017 }
2018 reiserfs_write_lock(s);
2023 2019
2024 /* look for files which were to be removed in previous session */ 2020 /* look for files which were to be removed in previous session */
2025 finish_unfinished(s); 2021 finish_unfinished(s);
@@ -2028,12 +2024,14 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
2028 reiserfs_info(s, "using 3.5.x disk format\n"); 2024 reiserfs_info(s, "using 3.5.x disk format\n");
2029 } 2025 }
2030 2026
2027 reiserfs_write_unlock(s);
2031 if ((errval = reiserfs_lookup_privroot(s)) || 2028 if ((errval = reiserfs_lookup_privroot(s)) ||
2032 (errval = reiserfs_xattr_init(s, s->s_flags))) { 2029 (errval = reiserfs_xattr_init(s, s->s_flags))) {
2033 dput(s->s_root); 2030 dput(s->s_root);
2034 s->s_root = NULL; 2031 s->s_root = NULL;
2035 goto error; 2032 goto error_unlocked;
2036 } 2033 }
2034 reiserfs_write_lock(s);
2037 } 2035 }
2038 // mark hash in super block: it could be unset. overwrite should be ok 2036 // mark hash in super block: it could be unset. overwrite should be ok
2039 set_sb_hash_function_code(rs, function2code(sbi->s_hash_function)); 2037 set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index c69cdd749f09..8a9e2dcfe004 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -81,8 +81,7 @@ static int xattr_unlink(struct inode *dir, struct dentry *dentry)
81 int error; 81 int error;
82 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 82 BUG_ON(!mutex_is_locked(&dir->i_mutex));
83 83
84 reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex, 84 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD);
85 I_MUTEX_CHILD, dir->i_sb);
86 error = dir->i_op->unlink(dir, dentry); 85 error = dir->i_op->unlink(dir, dentry);
87 mutex_unlock(&dentry->d_inode->i_mutex); 86 mutex_unlock(&dentry->d_inode->i_mutex);
88 87
@@ -96,8 +95,7 @@ static int xattr_rmdir(struct inode *dir, struct dentry *dentry)
96 int error; 95 int error;
97 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 96 BUG_ON(!mutex_is_locked(&dir->i_mutex));
98 97
99 reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex, 98 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD);
100 I_MUTEX_CHILD, dir->i_sb);
101 error = dir->i_op->rmdir(dir, dentry); 99 error = dir->i_op->rmdir(dir, dentry);
102 if (!error) 100 if (!error)
103 dentry->d_inode->i_flags |= S_DEAD; 101 dentry->d_inode->i_flags |= S_DEAD;
@@ -232,22 +230,17 @@ static int reiserfs_for_each_xattr(struct inode *inode,
232 if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) 230 if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
233 return 0; 231 return 0;
234 232
235 reiserfs_write_unlock(inode->i_sb);
236 dir = open_xa_dir(inode, XATTR_REPLACE); 233 dir = open_xa_dir(inode, XATTR_REPLACE);
237 if (IS_ERR(dir)) { 234 if (IS_ERR(dir)) {
238 err = PTR_ERR(dir); 235 err = PTR_ERR(dir);
239 reiserfs_write_lock(inode->i_sb);
240 goto out; 236 goto out;
241 } else if (!dir->d_inode) { 237 } else if (!dir->d_inode) {
242 err = 0; 238 err = 0;
243 reiserfs_write_lock(inode->i_sb);
244 goto out_dir; 239 goto out_dir;
245 } 240 }
246 241
247 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); 242 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
248 243
249 reiserfs_write_lock(inode->i_sb);
250
251 buf.xadir = dir; 244 buf.xadir = dir;
252 while (1) { 245 while (1) {
253 err = reiserfs_readdir_inode(dir->d_inode, &buf.ctx); 246 err = reiserfs_readdir_inode(dir->d_inode, &buf.ctx);
@@ -281,14 +274,17 @@ static int reiserfs_for_each_xattr(struct inode *inode,
281 int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 + 274 int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 +
282 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb); 275 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
283 struct reiserfs_transaction_handle th; 276 struct reiserfs_transaction_handle th;
277 reiserfs_write_lock(inode->i_sb);
284 err = journal_begin(&th, inode->i_sb, blocks); 278 err = journal_begin(&th, inode->i_sb, blocks);
279 reiserfs_write_unlock(inode->i_sb);
285 if (!err) { 280 if (!err) {
286 int jerror; 281 int jerror;
287 reiserfs_mutex_lock_nested_safe( 282 mutex_lock_nested(&dir->d_parent->d_inode->i_mutex,
288 &dir->d_parent->d_inode->i_mutex, 283 I_MUTEX_XATTR);
289 I_MUTEX_XATTR, inode->i_sb);
290 err = action(dir, data); 284 err = action(dir, data);
285 reiserfs_write_lock(inode->i_sb);
291 jerror = journal_end(&th, inode->i_sb, blocks); 286 jerror = journal_end(&th, inode->i_sb, blocks);
287 reiserfs_write_unlock(inode->i_sb);
292 mutex_unlock(&dir->d_parent->d_inode->i_mutex); 288 mutex_unlock(&dir->d_parent->d_inode->i_mutex);
293 err = jerror ?: err; 289 err = jerror ?: err;
294 } 290 }
@@ -455,9 +451,7 @@ static int lookup_and_delete_xattr(struct inode *inode, const char *name)
455 } 451 }
456 452
457 if (dentry->d_inode) { 453 if (dentry->d_inode) {
458 reiserfs_write_lock(inode->i_sb);
459 err = xattr_unlink(xadir->d_inode, dentry); 454 err = xattr_unlink(xadir->d_inode, dentry);
460 reiserfs_write_unlock(inode->i_sb);
461 update_ctime(inode); 455 update_ctime(inode);
462 } 456 }
463 457
@@ -491,24 +485,17 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
491 if (get_inode_sd_version(inode) == STAT_DATA_V1) 485 if (get_inode_sd_version(inode) == STAT_DATA_V1)
492 return -EOPNOTSUPP; 486 return -EOPNOTSUPP;
493 487
494 reiserfs_write_unlock(inode->i_sb);
495
496 if (!buffer) { 488 if (!buffer) {
497 err = lookup_and_delete_xattr(inode, name); 489 err = lookup_and_delete_xattr(inode, name);
498 reiserfs_write_lock(inode->i_sb);
499 return err; 490 return err;
500 } 491 }
501 492
502 dentry = xattr_lookup(inode, name, flags); 493 dentry = xattr_lookup(inode, name, flags);
503 if (IS_ERR(dentry)) { 494 if (IS_ERR(dentry))
504 reiserfs_write_lock(inode->i_sb);
505 return PTR_ERR(dentry); 495 return PTR_ERR(dentry);
506 }
507 496
508 down_write(&REISERFS_I(inode)->i_xattr_sem); 497 down_write(&REISERFS_I(inode)->i_xattr_sem);
509 498
510 reiserfs_write_lock(inode->i_sb);
511
512 xahash = xattr_hash(buffer, buffer_size); 499 xahash = xattr_hash(buffer, buffer_size);
513 while (buffer_pos < buffer_size || buffer_pos == 0) { 500 while (buffer_pos < buffer_size || buffer_pos == 0) {
514 size_t chunk; 501 size_t chunk;
@@ -538,6 +525,7 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
538 rxh->h_hash = cpu_to_le32(xahash); 525 rxh->h_hash = cpu_to_le32(xahash);
539 } 526 }
540 527
528 reiserfs_write_lock(inode->i_sb);
541 err = __reiserfs_write_begin(page, page_offset, chunk + skip); 529 err = __reiserfs_write_begin(page, page_offset, chunk + skip);
542 if (!err) { 530 if (!err) {
543 if (buffer) 531 if (buffer)
@@ -546,6 +534,7 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
546 page_offset + chunk + 534 page_offset + chunk +
547 skip); 535 skip);
548 } 536 }
537 reiserfs_write_unlock(inode->i_sb);
549 unlock_page(page); 538 unlock_page(page);
550 reiserfs_put_page(page); 539 reiserfs_put_page(page);
551 buffer_pos += chunk; 540 buffer_pos += chunk;
@@ -563,10 +552,8 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
563 .ia_valid = ATTR_SIZE | ATTR_CTIME, 552 .ia_valid = ATTR_SIZE | ATTR_CTIME,
564 }; 553 };
565 554
566 reiserfs_write_unlock(inode->i_sb);
567 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR); 555 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR);
568 inode_dio_wait(dentry->d_inode); 556 inode_dio_wait(dentry->d_inode);
569 reiserfs_write_lock(inode->i_sb);
570 557
571 err = reiserfs_setattr(dentry, &newattrs); 558 err = reiserfs_setattr(dentry, &newattrs);
572 mutex_unlock(&dentry->d_inode->i_mutex); 559 mutex_unlock(&dentry->d_inode->i_mutex);
@@ -592,18 +579,19 @@ int reiserfs_xattr_set(struct inode *inode, const char *name,
592 579
593 reiserfs_write_lock(inode->i_sb); 580 reiserfs_write_lock(inode->i_sb);
594 error = journal_begin(&th, inode->i_sb, jbegin_count); 581 error = journal_begin(&th, inode->i_sb, jbegin_count);
582 reiserfs_write_unlock(inode->i_sb);
595 if (error) { 583 if (error) {
596 reiserfs_write_unlock(inode->i_sb);
597 return error; 584 return error;
598 } 585 }
599 586
600 error = reiserfs_xattr_set_handle(&th, inode, name, 587 error = reiserfs_xattr_set_handle(&th, inode, name,
601 buffer, buffer_size, flags); 588 buffer, buffer_size, flags);
602 589
590 reiserfs_write_lock(inode->i_sb);
603 error2 = journal_end(&th, inode->i_sb, jbegin_count); 591 error2 = journal_end(&th, inode->i_sb, jbegin_count);
592 reiserfs_write_unlock(inode->i_sb);
604 if (error == 0) 593 if (error == 0)
605 error = error2; 594 error = error2;
606 reiserfs_write_unlock(inode->i_sb);
607 595
608 return error; 596 return error;
609} 597}
@@ -968,7 +956,7 @@ int reiserfs_lookup_privroot(struct super_block *s)
968 int err = 0; 956 int err = 0;
969 957
970 /* If we don't have the privroot located yet - go find it */ 958 /* If we don't have the privroot located yet - go find it */
971 reiserfs_mutex_lock_safe(&s->s_root->d_inode->i_mutex, s); 959 mutex_lock(&s->s_root->d_inode->i_mutex);
972 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root, 960 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
973 strlen(PRIVROOT_NAME)); 961 strlen(PRIVROOT_NAME));
974 if (!IS_ERR(dentry)) { 962 if (!IS_ERR(dentry)) {
@@ -996,14 +984,14 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
996 goto error; 984 goto error;
997 985
998 if (!privroot->d_inode && !(mount_flags & MS_RDONLY)) { 986 if (!privroot->d_inode && !(mount_flags & MS_RDONLY)) {
999 reiserfs_mutex_lock_safe(&s->s_root->d_inode->i_mutex, s); 987 mutex_lock(&s->s_root->d_inode->i_mutex);
1000 err = create_privroot(REISERFS_SB(s)->priv_root); 988 err = create_privroot(REISERFS_SB(s)->priv_root);
1001 mutex_unlock(&s->s_root->d_inode->i_mutex); 989 mutex_unlock(&s->s_root->d_inode->i_mutex);
1002 } 990 }
1003 991
1004 if (privroot->d_inode) { 992 if (privroot->d_inode) {
1005 s->s_xattr = reiserfs_xattr_handlers; 993 s->s_xattr = reiserfs_xattr_handlers;
1006 reiserfs_mutex_lock_safe(&privroot->d_inode->i_mutex, s); 994 mutex_lock(&privroot->d_inode->i_mutex);
1007 if (!REISERFS_SB(s)->xattr_root) { 995 if (!REISERFS_SB(s)->xattr_root) {
1008 struct dentry *dentry; 996 struct dentry *dentry;
1009 dentry = lookup_one_len(XAROOT_NAME, privroot, 997 dentry = lookup_one_len(XAROOT_NAME, privroot,
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index 6c8767fdfc6a..06c04f73da65 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -49,13 +49,15 @@ posix_acl_set(struct dentry *dentry, const char *name, const void *value,
49 49
50 reiserfs_write_lock(inode->i_sb); 50 reiserfs_write_lock(inode->i_sb);
51 error = journal_begin(&th, inode->i_sb, jcreate_blocks); 51 error = journal_begin(&th, inode->i_sb, jcreate_blocks);
52 reiserfs_write_unlock(inode->i_sb);
52 if (error == 0) { 53 if (error == 0) {
53 error = reiserfs_set_acl(&th, inode, type, acl); 54 error = reiserfs_set_acl(&th, inode, type, acl);
55 reiserfs_write_lock(inode->i_sb);
54 error2 = journal_end(&th, inode->i_sb, jcreate_blocks); 56 error2 = journal_end(&th, inode->i_sb, jcreate_blocks);
57 reiserfs_write_unlock(inode->i_sb);
55 if (error2) 58 if (error2)
56 error = error2; 59 error = error2;
57 } 60 }
58 reiserfs_write_unlock(inode->i_sb);
59 61
60 release_and_out: 62 release_and_out:
61 posix_acl_release(acl); 63 posix_acl_release(acl);
@@ -435,12 +437,14 @@ int reiserfs_cache_default_acl(struct inode *inode)
435 return nblocks; 437 return nblocks;
436} 438}
437 439
440/*
441 * Called under i_mutex
442 */
438int reiserfs_acl_chmod(struct inode *inode) 443int reiserfs_acl_chmod(struct inode *inode)
439{ 444{
440 struct reiserfs_transaction_handle th; 445 struct reiserfs_transaction_handle th;
441 struct posix_acl *acl; 446 struct posix_acl *acl;
442 size_t size; 447 size_t size;
443 int depth;
444 int error; 448 int error;
445 449
446 if (IS_PRIVATE(inode)) 450 if (IS_PRIVATE(inode))
@@ -454,9 +458,7 @@ int reiserfs_acl_chmod(struct inode *inode)
454 return 0; 458 return 0;
455 } 459 }
456 460
457 reiserfs_write_unlock(inode->i_sb);
458 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); 461 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
459 reiserfs_write_lock(inode->i_sb);
460 if (!acl) 462 if (!acl)
461 return 0; 463 return 0;
462 if (IS_ERR(acl)) 464 if (IS_ERR(acl))
@@ -466,16 +468,18 @@ int reiserfs_acl_chmod(struct inode *inode)
466 return error; 468 return error;
467 469
468 size = reiserfs_xattr_nblocks(inode, reiserfs_acl_size(acl->a_count)); 470 size = reiserfs_xattr_nblocks(inode, reiserfs_acl_size(acl->a_count));
469 depth = reiserfs_write_lock_once(inode->i_sb); 471 reiserfs_write_lock(inode->i_sb);
470 error = journal_begin(&th, inode->i_sb, size * 2); 472 error = journal_begin(&th, inode->i_sb, size * 2);
473 reiserfs_write_unlock(inode->i_sb);
471 if (!error) { 474 if (!error) {
472 int error2; 475 int error2;
473 error = reiserfs_set_acl(&th, inode, ACL_TYPE_ACCESS, acl); 476 error = reiserfs_set_acl(&th, inode, ACL_TYPE_ACCESS, acl);
477 reiserfs_write_lock(inode->i_sb);
474 error2 = journal_end(&th, inode->i_sb, size * 2); 478 error2 = journal_end(&th, inode->i_sb, size * 2);
479 reiserfs_write_unlock(inode->i_sb);
475 if (error2) 480 if (error2)
476 error = error2; 481 error = error2;
477 } 482 }
478 reiserfs_write_unlock_once(inode->i_sb, depth);
479 posix_acl_release(acl); 483 posix_acl_release(acl);
480 return error; 484 return error;
481} 485}