Skip to contentSkip to conversation

BUG: reiserfs+acl+quota deadlock

DISCUSSION Tarmo Tänav 4 participants 13 messages Aug 10, 2005 – Aug 18, 2005

lore
Share & tools
lore
#0 lore raw

Hi,

I've already reported a similiar bug to the one I found now and that was fixed by:
"[PATCH] reiserfs: fix deadlock in inode creation failure path w/ default ACL"

This bug is similiar in effect but has some differences in how to trigger it. The end effect will be just like with the other bug that the affected directory will be unaccessible to any user or process.

So here's the way to reproduce it, as minimal as I could get it:

You need reiserfs, quota and acl support in kernel. you also need quota tools (edquota, quotaon, quotacheck), I used linuxquota 3.12.

# cd /mnt
# dd if=/dev/zero of=test bs=1M count=50
50+0 records in
50+0 records out
# mkreiserfs -f test >/dev/null
mkreiserfs 3.6.19 (2003 www.namesys.com)

test is not a block special device
Continue (y/n):y

# mkdir mpoint
# mount test mpoint -o loop,acl,usrquota
# mkdir mpoint/user1
# useradd -d /mnt/mpoint/user1 user1     # may also use existing user
# chown user1 mpoint/user1
# quotacheck -v mpoint                   # initializes quota file
# edquota user1
---- set soft block limit to 1000, hard limit to 4000 ----
# edquota -t
---- set the grace periods to something small: 1minutes ---
# quotaon mpoint
# ## at this point "repquota -a" should show the quota for user1
# su user1
# cd
# ## now we are in user1 home dir as user1
# cat /dev/zero > file1
loop2: warning, user block quota exceeded.
loop2: write failed, user block limit reached.
cat: write error: No space left on device
--- now we wait till the grace period expires (repquota -a) ----
# cat "" > otherfile
loop2: write failed, user block quota exceeded too long.
---- and it will hang forever ----
# ## /mnt/mpoint can still be accessed, but /mnt/mpoint/user1 can't

I tested this on an -mm patchset kernel (2.6.13-rc5-mm1), but I discovered the bug in my server which runs plain 2.6.12 with the patch from Jeff Mahoney for the first reiserfs+acl bug.

The main difference between the two bugs is that the first one requires the existance of a default acl, this one does not, but it does require acl to be enabled.

PS. please CC, I'm not subscribed to the list

Signature · 1 line
Tarmo Tänav <[email protected]>
#1 lore raw

Hello,

Quoted 51 lines

I've already reported a similiar bug to the one I found now and that was fixed by:
"[PATCH] reiserfs: fix deadlock in inode creation failure path w/ default ACL"

This bug is similiar in effect but has some differences in how to trigger it. The end effect will be just like with the other bug that the affected directory will be unaccessible to any user or process.

So here's the way to reproduce it, as minimal as I could get it:

You need reiserfs, quota and acl support in kernel. you also need quota tools (edquota, quotaon, quotacheck), I used linuxquota 3.12.

# cd /mnt
# dd if=/dev/zero of=test bs=1M count=50
50+0 records in
50+0 records out
# mkreiserfs -f test >/dev/null
mkreiserfs 3.6.19 (2003 www.namesys.com)

test is not a block special device
Continue (y/n):y

# mkdir mpoint
# mount test mpoint -o loop,acl,usrquota
# mkdir mpoint/user1
# useradd -d /mnt/mpoint/user1 user1     # may also use existing user
# chown user1 mpoint/user1
# quotacheck -v mpoint                   # initializes quota file
# edquota user1
---- set soft block limit to 1000, hard limit to 4000 ----
# edquota -t
---- set the grace periods to something small: 1minutes ---
# quotaon mpoint
# ## at this point "repquota -a" should show the quota for user1
# su user1
# cd
# ## now we are in user1 home dir as user1
# cat /dev/zero > file1
loop2: warning, user block quota exceeded.
loop2: write failed, user block limit reached.
cat: write error: No space left on device
--- now we wait till the grace period expires (repquota -a) ----
# cat "" > otherfile
loop2: write failed, user block quota exceeded too long.
---- and it will hang forever ----
# ## /mnt/mpoint can still be accessed, but /mnt/mpoint/user1 can't
Quoted 7 lines

