[Devel] [PATCH RHEL7 COMMIT] ms/cgroup: let a symlink too be created with a cftype file
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Jan 29 15:16:50 MSK 2020
The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.2.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.3.1
------>
commit 96fa4a6f6d3dae0178b5770fb88da7000c525fc8
Author: Angelo Ruocco <angeloruocco90 at gmail.com>
Date: Wed Jan 29 12:16:50 2020 +0000
ms/cgroup: let a symlink too be created with a cftype file
This commit enables a cftype to have a symlink (of any name) that
points to the file associated with the cftype.
Signed-off-by: Angelo Ruocco <angeloruocco90 at gmail.com>
Signed-off-by: Paolo Valente <paolo.valente at linaro.org>
Signed-off-by: Jens Axboe <axboe at kernel.dk>
https://jira.sw.ru/browse/PSBM-101019
(cherry-picked from 54b7b868e826b294687c439b68ec55fe20cafe5b)
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
include/linux/cgroup-defs.h | 3 +++
kernel/cgroup/cgroup.c | 33 +++++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 05c46b2..ecf7d46 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -102,6 +102,8 @@ enum {
*/
CFTYPE_VE_WRITABLE = (1 << 15),
+ CFTYPE_SYMLINKED = (1 << 6), /* pointed to by symlink too */
+
/* internal flags, do not use outside cgroup core proper */
__CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */
__CFTYPE_NOT_ON_DFL = (1 << 17), /* not on default hierarchy */
@@ -510,6 +512,7 @@ struct cftype {
* end of cftype array.
*/
char name[MAX_CFTYPE_NAME];
+ char link_name[MAX_CFTYPE_NAME];
unsigned long private;
/*
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 7376dd5..ae811e4 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1420,8 +1420,8 @@ struct cgroup *task_cgroup_from_root(struct task_struct *task,
static struct kernfs_syscall_ops cgroup_kf_syscall_ops;
-static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft,
- char *buf)
+static char *cgroup_fill_name(struct cgroup *cgrp, const struct cftype *cft,
+ char *buf, bool write_link_name)
{
struct cgroup_subsys *ss = cft->ss;
@@ -1429,12 +1429,25 @@ static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft,
!(cgrp->root->flags & CGRP_ROOT_NOPREFIX))
snprintf(buf, CGROUP_FILE_NAME_MAX, "%s.%s",
cgroup_on_dfl(cgrp) ? ss->name : ss->legacy_name,
- cft->name);
+ write_link_name ? cft->link_name : cft->name);
else
- strscpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
+ strscpy(buf, write_link_name ? cft->link_name : cft->name,
+ CGROUP_FILE_NAME_MAX);
return buf;
}
+static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft,
+ char *buf)
+{
+ return cgroup_fill_name(cgrp, cft, buf, false);
+}
+
+static char *cgroup_link_name(struct cgroup *cgrp, const struct cftype *cft,
+ char *buf)
+{
+ return cgroup_fill_name(cgrp, cft, buf, true);
+}
+
/**
* cgroup_file_mode - deduce file mode of a control file
* @cft: the control file in question
@@ -1593,6 +1606,9 @@ static void cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft)
}
kernfs_remove_by_name(cgrp->kn, cgroup_file_name(cgrp, cft, name));
+ if (cft->flags & CFTYPE_SYMLINKED)
+ kernfs_remove_by_name(cgrp->kn,
+ cgroup_link_name(cgrp, cft, name));
}
/**
@@ -3643,6 +3659,7 @@ static int cgroup_add_file(struct cgroup_subsys_state *css, struct cgroup *cgrp,
{
char name[CGROUP_FILE_NAME_MAX];
struct kernfs_node *kn;
+ struct kernfs_node *kn_link;
struct lock_class_key *key = NULL;
int ret;
@@ -3671,6 +3688,14 @@ static int cgroup_add_file(struct cgroup_subsys_state *css, struct cgroup *cgrp,
spin_unlock_irq(&cgroup_file_kn_lock);
}
+ if (cft->flags & CFTYPE_SYMLINKED) {
+ kn_link = kernfs_create_link(cgrp->kn,
+ cgroup_link_name(cgrp, cft, name),
+ kn);
+ if (IS_ERR(kn_link))
+ return PTR_ERR(kn_link);
+ }
+
return 0;
}
More information about the Devel
mailing list