1 From: Jeff Mahoney <jeffm@suse.com>
2 Subject: reiserfs: eliminate per-super xattr lock
4 With the switch to using inode->i_mutex locking during lookups/creation in
5 the xattr root, the per-super xattr lock is no longer needed.
9 Signed-off-by: Jeff Mahoney <jeffm@suse.com>
11 fs/reiserfs/inode.c | 14 -------
12 fs/reiserfs/namei.c | 29 ----------------
13 fs/reiserfs/super.c | 4 --
14 fs/reiserfs/xattr.c | 70 +++++++++++++++++++-------------------
15 fs/reiserfs/xattr_acl.c | 74 ++++++++++++++++++-----------------------
16 include/linux/reiserfs_fs.h | 3 -
17 include/linux/reiserfs_fs_sb.h | 3 -
18 include/linux/reiserfs_xattr.h | 28 ++-------------
19 8 files changed, 74 insertions(+), 151 deletions(-)
21 --- a/fs/reiserfs/inode.c
22 +++ b/fs/reiserfs/inode.c
23 @@ -1962,19 +1962,7 @@ int reiserfs_new_inode(struct reiserfs_t
26 th->t_trans_id = 0; /* so the caller can't use this handle later */
28 - /* If we were inheriting an ACL, we need to release the lock so that
29 - * iput doesn't deadlock in reiserfs_delete_xattrs. The locking
30 - * code really needs to be reworked, but this will take care of it
31 - * for now. -jeffm */
32 -#ifdef CONFIG_REISERFS_FS_POSIX_ACL
33 - if (REISERFS_I(dir)->i_acl_default && !IS_ERR(REISERFS_I(dir)->i_acl_default)) {
34 - reiserfs_write_unlock_xattrs(dir->i_sb);
36 - reiserfs_write_lock_xattrs(dir->i_sb);
44 --- a/fs/reiserfs/namei.c
45 +++ b/fs/reiserfs/namei.c
46 @@ -618,9 +618,6 @@ static int reiserfs_create(struct inode
48 reiserfs_write_lock(dir->i_sb);
51 - reiserfs_write_lock_xattrs(dir->i_sb);
53 retval = journal_begin(&th, dir->i_sb, jbegin_count);
55 drop_new_inode(inode);
56 @@ -633,11 +630,6 @@ static int reiserfs_create(struct inode
61 - reiserfs_write_unlock_xattrs(dir->i_sb);
65 inode->i_op = &reiserfs_file_inode_operations;
66 inode->i_fop = &reiserfs_file_operations;
67 inode->i_mapping->a_ops = &reiserfs_address_space_operations;
68 @@ -662,8 +654,6 @@ static int reiserfs_create(struct inode
69 retval = journal_end(&th, dir->i_sb, jbegin_count);
73 - reiserfs_write_unlock_xattrs(dir->i_sb);
74 reiserfs_write_unlock(dir->i_sb);
77 @@ -693,9 +683,6 @@ static int reiserfs_mknod(struct inode *
79 reiserfs_write_lock(dir->i_sb);
82 - reiserfs_write_lock_xattrs(dir->i_sb);
84 retval = journal_begin(&th, dir->i_sb, jbegin_count);
86 drop_new_inode(inode);
87 @@ -709,11 +696,6 @@ static int reiserfs_mknod(struct inode *
92 - reiserfs_write_unlock_xattrs(dir->i_sb);
96 inode->i_op = &reiserfs_special_inode_operations;
97 init_special_inode(inode, inode->i_mode, rdev);
99 @@ -741,8 +723,6 @@ static int reiserfs_mknod(struct inode *
100 retval = journal_end(&th, dir->i_sb, jbegin_count);
104 - reiserfs_write_unlock_xattrs(dir->i_sb);
105 reiserfs_write_unlock(dir->i_sb);
108 @@ -772,8 +752,6 @@ static int reiserfs_mkdir(struct inode *
109 locked = reiserfs_cache_default_acl(dir);
111 reiserfs_write_lock(dir->i_sb);
113 - reiserfs_write_lock_xattrs(dir->i_sb);
115 retval = journal_begin(&th, dir->i_sb, jbegin_count);
117 @@ -795,11 +773,6 @@ static int reiserfs_mkdir(struct inode *
122 - reiserfs_write_unlock_xattrs(dir->i_sb);
126 reiserfs_update_inode_transaction(inode);
127 reiserfs_update_inode_transaction(dir);
129 @@ -827,8 +800,6 @@ static int reiserfs_mkdir(struct inode *
130 d_instantiate(dentry, inode);
131 retval = journal_end(&th, dir->i_sb, jbegin_count);
134 - reiserfs_write_unlock_xattrs(dir->i_sb);
135 reiserfs_write_unlock(dir->i_sb);
138 --- a/fs/reiserfs/super.c
139 +++ b/fs/reiserfs/super.c
140 @@ -1644,10 +1644,6 @@ static int reiserfs_fill_super(struct su
141 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
142 /* Preallocate by 16 blocks (17-1) at once */
143 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
144 -#ifdef CONFIG_REISERFS_FS_XATTR
145 - /* Initialize the rwsem for xattr dir */
146 - init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
148 /* setup default block allocator options */
149 reiserfs_init_alloc_options(s);
151 --- a/fs/reiserfs/xattr.c
152 +++ b/fs/reiserfs/xattr.c
154 * these are special cases for filesystem ACLs, they are interpreted by the
155 * kernel, in addition, they are negatively and positively cached and attached
156 * to the inode so that unnecessary lookups are avoided.
158 + * Locking works like so:
159 + * The xattr root (/.reiserfs_priv/xattrs) is protected by its i_mutex.
160 + * The xattr dir (/.reiserfs_priv/xattrs/<oid>.<gen>) is protected by
161 + * inode->xattr_sem.
162 + * The xattrs themselves are likewise protected by the xattr_sem.
165 #include <linux/reiserfs_fs.h>
166 @@ -392,16 +398,17 @@ reiserfs_delete_xattrs_filler(void *buf,
167 /* This is called w/ inode->i_mutex downed */
168 int reiserfs_delete_xattrs(struct inode *inode)
170 - struct dentry *dir, *root;
172 + struct dentry *dir, *root;
173 + struct reiserfs_transaction_handle th;
174 + int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 +
175 + 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
177 /* Skip out, an xattr has no xattrs associated with it */
178 if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
181 - reiserfs_read_lock_xattrs(inode->i_sb);
182 dir = open_xa_dir(inode, XATTR_REPLACE);
183 - reiserfs_read_unlock_xattrs(inode->i_sb);
187 @@ -416,18 +423,26 @@ int reiserfs_delete_xattrs(struct inode
191 - /* Leftovers besides . and .. -- that's not good. */
192 - if (dir->d_inode->i_nlink <= 2) {
193 - root = open_xa_root(inode->i_sb, XATTR_REPLACE);
194 - reiserfs_write_lock_xattrs(inode->i_sb);
195 + /* We start a transaction here to avoid a ABBA situation
196 + * between the xattr root's i_mutex and the journal lock.
197 + * Inode creation will inherit an ACL, which requires a
198 + * lookup. The lookup locks the xattr root i_mutex with a
199 + * transaction open. Inode deletion takes teh xattr root
200 + * i_mutex to delete the directory and then starts a
201 + * transaction inside it. Boom. This doesn't incur much
202 + * additional overhead since the reiserfs_rmdir transaction
203 + * will just nest inside the outer transaction. */
204 + err = journal_begin(&th, inode->i_sb, blocks);
207 + root = dget(dir->d_parent);
208 mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_XATTR);
209 err = xattr_rmdir(root->d_inode, dir);
210 + jerror = journal_end(&th, inode->i_sb, blocks);
211 mutex_unlock(&root->d_inode->i_mutex);
212 - reiserfs_write_unlock_xattrs(inode->i_sb);
215 - reiserfs_warning(inode->i_sb, "jdm-20006",
216 - "Couldn't remove all entries in directory");
218 + err = jerror ?: err;
222 @@ -437,6 +452,9 @@ out:
224 REISERFS_I(inode)->i_flags =
225 REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
227 + reiserfs_warning(inode->i_sb, "jdm-20004",
228 + "Couldn't remove all xattrs (%d)\n", err);
232 @@ -485,9 +503,7 @@ int reiserfs_chown_xattrs(struct inode *
233 if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
236 - reiserfs_read_lock_xattrs(inode->i_sb);
237 dir = open_xa_dir(inode, XATTR_REPLACE);
238 - reiserfs_read_unlock_xattrs(inode->i_sb);
240 if (PTR_ERR(dir) != -ENODATA)
242 @@ -731,6 +747,11 @@ reiserfs_xattr_get(const struct inode *i
246 + /* protect against concurrent access. xattrs are backed by
247 + * regular files, but they're not regular files. The updates
248 + * must be atomic from the perspective of the user. */
249 + mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR);
251 isize = i_size_read(dentry->d_inode);
252 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
254 @@ -798,6 +819,7 @@ reiserfs_xattr_get(const struct inode *i
258 + mutex_unlock(&dentry->d_inode->i_mutex);
262 @@ -834,7 +856,6 @@ int reiserfs_xattr_del(struct inode *ino
263 static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char *);
265 * Inode operation getxattr()
266 - * Preliminary locking: we down dentry->d_inode->i_mutex
269 reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
270 @@ -848,9 +869,7 @@ reiserfs_getxattr(struct dentry * dentry
273 reiserfs_read_lock_xattr_i(dentry->d_inode);
274 - reiserfs_read_lock_xattrs(dentry->d_sb);
275 err = xah->get(dentry->d_inode, name, buffer, size);
276 - reiserfs_read_unlock_xattrs(dentry->d_sb);
277 reiserfs_read_unlock_xattr_i(dentry->d_inode);
280 @@ -866,23 +885,13 @@ reiserfs_setxattr(struct dentry *dentry,
282 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
286 if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
287 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
290 reiserfs_write_lock_xattr_i(dentry->d_inode);
291 - lock = !has_xattr_dir(dentry->d_inode);
293 - reiserfs_write_lock_xattrs(dentry->d_sb);
295 - reiserfs_read_lock_xattrs(dentry->d_sb);
296 err = xah->set(dentry->d_inode, name, value, size, flags);
298 - reiserfs_write_unlock_xattrs(dentry->d_sb);
300 - reiserfs_read_unlock_xattrs(dentry->d_sb);
301 reiserfs_write_unlock_xattr_i(dentry->d_inode);
304 @@ -902,8 +911,6 @@ int reiserfs_removexattr(struct dentry *
307 reiserfs_write_lock_xattr_i(dentry->d_inode);
308 - reiserfs_read_lock_xattrs(dentry->d_sb);
310 /* Deletion pre-operation */
312 err = xah->del(dentry->d_inode, name);
313 @@ -917,7 +924,6 @@ int reiserfs_removexattr(struct dentry *
314 mark_inode_dirty(dentry->d_inode);
317 - reiserfs_read_unlock_xattrs(dentry->d_sb);
318 reiserfs_write_unlock_xattr_i(dentry->d_inode);
321 @@ -966,8 +972,6 @@ reiserfs_listxattr_filler(void *buf, con
324 * Inode operation listxattr()
326 - * Preliminary locking: we down dentry->d_inode->i_mutex
328 ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
330 @@ -983,9 +987,7 @@ ssize_t reiserfs_listxattr(struct dentry
333 reiserfs_read_lock_xattr_i(dentry->d_inode);
334 - reiserfs_read_lock_xattrs(dentry->d_sb);
335 dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE);
336 - reiserfs_read_unlock_xattrs(dentry->d_sb);
340 @@ -1114,11 +1116,9 @@ static int reiserfs_check_acl(struct ino
341 int error = -EAGAIN; /* do regular unix permission checks by default */
343 reiserfs_read_lock_xattr_i(inode);
344 - reiserfs_read_lock_xattrs(inode->i_sb);
346 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
348 - reiserfs_read_unlock_xattrs(inode->i_sb);
349 reiserfs_read_unlock_xattr_i(inode);
352 --- a/fs/reiserfs/xattr_acl.c
353 +++ b/fs/reiserfs/xattr_acl.c
354 @@ -172,6 +172,29 @@ static void *posix_acl_to_disk(const str
355 return ERR_PTR(-EINVAL);
358 +static inline void iset_acl(struct inode *inode, struct posix_acl **i_acl,
359 + struct posix_acl *acl)
361 + spin_lock(&inode->i_lock);
362 + if (*i_acl != ERR_PTR(-ENODATA))
363 + posix_acl_release(*i_acl);
364 + *i_acl = posix_acl_dup(acl);
365 + spin_unlock(&inode->i_lock);
368 +static inline struct posix_acl *iget_acl(struct inode *inode,
369 + struct posix_acl **i_acl)
371 + struct posix_acl *acl = ERR_PTR(-ENODATA);
373 + spin_lock(&inode->i_lock);
374 + if (*i_acl != ERR_PTR(-ENODATA))
375 + acl = posix_acl_dup(*i_acl);
376 + spin_unlock(&inode->i_lock);
382 * Inode operation get_posix_acl().
384 @@ -199,11 +222,11 @@ struct posix_acl *reiserfs_get_acl(struc
385 return ERR_PTR(-EINVAL);
388 - if (IS_ERR(*p_acl)) {
389 - if (PTR_ERR(*p_acl) == -ENODATA)
391 - } else if (*p_acl != NULL)
392 - return posix_acl_dup(*p_acl);
393 + acl = iget_acl(inode, p_acl);
394 + if (acl && !IS_ERR(acl))
396 + else if (PTR_ERR(acl) == -ENODATA)
399 size = reiserfs_xattr_get(inode, name, NULL, 0);
401 @@ -229,7 +252,7 @@ struct posix_acl *reiserfs_get_acl(struc
403 acl = posix_acl_from_disk(value, retval);
405 - *p_acl = posix_acl_dup(acl);
406 + iset_acl(inode, p_acl, acl);
410 @@ -300,16 +323,8 @@ reiserfs_set_acl(struct inode *inode, in
415 - /* Release the old one */
416 - if (!IS_ERR(*p_acl) && *p_acl)
417 - posix_acl_release(*p_acl);
420 - *p_acl = ERR_PTR(-ENODATA);
422 - *p_acl = posix_acl_dup(acl);
425 + iset_acl(inode, p_acl, acl);
429 @@ -404,9 +419,7 @@ int reiserfs_cache_default_acl(struct in
430 if (reiserfs_posixacl(inode->i_sb) && !IS_PRIVATE(inode)) {
431 struct posix_acl *acl;
432 reiserfs_read_lock_xattr_i(inode);
433 - reiserfs_read_lock_xattrs(inode->i_sb);
434 acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
435 - reiserfs_read_unlock_xattrs(inode->i_sb);
436 reiserfs_read_unlock_xattr_i(inode);
437 ret = (acl && !IS_ERR(acl));
439 @@ -429,9 +442,7 @@ int reiserfs_acl_chmod(struct inode *ino
443 - reiserfs_read_lock_xattrs(inode->i_sb);
444 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
445 - reiserfs_read_unlock_xattrs(inode->i_sb);
449 @@ -442,17 +453,8 @@ int reiserfs_acl_chmod(struct inode *ino
451 error = posix_acl_chmod_masq(clone, inode->i_mode);
453 - int lock = !has_xattr_dir(inode);
454 reiserfs_write_lock_xattr_i(inode);
456 - reiserfs_write_lock_xattrs(inode->i_sb);
458 - reiserfs_read_lock_xattrs(inode->i_sb);
459 error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone);
461 - reiserfs_write_unlock_xattrs(inode->i_sb);
463 - reiserfs_read_unlock_xattrs(inode->i_sb);
464 reiserfs_write_unlock_xattr_i(inode);
466 posix_acl_release(clone);
467 @@ -480,14 +482,9 @@ posix_acl_access_set(struct inode *inode
468 static int posix_acl_access_del(struct inode *inode, const char *name)
470 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
471 - struct posix_acl **acl = &reiserfs_i->i_acl_access;
472 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
474 - if (!IS_ERR(*acl) && *acl) {
475 - posix_acl_release(*acl);
476 - *acl = ERR_PTR(-ENODATA);
479 + iset_acl(inode, &reiserfs_i->i_acl_access, ERR_PTR(-ENODATA));
483 @@ -533,14 +530,9 @@ posix_acl_default_set(struct inode *inod
484 static int posix_acl_default_del(struct inode *inode, const char *name)
486 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
487 - struct posix_acl **acl = &reiserfs_i->i_acl_default;
488 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
490 - if (!IS_ERR(*acl) && *acl) {
491 - posix_acl_release(*acl);
492 - *acl = ERR_PTR(-ENODATA);
495 + iset_acl(inode, &reiserfs_i->i_acl_default, ERR_PTR(-ENODATA));
499 --- a/include/linux/reiserfs_fs.h
500 +++ b/include/linux/reiserfs_fs.h
501 @@ -2224,7 +2224,4 @@ int reiserfs_unpack(struct inode *inode,
502 #define reiserfs_write_lock( sb ) lock_kernel()
503 #define reiserfs_write_unlock( sb ) unlock_kernel()
506 -#define REISERFS_XATTR_DIR_SEM(s) (REISERFS_SB(s)->xattr_dir_sem)
508 #endif /* _LINUX_REISER_FS_H */
509 --- a/include/linux/reiserfs_fs_sb.h
510 +++ b/include/linux/reiserfs_fs_sb.h
511 @@ -402,9 +402,6 @@ struct reiserfs_sb_info {
512 spinlock_t bitmap_lock; /* this lock on now only used to protect reserved_blocks variable */
513 struct dentry *priv_root; /* root of /.reiserfs_priv */
514 struct dentry *xattr_root; /* root of /.reiserfs_priv/.xa */
515 -#ifdef CONFIG_REISERFS_FS_XATTR
516 - struct rw_semaphore xattr_dir_sem;
520 char *s_qf_names[MAXQUOTAS];
521 --- a/include/linux/reiserfs_xattr.h
522 +++ b/include/linux/reiserfs_xattr.h
523 @@ -67,45 +67,27 @@ extern struct reiserfs_xattr_handler use
524 extern struct reiserfs_xattr_handler trusted_handler;
525 extern struct reiserfs_xattr_handler security_handler;
527 -static inline void reiserfs_write_lock_xattrs(struct super_block *sb)
529 - down_write(&REISERFS_XATTR_DIR_SEM(sb));
531 -static inline void reiserfs_write_unlock_xattrs(struct super_block *sb)
533 - up_write(&REISERFS_XATTR_DIR_SEM(sb));
535 -static inline void reiserfs_read_lock_xattrs(struct super_block *sb)
537 - down_read(&REISERFS_XATTR_DIR_SEM(sb));
540 -static inline void reiserfs_read_unlock_xattrs(struct super_block *sb)
542 - up_read(&REISERFS_XATTR_DIR_SEM(sb));
545 static inline void reiserfs_write_lock_xattr_i(struct inode *inode)
547 - down_write(&REISERFS_I(inode)->xattr_sem);
548 + down_write(&REISERFS_I(inode)->i_xattr_sem);
550 static inline void reiserfs_write_unlock_xattr_i(struct inode *inode)
552 - up_write(&REISERFS_I(inode)->xattr_sem);
553 + up_write(&REISERFS_I(inode)->i_xattr_sem);
555 static inline void reiserfs_read_lock_xattr_i(struct inode *inode)
557 - down_read(&REISERFS_I(inode)->xattr_sem);
558 + down_read(&REISERFS_I(inode)->i_xattr_sem);
561 static inline void reiserfs_read_unlock_xattr_i(struct inode *inode)
563 - up_read(&REISERFS_I(inode)->xattr_sem);
564 + up_read(&REISERFS_I(inode)->i_xattr_sem);
567 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
569 - init_rwsem(&REISERFS_I(inode)->xattr_sem);
570 + init_rwsem(&REISERFS_I(inode)->i_xattr_sem);