From patchwork Tue Mar 10 17:22:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 5979661 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E65B49F399 for ; Tue, 10 Mar 2015 17:22:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F2A45201DD for ; Tue, 10 Mar 2015 17:22:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EAA1A201F4 for ; Tue, 10 Mar 2015 17:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932081AbbCJRWT (ORCPT ); Tue, 10 Mar 2015 13:22:19 -0400 Received: from forward-corp1g.mail.yandex.net ([95.108.253.251]:39836 "EHLO forward-corp1g.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753732AbbCJRWQ (ORCPT ); Tue, 10 Mar 2015 13:22:16 -0400 Received: from smtpcorp1m.mail.yandex.net (smtpcorp1m.mail.yandex.net [77.88.61.150]) by forward-corp1g.mail.yandex.net (Yandex) with ESMTP id 8BF3E366037C; Tue, 10 Mar 2015 20:22:13 +0300 (MSK) Received: from smtpcorp1m.mail.yandex.net (localhost [127.0.0.1]) by smtpcorp1m.mail.yandex.net (Yandex) with ESMTP id 535FC2CA043C; Tue, 10 Mar 2015 20:22:13 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:408:a45e:343f:b17c:8d0d]) by smtpcorp1m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id eY0D3yGvJ6-MDoWLZsY; Tue, 10 Mar 2015 20:22:13 +0300 (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1426008133; bh=0xtJbJcc9TlWEuDlx9ga0+gp33uRp+qk1r1C/KLvcyc=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding; b=mZObk9G34vDDlqrTC4L/VjN5QyYNFOy4ksceRZWP/OMg423va622FdeZQX/fQkyBB TUddN1qREe8AaXaQwPyRBLbJtEWYtcw0KOb+cCHYe84bX1jrZqf+vkVtPshhVZkz8s oB0MmMHmGJvcc35po3BaWxY52hGr2nuTxKGWM/FM= Authentication-Results: smtpcorp1m.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH RFC v2 6/6] ext4: mangle statfs results accourding to project quota usage and limits From: Konstantin Khlebnikov To: linux-fsdevel@vger.kernel.org, Dave Chinner , Jan Kara , linux-ext4@vger.kernel.org, Theodore Ts'o Cc: Dmitry Monakhov , Andy Lutomirski , linux-kernel@vger.kernel.org, Li Xi Date: Tue, 10 Mar 2015 20:22:12 +0300 Message-ID: <20150310172212.23081.64204.stgit@buzz> In-Reply-To: <20150310171133.23081.49616.stgit@buzz> References: <20150310171133.23081.49616.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds helper function dquot_mangle_statfs() which fills statfs result with information from project quota counters. XFS does the same thing in function xfs_fill_statvfs_from_dquot(). As a result subtree under project quota acts like separate filesystem, for example 'df' inside chroot or container will show expected numbers. Signed-off-by: Konstantin Khlebnikov --- fs/ext4/super.c | 2 +- fs/quota/dquot.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/quotaops.h | 7 ++++++ 3 files changed, 59 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 6a6506bce53c..09ffa4905651 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5154,7 +5154,7 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; - return 0; + return dquot_mangle_statfs(dentry, buf); } /* Helper function for writing quotas on sync - we need to start transaction diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 0b61357554ed..b05ebbcb4d5e 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -2025,6 +2025,57 @@ int dquot_file_open(struct inode *inode, struct file *file) EXPORT_SYMBOL(dquot_file_open); /* + * Update statfs results accourding to project quota limits. + */ +int dquot_mangle_statfs(struct dentry *dentry, struct kstatfs *buf) +{ + u64 blimit = 0, ilimit = 0, busage, iusage, bfree, ifree; + struct inode *inode = dentry->d_inode; + struct super_block *sb = dentry->d_sb; + struct dquot *dquot; + + if (!sb_has_quota_limits_enabled(sb, PRJQUOTA)) + return 0; + + __dquot_initialize(inode, PRJQUOTA); + + spin_lock(&dq_data_lock); + dquot = i_dquot(inode)[PRJQUOTA]; + if (dquot) { + struct mem_dqblk *dm = &(dquot->dq_dqb); + + blimit = dm->dqb_bsoftlimit ?: dm->dqb_bhardlimit; + busage = dm->dqb_curspace + dm->dqb_rsvspace; + ilimit = dm->dqb_isoftlimit ?: dm->dqb_ihardlimit; + iusage = dm->dqb_curinodes; + } + spin_unlock(&dq_data_lock); + + if (blimit) { + blimit = div_u64(blimit, buf->f_bsize); + busage = div_u64(busage, buf->f_bsize); + bfree = (blimit <= busage) ? 0 : (blimit - busage); + if (buf->f_blocks > blimit) + buf->f_blocks = blimit; + if (buf->f_bfree > bfree) + buf->f_bfree = bfree; + if (buf->f_bavail > bfree) + buf->f_bavail = bfree; + } + + if (ilimit) { + ifree = (ilimit <= iusage) ? 0 : (ilimit - iusage); + if (buf->f_files > ilimit) + buf->f_files = ilimit; + if (buf->f_ffree > ifree) + buf->f_ffree = ifree; + } + + return 0; +} +EXPORT_SYMBOL(dquot_mangle_statfs); + +/* * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount) */ int dquot_disable(struct super_block *sb, int type, unsigned int flags) diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h index 810b88c69c5b..cd4c02e3d17e 100644 --- a/include/linux/quotaops.h +++ b/include/linux/quotaops.h @@ -8,6 +8,7 @@ #define _LINUX_QUOTAOPS_ #include +#include /* * Flags for functions __dquot_alloc_space() and __dquot_free_space() @@ -93,6 +94,7 @@ int dquot_commit_info(struct super_block *sb, int type); int dquot_mark_dquot_dirty(struct dquot *dquot); int dquot_file_open(struct inode *inode, struct file *file); +int dquot_mangle_statfs(struct dentry *dentry, struct kstatfs *buf); int dquot_enable(struct inode *inode, int type, int format_id, unsigned int flags); @@ -283,6 +285,11 @@ static inline int dquot_resume(struct super_block *sb, int type) #define dquot_file_open generic_file_open +static inline int dquot_mangle_statfs(struct dentry *d, struct kstatfs *buf) +{ + return 0; +} + static inline int dquot_writeback_dquots(struct super_block *sb, int type) { return 0;