I tested this on an -mm patchset kernel (2.6.13-rc5-mm1), but I discovered the bug in my server which runs plain 2.6.12 with the patch from Jeff Mahoney for the first reiserfs+acl bug.

The main difference between the two bugs is that the first one requires the existance of a default acl, this one does not, but it does require acl to be enabled.

This seems to be the same problem as bug #4771 that I've just fix. Can
you try attached patch please?
Andrew, can you include the patch into -mm if ReiserFS guys won't object?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs

Initialize key object ID in inode so that we don't try to remove the inode when we fail on some checks even before we manage to allocate something.

fs/reiserfs/namei.c +3 -0
diff -rupX /home/jack/.kerndiffexclude linux-2.6.13-rc6/fs/reiserfs/namei.c linux-2.6.13-rc6-reiser_create_fix/fs/reiserfs/namei.c
@@ -593,6 +593,9 @@ static int new_inode_init(struct inode *
 	 */
 	inode->i_uid = current->fsuid;
 	inode->i_mode = mode;
+	/* Make inode invalid - just in case we are going to drop it before
+	 * the initialization happens */
+	INODE_PKEY(inode)->k_objectid = 0;
 
 	if (dir->i_mode & S_ISGID) {
 		inode->i_gid = dir->i_gid;
#2 lore raw

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

Quoted 63 lines · Jan Kara

Hello,

Quoted 51 lines

I've already reported a similiar bug to the one I found now and that was fixed by:
"[PATCH] reiserfs: fix deadlock in inode creation failure path w/ default ACL"

This bug is similiar in effect but has some differences in how to trigger it. The end effect will be just like with the other bug that the affected directory will be unaccessible to any user or process.

So here's the way to reproduce it, as minimal as I could get it:

You need reiserfs, quota and acl support in kernel. you also need quota tools (edquota, quotaon, quotacheck), I used linuxquota 3.12.

# cd /mnt
# dd if=/dev/zero of=test bs=1M count=50
50+0 records in
50+0 records out
# mkreiserfs -f test >/dev/null
mkreiserfs 3.6.19 (2003 www.namesys.com)

test is not a block special device
Continue (y/n):y

# mkdir mpoint
# mount test mpoint -o loop,acl,usrquota
# mkdir mpoint/user1
# useradd -d /mnt/mpoint/user1 user1     # may also use existing user
# chown user1 mpoint/user1
# quotacheck -v mpoint                   # initializes quota file
# edquota user1
---- set soft block limit to 1000, hard limit to 4000 ----
# edquota -t
---- set the grace periods to something small: 1minutes ---
# quotaon mpoint
# ## at this point "repquota -a" should show the quota for user1
# su user1
# cd
# ## now we are in user1 home dir as user1
# cat /dev/zero > file1
loop2: warning, user block quota exceeded.
loop2: write failed, user block limit reached.
cat: write error: No space left on device
--- now we wait till the grace period expires (repquota -a) ----
# cat "" > otherfile
loop2: write failed, user block quota exceeded too long.
---- and it will hang forever ----
# ## /mnt/mpoint can still be accessed, but /mnt/mpoint/user1 can't
Quoted 7 lines

I tested this on an -mm patchset kernel (2.6.13-rc5-mm1), but I discovered the bug in my server which runs plain 2.6.12 with the patch from Jeff Mahoney for the first reiserfs+acl bug.

The main difference between the two bugs is that the first one requires the existance of a default acl, this one does not, but it does require acl to be enabled.

This seems to be the same problem as bug #4771 that I've just fix. Can
you try attached patch please?
Andrew, can you include the patch into -mm if ReiserFS guys won't object?

#3 lore raw
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

Oops, sorry. I forgot to mount the fs with ACL mount option and so I
was not able to reproduce the hang. My fault, your bug is a different problem. Now it hangs also for me so I can debug it :)

Honza

Quoted 65 lines · Jan Kara
Quoted 63 lines

Hello,

Quoted 51 lines

I've already reported a similiar bug to the one I found now and that was fixed by:
"[PATCH] reiserfs: fix deadlock in inode creation failure path w/ default ACL"

This bug is similiar in effect but has some differences in how to trigger it. The end effect will be just like with the other bug that the affected directory will be unaccessible to any user or process.

So here's the way to reproduce it, as minimal as I could get it:

You need reiserfs, quota and acl support in kernel. you also need quota tools (edquota, quotaon, quotacheck), I used linuxquota 3.12.

# cd /mnt
# dd if=/dev/zero of=test bs=1M count=50
50+0 records in
50+0 records out
# mkreiserfs -f test >/dev/null
mkreiserfs 3.6.19 (2003 www.namesys.com)

test is not a block special device
Continue (y/n):y

# mkdir mpoint
# mount test mpoint -o loop,acl,usrquota
# mkdir mpoint/user1
# useradd -d /mnt/mpoint/user1 user1     # may also use existing user
# chown user1 mpoint/user1
# quotacheck -v mpoint                   # initializes quota file
# edquota user1
---- set soft block limit to 1000, hard limit to 4000 ----
# edquota -t
---- set the grace periods to something small: 1minutes ---
# quotaon mpoint
# ## at this point "repquota -a" should show the quota for user1
# su user1
# cd
# ## now we are in user1 home dir as user1
# cat /dev/zero > file1
loop2: warning, user block quota exceeded.
loop2: write failed, user block limit reached.
cat: write error: No space left on device
--- now we wait till the grace period expires (repquota -a) ----
# cat "" > otherfile
loop2: write failed, user block quota exceeded too long.
---- and it will hang forever ----
# ## /mnt/mpoint can still be accessed, but /mnt/mpoint/user1 can't
Quoted 7 lines

I tested this on an -mm patchset kernel (2.6.13-rc5-mm1), but I discovered the bug in my server which runs plain 2.6.12 with the patch from Jeff Mahoney for the first reiserfs+acl bug.

The main difference between the two bugs is that the first one requires the existance of a default acl, this one does not, but it does require acl to be enabled.

This seems to be the same problem as bug #4771 that I've just fix. Can
you try attached patch please?
Andrew, can you include the patch into -mm if ReiserFS guys won't object?

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
#4 lore raw

Hello

Quoted 10 lines · Jan Kara
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not. It does unlocking/locking xattrs on error handling path, but has no idea about whether xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

Tarmo, please check if this patch works for you.

 fs/reiserfs/inode.c         |   13 +++++++++----
 fs/reiserfs/namei.c         |    8 ++++----
 include/linux/reiserfs_fs.h |    2 +-
 3 files changed, 14 insertions(+), 9 deletions(-)
fs/reiserfs/inode.c renamed from fs/reiserfs/inode.c~reiserfs-debug-1 +9 -4
diff -puN fs/reiserfs/inode.c~reiserfs-debug-1 fs/reiserfs/inode.c
@@ -1776,7 +1776,7 @@ int reiserfs_new_inode(struct reiserfs_t
 		       /* 0 for regular, EMTRY_DIR_SIZE for dirs, 
 		          strlen (symname) for symlinks) */
 		       loff_t i_size, struct dentry *dentry,
-		       struct inode *inode)
+		       struct inode *inode, int locked)
 {
 	struct super_block *sb;
 	INITIALIZE_PATH(path_to_key);
@@ -1966,6 +1966,7 @@ int reiserfs_new_inode(struct reiserfs_t
  * are place holders for what the quota code actually needs.
  */
       out_bad_inode:
+
 	/* Invalidate the object, nothing was inserted yet */
 	INODE_PKEY(inode)->k_objectid = 0;
 
@@ -1988,11 +1989,15 @@ int reiserfs_new_inode(struct reiserfs_t
 	 * code really needs to be reworked, but this will take care of it
 	 * for now. -jeffm */
 	if (REISERFS_I(dir)->i_acl_default) {
-		reiserfs_write_unlock_xattrs(dir->i_sb);
+		if (locked)
+			reiserfs_write_unlock_xattrs(dir->i_sb);
 		iput(inode);
-		reiserfs_write_lock_xattrs(dir->i_sb);
-	} else
+		if (locked)
+			reiserfs_write_lock_xattrs(dir->i_sb);
+	} else {
 		iput(inode);
+	}
+
 	return err;
 }
 
fs/reiserfs/namei.c renamed from fs/reiserfs/namei.c~reiserfs-debug-1 +4 -4
diff -puN fs/reiserfs/namei.c~reiserfs-debug-1 fs/reiserfs/namei.c
@@ -638,7 +638,7 @@ static int reiserfs_create(struct inode 
 
 	retval =
 	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-			       inode);
+			       inode, locked);
 	if (retval)
 		goto out_failed;
 
