[2/2] btrfs: Add quota_override knob into sysfs
diff mbox

Message ID 20170421231304.GA3787@ircssh-2.c.rugged-nimbus-611.internal
State New
Headers show

Commit Message

Sargun Dhillon April 21, 2017, 11:13 p.m. UTC
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 <sargun@sargun.me>
---
 fs/btrfs/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

David Sterba May 5, 2017, 7:09 p.m. UTC | #1
On Fri, Apr 21, 2017 at 11:13:06PM +0000, Sargun Dhillon wrote:
> 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.

So we've moved to the hardest part, where to put the sysfs file and how
to name it.

My first though was against putting it right under the filesystem UUID
and rather introduce a directory with all tunables, but we already
have a read-write label there. Ok then.

The valid values are 0 and 1. And no locking is needed as fs_info::flags
are updated atomically (once patch 1 is updated).
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

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,
 };