Skip to contentSkip to conversation

ext4: add a new spinlock i_raw_lock to protect the ext4's raw inode

PATCH In review Theodore Ts'o 4 participants 11 messages Apr 12, 2014 – Apr 15, 2014 ext4 file system

lore
Share & tools
lore

Theodore Ts'o

author maintainer
#0 lore raw

PATCH 1/1 ext4: add a new spinlock i_raw_lock to protect the ext4's raw inode

To avoid potential data races, use a spinlock which protects the raw (on-disk) inode.

---
 fs/ext4/ext4.h  | 2 ++
 fs/ext4/inode.c | 5 ++++-
 fs/ext4/super.c | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)
fs/ext4/ext4.h +2 -0
index 86c2cda..1d08a1b 100644
@@ -875,6 +875,8 @@ struct ext4_inode_info {
 	struct inode vfs_inode;
 	struct jbd2_inode *jinode;
 
+	spinlock_t i_raw_lock;	/* protects updates to the raw inode */
+
 	/*
 	 * File creation time. Its function is same as that of
 	 * struct timespec i_{a,c,m}time in the generic inode.
fs/ext4/inode.c +4 -1
index 2eb5fad..1ee8ff6 100644
@@ -4311,7 +4311,9 @@ static int ext4_do_update_inode(handle_t *handle,
 	uid_t i_uid;
 	gid_t i_gid;
 
-	/* For fields not not tracking in the in-memory inode,
+	spin_lock(&ei->i_raw_lock);
+
+	/* For fields not tracked in the in-memory inode,
 	 * initialise them to zero for new inodes. */
 	if (ext4_test_inode_state(inode, EXT4_STATE_NEW))
 		memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
@@ -4419,6 +4421,7 @@ static int ext4_do_update_inode(handle_t *handle,
 
 	ext4_update_inode_fsync_trans(handle, inode, need_datasync);
 out_brelse:
+	spin_unlock(&ei->i_raw_lock);
 	brelse(bh);
 	ext4_std_error(inode->i_sb, err);
 	return err;
fs/ext4/super.c +1 -0
index c4895c1..1f8cb18 100644
@@ -879,6 +879,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
 		return NULL;
 
 	ei->vfs_inode.i_version = 1;
+	spin_lock_init(&ei->i_raw_lock);
 	INIT_LIST_HEAD(&ei->i_prealloc_list);
 	spin_lock_init(&ei->i_prealloc_lock);
 	ext4_es_init_tree(&ei->i_es_tree);
Signature · 6 lines
1.9.0

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author maintainer
#1 lore raw

PATCH 1/3 generic/004: fix filtering of expected error message

The failure message goes to stderr, so we need to redirect stderr to stdout before running sed.

Cc Christoph Hellwig <[email protected]>
---
 tests/generic/004     | 2 +-
 tests/generic/004.out | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/generic/004 +1 -1
index 406c29e..23ca349 100755
@@ -58,7 +58,7 @@ $XFS_IO_PROG -T \
 rm ${testfile}
 
 # test creating a r/o tmpfile.  Should fail
-$XFS_IO_PROG -Tr ${TEST_DIR} -c "close" | _filter_test_dir
+$XFS_IO_PROG -Tr ${TEST_DIR} -c "close" 2>&1 | _filter_test_dir
 
 # success, all done
 status=0
tests/generic/004.out +1 -1
index b85c11c..527b2c2 100644
@@ -3,4 +3,4 @@ wrote 4096/4096 bytes at offset 0
 XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 read 4096/4096 bytes at offset 0
 XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-/mnt/test: Invalid argument
+TEST_DIR: Invalid argument
Signature · 6 lines
1.9.0

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] generic/004: fix filtering of expected error message

Quoted 2 lines · Theodore Ts'o

The failure message goes to stderr, so we need to redirect stderr to stdout before running sed.

Heh, whoops.

Quoted 31 lines
Cc Christoph Hellwig <[email protected]>
---
 tests/generic/004     | 2 +-
 tests/generic/004.out | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/generic/004 +1 -1
index 406c29e..23ca349 100755
@@ -58,7 +58,7 @@ $XFS_IO_PROG -T \
 rm ${testfile}
 
 # test creating a r/o tmpfile.  Should fail
-$XFS_IO_PROG -Tr ${TEST_DIR} -c "close" | _filter_test_dir
+$XFS_IO_PROG -Tr ${TEST_DIR} -c "close" 2>&1 | _filter_test_dir
 
 # success, all done
 status=0
tests/generic/004.out +1 -1
index b85c11c..527b2c2 100644
@@ -3,4 +3,4 @@ wrote 4096/4096 bytes at offset 0
 XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 read 4096/4096 bytes at offset 0
 XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-/mnt/test: Invalid argument
+TEST_DIR: Invalid argument
author maintainer
#3 lore raw

PATCH 2/3 generic/022: update expected output after the test was renamed

In reply to Theodore Ts'o

After generic/022 was renamed by commit 21723cdb, the wrong test number was put into generic/022.out. Fix this.

---
 tests/generic/022.out | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/022.out +1 -1
index 96c2d33..fbffa59 100644
@@ -1,4 +1,4 @@
-QA output created by 009
+QA output created by 022
 	1. into a hole
 f4f35d60b3cc18aaa6d8d92f0cd3708a
 	2. into allocated space
Signature · 1 line
1.9.0
#4 lore raw

Re: [PATCH 2/3] generic/022: update expected output after the test was renamed

Quoted 5 lines · Theodore Ts'o

After generic/022 was renamed by commit 21723cdb, the wrong test number was put into generic/022.out. Fix this.

Lukas sent this a couple days ago as well.

In any case, again, Reviewed-by: Eric Sandeen <[email protected]>

Quoted 15 lines
---
 tests/generic/022.out | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/022.out +1 -1
index 96c2d33..fbffa59 100644
@@ -1,4 +1,4 @@
-QA output created by 009
+QA output created by 022
 	1. into a hole
 f4f35d60b3cc18aaa6d8d92f0cd3708a
 	2. into allocated space
author maintainer
#5 lore raw

PATCH 3/3 generic/237: fix filtering for expected failure message

In reply to Theodore Ts'o

Newer kernels return EACCES instead of EPERM when modifying an acl fails. Update the filtering to handle this.

---
 tests/generic/237     | 2 +-
 tests/generic/237.out | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/generic/237 +1 -1
index 6a61ec8..b068150 100755
@@ -68,7 +68,7 @@ touch file1
 chown $acl1.$acl1 file1
 
 echo "Expect to FAIL"
-$runas -u $acl2 -g $acl2 -- `which setfacl` -m u::rwx file1 2>&1 | sed 's/^setfacl: \/.*file1: Operation not permitted$/setfacl: file1: Operation not permitted/'
+$runas -u $acl2 -g $acl2 -- `which setfacl` -m u::rwx file1 2>&1 | sed -e 's/Permission denied/Operation not permitted/' -e 's/file1: //' -e 's,[/a-zA-Z]*setfacl: ,setfacl: ,'
 
 echo "Test over."
 # success, all done
tests/generic/237.out +1 -1
index 09d98c6..4edafa6 100644
@@ -1,4 +1,4 @@
 QA output created by 237
 Expect to FAIL
-setfacl: file1: Operation not permitted
+setfacl: Operation not permitted
 Test over.
Signature · 6 lines
1.9.0

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#6 lore raw

Re: [PATCH 3/3] generic/237: fix filtering for expected failure message

Quoted 4 lines · Theodore Ts'o

Newer kernels return EACCES instead of EPERM when modifying an acl fails. Update the filtering to handle this.

I've not seen this yet. What exact configuration do you use to get the error?

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author maintainer
#7 lore raw

Re: [PATCH 3/3] generic/237: fix filtering for expected failure message

Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Theodore Ts'o

Newer kernels return EACCES instead of EPERM when modifying an acl fails. Update the filtering to handle this.

I've not seen this yet. What exact configuration do you use to get the error?

I was using a 32-bit kernel, using a recent Linus upstream. The bug was showing up for both ext4 and xfs, and xfstests-bld is using a very recent version of the acl package?

If you're not seeing it, perhaps the most likely cause would be the fact that I was using an i386 kernel, and/or the version of the acl userspace package found in kvm-xfstests?

If you want a repro, you could grab:

git://git.kernel.org/pub/scm/fs/ext2/xfstests-bld.git

and then building the per the README.

If you don't have a Debian testing system conviently to hand, you could pull down:

https://www.kernel.org/pub/linux/kernel/people/tytso/kvm-xfstests/root_fs.img.i386

... and then update the image to have the xfstests upstream version of /root/xfstests/tests/generic/237*.

Cheers,

- Ted

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#8 lore raw

Re: [PATCH 3/3] generic/237: fix filtering for expected failure message

In reply to Theodore Ts'o
Quoted 14 lines · Theodore Ts'o

Newer kernels return EACCES instead of EPERM when modifying an acl fails. Update the filtering to handle this.

---
 tests/generic/237     | 2 +-
 tests/generic/237.out | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/generic/237 +0 -0
index 6a61ec8..b068150 100755

tests/generic/237 touch file1 · line 71

Quoted 5 lines
tests/generic/237 +1 -1
@@ -68,7 +68,7 @@ touch file1
 chown $acl1.$acl1 file1
 
 echo "Expect to FAIL"
-$runas -u $acl2 -g $acl2 -- `which setfacl` -m u::rwx file1 2>&1 | sed 's/^setfacl: \/.*file1: Operation not permitted$/setfacl: file1: Operation not permitted/'
+$runas -u $acl2 -g $acl2 -- `which setfacl` -m u::rwx file1 2>&1 | sed -e 's/Permission denied/Operation not permitted/' -e 's/file1: //' -e 's,[/a-zA-Z]*setfacl: ,setfacl: ,'

This is getting unweildy. Can you factor this into a local _filter_setfacl_error function of some kind? It would also help if you put a comment iterating all the different output formats it's now trying to filter out, too.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author maintainer
#9 lore raw

Re: [PATCH 3/3] generic/237: fix filtering for expected failure message

After looking at this more closely, this patch isn't needed. It was a configuration screw up on my end.

- Ted