From patchwork Fri Apr 21 23:12:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 9693921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 88F8C601D4 for ; Fri, 21 Apr 2017 23:12:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7945E2867F for ; Fri, 21 Apr 2017 23:12:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A87C28684; Fri, 21 Apr 2017 23:12:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB7D82867F for ; Fri, 21 Apr 2017 23:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1041525AbdDUXMv (ORCPT ); Fri, 21 Apr 2017 19:12:51 -0400 Received: from mail-it0-f45.google.com ([209.85.214.45]:37605 "EHLO mail-it0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1041407AbdDUXMu (ORCPT ); Fri, 21 Apr 2017 19:12:50 -0400 Received: by mail-it0-f45.google.com with SMTP id x188so178172itb.0 for ; Fri, 21 Apr 2017 16:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=from:date:to:subject:message-id:mime-version:content-disposition :user-agent; bh=GitwpswKlpm6X1P6AB3U+0jRXeC/IyYmQfhod30BcKQ=; b=dDiLXRh1m68mASn/BlPE3v7J5HalKlrvC4voiUoU0Y0bJeTz9U8yYQ1y/+HCDsZFCR +rgz13WpdLvv1XveqMt2dp1fTIPfJTyCLb6vASoBUeQlkltFMiZ5Sg0TvxVJojt8Kh4v Hs/ydd8YFVRj8VX8vzBKodwSc04wGU4iHI8N0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:subject:message-id:mime-version :content-disposition:user-agent; bh=GitwpswKlpm6X1P6AB3U+0jRXeC/IyYmQfhod30BcKQ=; b=Bed13PKgfvlqlbdxAxYZOgkpt2sVUUeD+R4hzAdZkD0YerAef2xCGGhXi3yKNwyb4G IfkYYoE1cEKCkUdMUWM7lj79Vky99DLu05OHzTPc2dusw255Hvi/mQ+QC5XTTZ1Eigli +MHsT9+C8NH7OVCMxLMM5jT8biVQpKLgLosai5pXsoI67x+dgE5OJ2YWFQ27c4Uvb9fV 2PmXbTKK5rzS1yY94e8a09abGG1yjsUxPhTFfBi+jMoYSQjmpRcjYLfXvFcysbHp8ueu kNhpcG0jJ8eNvb9v4J5Es4O4IulHAXwVd8mrxIadA5lTLkLHXuNdGxG/iYpvc2GywnVh 56EA== X-Gm-Message-State: AN3rC/5RaadysbuFeYoZ3UsYPOXMvI1YQ2qITtMTg7GV5oGEwpJPB+01 K3A+d8kVefvqF6z1hHQ= X-Received: by 10.36.89.207 with SMTP id p198mr1335744itb.71.1492816368914; Fri, 21 Apr 2017 16:12:48 -0700 (PDT) Received: from ircssh-2.c.rugged-nimbus-611.internal (80.60.198.104.bc.googleusercontent.com. [104.198.60.80]) by smtp.gmail.com with ESMTPSA id p70sm1352666itg.0.2017.04.21.16.12.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Apr 2017 16:12:48 -0700 (PDT) From: Sargun Dhillon X-Google-Original-From: Sargun Dhillon Date: Fri, 21 Apr 2017 23:12:47 +0000 To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] btrfs: add quota override attribute Message-ID: <20170421231246.GA3778@ircssh-2.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces the quota override flag to btrfs_fs_info, and a change to quota limit checking code to temporarily allow for quota to be overridden for processes with cap_sys_resource. It's useful for administrative programs, such as log rotation, that may need to temporarily use more disk space in order to free up a greater amount of overall disk space without yielding more disk space to the rest of userland. Eventually, we may want to add the idea of an operator-specific quota, operator reserved space, or something else to allow for administrative override, but this is perhaps the simplest solution. Signed-off-by: Sargun Dhillon --- fs/btrfs/ctree.h | 3 +++ fs/btrfs/qgroup.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index c411590..01a095b 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1098,6 +1098,9 @@ struct btrfs_fs_info { u32 nodesize; u32 sectorsize; u32 stripesize; + + /* Allow tasks with cap_sys_resource to override the quota */ + bool quota_override; }; static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index a59801d..0328492 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2347,8 +2347,12 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, return ret; } -static bool qgroup_check_limits(const struct btrfs_qgroup *qg, u64 num_bytes) +static bool qgroup_check_limits(const struct btrfs_qgroup *qg, + u64 num_bytes, bool quota_override) { + if (quota_override && capable(CAP_SYS_RESOURCE)) + return true; + if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) && qg->reserved + (s64)qg->rfer + num_bytes > qg->max_rfer) return false; @@ -2366,6 +2370,7 @@ static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes, bool enforce) struct btrfs_qgroup *qgroup; struct btrfs_fs_info *fs_info = root->fs_info; u64 ref_root = root->root_key.objectid; + bool qo = fs_info->quota_override; int ret = 0; struct ulist_node *unode; struct ulist_iterator uiter; @@ -2401,7 +2406,7 @@ static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes, bool enforce) qg = unode_aux_to_qgroup(unode); - if (enforce && !qgroup_check_limits(qg, num_bytes)) { + if (enforce && !qgroup_check_limits(qg, num_bytes, qo)) { ret = -EDQUOT; goto out; }