From patchwork Thu May 11 21:18:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 9723179 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 8A05A60387 for ; Thu, 11 May 2017 21:18:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8196128731 for ; Thu, 11 May 2017 21:18:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75F5828736; Thu, 11 May 2017 21:18:10 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 F1B0928732 for ; Thu, 11 May 2017 21:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755309AbdEKVSH (ORCPT ); Thu, 11 May 2017 17:18:07 -0400 Received: from mail-it0-f45.google.com ([209.85.214.45]:35841 "EHLO mail-it0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753875AbdEKVSG (ORCPT ); Thu, 11 May 2017 17:18:06 -0400 Received: by mail-it0-f45.google.com with SMTP id o5so603630ith.1 for ; Thu, 11 May 2017 14:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=dTsU4DaOGxXV2JCYiiZ7jyNk3UuB5SAIsTmgTJi7gFg=; b=HGHgLNra3JEQ51XkXw4AouBLxSlvG7bflXEvFHHno8AAx3GWePeRnTl7gfzNBnTSCu /wWMmQH3mXXpjGKaHNwCLxcUFBIP3kryBS04qnm9/Rb0EgNvSWGUzTNfhKirOu3/JfcE ypm9cci62bHPTs7shStrgQxle8+FGxmbOqkno= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=dTsU4DaOGxXV2JCYiiZ7jyNk3UuB5SAIsTmgTJi7gFg=; b=VD40l9y06kT4GkL5fMTGbUXu50vwO3f1FN02HH+eIu9xJmc59p0y+uTXpVlSlYHuAm 2ederVT9cJCW6V7QWoT51lNBM0vV2N09V8AC+BVe/rohkn/EleOfHYYQ9sgxmP+KWm90 hWkoJZEZWoNU8O+tfmwn7+oPdHwlMoIOxEBeR0oRY0DdUjVF8bZHqO6ftoGnbB6UgXOk +bI5B7wpyQyAPdDPm2N8tCsGvV+yZfw/AG75yV784ThZgTLegADvmjlpd2u5hx3V9DMM NNZDMqV2BkkuiSnCwZ15ggaoXXRcOHOQTLSTCSuzs1IETnN3wbGnQc1OxlDKZs/mJV++ ql6Q== X-Gm-Message-State: AODbwcCiXN9R5qQR93qFUrtP+sQ2CW/53d5HD0zmcl8vUkZ56Ytuq92X e6qGHN24/tkMfw== X-Received: by 10.36.147.65 with SMTP id y62mr652563itd.68.1494537485147; Thu, 11 May 2017 14:18:05 -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 u135sm38670itu.10.2017.05.11.14.18.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 May 2017 14:18:04 -0700 (PDT) Date: Thu, 11 May 2017 21:18:03 +0000 From: Sargun Dhillon To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, quwenruo@cn.fujitsu.com Subject: [PATCH v2 2/2] btrfs: Add quota_override knob into sysfs Message-ID: <20170511211801.GA8422@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 adds the read-write attribute quota_override into sysfs. Any process which has cap_sys_resource can set this flag to on, and once it is set to true, processes with cap_sys_resource can exceed the quota. Signed-off-by: Sargun Dhillon --- fs/btrfs/sysfs.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 1f157fb..c2d5f35 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -447,11 +447,52 @@ static ssize_t btrfs_clone_alignment_show(struct kobject *kobj, BTRFS_ATTR(clone_alignment, btrfs_clone_alignment_show); +static ssize_t quota_override_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + struct btrfs_fs_info *fs_info = to_fs_info(kobj); + int quota_override; + + quota_override = test_bit(BTRFS_FS_QUOTA_OVERRIDE, &fs_info->flags); + return snprintf(buf, PAGE_SIZE, "%d\n", quota_override); +} + +static ssize_t quota_override_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + struct btrfs_fs_info *fs_info = to_fs_info(kobj); + unsigned long knob; + int err; + + if (!fs_info) + return -EPERM; + + if (!capable(CAP_SYS_RESOURCE)) + return -EPERM; + + err = kstrtoul(buf, 10, &knob); + if (err) + return err; + if (knob > 1) + return -EINVAL; + + if (knob) + set_bit(BTRFS_FS_QUOTA_OVERRIDE, &fs_info->flags); + else + clear_bit(BTRFS_FS_QUOTA_OVERRIDE, &fs_info->flags); + + return len; +} + +BTRFS_ATTR_RW(quota_override, quota_override_show, quota_override_store); + static const struct attribute *btrfs_attrs[] = { BTRFS_ATTR_PTR(label), BTRFS_ATTR_PTR(nodesize), BTRFS_ATTR_PTR(sectorsize), BTRFS_ATTR_PTR(clone_alignment), + BTRFS_ATTR_PTR(quota_override), NULL, };