* [PATCH 1/4] tune2fs/quota: always create hidden quota files
@ 2012-07-13 22:25 Aditya Kali
2012-07-13 22:25 ` [PATCH 2/4] libquota: fix quota_inode_truncate() Aditya Kali
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Aditya Kali @ 2012-07-13 22:25 UTC (permalink / raw)
To: tytso, johann, linux-ext4; +Cc: Aditya Kali
Currently 'tune2fs -O quota <dev>' will try to use existing
quota files and write their inode numbers in the superblock.
Next e2fsck run then converts these into hidden quota inodes
(ino #3 & #4). But this approach has problems:
1) Before e2fsck run, the inodes are visible to the user and
might get corrupted or removed or replaced by the user.
2) Since these are user visible, we have to include
their block usage in the quota accounting. But once
these inodes are hidden, e2fsck will have to decrement
their usage from the quota accounting (which e2fsck
currently doesn't do and instead reports error).
(the following used to give e2fsck error previously:
# assume <dev> has aquota.user & aquota.group files
$ tune2fs -O quota <dev> # stores ino# of quota files in
# ext4 superblock
$ e2fsck -f <dev> # hides quota files, but now quota
# usage is incorrect.
<< quota errors >>
Instead of making e2fsck complicated, this patch creates the
hidden quota inodes at 'tune2fs -O quota' time iteself. The
usage is computed freshly and limits are copied from the
aquota.user and aquota.group files as earlier.
Signed-off-by: Aditya Kali <adityakali@google.com>
---
lib/quota/mkquota.c | 17 ++++++++++-------
lib/quota/mkquota.h | 2 +-
misc/tune2fs.c | 22 ++++++----------------
3 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/lib/quota/mkquota.c b/lib/quota/mkquota.c
index c7869fd..42af1f2 100644
--- a/lib/quota/mkquota.c
+++ b/lib/quota/mkquota.c
@@ -386,7 +386,9 @@ errcode_t quota_compute_usage(quota_ctx_t qctx)
}
if (ino == 0)
break;
- if (inode.i_links_count) {
+ if (inode.i_links_count &&
+ (ino == EXT2_ROOT_INO ||
+ ino >= EXT2_FIRST_INODE(fs->super))) {
space = ext2fs_inode_i_blocks(fs, &inode) << 9;
quota_data_add(qctx, &inode, ino, space);
quota_data_inodes(qctx, &inode, ino, +1);
@@ -413,13 +415,15 @@ static int scan_dquots_callback(struct dquot *dquot, void *cb_data)
dq = get_dq(quota_dict, dquot->dq_id);
dq->dq_id = dquot->dq_id;
+ dq->dq_dqb.u.v2_mdqb.dqb_off = dquot->dq_dqb.u.v2_mdqb.dqb_off;
/* Check if there is inconsistancy. */
if (dq->dq_dqb.dqb_curspace != dquot->dq_dqb.dqb_curspace ||
dq->dq_dqb.dqb_curinodes != dquot->dq_dqb.dqb_curinodes) {
scan_data->usage_is_inconsistent = 1;
- log_err("Usage inconsistent for ID %d: (%llu, %llu) != "
- "(%llu, %llu)", dq->dq_id, dq->dq_dqb.dqb_curspace,
+ fprintf(stderr, "[QUOTA WARNING] Usage inconsistent for ID %d:"
+ "actual (%llu, %llu) != expected (%llu, %llu)\n",
+ dq->dq_id, dq->dq_dqb.dqb_curspace,
dq->dq_dqb.dqb_curinodes, dquot->dq_dqb.dqb_curspace,
dquot->dq_dqb.dqb_curinodes);
}
@@ -473,9 +477,9 @@ static errcode_t quota_write_all_dquots(struct quota_handle *qh,
}
/*
- * Update usage of in quota file, limits keep unchaged
+ * Updates the in-memory quota limits from the given quota inode.
*/
-errcode_t quota_update_inode(quota_ctx_t qctx, ext2_ino_t qf_ino, int type)
+errcode_t quota_update_limits(quota_ctx_t qctx, ext2_ino_t qf_ino, int type)
{
struct quota_handle *qh;
errcode_t err;
@@ -489,14 +493,13 @@ errcode_t quota_update_inode(quota_ctx_t qctx, ext2_ino_t qf_ino, int type)
return err;
}
- err = quota_file_open(qh, qctx->fs, qf_ino, type, -1, EXT2_FILE_WRITE);
+ err = quota_file_open(qh, qctx->fs, qf_ino, type, -1, 0);
if (err) {
log_err("Open quota file failed", "");
goto out;
}
quota_read_all_dquots(qh, qctx, 1);
- quota_write_all_dquots(qh, qctx);
err = quota_file_close(qh);
if (err) {
diff --git a/lib/quota/mkquota.h b/lib/quota/mkquota.h
index a0c603f..ee15071 100644
--- a/lib/quota/mkquota.h
+++ b/lib/quota/mkquota.h
@@ -51,7 +51,7 @@ void quota_data_add(quota_ctx_t qctx, struct ext2_inode *inode, ext2_ino_t ino,
void quota_data_sub(quota_ctx_t qctx, struct ext2_inode *inode, ext2_ino_t ino,
qsize_t space);
errcode_t quota_write_inode(quota_ctx_t qctx, int qtype);
-errcode_t quota_update_inode(quota_ctx_t qctx, ext2_ino_t qf_ino, int type);
+errcode_t quota_update_limits(quota_ctx_t qctx, ext2_ino_t qf_ino, int type);
errcode_t quota_compute_usage(quota_ctx_t qctx);
void quota_release_context(quota_ctx_t *qctx);
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index f1f0bcf..73bc10c 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -713,28 +713,18 @@ void handle_quota_options(ext2_filsys fs)
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);
- }
+ QFMT_VFS_V1)) > 0)
+ quota_update_limits(qctx, qf_ino, USRQUOTA);
+ quota_write_inode(qctx, USRQUOTA);
} else if (usrquota == QOPT_DISABLE) {
quota_remove_inode(fs, USRQUOTA);
}
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);
- }
+ QFMT_VFS_V1)) > 0)
+ quota_update_limits(qctx, qf_ino, GRPQUOTA);
+ quota_write_inode(qctx, GRPQUOTA);
} else if (grpquota == QOPT_DISABLE) {
quota_remove_inode(fs, GRPQUOTA);
}
--
1.7.7.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] libquota: fix quota_inode_truncate()
2012-07-13 22:25 [PATCH 1/4] tune2fs/quota: always create hidden quota files Aditya Kali
@ 2012-07-13 22:25 ` Aditya Kali
2012-07-13 22:25 ` [PATCH 3/4] e2fsck/quota: mark FS invalid if quotas are not fixed Aditya Kali
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Aditya Kali @ 2012-07-13 22:25 UTC (permalink / raw)
To: tytso, johann, linux-ext4; +Cc: Aditya Kali
We failed to clear EXT2_FLAG_SUPER_ONLY after deleting the
quota inode and so, the updated block bitmap was not written
back. This caused fsck to complain after running
'tune2fs -O ^quota <dev>'. Clear this flag so that updated
block bitmap gets written. Also, avoid truncating the quota
inode if it is not hidden.
Signed-off-by: Aditya Kali <adityakali@google.com>
---
lib/quota/quotaio.c | 20 ++++++++++++--------
1 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/lib/quota/quotaio.c b/lib/quota/quotaio.c
index c0ebaa1..7cdd653 100644
--- a/lib/quota/quotaio.c
+++ b/lib/quota/quotaio.c
@@ -133,14 +133,18 @@ errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino)
if ((err = ext2fs_read_inode(fs, ino, &inode)))
return err;
- inode.i_dtime = fs->now ? fs->now : time(0);
- if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
- return 0;
-
- ext2fs_block_iterate3(fs, ino, BLOCK_FLAG_READ_ONLY, NULL,
- release_blocks_proc, NULL);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] e2fsck/quota: mark FS invalid if quotas are not fixed
2012-07-13 22:25 [PATCH 1/4] tune2fs/quota: always create hidden quota files Aditya Kali
2012-07-13 22:25 ` [PATCH 2/4] libquota: fix quota_inode_truncate() Aditya Kali
@ 2012-07-13 22:25 ` Aditya Kali
2012-07-13 22:25 ` [PATCH 4/4] tune2fs: fix quota feature removal Aditya Kali
2012-07-17 5:22 ` [PATCH 1/4] tune2fs/quota: always create hidden quota files Theodore Ts'o
3 siblings, 0 replies; 5+ messages in thread
From: Aditya Kali @ 2012-07-13 22:25 UTC (permalink / raw)
To: tytso, johann, linux-ext4; +Cc: Aditya Kali
If user chooses to not fix quota info, then the FS should be
marked as having errors. PR_NO_OK prevented this from happening.
Signed-off-by: Aditya Kali <adityakali@google.com>
---
e2fsck/problem.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/e2fsck/problem.c b/e2fsck/problem.c
index 0948bdb..6a7b6fc 100644
--- a/e2fsck/problem.c
+++ b/e2fsck/problem.c
@@ -1694,7 +1694,7 @@ static struct e2fsck_problem problem_table[] = {
/* Update quota information if it is inconsistent */
{ PR_6_UPDATE_QUOTAS,
N_("Update quota info for quota type %N"),
- PROMPT_NULL, PR_PREEN_OK | PR_NO_OK },
+ PROMPT_NULL, PR_PREEN_OK },
{ 0 }
};
--
1.7.7.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] tune2fs: fix quota feature removal
2012-07-13 22:25 [PATCH 1/4] tune2fs/quota: always create hidden quota files Aditya Kali
2012-07-13 22:25 ` [PATCH 2/4] libquota: fix quota_inode_truncate() Aditya Kali
2012-07-13 22:25 ` [PATCH 3/4] e2fsck/quota: mark FS invalid if quotas are not fixed Aditya Kali
@ 2012-07-13 22:25 ` Aditya Kali
2012-07-17 5:22 ` [PATCH 1/4] tune2fs/quota: always create hidden quota files Theodore Ts'o
3 siblings, 0 replies; 5+ messages in thread
From: Aditya Kali @ 2012-07-13 22:25 UTC (permalink / raw)
To: tytso, johann, linux-ext4; +Cc: Aditya Kali
When the last quota inode is removed, the 'quota' feature
flag was not removed from superblock in some cases.
Ex:
$ mke2fs -t ext4 -O quota <dev> # creates both usr & grp
# quota inodes
$ tune2fs -Q ^usrquota <dev> # removes usr quota inode
$ tune2fs -Q ^grpquota <dev> # removes grp quota inode,
# but the 'quota' feature flag
# was not removed from superblock
This patch removes the 'quota' feature flag from superblock
if none of the quota inodes are set.
Signed-off-by: Aditya Kali <adityakali@google.com>
---
misc/tune2fs.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 73bc10c..fb46fb6 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -734,7 +734,8 @@ void handle_quota_options(ext2_filsys fs)
if ((usrquota == QOPT_ENABLE) || (grpquota == QOPT_ENABLE)) {
fs->super->s_feature_ro_compat |= EXT4_FEATURE_RO_COMPAT_QUOTA;
ext2fs_mark_super_dirty(fs);
- } else if ((usrquota == QOPT_DISABLE) && (grpquota == QOPT_DISABLE)) {
+ } else if (!fs->super->s_usr_quota_inum &&
+ !fs->super->s_grp_quota_inum) {
fs->super->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
ext2fs_mark_super_dirty(fs);
}
--
1.7.7.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/4] tune2fs/quota: always create hidden quota files
2012-07-13 22:25 [PATCH 1/4] tune2fs/quota: always create hidden quota files Aditya Kali
` (2 preceding siblings ...)
2012-07-13 22:25 ` [PATCH 4/4] tune2fs: fix quota feature removal Aditya Kali
@ 2012-07-17 5:22 ` Theodore Ts'o
3 siblings, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2012-07-17 5:22 UTC (permalink / raw)
To: Aditya Kali; +Cc: johann, linux-ext4
I've applied all four quota patches to the maint branch of e2fsprogs,
thanks!
- Ted
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-07-17 5:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-13 22:25 [PATCH 1/4] tune2fs/quota: always create hidden quota files Aditya Kali
2012-07-13 22:25 ` [PATCH 2/4] libquota: fix quota_inode_truncate() Aditya Kali
2012-07-13 22:25 ` [PATCH 3/4] e2fsck/quota: mark FS invalid if quotas are not fixed Aditya Kali
2012-07-13 22:25 ` [PATCH 4/4] tune2fs: fix quota feature removal Aditya Kali
2012-07-17 5:22 ` [PATCH 1/4] tune2fs/quota: always create hidden quota files Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).