Patchwork [2/3] tune2fs: preserve old limits when turn on quota feature

login
register
mail settings
Submitter Niu
Date Nov. 6, 2011, 1:39 p.m.
Message ID <4EB68DF8.7030608@whamcloud.com>
Download mbox | patch
Permalink /patch/123931/
State Accepted
Headers show

Comments

Niu - Nov. 6, 2011, 1:39 p.m.
When turn on quota by tune2fs, if the old quota file exist, the quota
usage should be recomputed but the old limits should be preserved.

Signed-off-by: Niu Yawei <niu@whamcloud.com>
---
 misc/tune2fs.c |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

-- 1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o - Nov. 14, 2011, 3:59 p.m.
On Sun, Nov 06, 2011 at 09:39:04PM +0800, Niu wrote:
> When turn on quota by tune2fs, if the old quota file exist, the quota
> usage should be recomputed but the old limits should be preserved.
> 
> Signed-off-by: Niu Yawei <niu@whamcloud.com>

Thanks, applied.

Note: it looks like we need a similar fix for e2fsck, so that the
limits are preserved, right?  From what I can tell a patch to fix this
hasn't crossed my desk yet....

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 8bcf667..74a0489 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -700,7 +700,6 @@  err:
 void handle_quota_options(ext2_filsys fs)
 {
 	quota_ctx_t qctx;
-	errcode_t retval;
 	ext2_ino_t qf_ino;
 
 	if (!usrquota && !grpquota)
@@ -712,15 +711,33 @@  void handle_quota_options(ext2_filsys fs)
 	if (usrquota == QOPT_ENABLE || grpquota == QOPT_ENABLE)
 		quota_compute_usage(qctx);
 
-	if (usrquota == QOPT_ENABLE)
-		quota_write_inode(qctx, USRQUOTA);
-	else if (usrquota == QOPT_DISABLE)
+	if (usrquota == QOPT_ENABLE && !fs->super->s_usr_quota_inum) {
+		if ((qf_ino = quota_file_exists(fs, USRQUOTA,
+						QFMT_VFS_V1)) > 0) {
+			if (quota_update_inode(qctx, qf_ino, USRQUOTA) == 0)
+				quota_set_sb_inum(fs, qf_ino, USRQUOTA);
+			else
+				quota_write_inode(qctx, USRQUOTA);
+		} else {
+			quota_write_inode(qctx, USRQUOTA);
+		}
+	} else if (usrquota == QOPT_DISABLE) {
 		quota_remove_inode(fs, USRQUOTA);
+	}
 
-	if (grpquota == QOPT_ENABLE)
-		quota_write_inode(qctx, GRPQUOTA);
-	else if (grpquota == QOPT_DISABLE)
+	if (grpquota == QOPT_ENABLE && !fs->super->s_grp_quota_inum) {
+		if ((qf_ino = quota_file_exists(fs, GRPQUOTA,
+						QFMT_VFS_V1)) > 0) {
+			if (quota_update_inode(qctx, qf_ino, GRPQUOTA) == 0)
+				quota_set_sb_inum(fs, qf_ino, GRPQUOTA);
+			else
+				quota_write_inode(qctx, GRPQUOTA);
+		} else {
+			quota_write_inode(qctx, GRPQUOTA);
+		}
+	} else if (grpquota == QOPT_DISABLE) {
 		quota_remove_inode(fs, GRPQUOTA);
+	}
 
 	quota_release_context(&qctx);