* [PATCH v2 0/2] btrfs: allow mechanism to override quota
@ 2017-05-11 21:17 Sargun Dhillon
2017-05-11 21:17 ` [PATCH v2 1/2] btrfs: add quota override flag to enable quota override for sys_resource Sargun Dhillon
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Sargun Dhillon @ 2017-05-11 21:17 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, quwenruo
This patchset makes it so that on a per-filesystem basis one can disable
quota enforcement for users with cap_sys_resource. This patchset can
likely later be extended to per-qgroup, or a per-volume basis. I'm
thinking of extending the sysfs interface to list the qgroups and
this same interface for the qgroups themselves.
Changes since v1:
-Rather than a separate member of btrfs_fs_info, use the existing
flags field
Sargun Dhillon (2):
btrfs: add quota override flag to enable quota override for
sys_resource
btrfs: Add quota_override knob into sysfs
fs/btrfs/ctree.h | 2 ++
fs/btrfs/qgroup.c | 5 +++++
fs/btrfs/sysfs.c | 41 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
--
2.9.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] btrfs: add quota override flag to enable quota override for sys_resource
2017-05-11 21:17 [PATCH v2 0/2] btrfs: allow mechanism to override quota Sargun Dhillon
@ 2017-05-11 21:17 ` Sargun Dhillon
2017-05-11 21:18 ` [PATCH v2 2/2] btrfs: Add quota_override knob into sysfs Sargun Dhillon
2017-05-12 14:48 ` [PATCH v2 0/2] btrfs: allow mechanism to override quota David Sterba
2 siblings, 0 replies; 6+ messages in thread
From: Sargun Dhillon @ 2017-05-11 21:17 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, quwenruo
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 <sargun@sargun.me>
---
fs/btrfs/ctree.h | 2 ++
fs/btrfs/qgroup.c | 5 +++++
2 files changed, 7 insertions(+)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 643c70d..e86cb7c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -716,6 +716,8 @@ struct btrfs_delayed_root;
#define BTRFS_FS_BTREE_ERR 11
#define BTRFS_FS_LOG1_ERR 12
#define BTRFS_FS_LOG2_ERR 13
+#define BTRFS_FS_QUOTA_OVERRIDE 14
+
/*
* Indicate that a whole-filesystem exclusive operation is running
* (device replace, resize, device add/delete, balance)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index deffbeb..458fec0 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2338,6 +2338,11 @@ static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes, bool enforce)
if (num_bytes == 0)
return 0;
+
+ if (test_bit(BTRFS_FS_QUOTA_OVERRIDE, &fs_info->flags) &&
+ capable(CAP_SYS_RESOURCE))
+ enforce = false;
+
retry:
spin_lock(&fs_info->qgroup_lock);
quota_root = fs_info->quota_root;
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] btrfs: Add quota_override knob into sysfs
2017-05-11 21:17 [PATCH v2 0/2] btrfs: allow mechanism to override quota Sargun Dhillon
2017-05-11 21:17 ` [PATCH v2 1/2] btrfs: add quota override flag to enable quota override for sys_resource Sargun Dhillon
@ 2017-05-11 21:18 ` Sargun Dhillon
2017-05-12 14:48 ` [PATCH v2 0/2] btrfs: allow mechanism to override quota David Sterba
2 siblings, 0 replies; 6+ messages in thread
From: Sargun Dhillon @ 2017-05-11 21:18 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, quwenruo
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 | 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,
};
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] btrfs: allow mechanism to override quota
2017-05-11 21:17 [PATCH v2 0/2] btrfs: allow mechanism to override quota Sargun Dhillon
2017-05-11 21:17 ` [PATCH v2 1/2] btrfs: add quota override flag to enable quota override for sys_resource Sargun Dhillon
2017-05-11 21:18 ` [PATCH v2 2/2] btrfs: Add quota_override knob into sysfs Sargun Dhillon
@ 2017-05-12 14:48 ` David Sterba
2017-05-19 8:39 ` Sargun Dhillon
2 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2017-05-12 14:48 UTC (permalink / raw)
To: Sargun Dhillon; +Cc: linux-btrfs, dsterba, quwenruo
On Thu, May 11, 2017 at 09:17:01PM +0000, Sargun Dhillon wrote:
> This patchset makes it so that on a per-filesystem basis one can disable
> quota enforcement for users with cap_sys_resource. This patchset can
> likely later be extended to per-qgroup, or a per-volume basis. I'm
> thinking of extending the sysfs interface to list the qgroups and
> this same interface for the qgroups themselves.
>
> Changes since v1:
> -Rather than a separate member of btrfs_fs_info, use the existing
> flags field
Looks good to me, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] btrfs: allow mechanism to override quota
2017-05-12 14:48 ` [PATCH v2 0/2] btrfs: allow mechanism to override quota David Sterba
@ 2017-05-19 8:39 ` Sargun Dhillon
2017-05-19 13:26 ` David Sterba
0 siblings, 1 reply; 6+ messages in thread
From: Sargun Dhillon @ 2017-05-19 8:39 UTC (permalink / raw)
To: dsterba, Sargun Dhillon, BTRFS ML, Qu Wenruo
On Fri, May 12, 2017 at 7:48 AM, David Sterba <dsterba@suse.cz> wrote:
> On Thu, May 11, 2017 at 09:17:01PM +0000, Sargun Dhillon wrote:
>> This patchset makes it so that on a per-filesystem basis one can disable
>> quota enforcement for users with cap_sys_resource. This patchset can
>> likely later be extended to per-qgroup, or a per-volume basis. I'm
>> thinking of extending the sysfs interface to list the qgroups and
>> this same interface for the qgroups themselves.
>>
>> Changes since v1:
>> -Rather than a separate member of btrfs_fs_info, use the existing
>> flags field
>
> Looks good to me, thanks.
I'm curious as to whether this approach is fine to get an Acked-by, or
if I need to figure out how to make it more leak-tolerant. I don't
think modifying the overridden extents inflight is a problem. I'm not
sure of a way a user would be able to create *new* chunks of data.
Alternatively, I'd be quite happy making this applicable to metadata
only, for file xattrs, creation, deletion, etc..
Opinions?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] btrfs: allow mechanism to override quota
2017-05-19 8:39 ` Sargun Dhillon
@ 2017-05-19 13:26 ` David Sterba
0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2017-05-19 13:26 UTC (permalink / raw)
To: Sargun Dhillon; +Cc: BTRFS ML, Qu Wenruo
On Fri, May 19, 2017 at 01:39:49AM -0700, Sargun Dhillon wrote:
> On Fri, May 12, 2017 at 7:48 AM, David Sterba <dsterba@suse.cz> wrote:
> > On Thu, May 11, 2017 at 09:17:01PM +0000, Sargun Dhillon wrote:
> >> This patchset makes it so that on a per-filesystem basis one can disable
> >> quota enforcement for users with cap_sys_resource. This patchset can
> >> likely later be extended to per-qgroup, or a per-volume basis. I'm
> >> thinking of extending the sysfs interface to list the qgroups and
> >> this same interface for the qgroups themselves.
> >>
> >> Changes since v1:
> >> -Rather than a separate member of btrfs_fs_info, use the existing
> >> flags field
> >
> > Looks good to me, thanks.
> I'm curious as to whether this approach is fine to get an Acked-by,
This was meant as an acked-by, the patch is now queued for 4.13, but as
it add some user-visible interface, this may need more time to see if we
haven't missed something.
> or
> if I need to figure out how to make it more leak-tolerant. I don't
> think modifying the overridden extents inflight is a problem. I'm not
> sure of a way a user would be able to create *new* chunks of data.
> Alternatively, I'd be quite happy making this applicable to metadata
> only, for file xattrs, creation, deletion, etc..
>From the interface POV, this can be set as a bitmask. I haven't looked
if we'd be able to propagate all the changes everywhere in the code,
but sounds doable, bug I'm not sure if this level of fine-grained control
is desired.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-05-19 13:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-11 21:17 [PATCH v2 0/2] btrfs: allow mechanism to override quota Sargun Dhillon
2017-05-11 21:17 ` [PATCH v2 1/2] btrfs: add quota override flag to enable quota override for sys_resource Sargun Dhillon
2017-05-11 21:18 ` [PATCH v2 2/2] btrfs: Add quota_override knob into sysfs Sargun Dhillon
2017-05-12 14:48 ` [PATCH v2 0/2] btrfs: allow mechanism to override quota David Sterba
2017-05-19 8:39 ` Sargun Dhillon
2017-05-19 13:26 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).