@@ -713,7 +713,7 @@ static int reiserfs_mknod(struct inode *
 
 	retval =
 	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-			       inode);
+			       inode, locked);
 	if (retval) {
 		goto out_failed;
 	}
@@ -798,7 +798,7 @@ static int reiserfs_mkdir(struct inode *
 	    retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
 					old_format_only(dir->i_sb) ?
 					EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
-					dentry, inode);
+					dentry, inode, locked);
 	if (retval) {
 		dir->i_nlink--;
 		goto out_failed;
@@ -1086,7 +1086,7 @@ static int reiserfs_symlink(struct inode
 
 	retval =
 	    reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
-			       dentry, inode);
+			       dentry, inode, 0);
 	reiserfs_kfree(name, item_len, parent_dir->i_sb);
 	if (retval) {		/* reiserfs_new_inode iputs for us */
 		goto out_failed;
include/linux/reiserfs_fs.h renamed from include/linux/reiserfs_fs.h~reiserfs-debug-1 +1 -1
diff -puN include/linux/reiserfs_fs.h~reiserfs-debug-1 include/linux/reiserfs_fs.h
@@ -1890,7 +1890,7 @@ struct inode *reiserfs_iget(struct super
 int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
 		       struct inode *dir, int mode,
 		       const char *symname, loff_t i_size,
-		       struct dentry *dentry, struct inode *inode);
+		       struct dentry *dentry, struct inode *inode, int locked);
 
 void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
 			     struct inode *inode, loff_t size);

