Skip to contentSkip to conversation

reiserfs: Fix locking in reiserfs_quota_on()

PATCH In review Jan Kara 3 participants 5 messages Oct 28, 2010 – Nov 9, 2010 VFS

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 reiserfs: Fix locking in reiserfs_quota_on()

reiserfs_quota_on() unpacks a tail of quota file in case it has one. But after BKL conversion, reiserfs_unpack() expects to be called with write_lock held. So acquire the lock before calling reiserfs_unpack() to avoid assertion failures.

---
 fs/reiserfs/super.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Frederic, would you merge this patch or should I merge it?

fs/reiserfs/super.c +2 -0
index 6e85cfd..73c000f 100644
@@ -2059,7 +2059,9 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
 	inode = path->dentry->d_inode;
 	/* We must not pack tails for quota files on reiserfs for quota IO to work */
 	if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
+		reiserfs_write_lock(sb);
 		err = reiserfs_unpack(inode, NULL);
+		reiserfs_write_unlock(sb);
 		if (err) {
 			reiserfs_warning(sb, "super-6520",
 				"Unpacking tail of quota file failed"
Signature · 1 line
1.7.1
maintainer
#1 lore raw

BTW, why does reiserfs flips MS_ACTIVE on for a while during
mount around the quota work?

#2 lore raw
In reply to Jan Kara
Quoted 30 lines · Jan Kara

reiserfs_quota_on() unpacks a tail of quota file in case it has one. But after BKL conversion, reiserfs_unpack() expects to be called with write_lock held. So acquire the lock before calling reiserfs_unpack() to avoid assertion failures.

---
 fs/reiserfs/super.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Frederic, would you merge this patch or should I merge it?

fs/reiserfs/super.c +2 -0
index 6e85cfd..73c000f 100644
@@ -2059,7 +2059,9 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
 	inode = path->dentry->d_inode;
 	/* We must not pack tails for quota files on reiserfs for quota IO to work */
 	if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
+		reiserfs_write_lock(sb);
 		err = reiserfs_unpack(inode, NULL);
+		reiserfs_write_unlock(sb);
 		if (err) {
 			reiserfs_warning(sb, "super-6520",
 				"Unpacking tail of quota file failed"
Signature · 1 line
1.7.1

Yeah. This is due to a recent fix in reiserfs_unpack().
And in this fix I assumed reiserfs_unpack() was always called under the reiserfs lock.
I was wrong, I thought that reiserfs_quota_on() was ok because it can call joural_begin() which appears to have the same requirements. But no that's probably another bug, journal_begin() should also be called under the reiserfs lock.
Anyway that must be another patch.

For this specific problem, it might be slightly more proper to do the below. It lowers a bit the reiserfs lock coverage and also fixes a weird lock-unlock ordering in reiserfs_unpack() that was doing:

Lock A - Lock B - Unlock A - Unlock B

Hmm?

fs/reiserfs/ioctl.c +1 -1
index 5cbb81e..af2a58f 100644
@@ -189,8 +189,8 @@ int reiserfs_unpack(struct inode *inode, struct file *filp)
 	/* we need to make sure nobody is changing the file size beneath
 	 ** us
 	 */
-	reiserfs_mutex_lock_safe(&inode->i_mutex, inode->i_sb);
 	depth = reiserfs_write_lock_once(inode->i_sb);
+	reiserfs_mutex_lock_safe(&inode->i_mutex, inode->i_sb);
 
 	write_from = inode->i_size & (blocksize - 1);
 	/* if we are on a block boundary, we are already unpacked.  */
author reviewer
#3 lore raw
Quoted 44 lines · Frederic Weisbecker
Quoted 30 lines · Jan Kara

reiserfs_quota_on() unpacks a tail of quota file in case it has one. But after BKL conversion, reiserfs_unpack() expects to be called with write_lock held. So acquire the lock before calling reiserfs_unpack() to avoid assertion failures.

---
 fs/reiserfs/super.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Frederic, would you merge this patch or should I merge it?

fs/reiserfs/super.c +2 -0
index 6e85cfd..73c000f 100644
@@ -2059,7 +2059,9 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
 	inode = path->dentry->d_inode;
 	/* We must not pack tails for quota files on reiserfs for quota IO to work */
 	if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
+		reiserfs_write_lock(sb);
 		err = reiserfs_unpack(inode, NULL);
+		reiserfs_write_unlock(sb);
 		if (err) {
 			reiserfs_warning(sb, "super-6520",
 				"Unpacking tail of quota file failed"
Signature · 1 line
1.7.1

Yeah. This is due to a recent fix in reiserfs_unpack().
And in this fix I assumed reiserfs_unpack() was always called under the reiserfs lock.
I was wrong, I thought that reiserfs_quota_on() was ok because it can call joural_begin() which appears to have the same requirements. But no that's probably another bug, journal_begin() should also be called under the reiserfs lock.
Anyway that must be another patch.

Quoted 7 lines

For this specific problem, it might be slightly more proper to do the below. It lowers a bit the reiserfs lock coverage and also fixes a weird lock-unlock ordering in reiserfs_unpack() that was doing:

Lock A - Lock B - Unlock A - Unlock B

Hmm?

Looks OK to me. Do you plan to merge it?

Honza

Quoted 16 lines
fs/reiserfs/ioctl.c +1 -1
index 5cbb81e..af2a58f 100644
@@ -189,8 +189,8 @@ int reiserfs_unpack(struct inode *inode, struct file *filp)
 	/* we need to make sure nobody is changing the file size beneath
 	 ** us
 	 */
-	reiserfs_mutex_lock_safe(&inode->i_mutex, inode->i_sb);
 	depth = reiserfs_write_lock_once(inode->i_sb);
+	reiserfs_mutex_lock_safe(&inode->i_mutex, inode->i_sb);
 
 	write_from = inode->i_size & (blocksize - 1);
 	/* if we are on a block boundary, we are already unpacked.  */
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#4 lore raw
Quoted 45 lines · Jan Kara
Quoted 44 lines · Frederic Weisbecker
Quoted 30 lines · Jan Kara

reiserfs_quota_on() unpacks a tail of quota file in case it has one. But after BKL conversion, reiserfs_unpack() expects to be called with write_lock held. So acquire the lock before calling reiserfs_unpack() to avoid assertion failures.

---
 fs/reiserfs/super.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Frederic, would you merge this patch or should I merge it?

fs/reiserfs/super.c +2 -0
index 6e85cfd..73c000f 100644
@@ -2059,7 +2059,9 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
 	inode = path->dentry->d_inode;
 	/* We must not pack tails for quota files on reiserfs for quota IO to work */
 	if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
+		reiserfs_write_lock(sb);
 		err = reiserfs_unpack(inode, NULL);
+		reiserfs_write_unlock(sb);
 		if (err) {
 			reiserfs_warning(sb, "super-6520",
 				"Unpacking tail of quota file failed"
Signature · 1 line
1.7.1

Yeah. This is due to a recent fix in reiserfs_unpack().
And in this fix I assumed reiserfs_unpack() was always called under the reiserfs lock.
I was wrong, I thought that reiserfs_quota_on() was ok because it can call joural_begin() which appears to have the same requirements. But no that's probably another bug, journal_begin() should also be called under the reiserfs lock.
Anyway that must be another patch.

Quoted 8 lines
Quoted 7 lines

For this specific problem, it might be slightly more proper to do the below. It lowers a bit the reiserfs lock coverage and also fixes a weird lock-unlock ordering in reiserfs_unpack() that was doing:

Lock A - Lock B - Unlock A - Unlock B

Hmm?

Looks OK to me. Do you plan to merge it?

Yep, will be sent to Andrew soon.

Thanks!