From patchwork Fri Apr 21 23:13:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 9693923 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 5D189601D4 for ; Fri, 21 Apr 2017 23:13:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E9822867F for ; Fri, 21 Apr 2017 23:13:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 439F328684; Fri, 21 Apr 2017 23:13:12 +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 BAC9D2867F for ; Fri, 21 Apr 2017 23:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1041885AbdDUXNK (ORCPT ); Fri, 21 Apr 2017 19:13:10 -0400 Received: from mail-io0-f169.google.com ([209.85.223.169]:34264 "EHLO mail-io0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1041569AbdDUXNI (ORCPT ); Fri, 21 Apr 2017 19:13:08 -0400 Received: by mail-io0-f169.google.com with SMTP id a103so136376145ioj.1 for ; Fri, 21 Apr 2017 16:13:08 -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=I3bGRxpI/58ltr8iYjrDwotb9ZQWxphd1RhisADo1AY=; b=YZ47kTPmp+L3YcFlA4kR3k4nL25n7boLoNdq/tJpUd7bBM4LKWTwcMuKLpFPIYZSrg +VMp63rWPJACKDHeHwoVKaOg94LFvUbjRYMaxdVPQsB+I35LpxvdqDSZoauqNNj1Uv9L JO8wm3036Bfu3MTrBroHtwv7JQqbV1uVMZc+8= 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=I3bGRxpI/58ltr8iYjrDwotb9ZQWxphd1RhisADo1AY=; b=W+qFgg9h6pXIF+1xBg3qnGVjyzsvH/QaNXzADedjydi5W8pVBySMIO5pEaHxzszHBs if0HQAz6ir7yHQRfA8zpUFZDDiaOCnrHpiGIRAxSIc2IVdJABUCGbHUhST19FTZHQQUp 1YOrYq32q3BRLgLAWKmA8l6ymt2oxIDcOffs7HI3AnoeU1hn4nJHU5T7d95GSTVK10hs nrPRORg90FN5qxANtrpvwxvgJSwm2dga53Vq/2bteUruJRAkuR0+c+zcFJQP06DALIX4 NmFPWfPyOMCHpTARzXghTXoqj8fmwQ0405tjRuwhzx0sR+Da7WP7oheUSll3358EdRxl JipA== X-Gm-Message-State: AN3rC/4m/ELExeTUg+Nk3OtUkJdkQ+A48N6hlboTfvsCT4U3Y7dK3keQ pKu/QHH+5SSZz/f/Rtk= X-Received: by 10.107.136.93 with SMTP id k90mr17044643iod.51.1492816387658; Fri, 21 Apr 2017 16:13:07 -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 62sm4714094iou.10.2017.04.21.16.13.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Apr 2017 16:13:07 -0700 (PDT) From: Sargun Dhillon X-Google-Original-From: Sargun Dhillon Date: Fri, 21 Apr 2017 23:13:06 +0000 To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs: Add quota_override knob into sysfs Message-ID: <20170421231304.GA3787@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 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 1f157fb..c62acca 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -447,11 +447,47 @@ 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); + + return snprintf(buf, PAGE_SIZE, "%d\n", fs_info->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; + + fs_info->quota_override = !!knob; + + 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, };