_

#5 lore raw
In reply to Jan Kara

Hello

Quoted 10 lines · Jan Kara
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not. It does unlocking/locking xattrs on error handling path, but has no idea about whether xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

Tarmo, please check if this patch works for you.

 fs/reiserfs/inode.c         |   13 +++++++++----
 fs/reiserfs/namei.c         |    8 ++++----
 include/linux/reiserfs_fs.h |    2 +-
 3 files changed, 14 insertions(+), 9 deletions(-)
fs/reiserfs/inode.c renamed from fs/reiserfs/inode.c~reiserfs-debug-1 +9 -4
diff -puN fs/reiserfs/inode.c~reiserfs-debug-1 fs/reiserfs/inode.c
@@ -1776,7 +1776,7 @@ int reiserfs_new_inode(struct reiserfs_t
 		       /* 0 for regular, EMTRY_DIR_SIZE for dirs, 
 		          strlen (symname) for symlinks) */
 		       loff_t i_size, struct dentry *dentry,
-		       struct inode *inode)
+		       struct inode *inode, int locked)
 {
 	struct super_block *sb;
 	INITIALIZE_PATH(path_to_key);
@@ -1966,6 +1966,7 @@ int reiserfs_new_inode(struct reiserfs_t
  * are place holders for what the quota code actually needs.
  */
       out_bad_inode:
+
 	/* Invalidate the object, nothing was inserted yet */
 	INODE_PKEY(inode)->k_objectid = 0;
 
@@ -1988,11 +1989,15 @@ int reiserfs_new_inode(struct reiserfs_t
 	 * code really needs to be reworked, but this will take care of it
 	 * for now. -jeffm */
 	if (REISERFS_I(dir)->i_acl_default) {
-		reiserfs_write_unlock_xattrs(dir->i_sb);
+		if (locked)
+			reiserfs_write_unlock_xattrs(dir->i_sb);
 		iput(inode);
-		reiserfs_write_lock_xattrs(dir->i_sb);
-	} else
+		if (locked)
+			reiserfs_write_lock_xattrs(dir->i_sb);
+	} else {
 		iput(inode);
+	}
+
 	return err;
 }
 
fs/reiserfs/namei.c renamed from fs/reiserfs/namei.c~reiserfs-debug-1 +4 -4
diff -puN fs/reiserfs/namei.c~reiserfs-debug-1 fs/reiserfs/namei.c
@@ -638,7 +638,7 @@ static int reiserfs_create(struct inode 
 
 	retval =
 	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-			       inode);
+			       inode, locked);
 	if (retval)
 		goto out_failed;
 
