Skip to contentSkip to conversation

quota: fix wrong condition in is_quota_modification()

PATCH In review Chao Yu 2 participants 5 messages Sep 11, 2019 – Sep 17, 2019

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 quota: fix wrong condition in is_quota_modification()

Quoted from
commit 3da40c7b0898 ("ext4: only call ext4_truncate when size <= isize")

" At LSF we decided that if we truncate up from isize we shouldn't trim
fallocated blocks that were fallocated with KEEP_SIZE and are past the
new i_size. This patch fixes ext4 to do this. "

And generic/092 of fstest have covered this case for long time, however is_quota_modification() didn't adjust based on that rule, so that in below condition, we will lose to quota block change:
- fallocate blocks beyond EOF
- remount
- truncate(file_path, file_size)

Fix it.

---
 include/linux/quotaops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/quotaops.h +1 -1
index dc905a4ff8d7..bd30acad3a7f 100644
@@ -22,7 +22,7 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 /* i_mutex must being held */
 static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
 {
-	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size <= inode->i_size) ||
 		(ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
 		(ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
 }
Signature · 1 line
2.18.0.rc1
reviewer
#1 lore raw
Quoted 26 lines · Chao Yu

Quoted from
commit 3da40c7b0898 ("ext4: only call ext4_truncate when size <= isize")

" At LSF we decided that if we truncate up from isize we shouldn't trim
fallocated blocks that were fallocated with KEEP_SIZE and are past the
new i_size. This patch fixes ext4 to do this. "

And generic/092 of fstest have covered this case for long time, however is_quota_modification() didn't adjust based on that rule, so that in below condition, we will lose to quota block change:
- fallocate blocks beyond EOF
- remount
- truncate(file_path, file_size)

Fix it.

---
 include/linux/quotaops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/quotaops.h +0 -0
index dc905a4ff8d7..bd30acad3a7f 100644

include/linux/quotaops.h static inline struct quota_info *sb_dqopt(struct super_block *sb) · line 28

Quoted 8 lines
include/linux/quotaops.h +1 -1
@@ -22,7 +22,7 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 /* i_mutex must being held */
 static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
 {
-	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size <= inode->i_size) ||
 		(ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
 		(ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
 }

OK, but your change makes i_size extension not to be quota modification which is IMO wrong. So I think the condition should just be:

	return (ia->ia_valid & ATTR_SIZE) || ...

I'll fix the patch up and pull it into my tree.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#2 lore raw
Quoted 22 lines · Jan Kara
Quoted 21 lines · Chao Yu

Quoted from
commit 3da40c7b0898 ("ext4: only call ext4_truncate when size <= isize")

" At LSF we decided that if we truncate up from isize we shouldn't trim
fallocated blocks that were fallocated with KEEP_SIZE and are past the
new i_size. This patch fixes ext4 to do this. "

And generic/092 of fstest have covered this case for long time, however is_quota_modification() didn't adjust based on that rule, so that in below condition, we will lose to quota block change:
- fallocate blocks beyond EOF
- remount
- truncate(file_path, file_size)

Fix it.

---
 include/linux/quotaops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

include/linux/quotaops.h static inline struct quota_info *sb_dqopt(struct super_block *sb) · line 28

Quoted 13 lines
include/linux/quotaops.h +1 -1
index dc905a4ff8d7..bd30acad3a7f 100644
@@ -22,7 +22,7 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 /* i_mutex must being held */
 static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
 {
-	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size <= inode->i_size) ||
 		(ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
 		(ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
 }

OK, but your change makes i_size extension not to be quota modification

I just try to adapt below rules covered with generic/092, which restrict to not trim preallocate blocks beyond i_size, in that case, filesystem won't change i_blocks.

1) truncate(i_size) will trim all blocks past i_size.
2) truncate(x) where x > i_size will not trim all blocks past i_size.

However, I'm okay with your change, because there could be filesystems won't follow above rule.

Thanks,

Quoted 8 lines

which is IMO wrong. So I think the condition should just be:

	return (ia->ia_valid & ATTR_SIZE) || ...

I'll fix the patch up and pull it into my tree.

Honza

reviewer
#3 lore raw
Quoted 18 lines · Chao Yu
Quoted 16 lines · Jan Kara

include/linux/quotaops.h static inline struct quota_info *sb_dqopt(struct super_block *sb) · line 28

Quoted 13 lines · Chao Yu
include/linux/quotaops.h +1 -1
index dc905a4ff8d7..bd30acad3a7f 100644
@@ -22,7 +22,7 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 /* i_mutex must being held */
 static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
 {
-	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size <= inode->i_size) ||
 		(ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
 		(ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
 }

OK, but your change makes i_size extension not to be quota modification

Quoted 6 lines

I just try to adapt below rules covered with generic/092, which restrict to not trim preallocate blocks beyond i_size, in that case, filesystem won't change i_blocks.

1) truncate(i_size) will trim all blocks past i_size.
2) truncate(x) where x > i_size will not trim all blocks past i_size.

Ah, OK.

Quoted 2 lines

However, I'm okay with your change, because there could be filesystems won't follow above rule.

Yes, I'm concerned that some filesystem may change i_blocks in some corner case when growing inode size (e.g. when it decides to convert inode from inline format to a normal block based format or something like that). So I don't think the optimization is really worth the chance for breakage.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#4 lore raw
Quoted 28 lines · Jan Kara
Quoted 18 lines · Chao Yu
Quoted 16 lines · Jan Kara

include/linux/quotaops.h static inline struct quota_info *sb_dqopt(struct super_block *sb) · line 28

Quoted 13 lines · Chao Yu
include/linux/quotaops.h +1 -1
index dc905a4ff8d7..bd30acad3a7f 100644
@@ -22,7 +22,7 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 /* i_mutex must being held */
 static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
 {
-	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size <= inode->i_size) ||
 		(ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
 		(ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
 }

OK, but your change makes i_size extension not to be quota modification

Quoted 6 lines

I just try to adapt below rules covered with generic/092, which restrict to not trim preallocate blocks beyond i_size, in that case, filesystem won't change i_blocks.

1) truncate(i_size) will trim all blocks past i_size.
2) truncate(x) where x > i_size will not trim all blocks past i_size.

Ah, OK.

Quoted 7 lines
Quoted 2 lines

However, I'm okay with your change, because there could be filesystems won't follow above rule.

Yes, I'm concerned that some filesystem may change i_blocks in some corner case when growing inode size (e.g. when it decides to convert inode from inline format to a normal block based format or something like that). So I don't think the optimization is really worth the chance for breakage.

Agreed, :)

Thanks,

Quoted 3 lines

Honza