aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs')
-rw-r--r--fs/reiserfs/file.c12
-rw-r--r--fs/reiserfs/hashes.c1
-rw-r--r--fs/reiserfs/inode.c42
-rw-r--r--fs/reiserfs/ioctl.c5
-rw-r--r--fs/reiserfs/journal.c32
-rw-r--r--fs/reiserfs/namei.c6
-rw-r--r--fs/reiserfs/super.c4
-rw-r--r--fs/reiserfs/tail_conversion.c2
-rw-r--r--fs/reiserfs/xattr.c60
-rw-r--r--fs/reiserfs/xattr_acl.c7
-rw-r--r--fs/reiserfs/xattr_trusted.c1
-rw-r--r--fs/reiserfs/xattr_user.c30
12 files changed, 92 insertions, 110 deletions
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index 7892a865b58..ad6fa964b0e 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -49,7 +49,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp)
49 } 49 }
50 50
51 reiserfs_write_lock(inode->i_sb); 51 reiserfs_write_lock(inode->i_sb);
52 down(&inode->i_sem); 52 mutex_lock(&inode->i_mutex);
53 /* freeing preallocation only involves relogging blocks that 53 /* freeing preallocation only involves relogging blocks that
54 * are already in the current transaction. preallocation gets 54 * are already in the current transaction. preallocation gets
55 * freed at the end of each transaction, so it is impossible for 55 * freed at the end of each transaction, so it is impossible for
@@ -100,7 +100,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp)
100 err = reiserfs_truncate_file(inode, 0); 100 err = reiserfs_truncate_file(inode, 0);
101 } 101 }
102 out: 102 out:
103 up(&inode->i_sem); 103 mutex_unlock(&inode->i_mutex);
104 reiserfs_write_unlock(inode->i_sb); 104 reiserfs_write_unlock(inode->i_sb);
105 return err; 105 return err;
106} 106}
@@ -1342,7 +1342,7 @@ static ssize_t reiserfs_file_write(struct file *file, /* the file we are going t
1342 if (unlikely(!access_ok(VERIFY_READ, buf, count))) 1342 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
1343 return -EFAULT; 1343 return -EFAULT;
1344 1344
1345 down(&inode->i_sem); // locks the entire file for just us 1345 mutex_lock(&inode->i_mutex); // locks the entire file for just us
1346 1346
1347 pos = *ppos; 1347 pos = *ppos;
1348 1348
@@ -1360,7 +1360,7 @@ static ssize_t reiserfs_file_write(struct file *file, /* the file we are going t
1360 if (res) 1360 if (res)
1361 goto out; 1361 goto out;
1362 1362
1363 inode_update_time(inode, 1); /* Both mtime and ctime */ 1363 file_update_time(file);
1364 1364
1365 // Ok, we are done with all the checks. 1365 // Ok, we are done with all the checks.
1366 1366
@@ -1532,12 +1532,12 @@ static ssize_t reiserfs_file_write(struct file *file, /* the file we are going t
1532 generic_osync_inode(inode, file->f_mapping, 1532 generic_osync_inode(inode, file->f_mapping,
1533 OSYNC_METADATA | OSYNC_DATA); 1533 OSYNC_METADATA | OSYNC_DATA);
1534 1534
1535 up(&inode->i_sem); 1535 mutex_unlock(&inode->i_mutex);
1536 reiserfs_async_progress_wait(inode->i_sb); 1536 reiserfs_async_progress_wait(inode->i_sb);
1537 return (already_written != 0) ? already_written : res; 1537 return (already_written != 0) ? already_written : res;
1538 1538
1539 out: 1539 out:
1540 up(&inode->i_sem); // unlock the file on exit. 1540 mutex_unlock(&inode->i_mutex); // unlock the file on exit.
1541 return res; 1541 return res;
1542} 1542}
1543 1543
diff --git a/fs/reiserfs/hashes.c b/fs/reiserfs/hashes.c
index 37c1306eb9b..a3ec238fd9e 100644
--- a/fs/reiserfs/hashes.c
+++ b/fs/reiserfs/hashes.c
@@ -19,6 +19,7 @@
19// 19//
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/reiserfs_fs.h>
22#include <asm/types.h> 23#include <asm/types.h>
23#include <asm/bug.h> 24#include <asm/bug.h>
24 25
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 5f82352b97e..ffa34b861bd 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -32,6 +32,7 @@ void reiserfs_delete_inode(struct inode *inode)
32 JOURNAL_PER_BALANCE_CNT * 2 + 32 JOURNAL_PER_BALANCE_CNT * 2 +
33 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); 33 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb);
34 struct reiserfs_transaction_handle th; 34 struct reiserfs_transaction_handle th;
35 int err;
35 36
36 truncate_inode_pages(&inode->i_data, 0); 37 truncate_inode_pages(&inode->i_data, 0);
37 38
@@ -39,32 +40,36 @@ void reiserfs_delete_inode(struct inode *inode)
39 40
40 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ 41 /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */
41 if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */ 42 if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */
42 down(&inode->i_sem); 43 mutex_lock(&inode->i_mutex);
43 44
44 reiserfs_delete_xattrs(inode); 45 reiserfs_delete_xattrs(inode);
45 46
46 if (journal_begin(&th, inode->i_sb, jbegin_count)) { 47 if (journal_begin(&th, inode->i_sb, jbegin_count)) {
47 up(&inode->i_sem); 48 mutex_unlock(&inode->i_mutex);
48 goto out; 49 goto out;
49 } 50 }
50 reiserfs_update_inode_transaction(inode); 51 reiserfs_update_inode_transaction(inode);
51 52
52 if (reiserfs_delete_object(&th, inode)) { 53 err = reiserfs_delete_object(&th, inode);
53 up(&inode->i_sem);
54 goto out;
55 }
56 54
57 /* Do quota update inside a transaction for journaled quotas. We must do that 55 /* Do quota update inside a transaction for journaled quotas. We must do that
58 * after delete_object so that quota updates go into the same transaction as 56 * after delete_object so that quota updates go into the same transaction as
59 * stat data deletion */ 57 * stat data deletion */
60 DQUOT_FREE_INODE(inode); 58 if (!err)
59 DQUOT_FREE_INODE(inode);
61 60
62 if (journal_end(&th, inode->i_sb, jbegin_count)) { 61 if (journal_end(&th, inode->i_sb, jbegin_count)) {
63 up(&inode->i_sem); 62 mutex_unlock(&inode->i_mutex);
64 goto out; 63 goto out;
65 } 64 }
66 65
67 up(&inode->i_sem); 66 mutex_unlock(&inode->i_mutex);
67
68 /* check return value from reiserfs_delete_object after
69 * ending the transaction
70 */
71 if (err)
72 goto out;
68 73
69 /* all items of file are deleted, so we can remove "save" link */ 74 /* all items of file are deleted, so we can remove "save" link */
70 remove_save_link(inode, 0 /* not truncate */ ); /* we can't do anything 75 remove_save_link(inode, 0 /* not truncate */ ); /* we can't do anything
@@ -546,7 +551,7 @@ static int convert_tail_for_hole(struct inode *inode,
546 551
547 /* we don't have to make sure the conversion did not happen while 552 /* we don't have to make sure the conversion did not happen while
548 ** we were locking the page because anyone that could convert 553 ** we were locking the page because anyone that could convert
549 ** must first take i_sem. 554 ** must first take i_mutex.
550 ** 555 **
551 ** We must fix the tail page for writing because it might have buffers 556 ** We must fix the tail page for writing because it might have buffers
552 ** that are mapped, but have a block number of 0. This indicates tail 557 ** that are mapped, but have a block number of 0. This indicates tail
@@ -581,7 +586,7 @@ static inline int _allocate_block(struct reiserfs_transaction_handle *th,
581 BUG_ON(!th->t_trans_id); 586 BUG_ON(!th->t_trans_id);
582 587
583#ifdef REISERFS_PREALLOCATE 588#ifdef REISERFS_PREALLOCATE
584 if (!(flags & GET_BLOCK_NO_ISEM)) { 589 if (!(flags & GET_BLOCK_NO_IMUX)) {
585 return reiserfs_new_unf_blocknrs2(th, inode, allocated_block_nr, 590 return reiserfs_new_unf_blocknrs2(th, inode, allocated_block_nr,
586 path, block); 591 path, block);
587 } 592 }
@@ -2099,6 +2104,7 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
2099 struct page *page = NULL; 2104 struct page *page = NULL;
2100 int error; 2105 int error;
2101 struct buffer_head *bh = NULL; 2106 struct buffer_head *bh = NULL;
2107 int err2;
2102 2108
2103 reiserfs_write_lock(p_s_inode->i_sb); 2109 reiserfs_write_lock(p_s_inode->i_sb);
2104 2110
@@ -2136,14 +2142,18 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
2136 transaction of truncating gets committed - on reboot the file 2142 transaction of truncating gets committed - on reboot the file
2137 either appears truncated properly or not truncated at all */ 2143 either appears truncated properly or not truncated at all */
2138 add_save_link(&th, p_s_inode, 1); 2144 add_save_link(&th, p_s_inode, 1);
2139 error = reiserfs_do_truncate(&th, p_s_inode, page, update_timestamps); 2145 err2 = reiserfs_do_truncate(&th, p_s_inode, page, update_timestamps);
2140 if (error)
2141 goto out;
2142 error = 2146 error =
2143 journal_end(&th, p_s_inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1); 2147 journal_end(&th, p_s_inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1);
2144 if (error) 2148 if (error)
2145 goto out; 2149 goto out;
2146 2150
2151 /* check reiserfs_do_truncate after ending the transaction */
2152 if (err2) {
2153 error = err2;
2154 goto out;
2155 }
2156
2147 if (update_timestamps) { 2157 if (update_timestamps) {
2148 error = remove_save_link(p_s_inode, 1 /* truncate */ ); 2158 error = remove_save_link(p_s_inode, 1 /* truncate */ );
2149 if (error) 2159 if (error)
@@ -2194,7 +2204,7 @@ static int map_block_for_writepage(struct inode *inode,
2194 INITIALIZE_PATH(path); 2204 INITIALIZE_PATH(path);
2195 int pos_in_item; 2205 int pos_in_item;
2196 int jbegin_count = JOURNAL_PER_BALANCE_CNT; 2206 int jbegin_count = JOURNAL_PER_BALANCE_CNT;
2197 loff_t byte_offset = (block << inode->i_sb->s_blocksize_bits) + 1; 2207 loff_t byte_offset = ((loff_t)block << inode->i_sb->s_blocksize_bits)+1;
2198 int retval; 2208 int retval;
2199 int use_get_block = 0; 2209 int use_get_block = 0;
2200 int bytes_copied = 0; 2210 int bytes_copied = 0;
@@ -2308,7 +2318,7 @@ static int map_block_for_writepage(struct inode *inode,
2308 /* this is where we fill in holes in the file. */ 2318 /* this is where we fill in holes in the file. */
2309 if (use_get_block) { 2319 if (use_get_block) {
2310 retval = reiserfs_get_block(inode, block, bh_result, 2320 retval = reiserfs_get_block(inode, block, bh_result,
2311 GET_BLOCK_CREATE | GET_BLOCK_NO_ISEM 2321 GET_BLOCK_CREATE | GET_BLOCK_NO_IMUX
2312 | GET_BLOCK_NO_DANGLE); 2322 | GET_BLOCK_NO_DANGLE);
2313 if (!retval) { 2323 if (!retval) {
2314 if (!buffer_mapped(bh_result) 2324 if (!buffer_mapped(bh_result)
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index 81fc00285f6..745c8810089 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -2,6 +2,7 @@
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README 2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 */ 3 */
4 4
5#include <linux/capability.h>
5#include <linux/fs.h> 6#include <linux/fs.h>
6#include <linux/reiserfs_fs.h> 7#include <linux/reiserfs_fs.h>
7#include <linux/time.h> 8#include <linux/time.h>
@@ -120,7 +121,7 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp)
120 /* we need to make sure nobody is changing the file size beneath 121 /* we need to make sure nobody is changing the file size beneath
121 ** us 122 ** us
122 */ 123 */
123 down(&inode->i_sem); 124 mutex_lock(&inode->i_mutex);
124 125
125 write_from = inode->i_size & (blocksize - 1); 126 write_from = inode->i_size & (blocksize - 1);
126 /* if we are on a block boundary, we are already unpacked. */ 127 /* if we are on a block boundary, we are already unpacked. */
@@ -156,7 +157,7 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp)
156 page_cache_release(page); 157 page_cache_release(page);
157 158
158 out: 159 out:
159 up(&inode->i_sem); 160 mutex_unlock(&inode->i_mutex);
160 reiserfs_write_unlock(inode->i_sb); 161 reiserfs_write_unlock(inode->i_sb);
161 return retval; 162 return retval;
162} 163}
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 4b15761434b..4491fcf2a0e 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -1039,6 +1039,10 @@ static int flush_commit_list(struct super_block *s,
1039 } 1039 }
1040 atomic_dec(&journal->j_async_throttle); 1040 atomic_dec(&journal->j_async_throttle);
1041 1041
1042 /* We're skipping the commit if there's an error */
1043 if (retval || reiserfs_is_journal_aborted(journal))
1044 barrier = 0;
1045
1042 /* wait on everything written so far before writing the commit 1046 /* wait on everything written so far before writing the commit
1043 * if we are in barrier mode, send the commit down now 1047 * if we are in barrier mode, send the commit down now
1044 */ 1048 */
@@ -1077,10 +1081,16 @@ static int flush_commit_list(struct super_block *s,
1077 BUG_ON(atomic_read(&(jl->j_commit_left)) != 1); 1081 BUG_ON(atomic_read(&(jl->j_commit_left)) != 1);
1078 1082
1079 if (!barrier) { 1083 if (!barrier) {
1080 if (buffer_dirty(jl->j_commit_bh)) 1084 /* If there was a write error in the journal - we can't commit
1081 BUG(); 1085 * this transaction - it will be invalid and, if successful,
1082 mark_buffer_dirty(jl->j_commit_bh); 1086 * will just end up propogating the write error out to
1083 sync_dirty_buffer(jl->j_commit_bh); 1087 * the file system. */
1088 if (likely(!retval && !reiserfs_is_journal_aborted (journal))) {
1089 if (buffer_dirty(jl->j_commit_bh))
1090 BUG();
1091 mark_buffer_dirty(jl->j_commit_bh) ;
1092 sync_dirty_buffer(jl->j_commit_bh) ;
1093 }
1084 } else 1094 } else
1085 wait_on_buffer(jl->j_commit_bh); 1095 wait_on_buffer(jl->j_commit_bh);
1086 1096
@@ -2757,6 +2767,15 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2757 journal->j_cnode_used = 0; 2767 journal->j_cnode_used = 0;
2758 journal->j_must_wait = 0; 2768 journal->j_must_wait = 0;
2759 2769
2770 if (journal->j_cnode_free == 0) {
2771 reiserfs_warning(p_s_sb, "journal-2004: Journal cnode memory "
2772 "allocation failed (%ld bytes). Journal is "
2773 "too large for available memory. Usually "
2774 "this is due to a journal that is too large.",
2775 sizeof (struct reiserfs_journal_cnode) * num_cnodes);
2776 goto free_and_return;
2777 }
2778
2760 init_journal_hash(p_s_sb); 2779 init_journal_hash(p_s_sb);
2761 jl = journal->j_current_jl; 2780 jl = journal->j_current_jl;
2762 jl->j_list_bitmap = get_list_bitmap(p_s_sb, jl); 2781 jl->j_list_bitmap = get_list_bitmap(p_s_sb, jl);
@@ -3906,10 +3925,13 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
3906 flush = 1; 3925 flush = 1;
3907 } 3926 }
3908#ifdef REISERFS_PREALLOCATE 3927#ifdef REISERFS_PREALLOCATE
3909 /* quota ops might need to nest, setup the journal_info pointer for them */ 3928 /* quota ops might need to nest, setup the journal_info pointer for them
3929 * and raise the refcount so that it is > 0. */
3910 current->journal_info = th; 3930 current->journal_info = th;
3931 th->t_refcount++;
3911 reiserfs_discard_all_prealloc(th); /* it should not involve new blocks into 3932 reiserfs_discard_all_prealloc(th); /* it should not involve new blocks into
3912 * the transaction */ 3933 * the transaction */
3934 th->t_refcount--;
3913 current->journal_info = th->t_handle_save; 3935 current->journal_info = th->t_handle_save;
3914#endif 3936#endif
3915 3937
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index 3549067c42d..8f8d8d01107 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -375,11 +375,7 @@ static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
375 return ERR_PTR(-EIO); 375 return ERR_PTR(-EIO);
376 } 376 }
377 377
378 if (inode) 378 return d_splice_alias(inode, dentry);
379 return d_splice_alias(inode, dentry);
380
381 d_add(dentry, inode);
382 return NULL;
383} 379}
384 380
385/* 381/*
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 42afb5bef11..397d9590c8f 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -2211,7 +2211,7 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
2211 size_t towrite = len; 2211 size_t towrite = len;
2212 struct buffer_head tmp_bh, *bh; 2212 struct buffer_head tmp_bh, *bh;
2213 2213
2214 down(&inode->i_sem); 2214 mutex_lock(&inode->i_mutex);
2215 while (towrite > 0) { 2215 while (towrite > 0) {
2216 tocopy = sb->s_blocksize - offset < towrite ? 2216 tocopy = sb->s_blocksize - offset < towrite ?
2217 sb->s_blocksize - offset : towrite; 2217 sb->s_blocksize - offset : towrite;
@@ -2250,7 +2250,7 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
2250 inode->i_version++; 2250 inode->i_version++;
2251 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 2251 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2252 mark_inode_dirty(inode); 2252 mark_inode_dirty(inode);
2253 up(&inode->i_sem); 2253 mutex_unlock(&inode->i_mutex);
2254 return len - towrite; 2254 return len - towrite;
2255} 2255}
2256 2256
diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c
index c92e124f628..196e971c03c 100644
--- a/fs/reiserfs/tail_conversion.c
+++ b/fs/reiserfs/tail_conversion.c
@@ -205,7 +205,7 @@ int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_in
205 1) * p_s_sb->s_blocksize; 205 1) * p_s_sb->s_blocksize;
206 pos1 = pos; 206 pos1 = pos;
207 207
208 // we are protected by i_sem. The tail can not disapper, not 208 // we are protected by i_mutex. The tail can not disapper, not
209 // append can be done either 209 // append can be done either
210 // we are in truncate or packing tail in file_release 210 // we are in truncate or packing tail in file_release
211 211
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index 72e12079867..cc061bfd437 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -30,6 +30,7 @@
30 */ 30 */
31 31
32#include <linux/reiserfs_fs.h> 32#include <linux/reiserfs_fs.h>
33#include <linux/capability.h>
33#include <linux/dcache.h> 34#include <linux/dcache.h>
34#include <linux/namei.h> 35#include <linux/namei.h>
35#include <linux/errno.h> 36#include <linux/errno.h>
@@ -67,11 +68,11 @@ static struct dentry *create_xa_root(struct super_block *sb)
67 goto out; 68 goto out;
68 } else if (!xaroot->d_inode) { 69 } else if (!xaroot->d_inode) {
69 int err; 70 int err;
70 down(&privroot->d_inode->i_sem); 71 mutex_lock(&privroot->d_inode->i_mutex);
71 err = 72 err =
72 privroot->d_inode->i_op->mkdir(privroot->d_inode, xaroot, 73 privroot->d_inode->i_op->mkdir(privroot->d_inode, xaroot,
73 0700); 74 0700);
74 up(&privroot->d_inode->i_sem); 75 mutex_unlock(&privroot->d_inode->i_mutex);
75 76
76 if (err) { 77 if (err) {
77 dput(xaroot); 78 dput(xaroot);
@@ -115,8 +116,8 @@ static struct dentry *__get_xa_root(struct super_block *s)
115} 116}
116 117
117/* Returns the dentry (or NULL) referring to the root of the extended 118/* Returns the dentry (or NULL) referring to the root of the extended
118 * attribute directory tree. If it has already been retreived, it is used. 119 * attribute directory tree. If it has already been retrieved, it is used.
119 * Otherwise, we attempt to retreive it from disk. It may also return 120 * Otherwise, we attempt to retrieve it from disk. It may also return
120 * a pointer-encoded error. 121 * a pointer-encoded error.
121 */ 122 */
122static inline struct dentry *get_xa_root(struct super_block *s) 123static inline struct dentry *get_xa_root(struct super_block *s)
@@ -219,7 +220,7 @@ static struct dentry *get_xa_file_dentry(const struct inode *inode,
219 } else if (flags & XATTR_REPLACE || flags & FL_READONLY) { 220 } else if (flags & XATTR_REPLACE || flags & FL_READONLY) {
220 goto out; 221 goto out;
221 } else { 222 } else {
222 /* inode->i_sem is down, so nothing else can try to create 223 /* inode->i_mutex is down, so nothing else can try to create
223 * the same xattr */ 224 * the same xattr */
224 err = xadir->d_inode->i_op->create(xadir->d_inode, xafile, 225 err = xadir->d_inode->i_op->create(xadir->d_inode, xafile,
225 0700 | S_IFREG, NULL); 226 0700 | S_IFREG, NULL);
@@ -268,7 +269,7 @@ static struct file *open_xa_file(const struct inode *inode, const char *name,
268 * and don't mess with f->f_pos, but the idea is the same. Do some 269 * and don't mess with f->f_pos, but the idea is the same. Do some
269 * action on each and every entry in the directory. 270 * action on each and every entry in the directory.
270 * 271 *
271 * we're called with i_sem held, so there are no worries about the directory 272 * we're called with i_mutex held, so there are no worries about the directory
272 * changing underneath us. 273 * changing underneath us.
273 */ 274 */
274static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir) 275static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
@@ -426,7 +427,7 @@ int xattr_readdir(struct file *file, filldir_t filler, void *buf)
426 int res = -ENOTDIR; 427 int res = -ENOTDIR;
427 if (!file->f_op || !file->f_op->readdir) 428 if (!file->f_op || !file->f_op->readdir)
428 goto out; 429 goto out;
429 down(&inode->i_sem); 430 mutex_lock(&inode->i_mutex);
430// down(&inode->i_zombie); 431// down(&inode->i_zombie);
431 res = -ENOENT; 432 res = -ENOENT;
432 if (!IS_DEADDIR(inode)) { 433 if (!IS_DEADDIR(inode)) {
@@ -435,7 +436,7 @@ int xattr_readdir(struct file *file, filldir_t filler, void *buf)
435 unlock_kernel(); 436 unlock_kernel();
436 } 437 }
437// up(&inode->i_zombie); 438// up(&inode->i_zombie);
438 up(&inode->i_sem); 439 mutex_unlock(&inode->i_mutex);
439 out: 440 out:
440 return res; 441 return res;
441} 442}
@@ -480,7 +481,7 @@ static inline __u32 xattr_hash(const char *msg, int len)
480/* Generic extended attribute operations that can be used by xa plugins */ 481/* Generic extended attribute operations that can be used by xa plugins */
481 482
482/* 483/*
483 * inode->i_sem: down 484 * inode->i_mutex: down
484 */ 485 */
485int 486int
486reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer, 487reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
@@ -497,12 +498,6 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
497 struct iattr newattrs; 498 struct iattr newattrs;
498 __u32 xahash = 0; 499 __u32 xahash = 0;
499 500
500 if (IS_RDONLY(inode))
501 return -EROFS;
502
503 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
504 return -EPERM;
505
506 if (get_inode_sd_version(inode) == STAT_DATA_V1) 501 if (get_inode_sd_version(inode) == STAT_DATA_V1)
507 return -EOPNOTSUPP; 502 return -EOPNOTSUPP;
508 503
@@ -535,7 +530,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
535 /* Resize it so we're ok to write there */ 530 /* Resize it so we're ok to write there */
536 newattrs.ia_size = buffer_size; 531 newattrs.ia_size = buffer_size;
537 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 532 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
538 down(&xinode->i_sem); 533 mutex_lock(&xinode->i_mutex);
539 err = notify_change(fp->f_dentry, &newattrs); 534 err = notify_change(fp->f_dentry, &newattrs);
540 if (err) 535 if (err)
541 goto out_filp; 536 goto out_filp;
@@ -598,7 +593,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
598 } 593 }
599 594
600 out_filp: 595 out_filp:
601 up(&xinode->i_sem); 596 mutex_unlock(&xinode->i_mutex);
602 fput(fp); 597 fput(fp);
603 598
604 out: 599 out:
@@ -606,7 +601,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
606} 601}
607 602
608/* 603/*
609 * inode->i_sem: down 604 * inode->i_mutex: down
610 */ 605 */
611int 606int
612reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer, 607reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
@@ -758,9 +753,6 @@ int reiserfs_xattr_del(struct inode *inode, const char *name)
758 struct dentry *dir; 753 struct dentry *dir;
759 int err; 754 int err;
760 755
761 if (IS_RDONLY(inode))
762 return -EROFS;
763
764 dir = open_xa_dir(inode, FL_READONLY); 756 dir = open_xa_dir(inode, FL_READONLY);
765 if (IS_ERR(dir)) { 757 if (IS_ERR(dir)) {
766 err = PTR_ERR(dir); 758 err = PTR_ERR(dir);
@@ -793,7 +785,7 @@ reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
793 785
794} 786}
795 787
796/* This is called w/ inode->i_sem downed */ 788/* This is called w/ inode->i_mutex downed */
797int reiserfs_delete_xattrs(struct inode *inode) 789int reiserfs_delete_xattrs(struct inode *inode)
798{ 790{
799 struct file *fp; 791 struct file *fp;
@@ -946,7 +938,7 @@ int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
946 938
947/* 939/*
948 * Inode operation getxattr() 940 * Inode operation getxattr()
949 * Preliminary locking: we down dentry->d_inode->i_sem 941 * Preliminary locking: we down dentry->d_inode->i_mutex
950 */ 942 */
951ssize_t 943ssize_t
952reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, 944reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
@@ -970,7 +962,7 @@ reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
970/* 962/*
971 * Inode operation setxattr() 963 * Inode operation setxattr()
972 * 964 *
973 * dentry->d_inode->i_sem down 965 * dentry->d_inode->i_mutex down
974 */ 966 */
975int 967int
976reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, 968reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
@@ -984,12 +976,6 @@ reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
984 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 976 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
985 return -EOPNOTSUPP; 977 return -EOPNOTSUPP;
986 978
987 if (IS_RDONLY(dentry->d_inode))
988 return -EROFS;
989
990 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode))
991 return -EROFS;
992
993 reiserfs_write_lock_xattr_i(dentry->d_inode); 979 reiserfs_write_lock_xattr_i(dentry->d_inode);
994 lock = !has_xattr_dir(dentry->d_inode); 980 lock = !has_xattr_dir(dentry->d_inode);
995 if (lock) 981 if (lock)
@@ -1008,7 +994,7 @@ reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
1008/* 994/*
1009 * Inode operation removexattr() 995 * Inode operation removexattr()
1010 * 996 *
1011 * dentry->d_inode->i_sem down 997 * dentry->d_inode->i_mutex down
1012 */ 998 */
1013int reiserfs_removexattr(struct dentry *dentry, const char *name) 999int reiserfs_removexattr(struct dentry *dentry, const char *name)
1014{ 1000{
@@ -1019,12 +1005,6 @@ int reiserfs_removexattr(struct dentry *dentry, const char *name)
1019 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 1005 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
1020 return -EOPNOTSUPP; 1006 return -EOPNOTSUPP;
1021 1007
1022 if (IS_RDONLY(dentry->d_inode))
1023 return -EROFS;
1024
1025 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode))
1026 return -EPERM;
1027
1028 reiserfs_write_lock_xattr_i(dentry->d_inode); 1008 reiserfs_write_lock_xattr_i(dentry->d_inode);
1029 reiserfs_read_lock_xattrs(dentry->d_sb); 1009 reiserfs_read_lock_xattrs(dentry->d_sb);
1030 1010
@@ -1091,7 +1071,7 @@ reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
1091/* 1071/*
1092 * Inode operation listxattr() 1072 * Inode operation listxattr()
1093 * 1073 *
1094 * Preliminary locking: we down dentry->d_inode->i_sem 1074 * Preliminary locking: we down dentry->d_inode->i_mutex
1095 */ 1075 */
1096ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) 1076ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
1097{ 1077{
@@ -1289,9 +1269,9 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1289 if (!IS_ERR(dentry)) { 1269 if (!IS_ERR(dentry)) {
1290 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) { 1270 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) {
1291 struct inode *inode = dentry->d_parent->d_inode; 1271 struct inode *inode = dentry->d_parent->d_inode;
1292 down(&inode->i_sem); 1272 mutex_lock(&inode->i_mutex);
1293 err = inode->i_op->mkdir(inode, dentry, 0700); 1273 err = inode->i_op->mkdir(inode, dentry, 0700);
1294 up(&inode->i_sem); 1274 mutex_unlock(&inode->i_mutex);
1295 if (err) { 1275 if (err) {
1296 dput(dentry); 1276 dput(dentry);
1297 dentry = NULL; 1277 dentry = NULL;
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index a47ac9aac8b..43de3ba8333 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -1,3 +1,4 @@
1#include <linux/capability.h>
1#include <linux/fs.h> 2#include <linux/fs.h>
2#include <linux/posix_acl.h> 3#include <linux/posix_acl.h>
3#include <linux/reiserfs_fs.h> 4#include <linux/reiserfs_fs.h>
@@ -174,7 +175,7 @@ static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
174/* 175/*
175 * Inode operation get_posix_acl(). 176 * Inode operation get_posix_acl().
176 * 177 *
177 * inode->i_sem: down 178 * inode->i_mutex: down
178 * BKL held [before 2.5.x] 179 * BKL held [before 2.5.x]
179 */ 180 */
180struct posix_acl *reiserfs_get_acl(struct inode *inode, int type) 181struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
@@ -237,7 +238,7 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
237/* 238/*
238 * Inode operation set_posix_acl(). 239 * Inode operation set_posix_acl().
239 * 240 *
240 * inode->i_sem: down 241 * inode->i_mutex: down
241 * BKL held [before 2.5.x] 242 * BKL held [before 2.5.x]
242 */ 243 */
243static int 244static int
@@ -312,7 +313,7 @@ reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
312 return error; 313 return error;
313} 314}
314 315
315/* dir->i_sem: down, 316/* dir->i_mutex: locked,
316 * inode is new and not released into the wild yet */ 317 * inode is new and not released into the wild yet */
317int 318int
318reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry, 319reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
diff --git a/fs/reiserfs/xattr_trusted.c b/fs/reiserfs/xattr_trusted.c
index 2501f7e66ab..024a938ca60 100644
--- a/fs/reiserfs/xattr_trusted.c
+++ b/fs/reiserfs/xattr_trusted.c
@@ -1,4 +1,5 @@
1#include <linux/reiserfs_fs.h> 1#include <linux/reiserfs_fs.h>
2#include <linux/capability.h>
2#include <linux/errno.h> 3#include <linux/errno.h>
3#include <linux/fs.h> 4#include <linux/fs.h>
4#include <linux/pagemap.h> 5#include <linux/pagemap.h>
diff --git a/fs/reiserfs/xattr_user.c b/fs/reiserfs/xattr_user.c
index 51458048ca6..073f39364b1 100644
--- a/fs/reiserfs/xattr_user.c
+++ b/fs/reiserfs/xattr_user.c
@@ -16,18 +16,10 @@ static int
16user_get(struct inode *inode, const char *name, void *buffer, size_t size) 16user_get(struct inode *inode, const char *name, void *buffer, size_t size)
17{ 17{
18 18
19 int error;
20
21 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 19 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
22 return -EINVAL; 20 return -EINVAL;
23
24 if (!reiserfs_xattrs_user(inode->i_sb)) 21 if (!reiserfs_xattrs_user(inode->i_sb))
25 return -EOPNOTSUPP; 22 return -EOPNOTSUPP;
26
27 error = reiserfs_permission_locked(inode, MAY_READ, NULL);
28 if (error)
29 return error;
30
31 return reiserfs_xattr_get(inode, name, buffer, size); 23 return reiserfs_xattr_get(inode, name, buffer, size);
32} 24}
33 25
@@ -36,43 +28,21 @@ user_set(struct inode *inode, const char *name, const void *buffer,
36 size_t size, int flags) 28 size_t size, int flags)
37{ 29{
38 30
39 int error;
40
41 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 31 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
42 return -EINVAL; 32 return -EINVAL;
43 33
44 if (!reiserfs_xattrs_user(inode->i_sb)) 34 if (!reiserfs_xattrs_user(inode->i_sb))
45 return -EOPNOTSUPP; 35 return -EOPNOTSUPP;
46
47 if (!S_ISREG(inode->i_mode) &&
48 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
49 return -EPERM;
50
51 error = reiserfs_permission_locked(inode, MAY_WRITE, NULL);
52 if (error)
53 return error;
54
55 return reiserfs_xattr_set(inode, name, buffer, size, flags); 36 return reiserfs_xattr_set(inode, name, buffer, size, flags);
56} 37}
57 38
58static int user_del(struct inode *inode, const char *name) 39static int user_del(struct inode *inode, const char *name)
59{ 40{
60 int error;
61
62 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 41 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
63 return -EINVAL; 42 return -EINVAL;
64 43
65 if (!reiserfs_xattrs_user(inode->i_sb)) 44 if (!reiserfs_xattrs_user(inode->i_sb))
66 return -EOPNOTSUPP; 45 return -EOPNOTSUPP;
67
68 if (!S_ISREG(inode->i_mode) &&
69 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
70 return -EPERM;
71
72 error = reiserfs_permission_locked(inode, MAY_WRITE, NULL);
73 if (error)
74 return error;
75
76 return 0; 46 return 0;
77} 47}
78 48