@@ -713,7 +713,7 @@ static int reiserfs_mknod(struct inode *
 
 	retval =
 	    reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-			       inode);
+			       inode, locked);
 	if (retval) {
 		goto out_failed;
 	}
@@ -798,7 +798,7 @@ static int reiserfs_mkdir(struct inode *
 	    retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
 					old_format_only(dir->i_sb) ?
 					EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
-					dentry, inode);
+					dentry, inode, locked);
 	if (retval) {
 		dir->i_nlink--;
 		goto out_failed;
@@ -1086,7 +1086,7 @@ static int reiserfs_symlink(struct inode
 
 	retval =
 	    reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
-			       dentry, inode);
+			       dentry, inode, 0);
 	reiserfs_kfree(name, item_len, parent_dir->i_sb);
 	if (retval) {		/* reiserfs_new_inode iputs for us */
 		goto out_failed;
include/linux/reiserfs_fs.h renamed from include/linux/reiserfs_fs.h~reiserfs-debug-1 +1 -1
diff -puN include/linux/reiserfs_fs.h~reiserfs-debug-1 include/linux/reiserfs_fs.h
@@ -1890,7 +1890,7 @@ struct inode *reiserfs_iget(struct super
 int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
 		       struct inode *dir, int mode,
 		       const char *symname, loff_t i_size,
-		       struct dentry *dentry, struct inode *inode);
+		       struct dentry *dentry, struct inode *inode, int locked);
 
 void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
 			     struct inode *inode, loff_t size);

_

#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 14 lines · Vladimir V. Saveliev

Hello

Quoted 10 lines · Jan Kara
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

Quoted 7 lines

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not.
It does unlocking/locking xattrs on error handling path, but has no idea about whether
xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

Does this patch actually fix it? It shouldn't.

The logic is like this: If a default ACL is associated with the parent when the inode is created, xattrs will be locked so that the ACL can be inherited. Since reiserfs_new_inode is called from the VFS layer with inode->i_sem downed, {set,remove}xattr is locked out. The default ACL can't be removed/added/changed while reiserfs_new_inode is running. Therefore, if there is a default ACL, xattrs must be locked.

- -Jeff

- --
Jeff Mahoney
SuSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFC/LwALPWxlyuTD7IRAl1hAJ9dVKCWPYdMO85+EKjL+2kq9dy3ngCfdS9w 56060gxdR2z0d6UFP79yQ1A=
=S8+3
-----END PGP SIGNATURE-----

