From patchwork Fri Jul 13 22:25:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Kali X-Patchwork-Id: 170975 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5A53C2C02B9 for ; Sat, 14 Jul 2012 08:25:22 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752365Ab2GMWZT (ORCPT ); Fri, 13 Jul 2012 18:25:19 -0400 Received: from mail-bk0-f74.google.com ([209.85.214.74]:57177 "EHLO mail-bk0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752272Ab2GMWZP (ORCPT ); Fri, 13 Jul 2012 18:25:15 -0400 Received: by bkcjc3 with SMTP id jc3so206765bkc.1 for ; Fri, 13 Jul 2012 15:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=+aAq8AapoYvTOzesOE3tNtkgf1jw79KUo2PhVVnr0X8=; b=AS/hFmtYrPnw0n+CWjKdS03xupnCX6EIW6M4Lp7ym/mj5KE1tOaB+wORsCtEsFzOtb E7WBuaJiOEGwM00Yf6PdNvgXi40aXAx68a4TIs/k4UIFApBqe12YNF/+1SrQ6AUdeobc t/Y5f+iwrZcl1J03zKGWxp8DFBGB3o+Bb2mzvjxiyicp6TscbfFw4Lxc3WjKG3Ou4fuk Uw2G21rdZZmF72leVzNlGp0oSVC28+gox2xPHgQLucuGK6r5CqkXA6vFKNzNyavFd3c3 ya0fNdMuVQtgXyCRiEwsv9wGcvPrOARkf8BmZ1/0SCrvcTJ0bkVTPIT0yLIJJ2EqjdtP Nf3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=+aAq8AapoYvTOzesOE3tNtkgf1jw79KUo2PhVVnr0X8=; b=TzfJrLXDQXc11GrlwBFFAmOStCIeo8pq7pmuPRsRbwthAU49Y2iPNaXOdewadz5gSi uzSVj36A1kA227FfeA7Rw+bBJDX9T4vIBncdPZwNFhXhrKMh98mNUIo8h0NTMCyHMXWT G7l5eME1OFdKebHbAx6LHUSON4Ty9GNg1Ht6RYmie6oJdxgMIr7Qe9N9CzWgc5/kMPUb TgnHb14kfykbrH/2lccIKiF+B74qPD1OXImTzejf4l04lAvt43tx4nqYdJF4kAQ+fyx6 b9toXydb1f6AQRz8mQjMh2H+vNnUIkRS6GcxCbxeMIdfZKI+TLODWbDPPlGkA69WzPFP NCWA== Received: by 10.14.95.8 with SMTP id o8mr1419693eef.13.1342218313287; Fri, 13 Jul 2012 15:25:13 -0700 (PDT) Received: by 10.14.95.8 with SMTP id o8mr1419687eef.13.1342218313199; Fri, 13 Jul 2012 15:25:13 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id b16si5993668eeg.3.2012.07.13.15.25.13 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 13 Jul 2012 15:25:13 -0700 (PDT) Received: from adityakali.mtv.corp.google.com (adityakali.mtv.corp.google.com [172.18.96.56]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id D31B8200057; Fri, 13 Jul 2012 15:25:12 -0700 (PDT) Received: by adityakali.mtv.corp.google.com (Postfix, from userid 22404) id 329891DE662; Fri, 13 Jul 2012 15:25:12 -0700 (PDT) From: Aditya Kali To: tytso@mit.edu, johann@whamcloud.com, linux-ext4@vger.kernel.org Cc: Aditya Kali Subject: [PATCH 1/4] tune2fs/quota: always create hidden quota files Date: Fri, 13 Jul 2012 15:25:06 -0700 Message-Id: <1342218309-25983-1-git-send-email-adityakali@google.com> X-Mailer: git-send-email 1.7.7.3 X-Gm-Message-State: ALoCoQkGYIsE7TAPcPjubax2qbszQ91mll0+3F9nnPiqtpV3mLmWwcpIBsyzP3ewutiEpi1jAEoLtd0JcihH2k1ArHGvAr5cEKhL1WTf6BrpuoPyFzCIeXN1/3uM2hJRwVNeFdUVS0Jw4A1NI4uxB+8xcf1Dzvkl/rncBtsoMX3CvnxPUZKud+jUZesgVoliaIjBNtw9A2XY Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Currently 'tune2fs -O quota ' 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 has aquota.user & aquota.group files $ tune2fs -O quota # stores ino# of quota files in # ext4 superblock $ e2fsck -f # 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 --- 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); }