From patchwork Wed Feb 11 15:11:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 5813221 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 3C3769F336 for ; Wed, 11 Feb 2015 15:12:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F1F8201C0 for ; Wed, 11 Feb 2015 15:12:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3ADC8200D0 for ; Wed, 11 Feb 2015 15:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753850AbbBKPMD (ORCPT ); Wed, 11 Feb 2015 10:12:03 -0500 Received: from forward-corp1g.mail.yandex.net ([95.108.253.251]:49859 "EHLO forward-corp1g.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752642AbbBKPL6 (ORCPT ); Wed, 11 Feb 2015 10:11:58 -0500 Received: from smtpcorp1m.mail.yandex.net (smtpcorp1m.mail.yandex.net [77.88.61.150]) by forward-corp1g.mail.yandex.net (Yandex) with ESMTP id 6E0A73660328; Wed, 11 Feb 2015 18:11:50 +0300 (MSK) Received: from smtpcorp1m.mail.yandex.net (localhost [127.0.0.1]) by smtpcorp1m.mail.yandex.net (Yandex) with ESMTP id 313692CA03DD; Wed, 11 Feb 2015 18:11:50 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:408:f4d2:daa0:d7a5:c625]) by smtpcorp1m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id fA7UutXvUI-BoO8xUnO; Wed, 11 Feb 2015 18:11:50 +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=1423667510; bh=iZZwIOrxy2h1DGKMc/CKlaLGvT4TeINz9C3/uiQ0xSo=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Ew89OKnROncFJ0RKg+ytz5BKwfGa47eg3DOF5B7zNkm3DYo+eOJQZEth8XrhBze49 1Gj7LL2hzKNCFwrrCyaiehAyZ5UvMIjVyZLCEPfVC9DaqQ1Ku9RjroifMc+dVbuDOM WjVh3xhuHnLDaPUpirhMLffqBqyw+KhBjdpEF8TI= Authentication-Results: smtpcorp1m.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH RFC 3/6] quota: mangle statfs result according to project quota usage and limits From: Konstantin Khlebnikov To: Linux FS Devel , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jan Kara , Linux API , containers@lists.linux-foundation.org, Dave Chinner , Andy Lutomirski , Christoph Hellwig , Dmitry Monakhov , "Eric W. Biederman" , Li Xi , Theodore Ts'o , Al Viro Date: Wed, 11 Feb 2015 18:11:49 +0300 Message-ID: <20150211151149.6717.10971.stgit@buzz> In-Reply-To: <20150211151146.6717.62017.stgit@buzz> References: <20150211151146.6717.62017.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 updates amount of available space and inodes returned by vfs_statfs() according to project quota for this directory. This works only if sysctl fs.protected_projects = 1. Signed-off-by: Konstantin Khlebnikov --- fs/quota/dquot.c | 56 ++++++++++++++++++++++++++++++++++++++++++++-- fs/statfs.c | 5 +++- include/linux/quotaops.h | 5 ++++ 3 files changed, 63 insertions(+), 3 deletions(-) -- 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/quota/dquot.c b/fs/quota/dquot.c index afa5f67..e3dfac8 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -1242,15 +1243,20 @@ static void flush_warnings(struct dquot_warn *warn) } } -static int ignore_hardlimit(struct dquot *dquot) +static bool sb_ignore_hardlimit(struct super_block *sb, int type) { - struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type]; + struct mem_dqinfo *info = sb_dqinfo(sb, type); return capable(CAP_SYS_RESOURCE) && (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & DQF_ROOT_SQUASH)); } +static bool ignore_hardlimit(struct dquot *dquot) +{ + return sb_ignore_hardlimit(dquot->dq_sb, dquot->dq_id.type); +} + /* needs dq_data_lock */ static int check_idq(struct dquot *dquot, qsize_t inodes, struct dquot_warn *warn) @@ -2022,6 +2028,52 @@ int dquot_file_open(struct inode *inode, struct file *file) } EXPORT_SYMBOL(dquot_file_open); +void dquot_mangle_statfs(const struct path *path, struct kstatfs *buf) +{ + struct inode *inode = path->dentry->d_inode; + struct super_block *sb = inode->i_sb; + u64 blimit = 0, ilimit = 0, busage, iusage; + struct dquot **dquots; + + if (!sysctl_protected_projects || + !sb_has_quota_limits_enabled(sb, PRJQUOTA) || + sb_ignore_hardlimit(sb, PRJQUOTA)) + return; + + dquots = i_dquot(inode); + if (!dquots[PRJQUOTA]) + return; + + spin_lock(&dq_data_lock); + if (dquots[PRJQUOTA]) { + struct mem_dqblk *dm = &(dquots[PRJQUOTA]->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) { + u64 bavail = (blimit <= busage) ? 0 : + div64_long(blimit - busage, buf->f_bsize); + + if (buf->f_bavail > bavail) + buf->f_bavail = bavail; + } + + if (ilimit) { + u64 iavail = (ilimit <= iusage) ? 0 : (ilimit - iusage); + + if (buf->f_ffree > iavail) { + /* Cut count of "free" inodes but keep "used" */ + buf->f_files -= buf->f_ffree - iavail; + buf->f_ffree = iavail; + } + } +} + /* * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount) */ diff --git a/fs/statfs.c b/fs/statfs.c index 083dc0a..3fa6192 100644 --- a/fs/statfs.c +++ b/fs/statfs.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "internal.h" static int flags_by_mnt(int mnt_flags) @@ -68,8 +69,10 @@ int vfs_statfs(struct path *path, struct kstatfs *buf) int error; error = statfs_by_dentry(path->dentry, buf); - if (!error) + if (!error) { buf->f_flags = calculate_f_flags(path->mnt); + dquot_mangle_statfs(path, buf); + } return error; } EXPORT_SYMBOL(vfs_statfs); diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h index ba54745..42fe4d9 100644 --- a/include/linux/quotaops.h +++ b/include/linux/quotaops.h @@ -85,6 +85,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); +void dquot_mangle_statfs(const struct path *path, struct kstatfs *buf); int dquot_enable(struct inode *inode, int type, int format_id, unsigned int flags); @@ -275,6 +276,10 @@ static inline int dquot_resume(struct super_block *sb, int type) #define dquot_file_open generic_file_open +static inline void dquot_mangle_statfs(struct path *path, struct kstatfs *buf) +{ +} + static inline int dquot_writeback_dquots(struct super_block *sb, int type) { return 0;