#7 lore raw
Quoted 8 lines · Vladimir V. Saveliev
Quoted 8 lines

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not.
It does unlocking/locking xattrs on error handling path, but has no idea about whether
xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

I tested the patch, it did not fix the problem. Is there any way that I could help diagnose the problem? (so far I have not tried reiserfs or kernel debug options, could those help?)

Quoted 9 lines · Jeff Mahoney

Does this patch actually fix it? It shouldn't.

The logic is like this: If a default ACL is associated with the parent when the inode is created, xattrs will be locked so that the ACL can be inherited. Since reiserfs_new_inode is called from the VFS layer with inode->i_sem downed, {set,remove}xattr is locked out. The default ACL can't be removed/added/changed while reiserfs_new_inode is running. Therefore, if there is a default ACL, xattrs must be locked.

I don't know if you read my report on this bug, but note that it had no requirement for any ACL's to be used (even default ACL's), there was only need for acl support to be enabled when mounting the partition.

Signature · 1 line
Tarmo Tänav <[email protected]>
#8 lore raw
In reply to Jeff Mahoney

Hello

Quoted 28 lines · Jeff Mahoney
Quoted 14 lines · Vladimir V. Saveliev
Quoted 14 lines

Hello

Quoted 10 lines · Jan Kara
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

Quoted 7 lines
Quoted 7 lines

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not.
It does unlocking/locking xattrs on error handling path, but has no idea about whether
xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

Quoted 9 lines

Does this patch actually fix it? It shouldn't.

The logic is like this: If a default ACL is associated with the parent when the inode is created, xattrs will be locked so that the ACL can be inherited. Since reiserfs_new_inode is called from the VFS layer with inode->i_sem downed, {set,remove}xattr is locked out. The default ACL can't be removed/added/changed while reiserfs_new_inode is running. Therefore, if there is a default ACL, xattrs must be locked.

xattr's locking in reiserfs_create depends on result of this function:

int reiserfs_cache_default_acl(struct inode *inode)

{
	int ret = 0;
	if (reiserfs_posixacl(inode->i_sb) && !is_reiserfs_priv_object(inode)) {
		struct posix_acl *acl;
		reiserfs_read_lock_xattr_i(inode);
		reiserfs_read_lock_xattrs(inode->i_sb);
		acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
		reiserfs_read_unlock_xattrs(inode->i_sb);
		reiserfs_read_unlock_xattr_i(inode);
		ret = acl ? 1 : 0;
		posix_acl_release(acl);
	}

	return ret;
}

Could it be that it returned 0 in this test?

Also, the line:
ret = acl ? 1 : 0;
is suspicious because reiserfs_get_acl sometimes returns error codes instead on NULL. Is it intentional?

Quoted 5 lines

-Jeff

--
Jeff Mahoney
SuSE Labs

#9 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 63 lines · Vladimir V. Saveliev

Hello

Quoted 29 lines · Jeff Mahoney
Quoted 14 lines · Vladimir V. Saveliev
Quoted 14 lines

Hello

Quoted 10 lines · Jan Kara
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

Quoted 8 lines
Quoted 8 lines

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not.
It does unlocking/locking xattrs on error handling path, but has no idea
about whether
xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

Quoted 9 lines

Does this patch actually fix it? It shouldn't.

The logic is like this: If a default ACL is associated with the parent when the inode is created, xattrs will be locked so that the ACL can be inherited. Since reiserfs_new_inode is called from the VFS layer with inode->i_sem downed, {set,remove}xattr is locked out. The default ACL can't be removed/added/changed while reiserfs_new_inode is running. Therefore, if there is a default ACL, xattrs must be locked.

xattr's locking in reiserfs_create depends on result of this function:

int reiserfs_cache_default_acl(struct inode *inode)

{
    int ret = 0;
    if (reiserfs_posixacl(inode->i_sb) &&
!is_reiserfs_priv_object(inode)) {
        struct posix_acl *acl;
        reiserfs_read_lock_xattr_i(inode);
        reiserfs_read_lock_xattrs(inode->i_sb);
        acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
        reiserfs_read_unlock_xattrs(inode->i_sb);
        reiserfs_read_unlock_xattr_i(inode);
        ret = acl ? 1 : 0;
        posix_acl_release(acl);
    }

    return ret;
}
Quoted 6 lines

Could it be that it returned 0 in this test?

Also, the line:
ret = acl ? 1 : 0;
is suspicious because reiserfs_get_acl sometimes returns error codes instead on NULL. Is it intentional?

Yes, it is intentional. The error could be transient and the subsequent reiserfs_get_acl used when inheriting the default ACL could succeed - requiring the lock. However, you're right in that it does cause an issue with the logic used in reiserfs_new_inode.

That said, I don't believe that particular bug is at fault for causing the problem. The issue is simpler - negative ACL lookups are cached. So, if there is no default ACL, the value of REISERFS_I(inode)->i_acl_default would not be NULL, it would be ERR_PTR(-ENODATA), which would hit the unlock/lock section. This wouldn't trigger without ACLs enabled, since i_acl_default would always be NULL because no lookup would have been attempted.

I have a series of patches that clean up the xattr code significantly that I need to work out the kinks on. The whole mess with locking and default ACLs will be eliminated completely.

I've posted the patches at:
ftp://ftp.suse.com/pub/people/jeffm/reiserfs/xattr-rework/

- -Jeff

- --
Jeff Mahoney
SuSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFC/NqYLPWxlyuTD7IRAuT1AJwOODZzw0GC9DgzixJsCj+ToEwh1gCglUKA Namj+PpBViAmvkI1KA70KB0=
=/oop
-----END PGP SIGNATURE-----

#10 lore raw
In reply to Vladimir V. Saveliev
Quoted 8 lines · Vladimir V. Saveliev

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not. It does unlocking/locking xattrs on error handling path, but has no idea about whether xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

Tarmo, please check if this patch works for you.

Sorry, I made a mistake when I first tested the patch, got some kernel images mixed up, it does fix the problem, thank you.

Signature · 1 line
Tarmo Tänav <[email protected]>
#11 lore raw
In reply to Vladimir V. Saveliev

Hello,

Quoted 12 lines
Quoted 10 lines · Jan Kara
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

Quoted 7 lines

It looks like the problem is that reiserfs_new_inode can be called either having xattrs locked or not.
It does unlocking/locking xattrs on error handling path, but has no idea about whether
xattrs are locked of not.
The attached patch seems to fix the problem.
I am not sure whether it is correct way to fix this problem, though.

I've already fixed this problem and Andrew accepted the patch into
-mm. I took a bit different approach but yours might be better in a long run (mine is just a one liner). The patch is attached if you're interested.

Honza
--
Jan Kara <[email protected]>
SuSE CR Labs

When i_acl_default is set to some error we do not hold the lock (hence we are not allowed to drop it and reacquire later).

fs/reiserfs/inode.c +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.13-rc6-1-reiser_create_fix/fs/reiserfs/inode.c linux-2.6.13-rc6-2-reiser_xattr_fix/fs/reiserfs/inode.c
@@ -1985,7 +1985,7 @@ int reiserfs_new_inode(struct reiserfs_t
 	 * iput doesn't deadlock in reiserfs_delete_xattrs. The locking
 	 * code really needs to be reworked, but this will take care of it
 	 * for now. -jeffm */
-	if (REISERFS_I(dir)->i_acl_default) {
+	if (REISERFS_I(dir)->i_acl_default && !IS_ERR(REISERFS_I(dir)->i_acl_default)) {
 		reiserfs_write_unlock_xattrs(dir->i_sb);
 		iput(inode);
 		reiserfs_write_lock_xattrs(dir->i_sb);
#12 lore raw
In reply to Tarmo Tänav
Quoted 9 lines

Tried the attached patch but it changed nothing, I trying to create a new file as a user whose quota grace time has ran out will still cause everything accessing the users homedir (the one with the quota) to hang in D state.

Also note that the bug I reported only exists when acl is also enabled (does not have to be used). And although my kernel is not built with debug (or reiserfs debug) support, I don't get any oopses or reiserfs errors.. it just hangs.

OK, I've debugged the hang (I think the bug was actually introduced by
Jeff's fix). Attached patch should fix it.

Honza

Quoted 65 lines · Jan Kara
Quoted 63 lines

Hello,

Quoted 51 lines

I've already reported a similiar bug to the one I found now and that was fixed by:
"[PATCH] reiserfs: fix deadlock in inode creation failure path w/ default ACL"

This bug is similiar in effect but has some differences in how to trigger it. The end effect will be just like with the other bug that the affected directory will be unaccessible to any user or process.

So here's the way to reproduce it, as minimal as I could get it:

You need reiserfs, quota and acl support in kernel. you also need quota tools (edquota, quotaon, quotacheck), I used linuxquota 3.12.

# cd /mnt
# dd if=/dev/zero of=test bs=1M count=50
50+0 records in
50+0 records out
# mkreiserfs -f test >/dev/null
mkreiserfs 3.6.19 (2003 www.namesys.com)

test is not a block special device
Continue (y/n):y

# mkdir mpoint
# mount test mpoint -o loop,acl,usrquota
# mkdir mpoint/user1
# useradd -d /mnt/mpoint/user1 user1     # may also use existing user
# chown user1 mpoint/user1
# quotacheck -v mpoint                   # initializes quota file
# edquota user1
---- set soft block limit to 1000, hard limit to 4000 ----
# edquota -t
---- set the grace periods to something small: 1minutes ---
# quotaon mpoint
# ## at this point "repquota -a" should show the quota for user1
# su user1
# cd
# ## now we are in user1 home dir as user1
# cat /dev/zero > file1
loop2: warning, user block quota exceeded.
loop2: write failed, user block limit reached.
cat: write error: No space left on device
--- now we wait till the grace period expires (repquota -a) ----
# cat "" > otherfile
loop2: write failed, user block quota exceeded too long.
---- and it will hang forever ----
# ## /mnt/mpoint can still be accessed, but /mnt/mpoint/user1 can't
Quoted 7 lines

I tested this on an -mm patchset kernel (2.6.13-rc5-mm1), but I discovered the bug in my server which runs plain 2.6.12 with the patch from Jeff Mahoney for the first reiserfs+acl bug.

The main difference between the two bugs is that the first one requires the existance of a default acl, this one does not, but it does require acl to be enabled.

This seems to be the same problem as bug #4771 that I've just fix. Can
you try attached patch please?
Andrew, can you include the patch into -mm if ReiserFS guys won't object?

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs

When i_acl_default is set to some error we do not hold the lock (hence we are not allowed to drop it and reacquire later).

fs/reiserfs/inode.c +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.13-rc6-1-reiser_create_fix/fs/reiserfs/inode.c linux-2.6.13-rc6-2-reiser_xattr_fix/fs/reiserfs/inode.c
@@ -1985,7 +1985,7 @@ int reiserfs_new_inode(struct reiserfs_t
 	 * iput doesn't deadlock in reiserfs_delete_xattrs. The locking
 	 * code really needs to be reworked, but this will take care of it
 	 * for now. -jeffm */
-	if (REISERFS_I(dir)->i_acl_default) {
+	if (REISERFS_I(dir)->i_acl_default && !IS_ERR(REISERFS_I(dir)->i_acl_default)) {
 		reiserfs_write_unlock_xattrs(dir->i_sb);
 		iput(inode);
 		reiserfs_write_lock_xattrs(dir->i_sb);