From: Daniel Xu <dxu@dxuuu.xyz>
To: cgroups@vger.kernel.org, tj@kernel.org, lizefan@huawei.com,
hannes@cmpxchg.org
Cc: Daniel Xu <dxu@dxuuu.xyz>,
shakeelb@google.com, linux-kernel@vger.kernel.org,
gregkh@linuxfoundation.org, kernel-team@fb.com
Subject: [PATCH v2 4/4] cgroupfs: Support user xattrs
Date: Thu, 5 Mar 2020 13:16:32 -0800 [thread overview]
Message-ID: <20200305211632.15369-5-dxu@dxuuu.xyz> (raw)
In-Reply-To: <20200305211632.15369-1-dxu@dxuuu.xyz>
This patch turns on xattr support for cgroupfs. This is useful for
letting non-root owners of delegated subtrees attach metadata to
cgroups.
One use case is for subtree owners to tell a userspace out of memory
killer to bias away from killing specific subtrees.
Tests:
[/sys/fs/cgroup]# for i in $(seq 0 130); \
do setfattr workload.slice -n user.name$i -v wow; done
setfattr: workload.slice: No space left on device
setfattr: workload.slice: No space left on device
setfattr: workload.slice: No space left on device
[/sys/fs/cgroup]# for i in $(seq 0 130); \
do setfattr workload.slice --remove user.name$i; done
setfattr: workload.slice: No such attribute
setfattr: workload.slice: No such attribute
setfattr: workload.slice: No such attribute
[/sys/fs/cgroup]# for i in $(seq 0 130); \
do setfattr workload.slice -n user.name$i -v wow; done
setfattr: workload.slice: No space left on device
setfattr: workload.slice: No space left on device
setfattr: workload.slice: No space left on device
`seq 0 130` is inclusive, and 131 - 128 = 3, which is the number of
errors we expect to see.
[/data]# cat testxattr.c
#include <sys/types.h>
#include <sys/xattr.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
char name[256];
char *buf = malloc(64 << 10);
if (!buf) {
perror("malloc");
return 1;
}
for (int i = 0; i < 4; ++i) {
snprintf(name, 256, "user.bigone%d", i);
if (setxattr("/sys/fs/cgroup/system.slice", name, buf,
64 << 10, 0)) {
printf("setxattr failed on iteration=%d\n", i);
return 1;
}
}
return 0;
}
[/data]# ./a.out
setxattr failed on iteration=2
[/data]# ./a.out
setxattr failed on iteration=0
[/sys/fs/cgroup]# setfattr -x user.bigone0 system.slice/
[/sys/fs/cgroup]# setfattr -x user.bigone1 system.slice/
[/data]# ./a.out
setxattr failed on iteration=2
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
kernel/cgroup/cgroup.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 75f687301bbf..21621b43a8ab 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1954,7 +1954,8 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
root->kf_root = kernfs_create_root(kf_sops,
KERNFS_ROOT_CREATE_DEACTIVATED |
- KERNFS_ROOT_SUPPORT_EXPORTOP,
+ KERNFS_ROOT_SUPPORT_EXPORTOP |
+ KERNFS_ROOT_SUPPORT_USER_XATTR,
root_cgrp);
if (IS_ERR(root->kf_root)) {
ret = PTR_ERR(root->kf_root);
--
2.21.1
prev parent reply other threads:[~2020-03-05 21:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-05 21:16 [PATCH v2 0/4] Support user xattrs in cgroupfs Daniel Xu
2020-03-05 21:16 ` [PATCH v2 1/4] kernfs: kvmalloc xattr value instead of kmalloc Daniel Xu
2020-03-06 8:49 ` Joe Perches
2020-03-06 9:37 ` Greg KH
2020-03-09 18:21 ` Daniel Xu
2020-03-09 19:41 ` Joe Perches
2020-03-09 19:51 ` Tejun Heo
2020-03-09 19:58 ` Joe Perches
2020-03-09 20:05 ` Tejun Heo
2020-03-10 19:40 ` Shakeel Butt
2020-03-10 20:40 ` Daniel Xu
2020-03-10 20:41 ` Shakeel Butt
2020-03-05 21:16 ` [PATCH v2 2/4] kernfs: Add removed_size out param for simple_xattr_set Daniel Xu
2020-03-10 18:20 ` Daniel Xu
2020-03-05 21:16 ` [PATCH v2 3/4] kernfs: Add option to enable user xattrs Daniel Xu
2020-03-05 21:16 ` Daniel Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200305211632.15369-5-dxu@dxuuu.xyz \
--to=dxu@dxuuu.xyz \
--cc=cgroups@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=shakeelb@google.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).